akhauriyash/Code-Regression huggingface dataset:
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    const int max_c = int(1e6) + 10;
    vector<int> cnts(max_c + 1);

    for (int i = 0; i != n; ++i)
        cnts[input<int>()] += 1;

    const int mod = 998244353;

    auto add = [&](int a, int b) {
        return a + b >= mod ? a + b - mod : a + b;
    };
    
    auto sub = [&](int a, int b) {
        return a >= b ? a - b : mod + a - b;
    };

    auto mult = [&](int a, int b) {
        return (int64_t(a) * b) % mod;
    };

    auto fpow = [&](int a, int n, int r) {
        while (n) {
            if (n % 2)
                r = mult(r, a);

            a = mult(a, a);
            n /= 2;
        }

        return r;
    };

    
    vector<int> divs(max_c + 1, -1);
    for (int i = 2; i <= max_c; ++i)
        for (int j = 2 * i; j <= max_c; j += i)
            if (divs[j] == -1)
                divs[j] = i;
    
    vector<int> mu(max_c + 1);
    for (int i = 2; i <= max_c; ++i)
        if (divs[i] == -1)
            mu[i] = -1;
        else {
            int p = divs[i];
            if ((i / p) % p == 0)
                mu[i] = 0;
            else
                mu[i] = -mu[i / p];
        }
    
    vector<int> sums(max_c + 1);
    for (int div = 1; div <= max_c; ++div) {
        int cur_sum = 0;
        
        for (int val = div; val <= max_c; val += div) {
            for (int i = 0; i != cnts[val]; ++i) {
                sums[div] = add(sums[div], mult(cur_sum, val));
                cur_sum = add(cur_sum, val);                
            }
        }
    }

    int ans = 0;
    for (int div = 1; div <= max_c; ++div) {
        int64_t sm = sums[div];
        for (int sup = 2 * div; sup <= max_c; sup += div) {
            sm = sm + mu[sup / div] * sums[sup];
            sm %= mod;
        }

        if (sm < 0)
            sm += mod;
        
        ans = add(ans, fpow(div, mod - 2, sm));
    }
    
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 17920
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8, i8, i8[:]), cache=True)
def main(H, W, XY):
    U = 300_010
    row = np.zeros(U, np.int64)
    col = np.zeros(U, np.int64)
    for i in range(0, len(XY), 2):
        x, y = XY[i:i + 2] - 1
        row[x] += 1
        col[y] += 1
    row_max = row.max()
    col_max = col.max()
    choice = np.sum(row == row_max) * np.sum(col == col_max)
    for i in range(0, len(XY), 2):
        x, y = XY[i:i + 2] - 1
        if row[x] == row_max and col[y] == col_max:
            choice -= 1
    x = row_max + col_max
    return x if choice else x - 1

H, W, M = map(int, readline().split())
XY = np.array(read().split(), np.int64)

print(main(H, W, XY))

Measured memory_bytes: 148388
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int max4 = 100 / 4;
		int max7 = 100 / 7;

		boolean flag = false;

		for (int i = 0; i < max4; i++) {
			for (int j = 0; j < max7; j++) {
				if (n == 4 * i + 7 * j) {
					flag = true;
				}
			}
		}

		System.out.println(flag ? "Yes" : "No");

	}

}


Measured memory_bytes: 21204
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
B = sorted([(A[i][0]-A[i][1],A[i][0]+A[i][1]) for i in range(N)],key=lambda x:x[0],reverse=True)
B = sorted(B,key=lambda x:x[1])
cnt = 1
cur = B[0][1]
for i in range(1,N):
    if B[i][0]>=cur:
        cnt += 1
        cur = B[i][1]
print(cnt)

