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

using namespace std;

int s[100005];
int main()
{
    int n,k,i,sum=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
    }
    n=n-k;
    sum=1;
    if(n>0)
    {
        sum=sum+n/(k-1);
        n=n-(sum-1)*(k-1);
    }
    if(n>0)
        sum=sum+1;
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] a = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                a[i, 0] = int.Parse(s[0]);
                a[i, 1] = int.Parse(s[1]);
                a[i, 2] = int.Parse(s[2]);
            }

            if (a[0, 0] - a[0, 1] != a[1, 0] - a[1, 1] ||
                a[1, 0] - a[1, 1] != a[2, 0] - a[2, 1] ||
                a[0, 1] - a[0, 2] != a[1, 1] - a[1, 2] ||
                a[1, 1] - a[1, 2] != a[2, 1] - a[2, 2])
            {
                Console.WriteLine("No");
                return;
            }

            if (a[0, 0] - a[1, 0] != a[0, 1] - a[1, 1] ||
                a[0, 1] - a[1, 1] != a[0, 2] - a[1, 2] ||
                a[1, 0] - a[2, 0] != a[1, 1] - a[2, 1] ||
                a[1, 1] - a[2, 1] != a[1, 2] - a[2, 2])
            {
                Console.WriteLine("No");
                return;
            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;
map<__uint128_t,int>memo;

int M,N;
vector<string>v;
int dfs(__uint128_t t){
	if(memo.find(t)!=memo.end())return memo[t];
	int c=0;
	for(int i=0;i<N;i++){
		if(t&(__uint128_t)(1)<<i)c++;
	}
	if(c==1)return 0;

	int r=1<<30;
	for(int j=0;j<M;j++){
		__uint128_t a=0,b=0;
		for(int i=0;i<N;i++){
			__uint128_t e=(__uint128_t)(1)<<i;
			if(t&e)(v[i][j]=='0'?a:b)|=e;
		}
		if(a&&b)r=min(r,max(dfs(a),dfs(b))+1);
	}
	return memo[t]=r;
}

int main(){
	for(;cin>>M>>N,M;){
		v.resize(N);
		for(int i=0;i<N;i++)cin>>v[i];
		__uint128_t t=0;
		for(int i=0;i<N;i++)t|=(__uint128_t)(1)<<i;
		memo.clear();
		printf("%d\n",dfs(t));
	}
}

Measured memory_bytes: 2696
import collections

N, K = map(int, input().split())
A = list(map(int, input().split()))

count = collections.Counter(A)
if len(count) <= K:
    print(0)
else:
    num_cnt = 0
    for _, c in count.most_common()[K:]:
        num_cnt += c

    print(num_cnt)

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

int a[1500001] = {0}, b[1500001] = {0};

int main() {
  int n, m;
  int h[1501] = {0}, w[1501] = {0};
  int rh[1501] = {0}, rw[1501] = {0};

  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 1; i <= n; i++) {
      cin >> h[i];
      rh[i] = h[i] + rh[i-1];
    }
    for (int i = 1; i <= m; i++) {
      cin >> w[i];
      rw[i] = w[i] + rw[i-1];
    }

    long long ans = 0;
    for (int i = 0; i < 1500001; i++) {
      a[i] = 0;
      b[i] = 0;
    }
    for (int i = 0; i <= n - 1; i++) {
      for (int j = i + 1; j <= n; j++) {
        long long x = rh[j] - rh[i];
        a[x]++;
      }
    }
    for (int i = 0; i <= m - 1; i++) {
      for (int j = i + 1; j <= m; j++) {
        long long x = rw[j] - rw[i];
        b[x]++;
      }
    }
    for (int i = 0; i < 1500001; i++) {
      ans += a[i]*b[i];
    }

    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 14816
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  rep(i,n){
    cin >> a[i];
    sum ^= a[i];
  }

  rep(i,n){
    cout << (sum^a[i]) << " ";
  }
  cout << ln;


  return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    cout<<(n*(n-1)+m*(m-1))/2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	ll a, b, n;
	cin >> a >> b >> n;
	cout << (a * min(b - 1, n)) / b - a * (min(b - 1, n) / b);
}


Measured memory_bytes: 3596
N , M = map(int,input().split())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    tmp =l.pop(0)
    L.append(l)
