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

int main() 
{	

	int n;
	scanf("%d", &n);

	int pos = -1, mab = -1, vp = -1;
	for(int i = 1; i<=n; i++){
		int val;
		scanf("%d", &val);
		if(abs(val) > mab) pos = i, mab = abs(val), vp  = val;
	}

	printf("%d\n", 2*n);

	if(vp>=0){

		printf("%d 1\n", pos);
		printf("%d 1\n", pos);

		for(int i = 2; i<=n; i++){
			printf("%d %d\n", i-1, i);
			printf("%d %d\n", i-1, i);
		}

	}else{

		printf("%d %d\n", pos, n);
		printf("%d %d\n", pos, n);

		for(int i = n-1; i>0; i--){
			printf("%d %d\n", i + 1 , i );
			printf("%d %d\n", i  + 1, i );
		}

	}

    return 0;
}


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

int main() {
long long  n,m;
cin >>n >>m;
vector<pair<long long ,long long >>a(n);
for(long long  i=0;i<n;i++){
    long long  aa,aaa;
    cin >> aa >>aaa;
    a.at(i)=make_pair(aa,aaa);
}
sort(a.begin(),a.end());
long long j=0;
long long che=0;
for(long long  i=0;i<m;i++){
if(a.at(j).second==0)j++;
    a.at(j).second--;
    che+=a.at(j).first;
}
cout <<che <<endl;
}



Measured memory_bytes: 1792
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, c = LI()
clock_pos = []
value = []
for pos, v in LIR(n):
    clock_pos += [pos]
    value += [v]


rounding_max = [0]
counter_rounding_max = [0]
return_max = [0]
counter_return_max = [0]
ret = 0
counter_ret = 0
for i in range(n):
    ret += value[i]
    counter_ret += value[-i - 1]
    rounding_max += [max(rounding_max[-1], ret - clock_pos[i])]
    counter_rounding_max += [max(counter_rounding_max[-1], counter_ret - (c - clock_pos[-i - 1]))]
    return_max += [max(return_max[-1], ret - clock_pos[i] * 2)]
    counter_return_max += [max(counter_return_max[-1], counter_ret - (c - clock_pos[-i - 1]) * 2)]



ans = max(rounding_max[-1], counter_rounding_max[-1])
for j in range(1, n + 1):
    ans = max(ans, return_max[j] + counter_rounding_max[n - j], counter_return_max[j] + rounding_max[n - j])


print(ans)

