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

int main(void){
    int N,K;
    cin >> N >> K;
    vector<int> d(K);
    for(int i = 0; i < K;i++)cin >> d[i];
    
    for(int i = N; N < 10000; i++){
        
        int M = i;
        bool flag = false;
        while(M){
            
            int A = M % 10;
            for(auto a:d){
                if(A==a)flag = true;
            }
            
            M/= 10;
            
        }
        
        if(flag)continue;
        cout << i << endl;
        return 0;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], W = I[1];
		var v = new int[N];
		var w = new int[N];
		for (var i = 0; i < N; i++) { I = G; w[i] = I[0]; v[i] = I[1]; }
		var V = v.Sum();
		var dp = new long[V + 1];
		for (var i = 1; i <= V; i++) dp[i] = INFL;
		for (var i = 0; i < N; i++) for (var j = V; j >= v[i]; j--) dp[j] = Min(dp[j], w[i] + dp[j - v[i]]);
		var ans = 0;
		for (var j = V; j >= 0; j--) if (dp[j] <= W) { ans = j; break; }
		WriteLine(ans);
	}
}


Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=998244353;
const int maxn=(1e5)+10;
int n,cnt[maxn];
ll ans=1;
ll ksm(ll x,ll y) {
	ll res=1;
	while (y) {
		if (y&1) res=res*x%mod;
		x=x*x%mod; y>>=1;
	} return res;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); int x;
	for (int i=1;i<=n;i++) {
		read(x),cnt[x]++;
		if (i==1&&x!=0) { printf("0\n"); return 0; }
	}
	if (cnt[0]!=1) { printf("0\n"); return 0; }
	for (int i=1;i<n;i++) {
		ans=ans*ksm(cnt[i-1],cnt[i])%mod;
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

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

int main(){
	int n;
	string str;
	while(cin >> n, n){
		int field = 0;
		int card[10];
		fill(card, card+10, 0);

		cin >> str;
		for(int i=0; i < str.size(); i++){
			card[i%n]++;
			if(str[i] == 'M');
			else if(str[i] == 'S'){
				field += card[i%n];
				card[i%n] = 0;
			}
			else if(str[i]  == 'L'){
				card[i%n] += field;
				field = 0;
			}
		}
		sort(card, card+n);
		for(int i=0; i < n; i++){
			cout << card[i] << " ";
		}
		cout << field << endl;
	}
}

Measured memory_bytes: 1224
a, v = list(map(int, input().split(' ')))
b, w = list(map(int, input().split(' ')))
t = int(input())

distance = b - a
relative_velocity = w - v
if relative_velocity > 0:
    print('NO')
else:
    if (abs(relative_velocity)*t >= abs(distance)):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9188
#include <stdio.h>
int n, k;
int a[200000];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	for (int i = k; i < n; i++) {
		if (a[i - k] < a[i])printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 2444
N = int(input())
A = list(map(int,input().split()))
i = 0
k = 0

for i in range(len(A)):
    v = A[i]
    j = i-1
    while j>=0 and A[j]>v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)



Measured memory_bytes: 5980
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
    int a, b; cin >> a >> b;
    char t[100][101];
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) t[i][j] = i < 50 ? '.' : '#';
        t[i][100] = '\0';
    }
    a--, b--;
    for (int i = 1; b; i += 2) for (int j = 1; b && j < 100; j += 2) b--, t[i][j] = '#';
    for (int i = 51; a; i += 2) for (int j = 1; a && j < 100; j += 2) a--, t[i][j] = '.';
    cout << "100 100\n";
    for (int i = 0; i < 100; i++) puts(t[i]);
}


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  ll X;
  std::cin >> X;

  ll balance = 100;
  int ans = 0;
  while(balance < X) {
    balance += balance / 100;
    ++ans;
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 3612
n = int(input())
ab = []
for _ in range(n):
    a = list(map(int, input().split()))
    ab.append(a)

ab.sort(key=lambda x: x[1])

count = 1
ans = 1
init = ab[0][0]
if ab[0][0] > ab[0][1]:
    ans = 0
for i in range(1, n):
    if init <= ab[i][1]:
        init += ab[i][0]
        count += 1
        if init > ab[i][1]:
            ans = 0
            break
if ans == 0:
    print("No")
else:
    if count == n:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 53724
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

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

		int s = a * b;
		double tsubo = 3.305785;

		double area = (double)s / tsubo;

		System.out.println(area);



	}
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	double p[6], q[6];
	rep(i, 6) {
		int x; cin >> x;
		p[i] = (double)x / 100;
	}
	rep(i, 6) {
		int x; cin >> x;
		q[i] = (double)x / 100;
	}

	double lo = 0.0, hi = 1.0;
	double ans = 1.0;

	rep(tt, 1000) {
		double m1 = (lo * 2 + hi) / 3;
		double m2 = (hi * 2 + lo) / 3;
		double p1 = 0, p2 = 0;
		rep(i, 6) p1 += max(m1 * p[i], (1 - m1) * q[i]);
		rep(i, 6) p2 += max(m2 * p[i], (1 - m2) * q[i]);
		chmin(ans, min(p1, p2));
		if (p1 > p2) {
			lo = m1;
		} else {
			hi = m2;
		}
	}
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
readlines.each do |l|
  l.chomp!
  win = "d"
  (0..6).step(3) {|i| win = l[i] if l[i] == l[i+1] && l[i] == l[i+2] && l[i] != "s"}
  (0..2).each {|i| win = l[i] if l[i] == l[i+3] && l[i] == l[i+6] && l[i] != "s"} 
  win = l[0] if l[0] == l[4] && l[0] == l[8] && l[0] != "s"
  win = l[2] if l[2] == l[4] && l[2] == l[6] && l[2] != "s"
  puts win 
