akhauriyash/Code-Regression huggingface dataset:
from math import gcd


class Eratosthenes(): # エラトステネスの篩
    def __init__(self, N): # 素数リスト生成 O(n*log(log n))
        self.fact = [i for i in range(N + 1)]
        for i in range(2, int(N**0.5) + 1):
            if self.fact[i] < i:
                continue
            for j in range(i * 2, N + 1, i):
                self.fact[j] = i
        self.prime_list = [i for i, pi in enumerate(self.fact[2:], 2) if pi == i]


    def factor(self, NUM):  # 高速素因数分解 O(log num)
        PRIME = set()
        while NUM > 1:
            PRIME.add(self.fact[NUM])
            NUM //= self.fact[NUM]
        return PRIME


n = int(input())
a = list(map(int, input().split()))

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print('not coprime')
    exit()

era = Eratosthenes(max(a))
num = set()
for ai in a:
    prime = era.factor(ai)
    if len(prime & num) > 0:
        print('setwise coprime')
        break
    num |= prime
else:
    print('pairwise coprime')


Measured memory_bytes: 217916
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

int main(){

	char buf[11];
	int length;

	scanf("%s",buf);

	for(length = 0; buf[length] != '\0'; length++);

	int count = 0,limit = length/2-1;

	for(int i = 0; i <= limit; i++){
		switch(buf[i]){
		case '(':
			if(buf[length-1-i] != ')')count++;
			break;
		case ')':
			if(buf[length-1-i] != '(')count++;
			break;
		case 'w':
			if(buf[length-1-i] != 'w')count++;
			break;
		case 'i':
			if(buf[length-1-i] != 'i')count++;
			break;
		}
	}

	if(length%2 != 0){
		if(buf[(length-1)/2] == '(' || buf[(length-1)/2] == ')')count++;
	}

	printf("%d\n",count);

	return 0;
}

Measured memory_bytes: 2732
N=int(input())
start=0
end=0
r=0
cnt=0
for i in range(N):
    s=input()
    cnt+=s.count('AB')
    if s[0] == 'B':
        start+=1
    if s[-1] == 'A':
        end+=1
    if s[0] == 'B' and s[-1] == 'A':
        r+=1
if start == end and start == r and end > 0:
    cnt -=1
print(cnt+min(start,end))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,sum=0;
    cin>>n;
    ll arr[n],ans[n];
    for(i=0;i<n-1;i++)
        cin>>arr[i];
    ans[0]=arr[0];
    for(i=1;i<(n-1);i++){
        ans[i]=min(arr[i],arr[i-1]);
    }
    ans[n-1]=arr[n-2];
    for(i=0;i<n;i++)
        sum+=ans[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
#include <atcoder/convolution>
using namespace atcoder;
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
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 (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a / gcd(a, b) * b;}
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vl a(n), b(m);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) cin >> b[i];
	vl ans = convolution(a, b);
	for(int i = 0; i < n + m - 1; i++){
		cout << ans[i] << " ";
	}
} 


Measured memory_bytes: 27252
import math
ab = input().split(' ')
if len(ab) != 2:
    raise Exception

a = int(ab[0])
b = int(ab[1])

min_x_a = math.ceil(a / 0.08)
bound = (a + 1) / 0.08
if bound == int(bound):
    max_x_a = int(bound) - 1
else:
    max_x_a = int(bound)

min_x_b = math.ceil(b / 0.1)
bound = (b + 1) / 0.1
if bound == int(bound):
    max_x_b = int(bound) - 1
else:
    max_x_b = int(bound)

if min_x_a < min_x_b and max_x_a < min_x_b:
    print(-1)
elif min_x_b < min_x_a and max_x_b < min_x_a:
    print(-1)
else:
    print(max(min_x_a, min_x_b))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <bitset>
using namespace std;
int main(){
	int N, A[2010]; 
	cin >> N;
	int S = 0; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; S += A[i]; 
	}
	bitset<4000010> B; 
	B.reset();
	B.set(0, 1); 
	for(int i = 0; i < N; i++){
		B = B | (B << A[i]); 
	}
	for(int i = (S+1)/2; i <= S; i++){
		if(B.test(i)){
			cout << i << endl; return 0; 
		}
	}
}

