akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX_V = 2000;
int V; // 頂点数!!!
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v] = true;
  for(int i = 0; i < G[v].size(); i++){
    int u = G[v][i];
    int w = match[u];
    if(w < 0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(){
  int res = 0;
  memset(match, -1, sizeof match);
  for(int v = 0; v < V; v++){
    if(match[v] < 0){
      memset(used, 0, sizeof used);
      if(dfs(v)) res++;
    }
  }
  return res;
}

int main(){
  int N, M, L;
  while(cin >> N >> M >> L && N){
    int d[100][100] = {};
    REP(i, N) REP(j, N) d[i][j] = (i != j ? INF : 0);
    REP(i, M){
      int u, v, c;
      scanf("%d %d %d", &u, &v, &c);
      d[u][v] = d[v][u] = c;
    }
    REP(k, N) REP(i, N) REP(j, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    int p[1000], t[1000];
    REP(i, L){
      scanf("%d %d", &p[i], &t[i]);
    }
    V = 2 * L;
    REP(i, V) G[i].clear();
    REP(i, L) FOR(j, i + 1, L) if(t[i] > t[j]) { swap(t[i], t[j]); swap(p[i], p[j]); }
    REP(i, L) FOR(j, i + 1, L){
      if(t[i] + d[p[i]][p[j]] <= t[j]) add_edge(i, L + j);
    }
    cout << L - bipartite_matching() << endl;
  }
  return 0;
}

Measured memory_bytes: 8132
N = int(input())
A = [int(s) for s in input().split()]

def main():
    e = {}
    for n in A:
        if not n in e.keys():
            e[n] = 0
        e[n] += 1

    fe = {k:v for k, v in e.items() if v >= 2}
    se = sorted(fe.items(), key=lambda o: o[0], reverse=True)
    if len(se) == 0:
        ans = 0
    elif se[0][1] >= 4:
        ans = se[0][0] ** 2
    elif len(se) == 1:
        ans = 0
    else:
        ans = se[0][0] * se[1][0]
    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
   ll k, n, l = 0;
   cin >> k >> n;
   vector<ll> a(n);

   for(int i = 0; i < n; i++) {
       cin >> a[i];
   }
   a.push_back(k + a[0]);
   for(int i = 0; i < n; i++) {
       l = max(l, a[i + 1] - a[i]);
   } 

   cout << k - l << endl; 
   
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long

void solve(){
	char a;
	cin >> a;
	if(isupper(a)) cout << "A\n";
	else cout << "a\n";
}

int main(){
	IOS;
	int t = 1; 
	// cin >> t;
	while(t--) solve();
	return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;

int w, h;
char c[20][25];

int x[11], y[11];
int dCounter;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int minlength[20][20];
bool used[20][20];

void bfs(P s) {
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) minlength[i][j] = INF, used[i][j] = false;
  minlength[s.second][s.first] = 0;
  queue<P> que;
  que.push(s);
  while (!que.empty()) {
    P p = que.front(); que.pop();
    int px = p.first, py = p.second;
    if (used[py][px]) continue;
    used[py][px] = true;
    for (int i = 0; i < 4; i++) {
      int newy = py + dy[i], newx = px + dx[i];
      if (newy < 0 || newy >= h || newx < 0 || newx >= w) continue;
      if (c[py + dy[i]][px + dx[i]] != 'x' && !used[newy][newx]) {
        minlength[py + dy[i]][px + dx[i]] = minlength[py][px] + 1;
        que.push(P(px + dx[i], py + dy[i]));
      }
    }
  }
}

int cost[11][11];
int bitdp[1<<12][11];

int main() {
  while (1) {
    scanf("%d%d", &w, &h);
    if (w == 0) break;
    for (int i = 0; i < h; i++) scanf("%s", c[i]);
    dCounter = 1;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (c[i][j] == '*') x[dCounter] = j, y[dCounter++] = i;
        if (c[i][j] == 'o') x[0] = j, y[0] = i;
      }
    }
    bool flag = false;
    for (int i = 0; i < dCounter; i++) {
      bfs(P(x[i], y[i]));
      for (int j = 0; j < dCounter; j++) {
        cost[i][j] = minlength[y[j]][x[j]];
        if (cost[i][j] == INF) i = j = dCounter, flag = true;
      }
    }
    if (flag) {
      printf("-1\n");
      continue;
    }
    int maxbit = (1 << dCounter) - 1 - (1 << 0);
    for (int i = 0; i < maxbit; i++)
      for (int j = 0; j < dCounter; j++) bitdp[i][j] = INF;
    bitdp[maxbit][0] = 0;
    for (int s = maxbit; s > 0; s--) {
      for (int from = 0; from < dCounter; from++) {
        int frombit = 1 << from;
        if (s & frombit) continue;
        if (bitdp[s][from] == INF) continue;
        for (int to = 0; to < dCounter; to++) {
          int tobit = 1 << to;
          if ((s & tobit) == 0) continue;
          bitdp[s - tobit][to] = min(bitdp[s - tobit][to], bitdp[s][from] + cost[from][to]);
        }
      }
    }
    int ans = INF;
    for (int i = 0; i < dCounter; i++) ans = min(ans, bitdp[0][i]);
    printf("%d\n", ans);
  }
}



Measured memory_bytes: 2728
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int A, B;
    cin >> A >> B;
    int ans = max(max(A + B, A - B), A * B);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char memo[100001] = {0};

int a(int i, int sum, int ans) {
  if (sum > 100000) return 0;
  if (i == 6) {
    if (sum == ans) return 1;
    return 0;
  }

  int c, tmp, tmpsum;
  for (c=0; c <= 1000000 ;c++) {
    if ((100+i)*c > 100000-sum) break;
    tmpsum = (100+i)*c+sum;
    if (memo[tmpsum] >= 1) return memo[tmpsum] - 1;
    if ((tmp = a(i+1, tmpsum, ans)) == 1) return 1;
    memo[tmpsum] = tmp + 1;
  }

  return 0;
}

int main() {
  int ans;
  scanf("%d", &ans);
  printf("%d\n", a(0,0,ans));
  return 0;
}


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

int main(void){
  int n;
  int i,j,k;
  long long h,w,ans;
  cin>>h>>w;
  ans=floor(h*w/2)+(h*w)%2;
  if(h==1||w==1)ans=1;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();

        if (e - a > k){
            System.out.println(":(");
        }else {
            System.out.println("Yay!");
        }

    }

}

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


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

  ll n;
  cin >> n;
  ll ans = 1000;
  rep(i,100){
    if(1000*i - n >=0){
      ans = min(ans, 1000 * i -n);
    }
  }
  cout << ans << endl;
  
  return 0;
    

}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dp[101][100001];

