akhauriyash/Code-Regression huggingface dataset:
from collections import deque
# H,Wの向きに注意
H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[0 for i in range(W)] for j in range(H)]

def bfs(q):
    tmp=deque(q)
    ch = [[False for i in range(W)] for j in range(H)]
    count = 0
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<H and 0<=ny<W:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    V[nx][ny]=V[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
            else:
                continue
ju=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            ju.append([i,j])
bfs(ju)
for i in range(H):
    for j in range(W):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])
print(ans)



Measured memory_bytes: 165128
import math
 
def main():
    H = int(input())
    W = int(input())
    N = int(input())
 
    if H >= W:
        h = H
        w = W
    else:
        h = W
        w = H
    
    ans = math.ceil(N / h)
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i = x;i<n;i++)
#define S(v) sort(v.begin(), v.end());
#define ff first
#define ss second


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	// freopen("in.txt","r", stdin);
	ll n;
	cin>>n;
	vector<ll> v(n);
	loop(i,0,n)cin>>v[i];
	S(v);
	ll x = (n+1)/2;
	cout<<v[x] - v[x - 1];
}

Measured memory_bytes: 3964
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    H = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    attack = 1
    while H > 1:
        ans += attack
        attack *= 2
        H = H // 2
    print(ans + attack)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9180
# -*- coding: utf-8 -*-

N,L = list(map(int, input().split()))
alist = list(map(int, input().split()))
arr = []
for i in range(L):
  while arr and alist[i] <= alist[arr[-1]]:
    arr.pop()
  arr.append(i)
for i in range(L, N):
  print(alist[arr[0]], end=' ')
  while arr and arr[0] <= i-L:
    arr.pop(0)
  while arr and alist[i] <= alist[arr[-1]]:
    arr.pop()
  arr.append(i)
print(alist[arr[0]])



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

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

    range (i, 1, m + 1) {
        rep (j, n - 1) if (a[j] % i > a[j + 1] % i) swap(a[j], a[j + 1]);
    }

    rep (i, n) cout << a[i] << endl;

    return 0;
}


Measured memory_bytes: 3112
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, K = MAP()

if -(-N//2) >= K:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 5144
s = str(input())
a = "abcdefghijklmnopqrstuvwxyz"
count = 0
n = 0
for i in range(len(a)):
    for j in range(len(s)):
        if a[i] == s[j]:
            count += 1
            break
    if count == 0:
        ans = a[i]
        print(ans)
        n = 1
        break
    else:
        count = 0
if n == 0:
    print("None")

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main {
	public static int MMAX = 5000 + 1;
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int z = sc.nextInt();
			if (x+y+z==0) {
				break;
			}
			int v[] = new int[x];
			for (int i=0;i<x;i++) {
				v[i] = sc.nextInt();
			}
			double p[][] = new double[y+1][MMAX];
			p[0][0]=1.0d;
			int event[] = new int[y+1];
			int eventa[] = new int[y+1];
			for (int i=0;i<z;i++) {
				int n = sc.nextInt();
				int e = sc.nextInt();
				int a = sc.nextInt();
				event[n]=e;
				eventa[n]=a;
			}
			//System.out.println("----");
			for (int i=0;i<y;i++) {
				for (int m=0;m<MMAX;m++) {
					if (p[i][m]==0.0) {
						continue;
					}
					//System.out.println(i+","+m+","+p[i][m]);
					for (int j=0;j<x;j++) {
						int money = m;
						int target = i+v[j];
						if (target>y) {
							target=y;
						}
						switch (event[target]) {
						case 1:
							target+=eventa[target];
							if (target>y) {
								target=y;
							}
							break;
						case 2:
							money+=eventa[target];
							break;
						case 3:
							money-=eventa[target];
							if (money<0) {
								money = 0;
							}
							break;
						}
						p[target][money]+=p[i][m]/x;
						//System.out.println(i+" To "+target+" :p="+p[i][m]/x+" : money=" + m + " To "+money);
					}
				}
			}
			double ans = 0.0;
			for (int i=0;i<MMAX;i++) {
				ans+=p[y][i]*i;
			}
			System.out.println((int) ans);
		}
	}
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

bool ok(string s)
{
	int n=s.size();
	return n%2==0&& s.substr(0,n/2)==s.substr(n/2);
}