cnt = 0
for i in range(1,1+M):
    for x in L:
        if i in x:
            pass
        else:
            break
    else:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
;; A - Remaining Balls

(let ((s1 (read))
      (s2 (read))
      (a  (read))
      (b  (read))
      (u  (read)))
  (format t "~a ~a~%"
      (if (eq s1 u) (1- a) a)
      (if (eq s2 u) (1- b) b)))


Measured memory_bytes: 11232
#include<bits/stdc++.h>
using namespace std;
int solve(int a[][3],int dp[][3],int n,int j,int i){
	if(i==n){
		return 0;
	}
	int ans=INT_MIN;
	for(int k=0;k<3;k++){
		if(k!=j){
			int h;
		    if(dp[i][k]==0){
		    	dp[i][k]=solve(a,dp,n,k,i+1);
		    }
		   ans=max(ans,a[i][k]+dp[i][k]);	
		}
	}
	return ans;
}
int main(){
	int n,k;
	cin>>n;
	int a[n][3];
	int dp[n][3];
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		dp[i][0]=0;
		dp[i][1]=0;
		dp[i][2]=0;
	}
    cout<<solve(a,dp,n,4,0)<<"\n";
}

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

struct UnionFind{
  int N;
  vector<int> rank,par,sz;
  UnionFind(int n){
    N=n;
    rank.resize(N+1,1);
    par.resize(N+1);
    sz.resize(N+1,1);
    r(i,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    if(rank[rx]>rank[ry]){
      sz[rx]+=sz[ry];
      par[ry]=rx;
    }
    else {
      sz[ry]+=sz[rx];
      par[rx]=ry;
      if(rank[rx]==rank[ry])rank[ry]++;
    }
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  
  int get_size(int x){
    return sz[root(x)];
  }
  
};

int main(){
  int n,m,k;
  cin >> n >> m >> k; 
  UnionFind uf(n);
  int count[n];
  r(i,n)count[i]=100000;
  while(m--){
    int a,b;
    cin >> a >> b;
    uf.unite(a-1,b-1);
    count[a-1]--;	count[b-1]--;
  }
  r(i,n){
    count[i]+=uf.get_size(i)-1;
  }
  while(k--){
   int c,d;
    cin >> c >> d;
    if(uf.same(c-1,d-1)){
      count[c-1]--;	count[d-1]--;
    }
  }
  r(i,n)cout<<count[i]-100000<<" ";
  cout<<endl;
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(){
	
	int A[100][100], B[100], n, m, i, j, show = 0;
	
	scanf("%d",&n);
	scanf("%d",&m);
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			
			scanf("%d",&A[i][j]);
		}
	}
	
	for(j = 0; j < m; j++){
		
		scanf("%d",&B[j]);
	}
	
	
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			
			show += A[i][j] * B[j];
		}
		printf("%d\n",show);
		show = 0;
	}
	
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll n, k, a[100100], bst = LLONG_MAX, A[100100], B[100100], vfa, vfb;

int main(){
//	ifstream cin("tst.in");
//	ofstream out("tst.out");
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= n; i++)
		if(a[i] < 0)
			A[++vfa] = a[i];
		else B[++vfb] = a[i];
	reverse(A + 1, A + vfa + 1);
//	for(int i = 1; i <= min(k, vfa); i++)
//		if(k - i <= vfb)
//			bst = min(bst, -A[i] + (B[k - i] - A[i]) * (long long)(k > i));
//	for(int i = 1; i <= min(k, vfb); i++)
//		if(k - i <= vfa)
//			bst = min(bst, B[i] + (B[i] - A[k - i] * (long long)(k > i)));
	for(int i = 1; i + k - 1 <= n; i++){
		bst = min(bst, (a[i] < 0 ? -a[i] + a[i + k - 1] - a[i] : a[i + k - 1]));
		bst = min(bst, (a[i + k - 1] >= 0 ? a[i + k - 1] + a[i + k - 1] - a[i] : -a[i]));
	}
	cout << bst;
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct
{
	int h, p, q;
} Line;

class GreaterHeight
{
public:
	bool operator() (const Line& lhs, const Line& rhs)
	{
		return lhs.h > rhs.h;
	}
};

