akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cost;
        bool operator>(const state s) const { return cost > s.cost; }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<long long> shortest_path(long long S) {
        vector<long long> dp(E.size(), INF);
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0 });
        while(!q.empty()) {
            long long v = q.top().v, cost = q.top().cost;
            q.pop();
            if(dp[v] <= cost) continue;
            dp[v] = cost;
            for(int i=0;i < E[v].size() ; i++) {
            long long nv = E[v][i].v, ncost = cost + E[v][i].dist;
            if(dp[nv] > ncost) q.push((state) { nv, ncost });
            }
        }
        return dp;
    }
};


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

    int n,m;
    cin>>n>>m;
    // ~n:パ、~2n：ケン1、~3nケン1でいる位置
    Dijkstra di(3*n);

    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--,v--;
        //パ→ケン1
        di.add_directed_edge(u,v+n,1);

        //ケン1→ケン2
        di.add_directed_edge(u+n,v+n+n,1);

        //ケン2→パ
        di.add_directed_edge(u+n+n,v,1);
    }
    int s,t;
    cin>>s>>t;
    s--,t--;
    vector<ll> dist = di.shortest_path(s);
    if(dist[t] < 1e9 && dist[t]%3==0){
        cout<<dist[t]/3<<endl;
    }
    else cout<<-1<<endl;
    

}


Measured memory_bytes: 19072
use std::str::FromStr;
use std::io::stdin;

fn main() {
    let n = read::<usize>();
    let vec = read_vec::<u64>();
    let mut result = true;
    for i in 0..n {
        result = result && match (vec[i] % 2, vec[i] % 3, vec[i] % 5) {
            (0, 0, _) => true,
            (0, _, 0) => true,
            (0, _, _) => false,
            (_, _, _) => true,
        }
    }
    println!("{}", if result { "APPROVED" } else { "DENIED" });
}

fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|x| x.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=set(a);B=set(b)
c=1;N=0;M=0
for k in range(m*n,0,-1):
  if k in A and k in B:
    N+=1;M+=1
  elif k in A:
    c*=M;N+=1
  elif k in B:
    c*=N;M+=1
  else:
    c*=M*N-m*n+k
  c=c%(10**9+7)
