akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
use proconio::fastout;
use std::collections::BinaryHeap;
use std::cmp::Reverse;


#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut ans = 0;
    for j in 1 .. n + 1 {
        for i in (j .. n + 1).step_by(j) {
            if i % j == 0 { ans += i }
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 2152
n = int(input())
p = list(map(float, input().split()))

dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
    dp[i][0] = dp[i-1][0]*(1-p[i-1]) 
for i in range(1, n+1):
    for j in range(1, i+1):
        dp[i][j] += dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1-p[i-1])
        #print(dp, sep='\n')        
ans = 0
for j in range(n//2+1, n+1):
    ans += dp[n][j]

print(ans)
        

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	int mx = N + 1;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if(mx > A[i]){
			res++;
			mx = A[i];
		}
	}
	cout << res << endl;
}

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

#define ll long long
// #define endl '\n'

// void max_self(int &a, int b){a = max(a, b);}
// void min_self(int &a, int b){a = min(a, b);}

void solve(){
	ll d, t, s; cin>>d>>t>>s;
	if(d <= t * s){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int edges[512][512];

// 頂点[left, right)に辺を張る
void add_edge(int left, int right, int level) {
    if(right - left == 1) return;
    int mid = (left+right)/2;
    add_edge(left, mid, level+1);
    add_edge(mid, right, level+1);

    for(int i=left; i<mid; i++)
    for(int j=mid; j<right; j++) {
        edges[i][j] = level;
        edges[j][i] = level;
    }
}

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

    add_edge(0, n, 1);
    for(int i=0; i<n-1; i++) {
        for(int j=i+1; j<n; j++) {
            cout << edges[i][j] << " ";
        }
        cout << endl;
    }
}

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

int main(){
    int K,count;
    string str1,str3,str4;
    cin >> K >> str1;
    str3 ="...";
    count=str1.size();
    //cout << count << endl;
    if(count<=K){
        cout << str1;
    }else{
        string str2(str1,0,K);
        //cout << str2 << endl;
        str4=str2+str3;
        cout << str4 << endl;
    }
    return 0;
}

Measured memory_bytes: 3576
use io::*;
use proconio::{fastout, input};
use std::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        a: [i64; n],
    }
    for i in 0..n - k {
        if (a[i] < a[i + k]) {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

void pfact(ll n, map<ll,ll> &mp) {
  while(n%2==0) { mp[2]++; n /= 2;}
  for(ll i=3;i*i<=n;i+=2) {
    while(n%i==0) { mp[i]++; n/=i;}
  }
  if (n!=1) mp[n]+=1;
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,ans=0,ans_=0;cin>>N;
  map<ll,ll> mp;
  for(ll i=1;i<=N;++i) pfact(i,mp);
  ll num2=0,num4=0,num14=0,num24=0,num74=0;
  for(auto i:mp) {
    if(2<=i.second) num2++;
    if(4<=i.second) num4++;
    if(14<=i.second) num14++;
    if(24<=i.second) num24++;
    if(74<=i.second) num74++; 
  }
  ans+=num74+num24*(num2-1)+num14*(num4-1)+num4*(num4-1)*(num2-2)/2;
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;

    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(i*j==n)
            {
                cout<<"Yes\n";
                exit(0);
            }

        }
    }


   cout<<"No\n";
    exit(0);
}


Measured memory_bytes: 3600
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#pragma comment(linker, "/STACK:256000000")
using namespace std;

#define in(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)
#define forn(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef long double ld;

int main()
{
	//in("input.txt");
	//out("output.txt");
	srand(1373737);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	char c;
	cin >> c;
	c++;
	cout << c;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int merge(int A[], int left, int mid, int right){
  int compare_count = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];
  for(int i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  for(int i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  L[n1] = 0x7fffffff;
  R[n2] = 0x7fffffff;
  int i = 0, j = 0;
  for(int k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
    compare_count++;
  }
  return compare_count;
}
int mergesort(int A[], int left, int right){
  int compare_count = 0;
  if(left+1 < right){
    int mid = (left + right) / 2;
    compare_count += mergesort(A, left, mid);
    compare_count += mergesort(A, mid, right);
    compare_count += merge(A, left, mid, right);
  }
  return compare_count;
}

int main(){
  int n;
  scanf("%d", &n);
  if(n == 0){
    printf("\n0\n");
    return 0;
  }
  int S[500000];
  for(int i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }
  int count = mergesort(S, 0, n);
  printf("%d", S[0]);
  for(int i = 1; i < n; i++){
    printf(" %d", S[i]);
  }
  printf("\n");
  printf("%d\n", count);
}

Measured memory_bytes: 4916
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    vector<int> V;
    vector<int> C;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        V.emplace_back(tmp);
    }
    for(int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        C.emplace_back(tmp);
    }

    int X = 0, Y = 0;
    for(int i = 0; i < N; i++) {
        if(V[i] > C[i]) {
            X += V[i];
            Y += C[i];
        }
    }
    cout << X - Y << endl;
    return 0;
}