int main()
{
	int n, m, a;
	while (scanf("%d %d %d", &n, &m, &a) != EOF) {
		if (n == 0 && m == 0 && a == 0)
			break;
		vector<Line> line(m);
		for (int i = 0; i < m; ++i)
			scanf("%d %d %d", &line[i].h, &line[i].p, &line[i].q);
		sort(line.begin(), line.end(), GreaterHeight());
		
		for (int i = 0; i < m; ++i) {
			if (line[i].p == a)
				swap(a, line[i].q);
			else if (line[i].q == a)
				swap(a, line[i].p);
		}
		printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
  int math,t,in,out,MAX,bell=0;
  cin >> t >> math;
  MAX=math;
  for(int y=0;y<t;y++){
    cin >> in >> out;
    math+=in;
    math-=out;
    if(MAX<math){
      MAX=math;
    }
    if(math<0){
      bell++;
    }
  }
  if(bell!=0){
    cout << "0" << endl;
  }
  else{
    cout << MAX << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>

const int MAXN = (int)2e6 + 3;
const int P = (int)1e9 + 7;

int64_t factorial[MAXN];


// Init array 'factorial'.
void init(int n) {
  factorial[0] = 1;
  for (int i = 1; i <= n; ++i) {
    factorial[i] = factorial[i - 1] * i % P;
  }
}

// Calc the inv of x (mod P).
int64_t inv(int64_t x) {
  auto power = [](int64_t a, int64_t b) -> int64_t {
    int64_t ans = 1;
    while (b > 0) {
      if (b & 1) ans = ans * a % P;
      a = a * a % P;
      b >>= 1;
    }
    return ans;
  };
  
  x %= P;
  return power(x, P - 2);
}

// Calc Comb(x, y) % P.
int64_t comb(int64_t x, int64_t y) {
  if (y == 0 || y == x) return 1;
  if (x < y) return 0;
  return factorial[x] * inv(factorial[y] * factorial[x - y]) % P;
}

int64_t solve(int r1, int r2, int c1, int c2) {
  int max_n = r2 + c2 + 2;
  init(max_n);
  int64_t ans = comb(r2 + c2 + 2, r2 + 1) - comb(c2 + r1 + 1, r1) - 
                comb(r2 + c1 + 1, r2 + 1) + comb(r1 + c1, r1);
  ans = (ans % P + P) % P;
  return ans;
}

int main() {
  int r1, c1, r2, c2;
  std::cin >> r1 >> c1 >> r2 >> c2;
  std::cout << solve(r1, r2, c1, c2) << std::endl;
  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define rep3(i,n,m) for(long long i=n;i>=m;i--)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
 ll n,l ;
 cin>> n>>l ;
 vector<ll> A(n) ;
 rep(i,n) cin>> A[i] ;
 ll ko=-1 ;
 rep(i,n-1){
 if(A[i]+A[i+1]>=l){
   ko= i ;
   break ;
 }
 }
   if(ko==-1)
   cout <<"Impossible"<<endl ;
   else{
    cout<<"Possible"<<endl ;
     rep2(i,1,ko){
       cout<<i<<endl ;
     }
      rep3(i,n-1,ko+2){
        cout <<i<<endl;
      }
       cout <<ko+1<<endl ;
   }
    
    return 0;
}

Measured memory_bytes: 1664
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $a = explode(" ", trim(fgets(STDIN)));

  if($n==1){
    echo $a[0];
    exit;
  }

  $b1=[];
  $b2=[];
  for($i=0;$i<$n;$i++){
    if($i%2==0){
      $b1[]=$a[$i];
    }else{
      $b2[]=$a[$i];
    }
  }

  if($n%2==0){
    krsort($b2);
    echo implode(" ",$b2);
    echo " ";
    echo implode(" ",$b1);  
  }else{
    krsort($b1);
    echo implode(" ",$b1);
    echo " ";
    echo implode(" ",$b2);  
  }


Measured memory_bytes: 42904
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
int A[10][10];
int N;
const int W = 10;
const int H = 10;
const int L = 13;

pair<int, int> next() {
    REP(y, H) REP(x, W) if(A[y][x] > 0) {
        return make_pair(x, y);
    }
    return make_pair(-1, -1);
}
int len[4] = {0, 5, 9, 13};
int dx[] = {
    0, 1, 0, -1, 0,  1, 1, -1, -1,  2, 0, -2, 0
};
int dy[] = {
    0, 0, 1, 0, -1,  1, -1, -1, 1,  0, 2, 0, -2
};
int r[3] = {1, 1, 2};

int ok(int cx, int cy) {
    REP(i, L) {
        int x = cx + dx[i];
        int y = cy + dy[i];
        if(x < 0 || W <= x) return i;
        if(y < 0 || H <= y) return i;
        if(A[y][x] == 0) return i;
    }
    return L;
}
void add(int cx, int cy, int l, int r, int d) {
    for(int i = l; i < r; i++) {
        int x = cx + dx[i];
        int y = cy + dy[i];
        A[y][x] += d;
    }
}

int hist_x[15];
int hist_y[15];
int hist_z[15];

bool dfs(int iter) {
    if(iter == N) {
        if(next().first != -1) return false;
        REP(i, N) {
            int x = hist_x[i];
            int y = hist_y[i];
            int z = hist_z[i];
            cout << x << " " << y << " " << z << endl;
        }
        return true;
    }

    auto p = next();
    int px = p.first, py = p.second;
    // REP(y, H) {
    //     REP(x, W) cout << A[y][x] << " ";
    //     cout << endl;
    // }
    REP(k, 3) for(int i = len[k]; i < len[k + 1]; i++) {
        int cx = px - dx[i];
        int cy = py - dy[i];
        int r = ok(cx, cy);

        int max_k2 = -1;
        for(int k2 = 0; k2 < 3; k2++) {
            if(len[k2 + 1] <= r) {
                max_k2 = k2;
                add(cx, cy, len[k2], len[k2 + 1], -1);
                hist_x[iter] = cx;
                hist_y[iter] = cy;
                hist_z[iter] = k2 + 1;
                if(dfs(iter + 1)) return true;
            } else {
                break;
            }
        }

        if(max_k2 >= 0) {
            add(cx, cy, len[0], len[max_k2 + 1], +1);
        }
    }

    return false;
}



int main(){
    while(cin >> N) {
        REP(y, H) REP(x, W) cin >> A[y][x];

        bool b = dfs(0);
        assert(b);
    }
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    while (N > 0) {
        N /= K;
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
4
1 1 1 1
)");
#define cin input
#endif

int main()
{
	int n;
	cin >> n;

	array<int, 100000> c[2] = {};
	int mx[2] = {};
	int mn[2] = {};

	REP (i, n)
	{
		int v;
		cin >> v;
		auto x = ++c[i % 2][--v];
		if (x > mx[i % 2])
		{
			mx[i % 2] = x;
			mn[i % 2] = v;
		}
	}

	if (mn[0] != mn[1])
		cout << (n - mx[0] - mx[1]) << endl;
	else
	{
		sort(c[0].begin(), c[0].end());
		sort(c[1].begin(), c[1].end());
		cout << min(n - mx[0] - c[1][99998], n - mx[1] - c[0][99998]) << endl;
	}

	return 0;
}


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

int main()
{
  int n;
  scanf("%d",&n);
  string a[200005];
  for(int i=1; i<=n; i++)
  {
    cin>>a[i];
  }
  sort(a+1,a+1+n);
  int maxn=1,mx=1;
  for(int i=2; i<=n; i++)
  {
    if(a[i]==a[i-1])
    {
      maxn++;
      mx=max(mx,maxn);
    }
    if(a[i]!=a[i-1])
    {
      mx=max(mx,maxn);
      maxn=1;
    }
  }
  int minn=1;
  if (mx==1) cout<<a[1]<<endl;
  for (int i=2; i<=n; i++)
  {
    if (a[i]==a[i-1]) minn++;
    else minn=1;
    if (minn==mx) cout<<a[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 14208
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [i32; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: usize, b: usize, c: usize,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input!{
        n: usize
    }
    println!("{}", if n % 2==0 {n} else {2*n});
}

Measured memory_bytes: 4476
#include <stdio.h>
#include <math.h>

#ifndef Boolean
#define Boolean int
#endif

#ifndef TRUE            /* TRUE が定義されていなかったら */
#define TRUE 1
#endif

#ifndef FALSE           /* FALSE が定義されていなかったら */
#define FALSE 0
#endif

Boolean isprime(int x);

int main() {

    int n,count,i,x;
    count = 0;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        if(isprime(x) == TRUE){
            count = count + 1;
        }
    }
    printf("%d\n", count);

    return 0;
}

Boolean isprime(int x){
    int j;
    double a = sqrt(x);
    if(x <= 1){
        return (FALSE);
    }
    for(j = 2; j <= a; j++){
        if(x % j == 0){
            return (FALSE);
        }
    }
    return (TRUE);
}



Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	if (N % 2 == 0) cout << N << endl;
	else cout << 2 * N << endl;
	return 0;
}


Measured memory_bytes: 256
# frozen_string_literal: true

N, D = gets.chomp.split.map(&:to_i)

def distance(p, q)
  Math.sqrt(p**2 + q**2)
end
count = 0
N.times.map do
  x, y = gets.chomp.split.map(&:to_i)
  dist = distance(x, y)
  count += 1 if dist <= D
end

puts count


Measured memory_bytes: 16124
s = input()
n = len(s)
for i in range(n):
    if s[i] == 'A':
        l = i
        break
for i in range(n-1,i,-1):
    if s[i] == 'Z':
        r = i+1
        break
ans = max(0,r-l)
print(ans)
    
    

Measured memory_bytes: 3516
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
a.sort()

class Factorial:
  def __init__(self, n, mod):
    self.mod = mod
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod
  def permi(self, n, k):
    return self.f[n] * self.i[n - k] % self.mod

f = Factorial(N, mod)

res = 0
for l in range(N - K + 1):
  res -= f.combi(N - l - 1, K - 1) * a[l]
  res %= mod
for r in range(K - 1, N):
  res += f.combi(r, K - 1) * a[r]
  res %= mod
print(res)


Measured memory_bytes: 99200
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

int main()
{
  uint64_t N;
  cin >> N;

  vector<uint64_t> A(N), B(N);
  N_TIMES(n, N) { cin >> A[n] >> B[n]; }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  uint64_t M = N >> 1;
  uint64_t P = A[M], Q = B[M];
  if (N % 2 == 0) {
    P += A[M - 1];
    Q += B[M - 1];
  }
  
  cout << (Q - P + 1) << endl;

  return 0;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, k; cin >> n >> k;
    VL h(n); cin >> h;
    SORT(h);
    ll ans = 0;
    FOR(i, 0, n - k)ans += h[i];
    cout << ans << "\n";
}


Measured memory_bytes: 1792
package main
 
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Count(L *[]int, l int) int {
  N := len((*L))
  if (*L)[N - 1] < l { return N }
  if l <= (*L)[0] { return 0 }
  high := N - 1
  low := 0
  for 1 < high - low {
    med := (high + low) / 2
    if (*L)[med] < l {
      low = med
    } else {
      high = med
    }
  }
  return high
}

func main() {
  N := NextInt()
  L := NextIntVec()
  sort.Ints(L)
  cnt := 0
  for i := 0; i < N - 1; i++ {
    for j := i + 1; j < N; j++ {
      d := L[j] - L[i]
      offset := 0
      if L[i] <= d { offset = 1 }
      long := Count(&L, L[i] + L[j])
      short := Count(&L, d + 1)
      cnt += long - short - 2 + offset
    }
  }
  Write(cnt / 3)
  Output()
}

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

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn adder (i: usize, j: usize) -> isize{
    let mut pow: usize = 1;
    for k in 1..i {
        pow *= 10;
    }
    (pow * j) as isize
}

fn main(){
    input!{
        n: usize,
        a:[i64;n]
    }
    let mut min:i64 = std::i64::MAX;
    for i in 1..100{
        let mut sum = 0i64;
        for &x in a.iter() {sum += (x - i)*(x - i)};
        if sum < min {min = sum;}
    }
    print!("{}", min);
}


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

typedef long long ll;
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD 10e9+7

void max_self(int& a, int b) { a=a>b?a:b; }
void min_self(int& a, int b) { a=a<b?a:b; }

using namespace std;

int n, k;
int x, y;
int num_ways;
double area;
double ans;


int main() {
    cin >> n >> k >> x >> y;
    area = n*(double)k/2.0;

    if(!(n&1)) {
        if(x==n>>1)
            num_ways++;
    }
    if(!(k&1)) {
        if(y==k>>1)
            num_ways++;
    }

    cout << area << ' ';


    if(num_ways>1)
        cout << 1;
    else
        cout << 0;
    
    cout << endl;
    



    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);

int main(void){
    ABC141();
}

void ABC141(){
    string s;
    cin>>s;
    cerr<<s<<endl;
    for(i=0;i<s.length();i++){
        if((i%2==0)&&(s[i]=='R'||s[i]=='U'||s[i]=='D'))count1++;
        if((i%2==1)&&(s[i]=='L'||s[i]=='U'||s[i]=='D'))count1++;
        cerr<<count1<<" ";
    }
    if(count1==s.length())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

const int MAX_V = 100000;

int C[MAX_V], L[MAX_V], N[MAX_V], P[MAX_V];
int NUM = 0;

vector<int> G[MAX_V];

void dfs(int cur, int prev) {
  NUM++;

  C[cur] = 1;
  N[cur] = L[cur] = NUM;

  for (int i = 0; i < G[cur].size(); i++) {
    int next = G[cur][i];

    if (C[next] == -1) {
      P[next] = cur;
      dfs(next, cur);
      L[cur] = min(L[cur], L[next]);
    } else if (next != prev) {
      L[cur] = min(L[cur], N[next]);
    }
  }
}

void art_points(int points) {
  dfs(0, -1);

  int root_of_children = 0;
  set<int> ap; // art_points

  for (int i = 1; i < points; i++) {
    int p = P[i];
    if (p == 0) root_of_children++;
    else if (N[p] <= L[i]) ap.insert(p);
  }

  if (root_of_children > 1) ap.insert(0);

  for (set<int>::iterator it = ap.begin(); it != ap.end(); it++)
    cout << *it << endl;
}

int main() {
  int v, e; cin >> v >> e;

  for (int i = 0; i < v; i++) C[i] = -1;

  for (int i = 0; i < e; i++) {
    int s, t; cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  art_points(v);

  return 0;
}

Measured memory_bytes: 5152
require 'set'
require 'pp'

n = gets.chomp!.to_i
po = []
po_set = SortedSet.new
n.times do |i|
  x, y = gets.chomp!.split(" ").map!(&:to_i)
  po[i] = [x, y, i + 1]
  po_set << po[i]
end

max = n

diff = {}
diff2 = {}

# 2点を選んだときの相対距離
po.permutation(2).each do |po1, po2|
  diff_x = po1[0] - po2[0]
  diff_y = po1[1] - po2[1]
  key = "#{diff_x},#{diff_y}"
  diff[key] = (diff[key] || 0) + 1
  diff2[key] = (diff2[key] || {})
  diff2[key][po1[2]] = po1[2]
end

#pp diff
#pp diff2

count = diff2.inject(0) {|m, (_, v)| m = (v.count > m) ? v.count : m } 

puts max - count


Measured memory_bytes: 3580
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int A,P;
    private void solve() {
        A = nextInt();
        P = nextInt();

        out.println((A * 3 + P) / 2);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll v[4], N, a[4] = { 1,2,4,8 }, ng[4] = {};
    rep(i, 4)cin >> v[i];
    cin >> N;
    N *= 4;

    rep(i, 4)FOR(j, i + 1, 4) {
        if (v[i] * a[j] < v[j] * a[i])ng[j] = 1;
    }

    ll ans = 0;
    for (int i = 3; i >= 0; --i)if (!ng[i]) {
        ans += N / a[i] * v[i];
        N %= a[i];
    }
    cout << ans << endl;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] n = new int[3];
        n[0] = sc.nextInt();
        n[1] = sc.nextInt();
        n[2] = sc.nextInt();
        Arrays.sort(n);
        if (n[0] == 5 && n[1] == 5 && n[2] == 7) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }

}


Measured memory_bytes: 20564
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
struct Block
{
    int w, s;
    ll v;
    bool operator<(const Block& b) const { return w + s < b.w + b.s; };
};
int main()
{
    int N;
    std::cin >> N;
    std::vector<Block> b(N);
    for (int i = 0; i < N; i++) { std::cin >> b[i].w >> b[i].s >> b[i].v; }
    std::sort(b.begin(), b.end());
    std::vector<ll> dp(20001, -(1LL << 60));
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = std::min(b[i].s, 20000 - b[i].w); j >= 0; j--) { dp[j + b[i].w] = std::max(dp[j + b[i].w], dp[j] + b[i].v); }
    }
    std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))



//*
//遅延セグ木ここから
//↓ここを変える
typedef struct sayouso{ll a,b;}sayouso;
typedef struct atai{ll a;}atai;
//↑ここを変える

typedef struct node{sayouso T;atai x;}node;
node *lsegN,*lseg;
ll lsegNUM,lsegk;

//↓ここから変える
sayouso sid={1,0};
atai aid={0};
atai xx(atai x,atai y){
	atai ret;
	ret.a=min(x.a,y.a);
	return ret;
}
atai Tx(sayouso T,atai x){
	atai ret;
	ret.a=T.a*x.a+T.b;
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.a=S.a*T.a;
	ret.b=S.b+S.a*T.b;
	return ret;
}
sayouso fT(sayouso T,ll k){
	sayouso ret;
	ret.a=T.a;
	ret.b=T.b;
	return ret;
}
//↑ここまで変える

//要素数(2ベキ)でこれを呼ぶ
void lseguse(ll n){
	lsegN=(node*)calloc(2*n,sizeof(node));
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	lsegk=0;while(n/=2)lsegk++;
	rep(i,1,2*lsegNUM){
		lsegN[i].x=aid;
		lsegN[i].T=sid;
	}
}
//lseg[i].xに値を与えてから初期化
void lseginit(){
	for(ll i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr,ll ck){
	if(l>=r)return;
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm,ck-1);
	lsegupdatesub(l,r,T,2*i+1,cm,cr,ck-1);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(fT(lsegN[2*i].T,ck-1),lsegN[2*i].x),Tx(fT(lsegN[2*i+1].T,ck-1),lsegN[2*i+1].x));
	lsegN[i].T=sid;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM,lsegk);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr,ll ck){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(fT(lsegN[i].T,ck),lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(fT(lsegN[i].T,ck),lsegN[i].x);
	lsegN[i].T=sid;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm,ck-1);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr,ck-1);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm,ck-1),lsegcalcsub(l,r,2*i+1,cm,cr,ck-1));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM,lsegk);}