Measured memory_bytes: 89948
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int main(){
  int H,W,D; cin >> H >> W >> D;
  vvi a(H,vi(W));
  rep(h,H) rep(w,W){
    cin >> a[h][w];
    a[h][w]--;
  }

  vector<pii> C(H*W);
  rep(h,H) rep(w,W) {
    C[a[h][w]] = mp(h,w);
  }

  vi S(H*W);
  rep(i,H*W) {
    if(i+D < H*W){
      int h = C[i].first;
      int w = C[i].second;
      int nh = C[i+D].first;
      int nw = C[i+D].second;
      S[i+D] = S[i] + abs(h-nh) + abs(w-nw);
    }
  }



  int Q; cin >> Q;
  while(Q--){
    int l,r; cin >> l >> r;
    l--; r--;
    cout << S[r] - S[l] << endl;
  }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
const ll MOD = 1000000007;

int main() {
    priority_queue<ll> que;
    int n,m;
    cin >> n >> m;
    rep(i,n) {
        int a;
        cin >> a;
        que.push(a);
    }
    while(m > 0) {
        ll tmp = que.top()/2;
        que.pop();
        que.push(tmp);
        m--;
    }
    ll ans = 0;
    rep(i,n) {
        ans += que.top();
        que.pop();
    }
    cout << ans;
}

Measured memory_bytes: 1400
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
int n,b,a,L;
ld c,r,d[41],ans=100000;
int main(void){
    while(1){
    cin>>r>>n;
    if(r==0&&n==0)return 0;
    ans=100000;
    for(int i=0;i<41;i++)d[i]=0;
    for(int i=0;i<n;i++){
        cin>>a>>b>>c;
        for(int j=a;j<b;j++){
            //d[j+20]=min(c,d[j+20]);
            d[j+20]=max(c,d[j+20]);
        }
    }
    //for(int i=0;i<41;i++)if(d[i]==100000)d[i]=0;
    for(int i=0;i<=40;i++){
        ld l=i;
        if(l-20<0)L=19-l;
        else L=l-20;
        if(r<=L)continue;
        //cout<<r<<" "<<L<<ans<<" "<<"W"<<pow(r*r-L*L,0.5)<<" "<<d[i]<<endl;
        ans=min(ans,r-pow(r*r-L*L,0.5)+d[i]);
    }
    cout<<setprecision(10)<<ans<<endl;
    }
}



Measured memory_bytes: 3364
/**
 *    author:  tourist
 *    created: 12.12.2019 13:23:22       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long k, a, b;
  cin >> k >> a >> b;
  if (a >= k) {
    cout << 1 << '\n';
  } else {
    if (a > b) {
      cout << (k - a + (a - b) - 1) / (a - b) * 2 + 1 << '\n';
    } else {
      cout << -1 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
int s;	
int h;
int m;

scanf("%d", &s);
	
h = s / 3600;
m = (s / 60) % 60;
s = s % 60;
	
printf("%d:%d:%d\n", h, m, s);
	
return (0);

}

Measured memory_bytes: 592
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
S.append(0)
ans = 0
for i in range(q):
    j = 0
    key = (T[i])
    S[n] = key
    while S[j] != key:
        j += 1
    if j != n:
        ans += 1
print(ans)
        


Measured memory_bytes: 6332
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<char,string>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

char maxi(char a,char b){
    if(a>b) return a;
    else return b;
}

string narabi(int x){
    string ret="a";
    char y='a';
    rep(i,x){
        y +=1;
        ret=ret+y;
    }
    return ret;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<vector<P>> dp(n,vector<P>(0));
    dp[0]={P('a',"a")};
    rep(i,n-1){
        rep(j,dp[i].size()){
            for(char k='a';k<=dp[i][j].first+1;k +=1){
                dp[i+1].emplace_back(maxi(k,dp[i][j].first),dp[i][j].second+k);
            }
        }
    }
    vector<string> ans(0);
    for(auto x:dp[n-1]){
        ans.emplace_back(x.second);
    }
    sort(all(ans));
    for(auto x:ans) cout<<x<<endl;
}

Measured memory_bytes: 12656
import java.util.*;
import java.lang.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        if(x < a){
            System.out.println(0);
        }else if(x >= a){
            System.out.println(10);
        }
        
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
typedef long long ll;
int N, C;
ll dp[400002], jmp[400002];
bool  val[400002];
vector<ll> occ[400002];
ll add(ll a, ll b){return (a+b)%1000000007L;}
ll mul(ll a, ll b){return (a*b)%1000000007L;}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    cin >> N;
    memset(val, false, N+1);
    for (int i=0;i<N;i++){
        cin >> C;
        // if (C >= 400001) {
        //     cout << -1 << endl;
        //     return 0;
        // }
        val[C] = true;
        occ[C].push_back(i);
    }
    memset(jmp, -1, N+1);
    for (int i=1;i<=200000;i++){
        if (!val[i]) continue;
        for (int j=0;j<occ[i].size()-1;j++){
            // if (occ[i][j]>=N || occ[i][j]<0 ) {
            //     cout << -1 << endl;
            //     return 0;
            // }
            jmp[occ[i][j]] = occ[i][j+1];
        }
    }
    memset(dp, 0, N+1);
    dp[0] = 1;
    for (int i=0;i<N-1;i++){
        dp[i+1] = add(dp[i+1], dp[i]);
        if (jmp[i]!=-1 && jmp[i]!=(i+1) && jmp[i]<N){
            if (jmp[i]>=N) {
                cout << -1 << endl;
                return 0;
            }
            dp[jmp[i]] = add(dp[jmp[i]], dp[i]);
        }
    }   
    cout << dp[N-1] << endl;
}

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

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    vector<int> ans(n,0);
    x--;y--;
    rep(i,n){
        for(int j=i+1;j<n;++j){
            int diff=j-i;
            diff=min(j-i,abs(x-i)+1+abs(y-j));
            ans.at(diff)++;
        }
    }
    for(int i=1;i<n;++i){
        cout<<ans.at(i)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main()
    {

        var N = int.Parse(Console.ReadLine());
        List<int> list = new List<int>();
        List<int> outPut = new List<int>();

        for (int i = 0; i < N; i++)
        {
            var tmp = int.Parse(Console.ReadLine());
            list.Add(tmp);
        }

        outPut.Add(list[0]);
        for (int i = 0; i < N; i++)
         {
            if (outPut.Last() < list[i])
            {
                outPut.Add(list[i]);
            }
            else
            {
                var index = outPut.FindIndex(n => n >= list[i]);
                if (index - 1 < 0)
                {
                    outPut[0] = list[i];
                }
                else
                {
                    outPut[index] = list[i];
                }
            }
        }

        Console.WriteLine(outPut.Count());

        //if (outPut.Count() > 1)
        //{
        //    Console.WriteLine(N - outPut.Count());
        //}
        //else
        //{
        //    Console.WriteLine(N - 1);
        //}
    }
}


Measured memory_bytes: 25016
var fs = require('fs')
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');

function main(){
	console.log(input[0].split(' ').map(Number).sort().join(' '));
}

main();


Measured memory_bytes: 15156
# B
n,d = map(int, input().split())
xi = [list(map(int, input().split())) for i in range(n)]
heihou = [i*i for i in range(200)]
count=0
for i in range(n-1):
    for j in range(i+1, n):
        total = 0
        for k in range(d):
            h = xi[i][k] - xi[j][k]
            hpow = h*h
            total+=hpow
        if total in heihou:
            count+=1
print(count)

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

int main(){

  int b1,b2,b3;
  cin >> b1 >> b2 >> b3;
  if(b1==1 && b2 == 0 && b3 == 0){
    cout << "Close" << endl;
  }
  if(b1==0 && b2==1 && b3==0){
     cout << "Close" << endl;
  }
  if(b1==1 && b2==1 && b3==0){
     cout << "Open" << endl;
  }
  if(b1==0 && b2==0 && b3==1){
     cout << "Open" << endl;
  }
  if(b1==0 && b2==0 && b3==0){
     cout << "Close" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>

int main() {
    int t; std::cin >> t;
    for (int i=0; i<t; i++) {
        int a[3];
        std::cin >> a[0] >> a[1] >> a[2];
        std::sort(std::begin(a), std::end(a));
        if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }
}



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

int main(){
 int d,t,s; cin>>d>>t>>s;
 if(d<=t*s) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
 return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <cstring>

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
typedef long long ll;

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

using namespace std;

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

    if(a <= 5){
        b = 0;
    }
    else if(a < 13){
        b /= 2;
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#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 pii=pair<int,int>;
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(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int 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 acm(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));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
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>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;}

void solve(int n){
	vs code(n);
	string s;
	int mx=0,ans=-1;
	rep(i,n){
		cin>>s;
		rep(j,s.size()){
			if(j==0||s[j-1]=='a'||s[j-1]=='i'||s[j-1]=='u'||s[j-1]=='e'||s[j-1]=='o')code[i].push_back(s[j]);
		}
		chmax(mx,(int)code[i].size());
	}
	range(i,1,mx+1){
		bool ok=true;
		rep(j,n)rep(k,n){
			if(j!=k&&code[j].substr(0,i)==code[k].substr(0,i))ok=false;
		}
		if(ok){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n)solve(n);
}



Measured memory_bytes: 3244
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define PI 3.1415926535897932384626433832795
#define F first
#define S second
#define V vector<ll>
#define ALL(sss) sss.begin(),sss.end()
#define arall(rr,n) rr+0,rr+n 
#define mod 1000000007
#define M 100
#define MAXN 1000000000

 
int dp[262145][2];
int ans=INT_MAX;
ll n;
using namespace std;


void fileio(){
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}




int main(){


     fileio();
    
   
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  

    ll T=1,q;
    //cin>>T;
    while(T--){

        ll n,k;cin>>n;
        ll a[n],b[n],c[n];
        for (int i = 0; i < n; ++i)
        {
            /* code */cin>>a[i]>>b[i]>>c[i];
        }

        ll dp[n+1][3];

        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];

        
        for (ll i = 1; i < n; ++i)
        {
            dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
        }

        cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});

        // cout<<"Case #"<<q<<": "<<ans<<endl;
    }
    
