akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n,0);
    rep(i,n)cin >> a[i];
    ll res = 0;
    rep(i,n){
        ll right = 0;
        ll all = 0;
        repp(j,i,n)if(a[i] > a[j])right++;
        rep(j,n)if(a[i] > a[j])all ++;
        res += right * k % MOD;
        res %= MOD;
        res += (k - 1) * k / 2 % MOD * all % MOD;
        res %= MOD;
    }
    cout << res  << endl;
    return 0;
}

Measured memory_bytes: 380
// agc015_a
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define FOR(i, a) for (auto i : a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define show1d(v)                                                              \
  rep(i, v.size()) cout << " " << v[i];                                        \
  cout << endl << endl;
#define show2d(v)                                                              \
  rep(i, v.size()) {                                                           \
    rep(j, v[i].size()) cout << " " << v[i][j];                                \
    cout << endl;                                                              \
  }                                                                            \
  cout << endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main(int argc, char *argv[]) {
  ll n, a, b, asum, bsum;
  cin >> n >> a >> b;

  if ((n == 1 && a != b) || a > b) {
    cout << 0 << endl;
    return 0;
  }

  if (n == 1 && a == b) {
    cout << 1 << endl;
    return 0;
  }

  asum = b;
  bsum = a;

  rep(i, n - 1) {
    asum += a;
    bsum += b;
  }

  cout << bsum - asum + 1 << endl;

  return 0;
}


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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    vector<int> a(3);
    for(int i=0; i<3; i++) cin >> a[i];
    sort(a.begin(), a.end());

    if(a[0] == 5 && a[1] == 5 && a[2] == 7) 
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 256
import bisect
n,x=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
S=[]
s=0
for i in range(n):
  s+=A[i]
  S.append(s)
k=bisect.bisect(S,x)
if k<n and x==S[k]:
  k+=1
if k==n and x!=S[-1]:
  k-=1
print(k)

Measured memory_bytes: 3064
import math
def f(x,y):
  s = 0
  for i in range(len(x)):
    s += (x[i]-y[i]) ** 2
  return math.sqrt(s)

n,d = map(int, input().split())
X = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    if f(X[i],X[j]) == math.floor(f(X[i],X[j])):
      ans += 1
 
print(ans)

Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

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

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		String S = sc.next();
		String ret = "";
		for (int i = 0; i < S.length(); i++) {
			char data = S.charAt(i);
			int alIndex = wordSearch(data);
			alIndex += N;
			if (alIndex >= 26) {
				alIndex -= 26;
			}
			ret += alphabet[alIndex];
		}
		System.out.println(ret);
	}

	public static int wordSearch(char c) {
		for (int i = 0; i < alphabet.length; i++) {
			if (c == alphabet[i]) {
				return i;
			}
		}
		return -1;
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 144852
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;


signed main() {
ll N,K;
//string ans;
cin >> N >> K;
vector<ll> A(N);
REP(i,N){
    cin >> A[i];
}
REP(i,N-K){
    if(A[i]<A[K+i]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}



return 0;
}


Measured memory_bytes: 4844
#include<iostream>
using namespace std;
int main() {
	int n, m, x, y;
	int a[105] = {0};
	cin>>n>>m;
	for (int i = 0; i < m; i++) {
		cin>>x;
		for (int j = 0; j < x; j++) {
			cin>>y;
			a[y] = 1;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) 
	if (!a[i]) cnt++;
	cout<<cnt;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<int> v(n);
    int sum = 0;
    rep(i, n){
        cin >> v[i];
        sum += v[i];
    }
    sort(all(v));
    bool flag = true;
    for(int i = 1; i <= m; i++){
        if(v[n - i] * 4 * m < sum){
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<<max(max(a*c,b*d),max(a*d,b*c))<<endl;
}

Measured memory_bytes: 3192
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,m;
    vpl check;
    vpl stud;
    ll x,y;

    cin >> n >> m;

    rp(i,n) {
        cin >> x >> y;
        stud.pb(mp(x,y));
    }
    rp(i,m){
        cin >> x >> y;
        check.pb(mp(x,y));
    }

    rp(i,n){
        ll ans;
        ll mn = INF;
        rpd(j,m){
            ll curD = abs(stud[i].f - check[j].f) + abs(stud[i].s - check[j].s);
            if(curD <= mn){
                mn = curD;
                ans = j+1;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	if (s[k-1] == 'A')
		s[k-1] = 'a';
	else if (s[k-1] == 'B')
		s[k-1] = 'b';
	else if (s[k-1] == 'C')
		s[k-1] = 'c';
	cout << s << endl;
}


Measured memory_bytes: 256
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import pprint
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v,depth):
    # ノードに訪れた
    visited[v] = 1
    if depth == 2:
        return
    for a, b in sides:
        if v == a-1:
            depth += 1
            dfs(b-1, depth)
            depth -= 1

n, m = MI()
sides = [LI() for _ in range(m)]
islands = [[0] * 2 for _ in range(n)]

for a, b in sides:
    if a-1 == 0:
        islands[b-1][0] = 1
    if b-1 == n-1:
        islands[a-1][1] = 1

for a, b in islands:
    if a == b == 1:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')


Measured memory_bytes: 62228
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <array>
#include <map>
#include <set>
using namespace std;

long long GetNumber(size_t A, size_t B, size_t C, size_t K){
    if (K%2==0) return A-B;
    else        return B-A;
}

int main()
{
    unsigned long long A, B, C, K;
    cin >> A >> B >> C >> K;
    auto n = GetNumber(A, B, C, K);
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;
	auto D = RD;

	writeln(max(min(B, D) - max(A, C), 0));
	stdout.flush();
	debug readln();
}

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

using namespace std;

int main(){
  int N; cin>>N;
  vector<int> v(N); 
  for(int i=0;i<N;i++) cin>>v[i];

  bool check=true;
  int ans=0,i=0; 
  while(check){
    if(v[i]%2==0){
      v[i]/=2; ans++;
    }
    else{
      i++;
    }
    if(i==N) check=false;
  }

  cout<<ans<<endl;

  return 0;
}



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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;

signed main(){
  int n;
  cin>>n;
  vint a(n),b(n);
  rep(i,n)cin>>a[i],b[i]=a[i];
  sort(all(b));
  rep(i,n){
    signed itr=lower_bound(all(b),a[i])-b.begin();
    if(itr<n/2)cout<<b[n/2]<<endl;
    else cout<<b[n/2-1]<<endl;
  }

  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define mp(x, y) make_pair((x), (y))
using namespace std;
using lint = long long;
using P = pair<int, int>;
using V = vector<int>;
constexpr int MOD = 1e9 + 7;

int A, B, C, F, H, I, J, K, L, M, N, S, T, U, W;
// lint A, B, F, H, I, J, K, L, M, N, S, T, U, W;
// string A, B;
// int ans;
// string ans;

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

	cin >> N;
	vector<set<int>> graph(N);
	vector<P> edges(N - 1);
	rep(i, N - 1) {
		cin >> F >> S;
		F--; S--;
		graph[F].insert(S);
		graph[S].insert(F);
		edges[i] = mp(min(F,S), max(S,F));
	}

	K = 0;
	rep(i, N) {
		K = max(K, (int)graph[i].size());
	}
	cout << K << endl;

	map<P, int> ans;
	vector<set<int>> colors(N);
	vector<bool> done(N, false);

	queue<int> q;
	q.push(0);
	while(!q.empty()) {
		int cur = q.front(); q.pop();
		done[cur] = true;
		int color = 0;
		for (auto nex : graph[cur]) {
			if (done[nex] == true) {
				continue;
			}
			q.push(nex);
			if (colors[cur].count(color) == 1) {
				color++;
			}
			colors[nex].insert(color);
			ans.insert(mp(mp(min(cur, nex), max(cur, nex)), color + 1));
			color++;
		}
	}

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

Measured memory_bytes: 30976
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
#define R(i) V[i]-V[i-1]
int n,q;
string s;
char V[200010][2];
bool judgeL(int x){
    rep(i,q){
        if(V[i][0]==s[x]){
            if(V[i][1]=='L')x--;
            else x++;
        }
        if(x==-1)return true;
        
    }
    return false;
}
bool judgeR(int x){
    rep(i,q){
        if(V[i][0]==s[x]){
            if(V[i][1]=='L')x--;
            else x++;
        }
        if(x==n)return true;
    }
    return false;
    
}
signed main() {
    cin>>n>>q>>s;
    rep(i,q)cin>>V[i][0]>>V[i][1];
    //二分探索
    int ans=0;
    int f=0,e=n;
    while(e>f){
        int x=(f+e)/2;
        if(judgeL(x))f=x+1;
        else e=x;
    }
    //cout<<f<<endl;
    ans+=f;
    f=0;e=n;
    while(e>f){
        int x=(f+e)/2;
        if(judgeR(x))e=x;
        else f=x+1;
    }
    //cout<<e<<endl;
    ans+=(n-e);
    cout<<n-ans<<endl;;
    
}

Measured memory_bytes: 900
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

L, R = [0]*(N+1), [0]*(N+1)
for i in range(1,N+1):
    L[i] = gcd(L[i-1], A[i-1])
    R[N-i] = gcd(R[N+1-i], A[N-i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))

print(ans)

Measured memory_bytes: 14080
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  long long T,N,cnt=0;
  long long prev,cur;
  cin>>N>>T;
  cin>>prev;
  if(N==1){
    cout<<T<<endl;
    return 0;
  }
  FOR(i,1,N){
    cin>>cur;
    cnt+=min(T,cur-prev);
    prev=cur;
  }
  cnt+=T;
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;

#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = 0;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return l+r;
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};
int main()
{
	string st;cin>>st;
	segtree seg(st.size());
	for (int i = 0; i < st.size(); ++i) {
		seg.update(i,1);
	}
	int N;cin>>N;
	int rest(N);
	
	string ans;
	vector<vector<int>>nums(26);
	for (int i = 0; i < st.size(); ++i) {
		char ch(st[i]);
		nums[ch-'a'].push_back(i);
	}
	vector<int>ks(26);
	for (int i = 0; i < st.size(); ++i) {
		for (int j = 0; j < 26; ++j) {
			if(nums[j].size()==ks[j])continue;
			else {
				int next=nums[j][ks[j]];
				int num=seg.query(0,next);
				if (rest >= num) {
					seg.update(next,0);
					rest-=num;
					ans.push_back('a'+j);
					ks[j]++;
					break;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
 int n;
 cin >> n;
 int ans = 0;
 bool flag = false;
 for(int i=0;i<101;i+=4){
     for(int j=0;j<101;j+=7){
         ans = i+j;
         if(ans==n) flag = true;
     }
 }
 if(flag) cout << "Yes" << endl;
 else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif



using namespace std;



ll knapSack(ll capacity, const ll weight[], ll value[], ll number){
    ll K[number+1][capacity+1];

    for (ll i = 0; i <= number; ++i) {
        for (ll j = 0; j <=capacity; ++j) {
            if(i==0 || j == 0)
                K[i][j] = 0;
            else if(weight[i-1] <= j)
                K[i][j] = max(value[i-1] + K[i-1][j-weight[i-1]], K[i-1][j]);
            else
                K[i][j] = K[i-1][j];


        }
    }



    return K[number][capacity];
}

int main()
{
    std::ios::sync_with_stdio(false);
    ll N, W;
    cin>>N>>W;
    ll weight[N];
    ll value[N];
    for (ll i = 0; i < N; ++i) {
        cin>>weight[i]>>value[i];
    }
    ll ans = knapSack(W, weight, value, N);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 79232
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	while (1) {
		int k, c, sum = 0;
		scanf("%d", &k);
		if (k == 0) break;
		for (int i = 0; i < k*(k-1) / 2; ++i) {
			scanf("%d", &c);
			sum += c;
		}
		printf("%d\n", sum /(k - 1));
	}
}

Measured memory_bytes: 2568
def solve():
  h,w = (int(i) for i in input().split())
  String = [input() for _ in range(h)]
  query = []
  for i in range(h):
    for j in range(w):
      if String[i][j] == "#":
        query.append((i,j))

  dx = [(-1,-1),(-1,0),(0,-1),(-1,1),(0,1),(1,-1),(1,0),(1,1)]
  newString = [[0]*w for _ in range(h)]
  while query:
    i,j = query.pop()
    for x,y in dx:
      nx = i+x
      ny = j+y
      if nx < 0 or ny < 0 or nx >= h or ny >= w:
        continue
      else:
        newString[nx][ny] += 1
  for i in range(h):
    for j in range(w):
      if not String[i][j] =="#":
        newString[i][j] = str(newString[i][j])
      else:
        newString[i][j] = "#"
  for i in range(h):
    print("".join(newString[i]))
solve()

Measured memory_bytes: 3188
package main

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

func main() {
	nextReader = newScanner()
	N := nextInt()
	S := nextString()
	ans := N
	for i := 0; i < N-1; i++ {
		if S[i] == S[i+1] {
			ans--
		}
	}
	fmt.Println(ans)
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 1024
#include  <iostream>
#include  <cstdlib>


int main(void)
{
	int a, b;

	std::cin >> a >> b;

	int x = -1, y = -1;

	if((4*a - b) >= 0 && (4*a - b) % 2 == 0)
		x = (4*a - b)/2;
	
	if((b - 2*a) >= 0 && (b - 2*a) % 2 == 0)
		y = (b - 2*a)/2;

	if(!(x == -1 || y == -1))
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;

	return EXIT_SUCCESS;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    vector<int > a(5);

    
    for(int i = 0;i<5;i++)
    {
        cin >> a[i];
    }

    int l=9;
    int m=0;
    int n=0;
    bool flag = true;
    for(int i = 0;i<5;i++)
    {
        if(((l%10) >= (a[i]%10)) && ((a[i]%10) != 0))
        {
            l = a[i];
            flag = false;
        }

        if(a[i]%10 == 0)
            n = a[i];
        else
            n = a[i] + 10 - (a[i]%10);
        
        m+=n;
    }
    
    if(flag == true)
    {
        cout << m << endl;
    }
    else
    {
        m+=(l%10);
        m -= 10;
        cout << m << endl;
    }

    return 0;    
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int A[100],N,i,num=0,minj,j,mikio;
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
      // if(j==N-1 && A[i]<A[minj]){
	
      }
mikio=A[i];
	A[i]=A[minj];
	A[minj]=mikio;
	if(i!=minj)	num++;
    }
  

  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[i],num);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 100000000000000
#define endl '\n'
ll power(ll a,ll b,ll m){ll ans=1;while(b){if(b&1) ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
ll arr[1000005];
bool str[1000005];
bool solve(ll n)
{
	for(ll i=2;i<=1000000;i++)
	{
		ll cnt=0;
		for(ll j=i;j<=1000000;j+=i)
		{
			if(str[j])
				cnt++;
		}
		if(cnt>1)
			return false;
	}
	return true;
}
int main()
{
	fastio;
	#ifdef gdb_18
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n;
	cin>>n;
	ll gx;
	memset(str,false,sizeof(str));
	for(ll i=1;i<=n;i++)
	{
		cin>>arr[i];
		str[arr[i]]=true;
		if(i==1)
			gx=arr[i];
		else
			gx=__gcd(gx,arr[i]);
	}
	if(gx==1 && solve(n))
		cout<<"pairwise coprime"<<endl;
	else if(gx==1)
		cout<<"setwise coprime"<<endl;
	else
		cout<<"not coprime"<<endl;
	return 0;	
}

Measured memory_bytes: 12364
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

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

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

func submit(n int, line string) int {
	W := make([]int, 0, n)
	for _, s := range strings.Split(line, " ") {
		w, _ := strconv.Atoi(s)
		W = append(W, w)
	}

	var i, r, l int
	j := n - 1
	for i <= j {
		if r < l {
			r += W[i]
			i++
		} else {
			l += W[j]
			j--
		}
	}

	return abs(r - l)
}

func main() {
	line := nextLine()
	n, _ := strconv.Atoi(line)
	line = nextLine()
	ans := submit(n, line)
	fmt.Println(ans)
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		//
		int all_number = 0;
		int answer = 0;
		String out_all = "";

		// テキスト入力クラス
		Scanner sc = new Scanner(System.in);

		//
		while (sc.hasNext()) {
			//
			all_number = sc.nextInt();
			answer = sc.nextInt();

			if (all_number == 0 && answer == 0)
				break;
			int out = 0;
			// 一つ目の数を選ぶ
			for (int f = 1; f <= all_number; f++) {
				// 二つ目の数を選ぶ
				for (int s = 1; s <= all_number; s++) {
					// 同じ数字は使えないので
					if (s != f) {
						// 三つの数を選ぶ
						for (int t = 1; t <= all_number; t++) {
							if (s != f && f != t && t != s
									&& s + f + t == answer) {
								// System.out.println(f+","+s+","+t);
								out = 1 + out;
							}
						}
					}
				}
			}
			// 組み合わせなので、3で割る
			out = out / 6;
			// 出力文字列
			out_all = out_all + "" + String.valueOf(out) + "\n";
		}
		// 出力
		System.out.print(out_all);
	}
}

Measured memory_bytes: 20064
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int x,n,p[101];
int main(){
	ios::sync_with_stdio(0);
	cin>>x>>n;
	rep(i,n)
	cin>>p[i];
	int ans=-1;
	sort(p,p+n);
	int now=0;
	rep(i,n){
		while(now<p[i]){
			if(abs(now-x)<abs(x-ans))
			ans=now;
			now++;
		}
		now++;
	}
	while(now<=x*2){
		if(abs(now-x)<abs(x-ans))
			ans=now;
		now++;
	}
	cout<<ans;
	re 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}


template<typename T>
struct Edge {
	int from, to;
	T cost;
	Edge () {}
	Edge (int from, int to, T cost ) : from(from), to(to), cost(cost) {}
	Edge (int to, T cost) : from(-1), to(to), cost(cost) {}
};

template<typename T>
vector<T> Dijkstra(int V, const vector<vector<Edge<T>>> &G, int s) {
	using Node = pair<T, int>;
	constexpr T INF = numeric_limits<T>::max();
	vector<T> d(V, INF);
	priority_queue<Node, vector<Node>, greater<Node>> pq;

	d[s] = 0;
	pq.emplace(0, s);
	while (!pq.empty()) {
		Node node = pq.top(); pq.pop();
		if (d[node.second] < node.first) continue;
		for (auto &e : G[node.second]) {
			T cost = e.cost + node.first;
			if (cost < d[e.to]) {
				d[e.to] = cost;
				pq.emplace(cost, e.to);
			}
		}
	}

	return (d);
}


double pdist(double x1, double y1, double x2, double y2) {
	return (sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
}

int main() {
	double sx, sy, tx, ty;	
	cin >> sx >> sy >> tx >> ty;
	int N; cin >> N;
	int V; V = N + 2;
	vector<double> X(V), Y(V), R(V);
	vector<vector<Edge<double>>>G(V);

	X[0] = sx, Y[0] = sy, R[0] = 0;
	X[N+1] = tx, Y[N+1] = ty, R[N+1] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> R[i];
	}
	
	for (int i = 0; i < V; i++) {
		for (int j = i + 1; j < V; j++) {
			double dist = max(0.0, pdist(X[i], Y[i], X[j], Y[j]) - R[i] - R[j]);
			G[i].emplace_back(j, dist);
			G[j].emplace_back(i, dist);
		}
	}
	vector<double> ans = Dijkstra(V, G, 0);
	
	cout << fixed << setprecision(10) << ans[N+1] << endl;

	return (0);
}

Measured memory_bytes: 22768
# 2020/02/15
# AtCoder Beginner Contest 097 - B

# Input
x = int(input())

expolist = list()

# Make list
for i in range(1, 32):
    for j in range(2, 10):
        expo = i ** j
        if expo > x:
            break
        else:
            expolist.append(expo)

# Output
print(max(expolist))


Measured memory_bytes: 2940
#include <iostream>
#include<cstdio>
#include<iomanip>
using namespace std;

int main(void) {
  int N;
  cin >> N;
  double in = 0;
  double bunbo = 0;
  for(int i = 0; i < N; i++) {
    cin >> in; 
    double tmp = (double)1/in;
    bunbo += (double)tmp;
  }
  std::cout<<std::fixed<<std::setprecision(5);
  cout << (double)1000/(bunbo*1000);
  
  return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("a") || s.equals("i") || s.equals("u") || s.equals("e") || s.equals("o")) {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }

    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll x, y;
  cin >> x >> y;
  if(x + y < 2)cout << "Brown" << endl;
  else if(abs(x-y) < 2) cout << "Brown" << endl;
  else cout << "Alice" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
'''
b = []

front = False
for i in a:
    if front:
        b.insert(0, i)
        front = False
    else:
        b.append(i)
        front = True




if front:
    b.reverse()


b = list(map(str, b))
b = " ".join(b)
print(b)
'''


first = a[0:n:2]
last = a[1:n:2]
last = last[::-1]
answer = last + first
if n%2 != 0:
    answer = answer[::-1]

print(*answer, sep=" ")

Measured memory_bytes: 30812
#include <bits/stdc++.h>
using namespace std;
typedef double D;

typedef complex<D> P;
typedef vector<P> Poly;
const D eps=1e-7;
typedef pair<P,P> Line;

#define mp make_pair

inline void x(P& p,D n){p.real(n);}
inline void y(P& p,D n){p.imag(n);}
inline D x(P& p){return p.real();}
inline D y(P& p){return p.imag();}

inline D dot(const P a,const P b){
    return a.real()*b.real()+a.imag()*b.imag();
}

inline D cross(const P a,const P b){
    return a.real()*b.imag()-a.imag()*b.real();
}

inline D distance(P p,Line l){
    auto a=l.first;
    auto b=l.second;
    auto c=p;
    if(dot(b-a,c-a)<-eps)return abs(c-a);
    if(dot(a-b,c-b)<-eps)return abs(c-b);
    return abs(cross(b-a,c-a))/abs(b-a);
}
const D INF=1e9;
int main() {
    cout<<fixed;
    cout<<setprecision(10);
    int N,M;D X,Y;
    cin>>N>>M>>X>>Y;
    Poly esa(N+1);
    x(esa[0],X);y(esa[0],Y);
    vector<D> dist(N+1,INF);
    vector<bool> used(N+1,false);
    used[0]=true;
        for(int i=1;i<=N;i++){
            D px,py;cin>>px>>py;
            x(esa[i],px);
            y(esa[i],py);
            dist[i]=abs(esa[0]-esa[i]);
        }

    D res=0;

    while(M--){
        D len=INF;int id=0;
        for(int i = 0; i <= N; i++)
            if(used[i]==false&&len-eps>dist[i]){
                len=dist[i];
                id=i;
            }
        //for(auto& it : dist)cout<<it<<" ";cout<<endl;
        len=INF;int jd=0;
        for(int i = 0; i <= N; i++)
            if(used[i]&&len-eps>abs(esa[id]-esa[i])){
                len=abs(esa[id]-esa[i]);
                jd=i;
            }
        used[id]=true;
        //cout<<id<<" "<<jd<<endl;
        Line l(esa[id],esa[jd]);
        res+=abs(esa[id]-esa[jd]);
        for(int i = 1; i <= N; i++)
            dist[i]=min(dist[i],distance(esa[i],l));
    }

    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3408
#include<bits/stdc++.h>
using namespace std;
int ac[100005];
char ch[100005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,q;
	string s;
	cin>>n>>q>>s;
	for(int i=0; s[i]; i++) ch[i+1] = s[i];
	for(int i=1; i<=n; i++){
		if(ch[i]=='A' && ch[i+1]=='C') ac[i]++;
	}
	for(int i=1; i<=n; i++) ac[i]+=ac[i-1];
	while(q--){
		int a,b;
		cin>>a>>b;
		int ret = ac[b]-ac[a-1];
		if(ch[b]=='A' && ch[b+1]=='C') ret--;
		cout<<ret<<'\n';
	}
}

Measured memory_bytes: 4256
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

int main (){
	tint n,c,k;
	cin>>n;
	tint a[n];
	tint su[n+1];
	su[0]=0;
	forn(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	forn(i,n){
		su[i+1]=a[i]+su[i];
	}
	int lo=-1;
	int hi=n-1;
	while(hi-lo>1){
		int mid=(lo+hi)/2;
		tint suma=su[mid+1];
		//cout<<lo<<"-"<<hi<<endl;
		//cout<<"pruebo mid "<<mid<<", "<<suma<<endl;
		bool vale=true;
		forsn(i, mid+1, n){
			if(2*suma>=a[i]){
				suma+=a[i];
			}else{
				//cout<<suma<<", "<<a[i]<<endl;
				vale=false;
			}
		}
		if(vale){
			hi=mid;
		}else{
			lo=mid;
		}
	}
	cout<<n-hi<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    string s;
    cin >> s;
    s.pop_back();
    s.pop_back();
    while (s.length() > 0)
    {
        int a = s.length() / 2;
        if (s.substr(0, a) == s.substr(a, a))
        {
            cout << s.length() << endl;
            return 0;
        }
        s.pop_back();
        s.pop_back();
    }
    cout << s.length() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main()
{
	float H;
	int size, sum = 0;
	cin >> H >> size;
	int *arrA;
	arrA = new int[size];
	for (int i = 0; i < size; i++)
	{
		cin >> arrA[i];
		sum += arrA[i];
	}
	if (sum>=H)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	/*if (Common_Raccoon(H, arrA, size,0, 0))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;*/

}


Measured memory_bytes: 640
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var S string
	scanner.Scan()
	S = scanner.Text()
	fmt.Println(solve(S))
}
func solve(S string) string {
	if S == "ABC" {
		return "ARC"
	}
	return "ABC"
}


Measured memory_bytes: 1752
def solve(X, D, lb, ub):
    # min abs(X + t * D) (lb <= t <= ub)
    t = round(-X / D)
    ans = abs(X)
    for i in [-2, -1, 0, +1, +2]:
        tt = t + i
        tt = min(tt, ub)
        tt = max(tt, lb)
        y = X + tt * D
        ans = min(ans, abs(y))
    return ans

X, K, D = map(int, input().split())

y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
    print(min(abs(y1), abs(y2)))
else:
    if K % 2 == 0:
        ans = solve(X, D * 2, -(K // 2), +(K // 2))
    else:
        ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
        ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
        ans = min(ans1, ans2)
    print(ans)



Measured memory_bytes: 61964
a=[0]*26
w='abcdefghijklmnopqrstuvwxyz'
try:
    while True:
        s=list(raw_input().upper())
        for i in s:
            if i=='A':
                a[0]+=1
            elif i=='B':
                a[1]+=1
            elif i=='C':
                a[2]+=1
            elif i=='D':
                a[3]+=1
            elif i=='E':
                a[4]+=1
            elif i=='F':
                a[5]+=1
            elif i=='G':
                a[6]+=1
            elif i=='H':
                a[7]+=1
            elif i=='I':
                a[8]+=1
            elif i=='J':
                a[9]+=1
            elif i=='K':
                a[10]+=1
            elif i=='L':
                a[11]+=1
            elif i=='M':
                a[12]+=1
            elif i=='N':
                a[13]+=1
            elif i=='O':
                a[14]+=1
            elif i=='P':
                a[15]+=1
            elif i=='Q':
                a[16]+=1
            elif i=='R':
                a[17]+=1
            elif i=='S':
                a[18]+=1
            elif i=='T':
                a[19]+=1
            elif i=='U':
                a[20]+=1
            elif i=='V':
                a[21]+=1
            elif i=='W':
                a[22]+=1
            elif i=='X':
                a[23]+=1
            elif i=='Y':
                a[24]+=1
            elif i=='Z':
                a[25]+=1 

except EOFError:
    pass

for i in range(26):
    print w[i:i+1], ':', str(a[i])

Measured memory_bytes: 6508
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
--
local H, W, K = read.nnnl()
local C = {}
for i=1,H do
    C[i] = read.l():totable()
end


local function getb(mh, mw)
    local b = 0
    for h=1,H do
        if mh & (1<<(h-1)) ~= 0 then
            for w=1,W do
                if mw & (1<<(w-1)) ~= 0 then
                    if C[h][w] == '#' then
                        b = b + 1
                    end
                end
            end
        end
    end
    return b
end

local c = 0
for mh=0,math.floor(2^H)-1 do
    for mw=0,math.floor(2^W)-1 do
        if getb(mh,mw) == K then
            c = c + 1
        end
    end
end
print(c)

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007
#define INF 2147483647

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

int N;
vector<int> value;

void update(int i, int x) {
	i += N-1;
	value[i] = x;
	while(i > 0) {
		i = (i - 1) / 2;
		value[i] = min(value[i*2+1], value[i*2+2]);
	}
}

int query(int a, int b, int k, int l, int r) {
	if(r <= a || b <= l) return INF;
	if(a <= l && r <= b) return value[k];
	else {
		int c1 = query(a, b, 2*k+1, l, (l+r)/2);
		int c2 = query(a, b, 2*k+2, (l+r)/2, r);
		return min(c1, c2);
	}
}

int main() {
	int n, q;
	cin >> n >> q;
	N = 1;
	while(N < n) N *= 2;

	value = vector<int>(2 * N - 1, INF);
	int com;
	rep(i,q) {
		cin >> com;
		if(com == 0) {
			int i,x;
			cin >> i >> x;
			update(i, x);
		}
		if(com == 1) {
			int s, t;
			cin >> s >> t;
			cout << query(s,t+1,0,0,N) << endl;
		}
	}
  return 0;
}


Measured memory_bytes: 3796