print(c)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int n,k;cin>>n>>k;
    vector<ll> h(n+1);
    rep(i,n) cin>>h[i+1];

    //まず，ある列を操作すること，その列を完全に消すことは同値(これは自分で気づけた)
    //消す列を選ぶ
    //うまくDPするために
    //必要な情報はDPのindex(次元？)に持たせる
    //何回操作したかとか，あと何回操作したかとかをDPに持たせるのはとても自然な考えだけど，もう一つ
    //今回，ある状況での部分解は削除しなかった最後の列に依るんだからそこを持ったほうがいいとわかる
    //なるほどなぁ
    ll dp[310][310];
    rep(i,310)rep(j,310) dp[i][j]=LINF;
    dp[0][0]=0;
    // dp[i][j] : 最後にi列を使った，サイズがj
    // dp[i][j]=min(k=1 to i-1  dp[k][j-1]+max(0,h[i]-h[k]))

    for(int j=1;j<=n-k;j++){
        for(int i=1;i<=n;i++){
            for(int k=0;k<i;k++){
                chmin(dp[i][j],dp[k][j-1]+max(0ll,h[i]-h[k]));
            }
        }
    }
    ll ans=LINF;
    rep(i,n+1){
        chmin(ans,dp[i][n-k]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}

let n = Scanner.readInt()
print(n*n)


Measured memory_bytes: 13196
// TP1_5_C:   Print a Chessboard
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int H, W;
    int h, w;
 
    while (1) {
        scanf("%d%d", &H, &W);
        if (H == 0 && W == 0) break;
        for (h = 0; h < H; h++) {
            for (w = 0; w < W; w++) {
                putchar(((h & 1) ^ (w & 1)) == 0 ? '#' : '.');      }
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main(){
	int m,d,ans=0;
	cin>>m>>d;
	for (int i=1;i<=m;i++){
		for (int j=2;j<=9;j++) for (int k=2;k<=9;k++) if (j*10+k<=d && j*k==i) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n,k,a[1100];
int main(void)
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=1;i<=k;i++)ans+=a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3192
#include<cstdio>

int main(){
    char os;
    int a,b,c;
    for(;;){
        scanf("%d %c %d",&a,&os,&b);
            if(os == '+'){
                c = a + b;
            }
            else if(os == '-'){
                c = a - b;
            }
            else if(os == '*'){
                c = a * b;
            }
            else if(os == '/'){
                c = a / b;
            }
            else if(os == '?'){
                break;
            }
        printf("%d\n",c);
    }
}


Measured memory_bytes: 2716
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        int i = 1;
        while(true){
            int x = in.nextInt();
            if(x == 0) break;
            System.out.printf("Case %d: %d\n", i, x);
            i++;
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

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

  vector<ll> h(n);
  for (ll i = 0; i < n; ++i) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());

  ll ans = h[k-1] - h[0];
  for (ll i = k; i < n; ++i) {
    ans = min(ans, h[i] - h[i-k+1]);
  }

  cout << ans << endl;

  return 0;
}

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

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

int main() {
    int n;
    cin >> n;
    if ( !(n & 1) ) cout << n << endl;
    else            cout << n * 2 << endl;
    return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

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

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

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

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    string s;
    cin >> s;
    cout << string(s.size(), 'x') << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //g++-9で実行（gcc version 9.3.0），g++だとデフォルトのclang

using namespace std;

//#define int long long                         //intでオーバフローした時の切り替え用
#define OUT(x) std::cout << x << std::endl
#define DEBUG(x) cerr << #x << ": " << x << endl //エラー出力として変数名と変数の中身表示
#define DEBUG_VEC(v)                   \
    cerr << #v << ":";                 \
    for (int i = 0; i < v.size(); i++) \
        cerr << " " << v[i];           \
    cerr << endl;
#define DEBUG_MAT(v)                          \
    cerr << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cerr << v[i][j] << " ";           \
        }                                     \
        cerr << endl;                         \
    }
#define Sp(p) cout << setprecision(25) << fixed << p << endl; //小数点以下を25桁で表示
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back

//usingエイリアス（別名という意味，型定義のこと）
using ll = long long;
//template <class T> using Vec = std::vector<T>;//エイリアステンプレート

const ll MOD = (ll)1e9 + 7;
//const ll MOD = 998244353;あ
const ll INF = (ll)1e18 + 1;
const double EPS = 1e-9;
const long double pi = 3.1415926535897932384626433832795028841971L;

//マクロでintをlong longと定義したときはsinged
int main()
{
    cin.tie(0);                  //cinとcoutの同期を切る（高速化)
    ios::sync_with_stdio(false); //iostreamとstdioの同期を切る（高速化)

    int n;
    string s;
    cin >> n ;
    vector<int> result(4,0);
    for (int i=0;i<n;i++){
        cin >> s;
        if (s=="AC") result[0]++;
        else if (s=="WA") result[1]++;
        else if(s=="TLE") result[2]++;
        else result[3]++;
    }
    OUT("AC x " + to_string(result[0]));
    OUT("WA x " + to_string(result[1]));
    OUT("TLE x " + to_string(result[2]));
    OUT("RE x " + to_string(result[3]));
    
    return 0;
}

Measured memory_bytes: 3724
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut count = 0;
    for _ in 0..n {
        let h: usize = sc.read();
        if h >= k {
            count += 1;
        }
    }
    println!("{}", count);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
  vector<int> vec(3);
  for(int i = 0; i < 3; i++) {
    int x;
    cin >> x;
    vec[i] = x;
  }
  sort(vec.begin(), vec.end());
  cout << vec[0] + vec[1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());

    for(int i=0; i<N-1; i++){
        if(vec.at(i) == vec.at(i+1)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
def solve(s):
    n = len(s)
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            return '{} {}'.format(i + 1, i + 2)

    for i in range(n - 2):
        if s[i] == s[i + 2]:
            return '{} {}'.format(i + 1, i + 3)

    return '-1 -1'


s = input()
print(solve(s))


Measured memory_bytes: 3188
N = int(input())
csf = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    t = csf[i][0]+csf[i][1]
    for j in range(i+1, N-1):
        if t <= csf[j][1]:
            t = csf[j][1]
        else:
            t = (t+csf[j][2]-1)//csf[j][2] * csf[j][2]
        t += csf[j][0]
    print(t)
print(0)


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

int main(){
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    ll ans=0,mx=a[0];
    for(ll i=1;i<n;i++){
        if(a[i]<mx) ans+=mx-a[i];
        mx=max(mx,a[i]);
    }  
    cout<<ans<<endl;
    return 0;
}


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

bool is_prime(int64_t n) {
    if (n == 1) return false;
    for (int64_t i = 2; i * i <= n; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

// 素因数分解(素因数の数値とその回数のペア)
template <typename T>
std::vector<std::pair<T, T> > prime_factorize_pair(T N) {
    std::vector<std::pair<T, T> > res;
    for (T a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        T ex = 0; // 指数
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        // その結果を push
        res.emplace_back(a, ex);
    }
    // 最後に残った数について
    if (N != 1) res.emplace_back(N, 1);
    return res;
}

// 素因数分解(素因数の数値の一覧)
template <typename T>
std::vector<T> prime_factorize_list(T N) {
  std::vector<T> res;
  const auto factors = prime_factorize_pair<T>(N);
  for (const auto& p: factors){
    for (int i = 0; i < p.second; ++i) {
      res.emplace_back(p.first);
    }
  }
  return res;
}

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

  // 素因数分解 (24 = (2^3) * (3^1))
  auto factors = prime_factorize_pair(N);
  if (factors.size() == 0) {
    cout << 0 << endl;
    return 0;
  }

  // 一番大きな素因数の個数を求めておく
  int maxCoef = 0;
  for (const auto& f: factors) {
    if (maxCoef < f.second) {
      maxCoef = f.second;
    }
  }

  // 素因数分解した中から、最大の回数の条件に合う掛け算を求める
  // 未使用の最小約数で割り続ける
  int count = 0;
  for (int i = 1; i <= maxCoef; ++i) {
    for (auto& f: factors) {
      if (f.second >= i) {
        f.second-=i;
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define endl '\n'
#define el cout << endl
#define long long long
#define oo 1000000

const int N = 1e6;
int n;

int main()
{
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    int r, d, x;
    cin >> r >> d >> x;
    rep(i, 10)
    {
        x = x*r - d;
        cout << x << endl;
    }
}


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

int main(){
  int N;
  cin >> N;
  int a[N];
  int sumA = 0;
  int sumB = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  sort(a, a + N, greater<int>());
  for(int i = 0; i < N; i++){
    if(i % 2 == 0){
      sumA += a[i];
    }
    else{
      sumB += a[i];
    }
  }
  int ans = sumA - sumB;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	string s;
	cin >> s;
	for (char &c : s) if (c == '?') c = 'D';
	cout << s << '\n';
}

Measured memory_bytes: 3744
local a, b = io.read("*l"), io.read("*l")

local x = string.len(a)
local sum = 0

for i = 1, math.huge do

    if a == b then
        print("Yes")
        break
    else
        a = string.sub(a, -1) .. string.sub(a, 1, -2)
    end
    sum = sum + 1
    if sum == x then
        print("No")
        break
    end

end

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
#define LL long long
int a, b;
LL fac, ans;
int main () {
    scanf ("%d%d", &a, &b);
    if (b > a) swap (a, b);
    if (a == b) {
        fac = 1;
        for (int i = 1; i <= a; i++) {
            fac = fac * i % mod;
        }
        ans = 2 * fac * fac % mod;
    }
    else if (a == b + 1) {
        fac = 1;
        for (int i = 1; i <= b; i++) {
            fac = fac * i % mod;
        }
        ans = fac * a % mod * fac % mod;
    }
    else ans = 0;
    printf ("%lld\n", ans);
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

res = [0, 0]
cnt = [0]


def dfs(x):
    if len(x) == N:
        if all(u == v for u, v in zip(P, x)):
            res[0] = cnt[0]
        if all(u == v for u, v in zip(Q, x)):
            res[1] = cnt[0]
        cnt[0] += 1
        return

    for i in range(1, N + 1):
        if i not in x:
            x.append(i)
            dfs(x)
            x.pop()


dfs([])
print(abs(res[0] - res[1]))


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,W,w[101],v[101];
int dp[101][100005];
void solve(){
    cin>>n>>W;
    rep(i,1,n+1) cin>>w[i]>>v[i];
    rep(i,1,n+1){
        rep(j,0,W+1){
            dp[i][j]=dp[i-1][j];
            if(j>=w[i]) dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
        }
    }
    cout<<dp[n][W]<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 78464
#二項係数、順列準備
MAX_NUM = 5* 10**5 + 1
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
  fac[i] = fac[i-1] * i % MOD
  inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
  finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,k):
  if n < k:
    return 0
  if n < 0 or k < 0:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

def perm(n,k):
  if n < k:
    return 0
  if n < 0 or k < 0:
    return 0
  return fac[n] * finv[n-k] % MOD

#主計算
N, M = map(int,input().split())

ans = 0
for K in range(N+1):
  term = comb(N, K) * perm(M, K) 
  term *= perm(M - K, N - K)**2
  term %= MOD
  if K % 2 == 0:
    ans = (ans + term) % MOD
  else:
    ans = (ans - term) % MOD
    
print(ans)

Measured memory_bytes: 68216
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        int[] ans=new int[n];
        for(int i=0;i<26;i++){
            if(s.contains(Character.toString((char)(97+i)))){
                ans[s.indexOf((char)(97+i))]++;
                ans[s.lastIndexOf((char)(97+i))]--;
            }
        }
        int finalans=ans[0];
        for(int i=1;i<n;i++){
            finalans=Math.max(finalans,ans[i]+=ans[i-1]);
        }
        System.out.println(finalans);

    }
}

Measured memory_bytes: 23892
N,A,B,K=map(int,input().split())
mod=998244353

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod

inverseFactorial=[1]*(N+1)
inverseFactorial[N]=power(Factorial[N],mod-2)
for i in range(0,N)[::-1]:
  inverseFactorial[i]=(inverseFactorial[i+1]*(i+1))%mod
  
def comb(x,y):
  if x<y:
    return 0
  return (Factorial[x]*inverseFactorial[y]*inverseFactorial[x-y])%mod
      
ans=0  
for i in range(K//A+1):
  if (K-A*i)%B==0:
    j=(K-A*i)//B
    ans+=comb(N,i)*comb(N,j)
    ans%=mod
  

    
print(ans%mod)

  

Measured memory_bytes: 73540
from sys import stdin
from collections import defaultdict

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = defaultdict(int)

for i in range(N):
    tmp = 1
    a = A[i]
    g_tmp = defaultdict(int)
    while tmp <= A[i] ** 0.5:
        cnt = 0
        while tmp > 1 and a % tmp == 0:
            a //= tmp
            cnt += 1
        if cnt > 0:
            g_tmp[tmp] = max(g_tmp[tmp], cnt)
        tmp += 1
    for j in g_tmp:
        g[j] = max(g[j], g_tmp[j])
    if a > 1:
        if a not in g:
            g[a] = 1

l = 1
ans = 0
for i in g:
    l *= pow(i, g[i], mod)
    l %= mod
for a in A:
    ans += l * pow(a, mod - 2, mod)
    ans %= mod

print(ans)

Measured memory_bytes: 51932
//q055.cpp
//Tue Aug 25 22:09:54 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	multiset<int> ms;
	rep(i,n){
		auto itr = ms.lower_bound(a[i]);
		if(itr != ms.begin()){
			itr--;
			ms.erase(itr);
		}
		ms.insert(a[i]);
	}

	cout << ms.size() << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 8684
S, T = input(), input()
cnt1, cnt2, r1, r2 =[], [], [], []
for c in S:
    if not c in r1:
        cnt1.append(S.count(c))
        r1.append(c)
for c in T:
    if not c in r2:
        cnt2.append(T.count(c))
        r2.append(c)
cnt1.sort()
cnt2.sort()
if cnt1 == cnt2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
def main():
    ret = 0
    n = int(input())
    a = list(map(int, input().split()))
    current = a[0]
    temp = 1
    for i in a[1:]:
        if i != current:
            ret += temp // 2
            temp = 1
            current = i
        else:
            temp += 1
    print(ret + temp // 2)
    return 0
main()

Measured memory_bytes: 3316
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  char b; cin >> b;
  if (b=='A'){cout << "T" << endl;}
  else if (b=='T'){cout << "A" << endl;}
  else if (b=='G'){cout << "C" << endl;}
  else if (b=='C'){cout << "G" << endl;}

  return 0;
}


Measured memory_bytes: 256
num = int(input())
num_list = input().split(' ')
num_list[0] = int(num_list[0])
for i in range(num):
    num_list[i] = int(num_list[i])
count = 0
for i in range(num):
    if num_list[i] != i+1:
        count = count +1
if count > 2:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N, K = LI()
    h_list = LI()

    cnt = 0
    for h in h_list:
        if h >= K:
            cnt += 1
    print(cnt)

solve()

Measured memory_bytes: 11896
//#define DEBUG
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
const int inf = 0X3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int mod = 1000000007;
typedef long long ll;

int h, a;

int main() {
    while(cin >> h >> a) {
        int ans = 0;
        if (h % a) {
            ans = h / a + 1;
        } else ans = h / a;
        cout << ans << '\n';
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n; cin >> n;
  vector<long> monster(n+1);
  long answer = 0;
  for(int i=0; i<n+1; i++) cin >> monster.at(i);
  for(int i=0; i<n; i++){
    int a; cin >> a;
    if(monster.at(i)>=a){
      answer += a;
    }
    else if(monster.at(i)+monster.at(i+1)>=a){
      answer += a;
      monster.at(i+1) = monster.at(i)+monster.at(i+1)-a;
    }
    else{
      answer += monster.at(i)+monster.at(i+1);
      monster.at(i+1) = 0;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

template <class T, class F>
T LowerBound(T i0, T i1, F f) {
    while (i0 < i1) {
        T i = (i0 + i1) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

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

    vector<int> a(n), r(n * 2);

    auto f = [&]() -> int {
        cout << '?';
        for (int i = 0; i < n; i++) {
            cout << ' ' << a[i] + 1;
        }
        cout << endl;

        static string s;
        cin >> s;
        return s == "Blue";
    };

    for (int i = 0; i < n; i++) {
        a[i] = i + n;
    }
    int b = f();

    int j = LowerBound<int>(1, n, [&](int j) {
        for (int i = 0; i < n; i++) {
            a[i] = i + j;
        }
        return f() == b;
    }) - 1;

    r[j] = b ^ 1;
    r[j + n] = b;

    for (int i = 1; i < n; i++) {
        a[i] = i + j;
    }
    for (int i = 1; i < n; i++) {
        a[0] = (i + j + n) % (n * 2);
        r[a[0]] = f();
    }

    for (int i = 1; i < n; i++) {
        a[i] = (i + j + n) % (n * 2);
    }
    for (int i = 1; i < n; i++) {
        a[0] = i + j;
        r[a[0]] = f();
    }

    cout << "! ";
    for (int i = 0; i < n * 2; i++) {
        cout << "RB"[r[i]];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 724
D,G = list(map(int,input().split()))
PC = [list(map(int, input().split())) for _ in range(D)]

def all_green(t,s):
    if t == -1:
        return float('inf')
    num = min(PC[t][0],s//(100*(t+1)))
    k = num * 100 * (t+1)
    if num == PC[t][0]:
        k += PC[t][1]
    if k < s:
        num += all_green(t-1,s-k)
    return min(num,all_green(t-1,s))
print(all_green(D-1,G))

Measured memory_bytes: 3064
#include <stdio.h>

typedef struct {
    int x;
    int y;
} POINT;

int check_star(POINT *moto, POINT *saki, int check, int m, int n)
{
    int i, j;
    int dx, dy;
    int count;
    
    count = 0;
    for (i = 0; i < m; i++){
        dx = moto[0].x - moto[i].x;
        dy = moto[0].y - moto[i].y;
        for (j = 0; j < n; j++){
            if (dx == saki[check].x - saki[j].x && dy == saki[check].y - saki[j].y){
                count++;
                break;
            }
        }
    }
    
    if (count == m){
        return (1);
    }
    return (0);
}

int main(void)
{
    POINT star[200];
    POINT pic[1000];
    int dx, dy;
    int m, n;
    int i, j;
    
    while (1){
        scanf("%d", &m);
        
        for (i = 0; i < m; i++){
            scanf("%d%d", &star[i].x, &star[i].y);
        }
        
        if (m == 0){
            break;
        }
        
        scanf("%d", &n);
        
        for (i = 0 ; i < n; i++){
            scanf("%d%d", &pic[i].x, &pic[i].y);
        }
        
        dx = dy = 0;
        for (i = 0; i < n; i++){
            if (check_star(star, pic, i, m, n) == 1){
                dx = pic[i].x - star[0].x;
                dy = pic[i].y - star[0].y;
            }
        }
        
        printf("%d %d\n", dx, dy);
    }
    
    return (0);
}

Measured memory_bytes: 416
#include<bits/stdc++.h>
using namespace std;
int main(){

  
  int r;

  cin>>r;

  if(r<1200){
    cout<<"ABC"<<endl;
  }else if(r<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }

  return 0;

}


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

int main() {
  int N;
  cin >> N;
  for (int n = 1; n <= N; n++) {
    int cnt = 0;
    for (int x = 1; x * x < n; x++) {
      for (int y = 1; x * x + y * y + x * y < n; y++) {
        for (int z = 1; x * z + y * z + z * z <= n - x * x - y * y - x * y; z++) {
          if (x * x + y * y + z * z + x * y + y * z + z * x == n) cnt++;
        }
      }
    }
    cout << cnt << "\n";
  }
}

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

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

int main(){
	const int INF = 1e9;
	int H,N;
	cin >> H >> N;
	vector<P> M(N+1);
	rep(i,N){ int a,b; cin >> a >> b; M[i+1] = make_pair(a,b); }
	vector<vector<int>> dp(H+1, vector<int>(N+1,INF));
	for(int i=1; i<=H; i++){
		for(int j=1; j<=N; j++){
			int attack = M[j].first;
			int cost = M[j].second;
			if(i<=attack){
				dp[i][j] = min(dp[i][j-1], cost);
			}else{
				dp[i][j] = min(dp[i][j-1], dp[i-attack][j]+cost);
			}
		}
	}

	cout << dp[H][N] << endl;


	return 0;
}

Measured memory_bytes: 39680
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

const int MAX_SIZE = 1000010; // 10000010でもよさそう？
bool isprime[MAX_SIZE];
vector<int> prime_num;

void init() {
  fill(isprime, isprime+MAX_SIZE, true);
  isprime[0] = isprime[1] = false;
  for (auto i=2; i<MAX_SIZE; i++) {
    if (isprime[i]) {
      prime_num.push_back(i);
      for (auto j=2; i*j<MAX_SIZE; j++) {
        isprime[i*j] = false;
      }
    }
  }
}

bool prime(long long x) { // 2 \leq x \leq MAX_SIZE^2
  if (x < MAX_SIZE) {
    return isprime[x];
  }
  for (auto e : prime_num) {
    if (x%e == 0) return false;
  }
  return true;
}

int main () {
  init();
  int Q;
  cin >> Q;
  int l[100010], r[100010];
  for (auto i = 0; i < Q; ++i) {
    cin >> l[i] >> r[i];
  }
  int ok[100010];
  for (auto i = 0; i < 100010; ++i) {
    if (i%2 == 1 && isprime[i] && isprime[(i+1)/2]) {
      ok[i] = 1;
    } else {
      ok[i] = 0;
    }
  }
  for (auto i = 0; i < 100009; ++i) {
    ok[i+1] += ok[i];
  }
  for (auto i = 0; i < Q; ++i) {
    cout << ok[r[i]] - ok[l[i]-1] << endl;
  }
}


Measured memory_bytes: 3192
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=input().rstrip()
print("ABC"+n)

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

int main(void)
{
    int K, N;
    cin >> K >> N;

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

    int dist, maxDist, totalDist;
    totalDist = K - A[N - 1] + A[0];
    maxDist = K - A[N - 1] + A[0];
    for (int i = 0; i < N - 1; ++i) {
        dist = A[i + 1] - A[i];
        totalDist += dist;
        if (maxDist < dist) maxDist = dist;
    }

    cout << totalDist - maxDist << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
 int a,b,c,k,i=1,ct=0,ans;
 cin >>a>>b>>k;
 vector<int> data(100);

while(true){
  if(a%i==0 && b%i==0){
    data.at(ct)=i;
    ct++;
  }
    if(i>a || i>b){
      break;
    }
  i++;
}
 ans=data.at(ct-k);
 cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
main = interact $ show . process . read
process n 
	| even m = b $ m 
    | otherwise = ( a n m ) + ( b $ m - 1 )
	where
    	m = k n
    	k 0 = 0
        k t = 1 + (k $ div t 10)
        a n m = n + 1 - (10 ^ (m - 1))
        b x = div ( 10 ^ x - 1 ) 11

        

Measured memory_bytes: 508
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

total = 0
temp = float("inf")
for i in range(n):
  if a[i] == temp + 1:
    total += c[a[i - 1] - 1]
  temp = a[i]
  total += b[a[i] - 1]
print(total)

Measured memory_bytes: 3064
n, d = map(int, input().split())

#print(n, d)

x = []
y = []

for i in range(n):
    tempx, tempy = map(int, input().split())
    x.append(tempx)
    y.append(tempy)

count = 0


for i in range(n):
    if(d ** 2 >= x[i] ** 2 + y[i] ** 2):
        count += 1

print(count)


Measured memory_bytes: 24580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,X;
  cin >> A >> B >> X;
  if(A+B-1-X >= 0 && A <= X){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main() {
    int a, b, c ;
    cin >> a >> b >> c ;
    if (a > b){
        swap(a, b);
    }
    if (b > c){
        swap(b, c);
    }
    if (a > b){
        swap(a, b);
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3092
N = int(input())
A = [int(i) for i in input().split()]

f, t, o = 0, 0, 0
for a in A:
    if a % 4 == 0:
        f += 1
    elif a % 2 == 0:
        t += 1
    else:
        o += 1

if o <= f + (t == 0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
import math
s = input()
count = 0

if len(s) % 2 == 0:
    x = len(s) // 2
else:
    x = math.floor(len(s) / 2)

for i in range(x):
    if s[i] != s[len(s)-1-i]:
        count += 1

print(count)


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

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-8;
const double pi=acos(-1.0);
const int K=1e6+7;
const int mod=1e9+7;

int n,a,b,c,ans;

int main(void)
{
    scanf("%d",&n);
    for(int i=1,x;i<=n;i++)
    {
        scanf("%d",&x);
        if(x%4==0) c++;
        else if(x%2==0) b++;
        else a++;
    }
    c-=a;
    if(c>=0||(c==-1&&b==0)) puts("Yes");
    else    puts("No");
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, C) = readLine()!!.split(" ").map { it.toInt() }
    val D = mutableListOf<IntArray>()
    val c = mutableListOf<IntArray>()
    (1..C).forEach {
        val d = readLine()!!.split(" ").map { it.toInt() }
        D.add(d.toIntArray())
    }
    (1..N).forEach {
        val ci = readLine()!!.split(" ").map { it.toInt() }
        c.add(ci.toIntArray())
    }




    val zeroMod3Scores = IntArray(C)
    val oneMod3Scores = IntArray(C)
    val twoMod3Scores = IntArray(C)

    // O(CN^2)
    (1..C).forEach { to ->
        var costZero = 0
        var costOne = 0
        var costTwo = 0
        (0 until N).forEach { x ->
            (0 until N).forEach { y ->
                val sum = (x + 1) + (y + 1)
                val from = c[x][y]
                val cost = D[from -1][to - 1]
                if (sum % 3 == 0) {
                    costZero += cost
                } else if (sum % 3 == 1) {
                    costOne += cost
                } else {
                    costTwo += cost
                }
            }
        }
        zeroMod3Scores[to - 1] = costZero
        oneMod3Scores[to - 1] = costOne
        twoMod3Scores[to - 1] = costTwo
    }

    var minCost = Int.MAX_VALUE
    // O(C^3)
    (0 until C).forEach {i ->
        (0 until C).forEach {j ->
            (0 until C).forEach {k ->
                if (i != j && j != k && k != i) {
                    minCost = Math.min(minCost,
                            zeroMod3Scores[i] + oneMod3Scores[j] + twoMod3Scores[k]
                    )
                }
            }
        }
    }
    println(minCost)
}


Measured memory_bytes: 50956
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

const ll mod = 1e9 + 7;

ll extgcd(ll a, ll b, ll&x, ll&y)
{
  if (b == 0)
  {
    x = 1;
    y = 0;
    return a;
  }
  else
  {
    ll q = a / b;
    ll g = extgcd(b, a - q * b, x, y);
    ll z = x - q * y;
    x = y;
    y = z;
    return g;
  }
}

//modp逆元
ll inversemod(ll a, ll p)
{
  ll x, y;
  extgcd(a, p, x, y);
  x %= p;
  if (x < 0)
  {
    x += p;
  }
  return x;
}

ll power_ll_p(ll a, ll b, ll p)	//F_pでのべき
{
  if (b > p)
  {
    b %= (p - 1);//位数p-1
  }
  if (b == 0)
  {
    return 1;
  }
  if (b % 2 == 0)
  {
    ll t = power_ll_p(a, b / 2, p);
    return t * t % p;
  }
  else
  {
    return a * power_ll_p(a, b - 1, p) % p;
  }
}

ll combination_p(ll n, ll r, ll p)	//コンビネーション
{
  if (r > n - r)
  {
    r = n - r;
  }
  ll ans = 1;
  for (ll i = 0; i < r; i++)
  {
    ans *= n - i;
    ans %= p;
  }
  ll subans = 1;
  for (ll i = 0; i < r; i++)
  {
    subans *= i + 1;
    subans %= p;
  }
  ans *= power_ll_p(subans, p - 2, p);		//逆元は^(p-2)
  ans %= p;
  return ans;
}

int main()
{
  ll x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0 || x > 2 * y || y > 2 * x)
  {
    cout << 0 << "\n";
  }
  else
  {
    ll n = (x + y) / 3;
    ll m = x - n;
    cout << combination_p(n, m, mod) << "\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, Q; 
	cin >> N >> Q; 
	string S; 
	cin >> S; 
	bool AC[100010] = {}; 
	int T[100010] = {}; 
	for(int i = 1; i <= N-1; i++){
		if(S.at(i-1) == 'A' && S.at(i) == 'C')
			AC[i] = true; 
		T[i] = T[i-1]; 
		if(AC[i]) T[i] ++; 
	}
	for(int i = 0; i < Q; i++){
		int L, R; 
		cin >> L >> R; 
		cout << T[R-1] - T[L-1] << endl; 
	}
}

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

using namespace std;


#define PI 3.14159265
#define int long long

int n, k;

bool f(int m, vector <int> &a){


	vector <int> p(n);

	for(int i = 0; i < n; i++){
		p[i] = a[i] % m;
	}

	sort(p.begin(), p.end());


	for(int i = 1; i < n; i++){
		p[i] += p[i - 1];
	}

	int record = 1e9;

	for(int i = 0; i < n; i++){
		if(0 == (n - i - 1) * m - p[n - 1]){
			record = min(record, p[i]);
		}

		if((i + 1) * m == p[n - 1]){
			record = min(record, p[n - 1] - p[i]);
		}
	}

	return record <= k;
}

main(){

	cin >> n >> k;

	vector <int> a(n);

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


	int sum = accumulate(a.begin(), a.end(), 0);

	set <int> s;

	for(int i = 1; i * i <= sum; i++){
		if(sum % i == 0){
			s.insert(i);
			s.insert(sum / i);
		}
	}

	int ans = 1;

	for(auto it : s){
		if(f(it, a)){
			ans = max(ans, it);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ; 
    cin >> n ; 
    for(int i = 1000; ; i+= 1000){
        if ( i >= n ){
            cout << i - n << endl ;
            return 0 ;
        }
    }
    return 0; 
}

Measured memory_bytes: 3652
main = do
  n <- getLine
  case n of
    "a" -> putStrLn "vowel"
    "i" -> putStrLn "vowel"
    "u" -> putStrLn "vowel"
    "e" -> putStrLn "vowel"
    "o" -> putStrLn "vowel"
    otherwise -> putStrLn "consonant"

Measured memory_bytes: 380
use strict;
use warnings;
package SuffixArray;
sub sa_is(\@$);
sub sa_is(\@$){
	my@s=@{$_[0]};
	my$upper=$_[1];
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
	elsif($n==2){
		if($s[0]<$s[1]){
			return(0,1);
		}
		else{
			return(1,0);
		}
	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l=(0)x($upper+1);
	my@sum_s=(0)x($upper+1);
	for(0..$n-1){
		if($ls[$_]){
			$sum_l[$s[$_]+1]++;
		}
		else{
			$sum_s[$s[$_]]++;
		}
	}
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(0..$n-1){
			my$v=$sa[$_];
			$sa[$buf[$s[$v-1]]++]=$v-1if$v>=1&&!$ls[$v-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms_map=(-1)x($n+1);
	my$m=0;
	my@lms=();
	for(1..$n-1){
		if(!$ls[$_-1]&&$ls[$_]){
			$lms_map[$_]=$m++;
			push@lms,$_;
		}
	}
	@sa=$induce->(@lms);
	if($m>0){
		my@sorted_lms;
		for(@sa){
			push@sorted_lms,$_ if$lms_map[$_]!=-1;
		}
		my@rec_s=();
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms_map[$l]+1<$m?$lms[$lms_map[$l]+1]:$n;
			my$end_r=$lms_map[$r]+1<$m?$lms[$lms_map[$r]+1]:$n;
			my$same=1;
			if($end_l-$l!=$end_r-$r){
				$same=0;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$same=0if$l==$n||$r==$n||$s[$l]!=$s[$r];
			}
			$rec_upper++if!$same;
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper;
		}
		my@rec_sa=SuffixArray::sa_is(@rec_s,$rec_upper);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array(\$){
	my@s=map ord,split"",${$_[0]};
	return sa_is(@s,255);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array(\$\@){
	my@s=map ord,split"",${$_[0]};
	return lcp(@s,@{$_[1]});
}
package main;
my$s=<>;
chomp$s;
my@sa=SuffixArray::suffix_array($s);
my@lcp=LcpArray::lcp_array($s,@sa);
my$ans=@sa*(@sa+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


Measured memory_bytes: 252584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)




int main() {
	int N, K, Q; cin >> N >> K >> Q;
	vector<int> P(N + 1);
	rep(i, Q) {
		int a; cin >> a;
		P[a]++;
	}
	rep (i, N + 1) {
		if (i == 0) continue;
		if (K - ((Q - P[i])) > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 1024