akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<cstdint>
//#include<>
using namespace std;

typedef int64_t i64;typedef int32_t i32;
typedef int16_t i16;typedef int8_t i8;
typedef uint64_t ui64;typedef uint32_t ui32;
typedef uint16_t ui16;typedef uint8_t ui8;

typedef i32 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define repeat_eq(i,j,k) for(int__ i=(j);i<=(k);i++)
#define all(v) begin(v),end(v)

const i32 INF=1<<30;//=10E10

inline int taxed(int notax,int taxrate){
  return notax*(100+taxrate)/100;
}

int main()
{
  int x,y,s;
  while(cin>>x>>y>>s){
    if(x==0&&y==0&&s==0)break;
    int a,b=s-1;
    int ans=0;
    for(a=1;a<s;a++){
      int a_=taxed(a,x);
      while(a_+ taxed(b,x) > s && b>1)--b;
      if(a_+ taxed(b,x)==s){
	ans=max(ans,taxed(a,y)+taxed(b,y));
      }
      
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int insertionSort(int A[], int N, int g) {
  int cnt = 0;
  for (int i=g; i<N; i++) {
    int v = A[i];
    int j = i-g;
    while (j>=0 && A[j]>v) {
      A[j+g] = A[j];
      j = j-g;
      cnt++;
    }
    A[j+g] = v;
  }
  return cnt;
}

void shellSort(int A[], int N) {
  int m = 1;
  int ans = N;
  while (ans>1) {
    ans /= 2;
    m++;
  }
  int G[m];
  for (int i=0; i<m; i++) G[m-i-1] = (int) pow(2, i);
  cout << m << endl;
  // Gの要素をプリント.
  for (int i=0; i<m; i++) {
    if (i>0) cout << " ";
    cout << G[i];
  }
  cout << endl;

  int cnt = 0;
  for (int i=0; i<m; i++) cnt += insertionSort(A, N, G[i]);
  cout << cnt << endl;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i=0; i<N; i++) cin >> A[i];
  shellSort(A, N);
  for (int i=0; i<N; i++) cout << A[i] << endl;
}


Measured memory_bytes: 7184
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
#define pb push_back
#define x first
#define y second
#define INF 1000000001
using namespace std;
typedef long long ll;

void solve(){
	int n;
	cin >> n;
	vector<int> h(n);
	forn(i,n) cin >> h[i];
	vector<int> dp(n,0);
	dp[1] = abs(h[1]-h[0])+dp[0];
	for(int i=2;i<n;i++){
		dp[i] = min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
	}
	cout << dp[n-1] << endl;
}   
    
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3920
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(n) inp(m)
	inp(k)
	n=max(n,m);
	cout<<k/n+(k%n!=0)<<'\n';
	printclock;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n,a,b,c=0,d;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		d=0;
		for(int j=i;j>0;j/=10){
			d+=j%10;
		}
		if(a<=d&&d<=b)c+=i;
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

const ll mod = 1e9+7;
const int INF = 1e9;
const ll MAXN = 1e9;

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

  vector<int> cnt(n),e(n),w(n);

  if(s[0] == 'E') e[0]++;
  else w[0]++;
  for(int i = 1; i < n; i++)
  {
    e[i] = e[i-1];
    w[i] = w[i-1];
    if(s[i] == 'E') e[i]++;
    else w[i]++;
  }

  int min = e[n-1]-e[0];
  for(int i = 1; i < n; i++)
  {
    cnt[i] = w[i-1] + e[n-1] - e[i];
    if(min > cnt[i]) min = cnt[i];
  }

  cout << min << endl;

  return 0;
}

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

using namespace std;

int main() {
  static std::bitset<1000000000> bits{};
  int a;
  std::cin >> a;
  while (std::cin >> a) {
    a--;
    bits[a] = bits[a] ^ 1;
  }
  std::cout << bits.count() << std::endl;
  return 0;
}


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

if __name__ == '__main__':
    N = raw_input()
    if int(N[0])+int(N[1])+int(N[2])+int(N[3]) == 7:
        print('{0}+{1}+{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])+int(N[2])-int(N[3]) == 7:
        print('{0}+{1}+{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])-int(N[2])+int(N[3]) == 7:
        print('{0}+{1}-{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])-int(N[2])-int(N[3]) == 7:
        print('{0}+{1}-{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])+int(N[2])+int(N[3]) == 7:
        print('{0}-{1}+{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])+int(N[2])-int(N[3]) == 7:
        print('{0}-{1}+{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])-int(N[2])+int(N[3]) == 7:
        print('{0}-{1}-{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])-int(N[2])-int(N[3]) == 7:
        print('{0}-{1}-{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))


Measured memory_bytes: 2696
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Solution {
public:
	/* time: O(n + q), space: O(n) */
	vector<bool> attackSurvival(int n, int k, const vector<int>& questions) {
		const int q = questions.size();
		vector<int> nCorrect(n);
		for (int player : questions)
			++nCorrect[player - 1];

		vector<bool> ans(n);
		for (int i = 0; i < n; ++i)
			ans[i] = (k - (q - nCorrect[i])) > 0;
		return ans;
	}
};

int main() {
	int n, k, q;
	cin >> n >> k >> q;

	vector<int> questions(q);
	for (int i = 0; i < q; ++i)
		cin >> questions[i];

	Solution sol;
	vector<bool> ans = sol.attackSurvival(n, k, questions);
	for (int i = 0; i < n; ++i)
		cout << (ans[i] ? "Yes" : "No") << endl;
	return 0;
}


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

bool linerSearch(int A[],int n,int key){
    int ans=0;
    for(int i=0;i<n;i++){
        if(A[i]==key){ans=1;break;}
    }
    return ans;
}

int main(){
    int n,q,k;
    cin>>n;
    int S[n];
    for(int i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    cin>>q;
    int ans=0;
    for(int i=0;i<q;i++){
        scanf("%d",&k);
        if(linerSearch(S,n,k))ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
    int m, d, ans = 0;
    cin >> m >> d;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= d; j++) {
            if (j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i) {
                ans++;
            }
        }
    cout << ans << endl;
    return 0;
}


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

#include <cassert>
using namespace std;

const int MOD = 1e9 + 7;

inline void ModSum(int& x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
    if (x < 0) {
        x += MOD;
    }
}

inline int GetModSum(int x, int y) {
    ModSum(x, y);
    return x;
}

const long long INF = 2e18;

int n;
long long a, b;
vector<long long> s;

vector<int> ab, sab;
vector<int> ba, sba;

vector<int> posBinA, posBinB;
vector<int> posGoodA, posGoodB;

inline int GetSum(int l, int r, const vector<int>& sum) {
    if (l == 0) {
        return sum[r];
    } else {
        int result = sum[r];
        ModSum(result, -sum[l - 1]);
        return result;
    }
}

void Solve() {
    s.push_back(INF);
    ++n;

    auto fillPosBin = [&] (vector<int>& posBin, long long bound) {
        posBin.resize(n);
        for (int i = 0; i + 1 < n; ++i) {
            posBin[i] = -1;
            {
                int bl = 0;
                int br = i - 1;
                while (bl <= br) {
                    int bm = (bl + br) >> 1;

                    if (s[i + 1] - s[bm] >= bound) {
                        posBin[i] = bm;
                        bl = bm + 1;
                    } else {
                        br = bm - 1;
                    }
                }
            }
        }
    };

    fillPosBin(posBinA, b);
    fillPosBin(posBinB, a);

    auto fillPosGood = [&] (vector<int>& posGood, long long bound) {
        posGood.resize(n);
        for (int i = 0; i < n; ++i) {
            posGood[i] = i;
            if (i > 0 && s[i] - s[i - 1] >= bound) {
                posGood[i] = posGood[i - 1];
            }
        }
    };

    fillPosGood(posGoodA, a);
    fillPosGood(posGoodB, b);

    ab.resize(n);
    sab.resize(n);

    ba.resize(n);
    sba.resize(n);

    for (int i = 0; i + 1 < n; ++i) {
        ab[i] = 0;
        if (posGoodA[i] == 0) {
            ModSum(ab[i], 1);
        }
        if (posBinA[i] != -1) {
            int pl = max(0, posGoodA[i] - 1);
            int pr = min(i - 1, posBinA[i]);

            if (pl <= pr) {
                ModSum(ab[i], GetSum(pl, pr, sba));
            }
        }

        ba[i] = 0;
        if (posGoodB[i] == 0) {
            ModSum(ba[i], 1);
        }
        if (posBinB[i] != -1) {
            int pl = max(0, posGoodB[i] - 1);
            int pr = min(i - 1, posBinB[i]);

            if (pl <= pr) {
                ModSum(ba[i], GetSum(pl, pr, sab));
            }
        }

        sab[i] = (i == 0 ? 0 : sab[i - 1]);
        ModSum(sab[i], ab[i]);

        sba[i] = (i == 0 ? 0 : sba[i - 1]);
        ModSum(sba[i], ba[i]);
    }

    int result = ab[n - 2];
    ModSum(result, ba[n - 2]);

    cout << result << endl;
}

bool Read() {
    if (!(cin >> n)) {
        return false;
    }
    cin >> a >> b;
    s.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    return true;
}

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

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (Read()) {
        Solve();
    }

    return 0;
}


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


int main()
{
    string s;
    cin>>s;
    ll l = s.size(); //cout<<l<<endl;
    ll ara[l+1];
    ll temp, sum = 0;

    for(ll i = 0; i <= l; i++){
        if(i == 0 && s[i] == '<'){
            ara[i] = 0;
            sum += ara[i];
        }
        else if(s[i-1] == '>' && s[i] == '<'){
            ara[i] = 0;
            sum += ara[i];
        }

        else if(s[i-1] == '<' && s[i] == '<'){
            ara[i] = ara[i-1] + 1;
            sum += ara[i];
        }

        else if(i == l && s[i-1] == '>'){
            ara[i] = 0;
            sum += ara[i];
        }




    }

    for(ll i = l; i >= 0; i--){
        if(i == l && s[i-1] == '<'){
            ara[i] = ara[i-1] + 1;
            sum += ara[i];
        }

        else if(s[i] == '>' && s[i-1] == '>'){
            ara[i] = ara[i+1] + 1;
            sum += ara[i];
        }

        else if(s[i] == '>' && s[i-1] == '<'){
            temp = max(ara[i+1], ara[i-1]);
            temp++;
            ara[i] = temp;
            sum += ara[i];
        }
        else if(i == 0 && s[i] == '>'){
            ara[i] = ara[i+1] + 1;
            sum += ara[i];
        }



    }

    cout<<sum<<endl;


    return 0;
}




Measured memory_bytes: 4740
def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    def solve(positive, A):
        total = 0
        ope = 0
        for i in range(len(A)):
            # print("####")
            # print(total)
            # print(ope)
            if positive:
                # 次は負の数=正の数になるなら補正
                if total + A[i] >= 0:
                    ope += total + A[i] + 1
                    total = total + A[i] - (total + A[i]) - 1
                else:
                    total += A[i]
            else:
                # 次は正の数=負の数になるなら補正
                if total + A[i] <= 0:
                    ope += abs(total + A[i]) + 1
                    total = total + A[i] + abs(total + A[i]) + 1
                else:
                    total += A[i]
            positive = (not positive)
        return ope
    
    print(min(solve(True, A), solve(False, A)))



if '__main__' == __name__:
    resolve()

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


class Solution{
    
    void solve() throws IOException{

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        String a = bufferedReader.readLine();

        HashMap<Character,List<Integer>> hashMap = new HashMap<Character,List<Integer>>();

        
        for(int i=0;i<a.length();i++){

           List<Integer> indexesList = hashMap.getOrDefault(a.charAt(i),new ArrayList<Integer>());

            indexesList.add(i);

            hashMap.put(a.charAt(i), indexesList);


            if(indexesList.size() > 1){
                int index1 = indexesList.get(indexesList.size()-2);
                int index2 = indexesList.get(indexesList.size()-1);

                if(2  > (index2-index1-1)){

                    System.out.println((index1+1) + " " + (index2+1));
                    return;
                }

            }


        }



        System.out.println("-1 -1");

    }
}

public class Main {
    public static void main(String[] args) throws IOException{
        new Solution().solve();
    }   
}

Measured memory_bytes: 41520
#include<iostream>
#include<string>

bool existNum[1000] = {false};

int main(){
    int N;
    std::string S;
    std::cin >> N >> S;

    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            int nowCheckNum[2] = {i, j};
            int offset = 0;
            int baseVal = 100 * i + 10 * j;
            for(int SInd = 0; SInd < N; SInd++){
                if(offset < 2 && nowCheckNum[offset] == (S[SInd] - '0')){
                     offset++;
                     continue;
                }
                if(offset == 2) existNum[baseVal + S[SInd] - '0'] = true;
            }
        }
    }

    int cnt = 0;
    for(int i = 0; i < 1000; i++) cnt += existNum[i];
    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
s1 = [0]
s2 = [0]
temp1 = 0
temp2 = 0
for i in range(n):
    temp1 += a1[i]
    temp2 += a2[i]
    s1.append(temp1)
    s2.append(temp2)
ans = 0
for i in range(n + 1):
    ans = max(ans, s2[n] - s2[i - 1] + s1[i])
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
using ld = long double;
using ulli = unsigned long long int;
#define filein freopen ("in.txt", "r", stdin)
#define fileout freopen ("out.txt", "w", stdout)
#define dbg(x) cerr << #x << ": " << x << endl
#define all(v) ((v).begin()),((v).end())
#define PI 3.14159265 
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,n) for(int i=1;i<=n;i++)
#define mod 1000000007
void solve(){
	string s;
	cin>>s;
	if((int) s.size() < 6 or (s[2] != s[3] or s[4] != s[5])){
		cout<<"No";
	}else{
		cout<<"Yes";
	}
}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}


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

typedef long long ll;

int main()
{
	ll n, m;
  	cin >> n >> m;
  	ll tall[n+1];
  	for(int i = 1; i <= n; i++)
    {
    	cin >> tall[i];
    }
  	int a[m];
  	int b[m];
  	for(int i = 0; i < m; i++)
    {
    	cin >> a[i] >> b[i];
    }
  	int good[n+1];
  	for(int i = 1; i <= n; i++)
    {
    	good[i] = 0;
    }
  	for(int i = 0; i < m; i++)
    {
    	if(tall[a[i]] > tall[b[i]])
        {
        	good[b[i]]++; 
        }
      	else if(tall[a[i]] < tall[b[i]])
        {
        	good[a[i]]++;
        }
      	else if(tall[a[i]] == tall[b[i]])
        {
        	good[a[i]]++;
          	good[b[i]]++;
        }
    }
  	int ans = 0;
  	for(int i = 1; i <= n; i++)
    {
    	if(good[i] == 0)
        {
        	ans++;
        }
    }
  	cout << ans << endl;
}


Measured memory_bytes: 5576
def gcd(a,b):
    if a<b:
        a,b=b,a
    if b==0:
        return a
    else:
        return gcd(b,a%b)

K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=gcd(i,gcd(j,k))
print(ans)

Measured memory_bytes: 80376
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int H,W;cin >> H >> W;
  string S[H];
  int i,j;
  REP(i,H) cin >> S[i];
  int maximum = 0;
  int n_onLamp[H][W];
  REP(i,H){
    int count = 0;
    int state = 0;
    REP(j,W+1){
      if(j!=W)n_onLamp[i][j] = 0;
      if(j==W || S[i][j] == '#'){
        state = j;
        while(--j>=0 && S[i][j] == '.')n_onLamp[i][j] += count;
        j = state;
        count = 0;
      }else count++;
    }
  }
  REP(j,W){
    int count = 0;
    int state = 0;
    REP(i,H+1){
      if(i==H || S[i][j] == '#'){
        state = i;
        while(--i>=0 && S[i][j] == '.'){
          n_onLamp[i][j] += count;
          maximum = max(maximum,n_onLamp[i][j]);
        }
        i = state;
        count = 0;
      }else count++;
    }
  }
  cout << maximum-1 << endl;
  return 0;
}


Measured memory_bytes: 19968
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int w,a,b;
    cin >> w >> a >> b;
    int t;
    if(b<a){
      t=a;
      a=b;
      b=t;
    }
    cout << max(b-a-w,0);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    s = input()
    letter = s[0]
    if letter in d:
        d[letter] += 1
ans = 0
l = ["M", "A", "R", "C", "H"]
t1 = 0
t2 = 0
t3 = 0
for i in range(0, 3):
    if d[l[i]] != 0:
        t1 = d[l[i]]
        for j in range(i+1, 4):
            if d[l[j]] != 0:
                t2 = d[l[j]]
                for k in range(j+1, 5):
                    if d[l[k]] != 0:
                        t3 = d[l[k]]
                        ans += t1 * t2 * t3
print(ans)

Measured memory_bytes: 3064
// AOJ ITP2_11_B Enumeration of Subsets II
// 2019.3.9 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (isdigit(c));
	return n;
}

void out(int n)
{
	int i;
	char ob[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
}

int main()
{
	int i, j, k, n, max, mask;

	n = in(), max = 1 << n;
	k = in(), mask = 0;
	while (k--) mask |= 1 << in();
	for (i = 0; i < max; i++) {
		if ((i & mask) != mask) continue;
		out(i), pc(':');
		k = i; for (j = 0; k; j++) {
			if (k & 1) pc(' '), out(j);
			k >>= 1;
		}
		pc('\n');
	}
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  unordered_map<string,long long> mp;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  long long ans=0;
  for(auto p:mp){
      ans += p.second*(p.second-1)/2;
  }
  cout << ans << endl;
}  

Measured memory_bytes: 10660
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG minpro2019/b.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v[4];
    rep(i, 4){
        v[i] = 0;
    }
    rep(i, 3){
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a]++; v[b]++;
    }
    rep(i, 4){
        if(v[i] == 3){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int length = scan.nextInt();

		int a[] = new int[length];

		for (int i = 0; i < length; i++) {
			a[i] = scan.nextInt();
		}

        for (int i = 0; i < a.length; i++) {
            System.out.print(i + 1 == a.length ? a[i] + "\n" : a[i] + " ");
        }

		// 挿入ソート
		for (int i = 1; i < a.length; i++) {
			int key = a[i];
			int j = i - 1;

			while (j >= 0 && a[j] > key) {
				int temp = a[j];
				a[j] = key;
				a[j + 1] = temp;
				j = j - 1;
			}

            for (int k = 0; k < a.length; k++) {
                System.out.print(k + 1 == a.length ? a[k] + "\n" : a[k] + " ");
            }

		}

	}

}

Measured memory_bytes: 12000
import java.util.*;

class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int N = Integer.parseInt(sc.next());
      	int K = Integer.parseInt(sc.next());
      	int[] A = new int[N];
      	for (int i=0; i<N; i++) {A[i] = Integer.parseInt(sc.next());}
      
      	double per;//a_i+k-1 / a_i-1
      	
      	for (int i = 1; i < N - K + 1; i++) {
            	per = ((double)A[i + K - 1]) / ((double)A[i - 1]);
              	if (per > 1) {
              	System.out.println("Yes");
            	} else {System.out.println("No");}
        }
	}
}

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

int main() {
    long a, b, k;
    cin >> a >> b >> k;

    if ( a + b <= k ) cout << 0 << " " << 0 << endl;
    else if ( k < a ) cout << a - k << " " << b << endl;
    else if ( k >= a ) cout << 0 << " " << b - ( k - a ) << endl;

    return 0;
}

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

int main(){
    int n; cin >> n;
    int tmp=0, ans=0;
    int h1, h2; cin >> h1;
    for(int i=1; i<n; i++){
        cin >> h2;
        if(h1>=h2) tmp++;
        if(!(h1>=h2) || i==n-1){
            ans=max(ans, tmp);
            tmp=0;
        }
        h1=h2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

*I, = open(0).read().split()
N, A, B, C = map(int, I[:4])
S = I[4:]

Cnt = {"A": A, "B": B, "C": C}

ans = [""] * N
def dfs(i):
    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    for L, R in (S[i], reversed(S[i])):
        if Cnt[R] > 0:
            Cnt[L] += 1
            Cnt[R] -= 1

            ans[i] = L
            dfs(i + 1)

            Cnt[L] -= 1
            Cnt[R] += 1


dfs(0)
print("No")


Measured memory_bytes: 115896
from collections import defaultdict

N = int(input())
words = defaultdict(int)
for i in range(N):
    s = list(input())
    s.sort()
    words[''.join(s)] += 1

ans = 0
for n in words.values():
    if n == 1:
        continue
    ans += n * (n - 1) // 2
print(ans)


Measured memory_bytes: 18192
def f():
  A=[raw_input() for _ in range(h)]
  x,y=0,0
  while 1:
    a=A[y]
    s=a[x]
    A[y]=a[0:x]+'x'+a[x+1:]
    if s==">": x+=1
    elif s=="<": x-=1
    elif s=="v": y+=1
    elif s=="^": y-=1
    elif s==".": return x,y
    else: return []
  
while 1:
  h,w=map(int,raw_input().split())
  if h==w==0: break
  x=f()
  if x==[]: print "LOOP"
  else: print x[0],x[1]

Measured memory_bytes: 4236
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x)      x.begin(), x.end()
#define rep(i,n)    for (int i = 0; i < (n); ++i)
#define reps(i,s,t) for (int i = (s); i <= (t); ++i)
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

namespace std {
    template<> struct hash<pii> {
        size_t operator() (const pii &x) const { return (x.first << 30) ^ (x.second); }
    };
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    i64 H, W, N;
    i64 cnt[10] {};
    unordered_set<pii> p;

    cin >> H >> W >> N;
    cnt[0] = (H-2) * (W-2);

    while(N--) {
        int a, b;
        cin >> a >> b;

        reps(sy, a-2, a) {
            reps(sx, b-2, b) {
                const i64 gy = sy + 2;
                const i64 gx = sx + 2;
                if (sy < 1 || sx < 1 || gy > H || gx > W) continue;

                int u = 0;
                reps(i, sy, gy) reps(j, sx, gx) {
                    if (p.count({i,j})) ++u;
                }

                --cnt[u];
                ++cnt[u+1];
            }
        }
        p.emplace(a, b);
    }

    rep(i, 10) {
        cout << cnt[i] << "\n";
    }


    return 0;
}



Measured memory_bytes: 6052
#include<iostream>
using namespace std;
int main(){
  int a,b;
  string s,t,u;
  cin >> s >> t >> a >> b >> u;
  if(u == s){
    cout << a-1 << " " << b << endl;
  }
  else if(u == t){
    cout << a << " " << b-1 << endl;
  }
}

  

Measured memory_bytes: 256
n = int(input())
count = 0
if n == 100000:
  count=90909
elif 10 ** 4 <= n and n < 10 ** 5:
  count = 9 + 900 + n - 10**4 + 1
elif 10**3 <= n and n < 10 **4:
  count = 909
elif 10 ** 2 <= n and n < 10 **3:
  count = 9 + n - 10**2 +1
elif 10 ** 1 <= n and n <10**2:
  count = 9
else:
  count = n
print(count)
    

Measured memory_bytes: 3060
#include <stdio.h>

double ans;
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		double t;
		char s[10];
		scanf("%lf %s",&t,s);
		if(s[0]=='J')ans+=t;
		else ans+=t*380000;
	}
	printf("%.9f",ans);
}

Measured memory_bytes: 128
//AtCoder Beginner Contest 086
//C - Traveling

#include <iostream>
#include <algorithm>

using namespace std;

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

    int t1 = 0;
    int x1 = 0;
    int y1 = 0;

    for(int i=0;i<n;i++){
        int t2,x2,y2;
        cin >> t2 >> x2 >> y2;

        int dis = abs(x1-x2)+abs(y1-y2);
        if( !( dis%2==(t2-t1)%2 && dis<=(t2-t1) ) ){
            cout << "No" << endl;
            return 0;
        }

        t1 = t2; x1 = x2; y1 = y2;
    }

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


Measured memory_bytes: 256
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            Console.WriteLine(AB[0] * AB[1] / GCD(AB[0], AB[1]));
        }
        static long GCD(long A, long B)
        {
            if (B > A) return GCD(B, A);
            if (A % B == 0)
            {
                return B;
            }
            else
            {
                return GCD(B, A % B);
            }
        }
    }
}


