akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())

void Add(ll &a, ll b){
    a=(a+b)%mod;
    return;
}

void Pro(ll &a, ll b){
    a=(a*b)%mod;
    return;
}

vec Solve(){
    ll N; cin>>N;
    vec A(N), B(N), Count(N+1,0), CountB(N+1,0);
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>B[i];
    rep(i,N) {Count[A[i]]++; Count[B[i]]++; CountB[B[i]]++;}
    ll Max_Count=-1, Max_i=-1;
    vec akan;
    akan.pb(-1);
    rep(i,N+1) if(Count[i]>N) return akan;
    vec ans(N,-1);
    priority_queue<P> Q;
    rep(i,N+1) if(CountB[i]) Q.push(mp(Count[i],i));
    while(!Q.empty()){
        ll x=Q.top().second;
        Q.pop();
        ll f=upper_bound(ALL(A),x)-A.begin();
        rep(i,CountB[x]){
            ll I=(f+N+i)%N;
            while(ans[I]>=0){
                f++; I=(f+N+i)%N;
            }
            ans[I]=x;
        }
    }
    return ans;

}

int main(){
    vec ANS=Solve();
    if(ANS[0]<0) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        for(auto e:ANS) cout<<e<<' ';
        cout<<endl;
    }
}

Measured memory_bytes: 15264
#include<cstdio>
#include<queue>
using pii=std::pair<int,int>;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    if((n-1)*(n-2)/2<k){
        printf("-1\n");
        return 0;
    }
    std::queue<pii> q;
    for(int i=2;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            q.push({i,j});
        }
    }
    for(int i=0;i<k;i++){
        q.pop();
    }
    printf("%d\n",n-1+(int)q.size());
    for(int i=2;i<=n;i++){
        printf("1 %d\n",i);
    }
    while(!q.empty()){
        pii p=q.front();
        printf("%d %d\n",p.first,p.second);
        q.pop();
    }
    return 0;
}

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

using namespace std;

int main(){
    string str; cin >> str;
    bool ans = true;
    if(str[0] != 'Y') ans = false;
    if(str[1] != 'A') ans = false;
    if(str[2] != 'K') ans = false;
    if(str[3] != 'I') ans = false;

    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    int n;
    string N;

    cin >> n;

    N = std::to_string(n);

    if(N.find("7") != std::string::npos) {
        cout << "Yes";
    } else {
        cout << "No";
    }


    

}

Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N;

int tominutes(int w, int s){
  int h = s/100;
  int m = s%100;
  if(h >= 24){
    h -= 24;
    w++;
  }
  return h*60+m+w*60*24;
}

