akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    ll N,M;cin>>N>>M;
    vector <ll> p;p.resize(N);
    vector <ll> p_inverse = p;
    for(int i=0;i<N;i++) {cin>>p[i];p[i]--;p_inverse[p[i]] = i;}
    UnionFind tree(N);
    for(int i=0;i<M;i++){
        int x,y;cin>>x>>y;
        x--;y--;
        tree.unite(x,y);
        //tree.unite(y,x);
    }

    vector < set <ll> > sets(N);

    for(int i=0;i<N;i++) tree.root(i);
    for(int i=0;i<N;i++){
        if(tree.par[i] ==i) sets[i].insert(i);
        else sets[tree.par[i]].insert(i);
    }
ll ans = 0;
    for(int i=0;i<N;i++){
        if(sets[i].empty()) continue;
        set <ll> nowSet = sets[i];
        for(auto itr = nowSet.begin();itr != nowSet.end();itr++){
            ll now = *itr;
           // cout<<now<<" ";
            if(nowSet.find(p_inverse[now]) != nowSet.end()) ans++;

        }
//cout<<endl;
    }
cout<<ans<<endl;


}

Measured memory_bytes: 16256
from collections import Counter

def alp(c):
    return ord(c) - ord('a')

n = input()
C = [0 for _ in xrange(26)]
s = raw_input()
for c in s:
    C[alp(c)] += 1


for i in xrange(n-1):
    s = raw_input()
    D = [0 for _ in xrange(26)]
    for c in s:
        D[alp(c)] += 1
    for j in xrange(26):
        C[j] = min(C[j], D[j])

ans = ""
for i in xrange(26):
    ans += chr(ord('a')+i) * C[i]
print ans


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

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

	set<int> st;

	for (int i = a; i < min(a + k, b + 1); i++)
	{
		st.insert(i);
	}
	for (int i = b; max(a - 1, b - k) < i; i--)
	{
		st.insert(i);
	}

	for (auto &&x : st)
	{
		cout << x << endl;
	}

	return 0;
}

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

int main() {
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    queue<char> qa, qb , qc;
    rep(i, sa.size()) qa.push(sa.at(i));
    rep(i, sb.size()) qb.push(sb.at(i));
    rep(i, sc.size()) qc.push(sc.at(i));

    qa.push('x');
    qb.push('x');
    qc.push('x');


    int cnt = 0;
    char x;
    x = qa.front();
    qa.pop();

    while(!qa.empty() || !qb.empty() || !qc.empty()){
        if(x == 'a'){
            if(qa.front() == 'x'){
                cout << 'A' << endl;
                return 0;
            }
            x = qa.front();
            qa.pop();
        }
        else if(x == 'b'){
            if(qb.front() == 'x'){
                cout << 'B' << endl;
                return 0;
            }
            x = qb.front();
            qb.pop();
        }
        else if(x == 'c'){
            if(qc.front() == 'x'){
                cout << 'C' << endl;
                return 0;
            }
            x = qc.front();
            qc.pop();
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
#define mod 1000000007
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a<6)cout<<0<<endl;
    else if(a<=12)cout<<b/2<<endl;
    else cout<<b<<endl;

    return 0;
}

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

using namespace std;

vector<pair<int, int>> a;
vector<int> x;
vector<vector<pair<int, int>>> g;
vector<bool> mark;
vector<int> xors;
vector<int> res;

int DFS(int vertex)
{
    int ans = xors[vertex];
    mark[vertex] = true;
    for (auto it : g[vertex])
    {
        int to = it.first;
        if (!mark[to])
        {
            int r = DFS(to);
            if (r == 1)
                res.push_back(it.second);
            ans ^= r;
        }
    }
    return ans;
}

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

    int n, m;
    cin >> n >> m;

    a.resize(n);
    for (int i = 0; i < n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());

    x.resize(n);
    for (int i = 0; i < n; i++)
        x[i] = a[i].first;

    g.resize(n + 1);
    for (int i = 0; i < m; i++)
    {
        int l, r;
        cin >> l >> r;

        l = lower_bound(x.begin(), x.end(), l) - x.begin();
        r = lower_bound(x.begin(), x.end(), r + 1) - x.begin();

        g[l].push_back({r, i});
        g[r].push_back({l, i});
    }

    xors.resize(n + 1);
    for (int i = 0; i < n - 1; i++)
        xors[i + 1] = (a[i].second ^ a[i + 1].second);\
    xors[0] = a[0].second;
    xors[n] = a[n - 1].second;

    mark.assign(n + 1, false);
    for (int i = 0; i < n; i++)
        if (!mark[i])
        {
            int r = DFS(i);
            if (r == 1)
            {
                cout << "-1\n";
                return 0;
            }
        }

    cout << res.size() << "\n";
    sort(res.begin(), res.end());
    for (auto it : res)
        cout << it + 1 << " ";
    cout << "\n";

    return 0;
}


