akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define MOD 1000000007
using pi = pair<int, int>;
vector<int> adj[200100];
bool visited[200100];
int dfs(int x)
{
    int ans = 0;
    if(visited[x] == false)
    {
        visited[x] = true;
        ans++;
        for(auto i:adj[x])
            ans += dfs(i);
    }
    return ans;
}
int main()
{
    int n, m;
    cin >> n >> m;
    int mx = 0;
    memset(visited, false, sizeof(visited));
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    for(int i = 0; i < n; i++)
    {
        if(visited[i] == 0)
            mx = max(mx, dfs(i));
    }
    cout << mx << endl;
}


Measured memory_bytes: 20928
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N, S = input(int, str)
    if N % 2 == 1:
        print("No")
        return
    yesno(S[:N // 2] == S[N // 2:])


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 5040
#include <iostream>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(int argc, char *argv[])
{
	int N, W;
	int w[105], v[105];
	ll inf = 1e13;

	cin >> N >> W;

	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i <= 100000; i++) {
		dp[i] = inf;
	}
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 100000; j >= 0; j--) {
			if  (j - v[i] >= 0) {
				dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i <= 100000; i++) {
		if (dp[i] <= W) {
			ans = max(ans, (ll) i);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	for (int h = 1; ; ) {
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}

	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main(){
	cin >> n;
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) printf("%d\n", A[i]);

	return 0;
}


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

int main() {
  int N, X; cin >> N >> X;
  vector<int> m(N);
  for (int i = 0; i < N; i++) cin >> m.at(i);
  int su, mi;
  su = mi = m.at(0);
  for (int i = 1; i < N; i++) {
    su += m.at(i);
    mi = min(mi, m.at(i));
  }
  cout << N + (X - su) / mi << endl;
  
}


Measured memory_bytes: 256
class UnionFind():

    def __init__(self, n):
        # n個の要素
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        要素xのrootを見つける
        """
        if self.parents[x] < 0:
            return x
        else:
            # 再帰的にrootを求める
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        """
        要素x,要素yについて
        rootが同じ場合そのまま
        異なる場合は要素xの末尾に要素yを付ける
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        要素xの集合の大きさを返す
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        要素xと要素yのrootが同じか返す
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def __str__(self):
        return '\n'.join(('{}: {}'.format(r, self.members(r)) for r in self.roots()))


N,M = map(int,input().split())

A_B = [list(map(int,input().split())) for _ in range(M)]

union = UnionFind(N)

cnt_town = [False] * M

for a,b in A_B:
  union.unite(a-1,b-1)
print(len(union.roots())-1)



Measured memory_bytes: 30144
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (A >= K)
    {
        cout << K << endl;
    }
    else if (A + B >= K)
    {
        cout << A << endl;
    }
    else
    {
        cout << A - (K - A - B) << endl;
    }
}

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

int main(int argc, char *argv[]){
  int N;
  cin>>N;
  vector<int> vec(100000,0);
  for(int i=0; i<N; i++){
    int a;
    cin>>a;
    vec[a]++;
  }
  int max=-1;
  int count=0;
  for(int i=0; i<100000; i++){
    if(vec[i]==0) continue;
    count=0;
    if(i==0) count+=vec[i+1]+vec[i];
    if(i==N-1) count+=vec[i-1]+vec[i];
    else if(i!=0 && i!=N-1) count+=vec[i+1]+vec[i-1]+vec[i];
    if(count>max) max=count;
  }
  
  cout<<max<<endl;
}
  


Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int N = fs.nextInt();
		int A[] = fs.nextIntArray(N);
		long sum[] = new long[N+1];
		sum[0] = 0;
		for(int i=0;i<N;i++) sum[i+1]=sum[i]+A[i];
		
		long ans = Long.MAX_VALUE/2;
		for(int center=3;center<N;center++) {
			//左のPとQ
			long suml = sum[center-1];
			long hsuml = suml/2;
			//左の配列について二分探索
			int l = -1, r = center;
			while(l+1<r) {
				int c = (l + r)/2;
				if(sum[c]<hsuml)l=c;
				else r = c;
			}
			long P1 = sum[l];
			long Q1 = suml - P1;
			long P2 = sum[r];
			long Q2 = suml - P2;
			
			//右のRとS
			long sumr = sum[N]-suml;
			long hsumr = sumr/2;
			//右の配列について二分探索
			l = center-1; r = N+1; 
			while(l+1<r) {
				int c = (l + r)/2;
				if(sum[c]<hsumr+sum[center-1])l=c;
				else r = c;
			}
			if(l==center-1) {
				l++;r++;
			}
			long R1 = sum[l]-sum[center-1];
			long S1 = sumr - R1;
			long R2 = sum[r]-sum[center-1];
			long S2 = sumr - R2;
			
			ans = Math.min(ans, absmax(P1,Q1,R1,S1));
			ans = Math.min(ans, absmax(P1,Q1,R2,S2));
			ans = Math.min(ans, absmax(P2,Q2,R1,S1));			
			ans = Math.min(ans, absmax(P2,Q2,R2,S2));			
			
		}
		System.out.println(ans);
	}
	static long absmax(long P, long Q, long R, long S) {
		long t[] = {P,Q,R,S};
		Arrays.sort(t);
		long res = t[3] - t[0];
		return res;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 61632
fun main(args: Array<String>){
    val N = readLine()!!.toInt()
    val A = Array(N){ readLine()!!.split(" ").map { it.toLong() }.toLongArray() }
    val redundant = Array(N){BooleanArray(N)}

    for (k in 0 until N) {
        for (i in 0 until N) {
            for (j in 0 until N) {
                if(A[i][j] > A[i][k] + A[k][j]){
                    println(-1)
                    return
                }
                if(A[i][j] == A[i][k] + A[k][j] && A[i][k] > 0 && A[k][j] > 0){
                    redundant[i][j] = true
                }
            }
        }
    }

    var ans = 0L
    for(i in 0 until N){
        for(j in i+1 until N){
            if(!redundant[i][j]) ans += A[i][j]
        }
    }
    println(ans)
}

Measured memory_bytes: 47912
#複数の整数入力を受け付ける関数
def datain(num):

    data = []
    iscnt = True

    while iscnt:
        for val in map(int,input().split()):
            data.append(val)
            if len(data) == num:
                iscnt = False
                break
        
    return data

num = int(input())
data = datain(num*3)
data.sort()
ans = 0

for i in range(num*3-2,num-1,-2):
    #print(i)
    ans += data[i]

#print(data)
print(ans)

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

using namespace std;

#define lc (1 + (idx << 1))
#define rc (2 + (idx << 1))
#define md ((st + nd) >> 1)
#define fi first
#define se second
#define pb push_back
typedef long long ll;

const int N = 16;
int a[N][N];
ll dp[1<<N];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (int j = 1; j < (1 << n); j++) {
		for (int u = 0; u < n; u++) {
			if (j & (1 << u)) {
				for (int v = u + 1; v < n; v++) {
					if (j & (1 << v)) {
						dp[j] += a[u][v];
					}
				}
			}
		}
	}
	for (int j = 1; j < (1 << n); j++) {
		int hold = j;
		do {
			dp[j] = max(dp[j], dp[hold] + dp[j^hold]);
			--hold;
			hold &= j;
		} while (hold != j);
	}
	printf("%lld", dp[(1<<n)-1]);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	map<int, int> mp1, mp2;
	for(int i = 0; i < n; i++) {
		int v; cin >> v;
		(i % 2 == 0? mp1[v]++ : mp2[v]++);
	}
	int a = 0, b = 0, c = 0, d = 0;
	int mx1 = 0, mx2 = 0;
	for(int i = 0; i <= 100005; i++) {
		if(mp1[i] >= a) {
			b = a;
			a = mp1[i];
			mx1 = i;
		}
	}
	for(int i = 100005; i >= 0; i--){
		if(mp2[i] >= c) {
			d = c;
			c = mp2[i];
			mx2 = i;
		}
	}
	if(mx1 != mx2) cout << n - a - c << endl;
	else {
		cout << min(n - a - d, n - b - c) << endl;
	}
	return 0;                                              
}
	


Measured memory_bytes: 9600
Sa = list(input())
Sb = list(input())
Sc = list(input())
turn = Sa
ans = "A"
while turn != []:
    card = turn[0]
    turn.pop(0)
    if card == "a":
        turn = Sa
        ans = "A"
    elif card == "b":
        turn = Sb
        ans = "B"
    else:
        turn = Sc
        ans = "C"
print(ans)

Measured memory_bytes: 9128
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, X: "List[int]"):
    if N >= M:
        print(0)
    else:
        X_s = sorted(X)
        b = []
        for i in range(0, M-1):
            b.append(X_s[i+1] - X_s[i])
        b_s = sorted(b, reverse=True)
        print(X_s[-1] - X_s[0] - sum(b_s[:N-1]))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, X)

