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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  int n; cin >> n;
  vi left(n+1, 0), right(n+1, 0), a(n);

  rep(i, n) cin >> a[i];
  rep(i, n) left[i+1] = __gcd(left[i], a[i]);

  reverse(all(a));

  rep(i, n) right[i+1] = __gcd(right[i], a[i]);

  int ans = 1;
  rep(i, n+1) chmax(ans, __gcd(left[i], right[n-i-1]));

  cout << ans << endl;
}

Measured memory_bytes: 4460
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    lli N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<lli> x(N);
    for (int i = 0; i < N; ++i) {
        cin >> x[i];
    }


    vector<lli> y(M);
    for (int i = 0; i < M; ++i) {
        cin >> y[i];
    }

    lli xMax = *max_element(x.begin(), x.end());
    lli yMin = *min_element(y.begin(), y.end());


    if (X < Y && xMax < yMin && xMax < Y && yMin > X+1) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
}

Measured memory_bytes: 256
def main():
    S = input()
    Q = int(input())
    order = [list(input().split()) for _ in range(Q)]
    left_flag = 0
    right_flag = 0
    cnt = 0
    for i in range(Q):
        if order[i][0] == '1':
            cnt += 1
        else:
            if cnt%2 == 0:
                if order[i][1] == '1':
                    if left_flag == 1:
                        left = order[i][2] + left
                    else:
                        left = order[i][2]
                        left_flag = 1
                else:
                    if right_flag == 1:
                        right = right + order[i][2]
                    else:
                        right = order[i][2]
                        right_flag = 1
            else:
                if order[i][1] == '2':
                    if left_flag == 1:
                        left = order[i][2] + left
                    else:
                        left = order[i][2]
                        left_flag = 1
                else:
                    if right_flag == 1:
                        right = right + order[i][2]
                    else:
                        right = order[i][2]
                        right_flag = 1
    if left_flag == 1 and right_flag == 1:
        S = left + S + right
    elif left_flag == 1 and right_flag == 0:
        S = left + S
    elif left_flag == 0 and right_flag == 1:
        S = S + right
    else:
        S = S

    if cnt%2 == 0:
        return(S)
    else:
        S2 = S[-1]
        for i in range(len(S)-2,-1,-1):
            S2 = S2 + S[i]
        return S2

print(main())


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

int main()
{
  int N ;
  cin>>N ;
  vector<int>d(N) ;
  for(int i=0;i<N;i++) cin>>d.at(i) ;
  
  /*大きい順にソート*/
  sort(d.begin(),d.end()) ;  
  reverse(d.begin(),d.end()) ;

  int max=1 ;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(d.at(i)>d.at(j)){
        i=j ;
        max++ ;
      }
    }
  }
  cout<<max<<endl ;
  
  return 0 ;
}


Measured memory_bytes: 256
#include<stdio.h>
void encode(char *,int);
int main(){
	int N;
	char S[10000];
	scanf("%d %s",&N,&S);
	encode(S,N);
	printf("%s",S);
	return 0;
}
void encode(char *str,int n){
	while(*str!='\0'){
		if(*str>'Z'-n)*str = *str+n-26;
		else *str = *str+n;
		*str++;
	}
}

Measured memory_bytes: 128
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = a.count(b[0])

if len(b) == 1 or c > 1: #bの長さが1または、最大値が2回以上存在するなら
    for i in range(n):
        print(b[0]) #最大値のみを表示

else: #bの長さが2以上なら
    for i in range(n):
        if a[i] == b[0]: #i番目が最大値だったら
            print(b[1]) #2番目に大きい値を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力

Measured memory_bytes: 17208
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include <numeric>
#include <stdio.h>
#include<cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;