Measured memory_bytes: 16636
a, b = map(int, input().split())
c = [1, 3, 5, 7, 8, 10, 12]
d = [4, 6, 9, 11]
e = [2]
if ((a in c) and (b in c)) or ((a in d) and (b in d)) or ((a in e) and (b in e)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#ifdef _MSC_VER
#  define _CRT_SECURE_NO_WARNINGS
#  define _USE_MATH_DEFINES
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double;
using u32 = unsigned int; using u64 = unsigned long long int; using str = string;
template <typename T> using vec = vector<T>; void in() { }
template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); }
template <typename T> void out(T &&x) { cout << x << "\n"; }
template <typename T, typename...TS> void out(T &&x, TS &&...xs) { cout << x << " "; out(move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t x; cin >> x; return x; }()
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) ((abs(x) & 1) == 0)
#define odd(x) ((abs(x) & 1) == 1)
#define bit(x, i) (((x) >> i) & 1)
#define append emplace_back
#define bisect_left lower_bound
#define bisect_right upper_bound
#define bound(a, x, b) (a <= x && x <= b)
const i64 MOD = 1000000007ll;
const f64 EPS = 1e-10;

i64 solve() {
    indef(i64, n, a, b, c, d);
    upto(0, n-2, t) {
        if (bound(-d*(n-1-t)+c*t, b-a, -c*(n-1-t)+d*t)) {
            return true;
        }
        if (bound(c*(n-1-t)-d*t, b-a, d*(n-1-t)-c*t)) {
            return true;
        }
        if (bound(-d*(n-2-t)+c*(t+1), b-a, -c*(n-2-t)+d*(t+1))) {
            return true;
        }
        if (bound(c*(n-2-t)-d*(t+1), b-a, d*(n-2-t)-c*(t+1))) {
            return true;
        }
    }
    return false;
}

