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

#define MAX_S 100000
#define MAX_T 100000

int N, M;
char S[MAX_S];
char T[MAX_T];

long long gcd(long long m, long long n)
{
	if( m < n ) {
		swap( m, n );
	}
	long long temp;
	while (m % n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

long long lcm(long long m, long long n)
{
	return m / gcd(m,n) * n;
}

int main() {

	cin >> N >> M;
	cin >> S >> T;
	long long L = lcm( N, M );
	long long ans = L;
	long long G = gcd( N, M );
	long long n = N / G;
	long long m = M / G;
	for( long long i = 0; i < G; i++ ) {
		if( S[i*n] != T[i*m] ) {
			ans = -1;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.TreeMap;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        String s = scanner.next();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'U' || c == 'D') continue;
            if (i % 2 == 1 && c == 'L') {
                continue;
            }
            if (i % 2 == 0 && c == 'R') {
                continue;
            }
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }
}



Measured memory_bytes: 23764
A = []
for i in [0]*3:
    A.append(list(map(int,input().split())))
N = int(input())
B = []
for i in [0]*N:
    B.append(int(input()))

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = -1

#ヨコ
for i in range(3):
    if A[i] == [-1,-1,-1]:
        print("Yes")
        exit()
#タテ
for i in range(3):
    if [A[0][i],A[1][i],A[2][i]] == [-1,-1,-1]:
        print("Yes")
        exit()
#ナナメ
if [A[0][0],A[1][1],A[2][2]] == [-1,-1,-1]:
    print("Yes")
    exit()
if [A[0][2],A[1][1],A[2][0]] == [-1,-1,-1]:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 9228
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        string w;
        cin >> w;

        sort(w.begin(), w.end());
        int cnt = 1;
        for (int i = 0; i < w.size() - 1; i++)
        {
                if (w[i] == w[i + 1])
                {
                        cnt++;
                }
                else
                {
                        if (cnt % 2 == 0)
                        {
                                cnt = 1;
                        }
                        else
                        {
                                cout << "No" << endl;
                                return 0;
                        }
                }
        }
        if (cnt % 2 != 0)
        {
                cout << "No" << endl;
        }
        else
        {
                cout << "Yes" << endl;
        }

        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n,m,k=0;
	cin>>n;
	m=n;
	while(n!=0)
	{
		k+=n%10;
		n/=10;
	}
	if(m%k==0) cout<<"Yes";
	else cout<<"No";
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  int buff;
  int max = *max_element(A.begin(), A.end());
  vector<int>::iterator maxIt = max_element(A.begin(), A.end());
  size_t maxIndex = distance(A.begin(), maxIt);
  A[maxIndex] = 1;
  int max2 = *max_element(A.begin(), A.end());
  
  for(int i=0; i<N; i++){
    if(i != maxIndex){
     cout << max << endl;
    }else{
     cout << max2 << endl;
    }
    
  } 
  
  return 0;
}



Measured memory_bytes: 2432
N = int(input())
S = [input() for _ in range(N)]
array1 = ['M', 'A', 'R', 'C', 'H']
array2 = [[] for _ in range(5)]

for i in S:
    if i[0] in array1:
        array2[array1.index(i[0])].append(i)

result = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            result += len(array2[i]) * len(array2[j]) * len(array2[k])

print(result)


Measured memory_bytes: 10648
#include<bits/stdc++.h>
#define ll long long

const ll mod = 1000000007 ;

bool isInteger(double n)
{
	if(floor(n)==ceil(n))
		return true ;
	return false ;
}

using namespace std ;

int main()
{
	int n;
	cin>>n;
	int x = n%10 ;
	if(x==2 || x==4 || x==5 || x==7 || x==9)
		cout<<"hon";
	else if(x==0 || x==1 || x==6 || x==8)
		cout<<"pon";
	else 
		cout<<"bon";
}


Measured memory_bytes: 3620
array = gets.chomp.split(' ').map(&:to_i)
a,b,c,d = false,false,false,false
array.each do |i|
  if i == 1
    a = true
  end
  if i == 9
    b = true
  end
  if i == 7
    c =true
  end
  if i == 4
    d =true
  end
end
  if a && b && c && d
    puts "YES"
  else
    puts "NO"
  end

Measured memory_bytes: 1788
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()
print(max(a) - min(a))

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

int main() {
	int n, x,cnt=1;
	int a,b=0;
	cin >> n >> x;
	for (int i = 0;i < n;i++) {
		cin >> a;
		b += a;
		if (b <= x) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
//reference:wtl666wtl
# include <stdio.h>
int a[103], b[103];
int main()
{
    int p1=0, p2=0, m=100;
    long long n;
    scanf("%lld",&n);
    ++n;
    while(n > 1)
    {
        if(n&1) a[++p1] = m--, --n;
        else b[++p2] = m--, n>>=1;
    }
    printf("%d\n",p1+p2<<1);
    for(int i=1; i<=p1; ++i)
        printf("%d ",a[i]);
    for(int i=p2; i>=1; --i)
        printf("%d ",b[i]);
    for(int i=101-p1-p2; i<=100; ++i)
        printf("%d ",i);
    puts("");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

bool dfs( int pos, int cnt );
vector< int > graph[SIZE];

int n, m;

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

    for( int i = 0; i < m; ++i ) {
        int a, b;
        cin >> a >> b;
        graph[a].pb( b );
        graph[b].pb( a );

    }
    bool res = dfs( 1, 0 );
    if( res ) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
    cout << endl;
    return 0;
}

bool dfs( int pos, int cnt ) {
    if( pos == n && cnt == 2 ) {
        return true;

    }
    if( cnt == 2 ) return false;

    for( int i = 0; i < graph[pos].size(); ++i ) {
        bool flg = dfs( graph[pos][i], cnt + 1 );
        if( flg ) return flg;

    }
    return false;
}


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

const int maxn = 2e3 + 5;
LL a[maxn],b[maxn][maxn];

int main(){
	int n;
	LL x,sum = 1LL << 60LL;
	cin >> n >> x;
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++){
		b[i][0] = a[i];
		for(int k = 1;k <= n - 1;k++){
			int pos = i - k;
			if(pos <= 0) pos = n - abs(pos);
			b[i][k] = min(b[i][k - 1],a[pos]);
		}
	}
	for(int k = 0;k <= n - 1;k++){
		LL ans = 0;
		for(int i = 1;i <= n;i++){
			ans += b[i][k];
		}
		sum = min(sum,ans + x * k);
	}
	cout << sum << endl;
}

Measured memory_bytes: 31616
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;

void main() {
  auto N = readln.chomp.to!int;
  auto Dn = readln.split.to!(int[]);

  int total = 0;
  foreach(i; 0..N) {
    for(int o=i+1; o<N; o++) {
      total += Dn[i] * Dn[o];
    }
  }

  writeln(total);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,a[1001],cnt=0,f=0;
  long int s=0;
  cin>>N>>M;
  for(int i=1;i<=N;i++)
  {
    cin>>a[i];
    s+=a[i];
  }
  
  for(int i=1;i<=N;i++)
  {  if (a[i]>=((float)s/(4*M)))
   { cnt++;
      if(cnt==M){f=1;break;}}
  }

  if (f==1)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	string s;
	cin>>a>>b>>s;
	bool f=true;
	for(int i=0;i<a;i++)
		if(!isdigit(s[i]))
			f=false;
	if(s[a]!='-')
		f=false;
	for(int i=a+1;i<s.size();i++)
		if(!isdigit(s[i]))
			f=false;
	if(f)
		cout<<"Yes";
	else
		cout<<"No";
 } 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> m(h);
    for (auto &e: m) cin >> e;

    vector<vector<int>> dp(h, vector<int>(w, 1e9));

    dp[0][0] = m[0][0] == '#' ? 1 : 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (i > 0) {
                int t = dp[i-1][j];
                if (m[i-1][j] == '.' && m[i][j] == '#') t++;
                dp[i][j] = min(dp[i][j], t);
            }
            if (j > 0) {
                int t = dp[i][j-1];
                if (m[i][j-1] == '.' && m[i][j] == '#') t++;
                dp[i][j] = min(dp[i][j], t);
            }
        }
    }

    cout << dp[h-1][w-1] << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
 
