akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

using pi = pair<int,int>;

const int N = 100000;
const int INF = 19191919;

struct edge{ int to,cost; };
vector<edge> G[N];

vector<int> query[N];

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

    vector<int> a(m),b(m),c(m);
    rep(i,m){
        cin >>a[i] >>b[i] >>c[i];
        --a[i]; --b[i];
        G[a[i]].pb({b[i],c[i]});
        G[b[i]].pb({a[i],c[i]});
    }

    vector<int> d(n,INF);
    priority_queue<pi,vector<pi>,greater<pi>> pq;
    while(k--){
        int f;
        cin >>f;
        --f;
        d[f] = 0;
        pq.push({0,f});
    }

    vector<int> s(q),t(q);
    rep(i,q){
        cin >>s[i] >>t[i];
        --s[i]; --t[i];
    }

    while(!pq.empty()){
        pi now = pq.top();
        pq.pop();
        int v = now.se;
        if(now.fi>d[v]) continue;
        for(const auto &e:G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                pq.push({d[e.to],e.to});
            }
        }
    }

    vector<pi> e;
    rep(i,m) e.pb({min(d[a[i]],d[b[i]]), i});
    sort(all(e));
    reverse(all(e));

    sort(all(d),greater<int>());
    vector<int> l(q,-1), r(q,n-1);
    rep(loop,18){
        rep(i,N) query[i].clear();
        rep(i,q) query[(l[i]+r[i])/2].pb(i);

        UF uf(n);
        int idx = 0;
        rep(i,n){
            while(idx<m && e[idx].fi>=d[i]){
                int id = e[idx].se;
                uf.unite(a[id],b[id]);
                ++idx;
            }

            for(int qid:query[i]){
                if(uf.same(s[qid],t[qid])) r[qid] = i;
                else l[qid] = i;
            }
        }
    }

    rep(i,q) cout << d[r[i]] << endl;
    return 0;
}



Measured memory_bytes: 29436
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        int count = 0;

        if(A == B){
            count += 1;
        }
        if(B == C){
            count += 1;
        }
        if(C == A){
            count += 1;
        }

        if(count == 1){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23252
// C - Successive Subtraction
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());

	if (a[0] >= 0 && a[n - 1] >= 0) {
		int c = a[0];
		for (int i = 1; i < n - 1; i++) c -= a[i];
		cout << (a[n - 1] - c) << endl;
		c = a[0];
		for (int i = 1; i < n - 1; i++) {
			cout << c << ' ' << a[i] << endl;
			c -= a[i];
		}
		cout << a[n - 1] << ' ' << c << endl;
	} else if (a[0] < 0 && a[n - 1] < 0) {
		int c = a[n - 1];
		for (int i = 0; i < n - 1; i++) c -= a[i];
		cout << c << endl;
		c = a[n - 1];
		for (int i = 0; i < n - 1; i++) {
			cout << c << ' ' << a[i] << endl;
			c -= a[i];
		}
	} else {
		int ans = 0;
		for (int i = 0; i < n; i++) ans += abs(a[i]);
		cout << ans << endl;
		for (int i = 1; i < n - 1; i++)
			if (a[i] >= 0) {
				cout << a[0] << ' ' << a[i] << endl;
				a[0] -= a[i];
			}
		int c = a[n - 1];
		for (int i = 0; i < n - 1; i++)
			if (a[i] < 0) {
				cout << c << ' ' << a[i] << endl;
				c -= a[i];
			}
	}

	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define maxn 600086

using namespace std;

struct Node{
	int sum, pl;
}t[maxn << 2];

#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)

inline void up(int x){
	t[x].sum = max(t[ls(x)].sum, t[rs(x)].sum);
}

inline void add(int x, int y){
	t[x].sum += y, t[x].pl += y;
}

inline void down(int x){
	if(t[x].pl){
		add(ls(x), t[x].pl);
		add(rs(x), t[x].pl);
		t[x].pl = 0;
	}
}

void modify(int x, int l, int r, int ll, int rr, int d){
	if(ll <= l && r <= rr){
		add(x, d);
		return;
	}
	down(x);
	int mid = l + r >> 1;
	if(mid >= ll) modify(ls(x), l, mid, ll, rr, d);
	if(mid < rr) modify(rs(x), mid + 1, r, ll, rr, d);
	up(x);
}

int query(int x, int l, int r, int ll, int rr){
	if(ll <= l && r <= rr) return t[x].sum;
	down(x);
	int mid = l + r >> 1, sum = 0;
	if(mid >= ll) sum = max(sum, query(ls(x), l, mid, ll, rr));
	if(mid < rr) sum = max(sum, query(rs(x), mid + 1, r, ll, rr));
	return sum;
}

int n, m, k;
int x[maxn], y[maxn];
int ans;
vector<int> v;
int a[2][maxn];
int sk[2][maxn], top[2];

