akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


ll N;
struct cnt { ll v; ll n; ll p; };

vector<vector<ll>> adj;
vector<vector<ll>> var;
vector<cnt> vsum;

void dfs1(int n=0,int p=-1) {
  vsum[n] = {1,1,p};
  for (auto x: adj[n]) {
    if (x==p) continue;
    dfs1(x,n);
    var[n].push_back(vsum[x].v);
    vsum[n].v += vsum[x].v;
    vsum[n].n = vsum[n].n*vsum[x].n%MOD;
  }
  ll now = 0;
  for (auto x: var[n]) {
    now += x;
    vsum[n].n = vsum[n].n*nck(now,x)%MOD;
  }
}

void dfs2(int n=0,int p=-1) {
  // cout << n << " " << p << endl;
  for (auto x: adj[n]) {
    if (x==p) continue;
    vsum[x].n = ((vsum[n].n * vsum[x].v)%MOD)*inv(N-vsum[x].v)%MOD;
    dfs2(x,n);
  }
}


int main() {
  c_fac();
  cin >> N;
  adj.resize(N);
  var.resize(N); vsum.resize(N);
  rep(i,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  dfs1(); dfs2();
  // rep(i,N) debug(all(var[i]));
  // rep(i,N) cout << vsum[i].v << " " << vsum[i].n << " " << vsum[i].p << endl;
  rep(i,N) cout << vsum[i].n << endl;
  return 0;
}

Measured memory_bytes: 35712
import copy as c

n, k = list(map(int, input().split()))
P = list(map(int, input().split()))


def solve(N, p, K):
    ans = sum(p[:K])
    #print(N, K, P)
    #ans = 0
    ans = c.copy(sum(p[:K]))
    sm = c.copy(ans)
    for i in range(K, N):
        #print(i-K, p[i-K], i, p[i])
        sm = sm - p[i-K] + p[i]
        ans = max(ans, sm)
        # print(ans)
    return ans


print(1/2.0 * k + 1.0/2 * solve(n, P, k))


Measured memory_bytes: 25572
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	vector<int>v(2 * N);
	for (int i = 0; i < 2 * N; i++) {
		v[i] = i + 1;
	}
	for (int i = 0; i < M; i++) {
		cin >> K;
		vector<int>w;
		if (!K) {
			for (int j = 0; j < N; j++) {
				w.push_back(v[j]);
				w.push_back(v[j + N]);
			}
		}
		else {
			for (int j = 0; j < 2 * N; j++) {
				w.push_back(v[(j + K) % (2 * N)]);
			}
		}
		v = w;
	}
	for (auto i : v)cout << i << endl;
	return 0;
}


Measured memory_bytes: 3160
N = int(input())
A = []
xy = []
for i in range(N):
  a = int(input())
  A.append(a)
  xykari = []
  for j in range(a):
    xykari2 = list(map(int, input().split()))
    xykari.append(xykari2)
  xy.append(xykari)

ans = 0

for i in range(2**N): # iはケース名
  honest = 0
  ng = 0
  for j in range(N):  # jはケースiでチェックする人j
    if ((i>>j)&1)==0:
      continue        # jが不親切なら次の人（j+1）のチェックに移る
    else:
      for k in range(A[j]):
        taisho = xy[j][k][0] - 1
        if xy[j][k][1] != ((i>>taisho)&1):
          ng = 1 
    honest += 1
  if ans < honest and ng == 0:
    ans = honest      # ansを更新

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n;
  cin>>n;
  int64 a[n];
  rep(i,n){
    cin>>a[i];
  }
  int countn=0;
  rep(i,n){
    if(a[i]<0){
      countn++;
    }
  }
  int64 ans=0;
  if(countn%2==0){
    rep(i,n){
      ans+=abs(a[i]);
    }
  }else{
    rep(i,n){
      ans+=abs(a[i]);
    }
    int64 mini=10000000000;
    rep(i,n){
      mini=min(mini,abs(a[i]));
    }
    ans-=2*mini;
  }
  cout<<ans;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef unsigned long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
 

 //1->year 2->month,3->both,4->Na
int check(char a,char b)
{
    if(a=='0'&&b=='0') return 1;
    if(a=='0'&&b!='0') return 3;
    if(a=='1'&&b<'3') return 3;
    else return 1;
}


 int main(void)
 {

    string date;
    cin>>date;

    int be = check(date[0],date[1]);

    int af = check(date[2],date[3]);

    if(be==1&&af==1) cout<<"NA"<<endl;
    if(be==1&&af==3) cout<<"YYMM"<<endl;
    if(be==3&&af==1) cout<<"MMYY"<<endl;
    if(be==3&&af==3) cout<<"AMBIGUOUS"<<endl;


 }

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int w;
  cin >> w;
  vi v(1, 1);
  int s = 1;
  for (int i = 1; s < w;) {
    i *= 3;
    s += i;
    v.pb(i);
  }
  cout << '+';
  for (int i = v.size() - 2; i >= 0; i--) {
    int x = v[i];
    if (s - x * 2 >= w) {
      s -= x * 2;
      cout << '-';
      continue;
    }
    if (s - x >= w) {
      cout << '0';
      s -= x;
      continue;
    }
    cout << '+';
  }
  cout << endl;
}