Measured memory_bytes: 43360
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  cin >> N >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> P(N + 1, 0);
  vector<int64_t> Ex2(N + 1, 0);
  for (int64_t i = 1; i <= N; ++i) {
    cin >> P[i];
    Ex2[i] = Ex2[i - 1] + (P[i] + 1LL);
  }
  int64_t result = INT64_MIN;
  for (int64_t i = K; i <= N; ++i) {
    const int64_t temp = Ex2[i] - Ex2[i - K];
    if (temp > result) {
      result = temp;
    }
  }
  cout << std::setprecision(20) << (static_cast<double>(result) / 2.0) << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n, k;
	cin >> n >> k;
	bool ans = n % k;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long a,b,x,temp;
    cin>>x;
    a=-64,b=-64;
    temp=a*a*a*a*a-b*b*b*b*b;
    while(temp!=x)
    {
        if(temp>x) b++;
        else a++;
        temp=a*a*a*a*a-b*b*b*b*b;
    }
    cout<<a<<" "<<b;
    return 0;
}

Measured memory_bytes: 3644
n,m = map(int,input().split())
t = []

for i in range(m):
    t.append(list(map(int,input().split())))
p = list(map(int,input().split()))

x = 0
import copy


for switch_cond in range(2**n):
    s = []

    for i in range(n):
        if switch_cond%2 == 0:
            s.append("off")
            switch_cond = switch_cond//2
        else:
            s.append("on")
            switch_cond = (switch_cond-1)//2
    for j in range(m):
        ss = copy.deepcopy(s)
        for r in range(n):
            if r+1 not in t[j][1:]:
                ss[r]="off"           
        if (ss.count("on"))%2 != p[j]:
            break
    else:
        x += 1
print(x)

Measured memory_bytes: 3444
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val X = sc.next().toInt()
        val N = sc.next().toInt()
        val p = Array(N) { sc.next().toInt() }.toSet()
        val ans = mutableListOf<Int>()

        var i = X
        while (i >= 0) {
            if (!p.contains(i)) {
                ans.add(i)
                break
            }
            i--
        }

        i = X
        while (i <= 101) {
            if (!p.contains(i)) {
                ans.add(i)
                break
            }
            i++
        }

        //dprint(ans)
        if (X - ans[0] <= ans[1] - X) {
            pw.println(ans[0])
        } else {
            pw.println(ans[1])
        }
    }
}


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

int main() {
 int m,a,b;
  while( cin>>m>>a>>b && m > 0 || a > 0 || b > 0){
    
    vector<int>vec(m);
    for(int i=0;i<m;i++){
      cin>>vec.at(i);
    }
    int ans=0;
    int num;
    
    
    for(int i=a;i<=b;i++){
   
     if(vec.at(i-1)-vec.at(i) >=ans){
       ans=vec.at(i-1)-vec.at(i);
       num =i;
     }
    }
    cout << num << endl;
  }
  return 0;
}
    
     
    
    
       
    
    
    
   
    
    


Measured memory_bytes: 3104
n = gets.to_i
nums = []
n.times { nums << gets.to_i }
previous = 0
ans = 0
nums.reverse.each_with_index do |num, index|
  current = [previous - 1, 0].max
  if current > num
    puts -1
    exit
  elsif current != num
    ans += num
  end
  previous = num
end
puts previous != 0 ? -1 : ans


Measured memory_bytes: 17756
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

using P = pair<int, int>;

int N;
P A[1000000];