int main(){
  while(scanf("%d", &N) && N){
    map<string, int>fm;
    vi fv, tv;
    int weekday, start;
    char name[64];
    rep(i, N){
      scanf("%s%d%d", name, &weekday, &start);
      int t = tominutes(weekday, start);
      fm[string(name)] = t;
      tv.PB(t);
    }

    int P;
    scanf("%d", &P);
    rep(i, P){
      scanf("%s", name);
      fv.PB(fm[string(name)]);
    }
    int flag = 0;
    sort(fv.begin(), fv.end());
    REP(i, 1, fv.size()){
      if(fv[i] - fv[i-1] < 30) flag = 1;
    }


    sort(tv.begin(), tv.end());
    rep(i, tv.size()) rep(j, fv.size()){
      if(abs(tv[i]-fv[j]) < 30){
	tv.erase(tv.begin()+i);
	i--;
	break;
      }
    }

    int res = tv.size();
    int time = 0;
    rep(i, tv.size()){
      if(tv[i] - time < 30){
	res--;
      }else{
	time = tv[i];
      }
    }

    printf("%d\n", flag?-1:P+res);

  }
  return 0;
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()
/* --- */
int main() {
	int h, w, x, y;
	cin >> w >> h >> x >> y;
	
	double ans = (h * 1.0 * w) / 2.0;
	int multi = (2 * x == w && 2 * y == h);
	cout << fixed << setprecision(17);
	cout << ans << ' ' << multi << '\n';
}



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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int32_t main(){
	IOS;
	int tt = 1; 
	//cin >> tt;
	while(tt--){
		int n; cin >> n;
		string s = "";
		while(n){
			s += 'a' + n % 26;
			//cout << n << endl;
			if(n % 26 == 0) n -= 1;
			else n -= (n % 26);
			n /= 26;
		}
		for(auto &x : s) {
			if(x == 'a') x = 'z';
			else x -= 1;
		}
		reverse(all(s));
		cout << s << endl;	
	}
	return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>

int main() {

	int a, b, c, min, mid, max;

	scanf("%d %d %d", &a, &b, &c);

	if(a <= b && a <= c)
	{
		printf("%d ", a);
		if (b <= c)
			printf("%d %d\n", b, c);
		else
			printf("%d %d\n", c, b);
	}
	
	else if(b <= a && b <= c)
	{
		printf("%d ", b);
		if (a <= c)
			printf("%d %d\n", a, c);
		else
			printf("%d %d\n", c, a);
	}
	
	else if (c <= a && c <= b)
	{
		printf("%d ", c);
		if (a <= b)
			printf("%d %d\n", a, b);
		else
			printf("%d %d\n", b, a);
	}

	return 0;
}

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

int main(){
    int N;
    cin>>N;
    ll arr[N];
    ll dp[N];
    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<N;i++){
        dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    cout<<dp[N-1];
}

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

// 簡易UF
struct UF{
    vector<int> p;
    int n;

    UF(int siz){
        n = siz;
        p.resize(n, 0);
        for(int i = 0; i < n; i++)  p[i] = i;
    }

    int parent(int x){
        if(p[x] != x)   p[x] = parent(p[x]);
        return p[x];
    }

    bool same(int x, int y){
        return parent(x) == parent(y);
    }
    
    void unite(int x, int y){
        x = parent(x), y = parent(y);
        p[x] = y;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    int p[n];
    for(int i = 0; i < n; i++)  cin >> p[i], p[i]--;
    int x[m], y[m];
    UF uf(n);
    for(int i = 0; i < m; i++){
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
        uf.unite(x[i], y[i]);
    }
    int ans = 0;
    for(int i = 0; i < n; i++)  ans += uf.parent(p[i])==uf.parent(i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l;
	string s[101];
	cin>>n>>l;
	for(int i=1;i<=n;i++) cin>>s[i];
	sort(s+1,s+n+1);
	for(int i=1;i<=n;i++) cout<<s[i];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, a, b; cin >> n >> a >> b;
	ll ma = b * (n - 1) + a;
	ll mi = a * (n - 1) + b;
	cout << max(0ll, ma - mi + 1) << endl;

	return 0;
}


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

using namespace std;

int main() {
	int N, Z, W;
	scanf ("%d %d %d", &N, &Z, &W);
	int arr[N];
	for (int i = 0; i < N; i++)
		scanf ("%d", &arr[i]);
	if (N == 1)
		printf("%d\n", abs(arr[N - 1] - W));
	else printf("%d\n", max(abs(W - arr[N - 1]), abs(arr[N - 1] - arr[N - 2])));
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s.front();
    cout << (int)s.size() - 2;
    cout << s.back() << "\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int a;
  cin >> a;
  int ans = a + a * a + a * a * a;
  cout << ans << endl;
  return 0;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  int a[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
    }
  }
  int n=0;
  vector<int>ans;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i==h-1&&j==w-1)break;
      if(i%2==0){
        if(a[i][j]%2==1){
          if(j!=w-1){
            ans.push_back(i+1);
            ans.push_back(j+1);
            ans.push_back(i+1);
            ans.push_back(j+2);
            a[i][j+1] += 1;
            n+=1;
          }else{
            ans.push_back(i+1);
            ans.push_back(j+1);
            ans.push_back(i+2);
            ans.push_back(j+1);
            a[i+1][j] += 1;
            n+=1;
          }
        }
      }else{
        if(a[i][w-j-1]%2==1){
          if(w-j-1!=0){
            ans.push_back(i+1);
            ans.push_back(w-j);
            ans.push_back(i+1);
            ans.push_back(w-j-1);
            a[i][w-j-2]+=1;
            n+=1;
          }else{
            ans.push_back(i+1);
            ans.push_back(w-j);
            ans.push_back(i+2);
            ans.push_back(w-j);
            a[i+1][w-j-1]+=1;
            n+=1;
          }
        }
      }
    }
  }
  cout << n << endl;
  for(int i=0;i<n;i++){
    cout << ans[4*i] << ' ' << ans[4*i+1] << ' ' << ans[4*i+2] << ' ' << ans[4*i+3] << endl;
  }
  return 0;
}