//遅延セグ木ここまで
//*/


int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	lseguse(1<<17);
	while(q--){
		int t;
		scanf("%d",&t);
		if(t){
			int x,y;
			scanf("%d%d",&x,&y);
			printf("%lld\n",lsegcalc(x,y+1).a);
		}
		else{
			int x,y,b;
			scanf("%d%d%d",&x,&y,&b);
			sayouso T={1,b};
			lsegupdate(x,y+1,T);
		}
	}
}


Measured memory_bytes: 8008
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

my ($A, $B, $M) = split / /, <STDIN>;
my @a = split / /, <STDIN>;
my @b = split / /, <STDIN>;
my (@x, @y, @z);
{
  for (my $i=0; $i<$M; $i++) {
    ($x[$i], $y[$i], $z[$i]) = split / /, <STDIN>;
  }
}
my $min = min(@a) + min(@b);

for (my $i=0; $i<$M; $i++) {
  my $value = $a[$x[$i]-1] + $b[$y[$i]-1] - $z[$i];
  $min = $value if $min > $value;
}
say $min;

Measured memory_bytes: 56768
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = 10**15

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())
fact = divisors(n)

ans = INF 
for item in fact:
    ans = min(ans, item + n // item - 2)
print(ans)

Measured memory_bytes: 39536
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) or i1<=len(D1):
        if D0[i0][0]!=D1[i1][0]:
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (len(D0)-1-i0)>0 and (len(D1)-1-i1)>0:
                    if D0[i0+1][1]>D1[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (len(D0)-1-i0)==0 :
                    i1+=1
                elif (len(D1)-1-i1)==0:
                    i0+=1



Measured memory_bytes: 21148
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <algorithm>
using  namespace  std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#ifdef Cyberdebut
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef pair <int, int> pii;
ll gcd(ll a, ll b){return a ? gcd(b%a,a):b;}
ll pow_mod(ll x, ll n, ll mod){ll ret=1LL;while(n){if(n&1)ret=ret*x%mod;x=x*x%mod;n>>=1;}return ret;}
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<62)-1;
const ll mod = 1e9+7;
const int N = 2e5+5;