signed main()
{
	cin >> N;
	REP(i, N)
	{
		int a;
		cin >> a;
		A[i] = make_pair(a, i);
	}
	ARY_SORT(A, N);

	REP(i, N)
	{
		cout << ((i == 0) ? "" : " ") << (A[i].second + 1);
	}
}



Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string ord,mes;
    cin>>ord>>mes;
    reverse(ord.begin(),ord.end());
    for(int j=0;j<ord.size();j++){
      char c=ord[j];
      
      if(c=='J'){
	rotate(mes.begin(),mes.begin()+mes.size()-1,mes.end());
      }else if(c=='C'){
	rotate(mes.begin(),mes.begin()+1,mes.end());
      }else if(c=='E'){
	string x,y,z;
	for(int k=0;k<mes.size()/2;k++){
	  x.push_back(mes[k]);
	}
	if(mes.size()%2==1) y.push_back(mes[mes.size()/2]);
	for(int k=mes.size()/2+(mes.size()%2?1:0);k<mes.size();k++){
	  z.push_back(mes[k]);
	}
	mes=z+y+x;
      }else if(c=='A'){
	reverse(mes.begin(),mes.end());
      }else if(c=='P'){
	for(int k=0;k<mes.size();k++){
	  if('1'<=mes[k]&&mes[k]<='9') mes[k]-=1;
	  else if(mes[k]=='0') mes[k]='9';
	}
      }else if(c=='M'){
	for(int k=0;k<mes.size();k++){
	  if('0'<=mes[k]&&mes[k]<='8') mes[k]+=1;
	  else if(mes[k]=='9') mes[k]='0';
	}
      }
    }
    cout<<mes<<endl;
  }
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<int> p(A); cin >> p;
  vector<int> q(B); cin >> q;
  vector<int> r(C); cin >> r;

  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  // sort(r.begin(), r.end());
  // [p.size() - X, p.size()]
  // [q.size() - Y, q.size()]
  vector<int> v;
  rep(i, X) v.push_back(p[i]);
  rep(i, Y) v.push_back(q[i]);
  rep(i, C) v.push_back(r[i]);
  sort(v.rbegin(), v.rend());
 // rep(i, X) cout << p[i] << ", "; cout << "\n";
 // rep(i, Y) cout << q[i] << ", "; cout << "\n";
 // rep(i, C) cout << r[i] << ", "; cout << "\n";
 // rep(i, v.size()) cout << v[i] << ", "; cout << "\n";
  ll ans = 0;
  rep(i, X + Y) {
    ans += v[i];
  }
  cout << ans << endl;
}






Measured memory_bytes: 3572
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
 		
int main() {
int N;
cin>>N;
for(int i=2;i<=55555;i+=5){
		int k;
	for(k=2;k*k<=i;k++){
		if(i%k==0){
		break;	
		}
	}
	if(k*k>i){
		if(i%5==2){
			cout<<i<<' ';
			if(--N==0){
cout<<endl;
				break;
			}
		}
	}
}
	
	
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
void solve()
{
int k;
cin>>k;
int total=0;
for (int i = 1; i < 1e7; i++)
{
    total=(total*10+7)%k;
    if(total==0)
    {
        cout<<i<<endl;
        return ;
    }
}
cout<<-1<<endl;
}
int main()
{

FASTIO
 long long int t;
 t=1;
 while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 3652
#include <cstring>
#include <cstdio>
int val[15][15], sum[100005], dp[100005][15]; 
inline void upd(int &x, int y)
{
	if (x < y)
		x = y; 
}
int main()
{
	// freopen("ARC078-F.in", "r", stdin); 
	int n, m; 
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int u, v, w; 
		scanf("%d%d%d", &u, &v, &w); 
		val[--u][--v] = w; 
		val[v][u] = w; 
	}
	for (int i = 0; i < 1 << n; i++)
	{
		for (int x = 0; x < n; x++)
		{
			for (int y = x; y < n; y++)
			{
				if ((i & (1 << x)) && (i & (1 << y)))
					sum[i] += val[x][y]; 
			}
		}
	}
	memset(dp, -0x3f, sizeof(dp)); 
	dp[1][0] = 0; 
	for (int s = 0; s < 1 << n; s++)
	{
		for (int i = 0; i < n; i++)
		{
			if (!(s & (1 << i)))
				continue; 
			for (int j = 0; j < n; j++)
			{
				if ((s & (1 << j)) || !val[i][j])
					continue; 
				upd(dp[s | (1 << j)][j], dp[s][i] + val[i][j]); 
			}
			int x = (1 << n) - 1 ^ s; 
			for (int t = x; t; t = t - 1 & x)
				upd(dp[s | t][i], dp[s][i] + sum[t | (1 << i)]); 
		}
	}
	printf("%d\n", sum[(1 << n) - 1] - dp[(1 << n) - 1][n - 1]);
	return 0; 
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define LL long long
#define M(a,b) memset(a,b,sizeof a)
#define pb(x) push_back(x)
using namespace std;
const int maxn=1e5+7;
int a[5];
int main()
{
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    a[2]=a[2]*10+a[1];
    printf("%d\n",a[2]+a[0]);
}


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

using namespace std;

int main(){
    vector<int> a(5);
    for(int i = 0; i < 5; i++){
        cin >> a[i];
    }
    int k;
    cin >> k;

    if(a[4] - a[0] > k){
        cout << ":(" << endl;
        return 0;
    }

    cout << "Yay!" << endl;
    return 0;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int n;
    int x=0;
    int maxn=0;
    string s;
    cin >> n >> s;
    for(int i=0;i<n;i++){
        if(s.substr(i,1)=="D"){
            x--;
        }else{
            x++;
            if(x>maxn){
                maxn = x;
            }
        }
    }
    cout << maxn << endl;
}

Measured memory_bytes: 256
N, *D, = [s.split() for s in open(0)]
N = int(N[0])
D = D[0][0]
if N%2 != 0:
    print("No")
elif N%2 == 0 and D[:int(N/2)] == D[int(N/2):]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i){
        if(i>=1&&i<10)++ans;
        if(i>=100&&i<1000)++ans;
        if(i>=10000&&i<100000)++ans;
    }
    cout<<ans<<endl;
}

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