int count(string s)
{
	int n=s.size();
	int res=0;
	rep(i,1<<n){
		string t;
		rep(j,n)
			if(i>>j&1)
				t+=s[j];
		res+=ok(t);
	}
	return res;
}

void test()
{
	dump(count("aa"));
	dump(count("abab"));
	dump(count("abba"));
	dump(count("abcabc"));
	dump(count("abccab"));
	dump(count("abcdcabd"));
	dump(count("abcddcab"));
}

int main()
{
	for(ll n;cin>>n&&n;){
		n++;
		int m=64-__builtin_clzll(n);
		deque<int> a,b;
		int c=0;
		per(i,m-1){
			a.push_back(++c);
			b.push_back(c);
			if(n>>i&1){
				a.push_back(++c);
				b.push_front(c);
			}
		}
		cout<<2*c<<endl;
		rep(i,a.size()) cout<<a[i]<<' ';
		rep(i,b.size()) cout<<b[i]<<" \n"[i+1==b.size()];
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<vector<int> > s(m);
    for(int i = 0;i < m;i++)
    {
        int k;
        cin >> k;
        for(int j = 0;j < k;j++)
        {
            int a;
            cin >> a;
            s[i].push_back(a - 1);
        }
    }
    int p[m];
    for(int i = 0;i < m;i++)
    {
        cin >> p[i];
    }
    int ans = 0;
    for(int bit = 0;bit < (1 << n);bit++)
    {
        bool flag = true;
        for(int i = 0;i < m;i++)
        {
            int count = 0;
            for(int j = 0;j < s[i].size();j++)
            {
                if(bit & (1 << s[i][j]))
                {
                    count++;
                }
            }
            if(count % 2 != p[i])
            {
                flag = false;
            }
        }
        if(flag)
        {
            ans++;
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define _A_ true
using namespace std;
 
int main(){
  int n,AC=0,strA,strB;
  int dp[1010][1010];
  char *A = new char[1500];
  char *B = new char[1500];
 
  scanf("%d",&n);
  while(_A_){
    if(AC == n)break;
    scanf("%s",A);
    scanf("%s",B);
    for(int i=0;i<1010;i++)for(int j=0;j<1010;j++)dp[i][j]=0;
strA = strlen(A); 
strB = strlen(B);

    for(int i=0;i<strA;i++){
      for(int j=0;j<strB;j++){
    if(A[i] == B[j]){
      dp[i+1][j+1]=dp[i][j]+1;
    }
    else{
      if(dp[i+1][j] > dp[i][j+1]){
        dp[i+1][j+1]=dp[i+1][j];
      }
      else {
        dp[i+1][j+1] = dp[i][j+1];
      }
    }
      }
    }
    printf("%d\n",dp[strA][strB]);
    AC++;
  }
  delete [] A;
  delete [] B;
 
  return 0;
}

Measured memory_bytes: 4908
if __name__ == '__main__':
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())

    answer = 0
    for i in range(A+1):
        for j in range(B+1):
            for k in range(C+1):
                if X == 500 * i + 100 * j + 50 * k:
                    answer += 1
    print(answer)

Measured memory_bytes: 3060
/*
 * hoge.c
 *
 *  Created on: 2017/08/26
 *      Author: CuSO4
 */


#include <stdio.h>

int main(){
	int i,j;
	for(i=1;i<10;i++){
		for(j=1;j<10;j++){
			printf("%dx%d=",i,j);
			int a = i * j;
			printf("%d\n",a);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include<stdio.h>

int main(){
  int A[100], n, i, j, t, sw = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j] < A[j-1] ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
	sw++;
      }
    }
  }

  for ( i = 0; i < n; i++ ){
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}




Measured memory_bytes: 2696
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<algorithm>
#include<queue>
#include<vector>
#include<time.h>
using namespace std;
const int INF=1<<30;
typedef long long ll;
const double eps=1e-8;


const double g=9.8;

int n,m;
double v,x,y;

struct point{
    double x,y;
};

struct Matrix{
    point a,b,c,d;
}e[100];

double gety(double vy,double t){
    return vy*t-0.5*g*t*t;
}

int cmp(double l,double r,double a){
    return a<l+eps?-1:a>r-eps?1:0;
}

bool juge(point Q){
    int i,j,k;
    double a=0.25*g*g,b=g*Q.y-v*v,c=Q.x*Q.x+Q.y*Q.y;
    double D=(b*b-4.0*a*c);
    if(D<0&&D>-eps)D=0;
    if(D<0)return false;
    for(i=-1;i<=1;i+=2){
        double t=(i*sqrt(D)-b)/(2.0*a);
        if(t<=0)continue;
        double t1=sqrt(t);
        double vx=Q.x/t1,vy=(0.5*g*t+Q.y)/t1;
        double yt=gety(vy,x/vx);
        if(yt<y-eps)continue;

        bool ok=true;
        for(j=0;j<n;j++){
            if(e[j].a.x>=x)continue;
            if(yt>=e[j].a.y&&y<=e[j].c.y&&e[j].d.x==x)ok=false;

            int yL=cmp(e[j].c.y,e[j].a.y,gety(vy,e[j].a.x/vx));
            int yR=cmp(e[j].d.y,e[j].b.y,gety(vy,e[j].b.x/vx));
            int xH=cmp(e[j].a.x,e[j].b.x,vx*(vy/g));
            int yH=cmp(e[j].c.y,e[j].a.y,gety(vy,(vy/g)));
            if(xH==0&&yH>=0&&yL<0)ok=false;
            if(yL*yR<=0)ok=false;
        }
        if(ok)return true;
    }
    return false;
}

int main()
{
    int i,j;
    cin>>n>>v>>x>>y;
    int cnt=0;
    for(i=0;i<n;i++){
        double x1,y1,x2,y2;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        if(x1>=x)continue;
        if(x2>x)x2=x;
        point a,b,c,d;
        a.x=x1,a.y=y2;
        b.x=x2,b.y=y2;
        c.x=x1,c.y=y1;
        d.x=x2,d.y=y1;
        e[cnt].a=a,e[cnt].b=b,e[cnt].c=c,e[cnt++].d=d;
    }
    n=cnt;
    int ok=0;
    point W;W.x=x,W.y=y;
    if(juge(W))ok=1;
    if(ok){
        printf("Yes\n");
        return 0;
    }
    for(i=0;i<n;i++){
        if(juge(e[i].a)||juge(e[i].b))ok=1;
    }
    if(ok)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1244
#include <iostream>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;

    int total = 0;
    for (int i = 0; i < 2; i++) {
        if (A >= B) {
            total += A;
            A--;
        } else {
            total += B;
            B--;
        }
    }

    cout << total << endl;

    return 0;
}


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

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

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

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

template<class T, class U>inline bool chmax(T &a, const U &b) { if(a<b){ a=b; return 1; } return 0; }
template<class T, class U>inline bool chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }


int main() {
  int n, m; cin>>n>>m;
  vector<int> p(n), b(n, 0);
  rep(i, m) {
    int t;
    string s;
    cin>>t>>s; --t;
    if (b[t] == 1) continue;
    else {
      if (s == "AC") b[t] = 1;
      else ++p[t];
    }
  }
  int ans1 = 0, ans2 = 0;
  rep(i, n) if (b[i] == 1) {
    ++ans1;
    ans2 += p[i];
  }
  print(ans1, ans2);

  return 0;
}

Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
n=int(input())
b_list=list(map(int,input().split()))
ans=0
for i in range(n):
    if i==0:
        ans+=b_list[0]
    elif i==n-1:
        ans+=b_list[n-2]
    else:
        ans+=min(b_list[i-1],b_list[i])
print(ans)



Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#define min(a,b) ((a)<(b)?(a):(b))
char s[1003],t[1003];
int lens,lent,ans=1<<30,sum;//sum为每一次需要改动的字符串个数
int main(){
    scanf("%s%s",s,t);
    lens=strlen(s),lent=strlen(t);
    for(int i=0;i<lens-lent+1;i++){//枚举左边界
        sum=0;//清0
        for(int j=0;j<lent;j++) if(s[i+j]!=t[j]) ++sum;
        //判断，如果跟t[j]不一样则改动
        ans=min(ans,sum);//取最小值
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vecl = vector<ll>;
using Graph = vector<vector<int>>;
/* #1 想定解（queueを用いた解法）

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K;
  cin >> K;
  ll num = 0;
  queue<ll> que;
  REP(i, 9) que.push(i + 1);
  while (K > 0) {
    num = que.front();
    //    cout << num << " ";
    if (num % 10 != 0) que.push(10 * num + num % 10 - 1);
    que.push(10 * num + num % 10);
    if (num % 10 != 9) que.push(10 * num + num % 10 + 1);
    que.pop();
    K--;
  }
  cout << num << endl;
  return 0;
}
*/

// #2 DFSを用いた解法
vector<ll> LIST;

void dfs(ll num, ll k) {
  if (k == 0) {
    LIST.push_back(num);
    return;
  } else if (num == 0) {
    REP(i, 10) dfs(i * pow(10, k - 1), k - 1);
    return;
  }
  ll p = pow(10, k);
  ll x = (num / p) % 10;
  if (x != 0) dfs(num + (x - 1) * pow(10, k - 1), k - 1);
  dfs(num + x * pow(10, k - 1), k - 1);
  if (x != 9) dfs(num + (x + 1) * pow(10, k - 1), k - 1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K;
  cin >> K;
  //  REP(i, 8) LIST.push_back(i + 2);
  dfs(0, 10);
  sort(LIST.begin(), LIST.end());
  // REP(n, 30) cout << LIST.at(n) << " ";
  cout << LIST.at(K) << endl;
  return 0;
}

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

vector<string> split(string& str, char delim) {
    stringstream ss(str);
    vector<string> res;
    string tmp;
    while(getline(ss, tmp, delim)){
        if(tmp.size() >= 3 && tmp.size() <= 6) res.push_back(tmp);
    }
    return(res);
}

void solve() {
    //カンマで統一
    for(int r = 0; r < input.length(); r++)if(input[r] == ' ' || input[r] == '.')input[r] = ',';
    vector<string> ans = split(input, ',');//分割
    for(int r = 0; r < ans.size(); r++) { //表示
        if(ans[r].size() >= 3 && ans[r].size() <= 6) {
            cout << ans[r];
            if(r == ans.size() - 1) putchar('\n');
            else putchar(' ');
        }
    }
    //cout << ans.size() << endl;
}

int main(void) {
    getline(cin, input);
    solve();
    return(0);
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
const ll SIZE = 1e5 + 10;


#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

vector<pair<ll, ll>> vec;

int main() {
    fastInp;

    ll n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        ll num;
        cin >> num;
        vec.push_back({ num, i });
    }
    
    sort(vec.begin(), vec.end());

    ll ans = 0;
    for (int i = 0; i < vec.size(); i++) {
        if ((vec[i].second % 2) != (i % 2)) ans++;
    }
    cout << ans / 2;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>

using namespace std;
int main(void){
    // Your code here!
    int k, s;
    cin >> k >> s;
    
    long long count = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s - x - y;
            if(0 <= z && z <= k) count++;
        }
    }
    
    cout << count << endl;
    return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  
  vector<vector<char>> data(n, vector<char>(n));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> data.at(i).at(j);
    }
  }
  
  vector<vector<char>> part(m, vector<char>(m));
  for(int i = 0; i < m; i++){
    for(int j = 0; j < m; j++){
      cin >> part.at(i).at(j);
    }
  }
  
  bool ok = false;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(j + m > n || i + m > n )
        continue;
      
      bool out = true;
      for(int a = 0; a < m; a++){
        for(int b = 0; b < m; b++){
          if(part.at(a).at(b) != data.at(i+a).at(j+b)){
            out = false;
          }
        }
      }
      if(out){
        ok = true;
      }
    }
  }
  
  if(ok)
    cout << "Yes" << endl;
 
  else
    cout << "No" << endl;            
}
 

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int K;
signed main(){
    scanf("%lld",&K);
    vector<int> runrun;
    queue<int> q;
    rep(i,9)q.push(i+1);
    while(!q.empty()){
        int a=q.front();q.pop();
        runrun.pb(a);
        //下に付け足す
        int s=a%10;
        for(int i=max((int)0,s-1);i<=min(s+1,(int)9);i++){
            int b=a*10+i;
            //10^5こめより小さい時だけpush
            if(b<=(int)3234566667)q.push(b);
        }  
    }
    sort(runrun.begin(),runrun.end());
    printf("%lld\n",runrun[K-1]);
    return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1001001001001001;


//N^P(modM)

using ll = long long int;
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}



