akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 50000
int main()
{
	int m;
	int i;
	int n = 0;
	scanf("%d",&m);
    for(i = 1;i<=m;i++)
    {
    	n += i;
    	if(n >= m)
    	{
    		printf("%d",i);
    		break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#define INF 9999999
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	string S;
	ull K;
	cin >> S >> K;
	int tmp = -1;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != '1') {
			tmp = i; break;
		}
	}
	if (tmp == -1)cout << 1 << endl;
	else {
		if (tmp >= K) cout << 1 << endl;
		else cout << S[tmp] << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int m, f, b;
    cin >> m >> f >> b;
    if (m < b) {
        if (m + f < b) {
            cout << "NA" << endl;
        } else {
            cout << b - m << endl;
        }
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3096
package main
import (
    "fmt"
)

func main() {
    var start_a, end_a, start_b, end_b int
    fmt.Scan(&start_a)
    fmt.Scan(&end_a)
    fmt.Scan(&start_b)
    fmt.Scan(&end_b)

    var result int

    if (end_a < start_b) || (end_b < start_a) {
        result = 0
    } else {

        var start, end int
        if start_a > start_b {
            start = start_a
        } else {
            start = start_b
        }

        if end_a > end_b {
            end = end_b
        } else {
            end = end_a
        }

        result = end - start
    }

    fmt.Println(result)
}


Measured memory_bytes: 512
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = getInt()
	}

	for i := 1; i < N; i++ {
		if h[i] > h[i-1] {
			h[i]--
		}
	}
	// out(h)
	for i := 1; i < N; i++ {
		if h[i] < h[i-1] {
			out("No")
			return
		}
	}
	out("Yes")
	return
}


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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> A;
    int tmp;
    bool alleven = true;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        A.emplace_back(tmp);
    }

    int cnt = 0;
    do
    {
        for (int i = 0; i < N; i++)
        {
            if (A[i] % 2 != 0)
            {
                alleven = false;
            }else{
                A[i] /= 2;
            }

        }
        if (!alleven) break;
        cnt += 1;

    } while (alleven);

    cout << cnt << endl;

    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int L;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>L;

    int hi=0;

    const int N = 20;


    vector<pair<int,int>> v;

    for (int i=2; i<=N; i++) {
	int ways = 1<<(N-i);
	while (hi+ways<=L) {
	    v.push_back({i, hi});
	    hi += ways;
	}
    }


    int nodes = N;
    int edges = (N-2)*2 + (int)v.size();

    cout<<nodes<<" "<<edges<<"\n";

    for (int i=2; i<N; i++) {
	int wei = 1<<(N-1-i);
	cout<<i<<" "<<i+1<<" "<<wei<<"\n";
	cout<<i<<" "<<i+1<<" "<<0<<"\n";
    }


    for (auto ed: v) {
	cout<<1<<" "<<ed.first<<" "<<ed.second<<"\n";
    }


    return 0;
}


Measured memory_bytes: 384
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
        static class Pair {
                int quan=0;
                String val="";
                Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                }
            }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    }

}



Measured memory_bytes: 77056
#include <stdio.h>

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

