akhauriyash/Code-Regression huggingface dataset:
import sys
import fractions

readline = sys.stdin.buffer.readline


def main():
    gcd = fractions.gcd

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

    N, M = map(int, readline().split())
    A = list(set(map(int, readline().split())))

    B = A[::]
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
        if semi_lcm > M:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 11968
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>

using namespace std;

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

    int count = 1;
    int d = 0;
    for(int i = 0 ; i < n ; i++){
        int L;
        cin >> L;
        d += L;
        if(d <= x){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}



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

int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    int k;
    if(a+b>n){
        k = a+b-n;
    }else{
        k = 0;
    }
    cout << min(a,b) << ' ' << k;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<char,char> mp;
int main(){
	mp['A']='T';
	mp['T']='A';
	mp['G']='C';
	mp['C']='G';
	char c;
	c=getchar();
	putchar(mp[c]);
	return 0;
} 

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll x;
  scanf("%lld", &x);

  ll total = 0;
  rep(i, 1, 1'000'000) {
    total += i;
    if (total >= x) {
      put(i);
      return 0;
    }
  }
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

s = input()
t = input()
if s == t:
    print('No')
    exit()
ss = sorted(s)
tt = sorted(t, reverse=True)
sss = ''.join(ss)
ttt = ''.join(tt)
if max(sss, ttt) == ttt:
    print('Yes')
else:
    print('No')


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

using namespace std;
int main() {
    string s; cin >> s;
    int K; cin >> K;
    set<string> st;
    for(int i = 0; i < s.size(); ++i){
        for(int j = 1; j <= 5; ++j){
            string str;
            for(int k = 0; k < j; ++k){
                if(i + k >= s.size()) continue;
                str += s[i + k];
            }
            st.insert(str);
        }
    }
    auto itr = st.begin();
    for(int i = 0; i < K - 1; ++i) {
        ++itr;
    }
    cout << *itr << "\n";
    return 0;

}

Measured memory_bytes: 1664
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())
b = list(myinput())
c = list(myinput())

a.sort()
b.sort()
c.sort()

# print(a)
# print(b)
# print(c)
# print("\n")

ls = [0]*n
for j in range(n):
    ind_a = bisect_left(a,b[j])
    ls[j] = ind_a
# print(ls)

ls_sum = [0]*n
s = 0
for i in range(n):
    s += ls[i]
    ls_sum[i] = s
# print(ls_sum)
     
count = 0
for k in range(n):
    ind_b = bisect_left(b,c[k])
    # print(k,ind_b)
    if ind_b==0:
        count += 0
    elif ind_b==n:
        count += ls_sum[-1]
    else:
        count += ls_sum[ind_b-1]
    # print(count)
print(count)

Measured memory_bytes: 107552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  int n, m;
  cin >> n >> m;
  
  int total = 0;
  for(int i = 1; i <= m; i++){
    int a;
    cin >> a;
    total += a;
  }
  
  if(n >= total) cout << n - total << endl;
  else cout << -1 << endl;
} 

Measured memory_bytes: 3636
#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) unique(v.begin(), 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> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int N;
ll a[401];

ll b[404];

void init() {
    b[0] = a[0];
    rep(i, 1, N) b[i] = b[i - 1] + a[i];
}

ll get(int l, int r) {
    ll rsl = b[r];
    if(l) rsl -= b[l - 1];
    return rsl;
}

ll memo[404][404];
int vis[404][404];

ll dp(int l, int r) {
    if(l == r) return 0;
    if(vis[l][r]) return memo[l][r];
    vis[l][r] = 1;

    ll rsl = INF;
    rep(i, l, r) chmin(rsl, dp(l, i) + dp(i + 1, r) + get(l, r));
    return memo[l][r] = rsl;
}

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

    cin >> N;
    rep(i, 0, N) cin >> a[i];
    init();
    cout << dp(0, N - 1) << endl;

}