int main()
{
    dp[0][0] = 1;
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i, n) cin >> a[i];
    int mod = 1e9 + 7;
    rep(i, n)
    {
        int sum[100001] = {};
        for (int j = 0; j <= k; j++)
            sum[j + 1] = (sum[j] + dp[i][j]) % mod;

        for (int j = 0; j <= k; j++)
            dp[i + 1][j] = (sum[j + 1] - sum[max(0, j - a[i])] + mod) % mod;
    }

    OP(dp[n][k]);
    return 0;
}

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

# 値を2進数→10進数に変換して格納
F = [int(input().replace(' ', ''), 2) for i in range(N)]

P = [[int(j) for j in input().split()] for j in range(N)]

ans = -float('inf')

# 店を営業する時間帯の通り数は最大で1024-1通り
for i in range(1, 2**10):
    # 売り上げを格納する変数
    temp = 0 
    for j in range(N):
        # 売り上げ×オープンしている店の数（bit演算and使用）
        temp += P[j][bin(i&F[j]).count('1')]
    ans = max(ans, temp)

print(ans)

Measured memory_bytes: 3064
import sys

def check(operate_list, num_list):
    res = num_list[0]
    for i, op in enumerate(operate_list):
        if op == "+":
            res += num_list[i+1]
        elif op == "-":
            res -= num_list[i+1]
    return res == 7