Measured memory_bytes: 5104
import sys
p=['41412121','41212141','21414121','21214141','14141212','14121214','12141412','12121414']
g=lambda x:list(map(int,x))
for e in sys.stdin:
 d={}
 for f in p:d[sum(s-t for s,t in zip(g(e.split()),g(f))if s>t)]=f
 print(*list(d[min(d)]))


Measured memory_bytes: 5728
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define MAX_V 10001
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
typedef pair<int,int> mypair;
vector<int> g[MAX_V],rg[MAX_V];
//void f_dfs(int s,vector<int> &st,vector<bool> &used,vector<vector<int> > g){
void f_dfs(int s,vector<int> &st,vector<bool> &used){
	used[s] = false;
for(int i=0;i<g[s].size();i++){
	if(used[g[s][i]]){
	//f_dfs(g[s][i],st,used,g);
	f_dfs(g[s][i],st,used);
	}
}
	st.push_back(s);
	return;
}	
//void s_dfs(int s,int num,vector<int>&grup, vector<bool> &rused,vector<vector<int> > rg){
void s_dfs(int s,int num,vector<int> &grup,vector<bool> &rused){
	rused[s] = true;
	grup[s] = num;
	for(int i=0;i<rg[s].size();i++){
	//if(!rused[rg[s][i]])s_dfs(rg[s][i],num,grup,rused,rg);
	if(!rused[rg[s][i]])s_dfs(rg[s][i],num,grup,rused);
	}
	return ;
}
//void strong(int v,vector<int>&grup,vector<vector<int> > g,vector<vector<int> >rg){
void strong(int v,vector<int> &grup){
 vector<int> st;
//vector<bool> used(v,true),rused(v,true);
vector<bool> used(v,true);
//for(int i=0;i<v;i++)if(used[i])f_dfs(i,st,used,g);
for(int i=0;i<v;i++)if(used[i])f_dfs(i,st,used);
int num = 1;

	for(int i=st.size()-1;i>=0;i--){
	int now = st[i];
	if(!used[now]){
	//s_dfs(now,num,grup,used,rg);
	s_dfs(now,num,grup,used);
	num++;
	}
	}
	return;
}
int main(){
int v,e;
cin>>v>>e;
//vector<vector<int> >  g(v),rg(v);
int s,t;
 rep(i,e){
	cin>>s>>t;
	g[s].push_back(t);
	rg[t].push_back(s);
 }
// stack<int> st;
vector<int> grup(v,0);
//vector<bool> used(v,true),rused(v,true);
//	f_dfs(0,st,used,g);
	/*cout<<"number of size"<<st.size()<<endl;
	while(!st.empty()){
	cout<<st.top()<<endl;
	st.pop();
	}*/
	//int num =1;
	/*while(!st.empty()){
	int now = st.top();
	st.pop();
	if(rused[now]){
	s_dfs(now,num,grup,rused,rg);
	num++;
	}
	}*/
//strong(v,grup,g,rg);
strong(v,grup);
int q;
cin>>q;

rep(i,q){
	int b,e;
cin>>b>>e;
if(grup[b]==grup[e]){
cout<<1<<endl;
}else{
cout<<0<<endl;
}

}
}



Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a; }