public class Main {
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    void solve() throws IOException {
    	String sa = ns();
    	String sb = ns();
    	String sc = ns();
    	
    	int turn = 0;
    	int ia = 0;
    	int ib = 0;
    	int ic = 0;
    	
    	while (true) {
    		if (turn == 0) {
    			if (ia == sa.length()) {
    				out.println("A");
    				break;
    			}
    			turn = sa.charAt(ia) - 'a';
    			ia++;
    		} else if (turn == 1) {
    			if (ib == sb.length()) {
    				out.println("B");
    				break;
    			}
    			turn = sb.charAt(ib) - 'a';
    			ib++;
    		} else {
    			if (ic == sc.length()) {
    				out.println("C");
    				break;
    			}
    			turn = sc.charAt(ic) - 'a';
    			ic++;
    		}
    	}
    }
 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 8144
S = input()
N=len(S) # 奇数
S1 = S[0:(N-1)//2]
S2 = S[(N+3)//2-1:]
S1_inv = S1[::-1]
S2_inv = S2[::-1]
S_inv = S[::-1]
if S1 == S1_inv and S2 == S2_inv and S==S_inv:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int sum = 0;
		int[] line = new int[3];

		for (int i = 0; i < 3; i++) {
			line[i] = sc.nextInt();
			sum += line[i];
		}

		int min = Integer.MAX_VALUE;

		for (int i = 0; i < 3; i++) {
			min = Math.min(min, sum-line[i]);
		}

		System.out.println(min);
	}

}


Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	int a;
	cin >> a;
	cout << a+a*a + a*a*a << endl;