//prllf("%.9f\n", x);//precision: 9 decimal places.

/*
    GP SUM:(
    (bk)-a)/k-1;//k is ratio and b is final term, a is initial term;

    Comparing two decimal numbers

    if (abs(a-b) < 1e-9) {
        // a and b are equal
    }
*/
    return 0;
}


Measured memory_bytes: 8280
#include<iostream>
#include<cstdio>

using namespace std;
#define ll long long int

int m, n, l;
int main(){
    cin >> m >> n >> l;
    ll a[m + 1][n + 1];
    ll b[n + 1][l + 1];
    ll c[m + 1][l + 1];
    for(int i = 1; i <= m; ++i){
        for(int j = 1; j <= n; ++j){
            scanf("%lld",&a[i][j]);
        }
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= l; ++j){
            scanf("%lld",&b[i][j]);
        }
    }
    
    for(int i = 1; i <= m; ++i){
        for(int j = 1; j <= l; ++j){
            c[i][j] = 0;
            for(int k = 1; k <= n; ++k){
                c[i][j] += a[i][k] * b[k][j];
            }
            if(j < l) cout << c[i][j] << " ";
            else cout << c[i][j] << endl;
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 3392
#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 fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

// B

void solve() {

}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(i,n) {
    if( (i+1) % 2 == 1 && a[i] % 2 == 1  ) ++ans;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int number;
  number =0;
  int a,b,c,d,e;

  for(int i=A;i<B+1;i++){
    a=i/10000;
    b=(i/1000)%10;
    d=(i%100)/10;
    e=i%10;
    if(a==e&&b==d){
      number++;
    }
  }
  cout << number << endl;
}


Measured memory_bytes: 256
/* ===================================*/
/* Author :   Moshiur Rahman Mohim    */
/* Email  :   mtmohim74@gmail.com     */
/* Institute: HSTU                    */
/* ===================================*/

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>

#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using  namespace  std;

const int INF = 0x7f7f7f7f;

#define pi              acos(-1.0)
#define mod             1000000007
#define MAX             10000
#define FOR(i, b, n)    for(LL i=b; i<=n; i++)
#define FORR(i, n, b)   for(LL i=n; i>=b; i--)
// Library.
#define mem(a,b)        memset(a,b,sizeof(a))
#define Sort(x)         sort(x.begin(),x.end())
#define Reverse(x)      reverse(x.begin(),x.end())
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a * (b / gcd(a,b)))
#define sq(x)           (x)*(x)
// File.
#define READ(f)         freopen(f, "r", stdin)
#define WRITE(f)        freopen(f, "w", stdout)
// i/o.
#define sf              scanf
#define pf              printf
#define pr1(x)          cout<<x<<"\n"
#define pr2(x,y)        cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z)      cout<<x<<" "<<y<<" "<<z<<"\n"
// Test Case.
#define TEST(i,t)       LL i,t;scanf("%lld",&t);for(i=1;i<=t;i++)

typedef unsigned int            U;
typedef long int                L;
typedef unsigned long int       LU;
typedef long long int           LL;
typedef unsigned long long int  LLU;
typedef float                   F;
typedef double                  LF;
typedef char                    C;

//STL
typedef vector<LL>vl;
typedef pair<int,int>pii;
typedef pair<string,int>psi;
typedef pair<LL,LL>pll;
typedef pair<LF,LF>pdd;
typedef vector<pii> vpii;

/*.......Global Function.......*/
// Compute b^p%m
int BigMod(LL B,LL P,LL M)
{
    LL R=1;
    while(P>0)
    {
        if(P%2==1)
            R=(R*B)%M;
        P/=2;
        B=(B*B)%M;
    }
    return (int)R;
}
//Ugly Numbers
LL maxDivide(LL a,LL b)
{
    while(a%b==0)
        a=a/b;
    return a;
}
LL isUgly(LL no)
{
    no=maxDivide(no,2);
    no=maxDivide(no,3);
    no=maxDivide(no,5);
    return (no==1)?1:0;
}
//XOR of 2 Numbers
LL myXOR(LL x,LL y)
{
    LL res=0;
    FORR(i,31,0)
    {
        bool b1=x&(1<<i);
        bool b2=y&(1<<i);
        bool xoredBit=(b1&b2)?0:(b1|b2);
        res<<=1;
        res|=xoredBit;
    }
    return res;
}
/*............End............*/
/*.......Global Declaration.......*/
int main()
{
    //READ("input.txt");
    //WRITE("output.txt");
    LL n,m,x,y,a,b,c,s;
    cin>>a>>b>>c;
    x=c/2;
    y=c/2;
    if(c%2==1)
        y+=1;
    n=x*a*b;
    m=y*a*b;
    s=abs(m-n);

    x=a/2;
    y=a/2;
    if(a%2==1)
        y+=1;
    n=x*c*b;
    m=y*c*b;
    s=min(s,abs(m-n));

    x=b/2;
    y=b/2;
    if(b%2==1)
        y+=1;
    n=x*a*c;
    m=y*a*c;
    s=min(s,abs(m-n));
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
package main
import(
    "fmt"
    "sort"
)
func main(){
    // Your code here!
    var n int
    fmt.Scan(&n)
    var ws works = make([]work, n)
    for i := 0; i < n; i++{
        var a, n int
        fmt.Scan(&a, &n)
        ws[i] = work{a,n}
    }
    sort.Sort(ws)

    sum := int64(0)
    for _, w := range ws {
        sum += int64(w.time)
        if sum > int64(w.limit){
            fmt.Println("No")
            return
        }
    }
    fmt.Println("Yes")
}

type work struct{ time, limit int }
type works []work
 
func (w works) Len() int           { return len(w) }
func (w works) Swap(i, j int)      { w[i], w[j] = w[j], w[i] }
func (w works) Less(i, j int) bool { return w[i].limit < w[j].limit }


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

char s[22];

int main() {
	scanf("%s", s);
	FOR(i,4) printf("%c", s[i]);
	printf(" ");
	FOR(i,8) printf("%c", s[i+4]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
using namespace std;
int ac, wa, tle, re;
string s;
int main()
{
	int t;
	cin>>t;
	while(t--)
{
	cin>>s;
	if(s=="AC") ac++;
	else if(s=="WA") wa++;
	else if(s=="TLE") tle++;
	else re++;
}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#define NUM 100
int main(){

  char S[NUM], X[NUM], Y[NUM];
  int N, i, j, k, count, max;
  char alp[] = "abcdefghijklmnopqrstuvwxyz";
  int alpnum[26];

  max = 0;

  scanf("%d", &N);
  scanf("%s", S);

  if(N < 2) return(-1);

  for(i=0; i<N; i++){
    for(j=0; j<=i; j++){
      X[j] = S[j];
    }
    for(j=i+1; j<N; j++){
      Y[j] = S[j];
    }

    for(j=0; j<26; j++){
      alpnum[j] = 0;
    }

    for(j=0; j<=i; j++){
      for(k=0; k<26; k++){
        if(X[j] == alp[k] && alpnum[k] == 0)
          alpnum[k] = 1;
      }
    }

    for(j=i+1; j<=N; j++){
      for(k=0; k<26; k++){
        if(Y[j] == alp[k] && alpnum[k] == 1)
          alpnum[k] = 2;
      }
    }

    count = 0;

    for(j=0; j<26; j++){
      if(alpnum[j] == 2)
        count++;
    }

    if(max < count)
      max = count;
  }

  printf("%d\n", max);
}

Measured memory_bytes: 128
n,m=gets.chomp.split(" ").map { |e| e.to_i }

x=gets.chomp.split(" ").map { |e| e.to_i }.sort

if n >= m
    puts 0
    exit
end
d=[]

for i in 0..m-2 do
    d[i] = x[i+1] - x[i]
end

d = d.sort

ans = 0

for i in 0..m-n-1 do
  ans += d[i]
end

puts ans


Measured memory_bytes: 11896
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N, H, W;
	cin >> N >> H >> W;
	cout << (N - H + 1) * (N - W + 1) << "\n";
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int M = in.nextInt();
			List<Integer> list = new ArrayList<>();
			int tmp = 0;
		    for(int i = 0; i < N; i++) {
		    	tmp = in.nextInt();
		    	for(int j = 0; j < tmp; j++) {
		    		list.add(in.nextInt());
		    	}
		    }
		    int count = 0;
		    int ans = 0;
		    Collections.sort(list);
		    for(int i = 1; i < list.size(); i++) {
		    	if(list.get(i) == list.get(i - 1)) {
		    		count++;
		    		if(count == N - 1) {
		    			ans++;
		    		}
		    	}else {
		    		count = 0;
		    	}
		    }
		    if(N == 1) {
		    	ans = list.size();
		    }
		    out.println(ans);
		}
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


Measured memory_bytes: 23508
import queue
import numpy as np
n = int(input())
aa = list(map(int, input().split()))
aa.sort(reverse=True)
aa = np.array(aa, dtype=int)*-1
q = queue.PriorityQueue()
q.put(aa[0])
cnt = 0
for i in aa[1:]:
    cnt += q.get()
    q.put(i)
    q.put(i)

print(-cnt)

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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) {
        cin >> a.at(i);
    }

    vector<int> order(n + 1, -1);
    vector<int> city;
    int c = 1, l = 0;
    {
        int p = 1;
        while(order.at(p) == -1) {
            order.at(p) = city.size();
            city.push_back(p);
            p = a.at(p-1);
        } 
        c = city.size() - order.at(p);
        l = order.at(p);
    }

    if(k < l) cout << city.at(k) << endl;
    else {
        k -= l;
        k %= c;
        cout << city.at(l + k) << endl;
    }

    return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

vi solve(vi d) {
    vi ans;
    while(!d.empty()) {
        int t = -1;
        RREP(i, d.size()) {
            if (i == d[i]) {
                t = i;
                break;
            }
        }
        if (t == -1) {
            return vi(1, -1);
        }
        ans.push_back(t + 1);
        d.erase(d.begin() + t);
    }
    reverse(ALL(ans));
    return ans;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n){
        vi d(n);
        REP(i, n) {
            cin >> d[i]; d[i] --;
        }
        vi ans = solve(d);
        REP(i, ans.size()) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true)
    {
      int n = sc.nextInt();
      int x = sc.nextInt();
      if(n == 0 && x == 0) break;
      int count=0;
      for(int i=1; i<=n; i++)
      {
        for(int j=i+1; j<=n; j++)
        {
          for(int k=j+1; k<=n; k++)
          {
            if(i+j+k == x) count++;
          }
        }
      }
      out.println(count);
    }
  }
}


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

constexpr int MAX_N = 1e5;
int s[MAX_N+1];

int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  // 累積和
  for (int i{}; i < N - 1; ++i) {
    s[i + 1] = s[i] + (S[i] == 'A' && S[i+1] == 'C' ? 1 : 0);
  }
  s[N] = s[N-1];

  for (int i{}; i < Q; ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    cout << s[r] - s[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	pfs := make(map[int]int)
	for i := 1; i <= N; i++ {
		pfs = primeFactors(i, pfs)
	}
	var n3, n5, n15, n25, n75 int
	for _, num := range pfs {
		num++
		if 75 <= num {
			n75++
		}
		if 25 <= num {
			n25++
		}
		if 15 <= num {
			n15++
		}
		if 5 <= num {
			n5++
		}
		if 3 <= num {
			n3++
		}
	}
	ans := 0
	ans += n75
	ans += n25 * (n3 - 1)
	ans += n15 * (n5 - 1)
	ans += (n5 * (n5 - 1) / 2) * (n3 - 2)

	fmt.Fprintln(wtr, ans)
}

func primeFactors(n int, pfs map[int]int) map[int]int {
	for n%2 == 0 {
		pfs[2]++
		n = n / 2
	}
	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs[i]++
			n = n / i
		}
	}
	if n > 2 {
		pfs[n]++
	}

	return pfs
}