int main(void)
{
	int num;
	int n[3];
	int rc;
	
	scanf("%d\n", &num);
	
	while (num-- > 0) {
		rc = scanf("%ld %ld %ld\n", &n[0], &n[1], &n[2]);
		if (rc == EOF || rc < 3) {
			break;
		}
		qsort(n, 3, sizeof(int), compare_int);
		
		if (n[0]*n[0] == n[1]*n[1] + n[2]*n[2]) {
			puts("YES");
		} else {
			puts("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
  int N,m=0,tmpi,L=0;
  cin >> N;
  int l[N];
  for(int i = 0;i < N;++i) cin >> l[i];
  for(int i = 0;i < N;++i){
    if(m < l[i]){
      m = l[i];
      tmpi = i; 
    }
  }
  l[tmpi]=0;
  for(int i = 0;i < N;++i){
    L += l[i];
  }
  if(m < L){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
    
    return 0;
}

Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()

ans = n * (1 + n) // 2 - n
print(int(ans))

Measured memory_bytes: 7376
# Contest: AtCoder Beginner Contest 152 (https://atcoder.jp/contests/abc152)
# Problem: E: Flatten (https://atcoder.jp/contests/abc152/tasks/abc152_e)

def rint():
    return int(input())


def rints():
    return list(map(int, input().split()))


from fractions import gcd
from functools import reduce
m = 10**9 + 7
def inv(a):
    return pow(a, m - 2, m)
def mod_lcm(a, b):
    return a * b // gcd(a, b)
n = rint()
a = rints()
l = reduce(mod_lcm, a) % m
print(sum(l * inv(ai) % m for ai in a) % m)


Measured memory_bytes: 67800
import re

def bubbleSort(A, n):
    flag = True
    while flag:
        flag = False
        for j in range (1,n)[::-1]:
            if int(re.sub("\\D", "", A[j])) < int(re.sub("\\D", "", A[j-1])):
                A[j],A[j-1] = A[j-1],A[j]
                flag = True
    return [str(a) for a in A]


def selectionSort(A, n):
    for i in range (n):
        minj = i
        for j in range (i,n):
            if int(re.sub("\\D", "", A[j])) < int(re.sub("\\D", "", A[minj])):
                minj = j
        A[i],A[minj] = A[minj],A[i]
    return [str(a) for a in A]



n = int(input())
A = input().split()
B = [str(a) for a in A]

if bubbleSort(A, n) == selectionSort(B, n):
    print(" ".join(bubbleSort(A, n)))
    print("Stable")
    print(" ".join(selectionSort(A, n)))
    print("Stable")
else:
    print(" ".join(bubbleSort(A, n)))
    print("Stable")
    print(" ".join(selectionSort(B, n)))
    print("Not stable")



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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for (int i = 0; i < N; i++) cin >> P[i];
  for (int i = 0; i < N; i++) cin >> Q[i];

  vector<int> A(N);
  for (int i = 0; i < N; i++) A[i] = i + 1;

  int a = 0;
  int b = 0;
  int count = 0;
  do {
    if (P == A) {
      a = count;
    }
    if (Q == A) {
      b = count;
    }
    count++;
  } while (next_permutation(A.begin(), A.end()));

  cout << abs(a - b) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main(){
    char str[256];
	int num;

	scanf("%s", str);
    num=atoi(str);
    if(num % 2==0) printf("%d\n",num/2);
    else printf("%d\n",(num+1)/2);
  	return 0;
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)
#define fi first
#define se second

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a = 1;
    while(a * a <= n) ++a;
    --a;
    cout << a * a << endl;
    return 0;
}

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

const int MAX_N = 3e5+10;
int N, K, Q;
int a[MAX_N];
int c[MAX_N];

void solve()
{
	for(int i=0;i<Q;++i)c[a[i]-1]++;
	for(int i=0;i<N;++i){
		if(K<=(Q-c[i])) cout << "No\n";
		else cout << "Yes\n";
	}
}

int main()
{
	cin >> N >> K >> Q;
	for(int i=0;i<Q;++i){
		cin >> a[i];
	}
	solve();
	return 0;
}

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

/*
変更箇所は順読み逆読みの少なくとも片方で役立たないといけない
つまり1点分として加算される必要がある
逆に1点分以上の役割は持てない<-嘘だった
例えば右端の文字が他に存在しない文字ならそれを変更するのはOK
*/
/*
問題概要は最長の回文を作れ？
だとすると中心決めてしまえばそこからは書き換えるかどうかは片側だけに注目すればよくて
sBtに対してsを右側から見ていくことを考える
変えるならt[now]しかありえなくて、書き換えた方がいいかどうかチェックするのに150^2かかる？
なんか違いそう
端から見て言ってdp[i][j][k]で考えるべき？
dp[i][j][k]:左からi文字右からj文字、k文字変更した時の最長回文
dp[i][j][k]=max(dp[i][j-1][k],dp[i-1][j][k],dp[i-1][j-1][k]+(s[i]==s[N-j-1]),dp[i-1][j-1][k-1]+1)
*/
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
int dp[400][400][400];
signed main(){
  string s;int K;cin>>s>>K;
  int N=s.size();
  if(K>=N/2)fin(N);
  int ans=0;
  for(int k=0;k<=K;k++){
    for(int i=1;i<N;i++){
      for(int j=1;i+j<=N;j++){
        dp[i][j][k]=max({dp[i][j-1][k],dp[i-1][j][k],dp[i-1][j-1][k]+2*(s[i-1]==s[N-j])});
        if(k)dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k-1]+2);
        ans=max(ans,dp[i][j][k]+(i+j<N));
      }
    }
  }
  cout<<max(ans,1)<<endl;
}


Measured memory_bytes: 187776
S = input()

len_S = len(S)
ans = 0
for i in range(len_S):
    tmp = 0
    tmp_ans = 0
    for j in range(i, len_S):
        if S[j] == 'A' or S[j] == 'C' or S[j] == 'G' or S[j] == 'T':
            tmp += 1
        else:
            tmp_ans = max(tmp_ans, tmp)
            tmp = 0
    ans = max(tmp_ans, tmp, ans)
print(ans)

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

int main() {
	int weeks, debt = 100000;

	cin >> weeks;
	for (int i = 0;i < weeks;i++) {
		debt *= 1.05;
		if (debt % 1000 != 0) debt = 1000 * (debt / 1000 + 1);
	}
	cout << debt << endl;
	return 0;
}

Measured memory_bytes: 2944
d,g = map(int,input().split())
p = [0] * d
c = [0] * d
for i in range(d):
    p[i],c[i] = map(int,input().split())
ans_num = float('inf')
for i in range(2 ** d):
    score_li = list(range(1,d+1))
    ans_li = []
    ans_n = 0
    for j in range(d):
        if i >> j & 1:
            ans_li.append(p[j]*score_li[j]*100+c[j])
            score_li[j] = -1
            ans_n += p[j]
    if sum(ans_li) < g:
        s = sum(ans_li)
        score_li.sort(reverse=True)
        for k in score_li:
            for l in range(p[k-1]):
                s += k*100
                ans_n += 1
                if s >= g:
                    ans_num = min(ans_n, ans_num)
    else:
        ans_num = min(ans_n, ans_num)
print(ans_num)

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int n, k; cin >> n >> k;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    
    sort(h.begin(), h.end());

    ll ans = 0;
    for (int i = 0; i < n - k; i++) {
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void)
{
    int  a,b[2000],i,j,n=0,m,x,y,z=0;
    char c[100],s[100];

    scanf("%d",&n);
    scanf("%s%s",c,s);

    for (size_t i = 0; i < n; i++)
    {
       printf("%c%c",c[i],s[i]);
    }
  printf("\n");
      return 0;
}

Measured memory_bytes: 128
n=int(input())
ans=list(input())
ans.sort()
for i in range(n-1):
    s=list(input())
    num1=0
    re=[]
    for j in range(len(ans)):
        if ans[j] in s:
            s.remove(ans[j])
        else:
            re.append(ans[j])
    for j in range(len(re)):
        ans.remove(re[j])
    if len(ans)==0:
        break
strans=""
for i in range(len(ans)):
    strans+=ans[i]
print(strans)


Measured memory_bytes: 9208
import java.util.Calendar;
import java.util.Scanner;

class Main {

	private static final int YEAR = 2004;
	private static final String SUNDAY = "Sunday";
	private static final String MONDAY = "Monday";
	private static final String TUESDAY = "Tuesday";
	private static final String WEDNESDAY = "Wednesday";
	private static final String THURSDAY = "Thursday";
	private static final String FRIDAY = "Friday";
	private static final String SATURDAY = "Saturday";

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while (sc.hasNextInt()) {
				int month = sc.nextInt();
				int day = sc.nextInt();
				if (month == 0 || day == 0) {
					break;
				}

				System.out.println(getDayOfTheWeek(month, day));

			}
		}
	}

	private static String getDayOfTheWeek(int month, int day) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(YEAR, month - 1, day);

		String dayOfTheWeek = null;
		switch (calendar.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.SUNDAY:
			dayOfTheWeek = SUNDAY;
			break;
		case Calendar.MONDAY:
			dayOfTheWeek = MONDAY;
			break;
		case Calendar.TUESDAY:
			dayOfTheWeek = TUESDAY;
			break;
		case Calendar.WEDNESDAY:
			dayOfTheWeek = WEDNESDAY;
			break;
		case Calendar.THURSDAY:
			dayOfTheWeek = THURSDAY;
			break;
		case Calendar.FRIDAY:
			dayOfTheWeek = FRIDAY;
			break;
		case Calendar.SATURDAY:
			dayOfTheWeek = SATURDAY;
			break;
		}
		return dayOfTheWeek;
	}
}