	return 0;
}

Measured memory_bytes: 3628
import sys
n = int(input())
si = []
for _ in range(n):
    s = input()
    l = 0
    r = 0
    count = 0
    for i in range(len(s)):
        if s[i] == "(":
            count += 1
        else:
            count = max(0, count-1)
    l = count
    count = 0
    for i in range(len(s)-1, -1, -1):
        if s[i] == ")":
            count += 1
        else:
            count = max(0, count-1)
    r = count
    si.append((l, r))

if len(si) == 1:
    if si[0] == (0, 0):
        print("Yes")
        sys.exit()

index_l = -1
index_r = -1
maxi_l = 0
maxi_r = 0
for i in range(n):
    a, b = si[i]
    if a == 0:
        if maxi_l < b:
            maxi_l = b
            index_l = i
    if b == 0:
        if maxi_r < a:
            maxi_r = a
            index_r = i


count = 0
if index_r < index_l:
    count += si.pop(index_l)[1]
    last = si.pop(index_r)
else:
    last = si.pop(index_r)
    count += si.pop(index_l)[1]

minus = []
plus = []
while si:
    a, b = si.pop()
    if a <= b:
        plus.append((a, b))
    else:
        minus.append((a, b))

plus.sort()
minus.sort(reverse = True, key = lambda x: x[1])

for a, b in plus:
    if count >= a:
        count += b-a
    else:
        print("No")
        sys.exit()

for a, b in minus:
    if count >= a:
        count += b-a
    else:
        print("No")
        sys.exit()

count -= last[0]

if count == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 208312
#include <bits/stdc++.h>
#define mod 1000000007
#define fr first
#define val second
#define N 100000000
#define fo(i,m,n) for(int i=m;i<n;i++)
#define M 7
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
using ul=unsigned long long;
using pii=pair<int,int>;
using vvi=vector<vector<int>>;
using vi=vector<int>;
using pll=pair<ll,ll>;
using vsi=vector<set<int>>;
using vll=vector<ll>;

ll power(ll a,ll n){
    ll j=0;
    ll x=1;
    while(1ll<<j<=n){
        if(1ll<<j&n)
            x=(x*a)%mod;

        a=a*a%mod;
        j++;
    }

    return x;
}

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

}

int lb(vi &a,int x){
    int n=a.size();
    int l=0;
    int r=n-1;
    int ind=-1;
    while(l<=r){
        int mid=(l+r)/2;
        if(x>=a[mid]){
            l=mid+1;
            ind=mid;
        }
        else
            r=mid-1;

    }

    return ind+1;

}

int up(vll &a,ll x){
    int n=a.size();
    int l=0;
    int r=n-1;
    int ind=-1;

    while(l<=r){
        int mid=(l+r)/2;
        if(a[mid]>x){
            r=mid-1;
            ind=mid;
        }
        else
            l=mid+1;

    }

    return ind;
}

ll max(ll a,ll b){
    if(a>b)
        return a;
    else
        return b;

}

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

}
template<typename T>
void pra(T a[],int n){
    fo(i,0,n)
            cout<<a[i]<<' ';
    cout<<endl;

}


int b;
bool csf(pair<pii,int> &x,pair<pii,int> &y){
    if(x.first.first/b==y.first.first/b)
        return x.first.second<y.first.second;

    return x.first.first/b<y.first.first/b;
}
vi c;

void ext(int v[],int &cnt,int l,int r,int cl,int cr){
    for(int i=cl-1;i>=l;i--){
        v[c[i]]++;
        if(v[c[i]]==1)
            cnt++;

    }

    for(int i=cr+1;i<=r;i++){
       // cout<<i<<' ';
        v[c[i]]++;
        if(v[c[i]]==1)
            cnt++;

    }

    for(int i=cl;i<l;i++){

        v[c[i]]--;
        if(v[c[i]]==0)
            cnt--;

    }



}