Measured memory_bytes: 11220
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

int can (char *s, i32 a, i32 t) {
  i32 now = a;
  while (now < t) {
    if (s[now + 1] == '#' && s[now + 2] == '#') return 0;
    if (s[now + 1] == '#') {
      now += 2;
    } else {
      now += 1;
    }
  }
  return now == t;
}

void run (void) {
  i32 n, a, b, c, d;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &a, &b, &c, &d);
  a--;
  b--;
  c--;
  d--;
  char *s = (char *) calloc (n + 3, sizeof (char)) + 1;
  scanf ("%s", s);
  s[-1] = s[n] = s[n + 1] = '#';
  if (!(can (s, a, c) && can (s, b, d))) {
    puts ("No");
    return;
  }
  if (c > d) {
    i32 ok = 0;
    for (i32 i = b; i <= d; ++i) {
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.' && can (s, a, i - 1)) {
	ok = 1;
      }
    }
    if (!ok) {
      puts ("No");
      return;
    }
  }
  puts ("Yes");
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 384
N = gets.to_i
S = gets.chomp

alf = ['A','B','C','D','E','F','G',
  'H','I','J','K','L','M','N','O','P',
  'Q','R','S','T','U','V','W','X','Y','Z']

result = ''
for c in S.chars
  x = alf.index(c)
  x = ( x + N ) % 26
  result += alf[x]