end

Measured memory_bytes: 6104
f = list(input())
s = []

for i, v in enumerate(f):
    if v == '\\':
        s.append([v, i])
    elif v == '/' and len(s) > 0:
        n = s.pop()
        if n[0] == '\\':
            t = i-n[1]
            s.append(['.', t])
        elif len(s) > 0:
            j = len(s)-1
            n1 = n[1]
            while j >= 0 and s[j][0] == '.':
                #print(n1, s[j][1])
                n1 += s[j][1]
                j -= 1
            if j >= 0:
                m = s[j]
                # print(m)
                n1 += i-m[1]
                s = s[:j]
                s.append(['.', n1])
            else:
                # print("err")
                s.append(n)

        else:
            s.append(n)
    #print(v, s, i)


a = [v[1] for v in s if v[0] == '.']
print(sum(a))
a.insert(0, len(a))
print(" ".join([str(v) for v in a]))



Measured memory_bytes: 8060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 537427207;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n,m;cin>>n>>m;
    string a[n];
    rep(i,n)cin>>a[i];
    string tmp[m];
    rep(i,m)cin>>tmp[i];
    rep(i,n-m+1){
        rep(j,n-m+1){
            bool ans = true;
            rep(p, m){
                rep(q,m){
                    if(a[i+p][j+q] != tmp[p][q])ans = false;
                }
            }
            if(ans){cout<<"Yes"<<endl; return 0; }
        }
    }
    cout<<"No"<<endl; return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

x = 100
year = 0
while x < N:
    x += x // 100
    year += 1
print(year)


