akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>

using namespace std;
typedef unsigned long long ullong;

ullong power(ullong x, ullong n, ullong M){
  ullong tmp = 1;

  if ( n > 0 ){
    tmp = power(x, n/2, M);
    if ( n%2 == 0 ) tmp = (tmp*tmp)%M;
    else tmp = (((tmp*tmp)%M)*x)%M;
  }
  return tmp;
}

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

  cout << power(m, n, 1000000007) << endl;

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int main()
{
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif

	ll n, k, i, p, d;
	cin >> n >> k;
	map<ll, ll> ma;
	while (k)
	{
		cin >> d;
		for (i = 0; i < d; i++)
		{
			cin >> p;
			ma[p] = 1;
		}
      k--;
	}
	cout << n - ma.size() << endl;

	return 0;
}

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

int n, m, p[100005];
set<int> A[100005];

vector<int> G[100005];
int used[100005];
int Num[100005];

void dfs(int x, int num){
  
  used[x] = 1;
  A[num].insert(x);
  Num[x] = num;
  
  for(int nx : G[x] ){
    if( used[nx] == 0 ) dfs( nx, num );
  }
  
}

signed main(){
  
  cin>>n>>m;
  
  for(int i=0;i<n;i++) cin>>p[i], p[i]--;
  
  for(int i=0;i<m;i++){
    int x, y;
    cin>>x>>y;
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  
  int num = 0;
  
  for(int i=0;i<n;i++){
    
    if( used[i] == 0 ){
      dfs( i, num );
      num++;
    }
    
  }
  
  
  
  int ans = 0;

  for(int i=0;i<n;i++){
    if( A[Num[p[i]]].count(i) ) ans++;
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 20480
mod=10**9+7
# mod inverse(逆元)
# 今回はfermatの小定理で求める
def mod_inv(x):
  return pow(x,mod-2,mod)

n=int(input())
A=list(map(int,input().split()))
# (N-1)!を求める
fac=1
for i in range(1,n):
  fac = fac*i%mod
# 各区間の個数テーブルを先に求める
cnt=[0]*n
for i in range(1,n):
  cnt[i] = fac * mod_inv(i) % mod
  cnt[i] = (cnt[i]+cnt[i-1]) % mod
# 計算
ans=0
for i in range(n-1):
  ans += (A[i+1]-A[i]) * cnt[i+1]
  ans %= mod

print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[51][51][2501];
signed main(){
    int n,a;
    cin>>n>>a;
    vector<int> vec;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        vec.push_back(t);
    }
    dp[0][0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=2500;k++){
                if(i-1>=0&&j>=0){
                    if(j-1>=0&&k-vec[i-1]>=0){
                        dp[i][j][k]+=dp[i-1][j-1][k-vec[i-1]];
                    }
                    dp[i][j][k]+=dp[i-1][j][k];
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][a*i];
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    ll cnt = 0;
    ll p = 0;
    char c = S[0];
    while(S[p] == c && p < N) ++p;
    if(p == N) cnt = N - 1;
    else {
        while(K > 0 && p < N) {
            while(S[p] != c && p < N) {
                S[p] = c;
                ++p;
            }
            --K;
            while(S[p] == c && p < N) ++p;
        }
        REP(i,0,N-1) {
            if(S[i] == S[i+1]) ++cnt;
        }
    }
    PR(cnt);
    

    return 0;
}

/*



*/

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 3640
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		System.out.println(combination(n,2) + combination(m,2));
	}
	public static long factorial(long n) {
		if (n <= 1)
			return 1;
		else {
			return n * factorial(n - 1);
		}
	}
	public static long combination(long n, long r) {
		long top = n;
		for (int i = 0; i < r - 1; i++) {
			top = top * (--n);
		}
		long bottom = factorial(r);
		return top / bottom;
	}
}


Measured memory_bytes: 21716
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        char[] c = sc.next().toCharArray();
        boolean ok = c.length == a + b + 1;
        for(int i=0;i<c.length;i++){
            if(i==a){
                if(c[i]!='-'){
                    ok=false;
                }
            }else{
                if(!Character.isDigit(c[i])){
                    ok=false;
                }
            }
        }
        System.out.println(ok?"Yes":"No");
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
int main(void){
  int a,b,c,i,sum=0;
  scanf("%d %d %d",&a,&b,&c);
  for(i=a;i<=b;i++){
    if(c%i==0)sum++;
  }
  printf("%d\n",sum);
  return(0);
}

Measured memory_bytes: 1848
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 1;
    rep(i,n-1)if(s[i] != s[i+1])cnt++;
    //cout << cnt << endl;
    while(k && cnt > 1){
        if(cnt >= 3){
            cnt -= 2;
            k--;
        }else{
            cnt--;
            k--;
        }
    }
    cout << n - cnt << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int N,M;
int cs(int n,int m){
    if(m==0) return 1;
    if(m==1) return n;
    if(m>n/2) return cs(n,n-m);
    if(m>1) return cs(n-1,m-1)+cs(n-1,m);
}
int main()
{
    cin>>N>>M;
    cout<<cs(N,2)+cs(M,2)<<endl;
}

Measured memory_bytes: 256
//なにもわからない
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline ll getll() {
	ll A = 0;
	if (ci - cn + 24 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int tmp[200001];
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
void pakuri_sort2(int N, int A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		for (int i = (1 << b) - 2; i >= 0; i--) kazu[i] += kazu[i + 1];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		for (int i = (1 << b) - 2; i >= 0; i--) kazu2[i] += kazu2[i + 1];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	ll N = getint(), K = getll();
	int A[200000], F[200000];
	rep(i, N) A[i] = getint();
	rep(i, N) F[i] = getint();
	pakuri_sort(N, A);
	pakuri_sort2(N, F);

	ll L = -1, R = 1e12;
	while (L + 1 < R) {
		ll M = (L + R) / 2;

		ll kazu = 0;
		rep(i, N) {
			if ((ll)A[i] * F[i] > M) {
				kazu += A[i] - M / F[i];
				if (kazu > K) break;
			}
		}
		if (kazu > K) L = M;
		else R = M;
	}

	printf("%lld", R);


	Would you please return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct LIS {
    vector<int>& v;
    vector<int> dp, id, ret, info;
    // info 1:unused 2:使っても良い 3:必ず使う
    int n, lis;
    LIS(vector<int>& _v) : v(_v) {
        n = v.size();
        dp.resize(n, INT_MAX / 2);
        id.resize(n, 0);
        rep(i, 0, n) {
            // 狭義単調増加列
            //id[i] = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
            // 広義単調増加列
            id[i] = upper_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
            dp[id[i]] = v[i];
        }
        int nl = *max_element(id.begin(), id.end());
        lis = nl;
        ret.resize(nl + 1, 0);
        rrep(i, n - 1, 0) if (id[i] == nl) ret[nl] = v[i], nl--;

        info.resize(n);
        vector<int> ma(n + 1), cnt(n);
        ma[lis] = INT_MAX / 2;
        rrep(i, n - 1, 0) {
            // 狭義単調増加列
            //if (ma[id[i] + 1] <= v[i]) info[i] = 1;
            // 広義単調増加列
            if (ma[id[i] + 1] < v[i]) info[i] = 1;

            else cnt[id[i]]++, ma[id[i]] = max(ma[id[i]], v[i]);
        }

        rrep(i, n - 1, 0) if (info[i] == 0 && cnt[id[i]] == 1) info[i] = 3;
        rep(i, 0, n) if (info[i] == 0) info[i] = 2;
        lis--;
    }
};

/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



double PI = 2 * acos(0.0);
typedef long long ll;
string A;
int X1, Y1, X2, Y2, N, X[201010], Y[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> X1 >> Y1 >> X2 >> Y2 >> N;
    rep(i, 0, N) cin >> X[i] >> Y[i];
    if (X1 > X2) {
        X1 = 100000000 - X1;
        X2 = 100000000 - X2;
        rep(i, 0, N) X[i] = 100000000 - X[i];
    }
    if (Y1 > Y2) {
        Y1 = 100000000 - Y1;
        Y2 = 100000000 - Y2;
        rep(i, 0, N) Y[i] = 100000000 - Y[i];
    }

    vector<pair<int, int>> v;
    rep(i, 0, N) if (Y1 <= Y[i] && Y[i] <= Y2 && X1 <= X[i] && X[i] <= X2) v.push_back({ X[i], Y[i] });
    sort(v.begin(), v.end());

    vector<int> vv;
    vv.push_back(-1);
    fore(p, v) vv.push_back(p.second);
    vv.push_back(INT_MAX / 2 - 1);
    LIS lis(vv);

    double ans = 100.0 * (X2 - X1 + Y2 - Y1);
    ans += (5.0 * PI - 20.0) * lis.lis;
    if (lis.lis == min(X2 - X1, Y2 - Y1) + 1) ans += 5.0 * PI;
    printf("%.15f\n", ans);
}

Measured memory_bytes: 9072
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

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

    double sum = 0;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        sum += 1.0 / a;
    }

    cout.precision(10);
    cout << 1.0 / sum;

    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  H,W = readline() |> split |> parseArray
  S=falses((H,W))
  for i in 1:H
    s=readline() |> strip
    S[i,:]=map(c->c=='.', collect(s))
  end

  c_h=zeros(Int, (H,W))
  for i in 1:H
    k=0
    for j in 1:W+1
      if (j==W+1 || !S[i,j])
        if k==j-1
          k=j
        else
          c=j-k-1 #(j-1)-(k+1)+1
          c_h[i,k+1:j-1]=c
          k=j
        end
      end
    end
  end
  # println(c_h)

  c_w=zeros(Int, (H,W))
  for i in 1:W
    j=1
    k=0
    for j in 1:H+1
      if (j==H+1 || !S[j,i])
        if k==j-1
          k=j
        else
          c=j-k-1
          c_w[k+1:j-1,i]=c
          k=j
        end
      end
    end
  end
  # println(c_w)

  maximum(c_h+c_w)-1 |> println

end

main()


Measured memory_bytes: 262688
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const long long INF = 9999999999999;
const int EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
class edge{
	public:
	int to;
	ll cost;
	bool type;
	inline edge(){}
	inline edge(int _to,ll _cost,bool _type){
		to = _to;
		cost = _cost;
		type = _type;
	}
	inline bool operator<(const edge &a)const{
		if(cost == a.cost)return to<a.to;
		return a.cost<cost;
	}
};
vector <edge> G[2000001];
ll d[2][2000001];
vector < pair<Pii,int> > switches;
bool start=false;
bool goal=false;
void putEdge(int K,bool type){
	rep(i,K-1){
		if(switches[i].fi.fi == switches[i+1].fi.fi){
			ll dist = switches[i+1].fi.se-switches[i].fi.se;
			G[switches[i].se].PB(edge(switches[i+1].se,dist,type));
			G[switches[i+1].se].PB(edge(switches[i].se,dist,type));
		}
	}
}
ll dijkstra(int K){
	fill(d[0],d[0]+K+10,INF);
	fill(d[1],d[1]+K+10,INF);
	priority_queue < edge > Q;
	Q.push(edge(0,0,0));
	while(!Q.empty()){
		edge e = Q.top();Q.pop();
		if(d[e.type][e.to] != INF)continue;
		d[e.type][e.to] = e.cost;
		rep(i,G[e.to].size()){
			if(e.type == G[e.to][i].type)Q.push(edge(G[e.to][i].to,G[e.to][i].cost+e.cost,e.type));
		}
		if(e.to == 0){
			if(start)Q.push(edge(e.to,e.cost+1,1-e.type));
		}
		else{
			Q.push(edge(e.to,e.cost+1,1-e.type));
		}
	}
	ll ans = min(d[0][K-1],d[1][K-1]);
	if(ans == INF)return -1;
	return ans;
}
int main(){
	int W,H,K;
	scanf("%d%d%d",&W,&H,&K);
	vector< Pii > v;
	rep(i,K){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;b--;
		if(a == 0 && b == 0)start = true;
		if(a == W-1 && b == H-1)goal = true;
		v.PB(Pii(b,a));
	}
	if(!start){
		v.PB(Pii(0,0));
		K++;
	}
	if(!goal){
		v.PB(Pii(H-1,W-1));
		K++;
	}
	sort(v.begin(),v.end());
	rep(i,K){
		switches.PB(mk(v[i],i));
	}
	putEdge(K,1);
	rep(i,K){
		swap(switches[i].fi.fi,switches[i].fi.se);
	}
	sort(switches.begin(),switches.end());
	putEdge(K,0);
	
	printf("%lld\n",dijkstra(K));
	return 0;
}

Measured memory_bytes: 85844
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n;
int start[100005];
int a[100005];

int main()
{
	LL z = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		z += a[i];
	}

	LL c = (1LL * n * (n + 1)) / 2;
	if (z % c != 0) {
		printf("NO\n");
		return 0;
	}
	LL nseq = z / c;

	int flag = 1;
	for (int i = 0; i < n; i++) {
		LL A = a[i];
		LL B = a[(i + 1) % n];

		A += nseq;
		A -= B;
		if (A < 0 || A % n) flag = 0;
		else start[(i + 1) % n] = A / n;
	}

	LL now = 0;
	int cnt = 0;
	for (int i = 0; i < 2 * n; i++) {
		if (i < n) {
			now += cnt;
			now += start[i];
			cnt+=start[i];
		}
		else {
			now += cnt;
			//now += start[i];
			now -= start[i - n] * n;

			if (now != a[i - n]) flag = 0;
		}
	}

	if (!flag) printf("NO\n");
	else printf("YES\n");


	return 0;
}


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

int gcd(int a, int b)
{
    int r;
    
    while(b!=0){
        r=a%b;
        a=b;
        b=r;
    }

    return a;
}        
    
int main(void)
{
    int n, i, ans, f;
    scanf("%d", &n);
    int a[n];

    for(i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    
    for(i=0;i<n-1;i++){
        a[i+1]=gcd(a[i], a[i+1]);
    }

    printf("%d\n", a[n-1]);
    
    return 0;
}


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

int *numbers;
int *used;

int ncr(int n, int r)
{
  int val=1;
  for (int i=0; i<r; i++)  val = val * (n-i) / (i+1);
  return val;
}

void combination(int *A, int n, int k, int m, int *aa)
{
  static int ii=0;
  if (m==k) {
    int sum=0;
    for (int i=0; i<k; i++) {
      sum += A[numbers[i]];
    }
    aa[ii++]=sum;
  } else {
    for (int i=0; i<n; i++) {
      if (m>0 && numbers[m-1]<i) continue;
      if (used[i]) continue;
      numbers[m] = i;
      used[i]=1;
      combination(A, n, k, m+1, aa);
      used[i]=0;
    }
  }
}
int main()
{
  int i, j, m, n, q;
  int ncomb=0;
  fscanf(stdin, "%d", &n);
  numbers = (int*)malloc(sizeof(int)*n);
  used = (int*)malloc(sizeof(int)*n);
  bzero(used, sizeof(int)*n);
  int A[n];
  for (i=0; i<n; i++) {
    ncomb += ncr(n, i+1);
    fscanf(stdin, "%d", A+i);
  }

  int *aa = (int*)malloc(sizeof(int)*ncomb);
  for (i=1; i<=n; i++)
    combination(A, n, i, 0, aa);

  fscanf(stdin, "%d", &q);
  for (i=0; i<q; i++) {
    fscanf(stdin, "%d", &m);
    for (j=0; j<ncomb; j++) {
      if (m==aa[j]) {
        puts("yes");
        break;
      }
    }
    if (j==ncomb)  puts("no");
  }
  return 0;
}


Measured memory_bytes: 5784
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
ans_dict = {}
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans_dict[i*10+j]=0
for num in range(1,n+1):
    num_str =  str(num)
    i = int(num_str[len(num_str)-1])
    j = int(num_str[0])
    if (i!=0) & (j!=0):
        ans_dict[i*10+j] +=1
for key_ in ans_dict.keys():
    if str(key_)[0] == str(key_)[1]:
        ans += ans_dict[key_]**2
    else:
        key_s = key_//10+int(str(key_)[1])*10
        ans += ans_dict[key_] * ans_dict[key_s]*2
        ans_dict[key_s] = 0
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int left=0, right=0;
  for(int i=0;i<N;++i) {
    if(S[i]=='(') {
      left++;
    }
    else {
      if(left==0) right++;
      else left--;
    }
  }
  for(int i=0;i<right;++i) cout<<'(';
  cout<<S;
  for(int i=0;i<left;++i) cout<<')';
  cout<<endl;
}



Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  
  int p[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  
  selectionSort(p, n);
  
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += p[i];
  }
  
  printf("%d\n", sum);
  
  return 0;
}

void selectionSort(int *p, int n)
{
  for (int i = 0; i < n; i++) {
    int minJ, minP = 1000;
    for (int j = i + 1; j < n; j++) {
      if (p[j] < minP) {
        minP = p[j];
        minJ = j;
      }
    }
    if (minP < p[i] ) {
      int tmpP = p[i];
      p[i] = minP;
      p[minJ] = tmpP;
    }
  }
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

ll col[200] = {0, 1, 0, 1, 1, 0};
string query(vector<ll> v) {
#ifdef DEBUG_
    cout << "?";
    for(auto i: v) cout << " " << i+1;
    cout << endl;

    ll cnt0 = 0, cnt1 = 0;
    for(auto i: v) {
        if(col[i] == 0) cnt0++;
        else cnt1++;
    }
    string ret;
    if(cnt0 > cnt1) ret = "Red";
    else ret = "Blue";
    cout << ret << endl;
    return ret;
#else
    cout << "?";
    for(auto i: v) cout << " " << i+1;
    cout << endl;

    string ret;
    cin >> ret;
    return ret;
#endif
}

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

    string ls, rs;
    { 
        vector<ll> v(n);
        iota(ALL(v), 0);
        ls = query(v);
        if(ls == "Red") rs = "Blue";
        else rs = "Red";
    }

    ll lb=0, ub=n;
    while(ub-lb>1) {
        ll mid = (lb+ub)/2;
        vector<ll> v;
        FOR(i, mid, mid+n) v.push_back(i);
        if(query(v) == ls) lb = mid;
        else ub = mid;
    }
    dump(lb, ub);

    // [ub, ub+n-1) が RB均等
    vector<ll> r, b;
    string ans(2*n, '?');
    REP(i, ub) {
        vector<ll> v;
        FOR(j, ub, ub+n-1) v.push_back(j);
        v.push_back(i);

        string ret = query(v);
        if(ret == "Red") ans[i] = 'R', r.push_back(i);
        else ans[i] = 'B', b.push_back(i);
    }
    FOR(i, ub+n-1, 2*n) {
        vector<ll> v;
        FOR(j, ub, ub+n-1) v.push_back(j);
        v.push_back(i);

        string ret = query(v);
        if(ret == "Red") ans[i] = 'R', r.push_back(i);
        else ans[i] = 'B', b.push_back(i);
    }
    
    FOR(i, ub, ub+n-1) {
        vector<ll> v;
        REP(j, (n-1)/2) v.push_back(r[j]);
        REP(j, (n-1)/2) v.push_back(b[j]);
        v.push_back(i);

        string ret = query(v);
        if(ret == "Red") ans[i] = 'R';
        else ans[i] = 'B';
    }

    cout << "! " << ans << endl;

    return 0;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 1000000007;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

int main() {
    int N;
    cin >> N;
    modint ans(1);
    ans = modint(10).pow(N) - (modint(9).pow(N) + modint(9).pow(N) - modint(8).pow(N));
    cout << ans << endl;
}


Measured memory_bytes: 3620
#!/usr/bin/env python

def main():
    N, M = list(map(int, input().split()))
    sc = [tuple(map(int, input().split())) for _ in range(M)]

    for i in range(1000):
        t = str(i)
        if len(t) != N:
            continue
        ok = True
        for s, c in sc:
            if int(t[s -1]) != c:
                ok = False
                break
        if ok:
            print(i)
            exit()
    print(-1)

if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
<?php
fscanf(STDIN, "%d", $n);
$inputs = [];

for ($i = 0; $n > $i; $i++) {
    $x = trim(fgets(STDIN));
    @$inputs[$x] += 1;
}
#var_dump([$n, $inputs]);

$max = max(array_values($inputs));

$tmp = [];
foreach ($inputs as $k => $v) {
    if ($max == $v) {
        $tmp[] = $k;
    }
}

sort($tmp, SORT_STRING);

echo join("\n", $tmp);


Measured memory_bytes: 31220
def main():
    """
    1 <= N <= 10^5
    1 <= Ai,Bi <= 10^9
    """
    N = int(input())
    *A, = map(int, input().split())
    *B, = map(int, input().split())

    ans = f(N, A, B)
    print(ans)


def a(N, A, B):
    ans = 0
    return ans


def f(N, A, B):
    diff = [b - a for a, b in zip(A, B)]
    diff = sorted(diff)
    diff_sum = sum(diff)

    if diff_sum > 0:
        return -1

    if len([d for d in diff if d <= 0]) == N:
        return 0

    start = 0
    end = N - 1
    used = [False] * N
    while start < end:
        ds = diff[start]
        de = diff[end]
        if ds <= 0 and de <= 0:
            break

        if ds < 0 and de > 0:
            cost = min(abs(ds), de)
            diff[start] += cost
            diff[end] -= cost

            used[start] = True
            used[end] = True

        if diff[start] >= 0:
            start += 1
        if diff[end] <= 0:
            end -= 1

    ans = sum(used)
    return ans


if __name__ == "__main__":
    main()


Measured memory_bytes: 90288
s = input()
l = len(s)
c = 0
if l%2 == 0:
    for i in range(0,l//2):
        if s[i] != s[l-1-i]:
            c = c+1
else:
    for i in range(0,l//2):
        if s[i] != s[l-1-i]:
            c = c+1
print(c)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
const int size=50+1;
char board[size][size];
bool vis[size][size]={true};
char search(int i,int j)
{
	char count='0';
	if(board[i][j]=='#')
	return '#';
	if(board[i-1][j-1]=='#')
	count++;
	if(board[i-1][j]=='#')
	count++;
	if(board[i-1][j+1]=='#')
	count++;
	if(board[i][j-1]=='#')
	count++;
	if(board[i][j+1]=='#')
	count++;
	if(board[i+1][j-1]=='#')
	count++;
	if(board[i+1][j]=='#')
	count++;
	if(board[i+1][j+1]=='#')
	count++;
	return count;
}
int main()
{
	int a,b;
	cin>>a>>b;
	int i,j;
	for(i=0;i<a;i++)
	{
		for(j=0;j<b;j++)
		{
			cin>>board[i][j];
		}
	}
	for(i=0;i<a;i++)
	{
		for(j=0;j<b;j++)
		{
			
			cout<<search(i,j);
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = list(input())
n = len(s)
judge = True

for i in range(n):
    if s[i] != s[n-1-i]:
        judge = False

for i in range((n-1)//2):
    if s[i] != s[(n-3)//2-i]:
        judge = False

for i in range((n+1)//2,n):
    if s[i] != s[n-1+(n+1)//2-i]:
        judge = False

if judge:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int num[100005];
const ll md=998244353;
ll ksm(ll n,ll k)
{
    ll ans=1;
    while(k)
    {
        if(k&1)
            ans=ans*n%md;
        k>>=1;
        n=n*n%md;
    }
    return ans;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int t;
        scanf("%d",&t);
        if(i==1 && t)
        {
            printf("0\n");
            return 0;
        }
        if(i!=1 && !t)
        {
            printf("0\n");
            return 0;
        }
        num[t]++;
    }
    ll ans=1,t=1;
    int f=0;
    for(int i=1;i<=100000;i++)
    {
        if(num[i])
        {
            if(f)
            {
                printf("0\n");
                return 0;
            }
            ans=ans*ksm(t,num[i])%md;
            t=num[i];
        }
        else
            f=1;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;
  for (int i=0; i<N; i++) {
    if(i<=N-1-i) {
      if (S.at(i)!=S.at(N-1-i)) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)
count = 0
i = 0
while True:
  if i == n:
    break
  m = s[i:i+2]
  if m == '01' or m == '10':
    s = s[:i] + s[i+2:]
    count += 2
    if i != 0:
      i -= 1
  else:
    i += 1
print(count)

Measured memory_bytes: 3428
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 200005
#define INF 0x3f3f3f3f
bool f[MAXN+5],pan;
vector<int> G[MAXN+5];
void DFS(int u,int fa){
	int cnt=0;
	for(int i=0;i<int(G[u].size());i++){
		int v=G[u][i];
		if(v==fa) continue;
		DFS(v,u);
		if(f[v]==1)
			cnt++;
	}
	if(cnt>=2){
		puts("First");
		exit(0);
	}
	f[u]=cnt^1;
	return ;
}
int main(){
	int n=read();
	for(int i=2;i<=n;i++){
		int u=read(),v=read();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	DFS(1,0);
	puts(f[1]?"First":"Second");
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector <int> h(n);
  REP(i, n) {
	cin >> h[i];
  }
  vector <int> hmax(n, 0);
  REP(i, m) {
	int a, b;
	cin >> a >> b;
	a--; b--;
	hmax[a] = max(hmax[a], h[b]);
	hmax[b] = max(hmax[b], h[a]);
  }
  int ans = 0;
  REP(i, n) {
	if (hmax[i] < h[i]) {
		ans++;
	  }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4052
#include<iostream>
#include<cstdio>

using namespace std;

int main() {
    int n, k; cin >> n >> k;
    double probability = 0;

    double ans = 0;

    for (int i = 1; i <= n; i++) {
        double probability = 1.0 / n;

        int now = i;

        while (now < k) {
            now *= 2;
            probability /= 2;
        }
        ans += probability;
    }
    printf("%.12f", ans);

    return 0;
} 


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

typedef struct elm {
    struct elm *next, *prev;
    int data;
} elm_t;

typedef struct {
    elm_t *front, *back;
} list_t;

void push_back(list_t *list, int data) {
    elm_t *e = malloc(sizeof(elm_t));
    elm_t *f = list->back->prev;
    e->next = f->next;
    e->prev = f;
    e->data = data;
    f->next = e;
    list->back->prev = e;
}

list_t *mklist() {
    list_t *l = malloc(sizeof(list_t));
    l->front = malloc(sizeof(elm_t));
    l->back = malloc(sizeof(elm_t));
    l->front->next = l->back;
    l->back->prev = l->front;
    return l;
}

char buf[100000 * 32];
int a[200000][2];

int cmp(const void *const key, const void *const memb) {
    return *(const int *) key - *(const int *) memb;
}

int main() {
    int n = 0, p = 0;
    long long r = 1;
    //FILE *f = fopen("in.txt","r");
    //size_t s = fread(buf, sizeof(*buf), 100000 * 32, f);
    size_t s = fread(buf, sizeof(*buf), 100000 * 32, stdin);
    int c = -1;
    for (size_t i = 0; i < s; i++) {
        if (buf[i] >= '0' && buf[i] <= '9') {
            int k = (int) strtol(buf + i, NULL, 10);
            if (c < 0) n = k;
            else {
                a[c][0] = k;
                a[c][1] = (c / n) * 2 - 1;
            }
            c++;
            while (buf[i] >= '0' && buf[i] <= '9')i++;
        }
    }
    qsort(a, n * 2, sizeof(int) * 2, cmp);
    for (int i = 0; i < n * 2; i++) {
        if (p * a[i][1] < 0) r = (r * abs(p)) % 1000000007;
        p += a[i][1];
    }
    printf("%lld\n", r);
}


Measured memory_bytes: 6268
A, B, C, X, Y = map(int, input().split())
"""
Cを2k枚買う
"""

ans = 10 ** 10
k = 0
while True:
    money = C * k
    money += A * max(0, X - k // 2) + B * max(0, Y - k // 2)
    # print(max(0, X - k // 2), max(0, Y - k // 2), k, money)
    ans = min(ans, money)
    if k // 2 >= max(X, Y):
        break
    k += 2
print(ans)


Measured memory_bytes: 39664
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b, c = M()
print(max(c-(a-b), 0))

Measured memory_bytes: 38640
#include "bits/stdc++.h"
using namespace std;
using ll=long long;

#include <vector>
#include <functional>

template <typename T,typename E>
struct LazySegmentTree{
   using F=std::function<T(T,T)>;
   using G=std::function<T(T,E,int,int)>;
   using H=std::function<T(E,E)>;

   int n;
   std::vector<T> dat;
   std::vector<E> laz;
   const F f;
   const G g;
   const H h;
   const T d1;
   const E d0;

   LazySegmentTree(int n_,const F f,const G g,const H h,const T d1,const E d0):f(f),g(g),h(h),d1(d1),d0(d0)
   {
      n=1;
      while(n_>n) n<<=1;
      dat.assign(2*n,d1);
      laz.assign(2*n,d0);
   }

   void set(int k,const T &x){
      dat[k+n]=x;
   }
   void eval(int k,int l,int r){
      if(laz[k]==d0) return;
      dat[k]=g(dat[k],laz[k],l,r);
      if(k<n){
         laz[2*k]=h(laz[2*k],laz[k]);
         laz[2*k+1]=h(laz[2*k+1],laz[k]);
      }
      laz[k]=d0;
   }
   void update(int a,int b,E x,int k=1,int l=0,int r=-1){
      if(r<0) r=n;
      eval(k,l,r);
      if(r<=a||b<=l) return;
      if(a<=l&&r<=b){
         laz[k]=h(laz[k],x);
         eval(k,l,r);
      }
      else{
         update(a,b,x,2*k,l,(l+r)/2);
         update(a,b,x,2*k+1,(l+r)/2,r);
         dat[k]=f(dat[2*k],dat[2*k+1]);
      }
   }
   T query(int a,int b,int k=1,int l=0,int r=-1){
      if(r<0) r=n;
      eval(k,l,r);
      if(r<=a||b<=l) return d1;
      if(a<=l&&r<=b) return dat[k];
      T vl=query(a,b,2*k,l,(l+r)/2);
      T vr=query(a,b,2*k+1,(l+r)/2,r);
      return f(vl,vr);
   }
};

/*

-RMinimumQ and RUpdateQ
f=[](T x,T y){ return min(x,y); };
g=[](T x,E y,int l,int r){ return y; };
h=[](E x,E y){ return y; };

-RSumQ and RAddQ
f=[](T x,T y){ return x+y; };
g=[](T x,E y,int l,int r){ return x+(r-l)*y; };
h=[](E x,E y){ return x+y; };

-RAddQ and RMinimumQ
f=[](T x,T y){ return min(x,y); };
g=[](T x,E y,int l,int r){ return x+y; };
h=[](E x,E y){ return x+y; };

-RSumQ and RUpdateQ
f=[](T x,T y){ return x+y; };
g=[](T x,E y,int l,int r){ return (r-l)*y; };
h=[](E x,E y){ return y; };

*/

int main(){
   int n,q;
   cin>>n>>q;
   using T=ll;
   using E=ll;
   auto f=[](T x,T y){ return min(x,y); };
   auto g=[](T x,E y,int l,int r){ return y; };
   auto h=[](E x,E y){ return y; };
   LazySegmentTree<ll,ll> seg(n,f,g,h,INT_MAX,INT_MAX);
   for(int i=0;i<q;++i){
      int com;
      cin>>com;
      int s,t,x;
      cin>>s>>t;
      if(com==0){
         cin>>x;
         seg.update(s,t+1,x);
      }
      else{
         cout<<seg.query(s,t+1)<<endl;
      }
   }
}



Measured memory_bytes: 7084
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

char buf[100];

int main(void) {
  int n, k;
  scanf("%d%d%s", &n, &k, buf);
  buf[k-1] += 'a'-'A';
  puts(buf);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll ans=0;
	for(int i=0;i<s.size();i++){
		bool me;
		if(i%2==0){
			me=false;
		}
		else{
			me=true;
		}
		char now=s[i];
		if(now=='g'){
			if(me){
				ans++;
			}
		}
		else{
			if(me==false){
				ans--;
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
import sys

s = input()
if s[0] == 'A':
    if 'C' in s[2:-1]:
        index = s[2:-1].index('C') + 2
        news = s[1:index] + s[index+1:]
        if news == news.lower():
            print('AC')
            sys.exit()
print("WA")


Measured memory_bytes: 2940
import Control.Applicative
import Text.Printf

solve :: [Double] -> Double
solve [x1, y1, x2, y2] = sqrt $ x * x + y * y
    where
        x = x1 - x2
        y = y1 - y2

main :: IO ()
main = getLine >>= putStrLn <$> printf "%.8f" <$> solve <$> map read <$> words

Measured memory_bytes: 4028
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int[][][] build = new int[4][3][10];

        int n = scanner.nextInt();
        int bnum, floor, room;
        int x;

        for(int i=0; i<n; i++){
            bnum = scanner.nextInt();
            floor = scanner.nextInt();
            room = scanner.nextInt();
            x = scanner.nextInt();
            build[bnum-1][floor-1][room-1] += x;
        }
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 10; k++){
                    System.out.print(" "+build[i][j][k]);
                }
                System.out.println("");
            }
            if(i < 3)System.out.println("####################");
        }

    }
}



Measured memory_bytes: 29760
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

int main(){
	long int N, K;
  	cin >> N >> K;
  	long int count1 = 0;
  	long int count2 = 0;
	if(K % 2 == 1) count1 = N / K;
	else { 
		count1 = N / K;
		count2 = N / (K / 2) - count1;
	}
	cout << count1 * count1 * count1 + count2 * count2 * count2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int H, W, K, black = 0, ans = 0;
  cin >> H >> W >> K;
  vector<vi> table(H, vi(W));
  vi yoko(H), tate(W);

  REP(i, H) {
    REP(j, W) {
      char c;
      cin >> c;
      if (c == '#') {
        table[i][j] = 1;
        black++;
        yoko[i]++;
        tate[j]++;
      }
    }
  }
  /*
    REP(i, H) {
      REP(j, W) { cout << table[i][j]; }
      cout << "\n";
    }
  */
  for (int bit = 0; bit < (1 << H); ++bit) {
    int red = 0;
    vi flag(6, 0);
    REP(i, H) {
      if (bit & (1 << i)) {
        red += yoko.at(i);
        flag.at(i) = 1;
      }
    }
    if (black - red < K)
      continue;
    else {
      for (int bit2 = 0; bit2 < (1 << W); ++bit2) {
        int red2 = 0;
        REP(j, W) {
          if (bit2 & (1 << j)) {
            REP(k, H) {
              // cout << table[k][j] << endl;
              if (flag.at(k)) {
                // cout << k << " = flag " << endl;
                continue;
              } else if (table[k][j])
                red2++;
            }
          }
        }
        // cout << "i = " << bit << " j = " << bit2 << endl;
        // cout << black << " " << red << " " << red2 << endl;
        if (black - red - red2 != K)
          continue;
        else
          ans++;
      }
    }
  }
  cout << ans << endl;
}
/*
for (int bit = 0; bit < (1 << N); ++bit) {
  vi skill(M);
  int sum = 0;
  bool flag = true;
  REP(i, N) {
    if (bit & (1 << i)) {
      sum += A.at(i).at(0);
      for (int k = 1; k < M + 1; k++) {
        skill.at(k - 1) += A.at(i).at(k);
      }
    }
  }
  for (auto a : skill) {
    if (a < X) flag = false;
  }
  if (flag && Ans > sum) Ans = sum;
}*/

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

int main(){
  int N;
  string s;
  string t;
  string g;
for(int i = 0;i < N * 2;i++){
  g = g + " ";
}
  cin >> N >> s >> t;
  for(int i = 0;i < N;i++){
    g.push_back(s[i]);
    g.push_back(t[i]);
  }
  cout << g << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int maxn = 1e8 + 8;
int main() {
    int n; cin >> n;
    int minnum;
    cin >> minnum;
    int ans = 1;
    for(int i = 1; i < n; ++i){
        int x; cin >> x;
        if(x <= minnum){
            ans++;
            minnum = x;
        }
    }
    cout << ans << endl;
    return 0;
}


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


b = sorted(b)
x = [[b[0],0]]

for i in range(1,a[1]):
    x.extend([[b[i],b[i]-b[i-1]]])

x = sorted(x ,key = lambda x: -x[1])

for i in range(a[1]):
    if i < a[0]-1:
        x[i].append(1)
    else:
        x[i].append(0)

x = sorted(x ,key = lambda x: x[0])

x[0][2] = 1

tmp = 0
res = 0

for i in range(1,a[1]):
    if x[i-1][2] == 1:
        tmp = x[i-1][0]
    if x[i][2]   == 1:
        res = res - tmp + x[i-1][0]
    elif i+1 == a[1]:
        res = res - tmp + x[i][0]
        
print(res)

Measured memory_bytes: 23200
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7
INF = float('INF')
#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

N, M = [int(x) for x in input().split()]
COSTS = [INF] * (1 << N)
COSTS[0] = 0
KEYS = [0]
A = [0]
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    key = 0
    for c in C:
        key |= (1 << (c-1))
    A.append(a)
    KEYS.append(key)

for pat in range(1 << N):
    for a, key in zip(A, KEYS):
        COSTS[pat | key] = min(COSTS[pat | key], COSTS[pat] + a)

ans = COSTS[(1 << N) - 1] 
if ans == INF:
    ans = -1 
print(ans)


Measured memory_bytes: 46808
N = int(input())
A_list = [int(x)-1 for x in input().split()]
B_list = [int(x) for x in input().split()]
C_list = [int(x) for x in input().split()]
ans = 0
prevA = -100
for A in A_list:
    ans += B_list[A]
    if (A == prevA+1):
        ans += C_list[prevA]
    prevA = A
print(ans)    


Measured memory_bytes: 38256
def is_prime(n):
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

count = 0

number = int(input())
for i in range(number):
    n = int(input())
    if is_prime(n):
        count = count + 1

print(count)

Measured memory_bytes: 6724
n = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""

while True:
    x = n_rem % 26
    # 余りが0、つまりzの場合は、26にします
    if x == 0:
        x = 26
    res += chars[x]

    # xを引いて、26で割ります
    n_rem -= x

    # 0なら終了します
    if n_rem == 0:
        break

    n_rem //= 26

# 0桁目が先頭で、最後の桁が末尾になっているので、反転させます
print(res[::-1])

Measured memory_bytes: 9100
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
x=[(-2,0)]+sorted(c.items(), key=lambda x:x[0])+[(0,0)]
l=len(x)-1
ans=0
for i in range(1,l):
    cnt=x[i][1]
    if x[i+1][0]-x[i][0]==1:
        cnt+=x[i+1][1]
    if x[i][0]-x[i-1][0]==1:
        cnt+=x[i-1][1]
    ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 16096