bool is_prime(ll n) {
  if(n==1) return false;
  else if (n == 2) return true;
  else if (n%2 == 0) return false;
  double sqrtn = sqrt(n);
  for(int i = 3; i <= sqrtn; i+=2) {
    if(n%i == 0) return false;
  }
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B; cin >> A >> B;
  ll j = min(A,B);
  ll ans = 1;
  for(ll i=1; i*i<=j; ++i) {
    if(j%i != 0) continue;
    if(A%i==0 && B%i==0) if(is_prime(i)) ++ans;
    if(j/i == i) continue;
    if(A%(j/i)==0 && B%(j/i)==0) if(is_prime(j/i)) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll K;

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

  ll ans = 0;
  for (ll a = 1; a <= K; a++) {
    for (ll b = 1; b <= K; b++) {
      for (ll c = 1; c <= K; c++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }

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

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int n, m;
    cin >> n >> m;
    vvi rel(n, vi(n, 0));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        rel[a][b]=1, rel[b][a]=1;
    }

    vi per(n);
    rep(i, n) per[i] = i;
    int res = 0;
    do {
        bool ok = true;
        if(per[0] != 0) break;
        rep(i, n-1) {
            if(!(rel[per[i]][per[i+1]] || rel[per[i+1]][per[i]])) ok = false;
        }
        if(ok) res++;
    } while(next_permutation(ALL(per)));

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
table = [0] * 101

for i in range(a, b+1):
    table[i] += 1

for j in range(c, d+1):
    table[j] += 1

print(table.count(2) if table.count(2) == 0 else table.count(2)-1)

Measured memory_bytes: 9116
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  String po=sc.next();
  String s=sc.next();
  boolean b=false;
  for(char c='a';c<='z';c++){
  if((po+c).equals(s)){
  b=true;
  }
  }
  System.out.println(b?"Yes":"No");
}
}

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;
#define ll  long long
#define PI  acos(-1)
#define pb  push_back
#define ins insert
#define INF 5000000000000000007 //1e18+7
#define mk  make_pair
#define ff  first
#define ss  second
#define endl "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a) (ll)a.size()
#define double long double
#define coud(a,b) cout << fixed << setprecision((b)) << (a)
#define mset(x,y)  memset(x,y,sizeof(x))
#define all(x)   (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bp(n)  __builtin_popcountll(n)
#define mxt(a)  *(max_element(a.begin(),a.end()))
#define mnt(a)  *(min_element(a.begin(),a.end()))
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define trav(a, x)    for(auto &a : x)

const double eps=1e-7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int d8x[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int d8y[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int d4x[4]={1, 0, 0, -1};
int d4y[4]={0, -1, 1, 0};
ll power(ll x,ll y){ll ans=1;x=x;while(y>0){if(y&1)ans=(ans*x);y=y>>1;x=(x*x);}return ans;}
ll sqr(ll x) { return x * x;}

template <typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template <class T> inline void chmax(T &x,T y){ x = max((x), (y));}
template <class T> inline void chmin(T &x,T y){ x = min((x), (y));}
template <class T> T abs(T x) { return x>0 ? x : -x;}
template <typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0) { if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
typedef pair<int,int>  pii;
typedef pair<ll,ll>  pll;
typedef vector<pll>  vpll;
typedef vector<pii>  vpii;
typedef vector<ll>   vll;
typedef vector<int>  vii;
#define minpq priority_queue<T,vector<T>,greater<T> >;
// #define T int
// #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
//*X.find_by_order(k) returns the kth largest element (0-based).
//X.order_of_key(val) returns the no. of values less than val.
ll ncr(ll n,ll r) {ll ans=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){ans*=(n-i);ans/=(i+1);}return ans;}
const int MOD = 1000000007;   
const int N = 200100;

// 🎲
ll n, a[N], pre[N], ans;
int32_t main() {
  cin.sync_with_stdio(0);cin.tie(0);
  cin.exceptions(cin.failbit);
  
  cin >> n;
  rep(i,1,n) cin >> a[i];
  rep(i,1,n) pre[i] = pre[i-1] + a[i], pre[i] %= MOD;
  for (int i=1; i<n; ++i) {
    ans = ans%MOD + ((a[i]%MOD)*(pre[n] - pre[i] + MOD)%MOD)%MOD;
    ans %= MOD;
  }
  cout << ans;
  return 0; 
}

/* 
    stuff you shoulds look for
    * int overflow,array bounds.
    * special cases (n=1?).
    * N,MOD value.
*/

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll MOD = 1000000007;
const ll N=1e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    int q,t,op,c=0;
    cin>>q;
    char k;
    string pre="",suf="";
    while (q--){
        cin>>t;
        if (t==1){
            c++;
            swap(pre,suf);
        }
        else{
            cin>>op>>k;
            if (op==1){
                pre+=k;
            }
            else{
                suf+=k;
            }
        }
    }
    if (c&1)
        reverse(s.begin(),s.end());
    reverse(pre.begin(),pre.end());
    string ans="";
    ans+=pre+s+suf;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1348
from collections import defaultdict
d=defaultdict(list)
n ,m =list(map(int,input().split()))
h=list(map(int,input().split()))
for i in range(m):
    a,b=list(map(int,input().split()))
    d[a].append(b)
    d[b].append(a)
s=0
for c in d:
    k=0
    for v in d[c]:
        if h[c-1]<=h[v-1]:
            k=1
            break
    #print(c,k,d)
    if k==0:
        s+=1
s+=n-len(d)
print(s)

Measured memory_bytes: 101788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            const int MOD = 1000000007;
            int[] nm = RArInt();
            bool[] IsBreak = new bool[nm[0] + 1];
            for (int i = 0; i < nm[1]; i++)
            {
                IsBreak[RInt()] = true;
            }

            int[] dp = new int[nm[0] + 1];
            dp[0] = 1;
            dp[1] = IsBreak[1] ? 0 : 1;

            for (int i = 2; i <= nm[0]; i++)
            {
                if (IsBreak[i])
                {
                    dp[i] = 0;
                }
                else
                {
                    dp[i] = (dp[i - 1] % MOD + dp[i - 2] % MOD) % MOD;
                }
            }
            Console.WriteLine(dp[nm[0]]);
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


Measured memory_bytes: 15300
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        int res = 0;
        for (int i = 0; i < A.length; i++) {
            res = gcd(res, A[i]);
        }
        System.out.println(res);
        sc.close();
    }

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

Measured memory_bytes: 49400
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>


#define ll long long
#define int ll
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 300 + 1;

int n , m , k , q;
int dp[N][N] , h[N];
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> h[i];		
	int ans = 1e18;
	for(int i = 0; i <= n ; i++){
		for(int j = 1 ;j <= n; j++)
			dp[i][j] = 1e18;
		dp[i][0] = 0;
	}

	for(int i = 1; i <= n; i++){
		dp[i][1] = h[i];
		for(int j = 2 ; j <= i ; j++){
			int cur = 1e18;
			for(int id2 = i - 1 ; id2 >= 0 ; id2--){
				cur = min(cur , dp[id2][j - 1] + max(0ll,h[i] - h[id2]));									
			}
			dp[i][j] = cur;
		}
		ans = min(ans , dp[i][n - k]);
	}

	cout << ans;
}

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