Measured memory_bytes: 27488
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main() {
  ll n;
  cin >> n;
  vector<ll> s(n);
  rep(i, n) cin >> s[i];

  ll ans = 0;
  FOR(c, 1, n - 1) {
    ll res = 0;
    vector<bool> used(n, false);
    for (ll k = 0; n - 1 - k * c > 0; ++k) {
      chmax(ans, res);
      if (used[k * c]) break;
      used[k * c] = true;
      if (used[n - 1 - k * c]) break;
      used[n - 1 - k * c] = true;
      res += s[k * c] + s[n - 1 - k * c];
    }
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void){
  string a, b, e;
  int c, d;

  cin >> a >> b;
  cin >> c >> d;
  cin >> e;

  if(a==e){
    cout << c-1 << " " << d << endl;
  }else{
    cout << c << " " << d-1 << endl;
  }
  return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int a;cin >>a;
    int ans=a+a*a+a*a*a;
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n;
    cin >> n;
    vi b(n - 1);
    rep(i, 0, n - 1) cin >> b[i];
    vi a;
    a.push_back(b[0]);
    rep(i, 0, n - 2)
    {
        a.push_back(min(b[i], b[i + 1]));
    }
    a.push_back(b[n - 2]);
    int ans = 0;
    rep(i, 0, n)
    {
        ans += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int task[3];
int i;
for(i=0;i<3;i++)
scanf("%d",&task[i]);
int tmp;
int j;
for(i=0;i<2;i++)
for(j=i+1;j<3;j++)
if(task[i]>task[j])
{
tmp=task[i];
task[i]=task[j];
task[j]=tmp;
}
printf("%d",task[2]-task[0]);
return 0;
}


Measured memory_bytes: 128
import kotlin.math.max

fun main() {
  val (K, X) = readInts()
  val result = mutableListOf<Int>()
  for (x in -1000000..1000000) {
    val d = if (x > X) x - X else X - x
    if (d < K) result.add(x)
  }
  println(result.joinToString(" "))
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

int main() {
  int N;
  cin >> N;
  int a,b,c;
  
  a = N%10;
  N = (N - a)/10;
  b = N%10;
  N = (N - b)/10;
  c = N%10;
  N = (N - c)/10;
  
  if(a==7 || b==7 || c==7) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    for(int i = 0; i < n - 2; i++){
        if(s.at(i) == 'A' && s.at(i+1) == 'B' && s.at(i+2) == 'C'){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

sortedA = sorted(A)
dic = {}
for i in range(N):
    dic[sortedA[i]] = i

ans = 0
for i in range(N):
    if i % 2 != dic[A[i]] % 2:
        ans += 1
print(ans//2)


Measured memory_bytes: 19872
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = [0]*13
    for k, v in c.items():
        if v >= 3 or k == 0:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        elif k == 12:
            cnt[12] += v
        else:
            s[k] += 1
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << 11):
        cur = cnt[:]
        for i in range(11):
            if s[i+1]:
                if bit & (1 << i):
                    cur[24 - (i+1)] += 1
                else:
                    cur[i+1] += 1
        if any(c >= 2 for c in cnt):
            continue
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne:
                if i - pre < mi:
                    mi = i - pre
                pre = i
        if mi != 24:
            ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42480
#include <cstdio>
#include <vector>
#include <algorithm>

using int64 = long long;

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> b(n);
  int64 ret = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    ret += x;
    b[i] = x + y;
  }
  std::sort(b.begin(), b.end());
  std::reverse(b.begin(), b.end());
  for (int i = 1; i < n; i += 2) ret -= b[i];
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 640
N=int(input())
X=list(map(int,input().split()))

X_sort=sorted(X)

med_n=X_sort[N//2-1]
med_p=X_sort[N//2]

for i in range(N):
    if X[i]<=med_n:
        print(med_p)
    else:
        print(med_n)


Measured memory_bytes: 25228
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;
map<int ,char> s;
int main()
{
	s[1] = s[3] = s[5] = s[7] = s[8] = s[10] = s[12] = 'A';
	s[4] = s[6] = s[9] = s[11] = 'B';
	s[2] = 'C';
	int n , m;
	cin >> n >> m;
	if(s[n] == s[m])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
	}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
vector<int> g[maxn], gc[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
    gc[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    g[v].push_back(u);
    g[u].push_back(v);
  }
  return true;
}

void dfs(int v, int p, int pc) {
  if (sz(g[v]) != 2) {
    if (pc != -1) {
      gc[v].push_back(pc);
      gc[pc].push_back(v);
    }
    pc = v;
  }
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i];
    if (u == p) {
      continue;
    }
    dfs(u, v, pc);
  }
}

void solve() {
  for (int v = 0; v < n; v++) {
    if (sz(g[v]) != 2) {
      dfs(v, -1, -1);
      break;
    }
  }
  int k = 0;
  for (int v = 0; v < n; v++) {
    if (sz(g[v]) != 2) {
      k++;
    }
  }
  if (k == 2) {
    printf("1\n");
    return;
  }
  int res = 0;
  for (int v = 0; v < n; v++) {
    if (sz(g[v]) == 2) {
      continue;
    }
    if (sz(gc[v]) == 1) {
      res++;
      continue;
    }
    bool leaf = false;
    for (int i = 0; i < sz(gc[v]); i++) {
      int u = gc[v][i];
      if (sz(gc[u]) == 1) {
        leaf = true;
        break;
      }
    }
    if (leaf) {
      res--;
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 12800
import java.util.*

fun main(args: Array<String>) {
    val N = nextInt()
    nextLine()
    val A = IntArray(N) { nextInt() }
    val C = IntArray(N + 1)
    var total = 0L
    A.forEach { a ->
        total += C[a]
        C[a]++
    }
    A.forEach { a ->
        println(total - (C[a] - 1)) // - nC2 + (n-1)C2 = -(n-1)
    }
}

val scanner = Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt() = scanner.nextInt()
fun nextLong() = scanner.nextLong()
fun nextLine() = scanner.nextLine()
fun nextList() = nextLine().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")

Measured memory_bytes: 73964
#include <bits/stdc++.h>
using namespace std;
bool used[27];
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		used[s[i]-'a']=1;
	}
	if(s.size()<26)
	{
		for(int i=0;i<26;i++)
		{
			if(!used[i])
			{
				s+=char('a'+i);
				break;
			}
		}
		cout<<s<<"\n";
		return 0;
	}
	int id=-1;
	for(int i=s.size()-2;i>=0;i--)
	{
		if(s[i]<s[i+1])
		{
			id=i;
			break;
		}
	}
	if(id==-1)
	{
		cout<<"-1\n";
		return 0;
	}
	string t=s.substr(0,id);
	int idx2=id+1;
	for(int i=id+1;i<s.size();i++)
	{
		if(s[i]<s[idx2] && s[i]>s[id])
			idx2=i;
	}
	t+=s[idx2];
	cout<<t<<"\n";
 	return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;


ll cmb[100][100];
int main(){
   ll n, m;
   cin >> n >> m;
   vector<ll> a(n), b(m);
   rep(i, n)cin >> a[i];
   rep(i, m)cin >> b[i];
   vector<ll> v;
   rep(i, n)v.push_back(a[i]);
   rep(i, m)v.push_back(b[i]);
   sort(ALL(v), greater<ll>());
   sort(ALL(a));
   sort(ALL(b));
   
   bool ff = true;
   rep(i, n - 1){
      if(a[i] == a[i + 1])ff = false;
   }
   rep(i, m - 1){
      if(b[i] == b[i + 1])ff = false;
   }
   if(!ff){
      cout << 0 << endl;
      return 0;
   }
   

   ll res = 1;
   a.push_back(INF);
   b.push_back(INF);
   REP(i, 1, n * m){
      ll acnt, bcnt;
      bool f = true;
      if(i == *lower_bound(ALL(a), i)){
         acnt = 1;
         f = false;
      }
      else acnt = a.end() - lower_bound(ALL(a), i) - 1;

      if(i == *lower_bound(ALL(b), i)){
         bcnt = 1;
         f = false;
      }
      else bcnt = b.end() - lower_bound(ALL(b), i) - 1;

      if(f){
         res = res * ((acnt * bcnt) % MOD - (m * n - i)) % MOD;
      }
      else res = res * (acnt * bcnt) % MOD;
   }
   cout << res << endl;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    int c = b - a;
    if(c <= 0) {
        cout << "delicious" << endl;
    } else if(c <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int num = 1, ans = 0, add = a - 1;
    while(num < b){
        num += add;
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}


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

int N, M, Q;
vector<int> a, b, c, d;
set<int> score_list;

void dfs(vector<int> &A){
   
    if(A.size() == 0){ //Aが空のとき（最初）
        for(int i=1; i<=M; i++){
            A.push_back(i);
            dfs(A);
            A.pop_back();
        }
    }
    
    else if(A.size() < N){
        for(int i=A.back(); i<=M; i++){
            A.push_back(i);
            dfs(A);
            A.pop_back();
        }
    }
    
    else{ // A.size() == N
        int score = 0;
        for(int i=0; i<Q; i++){
            if(A.at(b.at(i) - 1) - A.at(a.at(i) - 1) == c.at(i)) score += d.at(i);
        }
        score_list.insert(score);
    }

}

int main(){
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for(int i=0; i<Q; i++) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);

    vector<int> A;
    dfs(A);
    cout << *score_list.rbegin() << endl;
}

Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, M; 
  cin >> N >> M;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int sum = 0;
  REP(i, N) sum += A[i];

  int cnt = 0;
  REP(i, N){
    if(A[i]*4*M >= sum) cnt++;
  }

  if(cnt >= M) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

int main()
{
  int A,B;
  string S;
  cin >> A >> B;
  cin >> S;
  REP(i,A){
    if(S[i] > '9' || S[i] < '0'){
      cout << "No" << endl;
      return 0;
    }
  }
  if(S[A] != '-'){
    cout << "No" << endl;
    return 0;
  }
  REP(i,B){
    if(S[A+1+i] > '9' || S[A+1+i] < '0'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#define endl '\n'
using namespace std;
typedef long long int ll ;
const ll mod =1000000007;
ll pre[200005];
int main()
{
  ll n;
  cin>>n;ll ans=0;
  for(int i=1;i<=n;i++){
      ll cnt=0;
      ll val=i;
      while(val>0){
      cnt++;
      val/=10;}
      if(cnt%2==1) ans++;
  }
  cout<<ans<<endl;
    
}

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


#define ll long long

using namespace std;

ll n, p;
string s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> p >> s;

    if (p == 2) {
        ll ans = 0;
        for (ll i = n - 1; i >= 0; i--) {
            if ((s[i] - '0') % 2 == 0) {
                ans += i + 1;
            }
        }
        cout << ans;
        return 0;
    }

    if (p == 5) {
        ll ans = 0;
        for (ll i = n - 1; i >= 0; i--) {
            if (s[i] == '0' || s[i] == '5') {
                ans += i + 1;
            }
        }
        cout << ans;
        return 0;
    }
    vector<ll> d(p);

    ll pw = 1, num = 0;

    for (int i = n - 1; i >= 0; i--) {
        ll x = s[i] - '0';
        num = (num + x * pw) % p;
        d[num]++;
        pw = pw * 10 % p;
    }

    ll ans = 0;

    for (int i = 0; i < p; i++) {
        ans += d[i] * (d[i] - 1) / 2;
    }

    cout << ans + d[0];

    return 0;
}



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

int main()
{
    int a[3][3];
    int n;
    bool a_dash[3][3];
    int b[10];
    for( int i = 0; i < 3; i++ )
    {
        for( int j = 0; j < 3; j++ )
        {
            cin >> a[i][j];
            a_dash[i][j] = false;
        }
    }
    cin >> n;
    for( int i = 0; i < n; i++ )
    {
        cin >> b[i];
    }

    for( int i = 0; i < 3; i++ )
    {
        for( int j = 0; j < 3; j++ )
        {
            for( int k = 0; k < n; k++ )
            {
                if( a[i][j] == b[k] )
                {
                    a_dash[i][j] = true;
                }
            }
        }
    }

    for( int i = 0; i < 3; i++ )
    {
        if( a_dash[i][0] && a_dash[i][1] && a_dash[i][2] )
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    for( int i = 0; i < 3; i++ )
    {
        if( a_dash[0][i] && a_dash[1][i] && a_dash[2][i] )
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    /* 
    if( a_dash[0][0] && a_dash[1][1] && a_dash[2][2] )
    {
        cout << "Yes" << endl;
        return 0;
    }
    */

    if( a_dash[0][2] && a_dash[1][1] && a_dash[2][0] )
    {
        cout << "Yes" << endl;
        return 0;
    }
    int c = 0;
    for(int i = 0; i < 3; i++ )
    {
        for( int j = 0; j < 3; j++ )
        {
            if( i == j && a_dash[i][j] )
            {
                c++;
            }
        }
    }
    if(c== 3)
    {
        cout << "Yes" << endl;
        return 0;
    }


    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

static vector<large> leftsum(const vector<int>& v) {
    auto sums = vector<large>(v.size() + 1);
    for (auto i = 0; i < v.size(); ++i)
        sums[i + 1] = sums[i] + v[i];
    return sums;
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    auto a = vector<int>(n), b = vector<int>(m);
    for (auto& a_i : a)
        cin >> a_i;
    for (auto& b_i : b)
        cin >> b_i;

    auto asum = leftsum(a);
    auto bsum = leftsum(b);

    auto maxcnt = 0;
    for (auto i = 0; i < asum.size(); ++i) {
        if (asum[i] > k)
            break;

        auto L = 0, R = int(bsum.size());
        while (L + 1 < R) {
            auto m = L + (R - L) / 2;
            if (asum[i] + bsum[m] > k)
                R = m;
            else
                L = m;
        }

        auto cnt = i + L;
        maxcnt = max(maxcnt, cnt);
    }

    cout << maxcnt << endl;
    return 0;
}


Measured memory_bytes: 8020
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<sstream>
#include<fstream>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
/*freopen{"input.txt","r",stdin};
freopen{"output.txt","w",stdout};*/
#define mp make_pair
#define pb push_back
const int INF=1000*1000*1000;
const int maxn=2e5; 
typedef long long ll;
typedef long double ld;
typedef pair<int,int>PII;
//priority_queue <int,vector<int>,greater<int> > q1;  //从小到大 
//priority_queue <int,vector<int>,less<int> >q2;  //从大到小 

//set multiset vector queue priority_queue map multimap pair string structure 

//枚举 思维 贪心 搜索 模拟 预处理 二分 排序 

int main(){
	//ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	cout<<'x';
	
	
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

sort_A = sorted(A, reverse=True)
max_value = sort_A[0]
second_value = sort_A[1]

ans = []

for a in A:
    if a < max_value:
        ans.append(max_value)
    elif a == max_value:
        ans.append(second_value)

print(*ans, sep='\n')


Measured memory_bytes: 23664
#include <stdio.h>

int main()
{
    int i,n,m,a;
    int s=0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++) {
        scanf("%d",&a);
        s+=a;
    }
    if(n-s>=0) { printf("%d\n",n-s); }
    else { printf("-1\n"); }

    return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		int c0 = S.length() - S.replace("0", "").length();
		int c1 = S.length() - S.replace("1", "").length();

		System.out.println(2 * Math.min(c0, c1));

		sc.close();
	}
}

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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

using namespace std;

int main() {
  char a[3][3];

  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < 3; ++i) {
    cout << a[i][i];
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/c++io.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
 int x,y;
 cin>>x>>y;
if((x+y)%3==0||x%3==0||y%3==0)
    cout<<"Possible"<<endl;
else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <map>
#include <cmath>
using namespace std;
map<string,int> a,b;
int n,m;
string str;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>str;
		a[str]++;
	}
	cin>>m;
	for (int i=0;i<m;i++)
	{
		cin>>str;
		b[str]++;
	}
	int best=0;
	for (map<string,int>::iterator it=a.begin();it!=a.end();it++)
		best=max(best,it->second-b[it->first]);
	cout<<best<<endl;
	system("pause");
    return 0;
}

Measured memory_bytes: 504
#include <stdio.h>
 
#define max 1000000000000000000
 
long long a,sum=1;
double s=1;
 
int main(void){
    
    int n;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        
        scanf("%lld",&a);
        sum*=a;
        s*=a;
    }
    
    if(sum>max || s>max) printf("-1\n");
    else printf("%lld\n",sum);
    
    return 0;
    
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    while(1){
        int n,a[105];
        cin>>n;
        if(n==0)return 0;
        n++;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n;i++){
            vector<int>c;
            for(int j=0;j<n;j++)if(i!=j)c.push_back(a[j]);
            int d=c[1]-c[0];
            bool o=true;
            for(int j=0;j+1<c.size();j++)if(c[j+1]-c[j]!=d)o=false;
            if(o){
                cout<<a[i]<<endl;
                break;
            }
        }
    }
    
}



Measured memory_bytes: 3160
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  ll ans = 0;
  rep(i,1,n+1){
    if(i%3==0)continue;
    if(i%5==0)continue;
    ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	vector<int> a(5);
	rep(i, 5)scanf("%d", &a[i]);
	sort(all(a));
	int k;
	scanf("%d", &k);
	printf("%s\n", a[4] - a[0] <= k ? "Yay!" : ":(");

	Please AC;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int mod = (int)1e9+7;
const int nax = 3004;

ll dp[nax][nax];
ll a[nax];
int n;
ll sum = 0;

ll solve(int i, int j){	
	if(i>j)
		return 0;
	if(i==j)
		return a[i];
	if(dp[i][j]!=-1)
		return dp[i][j];
	ll ans = 0;
	ans = max(a[i] + min(solve(i+2,j),solve(i+1,j-1)),
			  a[j] + min(solve(i+1,j-1),solve(i,j-2))
			 );
	return dp[i][j] = ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++)
			dp[i][j] = -1;
	}
	ll taro = solve(0,n-1);
	ll zira = sum - taro;
	cout<<taro-zira;
 
 
    return 0;
}









Measured memory_bytes: 70784
def main()->None:
    N = int(input())
    A = map(int, input().split())

    odd_count = 0
    for a in A:
        if a % 2 == 1:
            odd_count += 1

    if odd_count % 2 == 0:
        print("YES")
    else:
        print("NO")



if __name__ == "__main__":
    main()

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



int32_t main(){
    int n;cin>>n;
    vector<int> v(n);
    for(int &i : v) cin>>i;
    int xor_of_all=accumulate(v.begin(),v.end(),0ll,[](int a,int b){return a^b;});
    for(int &i : v){
        i^=xor_of_all;
        cout<<i<<" ";
    }
    return 0;
}

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

signed main() {
    int N, C;
    cin >> N >> C;

    vector<vector<int>> D(C, vector<int> (C));
    for (auto& v : D) for (int& e : v) cin >> e;

    vector<vector<int>> c(N, vector<int> (N));
    vector<vector<int>> c_cnt(3, vector<int> (C));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
            --c[i][j];
            c_cnt[(i + j) % 3][c[i][j]]++;
        }
    }

    int ans = 1LL << 62;
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            if (i == j) continue;
            for (int k = 0; k < C; k++) {
                if (k == i || k == j) continue;

                int t = 0;
                for (int a = 0; a < C; a++) {
                    t += D[a][i] * c_cnt[0][a];
                    t += D[a][j] * c_cnt[1][a];
                    t += D[a][k] * c_cnt[2][a];
                }

                ans = min(ans, t);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<P> v;
	rep(i,m){
		int a, b;
		cin >> a >> b;
		--a; --b;
		v.emplace_back(b, a);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	int l = -1, r = INF;
	rep(i,m){
		chmax(l, v[i].second);
		chmin(r, v[i].first);
		if(r <= l){
			++ans;
			l = v[i].second;
			r = v[i].first;
		}
	}
	if(r != INF) ++ans;
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n = 0;
  for (int i = 0; i < 4; i++){
    if (s.at(i) == '+'){
      n++;
    }
    else {
      n--;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end

A, B = gli

def can_calc?(a, b)
  1 <= a && a <= 9 && 1 <= b && b <= 9
end

puts can_calc?(A, B) ? A * B : -1


Measured memory_bytes: 1788