Measured memory_bytes: 256
// AOJ 0301: Baton Relay Game
// 2017.10.31
// 2018.1.19

#include <stdio.h>

typedef struct _T { struct _T *pre, *nxt; int f; } T;
T tbl[200002];
int a[200002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

void calc(int m)
{
	int i, j;
	T *cur, *pre, *nxt;

	cur = tbl;
	for (i = 0; i < m; i++) {
		j = a[i];
		if (j & 1) while (j--) cur = cur->pre;
		else       while (j--) cur = cur->nxt;
		cur->f = 0;
		pre = cur->pre, nxt = cur->nxt;
		pre->nxt = nxt, nxt->pre = pre;
		cur = nxt;
	}
}

int main()
{
	int n, m, q, i;

	n = in(), m = in(), q = in();

	for (i = 0; i < n; i++) tbl[i].nxt = tbl+i+1, tbl[i].pre = tbl+i-1, tbl[i].f = 1;
	tbl[0].pre = tbl+n-1, tbl[n-1].nxt = tbl;

	for (i = 0; i < m; i++) a[i] = in();

	calc(m);

	while (q--) putchar('0' + tbl[in()].f), putchar('\n');
	return 0;
}



Measured memory_bytes: 7028
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int a,b;
  cin>>a>>b;

  cout<<max(0,a-2*b)<<endl;
}

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

using namespace std;