Measured memory_bytes: 2176
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  string s;
  cin>>s;
  bool flag = true;
  if(s[0]!='A') flag=false;
 
  int counter=0;
  for(int i = 1; i<s.size(); i++){
    if(i>=2&&i<s.size()-1){
      if(s[i]=='C') counter++;
      else if('a'>s[i]||'z'<s[i]) {
      flag=false;
      }
    }
    else if('a'>s[i]||'z'<s[i]) {
      flag=false;
       
    }
  }
  if(counter!=1)flag=false;
  if(flag) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
  return 0;
}


Measured memory_bytes: 256
/**
 *  author: mahfuzz
 *  created: 10.04.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ':' << x << "\n"
typedef long long ll;


int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int n; cin >> n;
    vector<int> vec;
    
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        vec.push_back(x);
    }
    
    sort(all(vec));
    
    vector<int> stamina;
    for(int i = vec[0]; i <= vec[n-1]; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            int x = (vec[j] - i) * (vec[j] - i);
            sum += x;
        }
        
        stamina.push_back(sum);
    }
    
    sort(all(stamina));
    cout << stamina[0] << "\n";
        
    return 0;
}



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

long long gcd(long long y, long long x){
    return x ? gcd(x,y%x) : y;
}

int main(){
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i, n){
        cin >> a.at(i);
    }
    
    rep(i, n-1){
        a.at(i+1) = gcd(a.at(i), a.at(i+1));
    }
    
    cout << a.at(n-1) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define pii pair<int, int>

using namespace std;

ll const MOD = 998244353;
ll a[1000000], b[1000000], sum, q, mx, n;

int main()
{
    ios::sync_with_stdio(0);
    /*cin >> s;
    dp[0][s[0]]=1;
    for (int i=1; i<s.size(); i++)
    {
        dp[i][s[i]]=(dp[i-1]['a']+dp[i-1]['b']+dp[i-1]['c'])%MOD;
        if (s[i]=='a')
        {
            dp[i]['b']=dp[i-1]['c'];
            dp[i]['c']=dp[i-1]['b'];
        }
        if (s[i]=='b')
        {
            dp[i]['a']=dp[i-1]['c'];
            dp[i]['c']=dp[i-1]['a'];
        }
        if (s[i]=='c')
        {
            dp[i]['b']=dp[i-1]['a'];
            dp[i]['a']=dp[i-1]['b'];
        }
    }
    cout << (dp[s.size()-1]['a']+dp[s.size()-1]['b']+dp[s.size()-1]['c'])%MOD;*/
    cin >> n;
    mx = 1e10;
    for (int i=0; i<n; i++)
    {
        cin >> a[i] >> b[i];
        if (a[i]>b[i] && b[i]<mx)
        {
            mx=b[i];
            q=b[i];
        }
        sum+=a[i];
    }
    if (mx==1e10)
        cout << 0;
    else cout << sum-q;
    return 0;
}


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> acc(n + 1, 0), bcc(m + 1, 0);
	for (int i = 1;i <= n;i++) cin >> acc[i], acc[i] += acc[i - 1];
	for (int i = 1;i <= m;i++) cin >> bcc[i], bcc[i] += bcc[i - 1];
	int ans = 0;
	for (int i = 0, j = m;i <= n and j >= 0;) {
		if (acc[i] + bcc[j] > k) {
			j--;
		}
		else {
			ans = max(ans, i + j);
			i++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//

int main() {
    init();
    string s, t;
    cin >> s >> t;
    int ss = s.size(), ts = t.size();
    vvl dp(ss + 1, vl(ts + 1));
    rep(i, ss) rep(j, ts) {
        if (s[i] == t[j])
            dp[i + 1][j + 1] = dp[i][j] + 1;
        else
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
    }
    string ans = "";
    while (dp[ss][ts] != 0) {
        if (dp[ss][ts] == dp[ss - 1][ts])
            ss--;
        else if (dp[ss][ts] == dp[ss][ts - 1])
            ts--;
        else {
            ss--;
            ts--;
            ans += s[ss];
        }
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70784
#include<stdio.h>

long s = 0,t = 0;

long f(long x){
  if(x > 1){
    x /= 2;
    s++;
  }
  else{
    return s;
  }
  return f(x);
}

long jijo(int y){
  long ans = 1;
  for(int i = 0;i < y;i++){
    ans *= 2;
  }

  return ans;
}
 
int main(){
  long h,ans1;
  long ans2;
  
  scanf("%ld",&h);

  ans1 = f(h);
  ans2 = jijo(ans1 + 1) - 1;

  printf("%ld\n",ans2);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
 
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
 
const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;
 
ll N;

struct Comp {
	bool operator()(const l_l &a, const l_l &b) {
		return a.first > b.first;
	}
};
 
void solve() {
    cin >> N;
    vector<string> a(N);
    vector<l_l> adds, subs;
    
	int tlc = 0, trc = 0;
 
    for (int i = 0; i < N; i++) {
		int lc = 0, rc = 0;
		cin >> a[i];
		for (auto& c : a[i]) {
			if (c == '(') {
				lc++;
			} else {
				if (lc) lc--;
				else rc++;
			}
		}
		if (lc && !rc) tlc += lc;
		else if (!lc && rc) trc += rc;
		else if (lc && rc) {
			if (lc >= rc) adds.push_back({rc, lc});
			else subs.push_back({rc, lc});
		}
	}
	sort(adds.begin(), adds.end());
    sort(subs.begin(), subs.end(), Comp());
    
    bool pos = true;
    for (auto& i : adds) {
		if (i.first > tlc) {
			pos = false;
			break;
		} else {
			tlc -= i.first;
			tlc += i.second;
		}
	}
	
	for (auto& i : subs) {
		if (i.first > tlc) {
			pos = false;
			break;
		} else {
			tlc -= i.first;
			tlc += i.second;
		}
	}
    
    if (pos && tlc == trc) cout << "Yes";
    else cout << "No";
}
 
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}
 
/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 34308
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (int i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;
const ll num[4] = {-1, 0, 1, 0};

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> vec(h);
    rep(i, 0, h) cin >> vec[i];
    int ans = true;
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            if (vec[i][j] == '#')
            {
                bool flag = true;
                rep(k, 0, 4)
                {

                    if (i + num[k] >= 0 && i + num[k] < h && j + num[(k + 1) % 4] >= 0 && j + num[(k + 1) % 4] < w && vec[i + num[k]][j + num[(k + 1) % 4]] == '#')
                        flag = false;
                }
                if (flag)
                    ans = false;
            }
        }
    }
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
using namespace std;

int move_x[4] = {-1, 1, 0, 0};
int move_y[4] = {0, 0, -1, 1};
string s[50];
int dist[50][50];
int main(){
    int H;
    int W;
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        cin >> s[i];
    }

    int black_num = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#'){
                black_num ++;
            }
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dist[i][j] = -1;
        }
    }

    dist[0][0] = 0;
    queue <pair <int, int> > q;
    q.push(make_pair(0, 0));

    while(!q.empty()){
        bool end = false;
        auto cur = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            int next_x = cur.first + move_x[i];
            int next_y = cur.second + move_y[i];
            if(0 <= next_x && next_x < H && 0 <= next_y && next_y < W 
                && s[next_x][next_y] != '#' && dist[next_x][next_y] < 0){
                    dist[next_x][next_y] = dist[cur.first][cur.second] + 1;
                    if(next_x == H - 1 && next_y == W - 1){
                        break;
                        end = true;
                    }
                    q.push(make_pair(next_x, next_y));
                }
        }
        if(end){
            break;
        }
    }

    if(dist[H-1][W-1] < 0){
        cout << -1 << endl;
    } else {
        cout << H * W - black_num - dist[H-1][W-1] - 1<< endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  int cnt[110000];//i文字目までのacの数  0index
  cnt[0]=0;
  rep(i,0,n-1){//i=a i+1=c ならば1たす
    cnt[i+1]=cnt[i];
    if(s[i]=='A'&&s[i+1]=='C') cnt[i+1]++;
  }
  
  
  
  
  
  
  rep(werui,0,q){
    int l,r;
    cin>>l>>r;
    l--;r--;
    cout<<cnt[r]-cnt[l]<<endl;
  }
}









Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807

