akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	int N,M,K;
	cin >> N >> M >> K;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=M;j++){
			//cout << i*M+j*N-i*j*2 << ' ';
			if(i*M+j*N-i*j*2==K){
				printf("Yes\n");
				return 0;
			}
		}
		//cout << endl;
	}
	printf("No\n");
	return 0;
}

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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

const int MOD = 1e9 + 7;
const int N = 510;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n,s = 0;
	cin >> n;
	for (int i = 1; i <= 1e7; ++i) {
		s = (s * 10 + 7) % n;
		if ( !s) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b,c;cin>>a>>b>>c;
  set<int> s;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  P((int)s.size());
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
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;}

#define INF 1120000000

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];

  long ans = 1;
  long odd = 1;
  rep(i,n){
    ans = ans*3;
    if(vec[i]%2==0) odd = odd*2;
  }

  cout << ans - odd << endl;

  return 0;
}


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

template <typename T>
void print_vector(vector<T>& vec) {
    cout << "print_vector -> ";
    for(int i=0; i<vec.size(); i++) {
        if(i == vec.size()-1) {
            cout << vec[i] << endl;
        }
        else {
            cout << vec[i] << " ";
        }
    }
    return;
}

vector<int> path[100010];

int main() {

    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }

    queue<int> q;
    q.push(0);
    vector<int> pre(N, -1);

    while(!q.empty()) {
        int node = q.front(); q.pop();
        for(int i=0; i<path[node].size(); i++) {
            if(pre[path[node][i]] == -1) {
                pre[path[node][i]] = node;
                q.push(path[node][i]);
            }
        }
    }

    cout << "Yes" << endl;
    for(int i=1; i<N; i++) {
        cout << pre[i] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 9924
def resolve():
    (N, M) = list(map(int, input().split(" ")))
    Xs = list(map(int, input().split(" ")))

    Xs.sort()
    diffs = [(i, Xs[i] - Xs[i-1]) for i in range(1, M)]
    diffs = sorted(diffs, key=lambda x: x[1], reverse=True)
    cnt = 0
    for i in range((N-1), len(diffs)):
        cnt += diffs[i][1]

    print(cnt)
    

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 19240
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#define REP(i,N) for(auto i = 0; i<N; i++)
#include <climits>

#include <cmath>
using namespace std;

int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}


int main() {

    string S;
    cin >> S;
    
    //// +はS[0]とS[1]の間、.....,S[N-2]とS[N-1] の間のN-1箇所入れられる。
    //// S = 10なので、2^{N-1}で管理して全部列挙する。
    
    long long ans = 0;
    long long temp = 0;
    
    if (S.size() == 1){
        cout << S[0]-'0' << endl;
        return 0;
    }
    
    for(auto a = 0; a < (1<<(S.size()-1)); a++){
        temp = S[0] - '0';

        for(auto i = 1; i < S.size()-1; i++){
            
            if ( (a >> (i-1)) % 2 == 1 ){
                ans += temp;
                temp = S[i]-'0';
            }else{
                temp = temp * 10 + S[i]-'0';
            }
        }
        
        if ( (a >> (S.size()-2))%2 == 0){
            temp = temp * 10 + S[S.size()-1]-'0';
            ans += temp;
        }else{
            ans += temp;
            ans += S[S.size()-1]-'0';
        }
        
    }
    
    cout << ans << endl;
    return 0;
    
}



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