void cal(){
	v.clear();
	memset(t, 0, sizeof(t));
	for(int i = 1;i <= k;i++) v.push_back(x[i]);
	v.push_back(0), v.push_back(n);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int n0 = v.size();
	for(int i = 1;i <= n0;i++) a[0][i] = 0, a[1][i] = m;
	for(int i = 1;i <= k;i++){
		int j = lower_bound(v.begin(), v.end(), x[i]) - v.begin() + 1;
		if(y[i] < m / 2) a[0][j] = max(a[0][j], y[i]);
		else a[1][j] = min(a[1][j], y[i]);
	}
	top[0] = top[1] = 0;
	for(int i = 1;i <= n0;i++){
		if(i > 1){
			ans = max(ans, 2 * (query(1, 1, n0, 1, i - 1) + v[i - 1])); 
			ans = max(ans, 2 * (v[i - 1] - v[i - 2] + m));
		}
		while(top[0] && a[0][sk[0][top[0]]] <= a[0][i]){
			modify(1, 1, n0, sk[0][top[0] - 1] + 1, sk[0][top[0]], -(m / 2 - a[0][sk[0][top[0]]]));
			--top[0];
		}
		modify(1, 1, n0, sk[0][top[0]] + 1, i, m / 2 - a[0][i]);
		sk[0][++top[0]] = i;
		
		while(top[1] && a[1][sk[1][top[1]]] >= a[1][i]){
			modify(1, 1, n0, sk[1][top[1] - 1] + 1, sk[1][top[1]], -(a[1][sk[1][top[1]]] - m / 2));
			--top[1];
		}
		modify(1, 1, n0, sk[1][top[1]] + 1, i, a[1][i] - m / 2);
		sk[1][++top[1]] = i;
		
		modify(1, 1, n0, i, i, i - 2 >= 0 ? -v[i - 2] : 0);
		//printf("%d %d--\n", i, i - 2 >= 0 ? -v[i - 2] : 0);
		
		
	}
}

int main(){
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 1;i <= k;i++) scanf("%d%d", &x[i], &y[i]);
	cal();
	for(int i = 1;i <= k;i++) swap(x[i], y[i]);
	swap(n, m);
	cal();
	printf("%d", ans);
}

Measured memory_bytes: 28604
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
double v[210];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%lf",&v[i]);
	sort(v+1,v+n+1);
	for(int i=2;i<=n;i++)
		v[i]=(v[i]+v[i-1])/2.0;
	printf("%.7lf\n",v[n]);
	return 0;
}

Measured memory_bytes: 128
n,x=map(int,input().split())
a=list(map(int,input().split()))
asum=[0]*(n-1)
for i in range(n-1):
    asum[i]+=(a[i]+a[i+1])
temp=0
for j in range(n-1):
    if asum[j]>=x:
        if j!=n-2:
            asum[j+1]-=min(a[j+1],(asum[j]-x))
        temp+=(asum[j]-x)
            
print(temp)

Measured memory_bytes: 85752
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define plll pair<ll, pll>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t x){
	if(was_output)cout << " ";
	was_output = true;
	cout << x;
}

void outendl(){
	was_output = false;
	cout << endl;
}

ll n, m, l;
vvector<pll> road;
vvector<ll> anses;

int func(int start, int target){
	vector<int> high(n+1, -1);
	vector<char> used(n+1, false);
	vector<int> ntarget;
	vector<int> reses(n+1, 1000);
	ntarget.push_back(start);
	high[start]=l;
	priority_queue<pll> pq;
	rep(j, n){
		if(ntarget.empty())break;
		foreach(j, ntarget){
			if(high[j]>=0){
				if(used[j])continue;
				used[j]=true;
				pq.emplace(l, j);
				high[j]=l;
			}
		}
		ntarget.clear();

		while(pq.size()){
			pll d = pq.top();
			pq.pop();
			if(high[d.second]!=d.first)continue;
			foreach(i, road[d.second]){
				int nf = d.first - i.second;
				if(high[i.first]>=nf)continue;
				reses[i.first]=min(reses[i.first], j);
				high[i.first]=nf;
				pq.emplace(nf, i.first);
				ntarget.push_back(i.first);
			}
		}
	}
	repa(i, n+1){
		if(reses[i]==1000)anses[start][i]=-1;
		else anses[start][i]=reses[i];
	}
	return anses[start][target];

}