Measured memory_bytes: 640
#include <iostream>
#include <queue>

using namespace std;

int main(){
    int K; cin >> K;
    queue<long long> qu;
    for(int i=1;i<10;i++) qu.push(i);
    while(--K){
        auto t = qu.front(); qu.pop();
        int b = t%10;
        for(int i=max(0, b-1);i<=min(9, b+1);i++){
            qu.push(10 * t + i);
        }
    }
    cout << qu.front() << endl;
}

Measured memory_bytes: 5136
from sys import stdin
import sys
import math

A,B = [int(x) for x in stdin.readline().rstrip().split()]
N1=int(A*100/8)
N2=int(B*10)
for i in range(B*20):
    N1=math.floor(i*0.08)
    if N1==A:
        N2=math.floor(i*0.1)
        if N2==B:
              print(i)
              sys.exit(0)
print(-1)


Measured memory_bytes: 3060
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			final int n = sc.nextInt();
			
			int sum = 0;
			int pre = 0;
			
			int[] array = new int[n];
			for(int i = 0; i < n; i++){
				array[i] = sc.nextInt();
			}
			
			Arrays.sort(array);
			
			for(int i = 0; i < n; i++){
				sum += pre + array[i];
				pre += array[i];
			}
			
			System.out.println(sum);
		
		}
	}

}