int main() {
  ll n;
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  ll ans=0;
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,29){
    vector<ll> a1(n);
    vector<ll> b1(n);
    ll pn=RepeatSquaring(2,i,INF);
    //cout<<pn<<endl;
    rep(j,n){
      a1[j]=a[j]%(pn*2);
      b1[j]=b[j]%(pn*2);
    }
    sort(a1.begin(),a1.end());
    sort(b1.begin(),b1.end());
  //  cout<<a1[0]<<' '<<a1[1]<<' '<<b1[0]<<' '<<b1[1]<<endl;
    ll cnt=0;

    rep(j,n){
      ll now=a1[j];
      ll id1=lower_bound(b1.begin(),b1.end(),pn-now)-b1.begin();
      ll id2=lower_bound(b1.begin(),b1.end(),pn*2-now)-b1.begin();
      ll id3=lower_bound(b1.begin(),b1.end(),pn*3-now)-b1.begin();
      ll id4=lower_bound(b1.begin(),b1.end(),pn*4-now)-b1.begin();
      cnt+=(id2-id1+id4-id3);
  ///    cout<<a1[j]<<' '<<cnt<<'c'<<j<<'j'<<i<<'I'<<endl;
    }

    if ((cnt%2)==1) ans+=pn;


  }
cout<<ans;
}


