akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n;cin>>n;
	cout<<(n-1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
import Foundation

let s = Int(readLine()!)!
var a = [s]

var ai = s
for_m: for m in 1 ... 1000000 {
    if ai % 2 == 0 {
        ai = ai / 2
    } else {
        ai = 3 * ai + 1
    }
    a.append(ai)
    
    for n in 0 ..< m {
        if a[n] == a[m] {
            print(m+1)
            break for_m
        }
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int d[100][100];
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
int x, y, size;

int main(){
	while (scanf("%d,%d,%d", &x, &y, &size)!=EOF){
		if (size == 1){
			d[x][y]++;
			for (int i = 0; i < 4; i++){
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (nx >= 0 && ny >= 0 && nx < 10 && ny < 10){
					d[x + dx[i]][y + dy[i]]++;
				}
			}
		}
		if (size == 2){
			for (int i = -1; i <= 1; i++){
				for (int j = -1; j <= 1; j++){
					if (x + i >= 0 && x + i < 10 && y + j >= 0 && y + j < 10){
						d[x + i][y + j]++;
					}
				}
			}
		}
		if (size == 3){
			for (int i = -2; i <= 2; i++){
				for (int j = -2; j <= 2; j++){
					if (abs(i) + abs(j) <= 2){
						if (x + i >= 0 && x + i < 10 && y + j>=0 && y + j < 10){
							d[x + i][y + j]++;
						}
					}
				}
			}
		}
	}
	int ans = 0 , MAX = 0;
	REP(i, 10){
		REP(j, 10){
			if (d[i][j] == 0)ans++;
			MAX = max(MAX, d[i][j]);
		}
	}
	cout << ans << endl;
	cout << MAX << endl;
}

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


int h[101];
int N;

int count(int h[], int l, int r) {

  // cout << "[C]";
  // for (int i = 1; i <= N; i++) { cout << h[i] << " "; }
  // cout << endl;

  bool flag = true;
  for (int i = 1; i <= N; i++) { if (h[i] != 0) flag = false;}
  if (flag)
    return 0;

  if (l > r)
    return 0;

  int hmin = 1e9;
  for (int i = l; i <= r; i++) { hmin = min(h[i], hmin); }
  for (int i = l; i <= r; i++) { h[i] -= hmin; }

  int firstMin = l;
  while (h[firstMin] > 0) {
    firstMin++;
  }
  // cout << hmin << ":" << firstMin << " in [" << l << "," << r << "]" << endl;

  int ll = l, lr = firstMin - 1;
  int rl = firstMin + 1, rr = r;
  // printf("[%d,%d]\n", ll, lr);
  // printf("[%d,%d]\n", rl, rr);
  int cL = count(h, ll, lr);
  int cR = count(h, rl, rr);
  return hmin + cL + cR;
}


int main(void) {
  cin >> N;
  for (int i = 1; i <= N; i++) { cin >> h[i]; }
  int ans = count(h, 1, N);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
int main(){
    string s,t;
    cin>>s>>t;
    int n=s.length();
    bool ans=true;
    rep(i,n){
        if(s[i]!=t[i]){
            ans = false;
        }
    }
    YN(ans);
}

Measured memory_bytes: 3624
N, Q = map(int, input().split())
S = list(input())
L = [0]
cnt = 0

for i in range(1, N):
  if S[i-1] == "A" and S[i] == "C":
    cnt += 1
  L.append(cnt)

for _ in range(Q):
  l, r = map(int, input().split())
  print(L[r-1] - L[l-1])

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

ll n,k;
ll mod = 1e9+7;

ll modpow(ll a,ll b){
    if(b == 0) return 1;
    ll ans = modpow(a,b/2);
    ans *= ans;
    ans %= mod;
    if(b%2 == 1) ans = ans*a%mod;
    return ans;
}

int main(){
    cin >> n >> k;
    vector<ll> vec(k);
    for(ll i = k;i >= 1;i--){
        ll num = modpow(k/i,n);
        for(int j = 2;i*j <= k;j++){
            num -= vec[i*j-1];
            if(num < 0) num += mod;
        }
        vec[i-1] = num%mod;
    }
    ll ans = 0;
    for(ll i = 0; i< k;++i){
        ans = ans + (i+1)*vec[i]%mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3976
a,b,c=map(int,input().split())
d=int(input())
ans=0
for i in range(d):
  if a<b:
    pass
  else:
    b=b*2
    ans=ans+1
for j in range(d-ans):
  if b<c:
    pass
  else:
    c=c*2
    ans=ans+1
if c>b:
  print('Yes')
else:
  print('No')
    


Measured memory_bytes: 9120
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		char[] s = new char[S.length()];
		for(int i = 0; i < S.length(); i++) {
			s[i] = S.charAt(i);
		}
		s[3] = '8';
		System.out.println(s);

	}

}

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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    Int x = a[0];
    Int y = accumulate(all(a), (Int)0) - a[0];
    Int res = abs(x - y);
    for (Int i = 1; i < n - 1; i++) {
        x += a[i];
        y -= a[i];
        res = min(res, abs(x - y));
    }
    print(res);
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 4824
n = gets.to_i
a = gets.split.map(&:to_i)

def func a
  n = a.size
  b = a.map.to_a
  c = n.times.map{|i| b[i]/n}
  sum = c.inject(:+)
  n.times{|i|
    a[i] = sum + b[i]%n - c[i]
  }
  sum
end

ans = 0
while(1)
  res = func(a)
  ans += res
  break if res==0
end

p ans


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    string ans = "No";
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(N == i*j){
                ans = "Yes";
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, a = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
sum = x.inject(:+)
dp = Array.new(n + 1) { Array.new(sum * 2 + 1) }
(0..sum * 2).each do |j|
  dp[0][j] = 0
end
dp[0][sum] = 1

(1..n).each do |i|
  (0..sum * 2).each do |j|
    dp[i][j] =
    if j - (a - x[i - 1]) >= 0 && j - (a - x[i - 1]) <= sum * 2
      dp[i - 1][j] + dp[i - 1][j - (a - x[i - 1])]
    else
      dp[i - 1][j]
    end
  end
end

puts dp[n][sum] - 1


Measured memory_bytes: 3836
#include<stdio.h>
#include<string.h>
int main(void){
  char s[4];
  scanf("%s",s);
  if(strcmp(s,"SUN")==0){
    printf("7\n");
  }
  if(strcmp(s,"MON")==0){
    printf("6\n");
  }
  if(strcmp(s,"TUE")==0){
    printf("5\n");
  }
  if(strcmp(s,"WED")==0){
    printf("4\n");
  }
  if(strcmp(s,"THU")==0){
    printf("3\n");
  }
  if(strcmp(s,"FRI")==0){
    printf("2\n");
  }
  if(strcmp(s,"SAT")==0){
    printf("1\n");
  }
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    
    string s;
    cin >> s;
    int counter = 0;
    int sum = 700;
    for(counter = 0;counter < 3;counter++){
    if(s[counter] == 'o' ){
        sum = sum + 100;
    }
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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

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

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

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	n := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		if i%2 == 0 {
			n += a[i]
		} else {
			n -= a[i]
		}
	}

	x := n / 2
	fmt.Print(2*x, " ")
	for i := 0; i < N-1; i++ {
		x = a[i] - x
		fmt.Print(2*x, " ")
	}
	out()
}


Measured memory_bytes: 6528
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

class SumSegTree {
private:

 ll _sum(ll a, ll b, ll k, ll l, ll r) {
  if (r <= a || b <= l)return 0;    // 交差しない
  if (a <= l && r <= b)return dat[k];   // a,l,r,bの順で完全に含まれる
  else {
   ll s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
   ll s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
   return s1 + s2;
  }
 }
public:
 ll n, height;
 vector<ll> dat;

 // 初期化（_nは最大要素数）
 SumSegTree(ll _n) {
  n = 1;
  height = 1;
  while (n < _n) {
   n *= 2;
   height++;
  }
  dat = vector<ll>(2 * n - 1, 0);
 }

 // 場所i(0-indexed)にxを足す
 void add(ll i, ll x) {
  i += n - 1; // i番目の葉ノードへ
  dat[i] += x;
  while (i > 0) { // 下から上がっていく
   i = (i - 1) / 2;
   dat[i] += x;
  }
 }

 // 区間[a,b)の総和。ノードk=[l,r)に着目している。
 ll sum(ll a, ll b) {
  return _sum(a, b, 0, 0, n);
 }
};

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

	ll n,m;
	cin>>n>>m;
	Array a(n,0);
	REP(i,n) cin>>a[i];
	sort(all(a),greater<ll>());

	SumSegTree sum_i(101010);
	REP(i,n) sum_i.add(a[i],1);
	
	ll l=0;
	ll r=2e5+1;
	while(l+1<r){
		ll mid=(l+r)/2;

		ll num=0;
		REP(i,n){
			//i+j>=midとなる組み合わせの数
			num+=sum_i.sum(max(mid-a[i],0LL),100001);
		}
		//cerr<<mid<<" "<<num<<endl;

		if(num>=m){
			l=mid;
		}else{
			r=mid;
		}
	}
	//cerr<<l<<endl;

	SumSegTree sum_a(101010);
	REP(i,n) sum_a.add(a[i],a[i]);

	ll con=0;
	ll ans=0;
	REP(i,n){
		ll c = sum_i.sum(max(l-a[i],0LL),100001);//和がx以上になるaの数
		ans += sum_a.sum(max(l-a[i],0LL),100001);//和がx以上になるaの総和
		ans += c*a[i];
		con += c;
	}

	if(con>m) ans-=(con-m)*l;

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define MAX 200007

using namespace std;

int pw[MAX][3];
int sum[3];
int n;
string x;

void calc(int cnt, int idx){
    if(cnt <= 0)
        return;
    pw[0][idx] = 1;
    for( int i = 1; i < MAX; i++ ){
        pw[i][idx] = 2 * pw[i - 1][idx];
        pw[i][idx] %= cnt;
    }
    for( int i = 0; i < x.length(); i++ ){
        if(x[i] == '1'){
            sum[idx] += pw[n - i - 1][idx];
            sum[idx] %= cnt;
        }
    }
}

int f( int num ){
    //std::popc
    if(num == 0)
        return 0;
    int p = __builtin_popcount (num);
    return 1 + f(num % p);
}

int main()
{
    
    int cnt = 0;
    
    cin >> n >> x;
    for( int i = 0; i < n; i++ ){
        if(x[i] == '1')
            cnt++;
    }
    calc(cnt - 1, 0);
    calc(cnt, 1);
    calc(cnt + 1, 2);
    for( int i = 0; i < n; i++ ){
        if(x[i] == '0'){
            int rem = sum[2];
            rem += pw[(n - i - 1)][2];
            rem %= (cnt + 1);
            //cout << rem << endl;
            cout << (1 + f(rem)) << endl;
        }
        else{
            if(cnt == 1)
                cout << 0 << endl;
            else{
                int rem = sum[0];
                rem -= pw[(n - i - 1)][0];
                rem %= (cnt - 1);
                if(rem < 0)
                    rem += (cnt - 1);
                cout << (1 + f(rem)) << endl;
            }
        }
    }
    return 0;
}

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

int main(){

int x,y,z;
int flg = 0;

cin >> x >> y >> z;


if(x + y == z)      flg = 1;
else if(x + z == y) flg = 1;
else if(y + z == x) flg = 1;

if(flg == 1) cout << "Yes" << endl;
else         cout << "No" << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  string s;
  cin >> s;
  if (s.back() == 's') {
    s += "es";
  } else {
    s += "s";
  }
  cout << s << endl;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string A;
    cin >> A;
    int N = A.size();

    vector<int> dist(26 * (N + 1), INF), pre(26 * (N + 1), -1);
    rep(c, 26) dist[c] = 1;
    queue<pair<int, int>> q;
    rep(c, 26) {
        int i = 0;
        for (; i < N; ++i) {
            dist[26 * i + c] = 1;
            if (A[i] - 'a' == c) break;
        }
        dist[26 * i + c] = 1;
        q.emplace(26 * i + c, -1);
    }
    int last = -1;
    while (!q.empty()) {
        auto v = q.front();
        q.pop();
        int n = v.first / 26;
        if (n == N) {
            last = v.first;
            break;
        }

        rep(c, 26) {
            if (dist[v.first] + 1 >= dist[26 * (n + 1) + c]) continue;
            rep(i, n + 1, N + 1) {
                dist[26 * i + c] = dist[v.first] + 1;
                pre[26 * i + c] = v.first;
                if (i == N || dist[v.first] + 1 >= dist[26 * (i + 1) + c] || A[i] - 'a' == c) {
                    q.emplace(26 * i + c, v.first);
                    break;
                }
            }
        }
    }

    string ans;
    ans.push_back(last % 26 + 'a');
    while (pre[last] != -1) {
        last = pre[last];
        ans.push_back(last % 26 + 'a');
    }
    reverse(all(ans));
    write(ans);

    // cout << (char)(last % 26 + 'a') << endl;
    // cout << " " << A << endl;
    // rep(c, 26) {
    //     cout << (char)(c + 'a');
    //     rep(i, N + 1) dist[26 * i + c] == INF ? cout << "-" : cout << dist[26 * i + c];
    //     cout << endl;
    //     cout << " ";
    //     rep(i, N + 1) pre[26 * i + c] == -1 ? cout << "-" : cout << (char)(pre[26 * i + c] % 26 + 'a');
    //     cout << endl;
    // }
}

Measured memory_bytes: 41364
unittest
{
	assert( [ "3", "2 3 4" ].parse.expand.solve == 13 );
	assert( [ "5", "12 12 12 12 12" ].parse.expand.solve == 5 );
	assert( [ "3", "1000000 999999 999998" ].parse.expand.solve == 996989508 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// asの最小公倍数を計算（gcd()使うとオーバーフローするので素因数分解でやる）
	auto m = 1L;
	{
		long[ long ] mps;
		auto ps = as.reduce!max.primes;
		foreach( a; as )
		{
			foreach( g; primefactorize( a, ps ).group )
			{
				if( g[ 0 ] !in mps ) mps[ g[ 0 ] ] = g[ 1 ];
				else                 mps[ g[ 0 ] ] = max( mps[ g[ 0 ] ], g[ 1 ] );
			}
		}
		foreach( p, n; mps )
		{
			m = m.mulMod( p.powMod( n ) );
		}
	}
	
	// bsの合計を計算
	auto ans = 0L;
	foreach( a; as )
	{
		ans = ans.addMod( m.divMod( a ) );
	}
	return ans;
}

// 素数列
auto primes( long x )
{
	Appender!( long[] ) ps;
	if( x < 2 ) return ps.data;
	
	auto cs = new bool[]( x + 1 );
	ps ~= 2L;
	for( auto i = 3L; i * i < cs.length; i += 2 )
	{
		if( cs[ i ] ) continue;
		for( auto j = i; i * j < cs.length; j++ )
		{
			cs[ i * j ] = true;
		}
	}
	for( auto i = 3L; i < cs.length; i += 2 )
	{
		if( !cs[ i ] ) ps ~= i;
	}
	return ps.data;
}

// 素因数分解
auto primefactorize( long x, long[] ps )
{
	Appender!( long[] ) fs;
	if( x < 2 ) return fs.data;
	
	auto s = ( cast( long ) x ^^ 0.5L ) + 1;
	foreach( p; ps )
	{
		if( s < p ) break;
		while( x % p == 0 )
		{
			x /= p;
			fs ~= p;
		}
		if( x < 2 ) break;
	}
	if( 2 <= x ) fs ~= x;
	return fs.data;
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// 割り算
auto divMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y.powMod!MOD( MOD - 2 ) % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}


Measured memory_bytes: 5116
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
 
 
int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll ans = b + min(a+b+1,c);
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int i,N,M,sum,all,A,B,C,D;
  long ans;
  bool can;
  can=false;
  //  string S,A;
  
  cin>>A>>B>>C>>D;

  ans=0;
  sum=N;
  
  for(;;){
    C-=B;
     if(C<1){
       cout<<"Yes"<<endl;
       break;
     }
   A-=D;
     if(A<1){
       cout<<"No"<<endl;
       break;
  }
  }
  return 0;
}


Measured memory_bytes: 3004
n,m=map(int,input().split())
p=list(map(int,input().split()))
class UnionFind(object):
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for i in range(N)]
    
    def merge(self, a, b):
        if self.issame(a,b):
            return
        pa = self.root(a)
        pb = self.root(b)
        self.parent[pa] = pb
        self.size[pb] += self.size[pa]
    def root(self, x):
        p = self.parent[x]
        if p == x:
            return x
        else:
            r = self.root(p)
            self.parent[x] = r
            return r
    
    def issame(self, x, y):
        return self.root(x) == self.root(y)
    
    def getsize(self, x):
        return self.size[self.root(x)]

uf=UnionFind(2*n)
for i in range(n):
    uf.merge(i,p[i]+n-1)
for i in range(m):
    x,y=map(int,input().split())
    x-=1;y-=1
    uf.merge(x,y)
ans=0
for i in range(n):
    ans+=int(uf.issame(i,i+n))
print(ans)

Measured memory_bytes: 16996
#include <stdio.h>
int main(){
	char ch;
	while((ch = getchar()) != EOF){
			if(ch >= 97 && ch <= 122) printf("%c",ch-32);
			else if(ch >= 65 && ch <= 90) printf("%c",ch+32);
			else printf("%c",ch);
	}
	return 0;
}



Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
const int mxn = 550;
int f[mxn] , c[mxn] , s[mxn];
int main()
{
    int n;
    cin>>n;
    for(int i = 1; i < n; i++)
    cin>>c[i]>>s[i]>>f[i];
    for(int i = 1; i < n; i++)
    {
        long long sum = 0;
        for(int j = i; j < n; j++)
        {
            if(s[j] >= sum)
            {
                sum = s[j];
            }
            else
            {
                long long tmp = sum%f[j];
                if(tmp)
                sum += f[j]-tmp;
            }
            //cout<<c[j]<<" "<<j<<endl;
            sum += c[j];
          //  cout<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    cout<<0<<endl;
    return 0;
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
//		freopen("input.txt","r",stdin);
	#endif
	int r,c,n;
	cin>>r>>c>>n;
	vector<vector<int>> color(r,vector<int> (c));
	vector<int> sz(n);
	for(int i=0;i<n;i++)cin>>sz[i];
	int at=0;
	int x=0,y=0;
	while(1){
		if(at < n && !sz[at])at++;
		// cerr << x << ' ' << y << ' ' << at << '\n';
		if(at == n)break;
		color[x][y] = at+1;
		sz[at]--;
		y += ((x%2) == 0?1:-1);
		if(y == c || y < 0){
			x++;
			y += ((x%2) == 0?1:-1);
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++)
			cout << color[i][j] << ' ';
		cout << '\n';
	}
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,k;
long long ans,a[100001],b[100001];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		if (a[i]>0)b[++m]=a[i];
	for(int i=1;i<=n;i++)
		if (a[i]>0){
			n=i-1;
			break;
		}
	for(int i=1;i<=n/2;i++)swap(a[i],a[n-i+1]);
	ans=5000000000000000000LL;
	for(int i=max(0,k-m);i<=min(n,k);i++)
		if (i>=k)ans=min(ans,-a[i]);
		else ans=min(ans,min(-2*a[i]+b[k-i],b[k-i]*2-a[i]));
	printf("%lld",ans);
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
const long long mx=1ll<<60;
long long a,b,sum,lst,t;
vector<pair<long long,long long> > ans;
int mxb(long long a){t=60;while((a&(1ll<<t))==0)t--;return t;}
int main()
{
	cin>>a>>b;if(a==b){puts("1");return 0;}int t=mxb(a^b);
	int i;for(i=60;i>t;i--) if((a>>i)&1) {a^=(1ll<<i);b^=(1ll<<i);}
	ans.push_back(make_pair(a,(1ll<<t)-1));
	if(b!=(1ll<<t)) ans.push_back(make_pair((1ll<<t),(1ll<<t)+(1ll<<(mxb(b^(1ll<<t))+1))-1)); else ans.push_back(make_pair((1ll<<t),(1ll<<t)));
	ans.push_back(make_pair((1ll<<t)+a,(1ll<<(t+1))-1));
	sort(ans.begin(),ans.end());lst=-1;sum=0;
//	for(i=0;i<ans.size();i++) cerr<<ans[i].first<<' '<<ans[i].second<<endl;
	for(i=0;i<ans.size();i++) if(lst<ans[i].first){sum+=ans[i].second-ans[i].first+1;lst=ans[i].second;} else if(lst<ans[i].second){sum+=ans[i].second-lst;lst=ans[i].second;}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int _ = 3e3 + 5, p = 1e9 + 7;

int n, m, a[_], dp[_][_];

inline int power(int x, int k) {
    int res = 1;
    for (; k; k >>= 1, x = 1ll * x * x % p)
        if (k & 1) res = 1ll * res * x % p;
    return res % p;
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) dp[i][j] = a[i] < a[j];
    int inv2 = power(2, p - 2);
    for (int x, y, i = 1; i <= m; ++i) {
        scanf("%d %d", &x, &y);
        dp[x][y] = dp[y][x] = 1ll * inv2 * ((dp[x][y] + dp[y][x]) % p) % p;
        for (int j = 1; j <= n; ++j) {
            if (j == x | j == y) continue ;
            dp[x][j] = dp[y][j] = 1ll * inv2 * ((dp[x][j] + dp[y][j]) % p) % p;
            dp[j][x] = dp[j][y] = 1ll * inv2 * ((dp[j][x] + dp[j][y]) % p) % p;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j < i; ++j) ans = (ans + dp[i][j]) % p;
    ans = 1ll * ans * power(2, m) % p;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, a, b;
  a = 0;
  cin >> N;
  vector<string> vecn(N);
  for (int i = 0; i < N; i++) {
    cin >> vecn.at(i);
  }
  cin >> M;
  vector<string> vecm(M);
  for (int i = 0; i < M; i++) {
    cin >> vecm.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    b = 1;
    for (int j = i + 1; j < N; j++) {
      if (vecn.at(i) == vecn.at(j)) {
        b++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (vecn.at(i) == vecm.at(j)) {
        b--;
      }
    }
    if (a < b) {
      a = b;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define double long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef pair<pii,pii> ppp;
typedef vector< pii > vp;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

void swap(char &a,char &b)
{ auto tm=a; a=b; b=tm; }

void mina(int &a,int b)
{ a=(a<b?a:b); }

void maxa(int &a,int b)
{ a=(a>b?a:b); }

  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=1e18;
  const int N=2e5+25;
  const int M=31;

 
 void doit()
 { 
   int n,m,s=0; cin>>n>>m;
   rep(i,0,m){
     int x; cin>>x; s+=x;
   }

   cout<<max(-1LL,n-s);
   
 }

signed main()
{ 
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

   int tc=1;                         
 //  cin>>tc;

  rep(i,1,tc+1)
  { // cout<<"Case #"<<i<<": ";
    
   doit();
   if(i<tc)
   cout<<nl;
  }
  

 return 0; 
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int L = a + b;
  int R = c + d;
  if (L == R) {
    cout << "Balanced" << endl;
  }
  else if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int W, a, b; scanf("%d %d %d", &W, &a, &b);
  if (a > b) { swap(a, b); }
  int ans = (a + W < b) ? (b - (a + W)) : 0;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAXN=1e3+10;
const int MOD=1e9+7;

char ploca[MAXN][MAXN];
long long int dp[MAXN][MAXN]={0};

int main()
{
    int n, m;

    cin >>n>>m;

    for (int i=0; i<n; ++i)
    {
        for (int j=0; j<m; ++j)
        {
            cin >>ploca[i][j];
        }
    }

    for (int i=0; i<n; ++i)
    {
        for (int j=0; j<m; ++j)
        {
            if (ploca[i][j]=='.')
            {
                if (i==0 and j==0)
                    dp[i][j]=1;
                else if (i==0)
                    dp[i][j]=dp[i][j-1]%MOD;
                else if (j==0)
                    dp[i][j]=dp[i-1][j]%MOD;
                else
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }
        }
    }

    cout <<dp[n-1][m-1];

    return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<cstdio>
#define MAX 500002
using namespace std;

int left(int i){ return 2 * i; }
int right(int i){ return 2 * i + 1; }

int A[MAX], H;

void maxHeapify(int i){
    int largest,tmp;
    int l = left(i);
    int r = right(i);
    
    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    
    if (r <= H && A[r] > A[largest]) largest = r;
    
    if (largest != i){
        tmp = A[i]; A[i] = A[largest]; A[largest] = tmp;
        maxHeapify(largest);
    }
}

int main(){
    scanf("%d",&H);
    for(int i = 1; i <= H; i++) scanf("%d",&A[i]);
    for(int i = H / 2; i > 0; i--){
        maxHeapify(i);
    }
    for(int i = 1; i <= H; i++) printf(" %d",A[i]);
    cout << endl;
    return 0;
}


Measured memory_bytes: 5160
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int n, k;
vector<vector<int>> bi;
vector<int> val, target(32, 0);

ll f(vector<int> v){
    ll ret = 0;
    for(int i = 0; i < n; i++){
        bool valid = true;
        for(int j = 0; j < 32; j++){
            valid &= (v[j] >= bi[i][j]);
        }
        if(valid)   ret += val[i];
    }
    return ret;
}

int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        if(a > k)   continue;
        vector<int> tmp(32, 0);
        for(int j = 0; j < 32; j++) tmp[j] = a % 2, a /= 2;
        bi.push_back(tmp);
        val.push_back(b);
    }
    n = val.size();
    for(int i = 0; i < 32; i++) target[i] = k%2, k /= 2;
    int msb = 0;
    for(int i = 0; i < 32; i++){
        if(target[i] == 1)  msb = i;
    }
    ll ans = f(target);
    for(int i = msb-1; i >= 0; i--){
        if(target[i] == 0)  continue;
        vector<int> cp = target;
        cp[i] = 0;
        for(int j = i-1; j >= 0; j--)   cp[j] = 1;
        ans = max(ans, f(cp));
    }
    target[msb] = 0;
    for(int i = msb-1; i >= 0; i--) target[i] = 1;
    ans = max(ans, f(target));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17712
#include <bits/stdc++.h>
using namespace std;
long long dp[200000][5];
int main()
{
    int L; cin >> L;
    vector<int> A(L); for (int& a : A) cin >> a;
    if (A[0] == 0) {
        dp[0][0] = 0;
        dp[0][1] = 2;
        dp[0][2] = 1;
        dp[0][3] = 2;
        dp[0][4] = 0;
    } else if (A[0] % 2 == 1) {
        dp[0][0] = A[0];
        dp[0][1] = 1;
        dp[0][2] = 0;
        dp[0][3] = 1;
        dp[0][4] = A[0];
    } else {
        dp[0][0] = A[0];
        dp[0][1] = 0;
        dp[0][2] = 1;
        dp[0][3] = 0;
        dp[0][4] = A[0];
    }
    for (int i = 1; i < L; i++) {
        dp[i][0] = dp[i-1][0];
        dp[i][1] = min(dp[i][0], dp[i-1][1]);
        dp[i][2] = min(dp[i][1], dp[i-1][2]);
        dp[i][3] = min(dp[i][2], dp[i-1][3]);
        dp[i][4] = min(dp[i][3], dp[i-1][4]);
        if (A[i] == 0) {
            dp[i][1] += 2;
            dp[i][2] += 1;
            dp[i][3] += 2;
        } else if (A[i] % 2 == 1) {
            dp[i][0] += A[i];
            dp[i][1] += 1;
            dp[i][3] += 1;
            dp[i][4] += A[i];
        } else {
            dp[i][0] += A[i];
            dp[i][2] += 1;
            dp[i][4] += A[i];
        }
    }
    cout << min({ dp[L-1][0], dp[L-1][1], dp[L-1][2], dp[L-1][3], dp[L-1][4] }) << endl;
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    
    int ans = 1;
    
    for (int i = 1; i <= n; i++) {
        ans = min(ans * 2, ans + k);
    }
    
    cout << ans << endl;
    
    return 0;
}

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

std::vector<std::pair<long long, int>> factorize(long long val)
{

    std::vector<std::pair<long long, int>> ret;

    for (long long i = 2; i * i <= val; i++) {
        if (val % i == 0) {
            ret.emplace_back(i, 0);
            while (val % i == 0) {
                val /= i;
                ret.back().second++;
                // cout << val << endl;
            }
        }
    }
    if (val != 1 && val != 0)
        ret.emplace_back(val, 1);
    return ret;
}

void solve(long long N){
    vector<pair<ll, int>> factors = factorize(N);
    ll ans = 0;
    for(auto factor : factors) {
        ll sum = 1;
        ll val = 0;
        // cout << "p" << factor.first << ", "<<"e=" << factor.second << endl;
        while(1) {
            val += sum;
            // cout << "val=" << val << endl;
            if (factor.second >= val) {
                sum++;
                ans++;
            }
            else
            break;
        }
    }
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,y;
	cin>>n>>y;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n-i;j++)
			if(i*10000+j*5000+(n-i-j)*1000==y)
				cout<<i<<' '<<j<<' '<<n-i-j<<'\n',exit(0);
	cout<<"-1 -1 -1\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define here(x) cout << " #x = " << x << endl;
#define show(x) {for( auto ii : x) cout << ii << en; cout << endl;}
#define shop(n,x) {for(int i = 0; i < n; i++) cout << x << en; cout << endl;}
#define ff first
#define ss second
#define sq(x) (x*x)
#define endl '\n'
#define en " "
#define pb push_back
#define mpair make_pair
ll mod=1000000007;
double pi=3.1415926536;
ll n;
// ll dp[200003];
int main()
{
	fastio();
	int tt = 1;
	//cin >> tt;
	while(tt--)
	{
		// go fast 		check		//		CHECK -> if()   else if()
		
		ll x=0, m=0, y=0, d=1, k=mod;
		cin >> n >> k;
		ll a[n], dp[n];
		for(int i = 0; i < n; i++)
			cin >> a[i];

		dp[n - 1] = 0;
		dp[n - 2] = abs(a[n - 1] - a[n - 2]);

		for(int i = n-3; i >= 0; i--)
		{
			dp[i] = mod;
			for(int j = 1; j <= k && i + j < n; j++)
				dp[i] = min(dp[i], abs(a[i + j] - a[i]) + dp[i + j]);
		}
				
		cout << dp[0] << endl;
	}
}


Measured memory_bytes: 1792
n = int(input())
a = [0]+[int(input()) for _ in range(n)]
check = [0] * (n+1)
now = 1
cnt = 0
while now != 2:
    if check[now] == 1: break
    cnt += 1
    check[now] = 1
    now = a[now]
print(cnt if now == 2 else -1)

Measured memory_bytes: 13780
<?php
  	fscanf(STDIN, '%d', $num);
	$input = rtrim(fgets(STDIN));
	$nums = explode(' ', $input);

	$cnt = 0;
	while(1){
      foreach($nums as $key => $val){
          if($val % 2 == 1){
              break 2;
          }
        $nums[$key] /= 2;
      }
      ++$cnt;
    }

	echo $cnt;

Measured memory_bytes: 4604
import math
a,b,h,m=map(int,input().split())

p=math.pi
ax=a*math.cos(2*p*(60*h+m)/720)
ay=a*math.sin(2*p*(60*h+m)/720)
bx=b*math.cos(2*p*m/60)
by=b*math.sin(2*p*m/60)

d=math.sqrt((ax-bx)**2+(ay-by)**2)
print(d)

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

int nd(int n){
    int s=0;
    while(n!=0){
        s+= n%10;
        n/=10;
    }
    return s;
}

int main(){
    int n; cin>>n;
    cout<<(n%nd(n)? "No" : "Yes");
    return 0;
}


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

int n,ans=1;
int t[MAX];
int L[MAX],R[MAX];

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",&t[i]);
  L[0]=R[n-1]=1;
  for(int i=1;i<n;i++)L[i]=(t[i]==t[i-1]?1:L[i-1]+1);
  for(int i=n-2;i>=0;i--)R[i]=(t[i]==t[i+1]?1:R[i+1]+1);
  for(int i=1;i<n;i++)ans=max(ans,L[i-1]+R[i]+R[i+R[i]]);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 2360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
   ll n;cin>>n;
   ld a[n];f(i,0,n)cin>>a[i];
    sort(a,a+n);ld sum=a[0];
    f(i,1,n){
        sum=(sum+a[i])/2;
    }
    cout<<sum;
    return 0;
}   


Measured memory_bytes: 256
#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_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

const ll R=3;

ll Hash(vector<vector<ll>> &A){
    ll ret=0;
    for(int i=0;i<R;i++){
        for(int t=0;t<R;t++){
            ret+=A[i][t];
            if(i+1!=R || t+1!=R){
                ret*=10;
            }
        }
    }
    return ret;
}

map<ll,ll> M;

vector<ll> dx={0,1,0,-1};
vector<ll> dy={1,0,-1,0};

struct PZL{
    ll hash;
    vector<vector<ll>> A;
    ll h,w;
    ll d;
};


void bfs(vector<vector<ll>> A){
    queue<PZL> Q;
    Q.push({Hash(A),A,2,2,0});
    M[Hash(A)]=0;
    while(!Q.empty()){
        PZL W=Q.front(); Q.pop();
        for(int i=0;i<4;i++){
            ll x=W.h+dx[i];
            ll y=W.w+dy[i];
            if(x<0 || y<0 || x>=R || y>=R){continue;}
            PZL N=W;
            swap(N.A[x][y],N.A[W.h][W.w]);
            N.hash=Hash(N.A);
            if(M.count(N.hash)){continue;}
            N.h=x;
            N.w=y;
            M[N.hash]=++N.d;
            Q.push(N);
        }
    }
}



int main(){
    bfs({{1,2,3},{4,5,6},{7,8,0}});
    vector<vector<ll>> A(3,vector<ll>(3));
    for(int i=0;i<R;i++){
        for(int t=0;t<R;t++){
            cin>>A[i][t];
        }
    }
    ll h=Hash(A);
    cout<<M[h]<<endl;
    
    
    return 0;
}



Measured memory_bytes: 17968
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<u32>();
    let (s, w) = (line[0], line[1]);

    if w >= s{
        println!("unsafe");
    }else{
        println!("safe");
    }
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, M, V, P;
  cin >> N >> M >> V >> P;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.rbegin(),vec.rend());
  int border = vec.at(P-1); //border以上であれば可能
  int ok = P-1;
  int ng = N;
  while(ng - ok > 1){
    bool flag = true;
    int mid = (ok + ng) / 2;
    int score = vec.at(mid) + M;
    if(score < border){
      flag = false;
    }
    int64_t vote = V*M;
    for(int i=0; i<N; i++){
      if(i < P-1 || i >= mid){
        vote -= M;
      }
      else{
        vote -= max((int64_t)0,score - vec.at(i));
      }
    }
    if(vote > 0){
      flag = false;
    }
    if(flag){
      ok = mid;
    }
    else{
      ng = mid;
    }
  }
  cout << ok + 1 << endl;  
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,Pll> a,pair<ll,Pll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se.fi>b.se.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    long double a;long double b;cin>>a>>b;
    long double x =a*b*100.0;
    ll xx=x/100;
    cout<<xx<<endl;
    //-------------------------------  
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------



















































Measured memory_bytes: 3732
#include <vector>
#include <stdio.h>
using namespace std;

const int maxn = 102;
int m, n, nColor, res[maxn][maxn];
vector<int> p;

int main() {
    //freopen("4adj.inp", "r", stdin);
    scanf("%d%d%d", &m, &n, &nColor);
    for (int i=1; i<=nColor; ++i) {
        int x; scanf("%d", &x);
        while (x--) p.push_back(i);
    }
    int posRow = 0;
    while (p.size()) {
        ++posRow;
        int posCol = posRow%2==0 ? n+1 : 0, t = posRow%2==0 ? -1 : 1;
        for (int i=1; i<=n; ++i) {
            res[posRow][posCol+=t] = p.back();
            p.pop_back();
        }
    }
    for (int i=1; i<=m; ++i) {
        for (int j=1; j<=n; ++j) {
            printf("%d ", res[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string w;
    cin>>w;
    if(w=="Cloudy")
        cout<<"Rainy"<<endl;
    if(w=="Sunny")
        cout<<"Cloudy"<<endl;
    if(w=="Rainy")
        cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<cstdio>
    #include<vector>
    #include<cmath>
    #include<cstring>
    #include<fstream>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int INF=0x3f3f3f3f;
    const int MAXN=1e5+5;
    int tot,head[MAXN];
    LL dist[MAXN];
    bool vis[MAXN];

    struct Edge
    {
        int from,to,nxt;
        LL cost;
    }e[MAXN*2];

    void addedge(int u,int v,int w)
    {
        e[tot].from=u;
        e[tot].to=v;
        e[tot].cost=w;
        e[tot].nxt=head[u];
        head[u]=tot++;
    }

    void dfs(int u,int fa)
    {
        for(int i=head[u];i!=-1;i=e[i].nxt)
        {
            int to=e[i].to;
            if(to==fa) continue;
            dist[to]=dist[u]+e[i].cost;
            dfs(to,u);
        }
    }

    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            tot=0;
            memset(head,-1,sizeof(head));
            memset(dist,0,sizeof(dist));
            int u,v;
            LL w;
            for(int i=1;i<=n-1;i++)
            {
                scanf("%d%d%lld",&u,&v,&w);
                addedge(u,v,w);
                addedge(v,u,w);
            }
            int q,k;
            scanf("%d%d",&q,&k);
            dfs(k,-1);
    //        for(int i=1;i<=n;i++)
    //            cout<<dist[i]<<" ";
    //        cout<<endl;
            int x,y;
            for(int i=1;i<=q;i++)
            {
                scanf("%d%d",&x,&y);
                printf("%lld\n",dist[x]+dist[y]);
            }
        }
        return 0;
    }

Measured memory_bytes: 12288
import java.util.Scanner;

public class Main
{
    public static void main(String... args)
    {
        final Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            System.out.println(Integer.toString(a + b).length());
        }
    }
}

Measured memory_bytes: 20576