akhauriyash/Code-Regression huggingface dataset:
cursor = 0
n = int(input())

class LinkedList():
    class Cell():
        def __init__(self,val,pre,post):
            self.val = val
            self.pre = pre
            self.post = post

    def __init__(self):
        self.cursor = LinkedList.Cell(None,None,None)
        
    def insert(self,val):
        temp = self.cursor
        self.cursor = LinkedList.Cell(val,temp.pre,temp)
        if temp.pre != None:
            temp.pre.post = self.cursor
        temp.pre = self.cursor
        
        
            

    def move(self,d):
        if d > 0:
            for i in range(d):
                self.cursor = self.cursor.post
                
        else:
            
            for i in range(-d):
                
                self.cursor = self.cursor.pre
            
    def remove(self):
        temp = self.cursor
        tpos = temp.post
        
        if temp.pre != None:
            tpre = temp.pre
            tpre.post = tpos
            tpos.pre = tpre
        else:
            tpos.pre = None
        del temp
        self.cursor = tpos
        
    def moveToTop(self):
        while self.cursor.pre != None:
            self.cursor = self.cursor.pre

linkedList = LinkedList()

for i in range(n):
    a = [int(j) for j in input().split()]
    if a[0] == 0:
        linkedList.insert(a[1])
    elif a[0] == 1:
        linkedList.move(a[1])
    elif a[0] == 2:
        linkedList.remove()

linkedList.moveToTop()
print(linkedList.cursor.val)
while linkedList.cursor.post.val != None:
    linkedList.cursor = linkedList.cursor.post
    print(linkedList.cursor.val)



Measured memory_bytes: 89088
def solve(n, k, s):
    if s < 10 ** 9:
        res_list = [s] * k + [s + 1] * (n - k)
    else:
        res_list = [s] * k + [s - 1] * (n - k)
    res = " ".join([str(a) for a in res_list])
    return res


def main():
    n, k, s = map(int, input().split())
    res = solve(n, k, s)
    print(res)


def test():
    assert solve(4, 2, 3) == "3 3 4 4"
    assert solve(5, 3, 100) == "100 100 100 101 101"
    assert solve(5, 3, 1) == "1 1 1 2 2"


if __name__ == "__main__":
    test()
    main()


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

const int SIZE=2010;

int L[SIZE][SIZE],R[SIZE][SIZE];
int U[SIZE][SIZE],D[SIZE][SIZE];

signed main()
{
    int H,W; cin>>H>>W;
    vector<string> s(H);
    for(int i=0;i<H;i++){
	cin>>s[i];
    }

    for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	    if(s[i][j]=='#'){
		L[i][j]=R[i][j]=U[i][j]=D[i][j]=-1;
	    }
	}
    }

    for(int i=0;i<H;i++){
	for(int j=1;j<W;j++){
	    if(s[i][j]=='#') continue;
	    L[i][j]=L[i][j-1]+1;
	}
    }
/*
    for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	    cout<<L[i][j]<<' ';
	}
	cout<<endl;
    }
*/
    for(int i=0;i<H;i++){
	for(int j=W-2;j>=0;j--){
	    if(s[i][j]=='#') continue;
	    R[i][j]=R[i][j+1]+1;
	}
    }
    for(int i=1;i<H;i++){
	for(int j=0;j<W;j++){
	    if(s[i][j]=='#') continue;
	    U[i][j]=U[i-1][j]+1;
	}
    }
    for(int i=H-2;i>=0;i--){
	for(int j=0;j<W;j++){
	    if(s[i][j]=='#') continue;
	    D[i][j]=D[i+1][j]+1;
	}
    }
    int ans=0;
    for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	    if(s[i][j]=='#') continue;
	    ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]+1);
	}
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 130432
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{␣"; for(auto nth : list){ cout << nth << "␣"; } cout << "}" << endl;

using namespace std;