if __name__ == '__main__':
    main()


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

int n, m, c[300];

void Lsh(){
  int b1[300], b2[300];
  for(int i = 1; i <= n; i++){
    b1[i] = c[i]; b2[i] = c[n+i];
  }
  for(int i = 1; i <= n; i++){
    c[2 * i - 1] = b1[i];
    c[2 * i] = b2[i];
  }
}

void Kcut(int k){
  int b1[300], b2[300];
  for(int i = 1; i <= k; i++) b1[i] = c[i];
  for(int i = 1; i <= 2 * n - k; i++) b2[i] = c[i + k];

  for(int i = 1; i <= 2 * n - k; i++) c[i] = b2[i];
  for(int i = 1; i <= k; i++) c[i + 2 * n - k] = b1[i];
}

int main(void){
  cin >> n >> m;
  for(int i = 1; i <= 2 * n; i++) c[i] = i;
  for(int i = 0; i < m; i++){
    int com; cin >> com;
    if(com == 0) Lsh();
    else Kcut(com);
  }
  for(int i = 1; i <= 2 * n; i++) cout << c[i] << endl;
  return 0;
}

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

#define all(v)  begin(v), end(v)
#define endl    '\n';
#define int     long long
#define pii     pair<int, int>
#define sz(x)   (int) x.size()