void warshallfloyd(vector< vector <ll> > &d)
{
for (int k = 0; k < d.size(); k++)
  for (int i = 0; i < d.size(); i++)
    for (int j = 0; j < d.size(); j++)
      d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main()
{
ll n;
ll m;
cin >> n >> m;
vector<vector<ll>> d(n, vector<ll>(n, INF));
rep(i, n) { d[i][i] = 0; }
rep(i, m)
{
  ll a, b, c;
  cin >> a >> b >> c;
  d[a][b] = c;
}
warshallfloyd(d);
rep(i, n) if (d[i][i] < 0)
{
  cout << "NEGATIVE CYCLE" << endl;
  return 0;
}
for (int i = 0; i < n; ++i)
{
  for (int j = 0; j < n; ++j)
  {
    if(j>0)cout << " " ;
    ll num = d[i][j];
    if (num <= INF / 2)
      cout << num ;
    else
      cout << "INF" ;
  }
  cout << endl;
}

return 0;
}



Measured memory_bytes: 3192
#include<iostream>
#include<vector>
#include<string>
#include <queue>
#include<map>
#include <cstring>

using namespace std;
#define _USE_MATH_DEFINES
# define M_PI 3.14159265358979323846
# define MOD 1000000007
#define ll long long int
#define pii pair<ll, ll>
#define pb push_back
#define MIN -9,223,372,036,854,775
#define N 100005
#define all(v) v.begin(),v.end()

void solve(){
    ll i,j,k,n,ans=-1,m,x,y,dx,dy;
    cin>>n>>m>>x>>y>>dx>>dy;
    char g[n][m];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>g[i][j];
    x--; y--; dx--; dy--;

    priority_queue<pair<ll, pii> , vector<pair<ll, pii> > , greater<pair<ll, pii> > > pq;
    pq.push({0,{x,y}});
    int vis[n][m];
    memset(vis, 0, sizeof(vis));

    ll r[]={1,-1,0,0};
    ll c[]={0,0,1,-1};

    while(!pq.empty()){
        ll d = pq.top().first;
        ll x = pq.top().second.first;
        ll y = pq.top().second.second;
        pq.pop();
        if(x<0 || y<0 || x>=n || y>=m)
            continue;
        if(vis[x][y])
            continue;
        //cout<<x<<" "<<y<<"\n";
        if(x==dx && y==dy){
            ans=d;
            break;
        }
        vis[x][y]=1;

        for(i=0;i<4;i++){
            if( x+r[i]<n && y+c[i]<m && x+r[i]>=0 && y+c[i]>=0 ){
                if( g[x+r[i]][y+c[i]] =='.' )
                    pq.push({d, { x+r[i], y+c[i] } } );
                }
            }
            for(j=-2;j<3;j++){
                for(k=-2;k<3;k++){
                    ll tx = x+j;
                    ll ty = y+k;
                    if( tx<n && ty<m && tx>=0 && ty>=0 ){
                        if(g[tx][ty]=='.')
                            pq.push({ d+1, {tx,ty} });
                        }
                }
            }
        }

    cout<<ans;
}

int main() {
    ll t=1;
	//cin>>t;
	while( t-- ){
	    solve();
	    cout<<"\n";
	}
	return 0;
}
/*

4 5
1 2
2 5
#.###
####.4 5
1 2
2 5
#.###
####.
#..##
#..##

#..##
#..##

*/


Measured memory_bytes: 13916
package main

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

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	var vs, cs []int
	for i := 0; i < n; i++ {
		vs = append(vs, nextInt(sc))
	}
	for i := 0; i < n; i++ {
		cs = append(cs, nextInt(sc))
	}
	var answer int
	for i := 0; i < n; i++ {
		if vs[i] > cs[i] {
			answer += vs[i] - cs[i]
		}
	}
	fmt.Println(answer)

}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

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