Measured memory_bytes: 9448
function main (s) {
	s=s.split("\n");
	var n=Number(s[0]);
	var a=Number(s[1]);
	if(n%500<=a)console.log("Yes\n");
	else console.log("No\n");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

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

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 998244353;


    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    rep(i,n)cin>>p[i];
    sort(p.begin(),p.end());
    int ans=0;
    rep(i,k)ans+=p[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#import<atcoder/all>
using namespace std;int n,a,i;int main(){cin>>n>>a;atcoder::fenwick_tree<long>f(n);for(;i<n;i++)cin>>a,f.add(i,a);for(;cin>>n>>a>>i;n&&cout<<f.sum(a,i)<<' ')if(!n)f.add(a,i);}

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

using namespace std;
int main(){
  int n,a,b,c,x;
  while(cin>>n>>a>>b>>c>>x,n+a+b+c+x){
    vector<int>Y;
    int ans=0;
    int flag=1;
    for(int i=0;i<n;i++){
      int s;cin>>s;
      while(x!=s&&flag==1){
	x=(a*x+b)%c;
	ans++;
	if(ans>10000){
	  ans=-1;
	  flag=0;
	  break;
	}
      }
      if(i!=n-1&&flag==1){
	x=(a*x+b)%c;
	ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, x, a; set <int> s;

void solve()
{
    cin >> x >> n;
    for (int i=0; i<n; i++) {
        cin >> a; s.insert(a);
    }
    int k = x, l = x;
    while (true) {
        if (s.count(l)==0) {
            nout(l); return;
        }
        if (s.count(k)==0) {
            nout(k); return;
        }
        k++;
        l--;
    }
    
}

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

Measured memory_bytes: 3640
n=int(input())
ans=0
dcnt=0
for i in range(1,n+1):
        if i%2!=0:
                for j in range(1, i+1):
                        if i%j==0:
                                dcnt += 1
                if dcnt==8:
                        ans += 1
                dcnt=0
print(ans)

Measured memory_bytes: 38868
#include <stdio.h>
#include <ctype.h>
#include <bits/stdc++.h>
#include<algorithm>
#include <set>
using namespace std;
multiset<int> st;     

 int j = 0;

int main() {
  int N,M;
  int a[1010];
  cin >> N>>M;
  for(int i=0;i<N;i++)cin >> a[i];
  sort(a,a+N);
  
  for(int i=0;i<M;i++){
   
   j += a[i];
  }
    
    
    cout << j <<endl;
  

}

Measured memory_bytes: 3612
def main():
    S = input()
    N = len(S)
    res = [0] * N
    for i in range(N-1):
        if S[i] == 'R' and S[i+1] == 'L':
            l, r, cnt = i, i+1, 0
            while l >= 0 and S[l] == 'R':
                if cnt % 2 == 0:
                    res[i] += 1
                else:
                    res[i+1] += 1
                cnt += 1
                l -= 1

            cnt = 0
            while r < N and S[r] == 'L':
                if cnt % 2 == 0:
                    res[i+1] += 1
                else:
                    res[i] += 1
                cnt += 1
                r += 1
    print(" ".join([str(r) for r in res]))

if __name__ == "__main__":
    main()

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

int main(void){
    int n, m;
    string s[100];
    string t[100];
    
    cin >> n;
    int i;
    for(i = 0; i < n; i++){
        cin >> s[i];
    }
    
    cin >> m;
    int j;
    for(j = 0; j < m; j++){
        cin >> t[j];
    }
    
    int max = 0;
    int cnt;
    int k;
    for(i = 0; i < n; i++){
        cnt = 0;
        for(k = i; k < n; k++){
            if(s[i] == s[k]){
                cnt++;
            }
        }
        for(j = 0; j < m; j++){
            if(s[i] == t[j]){
                cnt--;
            }
        }
        
        if(cnt > max){
            max = cnt;
        }
    }
    
    cout << max << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 整数の入力
            long a = Long.parseLong(in.next());
            long b = Long.parseLong(in.next());
            long ans = 0;

            ans = lcm(a, b);

            // 出力
            out.println(ans);

        }

        static long lcm(long a, long b) {
            long temp;
            long c = a;
            c *= b;
            while ((temp = a % b) != 0) {
                a = b;
                b = temp;
            }
            return (long) (c / b);
        }

    }
}



Measured memory_bytes: 23252
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    int64_t N;
    std::cin >> N;

    int64_t dp[100010] = {};

    for (int64_t i = 0; i < N; ++i) {
        int64_t a;
        std::cin >> a;
        dp[a]++;
    }

    int64_t ans = 0;
    for (int64_t i = 1; i < 100010; ++i) {
        ans += i * dp[i];
    }

    int64_t Q;
    std::cin >> Q;
    for (int64_t i = 0; i < Q; ++i) {
        int64_t b, c;
        std::cin >> b >> c;
        int64_t num = dp[b];
        dp[c] += dp[b];
        dp[b] = 0;

        ans -= num * b;
        ans += num * c;
        std::cout << ans << std::endl;
    }

    return 0;
}

Measured memory_bytes: 4376
S = input()

if S[0] != 'A':
    print('WA')
    exit()
    
index = S[2:-1].find('C')
if index == -1:
    print('WA')
    exit()
index = S[2:-1].find('C',index+1)
if index >= 0:
    print('WA')
    exit()


index = S.find('C')
S=S[1:index] + S[index + 1:len(S)]

if S != S.lower():
    print('WA')
    exit()

print('AC')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define sort(a) sort((a).begin(),(a).end())
#define rev(a) reverse((a).begin(),(a).end())
using db = double;
using namespace std;
typedef long long ll;


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


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//Transparent Mahjong
public class Main{

	int[] c, use;
	int free = 0;
	
	boolean f(int k, int u){
		if(free < u)return false;
		if(k==13){
			for(int i=1;i<=12;i++){
				if(use[i]<c[i] || 4<use[i])return false;
			}
			return true;
		}
		if(4<use[k])return false;
		if(use[k]<=1){
			int d = Math.max(0, 3-(c[k]-use[k]));
			use[k]+=3;
			if(f(k, u+d))return true;
			use[k]-=3;
		}
		if(c[k]<=use[k] && f(k+1, u))return true;
		if(k<=10){
			for(int i=1;i<=4;i++){
				int d = 0;
				for(int j=k;j<k+3;j++){
					d += Math.max(0, i-(c[j]-use[j]));
					use[j]+=i;
				}
				if(f(k+1, u+d))return true;
				for(int j=k;j<k+3;j++)use[j]-=i;
			}
		}
		return false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		c = new int[13];
		use = new int[13];
		for(int i=0;i<3*n+1;i++){
			String s = sc.next();
			if("*".equals(s))free++;
			else c[Integer.parseInt(s)]++;
		}
		List<Integer> res = new ArrayList<Integer>();
		for(int i=1;i<=12;i++){
			if(c[i]<4){
				c[i]++;
				for(int j=1;j<=12;j++){
					Arrays.fill(use, 0);
					use[j] = 2;
					if(f(1, 0)){
						res.add(i);
						break;
					}
				}
				c[i]--;
			}
		}
		if(res.isEmpty())System.out.println(-1);
		else for(int x:res)System.out.println(x);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI 2*acos(0.0)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define rt return true
#define rf return false

///................function.....................///
#define siz(s) (int)(s.size())
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define dbg(a) cout << #a << " = " << a << " ";
///...........knight moves.....................///
///int dx[] = {+1,+1,-1,-1,+2,+2,-2,-2};
///int dy[] = {+2,-2,+2,-2,+1,-1,+1,-1};
const int N=200005;
vb vis(N);
vvi graph(N);
map<pii,bool>mmp;
int cnt;
void dfs(int node)
{
    cnt++;
    vis[node]=true;
    for(auto it:graph[node])
    {
        if(!vis[it])
            dfs(it);
    }
}
int main()
{
    FIO;
    int n,m,i,j;
    cin>>n>>m;
    int a,b;
    for(i=0; i<m; i++)
    {
        cin>>a>>b;
        if(mmp[mp(a,b)])continue;
        mmp[mp(a,b)]=true;
        mmp[mp(b,a)]=true;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    int mx=0;
    for(i=1; i<=n; i++)
    {
        if(vis[i]==0)
        {
            cnt=0;
            dfs(i);
        }
        mx=max(cnt,mx);
    }
    cout<<mx<<endl;
}


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

typedef long long LL;

const LL MOD = 1e9+7;

inline LL dmod(LL x){
	return x%MOD;
}

int n;
string s;
int pan;
LL memo[5005][5005];

LL dp(int id, int jadi){
	if(id >= n){
		if(jadi == pan) return 1LL;
		else return 0LL;
	}
	LL &ret = memo[id][jadi];
	if(ret!=-1) return ret;
	ret = 0LL;
	ret = dp(id+1,jadi+1)*2LL;
	ret = dmod(ret+dp(id+1,(jadi>0)?jadi-1:jadi));
	return ret;
}

LL fe(LL x, LL y){
	if(y==0) return 1LL;
	LL ret = fe(x,y/2);
	ret = dmod(ret*ret);
	if(y&1){
		ret = dmod(ret*x);
	}
	return ret;
}

int main(){
	memset(memo,-1,sizeof(memo));
	cin >> n;
	cin >> s;
	pan = s.size();
	LL ans = dp(0,0);
	LL tmp = fe(2LL,pan);
	ans = dmod(ans*fe(tmp,MOD-2));
	cout << ans << endl;
	return 0;
}

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

def calc(x, y):
    return 4 * x + 7 * y

max4 = N // 4 + 2
max7 = N // 7 + 2

re = 'No'
for i in range(max4):
    for j in range(max7):
        if calc(i, j) == N:
            re = 'Yes'
            break
            
print(re)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0;i<n;i++)arr[i]=sc.nextInt();
		int output = 0;
		for(int i = 1;i<n-1;i++) {
			if(arr[i]>arr[i-1]&&arr[i]<arr[i+1])output++;
			else if(arr[i]<arr[i-1]&&arr[i]>arr[i+1])output++;
		}
		System.out.println(output);

	}

}


Measured memory_bytes: 22868
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#define rep(i,n) for(int i = 0; i < (long int)n; i++)
typedef long long ll;
using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<ll> d(n);
  rep(i,n){
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  cout << d[n/2] - d[n/2-1];
  return 0;
}


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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;
	vector<pair<int, int>> drinks(N);
	for (auto& d : drinks) {
		cin >> d.first >> d.second;
	}
	sort(drinks.begin(), drinks.end());

	ll ans = 0;
	for (auto& d : drinks) {
		int take = min(M, d.second);
		ans += ll(take) * d.first;
		M -= take;
		if (M == 0) {
			break;
		}
	}
	cout << ans << '\n';

	return 0;
}


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

int main(){
  int n;
  cin >> n;
  
  vector<long> a(n+1); // モンスターの数
  vector<long> b(n);   // 倒せる数
  
  for(int i = 0; i < n + 1; i++){
    cin >> a[i];
  }
  
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }

  long sum = 0;
  long nokori = 0;
  
  for(int i = 0; i < n; i++){
    if(a[i] > b[i]){ // モンスター＞倒せる数
      sum += b[i];
    }
    else{ // 倒せる＞モンスター
      sum += a[i];
      nokori = b[i] - a[i];
      
      if(a[i+1] > nokori){ //次の街のモンスター＞残りの倒せる数
        sum += nokori;
        a[i+1] -= nokori;
      }
      else{
        sum += a[i+1];
        a[i+1] = 0;
      }
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
const int MAX = 100001;

template<class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];
  //dp[i][j] : i-1までで価値がjである最小の重さ
  vector<vector<ll>> dp(101, vector<ll>(100001, INF));
  dp[0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < MAX; j++) {
      if (j - v[i] >= 0) chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
      chmin(dp[i + 1][j], dp[i][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < MAX; i++) {
    if (dp[N][i] <= W) ans = i;
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
void debug(vector<T> &vec) {
    for (auto x : vec) {
        cout << x << " ";
    }
    cout << endl;
    return;
}

template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

void solve(int n, int k) {
    n += 1;
    vector<int> a(n, 0);
    REP(i, k) {
        int input;
        cin >> input;
        a[input] = 1;
    }

    if (a[0] == 0) {
        int ans = 0;
        for (int left = 0; left < n; left++) {
            if (a[left] == 0) continue;
            int right = left + 1;
            while (right < n && a[right] == 1) {
                right += 1;
            }
            ans = max(ans, right - left);
        }

        cout << ans << endl;

    } else {
        int ans = 0, used = 0;
        for (int left = 1; left < n; left++) {
            if (a[left] == 0) continue;
            int right = left + 1;
            while (right < n && a[right] == 1) {
                right += 1;
            }

            int tmp = right;
            right += 1;
            while (right < n && a[right] == 1) {
                right += 1;
            }

            ans = max(ans, right - left);
            left = tmp;
        }

        cout << ans << endl;
    }
}

int main() {
    int n, k;
    while (cin >> n >> k && n) {
        solve(n, k);
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n;
	string s;
	cin>>n;
	cin>>s;
	if(n%2==0&&s.substr(0,n/2)==s.substr(n/2,n/2))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#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 max = -1;
    for(int i = 0; i < N; i++){
        for(int n = i+1; n < N; n++){
            if(max < abs(a[i]-a[n])){
                max = abs(a[i] - a[n]);
            }
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
Ga={}
Gb={}
A=list(input())
B=list(input())
flag = True
for i in range(len(A)):
  if A[i] in Ga and Ga[A[i]] != B[i]:
    flag = False
    break
  else:
    Ga[A[i]] = B[i]
for i in range(len(B)):
  if B[i] in Gb and Gb[B[i]] != A[i]:
    flag = False
    break
  else:
    Gb[B[i]] = A[i]
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 6704
import java.util.*;

public class Main{
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	String fir = s.substring(0, 1);
	String sec = s.substring(1, 2);
	String thi = s.substring(2, 3);
	String fou = s.substring(3, 4);
	String ans;
	if(fir.equals(sec) & fir.equals(thi)) {
		ans = "Yes";
	}else if(sec.equals(thi) & sec.equals(fou)) {
		ans = "Yes";
	}else {
		ans = "No";
	}
	System.out.print(ans);
	
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
const int mod=1e9+7;

int f(int n,int p){
  if(n==0){return 1;}
  int64_t x=f(n/2,p);x%=mod;
  x*=x;x%=mod;
  if(n%2!=0){x*=p;}
  x%=mod;
  return x;
}
 
int choose(int n,int a){
  int64_t u=1,d=1;
  for(int i=0;i<a;i++){
    u*=n-i;u%=mod;
    d*=i+1;d%=mod;
  }
  return u*f(mod-2,d)%mod;
}

int main() {
  int X,Y;
  cin>>X>>Y;
  if((X+Y)%3!=0){cout<<0<<endl;return 0;}
  int n=(X+Y)/3;
  if(X-n<0||Y-n<0){cout<<0<<endl;return 0;}
  cout<<choose(X-n+Y-n,X-n)<<endl;
  return 0;
}

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

int main() {
  int a,s1,s2,s3;
  cin >> a;
  
  s1 = a / 100;
  s2 = a / 10 - s1 * 10;
  s3 = a - s1 * 100 - s2 * 10;
  
  cout << s1 + s2 + s3 << endl;
  // cout << s2 << endl;
  // cout << s3 << endl;

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> C(N - 1), S(N - 1), F(N - 1);
    REP(i, N - 1) cin >> C.at(i) >> S.at(i) >> F.at(i);

    REP(i, N) {
        int st = i;
        int time = 0;
        FOR(now, i, N - 1) {
            if (time < S[now]) time = S[now];
            if (time % F[now] != 0) time += F[now] - (time % F[now]);
            time += C[now];
        }
        cout << time << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,N,j;
  int v,A[1000];
  scanf("%d",&N);

  for(i=0;i<=N-1;i++){
    scanf("%d", &A[i]);
    if(i==N-1){
    printf("%d\n",A[i]);
    }
    else{
      printf("%d ",A[i]);
    }
  }
  
   for(i=1; i<=N-1;i++){
    v=A[i];
    j = i-1;
     while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
     }
      for(j=0;j<N;j++){
	if(j==N-1){
       printf("%d\n",A[j]);
	}
	else {
	  printf("%d ",A[j]);
	}
     }
    }
   return 0;
}



Measured memory_bytes: 2056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long[] answers = new long[100000];

        for (int x = 1; x <= 100; x++)
        {
            for (int y = 1; y <= 100; y++)
            {
                for (int z = 1; z <= 100; z++)
                {
                    long num = x * x + y * y + z * z + x * y + y * z + z * x;
                    answers[num]++;
                }
            }
        }

        for (int i = 1; i <= n; i++)
        {
            Console.WriteLine(answers[i]);
        }

    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27824
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e3+1;
int h, w;
ll DP[N][N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  DP[0][1] = 1;
  FOR(i, 0, h){
    string s;
    cin >> s;
    FOR(j, 0, w) if(s[j]=='.') DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % MOD;
  }
  cout << DP[h][w] << endl;
}


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

int main(){
  int ans=0;
  string s;
  cin>>s;
  
  if(s[0]=='1'){
    ans++;
  }
  if(s[1]=='1'){
    ans++;
  }
  if(s[2]=='1'){
    ans++;
    
  }
  cout<<ans<<endl;
}
  


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

typedef struct{
  int t;
  int s;
  int d;
}Data;

bool operator<(Data d1,Data d2){
  return (d1.t < d2.t);
}

int main(){
  int n,m;
  while(cin>>n>>m,n){
    vector<Data> v(m);
    for(int i=0;i<m;i++){
      cin>>v[i].t>>v[i].s>>v[i].d;
      v[i].s--;
      v[i].d--;
    }
    sort(v.begin(),v.end());
    vector<int> infected(n,0);
    int cnt=1;
    infected[0]=-1;

    for(int i=0;i<m;i++){
      if(infected[v[i].s]!=0 && infected[v[i].s]!=v[i].t && infected[v[i].d]==0){
	infected[v[i].d]=v[i].t;
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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

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

if a < b then
  if k < a - 1 then
    puts (1 + k).to_s
  elsif b - a <= 1 then
    puts (1 + k).to_s
  else
    k -= a - 1
    m = k / 2
    t = a
    t += m * (b - a)
    
    if k % 2 == 1 then
      t += 1
    end
    
    puts t.to_s
  end
else
  puts (1 + k).to_s
end

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int dpr[n];
    int dpl[n];
    dpr[0] = 0;
    dpl[n-1] = 0;
    for(int i = 0; i < n-1; i++){
        if(s[i] == 'W'){
            dpr[i+1] = dpr[i]+1;
        } else {
            dpr[i+1] = dpr[i];
        }
    }
    for(int i = n-1; i >=1; i--){
        if(s[i] == 'E'){
            dpl[i-1] = dpl[i]+1;
        } else {
            dpl[i-1] = dpl[i];
        }
    }
    int ans = min(dpr[n-1], dpl[0]);
    for(int i = 1; i < n-2; i++){
        ans = min(ans, dpr[i]+dpl[i]);
    }
    cout << ans << endl;
    return 0;
}


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

 

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

#define rep(i, from, to) for (int i = from; i < (to); ++i)

#define all(x) x.begin(), x.end()

#define sz(x) (int) (x).size()

#define FOR(i, to) for (int i = 0; i < (to); ++i)

 

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pii;

typedef pair<double,double> pdd;

typedef vector<ll> vll;

typedef vector<pair<int,int>> vpi;

typedef pair<ll,ll> pll;

typedef vector<string> vs;

#define MOD 998244353

#define mod 998244353

#define INF 1000000000LL * 100000000LL

#define Nmax 202020

int N, T, M, K, Q;



ll A[202020];


int main() {

  cin.sync_with_stdio(false);

  cin >> N;
  FOR(i, N) {
    cin >> A[i];
  }
  if(A[N-1] != 2) {
    cout << "-1"; return 0;
  } else {
    ll mn = 2;
    ll ma = 3;
    for(int i=N-2;i>=0;--i) {
      if(mn % A[i] != 0)
      mn = mn + (A[i] - (mn % A[i]));
      ma = ma - (ma % A[i]) + A[i] - 1;
      
      if(mn > ma) {
        cout << "-1";
        return 0;
      }
      
    }
    cout << mn << " " << ma << endl;
  }

}

 

Measured memory_bytes: 1024
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,b[101],a[101];
int32_t main(){
CODE_START;
cin>>n;
for(ll i=0;i<n-1;i++)
cin>>b[i];
b[n-1]=b[n-2];
a[0]=b[0];
for(ll i=1;i<n;i++)
a[i]=min(b[i],b[i-1]);
ll ans=0;
for(ll i=0;i<n;i++)
ans=ans+a[i];
cout<<ans<<endl;
}


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

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

using namespace std;

char ask(int x){
	printf("%d\n",x);
	fflush(stdout);

	char s[8]; scanf("%s",s);
	if(s[0]=='V') exit(0);
	return s[0];
}

int main(){
	int n; scanf("%d",&n);

	char r1=ask(0);

	int lo=0,hi=n;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		char r2=ask(mi);
		if(((mi-lo)%2==0 && r1!=r2) || ((mi-lo)%2==1 && r1==r2)){
			hi=mi;
		}
		else{
			lo=mi;
			r1=r2;
		}
	}
	assert(false);

	return 0;
}


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

BA = 0
start_B = 0
end_A = 0

ans = 0
for _ in range(N):
    s = list(input())
    if s[0] == 'B' and s[-1] == 'A':
        BA += 1
    elif s[0] == 'B':
        start_B += 1
    elif s[-1] == 'A':
        end_A += 1
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'B':
            ans += 1
ans += min(start_B, end_A)
if BA > 0:
    ans += BA - 1
if (start_B > 0 or end_A > 0) and BA > 0:
    ans += 1
print(ans)


Measured memory_bytes: 3064
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int h,w;
bool bo[410][410];
char mp[410][410];
int bcount,wcount;
void dfs(P p) {
    int flag=(mp[p.first][p.second]=='#'?0:1);
    bo[p.first][p.second]=true;
    // flag==0?bcount++:wcount++;
    rep(i, 4) {
        int x =p.first+dx[i],y=p.second+dy[i];
        if(x<0||x>=h||y<0||y>=w) continue;
        if(mp[x][y]==mp[p.first][p.second]) continue;
        if(bo[x][y])continue;
        bo[x][y]=true;
        flag==0?wcount++:bcount++;
        // cout << "(x,y)=(" << x << "," << y << ")" << endl;
        dfs({x,y});
    }
}
signed main() {
    cin >> h >> w;
    queue<P> que;
    rep(i, h) {
        rep(j, w) {
            cin >> mp[i][j];
            if(mp[i][j]=='#') {
                que.push({i,j});
            }
        }
    }
    int ans = 0;
    while(!que.empty()) {
        P p = que.front();que.pop();
        if(bo[p.first][p.second]) continue;
        bcount=1,wcount=0;
        dfs(p);
        ans+=bcount*wcount;
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(VI::iterator it=(v).begin();it!=(v).end();++it)
#define IN(v) std::cin>>(v)
#define OUT(v) cout<<v<<endl
#define DEBUG(var) std::cerr<<var<<std::endl

bool isprime(int n) {
  for (int i = 3; i * i <= n; ++i) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<int> v;
  for (int i = 11; i <= 55555 && v.size() < N; i += 10) {
    if (isprime(i))
      v.PB(i);
  }
  REP(i, N-1)
    cout << v[i] << " ";
  cout << v[N-1];

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long int Max = -1000000;
    long int Min = 1000000;
    long int Sum = 0;
    int tmp;
    for (int i = 0; i < n; i++) 
    {
        cin >> tmp;
        Sum += tmp;
        if (tmp > Max)
        {
            Max = tmp;
        }
        if (tmp < Min)
        {
            Min = tmp;
        }
    }

    std::cout << Min << ' ' << Max << ' ' << Sum <<endl;
    return 0;
}




Measured memory_bytes: 3104
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
typedef long long int ll;
int main() {
    int r,c,k;
    scanf("%d %d %d",&r,&c,&k);
    if (r>c*k) printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1648
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, c = ns()
    l = 10 ** 5
    table = [[0 for _ in range(l + 1)] for __ in range(c)]

    for _ in range(n):
        s, t, ci = ns()
        ci -= 1
        table[ci][s] += 1
        table[ci][t] -= 1

    ans = 0
    tmp = 0
    for i in range(l + 1):
        fin = 0
        for j in range(c):
            if table[j][i] > 0:
                tmp += table[j][i]
            else:
                fin += table[j][i]
        ans = max(ans, tmp)
        tmp += fin
    print(ans)


if __name__ == '__main__':
    main()


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

array = [int(i) for i in input().split()]
calc_array = []

cnt = 0

for n in array:
    if n < 0:
        cnt += 1
    calc_array.append(abs(n))
        
if cnt % 2 == 0 or 0 in calc_array:
    output = sum(calc_array)
else :
    output = sum(calc_array) - (2*min(calc_array))
    
print(output)

Measured memory_bytes: 19852
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
before = sum(a)
for i in range(n):
    if(a[i] >= b[i]):
        a[i] -= b[i]
    else:
        b[i] -= a[i]
        a[i] = 0
        a[i+1] = max(0, a[i+1] - b[i])
after = sum(a)
print(before - after)

Measured memory_bytes: 19156