Measured memory_bytes: 12000
N, P = map(int, input().split())
A = list(map(lambda a: int(a) % 2, input().split()))

if P == 1 and A.count(1) == 0:
    print(0)
    exit()

if P == 0 and A.count(1) == 0:
    print(2**N)
    exit()

print(2**(N - 1))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long dp[101][2][101] = { 0 };
int main() {
	string n;
	int ka;
	cin >> n >> ka;
	dp[0][0][0] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int k = 0; k < 101; k++) {
			dp[i + 1][1][k + 1] += dp[i][1][k] * 9;
			dp[i + 1][1][k] += dp[i][1][k];
		}
		for (int k = 0; k < 101; k++) {
			if (n[i] == '0') {
				dp[i + 1][0][k] += dp[i][0][k];
			}
			else {
				dp[i + 1][0][k + 1] += dp[i][0][k];
				dp[i + 1][1][k + 1] += dp[i][0][k] * int(n[i] - '0' - 1);
				dp[i + 1][1][k] += dp[i][0][k];
			}
		}
	}

	cout << dp[n.size()][0][ka] + dp[n.size()][1][ka] << endl;
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void){
  int i,N,c=0;
  scanf("%d",&N);
  int P[N],A[N];
  for(i=0;i<N;i++){
    scanf("%d",&P[i]);
    A[i] = i+1;
  }
  
  
  
  for(i=0;i<N;i++){
    //printf("%d %d\n",P[i],A[i]);
    if(P[i]!=A[i]){
      c++;
    }
  }
  
  //printf("%d\n",c);
  
  if(c==2 || c==0){
    printf("YES");
  }else{
    printf("NO");
  }
  
}