int n, a[N], pos[N];

int dp[2][N][31], lg[N];//dp[i][j]从i开始，长度为2^j的一段元素中的最小值
//初始化RMQ,  b数组下标从1开始，从0开始简单修改
void rmq_init(){
    for(int i=2; i<=n; i++) if(i & (i-1)) lg[i] = lg[i-1]; else lg[i] = lg[i-1]+1;
    for(int k=0; k<2; k++)for(int i=1; i<=n; i++)dp[k][i][0] = (i%2 == k) ? a[i]:n+1;
    for(int k=0; k<2; k++)
        for(int j=1; (1<<j)<=n; j++)
            for(int i=1; i+(1<<j)-1<=n; i++)
            dp[k][i][j] = min(dp[k][i][j-1], dp[k][i+(1<<(j-1))][j-1]);
}
//查询最大值 ,中间部分是交叉的
int rmq(int x, int l,int r){
    int k = lg[r-l+1];
    return min(dp[x][l][k], dp[x][r-(1<<k)+1][k]);
}

pair<int, int> calc(int l, int r){
    int x = rmq(l&1, l, r);
    int y = rmq((pos[x]+1)&1, pos[x]+1, r);
    return {-x, -y};
}

int  main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++)scanf("%d", &a[i]), pos[a[i]] = i;
    rmq_init();

    priority_queue<pair<pii, pii > >pq;
    pq.push({calc(1, n), {1, n} });
    while(pq.size()){
        auto now = pq.top(); pq.pop();
        int x = -now.ff.ff, y = -now.ff.ss;
        printf("%d %d ", x, y);
        int l = now.ss.ff, r = now.ss.ss;
        x = pos[x], y = pos[y];
        if(l < x-1)pq.push({calc(l, x-1), {l, x-1} });
        if(x+1 < y-1)pq.push({calc(x+1, y-1), {x+1, y-1} });
        if(y+1 < r)pq.push({calc(y+1, r), {y+1, r} });
    }
    puts("");
    return 0;
}