int main() {
    int N, D; cin >> N >> D;
    D = D * 2 + 1;
    cout << (N + D - 1) / D << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    String S = scanner.nextLine();
    int N = 0;
    for ( int i = 0; i < S.length(); i++ ) {
      if ( S.charAt(i) == '+') {
        N++;
      } else {
        N--;
      }
    }
    System.out.println(N);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
ll MOD = 10e9 + 7;

int main() {
    int yy,mm;
    bool yymm = false, mmyy = false;
    scanf("%2d%2d", &yy, &mm);
    if (0 <= yy  && 1 <= mm && mm <= 12) yymm = true;
    if (0 <= mm  && 1 <= yy && yy <= 12) mmyy = true;
    if (yymm && mmyy) OUT("AMBIGUOUS");
    else if(yymm) OUT("YYMM");
    else if(mmyy) OUT("MMYY");
    else OUT("NA");
    return 0;
}

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

using namespace std;


void solve(int n,int m){
	int dif,s1,s2,tmp,flag;
	vector<int>v1,v2;
	s1=0;
	s2=0;
	for(int i=0;i<n;i++){
		cin >>tmp;
		s1+=tmp;
		v1.push_back(tmp);
	}
	for(int i=0;i<m;i++){
		cin >> tmp;
		s2+=tmp;
		v2.push_back(tmp);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	dif=s1-s2;
	if(dif%2!=0){
		cout << -1 <<endl;
		return;
	}
	dif = dif/2;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(v1[i]==v2[j]+dif){
				cout << v1[i] << " " << v2[j] << endl;
				return;
			}
		}
	}
	cout << -1 <<endl;
	return ;		
}