Measured memory_bytes: 128
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n=int(input())
a=list(map(int,stdin.readline().split()))
suff=defaultdict(lambda:0)
ans=0
for i in range(n-1,-1,-1):
    ans+=a[i]
    suff[n-i]=ans 
ans=0
# print(suff)
for i in range(n-1):
    ans+=a[i]*suff[n-i-1]
print(ans)

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100050

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2147483647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//


int DP[MAX];

//
int main(){
	int N,Q;
	string S;
	cin >> N >> Q >> S;
	
	REPS(i,1,N){
		DP[i]=DP[i-1];
		if(S[i-1]=='A' && S[i]=='C')++DP[i];
	}

	REP(i,Q){
		int l,r;cin >> l >> r;
		cout << DP[--r]-DP[--l] << endl;
	}



	return 0;
}




Measured memory_bytes: 1408
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    res = 1
    for a in A:
        res *= a
        if res > 10 ** 18:
            print(-1)
            break
    else:
        print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21788
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
	string s;
	cin>>s;
	if((s[2]==s[3])&&(s[4]==s[5]))
	{
		cout<<"Yes";
	}
	else cout<<"No";
}
signed main()
{
	
		/***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
		
	}
	TIME
	return 0;
}

Measured memory_bytes: 256
a, b, c= (int(i) for i in input().split())
if a <= b and a <= c:
    if b <= c:
        print(a,b,c)
    else:
        print(a,c,b)
elif b <= a and b <= c:
    if a <= c:
        print(b,a,c)
    else:
        print(b,c,a)

elif c <= a and c <=b:
    if  a <= b:
        print(c,a,b)
    else:
        print(c,b,a)
        


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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = y; x <= z; x++)
#define REPP(x, y, z) for(int x = y; x >= z; x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn 80+5

//structure

//declaration
int a[maxn][maxn];
int b[maxn][maxn];
bool dp[maxn][maxn][6400*2+10];
//functions


int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

	int h, w;
	MSET(dp, false);

	scanf("%d %d", &h, &w);

	REP(i, 1, h)
		REP(j, 1, w)
			scanf("%d", &a[i][j]);
	
	REP(i, 1, h)
		REP(j, 1, w)
			scanf("%d", &b[i][j]);

	dp[1][1][6400-abs(a[1][1]-b[1][1])] = true;
	dp[1][1][6400+abs(a[1][1]-b[1][1])] = true;

	REP(i, 1, h)
		REP(j, 1, w)
		{
			REP(k, 1, 6400*2+5)
			{
				if(dp[i][j][k])
				{
					// cout << i << ' ' << j << ' ' << k << endl;
					if(i+1 <= h)
					{
						dp[i+1][j][k+abs(a[i+1][j]-b[i+1][j])] = true;
						dp[i+1][j][k-abs(a[i+1][j]-b[i+1][j])] = true;
					}
					
					if(j+1 <= w)
					{
						dp[i][j+1][k+abs(a[i][j+1]-b[i][j+1])] = true;
						dp[i][j+1][k-abs(a[i][j+1]-b[i][j+1])] = true;
					}	
				}
			}
		}

	int ans = 1e9;

	REP(i, 0, 6400*2+5)
	{
		if(dp[h][w][i] == true)
		{
			// cout << i << ' ' << ans << endl;
			ans = min(ans, abs(i-6400));
		}
	}

	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int n,sum;
  cin >> n;
  int arr[n];
  int arr1[n];
  int arr2[n];
  for(int i = 0; i < n; i++){
    cin >> arr1[i];
  }
  for(int i = 0; i < n; i++){
    cin >> arr2[i];
  }
  for(int i = 0; i < n; i++){
    arr[i] = arr1[i] - arr2[i];
  }
  for(int i = 0; i < n; i++){
    if(arr[i] > 0){
      sum += arr[i];
    }
  }
  cout << sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(ALL(v))
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define ret return

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

int MAX(int a,int b){if(a>b){return a;}return b;}
int MIN(int a,int b){if(a<b){return a;}return b;}
int GCD(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){int c=GCD(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int POW(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
ll LLMAX(ll a,ll b){if(a>b){return a;}return b;}
ll LLMIN(ll a,ll b){if(a<b){return a;}return b;}
ll llGCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
ll llLCM(ll a,ll b){ll c=llGCD(a,b);a/=c;return a*b;}
ll llnCr(ll a,ll b){ll i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
ll llnHr(ll a,ll b){return llnCr(a+b-1,b);}
ll llpow(ll a,ll b){ll i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

   	int n, a[100010], k, max = -114514;
   	cin >> n >> k;
   	REP(i, n){
   		cin >> a[i];
   		if(a[i] > max) max = a[i];
   	}

   	if(k > max){
   		cout << "IMPOSSIBLE" << endl;
   		ret 0;
   	}
   	
   	REP(i, n){
   		if(k == a[i]){
   			cout << "POSSIBLE" << endl;
   			ret 0;
   		}
   	}

   	int gcd = GCD(a[0], a[1]);
   	FOR(i, 2, n) gcd = GCD(gcd, a[i]);

   	if(k % gcd == 0) cout << "POSSIBLE" << endl;
   	else cout << "IMPOSSIBLE" << endl;

	ret 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
const ll mod = 1e9 + 7;
int n;
ll a[N], b[N];
map<pair<ll, ll>, ll> mp;
ll ans = 1, cnt1, cnt2, cnt;
ll ksm(ll p, ll q) {
	ll ret = 1;
	while (q) {
		if (q & 1) ret = (ret * p) % mod;
		p = (p * p) % mod;
		q = q >> 1;
	}
	return ret;
}
ll f(ll x) {
	return ksm(2, x);
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] == 0 || b[i] == 0) {
			if (a[i] == 0 && b[i] == 0) {
				cnt++;
			} else if (a[i] == 0) {
				cnt1++;
			} else if (b[i] == 0) {
				cnt2++;
			}
			continue;
		}
		ll gcd = __gcd(a[i], b[i]);
		a[i] /= gcd;
		b[i] /= gcd;
		if (a[i] < 0) a[i] = -a[i], b[i] = -b[i];
		mp[make_pair(a[i], b[i])]++;
	}
	for (map<pair<ll, ll>, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second == 0) continue;
		ll u = it->first.first;
		ll v = it->first.second;
		ll now = f(mp[make_pair(u, v)]);
		v = -v;
		if (v < 0) v = -v, u = -u;
		if (mp.count(make_pair(v, u))) {
			now = (now + f(mp[make_pair(v, u)]) - 1) % mod;
			mp[make_pair(v, u)] = 0;
		}
		now = now % mod;
		ans = (ans * now) % mod;
	}
	ans = (ans * ((f(max(cnt1, cnt2)) + f(min(cnt1, cnt2)) - 1) % mod)) % mod;
	ans += cnt;
	cout << (ans - 1 + mod) % mod;
	return 0;
}

Measured memory_bytes: 19124