akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try {
			Scanner scanner = new Scanner(System.in);
			int k = scanner.nextInt();
			int x = scanner.nextInt();

			Main testB = new Main();
			ArrayList<Integer> answer = testB.oneClue(k, x);
			for (int i = 0; i < answer.size(); i++) {
				System.out.print(answer.get(i)+ " ");
			}
			scanner.close();

		} catch (InputMismatchException e) {
			// TODO: handle exception
			System.out.println("整数を入力してください");
		}
	}


	public ArrayList<Integer> oneClue(int k, int x) {
		ArrayList<Integer> answer = new ArrayList<>();
		for(int i = x-k+1; i <= x+k-1; i++) {
			if(i >= -1000000 && i <= 1000000) {
				answer.add(i);
			}
		}

		return answer;
	}

}



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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<vector<P>> edges(200010);
vector<ll> dist;

void dfs(int i,int p) {
    for (P j : edges[i]) if (j.first != p) {
        dist[j.first] = dist[i]+j.second;
        dfs(j.first,i);
    }
}

int main() {
    int n;
    cin >> n;
    edges.resize(n);
    dist.resize(n,1LL<<50);
    for (int i = 0;i < n-1;++i) {
        int u,v,w;
        cin >> u >> v >> w;
        u--;v--;
        edges[u].push_back(P(v,w));
        edges[v].push_back(P(u,w));
    }
    int q,k;
    cin >> q >> k;
    k--;
    dist[k] = 0;
    dfs(k,-1);
    for (int i = 0;i < q;++i)  {
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << dist[x]+dist[y] << "\n";
    }
    return 0;
}

Measured memory_bytes: 15104
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 41;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	map<int, int> m;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		m[str[0]]++;
	}
	vector<int> v;
	for (auto &p : m)
	{
		v.push_back(p.second);
	}
	int ans = 0;
	while (!v.empty())
	{
		sort(v.rbegin(), v.rend());
		while (!v.empty() && v.back() == 0) v.pop_back();
		if (v.size() < k) break;
		for (int i = 0; i < k; i++) v[i] --;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var HW = Sarray();
            var H = HW[0];
            var W = HW[1];
            var Sij = new string[H];
            for (var i = 0; i < H; ++i)
                Sij[i] = ReadLine();
            var dp = new long[W];

            for (var w = 1; w < W; ++w)
            {
                dp[w] = dp[w - 1];
                if (Sij[0][w - 1] != Sij[0][w]) 
                    ++dp[w];
            }
            for (var h = 1; h < H; ++h)
            {
                if (Sij[h - 1][0] != Sij[h][0])
                    ++dp[0];
                for (var w = 1; w < W; ++w)
                {
                    var row = dp[w - 1];
                    if (Sij[h][w - 1] != Sij[h][w])
                        ++row;
                    var col = dp[w];
                    if (Sij[h - 1][w] != Sij[h][w])
                        ++col;
                    dp[w] = Min(row, col);
                }
            }
            var ans = dp[W - 1];
            if (Sij[0][0] == '#') ++ans;
            if (Sij[(int)H - 1][(int)W - 1] == '#') ++ans;
            WriteLine(ans / 2);
            //Out.Flush();
        }
    }
}

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

const double EPS = 1e-10;

typedef complex<double> Point;
#define X real()
#define Y imag()

struct Segment {
  Point p1, p2;
  Segment(){};
  Segment(Point p1, Point p2) : p1(p1), p2(p2) {};
};
typedef Segment Line;

// 内積
double dot(Point a, Point b){return real(conj(a) * b);}

// 射影
Point project(Line l, Point p) {
  double r = dot(p - l.p1, l.p2 - l.p1) / norm(l.p2 -l.p1);
  return l.p1 + (l.p2 - l.p1) * r;
}

int main() {
  int x1,y1,x2,y2,q,xp,yp;
  cin>>x1>>y1>>x2>>y2>>q;
  Line l(Point(x1,y1), Point(x2,y2));
  for(int i=0;i<q;++i){
    cin>>xp>>yp;
    Point p(xp,yp);
    printf("%.8f %.8f\n", project(l,p).X, project(l,p).Y);
  }
  return 0;
}