Measured memory_bytes: 2304
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
			String str;
			StringBuilder cards = new StringBuilder( 200+1 );
			int m, shuffle;
	        while( null != ( str = kb.readLine() ) ) {
	        	if( str.equals( "-" ) ) { break; }
	        	
	        	m = Integer.parseInt( kb.readLine() );
	        	for( int i=0; i<m; i++ ) {
	        		shuffle = Integer.parseInt( kb.readLine() );
	        		cards.append( str.substring( shuffle ) );
	        		cards.append( str.substring( 0, shuffle ) );
	        		str = cards.toString();
	        		cards.setLength( 0 );
	        	}
	        	System.out.println( str );	
	        }
			
		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 16920
//AtCoder Beginner Contest 174
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e6 + 5;
const double E = 1e-9;

//------------------------------------------------------------------------------

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/
	int x;
	cin >> x;
	if (x >= 30)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}
//02-08-2020 17:30:53
//------------------------------------------------------------------------------

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

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

	int res = 0;
	for(int i=1;i<=n;i+=2){
		if(a[i]&1)res++;
	}
	cout<<res<<endl;
}

int main(){
	int t; t=1;
	// cin>>t;
	for(int tt=1;tt<=t;tt++)solve(tt);
}

Measured memory_bytes: 3504
N=int(input())
F=[list(input().split()) for _ in range(N)]
P=[list(map(int, input().split())) for _ in range(N)]

ans=[]
for i in range(1,2**10):
    tmp=0
    for j in range(N):
        b=''.join(F[j])
        ct=0
        for k in range(10):
            if (i>>k)&int(b[k]):
                ct+=1
        tmp+=P[j][ct]
    ans.append(tmp)
print(max(ans))

Measured memory_bytes: 91960
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

ll N, K;
ll a[300000], d[300000];
ll v, sz;

signed main() {
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  ll i = 1, n = 1;
  while (true) {
    if (d[i] > 0) {
      v = i;
      sz = n - d[i];
      break;
    }
    d[i] = n;
    n++;
    i = a[i];
  }

  i = 1;
  while (K > 0) {
    // i で何度かループ
    if (i == v) K %= sz;
    if (K == 0) break;
    // 次へ
    K--;
    i = a[i];
  }
  // cout << "v = " << v << " sz = " << sz << endl;
  cout << i << endl;

  return 0;
}


Measured memory_bytes: 6784
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int a, p;
	cin >> a >> p;
	cout << (3*a+p)/2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI_INT 3.14159265358979323846
