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

int main() {
  string orig;
  int n;
  cin >> orig >> n;
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    string str;
    cin >> str;
    bool endit, endis = false;
    for(int is = 0; is < 10 && !endis; ++is, endit = false) for(int it = 0; it < orig.size() && !endit; ++it) {
      if(orig[it] != str[(is + it) % str.size()]) {
        endit = true;
      } else if(it == orig.size() - 1) {
        ++ans;
        endit = endis = true;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1208
n,m = map(int, input().split())
x = sorted(list(map(int, input().split())))

if n >= m:
  print(0)
  exit()

nums = [0]*(m-1)
for i in range(m-1): nums[i] = x[i+1] - x[i]
nums = sorted(nums)
print(sum(nums[:m-1-(n-1)]))

Measured memory_bytes: 20364
#include <iostream>
using namespace std;
int main(void)
{
    int N, H[20], sum = 1;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    for (int i = 1; i < N; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if (H[j] > H[i])
            {
                break;
            }
            if (j == i - 1)
            {
                sum++;
            }
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,x,y;
vi a,b;

int main(){
	cin>>n>>m>>x>>y;
	a=vi(n);b=vi(m);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	bool B=0;
	for(int i=x+1;i<=y;i++){
		bool flag=1;
		for(int j=0;j<n;j++) if(a[j]>=i) flag=0;
		for(int j=0;j<m;j++) if(b[j]<i) flag=0;
		B|=flag;
	}
	cout<<(B?"No War":"War")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int quelim = 20;
bool query(int k) {
    if (quelim-- <= 0) exit(0);
    string s;
    cout << k << endl;
    cin >> s;
    if (s == "Vacant") exit(0);
    if (s == "Male") return false;
    if (s == "Female") return true;
}
int main() {
    int n;
    cin >> n;
    vector<int> seat(n, -1);
    int l = 0, r = n - 1;
    seat[0] = query(0);
    while (r - l + 1 > quelim && l + 1 < r) {
        bool a, b;
        int m = (l + r) / 2, lsiz = m - l + 1;
        a = (seat[l]);
        if (seat[m] < 0) seat[m] = query(m);
        b = (seat[m]);
        if (((lsiz & 1) && a == b) || (!(lsiz & 1) && a != b))
            l = m;
        else
            r = m;
    }
    for (int i = l; i <= r; ++i) {
        if (seat[i] < 0) seat[i] = query(i);
    }
    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int N;
vector<ll> A;

void solve() {
    vector<ll> p, m;
    rep(i, N) {
        if (A[i] >= 0) p.pb(A[i]);
        else m.pb(A[i]);
    }
    sort(rall(p));
    sort(all(m));
    if (m.empty()) m.pb(p.back()), p.pop_back();
    if (p.empty()) p.pb(m.back()), m.pop_back();

    vector<pair<ll, ll>> res;
    ll cur = m[0];
    rep(i, p.size()-1) {
        res.pb({cur, p[i]});
        cur -= p[i];
    }
    res.pb({p.back(), cur});
    cur = p.back() - cur;

    REP(i, 1, m.size()) {
        res.pb({cur, m[i]});
        cur -= m[i];
    }

    cout << cur << endl;
    for (pair<ll, ll> x : res) {
        cout << x.fi << ' ' << x.se << endl;
    }
}

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

    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];
    solve();
    return 0;
}


Measured memory_bytes: 6000
#include <bits/stdc++.h>
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 FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int n;
int maze[505][505];
int d[505][505];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void bfs(int sx, int sy){
	queue<PII> q;
	d[sx][sy]--;
	q.push(MP(sx,sy));
	while(q.size()){
		PII p=q.front(); q.pop();
		rep(i,4){
			int nx=p.first+dx[i], ny=p.second+dy[i];
			if(0<=nx&&nx<n&&0<=ny&&ny<n){
				if(maze[nx][ny]){
					if(d[nx][ny]>d[p.first][p.second]+1){
						d[nx][ny]=d[p.first][p.second]+1; q.push(MP(nx,ny));
					}
				}else{
					if(d[nx][ny]>d[p.first][p.second]){
						d[nx][ny]=d[p.first][p.second]; q.push(MP(nx,ny));
					}
				}
			}
		}
	}
}


signed main(){
	cin>>n;
	int ans=0;
	rep(i,n)rep(j,n) d[i][j]=min(min(i,n-1-i),min(j,n-j-1))+1,maze[i][j]=1;
	rep(i,n*n){
		int p; cin>>p; p--;
		int sx=p/n, sy=p%n;
		ans+=d[sx][sy]-1;
		maze[sx][sy]--;
		bfs(sx,sy);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 5648
package main

import (
	"fmt"
	"sort"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	nums := []string{}
	for i := 1; i <= n; i++ {
		nums = append(nums, strconv.Itoa(i))
	}

	all := perms(nums)
	sort.Strings(all)

	ps := scanStringSlice(n)
	qs := scanStringSlice(n)

	p := strings.Join(ps, "")
	q := strings.Join(qs, "")

	a := sort.SearchStrings(all, p) + 1
	b := sort.SearchStrings(all, q) + 1

	if a > b {
		fmt.Printf("%d\n", a-b)
	} else {
		fmt.Printf("%d\n", b-a)
	}

}

func perms(unused []string) []string {

	if len(unused) <= 1 {
		return unused
	}

	res := []string{}
	for _, h := range unused {
		us := []string{}
		for _, s := range unused {
			if s != h {
				us = append(us, s)
			}
		}
		pfs := perms(us)
		for _, pf := range pfs {
			res = append(res, h+pf)
		}
	}

	return res
}

func scanStringSlice(size int) []string {
	input := []string{}
	for i := 0; i < size; i++ {
		var in string
		fmt.Scanf("%s", &in)
		input = append(input, in)
	}
	return input
}


Measured memory_bytes: 6656
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


//ABC124_b
int main() {
	int n;
	cin >> n;
	int A[110];
	rep(i, n) cin >> A[i];

	int cnt = 0;
	int mx = 0;
	rep(i, n) {
		if (A[i] >= mx) cnt++;
		mx = max(mx, A[i]);
	}
	cout << cnt << endl;
}

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

using namespace std;

#define int long long

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

    queue<int> q;
    for(int i = 1; i < 10; i++) q.push(i);

    int cnt = 1;
    while(cnt < k) {
        int x = q.front();
        q.pop();
        if(x % 10 != 0) q.push(10 * x + (x % 10) - 1);
        q.push(10 * x + (x % 10));
        if(x % 10 != 9) q.push(10 * x + (x % 10) + 1);
        cnt++;
    }

    cout << q.front() << endl;
    return 0;
}

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

int main() {
    int  T;
    cin >> T;

    int evenNumber =0;
    int oddNumber = 0;
    
    for (int i = 1; i <= T; i++)
    {
        if (i%2 ==0)
            evenNumber+=1;
        else
            oddNumber+=1;
    }
    
    cout << oddNumber*evenNumber;
    return 0;
}

Measured memory_bytes: 256
s = list(input())

ans1 = 0
ans2 = 0
for i in range(len(s)):
    if i%2 == 0 and s[i] == '0':
        ans1 += 1
    elif i%2 == 1 and s[i] == '1':
        ans1 += 1
    
    if i%2 == 0 and s[i] == '1':
        ans2 += 1
    elif i%2 == 1 and s[i] == '0':
        ans2 += 1

print(min(ans1, ans2))

Measured memory_bytes: 3956
import bisect
from collections import deque
N=int(input())
a=deque([int(input())])
for _ in range(N-1):
  num=int(input())
  if num<=a[0]:
    a.appendleft(num)
  else:
    a[bisect.bisect_left(a, num)-1]=num
print(len(a))


Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
void solve() 
{
    string s,t;cin>>s>>t;
    vector<vector<int>>dp(3030,vector<int>(3030,0));
    rep(i,1,s.size()+1)rep(j,1,t.size()+1)s[i-1]==t[j-1]?dp[i][j]=dp[i-1][j-1]+1:dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
    stack<char>ans;
    int ss=s.size(),ts=t.size();
    while(ss!=0&&ts!=0){
        if(s[ss-1]==t[ts-1]){
            ans.push(s[ss-1]);
            ss--;ts--;
        }else dp[ss-1][ts]>=dp[ss][ts-1]?ss--:ts--;
    }
    while(!ans.empty()){cout<<ans.top();ans.pop();}cout<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 36352
import sys

n, m = map(int, sys.stdin.readline().rstrip().split())
sc = [sys.stdin.readline().rstrip().split() for i in range(m)]
if n > 1:
    ans = ['1'] + ['0'] * (n - 1)
else:
    ans = ['0']
tmp = [0] * n
for sci in sc:
    s, c = sci
    if n > 1 and s == '1' and c == '0':
        print(-1)
        sys.exit()
    if tmp[int(s) - 1] > 0 and ans[int(s)-1] != c:
        print(-1)
        sys.exit()
    ans[int(s)-1] = c
    tmp[int(s) - 1] += 1
# print(ans)
print(''.join(ans))

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

int main() {
  int A, B;
  cin >> A >> B;
  string S; cin >> S;
  
  bool found = 0;
  bool haihun = 0;
  if(S.at(A)=='-') haihun = 1;
  //cout << "haihun: " << haihun << endl;
  for(int i=0;i<A;i++){
    if(S.at(i) == '-'){
      found = true;
      break;
    }
  }
  for(int i=A+1;i<S.size();i++){
    if(S.at(i) == '-'){
      found = true;
      break;
    }
  }
  
  if(haihun && !found) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int n; cin >> n;

	vector <int> p(n);

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

	int maxim = p[0], cnt = 1;

	for(int i = 1; i < n; i++){
		if(p[i] < maxim){
			cnt++;
		}
		maxim = min(maxim, p[i]);
	}


	cout << cnt << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 1792
# https://atcoder.jp/contests/abc161/tasks/abc161_d

import sys
# sys.setrecursionlimit(100000)
import heapq


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = int(input())
    if n < 10:
        print(n)
        return
    cnt = 0
    hq = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    while cnt < n:
        i = heapq.heappop(hq)
        cnt += 1
        if cnt == n:
            print(i)
            return
        r = int(str(i)[::-1][0])
        heapq.heappush(hq, int(str(i) + str(r)))
        if r != 9:
            heapq.heappush(hq, int(str(i) + str(r + 1)))
        if r != 0:
            heapq.heappush(hq, int(str(i) + str(r - 1)))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 87032
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<double, double> P;

int dfs(int u, int prev, int *cnt, int *prenum, int *lowest, vector< vector<int> > &v, vector<P> &res){
  prenum[u] = lowest[u] = ++(*cnt);
  REP(i, v[u].size()){
    int next = v[u][i];
    if(prenum[next] == -1){
      lowest[u] = min(lowest[u], dfs(next, u, cnt, prenum, lowest, v, res));
      if(lowest[next] == prenum[next]) res.push_back(P(min(u, next), max(u, next)));
    }
    else if(prev != next)
      lowest[u] = min(lowest[u], lowest[next]);
  }
  return lowest[u];
}

vector<P> articulation_points(int V, int E, vector< vector<int> > &v){
  int prenum[V], lowest[V];
  memset(prenum, -1, sizeof(prenum));
  int tmp = 1;
  vector<P> res;
  dfs(0, -1, &tmp, prenum, lowest, v, res);
  return res;
}

int main() {
  int V, E; cin >>V >>E;
  vector< vector<int> > es(V);
  REP(i, E){
    int f, t; cin >>f >>t;
    es[f].push_back(t);
    es[t].push_back(f);
  }
  vector<P> ans = articulation_points(V, E, es);
  SORT(ans);
  REP(i, ans.size()) cout <<ans[i].first <<" " <<ans[i].second <<endl;
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<sstream>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<pair<ll,ll>,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
#define rs resize
int main()
{
   std::ios::sync_with_stdio(false);
   ll n,i,ans=LLONG_MAX;
   cin>>n;
   ll a[n];
   rep(i,0,n)
   { cin>>a[i];
     if(i>0)
      a[i]+=a[i-1];
   }
   rep(i,0,n-1)
    ans = min(ans,llabs(a[n-1] - a[i] - a[i]));
   cout<<ans;
   return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

int main(){
	int n;
	cin>>n;
	int a[n];
	REP(i,n)cin>>a[i];
	sort(a,a+n,greater<int>());
	int res=0;
	for(int i=0;i<n;i++){
		if(i%2==0)res+=a[i];
		else res-=a[i];
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
double dp[10][1<<9][350];
int A[10];int B[10];
double eps=1e-9;
int main(){
	int T;scanf("%d",&T);
	while(T--){
		for(int i=0;i<9;i++)scanf("%d",A+i);
		for(int i=0;i<9;i++)scanf("%d",B+i);
		for(int i=0;i<10;i++)for(int j=0;j<(1<<9);j++)for(int k=0;k<350;k++)
			dp[i][j][k]=0;
		dp[0][0][175]=1;
		for(int i=0;i<9;i++){
			for(int j=0;j<(1<<9);j++){
				for(int k=0;k<350;k++){
					if(dp[i][j][k]<eps)continue;
					for(int l=0;l<9;l++){
						if(j&(1<<l))continue;
						if(A[i]>B[l])dp[i+1][j+(1<<l)][k+A[i]+B[l]]+=dp[i][j][k]/(9-i);
						else dp[i+1][j+(1<<l)][k-A[i]-B[l]]+=dp[i][j][k]/(9-i);
					}
				}
			}
		}
		double L=0;
		double R=0;
		for(int i=0;i<350;i++){
			if(i<175)R+=dp[9][(1<<9)-1][i];
			if(i>175)L+=dp[9][(1<<9)-1][i];
		}
		printf("%f %f\n",L,R);
	}
}

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

int route(int x0, int y0, int t0, int t1, int x1, int y1) {
  int x, y, t;
  if (x0<x1) x=x1-x0;
  else x=x0-x1;
  if (y0<y1) y=y1-y0;
  else y=y0-y1;
  t=t1-t0;
  if (x+y<=t && (t-(x+y))%2==0) return 1;
  else return 0;
}

int main() {
  
  int N;
  cin >> N;
  
  int s=0;
  int ox, oy, ot;
  for (int i=0; i<N; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    if (i==0) {
      ox=0;
      oy=0;
      ot=0;
    }
    s=route(ox, oy, ot, t, x, y);
    ox=x;
    oy=y;
    ot=t;
  }
  
  if (s==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N, C = map(int, input().split())

D = []
c = []

for i in range(C) :
    line = list(map(int, input().split()))
    D.append(line)
for i in range(N) :
    line = list(map(int, input().split()))
    c.append(line)

colorCount = [[0 for _ in range(C + 1)] for _ in range(3)]  # colorCount[index][color]
for i in range(N) :
    for j in range(N) :
        colorCount[(i + j + 2) % 3][c[i][j]] += 1

ans = float('inf')
for firstColor in range(1, C + 1) :
    for secondColor in range(1, C + 1) :
        for thirdColor in range(1, C + 1) :
            if firstColor == secondColor or secondColor == thirdColor or thirdColor == firstColor :
                continue
            cost = 0
            for dist, toColor in enumerate([secondColor, thirdColor, firstColor]) :
                for fromColor in range(1, C + 1) :
                    if toColor == fromColor :
                        continue
                    cost += colorCount[dist][fromColor] * D[fromColor - 1][toColor - 1]
            ans = min(ans, cost)

print(ans)

Measured memory_bytes: 5620
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M=nm()
print('Yes' if N==M else 'No')

Measured memory_bytes: 63980
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string s;
    cin >> s;
    
    int cnt = 0;
    vector<int> A_num(s.size(), -1);
    rep(i, s.size()) {
        if (s[i] == 'A') {
            A_num[i] = cnt;
            ++cnt;
        }
    }
    vector<int> A_ans(cnt, -1);
    for (int i = (int)s.size() - 1; i >= 0; --i) {
        if (s[i] != 'A') continue;
        int BC_cnt = 0;
        for (int j = i + 1; j < (int)s.size() - 1; ++j) {
            if (s[j] == 'A') {
                A_ans[A_num[i]] = BC_cnt + A_ans[A_num[j]];
                break;
            }
            if (s[j] == 'C') break;
            if (s[j + 1] == 'C') {
                ++BC_cnt;
                ++j;
            } else {
                break;
            }
        }
        if (A_ans[A_num[i]] == -1) A_ans[A_num[i]] = BC_cnt;
    }
    long long ans = 0;
    rep(i, cnt) ans += A_ans[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5092
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,j,k,n;
  long long int s=0;
 cin >> n;
 for(i=1;i<=n;i++)
 {
  for(j=1;j<=n;j++)
  {
   for(k=1;k<=n;k++)
   s+=__gcd(__gcd(i,j),k);
  }
 }
 cout << s;
 return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	void solve(){
		lli N,K,i,j,p,q,base=26;
		string res="";
		cin>>N;
		N-=1;
		while(N>0){
			p=N%base;
			res.push_back(char(p+'a'));
			N=N/base-1;
		}
		if(N>=0)res.push_back(char(N+'a'));
		for(i=res.size()-1;i>=0;i--)cout<<res[i];
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,j,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
	
}


Measured memory_bytes: 3172
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let mut ss = s.next().unwrap().chars().collect::<std::collections::VecDeque<_>>();
	let q: usize = s.next().unwrap().parse().unwrap();
	let mut dir = 0;
	for _ in 0..q {
		let t = s.next().unwrap();
		if t == "1" {
			dir ^= 1;
		} else {
			let f = s.next().unwrap().parse::<i8>().unwrap() - 1;
			let c = s.next().unwrap().chars().next().unwrap();
			if dir ^ f == 0 {
				ss.push_front(c);
			} else {
				ss.push_back(c);
			}
		}
	}
	let ans = if dir == 0 {
		ss.into_iter().collect::<String>()
	} else {
		ss.into_iter().rev().collect::<String>()
	};
	println!("{}", ans);
}


Measured memory_bytes: 10492
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 200001
#define INF   1000000000000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll A[MAX_N];

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

    fill(A, A + MAX_N, 0);

    ll N, K;
    cin >> N >> K;
    for(ll i = 0; i < N; i++) cin >> A[i];
    sort(A, A + N);

    ll left  = -INF;
    ll right = INF;

    while(left + 1 < right) {
      ll x = (left + right) / 2;

      ll S = 0;
      ll T = 0;
      
      for(ll i = 0; i < N; i++) {
	  
	if (A[i] > 0) {

	  ll lb = -1;
	  ll ub = N;
	  ll m;
	  while (lb + 1 < ub) {
	    m = (lb + ub)/2;
	    if (A[i]*A[m] <= x) lb = m;
	    else ub = m;
	  }
	  S += (lb + 1);
	}
	
	else if (A[i] < 0) {

	  ll lb = -1;
	  ll ub = N;
	  ll m;
	  while (lb + 1 < ub) {
	    m = (lb + ub)/2;
	    if (A[i]*A[m] <= x) ub = m;
	    else lb = m;
	  }
	  S += (N - ub);
	}
	
	else {
	  if (x >= 0) S += N;
	}
	if(A[i]*A[i] <= x) T++;

      }
      ll num = (S-T)/2;

      if (num < K) left = x;
      else right = x;
    }

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








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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Po pop_back
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL n;
    cin >> n;

    map<pair<LL, LL>, LL> mp;

    for(LL i = 1; i <= n; i++){
        LL N = i;
        LL b = N % 10;
        LL a;

        while(N){
            a = N % 10;
            N /= 10;
        }

        mp[{a, b}]++;
    }

    LL ans = 0;
    for(LL i = 1; i <= n; i++){
        LL N = i;
        LL b = N % 10;
        LL a;

        while(N){
            a = N % 10;
            N /= 10;
        }

        ans += mp[{b, a}];
    }

    cout << ans << '\n';
    return 0;
}




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

using namespace std;

typedef long long ll;
#define inf (1LL << 60)

ll sum[420][420];
ll dp[420][420];

void preprocess(ll a[], ll n) {

	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			sum[i][j] = a[j] + ((i == j) ? 0 : sum[i][j - 1]);
		}
	}
}

ll solve(ll s, ll f) {
	// cout << s << " , " << f << endl;
	if (s >= f)
		return 0;

	if (dp[s][f] != -1) return dp[s][f];

	ll add = inf;
	for (int k = s; k < f; k++) {
		add = min(solve(s, k) + solve(k + 1, f) + sum[s][f], add);
	}

	return dp[s][f] = add;
}


int main() {


	int n;
	cin >> n;

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

	preprocess(a, n);
	memset(dp, -1, sizeof dp);

	cout << solve(1, n) << endl;

	return 0;
}

Measured memory_bytes: 6292
import itertools
import math


def gcd(a,b):
    while b:
        a, b = b, a % b
    return a


def lcm(left, right):
    return (left * right) // gcd(left, right)


N = int(input().strip())
Ts = []
for i in range(N):
    Ts.append(int(input().strip()))

res = 0
if len(Ts) == 0:
    res = 0
elif len(Ts) == 1:
    res = Ts[0]
else:
    res = int(lcm(Ts[0], Ts[1]))
    for T in Ts[2:]:
        res = int(lcm(res, T))

print(str(int(res)))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int k, n;
	cin >> k >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	vector<int> dis(n, 0);
	for(int i = 0; i < n - 1; ++i) {
		dis[i] = abs(a[i + 1] - a[i]);
	}
	
	dis[n - 1] = k - a[n - 1] + a[0];
	
	sort(dis.begin(), dis.end());
	
	int ans = 0;
	for(int i = 0; i < n - 1; ++i) {
		ans += dis[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int n,cnt;
char s[100005];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    cin>>s+1;
    for(int i=1;i<=n;i++){
        cnt+=s[i]!=s[i-1];
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<iostream>
#include <string>
using namespace std;
 
int main() {
    int A,B,M;

    cin >> A >> B >> M;
    vector<int>a(A);
    vector<int>b(B);

    for(int i = 0;i < A;i++){
        cin >> a.at(i);
    }
    for(int i = 0;i < B;i++){
        cin >> b.at(i);
    }
    

    int tmp,x,y,z,ans(9999999);
      for(int i = 0;i < M;i++){
        
            cin >> x >> y >> z;
          	x--;
          	y--;
          	tmp = a[x] + b[y] - z;
          	ans = min(ans,tmp);
          
    }
   
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    tmp = a.at(0) + b.at(0);
    ans = min(ans,tmp);
    cout << ans;
    
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<vector<ll>> G(N);
    if(N % 2 == 0){
        ll cnt = 0;
        rep(i,N){
            REP(j,i+1,N){
                //rep(k,N){
                if(i==j) continue;
                if(i+j+2==N+1) continue;
                G[i].push_back(j);
                cnt++;
                //}
            }
        }
        cout << cnt << endl;
        rep(i,N){
            rep(j,G[i].size()){
                cout << i+1 << " " << G[i][j]+1 << endl;
            }
        }
    }else{
        ll cnt = 0;
        rep(i,N){
            REP(j,i+1,N){
                //rep(k,N){
                if(i==j) continue;
                if(i+j+2==N) continue;
                G[i].push_back(j);
                cnt++;
                //}
            }
        }
        cout << cnt << endl;
        rep(i,N){
            rep(j,G[i].size()){
                cout << i+1 << " " << G[i][j]+1 << endl;
            }
        }

    }
}


Measured memory_bytes: 3684
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//
        int N;
        cin >> N;

        cout << N / 3 << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  int a;
  cin >> a;
  cout << 3 * a * a << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main() {
	int n;
	std::cin >> n;
	int a, b, c;
	int adp=0, bdp=0, cdp=0;
	int atugi, btugi;
	for (int i = 0; i < n; i++) {
		std::cin >> a >> b >> c;
		if (bdp > cdp ) atugi = bdp + a;
		else atugi = cdp + a;
		if (adp > cdp) btugi = adp + b;
		else btugi = cdp + b;
		if (adp > bdp) cdp = adp + c;
		else cdp = bdp + c;

		adp = atugi;
		bdp = btugi;
	}
	if (adp > bdp) {
		if (adp > cdp) {
			std::cout << adp << std::endl;
		}
		else {
			std::cout << cdp << std::endl;
		}
	}
	else if (bdp > cdp) {
		std::cout << bdp << std::endl;
	}
	else {
		std::cout << cdp << std::endl;
	}
}


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

int main()
{
    int x, y;
    std::cin >> x >> y;

    while(true)
    {
        int surplus = x % y;
        x = y;
        y = surplus;

        if(surplus==0)
            break;
    }

    std::cout << x << std::endl;

    return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <string.h>

double Do(int N){
  int i;
  char u[4];
  double s, x;
  s = 0.0;
  for(i = 0;i < N;i++){
    scanf("%lf %s", &x, u);
    if(strcmp(u, "JPY") == 0) s += x;
    if(strcmp(u, "BTC") == 0) s += x * 380000.0;
  }
  return s;
}
  
int main(void){
  int N;
  scanf("%d", &N);
  printf("%g\n", Do(N));
  return 0;
}


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

using namespace std;

const int Max = 1e5 + 20;

int main() {
	int n, A[Max], Left[Max], Right[Max];
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> A[i];
	
	//Left[i] = gcd(A[1], A[2], ... A[i]);
	Left[1] = A[1];
	for (int i = 2; i <= n; ++i)
		Left[i] = __gcd(Left[i - 1], A[i]);
		
	//Right[i] = gcd(A[i], A[i + 1], .. A[n])
	Right[n] = A[n];
	for (int i = n - 1; i >= 1; --i)
		Right[i] = __gcd(Right[i + 1], A[i]);
	
	int res = 1;
	for (int i = 1; i <= n; ++i)
		res = max(res, __gcd(Left[i - 1], Right[i + 1]));
	cout << res;
	return 0;
}

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

int main(void){
  int n;
  cin>>n;
  
  vector<vector<int>>d(n,vector<int>(2));
  
  for(int i=0;i<n;i++){
   for(int j=0;j<2;j++){
    cin>>d.at(i).at(j); 
   }
  }
  
  bool flag=false;
  
  for(int i=0;i<n-2;i++){
   if((d.at(i).at(0)==d.at(i).at(1)) && (d.at(i+1).at(0)==d.at(i+1).at(1)) &&(d.at(i+2).at(0)==d.at(i+2).at(1))){
     flag=true;
     break;
   }
  }
  
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
struct edge{ ll to; ll cap; ll rev;};
const ll MAXN=2100;
vector<edge> G[MAXN];

const ll Start=698, Goal=699;
bool used[MAXN];

void addEdge0(ll from, ll to, ll cap){
    edge A={to,cap,(ll)G[to].size()};
    edge B={from,0,(ll)G[from].size()};
    G[from].push_back(A);
    G[to].push_back(B);
    return;
}//有向グラフを作る

void addEdge1(ll a, ll b, ll cap){
    edge A={b,cap,(ll)G[b].size()};
    edge B={a,cap,(ll)G[a].size()};
    G[a].push_back(A);
    G[b].push_back(B);
    return;
}//無向グラフを作る

ll dfs(ll v, ll t, ll f){
    if(v==t) return f;
    used[v]=true;
    rep(i,G[v].size()){
        edge &e=G[v][i];
        if(!used[e.to] && e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

ll MaxFlow(){
    ll ans=0;
    while(true){
        rep(i,MAXN) used[i]=false;
        ll P=dfs(Start,Goal,INF);
        if(P==0) break;
        ans+=P;
    }
    return ans;
}

int main(){
    ll SUM=0;
    vector<bool> d(MAXN,false);
    ll R,C; cin>>R>>C;
    rep(i,R) {
        string S; cin>>S;
        rep(j,C){
            ll K=(i*26)+j;
            if(S.at(j)=='#') {
                d.at(K)=true;
                addEdge0(Start,K,1);
                addEdge0(K,Goal,1);
            }
        }
    }
    ll count=700;
    rep(i,MAXN-30) {
        if(d.at(i)&&d.at(i+1)) {
            addEdge0(Start,count,1); 
            addEdge0(count,Goal,0); 
            addEdge0(count,i,INF); 
            addEdge0(count,i+1,INF); 
            SUM++; count++;
        }
        if(d.at(i)&&d.at(i+26)) {
            addEdge0(Start,count,0);
            addEdge0(count,Goal,1);
            addEdge0(i,count,INF);
            addEdge0(i+26,count,INF);
            SUM++; count++;
        }
    }

    cout<<MaxFlow()-SUM<<endl;



}


Measured memory_bytes: 3500
function Main(input){
  input = input.trim().split('\n').map(x=>x.split(' ').map(y=>parseInt(y)));
  var x = input[0][0];
  var n = input[0][1];
  if (n == 0){
    var ps = [];
  }else{
    var ps = input[1];
  }
  var inPs = Array(301).fill(0);
  for (let i=0;i<ps.length;i++){
    inPs[ps[i] + 100] = 1;
  }
  for (let i=0;i<100;i++){
    if (inPs[x+100-i] === 0){
      var ans = x-i;
      break;
    }else if (inPs[x+100+i] === 0){
      var ans = x+i;
      break;
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> a(n+1);
    int cnt=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++){
        if(a[a[i]]==i) cnt++;
    }
    cout<<cnt/2;
}

Measured memory_bytes: 3736
#pragma region Macros
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;
int_fast32_t nn, n, sqrtN;
int_fast64_t ans, d;
char c;
char wr[15];
char *w = wr;
main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> nn;
    const int_least32_t n = nn;
    if(n == 1) {
        putc_unlocked(49, stdout);
    } else {
        const int_fast32_t sqrtN = sqrt(n);
        ans = -(int_fast64_t)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
        for(int i = 1; i <= sqrtN; ++i) {
            const int_fast32_t a = n / i;
            ans += ((int_fast64_t)i * (i + a) * (a + 1 - i));
        }
        cout<<ans;
    }
}

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

using namespace std;

using int64 = long long;

int main() {
  int N, Q;
  cin >> N >> Q;
  vector< int64 > st{N};
  for(int i = 0; i < Q; i++) {
    int64 x;
    cin >> x;
    while(st.size() && st.back() >= x) st.pop_back();
    st.emplace_back(x);
  }
  map< int64, int64 > rot;
  rot[st.back()] = 1;
  for(int i = (int) st.size() - 2; i >= 0; i--) {
    while(prev(end(rot))->first > st[i]) {
      auto it = *prev(end(rot));
      rot.erase(prev(end(rot)));
      if(it.first / st[i] > 0) rot[st[i]] += (it.first / st[i]) * it.second;
      if(it.first % st[i] > 0) rot[it.first % st[i]] += it.second;
    }
  }
  vector< int64 > add(N);
  for(auto v : rot) add[v.first - 1] += v.second;
  for(int i = N - 2; i >= 0; i--) add[i] += add[i + 1];
  for(int i = 0; i < N; i++) cout << add[i] << endl;
}


Measured memory_bytes: 9076
from itertools import combinations

n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

minn = float('inf')
idx = [i for i in range(n)]
for i in range(1, n + 1):
    for comb in combinations(idx, i):
        status = [0] * m
        money = 0
        for j in comb:
            money += ca[j][0]
            for i, ai in enumerate(ca[j][1:]):
                status[i] += ai
        if min(status) >= x:
            minn = min(minn, money)
print(-1 if minn > 10**9 else minn)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
        if(a[i] == 1) cnt++;
    }

    ll tmp = a[0];
    for (ll i = 1; i < N; i++) {
        tmp = __gcd(tmp, a[i]);
    }
    if(tmp > 1){
        printf("not coprime\n");
        return 0;
    }

    if(N - cnt > 80000){
        printf("setwise coprime\n");
        return 0;
    }

    ll MA = 1000005;
    vector<ll> x(MA, 0);
    for (int i = 0; i < N; i++) {
        tmp = a[i];
        for (ll j = 2; j*j <= tmp; j++) {
            if(tmp % j == 0){
                if(x[j] > 0){
                    printf("setwise coprime\n");
                    return 0;
                }
                x[j]++;
                tmp  = tmp / j;
            }
            while(tmp % j == 0){
                tmp = tmp / j;
            }
        }
        if(tmp > 1){
            if(x[tmp] > 0){
                printf("setwise coprime\n");
                return 0;                
            }
            x[tmp]++;
        }
    }

    printf("pairwise coprime\n");

}

Measured memory_bytes: 18836
import sys
from collections import Counter
input()
D = map(int, input().split())
input()
T = map(int, input().split())

CD = Counter(D)
CT = Counter(T)
for x in CT:
  c = CD.get(x)
  if not c is None and CT[x] <= c:
    pass
  else:
    break
else:
  print("YES")
  sys.exit()
print("NO")



Measured memory_bytes: 67808
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,q=I()
s = v()
t = [0]*(n+1)
for i in range(n):
    t[i+1]=t[i]+(1 if s[i:i+2]=="AC" else 0)

ans = []
for i in range(q):
    l,r=I()
    ans.append(t[r-1]-t[l-1])
for i in ans:
    print(i)


Measured memory_bytes: 18376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

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

    return gcd(b, (a%b));
}

int main()
{
    cin >> K;
    ll sum = 0;

    rep2(i,1,K+1)
    rep2(j,1,K+1)
    rep2(k,1,K+1)
    {
        sum += gcd(i,gcd(j,k));
    }

    cout << sum;


    
    return 0;
}

Measured memory_bytes: 3636
N, M, X = map(int, input().split())
*A, = map(int, input().split())
to_n = 0
for i in range(X, N+1):
    if i in A:
        to_n += 1
to_zero = 0
for i in range(X, 0, -1):
    if i in A:
        to_zero += 1
print(min(to_n, to_zero))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n;
    cin>>n;
    vector<string> s(n);
    ll ans=0;
    map<string,int> m;
    rep(i,n)
    {
        cin>>s[i];
        int sn=s[i].length();
        rep(j,sn-1)
        {
            if(s[i][j]=='A' && s[i][j+1]=='B')ans++;
        }
        if(s[i][0]=='B')
        {
            if(s[i][sn-1]=='A')
            {
                m["BA"]++;
            }
            else
            {
                m["BX"]++;
            }
        }
        else
        {
            if(s[i][sn-1]=='A')
            {
                m["XA"]++;
            }
            else
            {
                m["XX"]++;
            }
            
        }
    }
    if(m["XA"]>0 && m["BX"]>0)
    {
        ans+=m["BA"]+1;
        m["XA"]--;
        m["BX"]--;
    }
    else if(m["XA"]>0 || m["BX"]>0)
    {
        ans+=m["BA"];
        if(m["XA"]>0 )m["XA"]--;else m["BX"]--;
    }
    else
    {
        ans+=m["BA"]>0?m["BA"]-1:0;
    }

    ans+=min(m["XA"],m["BX"]);
    cout<<ans;
    

}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<PLL>> roads(N+1);
	REP(i, M){
		LL a, b, c;
		cin>>a>>b>>c;
		roads[a].push_back(PLL(b, c));
	}
	vector<LL> latest(N+1, -INFLL);
	latest[1]=0;
	REP(i, N){
		REPA(j, N+1){
			foreach(k, roads[j]){
				latest[k.first] = max(latest[k.first], k.second + latest[j]);
			}
		}
	}
	LL num = latest[N];
	bool flag = true;
	REP(i, N){
		REPA(j, N+1){
			foreach(k, roads[j]){
				latest[k.first] = max(latest[k.first], k.second + latest[j]);
			}
		}
		if(num!=latest[N]){
			flag=false;
		}
	}
	if(flag){
		cout << num << endl;
	}else{
		cout << "inf" << endl;
	}
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main() {
	int N, M, x, y, z, ans = 0;
	cin >> N >> M;
	vector<vector<int> > graph(N);
	for (int i = 0;i < M;++ i) {
		cin >> x >> y >> z;
		graph[--x].push_back(--y);
		graph[y].push_back(x);
	}
	vector<bool> bfs(N, false);
	queue<int> que;
	for (int i = 0;i < N;++ i) {
		if (bfs[i]) continue; // 調べ終わっている
		bfs[i] = true;
		++ ans;
		for (que.push(i);!que.empty();que.pop()) {
			int tmp = que.front();
			for (int j = 0;j < graph[tmp].size();++ j) {
				if (bfs[graph[tmp][j]]) continue; // 既に色を塗った
				bfs[graph[tmp][j]] = true;
				que.push(graph[tmp][j]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6520
#include <iostream>
using namespace std;
int abs(int x){return x > 0 ? x : -x;}
int max(int x, int y){return x > y ? x : y;}

int main(){
	int CX, CY, H;
	int N; cin >> N;
	int x[N], y[N], h[N];
	int x0, y0, h0;
	h0 = 0;
	int x1, y1, h1;
	bool flag;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i] >> h[i];
		if(h0 == 0 && h[i] > 0){
			x0 = x[i]; y0 = y[i]; h0 = h[i];
		}
	}
	for(CX = 0; CX <= 100; CX++){
		for(CY = 0; CY <= 100; CY++){
			flag = true;
			H = h0 + abs(x0 - CX) + abs(y0 - CY);
			for(int i = 0; i < N; i++){
				if(max(H - abs(x[i] - CX) - abs(y[i] - CY), 0) != h[i]){
					flag = false;
					break;
				}
			}
			if(flag){
				cout << CX << " " << CY << " " << H << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256