Measured memory_bytes: 6548
import sys
N, M = map(int, input().split())
num = [0] * (N + 1)
reg = [0] * (N + 1)
if N > 1:
  num[1] = 1

for i in range(M):
  s, c = map(int, input().split())
  if N > 1 and s == 1 and c == 0:
    print (-1)
    sys.exit()
  if reg[s] == 1 and num[s] != c:
    print (-1)
    sys.exit()
  num[s] = c
  reg[s] = 1

result = ""
for i in range(1, N + 1):
  result += str(num[i])
print (result)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int dp[2160][2160];
Int res;
Int n;
string str;
Int fact[1080000];
Int revfact[1080000];
Int rev[1080000];

void init(){
  Int m = MOD;
  fact[0] = 1;
  revfact[0] = 1;
  rev[0] = 0;
  rev[1] = 1;
  for(int i = 1;i < 1080000;i++){
    fact[i] = fact[i-1] * i % m;
    if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD;
    revfact[i] = revfact[i-1] * rev[i] % MOD;
  }
}

class Initter{
public:
  Initter(){
    init();
  }
};
Initter initter;
Int nCk(Int n, Int k){
  if(n < k)return 0;
  if(k < 0)return 0;
  return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD;
}

Int cntr, cntb;

int main(){
  dp[0][0] = 1;
  cin >> str;
  n= str.size();
  for(int i = 1;i <= n;i++){
    char s = str[i-1];
    s -= '0';
    cntr += 2 - s;
    cntb += s;
    for(int j = 0;j <= n;j++){
      if(cntr - j > 0){
	dp[i][j+1] += dp[i-1][j];
	dp[i][j+1]%=MOD;
      }
      if(cntb - (i-j-1) > 0){
	dp[i][j] += dp[i-1][j];
	dp[i][j] %= MOD;
      }
    }
  }
  for(int j = 0;j <= n;j++){
    //    cout << dp[n][j] << endl;
    res += dp[n][j] *nCk(n, cntr-j) %MOD;
    res %= MOD;
  }cout << res << endl;
  return 0;
}