#define PI acos(-1.0)
#define LL long long
#define N 100000007
#define MOD 10000007
#define MX numeric_limits<long long>::max();
#define MN numeric_limits<long long>::min();
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define FILL(v, n) fill(v.begin(), v.end(), n);
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define PRINT(v) for(int i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define SCAN(v) for(int i=0; i<n; i++) { int temp; cin>>temp; v.push_back(temp); }
#define SORT(v) sort(v.begin(), v.end());

using namespace std;

int main()
{
    string line;
    cin >> line;

    LL ans=0;

    char pre=line[0];

    for(int i=1; i<line.size(); i++)
    {
        if(pre==line[i])
        {
            ans++;

            if(line[i]=='0')
                pre='1';
            else
                pre='0';
        }

        else
            pre=line[i];
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  YesNo(N%10 == N/100);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(M);
  int sum = 0;
  for(int i = 0; i < M; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  if(sum > N) {
    cout << -1 << endl;
  }
  else {
    cout << N - sum << endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#define fo(i,a,b) for(i=a;i<=b;i++)

using namespace std;

const int maxn=1e5+5;

int a[maxn],b[maxn],c[maxn],d[maxn],fa[maxn];
int i,j,k,l,m,n,x,y,ans,p;
map<int,int> f;

int getfather(int x){
	if (fa[x]==x) return x; else fa[x]=getfather(fa[x]);
	return fa[x];
}
int main(){
//	freopen("016d.in","r",stdin);
	scanf("%d",&n);
	l=0;
	fo(i,1,n){
		scanf("%d",&a[i]);
		l^=a[i];
	}
	a[n+1]=l; l=0;
	fo(i,1,n){
		scanf("%d",&b[i]);
		l^=b[i];
	}
	b[++n]=l;
	fo(i,1,n){
		c[i]=a[i]; d[i]=b[i];
	}
	sort(c+1,c+n+1); sort(d+1,d+n+1);
	fo(i,1,n-1) if (c[i]!=d[i]) break;
	if (i<n){
		printf("-1\n");
		return 0;
	}
	fo(i,1,n){
		if (a[i]!=b[i] && i!=n) ans++;
		if (i==n && ans==0){
			printf("0\n"); return 0;
		}
		if (a[i]!=b[i] || i==n){
			if (!f[a[i]]) f[a[i]]=++p;
			if (!f[b[i]]) f[b[i]]=++p;
		}
	}
	fo(i,1,p) fa[i]=i;
	fo(i,1,n) if (a[i]!=b[i]) fa[getfather(f[a[i]])]=getfather(f[b[i]]);
	fo(i,1,p) if (getfather(i)==i) ans++;
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 8448
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};

use std::collections::HashMap;
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a : Vec<u64> = (0..n).map(|_| iter.next().unwrap().parse().unwrap()).collect();
    
    let mut map = HashMap::new();
    
    for item in &a {
        if let Some(x) = map.get_mut(item) {
            *x +=1;
            continue;
        } 
        
        map.insert(item, 1);
    }
    
    let mut sum = 0u64;
    for (k, v) in &map {
        let v = *v;
            
        sum += v * (v - 1) / 2;
    }
    
    
    for item in &a {
        // 標準となるsumから現在のkeyのCを引いて一引いたCを足す
        // sum - vC2 + (v-1)C2
        // = sum - v * (v - 1) / 2 + (v - 1) * (v - 2) / 2
        // = sum - (v - 1)
        let tmp = sum - map.get(&item).unwrap() + 1;
        println!("{:?}", tmp);
    }
    
}

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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007

ll n,a[200005];
int main(){
    cin>>n;
    rep(i,1,n) cin>>a[i];
    if(n%2){
        for(ll i=n;i>=1;i-=2) cout<<a[i]<<" ";
        for(ll i=2;i<n;i+=2) cout<<a[i]<<" ";
    }
    else{
        for(ll i=n;i>=1;i-=2) cout<<a[i]<<" ";
        for(ll i=1;i<n;i+=2) cout<<a[i]<<" ";
    }

}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    char a=('A'+(s1[0]-'a')),b=('A'+(s2[0]-'a')),c=('A'+(s3[0]-'a'));
    cout <<a<<b<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int L = 2, R = 2;
  int k;
  cin>>k;
  VI rds;
  RE (i, k) {
    int a;
    cin>>a;
    rds.PB(a);
  }
  while (!rds.empty()) {
    int a = rds.back();
    L = a * ((L + a - 1) / a);
    R = a * ((R / a) + 1) - 1;
    rds.pop_back();
  }
  if (L <= R) {
    cout<<L<<" "<<R<<endl;
  } else {
    cout<<"-1\n";
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 1400
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
int n; double r, t;
int main() {
	cin >> n >> r >> t; t *= pi / 180;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
	vector<vector<vector<bool> > > ok(n, vector<vector<bool> >(n, vector<bool>(n, false)));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			for (int k = 0; k < n; k++) {
				if (j == k) continue;
				double t2 = (x[j] - x[i]) * (x[j] - x[k]) + (y[j] - y[i]) * (y[j] - y[k]);
				t2 /= hypot(x[j] - x[i], y[j] - y[i]);
				t2 /= hypot(x[j] - x[k], y[j] - y[k]);
				if (pi - acos(t2) < t) ok[i][j][k] = true;
			}
		}
	}
	vector<vector<double> > dist(n, vector<double>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dist[i][j] = hypot(x[i] - x[j], y[i] - y[j]);
		}
	}
	int lim = (int)r;
	vector<vector<vector<double> > > dp(lim, vector<vector<double> >(n, vector<double>(n, 1.0e+10))); // (carrot - 2, now, prev)
	for (int i = 1; i < n; i++) dp[0][i][0] = hypot(x[0] - x[i], y[0] - y[i]);
	for (int i = 1; i < lim; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (j == k) continue;
				for (int l = 0; l < n; l++) {
					if (!ok[j][k][l]) continue;
					dp[i][j][k] = min(dp[i][j][k], dp[i - 1][k][l] + dist[j][k]);
				}
			}
		}
	}
	int ret = 0;
	for (int i = 0; i < lim; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (dp[i][j][k] < r) ret = max(ret, i + 1);
			}
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 42440
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,d=INTM()
    print(int((n+(d*2+0.9))//(d*2+1)))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

typedef pair<int,int> P;

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

int main(){
	int h,w,cnt[1000][1000] = {};
	string field[1000];
	cin >> h >> w;
	for(int i = 0;i < h;i++) cin >> field[i];
	set<P> next;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(field[i][j] == '.') continue;
			next.insert(P(i,j));
			for(int k = 0;k < 8;k++){
				int nx = i + dx[k],ny = j + dy[k];
				if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] == '.') cnt[i][j]++;
			}
		}
	}
	for(int res = 0;;res++){
		bool chg = false;
		vector<P> chgs;
		for(auto it = next.begin();it != next.end();it++){
			P p = *it;
			int i = p.first,j = p.second;
			if(field[i][j] != '.' && cnt[i][j] >= field[i][j] - '0'){
				field[i][j] = '.';
				chg = true;
				for(int k = 0;k < 8;k++){
					int nx = i + dx[k],ny = j + dy[k];
					if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] != '.') {
						chgs.push_back(P(nx,ny));
					}
				}
			}
		}
		next.clear();
		for(int i = 0;i < chgs.size();i++){
			int x = chgs[i].first,y = chgs[i].second;
			cnt[x][y]++;
			next.insert(P(x,y));
		}
		if(!chg){
			cout << res << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 54552
import sys, math
import bisect
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def isPrime(n):
    if n < 2:
        return False
    i = 2
    while i*i <= n:
        if n%i==0:
            return False
        i += 1
    return True

def main():
    l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = ii()
    print(l[K-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 61968
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.06.29 20:35:45
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int n, d[100010];
    scanf("%d", &n);
    rep(i, n) scanf("%d", &d[i]);
    vector<int> vec;
    rep(i, n) {
        vec.pb(d[i]);
    }

    sor(vec);

    int ret = vec[n / 2] - vec[n / 2 - 1];

    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 1276
using System;

namespace _6_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var card = new int[52];
            for (var i = 0; i < n; i++)
            {
                var c = Console.ReadLine().Split();
                var s = c[0];
                var num = int.Parse(c[1]);
                if (s == "S")
                {
                    card[num - 1]++;
                }
                else if (s == "H")
                {
                    card[(num - 1) + 13]++;
                }
                else if (s == "C")
                {
                    card[(num - 1) + 26]++;
                }
                else
                {
                    card[(num - 1) + 39]++;
                }
            }
            for (var i = 0; i < 52; i++)
            {
                if (card[i] == 0)
                {
                    if(i<13)
                    {
                        Console.WriteLine("S {0}", i + 1);
                    }
                    else if(i>=13 && i<26)
                    {
                        Console.WriteLine("H {0}", i + 1 - 13);
                    }
                    else if(i>=26 && i<39)
                    {
                        Console.WriteLine("C {0}", i + 1 - 26);
                    }
                    else
                    {
                        Console.WriteLine("D {0}", i + 1 - 39);
                    }
                }
            }
        }
    }
}