int main(){
  int listnum, strnum, i, j;
  char temp;
  char lista[256];
  char listb[256];

  while(cin >> listnum && listnum){
    for(i = 0; i < listnum; i++){
      cin >> lista[i];
      cin >> listb[i];
    }
    cin >> strnum;
    for(i = 0; i < strnum; i++){
      cin >> temp;
      for(j = 0; j < listnum; j++){
        if(temp == lista[j]){
          temp = listb[j];
          break;
        }
      }
      cout << temp;
    }

    cout << "\n";
  }

  return 0;
}

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

int main() {
  int a,b,num1,num2,num3,flag;
  num1=num2=flag=0;
  cin >> a >> b;
  b=b/1000;
  num1=10,num2=5,num3=1;
  for(int i=0;i<a+1;i++){
  	for(int j=0; i+j<a+1;j++){
  		for(int k=0; i+j+k<a+1; k++){
  			if(b-i*10-j*5-k==0 && i+j+k==a){
  				cout << i <<" "<< j <<" "<< k << endl;
  				exit(0);
  				flag=1;
  				break;
  			}
  		}
  	}
  }
  if(flag==0){
    cout << "-1 -1 -1" <<endl;
  }
 }

Measured memory_bytes: 384
N = int(input())
S = list(input())
ans = 0
R, G, B = 0, 0, 0

for char in S:
    if char == "R":
        R += 1
    elif char == "G":
        G += 1
    else:
        B += 1

ans = R*G*B

for i in range(len(S)):
    for j in range(i+1, len(S)):
        if S[i] != S[j]:
            i2j = j - i
            try:
                if not S[j+i2j] in [S[i], S[j]]:
                    ans -= 1
            except:
                break

print(ans)


Measured memory_bytes: 9212
def resolve():
    import sys
    input = sys.stdin.readline
    import math
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    l,r=0,a[-1]
    while math.ceil(r)>math.ceil(l):
        x=(l+r)/2
        cnt=0
        for i in a:
            if i%x==0:
                cnt+=i//x-1
            else:
                cnt+=i//x
        if cnt>k:
            l=x
        else:
            r=x
    print(math.ceil(l))

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 91988
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

int main() {
	char b;
	cin >> b;

	map<char, char> acgt {
		{'A', 'T'},
		{'T', 'A'},
		{'C', 'G'},
		{'G', 'C'},
	};

	cout << acgt[b] << endl;

	return 0;
}


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

int N;
int A[1<<20];

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

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

    int counter = 0;
    for(int i = 1;i <= N;i++) {
        if(A[i] == i) {
            counter += 1;
            if(i == N) break;
            swap(A[i], A[i+1]);
        }
    }

    cout<<counter<<endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
          int n,m;
          cin>>n>>m;
          bool ac[n];
          int pen[n];
          memset(pen,0,sizeof pen);
          memset(ac,false,sizeof ac);
          fri(i,0,m)
          {
                    int in;
                    string ve;
                    cin>>in;
                    --in;
                    cin>>ve;
                    if(ve == "AC")
                    {
                              ac[in] = true;
                    }
                    else{
                              if(!ac[in])
                              {
                                        ++pen[in];
                              }
                    }
          }
          int cr,pe;
          cr = pe = 0;
          fri(i,0,n){
                    cr += ac[i];
          }
          fri(i,0,n)
          {
                    if(ac[i]){
                              pe += pen[i];
                    }
          }
          cout<<cr<<" "<<pe<<endl;

}


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