// lower_bound()
// __builtin_popcount()
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// const double eps=1e-12;
// #pragma comment(linker,"/STACK:102400000,102400000")


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


int main() 
{
	long long n,  m;
	cin>>n>>m;
	long long sum = 0;
	for(int i = 0; i < m;  i++){
		long long x ;cin>>x;
		sum+=x;
	}
	if(n>=sum)
		cout<<n-sum;
	else cout<<-1;
    return 0;
} 



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

int main(){
    int A,B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B)% 3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
}


Measured memory_bytes: 256
from sys import stdin
import math

n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

result = 999999999
for i in range(100):
    sum = 0
    for xx in x:
        sum += (xx - i) * (xx - i)
    if sum < result:
        result = sum

print(result)


Measured memory_bytes: 3064
//
// ALDS1_1_C:   Prime Numbers
// implementation-1
//


#include <iostream>
#include <math.h>
using namespace std;


bool prime_number(int x) {

	if ( x==0 || x==1) return false;
	if ((x>2) && ( x % 2 == 0)) return false;

	for(int i=3; i<=sqrt(x); i+=2) {
		if (x % i == 0) return false;
	}
	return true;
}

int main() {
	int N;
	cin >> N;

	int x;
	int ans=0;     //素数の数
	for(int i=0; i<N; i++) {
		cin >> x;
		if (prime_number(x)) {
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3072
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
	
	
	void run() {
		FastScanner sc = new FastScanner();
		char[] cs=sc.next().toCharArray();
		boolean ok=true;
		ok&=cs[2]==cs[3];
		ok&=cs[4]==cs[5];
		System.out.println(ok?"Yes":"No");
	}
	
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
	
	
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
}


Measured memory_bytes: 22484
#include <iostream>
#include <cstdio>
using namespace std;
long long n,a,b=1,k,ans;
bool f;
int main(){
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a);
		if(a!=b)ans++;
		else {
			b++;
			f=1;
		}
	}
	if(f)
	cout<<ans;
	else cout<<"-1";
	return 0;
}

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

int main() {
	double pi = 3.14159265358979323846264338327950288;
	double a,b,h,m;
	double angle;
	cin >> a >> b >> h >> m;
	angle = (h/12+m/60/12-m/60)*2*pi;
	double x = a-b*cos(angle);
	double y = b*sin(angle);
	double xxyy = x*x+y*y;
	double ans = sqrt(xxyy);
	printf("%10.20f",ans);
	return 0;
}


Measured memory_bytes: 4028