Measured memory_bytes: 15952
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

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

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

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

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

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

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	a := make([]int, n)
	for i, _ := range a {
		a[i] = readInt()
	}

	x := 0
	for i, v := range a {
		if i%2 == 0 {
			x += v
		} else {
			x -= v
		}
	}

	ans := make([]int, n)
	ans[0] = x
	for i := 1; i < n; i++ {
		ans[i] = 2*a[i-1] - ans[i-1]
	}

	for _, v := range ans {
		fmt.Printf("%v ", v)
	}
}


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

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

    long long int n, k, x;
    long long int ans = 0;
    cin >> n;
    cin >> k;
    for (int i = 0; i < n; i++){
        cin >> x;
        ans += 2 * min(x, abs(k - x));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
Price = []
maxPrice = 0
sumTotal = 0
for i in range(N):
    priceCurrent = int(input())
    Price.append(priceCurrent)
    if priceCurrent > maxPrice:
        maxPrice = priceCurrent
    sumTotal += priceCurrent
sumTotal -= int(maxPrice/2)
print(sumTotal)


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

using namespace std;

typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> G(n + 1);
    vector<ll> deg_in(n + 1);
    ll i, j, k;
    for(i = 0; i < n -1 + m;i++){
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        deg_in[b]++;
    }
    ll root = -1;
    for(i = 1; i <= n; i++) {
        if(deg_in[i]==0){
            root = i;
            break;
        }
    }
    vector<ll> parent(n + 1,-1);
    parent[root] = 0;
    queue<ll> que;
    que.push(root);
    while(!que.empty()){
        ll now = que.front();
        que.pop();
        for(ll x:G[now]){
            deg_in[x]--;
            if(deg_in[x]==0){
                parent[x] = now;
                que.push(x);
            }
        }
    }

    for(i = 1; i <= n;i++){
        cout << parent[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
int main() {
	string a, b, c; cin >> a >> b >> c;
	cout << a[0] << b[1] << c[2] << endl;
	return 0;
}

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

ll gcd(ll m,ll n);

int main(void){
    ll A[100002];
    ll N;
    cin >> N;
    rep(i,N) cin >> A[i+1];
    
 
    
    ll L[100002],R[100002];
    L[0] = 0;
    R[N+1] = 0;
    
    rep(i,N){
        L[i+1] = gcd(L[i],A[i+1]);
        R[N-i] = gcd(R[N-i+1],A[N-i]);       
    }
    
    ll ans = 0;
    
    rep(i,N){
        ans = max(ans,gcd(L[i],R[i+2]));
    }
    cout  << ans << endl;
}

ll gcd(ll m,ll n){
    ll a = min(m,n);
    ll b =max(m,n);
    ll r= a%b;
    while(r>0){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  string s,t,ans;
  cin >> n >> s >> t;

  for(int i=0; i<n; i++){
    ans+= s[i];
    ans+= t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long  dfs(long long n,long long omomi);
long long w,w_,n_;
main(){
  cin>>w;
  w_=w;
  n_=1;
  while(n_<w){
    n_*=3;
  }
  dfs(1,0);
  cout<<endl;
}
long long dfs(long long n,long long omomi){
  if(omomi==w) return 1;
  if(n_<n) return 0;
  if(dfs(n*3,omomi+n)==1){
    cout<<'+';
    return 1;
  }
  if(dfs(n*3,omomi-n)==1){
    cout<<'-';
    return 1;
  }
  if(dfs(n*3,omomi)==1){
    cout<<'0';
    return 1;
  }
}

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define pi pair<double, double>

pi a[1234];
bool cmp(pi x, pi y) {
    return atan2(x.second, x.first) < atan2(y.second, y.first);
}
int main() {
    int n;
    cin>>n;
    set<int>S;
    int tmp=0;
    int ans=0;
    for (int i=1;i<1000000;i++) {
        tmp=tmp*10+7;
        tmp%=n;
        ans++;
        if (tmp==0) {
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}



Measured memory_bytes: 3688
#include <cstdio>
// B - Reversi

#define MOD 1000000007

using namespace std;

int C[200005];
int cnt[200005];

int main() {
    int N,i,ans;

    scanf("%d",&N);
    
    ans = 1;
    for (i = 1;i <= N;i++) {
        scanf("%d",&C[i]);
        if (C[i] != C[i - 1]) {
            ans += cnt[C[i]];
            ans %= MOD;
            cnt[C[i]] = ans;
        }
    }

    printf("%d\n",ans);

    return 0;
}


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

int hexa(char a)
{
	switch(a)
	{
	case 'A':
		return 10;
	case 'B':	
		return 11;
	case 'C': 
		return 12;
	case 'D':
		return 13;
	case 'E':
		return 14;
	case 'F':
		return 15;				
	}	
}



int main()
{
	char a,b;
	cin>>a>>b;
	
	int an,bn;
	an=hexa(a);
	bn=hexa(b);
	
	if(an<bn)
		cout<<"<";
	else
		{
			if(an>bn)
			cout<<">";
			else{
			
			cout<<"=";
		}}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[100001];
ll pow2[100001];
const int MOD = 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	pow2[0]=1;
	for(int i = 1; i <= 100000; i++) pow2[i]=(pow2[i-1]*2)%MOD;
	int n; cin>>n;
	for(int i = 0; i < n; i++) cin>>a[i];
	sort(a,a+n);
	if(n&1)
	{
		if(a[0]!=0)
		{
			cout<<0; return 0;
		}
		int pp = 2;
		for(int i = 1; i < n; i+=2)
		{
			if(!(a[i]==pp&&a[i+1]==pp))
			{
				cout<<0; return 0;
			}
			pp+=2;
		}
	}
	else
	{
		int pp = 1;
		for(int i = 0; i < n; i+=2)
		{
			if(!(a[i]==pp&&a[i+1]==pp))
			{
				cout<<0; return 0;
			}
			pp+=2;
		}
	}
	cout<<pow2[n/2]<<'\n';
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=0; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  int n ;
  cin >> n ;
  vector<pair<pair<string,int>,int>> vec(n) ;
  
  REP(i,n){
    string a ;
    int b ;
    cin >> a >> b ;
    vec.at(i) = make_pair(make_pair(a,0-b),i) ;
  }
  sort(ALL(vec)) ;
  
  REP(i,n){
    cout << vec.at(i).second+1 <<endl ;
  }

  return 0 ;
}



Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
bool chk = false;
ll sub(ll a, ll b){
	ll ans = 0;
	while(a){
		if(a&1) ans += b;
//		cout << ans << ' ' << b << '\n';
		if(ans > INF || b > INF){
			chk = 1;
			break;
		}
		b <<= 1ll;
		a >>= 1ll;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n;cin >> n;
	ll ans = 1;
	vector<ll> ar;
	while(n--){
		ll a;
		cin >> a;
		ar.push_back(a);
	}
	sort(ar.begin(),ar.end());
	for(auto it : ar){
		if(!it){
			ans = 0;
			break;
		}
		ans = sub(it,ans);
		if(chk){
			ans = -1;
			break;
		}
	}
	cout << ans << '\n';
}


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

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> H(N);
    for(int i=0; i<N; i++) scanf(" %d", &H[i]);

    if(N == 1){printf("Yes\n"); return 0;}
    if(N == 2 && H[0]-1 <= H[1]){printf("Yes\n"); return 0;}
    if(N == 2 && H[0]-1 >  H[1]){printf("No\n"); return 0;}

    H[0]--;
    for(int i=1; i<N-1; i++){
        if(H[i-1] < H[i]) H[i]--;
        if(H[i] > H[i+1]){printf("No\n"); return 0;}
    }
    printf("Yes\n");
}

Measured memory_bytes: 640
#C - Low Elements
#条件を満たすiはpiがp1,p2,..,piで最小となる
n = int(input())
p = list(map(int,input().split()))
tmp = p[0]
ans = 1
for i in range(1,n):
    tmp = min(tmp,p[i])
    if tmp == p[i]:
        ans += 1
print(ans)

Measured memory_bytes: 24744
# 2019/06/16
# AtCoder Beginner Contest 130 - C

# Input
w, h, x, y = map(int,input().split())

ans1 = (w * h) / 2
if x * 2 == w and y * 2 == h:
    ans2 = 1
else:
    ans2 = 0

# Output
print(ans1, ans2)


Measured memory_bytes: 2940
/*
ID: zhaowei10
TASK:
LANG: C++
*/
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define MOD 1000000007
#define FOR(i, j, k, l) for (s32 i = j; i < k; i += l)
#define RFOR(i, j, k, l) for (s32 i = j; i >= k; i -= l)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(x) x.begin(), x.end()
#define MEAN(a, b) min(a, b) + (abs(b - a) >> 1)
#define FASTIO()    \
  cin.tie(nullptr); \
  ios::sync_with_stdio(false);

typedef int64_t s64;
typedef uint64_t u64;
typedef int32_t s32;
typedef uint32_t u32;
typedef float f32;
typedef double f64;
typedef pair<s32, s32> II;
typedef pair<s64, s64> LL;
typedef vector<s32> VI;
typedef vector<II> VII;
typedef vector<char> VC;
typedef vector<VII> VVII;
typedef priority_queue<s32> PQI;
typedef priority_queue<s32, VI, greater<s32>> PQIA;
typedef priority_queue<s64> PQL;
typedef priority_queue<II> PQII;
typedef priority_queue<II, VII, greater<II>> PQIIA;
typedef priority_queue<LL> PQLL;
typedef unordered_set<s32> USI;
typedef unordered_set<s64> USL;
typedef set<II> SII;
typedef multiset<s32> MSI;

template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}

template <typename T>
inline s32 ndigits(T x) {
  s32 r = 0;
  while (x) {
    x /= 10;
    ++r;
  }
  return r;
}

int main() {
  FASTIO();

  int n;
  string s;
  cin >> n >> s;

  string x = "ABC";
  int cnt = 0;
  for (int i = 0; i < n - 2; ++i) {
    bool f = true;
    for (int j = i; j < i + 3; ++j) {
      if (s[j] != x[j - i]) {
        f = false;
        break;
      }
    }
    if (f) ++cnt;
  }
  cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1<<29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string s; cin >> s;
    int i = 0;
    int onec = 0, zeroc = 0;
    rep(i, s.size()){
        if(s[i] == '1'){
            onec++;
        } else {
            zeroc++;
        }
    }
    cout << min(onec, zeroc) * 2 << endl;
}

Measured memory_bytes: 512
package main

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

func main() {
	in := bufio.NewScanner(os.Stdin)
	for in.Scan() {
		if err := in.Err(); err != nil {
			fmt.Fprintln(os.Stderr, err)
		}
		t := in.Text()
		if t == "0 0" {
			break
		}
		h, _ := strconv.Atoi(strings.Split(t, " ")[0])
		w, _ := strconv.Atoi(strings.Split(t, " ")[1])
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				fmt.Print("#")
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



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


int main()
{
    int n; cin>>n;
    int arr[n];
    int cost[n];

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

    cost[0]=0;

    for(int i=0;i<n;i++)
    {
        if(i+2<n) cost[i+2]= min( cost[i]+abs(arr[i+2]-arr[i]), cost[i+2]);
        if(i+1<n) cost[i+1]= min(cost[i]+abs(arr[i+1]-arr[i]), cost[i+1]);
       // cout<<cost[i]<<" "<<arr[i]<<"   ";
    }
    cout<<cost[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ll long long
using namespace std;

const int N = 3e5 + 5;
ll n,a,b,k;
ll fakt[N];
const ll mod = 998244353;

ll modexp(ll b,ll e,ll m){
	ll r = 1;
	while(e > 0){
		if((e & 1) == 1){
			r = (r * b) % m;
		}
		e = e / 2;
		b = (b * b) % m;
	}
	return r;
}

ll kombin(ll atas,ll bawah){
	if(bawah > atas){
		return 0;
	}
	if(bawah == atas){
		return 1;
	}

	ll c = (fakt[atas] * modexp(fakt[bawah], mod - 2, mod)) % mod;
	c = (c * modexp(fakt[atas - bawah], mod - 2, mod)) % mod;
	return c;
}

int main()
{
	cin.sync_with_stdio(0);		cin.tie(0);		cout.tie(0);

	cin >> n >> a >> b >> k;
	fakt[0] = 1;
	fakt[1] = 1;
	for(ll x = 2; x <= 300000; x++){
		fakt[x] = (fakt[x - 1] * (ll)x) % mod;
	}
	ll ans = 0;

	for(ll x = 0 ; x <= 300000; x++){
		if(x > n) break;
		ll rem = k - a * x;
		if(rem % b != 0 || rem < 0) continue;

		ll tk = rem / b;
		if(tk <= n){
			ans = (ans + (kombin(n, x) * kombin(n, tk)) % mod) % mod;
		}
	}
	cout << ans << "\n";
}	

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <math.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int a, b, x;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> a >> b >> x;

	double border = ((double)b/(double)a)*M_PI*360.0f;

	double deg = 0.0f;
	if(x>=((double)a*(double)a)*(double)b/2.0f) {
		double vol = ((double)a*(double)a)*(double)b - double(x);
		DOUT << "[1] vol="<<vol<<endl;
		double h = vol*2.0f/((double)a*(double)a);
		DOUT << "[1] h="<<h<<endl;
		deg = atan(h/(double)a) * 180.0f / (M_PI);
	}
	else {
		double vol = (double)x;	
		double h = vol*2.0f/((double)a*(double)b);
		deg = 90.0f - atan(h/b) * 180.0f / M_PI;
	}

	cout <<setprecision(10)<< deg << endl;

	return 0;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1196&lang=jp
typedef long long ll;
#define INF 1<<30
#define LINF 1LL<<60
struct edge {
	int from;
	int to;
	ll cost;
	edge() {}
	edge(int f, int t, int c) :from(f), to(t), cost(c) {}
};
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll n;
	while (cin >> n, n) {
		ll sum_d = 0;
		vector<ll> p(n - 1), d(n - 1);
		for (int i = 1; i < n;i++) { cin >> p[i - 1]; p[i - 1]--; }
		for (int i = 1; i < n;i++) { cin >> d[i - 1]; sum_d += d[i - 1]; }
		if (n == 3) { cout << sum_d << endl; continue; }
		vector<vector<edge>> G(n);
		for (int i = 1;i < n;i++) {
			G[p[i - 1]].push_back(edge(p[i - 1], i, d[i - 1]));
			G[i].push_back(edge(i, p[i - 1], d[i - 1]));
		}

		int from;
		ll leaf_cost = 0;
		vector<int> leaf(n, 0);
		for (int i = 0; i < n;i++) {
			if (G[i].size() == 1) { leaf_cost += G[i][0].cost; G[i].clear(); leaf[i] = 1; }
			else from = i;
		}
		for (int i = 0; i < n;i++) {
			for (int j = G[i].size() - 1; j >= 0; j--) {
				if (leaf[G[i][j].to] == 1) {
					G[i].erase(G[i].begin() + j);
				}
			}
		}
		/* diameter */
		int s, t;
		vector<ll> dist(n, INF);
		dist[from] = 0;
		queue<ll> q; q.push(from);
		while (!q.empty()) {
			ll n = q.front(); q.pop();
			for (auto e : G[n]) {
				//if (leaf[e.to] == 1) continue;
				if (dist[e.to] > dist[e.from] + e.cost) {
					dist[e.to] = dist[e.from] + e.cost;
					q.push(e.to);
				}
			}
		}
		int Max = -1;
		for (int i = 0; i < n; i++) {
			if (dist[i] == INF)continue;
			if (dist[i] >= Max) Max = dist[i], s = i;
		}
		fill(dist.begin(), dist.end(), INF);
		dist[s] = 0;q.push(s);
		while (!q.empty()) {
			ll n = q.front(); q.pop();
			for (auto e : G[n]) {
				//if (leaf[e.to] == 1) continue;
				if (dist[e.to] > dist[e.from] + e.cost) {
					dist[e.to] = dist[e.from] + e.cost;
					q.push(e.to);
				}
			}
		}

		Max = -1;
		for (int i = 0; i < n; i++) {
			if (dist[i] == INF) continue;
			if (dist[i] > Max) Max = dist[i], t = i;
		}

		ll Max_path_cost = dist[t];
		ll Other_path_cost = sum_d - leaf_cost;

		cout << sum_d + 2 * Other_path_cost - Max_path_cost << endl;
	}
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define ld long double
#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define roflan ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;

signed main(){
  roflan;
  int n, W;
  cin >> n >> W;
  vector <pii> a(n);
  int sum_val = 0;
  for (int i = 0; i < n; i++){
    cin >> a[i].F >> a[i].S;
    sum_val += a[i].S;
  }
  vector <int> dp(sum_val + 1, 1e18);
  dp[0] = 0;
  for (int i = 0; i < n; i++){
    for (int v = sum_val - a[i].S; v >= 0; v--){
      dp[v + a[i].S] = min(dp[v + a[i].S], dp[v] + a[i].F);
    }
  }
  int ans = 0;
  for (int i = 0; i <= sum_val; i++){
    if (dp[i] <= W){
      ans = max(ans, i);
    }
  }
  cout << ans;
  return 14 / 88;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n,m,dp[100009];
vector < int > v[100009];
int dfs(int node){
	int &ret = dp[node];
	if(ret != -1) return ret;
	ret = 0;
	for(int i=0;i<v[node].size();i++){
		int u = v[node][i];
		ret = max(ret,dfs(u)+1);
	}
	return ret;
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		v[a].push_back(b);
	}
	int mx = 0;
	for(int i=0;i<n;i++){
		mx = max(mx,dfs(i));
	}
	cout<<mx<<endl;
}


Measured memory_bytes: 8192