Measured memory_bytes: 3108
eval'N,M,A,*B='+`dd`.split*?,
s=[d=x=0]*9e5
B.map{|b|e=b
A>b&&b+=M
x+=t=b-A
[0,M].map{|m|s[m-~A]+=1
s[m+b]-=t
s[m-~b]+=t-1}
A=e}
p x-s.map{d+=$.+=_1}.max

Measured memory_bytes: 46288
N=int(input())
D,X=map(int,input().split())
A=list()
chocolate=0
for i in range(N):
    A.append(int(input()))
for i in range(D):
    for j in A:
        if ((i+1)%j==1)|(j==1):
            chocolate+=1
print(chocolate+X)

Measured memory_bytes: 9188
def tonari(h,w):
    kuro = False
    if h != 0:
        if S[h-1][w] == '#':
            kuro = True
    if h != H-1:
        if S[h+1][w] == '#':
            kuro = True
    if w != 0:
        if S[h][w-1] == '#':
            kuro = True
    if w != W-1:
        if S[h][w+1] == '#':
            kuro = True
    if kuro == False:
        print('No')
        exit()

H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            tonari(h,w)

print('Yes')

Measured memory_bytes: 3064
N, M, X = gets.split.map(&:to_i)
@book = $<.read.split.map(&:to_i).each_slice(M+1).to_a

dic = Array.new(M, 0)
@min = Float::INFINITY

def solve(dic, value, cnt)
  #puts "#{value} #{cnt}"
  if N <= cnt
  	#puts "#{dic} #{dic.min}"
  	@min = value if value < @min && X <= dic.min
  	return
  end
  
  1.upto(M) do |x|
  	#p "#{x} #{@book[cnt][x]}"
    dic[x-1] += @book[cnt][x]
  end
  
  solve(dic, value + @book[cnt][0], cnt +1)
  
  1.upto(M) do |x|
    dic[x-1] -= @book[cnt][x]
  end
  
  solve(dic, value, cnt +1)
  
end

solve(dic, 0, 0)

puts @min == Float::INFINITY ? '-1' : @min