Measured memory_bytes: 59776
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int N;
    cin >> N;
    int A[N];
    int minimum = MOD;
    long long sum = 0;
    int count = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += abs(A[i]);
        if (A[i] < 0) count++;
        minimum = min(minimum, abs(A[i]));
    }
    cout << (count % 2 == 0 ? sum : sum - 2 * minimum) << endl;
    return 0;
}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u32,
        b: u32
    }
    println!("{}", (a-1) * (b-1));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
bool check(int x,int y, int z) {
  if(x<0 || x>=5) return false;
  if(y<0 || y>=5) return false;
  if(z<0 || z>=5) return false;
  return true;
}
 
int main() {
  int n,t=1;
  while(cin >> n && n) {
    int a[5][5][5];
    for(int i=0; i<5; i++) {
      for(int j=0; j<5; j++) {
    string s;
    cin >> s;
    for(int k=0; k<5; k++) {
      if(s[k]=='1') a[i][j][k]=1;
      else a[i][j][k]=0;
    }
      }
    }
    int m1,m2;
    set<int> s1,s2;
    cin >> m1;
    while(m1--) {
      int x;
      cin >> x;
      s1.insert(x);
    }
    cin >> m2;
    while(m2--) {
      int x;
      cin >> x;
      s2.insert(x);
    }
    while(n--) {
      int b[5][5][5];
      for(int i=0; i<5; i++) {
    for(int j=0; j<5; j++) {
      for(int k=0; k<5; k++) b[i][j][k]=a[i][j][k];
    }
      }
      for(int i=0; i<5; i++) {
    for(int j=0; j<5; j++) {
      for(int k=0; k<5; k++) {
        int cnt=0;
        for(int dx=-1; dx<=1; dx++) {
          for(int dy=-1; dy<=1; dy++) {
        for(int dz=-1; dz<=1; dz++) {
          int x=i+dx,y=j+dy,z=k+dz;
          if(x==i && y==j && z==k) continue;
          if(check(x,y,z)) cnt+=b[x][y][z];
        }
          }
        }
        if(b[i][j][k]) {
          if(!s2.count(cnt)) a[i][j][k]=0;
        } else {
          if(s1.count(cnt)) a[i][j][k]=1;
        }
      }
    }
      }
    }
    if(t>1) cout << endl;
    cout << "Case " << t++ << ":" << endl;
    for(int i=0; i<5; i++) {
      if(i) cout << endl;
      for(int j=0; j<5; j++) {
    for(int k=0; k<5; k++) cout << a[i][j][k];
    cout << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1212
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto nmq = readln.chomp.split.to!(long[]);
    long N = nmq[0];
    long M = nmq[1];
    long Q = nmq[2];
    long[] L = new long[](M);
    long[] R = new long[](M);
    long[] Qp = new long[](Q);
    long[] Qq = new long[](Q);

    foreach (i; 0 .. M)
    {
        auto lr = readln.chomp.split.to!(long[]);
        L[i] = lr[0];
        R[i] = lr[1];
    }
    foreach (i; 0 .. Q)
    {
        auto pq = readln.chomp.split.to!(long[]);
        Qp[i] = pq[0];
        Qq[i] = pq[1];
    }

    long[][] table = new long[][](N + 1, N + 1);
    foreach (t; zip(L, R))
        table[t[0]][t[1]]++;

    foreach (i; 1 .. N + 1)
        foreach (j; 1 .. N + 1)
        {
            table[i][j] += table[i][j - 1];
            table[i][j - 1] += table[i - 1][j - 1];
        }

    foreach (i; 1 .. N + 1)
        table[i][N] += table[i - 1][N];

    // table.writeln;

    foreach (query; zip(Qp, Qq))
    {
        long result = table[query[1]][query[1]];
        result -= table[query[1]][query[0] - 1];
        result -= table[query[0] - 1][query[1]];
        result += table[query[0] - 1][query[0] - 1];
        result.writeln;
    }
}


Measured memory_bytes: 9724
#include<iostream>

using namespace std;

 int A,B,K,M;
 
 
 int main(){

  cin >> A >> B >> K;
  M = min (A, B);
  
  for (int i = M; i >=1; --i) {
   if (A% i == 0 && B% i== 0){
   --K;
   if (K == 0) {
    cout << i  << endl;
   }
  }
 }

 return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<cstring>
#define N 40010
#define M N*100
#define N1 110
#define ll long long
#define inf 1000000000
using namespace std;
struct node{
	int nxt,to;
	ll f;
}road[M];
int head[N],cur[N],cnt=1;
void add(int u,int v,ll f)
{
	road[++cnt]=(node){head[u],v,f};
	head[u]=cnt;
	road[++cnt]=(node){head[v],u,0};
	head[v]=cnt;
}
queue<int>q;
int dep[N];
bool bfs(int s,int t)
{
	memcpy(cur,head,sizeof(cur));
	memset(dep,127,sizeof(dep));
	dep[s]=0;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=road[i].nxt)
		if(road[i].f>0)
		{
			int v=road[i].to;
			if(dep[v]>=inf)
			{
				dep[v]=dep[u]+1;
				q.push(v);
			}
		}
	}
	return dep[t]<=inf;
}
ll dfs(int u,int t,ll flow)
{
	if(u==t || !flow) return flow;
	ll ans=0;
	for(int i=cur[u];i;i=road[i].nxt)
	{
		cur[u]=i;
		int v=road[i].to,f=0;
		if(dep[v]==dep[u]+1 && (f=dfs(v,t,min(flow,road[i].f))))
		{
			flow-=f;
			ans+=f;
			road[i].f-=f;
			road[i^1].f+=f;
			if(!flow) break;
		}
	}
	return ans;
}
ll dinic(int s,int t)
{
	ll ans=0;
	while(bfs(s,t)) ans+=dfs(s,t,inf);
	return ans;
}
int n,m;
int id(int x,int y){return (x-1)*m+y;}
int ids(int x,int o){return x*2+o;}
void add_e(int x,int y)
{
	add(ids(x,1),ids(y,0),inf);
	add(ids(y,1),ids(x,0),inf);
}
char str[N1][N1];
int main()
{
	scanf("%d%d",&n,&m);
	int s=(n*m)*2+2,t=s+1;
	for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		if(str[i][j]!='.')
		{
			for(int k=i+1;k<=n;k++)
			if(str[k][j]!='.')
				add_e(id(i,j),id(k,j));
			for(int k=j+1;k<=m;k++)
			if(str[i][k]!='.')
				add_e(id(i,j),id(i,k));
			if(str[i][j]=='S')
				add(s,ids(id(i,j),0),inf),add(ids(id(i,j),0),ids(id(i,j),1),inf);
			else if(str[i][j]=='T')
				add(ids(id(i,j),1),t,inf),add(ids(id(i,j),0),ids(id(i,j),1),inf);
			else add(ids(id(i,j),0),ids(id(i,j),1),1);
		}
	ll ans=dinic(s,t);
	printf("%lld\n",ans>=inf?-1:ans);
	return 0;
}


Measured memory_bytes: 62848
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	string S; cin >> S;
	bool r = false, l = false;
	for (int i = 0; i < S.size(); i++) {
		if (i % 2 == 1 && S[i] == 'R') r = true;
		if (i % 2 == 0 && S[i] == 'L') l = true;
	}

	if (r || l) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

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

const int N=1000010;

ll gcd(ll m, ll n) {//最大公約数
    if (n == 0)return m;
    return gcd(n, m % n);
}//gcd


int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> c(N,0);
  rep(i,n){
    cin>>a[i];
    c[a[i]]++;
  }
  bool pairwise=1;
  for(int i=2; i <= N; i++){
    int cnt=0;
    for(int j=i; j <=N; j+=i){
      cnt+=c[j];
    }
    if(cnt>1) pairwise=0;
  }
  if(pairwise){
    cout<<"pairwise coprime"<<endl;
    return 0;
  }
  int p=0;
  rep(i,n){
    p=gcd(p,a[i]);
  }
  if(p==1) cout<<"setwise coprime"<<endl;
  else cout<<"not coprime"<<endl;
}

Measured memory_bytes: 11080
#include <iostream>
#include <vector>
#include <set>

#define int long long

using namespace std;

void rec(int n, int len, vector<int> &v) {
  	v.push_back(n);
  	if (len >= 10) return;
  
  	int d = n % 10;
  	if (d > 0) rec(n * 10 + d-1, len+1, v);
  	if (d < 9) rec(n * 10 + d+1, len+1, v);
  	rec(n * 10 + d, len+1, v);
}

signed main() {
	int K;
  	cin >> K;
  	vector<int> v;
  	for (int i = 1; i < 10; i++) rec(i, 1, v);
  	set<int> s;
    for (int e : v) s.insert(e);
  	v.assign(s.begin(), s.end());
  	cout << v[K-1] << endl;
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5, mod = 1e9 + 7;
vector<int> g[maxn];
vector<pair<int, int> > ans;
int deg[maxn], dep[maxn];

void dfs(int u, int p)
{
    for (auto v : g[u]){
        if (dep[v] == 0){//树边
            dep[v] = dep[u] + 1;
            dfs(v, u);
        }else{//非树边
            if (dep[v] > dep[u]){//连回祖先了，祖先往子孙连
                ans.emplace_back(make_pair(u, v));
                ++deg[u];
            }
        }
    }

    if (deg[u] & 1){
        if (p != 0){
            ans.emplace_back(make_pair(u, p));
            ++deg[u];
        }
    }else{
        if (p != 0){
            ans.emplace_back(make_pair(p, u));
            ++deg[p];
        }
    }
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);

    int n, m;
    cin >> n >> m;
    if (m & 1){
        cout << "-1" << endl;
        return 0;
    }
    while (m--){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dep[1] = 1;
    dfs(1, 0);
    for (auto e : ans) cout << e.first << " " << e.second << '\n';
    return 0;
}


Measured memory_bytes: 14836
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, K;
  cin >> N >> K;
  long long v = K;

  for (int i = 1; i < N; i++) v *= (K-1);
  cout << v << endl;
}


Measured memory_bytes: 256
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
		int A = one.get(0);
		int B = one.get(1);
		int output = Math.max(A + B, Math.max(A - B, A * B));
		myout(output);
	}
	//Method addition frame start




	//Method addition frame end
}