struct Eins {
	vector<int> st;
	int n;
	Eins(int n = 0) : n(n) {
		st.resize(n << 2 | 1);
	}
	void build(int id,int l,int r,string&s) {
		if (l == r) {
			st[id] = (s[l-1] == 'B') + 1;
			return ;
		}
		int mid = l + r >> 1;
		build(id << 1,l,mid,s);
		build(id << 1|1,mid+1,r,s);
		st[id] = st[id << 1] + st[id << 1|1];
	}
	int get(int id,int l,int r,int L,int R) {
		if (l > R || r < L) return 0;
		if (L <= l && r <= R) return st[id];
		int mid = l + r >> 1;
		return get(id << 1,l,mid,L,R) + get(id << 1|1,mid+1,r,L,R);
	}
	int get(int L,int R) {
		return get(1,1,n,L,R);
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	Eins T1((int)s.size());
	Eins T2((int)t.size());
	T1.build(1,1,(int)s.size(),s);
	T2.build(1,1,(int)t.size(),t);
	int q;
	cin >> q;
	while (q--) {
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		if (T1.get(a,b) % 3 == T2.get(c,d) % 3) cout <<"YES\n";
		else cout <<"NO\n";
	}
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int i = 1;
  for(int cnt = 0; cnt <= n; cnt++) {
    if (i == 2) {
      cout << cnt;
      return 0;
    }
    i = a[i - 1];
  }
  cout << -1;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
using namespace std;


int main(){
	int N,A,B,C,X;
	while(cin>>N>>A>>B>>C>>X,N){
		int y,ans=-1;
		queue<int> Y;
		REP(i,0,N) cin>>y,Y.push(y);
		REP(i,0,10001){
			if(Y.front()==X) Y.pop();
			if(Y.empty()){
				ans=i;
				break;
			}
			X=(A*X+B)%C;
		}
		p(ans);
	}
	return 0;
}

Measured memory_bytes: 3044
n, m = gets.split.map(&:to_i)
r = Array.new(0)
sum = 1
a = Array.new(0)
b = Array.new(0)
m.times do |i|
	a, b = gets.split.map(&:to_i)
	r[i] = [a,b]
end

r.sort!.reverse!

k = r[0][0]

r.each do |i, j|
	if k >= j
		sum += 1
		k = i	
	end
end

puts sum





Measured memory_bytes: 10488
N = int(input())
A = list(map(int,input().split()))
four = 0
two = 0
one = 0 
for e in A:
    if e%4 == 0:
        four += 1
    elif e %2 == 0:
        two += 1
    else:
        one += 1

if two == 0:
    if one <= four + 1:
        print('Yes')
    else:
        print('No')
else:
    if one <= four:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 15020
using System;
using System.Linq;

namespace ABC098
{
    class C
    {
        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int[] WS = new int[N + 1];
            int[] ES = new int[N + 1];

            WS[0] = 0;
            ES[0] = 0;
            for (int i = 1; i < N + 1; i++)
            {
                if (S[i - 1] == 'W') { WS[i] = WS[i - 1] + 1; ES[i] = ES[i - 1]; }
                if (S[i - 1] == 'E') { ES[i] = ES[i - 1] + 1; WS[i] = WS[i - 1]; }
            }

            int[] res = new int[N + 1];

            for (int i = 0; i < N + 1; i++)
            {
                res[i] = WS[i] + ES[N] - ES[i];
            }

            Console.WriteLine(res.Min());
        }
    }
}


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int n;
	cin >> n;
	ll a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int type = 0;
	int ret = 1;
	for (int i = 1; i < n; i++) {
		if (type==1&&a[i]<a[i-1]) {
			ret++;
			type = 0;
			continue;
		}
		if (type==-1&&a[i]>a[i-1]) {
			ret++;
			type = 0;
			continue;
		}
		if (a[i]>a[i-1]) {
			type=1;
		}
		if (a[i]<a[i-1]) {
			type=-1;
		}
	}
	cout << ret << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
    int a[10]= {0};
    int b[10]= {0};
    int n,m;
    cin>>n>>m;
    int a1,b1;
    int temp=0;
    if(n==1)
    {
        for(int i=1; i<=m; i++)
        {
            cin>>a1>>b1;
            if(b[a1]==b1)
            {
                continue;
            }
            if(b[a1]==0)
            {
                b[a1]=b1;
                continue;
            }
            if(b[a1]!=b1)
                temp=1;
        }
    }
    else
    {
        for(int i=1; i<=m; i++)
        {
            cin>>a1>>b1;
            if(a1==1&&b1==0)
            {
                temp=1;
                continue;
            }
            if(b[a1]==b1)
            {
                continue;
            }
            if(b[a1]==0)
            {
                b[a1]=b1;
                continue;
            }
            if(b[a1]!=b1)
                temp=1;
        }
    }
    if(b[1]==0&&n!=1)
        b[1]=1;
    if(temp==1)
    {
        cout<<-1<<endl;
    }
    else
    {
        for(int i=1; i<=n; i++)
        {
            cout<<b[i];
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long int LLI;

string solve(string s, string t)
{
	int sum;
	for(int i = s.size() - t.size(); i >= 0; i--)
	{
		sum = 0;
		for(int j = 0; j < t.size(); j++)
			if( t[j] == s[i+j] or s[i+j] == '?' )
				sum++;
			else
				break;
		if( sum == t.size() )
		{
			for(int k = 0; k < i; k++)
				if( s[k] == '?' )
					s[k] = 'a';
			for(int k = i; k < i + t.size(); k++)
				s[k] = t[ k - i ];
			for(int k = i + t.size(); k < s.size(); k++)
				if( s[k] == '?' )
					s[k] = 'a';
			return s;
		}
	}
	return "UNRESTORABLE";		
}
int main()
{
	string s, t;
	cin >> s >> t;
	cout << solve(s,t);
	return 0;
}

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

int n;
bool a[25][25];
int dp[21][(1<<21)];
long long mod = 1e9 + 7;
int get(int i = 0 , int mask = 0)
{
    if(i == n)return (mask == (1<<n)-1);

    int &ret = dp[i][mask];
    if(~ret)    return ret;

    ret = 0;
    for(int j = 0 ; j < n ; j++)if(a[i][j] && (mask >> j & 1) == 0)
        ret = (1LL*ret + 1LL*get(i+1,mask|1<<j))%mod;
    return ret;
}

int main()
{
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < n ; j++)
            cin >> a[i][j];
    memset(dp,-1,sizeof dp);
    cout << get() << '\n';
    return 0;
}


Measured memory_bytes: 172288
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int N;
	while(1){
		cin >> N;
		if(N == 0) break;
		int i,j;
		int n, d;
		int h = 0, w = 0, w1 = 0;
		if(N == 1){
			cout << "1 " << "1" << endl; 
			continue;
		}
		else{
			int a[2*N + 1][2*N + 1];
			for(i = 0;i < 2*N+1;i++){
				for(j = 0;j < 2*N+1;j++){
					a[i][j] = 999;
					//cout << a[i][j];
				}
				//cout << endl;
			}
			a[N][N] = 0;
			int count = 1;
			for(int k = 0;k < N-1;k++){
				cin >> n >> d;
				//cout << endl;
				
				for(i = 0;i < 2*N+1;i++){
					for(j = 0;j < 2*N+1;j++){
						if(a[i][j] == n){
							if(d == 0){
								a[i][j-1] = count;
								count++;
							}
							if(d == 1){
								a[i+1][j] = count;
								count++;
							}
							if(d == 2){
								a[i][j+1] = count;
								count++;
							}
							if(d == 3){
								a[i-1][j] = count;
								count++;
							}
						}
						//cout << a[i][j];
					}
					//cout << endl;
				}
				//cout << endl;
			}
			/*for(i = 0;i < 2*N+1;i++){
				for(j = 0;j < 2*N+1;j++){
					cout << a[i][j];
				}
				cout << endl;
			}
			cout << endl;*/
			bool hantei = false;
			for(i = 0;i < 2*N+1;i++){
				for(j = 0;j < 2*N+1;j++){
					if(a[j][i] != 999){
						w = i;
						hantei = true;
						break;
					}	
				}
				if(hantei) break;
				//cout << "w = " << w << endl;
			}
			hantei = false;
			for(i = 2*N;i >= 0;i--){
				for(j = 0;j < 2*N+1;j++){
					if(a[j][i] != 999){
						w1 = i;
						hantei = true;
						break;
					}
				}
				if(hantei) break;
			}
			for(i = 0;i < 2*N+1;i++){
				for(j = 0;j < 2*N+1;j++){
					if(a[i][j] != 999){
						h++;
						break;
					}
				}
			}	
		}
		cout << w1-w+1 << " " << h << endl;
	}
	return 0;
}

Measured memory_bytes: 1780
(defun isPoor (a b c)
  (not
   (or 
    (and (= a b) (= b c)) 
    (and (/= a b) (/= b c) (/= c a))
    )
   )
  )
(defun YorN (bool)
  (if bool
      "Yes"
      "No"
      )
  )
(princ (YorN (isPoor (read) (read) (read))))

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

int main() {
	int n;
	cin>> n;
set<int> a;

for(int i=0;i<n;i++){
	int x;
	cin>>x;
	if(a.count(x)){
		a.erase(x);
	}
	else{
		a.insert(x);
	}
}
cout<<a.size()<<endl;

	return 0;
}

Measured memory_bytes: 4864
N,M=map(int,input().split())
L=[]
R=[]
for i in range(M):
  l,r=[int(i) for i in input().split()]
  L.append(l)
  R.append(r)
Lmax=max(L)
Rmin=min(R)
if Rmin-Lmax>=0:
  print(Rmin-Lmax+1)
else:
  print(0)

Measured memory_bytes: 10972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if(x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26400
//
// LCM (最小公倍数)
//
// verified
//   ABC 070 C - Multiple Clocks
//     https://beta.atcoder.jp/contests/abc070/tasks/abc070_c
//


/*
  a と b の最大公約数を G、最小公倍数を L とすると
     GL = ab
  が成り立つ。よって、 
     L = a/g * b (a は g で割り切れる)
   注意点として、L = a*b/g としてしまうと a*b の計算する部分でオーバーフローの危険がある。
*/


#include <iostream>
using namespace std;

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

long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}



int main() {
    int N; cin >> N;
    long long res = 1;
    for (int i = 0; i < N; ++i) {
        long long a; cin >> a;
        res = LCM(res, a);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import sys
x=int(input())
if x==2:
    print(2)
    sys.exit()
while True:
    flag=-1
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            flag=1
    if flag==-1:
        print(x)
        sys.exit()
    x+=1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,h,w;
    cin>>n>>h>>w;
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x>=h&&y>=w)
            ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
def inp(wide):
    a = input()
    ans = []
    for i in range(wide):
        if a[i] == '.':
            ans.append(['w',float('Inf')])
        else:
            ans.append(['b',float('Inf')])
    return ans
def chang(up,left,nex): 
    if nex[0] == 'w':
        return min(up[1],left[1])
    else:
        d = up[1]
        g = left[1]
        if up[0] == 'w':
            d = d+1
        if left[0] == 'w':
            g = g+1
        return min(d,g)
def main(board,high,wide,already):
    for i in range(wide):
        if 0 <= already-i and already -i < high:
            nex = board[already-i][i]
            if 0 <= already-i-1 and 0 <= i-1:
                board[already-i][i][1] = chang(board[already-i-1][i],board[already-i][i-1],nex)
            elif 0 <= already-i-1 and 0 > i-1:
                board[already-i][i][1] = chang(board[already-i-1][i],['w',float('inf')],nex)
            else:
                board[already-i][i][1] = chang(['w',float('inf')],board[already-i][i-1],nex)
    
    if already == high + wide -1:
        return board[high-1][wide-1][1]
    return main(board,high,wide,already+1)
    

a = input().split()
high = int(a[0])
wide = int(a[1])

board = []
for i in range(high):
    board.append([])
    board[i] = inp(wide)
if board[0][0][0] == 'w':
    board[0][0][1] = 0
else:
    board[0][0][1] = 1

if high < wide:
    bo = []
    for i in range(wide):
        bo.append([])
        for j in range(high):
            bo[i].append(board[j][i])   
else:
    bo = board
ans = main(bo,max(wide,high),min(wide,high),1)
print(ans)

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

int main() {
  int N;
  cin>>N;
  vector<pair<int,int>> p(N);
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    p[i]=make_pair(b,a);
  }
  sort(p.begin(),p.end());
  int T=0,Z=1;
  for(int i=0;i<N;i++){
    int a,b;
    tie(b,a)=p[i];
    T+=a;
    if(b<T){
      Z=0;
      break;
    }
  }
  if(Z){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}



Measured memory_bytes: 4844
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N,X;
    cin>>N>>X;
    vector<ll> ltbl(N);
    for(auto&& l:ltbl){
        cin>>l;
    }
    ll d=0;
    ll ans=0;
    for(int i=0;i<N;++i){
        d=d+ltbl[i];
        if(d<=X){
            ++ans;
        }
    }
    cout<<ans+1<<endl;
    return 0;
}

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

using namespace std;

int main(void)
{
  long long K;
  cin >> K;

  vector<long long> L; // Lunlun 数

  vector<long long> TMPold = {}; // ある桁の Lunlun 数を保存する
  
  // 1 桁
  for(long long i=0; i<9; i++) {
    long long newL = i+1;
    L.push_back(newL);
  }

  long long  start = 0;
  long long goal = 9;
  // 2 桁以降
 for(int i=0; i<10; i++) { // Lunlun 数の個数が 100001 を超えたらストップ
    int count = 0;
    for (long long i=start; i<goal; i++) { // i = TMPold のインデックス
      long long x = L.at(i);
      for (int j=-1; j<=1; j++) { // j = 新たに付け足す桁の数
        long long  one = x % 10;
        long long plus = one + j;
        if (plus >= 0 && plus <= 9) {
        long long newL = 10 * x + plus;
        L.push_back(newL);
        count++;
        }
      }
    }
    start = goal;
    goal = goal + count;
  }

      cout << L.at(K-1) << endl;
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
const int N=200000+5;
int main()
{
    int n,a[N];
    cin >> n;
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    sort(a,a+n);
    if(n==2) printf("%d %d\n",a[1],a[0]);
    else
    {
        int t=0;
        for(int i=0;i<n-1;i++)
        {
            if(a[i]<=a[n-1]/2) t=i;
            else break;
        }
        if(abs(a[t]*2-a[n-1])<=abs(a[n-1]-a[t+1]*2))
        {
            printf("%d %d\n",a[n-1],a[t]);
        }
        else printf("%d %d\n",a[n-1],a[t+1]);
    }
    return 0;
}


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

#define ll long long

int main() {
	
	ll x,k,d;
	cin >> x >> k >> d;
	x = abs(x);
	ll t = min(k, x/d);
	k -= t;
	x -= t*d;
	
	if(k%2 == 0) cout << x;
	else cout << d - x;
	return 0;
}


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

int main(void)
{
    //input
    int n;
    cin >> n;
    vector<int> a(n);

    //calculate
    int tmp;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> tmp;
        ++a[tmp-1];
    }
    for (int i = 0; i < n; i++)
        cout << a[i] << endl;
}


Measured memory_bytes: 4052
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node
{
    int c;
    int t;
}node[110];
bool cmp(Node a,Node b)
{
    return a.c<b.c;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int N,T;
    while(cin>>N>>T)
    {
        for(int i=0;i<N;i++)
        {
            scanf("%d%d",&node[i].c,&node[i].t);
        }
        sort(node,node+N,cmp);
        int i;
        for(i=0;i<N;i++)
        {
            if(node[i].t<=T)
            {
                break;
            }
        }
        if(i!=N)
        {
            cout<<node[i].c<<endl;
        }
        else
        {
            cout<<"TLE"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Web;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static System.Math;
 

class P
{
    static void Main()
    {
        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).Take(2).Aggregate(1, (x, y) => x * y) / 2);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double pi=3.141592653589793;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
	int a,b;
	cin>>a>>b;
int h,m;
cin>>h>>m;

double hk,mk;
hk=2.0*pi/720.0*(h*60.0+m+0.0);
mk=2.0*pi/60.0*(m+0.0);

double bv=cos(abs(hk-mk));
double val=(a+0.0)*(a+0.0)+(b+0.0)*(b+0.0)-2*(a+0.0)*(b+0.0)*bv;

val=sqrt(val);

dcout;
cout<<val<<endl;




}




Measured memory_bytes: 4204
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long N, std::vector<std::string> S) {
  sort(all(S));
  S.erase(unique(all(S)), S.end());
  ANS(S.size());
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  std::vector<std::string> S(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> S[i];
  }
  solve(N, std::move(S));
  return 0;
}


Measured memory_bytes: 9540
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string S;
	cin>>S;
	int flag=1;
	for(int i=0; i<3; i++)
	{
		
		if(S[i]==S[i+1])
		{
			flag=0;
			break;
		}
	}
	if(flag==0)
	{
		cout<<"Bad"<<endl;
	}
	else
	{
		cout<<"Good"<<endl;
	}
	return 0;
}
		


Measured memory_bytes: 256
#include<stdio.h>

int main(){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(b<=c||d<=a){
				puts("0");
				return 0;
		}
		if(a>c){
				if(b<d)printf("%d",b-a);
				else printf("%d",d-a);
		}
		else {	
				if(b<d)printf("%d",b-c);
				else printf("%d",d-c);
		}
		puts("");
		return 0;
}


Measured memory_bytes: 128
n = input()
a = int(n[0])*10 + int(n[1])
b = int(n[2])*10 + int(n[3])

s = 0
t = 0

if a > 0 and a <= 12:
  s = 1
if b > 0 and b <= 12:
  t = 1
if s == 1 and t == 1:
  print("AMBIGUOUS")
elif s == 0 and t == 1:
  print("YYMM")
elif s == 1 and t == 0:
  print("MMYY")
elif s == 0 and t == 0:
  print("NA")



Measured memory_bytes: 3064
from copy import deepcopy
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]
    if N == num:
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in range(length):
            ttmp = sorted(list(S[i]))
            for j in range(alphabet.index(ttmp[-1])+2):
                tmp.append(S[i]+alphabet[j])
        S = sorted(tmp)
        f(num+1,N,S)