int main() {
    int N,cnt=0;
    cin >> N;
    vector<int> ls(N);
    rep(i,N) cin >> ls[i];
    sort(ls.begin(),ls.end());
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) for(int k=j+1;k<N;k++){
        if (ls[i]<ls[j]+ls[k] && ls[j]<ls[k]+ls[i] && ls[k]<ls[i]+ls[j]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

using ll = long long;

const int N = 10005;

int n;
ll a[N], b[N], ac, bc;

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%lld", a + i);
    for(int i = 0; i < n; i++){
        scanf("%lld", b + i);
        if(a[i] > b[i]) bc += a[i] - b[i];
        else if((b[i] - a[i]) % 2){
            ac += (b[i] - a[i] + 1) / 2;
            bc++;
        }
        else ac += (b[i] - a[i]) / 2;
    }
    puts(ac >= bc ? "Yes" : "No");
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define fi first
#define se second
#define vec vector
const double eps=1e-6;
const int inf=0x3f3f3f3f;
#define N int(1e5+5)

int n,a[N];

void solve(){
	while(scanf("%d",&n)!=EOF){
		for (int i = 0; i < n; ++i){
			scanf("%d",&a[i]);
		}
		a[n]=n+2;
		int ret=0,cnt=0;
		for (int i = 0; i <= n; ++i){
			if(a[i]==i+1)cnt++;
			else {
				ret+=cnt/2+cnt%2;
				cnt=0;
			}
		}
		printf("%d\n",ret);
	}
}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  rep(i,3){
      if(s[i]==s[i+1]){
          cout << "Bad" << endl;
          return 0;
      }
  }
  cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/


int main()
{
  ll n,m;cin>>n>>m;
  ll a[n+m];
  for(ll i=0;i<n;i++)a[i]=0;
  for(ll i=n;i<n+m;i++)a[i]=1;
  ll ans=0;
  for(ll i=0;i<n+m;i++){
    for(ll j=i+1;j<n+m;j++){
      if((a[i]+a[j])%2==0){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int A, B, kari;
  int count=0;
  cin >> A >> B;
  
  int digit[5];
  for(int i=A;i<B+1;i++){
    kari=i;
    for(int j=0;j<5;j++){
      digit[j]=kari%10;
      kari=kari/10;
    }
    if(digit[0]==digit[4] && digit[1]==digit[3]){
      count++;
    }
  }
  cout << count << endl;
}

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

using LL = long long;
using ULL = unsigned long long;

using namespace std;

int main()
{
    int n, a, b;

    cin >> n >> a >> b;

    if ((a * n) > b)
    {
        cout << b << endl;
    }
    else 
    {
        cout << n * a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = 2005;

using namespace std;

int n, k, dp[N][N], nw[N][N], ans;
vector < int > g[N];

void dfs(int v, int pr)
{
	fill(dp[v], dp[v] + k + 1, 1);
	for (auto to : g[v])
	{
		if (to == pr)
			continue;
		dfs(to, v);
		for (int i = 0; i <= k; i++)
			nw[v][i] = dp[v][i];
		for (int i = 1; i <= k; i++)
		{
			nw[v][i] = max(nw[v][i], dp[to][i - 1] + dp[v][min(i, k - i)]);
			if (min(i - 1, k - i - 1) >= 0)
				nw[v][i] = max(nw[v][i], dp[v][i] + dp[to][min(i - 1, k - i - 1)]);
		}
		for (int i = 1; i <= k; i++)
			nw[v][i] = max(nw[v][i], nw[v][i - 1]);
		for (int i = 0; i <= k; i++)
			dp[v][i] = nw[v][i];
	}
	for (int i = 0; i <= k; i++)
		ans = max(ans, dp[v][i]);
}

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	scanf("%d%d", &n, &k);
	forn(i, n - 1)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		g[v].pb(u);
		g[u].pb(v);
	}
	//~solve
	dfs(1, -1);
	cout << n - ans << endl;		

	return 0;
}



Measured memory_bytes: 31872
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 5010
using namespace std;

int n,k,dp[20][N],num[N],ans;

void sol(int l,int r,int now)
{
	if(l==r)
	{
		int i;
		for(i=max(0,k-num[l]); i<k; i++)
		{
			if(dp[now][i]) break;
		}
		if(i<k) ans++;
		return;
	}
	int i,j,mid=((l+r)>>1);
	for(i=0;i<k;i++) dp[now+1][i]=dp[now][i];
	for(j=l; j<=mid; j++)
	{
		for(i=k-1; i>=num[j]; i--)
		{
			dp[now+1][i]|=dp[now+1][i-num[j]];
		}
	}
	sol(mid+1,r,now+1);
	for(i=0;i<k;i++) dp[now+1][i]=dp[now][i];
	for(j=mid+1;j<=r;j++)
	{
		for(i=k-1;i>=num[j];i--)
		{
			dp[now+1][i]|=dp[now+1][i-num[j]];
		}
	}
	sol(l,mid,now+1);
}

int main()
{
	int i,j;
	cin>>n>>k;
	for(i=1; i<=n; i++)
	{
		scanf("%d",&num[i]);
	}
	dp[0][0]=1;
	sol(1,n,0);
	cout<<n-ans;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int flag1,flag2;
	int count,ans=0;
	for(int i=0; i<n; i++){
		count=0;
		for(char alp='a'; alp<='z'; alp++){
			flag1=0,flag2=0;
			for(int j=0; j<=i; j++){
				if(s[j]==alp)flag1=1;
			}
			for(int j=i+1; j<n; j++){
				if(s[j]==alp)flag2=1;
			}
			if(flag1&&flag2)count++;
		}
		if(ans<count)ans=count;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a, b = [int(i) for i in input().split()]
content = input()

if len(content) == a + b + 1:
    A = content[:a]
    B = content[-b:]
    hyphn = content[a]
    if A.isdecimal() and B.isdecimal() and hyphn == '-':
        print('Yes')
    else :
        print('No')


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

struct comp{
	bool operator()(const pair<ll,ll>& a,const pair<ll,ll>& b) const{
		return a.second != b.second ? a.second < b.second : a.first < b.first;
	}
};

int N,A,B;
vector< pair<ll,ll> > P,Q;
set< pair<ll,ll> > S;
set< pair<ll,ll>,comp > E;
ll SY,SX,D;

ll dfs(ll y,ll x)
{
	ll res = upper_bound(ALL(P),make_pair(y - D,x + D)) - lower_bound(ALL(P),make_pair(y - D,x - D));
	res += upper_bound(ALL(P),make_pair(y + D,x + D)) - lower_bound(ALL(P),make_pair(y + D,x - D));
	res += upper_bound(ALL(Q),make_pair(y + D,x - D),comp()) - lower_bound(ALL(Q),make_pair(y - D,x - D),comp());
	res += upper_bound(ALL(Q),make_pair(y + D,x + D),comp()) - lower_bound(ALL(Q),make_pair(y - D,x + D),comp());
	res -= upper_bound(ALL(P),make_pair(y - D,x - D)) - lower_bound(ALL(P),make_pair(y - D,x - D));
	res -= upper_bound(ALL(P),make_pair(y - D,x + D)) - lower_bound(ALL(P),make_pair(y - D,x + D));
	res -= upper_bound(ALL(P),make_pair(y + D,x - D)) - lower_bound(ALL(P),make_pair(y + D,x - D));
	res -= upper_bound(ALL(P),make_pair(y + D,x + D)) - lower_bound(ALL(P),make_pair(y + D,x + D));
	vector< pair<ll,ll> > v;
	auto lo = S.lower_bound(make_pair(y - D,x - D)),hi = S.upper_bound(make_pair(y - D,x + D));
	for(;lo != hi;){
		v.push_back(*lo);
		E.erase(*lo);
		S.erase(lo++);
	}
	lo = S.lower_bound(make_pair(y + D,x - D)),hi = S.upper_bound(make_pair(y + D,x + D));
	for(;lo != hi;){
		v.push_back(*lo);
		E.erase(*lo);
		S.erase(lo++);
	}
	lo = E.lower_bound(make_pair(y - D,x - D)),hi = E.upper_bound(make_pair(y + D,x - D));
	for(;lo != hi;){
		v.push_back(*lo);
		S.erase(*lo);
		E.erase(lo++);
	}
	lo = E.lower_bound(make_pair(y - D,x + D)),hi = E.upper_bound(make_pair(y + D,x + D));
	for(;lo != hi;){
		v.push_back(*lo);
		S.erase(*lo);
		E.erase(lo++);
	}
	FOR(i,0,v.size()){
		res += dfs(v [i].first,v [i].second);
	}

	return res;
}


int main()
{
	scanf("%d%d%d",&N,&A,&B);
	A--; B--;

	P.resize(N); Q.resize(N);
	FOR(i,0,N){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		P [i] = {x + y,x - y};
		Q [i] = P [i];
		S.insert(P [i]);
		E.insert(P [i]);
	}
	SY = P [A].first; SX = P [A].second;
	D = max(abs(P [A].first - P [B].first),abs(P [A].second - P [B].second));
	sort(ALL(P));
	sort(ALL(Q),comp());

	S.erase({SY,SX}); E.erase({SY,SX});
	ll ans = dfs(SY,SX);
	ans /= 2;

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 22272
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cstdint>

using namespace std;

constexpr uint64_t one = 1;

uint64_t dxor(uint64_t n_) {
    uint64_t n = n_ + 1,r = 0;
    if(n % 4 <= 1) r = 0;
    else r = 1;
    for(int i = 1;i < 64;i++) {
        auto t = n & (0xffffffffffffffff >> (63 - i));
        if(t < (one << i)) continue;
        auto s = t - (one << i);
        if(s % 2) r = r | one << i;
    }
    return r;
}

int main() {
    uint64_t a,b;
    cin >> a >> b;
    cout << (dxor(a-1) ^ dxor(b)) << endl;
}


Measured memory_bytes: 256
def main():
  N,M=map(int,input().split())
  Inf=10**8
  dp=[Inf]*(2**N)
  dp[0]=0
  for i in range(M):
    a,b=map(int,input().split())
    tmp=list(map(int,input().split()))
    open_tresure=list(1<<j-1 for j in tmp)
   # print(open_tresure)
    op_tr=sum(open_tresure)
    for j in range(2**N):
      key=op_tr | j
      dp[key]=min(dp[key],dp[j]+a)
  if dp[-1]==Inf:
    print(-1)
  else:
    print(dp[-1])

main()

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define S_MAX 100
#define N_MAX 100000
#define M_MAX 200000
#define INF 10000000
#define MOD 1000000007
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;
typedef   signed long long dll;

int n, m;
int h, w;
int i, j, k;
int a, b;

char s[S_MAX + 1];

typedef struct {
	int in;
	int out;
} twoway;

void solve(){
	ull result = 0;
	ull prev;

	if (n < 1200) {
		puts("ABC");
	} else {
		puts("ARC");
	}

	return;
}

int main (void) {
	char *t;
	scanf("%d", &n);

	solve();
	return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <queue>

using namespace std;

int main()
{
    int N, Q;
    cin >> N >> Q;
    
    priority_queue<int> pQueue[N];
    
    for(int i = 0; i < Q; ++i)
    {
        int Command; cin >> Command;
        int t; cin >> t;
        
        if(Command == 0)
        {
            int val; cin >> val;
            pQueue[t].push(val);
        }
        else if(Command == 1)
        {
            if(pQueue[t].size())
              cout << pQueue[t].top() << endl;
        }
        else if(Command == 2)
        {
            if(pQueue[t].size())
              pQueue[t].pop();
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 4076
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    cin>>N;
    vector<pair<ll,ll>> A(N);
    REP(i,N){
        cin>>A[i].first;
        A[i].second=i;
    }

    sort(A.begin(),A.end(),greater<pair<ll,ll>>());

    vector<vector<ll>> dp(N+1,vector<ll>(N+1,0));
    REP(i,N){
        REP(j,N){
            ll a=A[i+j].first;
            ll idx=A[i+j].second;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+a*(idx-i));
            dp[i][j+1]=max(dp[i][j+1],dp[i][j]+a*(N-1-idx-j));
        }
    }

    ll ans=0;
    REP(i,N+1){
        ans=max(ans,dp[i][N-i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 34664
def abc044_c():
    ''' 過去提出を参考に '''
    _, A = map(int, input().split())
    X = list(map(lambda x: int(x) - A, input().split()))
    d = {0: 1}  # 負の値を取り得るため、配列でなく辞書で持つ
    for x in X:
        prev = list(d.items())  # 前のターンのぶんを保持しておく
        for val, cnt in prev:
            d[val + x] = d.get(val + x, 0) + cnt
    ans = d[0] - 1
    print(ans)

if __name__ == '__main__':
    abc044_c()

Measured memory_bytes: 9256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>
#include <map>
#include <tuple>
using namespace std;
int n, k, c, d[200009]; vector<pair<int, int>>D;
int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) { cin >> c; d[c]++; }
	for (int i = 1; i <= 200000; i++) { if (d[i] >= 1)D.push_back(make_pair(d[i], i)); }
	sort(D.begin(), D.end());
	int s = 0;
	for (int i = 0; i < (int)D.size() - k; i++)s += D[i].first;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
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
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int w[200];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}
	int ans = 0, res = Inf;
	int sum = 0, rer = 0;
	for (int i = 0; i < n; i++) {
		rer += w[i];
	}
	for (int i = 0; i < n; i++) {
		rer -= w[i];
		sum += w[i];
		if (res > abs(rer - sum)) {
			res = abs(rer - sum);
		}
	}
	cout << res << endl;
}

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

int main(){
  int N;
  int d[101];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> d[i];

  int num[101] = {0};
  for (int i = 0; i < N; i++) {
    num[d[i]]++;
  }

  int res = 0;
  for (int i = 1; i <= 100; i++) {
    if (num[i]) {
      ++res;
    }
  }
  cout << res << endl;

  return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;

    int mx = 0;
    LL res = 0;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if(a < mx) {
            res += mx - a;
        }
        mx = max(a, mx);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3612
a =  int(input())
b =  int(input())
c =  int(input())
d =  int(input())
e =  int(input())
k =  int(input())
if (e-a) > k:
    answer = ':('
else:
    if (d-a) > k:
        answer = ':('
    else:
        if (c-a) > k:
            answer = ':('
        else:
            if (b-a) > k:
                answer = ':('
            else:
                answer = 'Yay!'
print (answer)

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

int main() {
    long long A, V, B, W, T; cin >> A >> V >> B >> W >> T;
    if (W - V >= 0) {
        cout << "NO" << endl;
        return 0;
    }
    long long v = abs(W - V), d = abs(A - B);
    if (d > v * T) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

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

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

    int a, b;
    cin >> a >> b;

    if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long N; cin >> N;
    vector<long long>A(N);
    for (long long i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<long long>B = A;
    for (long long i = 1; i < N; i++) {
        B.at(i) = B.at(i - 1) ^ B.at(i);
    }
    long long num = B.at(N - 1);
    for (long long i = 0; i < N; i++) {
        long long ans = A.at(i);
        cout << (num ^ ans);
        if (i != N - 1) cout << ' ';
    }
}

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
char a[1000010];
int main()
{
    cin>>a;
    int x=0,y=0;
    int ans=0;
    for(int i=0;i<sizeof(a);i++)
    {
        if(x==y){x++;if(a[i]=='p')ans--;}
        else {y++;if(a[i]=='g'){ans++;}}
    }
    cout<<ans;

}

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

int n, m;
int a[100000];
int b[100000];
bool no[400];
bool used[400][400];
void sub(int s) {
  used[s][s] = true;
  for (int j = m - 1; j >= 0; --j) {
    int x = a[j];
    int y = b[j];
    if (used[s][x] && used[s][y]) {
      no[s] = true;
      return;
    } else if (used[s][x]) {
      used[s][y] = true;
    } else if (used[s][y]) {
      used[s][x] = true;
    }
  }
  return;
}

int main() {
  cin >> n >> m;
  for (int j = 0; j < m; ++j) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    a[j] = x;
    b[j] = y;
  }
  
  for (int i = 0; i < n; ++i) {
    sub(i);
  }
  
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (no[i]) continue;
    for (int j = i + 1; j < n; ++j) {
      if (no[j]) continue;
      
      bool ok = true;
      for (int k = 0; k < n; ++k) {
        if (used[i][k] && used[j][k]) {
          ok = false;
          break;
        }
      }
      
      if (ok) {
        ++cnt;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

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

  ll N;
  cin >> N;
  int cnt = 3;
  map<ll, ll> m1;
  map<ll, ll> m2;
  m1 = prime_factor(N-1);
  m2 = prime_factor(N);
  ll sum = 1;
  for(auto ite = m1.begin(); ite != m1.end(); ite++) {
    sum *= (ite->_2+1);
  }
  for (ll i = 2; i*i <= N; i++) {
    if (N % i == 0) {
      if (i * i == N)
        sum++;
      else {
        ll t = N;
        while (t % i == 0) {
          t /= i;
        }
        if (t % i == 1)
         sum++;
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vpii vector<pair<int, int>>
#define pii pair<int, int>
#define ar array
#define vvll vector<vll>
#define repa(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1e9
#define MP make_pair
#define ll long long int
#define M 1000000007
#define all(a) a.begin(), a.end()
// debugging
#define db(x) cout << x << "\n";
#define db1(x) cout << #x << "=" << x << "\n"
#define db2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << "\n"
#define db3(x, y, z) cout << #x << "=" << x << ", " << #y << "=" << y << ", " << #z << "=" << z << "\n"
#define dba(x)       \
    for (auto i : x) \
    cout << i << "\t"
#define dbm(x)                \
    for (auto i : x)          \
    {                         \
        for (auto j : i)      \
            cout << j << " "; \
        cout << "\n";         \
    }
#define MOD 1000000007
using namespace std;
const int maxN = 100000;
void solve()
{
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, b;
    cin >> n >> b;
    char c;
    cin >> c;
    ll d;
    cin >> d;
    b *= 100;
    b += d;
    cout << (n * b) / 100;
}

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

int main()
{
    ll h,n;
    cin >> h >> n;
    vector<ll> a;
    for( int i = 0; i < n; i++ )
    {
        int a_ = 0;
        cin >> a_;
        a.push_back(a_);
    }

    int sum = 0;
    for( int i = 0; i < n; ++i ){
        sum = sum + a[i];
    }
    
    if( sum >= h ){
        cout << "Yes" << endl;
    }
    else if( sum < h ){
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 1400
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string W,T,s="";
    int count,pos;

    cin >> W;
    if(W=="END_OF_TEXT"){
        cout << "0" <<endl;
        return 0;
    }

    cin >> T;
    count =0;

    while(T != "END_OF_TEXT"){
        for(int i=0;i<T.length();i++){
            if((T[i]>='A')&&(T[i]<='Z')){
                T[i] += 32;
            }
        }

        if(W==T){
            count++;
        }

        cin >> T;
    }



/*    pos = s.find(W);
    while(pos!=-1){
        count++;
        s=s.substr(pos+W.length());
        pos=s.find(W);
    }*/

    cout << count <<endl;

    return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>

#include <array>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>

#include <algorithm>
#include <numeric>

#include <cstdint>
#include <cctype>
#include <cmath>
#include <cassert>
#include <ctime>
#include <chrono>
#include <climits>
#include <fstream>
#include <ios>

#include <iterator>
#include <utility>
#include <complex>
#include <memory>


using namespace std;

//#define MY_DEBUG

#define DESYNC_IO


#ifdef MY_DEBUG
#define DEBUG_STDERR(x) cerr << x << endl;
#else
#define DEBUG_STDERR(x)
#endif // MY_DEBUG

void Solve() {
    long long a, b, k;
    cin >> a >> b >> k;
    int cnt{ 0 };
    while (true) {
        if (a % 2 != 0) {
            --a;
        }
        long long temp{ a / 2 };
        a -= temp;
        b += temp;
        ++cnt;
        if (cnt == k) {
            break;
        }
        if (b % 2 != 0) {
            --b;
        }
        temp = b / 2;
        b -= temp;
        a += temp;
        ++cnt;
        if (cnt == k) {
            break;
        }
    }
    cout << a << ' ' << b;
}

void Run() {
#ifdef MY_DEBUG
    chrono::high_resolution_clock::time_point start{ chrono::high_resolution_clock::now() };
#endif // MY_DEBUG

#ifdef DESYNC_IO
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif // DESYNC_IO

#ifdef MY_DEBUG
    ifstream input{ "input.txt" };
    cin.rdbuf(input.rdbuf());
#endif // MY_DEBUG

    Solve();

#ifdef MY_DEBUG
    auto dt{ std::chrono::high_resolution_clock::now() - start };
    auto dt_millisec{ std::chrono::duration_cast<std::chrono::milliseconds>(dt) };
#endif // MY_DEBUG
    DEBUG_STDERR("\ntime spent: " << dt_millisec.count() << " miilliseconds");
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
	int i, len, count = 0;
	char c[201], p[101], ccc[101];
	scanf("%s", c);
	strcpy(ccc,c);
	scanf("%s", p);
	strcat(c, ccc);
 //   len = strlen(p);
	if(strstr(c, p) == NULL) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 540
import sys
h, w = map(int, input().split())
i = 0
pos = 0
while h > i:
    s = input()
    l = s.find('#')
    r = s.rfind('#')
    if (l == pos and r >= pos):
        pos = r
        i += 1
    else:
        print('Impossible')
        sys.exit()
print('Possible')


Measured memory_bytes: 3188
n=int(input())
l=list(map(int,input().split()))
dp=[float('inf') for i in range(n+1)]
dp[0]=0
for i in range(len(dp)):
    for j in range(i+1,i+3):
        if(j<len(l)):
      	    dp[j]=min(dp[j],dp[i]+abs(l[j]-l[i]))
print(dp[n-1])

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

   typedef long long ll;
   typedef pair<ll, ll> P;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

   int dx[4]={1,0,-1,0};
   int dy[4]={0,1,0,-1};

const ll MAX_N = 1000;
ll N, H, W;
ll A[MAX_N], B[MAX_N];

int main(){
  ll ans = 0;
  cin >> N >> H >> W;
  REP(i, N){
    cin >> A[i] >> B[i];
    if (A[i] >= H && B[i] >= W) ans++;
  }
  cout << ans << endl;


}


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

const long long num = 1e6 + 10;
bool can_devid[num] = {false};
//bool can_devid[100];

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

    set<long long> s;
    set<long long> ng;

    for(long long i=0; i<N; ++i){
        long long a;
        cin >> a;

        if( s.count(a) > 0 ){
            ng.insert(a);
        }
        
        s.insert(a);
    }

    set<long long> ans;
    ans.clear();
    for(long long i: s){
        if(can_devid[i] == false && ng.count(i) == 0){
            ans.insert(i);
        }
        for(long long j=i*2; j<=num; j += i){
            can_devid[j] = true;
        }
    }


    cout << ans.size() << endl;
}


Measured memory_bytes: 22360
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    if n%2==1:
        print(0)
    elif n<10:
        print(0)
    else:
        ans=0
        for i in range(1,1000000):
            y=5**i
            num=(n//y)//2
            if num==0:
                break
            else:
                ans+=num
        print(ans)
resolve()

Measured memory_bytes: 38256
def f(s):
    if s == "#":
        return 1
    else:
        return 0

h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            cnt = 0
            if 0 <= i-1:
                cnt += f(s[i-1][j])
            if i+1 < h:
                cnt += f(s[i+1][j])
            if 0 <= j-1:
                cnt += f(s[i][j-1])
            if j+1 < w:
                cnt += f(s[i][j+1])
            
            if 0 <= i-1 and 0 <= j-1:
                cnt += f(s[i-1][j-1])
            if 0 <= i-1 and j+1 < w:
                cnt += f(s[i-1][j+1])
            if i+1 < h and 0 <= j-1:
                cnt += f(s[i+1][j-1])
            if i+1 < h and j+1 < w:
                cnt += f(s[i+1][j+1])
            
            
            s[i][j] = cnt

for i in range(h):
    for j in range(w):
        print(s[i][j], end="")
    if i != h-1:
        print("\n")


Measured memory_bytes: 3572
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)



int main() {
	int n,ran=1,cnt=-1;
	cin >> n;
	VI a(n+1);
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	//cout << "\n";
	for (int i = 0; i <= n; i++) {
		ran = a[ran];
		//cout << ran <<" ";
		if (ran == 2) {
			cnt = i + 1;
			break;
		}
	}
	//cout << "\n";
	cout << cnt << endl;
	return 0;

}




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

int main() {
  int a,b,h;
  cin >> a >>  b >> h;
  int s = (a+b)*h/2;
  cout << s << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

int a,b,ans=0;
string temp,chk;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
    
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	{
		temp = to_string(i);
		chk = temp;
		reverse(temp.begin(),temp.end());
		if(temp==chk)
			ans++;
	}
	cout<<ans;
}
	

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll ans = 0;
    rep(j, 61){
        ll zero = 0, ichi = 0;
        rep(i, n){
            if(a[i]%2==0){
                zero++;
            }else{
                ichi++;
            }
            a[i]/=2;
        }
        ans +=  (zero * ichi)%MOD * ((ll)pow(2, j)%MOD);
        ans %= MOD;
    }

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  
  long long cnt=0;
  long long A[N];
  long long temp;
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  while(1){
    sort(A,A+N);
    if(A[N-1]<N){
      cout<<cnt<<endl;
      return 0;
    }
    temp=1+(A[N-1]-N)/N;
    cnt+=temp;
    A[N-1]-=N*temp;
    for(int i=0;i<N-1;i++){
      A[i]+=temp;
    }
  }

  
  return 0;
}

  

Measured memory_bytes: 3612
def set_info(i, p, d):
    r = T[i]
    r[1], r[2] = p, d
    for c in r[0]:
        set_info(c, i, d+1)

n = int(input())
T = [None] * n
root = set(range(n))

for i in range(n):
    A = list(map(int, input().split()))
    ch = A[2:]
    T[A[0]] = [ch, None, None]
    root -= set(ch)

set_info(root.pop(), -1, 0)

for i,node in enumerate(T):
    ch, p, d = node
    print('node {}: parent = {}, depth = {}, {}, {}'.format(
            i, p, d, 'root' if not d else 'internal node' if ch else 'leaf', ch
        ))

Measured memory_bytes: 32740
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, m;
	cin >> n >> m;
	int k, in;
	bitset<11> bs[11];
	for (int i = 0; i < m; ++i)
	{
		cin >> k;
		for (int j = 0; j < k; ++j)
		{
			cin >> in;
			bs[i][in-1] = 1;
		}
	}
	int p[11];
	for (int i = 0; i < m; ++i)
	{
		cin >> p[i];
	}
	bitset<11> now, check;
	int ans = 0;
	for (int i = 0; i < (2<<(n-1)); ++i)
	{
		now = i;
		int ok = 1;
		for (int j = 0; j < m; ++j)
		{
			check = now & bs[j];
			if(check.count()%2!=p[j])
			{
				ok = 0;
			}
		}
		ans += ok;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,q=LI()
  s=S()

  l=[0]*(n+1)

  for i in range(n):
    l[i+1]=l[i]
    if s[i:i+2]=='AC':
      l[i+1]+=1

  l2=[]
  for _ in range(q):
    a,b=LI()
    l2.append(l[b-1]-l[a-1])

  for x in l2:
    print(x)

main()


Measured memory_bytes: 12804
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
N = int(input())
H = list(map(int, input().split()))

cnt = 1
hmax = H[0]
for i in range(1, N) :
  if hmax <= H[i] :
    cnt += 1
    hmax = H[i]
print (cnt)




Measured memory_bytes: 38256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
  string a,b;
  cin>>a>>b;
  cout<<b+a;
  return 0;
}
//code the AC sol !
// BS/queue/map


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input(), K = input();
    vector< int > a(N);
    cin >> a;
    
    bitset< 202020 > dp;
    range(i, 0, K) {
        if (dp[i]) continue;
        
        for (auto d : a) dp.set(i + d);
    }

    cout << (dp[K] ? "First" : "Second") << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

using namespace std;

using ll = long long;

const int N = 1e3 + 5;

int mat[3 * N][3 * N];
int sum[3 * N][3 * N];

bool solve() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int x, y;
        char c;
        scanf("%d %d %c", &x, &y, &c);
        if (c == 'W')
            y += k;
        x %= 2 * k, y %= 2 * k;
        if (x >= k && y >= k)
            x -= k, y -= k;
        else if (x >= k)
            x -= k, y += k;
        if (x < k && y < k) {
            ++mat[x + 1][y + 1];
            ++mat[x + k + 1][y + k + 1];
            ++mat[x + 2 * k + 1][y + 2 * k + 1];
            ++mat[x + 1][y + 2 * k + 1];
            ++mat[x + 2 * k + 1][y + 1];
        } else {
            ++mat[x + 1][y + 1];
            ++mat[x + 2 * k + 1][y + 1];
            ++mat[x + k + 1][y - k + 1];
            ++mat[x + k + 1][y + k + 1];
        }
    }
    for (int i = 3 * k; i > 0; --i) {
        for (int j = 3 * k; j > 0; --j)
            sum[i][j] = sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1] + mat[i][j];
    }
    for (int i = 1; i <= 2 * k + 1; ++i) {
        for (int j = 1; j <= 2 * k + 1; ++j)
            ans = max(ans, sum[i][j] + sum[i + k][j + k] - sum[i][j + k] - sum[i + k][j]);
    }
    cout << ans << endl;
    
    return 0;
}

int main() {
#ifdef LOCALHOST
    freopen("input", "r", stdin);
#endif
    while (solve());
    
    return 0;
}


Measured memory_bytes: 71040
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for _ in range(N+1)]
for i in range(2, N+1):
    a = int(input())
    G[a].append(i)

def dfs(v):
    if len(G[v]) == 0:
        return 1
    depth = []
    for u in G[v]:
        d = dfs(u) + 1
        depth.append(d)
    depth.sort()
    ret = 0
    for d in depth:
        if ret < d:
            ret = d
        else:
            ret += 1
    return ret

print(dfs(1) - 1)

Measured memory_bytes: 112560
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N;
    cin >> N;
    double cnt=0;
    rep(i, 1, N+1){
        if(i % 2 == 0) cnt++;
    }
    cout << (N-cnt)/N << endl;
    return 0;
}




Measured memory_bytes: 256
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter, defaultdict
    c = defaultdict(int)
    for k, v in Counter(A).items():
        c[k] = v
    ans = 0
    for i in range(max(A) + 1):
        if i != 0:
            cur = c[i] + c[i-1] + c[i+1]
        else:
            cur = c[i] + c[i+1]
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20572