end

puts result

Measured memory_bytes: 19836
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

const int MAX_N = 3000000;
const int MOD = 1000000007;
long long inv[MAX_N + 1], fac[MAX_N + 1], finv[MAX_N + 1];

void init() {
    inv[1] = fac[0] = fac[1] = finv[0] = finv[1] = 1;
    for (int i = 2; i <= MAX_N; ++i) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fac[i] = fac[i - 1] * i % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long nPk(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

long long nCk(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return nPk(n, k) * finv[k] % MOD;
}

long long nHk(int n, int k) {
    if (n < 0 || k < 0) return 0;
    return nCk(n + k - 1, k);
}

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

    init();
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r2++; c2++;
    int ans = 0;
    (ans += nCk(r2 + c2, c2)) %= MOD;
    (ans += MOD - nCk(r2 + c1, c1)) %= MOD;
    (ans += MOD - nCk(r1 + c2, c2)) %= MOD;
    (ans += nCk(r1 + c1, c1)) %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
#define rint register int 
using namespace std;
inline int read(){
	rint sum=0;
	rint ch=getchar(),f=1;
	while(ch>'9'||ch<'0'){
		ch=getchar();
		if(ch=='-'){
			f=-1;
		}
	}
	while(ch<='9'&&ch>='0'){
		sum=(sum<<3)+(sum<<1)+ch-48,ch=getchar(); 
	}
	return sum*f;
}
int n,len;
string a[101];
int main(){
	n=read();
	len=read();
	for(rint i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(rint i=1;i<=n;i++){
		cout<<a[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long int
#define FF first
#define pb push_back
#define SS second
#define double long double

typedef long long ll;

using namespace std;


int a[500005],b[500005],c[500005];
int dp[500005][3];

signed main()
{
 // freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);
  
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];

  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  for(int i=1;i<n;i++)
  {
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
  return 0;
}

Measured memory_bytes: 14592
#include <algorithm>
#include <cstdio>
#include <vector>
#include <complex>
using namespace std;

//---------------------------------------------------------------
using P = complex<double>;
double dot(const P& a, const P& b) { return real(conj(a) * b); }
double cross(const P& a, const P& b) { return imag(conj(a) * b); }
//---------------------------------------------------------------

int main() {
    vector<P> ps;
    double x, y;
    while (~scanf("%lf,%lf", &x, &y)) {
        ps.emplace_back(x, y);
    }
    double sum = 0;
    P a = ps[0];
    for (int i = 0; i < ps.size() - 2; i++) {
        P b = ps[i + 1], c = ps[i + 2];
        sum += cross(b - a, c - a) / 2;
    }
    printf("%.6f\n", abs(sum));
    return 0;
}


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

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

  int n;
  ll m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> sums_mod(n+1);
  rep(i, n) {
    sums_mod[i+1] = (sums_mod[i] + a[i]) % m;
  }

  unordered_map<ll, int> mod_m;
  ll ans = 0; 
  for (int i = 0; i < sums_mod.size(); ++i) {
    ans += mod_m[sums_mod[i]];
    mod_m[sums_mod[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5260
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    
    int[] cnts = new int[n];

    for(int i = 0; i < n; i++){
      cnts[i] = 0;
    }
    
    int cal;
    int x, y, z;
    
    for(x = 1; x < 100; x++){
      for(y = 1; true; y++){
        for(z = 1; true; z++){
          cal = x * x + y * y + z * z + x * y + y * z + z * x;
          if(cal > n){break;}
          
          cnts[cal - 1]++;
        }
        
        if(z == 1){break;}
      }
      
      if(y == 1){break;}
    }
    
    for(int i = 0; i < n; i++){
      System.out.println(cnts[i]);
    }
    
  }
}

Measured memory_bytes: 39052
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(b+c,a))
    return

#B
def B():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2:
            ans += 1
    print(ans)
    return

#C
def C():
    n = II()
    h = LI()
    h = h[::-1]
    for i in range(1, n):
        if h[i] <= h[i-1]:
            continue
        if h[i] == h[i - 1] + 1:
            h[i] -= 1
            continue
        print("No")
        return
    print("Yes")
    return

#D
def D():
    s = S()
    lens = len(s)
    ans = [0] * len(s)
    i = 0
    while i != len(s):
        for j in range(i, lens):
            if s[j] == "R":
                continue
            break
        R = j - i
        for i in range(j, lens):
            if s[i] == "L":
                continue
            break
        else:
            i += 1
        L = i - j
        ans[j] = R // 2 + (L+1) // 2
        ans[j - 1] = L // 2 + (R+1) // 2

    print(*ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 39280
n = int(input())
lst = map(int,raw_input().split())
for i in range(len(lst)):
    v = lst[i]
    j = i - 1
    while j >= 0 and lst[j] > v:
        lst[j+1] = lst[j]
        j -= 1
    lst[j+1] = v
    print ' '.join(map(str, lst))

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

typedef int ll;

#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()

typedef pair<int,int>pii;
typedef pair<int,pair<int,int> > piii;

const int mod=1e9+7;

int POWER[65];
int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
int inv(int x) {return power(x,mod-2);}

void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}

const int maxn=855;
int sr=-1,sc=-1;
bool vis[maxn][maxn];
int h,w,k,dis=10000000000;
vector<string>v;

queue<int>xq,yq,le;
bool chk(int x , int y , int z) {
	if(x>=0 && x<h && y>=0 && y<w) {
		if(vis[x][y]==0 && v[x][y]!='#' && z<=k) {
			vis[x][y]=1;
			int d=min(min(x,h-x-1),min(y,w-y-1));
			dis=min(dis,d);
			if(z<=k) {
				xq.push(x);
				yq.push(y);
				le.push(z);
			}
			return 1;
		}
	}
	return 0;
}
void bfs(int i , int j) {
	chk(i,j,0);
	while (!xq.empty()) {
		int a=xq.front(),b=yq.front(),c=le.front();
		xq.pop(),yq.pop(),le.pop();
		chk(a-1,b,c+1);
		chk(a+1,b,c+1);
		chk(a,b-1,c+1);
		chk(a,b+1,c+1);
	}
}

ll main() {
	// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);

	std:ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w>>k;

	for (int i=0 ; i<h ; i++) {
		string s;
		cin>>s;

		v.pb(s);
	}

	for (int i=0 ; i<v.size() ; i++) {
		for (int j=0 ; j<v[i].size() ; j++) {
			if(v[i][j]=='S') {
				sr=i,sc=j;
			}
		}
	}

	bfs(sr,sc);

	assert(dis!=10000000000);
	int ans=dis/k+1;
	if(dis%k!=0)
		ans++;
	cout<<ans<<endl;

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll INF = 1e18;

int N;
int val[200005];
vector<int> G[200005];
int ret[200005];

ll dp[200005];

void dfs(int now, int parent){
  ll a = val[now];
  ll idx = lower_bound(dp, dp+N, a) - dp;
  ll prev = dp[idx];
  dp[idx] = a;
  ret[now] = lower_bound(dp, dp+N, INF) - dp;
  rep(i,G[now].size()){
    if(G[now][i] == parent) continue;
    dfs(G[now][i], now);
  }
  dp[idx] = prev;
}

int main(){
  cin >> N;

  rep(i,N){
    cin >> val[i];
  }
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep(i,200005) dp[i] = INF;

  dfs(0, -1);
  
  rep(i,N){
    cout << ret[i] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 32020
let print_array a =
  Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) a;
  print_newline ()

let insertion_sort a n =
  print_array a;
  let rec insert j v =
    if j < 0 || a.(j) <= v then a.(j+1) <- v
    else (a.(j+1) <- a.(j); insert (j - 1) v)
  and doit i =
    if i < n then (insert (i - 1) a.(i); print_array a; doit (i + 1))
  in doit 1

let () =
  let n = read_int () in
  let a = Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (read_line ()))) in
  insertion_sort a n

Measured memory_bytes: 4068
#include <iostream>

using namespace std;

int main(){
	int N, K;
	cin >> N >> K;
	bool flag[N] = {0};

	for (int i = 0; i < K; i++){
		int d;
		cin >> d;
		for(int j = 0; j < d; j++){
			int A;
			cin >> A;
			flag[A-1] = true;
		}
	}

	int ans = 0;
	for(int i = 0; i < N; i++){
		if(!flag[i]){
			ans++;
		}
	}

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


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

int main() {
    string s,t;cin>>s>>t;
    int n = s.size();
    int ans = 0;
    rep(i,n)if(s[i]!=t[i])++ans;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3900
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  
  ll ans = 1;
  vector<int> color(3, 0);
  rep(i, n) {
    int cnt = 0;
    bool det = false;
    rep(j, 3) {
      if (a[i] == color[j]) {
        cnt++;
        if (!det) {
          color[j]++;
          det = true;
        }
      }
    }
    ans = (ans * cnt) % mod;
  }
  cout << ans << endl;



  
  return 0;
}

Measured memory_bytes: 640
#include	<stdio.h>
int	main(void)
{
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/(double)b;
	printf("%d %d %lf",d,r,f);
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_not_found(void) {
	int x[140] = { 0 };
	string s;
	int num=0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		x[s[i]]++;
	}
	for (int i = 97; i < 97 + 26; i++) {
		if (x[i] == 0) {
			num = i;
			break;
		}
	}
	if (num == 0) cout << "None" << endl;
	else          printf("%c\n", num);

}

int main()
{
	b_not_found();
    return 0;
}

Measured memory_bytes: 3676
#include<cstdio>
#include<algorithm>
using namespace std;
int a[102000],n,b,c,d;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&a[i]);
		if(a[i]%4==0) b++;
		if(a[i]%2==0) c++;
		if(a[i]%2!=0) d++;
	}
	c=c-b;
	if(c==0)
	{
		if(d<=b+1) printf("Yes\n");
		else printf("No\n");
	}
	else
	{
		if(d<=b) printf("Yes\n");
		else printf("No\n");
	}
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;


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

    int l, r, d;
    cin >> l >> r >> d;
    cout << (r / d) - ((l - 1) / d) << el;    

    return 0;
}

Measured memory_bytes: 3660
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
good_ob = [1] * n
for _ in range(m):
    a, b = map(int, input().split())
    if h_list[a - 1] > h_list[b - 1]:
        good_ob[b - 1] = 0
    elif h_list[a - 1] < h_list[b - 1]:
        good_ob[a - 1] = 0
    else:
        good_ob[a - 1], good_ob[b - 1] = 0, 0
print(sum(good_ob))

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

int main() {
    int N;
    string S;
    cin >> N >> S;

    int ans = 1;
    char slime = S[0];
    for (int i = 0; i < N; i++) {
        if (S[i] != slime) {
            ans++;
            slime = S[i];
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  string S;
  lint pow3[100050],pow2[100050];
  pow3[0]=1,pow2[0]=1;
  rep(i,100049) pow3[i+1]=(pow3[i]*3)%MOD;
  rep(i,100049) pow2[i+1]=(pow2[i]*2)%MOD;
  cin >> S;
  int L=S.length();
  lint ans=(S[L-1]=='0')?1:3;
  for(int i=2;i<=L;i++) if(S[L-i]=='1') ans=(ans*2+pow3[i-1])%MOD;
  cout << ans << endl;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(i=0; i<n; i++)
 
int main(void)
{
	int i, n, k, d, min;
	scanf("%d%d", &k, &n);
	int a[n];
	rep(i,n) scanf("%d", &a[i]);
 
	min = a[n-1]-a[0];
	for(i=1; i<n; i++){
		d = k-(a[i]-a[i-1]);
		if(d<min){
			min = d;
		}
	}
	printf("%d", min);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n , m , d = 0;
    cin >> n >> m;
    ll x[n] , y[n] , z[n];
    repll(n) cin >> x[i] >> y[i] >> z[i];
    for( ll i = 0 ; i < n ; i++ ) {
    	ll a[1003] = {};
    	for( ll j = 0 ; j < n ; j++ ) {
    		if( i == 0 ) a[j] = x[j] + y[j] + z[j];
    		else if( i == 1 ) a[j] = x[j] + y[j] - z[j];
    		else if( i == 2 ) a[j] = x[j] - y[j] + z[j];
    		else if( i == 3 ) a[j] = x[j] - y[j] - z[j];
    		else if( i == 4 ) a[j] = -x[j] + y[j] + z[j];
    		else if( i == 5 ) a[j] = -x[j] + y[j] - z[j];
    		else if( i == 6 ) a[j] = -x[j] - y[j] + z[j];
    		else if( i == 7 ) a[j] = -x[j] - y[j] - z[j];
		}
		sort( a , a + n );
		reverse( a , a + n );
		ll c = 0;
		for( ll j = 0 ; j < m ; j++ ) c += a[j];
		d = max( d , c );
	}
	cout << d;
}


Measured memory_bytes: 3708
#include <stdio.h>
#include <string.h>
int main(){
  int n;
  char c[2];
  int r = 0, b = 0;

  scanf("%d", &n);

  for(int cnt = 0; cnt <= n; cnt++){
    scanf("%c", &c[0]);
    if(c[0] == 'R'){
      r++;
    }else if(c[0] == 'B'){
      b++;
    }
  }

  if(r > b){
    printf("Yes");
  }else{
    printf("No");
  }
  //  printf("%d%d", r, b);
  printf("\n");

}


Measured memory_bytes: 128
def main():
    c11, c12, c13 = map(int, input().split())
    c21, c22, c23 = map(int, input().split())
    c31, c32, c33 = map(int, input().split())

    r1max = max([c11, c12, c13])
    r2max = max([c21, c22, c23])
    r3max = max([c31, c32, c33])
    c1max = max([c11, c21, c31])
    c2max = max([c12, c22, c32])
    c3max = max([c13, c23, c33])
    for a1 in range(0, r1max + 1):
        for a2 in range(0, r2max + 1):
            for a3 in range(0, r3max + 1):
                m = max([a1, a2, a3])
                for b1 in range(0, c1max - m + 1):
                    C11 = a1 + b1
                    C21 = a2 + b1
                    C31 = a3 + b1
                    if C11 == c11 and C21 == c21 and C31 == c31:
                        for b2 in range(0, c2max - m + 1):
                            C12 = a1 + b2
                            C22 = a2 + b2
                            C32 = a3 + b2
                            if C12 == c12 and C22 == c22 and C32 == c32:
                                for b3 in range(0, c3max - m + 1):
                                    C13 = a1 + b3
                                    C23 = a2 + b3
                                    C33 = a3 + b3
                                    if C13 == c13 and C23 == c23 and C33 == c33:
                                        print('Yes')
                                        return

    print('No')
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064