Measured memory_bytes: 3288
S=input()
l=int(len(S))
k=0
p=[0]*10
for i in range(l):
    if S[i]=="A" or S[i]=="G" or S[i]=="C" or S[i]=="T" :
        k+=1
        p[i]=k
    else:
        k=0
        p[i]=k
ans=max(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9])
print(ans)


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();

            if (n < 10) {
                out.println(n);
                return;
            }

            int cnt = 0;
            long t = n;
            for (int i = 0; i < 10000; i++) {
                t /= 10;
                if (t == 0) break;
                cnt++;
            }

            long p = 1;
            for (int i = 0; i < cnt; i++) {
                p *= 10;
            }

            out.println(9 * cnt + (n + 1) / p - 1);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <algorithm> 
#include <cmath> 
using namespace std;
int main(){
	char in[120];
	pair<pair<string,int>,int> p[110];
	int a;
	cin >> a;
	for(int i=0;i<a;i++){
		int t;
		cin >> in >> t;
		string tmp=in;
		p[i]=make_pair(make_pair(in,-t),i);
	}
	sort(p,p+a);
	for(int i=0;i<a;i++)printf("%d\n",p[i].second+1);
}


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

int main()
{
  char c;
  cin >> c;
  if (c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> a(N), b(N), c(N), res(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vector<int> cnt(100 + 1);
	for (int i = 0; i < N; i++) {
		cnt[a[i]]++;
	}
	for (int i = 0; i < N; i++) {
		if (cnt[a[i]] == 1) {
			res[i] += a[i];
		}
	}
	cnt.assign(100 + 1, 0);
	for (int i = 0; i < N; i++) {
		cnt[b[i]]++;
	}
	for (int i = 0; i < N; i++) {
		if (cnt[b[i]] == 1) {
			res[i] += b[i];
		}
	}
	cnt.assign(100 + 1, 0);
	for (int i = 0; i < N; i++) {
		cnt[c[i]]++;
	}
	for (int i = 0; i < N; i++) {
		if (cnt[c[i]] == 1) {
			res[i] += c[i];
		}
	}
	for (int i = 0; i < N; i++) {
		cout << res[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

//Main
public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		char[] line=sc.next().toCharArray();
		int sum=0;
		for (char c:line)		
		{ 
			sum+=c-'0';
		}
		
		System.out.println(sum%9==0?"Yes":"No");

	}

	static final Random random = new Random();

	static void ruffleSort(int[] a) {
		int n = a.length;//shuffle, then sort 
		for (int i = 0; i < n; i++) {
			int oi = random.nextInt(n), temp = a[oi];
			a[oi] = a[i];
			a[i] = temp;
		}
		Arrays.sort(a);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

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

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

}


Measured memory_bytes: 36764
#include <iostream>
#include <algorithm>
#include <map>
#include <regex>
#include <string>
#include <cstdlib>
#include <math.h>
using namespace std;
bool is_prime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main() {
  int X;
  cin >> X;
  while (true) {
      if (is_prime(X)) {
          cout << X << endl;
          return 0;
      }
      X++;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <time.h>

#define all(dat)      dat.begin(), dat.end()
#define rep(num)      for (int _ = 0; _ < num; _++)
#define loop(i, num)  for (int i = 0; i < num; i++)

using namespace std;

int n;

char ask(int pos) {
    
    char res[100];
    
    printf("%d\n", pos);
    
    fflush(stdout);
    
    scanf("%s", res);
    
    return res[0];
    
}

int main() {
    
    scanf("%d", &n);
    
    int l = 0, r = n - 1, mid;
    
    char s1 = ask(l);
    
    if (s1 == 'V')  return 0;
    
    char s2 = ask(r);
    
    if (s2 == 'V')  return 0;
    
    while (l < r) {
        
        mid = (l + r) / 2;
        
        char s3 = ask(mid);
        
        if (s3 == 'V')  return 0;
        
        if ((s1 == s3 && (mid - l) % 2 != 0) || (s1 != s3 && (mid - l) % 2 == 0) || (s2 == s3 && (r - mid) % 2 == 0) || (s2 != s3 && (r - mid) % 2 != 0)) {
            
            r = mid;
            
            s2 = s3;
            
        } else {
            
            l = mid;
            
            s1 = s3;
            
        }
        
    }
    
    return 0;
    
}


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

int a[100005];
int c[2];
int main()
{
    int n;

    cin >> n;

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

    sort(a+1 , a+n+1);

    int j = 0;

    for(int i = n ; i>=2 ; )
    {
        if(a[i]==a[i-1])
        {
            c[j++] = a[i];
            i--;
            if(j==2)
            {
                break;
            }
        }
        i--;
    }
    cout << 1ll*c[0]*c[1];
    return 0;
}


Measured memory_bytes: 640
/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define IO cin.tie(0),cout.tie(0)
#define ISWS ios::sync_with_stdio(0)
typedef long long Long;
void FastIO(){ISWS;IO;}

const int N = 1e8;

int main()
{
  FastIO();
  int tc, ca = 0;
  int d;
  cin >> d;
  int n = 0;
  int ans = 0;
  bool found = false;
  for (int i = 0;i < N;i++){
    n = ((n*10)+7) % d;
    if (n==0){
      found = true;
      break;
    }
    ans++;
  }
  //cout << n << '\n';
  if (!found)ans = -1;
  else ans++;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3664
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<int,ll>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 2003;
const ll lmod = 1e9+7;

int a[MAX_N];

int main(){
  int N,Z,W;
  cin >> N >> Z >> W ;
  rep(i,N) scanf("%d",a+i);
  if(N>1){
    int s[2];
    s[0] = abs(a[N-1]-W);
    s[1] = abs(a[N-2]-a[N-1]);
    cout << max(s[0],s[1]) << endl;
  }else{
    cout << abs(a[0]-W) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
S = [c for c in input()]
N = len(S) - 1
s1 = S[:(N-1)//2 + 1]
s2 = S[(N+3)//2:]

rs = list(reversed(S))
rs1 = list(reversed(s1))
rs2 = list(reversed(s2))
if S == rs and s1 == rs1 and s2 == rs2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  
  
  cin >> A >> B;
  
  if (A == 2){
    cout << "No" << endl;
    
  }
  
  else if (B == 2){
    cout << "No" << endl;
  }
    
    else {
      cout << "Yes" << endl;
    }
}
      
    

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  char s[1000];
  scanf("%s",s);
  int count,flag=0;
  for(count=0;s[count]!='\0';count++){
    if(s[count]=='C'){flag=1;}
    if(flag==1&&s[count]=='F'){flag=100;break;}
  }
  if(flag==100){printf("Yes\n");}
  else{printf("No\n");}
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vec;

lli n;
vec rc;
mat dp;

lli solve(lli x,lli y){
    if(x == y) return dp[x][y] = 0;
    if(dp[x][y]) return dp[x][y];
    lli ret = 1ll << 61;
    for(lli i = x;i < y;i++){
        ret = min(ret,solve(x,i) + solve(i+1,y) + rc[i].second*rc[x].first*rc[y].second);
    }
    return dp[x][y] = ret;
}


int main(){
    cin >> n;
    rc = vec(n);
    dp = mat(n,vll(n));
    for(lli i = 0;i < n;i++) cin >> rc[i].first >> rc[i].second;
    cout << solve(0,n-1) << endl;
    return 0;

}

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

int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  int q;
  cin >> q;
  vector<int> t(q);
  for (i = 0; i < q; i++) {
    cin >> t[i];
  }

  int result = 0;
  for (i = 0; i < q; i++) {
    for (j = 0; j < n; j++) {
      if (t[i] == s[j]) {
        result++;
        break;
      }
    }
  }
  cout << result << endl;
  return 0;
}



Measured memory_bytes: 3124
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "a.cpp"

int main() {
  ll x;
  cin >> x;
  cout << 10-x/200 << el;
}


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

int main() {
	int A,B,C;
  	cin >> A >> B >> C;
  
  	if(A == 5 && B == 5 && C == 7) {
    	cout << "YES" << endl;
    }else if(A == 5 && B == 7 && C == 5) {
    	cout << "YES" << endl;
    }else if(A == 7 && B == 5 && C == 5) {
    	cout << "YES" << endl;
    }else {
    	cout << "NO" << endl;
    }
}

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

int main(){
 int a,b,c,d,n;
  cin>>n;
  string s;
  set<string> s1;
  for(int i=1;i<=n;i++){
    cin>>s;
    s1.insert(s);
  }
  cout<<(int)s1.size()<<endl;
  
  return 0;
}


Measured memory_bytes: 19260
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

long long comb(int n, int r) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}

int main(){
    long long n;
    cin >> n;
    map<long long, long long> T;
    for(long long j = 1; j <= n; j++){
        long long num = j;
        for(long long i = 2; i * i <= num; i++){
            if(num % i != 0) continue;

            while(num % i == 0){
                if(T.find(i) == T.end()){
                    T[i] = 1;
                    num /= i;
                }
                else{
                    T[i]++;
                    num /= i;
                }
            }
        }
        if(num != 1 and T.find(num) == T.end()) T[num] = 1;
        else if(num != 1 and T.find(num) != T.end()) T[num]++;
    }

    long long cnt_2 = 0, cnt_4 = 0, cnt_14 = 0, cnt_24 = 0, cnt_74 = 0;
    map<long long, long long>::iterator it;
    for(it = T.begin(); it != T.end(); it++){
        if(it->second >= 2) cnt_2++;
        if(it->second >= 4) cnt_4++;
        if(it->second >=14) cnt_14++;
        if(it->second >= 24) cnt_24++;
        if(it->second >= 74) cnt_74++;
    }

    /*
    printf("cnt_2 %lld cnt_4 %lld cnt_14 %lld cnt_24 %lld\n", cnt_2, cnt_4, cnt_14, cnt_24);

    for(it = T.begin(); it != T.end(); it++){
        cout << it->first << " " << it->second << endl;
    }
    */

    long long ans = 0;

    if(cnt_2 > 2 and cnt_4 >= 2) ans += comb(cnt_2 - 2, 1) * comb(cnt_4, 2);
    if(cnt_2 > 1 and cnt_24 >= 1) ans += comb(cnt_2 - 1, 1) * comb(cnt_24, 1);
    if(cnt_4 > 1 and cnt_14 >= 1) ans += comb(cnt_4 - 1, 1) * comb(cnt_14, 1); 
    
    ans += cnt_74;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
using namespace std;
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	int m = max(a, max(b, c));
	int t = m - a + m - b + m - c;
	if (t % 2 == 1)t += 3;
	printf("%d\n", t / 2);
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

long long N;
int main() {
    std::cin >> N;
    N = std::sqrt(N);
    std::cout << N*N << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int cnt=0,res=0;
    for(int i=0;str[i];i++)
    {
        if(str[i]=='A' || str[i]=='C' || str[i]=='G' || str[i]=='T' )
        {
            cnt++;
            res=max(res,cnt);
        }
        else
              cnt=0;
    }
    cout<<res<<endl;
}


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

using namespace std;

const int MOD = 1e9 + 7;

void add(int &x, int y) {
   x += y;
   if (x >= MOD) x -= MOD;
}

struct FT {
   int N;
   vector<int> tr;
   FT(int N = 0) : N(N), tr(N) {}
   void modify(int x, int v) {
      for (; x < N; x |= (x + 1)) {
         add(tr[x], v);
      }
   }
   int get(int x) {
      int ans = 0;
      for (; x >= 0; x = (x & (x + 1)) - 1) {
         add(ans, tr[x]);
      }
      return ans;
   }
};

int main() {
   ios_base::sync_with_stdio(false);
   int N, M;
   cin >> N >> M;
   vector<int> X(N), Y(M);
   for (int i = 0; i < N; ++i) cin >> X[i];
   for (int i = 0; i < M; ++i) cin >> Y[i];
   vector<int> lid(N), rid(N);
   int ptr = -1;
   for (int i = 0; i < N; ++i) {
      while (ptr + 1 < M && Y[ptr + 1] < X[i]) {
         ptr++;
      }
      lid[i] = ptr;
   }
   ptr = M;
   for (int i = N - 1; i >= 0; --i) {
      while (ptr > 0 && Y[ptr - 1] > X[i]) {
         ptr--;
      }
      rid[i] = ptr;
   }
   vector<int> ls, rs;
   for (int i = 0; i < N; ++i) {
      if (lid[i] == -1 || rid[i] == M) continue;
      ls.emplace_back(X[i] - Y[lid[i]]);
      rs.emplace_back(Y[rid[i]] - X[i]);
   }
   sort(ls.begin(), ls.end());
   ls.resize(unique(ls.begin(), ls.end()) - ls.begin());
   sort(rs.begin(), rs.end());
   rs.resize(unique(rs.begin(), rs.end()) - rs.begin());
   int nl = ls.size();
   int nr = rs.size();
   vector<vector<int>> qs(nl);
   for (int i = 0; i < N; ++i) {
      if (lid[i] == -1 || rid[i] == M) continue;
      int il = lower_bound(ls.begin(), ls.end(), X[i] - Y[lid[i]]) - ls.begin();
      int ir = lower_bound(rs.begin(), rs.end(), Y[rid[i]] - X[i]) - rs.begin();
      qs[il].emplace_back(ir);
   }
   FT ft(nr + 1);
   ft.modify(0, 1);
   for (int i = 0; i < nl; ++i) {
      sort(qs[i].begin(), qs[i].end());
      qs[i].resize(unique(qs[i].begin(), qs[i].end()) - qs[i].begin());
      reverse(qs[i].begin(), qs[i].end());
      for (int j : qs[i]) {
         ft.modify(j + 1, ft.get(j));
      }
   }
   cout << ft.get(nr) << "\n";
   return 0;
}

Measured memory_bytes: 8052
#include<stdio.h>
int main(){
  char n;
  int a,b,j=0,i=0,data[1000];
  while(1){
    scanf("%d %c %d",&a,&n,&b);
    if(n=='?') break;
    if(n=='+'){
      data[i]=a+b;
    }
    if(n=='-'){
      data[i]=a-b;
    }
    if(n=='*'){
      data[i]=a*b;
    }
    if(n=='/'){
      data[i]=a/b;
    }
    i++;
    j++;
  }
  for(i=0;i<j;i++){
    printf("%d\n",data[i]);
  }
  return(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    for (int i = 0; i < S.length() - 8; i++) {
        cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int n,k,m;
long long f[333][333][333];

int main()
{
    scanf("%d%d%d",&n,&k,&m);
    f[0][1][0]=1;
    for(int i=0;i<=n;i++)
        for(int j=1;j<=k;j++)
            for(int p=i;p>=0;p--){
                if(p) (f[i][j][p-1]+=f[i][j][p]) %= m;
                else (f[i][j+1][i]+=f[i][j][p]) %= m;
                (f[i+1][j][p]+=f[i][j][p]*(p+1)) %= m;
            }
    printf("%lld\n",f[n][k+1][n]);
    return 0;
}

Measured memory_bytes: 262272
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s;
int ans;
int ss;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='S')
		{
			ss++;
		}
		else
		{
			if(ss)
			{
				ss--;
				ans++;
			}
		}
	}
	printf("%d",(int)s.size()-2*ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    ll ans{1};
    constexpr ll INF=1e18;
    cin>>n;
    vector<ll> a(n);
    for(auto&i:a){
        cin>>i;
        if(!i) return puts("0"),0;
    }
    fr(i,n){
        if(ans>INF/a[i]) return puts("-1"),0;
        ans*=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3988
using System;

class Program
{
 static void Main(string[] args)
 {
   string[] numStr;
   string cntStr;
   var valN = 0;
   var minNum = 0;
   var maxNum = 0;
   var sum = 0;
   var cnt1 = 0;
   var cnt2 = 0;
   var digit = 0;
   var digitSum =0;
   
   numStr = Console.ReadLine().Split(' ');
   
   valN = int.Parse(numStr[0]);
   minNum = int.Parse(numStr[1]);
   maxNum = int.Parse(numStr[2]);
   
   for( cnt1 = 0; cnt1 <= valN; cnt1++ )
   {
     digitSum = 0;
     cntStr = cnt1.ToString();
     digit = cnt1.ToString().Length;  
     
     for( cnt2 = 0; cnt2 < digit; cnt2++ )
     {
       digitSum += int.Parse(cntStr[cnt2].ToString());
     }
     
     if( ( minNum <= digitSum ) && ( digitSum <= maxNum ) )
     {
       sum += cnt1;
     }
   }
   
   Console.WriteLine(sum);
 }
}

Measured memory_bytes: 13140
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    N, X, Y = lr()
    edges = [[1]]
    for i in range(1, N-1):
        edges.append([i-1, i+1])
    edges.append([N-2])
    edges[X-1].append(Y-1)
    edges[Y-1].append(X-1)
    cnt = [0]*(N-1)
    for i in range(N):
        s = deque([[i, 1]])
        vis = [0]*N
        vis[i] = 1
        while len(s) > 0:
            v, dis = s.popleft()
            for j in edges[v]:
                if not vis[j]:
                    s.append([j, dis+1])
                    vis[j] = 1
                    cnt[dis-1] += 1
    for c in cnt:
        print(c//2)
resolve()

Measured memory_bytes: 47324
K = int(input())
A = list(map(int, input().split()))
min = 2
max = 2
for i in range(K-1, -1, -1):
    min += (-min) % A[i]
    max -= max % A[i]
    max += A[i] - 1
if max < min:
  print(-1)
  exit()
print(min, max)


Measured memory_bytes: 14224
k,n = map(int, input().split())
lst = list(map(int, input().split()))

maxDis = (k-lst[-1]) + lst[0]
for i in range(n-1):
  if lst[i+1] - lst[i] > maxDis:
    maxDis = lst[i+1] - lst[i]
print(k-maxDis)

Measured memory_bytes: 26436
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<





int main(void){
	int N, M;
    cin >> N >> M;
    vector<int> p;
    vector<string> S;
    int W[N];
    ll ans1 = 0;
    ll ans2 = 0;
    rep(i,N){
        W[i] = 0;
    }
    rep(i,M){
        int a;
        string b;
        cin >> a >> b;

        if(W[a-1] >= 0){
            if(b == "WA"){
                W[a-1] ++;  
            }else{
                ans1 ++;
                ans2 += W[a-1];
                W[a-1] = -1;
            }
        }
        
        p.PB(a);
        S.PB(b);
        
    }

    cout << ans1 SP ans2 << endl;



    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<string>> JUDGES(N);
    rep(i, M) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        JUDGES[p].push_back(s);
    }
    
    int AC = 0;
    int WA = 0;

    for(auto jds: JUDGES) {
        int wacnt = 0;
        for(string jd: jds) {
            if(jd == "AC") {
                ++AC;
                break;
            }
            else {
                ++wacnt;
            }
        }
        if(wacnt==jds.size()) {
            continue;
        }
        else {
            WA += wacnt;
        }
    }

    cout << AC << " " << WA << endl;

    return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    int cnt = 0;
    for(int n = a; n <= b; n++){
        if(n/10000 == n%10 && n/1000 - (n/10000)*10 == (n/10)%10){
            cnt ++;
        }
    }
    cout << cnt << endl;
}

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

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

using namespace std;

typedef long long int lli;

int main () {
    lli Q, H, S, D;
    cin >> Q >> H >> S >> D;
    lli N;
    cin >> N;
    lli m = min({Q * 4, H * 2, S});
    lli M = min(m * 2, D);
    if (N % 2) {
        cout << N / 2 * M + m << endl;
    } else {
        cout << N / 2 * M << endl;
    }
    return 0;
}


Measured memory_bytes: 764
import Foundation


func readStr() -> String {
  return readLine()!
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readTwoInts() -> (a: Int, b: Int) {
    let ints = readLine()!.split(separator: " ").map { Int($0)! }
    return (a: ints[0], b: ints[1])
}

print(readStr().map { Int(String($0))! }.reduce(0) { $0 + $1 } % 9 == 0 ? "Yes" : "No")


Measured memory_bytes: 14044
a, b, c, d = list(map(int, input().split()))
def gcd(x, y):
    if x == 0:
        return y
    else:
        return gcd(y%x, x)
def lcm(x,y):
    return x * y // gcd(x,y)
def f(n, x):
    return n // x
result = f(b,c) + f(b,d) - f(a-1,c) - f(a-1,d) -f(b,lcm(c,d)) + f(a-1,lcm(c,d))
print(b-a+1-result)

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define fi first
#define sec second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)
#define all(v)          v.begin(),v.end()
void fast(){ ios::sync_with_stdio(false); cin.tie(NULL);}
void file()
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);
    #endif
}

int temp,n,k,j;
set<int> s;
bool ok;

int main()
{
    fast();
    

    cin>>n>>k;
    for(int i=0;i<k;i++)
        cin>>temp,s.insert(temp);
    for(int i=n;i<100000;i++)
    {
        j=i;
        ok = 1;
        while (j) 
        {
            temp = j % 10;
            if (s.count(temp)) 
            {
                ok = 0;
                break;
            }
            j/=10;
        }
        if(ok)
        {
            cout<<i;
            break;
        }
    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int n;
	string s;
	cin >> n >> s;
	int max = 0;
	int sum = 0;
	for(int i = 0; i<n; i++)
	{
		if(s[i] == 'I'){
			sum++;
			if(sum > max){
				max= sum;
			}
		}
		else{
			sum--;
		}
	}
	cout << max;
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++)
    cin >> v.at(i);
  sort(v.begin(), v.end());
  double out = (v.at(0) + v.at(1)) / 2.0;
  for(int i = 2; i < n; i++)
    out = (out + v.at(i)) / 2;
  cout << setprecision(10) << out << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int k, s, cnt = 0;
int main()
{
    cin >> k;
    cin >> s;
    for (int i = 0; i <= k; i++){
        for (int j = 0; j <= k; j++){
            if (((s - i - j) <= k) && (s - i - j) >= 0){
                cnt ++;
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3116
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var N = ReadInt();
            var S = Read();
            YesOrNo(N % 2 == 0 && S.Slice(0, N / 2) == S.Slice(N / 2));
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll K, N; cin >> K >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll res = 0;
  REP(i, N - 1) {
    ll tmp = A[i + 1] - A[i];
    if(res < tmp) res = tmp;
  }
  ll tmp2 = (K - A[N - 1]) + A[0];
  if(res < tmp2) res = tmp2;
  cout << K - res << endl;
}

Measured memory_bytes: 4820
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int q[10][10] = {};
int dx[]= {0, 1, 0, -1, 0, 1, 1, -1, -1, 2, 0, -2, 0}, dy[] = {0, 0, 1, 0, -1, 1, -1, 1, -1, 0, 2, 0, -2};

bool is_in_field(int x, int y){
  return ((x >= 0 && x <= 9) && (y >= 0 && y <= 9));
}

void mark( int x, int y, int size,  int i) {
  
  if(is_in_field(x + dx[i], y + dy[i])) {
    q[x + dx[i]][y + dy[i]]++;
  }
  if(i != (size) * 4) mark(x, y, size, i + 1);
}


int main(){
  int x, y, size, max = 0, count = 0;
  while(~scanf("%d,%d,%d", &x, &y, &size)) {
    mark(x, y, size, 0);
  }
  for(x = 0; x < 10; x++)
    for(y = 0; y < 10; y++) {
      if(q[x][y] == 0) count++;
      else if(q[x][y] > max) max = q[x][y];
    }
  cout << count << endl << max <<endl;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	set<string>coll;
	while(n--)
	{
		string s;
		cin>>s;
		coll.insert(s);
	}
	int ans=coll.size();
	cout<<ans;
	return 0;
	
}

Measured memory_bytes: 19192
while True:
    num_lis = input().split()
    if num_lis[1] == '+':
        print(int(num_lis[0]) + int(num_lis[2]))
    elif num_lis[1] == '-':
        print(int(num_lis[0]) - int(num_lis[2]))
    elif num_lis[1] == '*':
        print(int(num_lis[0]) * int(num_lis[2]))
    elif num_lis[1] == '/':
        print(int(num_lis[0]) // int(num_lis[2]))
    else:
        break
        


Measured memory_bytes: 5596
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = input()
    if '7' in n:
        print('Yes')
    else:
        print('No')
if __name__ =='__main__':
    main()   


Measured memory_bytes: 8932
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>
 
using namespace std;

int main(){
    long n;cin>>n;
    vector<string>s;

    long count=0;


    for(int i=0;i<n;i++){
        string kp;
        cin>>kp;
        s.push_back(kp);
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<s[i].size();j++){
            if(s[i][j]=='A'){
                // j++;
                if(s[i][j+1]=='B')count++;
            }
        }
    }
    // cout<<count<<endl;

    long ab=0;
    long beginB=0;
    long endA=0;

    for(int i=0;i<n;i++){
        if(s[i].front()=='B'&&s[i].back()=='A')ab++;
        else if(s[i].front()=='B')beginB++;
        else if(s[i].back()=='A')endA++;
    }
    // cout<<beginB<<" "<<endA<<" "<<ab;
    if(ab==0)cout<<count+min(beginB,endA);
    else if(endA!=0||beginB!=0)cout<<count+ab+min(beginB,endA);
    else cout<<count+ab-1;
    cout<<endl;
}

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

bool is_prime(int x){
  if(x<=1) return false;
  for(int i=2;i*i<=x;i++)
    if(x%i==0) return false;
  return true;
}

signed main(){
  int x;
  cin>>x;

  int p=x;
  while(!is_prime(p)) p++;

  cout<<p<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); i++)
int main(){
  cin.tie(nullptr);
  ll n;
  cin>>n;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  ll cnt=0;
  for(ll i=0;i<n;i++){
    ll x = (ll)(lower_bound(a.begin(),a.end(),b[i])-a.begin());
    ll y = (ll)(c.end()-upper_bound(c.begin(),c.end(),b[i]));
    cnt+=x*y;
  }
  cout<<cnt<<endl;


}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

void dfs(int N, string& S) {
    if (N == (int)S.size()) {
        cout << S << endl;
        return;
    }
    set<char> cnt;
    for (auto& c : S) {
        cnt.insert(c);
    }
    for (auto& c : cnt) {
        S += c;
        dfs(N, S);
        S.pop_back();
    }
    S += *cnt.rbegin() + 1;
    dfs(N, S);
    S.pop_back();
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S = "a";
    dfs(N, S);
    return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;

class Pg
{
    static void Main()
    {
        string line;
        var sum = new List<int>();
        var ave = new List<int>();
        while ((line=Console.ReadLine())!=null)
        {
            var a = line.Split(',').Select(int.Parse).ToArray();
            sum.Add(a[0]*a[1]);
            ave.Add(a[1]);
        }
        Console.WriteLine("{0}\n{1:f0}",sum.Sum(),ave.Average());
    }
}


Measured memory_bytes: 18464
import java.util.Scanner;
import java.util.*;

public class Main{
    public static void main(String[] args){
        ArrayList<Integer> list =new ArrayList<Integer>();
        Scanner sc = new Scanner(System.in);
        int a= sc.nextInt();
        int b=a;
        for(int i=2;i<b/2;i++){
            while(a%i==0){
                list.add(i);
                a/=i;
            }
        }
        System.out.print(b+": ");
        if(list.isEmpty()) System.out.print(b);
        else{
       for(int i=0;i<list.size();i++){
           if(i==list.size()-1) System.out.print(list.get(i));
           else System.out.print(list.get(i)+" ");
       }
    }
        System.out.println();
        }
    }


Measured memory_bytes: 26748
def main():

    n = int(input())
    a_list = [list(map(int, input().split())) for _ in [0]*n]
    abc = []
    for i in range(n):
        for j in range(i+1, n):
            if a_list[i][j] > -1:
                abc.append((i, j, a_list[i][j]))

    def Kruskal(n, abc, weight=True):
        class unionfind():
            # size:要素数,tree：unionfind木
            def __init__(self, size):  # self,要素数
                self.size = size
                self.tree_root = list(range(self.size))
                self.tree_depth = [1]*self.size

            # rootを探す
            def root(self, index):
                temp_list = []
                temp = self.tree_root[index]
                while index != temp:
                    temp_list.append(index)
                    index = temp
                    temp = self.tree_root[index]
                for i in temp_list:
                    self.tree_root[i] = index
                return index

            # 結合
            def unite(self, index1, index2):
                r1 = self.root(index1)
                r2 = self.root(index2)
                if r1 != r2:
                    d1, d2 = self.tree_depth[r1], self.tree_depth[r2]
                    if d1 <= d2:
                        self.tree_root[r1] = r2
                        self.tree_depth[r2] = max(d1+1, d2)
                    else:
                        self.tree_root[r2] = r1
                        self.tree_depth[r1] = max(d2+1, d1)

            # 同じか判定
            def same(self, index1, index2):
                r1 = self.root(index1)
                r2 = self.root(index2)
                return r1 == r2

        uf = unionfind(n)
        ret = 0
        if weight:
            abc.sort(key=lambda x: x[2])
        for a, b, c in abc:
            if not uf.same(a, b):
                ret += c
                uf.unite(a, b)
        return ret

    print(Kruskal(n, abc))


main()


Measured memory_bytes: 6260