void test_case() {
    int n; 
    cin >> n;
    const int x = 1 + (int) sqrt(n);
    vector<int> a(n+1, 0);
    for (int i = 1; i <= x; i++) {
        for (int j = 1; j <= x; j++) {
            for (int k = 1; k <= x; k++) {
                int val = i*i + j*j + k*k;
                val += i*j + j*k + k*i;
                if (val <= n) 
                    a[val] += 1;
            }
        }
    }
    for (int i = 1; i <= n; i++)
        cout << a[i] << endl;
}

int32_t main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);

    int t = 1;
    // cin >> t;

    while (t--) { 
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3632
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<vector>
using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
	int n; cin >> n;
	long long a[n];
	REP(i, n) cin >> a[i];
	sort(a, a+n);

	int high = lower_bound(a, a+n, a[n-1]/2) - a;

	if(high == 0){
		cout << a[n-1] << " " << a[high] << endl;
		return 0;
	}

	if(high == n-1){
		cout << a[n-1] << " " << a[high-1] << endl;
		return 0;
	}

	int hh = a[n-1] - a[high];
	int ll = a[high-1];
	if(hh > ll){
		cout << a[n-1] << " " << a[high] << endl;
	}else{
		cout << a[n-1] << " " << a[high-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
#include<algorithm>
using namespace std;
int n,T,H,lim,t[101],h[101],p=0;

int jihanki(int a){
	int r;
	if(a==10){
		p+=10;
		T++;
		if(T>lim)return -1;
	}else{
		p+=100;
		H++;
	}
	if(p==180){
		p=0;
		return 0;
	}else if(p>=90){
		r=p-90;
		if(T*10>=r){
			T-=r/10;
			p=0;
			return r/10; 
		}else{
			return -1;
		}
	}else{
		return 0;
	}
}
int main(){
	int i,j,k,re,winner;
	cin>>n>>T>>H>>lim;
	for(i=0;i<n;i++){
		cin>>t[i]>>h[i];
	}
	while(1){
		for(i=0;i<n;i++){
			if(t[i]==0&&h[i]==0){
				winner=i;
				goto OUT;
			}else if(t[i]!=0){
				t[i]--;
				re=jihanki(10);
				if(re==-1){
					winner=i;goto OUT;
				}else if(re!=0){
					t[i]+=re;
				}
			}else{
				h[i]--;
				re=jihanki(100);
				if(re==-1){
					winner=i;goto OUT;
				}else if(re!=0){
					t[i]+=re;
				}
			}
		}
	}
	OUT:
	cout<<winner+1<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int num[20020020];

int main(){
    fast_io
    
    int r;
    cin>>r;
    cout<<r*2*PI<<endl;

    return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


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

	string s;
	cin >> s;
	int n = s.size();
	if (s[0] == '0' || s[n - 2] == '0' || s[n - 1] == '1') {
		cout << -1 << endl;
		return 0;
	}
	int cnt = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] != s[n - 2 - i]) {
			cout << -1 << endl;
			return 0;
		}
		if (s[i] == '1') cnt++;
	}
	for (int i = 1; i <= cnt; i++) {
		cout << i << ' ' << i + 1 << endl;
	}
	int pl = 1;
	int num = cnt + 2;
	for (int i = 0; i < n - 2; i++) {
		while (s[i] == '0') {
			cout << pl << ' ' << num << endl;
			num++; i++;
		}
		pl++;
	}
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define cBits(x) __builtin_popcount(x)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) a/gcd(a,b)*b
#define FOR(i,a,b) for (int i=a;i<b;i++)
#define FORr(i,a,b) for (int i=a;i>=b;i--)
#define MAX3(a,b,c) max(a,max(b,c))
#define MIN3(a,b,c) min(a,min(b,c))
#define eachTest int t; cin >> t; while(t--) solve();

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;

const int MOD=1000000007;

void solve() {
	;
}

vector <vector <int> > adj;
vector <bool> vis;
vector <int> topo;

void dfs(int u) {
	vis[u] = true;
	for (auto v:adj[u]) {
		if (!vis[v]) {
			dfs(v);
		}
	}
	topo.pb(u);
}

int main() {

	fastio;
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

	// eachTest

	int n, m;
	cin >> n >> m;
	adj.resize(n);
	vis.resize(n);
	int u, v;
	FOR(i,0,m) {
		cin >> u >> v;
		u--;v--;
		adj[u].pb(v);
	}
	FOR(i,0,n) {
		if (!vis[i]) {
			dfs(i);
		}
	}

	vector <int> table(n);

	int ans = 0;

	for (auto u:topo) {
		table[u] = 0;
		// if (adj[u].size() == 0) {
		// 	table[u] = 1;
		// 	continue;
		// }
		for (auto v:adj[u]) {
			table[u] = max(table[u], table[v]);
		}
		table[u]++;
		ans = max(ans, table[u]);
	}

	// for (auto u:topo) {
	// 	cout << u+1 << " -> " << table[u] << "\n";
	// }

	cout << ans-1 << "\n";


	return 0;
}


Measured memory_bytes: 8696
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string S; cin >> S;
  map<char, int> m;
  REP(i, S.size()) m[S[i]]++;
  int check = ceil(S.size() / 3.0) + 1;
  string ans = "YES";
  for(auto x : m) {
    if(x.second >= check) ans = "NO";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#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++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    vector<pair<ll, ll> > p;
    ll A;
    REP(i, N){
        cin >> A;
        p.push_back(make_pair(A, i));
    }
    sort(p.begin(), p.end());

    rep(i, N){
        if(i != 0){
            cout << " ";
        }
        cout << p[i].second;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5344
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define vi vector<int>
#define pb push_back
#define ll long long
#define qi queue<int>
#define vll vector<long long>
#define si set<int>
#define mi map<int,int>
#define mod %
#define frt(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define pair_int pair<int,int>
#define pair_ll pair<ll,ll>
#define pq priority_queue
#define N 100007



int main()
{
   string s,t;
   cin >> s >> t;
   int n = s.length();
   int m = t.length();

   int dp[n+1][m+1];
   
   char ex[n+1][m+1];
   int x[n+1][m+1];
   int y[n+1][m+1];

   

   fre(i,0,n)
   {
   	  fre(j,0,m)
   	  {
   	  	 if(i==0 || j==0) 
   	  	 {
   	  	 	dp[i][j]=0;
   	  	 	x[i][j] = 0;
   	  	 	y[i][j]=0;
   	  	 	ex[i][j]='.';
   	  	 	
   	  	 }

   	  	 else if(s[i-1]==t[j-1])
   	  	 {
   	  	 	dp[i][j] = dp[i-1][j-1]+1;
   	  	 	x[i][j] = i-1;
   	  	 	y[i][j] = j-1;
   	  	 	ex[i][j] = s[i-1];
   	  	 }
   	  	 	

   	  	 else
   	  	 {
   	  	 	if(dp[i-1][j] >= dp[i][j-1] && dp[i-1][j] >= dp[i-1][j-1])
   	  	 	{
   	  	 		dp[i][j] = dp[i-1][j];
   	  	 		x[i][j] = x[i-1][j];
   	  	 		y[i][j] = y[i-1][j];
   	  	 		ex[i][j] = ex[i-1][j];
   	  	 		
   	  	 	}
   	  	 	else if(dp[i-1][j-1] >= dp[i][j-1] && dp[i-1][j-1] >= dp[i-1][j])
   	  	 	{
   	  	 		dp[i][j] = dp[i-1][j-1];
   	  	 		x[i][j] = x[i-1][j-1];
   	  	 		y[i][j] = y[i-1][j-1];
   	  	 		ex[i][j] = ex[i-1][j-1];
   	  	 	}
   	  	 	else
   	  	 	{
   	  	 		dp[i][j] = dp[i][j-1];
   	  	 		x[i][j] = x[i][j-1];
   	  	 		y[i][j] = y[i][j-1];
   	  	 		ex[i][j] = ex[i][j-1];
   	  	 	}
   	  	 } 	 	
   	  }
   }

   int p = n;
   int q = m;
   int p1,q1;
   string str = ".";

   while(p>0 && q>0)
   {
   		if(ex[p][q]!='.')
   			str = str + ex[p][q];

   		p1 = x[p][q];
   		q1 = y[p][q];
   		p = p1;
   		q = q1;
   }

   // rev(str.begin(), str.end());
   str = str.substr(1,str.length()-1);
   reverse(str.begin(), str.end());
   cout << str << endl;
   // cout << ans << endl;
   return 0;

}

  


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

int main(void) {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int res=0;
    for(int pp=0; pp<N; pp++) {
        vector<bool> left(26,false);
        vector<bool> right(26,false);
        for(int i=0; i<pp; i++) left[(int)(S[i] - 'a')] = true;
        for(int i=pp; i<N; i++) right[(int)(S[i] - 'a')] = true;
        int sum=0;
        for(int i=0; i<26; i++) if(left[i] && right[i]) sum++;
        res = max(res, sum);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  int i=N;
  int c=0;
  while (i>0){
    c+=i%10;
    i/=10;
  }
  
  if (N%c==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3588
#include<stdio.h>
int main()
{
	int t[2];
	int i,h,m,s;
	for(i=0;i<6;i++)
	{
		scanf("%d%d%d",&h,&m,&s);
		t[i%2]=h*3600+m*60+s;
		if(i%2)
		{
			s=t[1]-t[0];
			printf("%d ",s/3600);
			s=s%3600;
			printf("%d ",s/60);
			s=s%60;
			printf("%d\n",s);
		}
	}
	return 0;
}

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

int main(){
    int i, h, n;
    int a, sum=0;
    cin >> h >> n;
    for (i=0; i<n; i++){
        cin >> a;
        sum +=a;
    }
    if(h <= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
bool zouka,gen,dottimo;

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    if(a[0]==a[1])dottimo=true;
    else if(a[0]<a[1])zouka=true;
    else gen=true;
    rrep(i,1,n-1){
        //cout<<i<<" "<<zouka<<" "<<gen<<" "<<dottimo<<"\n";
        if(a[i]==a[i+1])continue;
        if(a[i]<a[i+1]){
            if(zouka)continue;
            else if(dottimo){
                dottimo=false;
                zouka=true;
            }
            else if(gen){
                gen=false;
                if(a[i+1]==a[i+2])dottimo=true;
                else if(a[i+1]<a[i+2])zouka=true;
                else gen=true;
                i++;
                ans++;
            }
        }
        else{
            if(gen)continue;
            else if(dottimo){
                dottimo=false;
                gen=true;
            }
            else if(zouka){
                zouka=false;
                if(a[i+1]==a[i+2])dottimo=true;
                else if(a[i+1]<a[i+2])zouka=true;
                else gen=true;
                i++;
                ans++;
            }
        }
    }
    Cout(ans+1);
    return 0;
}


Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 170000;
int x[N] , y[N] , _ , vis[N];
void add(int a,int b) {
  x[_] = a , y[_++] = b;
  if(b == 0) vis[a] = true;
}

int main(){
  int n;
  scanf("%d",&n);
  for(int i=1;i<n;i+=3) {
    rep(j,0,n) if((i + j) & 1)
      add(i , j);
  }
  if(n % 3 == 1) {
    rep(j,0,n) if((n - 1 + j) & 1)
      add(n - 1 , j);
  }
  rep(i,0,n) if(i & 1 && !vis[i])
    add(i , 0);
  printf("%d\n",_);
  rep(i,0,_) printf("%d %d\n",x[i],y[i]);
  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n;

bool f(){
	if(n % 3 != 0){
		bool f = true;
		for(Int i=0; i<n; ++i){
			Int a; cin >> a;
			if(a != 0) f = false;
		}
		return f;
	}
	vector<Int> v(3, -1), w(3, 0);
	Int a; cin >> a;
	v[0] = a;
	w[0] = 1;
	for(Int i=1; i<n; ++i){
		cin >> a;
		if(v[0] == a){
			++w[0];
			continue;
		}
		if(v[1] == -1){
			v[1] = a;
			w[1] = 1;
			continue;
		}
		if(v[1] == a){
			++w[1];
			continue;
		}
		if(v[2] == -1){
			v[2] = a;
			w[2] = 1;
			continue;
		}
		if(v[2] == a){
			++w[2];
			continue;
		}
		return false;
	}
//	cout << v[0] << " " << v[1] << " " << v[2] << "\n";
//	cout << w[0] << " " << w[1] << " " << w[2] << "\n";
	if(v[1] == -1){
		return v[0] == 0;
	}else if(v[2] == -1){
		return (v[0] == 0 && 2*w[0] == w[1]) || (v[1] == 0 && 2*w[1] == w[0]);
	}else{
		return (v[0] == (v[1] ^ v[2])) && (v[1] == (v[2] ^ v[0])) && (v[2] == (v[0] ^ v[1])) && w[0] == w[1] && w[1] == w[2];
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	if(f()) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
  double x1, y1, x2, y2;

  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  printf("%.8f\n",sqrt(pow(x2-x1,2)+pow(y2-y1,2)));
  return 0;
}



Measured memory_bytes: 2116
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  int ans=0;
  while(a<0){
    a++;
    ans+=c;
  }
  if(a==0)
    ans+=d;
  while(a!=b){
    a++;
    ans+=e;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3084
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n) \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)   \
    sort(all(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
    return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto& x : v) is >> x;
    return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
    bool t = 0;
    for (const T& x : v.first) {
        if (t) os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int used[101010];
vector<int> G[101010];
vector<int> ans1, ans2;

void dfs(int v, vector<int> &l) {
    used[v] = true;

    int nxt = -1;

    for(int &w: G[v]) {
        if(used[w] == 0) nxt = w;
    }

    if(nxt == -1) return;
    l.push_back(nxt);
    dfs(nxt, l);
}

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1, ans1);
    dfs(1, ans2);

    reverse(all(ans1));
    cout << ans1.size() + ans2.size() + 1 << endl;

    for(int x: ans1) cout << x << " ";
    cout << 1 << " ";
    for(int x: ans2) cout << x << " ";
    cout << endl;
}




Measured memory_bytes: 9848
fun main(args: Array<String>) {
    val Q = readLine()!!.toInt()
    val max = 100000
    val a = IntArray(max + 1)
    a.fill(0)
    val isPrime = eratosthenes(max)

    fun is2017Like(num: Int) : Boolean {
        return isPrime[num] && isPrime[(num +1) /2]
    }
    (1..max).forEach {
        a[it] = if (is2017Like(it)) 1 else 0
    }

    (0 until max).forEach {
        a[it+1] += a[it]
    }

    (1..Q).forEach {
        val (l, r) = readLine()!!.split(" ").map { it.toInt() }
        println(a[r] - a[l - 1])
    }
}

fun eratosthenes(N: Int) : BooleanArray {
    val isPrime = BooleanArray(N + 1)
    isPrime.fill(true)
    isPrime[0] = false
    isPrime[1] = false

    (2..N).forEach {
        if (isPrime[it]) {
            var i = 2
            while (i * it <= N) {
                isPrime[i*it] = false
                i++
            }
        }
    }

    return isPrime
}


Measured memory_bytes: 57964
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n;
  cin >> n;
  int score[120];
  int sum = 0;
  rep(i,n) {cin >> score[i]; sum += score[i];}
  if (sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }
  
  int ans = 0;
  rep(i,n) {
    if (score[i] % 10 == 0) continue;
    int now = sum - score[i];
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a <= 8 && b <= 8) {
			System.out.print("Yay!");
		} else if ((a > 8 && b <= 8) || (a <= 8 && b > 8) || (a > 8 && b > 8)) {
			System.out.print(":(");
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int N =10;
int ans[N],sum;
bool vis[N];
double x[N],y[N],s;

double fun(double a,double b)
{
    return (a-b)*(a-b);
}
void dfs(int t,int n)
{
    if(t==n)
    {
        sum++;
        for(int i=1;i<n;i++)
        {
            double xx =fun(x[ans[i]],x[ans[i-1]]);
            double yy =fun(y[ans[i]],y[ans[i-1]]);
            s +=sqrt(xx+yy);
        }
        return ;
    }

    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            vis[i] =1;
            ans[t] =i;
            dfs(t+1,n);
            vis[i] =0;
        }
    }
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        s =0,sum =0;
        for(int i=1;i<=n;i++)
            scanf("%lf %lf",&x[i],&y[i]);
        dfs(0,n);
        printf("%.10f\n",s*1.0/sum);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();

		if (A <= 8 && B <= 8) {
			System.out.println("Yay!");
		} else if (A >= (16-B)/2 || B >= (16-A)/2) {
			System.out.println(":(");
		}
	}

}

Measured memory_bytes: 23764
def solve():
    MOD = 10**9 + 7

    N = int(input())
    Ass = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [0] * (1<<N)
    dp[0] = 1
    for S in range((1<<N)-1):
        dp[S] %= MOD
        iM = bin(S).count('1')
        for iW in range(N):
            if S & (1<<iW) == 0 and Ass[iM][iW]:
                S2 = S ^ (1<<iW)
                dp[S2] += dp[S]

    print(dp[-1] % MOD)


solve()


Measured memory_bytes: 58972
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
#define PI 3.14159265358979323846
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;

  
int main() {
  fast 
  ll n;
  cin >> n;
  ll arr[n];
  ll m1 =0;
  fr(i,0,n)
  {
      cin >> arr[i];
  }
  ll cnt=0;
  fr(i,0,n)
  {
      if(m1<=arr[i])
      {
          cnt++;
      }
      m1=max(m1,arr[i]);
  }
  cout << cnt;
  return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int main(){
	int n;
	scanf("%d",&n);
	int arr[n+1];
	for(int i=0;i<=n;i++)scanf("%d",&arr[i]);
	if(n==0){
		if(arr[0]==1)printf("1");
		else printf("-1");
		return 0;
	}
	if(arr[0]>0){printf("-1");return 0;}
	ll mx[n+1];mx[0]=1;
	for(int i=1;i<=n;i++){
		mx[i]=mx[i-1]*2LL;mx[i]%=LLINF;
		mx[i]-=arr[i];
		if(mx[i]<0||(mx[i]==0&&i<n)){printf("-1");return 0;}
	}
	ll mini=arr[n],maxi=arr[n];
	ll ans=arr[n];
	for(int i=n-1;i>=0;i--){
		mini=(mini+1)/2;
		if(mx[i]<mini){printf("-1");return 0;}
		maxi=min(maxi,mx[i]);
		mini+=arr[i];maxi+=arr[i];
		ans+=maxi;
	}
	printf("%lld",ans);
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    while(cin>>a>>b)
    {
        if(a+b==15)
        {
            cout<<'+'<<endl;
            
        }
        else if(a*b==15)
        {
            cout<<'*'<<endl;
        }
        else
        {
            cout<<'x'<<endl;
            
        }
    }
    return 0;
}

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

int main()
{
	int n,q,l[100000],r[100000];
	string s;
	cin>>n>>q>>s;
	for(int i=0;i<q;i++) cin>>l[i]>>r[i];
	
	int c=0,v[100000]={};
	for(int i=0;i<n;i++){
		if(s[i]=='A'&&s[i+1]=='C') c++;
		v[i+1]=c;
	}
	
	for(int i=0;i<q;i++) cout<<v[r[i]-1]-v[l[i]-1]<<endl;
	
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	int s;
	if (e - a > k) s++;

	if (s == 0) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	//return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

struct Die {
    array<int, 6> s;
    int& top() { return s[0]; }
    int& south() { return s[1]; }
    int& east() { return s[2]; }
    int& west() { return s[3]; }
    int& north() { return s[4]; }
    int& bottom() { return s[5]; }
    void roll(char c) {
        //the view from above
        // N
        //W E
        // S
        string b("EWNSRL");
        int v[6][4] = { {0,3,5,2},
                     {0,2,5,3},
                     {0,1,5,4},
                     {0,4,5,1},
                     {1,2,4,3},
                     {1,3,4,2} };
        for (int k = 0; k < 6; k++) {
            if (b[k] != c) continue;
            int t = s[v[k][0]];
            s[v[k][0]] = s[v[k][1]];
            s[v[k][1]] = s[v[k][2]];
            s[v[k][2]] = s[v[k][3]];
            s[v[k][3]] = t;
        }
    }
    using ll = long long;
    ll hash() {
        ll res = 0;
        for (int i = 0; i < 6; i++) res = res * 256 + s[i];
        return res;
    }
    bool operator==(const Die& d) const {
        for (int i = 0; i < 6; i++) if (s[i] != d.s[i]) return 0;
        return 1;
    }
    bool operator <(const Die& d) const {
        return s < d.s;
    }
};

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    vv<set<Die>> dist = vvec(H, W, set<Die>());
    Die start;
    start.top() = 1; start.south() = 2; start.east() = 3;
    start.west() = 4; start.north() = 5; start.bottom() = 6;
    dist[0][0].insert(start);
    queue<pair<pair<int, int>, Die>> q;
    q.emplace(make_pair(0, 0), start);
    while (!q.empty()) {
        auto v = q.front().first;
        auto dc = q.front().second;
        q.pop();
        constexpr char dirchar[] = { 'E','S','W','N' };
        rep(d, 4) {
            int nx = v.first + dy[d], ny = v.second + dx[d];
            Die dcn = dc;
            dcn.roll(dirchar[d]);
            if (nx < 0 || nx >= H || ny < 0 || ny >= W || dist[nx][ny].find(dcn) != dist[nx][ny].end() || S[nx][ny] == '#') continue;
            if (dcn.bottom() != S[nx][ny] - '0') continue;
            dist[nx][ny].insert(dcn);
            q.emplace(make_pair(nx, ny), dcn);
        }
    }
    write(dist[H - 1][W - 1].empty() ? "NO" : "YES");
}


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

int main()
{
	int a,b,c,d;
	while(~scanf("%d%d%d%d",&a,&b,&c,&d))
	{
		if(a*b>c*d||a*b==c*d)
			cout << a*b <<endl;
		else 
			cout << c*d <<endl;
	}	
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  for(int i = 0; i < n; i++) cin >> x.at(i);
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    int mi = min(abs(x.at(i) - k), x.at(i));
    ans += mi * 2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
T = input()

tl = len(T)

ans = -1
for i in range(0, len(S)-tl+1):
  count = 0
  for j in range(0, tl):
    if S[i+j] == T[j]:
      count += 1
  ans = max(ans, count)

print(tl-ans)

Measured memory_bytes: 8984
import sys
input = lambda: sys.stdin.readline().rstrip()
n, m = map(int, input().split())
may_contain_red = [0 for _ in range(n + 1)]
num_of_ball = [1 for _ in range(n + 1)]
may_contain_red[1] = 1
for i in range(m):
    x, y = map(int, input().split())
    num_of_ball[x] -= 1
    num_of_ball[y] += 1
    if may_contain_red[x] != 0:
        may_contain_red[y] = 1
    if num_of_ball[x] == 0:
        may_contain_red[x] = 0

print(sum(may_contain_red))


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod 998244353

ll pmod(ll n, ll p){
	ll m=n%mod;
	if(p==0) return 1;
	ll rtn=pmod((m*m)%mod, p/2)%mod;
	if(p%2==1) rtn=rtn*m%mod;
	return rtn;
}

int main(){
	int n;
	cin >> n;
	int m=0;
	map<int, ll> cnt;
	for(int i=0; i<n; i++){
		int d;
		cin >> d;
		if((i==0 && d!=0) || (i!=0 && d==0)){
			cout << 0 << endl;
			return 0;
		}
		cnt[d]++;
		m=max(m, d);
	}

	ll ans=1;
	for(int i=1; i<=m; i++){
		ans=ans*pmod(cnt[i-1], cnt[i])%mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/
signed main(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    int ans=1;
    int cnt=1;
    for(int i=0;i<n;i++){
        if(s[i]==t[i]){
            if(i==0){
                cnt=3;
            }else if(s[i-1]==t[i-1]){
                cnt*=2;
            }else{
                ans*=cnt;
                cnt=1;
            }
        }else{
            if(i==0){
                cnt=6;
            }else if(s[i-1]==t[i-1]){
                ans*=cnt;
                cnt=2;
            }else{
                cnt*=3;
            }
            i++;
            ans%=MOD;
        }
    }
    ans*=cnt;
    ans%=MOD;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int n,k ,i,j,p[100000],sum=0;
cin>>n>>k;
for(j=0; j<n;j++){cin>>p[j];}

for(i=0; i<n;i++){
    for(j=i+1;j<n;j++){
        if(p[j]<p[i]){
            int temp=p[i];
            p[i]=p[j];
            p[j]=temp;}
    }}
for(i=0;i<k;i++){
    sum=sum+p[i];
}
cout<<sum;
return 0;}

Measured memory_bytes: 3624
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
count=c
ans=0
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(m):
        count+=a[j]*b[j]
    if count>0:
        ans+=1
    count=c
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
int n, m, o, a, b, ans = 0, A[1010], B[1010];
int main() {
	cin >> n >> m >> o;
	rep(i, o) {
		cin >> A[i] >> B[i];
		if (n > A[i] && n < B[i]) ans = 1;
		else if (m > A[i] && m < B[i]) ans = 1;
		else if (n < A[i] && m > B[i]) ans = 1;
		else if (n == A[i] || m == B[i]) ans = 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3076