int main() {
  int a, b;
  cin >> a >> b;
  double c = double(10 * b);
  int ans = -1;
  for (int i=0; i<10;i++) {
    double d = (c + i) * 0.08;
    if((int)d == a) {
      ans = int (c + i);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s_a = list(input())[::-1]
s_b = list(input())[::-1]
s_c = list(input())[::-1]

person = "a"

try:
  while True:
    if person == "a":
      person = s_a.pop()
    elif person == "b":
      person = s_b.pop()
    else:
      person = s_c.pop()
except IndexError:
  print(person.upper())

Measured memory_bytes: 3060
/** Author: Nicklaus **/
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
#define PI 3.14159265358979324

int main(){
	int a, b, k;
	cin>>a>>b>>k;
	/*
	for(int i=1; i<=min(a,b); i++){
		if(a%i==0 && b%i==0){
			k--;
			//cout<<i<<"x"<<endl;
			if(!k) {cout<<i<<endl; return 0;}
		}
	}**/
	
	for(int i=min(a,b); i>=1; i--){
		if(a%i==0 && b%i==0){
			k--;
			if(!k){cout<<i<<"\n"; return 0;}
		}
	}
	cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#ifdef loc
    #include "loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 3005, mod = 1e9 + 7;
char s[N];
int f[N][N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    cin >> s;
    f[0][0] = f[0][1] = 1;
    rep(i, 1, n) {
        rep(j, 0, i + 1) {
            if(s[i - 1] == '>') {
                f[i][j] += f[i - 1][i];
                if(f[i][j] >= mod) {
                    f[i][j] -= mod;
                }
                if(j > 0) {
                    f[i][j] -= f[i - 1][j - 1];
                }
                if(f[i][j] < 0) {
                    f[i][j] += mod;
                }
            } else {
                if(j > 0) {
                    f[i][j] += f[i - 1][j - 1];
                }
                if(f[i][j] >= mod) {
                    f[i][j] -= mod;
                }
            }
            f[i][j + 1] = f[i][j];
        }
    }
    cout << f[n - 1][n - 1] << endl;
}

Measured memory_bytes: 34176
#ABC070 C - Multiple Clocks
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

N = int(input())
T = []
ans = 0

for i in range(N):
    T.append(int(input()))

for i in range(N-1):
    if i == 0:
        ans = lcm(T[0],T[1])    
    t = lcm(ans,T[i+1])
    ans = max(ans,t)

if len(T) == 1:
    print(T[0])
else:
    print(ans)

Measured memory_bytes: 5044
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
int main()
{
    string s;
    while(cin>>s)
    {
        long l,p,i;
        l=s.size();
        fr(i,l)
        {
            if(s[i]=='A')
            {
                p=i;
                break;
            }
        }
        for(i=l-1;i>=0;i--)
        {
            if(s[i]=='Z')
            {
                cout<<i-p+1<<"\n";
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 640
import java.util.*;


public class Main {
	public static void  main(String[]  args) {
		Scanner sc = new Scanner(System.in);
		//总数
		int n = sc.nextInt();
		//数组长度
		int m = sc.nextInt();
		//初始位置
		int x = sc.nextInt();
		int arr[] = new int[m];
		for(int i = 0;i<arr.length;i++){
			arr[i] = sc.nextInt();
		}

		int flag[] = new int[n];
		for(int i= 0;i<flag.length;i++){
			flag[i] = 0;
		}
		
		for(int i= 0;i<flag.length;i++){
			for(int j= 0;j<arr.length;j++){
				if(arr[j] == i){
					flag[i] = 1;
				}
			}
		}
		int leftResult =0;
		int rightResult =0;
		for(int i=x;i>=0;i--){
			leftResult = leftResult + flag[i];
		}
		for(int i=x+1;i<n;i++){
			rightResult = rightResult + flag[i];
		}
		if(leftResult < rightResult){
			System.out.println(leftResult);
		} else{
			System.out.println(rightResult);
		}
		
	}
}


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

int main(){
    int tc, n, a,b, res =0;
    cin >> tc >> n;
    while(tc--){
        cin >> a >> b;
        int64_t ans = (int64_t)a*a + (int64_t)b*b;
        if(ans <= (int64_t)(n)*(n) ){
            res++;
        }
    }
    cout << res;
    return 0;
}

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

using namespace std;

int main() {
    bool acd[100001];
    int wa_cnt[100001];
    for(int i = 0;i < 100001;i++) acd[i] = false;
    for(int i = 0;i < 100001;i++) wa_cnt[i] = 0;
    int n,m,p,accepted = 0;
    string s;
    cin >> n >> m;
    for(int i = 0;i < m;i++) {
        cin >> p >> s;
        if(!acd[p]) if(s == "AC") {
            acd[p] = true;
            accepted++;
        } else {
            wa_cnt[p]++;
        }
    }
    int penalty = 0;
    for(int i = 0;i <= n;i++) {
        if(acd[i]) penalty += wa_cnt[i];
    }
    cout << accepted << " " << penalty << endl;
}


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

using namespace std;

const int maxn = 1e5 + 10;
int cnt, n;
char s[maxn];
vector<int>g[maxn];
bool check()
{
	//n = strlen(s + 1);
	//cout << "!" << endl;
	if(s[1] != '1' || s[n] != '0')
		return 0;
	//cout << "!" << endl;
	int st = 1, ed = n - 1;
	while(st < ed)
	{
		if(s[st] != s[ed])
			return 0;
		st ++; ed --;
	}
	return 1;
}
struct Edge
{
	int u, v;
}e[maxn * 2];
int edge_num;
void dfs(int x, int fa)
{
	for(int i = g[x].size() - 1; i >= 0; i --)
	{
		int to = g[x][i];
		if(to == fa)
			continue;
		e[++ edge_num].u = x;
		e[edge_num].v = to;
		dfs(to, x);
	}
}
int main()
{
	//int n;
	//scanf("%d", &n);
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if(!check())
	{
		cout << -1;
		return 0;
	}
	int op = ++ cnt;
	g[1].push_back(2); g[2].push_back(1);
	op = ++ cnt;
	for(int i = 2; i < n; i ++)
	{
		if(s[i] == '1')
		{
			if(s[i - 1] != '0')
			{
				++ cnt;
				g[cnt].push_back(op);
				g[op].push_back(cnt);
			}
			op = cnt;
		}
		else
		{
			if(s[i - 1] == '1')
			{
				++ cnt;
				g[cnt].push_back(op);
				g[op].push_back(cnt);
				++ cnt;
				g[cnt].push_back(op);
				g[op].push_back(cnt);
			}
			else
			{
				++ cnt;
				g[cnt].push_back(op);
				g[op].push_back(cnt);
			}
		}
	}
	dfs(1, 0);
	for(int i = 1; i < n; i ++)
		printf("%d %d\n", e[i].u, e[i].v);
	return 0;
}


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

int N, A, B;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 0, c; i < N; i++) {
		cin >> c;
		((c&1) ? B : A)++;
	}
	A += B >> 1; B &= 1;
	puts(A && B ? "NO" : "YES");
	return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = 0

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

num = lcm(*a) - 1

for i in range(n):
    ans += num % a[i]

print(ans)

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


typedef long long ll;
int main() {
  int n, m; cin >> n >> m;
  priority_queue<double> pq;
  for (int i = 0; i < n; ++i) { 
    int a; cin >> a;
    pq.push(a);
  }
  for (int i = 0; i < m; ++i) {
    double a = pq.top(); pq.pop();
    a /= 2;
    pq.push(a);
  }
  ll ans = 0;
  while (!pq.empty()) {
    int a = pq.top(); pq.pop();
    ans += a;
  }
  cout << ans << endl;
}


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

static const int N= 100;
int p[N+1], m[N+1][N+1];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
      cin >> p[i-1] >> p[i];
    }
    for(int i=1; i<=n; i++) m[i][i] = 0;

    for(int l=2; l<=n; l++){ //l???????????????????¨????
      for(int i=1; i<=n-l+1; i++){
        int j = i + l -1;
        m[i][j] = ( 1 << 21); //???????????????????????§???
        for(int k=i; k<=j-1; k++){
          m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
        }
      }
    }
    cout << m[1][n] << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll a, b, c; cin >> a >> b >> c;
    if (a + b + c == 2 * max(a, max(b, c))) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
h,w=map(int,input().split())
a=['*'*(w+2)]+['*'+input()+'*' for _ in range(h)]+['*'*(w+2)]
from collections import deque
ans=0
for p in range(h):
  for q in range(w):
    d=deque()
    m=0
    if a[p+1][q+1]=='.':
      d.append([p+1,q+1])
      c=[[10000]*w for _ in range(h)]
      c[p][q]=1
      di=[[0,1],[1,0],[-1,0],[0,-1]]
      while d:
        g=d.popleft()
        for i in di:
          x=g[0]+i[0]
          y=g[1]+i[1]
          if a[x][y]=='.':
            if c[x-1][y-1]==10000:
              d.append([x,y])
              c[x-1][y-1]=c[g[0]-1][g[1]-1]+1
      for i in range(h):
        for j in range(w):
          if c[i][j]!=10000:
            m=max(m,c[i][j])
    ans=max(ans,m)
print(ans-1)

Measured memory_bytes: 46172
n,m=map(int,input().split())
a=list(map(int,input().split()))
count=0
for i in range(int(n)):
    if a[i]<sum(a)/(4*int(m)):
        count=count
    else:
        count=count+1
if count>=int(m):
    print("Yes")
else:
    print("No")
        

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

using namespace std;

void hawawa()
{
	int h, r;
	cin >> h >> r;
	if (-r < h) {
		cout << "1\n";
	}
	else if (-r == h) {
		cout << "0\n";
	}
	else {
		cout << "-1\n";
	}
}

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



Measured memory_bytes: 3216
def dice_rotation(dice, command):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	#S:1->2,2->6,6->5,5->1
	if command == 'S':
		dice[0] = tmp_dice[4]
		dice[4] = tmp_dice[5]
		dice[5] = tmp_dice[1]
		dice[1] = tmp_dice[0]
	#N:1->5,5->6,6->2,2->1
	elif command == 'N':
		dice[0] = tmp_dice[1]
		dice[1] = tmp_dice[5]
		dice[5] = tmp_dice[4]
		dice[4] = tmp_dice[0]
	#W:1->4,4->6,6->3,3->1
	elif command == 'W':
		dice[0] = tmp_dice[2]
		dice[2] = tmp_dice[5]
		dice[5] = tmp_dice[3]
		dice[3] = tmp_dice[0]
	#E:1->3,3->6,6->4,4->1
	elif command == 'E':
		dice[0] = tmp_dice[3]
		dice[3] = tmp_dice[5]
		dice[5] = tmp_dice[2]
		dice[2] = tmp_dice[0]

def dice_spinning(dice):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	dice[1] = tmp_dice[2]
	dice[2] = tmp_dice[4]
	dice[4] = tmp_dice[3]
	dice[3] = tmp_dice[1]

def comparison_dices(Dice1,Dice2):

	yes_counter = 0
	for j in range(6):
		if Dice1[j] == Dice2[j]:
			yes_counter += 1
	if yes_counter == 6:
		return True

	return False

def test():

	Dice1 = list(map(int,input().split()))
	Dice2 = list(map(int,input().split()))

	judgement_result = False

	#1st direction
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'S')

	#2nd direction
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'W')

	if judgement_result == True:
		print("Yes")
	else:
		print("No")

if __name__ == "__main__":
	test()



Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {
  static int n, k;

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

    n = sc.nextInt(); k = sc.nextInt();

    int count = 0;
    for(int i = 0; i < k; i++){
      int d = 1;
      for(int j = 1; j < n; j++){
        d *= k - 1;
      }
      count += d;
    }

    System.out.println(count);
  }
}


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

#define all(v) (v).begin(), (v).end()
using namespace std;

typedef long long LL;
const int MAX_N = 1005, TYPES = 3;
LL A[MAX_N][3];

int is_bit_set(LL n, int position)
{
    return ( (n&(1LL << position) ) != 0);
}

int main()
{
    int no_of_elements, target;
    cin >> no_of_elements >> target;

    for(int i = 0; i < no_of_elements; i++)
    {
        for(int t = 0; t < TYPES; t++)
        {
            cin >> A[i][t];
        }
    }

    const int MAX_MASK = (1LL << TYPES);
    LL best_sum = 0;

    for(int mask = 0; mask < MAX_MASK; mask++)
    {
        vector <LL> current_sum(no_of_elements, 0);

        for(int i = 0; i < no_of_elements; i++)
        {
            for(int t = 0; t < TYPES; t++)
            {
                current_sum[i] += (is_bit_set(mask, t) ? A[i][t] : -A[i][t]);
            }
        }

        sort(all(current_sum));
        reverse(all(current_sum));

        LL sum_here = 0;
        for(int i = 0; i < target;i++)
        {
            sum_here += current_sum[i];
        }

        best_sum = max(best_sum, sum_here);
    }

    cout << best_sum;
    return 0;
}


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

int main() {
    int a,b; cin>>a>>b;
    if(a>=10 || b>=10) 
    cout<<"-1"<<endl;
    else  cout<<a*b<<endl;
    return 0;
}

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

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

using namespace std;

int main(){
  int h,w;cin>>h>>w;

  vector<string> s;
  rep(i,h){
    string t;
    cin>>t;
    if(count(t.begin(), t.end(), '.')==w)continue;
    s.push_back(t);
  }

  bool enable_columns[w];
  rep(i,w){
    enable_columns[i]=false;
    rep(j,s.size()){
      if(s[j][i]=='#'){
        enable_columns[i]=true;
        break;
      }
    }
  }

  rep(i,s.size()){
    rep(j,w){
      if(enable_columns[j])cout<<s[i][j];
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>d;
    int y[100]={0};
    c=a%b;
    while(c!=0){
    	int t=b;
		b=a%b;
    	a=t;
    	c=a%b;
	}
	int j=0;
	for(int i=b;i>=1;i--){
		if(b%i==0){
			y[j]=i;
			j++;
		}
	}
	cout<<y[d-1]<<endl;
    return 0;
}



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

const int MN = 3005;

int N, pa[MN], pb[MN], id[MN * 2], nx[MN * 2];
std::string str, f[MN];

int main() {
	std::cin >> N >> str;
	str = " " + str;
	for (int i = 1, a = 0, b = 0; i <= N * 2; ++i)
		if (str[i] == 'a') pa[id[i] = ++a] = i;
		else pb[id[i] = ++b] = i;
	pa[N + 1] = pb[N + 1] = N * 2 + 1, id[N * 2 + 1] = N + 1;
	for (int i = 1, j = 0; i <= N + 1; ++i)
		while (j < std::min(pa[i], pb[i]))
			nx[++j] = i;
	for (int i = N; i >= 1; --i) {
		if (pa[i] > pb[i]) {
			int j = pb[i];
			for (; pb[id[j]] < pa[id[j]] && (id[j] <= i || pb[id[j]] < pa[id[j] - 1]); ++j)
				if (id[j] >= i) f[i] += str[j];
			f[i] += f[id[j]];
		} else f[i] = "ab" + f[nx[pb[i] + 1]];
		f[i] = std::max(f[i], f[i + 1]);
	}
	std::cout << f[1];
	return 0;
}

// Luogu : PinkRabbit

Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define N 5004
#define INF 1000000007
typedef long long int ll;
typedef long int li;

int temp1,temp2,mini = INF,num,n,maxi = -1;
vector<int> v;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int a,b;
    cin>>a>>b;
    cout<<max({a*b,a+b,a-b});
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """ 根を見つける関数を定義（同時にxを直接根にくっつける操作も行う）"""
        tmp = []
        parents = self.parents
        while parents[x] >= 0:
            tmp.append(x)
            x = parents[x]
        for y in tmp:
            parents[y] = x
        return x

    def union(self, x, y):
        """ 二つの木をくっつける（子を多く持つ方を根とした親子関係）。これは破壊的操作を行う。"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """ xとyが同じ根の子かを判定 """
        return self.find(x) == self.find(y)

    def size(self, x):
        """ xの根のparent（= 要素数）を返す """
        return -self.parents[self.find(x)]

    def members(self, x):
        """ xが属するグループの要素をリストとして返す """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """ 全ての根の要素をリストとして返す """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """ グループの数を返す """
        return len(self.roots())

    def size_list(self):
        """ 各グループの要素数のリストを返す(根の番号は返さない) """
        return [-x for x in self.parents if x < 0]

    def all_group_members(self):
        """ {根:[根の子のリスト],...}を辞書で返す """
        return {r: self.members(r) for r in self.roots()}

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


##############################################################################################################
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
P = list(map(int, input().split()))
U = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    U.union(a, b)
res = 0
for i, p in enumerate(P):
    if U.same(p-1,i):
        res += 1
print(res)


Measured memory_bytes: 83232
/*
Sharif Hasan - CSE, PUST
Apr 04, 2020 02: 47 PM 
*/
#include<bits/stdc++.h>
#define br cout<<"\n"

/*STL definations*/
#define pb push_back

#define FOR(i,n) for(i=0;i<n;i++)
#define FROM(a,i,n) for(i=a;i<n;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

class Solution {
public:
void solution() {
int a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b << endl;
}
public:
Solution() {
solution();
}
};

int main() {
Solution obj;
return 0;
}

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

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> a(N);
    REP(i,N)cin >> a[i];
    sort(a.begin(),a.end());
    bool ok = 1;
    if(N%3!=0)ok = 0;
    if(N/3 != count(a.begin(),a.end(),a[0]))ok = 0;
    bool ook = 0;
    if(a[0]==0 && N == count(a.begin(),a.end(),a[N/3]))ook = 1;
    if(ok && a[0]==0 && (N/3)*2 == count(a.begin(),a.end(),a[N/3]))ook = 1;
    if(N/3 != count(a.begin(),a.end(),a[N/3]))ok = 0;
    if(N/3 != count(a.begin(),a.end(),a[N-1]))ok = 0;
    if((a[0] ^ a[N/3] )!= a[N-1])ok = 0;
    ok = ok || ook;
    if(ok){
        cout <<"Yes"<< "\n";
    }
    else{
        cout <<"No"<< "\n";
    }
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());

        int res = 0;
        for (int a = 0; a <= A; a++) {
            for (int b = 0; b <= B; b++) {
                int c = (X - a * 500 - b * 100) / 50;
                if (c >= 0 && c <= C)
                    res++;
            }
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 35576
#include <stdio.h>
 
int main()
{
    int r,c;
    int i,j;
    int x[100][100];
    int r_sum = 0;
    int c_sum = 0;
    int n_sum = 0;
     
    scanf("%d %d",&r,&c);
     
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&x[i][j]);
            n_sum += x[i][j];
        }
    }
     
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            r_sum += x[i][j];
            printf("%d ",x[i][j]);
        }
        printf("%d\n",r_sum);
        r_sum = 0;
    }
     
    for(i=0;i<c;i++){
        for(j=0;j<r;j++){
            c_sum += x[j][i];
        }
        printf("%d ",c_sum);
        c_sum = 0;
    }
    printf("%d\n",n_sum);
    return 0;
}

Measured memory_bytes: 636
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  string s;
  cin >> s;
  int ans1 = 0;
  for (int i = 0; i < sz(s); i++) {
    ans1 += (s[i] - '0');
  }
  cout << max(ans1, (s[0] - '1') + 9 * (sz(s) - 1)) << "\n";
}



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

using namespace std;
typedef long long ll;

#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
const int maxn=1e5+5;
int a[maxn],b[maxn];
ll gcd(ll a, ll b)
{
    if(b)
        return gcd(b,a%b);
    return a;
}
int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b/gcd(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    /*
    int a, b, c;
    cin >> a >> b >> c;
    */
    
    /*
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    */
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (sz(s) % 2) { cout << "No" << endl; return 0; }
    rep(i, n / 2) if (s[i] != s[n / 2 + i]) { cout << "No" << endl; return 0; }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S;
int W;

signed main(){
    cin >> S >> W;
    rep(i, S.size()){
        if(i%W == 0) cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
long long n, m, x;
vector<pair<long long, vector<long long> > >v;

bool Is(long long a, long long b) {
    for(long long i = 13; i >= 0; i--) {
        if(a >= (1 << i)) {
            a -= (1 << i);
            if(i == b)
                return true;
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> x;
    long long y;
    for(long long i = 1; i <= n; i++) {
        cin >> y;
        vector<long long> temp;
        for(long long j = 1; j <= m; j++) {
            long long lol;
            cin >> lol;
            temp.push_back(lol);
        }
        v.push_back(make_pair(y, temp));
    }
    sort(v.begin(), v.end());
    long long dp[1 << n], ans = INT_MAX;
    for(long long i = 1; i < (1 << n); i++) {
        long long temp[13] = {0}, cost = 0;
        for(long long j = 0; j < n; j++) {
            if(Is(i, j)) {
                for(long long k = 0; k < v[j].second.size(); k++) {
                    temp[k] += v[j].second[k];
                }
                cost += v[j].first;
            }
        }
        long long f = 0;
        for(long long j = 0; j < m; j++) {
            if(temp[j] < x)
                f = 1;
        }
        if(f == 0)
            dp[i] = cost;
        if(f == 0) {
            ans = min(ans, dp[i]);
        }
    }
    if(ans == INT_MAX) {
        cout << "-1\n";
    }
    else {
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>
#include<stdlib.h>
#define ll long long

int main(){
  ll a,b;
  scanf("%lld %lld",&a,&b);
  if( b%a == 0 ){
    printf("%lld\n",a+b);
  }else{
    printf("%lld\n",b-a);
  }
  return 0;
}



Measured memory_bytes: 1736
#include <fstream>
#include <iostream>
#include <string>
#include <iterator>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
   long long a;
   cin>>a;
   long long sum=0;
   rep(i,a){
       if((i+1)%3==0||(i+1)%5==0){

       }
       else{
           sum+=(i+1);
       }
   }
   cout<<sum<<endl;
}


Measured memory_bytes: 3636
package main
 
import (
	"fmt"
)
 
func main() {
	var n int
	fmt.Scanln(&n)
 
	if n == 0 {
		fmt.Println(0)
		return
	}
 
	ds := []int{0, 0} // padding
	mbs := 0
 
	var v int
	for i := uint(0); ; i++ {
		if i%2 == 0 {
			v = 1 << i
		} else {
			v = -1 << i
		}
		ds = append(ds, ds[i]+v)
 
		if n < 0 && n >= ds[i+2] || n > 0 && n <= ds[i+2] {
			mbs = int(i + 2)
			break
		}
	}
 
	m := ds[mbs] - ds[mbs-2]
	bits := make([]rune, mbs-1)
	bits[0] = '1'
 
	for i := mbs - 1; i >= 2; i-- {
		bi := mbs - i
		diff := n - m
		if (diff < 0) == (ds[i] < 0) && abs(diff) > abs(ds[i-2]) {
			bits[bi] = '1'
			m += ds[i] - ds[i-2]
		} else {
			bits[bi] = '0'
		}
	}
 
	fmt.Println(string(bits))
}
 
func abs(a int) int {
	if a < 0 {
		return -1 * a
	}
	return a
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 1e12
const int MOD = 1000000007;
typedef pair<ll,ll> P;

int main(void){
    ll K,N,mP=-INF,ans=0;
    cin >> K >> N;
    vector<ll> A(N+10,0);
    vector<ll> Pass(N+10);
    REP(i,N){
        cin >> A[i];        
    }
    REP(i,N-1){
        Pass[i] = abs(A[i+1] - A[i]);
        ans += Pass[i];
        mP = max(mP,Pass[i]);
    }
    Pass[N-1] = abs(A[0]+(K-A[N-1]));
    ans += Pass[N-1];
    mP = max(mP,Pass[N-1]);

    cout << ans - mP << endl;
    return 0;
}

Measured memory_bytes: 6400
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<long long> dp(N+1);
    long long sum3 = 0;
    for (int i = 2; i <= N; i++) {
        if (i&1) {
            long long sum1 = dp[i-2] + A[i-1];
            long long sum2 = dp[i-3] + A[i-2];
            sum3 += A[i-3];
            dp[i] = max(sum1, max(sum2, sum3));
        }
        else {
            long long sum1 = dp[i-2] + A[i-1];
            long long sum2 = sum3 + A[i-2];
            dp[i] = max(sum1, sum2);
        }
        
    }

    cout << dp[N] << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 6372
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from operator import itemgetter

n = ni()
lefts = []
rights = []
intervals = []
for _ in range(n):
    l, r = li()
    r += 1
    lefts.append(l)
    rights.append(r)
    intervals.append((l, r))

maxleft = max(lefts)
minright = min(rights)
ans = 0

## (1)最高の左端と最低の右端が同じ集合にあるとき
# 1区間のみを選択
longest = 0
for l, r in intervals:
    if l == maxleft or r == minright:
        continue
    else:
        longest = max(longest, r - l)
ans = longest + max(0, minright - maxleft)

## (2)最高の左端と最低の右端が別の集合にあるとき
intervals = sorted(sorted(intervals, key=itemgetter(1), reverse=True), key=itemgetter(0))

s_maxleft = [intervals[0][0]]
s_minright = [intervals[0][1]]
t_maxleft = [intervals[-1][0]]
t_minright = [intervals[-1][1]]

for idx, (l, r) in enumerate(intervals):
    if idx == 0:
        continue
    s_maxleft.append(max(s_maxleft[-1], l))
    s_minright.append(min(s_minright[-1], r))

for idx, (l, r) in enumerate(intervals[::-1]):
    if idx == 0:
        continue
    t_maxleft.append(max(s_maxleft[-1], l))
    t_minright.append(min(t_minright[-1], r))

t_maxleft = t_maxleft[::-1]
t_minright = t_minright[::-1]

for i in range(n-1):
    ans = max(ans, max(0, s_minright[i] - s_maxleft[i]) + max(0, t_minright[i+1] - t_maxleft[i+1]))

print(ans)


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

class Node
{
public:
    int location;
    int p, l, r;
    Node() {}
};

class Point
{
public:
    int id, x, y;
    Point() {}
    Point(int id, int x, int y) : id(id), x(x), y(y) {}
    bool operator<(const Point &p) const
    {
        return id < p.id;
    }

    void print()
    {
        printf("%d\n", id);
    }
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth)
{
    if (!(l < r))
    {
        return NIL;
    }
    int mid = (l + r) / 2;
    int t = np++;
    if (depth % 2 == 0)
    {
        sort(P + l, P + r, lessX);
    }
    else
    {
        sort(P + l, P + r, lessY);
    }
    T[t].location = mid;
    T[t].l = makeKDTree(l, mid, depth + 1);
    T[t].r = makeKDTree(mid + 1, r, depth + 1);

    return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans)
{
    int x = P[T[v].location].x;
    int y = P[T[v].location].y;

    if (sx <= x && x <= tx && sy <= y && y <= ty)
    {
        ans.push_back(P[T[v].location]);
    }

    if (depth % 2 == 0)
    {
        if (T[v].l != NIL)
        {
            if (sx <= x)
            {
                find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
            }
        }
        if (T[v].r != NIL)
        {
            if (x <= tx)
            {
                find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
            }
        }
    }
    else
    {
        if (T[v].l != NIL)
        {
            if (sy <= y)
            {
                find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
            }
        }
        if (T[v].r != NIL)
        {
            if (y <= ty)
            {
                find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
            }
        }
    }
}

int main()
{
    int x, y;
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d %d", &x, &y);
        P[i] = Point(i, x, y);
        T[i].l = T[i].r = T[i].p = NIL;
    }

    np = 0;
    int root = makeKDTree(0, N, 0);

    int q;
    scanf("%d", &q);
    int sx, tx, sy, ty;
    vector<Point> ans;
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        ans.clear();
        find(root, sx, tx, sy, ty, 0, ans);
        sort(ans.begin(), ans.end());
        for (int j = 0; j < ans.size(); j++)
        {
            ans[j].print();
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 15888
#include<stdio.h>
int bubbleSort(int A[],int);
int main()
{
  int N,i,j,cn=0;
  int A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);

  cn = bubbleSort(A,N);
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cn);
  return 0;
}

int bubbleSort(int A[],int N){
    int j,i,r;
    int cnt=0;
    for(j=0;j < N+1;j++){
      for(i=N-1;i > 0;i--){
	if(A[i] < A[i-1]){
	r = A[i];
	A[i] = A[i-1];
	A[i-1] = r;
	cnt++;
      }
    }
  }
    return cnt;
  }
	 
	
      
  



Measured memory_bytes: 2052
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
last_index = -99
for i in range(n):
    food_index = a[i] - 1
    ans += b[food_index]
    if food_index - last_index == 1:
        ans += c[last_index]
    last_index = food_index

print(ans)


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

int main(){
	int monster, skill;
	int skills[100100];
	cin >> monster >> skill;
	for(int i = i; i < skill; ++i) cin >> skills[i];
	int sum = accumulate(skills, skills + skill, 0);
	if(sum >= monster) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var line = new List<List<int>>();
        for (int i = 0; i < 3; i++)
        {
            line.Add(Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList());
        }
        for (int i = 0; i < 3; i++)
        {
            var x = new List<int>();
            for (int j = 0; j < 3; j++)
            {
                x.Add(line[j][i]);
            }
            line.Add(x.ToList());
        }
        line.Add(new List<int> { line[0][0], line[1][1], line[2][2] });
        line.Add(new List<int> { line[0][2], line[1][1], line[2][0] });
        var b = new List<int>();
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            b.Add(int.Parse(Console.ReadLine()));
        }
        bool judge = false;
        for (int i = 0; i < line.Count(); i++)
        {
            int count = 0;
            for (int j = 0; j < b.Count(); j++)
            {
                if (line[i].Contains(b[j])) count++;
            }
            if (count >= 3) judge = true;
        }
        Console.WriteLine(judge ? "Yes" : "No");
    }
}


Measured memory_bytes: 13280
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL)

const ll modd=1e9+7;
const ll inff=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*-----------------------------------------------------------------------------------------------*/

int main(){
  fastt;
   
  ll l , r , d;
  cin >> l >> r >> d;

  ll right = r / d * d;
  ll left = l / d * d + (l%d == 0 ? 0 : d);

  if(left <= right) cout << (right-left)/d+1 << endl;
  else cout << 0 << endl;
 
  return 0;
}

Measured memory_bytes: 3616
N,X = map(int,input().split())
D = list(map(int,input().split()))

dist = [abs(X - D[i]) for i in range(N)]

def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a % b)
    
D = 0   
    
for i in range(N):
  D = gcd(D,dist[i])
  
print(D)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	int a[5],ge[5],sum=0;
	for (int i=0; i<5; i++)
	{
		cin>>a[i];

		ge[i]=a[i]%10;
		if (ge[i]!=0)
		{
			sum+=a[i]/10*10+10;
		}
		else
		{
			sum+=a[i];
			ge[i]+=9;
		}
	}
	sort (ge,ge+5);
	int minv=ge[0];
	if (a[0]%10==0&&a[1]%10==0&&a[2]%10==0&&a[3]%10==0&&a[4]%10==0)
	{
		cout<<sum;
		return 0;
	}
	cout<<sum-(10-minv);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

bool isOK(ll ans, ll K, const vector<ll> &A, const vector<ll> &F) {
	bool ret = true;
	ll cnt = 0; // how many times training done

	rep(i, A.size()) {
		ll x = dup(A[i]*F[i]-ans, F[i]); // (A*F - ans) / F
		x = max(x, 0LL);
		cnt += x;

		if(cnt>K) {
			ret = false;
			break;
		}
	}
	
	return ret;
}


int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	vector<ll> F(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> F[i];

	sort(A.begin(), A.end());
	sort(F.begin(), F.end());
	reverse(F.begin(), F.end());
	
	ll right = A[N-1]*F[0];
	ll left = -1;
	// 二分探索
	while(left+1<right) {
		ll mid = (right + left) /2;
		// cout << "mid: " << mid;
		if(isOK(mid, K, A, F)){
			right = mid;
			// cout << " is OK" << endl;
		} else {
			left= mid;
			// cout << " is NG" << endl;
		}
	}
	// right ぎりぎりOK
	// left ぎりぎりNG

	cout << right << endl;
	
	return 0;
}

Measured memory_bytes: 3328
import sys

DIRECTIONS = (
    (0, 0, 1),
    (0, -1, 0),
    (1, 0, 0),
    (-1, 0, 0),
    (0, 1, 0),
    (0, 0, -1)
)

DIRECTION_INDEX = {vec: i for i, vec in enumerate(DIRECTIONS)}


def cross(x, y):
    return (
        x[1] * y[2] - x[2] * y[1],
        x[2] * y[0] - x[0] * y[2],
        x[0] * y[1] - x[1] * y[0]
    )


values = [int(v) for v in sys.stdin.readline().strip().split()]
value_index = {value: i for i, value in enumerate(values)}

q = int(sys.stdin.readline())
for _ in range(q):
    top, front = (
        value_index[value]
        for value in map(int, sys.stdin.readline().strip().split())
    )
    index = DIRECTION_INDEX[cross(DIRECTIONS[top], DIRECTIONS[front])]
    print(values[index])



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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e6+5;
int dp[N];

void pre(){
  dp[0]=1;
  rep(i,1,N)
   dp[i]=dp[i-1]*i%mod;
}


int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}
int ncr(int x, int y){
  return divide(dp[x],dp[y]*dp[x-y]%mod);
}

void solve() {

  pre();
  int k;
  cin>>k;
  string s;
  cin>>s;
  int n = sz(s), ans = powm(26,n+k);
  rep(i,0,n)
    ans=(ans-ncr(n+k,i)*powm(25,n+k-i)%mod+mod)%mod;
  cout<<ans;
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}









int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


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


Measured memory_bytes: 19880