N = int(input())
f(1,N,["a"])

Measured memory_bytes: 16224
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N,Z,W;
    int[] a;

    private void solve() {
        N = nextInt();
        Z = nextInt();
        W = nextInt();

        a = new int[N];
        for(int i = 0;i < N;i++) {
            a[i] = nextInt();
        }

        int ans = 0;

        ans = Math.abs(a[N-1] - W);

        if (N > 1) {
            ans = Math.max(ans,Math.abs(a[N-1] - a[N-2]));
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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

Measured memory_bytes: 22868
// I want to AC


#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#include<queue>
#include<assert.h>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
//#define  ll long long
using namespace std;
const int maxn = 1e6+7;
#define FOR(i, x, y) for (ll i = (x), _##i = (y); i < _##i; ++i)

ll mod = 1e9+7;
//const int maxn = 100010;
//ll f[maxn];
//ll inv[maxn]; // 阶乘的逆元
//void CalFact()
//{
//    f[0] = 1;
//    for (int i = 1; i < maxn; i++) f[i] = (f[i - 1] * i) % p;
//    inv[maxn - 1] = Pow(f[maxn - 1], p - 2, p);
//    for (int i = maxn - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % p;
//}
//ll C(int n, int m) { return f[n] * inv[m] % p * inv[n - m] % p; }
int a,b,c,q;
map<string , int > mp;
int main() {
cin >>a>>b>>c;
if((a==b &&a!=c)||(c==b &&b!=a)||(a==c &&b!=c)) cout<<"Yes"<<endl;
else cout<<"No"<<endl;



	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>
#include <cassert>
#include <iso646.h>
#include <exception>
#include <stdexcept>

using namespace std;

typedef long long i64;

int solve(string s, const int m, const bool init_shift_r)
{
    int cnt = 0;

    int shift_l = 0;
    int shift_r = init_shift_r;
    while (true)
    {
        const int l = m - shift_l;
        const int r = m + shift_r;

        if (l < 0 && r >= s.size())
            break;

        if (l < 0 ||
            r >= s.size() ||
            s[l] != s[r])
            cnt++;


        if (l == r)
        {
            shift_l++;
            shift_r++;
        }
        else if (l >= 0 && r <= s.size())
        {
            if (s[l] != s[r])
            {
                if (s[l] == 'x')
                    shift_l++;
                else if (s[r] == 'x')
                    shift_r++;
            }
            else
            {
                shift_l++;
                shift_r++;
            }
        }
        else
        {
            shift_l++;
            shift_r++;
        }
    }

    return cnt;
}

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

    string s;
    cin >> s;

    string clean;
    for (char c : s)
        if (c != 'x')
            clean.push_back(c);

    bool is_palindrome = true;
    for (int i = 0; i < clean.size() / 2; i++)
        is_palindrome &= clean[i] == clean[clean.size() - i - 1];

    if (!is_palindrome)
    {
        cout << -1;
        return 0;
    }

    if (clean.empty())
    {
        cout << 0;
        return 0;
    }

    const int skip = clean.size() / 2 + (clean.size() & 1);
    int non_x_seen = 0;
    for (int i = 0; i < s.size(); i++)
        if (s[i] != 'x')
        {
            non_x_seen++;

            if (skip == non_x_seen)
            {
                if (clean.size() & 1)
                {
                    cout << solve(s, i, false);
                    return 0;
                }

                int j = i + 1;
                while (j < s.size() && s[j] == 'x') j++;

                const int d = j - i;

                cout << solve(s, i + d / 2, (d & 1));
                return 0;
            }
        }
}

Measured memory_bytes: 592
N,A,B=map(int,input().split())
p=10**9+7
def f(n,x):
    a,b=1,1
    for i in range(1,x+1):
        a=a*n%p
        b=b*i%p
        n-=1
    return a*pow(b,p-2,p)
print((pow(2,N,p)-1-f(N,A)-f(N,B))%p)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;


struct Myon2
{
    int a;
}

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        string S = cin.next();

        long ans = 0;
        int BC = 0;

        for (int i = S.Length - 1; i >= 0; i--)
        {
            if (i >= 1 && S[i] == 'C' && S[i - 1] == 'B') { i--; BC++; }
            else if (S[i] == 'A') ans += BC;
            else BC = 0;
        }

        Console.WriteLine(ans);
    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int N;
string S;

int main () {
  cin >> N >> S;
  int count = 0, ans = 0;
  
  for (int i = 0; i < N; i++){
    if (S[i] == 'I'){
      count++;
    }else{
      count--;
    }
    
    if (ans < count){
      ans = count;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
from itertools import combinations_with_replacement
n=int(input())
ans=[0]*100000
list1=list(combinations_with_replacement(list(range(1,100)), 3))
for i in range(len(list1)):
    x=list1[i][0]
    y=list1[i][1]
    z=list1[i][2]
    if len(list(set(list1[i])))==1:
        ans[(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(x*z)-1]+=1
    elif len(list(set(list1[i])))==2:
        ans[(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(x*z)-1]+=3
    else:
        ans[(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(x*z)-1]+=6
for i in range(n):
    print(ans[i])

Measured memory_bytes: 89868
// https://atcoder.jp/contests/abc124/tasks/abc124_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0, high = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (auto x : v) {
        if (x >= high) {
            ans++;
            high = x;
        }
    }

    cout << ans << '\n';

    return 0;
}

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

int digit_sum(int num){
    if(num==0) return 0;
    return num%10+digit_sum(floor(num/10));
}

int main(){
    int N,min=999999;
    cin>>N;
    for(int i=1;i<N;i++){
        int a=digit_sum(i);
        int b=digit_sum(N-i);
        if(min>a+b){
            min=a+b;
        }
    }
    cout<<min<<endl;
    return 0;
}

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

using namespace std;

signed main(){
    int n, d;
    cin >> n >> d;
    /* 監視員一人当たり2d+1本の木を監視できる */
    int ans = n / (2 * d + 1);
    if (n % (2 * d + 1) != 0)
        ++ans;
    cout << ans << endl;
    return 0;
}

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

#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int h, w;

  while(cin >> h >> w) {
    if(h == 0 && w == 0) break;
    for(int i=0; i<h; i++) {
      for(int j=0; j<w; j++) {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
}

Measured memory_bytes: 1112
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

typedef long long ll;


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

    string s;
    cin >> s;

    unordered_map<char, int> char_to_int{ {'R', 0}, {'G', 1}, {'B', 2} };
    vector<char> int_to_char{ 'R', 'G', 'B' };
    vector<int> rgb_cnts{0, 0, 0};
    vector<vector<int>> accum_rgb_cnts{vector<int>(), vector<int>(), vector<int>()};

    for (int i = 0; i < n; i++)
    {
        rgb_cnts[char_to_int[s[i]]]++;
        for (int j = 0; j < 3; j++)
        {
            accum_rgb_cnts[j].push_back(rgb_cnts[j]);
        }
    }

    ll cnt = 0;
    for (int i = 0; i < n - 3; i++)
    {
        for (int j = i + 1; j < n - 1; j++)
        {
            if (s[i] == s[j])
            {
                continue;
            }
            const char rem_rgb = int_to_char[3 - (char_to_int[s[i]] + char_to_int[s[j]])];
            cnt += rgb_cnts[char_to_int[rem_rgb]] - accum_rgb_cnts[char_to_int[rem_rgb]][j];

            const int k = 2 * j - i;
            if (k < n && s[k] == rem_rgb)
            {
                cnt--;
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3704
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

const int Maxn = 210;
const int INF = (int)1e8;
int d[Maxn][Maxn];

int n, m, k;
int r[10];

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    cin >> n >> m >> k;
    for (int i = 0; i < k; ++i) {
        cin >> r[i];
        --r[i];
    }
    sort(r, r + k);

    for (int i = 0; i < n; ++i) {
        fill(d[i], d[i] + n, INF);
        d[i][i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = d[b][a] = c;
    }

    for (int l = 0; l < n; ++l) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (d[i][l] == INF || d[l][j] == INF) continue;
                d[i][j] = min(d[i][j], d[i][l] + d[l][j]);
            }
        }
    }

    int ans = INF;
    do{
        int cost = 0;
        for (int i = 1; i < k; ++i) {
            cost += d[r[i - 1]][r[i]];
        }
        ans = min(ans, cost);
    }while(next_permutation(r, r + k));

    cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = double;
using ii = pair <int, int>;

#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define ROF(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define ALL(a, b) for(auto &a : b)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))

template <class T> void Max(T &x, T y) {
    x = (x > y) ? x : y;
}
template <class T> void Min(T &x, T y) {
    x = (x < y) ? x : y;
}

const int N = 6e5 + 5;
int n, m, p, x, y, cnt[3];
pair<ll, ll> a[N];

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> x >> y >> n >> m >> p;
    FOR(i, 1, n) cin >> a[i].fi, a[i].se = 1;
    FOR(i, 1, m) cin >> a[i + n].fi, a[i + n].se = 2;
    FOR(i, 1, p) cin >> a[i + n + m].fi, a[i + n + m].se = 0;
    sort(a + 1, a + n + m + p + 1);
    reverse(a + 1, a + n + m + p + 1);
    FOR(i, 1, x + y) cnt[a[i].se]++;
    if(cnt[1] <= x && cnt[2] <= y) {
        ll tot = 0;
        FOR(i, 1, x + y) {
            tot += a[i].fi;
        }
        return cout << tot, 0;
    }
    int c = x;
    ll tot = 0, ans = 0;
    int nn = n + m + p, tmp = x;
    FOR(i, 1, nn) {
        if(a[i].se == 1) {
            tot += a[i].fi, tmp--;
            if(!tmp)
                break;
        }
    }
    if(!tmp) {
      tmp = y;
      FOR(i, 1, nn) if(a[i].se != 1) {
          tot += a[i].fi, tmp--;
          if(!tmp)
              break;
      }
    }
    else tot = 0;
    ans = max(ans, tot);
    tmp = y, tot = 0;
    FOR(i, 1, nn) if(a[i].se == 2) {
        tot += a[i].fi, tmp--;
        if(!tmp)
            break;
    }
    //tmp = x;
    if(!tmp) {
        tmp = x;
        FOR(i, 1, nn) if(a[i].se != 2) {
        tot += a[i].fi, tmp--;
        if(!tmp)
            break;
        }
    }
    else tot = 0;
    Max(ans, tot);
    cout << ans;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  200010;  
const int mod = 1e9 + 7;
#define FI first
#define SE second
typedef pair<int, int>pii;
char s[N];
int main()  
{  
 //  freopen("in.txt","r",stdin);
   while (~scanf("%s", s))
   {
   		int n = strlen(s);
   		int ans = 0;
   		for (int i = 0; i < n; i++)
   			for (int j = i + 1; j < n; j++)
   				if ((j - i + 1)&1)
   					continue;
   				else
   				{
   					int h = (j - i + 1)>>1;

   					for (int k = 0; k < h; k++)
   						if (s[i + k] == s[i + h + k])
   						{
   							if (h < (n>>1))
   								ans = max(ans, k - i + 1);   							 
   						}
   						else
   							break;
   				}
   		printf("%d\n", ans<<1);

   }
   return 0;  
}  

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

int main() {
  
  int N;
  cin >> N;
  
  char c[N];
  for (int i = 0; i < N; i++) cin >> c[i];
  
  int ans = 0;
  for (int i = 0; i < N-2; i++) {
    if (c[i] == 'A' && c[i+1] == 'B' && c[i+2] == 'C') ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
using namespace std;

int main() {
	int n;cin>>n;
	int def=1;for(int i=0;i<6;i++)def*=10;

	vector<int> a(n),exist(def+1,0),ansadd(def+1,1);

	for(int i=0;i<n;i++){
		cin>>a[i];
		exist[a[i]]++;
	}
	if(exist[1]>0){
		if(exist[1]==1){
			cout<<1<<endl;
		}else{
			cout<<0<<endl;
		}
		return 0;
	}
	int ans=0;
	for(int i=2;i<=def;i++){
		if(exist[i]==0)continue;
		int temp=i*2;
		while(temp<=def){
			ansadd[temp]=0;
			temp+=i;
		}
		if(ansadd[i]){
			if(exist[i]==1){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11968