//#define DEBUG 1
#define LENGTH 1000

int plus(char in1[LENGTH], char in2[LENGTH], int out[LENGTH]);

main()
{
	int input;
	char input_str1[LENGTH];
	char input_str2[LENGTH];
	int out_str[LENGTH];
	scanf("%d", &input);
	int out_num[input][LENGTH];
	int i;
	for(i = 0; i < input; i++)
	{
		int j;
		int set = 0;
		for(j = 0; j < LENGTH; j++)
		{
			out_str[j] = 0;
			out_num[i][j] = -2;
			input_str1[j] = '\0';
			input_str2[j] = '\0';
		}
		scanf("\n");
		gets(input_str1);
		gets(input_str2);
		int count = plus(input_str1, input_str2, out_str);
#ifdef DEBUG
		printf("\n");
		printf("%d\n", count);
#endif
		if(count <= 80)
		{
			for(j = count - 1; j >= 0; j--)
			{
				out_num[i][set] = out_str[j];
				set++;
			}
		}
		else
		{
			out_num[i][0] = -1;
		}
	}
	for(i = 0; i < input; i++)
	{
		if(out_num[i][0] != -1)
		{
			int j = 0;
			while(out_num[i][j] != -2)
			{
				printf("%d", out_num[i][j]);
				j++;
			}
			printf("\n");
		}
		else if(out_num[i][0] == -1)
		{
			printf("overflow\n");
		}
	}
	return 0;
}

int plus(char in1[LENGTH], char in2[LENGTH], int out[LENGTH])
{
	int len1 = strlen(in1) - 1;
	int len2 = strlen(in2) - 1;
#ifdef DEBUG
	printf("%c\n%c\n", in1[len1], in2[len2]);
#endif
	int input = 0;
	int len;
	int dig_count = 1;
	if(len1 < len2)
	{
		len = len2 + 1;
	}
	else
	{
		len = len1 + 1;
	}
	int digit = 0;
	while(input < len)
	{
		int set1, set2;
		int sum = 0;
		if(len1< 0 && len2 < 0)
		{
			break;
		}
		else if(len1 < 0)
		{
			set2 = in2[len2] - '0';
			sum = set2;
			len2--;
		}
		else if(len2 < 0)
		{
			set1 = in1[len1] - '0';
			sum = set1;
			len1--;
		}
		else if(len1 >= 0 && len2 >= 0)
		{
			set1 = in1[len1] - '0';
			set2 = in2[len2] - '0';
			sum = set1 + set2;
			len1--;
			len2--;
		}
		int in_sum = sum + digit;
		sum = (sum + digit) % 10;
		out[input] = sum;
#ifdef DEBUG
		printf("%d", sum);
#endif
		input++;
		if((in_sum / 10) == 1)
		{
			digit = 1;
		}
		else
		{
			digit = 0;
		}
	}
	if(digit == 1)
	{
		out[len] = 1;
		input++;
	}
	return input;
}

Measured memory_bytes: 676
#include<bits/stdc++.h>
#define ll long long
#define Tipo int
#define ii pair<Tipo, Tipo>
#define vi vector<Tipo>
#define vii vector<ii>
#define fs first
#define sc second
#define oo 1000000009
#define N 200123

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    ll n, m;
    cin >> n >> m;
    n %= m;
    cout << min(n, abs(n - m)) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cmath>