def concat(operate_list, num_list):
    num_list = list(map(str, num_list))
    string = num_list[0]
    for op, num in zip(operate_list, num_list[1:]):
        # it is beautiful!
        string += op
        string += num
    string += "=7"
    return string

def main():
    line = sys.stdin.readline().strip()
    num_list = []
    for s in line:
        num_list.append(int(s))
    result = ""
    stack = []
    stack.append([])
    N = len(num_list)
    while(len(stack) != 0):
        l = stack.pop()
        if len(l) == N-1:
            if check(l, num_list):
                result = concat(l, num_list)
                break
        else:
            stack.append(l + ["+"]) # careful code
            stack.append(l + ["-"])

    print(result)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
int a,b,c;

cin>>a>>b>>c;
if(a!=b&&a!=c)
cout<<a;
else if(b!=a&&b!=c)
cout<<b;
else
cout<<c;

return 0;  
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 200010
typedef long long ll;
ll N,K,A[MAX];
ll loop_start=0,loop_end=0;
bool bit[MAX]={false};
ll memo[MAX];

void solve(ll town){
    bit[town] = true;
    memo[++loop_end] = town;
    if(bit[A[town]] == true){
        for(ll i=1;i<=loop_end;i++){
            if(memo[i] == A[town]){
                loop_start = i;
                break;
            }
        }
    }
    else solve(A[town]);
}
int main(){
    scanf("%lld %lld",&N,&K);
    for(ll i=1;i<=N;i++)
        scanf("%lld",A+i);
    solve(1);

    if(K-loop_start < 0){printf("%lld",memo[K+1]);}
    else
        printf("%lld",memo[loop_start + (K-loop_start+1)%(loop_end-loop_start+1)]);
}


Measured memory_bytes: 4972
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

vector<int> graph[200001];
bool is_reached[200001];
int coun;

void dfs(int now){
	coun++;
	is_reached[now] = true;
	for (auto x : graph[now]){
		if(!is_reached[x]) dfs(x);
	}
	return;
}