vector< vector<P> > g;

void dfs(int cur, int par, vector<int>& d) {
    for (P& p : g[cur]) {
        if (p.first == par) continue;
        d[p.first] = d[cur] + p.second;
        dfs(p.first, cur, d);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    g.resize(n);
    for (int i = 1; i < n; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        w %= 2;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }

    vector<int> d(n, 0);
    dfs(0, -1, d);
    for (int i = 0; i < n; i++) {
        cout << (d[i] % 2 == 1) << "\n";
    }
    return 0;
}

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


#define ll unsigned long long
#define ALL(x) x.begin(),x.end()

#define FASTIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int MOD = 1e9+7;
const int maxn = static_cast<int>(1e5+3);


ll power(ll x, ll int y){
    int res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x + MOD)%MOD;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%MOD; // Change x to x^2
    }
    return res;
}
int arr[maxn];

int main(){

    string s;cin >> s;
    replace(s.begin(),s.end(),',',' ');
    cout << s;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,x,y,z;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<0){
		x=a*c*-1;
		y=b*e;
		z=x+y+d;
	}
	else if(a>0){
		x=b-a;
		z=x*e;
	}
	else{
		x=b*e;
		z=x+d;
	}
	printf("%d\n",z);
	return 0;
}
	


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    sort(a.begin(), a.end());
    k -= accumulate(a.begin(), a.end(), 0);
    cout << n + k / a[0] << endl;
}


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

int main(void) {
	int N;
	cin >> N;
	int D, X;
	cin >> D >> X;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		sum += (D - 1) / A + 1;
	}
	cout << sum + X << endl;
	//system("pause");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
2 3
2 55
2 77
2 99
)");
#define cin input
#endif

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

	vector<int> index(m);
	map<int,int> p;
	map<int,int> q;

	for (int i=0; i<m; i++)
	{
		int key, val;
		cin >> val >> key;
		p[key]=val;
		index[i]=key;
	}

	vector<int> c(n,1);

	for(auto itr=p.begin(); itr!=p.end(); itr++)
		q[itr->first]=c[itr->second-1]++;

	for(int i=0; i<m; i++)
		printf("%06d%06d\n", p[index[i]], q[index[i]]);
}