#include<iostream>
#define maxn 100005
using namespace std;
char str[maxn];
long long k;
int main(){
	cin>>str>>k;
//	printf("%d",
	for(long long i=0;str[i]!='\0'&&k>0;){
	//	printf("%lld %lld",i,k);
		if(str[i]=='a'){i++;continue;}
	//	printf("ok");
	    while(('z'-str[i]+1)>k&&str[i]!='\0'){i++;}
	    if(str[i]!='\0'){
	    	k=k-('z'-str[i]+1);
	    	str[i]='a';
	    	i++;
		}
	//	printf("ok");
	}
	int len=strlen(str);
//	printf("%lld",k);
	if(k){
		while(k--){
			if(str[len-1]=='z')str[len-1]='a';
			else str[len-1]++;
		}
	}
//	printf("ok");
	cout<<str<<endl;
	return 0;
}
	


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
vector<int>g[100000],dp(100000,-1);
int rec(int i){
    if(dp[i]!=-1)return dp[i];
    for(auto x:g[i])dp[i]=max(dp[i],rec(x)+1);
    return dp[i]=max(dp[i],0);
}
int main(){
    int n,m,x,y,ans=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){cin>>x>>y;g[x-1].push_back(y-1);}
    for(int i=0;i<n;i++)ans=max(ans,rec(i));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll a, b;
  cin >> a >> b;
  ll bd = 0, tmpb = b;
  while(tmpb){
    tmpb /= 10;
    bd++;
  }
  ll d = 1;
  REP(i, bd) d *= 10;
  ll c = d * a + b;
  ll sc = sqrt(c);
  if(sc * sc == c) cout << "Yes";
  else cout << "No";
  return 0;
}


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

int main(void){
	int l, r;
	cin >> l >> r;
	if(r-l>=2019){
		cout << 0 << endl;
		return 0;
	}
	int ans = 2020;
	for(int i = l; i <= r; ++i){
		for(int j = i+1; j <= r; ++j){
			ans = min(ans, ((i%2019)*(j%2019))%2019);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC" << endl;
	}
	else if (R < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
int a,b;
int solve(int x){
    if(x<0){
        return 0;
    }
    else if(x%4==0){
        return x;
    }else if(x%4==3){
        return 0;
    }else if(x%4==2){
        return x+1;
    }else{
        return 1;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>a>>b;
    cout<<(solve(b)^solve(a-1))<<endl;
}


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

int H, W, i, j;
vector<string> fi;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

int main() {
    // 入力
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];
 // rep(i,H)rep(j,W)cout << fi[i][j] << endl;
    // 前処理
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Left[i][j] = cur;
        }
    }
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = W-1; j >= 0; --j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Right[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = 0; i < H; ++i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Up[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = H-1; i >= 0; --i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Down[i][j] = cur;
        }
    }

    // 集計
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') continue;
            res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 72448
/*
CF ID: Ankit717
LANG: C++
*/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define mod 1000000007
#define maxn 100005
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb push_back
#define pf push_front
#define nl cout << "\n";

const ll INF=1e18L+5;
 
struct Data{
	ll p;
	ll h;
};

void ini(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pll &a,pll &b){
	// if(a.first==b.first){
	// 	return a.second<b.second;
	// }else{
		return a.first>b.first;
	//}
}

// vector<pll> adj[maxn];
// vector<ll> par;
// vector<bool> vis;

ll gcd(ll a,ll b){
    while(a!=0){
        ll temp=a;
        a = b % a;
        b = temp;
    }

    return b;
}

// bool prime[maxn],near[maxn];
// void sieve(){
// 	f(i,0,maxn+1){
// 		prime[i]=true;
// 	}
// 	prime[0]=falsrime[1]=false;
// 	for(ll i=2;i*i<=maxn;i++){
// 		if(prime[i]){
// 			for(j=i*i;j<=maxn;j+=i){
// 				prime[j]=false;
// 			}
// 		}
// 	}
// }

void solve(){
	string s;
	cin >> s;
	ll cnt=(s[0]=='R'),ans=0;
	f(i,1,3){
		if(s[i]=='R' && s[i]==s[i-1]){
			cnt++;
		}else if(s[i]=='R' && s[i-1]=='S'){
			cnt++;
		}else if(s[i]=='S' && s[i-1]=='R'){
			ans=max(ans,cnt);
			cnt=0;
		}
	}
  ans=max(ans,cnt);

	cout << ans;
}

int main(){
	ini();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
    
	// ll t;
	// cin >> t;
	// f(i,0,t){
		solve();
	//}
}


Measured memory_bytes: 3648
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
    T tmp = r;
    r = l;
    l = tmp;
}



int main() {

  long n,t,k;
  cin >> n ;







  cout << ((n == 3 || n==5 || n==7)? "YES" : "NO" );

  // cout <<"w:" <<w << "  h:" <<h<<endl;


}




















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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  vector<ll> A(X), B(Y), C(Z);
  rep (i, X) cin >> A[i];
  rep (i, Y) cin >> B[i];
  rep (i, Z) cin >> C[i];

  vector<ll> AB;
  rep (i, X) rep (j, Y) AB.eb(A[i] + B[j]);

  sort(rall(AB));

  vector<ll> ans;
  rep (i, min(K, sz(AB))) rep (j, Z) {
    ans.eb(AB[i] + C[j]);
  }

  sort(rall(ans));

  rep (i, K) cout << ans[i] << endl;
}