Measured memory_bytes: 14376
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k;
vector<long long> vec, aq, sum;
map<int, int> mp;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	int cur = n;
	for (int i = 2; i * i <= n; i++) {
		if (n / i != cur) {
			cur = n / i;
			aq.pb(i - 1);
		}
	}
	if (aq.empty() || n / cur != aq[aq.size() - 1]) {
		aq.pb(n / cur);
	}
	int pre_idx = n / cur;
	while (1) {
		if (cur == 1) break;
		cur--;
		if (n / cur != pre_idx) {
			pre_idx = n / cur;
			aq.pb(n / cur);
		}
	}
	int len = aq.size();
	vec.resize(len);
	sum.resize(len);
	vec[0] = aq[0];
	for (int i = 1; i < len; i++) {
		vec[i] = aq[i] - aq[i - 1];
	}
	sum[0] = vec[0];
	for (int i = 1; i < len; i++) {
		sum[i] = sum[i - 1] + vec[i];
		sum[i] = sum[i] % MOD;
	}
	for (int i = 1; i < k; i++) {
		int tmp = len - 1;
		vec[0] = aq[0]*sum[tmp];
		vec[0] = vec[0] % MOD;
		for (int j = 1; j < len; j++) {
			tmp = len - 1 - j;
			vec[j] = (aq[j] - aq[j - 1])*sum[tmp];
			vec[j] = vec[j] % MOD;
		}
		sum[0] = vec[0];
		for (int i = 1; i < len; i++) {
			sum[i] = sum[i - 1] + vec[i];
			sum[i] = sum[i] % MOD;
		}
	}
	cout << sum[len - 1] << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    long long int X,Y;
    cin >> X >> Y;
    long long int ans = 0;
    int a =0;
    long long int A = X;
    for(int i = 0;1;i++){
      ans++;
      A = A*2;
      if(A >= X && A <= Y)a++;
      else break;
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    num_list = []
    for _ in range(n):
        num_list.append(int(input()))
    
    num_list.sort()

    min_count = 10**9
    for i in range(n-k+1):
        min_count = min(min_count, num_list[k-1+i]-num_list[i])

    print(min_count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 50392
#include <iostream>
#include <string>

bool solve(const std::string& s) {
  // [l, r)
  auto is_pali = [&](int l, int r) -> bool {
    int mid = (r - l) / 2 + l;
    for (int i = l; i < mid; ++i) {
      if (s[i] != s[r - 1 - i]) return false;
    }
    return true;
  };
  
  int len = s.length();
  int mid = len / 2;
  if (is_pali(0, len) && is_pali(0, mid) && is_pali(mid + 1, len))
    return true;
  return false;
}

int main() {
  std::string s;
  std::cin >> s;
  if (solve(s)) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

#define ll long long

struct element
{
	ll A;
	ll B;
};

bool operator<(const element &a, const element &b)
{
	return a.B < b.B;
}

int N;
element input[200005];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lld %lld", &input[i].A, &input[i].B);
	sort(input, input + N);

	ll sum = 0;

	bool fail = false;

	for (int i = 0; i < N; ++i)
	{
		sum += input[i].A;
		if (sum > input[i].B) fail = true;
	}

	if (fail) printf("No\n");
	else printf("Yes\n");

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
  int L;
  cin >> L;
  int a;
  a = pow(L,3);
  double b= a%27;
  int c= a/27;
  double d=b/27;
  if(d==0){
      cout << c << endl;
  }else{
      double e = c%10;
      int f = c/10;
      e = e+d;
      cout  << f<< e <<endl;
  }
  

  return 0;
}

Measured memory_bytes: 384
function bigAdd(A, B)
{
    var m, n, mn, i, j, carry, tmp;
    var buf, a1, a2;
    
    if(A.length > B.length){
        m = A.length;
        n = B.length;
        a1 = A.split("");
        a2 = B.split("");
    }
    else{
        m = B.length;
        n = A.length;
        a1 = B.split("");
        a2 = A.split("");
    }
    
    if( m > 80 ){
        console.log("overflow");
        return;
    }
    
    mn = m + 1;
    buf = new Array(mn);
    for(j=m-1,i=n-1,carry=0;i>=0;--i,--j){
        tmp = parseInt(a1[j]) + parseInt(a2[i]) + carry;
        buf[j+1] = tmp % 10;
        carry = parseInt(tmp / 10);
    }
    // Rest
    for(;j>=0;--j){
        tmp = parseInt(a1[j]) + carry;
        buf[j+1] = tmp % 10;
        carry = parseInt(tmp / 10);
    }
    buf[0] = carry;
    
    if( carry > 0 ){
        if( m == 80 ){
            console.log("overflow");
        }
        else{
            console.log(buf.join(""));
        }
    }
    else{
        console.log(buf.slice(1,mn).join(""));
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(input){
    var line = input.trim().split("\n");
    var i = 0;
    var N = parseInt(line[i++].trim());
    {
        for(;N>0;--N){
            bigAdd(line[i], line[i+1]);
            i=i+2;
        }
    }
});

Measured memory_bytes: 15664
N,D = gets.split(' ').map(&:to_i)

x = Array.new
N.times do |i|
	x[i] = gets.split(' ').map(&:to_i)
end

cnt = 0

(0..N-1).each do |i|
	(i+1..N-1).each do |j|
		sqdis = (0..D-1).map{|k| (x[i][k] - x[j][k]) ** 2}.inject(:+)
		if sqdis == (Math.sqrt(sqdis).round) ** 2
			cnt += 1
		end
	end
end

p cnt

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int ans;
  vector<int> A(3);
  for (int i=0; i<3; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  ans=A.at(0)+A.at(1)+10*A.at(2);
  cout << ans << endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;

int main() {
    rep(i,3){
        rep(j,3){
            cin >> a[i][j];
        }
    }
    cin >> n;
    rep(i,n){
        int b ;cin >> b;
        rep(j,3){
            rep(k,3){
            if(a[j][k]==b){
                   ok[j][k]=true;
                }
               
            }
        }
    }

    bool ans = false;
    rep(i,3){
        int cnt = 0;
        rep(j,3){
            if(ok[i][j]) cnt++;
        }
        if(cnt == 3) ans = true;
    }
    rep(j,3){
        int cnt = 0;
        rep(i,3){
            if(ok[i][j]) cnt++;
        }
        if(cnt == 3) ans = true;
    }

   if(ok[0][0]&&ok[1][1]&&ok[2][2]) ans = true;
    if(ok[0][2]&&ok[1][1]&&ok[2][0]) ans = true;

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;


   
 }


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

sum_v = sum(a)
min_v = 10**10
x = 0
for i in range(0,N-1):
    x += a[i]
    y = sum_v - x 
    
    min_v = min(min_v, abs(x-y))
print(min_v)


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<'\n'



int main(){
    int n;
    cin >> n;
    int ans = 0,count=1;
    while(ans<n){
        ans += count;
        count++;
    }
    int num = ans - n;
    FOR(i,1,count){
        if(i==num)continue;
        COUT(i);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000

int main(){
  int N;
  cin>>N;
  map<string,int> m;
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    m[S]=1;
  }

  cout<<m.size()<<endl;
}


Measured memory_bytes: 19260
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  cout << (S[2] == S[3] && S[4] == S[5] ? "Yes" : "No") << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    rep(i,n){
        cin >> a[i].first;  // pair型vectorはfirstでsortされる
        a[i].second = i;
    }

    sort(a.begin(), a.end());

    rep(i,n){
        if(i == a[n-1].second)
            cout << a[n-2].first << endl;
        else
            cout << a[n-1].first << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
//#define _GLIBCXX_DEBUG//only for debugging
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0)->ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod=1e9+7;
/* VARIABLE DECLARATION START */
int arr[int(1e5+1)];
/*  FUCNTION TEMPLATE STARTS  HERE */

double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA
   int n,k,x,y;
   cin>>n>>k>>x>>y;
   int sum=0;
   if(n>=k)
   {
    sum+=(k*x);
    n-=k;
    if(n>0)
      sum+=(n*y);
    cout<<sum<<endl;
   }
   else
   {
    cout<<n*x<<endl;
   }

}

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

int main(){
    int a=6;
    int b,c;
    cin>>b>>c;
    cout<<6-b-c<<endl;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
)
 
func main() {
  var a, b, c int
  five := 0
  seven := 0
  
  fmt.Scanf("%d", &a)
  if a == 5 {
    five++
  }
  if a == 7 {
    seven++
  }
  fmt.Scanf("%d", &b)
  if b == 5 {
    five++
  }
  if b == 7 {
    seven++
  }
  fmt.Scanf("%d", &c)
  if c == 5 {
    five++
  }
  if c == 7 {
    seven++
  }
  
  ans := "NO"
  if five == 2 && seven == 1{
    ans = "YES"
  }
  
  fmt.Printf("%s", ans)
}

Measured memory_bytes: 1832
#include <stdio.h>
#include <stdlib.h>

void merge_sort(long long x[], int n)
{
	static long long y[1001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

typedef struct {
	long long key;
	int id[3];
} data;

typedef struct {
	data *obj;
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = h->size;
	data tmp;
	h->obj[(h->size)++] = x;
	while (1) {
		if (i == 0) break;
		else if (h->obj[i].key > h->obj[(i-1)/2].key) {
			tmp = h->obj[(i-1)/2];
			h->obj[(i-1)/2] = h->obj[i];
			h->obj[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 0, j;
	data output = h->obj[0], tmp;
	h->obj[0] = h->obj[--(h->size)];
	while (1) {
		if (i * 2 + 1 >= h->size) break;
		else if (i * 2 + 2 >= h->size) j = i * 2 + 1;
		else if (h->obj[i*2+1].key > h->obj[i*2+2].key) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

#define Mod 100003

typedef struct List {
	struct List *next;
	int id[3];
} list;

int main()
{
	int i, j, k, X, Y, Z, K;
	long long A[1001], B[1001], C[1001];
	scanf("%d %d %d %d", &X, &Y, &Z, &K);
	for (i = 0; i < X; i++) scanf("%lld", &(A[i]));
	for (i = 0; i < Y; i++) scanf("%lld", &(B[i]));
	for (i = 0; i < Z; i++) scanf("%lld", &(C[i]));
	merge_sort(A, X);
	merge_sort(B, Y);
	merge_sort(C, Z);
	
	list *hash[Mod] = {}, appear[10001], *p;	
	data d;
	max_heap h;
	h.size = 0;
	h.obj = (data*)malloc(sizeof(data) * K * 3);
	d.key = A[X-1] + B[Y-1] + C[Z-1];
	d.id[0] = X - 1;
	d.id[1] = Y - 1;
	d.id[2] = Z - 1;
	push(d, &h);
	appear[0].id[0] = X - 1;
	appear[0].id[1] = Y - 1;
	appear[0].id[2] = Z - 1;
	appear[0].next = hash[d.key % Mod];
	hash[d.key % Mod] = &(appear[0]);
	for (i = 1, k = 1; i <= K; i++) {
		d = pop(&h);
		printf("%lld\n", d.key);
		for (j = 0; j < 3; j++) {
			if (d.id[j] > 0) {
				d.id[j]--;
				d.key = A[d.id[0]] + B[d.id[1]] + C[d.id[2]];
				for (p = hash[d.key % Mod]; p != NULL; p = p->next) if (p->id[0] == d.id[0] && p->id[1] == d.id[1] && p->id[2] == d.id[2]) break;
				if (p == NULL) {
					push(d, &h);
					appear[k].id[0] = d.id[0];
					appear[k].id[1] = d.id[1];
					appear[k].id[2] = d.id[2];
					appear[k].next = hash[d.key % Mod];
					hash[d.key % Mod] = &(appear[k++]);
				}
				d.id[j]++;
			}
		}
	}
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2824
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	char s[3];
	int acnt=0,bcnt=0,ccnt=0;
	for(int x=0;x<3;x++)
	{
		cin>>s[x];
	}
	for(int i=0;i<3;i++)
	{
		if(s[i]=='a')
			acnt++;
	}
	for(int j=0;j<3;j++)
	{
		if(s[j]=='b')
			bcnt++;
	}
	for(int k=0;k<3;k++)
	{
		if(s[k]=='c')
			ccnt++;
	}
	if(acnt==1&&bcnt==1&&ccnt==1)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int a,b,x;
    cin >> a >> b >> x;
    int first = x;
    int second = x;
    set<int> st;
    for(int i=a;first && i<=b; first--, i++){
        st.insert(i);
    }
    for(int i=b;second && i>=a; second--, i--){
        st.insert(i);
    }
    for(auto it=st.begin(); it!= st.end(); it++){
        cout << *it <<endl;
    }
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int N,T, A;
	int H[1010];
	cin >> N;
	cin >> T>>A;
	for (int i = 0; i < N;i++) {
		cin >> H[i];
	}
	double ter;
	ter = 1000.0 / 6.0 * double(T - A);
	int ans = 0;
	double temp = 10000000.0;
	for (int i = 0; i < N;i++) {
		if (fabs(double(H[i]) - ter) < temp) {
			ans = i+1;
			temp = fabs(double(H[i]) - ter);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int):
    s = sum([int(i) for i in str(N)])
    if N % s == 0:
        return "Yes"

    return "No"


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

if __name__ == '__main__':
    main()


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(N+1, vector<int>());
    vector<int> in(N+1, 0);
    for (int i = 0; i < N-1+M; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        in[b]++;
    }
    int root;
    for (int i = 1; i <= N; i++){
        if (in[i] == 0) {
            root = i;
            break;
        }
    }
    
    vector<int> par(N+1);
    par[root] = 0;
    queue<int> q;
    q.push(root);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (in[nxt] == 1) {
                par[nxt] = now;
                q.push(nxt);
            }
            else in[nxt]--;
        }
    }
    for (int i = 1; i <= N; i++) cout << par[i] << endl;
    return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

void solve()
{
   int n,m;
   cin >> n >> m;
   vector<int>arr(m);
   long long sum=0;
   for (int c=0;c<m;c++)
    cin >> arr[c],sum+=arr[c];
    if (sum>n)
        cout << -1 << endl;
    else 
        cout << n-sum << endl;


}


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

    }

    
    return 0;
}




Measured memory_bytes: 3640
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n;p[0]=l[0]
for i in range(1,n):p[i]=l[i]+(p[i-2]if i>1else 0);d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+(d[i-2]if i>1else 0))
print(d[-1])

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

int main() {
	int n, x = 0, X = x;
	string s;
	cin >> n >> s;
	for(int i=0;i<n;++i) {
		if(s[i]=='I') ++x;
		if(s[i]=='D') --x;
		if(x>X) X = x;
	}
	cout << X << '\n';
}

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

static const double eps = 1e-10;
typedef complex<double> point;
struct circle { point p; double r; };
inline double sq(double x) { return x * x; }

pair<point, point> cross(const circle& c1, const circle& c2)
{
    double d = abs(c1.p - c2.p);
    double rc = (sq(d) + sq(c1.r) - sq(c2.r)) / (2*d);
    double rs = sqrt(sq(c1.r) - sq(rc));
    point diff = (c2.p - c1.p) / d;
    return make_pair(c1.p + diff * point(rc, rs),
                     c1.p + diff * point(rc, -rs));
}

bool check_point(const vector<circle>& circles, point p)
{
    return all_of(begin(circles), end(circles),
            [p](const circle& c){ return sq(c.r + eps) > norm(c.p - p); });
}

bool check(const vector<circle>& ropes, double h)
{
    vector<circle> circles;
    for (const auto& c : ropes) {
        double r = sqrt(sq(c.r) - sq(h));
        circles.push_back({ c.p, r });
    }

    for (int i = 0; i < (int)circles.size(); ++i) {
        const circle& c1 = circles[i];
        if (check_point(circles, c1.p))
            return true;

        for (int j = i + 1; j < (int)circles.size(); ++j) {
            const circle& c2 = circles[j];
            double sqd = norm(c1.p - c2.p);
            if (sq(c1.r + c2.r) <= sqd)
                return false;
            auto cp = cross(c1, c2);
            if (check_point(circles, cp.first))
                return true;
            if (check_point(circles, cp.second))
                return true;
        }
    }

    return false;
}

int main()
{
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n, n) {
        double lo = 0, hi = 1e10;
        vector<circle> ropes;

        for (int i = 0; i < n; ++i) {
            double x, y, r;
            cin >> x >> y >> r;
            ropes.push_back({ point(x, y), r });
            hi = min(hi, r);
        }

        for (int i = 0; i < 100; ++i) {
            double mid = (lo + hi) / 2;
            if (check(ropes, mid))
                lo = mid;
            else
                hi = mid;
        }

        cout.precision(15);
        cout << hi << endl;
    }
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n, m; cin>>n>>m;
    vector<int> comp(n+10), judge(m+10);
    for(int i=0; i<n; i++) cin>>comp[i];
    for(int i=0; i<m; i++) cin>>judge[i];

    vector<int> cnt(n+10, 0);

    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            if(comp[j] <= judge[i]){
                cnt[j+1]++;
                break;
            }
        }
    }

    int ans=0, data;
    for(int i=1; i<=n; i++){
        if(cnt[i] > ans){
            ans=cnt[i];
            data=i;
        }
    }
    cout << data << endl;
}


Measured memory_bytes: 3100
#include <iostream>

using namespace std;
long long dp[405][405],s[405],a[405],i,j,k,n;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        s[i]=s[i-1]+a[i];
    }
    for(k=1;k<n;k++)
    {
        for(i=1;i+k<=n;i++)
        {
            dp[i][i+k]=a[i]+dp[i+1][i+k]+s[i+k]-s[i];
            for(j=i+1;j<i+k;j++)
            {
                dp[i][i+k]=min(dp[i][i+k], dp[i][j]+dp[j+1][i+k]+s[i+k]-s[i-1]);
            }
        }
    }
    cout<<dp[1][n];
    return 0;
}


Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var n = int.Parse(Console.ReadLine());
    var aho = Console.ReadLine();
    var kasa = 0;
    var mae = aho[0];
    for(var i = 1;i<n;i++){
      if(mae == aho[i]) kasa++;
      else mae = aho[i];
    }
    Console.WriteLine(n-kasa);
   
    
  }
}

Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
import itertools
n,w = map(int,input().split())
c = []
s = 0
for i in range(n):
  a,v = map(int,input().split())
  s += a
  c.append((a,v))
  
r = c[0][0]
L = min(100,w//r)
m = s-r*n+1
dp = [[[-float('inf')]*m for i in range(L+1)] for i in range(n+1)]
for i in range(n):
  dp[i][0][0] = 0

for i in range(n):
  for j in range(L):
    for k in range(m):
      W,V = c[i]
      R = W-r
      if k-R >= 0 and r*(j+1)+k <= w:
        dp[i+1][j+1][k] = max(dp[i][j+1][k],dp[i][j][k-R]+V)
      else:
        dp[i+1][j+1][k] = dp[i][j+1][k]
        
print(max(0,max(list(itertools.chain.from_iterable(dp[n])))))

Measured memory_bytes: 10496
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
#define mod 1000000007
#define G() Cr=getchar()
int Xr;char Cr;
inline int rd(){   //读入优化
    Xr=0,G();
    while(Cr<'0'||Cr>'9')G();
    while(Cr>='0'&&Cr<='9')Xr=(Xr<<3)+(Xr<<1)+Cr-'0',G();
    return Xr;
}
int ans;
int k,n;
int va[200005];
int main(){
	k=rd(),n=rd();
	for(int i=1;i<=n;i++)va[i]=rd();
	sort(va+1,va+1+n);
	ans=k-va[n]+va[1];
	va[++n]=k;
	for(int i=0;i<n;i++)ans=max(ans,va[i+1]-va[i]);
	cout<<k-ans;
}


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

def num_base10_to_num_baseN(num_base_10, base_N):
    if num_base_10 < base_N:
        return [num_base_10]
    else:
        result_list = num_base10_to_num_baseN(num_base_10 // base_N, base_N)
        result_list.append(num_base_10 % base_N)
        return result_list

s = num_base10_to_num_baseN(n, 26)

for i in range(len(s) - 1, 0, -1):
    if s[i] <= 0:
        s[i] += 26
        s[i - 1] -= 1

print("".join([chr(96 + x) for x in s if x != 0]))

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

int main(){
  string s;
  cin >> s;
  long long size = s.size();
  long long sum = 0;
   
  for(long long i=0; i < ( 1 << (size-1) ); i++){
    long long tmp = 0;
    long long tmp_sum = 0;
    bitset<10> plus(i);
    for(long long j = 0; j < (size); j++){
      if(plus.test(j)){
        tmp_sum += tmp*10 + s.at(j) - '0';
        tmp = 0;
      }else{
        tmp = tmp*10 + s.at(j) - '0';
      }
    }
    sum += (tmp_sum + tmp);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
areaStr = list(input())
N = len(areaStr)
tmpArea = []
totalArea = 0
eachArea = []
"""
for i in range(N):
    if areaStr[i] == "\\":
        tmpArea.append(i)
    elif areaStr[i] == "/":
        if len(tmpArea) != 0:
            totalArea += (i - tmpArea.pop())
    else:
        pass
    
"""


tmpArea = []
totalArea = 0
for i in range(N):
    if areaStr[i] == "\\":
        tmpArea.append(i)
    elif areaStr[i] == "/":
        if len(tmpArea) != 0:
            j = tmpArea.pop()
            
            totalArea += (i - j)
            a = i - j
            while(len(eachArea) > 0 and eachArea[len(eachArea) - 1][0] > j):
                a +=  eachArea.pop()[1]
               
            eachArea.append([j, a])
    else:
        pass
    

print(totalArea)
print(len(eachArea), end = "")
if len(eachArea) > 1:
    for i in range(len(eachArea)-1):
        print("", end = " ")
        print(eachArea[i][1], end = "")
if len(eachArea) >= 1:
    print("", end = " ")
    print(eachArea[len(eachArea)-1][1])
    
else:
    print("")








Measured memory_bytes: 7028
import sys
from pprint import pprint

from collections import deque

h, w = map(int, sys.stdin.readline().strip().split(" "))
field = []
for _ in range(h):
    field.append(list(sys.stdin.readline().strip()))

# pprint(field)

q = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            q.append((0, i, j))

while q:
    count, y, x = q.popleft()
    for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
        if 0 <= y+dy < h and 0 <= x+dx < w:
            # print(y+dy, x+dx, field[y+dy][x+dx])
            if field[y+dy][x+dx] == "#":
                continue
            else:
                field[y+dy][x+dx] = "#"
                q.append((count+1, y+dy, x+dx))

# pprint(field)
print(count)

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


using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


void go(){
	int n,k;cin>>n>>k;
	int x=1;
	while(n--) {
		if(x*2<x+k) {
			x*=2;
		}else {
			x+=k;
		}
	}
	cout<< x;
}
int main(){
   
   fastio();
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}




Measured memory_bytes: 3664
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int N;
    // vector<int> d(N,0);
    int d[99] = {};

    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> d[i];
    }

    int sum = 0;
    for(int i = 1 ; i < N ; i++){
        for(int j = 0 ; j < i ; j++){
            sum +=  d[i]*d[j];
        }
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
n = gets.to_i
nums = gets.split(" ").map(&:to_i)
even_count = 0
count = 0

while true do
    nums.each_with_index do |num, i|
        if num%2 == 0
           even_count += 1
           nums[i] /= 2
        end
    end
    if even_count != n 
        break
    end
    even_count = 0
    count += 1
end

puts count

Measured memory_bytes: 1788
a, b = map(int, input().split())
s = input()
ans = 0
for i in range(len(s)):
    if s[i] == "-":
        if i == a and len(s)-i-1 == b:
            ans = 1
            for j in range(b):
                if s[-j] == "-":
                    ans = 0
                    break
            break
if ans == 0:
    print("No")
else:
    print("Yes")
            

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    string s,a;
    cin >> s;
    int i=0,j=0;
    for(i=0;i<s.size();i++){
      if(s[i]=='0'){
        a.push_back('0');
        j++;
      }else if(s[i]=='1'){
        a.push_back('1');
        j++;
      }else{
        j=max(0,j-1);
        a=a.substr(0,j);
      }
    }
    cout << a;
    return 0;
}


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

int main(){
    int h,w;
    cin>>h>>w;
    string a,s(w+2,'#');
    cout<<s<<endl;
    for(int i=0;i<h;i++){
        cin>>a;
        cout<<'#'+a+'#'<<endl;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
for i in T:
    l = 0
    r = n
    while l<r:
        mid = (l+r)//2
        if S[mid] == i:
            ans+=1
            break
        elif S[mid]>i:
            r=mid
        elif S[mid]<i:
            l=mid+1  
print(ans)            


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    int ans = INF;
    int cnt = 0;
    bool flg = false;
    for(int i = 0; i < s.size(); ++i){
        if(!!(s[i] - '0') != flg) ++cnt;
        flg = !flg;
    }
    ans = cnt;
    cnt = 0;
    flg = true;
    for(int i = 0; i < s.size(); ++i){
        if(!!(s[i] - '0') != flg) ++cnt;
        flg = !flg;
    }
    ans = min(ans, cnt);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    System.out.println((N * (N - 1))/2 + (M * (M - 1))/2);
  }
}

Measured memory_bytes: 23764
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}




int main(){
    string s;
    cin>>s;
    for(int i=1;i<4;i++){
        if(s[i-1]==s[i]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

bool CountAlpha(const string, map<char, int>*);
double PalindromicAnagram(map<char, int>);
double Factorial(int);

int main(){
  double ans;
  string str;
  map<char, int> data;

  cin >> str;
  sort(str.begin(), str.end());

  if(CountAlpha(str, &data)){
    ans = PalindromicAnagram(data);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(0);
    cout << ans << endl;
  }else{
    cout << "0" << endl;
  }

  return 0;
}

bool CountAlpha(const string str, map<char, int>* data){
  int i, j, k, n;
  for(i=1, j=0, n=0; i<=str.size(); ++i){
    if(i == str.size() || str[i] != str[j]){
      k = i-j;
      if(k%2 == 1) ++n;
      data->insert(make_pair(str[j], k/2));
      j=i;
    }
  }
  if(n <= 1) return true;
  else return false;
}

double PalindromicAnagram(map<char, int> data){
  int n=0;
  double m=1.0;
  map<char, int>::iterator i;
  for(i=data.begin(); i!=data.end(); ++i){
    if(i->second == 0) continue;
    n += i->second;
    m *= Factorial(i->second);
  }
  return Factorial(n)/m;
}

double Factorial(int n){
  int i;
  double ans=1.0;
  for(i=1; i<=n; i++) ans *= i;
  return ans;
}

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

using namespace std;
void solve(){
    int n;
    cin>>n;
    vector<pair<int,int>> points(n);
    for(auto &[x,y] : points){
        cin>>x>>y;
    }
    sort(points.begin(), points.end());
    int mn1 = 1e9, mn2 = 1e9;   //x+y, x-y
    int ans = 0;
    for(auto &[x,y] : points){
        mn1 = min(mn1, x+y);
        mn2 = min(mn2, x-y);
        ans = max(ans, x+y - mn1);
        ans = max(ans, x-y - mn2);
    }
    cout<<ans<<"\n";
}
int main(){
  solve();
  return 0;
}

Measured memory_bytes: 4852
import math
NN = int(input())

def power_func(a,n,p):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res


a = power_func(10, NN , 10 ** 9 + 7)
b = power_func(9 , NN , 10 ** 9 + 7)
c = power_func(8 , NN , 10 ** 9 + 7)

x = ((a - b - b + c) + 10 ** 9 + 7 + 10 ** 9 + 7 ) % (10 ** 9 + 7)
print(x)



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

using namespace std;

int a[1000000];

int main(){
	int n, num = 0;
	scanf("%d", &n);
	for(int i = 0, x; i < n; i ++){
		scanf("%d", &x);
		if(x > n || a[x] == x) num++;
		else a[x] ++;
	}
	for(int i = 0; i <= 100000; i++){
		if(a[i] != i) num += a[i];
	}
	printf("%d\n", num);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i = 1;
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                System.out.print(" " + i);
            } else {
                while (x != 0) {
                    if (x % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
                    x /= 10;
                }
            }
            i++;
        }
        System.out.println();
    }
}


Measured memory_bytes: 28900
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; 
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    vector<pair<long long, long long> >prime_list = prime_factorize(N);
    int count = 0;
    int ps = prime_list.size();
    for (int i=0; i < ps; i++) {
        pair<long long, long long> w = prime_list[i];
        long long num = w.first;
        long long ex = w.second;
        int minus_count = 1;
        while (ex >= 1) {
            ex = ex - minus_count;
            if (ex >= 0) {
                count += 1;
                minus_count += 1;
            }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>

using namespace std;

int main()
{
  long long q,h,s,d,n;
  cin>>q>>h>>s>>d>>n;
  long long one=s;
  if(one>h*2)
    one=h*2;
  if(one>q*4)
    one=q*4;
  long long two=d;
  if(two>one*2)
    two=one*2;
  cout<<(n/2)*two+(n%2)*one<<endl;
}

Measured memory_bytes: 256
// AOJ 0635 Snake JOI
// 2018.2.15 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char uchar;
#define QMAX 10000
typedef struct { int t, s; uchar b, x; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t, uchar b, uchar x)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t, que[i].b = b, que[i].x = x;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define MAX 20
#define MIN(a,b)  ((a)<=(b)?(a):(b))

uchar t[10002];
int to[10002][MAX]; uchar d[10002][MAX]; short hi[10002];
char mk[10002][3][201];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int dijkstra(int start, int goal, int X)
{
	int i, u, v, c, k;
	unsigned char b, x, b2, x2;

	qsize = 0;
	enq(start, 0, 1, X);		// t[0] = 1
	while (qsize) {
		u = que[0].s, c = que[0].t, b = que[0].b, x = que[0].x, deq();
		if (u == goal) break;

		if (mk[u][b][x]) continue;
		mk[u][b][x] = 1;

		for (i = 0; i < hi[u]; i++) {
			v = to[u][i];
			if ((b | t[v]) == 3 && d[u][i] < x) continue;
			k = MIN(d[u][i], x);
			if (mk[v][b][k]) continue;
			if (t[v] > 0) b2 = t[v], x2 = X;
			else b2 = b, x2 = (x < d[u][i])? 0: x-d[u][i];
			enq(v, c+d[u][i], b2, x2);
		}
	}
	return c;
}

int main()
{
	int N, M, X, i, a, b, c;

	N = in(), M = in(), X = in();

	for (i = 0; i < N; i++) {
		a = getchar_unlocked() & 3; if (a < 2) a = !a;
		t[i] = a;			// 0:快適, 1:寒, 2:暑. 
		getchar_unlocked();
	}

	while (M--) {
		a = in()-1, b = in()-1, c = in();
		i = hi[a]++, to[a][i] = b, d[a][i] = c;
		i = hi[b]++, to[b][i] = a, d[b][i] = c;
	}

	printf("%d\n", dijkstra(0, N-1, X));
	return 0;
}


Measured memory_bytes: 7828
n = int(input())
l = list(map(int, input().split(" ")))
for i, v in enumerate(l):
    j = i - 1
    while j >= 0 and l[j] > v:
        l[j + 1] = l[j]
        j -= 1
    l[j + 1] = v
    print(*l)


Measured memory_bytes: 5976
#include <stdio.h>

int main(void) {
	int N, a;
	int max = 0, min = 1000;

	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d",&a);
		if (a > max) max = a;
		if (a < min) min = a;
	}

	printf("%d\n", max - min);

	return 0;
}

Measured memory_bytes: 128