Measured memory_bytes: 11648
import itertools
N,M=map(int,input().split())
l=list(itertools.permutations(range(N-1)))
h=[set(map(int, input().split())) for i in range(M)]
a=0
for i in range(len(l)):
    for k in range(M):
        if {1,l[i][0]+2}==h[k]:
            break
    else:
        continue
    for j in range(1,N-1):
        for k in range(M):
            if {l[i][j-1]+2,l[i][j]+2}==h[k]:
                break
        else:
            break
    else:
        a+=1
print(a)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int,int> P;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
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; }
const int INF = 1001001001;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans = 0;
    //start位置のfor文
    rep(si,h)rep(sj,w){
        if(s[si][sj]=='#')continue;
        vector<vector<int>> dist(h,vector<int>(w,INF));
        queue<pair<int,int>> q;
        //マスi,jを値xでupdateしようとする。updateできるならxをqueueに突っ込む。
        auto update = [&](int i, int j, int x){
            if (dist[i][j]!=INF) return;
            dist[i][j]=x;
            q.push(P(i,j)); // .emplace(i,j)
        };
        update(si,sj,0);
        while(!q.empty()){
            int i = q.front().first;
            int j = q.front().second; q.pop();
            rep(k,4){
                int ni = i + di[k], nj = j + dj[k];
                if (ni<0||ni>=h||nj<0||nj>=w) continue;
                if (s[ni][nj]=='#')continue;
                update(ni,nj,dist[i][j]+1);
            }
            
        }
        rep(i,h)rep(j,w){
            if (s[i][j]=='#') continue;
            chmax(ans,dist[i][j]);
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll powe(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

void solve()
{
    ll i,j,k=0,n,l;
    cin>>n;
    vll v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
        k^=v[i];
    }
    for(i=0;i<n;i++)
    {
        cout<<(k^v[i])<<" ";
    }
}

int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    while(t--)
    solve();
}


Measured memory_bytes: 4700
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
ll a[1919], b[1919], c[1919];
signed main() {
	ll x, y, z, k;
	cin >> x >> y >> z >> k;
	rep(i, x)cin >> a[i];
	rep(i, y)cin >> b[i];
	rep(i, z)cin >> c[i];
	ll memo[1000001];
	rep(i, x) {
		rep(j, y) {
			memo[i * y + j] = a[i] + b[j];
		}
	}
	sort(memo, memo + (x * y));
	reverse(memo, memo + (x * y));
	ll ans[3000003];
	rep(i, min(x* y, k)) {
		rep(j, z) {
			ans[i * z + j] = memo[i] + c[j];
		}
	}
	sort(ans, ans + min(x * y, k) * z);
	reverse(ans, ans + min(x * y, k) * z);
	rep(i, k)cout << ans[i] << endl;
	ggr
}

Measured memory_bytes: 31616
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

const i64 mod = 1e9+7LL;

int main(){
    i64 N, M, K;
    cin >> N >> M >> K;
    if(N > M)swap(N, M);
    i64 ret = 0;
    i64 C = 1;
    if(K != 2){
        auto pow = [&](i64 a, i64 r){
            i64 ret = 1LL;
            while(r){
                if(r&1LL)ret = ret * a % mod;
                a = a * a % mod;
                r >>= 1;
            }
            return ret;    
        };
        for(i64 i=1;i<=K-2;i++){
            C = C * (N * M - 1 - i) % mod * pow(i, mod-2) % mod;
        }
    }
    for(i64 s = 1LL;s <= N + M - 1LL;s++){
        for(i64 i = 0LL;i <= min(N, s);i++){
            i64 j = s - i;
            i64 n = max((i64)N - i, (i64)0LL);
            i64 m = max((i64)M - j, (i64)0LL);
            i64 k = n * m % mod;
            if(i!=0 && i!=s)k = k * 2 % mod;
            ret = (ret + k * s % mod) % mod;
        }
    }
    // cerr << C << endl;
    cout << ret * C % mod << endl;
    return 0;
}


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

int main(){

    int r;
    cin >> r;

    if(r<1200){
        cout << "ABC" << endl;
    }else if(r<2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<complex>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

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

bool pr(int n) {
    int i=2;
    while (i*i<=n) {
        if (n%i==0) return false;
        i++;
    }
    return true;
}


int main(){
    int mod=1000000007;
    bool b[50010]={0};
    int n,ans;
    for (int i=2;i<50010;++i) {
        b[i]=pr(i);
    }
    for (;;) {
        scanf("%d",&n);
        if (n==0) break;
        ans=0;
        for (int i=2;i<(n+1)/2+1;++i) {
            if ((n-i)<i) break;
            if (b[i] && b[n-i]) ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3188
a,b,k=map(int,input().split())
c=0
while True:
    if a%2:a-=1
    b+=a//2
    a//=2
    c+=1
    if c==k:break
    if b%2:b-=1
    a+=b//2
    b//=2
    c+=1
    if c==k:break
print(a,b)

Measured memory_bytes: 38384
from itertools import permutations

d, g = map(int, input().split())
g = g // 100
p = []
c = []

for _ in range(d):
	pp, cc = map(int, input().split())
	p.append(pp)
	c.append(cc // 100)

ans = float("inf")
for array in permutations(range(d)):
	gap = g
	num = 0
	for a in array:
		if p[a] * (a + 1) >= gap:
			num += (gap - 1) // (a + 1) + 1
			break
		elif p[a] * (a + 1) + c[a] >= gap:
			num += p[a]
			break
		else:
			num += p[a]
			gap -= p[a] * (a + 1) + c[a]

	if num < ans:
		ans = num

print(ans)

Measured memory_bytes: 42428
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
    long long A,B;
    cin >> A >> B;
    long long K;
    cin >> K;
    
    if(A >= K){
        A = A - K;
    }
    else if(A < K && B < (K - A)){
        A = 0;
        B = 0;
    }
    else if(A < K && B >= (K - A)){
        
        B = B - (K - A);
      	A = 0;
    }
    

    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
int n;ll C;
ll num[4][100004],v[100004],x[100004];
int main(){
	cin>>n>>C;
	for (int i=1;i<=n;i++) scanf ("%lld%lld",&x[i],&v[i]);
	num[0][0]=0,num[2][0]=0;
	ll val=0;
	for (int i=1;i<=n;i++){
		val+=v[i];
		num[0][i]=max(num[0][i-1],val-x[i]);
		num[2][i]=max(num[2][i-1],val-2*x[i]);
	}
	num[1][n+1]=0,num[3][n+1]=0;
	val=0;
	for (int i=n;i>=1;i--){
		val+=v[i];
		num[1][i]=max(num[1][i+1],val-(C-x[i]));
		num[3][i]=max(num[3][i+1],val-2*(C-x[i]));
	}
	ll ans=0;
	for (int i=0;i<=n;i++){
		ans=max(ans,num[0][i]+num[3][i+1]);
		ans=max(ans,num[2][i]+num[1][i+1]);
	}
	cout<<ans;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int N;
	int max1 = 0;
	int now = 0;
	int cnt = 0;
	cin >> N;
	vector<int> s;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	now = s[0];
	for (int i = 0; i < N - 1; i++) {
		if (now >= s[i + 1]) {
			cnt = 1 + cnt;
			now = s[i + 1];
		}
		else {
			int k = cnt;
			max1 = max(k, max1);
			cnt = 0;
			now = s[i + 1];
		}
	}
	cout << max(max1, cnt);
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(n);
    REP(i, n) { cin >> a[i]; }

    priority_queue<ll> que;
    REP(i, n) {
        que.push(a[i]);
    }

    ll con = 0;
    while(que.top() + con >= n) {
        ll ma = que.top();
        que.pop();
        ll t = (ma + con + 1) / (n + 1);
        ma -= t * (n + 1);
        con += t;
        que.push(ma);
    }
    cout << con << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 3588
N,K=map(int,input().split())
table=[[0]*K for i in range(K)]#W=1
C=0
for i in range(N):
    x,y,z=input().split()
    x = int(x)
    y=int(y)
    if z=='B':
        y +=K
    x %=(2*K)
    y %=(2*K)
    t = (x//K +y//K)%2
    x%= K
    y%=K
    if t:
        table[y][x]-=1
    else:
        table[y][x]+=1
        C+=1
B=N-C
#print(table)
pr=[[0]*(K+1) for i in range(K)]
for i in range(K):
    for j in range(K):
        pr[j][i+1]=pr[j][i]+table[j][i]
#print(pr)
pr2=[[0]*(K+1) for i in range(K+1)]
for j in range(K):
    for i in range(K):
        pr2[j+1][i+1]=pr2[j][i+1]+pr[j][i+1]
#print(pr2)
ans = 0
for i in range(K+1):
    for j in range(K+1):
        #s=pr2[K][K]-pr2[i-1][K] -pr2[K][j-1]+2*pr2[i-1][j-1]
        s =pr2[i][K] +pr2[K][j]-2*pr2[i][j]
        #白で塗った時に差し引き難点もらえるか
        #t=pr2[K][K]-s#黒で塗る
        #print(s,t,s-t,C-s)
        ans = max(ans,C-s,B+s)
print(ans)

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

using namespace std;

bool pal(string s)
{
    int i=0,j=s.size()-1;
    while(i<=j)
    {
        if(s[i]!=s[j])
        return false;
        i++;
        j--;
    }
    return true;
}
int main()
{
  string s,a,b;
    cin>>s;
    int n=s.size();
    int m=(n-1)/2;
    for(int i=0;i<m;i++)
    a+=s[i];
    m=(n+3)/2;
    for(int i=m-1;i<n;i++)
    b+=s[i];
    
    if(pal(s) and pal(a)and pal(b))
    cout<<"Yes";
    else 
    cout<<"No";

    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
sticks = sorted(l)
count = 0
if n <= 2:
    print(0)
else:
    for x in range(n-2):
        for y in range(x+1,n-1):
            for z in range(y+1,n):
                if sticks[x] != sticks[y] and sticks[y] != sticks[z] and sticks[z] != sticks[x] and sticks[x] + sticks[y] > sticks[z]:
                    count += 1
    print(count)

Measured memory_bytes: 9132
//
//  main.cpp
//  Testing_main
//
//  Created by Davidia on 2019-02-05.
//  Copyright © 2019 Davidia. All rights reserved.
//

#include <bits/stdc++.h>
/*
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




*/

#define MOD 1000000007


using namespace std;


vector<vector<int>> dp(1001, vector<int>(1001,-1));

int update(const vector<vector<char>> &cats_cage, int cx, int cy){
    if (cx == 0 && cy == 0){
        return 1;
    }
    if (dp[cx][cy] != -1){
        return dp[cx][cy];
    }
    int temp = 0;
    if (cx-1 >= 0 && cats_cage[cx-1][cy] != '#')
        temp += (update(cats_cage,cx-1,cy) % MOD);
    if (cy-1 >= 0 && cats_cage[cx][cy-1] != '#')
        temp += (update(cats_cage,cx,cy-1) % MOD);
    temp %= MOD;
    dp[cx][cy] = temp;
    return temp;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int h,w; cin >> h >> w;
    vector<vector<char>> maq(h,vector<char>(w));
    for (int i = 0; i < h; i++){
        string s; cin >> s;
        for (int j = 0; j < w; j++){
            maq.at(i).at(j) = s.at(j);
        }
    }
    /*
     for (int i = 0; i < h; i++){
     for (int j = 0; j < w; j++){
     cout << maq.at(i).at(j);
     }
     cout << '\n';
     }*/
    cout << update(maq,h-1,w-1) << '\n';
    
    
    return 0;
}


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

struct Point {
    double x, y;
};

int cnt = 0;

void koch(int n, Point a, Point b) {
    cnt++;
    if (n == 0) {
        return;
    }

    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;

    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;

    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    cout <<  s.x << " " << s.y << endl;
    koch(n - 1, s, u);
    cout <<  u.x << " " << u.y << endl;
    koch(n - 1, u, t);
    cout << t.x << " " << t.y << endl;
    koch(n - 1, t, b);
}

int main() {
    Point a, b;
    int n;
    cin >> n;

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    cout << fixed;
    cout << a.x << " " << a.y << endl;
    koch(n, a, b);
    cout << b.x << " " << b.y << endl;

}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, m, c;
    cin >> n >> m >> c;
    vector<ll> b(m);
    rep(i, 0, m) cin >> b[i];

    int ans = 0;
    rep(i, 0, n) {
        int tmp = c;
        rep(j, 0, m) {
            ll a;
            cin >> a;
            tmp += a * b[j];
        }
        if (tmp > 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256