i32 main()
{
    ios::sync_with_stdio(false);

#ifdef _MSC_VER
    /**
    ifstream fin("input.txt"); cin.rdbuf(fin.rdbuf()); assert(fin);
    ofstream fout("output.txt"); cout.rdbuf(fout.rdbuf()); assert(fout);
    /**/
#endif

    cout << fixed << setprecision(9);
    out(solve() ? "YES" : "NO");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>
#include <numeric>
#include <math.h>

#define LOOP(N) for(int i=0; i<(N); ++i)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(start); i<(end); ++i)

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using Graph = vector< vector<int> >;


int main() {
    int N; cin >> N;
    double ans = 0;
    int a;
    LOOP(N) {
        cin >> a;
        ans += 1.0/a;
    }
    cout << 1/ans;
}


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

#define x first
#define y second
#define all(a) (a).begin(), (a).end()

#define sz(a) (int) (a).size()

#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int c25, c50, c1, c2, n;
    cin >> c25 >> c50 >> c1 >> c2 >> n;
    c50 = min(c50, c25*2);
    c1 = min(c1, c50*2);
    c2 = min(c2, c1*2);
    cout << n/2*c2+(n%2)*c1 << '\n';
    return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n;
    cin >> n;
    ll cnt[n + 1] = {};
    for(ll i = 1; i <= n; i++) {
        ll now = i;
        while(now % 2 == 0) {
            cnt[2]++;
            now /= 2;
        }
        for(ll j = 3; j * j <= i; j += 2) {
            if(now % j == 0) {
                while(now % j == 0) {
                    cnt[j]++;
                    now /= j;
                }
            }
        }
        if(now > 1) {
            cnt[now]++;
        }
    }
    ll ret = 1;
    for(ll i = 2; i <= n; i++) {
        if(cnt[i]) {
            (ret *= (cnt[i] + 1)) %= MOD;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np

    N = int(input())
    P = np.array(list(map(int, input().split())))
    Q = np.array(list(map(int, input().split())))

    import itertools
    X = [i+1 for i in range(N)]
    for i, v in enumerate(itertools.permutations(X)):
        v = np.array(v)
        if (v == P).all():
            p = i
        if (v == Q).all():
            q = i
    print(abs(p-q))


if __name__ == "__main__":
    main()


Measured memory_bytes: 12904
import java.io.*;
import java.util.Arrays;

/**
 * ??????H cm ?????? W cm ????????????????????????
 * 
 * e.g.?????? 6 cm ?????? 10 cm
 * ##########
 * #........#
 * #........#
 * #........#
 * #........#
 * ##########
 * 
 * @author ikaruga
 */
class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            br.lines().forEach(line -> outputFrame(line.trim()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param line
     *            ??????H ?????? W(e.g."4 5")
     * @return String
     */
    private static void outputFrame(String line) {
    	String[] sizeArray = line.split("\\s");
    	if (sizeArray.length != 2) {
    		return;
    	}
    	if (Arrays.asList(sizeArray).stream().allMatch(s -> s.equals("0"))) {
    		return;
    	}
    	
    	int h = 0;
    	int w = 0;
    	int hh = Integer.parseInt(sizeArray[0]);
    	int ww = Integer.parseInt(sizeArray[1]);
    	StringBuilder sb = new StringBuilder();
    	for (h = 0; h < hh; h++) {
        	for (w = 0; w < ww; w++) {
        		if (w == 0) {
        			sb.append("#");
        		} else if (w == ww - 1) {
        			sb.append("#");
        			sb.append(System.lineSeparator());
        		} else if (h == 0 || h == hh - 1) {
        			sb.append("#");
        		} else {
        			sb.append(".");
        		}
        	}
    	}
    	System.out.println(sb.toString());
    }
}

Measured memory_bytes: 31572
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
h = na()
mh = [0 for i in range(n)]
for i in range(m):
    a, b = na()
    mh[a-1] = max(mh[a-1], h[b-1])
    mh[b-1] = max(mh[b-1], h[a-1])
ans = 0  
for i in range(n):
    if h[i] > mh[i]:
        ans += 1
print(ans)

Measured memory_bytes: 84868
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

#define rep(i, a, b) for(ll i = a; i < ll(b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    ll x,y;
    cin>>x>>y;
    cout<<(3-x-y+2)%3+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vcc;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}

int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
{
    ll i, j, n, m;
    ll c1 = 0;
    ll c2 = 0;
    fo(i, 3)
    {
        cin >> j;
        if (j == 5)
        {
            c1++;
        }
        if (j == 7)
        {
            c2++;
        }
    }
    if (c1 == 2 && c2 == 1)
    {
        cout << "YES";
    }
    else
        cout << "NO";
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int i, u, v;
    while (m--)
    {
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (v == par)
            continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 10620
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		int n = pStr.length;
		
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int accept = pInt[0] - pInt[1];
		
		if(pInt[2] > accept) {
			System.out.println(pInt[2] - accept);
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void) {
    int N,M,i,yaku;
    scanf("%d %d",&N,&M);
    if (M % N == 0) {
        printf("%d\n",M / N);
    } else {
        for (i = 1;i <= (M / N);i++) {
            if (M % i == 0) {
                yaku = i;
            }
        }
        printf("%d\n",yaku);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){}
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    P p[3];
    REP(i,3) {
      int x,y;
      cin >> x >> y;
      p[i] = P(x,y);
    }
    L l[3];
    REP(i,3)
    l[i] = L(p[i],p[(i+1)%3]);
    int xk,yk,xs,ys;
    cin >> xk >> yk >> xs >> ys;

    P pk(xk,yk), ps(xs,ys);
    L ll(pk,ps);
    int c = 0;
    REP(i,3) {
      if (intersectSS(l[i],ll))
        c++;
    }
    if (c == 1) cout << "OK";
    else cout << "NG";
    cout << endl;
  }
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
int main (){
    int N;
    cin>>N;
    double a;
    if(N%2==0){
        a=0.5;
    }
    else{
      double b=N;
        a=(b+1)/b/2;
    }
    cout<<a<<endl;
}

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

int main()
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  string s = "";
  int dx = tx - sx, dy = ty - sy;
  
  s.append(dx, 'R').append(dy, 'U').append(dx, 'L').append(dy+1, 'D')
    .append(dx+1, 'R').append(dy+1, 'U').append(1, 'L').append(1, 'U')
    .append(dx+1, 'L').append(dy+1, 'D').append(1, 'R');
  
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		if (n%i == 0 && n/i >= 1 && n/i <= 9) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3640
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

t = 1
for i in range(1, N - 1):
  t *= i

ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    x1, y1 = xy[i]
    x2, y2 = xy[j]
    ans += (((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (1 / 2)) * (N - 1) * 2 * t

n = 1
for i in range(1, N + 1):
  n *= i

ans /= n

print(ans)

Measured memory_bytes: 3188
N, Y = map(int, input().split())

a,b,c = (-1, -1, -1)
for i in range(N+1):
    for j in range(N+1-i):
        k = N-i-j
        if 10000*i + 5000*j + 1000*k == Y:
            a,b,c = i,j,k
            break
print(a,b,c)

Measured memory_bytes: 3060
n = gets.to_i
ans = 0
count = 0
cities = []

n.times do 
  cities << gets.split().map(&:to_i)
end

cities.permutation.to_a.each do |array|
  array.each_cons(2) do |(x1, y1), (x2, y2)|
    ans += ((x1-x2)**2 + (y1-y2)**2)**0.5
  end
  count += 1
end

puts ans / count.to_f

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int k;
  string s, s2;
  cin >> k >> s;
  s2 = s.substr(0, k) + "...";
  if (s.size() <= k)
    cout << s << endl;
  else
    cout << s2 << endl;

  return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int N, K;
int A[200010];
bool mem[200010];
set<int> S;

signed main()
{
    cin >> N >> K;
    rep(i, N)cin >> A[i];

    int l = 0;
    rep(i, N)
    {
        if(i && A[i - 1] > A[i])l = i;
        if(i - l + 1 >= K)mem[i - K + 1] = true;
    }

    int ans = 0;
    rep(i, N)if(mem[i])ans = 1;

    rep(i, K)S.insert(A[i]);

    if(!mem[0])ans++;
    rep(i, N - K)
    {
        S.insert(A[K + i]);
        if(!(*(S.begin()) == A[i] && *(--S.end()) == A[K + i])
        && !mem[i + 1])ans++;
        S.erase(A[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14532
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   int n,y;
   cin>>n>>y;
   for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
         int k=(n-i-j);
         if(k<0)continue;
         ll m=10000*i+5000*j+1000*k;
         if(m==y){
            cout<<i<<" "<<j<<" "<<k<<endl;
            return 0;
         }
      }
   }
   cout<<-1<<" "<<-1<<" "<<-1<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX = 100;

int main()
{
	int n = 0 , a[MAX];
	cin >> n;
	for (int i = 0;i < n;i++)		cin >> a[i];	
	for (int i = 1;i < n;i++)
	{
		for (int i = 0;i < n;i++)
		{
			cout << a[i];
			if (i < n - 1) cout << " ";
		}
		cout << endl;
		int j = i - 1;
		int key = a[i];
		while (j >= 0 && a[j] > key) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = key;
	}
	for (int i = 0;i < n;i++)
	{
		cout << a[i];
		if (i < n - 1) cout << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3128
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


int main()
{
	int N;
	cin >> N;
	map<int, int> mp;
	vec A(N);

	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		mp[A[i]]++;
	}

	int maxV = mp.rbegin()->first;

	for (int i = 0; i < N; ++i)
	{
		if (maxV == A[i] && mp[A[i]] == 1)
		{
			auto itr = mp.rbegin();
			itr++;
			cout << itr->first << endl;
		}
		else
		{
			cout << maxV << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 8704
#include<stdio.h>
int main(void)
{
	int a[100];
	int n, i;
	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	for(i=n-1; i>=0; i--){
		printf("%d", a[i]);
		if(i!=0){
			printf(" ");
		}
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];

int main(){
	int n, t;cin >> n >> t;
	for(int i = 1 ; i <= n ; i++)cin >> a[i];
	sort(a + 1, a + 1 + n);
	int cnt = 0;
	long long ans = 0;
	for(int i = 1; i <= n ; i++){
		ans += a[i] + t - max(a[i],cnt);
		cnt = a[i] + t;
	}
	cout << ans << endl;
	
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

ll n,a[N];

ll f(int x,int rem) {
  if (x == n + 1)
    return 0;
  int t = 0;
  if (rem && a[x]) {
    a[x]--;
    t++;
  }
  return t + f(x + 1,a[x] % 2) + a[x] / 2;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n;
  for (int i = 1 ; i <= n ; i++)
    cin >> a[i];
  cout << f(1,0);
}

Measured memory_bytes: 4224
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    sum_A = sum(A)
    cnt = 0
    for a in A:
        if a >= (sum_A / (4 * M)): 
            cnt += 1

    if cnt >= M:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[600005],b[200005],c[600005];
int l,r=1,o;
int main(){
	cin>>n;
	for(int i=0;i<=n*2;++i){
		if(i-n){
			cin>>a[i+(i<n?n+1:-n-1)];
		}
	}
	a[n*2+1]=a[n+1];
	a[n]=a[0]; 
	for(int i=0;i<n;++i){
		b[i]=a[0]^a[n+1+i];
	}
	for(int i=0;i<=n*2;++i){
		a[i]^=a[i+1];
	}
	for(int i=0;i<n;++i){
		a[i+n*2+1]=a[i+n+1];
	}
	a[n]=1<<30;
	for(int i=0;i<=n*2;++i){
		if((o=c[i-l]+i>=r)){
			for(l=i,r=max(r,i);a[r-l]==a[r];++r);
		}
		if((c[i]=o?r-l:c[i-l])==n){
			cout<<i-n-1<<' '<<b[i-n-1]<<'\n';
		}
	}
	return 0;
} 

Measured memory_bytes: 8448
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn dfs(
    mut a: &mut [usize],
    now_digit: usize,
    n: usize,
    m: usize,
    abcd: &[(usize, usize, usize, usize)],
) -> usize {
    if now_digit == n {
        // 配列aの評価値
        return abcd.iter().fold(0, |acc, now| {
            if a[now.1 - 1] - a[now.0 - 1] == now.2 {
                acc + now.3
            } else {
                acc
            }
        });
    }

    let mut max = 0;
    // [前の桁の値,m]
    for i in a[now_digit - 1]..=m {
        a[now_digit] = i;
        max = cmp::max(max, dfs(&mut a, now_digit + 1, n, m, abcd));
        //println!("{:?} {}", a, max);
    }

    max
}

fn solve() {
    input! {
        n: usize,
        m:usize,
        q:usize,
        abcd:[(usize,usize,usize,usize);q]
    }

    let mut a = vec![1; n];
    println!("{}", dfs(&mut a, 1, n, m, &abcd));
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

int main() {
  int k; cin >> k;
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[k-1];
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=LLONG_MAX,mod=1000000007,BS,k;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
		string s;cin>>s;ll num=0;
		for(ll i=0;i<s.length();i++){
			num+=(s[i]-'0');
			num%=9;
		}
		if(num)
		cout<<"No";
		else
		cout<<"Yes";
}


Measured memory_bytes: 3716
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	ll prime[100003];
	prime[0]=0;
	prime[1]=0;
	prime[2]=1;
	ll i,j;
	for(i=2;i<=100003;i++){
		prime[i]=1;
	}
	i=2;
	while(i*i<=100003){
		if(prime[i]==1){
			for(j=2*i;j<=100003;j+=i){
				prime[j]=0;
			}
		}
		i++;
	}
	ll N;
	cin >> N;
	while(prime[N]==0){
		N++;
	}
	cout << N <<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    if(n<m)swap(n,m);
    ll a=0,b=0;
    rep(i,n)a=a*10+m;
    puta(a);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
template <int MOD>
class ModInt {
  long long x;

 public:
  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt<MOD> pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }

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

using mint = ModInt<1000000007>;

string L;

mint p(int x, int d) {
  if (d == 0) return 1;
  mint res = 1;
  if (d % 2 != 0) res = x;
  mint r = p(x, d / 2);
  return r * r * res;
}

int main() {
  cin >> L;

  int N = L.size();

  mint ans = 0;
  int c = 0;
  rep(i, N) if (L[i] == '1') {
    ans += p(2, c) * p(3, N - i - 1);
    c++;
  }

  // L
  ans += p(2, c);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
a = 2, 3, 5

def f(n):
  m = memo.get(n)
  if m is None:
    nd = m = n * d
    for p, c in zip(a, b):
      p *= d
      k, r = divmod(nd, p);
      m = min(m, f(k) + r + c, r and f(k + 1) + p - r + c or m)
    memo[n] = m
  return m

t = int(input())
for _ in range(t):
  n, *b, d = map(int, input().split())
  memo = {0: 0, 1: d}
  print(f(n))


Measured memory_bytes: 10952
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int TAKA, AOKI;
  TAKA = c / b;
  if (c % b != 0) TAKA = TAKA + 1;
  AOKI = a / d;
  if (a % d != -0) AOKI = AOKI + 1;
  if (TAKA <= AOKI) cout << "Yes";
  if (TAKA > AOKI) cout << "No";
  return 0;
}

Measured memory_bytes: 3616
fn main() {
 let mut a=vec![[[0;10];3];4];
 let n:Vec<isize>=r();
 for _ in 0..n[0]{
  let c:Vec<isize>=r();
  let b = (c[0]-1) as usize;
  let f = (c[1]-1) as usize;
  let r = (c[2]-1) as usize;
  let v = c[3];
  a[b][f][r]+=v;
 }
 let z:Vec<_> = a.iter()
  .flat_map(|x|x.iter())
  .collect();
 for (i, x) in z.iter().enumerate(){
   if i%3==0&&i!=0{
    println!("{}", "#".repeat(20));
   }
  println!(" {}", x.iter().map(std::string::ToString::to_string).collect::<Vec<_>>().join(" "));
 }
}
fn r<T:std::str::FromStr>()->Vec<T>{
 let mut b=String::new();
 let s=std::io::stdin();
 s.read_line(&mut b).unwrap();
 b.split_whitespace().flat_map(str::parse).collect()
}


Measured memory_bytes: 5028
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
const char nl = '\n';
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
//The following debugging code was taken from Benjamin Qi's template :) 
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef LOCAL 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
//CODE STARTS HERE-----------------------------------------------------------------------------------------// 
const int N = 100, K = 1e5 + 10;
int n, k;
int arr[N], dp[K][2];
int solve(int stt, int trn){
    dbg(stt, trn);
    if(dp[stt][trn] != -1){
        return dp[stt][trn];
    }
    if(stt == 0){
        return trn ^ 1;
    }
    int works = trn ^ 1;
    for(int i =0; i < n; i++){
        if(stt-arr[i] >= 0){
            works = solve(stt-arr[i], trn^1); 
            if(works == trn){
                break;
            }
        }
    }
    return dp[stt][trn] = works;
}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    memset(dp, -1, sizeof(dp));
    for(int i =0 ; i < n; i++){
        cin >> arr[i];
    }
    cout << (solve(k, 0)?"Second":"First") << nl;
}

Measured memory_bytes: 12212
# AtCoder Beginner Contest 155: B (2020/02/16)
N = int(input())
l = input().split()
ans = True
for i in range(N):
    A = int(l[i])
    if A % 2 == 0:
        if A % 3 != 0 and A % 5 != 0:
            ans = False
if ans == True:
    print('APPROVED')
else:
    print('DENIED')

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX_N 310

using namespace std;

const int IINF = INT_MAX;



struct Recipe{
  int G;
  vector<int> S;
};


int N,E,T,W[MAX_N],C;
int mincost[MAX_N];

bool cmp(const int& a,const int& b){
  return mincost[a] > mincost[b];
}


int main(){
  cin >> N >> E >> T;
  --T;
  Recipe *reci = new Recipe[E];
  rep(i,N)cin>>W[i],mincost[i] = (W[i]?1:IINF);
  rep(i,E){
    cin >> reci[i].G >> C;
    --reci[i].G;
    reci[i].S.resize(C);
    rep(k,C){
      cin >> reci[i].S[k];
      --reci[i].S[k];
    }
  }

  bool update = true;
  while(update){
    update = false;
    rep(i,E){
      bool ok = true;
      int greef = 0,need = 0;
      sort(reci[i].S.begin(),reci[i].S.end(),cmp);
      rep(j,reci[i].S.size()){
        if( mincost[reci[i].S[j]] == IINF ){
          ok = false;
          break;
        } else{
          if( greef >= mincost[reci[i].S[j]] ) --greef;
          else{
            need += mincost[reci[i].S[j]] - greef;
            greef = mincost[reci[i].S[j]] - 1;
          }
        }
      }
      if(ok && mincost[reci[i].G] > need ){
        mincost[reci[i].G] = need;
        update = true;
      }
    }
  }

  cout << ((mincost[T]!=IINF)?mincost[T]:-1) << endl;

  delete [] reci;
  return 0;
}

Measured memory_bytes: 1280
place_count = int(input())
t_a = list(map(int, input().split()))

t = t_a[0]
target = t_a[1]

heights = list(map(int, input().split()))

temp = []
# ans = (idx, temperature diff)
ans = (0, 10000000)
for (idx, h) in enumerate(heights):
  temperature = t - (0.006 * h)
  if ans[1] > abs(temperature - target):
    ans = (idx + 1, abs(temperature - target))

print(ans[0])

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


int main() {
  int a,b,c,d,i,e;
  cin >> a >> b ;
  for (i=0;i<=a;i++){
    if(i*2+(a-i)*4==b){
      cout << "Yes";
      break;
    }
    if(i==a){
     cout << "No";
    }
  }
}



Measured memory_bytes: 3616
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = [0]
for i in range(1,len(S)):
    if S[i-1]=="A" and S[i]=="C":
        Asite.append(Asite[-1]+1)
    else:
        Asite.append(Asite[-1])


for l,r in lrlist:
    print(Asite[r]-Asite[l])


Measured memory_bytes: 24468
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll A, B;

int main() {
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;

  if(x < 1200)
    cout << "ABC" << endl;
  else if(x >= 2800)
    cout << "AGC" << endl;
  else
    cout << "ARC" << endl;
  return 0;
}


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

int main(){
	int a,b,c,color[100],x=3;
	for(int i=0;i<100;i++)color[i]=0;
	cin >> a >> b >> c;
	color[a-1]=1;
	if(color[b-1]==1){
		x--;
	}else{
		color[b-1]=1;
	}
	if(color[c-1]==1)x--;
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (a % 2 == b % 2) cout << "Alice\n";
  else cout << "Borys\n";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int key;
  struct Node *next,*prev;
};

struct Node *nil;
struct Node* listSearch(int key){
  struct Node *cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  struct Node *cur=nil->next;
  int isf=0;
  while(1){
    if(cur==nil)break;
    if(isf++>0)printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(struct Node *t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x=(struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){scanf("%d",&key);insert(key);np++;size++;}
    else if(com[0]=='d'){
      if(strlen(com)>6){
        if(com[6]=='F')deleteFirst();
        else if(com[6]=='L')deleteLast();
      }else{
        scanf("%d",&key);
        deleteKey(key); nd++;
      }
      size--;
    }
  }
  printList();

  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

using vi = vector<int>;
using vvi = vector<vi>;

int main() {

    int N,M;

    Scd2(N,M);

    vvi e( N );
    vi r( N,0 );

    int a,b;
    Rep(i,N+M-1){
        Scd2(a,b);
        a--,b--;
        e[a].push_back(b);
        r[b]++;
    }

    int head = 0;
    Rep(i,N){
        if( r[i] == 0 ) head = i;
    }

    vector<int> s(N,0);
    deque<int> d;

    d.push_back(head);

    while( !d.empty() ){
        int from = d.front();
        d.pop_front();
        for( int to : e[from] ){
            if( --r[to] == 0 ){
                s[to] = from+1;
                d.push_back(to);
            }
        }
    }

    Rep(i,N){
        printf ("%d\n", s[i] );
    }





    return 0;
}



Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

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

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
string dir[8] = { "R","L","D","U","RD","RU","LD","LU" };
char c[10][10];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	ll ans = INF;
	for (ll bits = 0;bits < (1 << n);++bits) {
		ll kazu = 0;
		ll res = 0;
		vector<ll>target;
		for (ll i = 0;i < n;++i) {
			if (bits & (1 << i)) {
				kazu++;
				target.push_back(i);
			}
		}
		if (kazu >= k) {
			vector<ll>a2(n);
			rep(i, n) {
				a2[i] = a[i];
			}
			for (ll i = 0;i < target.size();++i) {
				ll target2 = target[i];
				ll hmax = 0;
				for (ll j = 0;j < target2;++j) {
					hmax = max(hmax, a2[j]);
				}
				res += max((ll)0, hmax + 1 - a2[target2]);
				if (a2[target2] <= hmax + 1)a2[target2] = hmax + 1;
			}
			ans = min(ans, res);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3548
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    Q = int(input())

    reverse = False
    header = [''] * Q
    footer = [''] * Q
    for i in range(Q):
        query = input()
        if query[0] == '1':
            reverse = not reverse
        else:
            _, f, c = query.split()
            isHead = f == '1'
            if reverse:
                isHead = not isHead
            if isHead:
                header[i] = c
            else:
                footer[i] = c

    if reverse:
        print("".join(footer[::-1] + list(S)[::-1] + header))
    else:
        print("".join(header[::-1]) + S + "".join(footer))

if __name__ == '__main__':
    main()


Measured memory_bytes: 12600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

int main(){
    vector<int> x(4,0) ;
    vector<int> y(4,0) ;
    int dx,dy ;
    cin >> x.at(0) >> y.at(0) >> x.at(1) >> y.at(1) ;
    dx = x.at(1) - x.at(0) ;
    dy = y.at(1) - y.at(0) ;
    swap(dx,dy) ;
    dx *= -1 ;
    x.at(2) = x.at(1) + dx ;
    y.at(2) = y.at(1) + dy ;
    swap(dx,dy) ;
    dx *= -1 ;
    x.at(3) = x.at(2) + dx ;
    y.at(3) = y.at(2) + dy ;
    cout << x.at(2) << " " << y.at(2) << " " << x.at(3) << " " << y.at(3) << endl ;
}


Measured memory_bytes: 3640