akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using product = pair<ll,ll>;
using graph = vector<vector<ll>>;
using vll = vector<ll>;


int main(){
    ll N,M;
    cin>>N>>M;
    vector<ll> A(N,0);
    vector<pair<ll,ll>> D(M);
    for(ll i=0;i<N;i++)cin>>A[i];
    sort(A.begin(),A.end());

    for(ll i=0;i<M;i++)
    {
        ll B,C;cin>>B>>C;
        D.emplace_back(make_pair(C,B));
    }
    sort(D.rbegin(),D.rend());

    ll res=0;
    ll K = 0;
    for(ll i=0;i<M;i++){
        for(ll j=0;j<D[i].second;j++)
        {
            if(N<=K)break;
            res+=max(D[i].first,A[K++]);//Cは大きい方から、Aは小さい方から
        }
    }
    for(ll i=K;i<N;i++)res+=A[i];
    cout<<res<<endl;
    return 0;
}

//大きい方からN個取り出すのがバゲットだとやりにくいとき、配列を作って取り出す手法を使う。

Measured memory_bytes: 7204
using System;

class Program
{
    static void Main()
    {
        int i = 0;
        while (i == 0)
        {
            string[] HW = Console.ReadLine().Split();
            int H = int.Parse(HW[0]);
            int W = int.Parse(HW[1]);

            if (H == 0 && W == 0)
                break;

            for (int j = 1; j <= H; j++)
            {
                for (int k = 1; k <= W; k++)
                {
                    if (!(j % 2 == 0))
                    {
                        if (!(k % 2 == 0))
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write(".");
                        }
                    }
                    if(j % 2 == 0)
                    {
                        if(!(k % 2 == 0))
                        {
                            Console.Write(".");
                        }
                        else
                        {
                            Console.Write("#");
                        }
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8720
#include <iostream>
#include <cmath>
#include<algorithm>

using namespace std;


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

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

  int min_dis = 0;

  while (N) {
    long long xth_city;
    cin >> xth_city;
    long long dis = abs(xth_city-X);
    min_dis = gcd(min_dis, dis);
    N--;
  }
  cout << min_dis <<endl;

  return 0;
}


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


#define abs(N) ((N>0)?N:-1*N)
#define lt(A,B) ((A>B)?B:A)
#define gt(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

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

	long long R;
	long long maxv = -1000000001,minv = 100000000001;


	for (int i = 0; i < n; ++i) {
		cin >> R;
		maxv = gt(R-minv,maxv);
		minv = lt(minv,R);
	}
	println(maxv);





	return 0;
}



Measured memory_bytes: 3068
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()


def main():
    N,M = isRaw()
    scs = [isRaw() for _ in range(M)]
    start = 10**(N-1)
    if N == 1:
        start= 0
    for n in range(start,10**N):
        sn = str(n)
        flag = True
        for sc in scs:
            if sn[sc[0]-1] != str(sc[1]):
                flag= False
                break
        if flag:
            return n
    return -1
                    

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll dp[n + 1][2];
  dp[0][0] = 0;
  dp[0][1] = -INF;
  rep(i,n) cin >> a[i];
  int cursor;
  for (int i = 1; i <= n; ++i) {
    cursor = i - 1;
    dp[i][0] = max(dp[cursor][0] + a[cursor], dp[cursor][1] - a[cursor]);
    dp[i][1] = max(dp[cursor][0] - a[cursor], dp[cursor][1] + a[cursor]);
  }

  cout << dp[n][0] << endl;
}


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

int main(void){
    int n, x;
    cin >> n;

    for(int i = 1; i <= n; i++){
        x = i;
        if((x % 3) == 0) cout << ' ' << i;
        else{
            for(; x != 0; x /= 10){
                if((x % 10) == 3) {
                    cout << ' ' << i;
                    break;
                }
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // ここにプログラムを追記
    int a,b,s;
    cin >> a >> b;
    s=a+b;
    
    if(s%2)
    {
        cout << (s/2)+1 <<endl;
    }
    else
    {
        cout << (s/2) <<endl;
    }
}


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

int j[70000];

int main()
{
    int n;

    while (scanf("%d", &n), n){
        unsigned sum = 0;

        for (int i = 0; i < n; i++){
            int p;

            scanf("%d", &p);
            sum += p;
        }
        for (int i = 0; i < n - 1; i++){
            scanf("%d", j + i);
            sum += j[i];
        }

        sort(j, j + n - 1);
        unsigned pipe = 1;

        for (int i = 0; i < n - 1; i++){
            if (sum * pipe < (sum - j[i]) * (pipe + 1)){
                sum -= j[i];
                pipe++;
            }
        }
        printf("%u\n", sum * pipe);
    }

    return 0;
}

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

int main(){
  int k; cin>>k;
  
  if (k%2==0 || k%5==0){
    cout<<-1<<endl;
    return 0;
  }
  
  int ans=1;
  int num=7;
  num%=k;
  
  while (num!=0){
    num=num*10+7;
    num%=k;
    ans+=1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

//fixed << setprecision(8)

using namespace std;

#define ll long long
#define vec vector
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n,t,ans=10000;
	string s;

	cin >> n >> t;

	vector<pair<ll, ll>> a(n);

	forll(i, 0, n)
		cin >> a[i].first >> a[i].second;

	forll(i, 0, n)
	{
		if (a[i].second <= t)
			ans = min(ans, a[i].first);
	}

	if (ans > 1000)
		cout << "TLE";
	else
		cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int MAX=100000;
static const int NUL=-1;
int n;
vector<int>g[MAX]; //頂点数を100000とする
                   //隣接リスト
int color[MAX];
void dfs(int r, int c){
  stack<int>s;
  s.push(r);
  color[r]=c;
  while(!s.empty()){
    int u=s.top();
    s.pop();
    for(int i=0;i<g[u].size();++i){
      //頂点uに隣接する頂点uを探索
      int v=g[u][i];
      if(color[v]==NUL){
	color[v]=c;
	s.push(v);	
      }
    }
  }
}
int main(){
  int s,t,m,q;
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d %d",&s,&t);
    g[s].push_back(t); //sからtへ辺
    g[t].push_back(s); //tからsへ辺
  }
  int id=1;
  for(int i=0;i<n;i++){
    color[i]=NUL;
  }
  for(int u=0;u<n;u++){
    if(color[u]==NUL)
      dfs(u,id++); //id(色)にかぶりがないように
  }
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    scanf("%d %d",&s,&t);
    if(color[s]==color[t]) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
    
    



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

int main(){
  int a, b, c, d;
  cin >> a >> b;
  c = (a + 1) % 2;
  d = (b + 1) % 2;
  if(c == 0 && d == 0){
    cout << "Odd" <<endl;
  }
  else{
    cout << "Even" << endl;
  }
}
    



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

int main() {
    int N, M, Q, l[200000], r[200000], p[100000], q[100000], map[501][501] = {}, sum_map[501][501] = {};
    cin >> N >> M >> Q;
    for (int i = 0; i < M; i++) {
        cin >> l[i] >> r[i];
        map[l[i]][r[i]]++;
    }
    for (int i = 0; i < Q; i++) cin >> p[i] >> q[i];

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            sum_map[i][j] = sum_map[i][j - 1] + map[i][j];
        }
    }
    for (int num = 0; num < Q; num++) {
        int ans = 0;
        for (int i = p[num]; i <= q[num]; i++) {
            ans += sum_map[i][q[num]] - sum_map[i][p[num] - 1];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 5248
m, d = map(int, input().split())
count = 0
d10, d1 = divmod(d,10)
import sys
if d <= 21:
    print(0)
    sys.exit()
for i in range(2,d10 + 1):
    for j in range(2,10):
        for k in range(1,m+1):
            if i*10+j <= d and j*i == k:
                count += 1
print(count)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int s =a + b + c;
    int max = a;
    if(a<b)
        max = b;
    if(c>max)
            max = c;
        if (s != 2 * max)
            printf("No\n");
        else
            printf("Yes\n");
        return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		Outer:
			while(true){
				int a = sc.nextInt();
				char b = sc.next().charAt(0);
				int c = sc.nextInt();
				int result = 0;
				switch(b){
				case '+': result = a + c; break;
				case '-': result = a - c; break;
				case '*': result = a * c; break;
				case '/': result = a / c; break;
				case '%': result = a % c; break;
				case '?': break Outer;
				default : continue Outer;
				}
				System.out.println(result);
			}
	}
}




Measured memory_bytes: 26448
#include <stdio.h>

void line(int w) {
	int i;
	printf("#");
	for (i = 0; i < w - 2; i++) {
		printf(".");
	}
	printf("#\n");
	return;
}

int main(void) {
	int h, w, i;
	while (1) {
		scanf("%d%d", &h, &w);
		if (h == 0 && w == 0) break;
		for (i = 0; i < w; i++)
		{
			printf("#");
		}
		printf("\n");
		for (i = 0; i < h - 2; i++)
		{
			line(w);
		}
		for (i = 0; i < w; i++)
		{
			printf("#");
		}
		printf("\n\n");
	}
	return 0;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
#define ll long long int
#define llu unsigned long long int
#define vi vector<int>
#define vll vector<ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define M 1000000007
#define endl "\n"
using namespace std;
ll val[100001],wgt[100001],dp[100001];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,w; cin>>n>>w;
	for(ll i=0;i<n;i++){
		cin>>wgt[i]>>val[i];
		for(ll j=w;j>=0;j--){
			if(j-wgt[i]>=0) dp[j]=max(dp[j],dp[j-wgt[i]]+val[i]);
		}
	}
	cout<<dp[w]<<endl;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
s = input()
unhappy = 0
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':
    unhappy += 2
if s[0]=='L':
  unhappy += 1
if s[-1]=='R':
  unhappy += 1
print(min(n-unhappy+2*k, n-1))

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


int main()
{
  int N;
  char S[100];
  string str;
  str = "Three";
  cin >> N;
  for(int i = 0 ; i < N ; i++){
  cin >> S[i];
//  cout << i; //test
    if(S[i] == 'Y'){
      str = "Four";
      break;
    }
  }
    cout << str;
}

Measured memory_bytes: 256
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

long long cnt = 0;
vector<int> g;

int shell(int n) {
	int m = 0;
	for (int i = 1;; i = i*3  + 1, m++) {
		if (i > n)break;
		g.push_back(i);
	}
	return m;
}

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

}


int main()
{
	int a[1000001];
	int m;
	int n, i, j;
	cin >> n;
	m = shell(n);
	for (i = 0; i < n; i++)
		cin>>a[i];

		cout << m << endl;
		for (i = m-1; i >=0; i--) {
			insertionSort(a, n, g[i]);
			cout << g[i];
			if(i)cout<< ' ';
		}
		cout << "\n" << cnt << endl;
		for (i = 0; i < n; i++)
			cout << a[i] << endl;
    return 0;
}




Measured memory_bytes: 7068
import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())

tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x


q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)

values = values[1:]
print(" ".join(map(str, values)))


Measured memory_bytes: 130164
#include <iostream>
using namespace std;
const int MAXt=10000;

int n,pos=0,poss=0;
int pre[MAXt],in[MAXt],post[MAXt];

void rec(int l,int r)
{
	if(l>=r)return;
	int root=pre[pos++];
	int i;
	for(i=0;i<n;i++)if(in[i]==root)break;
	rec(l,i);
	rec(i+1,r);
	post[poss++]=root;
}

int main() {
	cin>>n;
	for(int i=0;i<n;i++)cin>>pre[i];
	for(int i=0;i<n;i++)cin>>in[i];
	rec(0,n);
	for(int i=0;i<n;i++)
	{
		if(i)cout<<" ";
		cout<<post[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>
#include <string.h>

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

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



int main(){
  long int N,M;
  scanf("%ld%ld",&N,&M);
  char S[300000];
  char T[300000];
  scanf("%s",S);
  scanf("%s",T);
  int i;
  int flag=0;
  long int ans=-1;
  for(i=0;i<N;i++){
    if((i*M)%N==0){
      if(S[i]!=T[i*M/N]){
	flag=1;
      }
    }
  }
  if(flag==0){
    ans=lcm(N,M);
  }
  printf("%ld",ans);
  return 0;
}

    


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main() {
    
    ll n;
    cin >> n;
    vector<ll> v(5);
    rep(i,5)    cin >> v[i];

    ll ans=4;
    ll mi=1000000000000000000;
    rep(i,5)    mi=min(mi,v[i]);
    ans+=(n+mi-1)/mi;

    cout << ans << endl;


 return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
aa = [-1] * (2*n)
bc = []

for i in range(m):
    b,c = map(int,input().split())
    bc.append((c,b))
bc.sort(reverse = True)

i = 0
for j in range(m):
    if i >= n:
        break
    for k in range(bc[j][1]):
        aa[i] = bc[j][0]
        i += 1

j = 0
for i in range(n):
    if a[i] < aa[j]:
        a[i] = aa[j]
        j += 1
        
print(sum(a))

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long int n,a,b;
  cin>>n>>a>>b;
  long long int x=n/(a+b);
  long long int y=n%(a+b);
  long long int z;
  if(y>=a){
     z=a;
  }else{
    z=y%a;

  }
  cout<<x*a+z;
  

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ada(int a,int b){
    if(a-b/2>0){
        return a-b/2;
    }
    else{
        return 0;
    }
}
int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int64_t sum=100000000000000000;
    for(int i=0;i<2*max(x,y)+1;i+=2){
        int64_t s=c*i+a*ada(x,i)+b*ada(y,i);
        sum=min(sum,s);
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
import sys
import collections
import itertools


def resolve(in_):
    H, W = map(int, next(in_).split())
    Ch, Cw = map(int, next(in_).split())
    Dh, Dw = map(int, next(in_).split())

    ch = Ch - 1
    cw = Cw - 1
    dh = Dh - 1
    dw = Dw - 1
    S = tuple(s.strip() for s in in_)
    wall_i = ord(b'#')
    # road_i = ord(b'.')
    used = [[False for h in range(W)] for w in range(H)]

    qu = collections.deque()
    qu.append((ch, cw))
    for ans in itertools.count():
        if not qu:
            return -1
        
        roads = []
        # walk
        while qu:
            h, w = qu.popleft()
            if used[h][w]:
                continue
            
            used[h][w] = True
            roads.append((h, w))
            if dh == h and dw == w:
                return ans

            for h0, w0 in ((h - 1, w), (h + 1, w), (h, w - 1), (h, w + 1)):
                if not (0 <= h0 < H and 0 <= w0 < W):
                    continue
                if S[h0][w0] == wall_i:
                    continue
                qu.append((h0, w0))
        # magic
        for h1, w1 in roads:
            for h2 in range(h1 - 2, h1 + 3):
                for w2 in range(w1 - 2, w1 + 3):
                    if not (0 <= h2 < H and 0 <= w2 < W):
                        continue
                    if used[h2][w2]:
                        continue
                    if S[h2][w2] == wall_i:
                        continue
                    qu.append((h2, w2))

    return ans

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103680
#include <bits/stdc++.h>
using namespace std;
int N=100010;
int main()
{
	int a[N]={0};
	int n;
	cin >> n;
	int b[n+10];
	for(int i=0;i<n;i++)
		scanf("%d",&b[i]);
	for(int i=0;i<n;i++){
		a[b[i]+1]++;
		a[b[i]]++;
		a[b[i]-1]++;
	}
	int p=0;
	for(int i=0;i<N;i++)
		p=a[i]>p?a[i]:p;
	cout << p;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll  p[20];
main(){
  ll n,sum=0;
  cin>>n;
  rep(i,0,n)cin>>p[i];
  sort(p,p+n);
  rep(i,0,n-1)sum+=p[i];
  cout<<sum+p[n-1]/2;
}

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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 1000
#define N cout<<"No\n"
#define Y cout<<"Yes\n"

int main()
{
    ll A,B,n,i,j,bcn=0,cn=0;
    string s;
    cin>>n>>A>>B;
    cin>>s;
    fr(i,n)
    {
        if(s[i]=='c') N;
        else if(s[i]=='a')
        {
            if(cn<A+B) {
                Y;
                cn++;
            }
            else N;
        }
        else
        {
            if(cn<A+B&&bcn<B)
            {
                Y;
                bcn++;
                cn++;
            }
            else N;
        }
    }

    return 0;
}




Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7
#define LD long double


int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    if(s.size() + 1 == t.size() && t.substr(0,s.size()) == s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

ll A,B,C,D;

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

int main(){
  ll ans=0;
  cin >> A>>B>>C>>D;
  ll gcdcd=gcd(C,D);
  //C/=gcdcd;
  //D/=gcdcd;
  ll CD=C/gcdcd*D;

  ll cnum=B/C-(A-1)/C;
  ll dnum=B/D-(A-1)/D;
  ll cdnum=B/CD-(A-1)/CD;
  ll nm=cnum+dnum-cdnum;
  ans=B-(A-1)-nm;

  cout<<ans<<endl;

  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n;
    cin>>n;
    vi v;
    ll a[n],b[n],total=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
        total^=a[i];
    }
    for(int i=0;i<n;i++)
    {
        ll temp=total^a[i];
        v.pb(temp);
    }
    for(auto t:v)cout<<t<<" ";
        cout<<endl;

}
return 0;
}

Measured memory_bytes: 8372
#include <iostream>
#include <array>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

#include <atcoder/lazysegtree>

using namespace std;
using namespace atcoder;
#define rep(i,l,r) for(int i = l; i < r; ++i)

using S = array<long long, 3>;
using F = bool;

S op(S s1, S s2) 
    {return {s1[0] + s2[0], s1[1] + s2[1], s1[2] + s2[2] + s1[0] * s2[1]};}
S e() {return {0, 0, 0};}

S mapping(F f, S s)
    {return (f ? S{s[1], s[0], s[0] * s[1] - s[2]} : s);}
F composition(F f1, F f2)
    {return f1 ^ f2;}
F id() {return false;}

int main() {
    int n, q, x, t, l, r;
    cin >> n >> q;

    vector<S> a(n);
    rep(i, 0, n) {
        cin >> x;
        a[i] = (x == 0 ? S{0, 1, 0} : S{1, 0, 0});
    }

    lazy_segtree<S, op, e, F, mapping, composition, id> lseg(a);

    rep(i, 0, q) {
        cin >> t >> l >> r;
        if (t == 1) {
            lseg.apply(l-1, r, true);
        } else {
            cout << lseg.prod(l-1, r)[2] << endl;
        }
    }
}


Measured memory_bytes: 20404
n,l=map(int,input().split())
if(l>=0):
	res=((n-1)*l)+((n*(n-1))//2)
else:
	if(abs(l)<n):
		res=(n*l)+((n*(n-1))//2)
	else:
		res=((n-1)*l)+(((n-2)*(n-1))//2)
print(res)

Measured memory_bytes: 3060
let () =
  Scanf.scanf "%s\n%s\n" @@ fun s t ->
  let ans = ref 0 in
  for i = 0 to (String.length s) - 1 do
    if s.[i] <> t.[i] then ans := !ans + 1
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 4712
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if (a == b) {
		cout << "YES" << endl;
		return 0;
	}
	if (w >= v) {
		cout << "NO" << endl;
		return 0;
	}
	if ((v - w) * t >= abs(a - b)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int main(){
  int n;
  map<string, int> items;
  string name;
  int value;
  
  while(cin >> n, n){
    items.clear();
    
    for(int i = 0 ; i < n ; i++){
      cin >> name >> value;
      items.insert(make_pair(name, value));
    }
    int m;
    int total;
    string names;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
      total = 0;
      cin >> name;
      cin >> m;
      for(int j = 0 ; j < m ; j++){
	cin >> names;
	total += items[names];
      }
      items[name] = min(items[name], total);
    }
    cin >> name;
    cout << items[name] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, k;
    cin >> a >> b >> k;
    if (a < k) {
        k -= a;
        a = 0;
        b = max(0LL, b - k);
    } else {
        a -= k;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define v(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
}

int main() {

    IO; 

    ll n;
    cin>>n;
    if(n<1200){
        cout<<"ABC"<<endl;
    }
    else{
        cout<<"ARC"<<endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n;
vector <int> a,b;

int get_mean(vector<int>& v)
{
	int t = (v.size()-1) / 2;
	return (v[t] + v[t+1]);
}

int get_mean_odd(vector<int>& v)
{
	int t = (v.size()) / 2;
	return v[t];
}


signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n;
	a.resize(n);
	b.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i] >> b[i];

	sort(all(a));
	sort(all(b));

	if(n%2 == 0)
	{
		int mn = get_mean(a);
		int mx = get_mean(b);

		cout << (mx - mn) + 1 << endl;
	}
	else
	{
		int mn = get_mean_odd(a);
		int mx = get_mean_odd(b);

		cout << (mx - mn) + 1 << endl;
	}

}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

using namespace std;

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

  int ans = 1e9;
  for (int i = 0; i <= n; i++) {
    int a = 1;
    for (int j = 0; j < i; j++) {
      a *= 2;
    }
    a += (n - i) * k;
    ans = min(ans, a);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    // 
    static final long MOD = 1_000_000_007;
    static final int MAX = 2000000000;
    static final int INF = 100000000;

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();   
        int high = n<m?m:n;
        int ans = 1+(l-1)/high;
        System.out.println(ans);
    }
}
  

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    
    set<int> check;
    
    bool ans;
    int x = A;
    while(true){
        x = x%B;
        if(x == C){
            ans = true;
            break;
        }else if(check.count(x)){
            ans = false;
            break;
        }
        check.insert(x);
        x += A;
    }
    
    if(ans){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char s[100001];
  scanf("%s",s);
  int len,i;
  len=strlen(s);
  int pos[len+1],lr[len+1],rl[len+1],lrlen=0,rllen=0;
  for(i=0;i<len;i++)
    pos[i]=0;
  for(i=0;i<len-1;i++){
    if(s[i]=='R' && s[i+1]=='L')
      rl[rllen++]=i;
    else if(s[i]=='L' && s[i+1]=='R')
      lr[lrlen++]=i;
  }
  lr[lrlen]=len-1;
  int j=0;
  for(i=0;i<len;i++){
    if(i>lr[j])
      j++;
    if((rl[j]-i)%2==0)
      pos[rl[j]]++;
    else
      pos[rl[j]+1]++;
  }
  for(i=0;i<len;i++)
    printf("%d ",pos[i]);
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n,-1){}

    int root(int x){
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y){
        int rx = root(x), ry = root(y);
        if(rx == ry) return false;
        if(size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

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

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

int main(){
	string s, ans = "NA";
	cin >> s;
	bool f1 = false, f2 = false;
	string a = s.substr(0,2), b = s.substr(2,2);
	if((a[0] == '0' && a[1] != '0' )|| (a[0] == '1' && (a[1] == '0' || a[1] == '1' || a[1] == '2'))) f1 = true;
	if((b[0] == '0' && b[1] != '0' )|| (b[0] == '1' && (b[1] == '0' || b[1] == '1' || b[1] == '2'))) f2 = true;
	if(f1 && f2) ans = "AMBIGUOUS";
	else if(f1) ans = "MMYY";
	else if(f2) ans = "YYMM";
	cout << ans << endl;
	return 0;
 }


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] line = br.readLine().split(" ");
		int prev = Integer.parseInt(line[0]);
		int now;
		int result = 0;
		int count = 0;
		for(int i=1; i<n; i++){
			now = Integer.parseInt(line[i]);
			if( prev >= now )
				count++;
			else{
				if( result < count )
					result = count;
				count = 0;
			}
			prev = now;
		}
		if( result < count )
			result = count;
		System.out.println(result);
	}
}


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

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

  vector<int> perm(N);
  for(int i=0; i<N; i++){
    cin >> perm.at(i);
    perm.at(i)--; // 1-indexed -> 0-indexed
  }

  vector<int64_t> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  int logK= 31- __builtin_clz(K);
  vector<vector<int>> trans(logK+1, vector<int>(N)); // trans.at(d).at(v): 頂点vから 2^d回操作したあとの遷移先
  trans.at(0)= perm;
  for(int d= 1; d<= logK; d++){
    for(int i=0; i<N; i++){
      trans.at(d).at(i)= trans.at(d-1).at(trans.at(d-1).at(i));
    }
  }
  
  vector<vector<int64_t>> sums(logK+1, vector<int64_t>(N)); // sums.at(d).at(v): 頂点vから 2^d回操作したあとのスコア
  vector<vector<int64_t>> cummaxs(logK+1, vector<int64_t>(N)); // cummaxs.at(d).at(v): 頂点vから 1回以上2^d回以下操作したあとの最大スコア
  for(int d=0; d<= logK; d++){
    for(int i=0; i<N; i++){
      sums.at(d).at(i)= (d > 0) ? sums.at(d-1).at(i)+ sums.at(d-1).at(trans.at(d-1).at(i))
                                : data.at(trans.at(0).at(i));
      cummaxs.at(d).at(i)= (d > 0) ? max(cummaxs.at(d-1).at(i), sums.at(d-1).at(i)+ cummaxs.at(d-1).at(trans.at(d-1).at(i)))
                                   : data.at(trans.at(0).at(i));
    }
  }

  vector<int64_t> memoK(N); // memoK.at(v): 頂点vから 1回以上K回以下操作したあとのスコアの最大値
  for(int i=0; i<N; i++){
    int64_t score_i= 0;
    int64_t walkthrough= 0;
    int v_walk= i;
    bool is_first= true;
    for(int d= logK; d>= 0; d--){
      if(K & (1<<d)){
        if(is_first){
          score_i= cummaxs.at(d).at(i);
          is_first= false;
        }
        else{
          score_i= max(score_i, walkthrough+ cummaxs.at(d).at(v_walk));
        }
        walkthrough+= sums.at(d).at(v_walk);
        v_walk= trans.at(d).at(v_walk);
      }
    }
    memoK.at(i)= score_i;
  }

  int64_t ans= INT64_MIN;
  for(auto score:memoK){
    ans= max(ans, score);
  }

  cout << ans << endl;
}

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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)

typedef long long ll;

using namespace std;

long compute_cost(
    const int n, const int a, const int b, const int c,
    const int index, vector<int>& l
) {
    vector<int> l_ret(3, 0);
    vector<long> cost_(3, 0);

    // indexをn桁の4進数に変換、その4進数がn本の棒の使用方法に対応
    int tmp = index;
    REP(int, i, 0, n) {
        int use = tmp % 4; // 0: 不使用; 1,2,3: 長さa,b,cの棒の材料にする
        tmp /= 4;

        if (use == 0) continue;
        
        if (l_ret[use-1] > 0) cost_[use - 1] += 10;  // 合成魔法のコスト計算
        l_ret[use - 1] += l[i];  // 合成魔法後の棒の長さ
    }

    // 棒が3本できていない場合を除外
    int l_min = *min_element(l_ret.begin(), l_ret.end());
    if (l_min <= 0) return LONG_MAX;

    long sum_cost = cost_[0] + cost_[1] + cost_[2];
    sum_cost += abs(l_ret[0] - a) + abs(l_ret[1] - b) + abs(l_ret[2] - c); // 他の魔法のコスト
    return sum_cost;
}

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

    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    REP(int, i, 0, n) {
        cin >> l[i];
    }

    int num_all = pow(4, n);
    long cost_min = LONG_MAX;
    REP (int, i, 0, num_all) {
        long cost = compute_cost(n, a, b, c, i, l);
        cost_min = min(cost_min, cost);
    }
    cout << cost_min << endl;

    return 0;
}


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

using namespace std;

const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;

      vector<vector<int>> graph(H, vector<int>(W, -1));
      graph[i][j] = 0;

      queue<pair<int, int>> que;
      que.push(make_pair(i, j));

      while (!que.empty()) {
        auto q = que.front();
        que.pop();

        int y = q.first, x = q.second;
        for (int k = 0; k < 4; k++) {
          int ny = y + dy[k], nx = x + dx[k];
          if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
          if (S[ny][nx] == '#' || graph[ny][nx] != -1) continue;

          graph[ny][nx] = graph[y][x] + 1;
          que.push(make_pair(ny, nx));
        }
      }

      int maxn = 0;
      for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
          maxn = max(maxn, graph[y][x]);
        }
      }

      res = max(res, maxn);
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	ll len;
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		cin >> len;
		char s[1000000];
		vector<ll>a;
		ll cont = 0;
		ll  starti = 0;
		roop(i, len) {
			cin >> s[i];
			if (cont > 0 && (starti - i) % 2 == 0)
			{
				if (s[i] == 'I'&&s[i - 1] == 'O'&&s[i - 2] == 'I') {
					cont++;
				}
				else {
					a.push_back(cont);
					cont = 0;
				}
			}
			else if (i >= 2 && cont == 0) {
				if (s[i] == 'I'&&s[i - 1] == 'O'&&s[i - 2] == 'I') {
					cont++;
				}
				starti = i;
			}
		}
		ll ans = 0;
		a.push_back(cont);
		roop(i, a.size()) {
			if (a[i] >= n) {
				ans += a[i] - n + 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 4076
import collections

n = int(raw_input())
p = map(int,raw_input().split(' '))
q = map(int,raw_input().split(' '))


elems = range(1, n+1)
res = []
c = [0]
def perms(i, elems,res):

	if i == len(elems):
		res.append(tuple(elems)) 
		return 
	for j in range(i, len(elems)):
		elems[j], elems[i] = elems[i], elems[j]
		perms(i+1, elems, res)
		elems[j], elems[i] = elems[i], elems[j]

perms(0, elems, res)

tp = tuple(p)
tq = tuple(q)
res.sort()
for i in range(len(res)):
	if res[i] == tp:
		ii = i

	if res[i] == tq:
		jj = i

print abs(jj - ii)

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

#define int int64_t
#define pii pair<int,int>
#define f first
#define s second

int solve(pii p[] , int n , int w) {
    int i , j , k, l;
    vector < vector < int > >dp(n+1 , vector < int > (w+1 , 0));
    for(i=1;i<=n;i++) {
        for(j=1;j<=w;j++) {
            dp[i][j] = dp[i-1][j];
            if(j - p[i].f >= 0) {
                dp[i][j] = max(dp[i][j] , dp[i-1][j-p[i].f] + p[i].s);
            }
        }
    }
    return dp[n][w];
}

int32_t main() {
	int n , w , i , j , k , l , c;
	cin >> n >> w;
	pii p[n+1];
	for(i=1;i<=n;i++) {
	    cin >> p[i].f >> p[i].s;
	}
	sort(p+1 , p+1+n , [&](pii &a , pii &b) {
	    if(a.f == b.f) return a.s > b.s;
	    return a.f < b.f;
	});
	cout << solve(p , n , w) << endl;
	return 0;
}

Measured memory_bytes: 80256
import sys
sys.setrecursionlimit(10**5)

def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LI_(): return [-1*int(x) for x in input().split()]
def II(): return int(input())
def IF(): return float(input())
def LM(func,n): return [[func(x) for x in input().split()]for i in range(n)]
mod = 1000000007
inf = float('INF')

def isCat(S):
    #print(S)
    if len(S) == 0:
        return True
    if S[0] != "m" or S[-1] != "w":
        return False
    c = 0
    i=0
    for i in range(1,len(S)-1):
        if S[i] == 'm':
            c += 1
        elif S[i] == 'w':
            c -= 1
        if c ==0:
            break
    if S[1] == 'e':
        i = 0
    return S[i+1] == 'e' and isCat(S[1:i+1]) and isCat(S[i+2:-1])



if(isCat(input())):
    print("Cat")
else:

    print("Rabbit")


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

int N, M;
vector<int> s, c;

bool ok(string str) {
    if (str.size() != N) return false;
    for (int i = 0; i < M; ++i){
        // charに型変換するとき '0' 付与しないとダメ（要勉強）
        if (str[s[i]] != (char)(c[i] + '0')) return false;
    }
    return true;
}

// 0以上10^N未満の整数を全探索する。Nは3までなので999が最大。
// 条件チェックのため文字列に変換してる。
string solve() {
    for (int i = 0; i <= 999; ++i) {
        stringstream iss; iss << i;
        string str = iss.str();
        if (ok(str)) return str;
    }
    return "-1";
}

int main() {
    cin >> N >> M;
    s.resize(M); 
    c.resize(M);
    for (int i = 0; i < M; ++i){
        cin >> s[i] >> c[i];
        //cout << "s[i]: " << s[i] << endl;
        --s[i]; // ok()でstr[s[i]]とs[i]を添字とするためデクリメントする(1ケタ目ならstr[0])
        //cout << "--s[i]: " << s[i] << endl;
    }
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int dp[(1<<15)+5][16],n,m;
int c[15][(1<<15)],u[15][15];
ll *zip[(1<<15)];
int main(){
	cin>>n>>m;
	rep(i,m){
		int a,b;cin>>a>>b;
		a--; b--;
		u[a][b] = 1;
	}
	rep(i,n)rep(j,(1<<n)){
		if(((j>>i)&1)) continue;
		rep(k,n){
			if(((j>>k)&1)) if(u[i][k]) c[i][j]++;
		}
	}
	//cout<<c[0][2]<<" " <<c[1][1]<<endl;
	dp[0][0] = 1; ll ret=0;
	rep(i,(1<<n)) zip[i] = new ll[(1<<__builtin_popcount(i))];
	for(int t=0;t<n;t++){
		for(int mask=0;mask<(1<<n);mask++){
			int x = mask,num = 0;
			while(1){
				//dp[x][t] -> dp[mask][t+1]
				int y = mask-x,z = (1<<n)-1-mask;
				ll val = 1;
				if(!t){
	    				rep(i,n){
	    					if(((x>>i)&1)){
	    						val = val*(1LL<<c[i][y])%mod;
	    					}
	    					else if(((z>>i)&1)){
	    						val = val*((1LL<<c[i][y])-1LL)%mod;
	    					}
	    				}
	    				zip[mask][num++] = val;
				}else val = zip[mask][num++];
				
				if(y%4 != 3){
				    dp[mask][t+1] = dp[mask][t+1]+dp[x][t]*val%mod;
				    dp[mask][t+1]%=mod;
				    if(mask == (1<<n)-1 && y) ret+=dp[x][t]*val%mod;
				}
				if(x == 0) break;
				x = (x-1)&mask;
				//cout<<x<<" " <<mask<<endl;
			}
		}
	}
	cout<<ret%mod<<endl;
}

Measured memory_bytes: 118912
N = int(input())
R = []
for i in range(N):
    s, p = map(str, input().split())
    R.append([i+1, s, int(p)])
R.sort(key=lambda x:x[2], reverse=True)
R.sort(key=lambda x:x[1])
for r in R:
    print(r[0])

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
const int INF = 2147483647;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

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

	if (s.find("AC") != s.npos) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+87;
int n;
ll s[N],f[N],g[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> s[i];
    --n;
    ll ans = 0;
    for (int c = 1; c < n; ++c) {
        for (int i = 1; i * c <= n; ++i) 
            f[i] = f[i-1] + s[i*c];
        g[0] = s[n%c];
        int j=0;
        for (int i = 1; n%c+i * c <= n; ++i) {
            g[i] = g[i-1] + s[i*c+n%c];
            j = i;
        }
        for (int a = n%c; a < n; a += c) {
            if (a <= c)
                continue;
            int k = (n-a)/c;
            int l = a/c-1;
            if (n%c != 0 || l+1>k)
                ans = max(ans, f[k] + g[j] - (l>=0?g[l]:0));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560