int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++){
		if (!is_reached[i]){
			coun = 0;
			dfs(i);
			ans = max(ans, coun);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 21000
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

int main(void) {
	int r, g, b;
	cin >> r >> g >> b;
	if((100*r+10*g+b)%4==0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int cmp(int a,int b){
	return a>b;
}
int main() {
	int n,k,t,s[200001]={0};
	scanf("%d%d",&n,&k);
	for(int i=1; i<=n; i++) {
		scanf("%d",&t);
		s[t]++;
	}
	sort(s+1,s+n+1,cmp);
	int ans=0;
	for(int i=k+1;i<=n;i++){
		ans+=s[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int max = 100003;
		boolean[] isNotPrime = new boolean[max + 1];
		for (int i = 2; i * i <= max; i++) {
			if (!isNotPrime[i]) {
				for (int j = i * i; j <= max; j += i) {
					isNotPrime[j] = true;
				}
			}

		}
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		scanner.close();
		while (isNotPrime[x]) {
			x++;
		}
		System.out.println(x);

	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,k;
	cin>>a>>b;
	c=a+b;
	if(c%2==0)
	{
		k=c/2;
		cout<<k;	
	}
	else 
	cout<<"IMPOSSIBLE";
	return 0;
}

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

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

  int num = stoi(a + b);

  int i = 1;
  string Ans = "No";
  while(i*i <= num) {
    if (num == i*i) {
      Ans = "Yes";
      break;
    }
    i++;
  }

  cout << Ans << endl;
}


Measured memory_bytes: 3620
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

A = A1 + A2 + A3

while(N != 0):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0
    N = N - 1

while(N != 0):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0
    N = N - 1

if(A[0:3] == [0,0,0] or A[3:6] == [0,0,0] or A[6:9] == [0,0,0]):
    print('Yes')
    
elif(A[0::3] == [0,0,0] or A[1::3] == [0,0,0] or A[2::3] == [0,0,0]):
    print('Yes')

elif(A[0] + A[4] + A[8] == 0 or A[2] + A[4] + A[6] ==0):
    print('Yes')
    
else:
    print('No')

Measured memory_bytes: 3064
n = int(input())

edge = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

c = list(map(int, input().split()))

hhh = c.copy()

c.sort(reverse=True)

w = [0] * n

w[0] = c.pop(0)

chk = [i for i in edge[0]]
# print(chk)

while chk != []:
    node = chk.pop(0)
    if w[node] == 0:
        w[node] = c.pop(0)
        chk.extend(edge[node])

print(sum(hhh) - max(hhh))

print(' '.join(map(str, w)))


Measured memory_bytes: 6132
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n;
int xS, yS, xT, yT, x[MAXN], y[MAXN], r[MAXN];
double D[1010][1010], d[MAXN];

double dist(double x1, double y1, double x2, double y2) {
	return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}

double dijk(int s, int t) {
	priority_queue<pair<double, int> > que;
	for (int i=0; i<=n; i++) d[i] = foo;
	d[s] = 0;
	que.push(mp(0, s));
	while (!que.empty()) {
		pair<double, int> tmp = que.top();
		if (tmp.SE == t) return d[t];
		que.pop();
		for (int i=0; i<=n; i++) if (i != tmp.SE) {
			if (d[i] > d[tmp.SE] + D[tmp.SE][i]) {
				d[i] = d[tmp.SE] + D[tmp.SE][i];
				que.push(mp(-d[i], i));
			}
		}
	}
	
	return foo;
}

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	scanf("%d%d%d%d", &xS, &yS, &xT, &yT);
	scanf("%d", &n);
	for (int i=1; i<=n; i++) {
		scanf("%d%d%d", &x[i], &y[i], &r[i]);
	}
	++n;
	x[0] = xS; y[0] = yS; r[0] = 0;
	x[n] = xT; y[n] = yT; r[n] = 0;
	for (int i=0; i<=n; i++) {
		for (int j=i+1; j<=n; j++) {
			double d = dist(x[i], y[i], x[j], y[j]);
			double totR = r[i] + r[j];
			if (d > totR) {
				D[i][j] = D[j][i] = d - totR;
			}
			else {
				D[i][j] = D[j][i] = 0;
			}
		}
	}
	
	double ans = dijk(0, n);
	printf("%.12lf", ans);
}


Measured memory_bytes: 12400
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        
        while(true){
        	int n=scan.nextInt();
        	if(n==0)break;
        	int [] ice =new int[10];
        	for(int i=0;i<n;i++){
        		ice[scan.nextInt()]++;
        	}
        	for(int k : ice){
        		if(k==0)System.out.print("-");
        		else for(int i=0;i<k;i++)System.out.print("*");
        		System.out.println();
        	}
        }
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type& a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	vi a(n),b(n),c(n-1);
	REP(i,n){
		cin>>a[i];
		a[i]--;
	}
	REP(i,n) cin>>b[i];
	REP(i,n-1) cin>>c[i];
	
	int sum=b[a[0]];
	for(int i=1;i<n;++i){
		sum+=b[a[i]];
		if(a[i]==a[i-1]+1) sum+=c[a[i]-1];
	}
	
	cout<<sum<<endl;
	return 0;
}

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

int main() {
	ll n,m,ans=1; cin>>n>>m;
	ll maxpart=m/n;

	for (ll i=1; i*i<=m; i++) {
		if (m%i==0) {
			//partition gcd is either i or m/i
			if (i <= maxpart) ans = max(ans,i);
			if (m/i <= maxpart) ans = max(ans,m/i);
		}
	}

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


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() {
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, n) {
        cin >> vec[i];
    }
    bool val = false;
    rep(i, n) {
        if (vec[i] % 2 == 0) {
            if ((vec[i] % 3 != 0) && (vec[i] % 5 != 0)) {
                val = true;
                break;
            }
        }
    }
    if (val) {
        cout << "DENIED" << endl;
    }else {
        cout << "APPROVED" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> con(8, vector<bool>(8, false));
  for (int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b; a--; b--;
    con.at(a).at(b) = con.at(b).at(a) = true;
  }
  bool checked[8];
  
  function<int(int, int)> dfs = [&](int cur, int visited){
    if (visited == n) return 1;
    int ret = 0;
    for (int i = 1; i < n; i++){
      if (con.at(cur).at(i) && (!checked[i])){
        visited++; checked[i] = true;
        ret += dfs(i, visited);
        visited--; checked[i] = false;
      }
    }
    return ret;
  };
  checked[0] = true;
  cout << dfs(0, 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b,c;
  ci(a>>b>>c);
  vec d(b);
  For(i,0,b)
    ci(d[i]);
  ll e=0;
  For(i,0,c)
    For(j,0,b)
      if(i==d[j]){
        e++;
        break;
      }
  co(min(e,b-e));
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		int N = sc.nextInt();
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		for (int i = 0; i < N; i++) {
			String s = sc.next();
			if (s.equals("AC")) {
				ac++;
			}
			else if (s.equals("WA")) {
				wa++;
			}
			else if (s.equals("TLE")) {
				tle++;
			}
			else if (s.equals("RE")) {
				re++;
			}
		}

		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);
	}

	private static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

	}
}


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

int main() {
	double n, ave = 0;
	double a[1000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ave += a[i] * 1.0;
	}
	ave /= n;
	double min = 100000, ans = 0;
	for (int i = 0; i < n; i++) {
		if (abs(a[i] - ave) < min) {
			ans = i;
			min = abs(a[i] - ave);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,k,a[100010],ans=1e9;
int main(){
	cin>>n>>k;
	for (int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for (int i=0;i<n-k+1;i++) ans=min(ans,a[i+k-1]-a[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
def isPrime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    for p in range(2, int(n**0.5)+1):
        if n % p == 0:
            return False
    return True

while True:
    try:
        n=int(input())
    except:
        break
    oup=0
    if n <=1:
        print(0)
    else:
        if isPrime(n-1)==True:
            if n-1==2:
                oup+=1
            else:
                oup+=2
        for i in range(3,n//2+2,2):
            if isPrime(i)!=True:
                continue
            j=n-i+1
            if i>j:
                continue
            elif isPrime(j)==True:
                if i==j:
                    oup+=1
                else:
                    oup+=2
        print(oup)


Measured memory_bytes: 5660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int x;
    cin>>x;
    int n=x/100;
    x%=100;
    cout<<(x<=n*5)<<endl;
}


Measured memory_bytes: 256
from itertools import product
n,m,x=map(int,input().split())
c=[0]*n
a=[0]*n
INF=10**9
for i in range(n):
  d,*b=map(int,input().split())
  c[i]=d
  a[i]=b
ans=INF
for z in product([0,1],repeat=n):
  u=[0]*m
  cost=0
  for i in range(n):
    cost+=c[i]*z[i]
    for j in range(m):
      u[j]+=a[i][j]*z[i]
  flg=True
  for j in range(m):
    if u[j]<x:
      flg=False
  if flg:
    ans=min(ans,cost)
if ans==INF:
  ans=-1
print(ans)

Measured memory_bytes: 9256
/* インクルードなど */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = pow(10, 9) + 7;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n+1,0);
    for (ll i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    for (ll i = 0; i < n; i++) {
        b[i+1] = b[i] + a[i];
    }
    ll ans = 0;
    for (ll i = 0; i < n-1; i++) {
        ans += a[i] * ((b[n] - b[i+1]) % MOD);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6432
#include <iostream>

using ll = long long;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin >> n;
	int t =1;
	while((t<<1)<=n)t=t<<1;
	cout << t;


	return 0;
}


Measured memory_bytes: 764
N, M = map(int,input().split())
A = list(map(int, input().split()))

BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(reverse = True, key=lambda x : x[1])

index = -1
for b, c in BC:
    for _ in range(b):
        index += 1
        if index >= N:
            break
        if A[index] >= c:
            break
        A[index] = c
    else:
        continue
    break
print(sum(A))


Measured memory_bytes: 32888
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

// gp_hash_table<int, int> table;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

pair<int, int> solve(int h, int w, int a, int b) {
  for (int x = 0; x <= h; ++x) {
    for (int y = 0; y <= w; ++y) {
      int row_ones = x * a + (h - x) * (w - a);
      int col_ones = y * b + (w - y) * (h - b);
      if (row_ones == col_ones) {
        return make_pair(x, y);
      }
    }
  }

  return make_pair(-1, -1);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int h, w, a, b;
  cin >> h >> w >> a >> b;

  auto res = solve(h, w, a, b);
  if (res.first == -1) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> row_cnt(h), col_cnt(w);
  for (int i = 0; i < h; ++i) {
    row_cnt[i] = (i < res.first ? a : w - a);
  }
  for (int j = 0; j < w; ++j) {
    col_cnt[j] = (j < res.second ? b : h - b);
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (row_cnt[i] > 0 && col_cnt[j] > 0) {
        --row_cnt[i] , --col_cnt[j];
        cout << '1';
      } else {
        cout << '0';
      }
    }
    cout << endl;
  }

}


Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int cmp(const void *a, const void *b);//比較関数

int main(void){
    int i, N;
    double VALUE[51];
    scanf("%d", &N);
    for(i=0; i<N; i++) scanf("%lf", VALUE+i);
    qsort(VALUE, N, sizeof(double), cmp);//昇順ソート
    for(i=0; i<N-1; i++){
        VALUE[i+1] = (VALUE[i]+VALUE[i+1]) / 2.0;
    }
    printf("%f\n", VALUE[N-1]);
    return 0;
}

int cmp(const void *a, const void *b){
    return *(double *)a - *(double *)b;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

/*--------switch header--------*/
#define ALGORITHM   1
#define CASSERT     0
#define CMATH       0
#define DEQUE       0
#define FUNCTIONAL  1
#define IOMANIP     1
#define IOSTREAM    1
#define LIST        0
#define MAP         0
#define QUEUE       0
#define SET         0
#define STRING      1
#define UTILITY     1
#define VECTOR      1
#define VEC_DEBUG   1

using namespace std;

#pragma region headers
#if VEC_DEBUG
#define _GLIBCXX_DEBUG
#endif
#if ALGORITHM
#include <algorithm>
#endif
#if CASSERT
#include <cassert>
#endif
#if CMATH
#include <cmath>
#endif
#if DEQUE
#include <deque>
#endif
#if FUNCTIONAL
#include <functional>
#endif
#if IOMANIP
#include <iomanip>
#endif
#if IOSTREAM
#include <iostream>
#endif
#if LIST
#include <list>
#endif
#if MAP
#include <map>
#endif
#if QUEUE
#include <queue>
#endif
#if SET
#include <set>
#endif
#if STRING
#include <string>
#endif
#if UTILITY
#include <utility>
#endif
#if VECTOR
#include <vector>
#endif
#pragma endregion


/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define ALL(x)          (x).begin(), (x).end()
#define rALL(x)         (x).rbegin(), (x).rend()
#define REP(i, n)       for(int i = 0; (i) < (n); (i)++)
#define rREP(i, n)      for(int i = n - 1; (i) >= 0 ; (i)--)
#define FOR(i, a, b)    for(int i = (a); (i) < (b) ; (i)++)
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    ll ans = 0;
    FOR(i, 1, n+1){
        if(!(i%15==0)&&!(i%3==0)&&!(i%5==0))
            ans += i;
    }

    cout << ans << endl;

return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string b; cin >> b;
    string ans = "";
    map<char,char> m;
    m['A'] = 'T'; m['T'] = 'A'; m['C'] = 'G'; m['G'] = 'C';
    REP(i,b.size()) ans += m[b[i]];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
  COMinit();
  ll s;
  cin >> s;
  ll d,ans=0;
 for(ll i=1;i<s/3+1;i++){
    d=s-i*3;
    ans=(ans+COM(i+d-1,d)%1000000007)%1000000007;
  }
  cout << ans;
}

Measured memory_bytes: 15592
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll H, W, N;
	cin >> H >> W >> N;
	vl X(N), Y(N);
	vector<vl> Xobslist(H);
	vl Xobsnum(H, 0);
	ll ans = H;
	rep(i, N) {
		cin >> X[i] >> Y[i];
		X[i]--;
		Y[i]--;
		Xobslist[X[i]].push_back(Y[i]);
		Xobsnum[X[i]]++;
	}
	ll can_go_to_Y = 0; // Y方向到達可能範囲 : 0 <= y <= can_go_to_Y
	rep(x, H) { // 上から順に見る
		if (x == 0)
			continue;
		ll xobsnum = Xobsnum[x];
		bool can_stop = false;
		bool can_go_to_Y_will_inc = true; // (x, can_go_to_Y + 1)に障害物がなければY方向到達可能範囲が1増える
		rep(i, xobsnum) {
			int y = Xobslist[x][i];
			if (y <= can_go_to_Y) {
				can_stop = true;
				break;
			}
			else if (y == can_go_to_Y + 1)
				can_go_to_Y_will_inc = false;
		}
		if (can_stop) {
			ans = x;
			break;
		}
		if (can_go_to_Y_will_inc)
			can_go_to_Y++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15872
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(input())
	}

	ans := "YES"
	nums := map[int]bool{}
	for i := 0; i < n; i++ {
		_, exists := nums[a[i]]
		if exists {
			ans = "NO"
			break
		}
		nums[a[i]] = true
	}
	fmt.Println(ans)
}


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



int main(int argc, char const *argv[])
{
	char Mark[4] = {'S', 'H','C', 'D'};
	int Number[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
	int Memory[4][13] = {0};
	int n=0;
	int i,j,k=0;
	cin >> n;
	char M;
	int N;


	for (k=0;k<n;++k)
	{
		cin >> M >>N;
		i=0;
		while(Mark[i] != M)
		{
			i++;
		}

		j=0;
		while(Number[j] != N)
		{
			j++;
		}

		Memory[i][j]=1;
	}

	for(i = 0; i<4;i++)
	{
		for(j=0;j<13;j++)
		{
			if(Memory[i][j] == 0)
			{
				cout << Mark[i] << " " << Number[j] << endl;
			}
		}
	}

	return 0;
}




Measured memory_bytes: 3056
#include "iostream"
using namespace std;
int main()
{
	int S, h, m, s;
	cin >> S;
	s = S % 3600 % 60;
	m = (S - s) / 60 % 60;
	h = (S-m*60-s)/3600;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


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

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    int back=0,front=0;
    int count = 0;
    int chohuku = 0;
    rep(i, n) {
        string s;cin >> s;
        if(s[0]=='B') front++;
        if(s.back()=='A') back++;
        if(s[0]=='B'&&s.back()=='A') chohuku++;
        rep(j, s.size()-1) if(s.substr(j,2)=="AB") count++;
    }
    bool ok = false;
    if(chohuku==front&&front==back&&chohuku) ok=true;
    cout << count+min(min(front,back)-ok,n-1) << endl;
    return 0;
}
/*
2
BAA
BBA
*/

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

int main(){
  string str;
  bool fl = true;
  cin >> str;
  reverse(str.begin(), str.end());
  while(!(str.empty()) && fl == true){
    if(str.substr(0,5) == "maerd") str.erase(0,5);
    else if(str.substr(0,7) == "remaerd") str.erase(0,7);
    else if(str.substr(0,5) == "esare") str.erase(0,5);
    else if(str.substr(0,6) == "resare") str.erase(0,6);
    else fl = false;
  }
  if(fl == true) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<double,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int m;cin >> m;
    vector<LL> d(m),c(m);
    LL ans = 0;
    LL sum = 0;
    for (int i = 0; i < m; i++) {
        cin >> d[i] >> c[i];
        ans += c[i];
        sum += d[i]*c[i];
    }
    ans--;
    ans += (sum - 1)/ 9;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
(let* ((n (read))
       (m (read)))
  (defun min-string (a b)
    (if (string< a b) a b))
  (princ (min-string (format nil "~A" (loop :for k :from 0 :upto (1- n) :sum(* m (expt 10 k))))
                     (format nil "~A" (loop :for k :from 0 :upto (1- m) :sum(* n (expt 10 k)))))))

Measured memory_bytes: 15200
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||b+c==a||a+c==b)
        {
        	printf("Yes");
        	return 0;
        }
    printf("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

  string str;
  cin >> str;
  
  int a,b,c,d;
  a = str[0] - '0';
  b = str[1] - '0';
  c = str[2] - '0';
  d = str[3] - '0';
  REP(k,2){
    int op1 = pow(-1,k);
    REP(i,2){
    int op2 = pow(-1,i);
      REP(j,2){
      int op3 = pow(-1,j);
        if(a+op1*b+op2*c+op3*d == 7){
          cout << a << (op1 == 1 ? '+' : '-') << 
                  b << (op2 == 1 ? '+' : '-') <<
                  c << (op3 == 1 ? '+' : '-') <<
                  d << "=7" << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	string S;
	cin >> N >> S;
	int cnt = 0;
	rep(i, N - 2)
	{
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    #全部異なるならbit全探索できそう
    #2つ以上同じものがあるとk以上同じものがある時　向きが逆だとして最小値候補に入れておく
    n=I()
    lis=LI()
    if 0 in lis:
        print(0)
        sys.exit()
    c=Counter(lis)
    ans=inf
    multi=[]
    for x in c.keys():
        #print(x)
        if c[x]>=3:
            print(0)
            sys.exit()
        elif c[x]>=2:
            ans=min(ans,x,24-2*x)
            multi.append(x)
    lis.append(0)
    lis=list(set(lis))
    u=len(lis)
    #print(lis)
    #ansは上限
    answers=[]
    #print(ans)
    for x in product([0,1],repeat=u):
        time=[]
        for i in range(u):
            if lis[i] in multi:
                time.append(lis[i])
                time.append(24-lis[i])
            elif x[i]==1:
                time.append(24-lis[i])
            else:
                time.append(lis[i])
        #print(time)
        z=ans
        for i in range(len(time)-1):
            for j in range(i+1,len(time)):
                z=min(z,24-abs(time[i]-time[j]),abs(time[i]-time[j]))   
        #print(z)
        answers.append(z)
        
    print(max(answers))
        
        
        
                
        
        
                
        
            
            
    
            
            
    


                
    
    
    
            
if __name__=="__main__":
    main()


Measured memory_bytes: 74708
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100009]; long long dp[100009][7]; bool vis[100009][7]; string s[100009];
long long solve(int pos, int depth) {
	if (pos == n) return 0;
	if (vis[pos][depth]) return dp[pos][depth];
	long long ret = -1LL << 61;
	if (s[pos] == "+") {
		ret = solve(pos + 1, depth) + a[pos] * (depth % 2 ? -1 : 1);
		if (depth > 0) ret = max(ret, solve(pos + 1, depth - 1) + a[pos] * (depth % 2 ? -1 : 1));
	}
	else {
		ret = solve(pos + 1, depth) + a[pos] * (depth % 2 ? 1 : -1);
		if (depth > 0) ret = max(ret, solve(pos + 1, depth - 1) + a[pos] * (depth % 2 ? 1 : -1));
		if (depth < 6) ret = max(ret, solve(pos + 1, depth + 1) + a[pos] * (depth % 2 ? 1 : -1));
	}
	vis[pos][depth] = true;
	dp[pos][depth] = ret;
	return ret;
}
int main() {
	cin >> n;
	s[0] = "+"; cin >> a[0];
	for (int i = 1; i < n; i++) cin >> s[i] >> a[i];
	long long ret = solve(0, 0);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 16896