int main(){
	int n,m;
	while(1){
		cin >> n >> m;
		if(n==0&&m==0)break;
		solve(n,m);
	}
	return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	int n,a;
	cin>>n>>a;
	if(n%500<=a){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
constexpr ll mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

using namespace std;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int a;
    cin>>a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var s = cin.next();

            var ans = 0;
            for (int i = 0; i < n-2; i++)
            {
                if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
            }

            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

int  main(){
  int count=0;
  string s;
  cin>>s;
  if(s[5]==1+'0'){
    count++;
  }
  if(s[6]>=5+'0'){
    count++;
  }
  
  if(count){
    cout<<"TBD"<<endl;
  }else{
    cout<<"Heisei"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int dp[1400][1401];

size_t get_largest_rectangle(vector<vector<int>> &g) {
    size_t h=g.size(), w=g[0].size();

    for (size_t i=0; i<h; ++i)
        for (size_t j=0; j<w; ++j)
            dp[i][j] = !g[i][j];

    for (size_t i=1; i<h; ++i)
        for (size_t j=0; j<w; ++j)
            if (dp[i][j])
                dp[i][j] += dp[i-1][j];

    size_t max_area=0;
    for (size_t i=0; i<h; ++i)
        for (size_t j=0; j<w; ++j) {
            if (!dp[i][j]) continue;

            int min_height=dp[i][j];
            for (size_t k=j+1; k<=w; ++k) {
                if (max_area < (k-j)*min_height)
                    max_area = (k-j)*min_height;

                if (!dp[i][k])
                    break;

                if (min_height > dp[i][k])
                    min_height = dp[i][k];
            }
        }

    return max_area;
}

int main() {
    size_t h, w;
    scanf("%zu %zu", &h, &w);

    vector<vector<int>> g(h, vector<int>(w));
    for (size_t i=0; i<h; ++i)
        for (size_t j=0; j<w; ++j)
            scanf("%d", &g[i][j]);

    printf("%zu\n", get_largest_rectangle(g));
    return 0;
}

Measured memory_bytes: 17756
#include<stdio.h>

int main()
{
   char s[3];

   scanf("%s", s);

   if((s[0] != s[1]) && (s[1] != s[2]) && (s[2] != s[0]))            
      printf("Yes\n");
   else {
      printf("No\n");
   }

   return 0;
}


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

vector<int> p,rank;

void makeSet(int x) {
    p.push_back(x);
    rank.push_back(0);
}

void link(int x, int y) {
    if(rank[x] > rank[y]) p[y] = x;
    else {
        p[x] = y;
        if(rank[x] == rank[y]) rank[y] = rank[y]+1;
    }
}

int findSet(int x) {
    if(x != p[x]) p[x] = findSet(p[x]);
    return p[x];
}

void unit(int x, int y) {
    link(findSet(x), findSet(y));
}

int main() {
    int n,q,com,x,y;
    cin >> n >> q;
    for(int i=0; i<n; i++) makeSet(i);
    for(int i=0; i<q; i++) {
        cin >> com >> x >> y;
        if(com == 0) unit(x,y);
        else {
            if(findSet(x) == findSet(y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3264
import sys
import heapq
INF = 1e20
n, k = [int(i) for i in sys.stdin.readline().split()]
ls = []
for i in range(n):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    ls.append((x, y))
ls.sort(key=lambda x:x[0])
x_ls, y_ls = zip(*ls)
best = INF

x_ls = sorted(list(x_ls))
y_ls = sorted(list(y_ls))
for left_ind in range(n - k + 1):
    left = x_ls[left_ind]
    for right_ind in range(left_ind + k - 1, n):
        right = x_ls[right_ind]
        for down_ind in range(n - k + 1):
            down = y_ls[down_ind]
            for up_ind in range(down_ind + k - 1, n):
                up = y_ls[up_ind]
                cnt = 0
                for i in range(n):
                    x, y = ls[i]
                    if left <= x <= right and up >= y >= down:
                        cnt += 1
                if cnt >= k:
                    best = min(best, (up - down) * (right - left))
print(max(1,best))

Measured memory_bytes: 47836
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 200000

using namespace std;

const ll mod = 1000000007;
ll v[maxn+5], s[maxn+5];

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  int i, j, z;
  for (i = 1; i <= n; i++) {
    cin >> v[i];
    s[i] = s[i-1] + v[i];
  }
  ll ans = 0;
  for (i = 1; i <= n; i++) {
    ans = (ans + (s[n]-s[i])%mod*v[i]%mod) % mod;
  }
  cout << ans;
  return 0;
}


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

#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0);
   int H,W;
   cin>>H>>W;
   if(H%3==0||W%3==0){
      cout<<0<<endl;
      return 0;
   }
   ull a_tate = (W/3)*H; 
   ull b_tate = (W/3+(W%3==2))*H;
   ull c_tate = (W/3+(W%3>=1))*H;
   ull ans = max(a_tate,max(b_tate,c_tate)) - min(a_tate,min(b_tate,c_tate));  
   ull a_yoko = (H/3)*W; 
   ull b_yoko = (H/3+(H%3==2))*W;
   ull c_yoko = (H/3+(H%3>=1))*W;
   ans = min( ans , max(a_yoko,max(b_yoko,c_yoko)) - min(a_yoko,min(b_yoko,c_yoko)));  
   for(ull i=1;i<H;i++){
      ull a=abs(max(i*W,max((H-i)*(W/2),(H-i)*(W/2+W%2))) - min(i*W,min((H-i)*(W/2),(H-i)*((W/2+W%2)))));
      ans = min(ans,a);
   }
   for(ull i=1;i<W;i++){
      ull a=abs(max(i*H,max((W-i)*(H/2),(W-i)*(H/2+H%2))) - min(i*H,min((W-i)*(H/2),(W-i)*((H/2+H%2)))));
      ans = min(ans,a);
   }
   cout << ans <<endl;
   return 0;
}


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

int main() {
    string n;
    cin >> n;
    ll k = n.size();
    ll sum = 0;
    for (int i = 0; i < k; i++) {
        sum += (ll)n[i] - 48;
    }
    if (sum % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////



int main() {
    
    ll n;cin>>n;
    ll a[n][3];rep(i,0,n-1)rep(j,0,2)cin>>a[i][j];
    if(a[0][2]==0){
        bool f=false;
        rep(i,1,n-1){
            if(a[i][2]!=0){
                rep(j,0,2){
                    swap(a[0][j],a[i][j]);
                }
                f=true;
                break;
            }
        }
        /*if(!f){
            bool x[105][105];memset(x,true,sizeof(x));
            rep(i,0,n-1){
                x[a[i][0]][a[i][1]]=false;
            }
            rep(ci,0,100)rep(cj,0,100){
                if(x[ci][cj]){
                    cout<<ci<<" "<<cj<<" "<<1<<endl;
                }
                return 0;
            }
        }*/
    }
    rep(ci,0,100){
        rep(cj,0,100){
            ll h=a[0][2]+abs(ci-a[0][0])+abs(cj-a[0][1]);
            bool flag=true;

            rep(i,1,n-1){
                if(a[i][2]==0){
                    if(a[i][2]+abs(ci-a[i][0])+abs(cj-a[i][1])<h){
                        flag=false;
                        break;
                    }
                }else if(h!=a[i][2]+abs(ci-a[i][0])+abs(cj-a[i][1])){
                    flag=false;
                    break;
                }
            }
            if(flag&&h>=1){
                cout<<ci<<" "<<cj<<" "<<h<<endl;
            }
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
  
struct point{
  ll x,y;
};
  
ll w,h,v,t,x,y,p,q;
ll R,H,W;
point o,O;
  
point calc(ll X,ll Y){
  ll dx=abs(X-O.x),dy=abs(Y-O.y);
  point res;
  
  if(dx%2==0)res.x=p;
  else res.x=w-p;
  
  if(dy%2==0)res.y=q;
  else res.y=h-q;
  
  res.x+=X*w;
  res.y+=Y*h;
  return res;
}
  
ll search(ll Y){
  ll l=0,r=W,m;
  while(l<r){
    m=(l+r)/2;
    point d=calc(m,Y);
    ll dist= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
    if( dist <= v*t*v*t  || o.x<= d.x ){
      r=m;
    }else{
      l=m+1;
    }
  }
  return l;
}
  
ll search2(ll Y){
  ll l=0,r=W,m;
  while(l<r){
    m=(l+r)/2;
    point d=calc(m,Y);
    ll dist= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
    if( dist <= v*t*v*t || d.x < o.x ){
      l=m+1;
    }else{
      r=m;
    }
  }
  return l;
}
  
int main(){
  cin>>w>>h>>v>>t>>x>>y>>p>>q;
  R=v*t;
  W=(v*t/w+2)*2;
  H=(v*t/h+2)*2;
  O.x=W/2;
  O.y=H/2;
  o.x=O.x*w+x;
  o.y=O.y*h+y;
  
  
  
  ll ans=0;
  for(ll i=0;i<=H;i++){
    ll a=search(i);
    ll b=search2(i);
    ans+=(b-a);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;

long long d() {
    long long x;
    
    return x;
}

int main() {
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        a.push_back(x);
    }
    long long res;
    long long modder1 = (1 + k) * k / 2 % mod;
    long long modder2 = (k - 1) * k / 2 % mod;
    for (int i = 0; i < n - 1; i++) {
        int x = 0;
        int y = 0;
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) x++;
            if (a[i] < a[j]) y++;
        }        
        res += modder1 * x;
        res %= mod;
        res += modder2 * y;
        res %= mod;
    }
    // cout << res << endl;
    // cout << ' ' << res << endl;
    cout << res << endl;
    return 0;
}


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

class Stack{
    public:
        vector<int> inner_vec;

        void push(int a){
            inner_vec.push_back(a);
        };

        int pop(){
            int last = inner_vec.back();
            inner_vec.pop_back();
            return last;
        }
};

int main(){
    char s[100];
    Stack stack;
    int a, b;
    while( scanf("%s", s) != EOF){
        if (s[0] == '-'){
            a = stack.pop();
            b = stack.pop();
            stack.push(b - a);
        }else if (s[0] == '+'){
            a = stack.pop();
            b = stack.pop();
            stack.push(a + b);
        }else if (s[0] ==  '*'){
            a = stack.pop();
            b = stack.pop();
            stack.push(a* b);
        }else{
            stack.push(stoi(s));
        }
    }

    printf("%d\n", stack.pop());

    return 0;
}


Measured memory_bytes: 3352
# frozen_string_literal: true

n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
MAX = 10**9 + 1

asum = [0]
bsum = [0]

n.times { |i| asum << asum.last + a[i] }
m.times { |i| bsum << bsum.last + b[i] }

i = 0
j = 0
ans = [0, 0]
asum.each do |as|
  break if as > k

  j = bsum.bsearch_index { |bs| as + bs > k }
  j ||= m + 1
  j -= 1 # bsearchでoverした分を引く
  ans = [i, j] if i + j > ans.sum
  i += 1
end

puts ans.sum


Measured memory_bytes: 50752
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
	//	String strInput = sc.nextLine();

		char chA ='a';
		char chA1 ='A';
		char[] arrayAlpha = new char[26];
		char[] arrayAlpha1 = new char[26];


		int[] arrayCount = new int[26];

		for(int i = 0; i <= ('z'-'a'); i++) {
			//System.out.println(chA++);
			arrayAlpha[i] = chA;
			arrayAlpha1[i] = chA1;

			chA1++;
			chA++;
		//	System.out.println("arrayAlpha[i]"+arrayAlpha[i]);
		}

		String strKarioki ="";
		char chKarioki1 =' ';

		while(sc.hasNext()) {

			String strInput = sc.nextLine();

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

				//??\?????????????????????????§£????????????
				strKarioki = strInput.substring(i,i+1);
				//String??????char??????????????????
				chKarioki1 = strKarioki.charAt(0);

				for(int j = 0; j <= ('z'-'a'); j++) {
					if(chKarioki1 == arrayAlpha[j] || chKarioki1 == arrayAlpha1[j]) {
						arrayCount[j] += 1;
					}
				}
			}
		}
		for(int j = 0; j <= ('z'-'a'); j++) {
			System.out.println(arrayAlpha[j] +" : "+arrayCount[j]);
		}
	}
}

Measured memory_bytes: 26276
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] a = new int[3][3];
		for(int i = 0 ; i < 3 ; i++) {
			for(int j = 0 ; j < 3 ; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int[] x = new int[3];
		int[] y = new int[3];
		x[0] = 0;
		for(int i = 0 ; i < 3 ; i++) {
			y[i] = a[0][i] - x[0];
		}
		for(int i = 0 ; i < 3 ; i++) {
			x[i] = a[i][0] - y[0];
		}
		boolean ok = true;
		for(int i = 0 ; i < 3 ; i++) {
			for(int j = 0 ; j < 3 ; j++) {
				if(a[i][j] != x[i] + y[j]) ok = false;
			}
		}
		if(ok) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];

int main(){
    int k,n,m,T;
    cin>>n>>m>>k;
    cout<<min(k,m/n)<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	long long int N;
	
	cin>>N;

	long long sq = (long long)ceil(sqrt(N));
	long long max_div = 1;
	for(int i=2; i<=sq; i++)
	{
		if(N % i == 0)
		{
			max_div = i;
		}
	}

	long long cp = N / max_div;

	cout<<cp+max_div-2<<endl;
}

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

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x - r >= 0 && x + r <= W&&y - r >= 0 && y + r <= H) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if((a==b&&b==c)||(a!=b && b!=c && c!=a))
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}



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

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define mod 1e9+7
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pp pop_back
#define bs binary_search
#define all(x) x.begin(),x.end()
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define test ll t ; cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {
	fast_io;
	
	ll a,b,x,ans=0;
	cin>>x;
	for(a=-1000;a<=1000;a++)
	{
	    for(b=-1000;b<=1000;b++)
	    {
	        if(pow(a,5)-pow(b,5)==x)
	        {
	            cout<<a<<" "<<b;
	            ans=1;
	            break;
	        }
	    }
	    if(ans)     break;
	}
	return 0;
}


Measured memory_bytes: 4024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		if(a + b > c + d) {
			System.out.println("Left");
		} else if(a + b == c + d) {
			System.out.println("Balanced");
		} else if(a + b < c + d) {
			System.out.println("Right");
		}
	}
}


Measured memory_bytes: 22100
m = 1000010
a = Array.new(m){[]}
(2...m).each{|i|
	if a[i].empty?
		j = i
		while j < m
			a[j] << i
			j += i
		end
	end
}
f = Array.new(m)
gets
d = 0
t = true
gets.split.map(&:to_i).each{|x|
	d = d.gcd(x)
	if t
		a[x].each{|y|
			t &&= !f[y]
			f[y] = true
		}
	end
}

puts (t ? "pairwise coprime" : d == 1 ? "setwise coprime" : "not coprime")


Measured memory_bytes: 197984