Measured memory_bytes: 43112
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

int main(){
	int a,b;
	scanf("%d%d", &a, &b);
	if(a==b) printf("Draw\n");
	else if(a == 1) printf("Alice\n");
	else if(b == 1) printf("Bob\n");
	else if(a>b) printf("Alice\n");
	else if(b>a) printf("Bob\n");

	return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n;
    cin >> n;
    FOR(i, 1, 9)
        if(n % i == 0 && n / i < 10)
        {
            cout << "Yes";
            return 0;
        }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
vector<int> aa,bb,cc;
int main(){
      ll n,k;
cin>>n>>k;
if(k%2==1){
  ll c=n/k;
  cout<<c*c*c<<endl;
}else{
  ll nn=1;
  ll c=0,cc=0;
  while(nn<=n){
    if(nn%k==0){
      c++;
    }else if(nn%k==k/2){
      cc++;
    }
    nn++;
  }
  cout<<c*c*c+cc*cc*cc<<endl;
}
  
    
	return 0;
}


Measured memory_bytes: 256
/*
AizuOnline A1114
Title
*/
#include <stdio.h>
#define max(x,y) (((x)>(y))?(x):(y))
//Global data section
int area[5][5];
char area_bin[5];
int m;
char dummy[100];
int runlen_1[32] = {0,1,1,2,1,1,2,3,1,1,1,2,2,2,3,4,1,1,1,2,1,1,2,3,2,2,2,2,3,3,4,5};
//
void area2bin()
{
  int i,j,c;

  for(i=0;i<5;i++)
    {
      area_bin[i]=0; c=1;
      for(j=0;j<5;j++,c<<=1)
	area_bin[i]+=c*area[i][4-j];
#ifdef DEBUG2
      printf("%d\n",area_bin[i]);
#endif
    }
}

int widest_rect()
{
  int i,j,c,p,maxs;

  maxs=0;

  for(i=0;i<5;i++)
    {
      p = area_bin[i];
      maxs = max(maxs,runlen_1[p]*1);
      for(j=i+1;j<5;j++)
	{
	  p &= area_bin[j];
#ifdef DEBUG
	  printf("%d %d %d\n",i,j,p);
#endif
	  maxs = max(maxs,runlen_1[p]*(j-i+1));
	}
    }
  return(maxs);
}
main()
{
  int i,j,k,ret;

  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      for(j=0;j<5;j++)
	for(k=0;k<5;k++)
	scanf("%d",&area[j][k]);
      scanf("\n");
      area2bin();
      ret=widest_rect();
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 604
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

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

int main(){
  ll N;cin>>N;
  map<string, ll> m;

  rep(i,N){
    string st; cin>>st;
    m[st]++;
  }

  ll M;cin>>M;
  rep(i,M){
    string st; cin>>st;
    m[st]--;
  }

  ll ans = 0;
  for(auto it = m.begin(); it != m.end(); it++){
    ans = max(ans , it->second);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll P(N);
  bool all_ok = true;
  REP(i, 0, N) {
    ll p;
    cin >> p;
    P[i] = p - 1;

    if (P[i] == i) {
      all_ok = false;
    }
  }

  if (all_ok) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  REP(i, 0, N - 1) {
    if (P[i] == i) {
      ans++;
      ll tmp = P[i];
      P[i] = P[i + 1];
      P[i + 1] = tmp;
      i++;
    }
  }
  if (P[N - 1] == N - 1) {
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a[3], b[3];
int cnt[4];
int main(){
    REP(i, 3){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        cnt[a[i]]++;
        cnt[b[i]]++;
    }
    int one = 2, two = 2;
    REP(i, 4){
        if(cnt[i] == 1)one--;
        if(cnt[i] == 2)two--;
    }
    cout << (!one && !two ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n; cin>>n;
    int a=0,b=0,cnt=0,both=0;
    for(int i=0;i<n;i++){
        string s; cin>>s;
        for(int j=0;j<s.size()-1;j++){
            if(s[j]=='A'&&s[j+1]=='B')cnt++;
        }
        if(s[0]=='B'&&!(s[s.size()-1]=='A'))b++;
        if(!(s[0]=='B')&&s[s.size()-1]=='A')a++;
        if(s[0]=='B'&&s[s.size()-1]=='A')both++;
    }
    int ans=cnt+both-1;
    if(both==0)ans++;
    if(both>=1){
        if(b>=1){
            ans++;
            b--;
        }
        if(a>=1){
            ans++;
            a--;
        }
    }
    ans+=min(a,b);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(i,a,b) for (int i = a; i <= (b); ++i) 
#define MOD 10e9 + 7
#define INF 2147483646
#define INFLL 9223372036854775807
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
		　　　  　 ,ﾍ／L──- 、
		　　　   　Lﾆ)r_」=＝= ｲ
		　　 　,ﾍ、i ﾉノλﾉﾊﾉﾍ
		　　   ,'　｀(ﾊﾘ ﾟ ヮﾟﾉi)　',
		　　 .i　　 >〈(つ,i!と)　　i
		　　  vﾍγk´_/___i,ゝﾍノ
		　　　　　 ｀ﾞr_,ｨ_ｧﾞ´
	*/
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	int i, j,k;
	int N,M;
	cin >> N >> M;
	if (N == M) {
		cout << "Yes" << endl;
	}
	else {
		cout<<"No"<<endl;
	}
}

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

using namespace std;
typedef long long ll;

int sign(int A){ return (A>0) - (A<0); }

int func(){
    cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	int d[100000] = {0};
    cin >> n;
    for(int i = 0; i < n; i++) cin >> d[i];

    int count = 0;
    sort(d, d+n);
    int index = n/2 - 1;
    if(d[index] == d[index + 1]){
        count = 0;
    }else{
        count = d[index + 1] - d[index];
    }

    return count;
}

int main(){
    cout << func() << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

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

int main(){
  long long w,h,n,i,j;
  cin >> h >> w >> n;
  map<pair<int,int>,int> mp;
  map<pair<int,int>,int>::iterator it;
  vector<long long> v(10,0);
  for(i=0;i<n;i++){
    int l,c;
    cin >> l >> c;
    for(j=0;j<9;j++){
      if(l+dx[j]>0&&l+dx[j]<h-1&&c+dy[j]>0&&c+dy[j]<w-1)
        mp[make_pair(l+dx[j],c+dy[j])]++;
    }
  }
  long long sum = 0;
  for(it=mp.begin();it!=mp.end();it++){
    v[it->second]++;
    //cout << it->first.first << " " << it->first.second << " " << it->second << endl;
    sum++;
  }
  cout << (h-2)*(w-2)-sum << endl;
  for(i=1;i<10;i++){
    cout << v[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 56448
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
auto solve(string s_) {
    auto NM = s_.split.map!(to!int)();
    immutable N=NM[0], M=NM[1];
    auto g = new int[][N+1];
    auto c = new int[N+1];
    foreach(_;0..N-1+M) {
        auto AB = readln.split.map!(to!int)();
        immutable A=AB[0], B=AB[1];
        g[A]~=B;
        c[B]++;
    }
    int[] e; e.reserve(N);
    int[] e2; e2.reserve(N);
    auto t = new int[N];
    foreach(i;1..N) if(c[i]==0) e~=i;
    while(e.length) {
        e2.length=0;
        foreach(u;e) foreach(v;g[u]) if(--c[v]==0) {
            e2~=v;
            t[v-1]=u;
        }
        swap(e,e2);
    }
    return t.map!(to!string).join("\n");
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 12924