int main() {
    int N, A, B;
    string S;

    cin >> N >> A >> B;
    cin >> S;

    int accepted = 0;
    int global_rank = 0;
    for (int nth = 0; nth < S.size(); ++nth) {
        char type = S[nth];

        if (type == 'a') {
            if (accepted < A+B) {
                accepted += 1;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
        else if (type == 'b') {
            global_rank += 1;
            if (accepted < A+B && global_rank <= B) {
                accepted += 1;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}


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

int main(){
    int a,b;
    while (1){
        cin >>a>>b;
        if (a==0&&b==0)break;
        if (a>b){
          cout<<b<<" "<<a<<endl;
        }else{
          cout<<a<<" "<<b<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string ans = "Yes";
    for (int i = 0; i < n; i++) {
        if (i % 2) {
            if (s.at(i) == 'R') {
                ans = "No";
                break;
            }
        } else {
            if (s.at(i) == 'L') {
                ans = "No";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using namespace rel_ops;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

int n;
int maxw;
int wt[110];
int val[110];
int offset;
int memo[100][500][100];

int f(int i, int w, int num) {
    if (i == n or w + offset * num > maxw)
        return 0;
    int& ret = memo[i][w][num];
    if (ret != -1)
        return ret;
    int a = f(i + 1, w, num);
    int b = 0;
    if (w + wt[i] + offset * (num + 1) <= maxw)
        b = val[i] + f(i + 1, w + wt[i], num + 1);
    return ret = max(a, b);
}

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> maxw;
    cin >> wt[0] >> val[0];
    offset = wt[0];
    wt[0] = 0;
    for (int i = 1; i < n; i++) {
        cin >> wt[i] >> val[i];
        wt[i] -= offset;
    }
    memset(memo, -1, sizeof memo);
    cout << f(0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 19840
/**
 * ???????????£??????????????? 3?¬?????????????
 */

// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

//constexpr ll INF = 1LL << 32;
constexpr int INF = numeric_limits<int>::max();

int V;
int E;
//vector<vector<vector<ll>>> dp;
vector<vector<vector<int>>> dp;

void warshallfloyd()
{
    FOR(k, 0, V) {
        REP(i, V) {
            REP(j, V) {
                if(dp[k][i][k] == INF || dp[k][k][j] == INF) {
                    dp[k+1][i][j] = dp[k][i][j];
                }
                else {
                    dp[k+1][i][j] = min(dp[k][i][j], dp[k][i][k] + dp[k][k][j]);
                }
            }
        }
    }
}

void solve()
{
    warshallfloyd();

    bool ok = true;
    REP(v, V) {
        if(dp[V][v][v] < 0) ok = false;
    }

    if(!ok) {
        cout << "NEGATIVE CYCLE" << "\n";
    }
    else {
        REP(i, V) {
            REP(j, V) {
                //ll d = dp[V][i][j];
                int d = dp[V][i][j];
                if(d == INF) {
                    cout << "INF";
                }
                else {
                    cout << d;
                }
                cout << (j == V-1 ? "\n" : " ");
            }
        }
    }
}

int main()
{
    cin >> V >> E;
    dp.resize(V+1);
    for(auto& mat : dp) {
        mat.resize(V);
        for(auto& row : mat) {
            row.resize(V);
        }
    }

    REP(from, V) {
        REP(to, V) {
            dp[0][from][to] = (from == to ? 0 : INF);
        }
    }

    REP(_, E) {
        int s, t, d;
        cin >> s >> t >> d;
        dp[0][s][t] = d;
    }

    solve();

    return 0;
}

Measured memory_bytes: 6976
from collections import Counter

MOD = 2019
S = input()
S = tuple(map(int, reversed(S)))
counter = Counter()
digit = 1
cumsum = 0
ans = 0

for i in range(len(S)):
    counter[cumsum] += 1
    cumsum += (S[i] * digit) % MOD
    cumsum %= MOD
    ans += counter[cumsum]
    digit *= 10
    digit %= MOD

print(ans)


Measured memory_bytes: 11320
#include <stddef.h>
#include <iostream>
#include <map>
#include <string>
#include <utility>
using namespace std;
int main() {
  map<string, int> word;
  string s, s1 = "", s2 = "";
  int a = 0;
  size_t b = 0;
  while (cin >> s)
    word[s]++;
  for (auto e : word) {
    if (a < e.second) {
      s1 = e.first;
      a = e.second;
    }
    if (b < e.first.size()) {
      s2 = e.first;
      b = e.first.size();
    }
  }
  cout << s1 << ' ' << s2 << endl;
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int x; cin >> x;
    int ans = 1;
    for(int b = 2; b < x+1; b++){
        int power = b*b;
        while(1){
            if(x < power) break;
            ans = max(ans, power);
            power *= b;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,a[200001];
map<int,int> mp;

int main(){
    cin >> N;
    for(int i=1;i<N+1;i++) mp[i] = 0;
    for(int i=1;i<N;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) cout << itr->second << endl;
    return 0;
}


Measured memory_bytes: 13796
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

priority_queue<int> S;

int main()
{
  for(int i = 0;i < 5;i++){
    int x;
    cin >>x;
    S.push(x);
  }
  for(int i = 0;i < 5;i++){
    cout <<S.top();
    S.pop();
    if(i !=4)
      cout <<" ";
    else
      cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int h = cin.ReadInt;
            int w = cin.ReadInt;

            Console.WriteLine((n - h + 1) * (n - w + 1));
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


vector<int> argsort(const vector<pair<string,int>> &v) {
      vector<int> index(v.size());
      iota(index.begin(), index.end(), 0);
      sort(index.begin(), index.end(),[&v](size_t i1, size_t i2) {
          if(v[i1].first == v[i2].first){
              return v[i1].second > v[i2].second;
          }else{
              return v[i1].first < v[i2].first;
          }

      });
      return index;
}

int main(){
    ll n;
    cin >> n;
    vector<pair<string, int>> sp(n);
    for(int i = 0; i < n; i++){
        cin >> sp[i].first >> sp[i].second;
    }
    vector<int> ans = argsort(sp);

    for(int i = 0; i < n; i++){
        cout << ans[i]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e: a) cin >> e;

    map<int, int> m;
    for (auto e: a) m[e]++;

    bool ans = false;
    if (m.size() == 1 && m.count(0)) ans = true;
    else if (n%3 == 0) {
        if (m.size() == 2) {
            if (m[0] == n/3) ans = true;
        } else if (m.size() == 3) {
            int t = 0;
            bool f = true;
            for (auto p: m) {
                t ^= p.first;
                if (p.second != n/3) f = false;
            }
            if (t == 0 && f) ans = true;
        }
    }
    
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
                first = false;
            }
            cout << x;
        }
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();
    out << ((N % 2) ? (N / 2 + 1) / static_cast<double>(N) : 0.5);

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
    const int N=(int)4e5+100;
    const int inf=(int)1e9+100;
#define filename ""

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,i;
    string s;
    cin>>n>>s;
    int ans=0;
    fo(i,n-2)
    {
        if (s.substr(i,3)=="ABC") ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int n,w;
  std::cin >> n >> w;
  long long * dp = new long long[w+1];
  long long * dpn = new long long[w+1];
  for (int i=0; i<=w; i++){
    dp[i] = 0;
    dpn[i] = 0;
  }
  
  long long nw;
  long long nv;

  for(int i=0; i<n; i++){
    std::cin >> nw >> nv;
    for(int j=0;j<=w;j++){
      dpn[j] = dp[j];
      if (j >= nw)
        dpn[j] = std::max(dpn[j], dp[j-nw]+nv);
    }
    for(int j=0;j<=w;j++)
      dp[j] = dpn[j];
  }
  std::cout << dp[w] << std::endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
using namespace std;
int main ()
{
    long long a,b,k;
    scanf("%lld%lld%lld",&a,&b,&k);
    if(k>=a)
	{
		k=k-a;
		a=0;
		if(k>=b)
		{

			k=k-b;
			b=0;
			printf("%lld %lld",a,b);
			return 0;
		}
		else
		{
			printf("%lld %lld",a,b-k);
			return 0;
		}
	}
	else
	{
		a=a-k;
		printf("%lld %lld",a,b);
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += (math.factorial(a[i])//(math.factorial(a[i]-2)*2))
print(count)

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

#define upper_point(dim, p, q) ((dim) ? (p)->y >= (q)->y: (p)->x >= (q)->x)

typedef struct _point point;
struct _point {
    int id;
    int x;
    int y;
};

typedef struct _kdt_node kdt_node;
struct _kdt_node {
    point p;
    kdt_node *left, *right;
};


static kdt_node *nodes;
static int node_index;
static int tree_size;

void kdt_init(int size) {
    node_index = 0;
    tree_size = size;
    nodes = (kdt_node *)malloc(sizeof(kdt_node) * size);
    // return nodes;
}

void kdt_destruct() {
    free(nodes);
}

kdt_node *new_node() {
    return &(nodes[node_index++]);
}

int cmp_x(const void *a, const void *b) {
    int ax, bx;
    ax = ((point *)a)->x;
    bx = ((point *)b)->x;
    if (ax < bx) {
        return -1;
    }
    else if (ax == bx) {
        return 0;
    }
    return 1;
}

int cmp_y(const void *a, const void *b) {
    int ay, by;
    ay = ((point *)a)->y;
    by = ((point *)b)->y;
    if (ay < by) {
        return -1;
    }
    else if (ay == by) {
        return 0;
    }
    return 1;
}

int cmp_int(const void *a, const void *b) {
    int ia, ib;
    ia = *(int *)a;
    ib = *(int *)b;
    if (ia < ib) {
        return -1;
    }
    else if (ia == ib) {
        return 0;
    }
    return 1;
}

kdt_node *build_tree(point *ps, int len, int depth) {
    int med_idx;
    if (len < 1) return NULL;

    qsort((void *)ps, len, sizeof(point), depth%2 ? cmp_y: cmp_x);
    med_idx = len / 2;

    kdt_node *node = new_node();
    node->p = ps[med_idx];
    node->left = build_tree(ps, med_idx, depth+1);
    node->right = build_tree(&(ps[med_idx+1]), len-med_idx-1, depth+1);
    return node;
}

void points_in_range(kdt_node *node, int dim, point *bl, point *tr, int *pid, int *pcnt) {
    if (node == NULL) return;
    point *p = &(node->p);
    if (p->x >= bl->x && p->x <= tr->x &&
        p->y >= bl->y && p->y <= tr->y) {
        *(pid+*pcnt) = p->id;
        (*pcnt)++;
    }
    if (upper_point(dim, p, bl)) points_in_range(node->left, !dim, bl, tr, pid, pcnt);
    if (upper_point(dim, tr, p)) points_in_range(node->right, !dim, bl, tr, pid, pcnt);
}

int main() {
    int i, n, q, x, y;
    point *ps, *p;
    kdt_node *tree;
    point bl, tr;
    int *pid;
    int pcnt;

    scanf("%d", &n);
    ps = (point *)malloc(sizeof(point) * n);
    pid = (int *)malloc(sizeof(int) * n);
    kdt_init(n);

    for (i = 0; i < n; i++) {
        p = &(ps[i]);
        scanf("%d %d", &x, &y);
        p->id = i;
        p->x = x;
        p->y = y;
    }
    tree = build_tree(ps, n, 0);

    scanf("%d", &q);
    while (q--) {
        scanf("%d %d %d %d", &(bl.x), &(tr.x), &(bl.y), &(tr.y));
        pcnt = 0;
        points_in_range(tree, 0, &bl, &tr, pid, &pcnt);
        qsort((void *)pid, pcnt, sizeof(int), cmp_int);
        for (i = 0; i < pcnt; i++) {
            printf("%d\n", pid[i]);
        }
        printf("\n");
    }
    

    kdt_destruct();

    return 0;
}

Measured memory_bytes: 24276
/*input
3
011
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int cnt[maxn];
int ans[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    REP1(i,maxn-1){
        int x=i;
        while(x){
            x%=__builtin_popcount(x);
            cnt[i]++;
        }
    }
    int n;
    cin>>n;
    string s;
    cin>>s;
    reverse(ALL(s));
    int one=0;
    REP(i,sz(s)) if(s[i]=='1') ++one;
    if(one==1){
        REP(i,sz(s)){
            if(s[i]=='1') ans[i]=0;
        }
        ll sum=0;
        MOD=one+1;
        REP(i,sz(s)){
            if(s[i]=='1'){
                sum+=mypow(2,i);
                sum%=MOD;
            }
        }
        REP(i,sz(s)){
            if(s[i]=='0'){
                ans[i]=cnt[(sum+mypow(2,i))%MOD]+1;
            }
        }
    }
    else if(one==0){
        REP(i,sz(s)){
            ans[i]=1;
        }
    }
    else{
        ll sum=0;
        MOD=one-1;
        REP(i,sz(s)){
            if(s[i]=='1'){
                sum+=mypow(2,i);
                sum%=MOD;
            }
        }
        REP(i,sz(s)){
            if(s[i]=='1'){
                ans[i]=cnt[(sum-mypow(2,i)+MOD)%MOD]+1;
            }
        }
        MOD=one+1;
        sum=0;
        REP(i,sz(s)){
            if(s[i]=='1'){
                sum+=mypow(2,i);
                sum%=MOD;
            }
        }
        REP(i,sz(s)){
            if(s[i]=='0'){
                ans[i]=cnt[(sum+mypow(2,i))%MOD]+1;
            }
        }
    }
    REP(i,sz(s)) cout<<ans[sz(s)-i-1]<<'\n';
}

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

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

   int x, n;
   cin >> x >> n;

   vector<int> a(101);
   for(int i = 0; i < n; i++){
       int x;
       cin >> x;
       a[x] = 1;
   }

   int mini = 10000;
   int ans = mini;

   for(int i = -100; i <= 110; i++){
       if(i < 0 ) {
           if(abs(i - x) < mini) {
               mini = abs(i-x);
               ans = i;
           }
       } else if (a[i] == 0){
           if(abs(i - x) < mini) {
               mini = abs(i-x);
               ans = i;
           }
       }
   }

   cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3600
A, B, C, D = [int(s) for s in input().split(' ')]

def gcd(a, b):
    if (a < b):
        return gcd(b, a)
    if (b == 0):
        return a
    return gcd(b, a % b)

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

def counter(division):
    a = A // division
    if A % division == 0:
        a -= 1
    b = B // division
    return b - a

c = counter(C)
d = counter(D)
cd = counter(lcm(C , D))
ret = B - A + 1 - c - d + cd
print(ret)



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int h, n;
  cin >> h >> n;
  int a[n], b[n];
  rep(i, 0, n) cin >> a[i] >> b[i];

  int dp[n + 1][h + 1];
  rep(i, 0, n + 1) rep(j, 0, h + 1) dp[i][j] = 1<<29;
  dp[0][0] = 0;

  rep(i, 0, n) {
    rep(j, 0, h + 1) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      dp[i + 1][min(h, j + a[i])] = min(dp[i + 1][min(h, j + a[i])], dp[i + 1][j] + b[i]);
    }
  }
  cout << dp[n][h] << endl;
}


Measured memory_bytes: 39424
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

struct LowLink {
private:
    vector< vector< int > > G;
    int V; // 頂点数
    vector< int > used, ord, low;

    int dfs(int idx, int k, int par) {
        used[idx] = true;
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_articulation = false;
        int cnt = 0;
        for (auto &to : G[idx]) {
            if (!used[to]) {
                ++cnt;
                k = dfs(to, k, idx);
                low[idx] = min(low[idx], low[to]);
                is_articulation |= ~par && low[to] >= ord[idx];
                if (ord[idx] < low[to]) bridge.push_back(minmax(idx, (int)to));
            }
            else if (to != par) {
                low[idx] = min(low[idx], ord[to]);
            }
        }
        is_articulation |= par == -1 && cnt > 1;
        if (is_articulation) articulation.push_back(idx);
        return k;
    }

public:
    vector< int > articulation; // 関節点
    vector< pair< int, int > > bridge; // 橋

    LowLink(int V) : V(V) {
        G.resize(V);
    }

    // 無向辺を張る
    void add_edge(int v, int u) {
        G[v].push_back(u);
        G[u].push_back(v);
    }

    void build() {
        used.assign(V, 0);
        ord.assign(V, 0);
        low.assign(V, 0);
        int k = 0;
        for (int i = 0; i < V; i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
    }
};

int main() {
    int v, e; cin >> v >> e;
    LowLink G(v);
    REP(i, e) {
        int s, t; scanf("%d %d", &s, &t);
        G.add_edge(s, t);
    }
    G.build();
    sort(G.articulation.begin(), G.articulation.end());
    for (auto &a : G.articulation) {
        printf("%d\n", a);
    }
    return 0;
}


Measured memory_bytes: 4620
def main():
    box = int(input())
    target = [0] + list(map(int, input().split()))
    balls = [0] * (box + 1)
    put = []
    for i in range(box, 1, -1):
        if not sum(balls[i::i]) % 2 == target[i]:
            balls[i] = 1
            put.append(str(i))
    all_balls = sum(balls)
    if not all_balls % 2 == target[1]:
        put.append("1")
        all_balls += 1
    print(all_balls)
    print(" ".join(put))


if __name__ == '__main__':
    main()



Measured memory_bytes: 17212
#include<stdio.h>

#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX+1];
int temp;

void maxHeapify( int i ){
	int l , r , largest;
	l = 2 * i;
	r = 2 * i + 1;
	
	if( l <= H && A[l] > A[i] ) largest = l;
	else largest = i;
	if( r <= H && A[r] > A[largest] ) largest = r;
	
	if( largest != i ){
		temp = A[i];
		A[i] = A[largest];
		A[largest] = temp;
		maxHeapify(largest);
	}
}

int extract(){
	int maxv;
	if( H < 1 ) return -INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void increaseKey( int i , int key ){
	if( key < A[i] ) return;
	A[i] = key;
	
	while( i > 1 && A[i/2] < A[i] ){
		temp = A[i];
		A[i] = A[i/2];
		A[i/2] = temp;
		i = i / 2;
	}
}

void insert( int key ){
	H++;
	A[H] = -INFTY;
	increaseKey(H,key);
}

int main( void ){
	
	int key;
	char com[10];
	
	while(1){
		scanf( "%s" , com );
		
		if( com[0] == 'e' && com[1] == 'n' ) break;
		if( com[0] == 'i' ){
			scanf( "%d" , &key );
			insert(key);
		}else{
			printf( "%d\n" , extract() );
		}
	}
	
	return 0;
}


Measured memory_bytes: 5624
r, g, b, n = [int(i) for i in input().split()]
total = 0
rm = n//r
for rn in range(rm + 1):
	gm = (n - rn * r) // g
	for gn in range(gm + 1):
		bd = n - r * rn - g * gn
		if bd % b == 0:
			total += 1
print(total)

Measured memory_bytes: 3060
n=int(input())

nmax = 1000000000000001

def elc(idx):
    return( chr(ord('a') + idx ) )

lmt = [0]
lst = [1]
cur = 0
kw = 1
ans = []
while(1):
    if cur > nmax :
        break
    kw *= 26
    cur = cur + kw
    lmt.append(cur)
    lst.append(kw)

for i,el in enumerate(lmt):
    #print(i,el,lst[i])
    #continue
    if n > el:
        continue
    
    k = n - lmt[i-1] - 1
    #k = n - 1
    j = i - 1
    #print(k,lmt[i-1])
    while True:
        wkm = k % lst[j]
        wks = k // lst[j]
        #print('j:',j,'wks:',elc(wks))
        ans.append(elc(wks))
        if j == 0:
            #print(k,elc(wkm))
            #ans.append(elc(wkm))
            break
        else:
            k = wkm
        j -= 1
    break
print(''.join(ans))

Measured memory_bytes: 61920
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

flag_increase = 0
flag_decrease = 0
ans = 0
tmp = data[0]

for i in data:
    if tmp > i:
        flag_decrease = 1
        if flag_increase == 1:
            ans += 1
            flag_increase = 0
            flag_decrease = 0
        tmp = i
        
    if tmp < i:
        flag_increase = 1
        if flag_decrease == 1:
            ans += 1
            flag_decrease = 0
            flag_increase = 0
        tmp = i
        
    #print(i,ans,flag_increase,flag_decrease)
print(ans+1)   

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

int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	string s; cin >> s;
	ll ans = 0, bcnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B')
			bcnt++;
		else
			ans += bcnt;
	}
	cout << ans << endl;


	return 0;   
}  


Measured memory_bytes: 720
//Solution by Tima
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7; 

char s[N];
int n;

vector <int> v;

void no(){
	puts("-1");
	exit(0);
}

int main () {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if(s[n] == '1' || s[1] == '0') no();

	for(int i = 1; i <= n; i++){
		if(s[i] == '1' && s[n - i] != '1') no();
	}

	for(int i = 1; i <= n; i++){
		if(s[i] == '1') {
			v.pb(i);
		}
	}
	v.pb(n);
	int cur = 1;
	int root = 0;
	for(int i = 1; i < v.size(); i++){
	    int tmp = cur + 1;
	    int rs = v[i];
	    if(root){
	    	printf("%d %d\n", root, cur);
	    	rs -= v[i - 1];
	    }
	    cerr << rs << endl;
	    for(int j = 0; j < rs - 1; j++){
	        printf("%d %d\n", cur, tmp);
	        tmp++;
	    }
	    root = cur;
	    cur = tmp;
	}

return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
#define rei(i,a,n) for(int i=(a);i<(n);i++)
#define red(i,a,n) for(int i=(a)-1;i>=(n);i--)
#define rep(i,n) rei(i,0,n)
#define rem(i,n) red(i,n,0)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int msb(ll x)
{
    union{double a;int32_t b[2];};
    a=x;
    return (b[1]>>20)-1023;
}
int mx=(int)1e9+7;
void sol()
{
    int n;
    ll s=0,ans=0;
    cin>>n;
    vi a(n);
    rep(i,n)
    {
        cin>>a[i];
        ans+=s*a[i];
        ans%=mx;
        s+=a[i];
        s%=mx;
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)sol();
}


Measured memory_bytes: 3984
#if 0
2019.12.13

不妨设二元组 (x, y) 满足 x <= y 。

若最大值和最小值颜色不同，贪心构造，
对于剩下的每个 (x, y) ，把 x 放在最小值，y 放在最大值。

否则最大值和最小值颜色相同，那么该颜色的极值确定，需要最小化另一颜色的极值。
依然考虑贪心，在剩下的二元组中每次选出 x 最小的二元组，
如果 x 需要放在新颜色，那么剩下的二元组都把 x 放在新颜色。
否则 y 放在新颜色，更新新颜色的 min, max ，删掉该二元组继续考虑。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef std::pair<int, int> Par;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005;
Par p[maxn];

int main() {
	int n = read;

	for(int i = 1; i <= n; i ++) {
		read(p[i].first, p[i].second);
		if(p[i].first > p[i].second)
			std::swap(p[i].first, p[i].second);
	}

	std::sort(p + 1, p + n + 1);

	int max = 0, min = 1000000000;
	for(int i = 1; i <= n; i ++) {
		max = std::max(max, p[i].second);
		min = std::min(min, p[i].second);
	}

	ll ans = 1ll * (p[n].first - p[1].first) * (max - min);
	debug("%lld\n", ans);

	int mp = 2;
	for(int i = 3; i <= n; i ++)
		if(p[i].second > p[mp].second)
			mp = i;

	for(int i = mp; i >= 3; i --)
		std::swap(p[i], p[i - 1]);

	min = std::min(p[1].second, p[2].first);
	max = std::max(p[1].second, p[2].first);

	int rmin = 1000000000;
	for(int i = 3; i <= n; i ++) {
		rmin = std::min(rmin, std::max(max, p[n].first) - std::min(min, p[i].first));
		min = std::min(min, p[i].second);
		max = std::max(max, p[i].second);
	}
	rmin = std::min(rmin, max - min);

	ans = std::min(ans, 1ll * (p[2].second - p[1].first) * rmin);

	printf("%lld\n", ans);
}


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

const int mod = 998244353;

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) { return po(x, mod - 2); }

int fact[400010], invf[400010];

int comb(int n, int k) {
    return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}
int H(int n, int k) {
    return comb(n + k - 1, k);
}

int N, M;
string A, B, C, D;

vector<int> Col;
vector<int> Ldp, Rdp, Rpsum, pmul;

int solve() {
    Col.clear();
    for(int i = 0; i < M; i++) {
        if(C[i] == '1' && D[i] == '1') Col.push_back(3);
        else if(C[i] == '1') Col.push_back(1);
        else if(D[i] == '1') Col.push_back(2);
    }

    if(Col.size() == 0) return 0;

    int a = 0;
    for(int i = 0; i < N; i++) if(A[i] == '1') a++;
    int x = 0, y = 0;
    Ldp = vector<int>(Col.size(), 0);
    if(a) {
        for(int i = 0; i < Col.size(); i++) {
            if(x == 0 && y == 0) Ldp[i] = 1;
            else Ldp[i] = H(x + y + 1, a - 1);
            if(Col[i] & 1) x++;
            if(Col[i] & 2) y++;
        }
    }
    else Ldp[0] = 1;

    a = 0;
    for(int i = 0; i < N; i++) if(B[i] == '1') a++;
    x = 0, y = 0;
    Rdp = vector<int>(Col.size(), 0);
    if(a) {
        for(int i = (int)Col.size() - 1; i >= 0; i--) {
            if(x == 0 && y == 0) Rdp[i] = 1;
            else Rdp[i] = H(x + y + 1, a - 1);
            if(Col[i] & 1) x++;
            if(Col[i] & 2) y++;
        }
    }
    else Rdp.back() = 1;

    pmul = vector<int>(Col.size());
    for(int i = 0; i < Col.size(); i++) {
        pmul[i] = (Col[i] == 3? 2 : 1);
        if(i) pmul[i] = 1LL * pmul[i] * pmul[i - 1] % mod;
    }

    Rpsum = vector<int>(Col.size());
    for(int i = (int)Col.size() - 1; i >= 0; i--) {
        Rpsum[i] = 1LL * Rdp[i] * pmul[i] % mod;
        if(i != (int)Col.size() - 1) {
            Rpsum[i] += Rpsum[i + 1];
            Rpsum[i] %= mod;
        }
    }

    int ret = 0;
    for(int i = 0; i < Col.size(); i++) {
        ret += 1LL * Ldp[i] * (Col[i] == 3? 2 : 1) % mod * (Rdp[i] + 1LL * (i == Col.size() - 1? 0 : Rpsum[i + 1]) * inv(pmul[i]) % mod) % mod;
        ret %= mod;
    }
    return ret;
}

int main() {
    fact[0] = 1;
    for(int i = 1; i < 400010; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < 400010; i++) {
        invf[i] = inv(fact[i]);
    }

    cin >> N >> M >> A >> B >> C >> D;

    int ans = 0;
    ans += solve();
    ans %= mod;
    swap(N, M);
    swap(A, C);
    swap(B, D);
    ans += solve();
    ans %= mod;

    if(ans == 0) ans = 1;
    cout << ans;
}


Measured memory_bytes: 6332
S = input()
count = 0
flag = False
if S[0] == "A":
    # print(S[2:-1]) #指定部分獲得できる
    tmp = S[2:-1]
    lower = S[1:]
    for i in range(len(tmp)):
        if tmp[i] == "C":
            count += 1
    if count == 1:
        tmpS = S.replace("A","a")
        tmpSS = tmpS.replace("C","c")
        if tmpSS.islower():
            flag = True

if flag:
    print("AC")
else:
    print("WA")
        
   

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

void primeFactor(ll val, map<ll,ll> &primeList){
  if(val<1){
    return;
  }
  for(int i=2;i*i<val;i++){
    while(val%i==0){
      primeList[i]++;
      val/=i;
    }
  }
  if(val!=1){
    primeList[val]=1;
  }
  return;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  string c;cin>>c;
  int cnt=0;
  for(int i=0;i<n;i++){
    if(c[i]=='R'){
      cnt++;
    }
  }
  int ans=0;
  for(int i=0;i<cnt;i++){
    if(c[i]=='W'){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {

  int A,B,C,X;
  cin >> A >> B >> C >> X;
  
  int s=0;
  for (int i=0; i<A+1; i++) {
    for (int j=0; j<B+1; j++) {
      for (int k=0; k<C+1; k++) {
        if (500*i+100*j+50*k==X) s++;
      }
    }
  }
  
  cout << s << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int l = Integer.parseInt(in[1]);

        int[] taste = new int[n];
        int sum = 0;
        int min = 1000000000;
        int ans = -1;
        for(int i = 0; i < n; i++) {
            taste[i] = l + i;
            sum += taste[i];
        }

        for(int i = 0; i < n; i++) {
            int tmp = Math.abs(taste[i]);
            if(tmp < min) {
                min = tmp;
                ans = i;
            }
        }

        System.out.println(sum - taste[ans]);
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 2000010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll powmod(ll a, ll b) {
    if (b == 0)
        return 1;
 
    ll k = powmod(a, b / 2);
    k = k * k % MOD;
    if (b & 1)
        k = k * a % MOD;
    return k;
}

int rev(int x) {
	return powmod(x, MOD - 2);
}

int f[MX];
int f1[MX];


int C(int n, int k) {
	if (k < 0 || k > n)
		return 0;
	return f[n] * f1[k] % MOD * f1[n - k] % MOD;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	
    f[0] = 1;
    fi(1, MX)
    	f[i] = f[i - 1] * i % MOD;
    f1[MX  - 1] = rev(f[MX - 1]);
    fi1(MX - 1, 0)
    	f1[i] = f1[i + 1] * (i + 1) % MOD;

    int res = 0;
   	int n;
   	cin >> n;
   	str s;
   	cin >> s;
   	int m = siz(s);
   	fi(m, m + n + 1) {
   		res += C(i - 1, m - 1) * powmod(25, i - m) % MOD * powmod(26, m + n - i);
   		res %= MOD;
   	}
   	cout << res << '\n';
}

Measured memory_bytes: 35540
package main

import (
	"fmt"
	"strconv"
)

func base(x, b int) string {
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	bs := ""
	for x > 0 {
		r := abs(x % b)
		bs = strconv.Itoa(r) + bs
		x -= r
		x /= b
	}
	if bs == "" {
		bs = "0"
	}
	return bs
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	fmt.Println(len(base(n, k)))
}


Measured memory_bytes: 512