int main(){

    fast_io
    int n,q;
    cin>>n>>q;
    c=vi(n+1);
    fo(i,1,n+1)
            cin>>c[i];

    b=sqrt(q)+500;

    vector<pair<pii,int>> queries;

    fo(i,0,q){
        int l,r;
        cin>>l>>r;
        queries.push_back({{l,r},i});

    }

    sort(queries.begin(),queries.end(),csf);
    int v[n+1];
    int cnt=0;
    int cl=0;
    int cr=0;
    fill(v,v+n+1,0);
    vi ans(q);
    fo(i,0,q){
        int l=queries[i].first.first;
        int r=queries[i].first.second;
        int ind=queries[i].second;
        if(r<cr){
            fill(v,v+n+1,0);
            cl=l;
            cr=l-1;
            cnt=0;
        }

        ext(v,cnt,l,r,cl,cr);
        cl=l;
        cr=r;
        //cout<<cnt<<' '<<ind<<endl;
        ans[ind]=cnt;

    }

    fo(i,0,q)
            cout<<ans[i]<<endl;



}


Measured memory_bytes: 15460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 素数判定O(√n)
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

int a[100010];

int main() {
    rep(i,100010){
        if(i%2==0) continue;
        if(is_prime(i) && is_prime((i+1)/2)) a[i]=1;
    }

    vector<int> s(100010,0);
    rep(i,100010) s[i+1]=s[i]+a[i];

    int q;
    cin>>q;
    while(q--){
        int l,r;
        cin>>l>>r;
        r++;
        cout<<s[r]-s[l]<<endl;
    }

    return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;

typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatirx;
typedef vector< string > SArray;
typedef vector< pii > PArray;

inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
const Double EPS = 1e-9;

inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

typedef pair< int, string > result;
typedef map< string, int > Points;

int n;
string names[22];
vector< Array > md;

void solve() {
	vector< SArray > times(31, SArray());
	
	for_(i,0,n) {
		int m = size_of(md[i]);
		for_(j,0,m) {
			times[ md[i][j] ].push_back(names[i]);
		}
	}
	
	Points points;
	
	for_(t,0,31) {
		int m_size = size_of(times[t]);
		int point = n - m_size + 1;
		
		for_(i,0,m_size) {
			points[ times[t][i] ] += point;
		}
	}
	
	vector< result > vr;
	for_(i,0,n) {
		vr.push_back( result(points[names[i]], names[i]));
	}
	
	sort(allof(vr));
	
	cout << vr[0].first << " " << vr[0].second << endl;
}

int main() {
	while (cin >> n, n) {
		md.assign(n, Array());
		for_(i,0,n) {
			int m; cin >> names[i] >> m;
			for_(j,0,m) {
				int d; cin >> d;
				md[i].push_back(d);
			}
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1264
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
data=[0]*2; f=1
for i in range(n):
    s=input()
    count+=s.count("AB")
    if s[0]=="B" and s[-1]=="A":
        data[0]+=1; data[1]+=1
    elif s[0]=="B":
        data[1]+=1; f=0
    elif s[-1]=="A":      
        data[0]+=1; f=0
count+=max(0,min(data)-f)
print(count)

Measured memory_bytes: 39664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;

string in;

void init(){
  in="";
}

void input(){
  cin>>in;
}

int solve(){
  int k,u,p,c;
  k=u=p=c=0;
  for(int i=0;i<in.size();i++){
    if(in[i]=='K'){
      k++;
    }else if(in[i]=='U'){
      u++;
    }else if(in[i]=='P'){
      p++;
    }else if(in[i]=='C'){
      c++;
    }
  }
  return min(min(k,u),min(p,c));
}


int main(){
  init();
  input();
  cout<<solve()<<endl;
}

Measured memory_bytes: 1188
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    int n,i,j,k,f,ff;f=0;
    int a[100050];
    a[0]=0;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
        sort(a+1,a+n+1);
    if(k>a[n])
        printf("IMPOSSIBLE");
    else
    {
        for(i=1;i<=n;i++)
            if(a[i]==k)
        {
            f=1;
            break;
        }

        for(i=n;i>=1;i--)
            if(a[i]==a[i-1]+1)
        {
            f=1;
            break;
        }
        for(i=n;i>=1;i--)
            if(a[i]==a[i-1]+2)
        {
            f=2;
            break;
        }
        if(f==2)
        {
            for(i=1;i<=n;i++)
                if(a[i]%2==1)
                break;
            if(i==n+1&&k%2==1)
                f=0;
            else
                f=1;
        }
        if(f==0)
        {
            ff=a[n]-k;
            for(i=1;i<=n;i++)
            {
                if(ff%a[i]==0||a[i]%k==0)
                {
                    f=1;
                    break;
                }
            }

        }
        

        if(f==1)
            printf("POSSIBLE");
        else
            printf("IMPOSSIBLE");
    }
        return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void prime(ll n);
map<ll,ll>mp;
vector<ll>vec;

int main(){
  ll n,p,ans=1;
  cin>>n>>p;
  prime(p);
  for(ll i=0;i<vec.size();i++){
    if(mp[vec[i]]>=n){
      for(int j=0;j<mp[vec[i]]/n;j++){
	ans*=vec[i];
      }
    }
  }
  cout<<ans<<endl;
  return(0);
}

void prime(ll n){
  for(ll i=2;i*i<=n;i++){
    if(n%i==0)vec.push_back(i);
    while(n%i==0){
      ++mp[i];
      n/=i;
    }
  }
  if(n!=1){
    vec.push_back(n);
    mp[n]=1;
  }
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

S = [int(x) - ord('0') for x in read().rstrip()]

N = len(S)

Scum = list(itertools.accumulate(S))

def test(x):
    if x + x <= N:
        return True
    L = N - x
    R = x
    cnt = Scum[R-1] - Scum[L] + S[L]
    return cnt in [0,R-L]

left = 0 # True
right = N + 1 # False
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        left = x
    else:
        right = x
answer = left
print(answer)

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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define int ll
const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;
const int MX = 777777 + 5;
const int mod = 1777777777;
const double EPS = 1e-10;



int fac[MX+5];
int power(int x, int y, int p)
{
    int res = 1;

    x = x % p;

    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}

int C(int n, int r, int p)
{
    if (r==0)
        return 1;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

void init(int mod){
    fac[0] = 1;
    for (int i=1 ; i<=MX; i++)
        fac[i] = fac[i-1]*i%mod;
}


void _() {
    int n,a,b;
    cin>> n >> a >> b;
    if(a>b || (n==1 && a!=b))cout << 0 << endl;
    else if(a==b )cout << 1 << endl;
    else
        cout << (n-1)*b+a-(n-1)*a-b+1 << endl;
};

#undef int
int main() {
#if __MINGW32__
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Input.txt", "r", stdin);
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Output.txt", "w", stdout);

#endif

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


}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	double A,T;
	int B;
	cin>>A>>B>>T;
	int ans=0;
	int i=1;
	while (true){
		if (A*i<=T+0.5){
			ans+=B;
			i++;
		}else{
			break;
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	long int a, b, k; //4バイトの符号付整数（-2の31乗～2の31乗-1）の値を記憶できる
	cin >> a >> b;

	k = (a + b) / 2;

	if ((a + b) % 2 != 0) {       // != は不等演算子
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << k << endl;
	}
	return 0;

}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T > struct SparseTable { //[a, b)
    vector<vector<T> > st;
    vector< int > lookup;
    
    SparseTable(const vector<T> &v) {
        int b = 0;
        while((1 << b) <= v.size()) ++b;
        st.assign(b, vector< T >(1 << b));
        for(int i = 0; i < v.size(); i++) {
            st[0][i] = v[i];
        }

        for(int i = 1; i < b; i++) {
            for(int j = 0; j + (1 << i) <= (1 << b); j++) {
                st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
            }
        }
        
        lookup.resize(v.size() + 1);
        
        for(int i = 2; i < lookup.size(); i++) {
            lookup[i] = lookup[i >> 1] + 1;
        }
    }
        
    inline T rmq(int l, int r) {
        int b = lookup[r - l];
        return min(st[b][l], st[b][r - (1 << b)]);
    }
};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    llong x;
    cin >> N >> x;
    vector<llong> slime(2 * N);
    rep(i, N) {
        llong a;
        cin >> a;
        slime[i] = a;
        slime[i + N] = a;
    }

    SparseTable<llong> st(slime);
    priority_queue<llong, vector<llong>, greater<llong> > PQ;
    rep(k, N) {
        llong ans = k * x;
        rep(i, N) {
            ans += st.rmq(N + i - k, N + i + 1);
        }
        PQ.push(ans);
    }

    cout << PQ.top() << endl;

    return 0;
}

Measured memory_bytes: 768
def isMonth(x):
  y = int(x)
  return (1 <= y and y <= 12)

date = input()
firstvalid = isMonth(date[0:2])
secondvalid = isMonth(date[2:])
 
if firstvalid and secondvalid:
  print('AMBIGUOUS')
elif firstvalid:
  print('MMYY')
elif secondvalid:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3060
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  tiles = list(map(int, input()))
  color = 0
  count = 0

  for tile in tiles:
    if tile == color:
      count += 1

    color = 1 - color

  if count > len(tiles) // 2:
    count = len(tiles) - count

  print(count)


if __name__ == '__main__':
  main()



Measured memory_bytes: 3956
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll digit(ll b,ll n)
{
    if(b<2||n<1)
    {
        return -MOD;
    }
    else if(n<b)
    {
        return n;
    }
    else
    {
        return digit(b,n/b)+(n%b);
    }
}
int main()
{
    ll n,s;
    cin>>n>>s;
    if(n==s)
    {
        cout<<n+1;
        return 0;
    }
    ll i=2;
    for(; i*i<=n; i++)
    {
        if(digit(i,n)==s)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    if(i*i==n)
        i--;

    for(; i>0; i--)
    {
        if(((n-s)%i==0)&&(digit((n-s)/i+1,n)==s))
        {
            cout<<(n-s)/i+1;
            return 0;
        }
    }

    cout<<-1;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


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

    unsigned int a[N];
    unsigned int ans = 0;
    rep(i, N){
        cin >> a[i];
        ans = ans ^ a[i];
    }
    rep(i, N){
        cout << (a[i] ^ ans);
        if(i == N - 1){
            cout << endl;
        }else{
            cout << " ";
        }
    }

    return 0;

}


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

using i64 = std::int_fast64_t;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

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

signed main() {
  i64 N, M;
  cin >> N >> M;
  vector<i64> A(N);
  cin >> A;
  sort(ALL(A));
  vector<i64> S(N + 1);
  REP(i, N) S[i + 1] = S[i] + A[i];
  i64 h_ng = 0;
  i64 h_ok = A[N - 1] * 2 + 1;
  i64 h = h_ok;
  i64 ans = 0;
  while (h_ok > h_ng + 1) {
    h = (h_ok + h_ng) / 2;
    i64 s = 0;
    i64 q = 0;
    i64 r = 0;
    i64 ge = 0;
    i64 gt = 0;
    RREP(i, N) {
      while (ge < N && !(A[i] + A[ge] >= h)) ge++;
      while (gt < N && !(A[i] + A[gt] > h)) gt++;
      q += N - gt;
      r += gt - ge;
      s += S[N] - S[gt] + A[i] * (N - gt);
    }
    if (q <= M) {
      h_ok = h;
      if (M <= q + r) {
        cout << (s + (M - q) * h) << endl;
        exit(0);
      }
    } else {
      h_ng = h;
    }
  }
}


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

template<typename T>
T GCD(T a, T b) {
  if(a > b) std::swap(a, b);
  if(a == 0) return b;
  else return GCD(b % a, a);
}

int main() {
  int K;
  std::cin >> K;

  int ans = 0;
  rep(a, K) {
    rep(b, K) {
      rep(c, K) {
        ans += GCD(a + 1, GCD(b + 1, c + 1));
      }
    }
  }

  std::cout << ans << '\n';
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int g = 0, p = 0, pt = 0;
  for(auto c : s) {
    if(g == p) {
      pt -= ('g' != c);
      g++;
    } else {
      p++;
      if(c == 'g')
        pt++;
    }
  }
  cout << pt << '\n';
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int a = -1e9, b, i, n, r;
  scanf("%d%d", &n, &b);
  for(i = 1; i < n; i++){
    scanf("%d", &r);
    if(r-b > a) a = r-b;
    if(b > r) b = r;
  }
  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 1840
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	ll n,k;
	cin>>n>>k;
	ll x=n%k;
	x=min(x,abs(k-x));	
	cout<<x;
}

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

int main(){
  int D,T,S;
  cin >> D >> T >> S;

  int r = D % S;
  int d = D / S;

  if(  (r == 0 &&  d <= T )  ||  (r != 0 && ( d + 1) <= T )) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632
n = int(input())
d_list = list(map(int, input().split()))
divider = 998244353

if d_list[0] != 0:
  print(0)
else:
  d_sort = sorted(d_list)
  d = 1
  pre_c = 1
  cur_c = 0
  count = 1
  for i in range(1, n):
    if d_sort[i] == d:
      cur_c += 1
    elif d_sort[i] == d + 1:
      count *= pre_c ** cur_c
      count %= divider
      d += 1
      pre_c = cur_c
      cur_c = 1
    else:
      count = 0
      cur_c = 0
      break
  count *= pre_c ** cur_c
  count %= divider
  print(count)

Measured memory_bytes: 14020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    cin >> N;
    VL A(N), B(N), C(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    rep(i, 0, N) cin >> C[i];
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));
    VL BC(N), acc(N+1, 0);
    rep(i, 0, N){
        auto itr = upper_bound(ALL(C), B[i]);
        auto pos = distance(C.begin(), itr);
        BC[i] = N - pos;
        acc[i+1] = BC[i] + acc[i];
    }
    ll ans = 0;
    rep(i, 0, N){
        auto itr = upper_bound(ALL(B), A[i]);
        auto pos = distance(B.begin(), itr);
        ans += acc[N] - acc[pos];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
// HOPE IS A GOOD THING MAY BE THE BEST OF THINGS AND NO GOOD THINGS EVER DIES  <3 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;

int main () {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;
    ans += min(k, a);
    k -= min(k, a);
    //cout << ans << endl;
    if (k > 0) {
        k -= min(k, b);
    }
    if (k > 0) {
        ans -= min(k, c);
        k -= min(k, c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N = 1e6+5;
lli ans[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i, j, k, cur;
    
    for(i=1;i<=2*sqrt(n);i++)
    {
        for(j=1;j<=2*sqrt(n);j++)
        {
            for(k=1;k<=2*sqrt(n);k++)
            {
                cur = (i+j)*(i+j) + (i+k)*(i+k) + (k+j)*(k+j);
                if(cur % 2) continue;
                
                cur /= 2;
                if(cur > n) break;
                ans[cur]++;
            }
        }
    }
    
    for(i=1;i<=n;i++) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>


using namespace std;



int main(){
    int x;
    while(cin>>x){
        int count = 0 ;
        if(x==0)break;
        while(x>=5){
            x/=5;
            count+=x;
        }
        cout<<count<<endl;
    }
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CExceptionHandling
    {
        static void Main(string[] args)
        {            
            var n = int.Parse(Console.ReadLine());
            var aList = new List<int>();
            int max = 0;
            int maxIndex = 0;
            for (int i = 0; i < n; i++)
            {
                int a = int.Parse(Console.ReadLine());
                if (max < a)
                {
                    max = a;
                    maxIndex = i;
                }
                aList.Add(a);
            }

            for (int i = 0; i < n; i++)
            {
                if (i == maxIndex)
                {
                    var tmpList = new List<int>(aList);
                    tmpList.RemoveAt(i);
                    Console.WriteLine(tmpList.Max());
                    continue;
                }
                Console.WriteLine(max);
            }
            
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 21076
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, M;
    cin >> N >> M;

    priority_queue<ll> que;
    rep(i, N) {
        ll a;
        cin >> a;
        que.push(a);
    }

    rep(i, M) {
        ll t = que.top();
        que.pop();
        que.push(t / 2);
    }

    ll res = 0;
    while (!que.empty()) {
        res += que.top();
        que.pop();
    }

    cout << res << endl;
}

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


int w, h;
int ans;
int map[50][50];
int dx[8] = { 0, 0, 1, 1, 1, -1, -1, -1 };
int dy[8] = { 1, -1, 1, 0, -1, 1, 0, -1 };

void solve(int x, int y)
{
	map[x][y] = 0;
	for (int i = 0; i < 8; i++)
	{
		int X = x + dx[i];
		int Y = y + dy[i];
		if (0 <= X && X < w && 0 <= Y && Y < h && map[X][Y] == 1)
		{
			solve(X, Y);
		}
	}
}

int main()
{
	while (cin >> w >> h, w + h)
	{
		ans = 0;
		for (int y = 0; y < h; y++)
		{
			for (int x = 0; x < w; x++)
			{
				cin >> map[x][y];
			}
		}

		for (int y = 0; y < h; y++)
		{
			for (int x = 0; x < w; x++)
			{
				if (map[x][y] == 1)
				{
					ans++;
					solve(x, y);
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
    ll x,k,d;cin>>x>>k>>d;
    if(x<0)x*=-1;
    ll dpos=min(x/d,k);
    if(dpos==k)cout<<x-d*k<<"\n";
    else
    {
        ll x1=x-dpos*d;
        ll x2=x-(dpos+1)*d;
        if((k-dpos)&1)cout<<abs(x2)<<"\n";
        else cout<<x1<<"\n";
    
    }
    
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//**always check if you are not killing input in between
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//string2=string1.substr(pos,length);if len no specified then till end
//void fill (ForwardIterator first, ForwardIterator last, const T& val);
//The range filled is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.


//If wrong on pretest 2 means logically wrong
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3588
n, q = map(int, input().split())
s = input()
l, r = [], []
for i in range(q):
    ls, rs = map(int, input().split())
    l.append(ls)
    r.append(rs)

c = [0 for i in range(n)]

for i in range(n-1):
    fnd = 0
    if s[i:i+2] == 'AC':
        fnd = 1
    c[i+1] = c[i]+fnd

for i in range(q):
    print(c[r[i]-1]-c[l[i]-1])


Measured memory_bytes: 15800
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    int a[n], b[n], c[n - 1], sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for(int i = 0; i < n - 1; i++)
    {
        cin >> c[i];
    }
    for(int i = 0; i < n; i++)
    {
        sum += b[a[i] - 1];
        if(i > 0 && a[i] - a[i - 1] == 1)
            sum += c[a[i - 1] - 1];
    }
    cout << sum << endl;

    return 0;
}


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

using namespace std;

int main(void)
{
	string s;
	cin >> s;

	int m = (s[5] - '0') * 10 + (s[6] - '0');
	if (m > 4) {
		cout << "TBD" << endl;
	}else{
		cout << "Heisei" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n,t,r;double S;main(i){for(;~scanf("%d",&n);(i=-i)>0?S=!puts(fabs(S)>1e-6?S>0?"1":"2":"0"):0)for(r=360;n--;r-=t)!n?t=r:scanf("%d",&t),S+=sin(t/57.3)*i;}

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

#define int long long
#define nl '\n'
#define tez ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

signed main()
{
	tez
	int n;
	cin >>n;
	int v[n],c[n];
	int i;
	for(i=0;i<n;i++)
	{
	    cin>>v[i];
	}
	for(i=0;i<n;i++)
	{
	    cin>>c[i];
	}
	int ans=0;
	for(i=0;i<n;i++)
	{
	    if(v[i]>c[i])ans+=v[i]-c[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import numpy as np
import copy

D = int(input())
C = list(map(int,input().split()))
contest = [list(map(int,input().split())) for i in range(D)]
inputs = [int(input()) for i in range(D)]
# print(contest)
# print(inputs)

lists = np.array([0 for i in range(26)])
Y = 0
for i,j in zip(contest,inputs):
    lists += 1
    lists[j-1] = 0
    X = C * lists.T
    # print(X)
    # print(sum(X))
    # x = sum(C[:j-1])+sum(C[j:])
    # y = i[j-1]-x+solve
    Y = i[j-1]-sum(X)+Y
    print(Y)
    Y = copy.deepcopy(Y)

Measured memory_bytes: 27036
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define fi first
#define sc second
using namespace std;
typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> PP;
int n,m,l;
vector<PP> G[50];
int dp[51][51];

int main(void){
	scanf("%d%d%d",&n,&m,&l);
	for(int i=0;i<m;i++){
		int d,a,k,t;
		scanf("%d%d%d%d",&d,&a,&k,&t);
		int from=d*n+a-1;
		int to=d*n+a+k-1;
		G[from].push_back(PP(to,P(t,1)));
	}
	for(int i=0;i<5*n;i++){
		G[i].push_back(PP(i+1,P(0,0)));
	}
	int res=0;
	for(int i=0;i<5*n;i++){
		for(int j=0;j<l;j++){
			for(int k=0;k<G[i].size();k++){
				PP p=G[i][k];
				dp[p.fi][j+p.sc.sc]=max(dp[p.fi][j+p.sc.sc],dp[i][j]+p.sc.fi);
				res=max(res,dp[p.fi][j+p.sc.sc]);
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1208
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef std::pair<int, int> Par;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005;
Par p[maxn];

int main() {
	int n = read;

	for(int i = 1; i <= n; i ++) {
		read(p[i].first, p[i].second);
		if(p[i].first > p[i].second)
			std::swap(p[i].first, p[i].second);
	}

	std::sort(p + 1, p + n + 1);

	int max = 0, min = 1000000000;
	for(int i = 1; i <= n; i ++) {
		max = std::max(max, p[i].second);
		min = std::min(min, p[i].second);
	}

	ll ans = 1ll * (p[n].first - p[1].first) * (max - min);
	debug("%lld\n", ans);

	int mp = 2;
	for(int i = 3; i <= n; i ++)
		if(p[i].second > p[mp].second)
			mp = i;

	for(int i = mp; i >= 3; i --)
		std::swap(p[i], p[i - 1]);

	min = std::min(p[1].second, p[2].first);
	max = std::max(p[1].second, p[2].first);

	int rmin = 1000000000;
	for(int i = 3; i <= n; i ++) {
		rmin = std::min(rmin, std::max(max, p[n].first) - std::min(min, p[i].first));
		min = std::min(min, p[i].second);
		max = std::max(max, p[i].second);
	}
	rmin = std::min(rmin, max - min);

	ans = std::min(ans, 1ll * (p[2].second - p[1].first) * rmin);

	printf("%lld\n", ans);
}


Measured memory_bytes: 1792
#include <cstdio>

int main(){
    int N;
    scanf("%d",&N);
    int a[N];
    for(int i = 0; i < N; i++){
        scanf(" %d",&a[i]);
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans = ans + a[i] - 1;
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
   int n,i,count=0;
   char s[50];
   cin>>n;
   cin>>s;
   for(i=0;i<n;i++)
   {
       if(s[i]=='A')
       {
           if(s[i+1]=='B')
           {
               if(s[i+2]=='C')
                   count++;
           }
       }
   }
   cout<<count;
    return 0;
}

Measured memory_bytes: 256