int main(){
	cin >> n >> m >> l;
	road.resize(n+1);
	anses.resize(n+1, vector<ll>(n+1, -2));
	rep(i, m){
		ll a, b, c;
		cin >> a >> b >> c;
		road[a].emplace_back(b, c);
		road[b].emplace_back(a, c);
	}
	int q;
	cin >> q;
	rep(i, q){
		int a, b;
		cin >> a >> b;
		if(anses[a][b]==-2)func(a, b);
		cout << anses[a][b] << endl;
	}

	return 0;
}



Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main(){
    int a[81];
    for (int i=1;i<=9;++i){
        for (int j=1;j<=9;++j){
            //cout << 9*(i-1) + j << ":" << i*j<<endl;
            a[9*(i-1) + j - 1] = i*j;
        }
    }

    int N;
    cin >> N;

    string ret = "No";

    for(int i=0;i<81;i++){
        if(a[i] == N){
            ret = "Yes";
            break;
        }
    }

    cout << ret << endl;





    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	scanf("%d", &n);
	int a[100005];
	int b[100005];
	ll sum = 0;
	for (int i = 0; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i<n; i++)
		scanf("%d", &b[i]);
	for (int i = 0; i<n; i++)
	{
		if (b[i]>a[i])
		{
			sum += a[i];
			b[i] -= a[i];
			a[i] = 0;
			if (a[i + 1]<b[i])
			{
				sum += a[i + 1];
				a[i + 1] = 0;
			}
			else
			{
				sum += b[i];
				a[i + 1] -= b[i];
			}
		}
		else sum += b[i];
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char s[5];
int main(){
    cin>>s;
    sort(s,s+4);
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) printf("Yes");
    else printf("No");
    return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int n;
  cin >> n;
  VLL a(n), b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  ll cnt = 0;
  for(int i = n-1; i >= 0; i--){
    int x;
    x = (b[i] - (a[i]+cnt) % b[i]) % b[i];
    cnt += x;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1916
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
  	ios::sync_with_stdio(false);
  	int N;
  	cin >> N;
  	int A[100];
  	long double sum;
  	for (int i = 0; i<N; i++) {
    	cin >> A[i];
    }
  	sort(A,A+N);
  	sum = A[0];
  	for (int i=1; i<N; i++) {
      sum = (sum + A[i])/2;
    }
    cout << sum << "\n";
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct tree{
    size_t n,r,md;
    vector<vector<int>> e;
    vector<int> pa,d,sz;
    vector<ll> ans,C;
    explicit tree(int n):n(n),e(n),d(n),C(n),ans(n, ll(n)*(n+1)/2){}
    explicit tree(string&s):n(s.length()/2+1),e(n),pa(n),d(n),sz(n,1){
        pa[0]=-1;
        int i{};
        stack<int> p;
        p.push(0);
        for(auto c:s){
            if(c=='('){
                pa[++i]=p.top();
                d[i]=p.size();
                e[p.top()].push_back(i);
                p.push(i);
            }
            else{
                sz[pa[p.top()]]+=sz[p.top()];
                p.pop();
            }
        }
        assert(i==n-1);
    }
    void built(bool f=true){
        static int a,b;
        for(auto&i:d) cin>>i,--i;
        fr(i,n-1){
            cin>>a>>b;
            if(f) --a,--b;
            add(a,b);
        }
    }
    void pbuilt(bool f=true){
        static int a;
        Fr(i,n-1){
            cin>>a;
            if(f) --a;
            add(a,i,false);
        }
    }
    void add(int a,int b,bool f=true){
        e[a].emplace_back(b);
        if(f) e[b].emplace_back(a);
    }
    template<class T>
    vector<T> square(int i){
        vector<T> ans(3,1);
        ans[1]=2;
        for(auto j:e[i]){
            auto a=move(square<T>(j));
            auto m0=ans.size(),m1=a.size();
            ans.resize(m0+m1-1,0);
            ifr(i0,m0){
                iFr(i1,m1-1) ans[i0+i1]+=ans[i0]*a[i1];
                ans[i0]*=a[0];
            }
        }
        return ans;
    }
    void r_dfs(int i,int p=-1){
        ll tmp = C[d[i]];
        pa[i]=p;
        for(auto j:e[i]) if(j!=p){
            C[d[i]]=0;
            r_dfs(j,i);
            sz[i]+=sz[j];
            ans[d[i]]-=(sz[j]-C[d[i]])*(sz[j]-C[d[i]]+1)/2;
        }
        C[d[i]] = tmp+sz[i];
    }
    void r_i(int r_){
        pa.resize(n);sz.resize(n,1),r=r_;
        r_dfs(r);
        fr(i,n){
            ans[i]-=(n-C[i])*(n-C[i]+1)/2;
        }
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    tree t(n);
    t.built();
    t.r_i(0);
    for(auto&i:t.ans) cout<<i<<'\n';
}

Measured memory_bytes: 38272
from itertools import product
N=int(input())
data=[]
for i in range(N):
    for j in range(int(input())):
        x,y=map(int,input().split())
        data.append((i,x-1,y))
ans=0
for i in product([1,0],repeat=N):
    s=True
    for k in data:
        if i[k[0]]==1 and i[k[1]]!=k[2]:
            s=False
            break
    if s:
        ans=max(ans,sum(i))
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
//#include <.h>

typedef struct{
  int id;
  int parent;
  int left;
  int right;
}Tree;

Tree *A;
int n;

void def(){
  int i;
  for (i = 1; i <= n; i++) {
    A[i].id = 0;
    A[i].parent = -1;
    A[i].left = -1;
    A[i].right = -1;
  }
}

void getParent(int i){
  //printf("getParent now\n");
  if(i==1){
    A[i].parent = -1;
    return;
  }
  A[i].parent = i/2;
}

void getChild(int i){
  //printf("getChild now\n");
  if(i*2 > n){
    A[i].left = -1;
  }else{
    A[i].left = i*2;
  }
  if(i*2 + 1 > n){
    A[i].right = -1;
  }else{
    A[i].right = i*2 + 1;
  }
}

void printer(){
  int i;
//各種表示
  for (i = 1; i <= n; i++) {
    printf("node %d: ",i);//添え字
    printf("key = %d, ",A[i].id );//中身
    if(A[i].parent != -1){//親の表示
      printf("parent key = %d, ",A[A[i].parent].id);
    }
    if(A[i].left != -1){//左の子の表示
      printf("left key = %d, ",A[A[i].left].id);
    }
    if(A[i].right != -1){
      printf("right key = %d, ",A[A[i].right].id);
    }
    printf("\n");
  }
}

int main() {
  int x;
  int i;

  scanf("%d",&n);
  A = malloc(sizeof(Tree) * (n + 1));
  def();
  for (i = 1; i <= n; i++) {
    scanf("%d",&A[i].id);
    getParent(i);
    getChild(i);
    //printf("%d ",A[i].id );
  }

  printer();

  free(A);
  return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <string> 
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
using namespace std;

int main(void) {
	string	O, E, ans;
	cin >> O >> E;

	for (int i = 0; i < E.size(); i++)
	{
		ans.push_back(O[i]);
		ans.push_back(E[i]);
	}
	if (O.size() > E.size())ans.push_back(O[O.size() - 1]);
	if (O.size() < E.size())ans.push_back(E[E.size() - 1]);
	cout << ans << endl;
	return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


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

    ll n, p;
    cin >> n >> p;

    if(n == 1){
        cout << p << endl;
        return 0;
    }

    ll res = 1;
    for(ll i = 2; i <= sqrt(p); ){
        if(p%i == 0){
            ll x = pow(i, n);
            if(p%x == 0){
                p /= x;
                res *= i;
            }
            else p /= i;
        }
        else i++;
    }

    cout << res << endl;
    

    return 0;
}



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

using namespace std;
constexpr int64_t INF = 1'000'000'000'000'000'000;

int main(void) {
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    for(int i=0; i<N; i++) {
        cin >> x[i];
    }

    vector< vector<int64_t> > cnt(N+1, vector<int64_t>(50*N+1, INF));
    cnt[0][0] = 1;

    for(int i=0; i<N; i++) {
        for(int j=i; j>=0; j--) {
            for(int k=50*N-x[i]; k>=0; k--) {
                if(cnt[j][k] != INF) {
                    if(cnt[j+1][k+x[i]] == INF) {
                        cnt[j+1][k+x[i]] = cnt[j][k];
                    } else {
                        cnt[j+1][k+x[i]] += cnt[j][k];
                    }
                }
            }
        }
    }

    int64_t ans = 0;
    for(int j=1; j<=N; j++) {
        for(int k=1; k<=50*N; k++) {
            if(j*A == k && cnt[j][k] != INF) {
                ans += cnt[j][k];
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back

using namespace std;
typedef long long ll;

int hist[110000];
int main()
{
  int N; cin >> N;
  REP(i, N) {
    int a; cin >> a;
    hist[a]++;
  }

  int ans = -1;
  for (int i = 1; i <= 100000; i++) {
    ans = max(ans, hist[i - 1] + hist[i] + hist[i + 1]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
n = int(input())
p = list(map(int, input().split()))
dif = 0
for i in range(n-1):
    if p[i] != i+1:
        dif += 1
if dif == 0:
    print("YES")
else:
    if dif > 2:
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	char zyuroku[17]={"0123456789abcdef"};
	int ni[16][4]={{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},
					{0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},
					{1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},	
					{1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}};
	int suu[32];
	int i,j,k,l;
	char buf[9];
	int q;
	int keta, su;
	int ke2,su2,su3[9];
	int flg;
	
	scanf("%d",&q);
	for(i=0;i<q;i++)	{
		scanf("%s",buf);
		for(j=0;j<8;j++)	{
			for(k=0;k<16;k++)	{
//				printf("%c ",buf[j]);
				if(buf[j]==zyuroku[k])	{
					suu[j*4]=ni[k][0];
					suu[j*4+1]=ni[k][1];
					suu[j*4+2]=ni[k][2];
					suu[j*4+3]=ni[k][3];
//					printf("j=%d k=%d\n",j,k);
				}
//				break;
			}
		}
		if(suu[0]==1)	{
			printf("-");
		}
		keta=1;
		su=0;
		for(j=24;j>=1;j--)	{
			su=su+suu[j]*keta;
			keta=keta*2;
		}
		printf("%d.",su);
		keta=500000000;
		su=0;
		for(j=25;j<=31;j++)	{
			su=su+keta*suu[j];
			keta=keta/2;
		}
		if(su==0)	{
			printf("0\n");
		}
		else {
			for(j=8;j>=0;j--)	{
				su3[j]=su%10;
				su=su/10;
			}
			for(j=8;j>=0;j--)	{
				if(su3[j]==0)	{
					su3[j]=-1;
				}
				else {
					break;
				}
			}
			for(j=0;j<=8;j++)	{
				if(su3[j]>=0)	{
					printf("%d",su3[j]);
				}
			}
			printf("\n");
		}
	}
	return 0;
}


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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MOD = 998244353;
const int MAXN = 300100;

int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}

int mul(int a, int b) {
  return (ll)a * b % MOD;
}

int pot(int a, int b) {
  if (!b) return 1;
  if (b % 2) return mul(a, pot(a, b - 1));
  int k = pot(a, b / 2);
  return mul(k, k);
}

int inv(int a) {
  return pot(a, MOD - 2);
}

int fak[MAXN];

int choose(int n, int k) {
  return mul(fak[n], inv(mul(fak[k], fak[n - k])));
}

int n, a, b;
ll k;

int main() {
  fak[0] = 1;
  FOR(i, 1, MAXN) fak[i] = mul(fak[i - 1], i);
  cin >> n >> a >> b >> k;
  ll sol = 0;
  REP(i, n + 1) {
    ll tream = (k - (ll)i * a) / b;
    if (tream * b != k - (ll)i * a) continue;
    if (tream > n || tream < 0) continue;
    sol = add(sol, mul(choose(n, i), choose(n, tream)));
  }

  cout << sol << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1005;
const int md = (int)1e9 + 7;
int n, m;
int a[N], b[N];
int mp[N][N], leftpoint = 1;
int used[N][N];
pair<int, int> point[N * N];
int choose, fix;
struct node
{
	int x, y;
	bool operator <(const node &rhs)const
	{
		return min(a[x], b[y]) > min(a[rhs.x], b[rhs.y]);
	}
	int val()
	{
		return min(a[x], b[y]);
	}
	int check()
	{
		return (used[x][y] == 0);
	}
} expand[N * N];
int mark[N * N];
long long ans = 1;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		if (mark[a[i]])
			return cout << 0, 0; 
		 point[a[i]].first = i;
		mark[a[i]] = 1;
	} 
	memset(mark, 0, sizeof(mark));
	for (int i = 1; i <= m; ++i)
	{
		cin >> b[i], point[b[i]].second = i;
		if (mark[b[i]])
			return cout << 0, 0;
		mark[b[i]] = 1;
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			expand[(i - 1) * m + j] = (node){i, j};
	sort(expand + 1, expand + n * m + 1);
	for (int i = n * m; i > 0; --i)
	{
//		cout << ans << endl;
		if (point[i].first > 0 && point[i].second > 0)
		{
			used[point[i].first][point[i].second] = 1;
//			++fix;
			--choose;
			continue;
		}
		if (point[i].first > 0)
		{
//			++fix;
			int tot = 0;
			int x = point[i].first;
			for (int j = 1; j <= m; ++j)
			if (used[x][j] == 0 && i <= b[j])
				++tot;
			ans = ans * tot % md;
			--choose;
			continue;
		}
		if (point[i].second > 0)
		{
//			++fix;
			int tot = 0;
			int y = point[i].second;
			for (int j = 1; j <= n; ++j)
			if (used[j][y] == 0 && i <= a[j])
				++tot;
			ans = ans * tot % md;
			--choose;
			continue;
		}
		while (leftpoint <= n * m && i <= expand[leftpoint].val())
		{
			leftpoint++;
//			--choose;
			choose++;
		}
		ans = ans * (choose - fix) % md;
//		cout << choose<< endl;
		--choose;
	}
//	cout << leftpoint << endl;
	cout << ans;
	return 0;
}


Measured memory_bytes: 20736
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k,ll p) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int d[200001];
int pre_DP(int a, int b) {
	int res = d[a + b - 2] * mod_pow(d[a - 1], Mod - 2, Mod) % Mod*
		mod_pow(d[b - 1], Mod - 2, Mod) % Mod;
	return res;
}
signed main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int ans = 0, sum = 1;
	d[0] = 1;
	for (int i = 1; i <= 200001; i++) {
		sum *= i;
		d[i] = (sum %= Mod);
	}
	for (int i = b+1; i <= w; i++) {
		int res = pre_DP(i, h - a);
		res *= pre_DP(w - i + 1, a);
		ans += res;
		ans %= Mod;
	}
	cout << ans << endl;
	getchar(); getchar();
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    const ll maxN = 1000000000;
    ll S;
    cin >> S;
    ll x1, y1, x2, y2, x3, y3;
    x1 = 0;
    y1 = 0;
    x2 = maxN;
    y2 = 1;
    ll p = S / maxN;
    ll q = S % maxN;
    if (q == 0)
    {
        x3 = q;
        y3 = p;
    }
    else
    {
        x3 = maxN - q;
        y3 = p + 1;
    }

    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}


Measured memory_bytes: 3576
s = input().split("/")
if int(s[0]) < 2019:
    print("Heisei")
elif int(s[0]) == 2019 and int(s[1]) < 4:
    print("Heisei")
elif int(s[0]) == 2019 and int(s[1]) == 4 and int(s[2]) <= 30:
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)

int main(void){
    int n;
    cin >> n;
    string a[n];
    bool flag = true;
    rep(i,n){
        cin >> a[i];
        if(i>0){
            if(a[i][0]!=a[i-1][a[i-1].size()-1])flag=false;
            rep(j,i)if(a[i] == a[j])flag=false;
        }
        if(flag==false)break;
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  string s,t;
  cin>>s>>t;
  int n=s.length();
  if(s==t.substr(0,n)){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}


Measured memory_bytes: 3624
//use itertools::Itertools;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

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:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize
    }

    let mut ans = 0;

    match n % 10 {
        0 => println!("pon"),
        1 => println!("pon"),
        2 => println!("hon"),
        3 => println!("bon"),
        4 => println!("hon"),
        5 => println!("hon"),
        6 => println!("pon"),
        7 => println!("hon"),
        8 => println!("pon"),
        9 => println!("hon"),
        _ => println!("gomi"),
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2272
from collections import deque

n, m = map(int, input().split())
adj = [[] for i in range(n + 1)]
for _ in range(m):
	a, b = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
dist = [-1 for i in range(n + 1)]
dist[1] = 0
Q = deque()
Q.append(1)
while len(Q) > 0:
	u = Q.popleft()
	for v in adj[u]:
		if dist[v] != -1:
			continue
		dist[v] = dist[u] + 1
		Q.append(v)
if dist[n] == 2:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

	int n, a=0;
	cin >> n;
	for (int x=1; x<n; x++) {
		int y = n-x;
		if (x < y)
			a++;
	}
	cout << a << '\n';
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = input()
    N = int(S)

    s = 0

    for x in S:
        s += int(x)

    if N % s == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61600
n = int(input())
flst = [int((26 ** i - 1) / 25) for i in range(1, 14)]
for i in range(len(flst)):
  if flst[i] <= n < flst[i + 1]:
    keta = i + 1
    break
n -= int(((26 ** keta - 26) / 25) + 1)
dname = ''
for i in range(keta):
  amari = n % 26
  dname += chr(amari + 97)
  n //= 26
print(dname[::-1])

Measured memory_bytes: 9204
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d", &N);
	int i = 0;
	while (i < 50000)
	{
		if ((i * 108) / 100 == N)
		{
			printf("%d\n", i);
			return 0;
		}
		i++;
	}
	printf(":(\n");
	// printf("%d\n", y);
	// printf("%f\n", y * 1.08);
	return (0);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

void solve_abc_b() {
	ll n, m;
	//ll x, y;
	//ll a, b, c;
	//ll k;
	//string s;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	cin >> n;

	mint p = 1;
	rep(i, n) {
		p *= i + 1;
	}

	cout << p.x << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_b();

	return 0;
}


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

int main(int argc, char *argv[])
{
    int a;

	cin >> a;
	if (a % 2 == 0) {
		cout << (a / 2) * (a / 2);
	} else {
		cout << (a / 2) * ((a / 2) + 1);
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  vector<pair<long, long>> AB(N);
  rep (i, N) {
    long a, b;
    cin >> a >> b;
    AB[i] = make_pair(a, b);
  }
  sort(AB.begin(), AB.end());
  priority_queue<long> pq;
  long i = 0;
  long result = 0;
  for (long day = 1; day <= M; day++) {
    while (i < N and AB[i].first <= day) {
      pq.push(AB[i].second);
      i++;
    }
    if (pq.size() == 0) continue;
    result += pq.top();
    pq.pop();
  }
  cout << result << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 2936
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(B/A>=C) cout << C << endl;
    else cout << B/A << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define N ((ll)301*1000)
#define MOD ((ll)1e9+7)

ll n,c,k,a[N];

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>c>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	ll i=0,ans=0;
	while(i<n)
	{
		ans++;
		ll j=i;
		while(j<n && j-i<c && a[j]<=a[i]+k)j++;
		i=j;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

N, x = map(int, input().split())
a = list(map(int, input().split()))
INF = 10**18
cost = [[INF] * N for _ in range(N)]
for i in range(N):
    cost[i][0] = a[i]
    for j in range(1, N):
        k = (i - j) % N
        cost[i][j] = min(a[k], cost[i][j - 1])
total = [sum(cost[i][j] for i in range(N)) for j in range(N)]
print(min(total[i] + x * i for i in range(N)))

Measured memory_bytes: 74560
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for (int i=0; i<N; i++) {
    cin >> C[i];
    for (int j=0; j<M; j++) cin >> A[i][j];
  }
  // 達成不可能かどうか調べる
  bool can = true;
  for (int i=0; i<M; i++) {
    int sum = 0;
    for (int j=0; j<N; j++) sum += A[j][i];
    if (sum<X) {
      can = false;
      break;
    }
  }
  vector<int> res;
  if (!can) cout << -1 << endl;
  else {
    for (int tmp=0; tmp<(1<<12); tmp++) {
      bitset<12> s(tmp);
      int sum = 0; // 価格の合計
      vector<int> memo(M, 0); // 各アルゴリズムについて得られる理解度
      for (int i=0; i<N; i++) {
        if (s.test(i)) {
          sum += C[i];
          for (int j=0; j<M; j++) memo[j] += A[i][j];
        }
      }
      sort(memo.begin(), memo.end());
      if (memo[0]>=X) res.push_back(sum);
    }
    sort(res.begin(), res.end());
    cout << res[0] << endl;
  }
}

Measured memory_bytes: 3664
N = int(input())
h = list(map(int,input().split()))

dp = [0 for i in range(N)]

for i in range(N-1):
    if i > 0:
        dp[i+1] = min(dp[i-1]+abs(h[i+1]-h[i-1]),dp[i]+abs(h[i+1]-h[i]))
    else:
        dp[i+1] = dp[i] + abs(h[i+1]-h[i])
        
print(dp[N-1])

Measured memory_bytes: 13980
n = int(input())
w = []
for _ in range(n):
    w.append(input())

for i in range(0, n-1):
    if w[i + 1][0] != w[i][len(w[i]) - 1]:
        print('No')
        exit()

li_uniq = list(set(w))
if len(li_uniq) != len(w):
    print('No')
    exit()

print('Yes')

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

LL dp[110][11000];

#define MOD 1000000007
LL powmod(LL a, LL n){
    if(n == 0) return 1;
    if(n % 2) return (a*powmod(a,n-1)) % MOD;
    LL c = powmod(a, n/2);
    return (c*c) % MOD;
}
LL inv(LL a){
    return powmod(a, MOD-2);
}


int main(){
    LL n, k;
    cin >> n >> k;
    for(LL N = 0; N <= n; N++){
        for(LL a = 0; a <= k*(n-N); a++){
            dp[N][a] = 0;
            if(N == 0) continue;
            for(LL val = 0; val <= k; val++){
                LL numadd = 0;
                LL newval = val + a;
                if(val <= N){
                    numadd = (val + a) / N;
                    newval = (val + a) % N;
                }
                dp[N][a] += dp[N-1][a + numadd];
                dp[N][a] %= MOD;
                dp[N][a] += newval * powmod(k+1, N-1);
                dp[N][a] %= MOD;
            }
        }
    }
    cout << dp[n][0] << endl;
}


Measured memory_bytes: 8192
import sys
from itertools import count


INF = sys.maxsize
N = int(input())
answer = INF

for i in count(1):
  # √N 見れば十分
  if i * i > N:
    break
  q, r = divmod(N, i)
  # 割り切れない場合は不適
  if r != 0:
    continue
  answer = min(
    answer, max(
      len(str(q)),
      len(str(N // q))
    )
  )

print(answer)

Measured memory_bytes: 38896
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
 
using namespace std;


int n, q = 0;
vector<int>A;
vector<int>M;

bool solve(int depth, int value);

bool solve(int depth, int value)
{
    if(depth == n) return (value == 0);

    if(solve(depth + 1, value)) return true;
    
    if(solve(depth + 1, value - A[depth])) return true;
    
    return false;
}


int main(void)
{
    //input
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int tmp;
        scanf("%d", &tmp);
        A.push_back(tmp);
    }
    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        int tmp;
        scanf("%d", &tmp);
        M.push_back(tmp);
    }
    
    for (int i = 0; i < q; ++i) {
        if(solve(0, M[i])) cout << "yes" << endl;
        else            cout << "no" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1220
/******************************************
* AUTHOR : cf/villazer *
******************************************/
#include <iostream>
#include<iomanip>
using namespace std;
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
#define lb(arr,n,x) lower_bound(arr,arr+n,x)-arr
#define ub(arr,n,x) upper_bound(arr,arr+n,x)-arr
#define endl "\n"
#define PI 3.14159265358979323846  /* pi */
#define sqr(x) (x)*(x)
#define all(v)  ((v).begin()),((v).end())
#define degreesToRadians(angleDegrees) (angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / PI) // Converts radians to degrees.

typedef long long ll;
typedef long double ld;
//Calculation of (x^y)%mm
ll mod_exp(ll x,ll y,ll mm)
{
    if(y==0)
        return(1);
    else if(y%2==0)
        return(mod_exp((x*x)%mm,y/2,mm));
    else
        return((x*mod_exp((x*x)%mm,(y-1)/2,mm))%mm);
}


int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

#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,m;
cin>>n>>m;
ll arr[m];
ll sum=0;
rep(i,m){
	cin>>arr[i];
	sum+=arr[i];
}
if(sum>n){
	cout<<"-1"<<endl;
	return 0;
}
cout<<n-sum<<endl;


return 0;
}

Measured memory_bytes: 3188
/*
      author : nishi5451
      created: 11.08.2020 22:49:25
*/

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


int main(){
    string s;
    cin >> s;
    if(s[0]==s[1] && s[1]==s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3632
n=int(input())
M=[list(map(int,input().split())) for _ in range(n)]

P=[M[0][0]]
for i in range(n):P.append(M[i][1])
DP=[[0 for _ in range(n)] for _ in range(n)]
for l in range(1,n):
    for i in range(n-l):
        j=i+l
        DP[i][j]=10**6
        for k in range(i,j):
            DP[i][j]=min(DP[i][j],DP[i][k]+DP[k+1][j]+P[i-1]*P[k]*P[j])
print(DP[0][-1])


Measured memory_bytes: 5664
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int x = stdIn.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = stdIn.nextInt();
		}
		Arrays.sort(a);
		
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(x >= a[i]) {
				if(i < N-1) {
					x -= a[i];
					count++;
				}
				else {
					if(x == a[i]) {
						x -= a[i];
						count++;
					}
				}
			}
			else {
				break;
			}
		}
		System.out.println(count);

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
ll K;
  cin>>K;
ll ans=0;
ll cmod=7%K;
  
if(K%2==0){
cout<<"-1"<<endl;
}
else if(K%5==0){
cout<<"-1"<<endl;
}
else{
  while(1){ans++;
    if(cmod==0){break;}
    cmod=cmod*10+7;
    cmod=cmod%K;
  }
  cout<<ans<<endl;
}
  
     
  
}


Measured memory_bytes: 3620
#include<iostream>

using namespace std;

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

	long long sum = 0;
	for(int i = 0; i < n; ++i){
		int a;
		cin >>a;
		sum += a;
	}
	if(sum % 2 == 0)
		cout <<"YES\n";
	else
		cout <<"NO\n";
	return 0;
}


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

int main(){
    int n, p;
    cin >> n;
    int a[n], b[n], t[n];
    for(int i = 0; i < n; i++){
        cin >> p;
        t[p - 1] = i;
    }
    for(int i = 0; i < n; i++){
        a[i] = 20001 * i + 1;
        b[i] = 20001 * n - a[i] + t[i];
    }
    for(int i = 0; i < n; i++){
        cout << a[i] << " ";
    }
    cout << endl;
    for(int i = 0; i < n; i++){
        cout << b[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 896
import numpy as np

def make_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

if __name__ == '__main__':
    A, B, K = map(int, input().split())
    N = make_divisors(np.gcd(A, B))
    N.sort(reverse=True)
    print(N[K-1])

Measured memory_bytes: 27080
N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)

for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1

print(ans)

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

int main(){

    while(1){
        int n, k; cin >> n >> k;
        if(n == 0) break;

        vector<int> a(n + 1);
        a[0] = 0;
        for(int i = 1; i <= n; i++){
            cin >> a[i];
            a[i] += a[i - 1];
        }

        int ans = -1000000000;
        for(int i = 0; i < n - k + 1; i++){
            int tmp = a[i + k] - a[i];
            ans = max(ans, tmp);
        }

        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

string s, t;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> s >> t;

    t.erase(t.end() - 1);

    if(s == t) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
int k, m, q;
ll a, b, n;
ll calc(ll x) {
	return ((ll)floor((ll)(a*x)/b) - (ll)a*(floor((ll)(x/b))));
}
int main() {
	io	
	cin>>a>>b>>n;
	if(n >= b-1) cout<<calc(b-1);
	else cout<<calc(n);
}


Measured memory_bytes: 3652