Measured memory_bytes: 32948
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007
#define MEM_SIZE = 1e5+5;

// vector<int> DP[MEM_SIZE]

void solve(void)
{

  int N;
  string str;
  cin>>N;
  cin>>str;
  int ANS = 0;
  for (int i = 0; i < N-2; i++)
  {
    if((str[i] == 'A') && (str[i+1] == 'B') &&(str[i+2] =='C'))ANS++;
  }

  cout<<ANS<<endl;
  
  return;
  
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

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

public class Main{
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			
			int[]a = new int[N];
			for(int i = 0;i<N;i++)a[i] = scan.nextInt();
			
			
			Arrays.sort(a);
			
			int min = a[0];
			int max = a[N-1];
			
			long mincost = Integer.MAX_VALUE;
			
			for(int i = min;i<=max;i++) {
				long cost = 0;
				
				for(int j = 0;j<N;j++) {
					cost+=(a[j]-i)*(a[j]-i);
				}
				
				if(mincost>cost)mincost = cost;
				
				
			}
			
			
			System.out.println(mincost);
			
			
			
			
			
			
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 23252
la = [1,3,5,7,8,10,12]
lb = [4,6,9,11]
lc = [2]

x, y = map(int, input().split())

if x in la and y in la:
  print('Yes')
elif x in lb and y in lb:
  print('Yes')
elif x in lc and y in lc:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<String> list = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			String s = sc.next().chars()
		    	      .sorted()
		    	      .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
		    	      .toString();
			list.add(s);
		}
		list.sort(null);
		list.add("");
		
		sc.close();
		
		long count = 1;
		long result = 0;
		for(int i = 1; i < list.size(); i++) {
			if(list.get(i).equals(list.get(i - 1))) {
				count++;
			}
			else {
				result += (count * (count - 1))/2;
				count = 1;
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 67296
-- unihernandez22
-- https://atcoder.jp/contests/abc146/tasks/abc146_b
-- implementation

import Data.Char

solve n c =
  chr $ ( (ord c) + n - 65 ) `mod` 26 + 65

main = do
  li <- getLine
  let n = read li
  s <- getLine
  putStrLn $ map (solve n) s



Measured memory_bytes: 5020
#include <bits/stdc++.h>
using namespace std;
const int N = 310;
int ptr[N], a[N][N], cnt[N];
bool mark[N];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < m; j ++)
            cin >> a[i][j];
    int ans = n;
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
           // for(int x = 0; x < n; x ++)
             //   cout << ptr[x] << " ";
         //   cout << endl;
           // for(int j = 1; j <= m; j ++)
            //    cout << cnt[j] << " ";
           // cout << endl;
            for(int x = 1; x <= m; x ++)
                cnt[x] = 0;
            for(int r = 0; r < n; r ++)
                cnt[a[r][ptr[r]]] ++;
            int mx = 0;
            for(int x = 1; x <= m; x ++)
                mx = max(mx, cnt[x]);
            ans = min(ans, mx);
            for(int r = 0; r < n; r ++){
                if(cnt[a[r][ptr[r]]] == mx and ptr[r] < m - 1)
                    mark[a[r][ptr[r]]] = true;
                while(ptr[r] < m and mark[a[r][ptr[r]]])
                    ptr[r] ++;
                if(ptr[r] == m){
                    cout << ans;
                    return 0;
                }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int K, X;
    cin >> K >> X;
    Yes(K * 500 >= X);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) {
    ostringstream stm;
    stm << n;
    return stm.str();
}
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;
}


int const INF = 1001001001;


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

int N;
cin >> N;
string S;
cin >> S;

int ans = 0;
int x = 0;

rep(i,N) {
    if(S[i] == 'I') x++;
    else x--;
    ans = max(ans, x);
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a+b<10)cout<<a+b<<endl;
    else cout<<"error"<<endl;
    
    return 0;
}

Measured memory_bytes: 256