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

int main() {
  
  int N; cin >> N; int ans = 0;
  
  for (int i = 0; i < N; i++) {
    int l, r; cin >> l >> r;
    ans += r - l + 1;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;
const int maxn = 10005;
int a[maxn];
int b[maxn];
int c[maxn];
int main()
{
    int n;
    cin >> n;
    ll sum1 = 0, sum2 = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum1 += a[i];
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> b[i];
        sum2 += b[i];
    }
    ll sum3 = 0;
    for(int i = 1; i <= n; i++)
    {
        if(a[i] > b[i])sum3 += a[i]-b[i];
    }
    bool ok = false;
//    if((sum2-sum1) < 0 || sum3 > (sum2-sum1) )ok = false;
        ll cao = 0;
        ll ni = 0;
    int ji = 0;
    for(int i = 1; i <= n; i++)
    {
        if(b[i] > a[i])
        {
            ll kk = (b[i]-a[i])/2;
            cao += kk;
        }
        else
        {
            ni += a[i]-b[i];
        }
    }
    if(cao >= ni)ok = true;
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
/*
                 ___====-_  _-====___
           _--^^^#####//      \\#####^^^--_
        _-^##########// (    ) \\##########^-_
       -############//  |\^^/|  \\############-
     _/############//   (@::@)   \\############\_
    /#############((     \\//     ))#############\
   -###############\\    (oo)    //###############-
  -#################\\  / VV \  //#################-
 -###################\\/      \//###################-
_#/|##########/\######(   /\   )######/\##########|\#_
|/ |#/\#/\#/\/  \#/\##\  |  |  /##/\#/  \/\#/\#/\#| \|
`  |/  V  V  `   V  \#\| |  | |/#/  V   '  V  V  \|  '
   `   `  `      `   / | |  | | \   '      '  '   '
                    (  | |  | |  )
                   __\ | |  | | /__
                  (vvv(VVV)(VVV)vvv)
                  ÁúÉñ±£ÓÓ ÓÀÎÞbug
*/


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

int main(){
	int n;cin>>n;int a[100],maxp=0,t,sum=0;
	for(int i=0;i<n;++i){
    	cin>>a[i];
      	sum+=a[i];
      	maxp=max(maxp,a[i]);
      	if(maxp==a[i])t=i;
    }
  	cout<<sum-a[t]/2<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;
#define MAX_N 400

// Input
char S[MAX_N];

int main() {
  cin >> S;

  if ((S[2] == S[3]) && (S[4] == S[5])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    int n;
    cin>>n;
    
    int k=n;
    
    int sum=0;
    while(k>=1){
        sum+=k%10;
        k/=10;
    }
    
    if(n%sum==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> res;
    for (ll i = 2; i*i <= n; ++i){
        if (n%i) continue;
        res.emplace_back(i, 0);
        while (n%i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

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

    auto res = factorize(m);
    combination c(1e6+1);
    mint ans = 1;
    rep(i, res.size()){
        ans *= c(n + res[i].second - 1, res[i].second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18808
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from itertools import product

N = I()
D = III()

if 0 in D:
    print(0)
elif N>=24:
    print(0)
elif N==23:
    D.sort()
    for i in range(N):
        if D[i]!=i//2+1:
            print(0)
            exit()
    print(1)
else:
    a = list(product([0,1],repeat=N))
    ans = 0
    for a0 in a:
        l = [False]*24
        flag = False
        for i in range(N):
            if a0[i]==0:
                if l[D[i]]:
                    flag = True
                    break
                else:
                    l[D[i]] = True
            else:
                if l[24-D[i]]:
                    flag = True
                    break
                else:
                    l[24-D[i]] = True
        if flag:
            continue
        before = 0
        val = 13
        for i in range(24):
            if l[i]:
                temp = min(i-before, 24-i+before)
                before = i
                if temp<val:
                    val = temp
        temp = min(before,24-before)
        if temp<val:
            val = temp
        if val>ans:
            ans = val
    print(ans)

Measured memory_bytes: 42736
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9



int main() {
	int n;
	cin >> n;
	int a[200005];
	fill(a, a + 3+n, INF);
	a[0] = 0;
	a[1] = 1;


	int six, nine;

	for (int i = 2;i <= n;i++) {
		six = 6;nine = 9;
		a[i] = a[i - 1]+1;
		while (six <=i ) {
			a[i] = min(a[i], (a[i - six] + 1));
			six *= 6;
		}
		while (nine <= i) {
			a[i] = min(a[i], (a[i - nine] + 1));
			nine *= 9;
		}

	}

	cout << a[n] << endl;

	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[][] alpha = new int[n][26];
		
		for(int i = 0; i < n; i++) {
			char[] str = sc.next().toCharArray();
			
			for(int j = 0; j < str.length; j++) {
				alpha[i][str[j] - 'a']++;
			}
		}
		
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < 26; i++) {
			int maxCount = Integer.MAX_VALUE;
			for(int j = 0; j < n; j++) {
				maxCount = Math.min(maxCount, alpha[j][i]);
			}
			
			for(int j = 0; j < maxCount; j++) {
				sb.append((char)(i + 'a'));
			}
		}
		
		System.out.println(sb);
	}

}


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

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

Measured memory_bytes: 3560
# -*- coding: utf-8 -*-
import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    T=[int(input()) for i in range(N)]
    lcm=1
    for x in T:
        lcm*=x//gcd(lcm,x)
    print(lcm)

if __name__ == '__main__':
    main()


Measured memory_bytes: 64716
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()
K = int(input())

import functools

@functools.lru_cache(None)
def rec(i, k, is_same):
    if k == 0:
        return 1
    if i == 0:
        if k >= 2:
            return 0
        if is_same == 1:
            return int(S[len(S) - i - 1])
        else:
            return 9

    res = 0
    a = int(S[len(S) - i - 1])
    if is_same == 1:
        for x in range(a + 1):
            if x == a and x == 0:
                res += rec(i - 1, k, 1)
            elif x == 0:
                res += rec(i - 1, k, 0)
            elif x == a:
                res += rec(i - 1, k - 1, 1)
            else:
                res += rec(i - 1, k - 1, 0)
    else:
        for x in range(10):
            if x == 0:
                res += rec(i - 1, k, 0)
            else:
                res += rec(i - 1, k - 1, 0)
    return res

n = len(S)
res = rec(n - 1, K, 1)
print(res)

Measured memory_bytes: 9640
#!/usr/bin/env ruby

a, b, c = gets.chomp.split.map(&:to_i)

K = gets.chomp.to_i + 1

K.times do
  warn [a, b, c].inspect
  if a < b && b < c
    puts 'Yes'
    exit
  end

  if a >= b
    b *= 2
    next
  end

  if b >= c
    c *= 2
  end
end

puts 'No'


Measured memory_bytes: 14380
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll n, m,ans=0,a,b; cin >> n >> m;	
 	priority_queue<ll> que;
	vector<vector<int>> d(100001, vector<int>());
	for (int i = 0; i < n; i++) 
		cin >> a >> b , d[a].push_back(b);
	for (int i = 1; i < m+1; i++) 
    {
		for (int j = 0; j < d[i].size(); j++) 
			que.push(d[i][j]);
		if (!que.empty()) 
			ans += que.top() , que.pop();
	}
	cout << ans;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N;
    cin >> N;
    string s, t;
    cin >> s;
    cin >> t;

    int ans = 2*N;

    for(int j=0; j<N; j++){
        string s_suf = s.substr(j,N-j);
        string t_pre = t.substr(0,N-j);
        if(s_suf == t_pre){
            ans -= (N-j);
            break;
        }
    }

    cout << ans << endl;
    return 0;


}

Measured memory_bytes: 3576
#include <stdio.h>
#include <math.h>
int main()
{
	int tanka[100];
	int kosuu[100];
	int i=0;
	int sum=0;
	int kazu=0;
	int ret;
	int count;
	double heikin=0;
	while(1){
		ret=scanf("%d,%d",&tanka[i],&kosuu[i]);    //tanka[i]とkosuu[i]に数字を入れる；
		if(ret==EOF){
			break;
		}
		i++;
	}
	count=i;
	for(i=0; i<count; i++){
		sum+=tanka[i]*kosuu[i];       //合計金額の計算
		kazu+=kosuu[i];               //数量合計の計算（平均計算のため）
	}
	heikin=(double)kazu/(double)count;    //数量平均の計算
	heikin=floor(heikin+0.5);         //平均値を四捨五入する（0.5を加えて、小数点以下を切り捨てる）
	kazu=(int)heikin;                 //heikin（実数）をkazu（整数）に入れる。小数点以下は既に四捨五入してある。
	printf("%d\n",sum);     //合計金額の表示
	printf("%d\n",kazu);    //数量平均の表示
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int i=1;
  while(1)
  {
    long long int a;
    cin>>a;
    if(a==0)
      break;
    else
      i+=1;
  }
  cout<<i;
  return 0;
}

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

int w, h, n, b[20], k[20], px[20], py[20], ans;
int res[20][20];

bool check(int id, const vector<vector<int> > &s, int sx, int sy, int gx, int gy){
	if( sx <= px[id] && px[id] <= gx && sy <= py[id] && py[id] <= gy ){
		bool flag = false;
	
		for(int y = sy; y <= gy; y++){
			for(int x = sx; x <= gx; x++){
				if( s[y][x] == id + 1 ){
					flag = true;
				}else if( s[y][x] != 0 ){
					return false;
				}
			}
		}
		return flag;
	}
	return false;
}

void fill_(int id, vector<vector<int> > &next, int sx, int sy, int gx, int gy){
	for(int y = sy; y <= gy; y++){
		for(int x = sx; x <= gx; x++){
			next[y][x] = id + 1;
		}
	}
}

void debug(const vector<vector<int> > &s){
	cout << "debug:" << endl;
	for(int y=0; y < h; y++){
		for(int x = 0; x < w; x++){
			if( x ) cout << " ";
			cout << s[y][x];
		}
		cout << endl;
	}
	cout << endl;
}

// id := 購入者番号, id = [0,n)
void dfs(int id, const vector<vector<int> > &s){
	
	if( id == n ){ // ぜんぶ調べた
		ans++;
		for(int y=0; y < h; y++){
			for(int x = 0; x < w; x++){
				res[y][x] = s[y][x];
			}
		}
	}else{
		
		for(int sy = 0; sy < h; sy++){
			for(int sx = 0; sx < w; sx++){
				for(int gy = sy; gy < h; gy++){
					for(int gx = sx; gx < w; gx++){
						int width = gx - sx + 1, height = gy - sy + 1;
						
						if( width * height == k[id] && check(id, s, sx, sy, gx, gy) ){
							vector<vector<int> > next = s;
							fill_(id, next, sx, sy, gx, gy);
							dfs(id + 1, next);
						}
					}
				}
			}
		}
	}
}

int main(){
	while( cin >> w >> h >> n, w || h || n ){
		for(int i = 0; i < n; i++) cin >> b[i] >> k[i];
		
		vector<vector<int> > s(h, vector<int>(w));
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				cin >> s[y][x];
				if( s[y][x] != 0 ){
					px[s[y][x]-1] = x;
					py[s[y][x]-1] = y;
				}
			}
		}
		
		ans = 0;
		dfs(0, s);
		if( ans != 1 ){
			cout << "NA" << endl;
		}else{
			for(int y=0; y < h; y++){
				for(int x = 0; x < w; x++){
					if( x ) cout << " ";
					cout << res[y][x];
				}
				cout << endl;
			}
		}
	}
}

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

using namespace std;
#define ll  long long
#define ld  long double

#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
string h;
int a, b, k;

ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (!(b & 1)) {
        return fastPow(x * x, b / 2);
    } else
        return x * fastPow(x * x, (b - 1) / 2);
}

//__builtin_popcount ();
ll arr[MAXN],ok1[MAXN],pre[MAXN],pre1[MAXN];

int main() {
    FAST
    int a,b;
    cin>>a>>b;
for(double i=1;i<=(int)1e5;i++)
{
    if(floor(i*.08) ==a && floor(i*.1)==b)
        return cout<<i,0;
}
cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,j,n,y;
	int card[4][13]={0};
	char f;
	
	scanf("%d\n",&n);
	
	for(j=0;j<n;j++)
	{
		scanf("%c%d\n",&f,&y);
		if(f=='S')
			card[0][y-1] = 1;
		else if(f=='H')
			card[1][y-1] = 1;
		else if(f=='C')
			card[2][y-1] = 1;
		else if(f=='D')
			card[3][y-1] = 1;
	}
	
	for(i=0;i<4;i++)
	{
		for(j=0;j<13;j++)
		{
			if(i == 0 && card[i][j]==0)
				printf("S %d\n",j+1);
			if(i == 1 && card[i][j]==0)
				printf("H %d\n",j+1);
			if(i == 2 && card[i][j]==0)
				printf("C %d\n",j+1);
			if(i == 3 && card[i][j]==0)
				printf("D %d\n",j+1);
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int sum = 0;
		for(int i = 1; i <= K; i ++) {
			for(int j = 1; j <= K; j ++) {
				for(int k = 1; k <= K; k ++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		int ret = 0;
		int max = Math.max(a, b);
		int min = Math.min(a, b);
		int amari = 0;
		while(true) {
			amari = max % min;
			if(amari == 0) {
				ret = min;
				break;
			}
			max = min;
			min = amari;
		}
		return ret;
	}
}

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

"""
input:
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0

output:
6
"""

import sys


class Rectangle(object):
    __slots__ = ('pos', 'height')

    def __init__(self, pos=float('inf'), height=-1):
        """
        init a Rectangle
        """
        self.pos = pos
        self.height = height


def gen_rec_info(_carpet_info):
    dp = [[float('inf')] * W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if int(_carpet_info[i][j]):
                dp[i][j] = 0
            else:
                dp[i][j] = dp[i - 1][j] + 1 if i else 1

    return dp


def get_largest_area(_hi_info):
    hi_max_area = 0
    rec_stack = []
    _hi_info.append(0)

    for i, v in enumerate(_hi_info):
        rect = Rectangle(pos=i, height=int(v))
        if not rec_stack:
            rec_stack.append(rect)
        else:
            last_height = rec_stack[-1].height
            if last_height < rect.height:
                rec_stack.append(rect)
            elif last_height > rect.height:
                target = i
                while rec_stack and rec_stack[-1].height >= rect.height:
                    pre = rec_stack.pop()
                    area = pre.height * (i - pre.pos)
                    hi_max_area = max(hi_max_area, area)
                    target = pre.pos
                rect.pos = target
                rec_stack.append(rect)

    return hi_max_area


def solve(_rec_info):
    overall_max_area = 0
    for hi_info in _rec_info:
        overall_max_area = max(overall_max_area, get_largest_area(hi_info))

    return overall_max_area


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    H, W = map(int, _input[0].split())
    carpet_info = list(map(lambda x: x.split(), _input[1:]))

    rec_info = gen_rec_info(carpet_info)
    # print(rec_info)
    ans = solve(rec_info)
    print(ans)

Measured memory_bytes: 69912
#include<stdio.h>
int main(){
  int n,k,ans=1,cnt=0;
  scanf("%d",&n);
  scanf("%d",&k);
  while(cnt<n){
    if(ans*2>ans+k){
      ans=ans+k;
      cnt++;
      // printf("%d\n",ans);
    }
    else{
      ans=ans*2;
      cnt++;
      // printf("%d\n",ans);
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;


//initialization here
//
int n, ma, mb;
int a[50], b[50], c[50];
int dp[50];
//
//initialization finish


// your function is here
//

//
// your function finished



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

	// your code is here
	//

	int n; cin >> n;
	string s; cin >> s;

	int ma = 0;
	int count = 0;
	rep(i, n)
	{
		if (s[i] == 'I')count++;
		else count--;

		ma = max(ma, count);
	}

	Print(ma);

	//
	// your code finished
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    ll cnt[n];
    fill(cnt, cnt+n, 0);
    for (int i=0; i<n; i++) {
        cin >> a[i];
        if (i - a[i] >= 0) cnt[i - a[i]]++;
    }
    ll ans = 0;
    for (int i=0; i<n; i++) {
        if (i + a[i] < n) ans += cnt[i + a[i]];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5968
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MD 1000000007

char sep[2] = {' ', '\n'};

int main() {
  int i, j, k, n, m, l;

  char str[1010];

  while(true) {
    scanf("%s", str);
    int len = strlen(str);
    int z = 0;
    rep(i, len) z += str[i] - '0';
    if (z == 0) break;
    cout << z << endl;
  }

  return 0;
}
  

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


int32_t main()
{
    int n,k;
    cin >> n >> k;
    
    vector<pair<int,int> >edges;
    vector<pair<int,int> >overall;

    if(k>((n-1)*(n-2)/2)) 
    {
        cout<<-1<<endl;
        return 0;
    }

    for(int i=2;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            overall.push_back({i,j});
        }
    }

    for(int i=2;i<=n;++i)
    {
        edges.push_back({1,i});
    }

    int left = (n-1)*(n-2)/2 - k;

    for(int i=0;i<left;++i)
    {
        edges.push_back(overall[i]);
    }


    cout<<edges.size()<<endl;
        for(auto i : edges)
        {
            cout<<i.first<<" "<<i.second<<endl;
        }
        //return 0;


    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
 
int main() {
  string s;
  char a;
  int res=0;

  cin >> s;

  a = s.at(0);

  for(int i = 1; i < s.size(); i++)
  {
    if(a == s.at(i)){
      res++;
      if(s.at(i)=='0'){
        s.at(i)='1';
      } 
      else{
        s.at(i)='0';
      }
    }
    a = s.at(i);
  }
  
  cout << res << endl;

}

Measured memory_bytes: 512
N, M = map(int, input().split())
E = [list(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        
        self.par[x] = self.find(self.par[x])
        return self.par[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def check_root(self, x, y):
        return self.find(x) == self.find(y)

ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j, e in enumerate(E):
        if j != i:
            uf.unite(e[0]-1, e[1]-1)
    
    if not uf.check_root(E[i][0]-1, E[i][1]-1):
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

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

  unsigned N, W;
  std::cin >> N >> W;
  unsigned weight, value;

  std::vector<std::vector<size_t>> dp(2);

  dp[0] = std::vector<size_t>(W+1, 0);
  dp[1] = std::vector<size_t>(W+1, 0);

  for (unsigned i = 1; i < N+1; ++i)
  { 
    std::cin >> weight >> value;
    for (unsigned j = 0; j < W+1; ++j)
    { 
      if (j >= weight)
      { 
        dp[1][j] = std::max(dp[0][j], dp[0][j-weight] + value);
      }
      else
      { 
        dp[1][j] = dp[0][j];
      }
    }
    dp[0].swap(dp[1]);
  }
  std::cout << dp[0][W];
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
    int di[7],a[7];
    char ch;
    int i;
    for(i=1;i<=6;i++){
        scanf("%d\n",&di[i]);
        a[i]=di[i];
    }
    /*for(i=1;i<=6;i++){
        printf("%d ",di[i]);
    }
    printf("\n");*/
    while(1){
        scanf("%c",&ch);
        //printf("%c\n",ch);
        if(ch=='\n'){
            break;
        }else if(ch=='N'){
            a[1]=di[2];
            a[2]=di[6];
            a[5]=di[1];
            a[6]=di[5];
        }else if(ch=='S'){
            a[2]=di[1];
            a[6]=di[2];
            a[1]=di[5];
            a[5]=di[6];
        }else if(ch=='E'){
            a[1]=di[4];
            a[4]=di[6];
            a[6]=di[3];
            a[3]=di[1];
        }else if(ch=='W'){
            a[4]=di[1];
            a[6]=di[4];
            a[3]=di[6];
            a[1]=di[3];
        }
        for(i=1;i<=6;i++){
            di[i]=a[i];
        }
    }
    printf("%d\n",di[1]);
    return 0; /*0?????????*/
}

Measured memory_bytes: 1820
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
	string c = "JOI";
	map<char, int> mc;
	for (int i = 0; i < c.size(); ++i) mc[c[i]] = i;

 	int w, h; cin >> h >> w;
	int k; cin >> k;
	vector<string> m(h);
	for (int y = 0; y < h; ++y) {
		cin >> m[y];
	}

	vector< vector< vector<int> > > s(3, vector< vector<int> >(h+1, vector<int>(w+1, 0)));
	for (int i = 0; i < 3; ++i) {
		for (int y = 1; y <= h; ++y) {
			for (int x = 1; x <= w; ++x) {
				if (m[y-1][x-1] == c[i]) s[i][y][x] = 1;
			}
		}
		for (int y = 1; y <= h; ++y) {
			for (int x = 2; x <= w; ++x) {
				s[i][y][x] += s[i][y][x-1];
			}
		}
		for (int x = 1; x <= w; ++x) {
			for (int y = 2; y <= h; ++y) {
				s[i][y][x] += s[i][y-1][x];
			}
		}
	}

	for (int t = 0; t < k; ++t) {
		int x1, y1, x2, y2; cin >> y1 >> x1 >> y2 >> x2;
		for (int i = 0; i < 3; ++i) {
			if (i) cout << " ";
			cout << (s[i][y2][x2] + s[i][y1-1][x1-1] - s[i][y2][x1-1] - s[i][y1-1][x2]);
		}
		cout << endl;
	}
}

Measured memory_bytes: 17904
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

void radix_sort(vector<int>::iterator b,vector<int>::iterator e) {
    vector<int> t(e - b);
    array<int, 256> c, s;
    for (int i = 0; i < 32; i += 8) {
        fill(c.begin(), c.end(), 0);
        for_each(b, e, [&](int j) {c[(j >> i) & 255]++;});
        s[0] = 0;
        partial_sum(c.begin(), c.end() - 1, s.begin() + 1);
        for_each(b, e, [&](int j) {t[s[(j >> i) & 255]++] = j;});
        copy(t.begin(), t.end(), b);
    }
}

int main() {
	for (int N, M; N = in(), M = in();) {
		vector<int> t(N), u;
		for (int &p: t)
			p = in();
		t.push_back(0);
		for (auto i = t.begin(); i != t.end(); i++)
			for (auto j = i; j != t.end(); j++)
				if (*i + *j <= M)
					u.push_back(*i + *j);
		radix_sort(u.begin(), u.end());
		int r = 0;
		for (auto i = u.begin(), e = u.end() - 1; i <= e; i++) {
			for (; *i + *e >= M; e--)
				;
			r = max(r, *i + *e);
		}
		outl(r);
	}
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct SegTree {
	std::vector<int64_t> data;
	int n;
	SegTree (int n_) {
		for (n = 1; n < n_; n <<= 1);
		data.resize(n << 1);
	}
	void assign(int i, int64_t val) {
		for (data[i += n] = val; i >>= 1; ) data[i] = std::max(data[i << 1], data[i << 1 | 1]);
	}
	int64_t max(int l, int r) {
		int64_t res = 0;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) res = std::max(res, data[--r]);
			if (l & 1) res = std::max(res, data[l++]);
		}
		return res;
	}
	int64_t operator [] (int i) { return data[i + n]; }
};
int main() {
	int n = ri();
	int h[n];
	for (int i = 0; i < n; i++) h[i] = ri() - 1;
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	SegTree tree(n);
	for (int i = 0; i < n; i++)
		tree.assign(h[i], tree.max(0, h[i]) + a[i]);
	std::cout << tree.max(0, tree.n) << std::endl;
	return 0;
}


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

typedef long long ll;

const int MOD = 1e9 + 7;
const int N = 1e6 + 1;
int r1, c1, r2, c2;
ll res;
ll fac[N * 2];
ll inv[N * 2];

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = res * a % MOD;
        }
        b >>= 1;
        a = a * a % MOD;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N * 2; ++i) {
        fac[i] = fac[i - 1] * i % MOD;
    }
    inv[N * 2 - 1] = power(fac[N * 2 - 1], MOD - 2);
    for (int i = N * 2 - 2; i >= 0; --i) {
        inv[i] = inv[i + 1] * (i + 1) % MOD;
    }
}

int comb(int a, int b) {
    return fac[a] * inv[b] % MOD * inv[a - b] % MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    init();

    cin >> r1 >> c1 >> r2 >> c2;

    for (int i = r1; i <= r2; ++i) {
        res = (res + comb(c2 + i + 1, i + 1) - comb(c1 + i, i + 1) + MOD) % MOD;
    }
    cout << res << endl;

    return 0;
}



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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	bool ok = true;
	rep(i,n){
		if(i%2 == 0 && s[i] == 'L') ok = false; 
		if(i%2 == 1 && s[i] == 'R') ok = false; 
	}
	if(ok) puts("Yes");
	else puts("No");
	return 0;
}

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

int main(){
  int n,a,b,x=0,y=0,z=0;
  cin>>n>>a>>b;
  for(int i=0; i<n; i++){
    int p;
    cin>>p;
    if(p<=a)x++;
    else if(p<=b)y++;
    else z++;
  }
  cout<<min(min(x,y),z)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

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

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main() {

	int a, b;
	long long int result[3];

	scanf("%d %d", &a, &b);

	result[0] = a + b;
	result[1] = a - b;
	result[2] = a * b;

	qsort(result, 3, sizeof(long long int), compare_int);
	printf("%lld", result[2]);

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin>>n;
  string w[n]; for(int i=0; i<n; i++) cin>>w[i];
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(w[i]==w[j]){
        cout<<"No";
        return 0;
      }
    }
  }
  for(int i=1; i<n; i++){
    if(w[i-1][w[i-1].size()-1]!=w[i][0]){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 3600
#
from collections import Counter

d = int(input())
l = []
for k in range(d):
  r = input()
   
  l.append(Counter(r))

oi = l[0]

for g in range(1,d):
    oi = oi & l[g]
    
    
print("".join(sorted(oi.elements())))



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll M1, D1, M2, D2; cin >> M1 >> D1 >> M2 >> D2;
    if (M1 + 1 == M2){cout << 1 << endl;}else{cout << 0 << endl;}
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll dp[61][3]={};
    dp[60][0]=1;
    for(int i=59;i>=0;i--){
        for(int j=0;j<=2;j++){
            for(int k=0;k<=2;k++){
                int kk=min(2,2*j+(int)((n>>i)&1)-k);
                if(kk>=0){
                    (dp[i][kk]+=dp[i+1][j])%=mod;
                }
            }
        }
    }
    cout << (dp[0][0]+dp[0][1]+dp[0][2])%mod << endl;
}

Measured memory_bytes: 256
N = int(input())

def f(num, use, counter):
    if num >N:
        return
    if use == 0b111:
        counter.append(1)
    f(num*10 + 7, use | 0b001, counter)
    f(num*10 + 5, use | 0b010, counter)
    f(num*10 + 3, use | 0b100, counter)

ans = []
f(0, 0, ans)
print(sum(ans))

Measured memory_bytes: 9400
K = int(input())
S = input()

m = 1000000007

result = 0
t = pow(26, K, m)
u = pow(26, -1, m) * 25 % m
l = len(S)
for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result = (result + t) % m
    t = (t * u) % m * (l + i) * pow(i + 1, -1, m) % m
print(result)


Measured memory_bytes: 10892
#include <stdio.h>

int main()
{
    int a, b, c;
    int tmp;
    scanf("%d %d %d", &a, &b, &c);
    tmp = a;
    a = b;
    b = tmp;
    tmp = c;
    c = a;
    a = tmp;
    printf("%d %d %d", a, b, c);
    return (0);
}

Measured memory_bytes: 128
#include<stdio.h>
int n, m, i, j, k, ans, x, y;
char s[200005], t[200005];
int main()
{
	scanf ("%s%s", s, t);
	n = sizeof(s);
	for (i=0; i<n; i++)
	{
		if (s[i] != t[i])
		{
			ans++;
		}
	}
	printf ("%d", ans);
	return 0;
}

Measured memory_bytes: 2112
N, K = map(int, input().split())
W = [int(input()) for _ in range(N)]
P_MIN = max(W)
P_MAX = 10 ** 9
while P_MIN < P_MAX:
    P = (P_MAX + P_MIN) // 2  # トラックの最大積載量
    M = 0
    i = 0
    while i < N:  # 最大積載量Pのトラックに荷物がなくなるまで載せる
        mass = 0  # トラックは初め何も載っていない
        while i < N and mass + W[i] <= P:  # 荷物がなくなるか，トラックに積めなくなるまで荷物を載せる
            mass += W[i]
            i += 1
        M += 1  # 使用したトラックの台数が1だけ増える
    if M > K:  # 最大積載量が小さすぎて，トラックが足りない場合
        P_MIN = P + 1
    elif M <= K:  # 逆に最大積載量が大きすぎて，トラックが余る場合
        P_MAX = P
print(P_MIN)


Measured memory_bytes: 9564
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n, l;
    cin >> n >> l;
    string s[n];
    rep(i, n) { cin >> s[i]; }

    sort(s, s + n);

    rep(i, n) { cout << s[i]; }
    cout << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
n,w = map(int, input().split())
a = [[int(x) for x in input().split()] for i in range(n)]
dp = [10**100 for i in range(10**5 + 1)]
dp[0] = 0
for i in range(n):
    for j in range(10**5, -1, -1):
        if dp[j] != 10**100:
            dp[j + a[i][1]] = min(dp[j + a[i][1]], dp[j] + a[i][0])
for i in range(10**5, -1, -1):
    if dp[i] <= w:
        print(i)
        exit(0)

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

int main(void)
{
    string sa, sb, sc;

    cin >> sa >> sb >> sc;

    int ia=0, ib=0, ic=0;

    char nn = 'a';

    while(1)
    {
        if(nn == 'a')
        {
            if(ia == sa.size())
            {
                cout << "A" << endl;
                break;
            }
            nn = sa[ia];
            ++ia;
        }
        else if(nn == 'b')
        {
            if(ib == sb.size())
            {
                cout << "B" << endl;
                break;
            }
            nn = sb[ib];
            ++ib;
        }
        else if(nn == 'c')
        {
            if(ic == sc.size())
            {
                cout << "C" << endl;
                break;
            }
            nn = sc[ic];
            ++ic;
        }


    }

    return 0;
}



Measured memory_bytes: 3588
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int W,a,b;
  cin>>W>>a>>b;
  cout<<max(0,max(b-a-W,a-b-W))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

map<char, int> m={{'s',0}, {'p',1}, {'r',2}};

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> point(3,0);
    cin >> point[0] >> point[1] >> point[2];

    string T;
    cin >> T;

    int ans=0;
    for(int i=0; i<N; i++){
        if(i-K<0){
            ans+=point[m[T[i]]];
            //cout << point[m[T[i]]] << endl;
            continue;
        }

        if(T[i]==T[i-K]){
            T[i]='.';
            continue;
        }
        //cout << point[m[T[i]]] << endl;
        ans+=point[m[T[i]]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import sys
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e, operator_func):
        self.e = e # 単位元
        self.size = N
        self.node = [self.e] * (2*N)
        self.operator_func = operator_func # 処理(add or xor max minなど)

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size-1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        # [l, r) についてqueryを求める
        x = self.e
        l += self.size
        r += self.size

        while l<r:
            if l&1:
                x = self.operator_func(x, self.node[l-1])
                l += 1
            if r&1:
                r -= 1
                x = self.operator_func(x, self.node[r-1])
            l >>= 1
            r >>= 1
        return x


def solve():
    N = int(input())
    l = [tuple(map(int, input().split())) for i in range(N)]
    l.sort(key=lambda x:(x[0], -x[1]))

    #1 [lmax, rmin] [*, *]
    #2 [lmax, *] [*, rmin]

    lmax = 0
    rmin = 10**12
    a, b = 0, 0

    for i in range(N):
        if lmax < l[i][0]:
            lmax = l[i][0]
            a = i
        if rmin > l[i][1]:
            rmin = l[i][1]
            b = i

    #1
    ans1 = 0
    for i in range(N):
        if i==a or i==b:
            continue
        ans1 = max(ans1, max(l[b][1]-l[a][0]+1, 0)+max(l[i][1]-l[i][0]+1, 0))

    #2
    ans2 = 0
    tree = SegTree(N, 10**12, min)
    tree.set_list([i[1] for i in l])
    for i in range(N-1):
        ans2 = max(ans2, max(l[b][1]-l[i][0]+1, 0)+max(tree.get(i+1, N)-l[a][0]+1, 0))

    ans = max(ans1, ans2)
    print(ans)


if __name__ == "__main__":
    solve()


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

typedef long long ll;

ll world(ll A){
    ll hoge = 2;
    ll res = 0;
    if (A%4==1||A%4==2) res++;
    while(hoge < 1e12){
      if (A%(2*hoge)>=hoge){
        if (A%2==0) res += hoge;
      }
      hoge *= 2;
    }
    return res;
}

int main(){
  ll A, B;
  cin >> A >> B;
  ll a = world(A-1);
  ll b = world(B);
  ll ans = b^a;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio> 
using namespace std;
int n,ans;
int fl[1000005];
int main(){
	scanf("%d",&n);
	for(int i=2;i<=1000000;i++)
		if(!fl[i]){
			if(i%5==1){
				ans++;
				printf("%d ",i);
				if(ans==n)return 0;
			}
			for(int j=2;i*j<=1000000;j++)
				fl[i*j]=1;
		}
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define nn 10000008
#define int long long 
#define mod 998244353
int f[nn],rf[nn];
int qpow(int x,int y=mod-2){
	int res=1;
	while(y){
		if(y&1) res=res*x%mod;
		x=x*x%mod;y=y/2;
	}
	return res;
}
int n;int p2[nn];
int C(int x,int y){
	return f[x]*rf[y]%mod*rf[x-y]%mod;
}
signed main(){
	f[0]=1;for(int i=1;i<nn;i++) f[i]=f[i-1]*i%mod;
	rf[nn-1]=qpow(f[nn-1]);
	for(int i=nn-2;i>=0;i--) rf[i]=rf[i+1]*(i+1)%mod;
	
	p2[0]=1;for(int i=1;i<nn;i++) p2[i]=p2[i-1]*2%mod;
	
	cin>>n;
	
	int ans=qpow(3,n);
	for(int i=n/2+1;i<=n;i++){
		ans-=C(n,i)*p2[n-i+1];
		ans%=mod;
	}
	ans+=mod;ans%=mod;cout<<ans%mod;
	
	
	return 0;
} 

Measured memory_bytes: 234624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
int t;
string a;
bool check(int x){
	map<string ,int> v;
	for(int i=1;i<=t+1-x;i++){
		string s=a.substr(i-1,x);
		if(v[s]){
			if(i-v[s]>=x){
				return true;
			}
		}else{
			v[s]=i;
		}
	}
	return false;
} 
int main(){
	cin>>t>>a;	
	int l=0,r=t/2;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 6668
def main():
    MOD = 10 ** 9 + 7
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    A.sort()
    if K == 1:
        print(A[N - 1])
        return
    # マイナスが0 or 1個の時はtop Kの積
    if A[1] >= 0:
        ans = 1
        for k in range(1, K + 1):
            ans *= A[-k]
            ans %= MOD
        print(ans)
        return
    # 非負が0個の場合
    # K:even -> tail Kの積
    # K:odd -> top Kの積
    if A[N - 1] < 0:
        ans = 1
        if K % 2 == 0:
            for k in range(K):
                ans *= A[k]
                ans %= MOD
        else:
            for k in range(1, K + 1):
                ans *= A[-k]
                ans %= MOD
        print(ans)
        return
    # 非負が1個の場合
    # K:even -> tail Kの積
    # K:odd -> tail (K - 1), top 1の積
    if A[N - 2] < 0 and A[N - 1] >= 0:
        ans = 1
        if K % 2 == 0:
            for k in range(K):
                ans *= A[k]
                ans %= MOD
        else:
            for k in range(1, K):
                ans *= A[-k]
                ans %= MOD
            ans *= A[N - 1]
            ans %= MOD
        print(ans)
        return
    # マイナスも非負も2つ以上ある場合
    # 両端から2要素ずつ走査していく
    left, right = 0, N - 1
    ans = 1
    while K >= 2:
        left_prod = A[left] * A[left + 1]
        right_prod = A[right - 1] * A[right]
        if left_prod < right_prod:
            ans *= right_prod
            right -= 2
        else:
            ans *= left_prod
            left += 2
        ans %= MOD
        K -= 2
    if K == 1:
        ans *= A[right]
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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

int main()
{
  int N;
  cin >> N;
  map<string, bool> t;

  for (int i = 0; i < N; ++i)
  {
    string Si;
    cin >> Si;
    t[Si] = true;
  }

  cout << t.size() << endl;;
}


Measured memory_bytes: 19228
S = gets.chomp

s = S.chars

i = S.size- 1
satisfied = true

loop do
  case s[i]
  when 'm' then
    if i >= 4 && s[i - 1] == 'a' && s[i - 2] == 'e' && s[i - 3] == 'r' && s[i - 4] == 'd'
      i -= 5
    else
      satisfied = false
      break
    end
  when 'r' then
    if i >= 6 && s[i - 1] == 'e' && s[i - 2] == 'm' && s[i - 3] == 'a' && s[i - 4] == 'e' && s[i - 5] == 'r' && s[i - 6] == 'd'
      i -= 7
    elsif i >= 5 && s[i - 1] == 'e' && s[i - 2] == 's' && s[i - 3] == 'a' && s[i - 4] == 'r' && s[i - 5] == 'e'
      i -= 6
    else
      satisfied = false
      break
    end
  when 'e' then
    if i >= 4 && s[i - 1] == 's' && s[i - 2] == 'a' && s[i - 3] == 'r' && s[i - 4] == 'e'
      i -= 5
    else
      satisfied = false
      break
    end
  else
    satisfied = false
    break
  end

  if i < 0
    break
  end
end

if satisfied
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 9468