akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long

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

  int n; cin >> n;
  vector<int> dp(n+1,1);
  for(int i = 2; i <= n; i++){
    dp[i] = dp[i-1] + dp[i-2];
  }
  cout << dp[n] << endl;

  return 0;
}



Measured memory_bytes: 3164
#include <cstdio>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
char s[maxn];
int prem[maxn];
int q[maxn];
int n;
int main() {
    scanf("%d", &n);
    scanf(" %s", s+1);
    int Q; scanf("%d", &Q);
    prem[0] = 0;
    for (int i = 1; i <= n; i++) 
        prem[i] = prem[i-1] + (s[i] == 'M');
    while (Q--) {
        int k; scanf("%d", &k);
        int cnt = 0; ll tot = 0, ans = 0;
        int hd = 0, tl = 0;
        for (int i = 1; i <= n; i++) {
            while (hd < tl && i - q[hd] >= k) {
                tot += prem[q[hd]];
                hd++;
                cnt --;
            }
            if (s[i] == 'C') {
                ans += (ll)cnt * prem[i-1] + tot;
            }
            if (s[i] == 'D') {
                q[tl++] = i;
                tot -= prem[i];
                cnt ++;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(num) scanf("%d",&num)
#define sff(num1,num2) scanf("%d %d",&num1,&num2)
#define sfff(num1,num2,num3) scanf("%d %d %d",&num1,&num2,&num3)
#define sl(num) scanf("%lld",&num)
#define sll(num1,num2) scanf("%lld %lld",&num1,&num2)
#define slll(num1,num2,num3) scanf("%lld %lld %lld",&num1,&num2,&num3)
#define rep(i,n) for(i=1;i<=n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define pb push_back
#define mpp make_pair
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
#define TIME cerr<<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<"s\n";
typedef long long int ll;
using namespace std;
int main()
{
    string a;
    cin>>a;
    int i;
    rep0(i,a.size())
    {
        if((i+1)&1)
        {
            if(a[i]=='L')
            {
                puts("No");
                return 0;
            }
        }
        else
        {
            if(a[i]=='R')
            {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=50005;
const int mod=1000007;
const double eps=1e-3;
int main()
{
        string str;
        while(cin>>str)
        {
                int len=str.size();
                printf("%c%d%c\n",str[0],len-2,str[len-1]);
        }
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

constexpr int kN = int(2E5 + 10), kInf = int(1E9 + 10);
int a[kN];

int Cut(int x, int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) ans += (a[i] - 1) / x;
	return ans;
}

int main() {
	int n, k, l, r, mid;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	l = 0, r = kInf;
	while (r - l > 1) {
		mid = (l + r) >> 1;
		if (Cut(mid, n) > k) l = mid;
		else r = mid;
	}	
	printf("%d\n", r);
}


Measured memory_bytes: 2484
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  string s;
  cin >> s;

  map<char, bool> m;
  REP(i, s.length()){
    m[s[i]] = true;
  }

  bool f = !(m['N'] ^ m['S']) && !(m['W'] ^ m['E']);

  cout << (f ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    p = LI()
    ans = 0
    change = False

    for i,x in enumerate(p):
        num = i+1
        if num == x:
            if change:
                change = False
            else:
                change = True
                ans += 1
        else:
            change = False

    print(ans)
main()            


Measured memory_bytes: 88708
n, w = gets.chomp.split.map(&:to_i)
wvs = Array.new(n) { |i| gets.chomp.split.map(&:to_i) }
dp = Array.new(w + 1, 0)

0.upto(n - 1) do |i|
  w.downto(wvs[i][0]) do |j|
    tmp = dp[j - wvs[i][0]] + wvs[i][1]
    dp[j] = tmp if tmp > dp[j]
  end
end

puts dp[-1]


Measured memory_bytes: 2556
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

int dp[202020][3];

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

  string s; cin >> s;
  int n = s.size();

  fill(dp[0], dp[202020], -INF);
  // abb
  dp[0][1] = 1; // 1
  dp[0][2] = -INF; // 2
  dp[1][1] = (s[0] == s[1]) ? -INF : 2; // 1, 1
  dp[1][2] = 1; // 2
  dp[2][1] = (s[0] != s[1] && s[1] != s[2]) ? 3 : 2; // 1, 1, 1   2, 1
  dp[2][2] = 2; // 1, 2

  for (int i = 3; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (j == 0) continue;
      if (j == 1) {
        if (s[i - 1] == s[i]) {
          dp[i][j] = dp[i - 1][2] + 1;
        } else {
          dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + 1;
        }
      } else if (j == 2) {
        if (s.substr(i - 1, 2) == s.substr(i - 3, 2)) {
          dp[i][j] = dp[i - 2][1] + 1;
        } else {
          dp[i][j] = max(dp[i - 2][1], dp[i - 2][2]) + 1;
        }
      }
    }
  }

  cout << max(dp[n - 1][1], dp[n - 1][2]) << '\n';


  return 0;
}

Measured memory_bytes: 2964
N, K = map(int, input().split())

ans = 0
lis = [0]*N
for _ in range(K):
    d = int(input())
    Ns = list(map(int, input().split()))
    for j in range(d):
        lis[Ns[j]-1] = 1

print(N-sum(lis))
    

Measured memory_bytes: 67780
N = int(input())
A = [int(i) for i in input().split()]

if 0 in A :
  print(0)
else :
  ret = 1
  for i in range(N) :
    ret *= A[i]
    if ret > 10 ** 18 :
      print(-1)
      break
  else :
    print(ret)

Measured memory_bytes: 84744
a = []
for i in range(5):
    a.append(int(input()))
y = 0
x = [i%10 for i in a]
if max(x) > 0:
    y = 10 - min(filter(lambda i:i!= 0, x))
b = [(i+9) // 10 *10 for i in a]
print(sum(b) - y)


Measured memory_bytes: 9180
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int vis[N];
vector<int>e[N],p1,p2;
deque<int>dq;
int main()
{
	int n,m,a,b,res,k;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	int r=1;
	vis[r]=1;
	dq.push_back(r);
	do
	{
		res=0;
		k=dq.front();
		vis[k]=1;
		p1.push_back(k);
		for(int i=0;i<e[k].size();i++)
		{
			if(!vis[e[k][i]])
			{
				dq.push_front(e[k][i]);
				res=1;
				break;
			}
		}
	}while(res);
	do
	{
		res=0;
		k=dq.back();
		vis[k]=1;
		p2.push_back(k);
		for(int i=0;i<e[k].size();i++)
		{
			if(!vis[e[k][i]])
			{
				dq.push_back(e[k][i]);
				res=1;
				break;
			}
		}
	}while(res);
	printf("%d\n",p1.size()+p2.size()-1);
	for(int i=p1.size()-1;i>=0;i--)
		printf("%d ",p1[i]);
	for(int i=1;i<p2.size();i++)
		printf("%d ",p2[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 7544
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
 
#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  string s; cin >> s; size_t t; t=s.length();
  if(s[0] != 'A'){
    cout << "WA";
    exit(0);
  }
  int cnt=0; int pos=100;
  for(int i=1;i<=s.length()-1;i++){
    if(isupper(s[i])){
      cnt++; pos = i;
    }
  }
  if(cnt != 1){
    cout << "WA";
    exit(0);
  }
  if(s[pos] != 'C'){
    cout << "WA";
    exit(0);
  }
  if(pos >= 2 && pos <= s.length()-2){
    cout << "AC";
  } else {
    cout << "WA";
  }
  
    
 
 return 0;
}

Measured memory_bytes: 256
s = input()[::-1]  # 反転
template = list('dream dreamer erase eraser'.split())
template = [c[::-1] for c in template]  # 反転

while s:
    for c in template:
        if s.startswith(c):
            s = s[len(c):]
            break
    else:
        break
print("YES") if s == "" else print("NO")


Measured memory_bytes: 3188
// ABC152_D
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <cstring>  // std::memset
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define repr(i, n) for (ll i=n-1; i >= 0; i++)  // n-1 ~ 0
#define rep1(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define all(vec) (vec).begin(), (vec).end()
#define sum(vec) accumulate(all(vec), 0LL)  // 0 は初期値
#define min_vec(vec) min_element(all(vec))  // iterator: * を先頭につける
#define max_vec(vec) max_element(all(vec))  // iterator: * を先頭につける
#define idx(vec, element_iter) distance((vec).begin(), element_iter)
const ll INF = 1LL<<60;  // 10^18（const int inf = 1<<29;）
const double PI = acos(-1);

ll dp[20010][2][2];

pll getLeftRightDigit(ll n) {
    // 左端（最大位），右端（最小位）の数字を取得
    string n_str = to_string(n);
    ll first = (ll)(n_str.front() - '0');
    ll second = (ll)(n_str.back() - '0');  // n%10 でも OK
    return pll(first, second);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    // input(sunippets: inpv, inpn, inps)
    ll N;
    cin >> N;
    
    // calculation
    // 数字のペアの数を前処理として計算
    map<pll, ll> mp;
    rep1(i, N) {
        pll p = getLeftRightDigit(i);
        mp[p]++;
    }
    
    // 各ペアの集計値の積を足していく：(1, 9), (9, 1)
    ll res = 0;
    for (ll i = 1; i <= 9; i++) {
        for (ll j = 1; j <= 9; j++) {
            pll a(i, j), b(j, i);
            res += mp[a] * mp[b];
        }
    }
    
    cout << res << "\n";
    
    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;
typedef pair<int,int> P;
const long long int MOD = 1000000007;
const int INF = 1000000000;

ll n, m, k;
ll kai[300000];

ll mod_pow(ll x, ll y){
    ll ret = 1;
    while(y){
        if(y&1) ret = ret*x%MOD;
        x = x*x%MOD;
        y /= 2;
    }
    return ret;
}

ll conb(ll x, ll y){
    ll ret = kai[x+y];
    ret = ret*mod_pow(kai[x],MOD-2)%MOD;
    ret = ret*mod_pow(kai[y],MOD-2)%MOD;
    return ret;
}

void init(){
    kai[0] = 1;
    for(ll i = 1; i < 300000; i++){
        kai[i] = (kai[i-1]*i)%MOD;
    }
}

ll pre(ll x, ll y){
    ll ret = 1;
    return ret;
}

int main(){
    cin >> n >> m >> k;
    init();
    ll ans = 0;
    for(ll i = 0; i <= k; i++){
        ll j = k-i;
        ll add = conb(n+2*i,m+2*j);
        ll add2 = conb(n+i,i);
        if(i > 0) add2 = (add2-conb(n+i+1,i-1)+MOD)%MOD;
        ll add3 = conb(m+j,j);
        if(j > 0) add3 = (add3-conb(m+j+1,j-1)+MOD)%MOD;
        add = add*add2%MOD;
        add = add*add3%MOD;
        ans = (ans+add)%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5388
class BIT:
    def __init__(self,N):
        self.N=N
        self.bit=[0]*(N+1)
        self.b=1<<N.bit_length()-1
    def add(self,a,w):
        x=a
        while(x<=self.N):
            self.bit[x]+=w
            x+=x&-x
    def get(self,a):
        ret,x=0,a-1
        while(x>0):
            ret+=self.bit[x]
            x-=x&-x
        return ret
    def cum(self,l,r):
        return self.get(r)-self.get(l) 
    def lowerbound(self,w):
        if w<=0:
            return 0
        x=0
        k=self.b
        while k>0:
            if x+k<=self.N and self.bit[x+k]<w:
                w-=self.bit[x+k]
                x+=k
            k//=2
        return x+1

N,Q=map(int,input().split())
bit=BIT(N)
a=list(map(int,input().split()))
for i in range(N):
    bit.add(i+1,a[i])
for _ in range(Q):
    c,A,B=map(int,input().split())
    if c==0:
        bit.add(A+1,B)
    else:
        A,B=A+1,B+1
        print(bit.cum(A,B))

Measured memory_bytes: 132352
/* Those who cannot remember the past are condemned to repeat it.*/
/* author:Ajeet */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define ll long long int
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int sz=1e7;
#define mod 1000000007
#define ull unsigned long long int
int dp[100005]={0};
vector<int>adj[100004];
bool vis[100005]={0};
void dfs(int node ){
    vis[node]=true;
    for(int i=0;i<adj[node].size();i++){
        if(!vis[adj[node][i]])
        dfs(adj[node][i]);
        dp[node]=max(dp[node],1+dp[adj[node][i]]);
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]) dfs(i);
    }
 // for(int i=1;i<=4;i++) cout<<dp[i]<<endl;
    cout<<*max_element(dp,dp+n+1)<<endl;
    return 0;

}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

int main(){
	vi a(8);
	vvi vec{
		{1,4},
		{0,2,5},
		{1,3,6},
		{2,7},
		{0,5},
		{1,4,6},
		{2,5,7},
		{3,6},
	};
	map<vi,int> m;
	iota(all(a),0);
	queue<pair<vi,pii>> q;
	q.emplace(a,mp(0,0));
	while(!q.empty()){
		vi data=q.front().fs;
		int cost=q.front().sc.fs;
		int zero=q.front().sc.sc;
		q.pop();
		if(m.find(data)!=m.end()){
			continue;
		}
		m[data]=cost;
		for(int i:vec[zero]){
			auto cp=data;
			cp[zero]=cp[i];
			cp[i]=0;
			q.emplace(cp,mp(cost+1,i));
		}
	}

	while(cin>>a[0]){
		range(i,1,8)cin>>a[i];
		cout<<m[a]<<endl;
	}
	return 0;
}



Measured memory_bytes: 5728
main = interact $ unlines . map show . plastic_board . map (map read . splitOn ',') . lines

splitOn c xs
 | null xs = []
 | head xs == c = splitOn c (tail xs)
 | otherwise = (takeWhile (/= c)) xs : splitOn c (dropWhile (/= c) xs)

plastic_board ds = [rects,diamonds]
 where
  rects = length $ filter (\[a,b,c] -> a^2+b^2 == c^2) ds
  diamonds = length $ filter (\[a,b,_] -> a == b) ds

Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  string S, ACGT("ACGT");
  cin >> S;
  int result = 0;
  int tmp = 0;
  for (auto s : S) {
    if (string::npos != ACGT.find(s)) {
      ++tmp;
    } else {
      result = max(result, tmp);
      tmp = 0;
    }
  }
  result = max(result, tmp);
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> vec(100);
    int min_ = min(A, B);
    for (int i=1; i <= min_; i++) {
        if (A % i == 0 && B % i == 0) {
            vec.push_back(i);
        }
    }

    sort(vec.begin(), vec.end(), greater<int>());
    cout << vec[K-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <stack>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int sum = a + b + c;
    if (sum >= 22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    string ans = "";
    rep(i, n) {
        if(s[i] == '0') {
            ans = ans + "0";
        }
        else if(s[i] == '1') {
            ans = ans + "1";
        }
        else if(s[i] == 'B') {
            if(ans != "") {
                ans.pop_back();
            }
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

set<int> S;

int main () {
  int N;
  cin >> N;
  int A[100010];
  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (auto i = 0; i < N; ++i) {
    auto it = S.find(A[i]);
    if (it == S.end()) {
      S.insert(A[i]);
    } else {
      S.erase(it);
    }
  }
  cout << S.size() << endl;
}


Measured memory_bytes: 5248
program aaa;
var
  i,j:longint;
  b:boolean;
  c:array[1..3,1..3]of longint;
begin
  for i:=1 to 3 do
    for j:=1 to 3 do
      read(c[i,j]);
  b:=true;
  j:=c[2,1]-c[1,1];
  for i:=2 to 3 do
    b:=b and (c[2,i]-c[1,i]=j);
  j:=c[3,1]-c[1,1];
  for i:=2 to 3 do
    b:=b and (c[3,i]-c[1,i]=j);
  j:=c[1,2]-c[1,1];
  for i:=2 to 3 do
    b:=b and (c[i,2]-c[i,1]=j);
  j:=c[1,3]-c[1,1];
  for i:=2 to 3 do
    b:=b and (c[i,3]-c[i,1]=j);
  if b then writeln('Yes')
       else writeln('No');
  readln;
  readln;
end.                                   

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


int main(){

vector<vector<int>>c(3,vector<int>(3));

for (int i = 0; i < 3; i++)
{
    for (int j = 0; j < 3; j++)
    {
        cin >> c.at(i).at(j);
    }
    
}


int m = 0;//iの初期値
int n = 100;//ループ最大
string ans = "No";

//normaldp
vector<int>a(3),b(3);
for (int i = m; i < n; i++)
{
    bool tmp = true;
    a[0] = i;
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    rep(p,2){
        rep(q,2){
            if(a[p]+b[q]!=c[p][q]){
                tmp = false;
            }
        }
    }

if(tmp){
        ans = "Yes";
        break;
    }
    
}

cout << ans << endl;
}


Measured memory_bytes: 256
import copy
n, m = map(int, input().split())
for i in range(n):
    a = list(map(int, input().split()))
    a_set = set(a[1:]) 
    if i == 0:
        base = copy.copy(a_set)
    else:
        base &= a_set
        # answer = len(base)
    # print(base)
    # for j in range(1, a[0]+1):
    #     if a[j] in base:
    #         continue
    #     else:
    #         answer -= 1
print(len(base))

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int a,b,n,t,k,k1;
  cin>>a>>b>>n;
  if(b>n)
  {
      cout<<(a*n)/b;
  }
  else
  {
       cout<<(a*(b-1))/b;
  }

}


Measured memory_bytes: 3624
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = input()[:-1]

if n[-1] == "s":
    print(n + "es")
else:
    print(n + "s")

Measured memory_bytes: 65444
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    if(a.equals("a")||a.equals("i")||a.equals("u")||a.equals("e")||a.equals("o")){
      System.out.println("vowel");
    }else{
      System.out.println("consonant");
    }
  }
  

  
}


Measured memory_bytes: 23764
N=int(input())
a=list(range(N))
b=list(range(N))
for i in range(N):
 a[i],b[i]=map(int,input().split())
c=0
for i in range(N):
 for j in range(N):
  c+=((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5
d=c/N
print(d)


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

int main(){
	int D;
	cin >> D;
	ll G;
	cin >> G;
	int p[D], c[D];
	vector<int> ans;
	for(int i=0; i<D; i++) cin >> p[i] >> c[i];
	for(int bit=0; bit<(1<<D); bit++){
		ll sum = 0, cnt = 0;
		vector<int> v;
		for(int i=0; i<D; i++){
			if(bit & (1<<i)){
				sum += 100*(i+1)*p[i] + c[i];
				cnt += p[i];
			}else{
				v.push_back(i);
			}
		}
		int max = -1;
		for(int i=0; i<v.size(); i++){
			if(max < v[i]) max = v[i];
		}
		if(max == -1){
			if(sum >= G) ans.push_back(cnt);
		}else{
			for(int i=0; i<p[max]; i++){
				if(sum + 100*(max+1)*i >= G){
					ans.push_back(cnt+i);
					break;
				}
			}
		}
	}
	ll M = 1000000000;
	for(int i=0; i<ans.size(); i++){
		if(M > ans[i]) M = ans[i];
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    long long a,b;
    scanf("%lld %lld",&a,&b);
    /*if(a%2==0)
    {
        printf("%lld",a*b/2);
    }
    else
    {
        if(b%2==0)
        {
            printf("%lld",a*b/2);
        }
        else
        {
            printf("%lld",(a*(b-1))/2+a/2+1);
        }
    }*/
    if(a==1 || b==1)
    {
        printf("1");
        return 0;
    }
    if((a*b)%2==1)
    {
        printf("%lld",((a*b)/2)+1);
    }
    else
    {
        printf("%lld",a*b/2);
    }
    return 0;
}


Measured memory_bytes: 128
var input = function()
{
  return input= require('fs').readFileSync('/dev/stdin', 'utf8').split(' ').map(Number);
};

var out = function(x)
{
  console.log(x);
  return x;
}

var surface =function(x)
{
  return Math.pow(x,2) * Math.PI;
}

var length = function(x)
{
  return 2*x*Math.PI;
}

var calc = function(x)
{
  var str = surface(x) +" " +  length(x);
  out(str);
  return str;
};

calc(input());

Measured memory_bytes: 7908
const fs = require("fs");
const line = fs.readFileSync("/dev/stdin");
const N = Number(line);
let res = 0;

for (let i = 1; i <= N; i++) {
  const n = Math.floor(N / i);
  res += (i * n * (n + 1)) / 2;
}

console.log(res);


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

def main():
    N, M = map(int, input().split())
    # [AC, WA]
    cnt = [[0, 0] for _ in range(N)]
    for _ in range(M):
        num, status = input().split()
        num = int(num) -1
        if status == "AC":
            if cnt[num][0] == 0:
                cnt[num][0] += 1
        if status == "WA":
            if cnt[num][0] == 0:
                cnt[num][1] += 1

    ac_cnt, wa_cnt = 0, 0
    for i in range(N):
        if cnt[i][0] == 1:
            ac_cnt += cnt[i][0]
            wa_cnt += cnt[i][1]

    print(ac_cnt, wa_cnt, sep=" ")

if __name__ == '__main__':
    main()


Measured memory_bytes: 13172
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int a[3];
int main() 
{string s;
 cin>>s;
 for (int i=0;i<3;i++){
 if (s[i]=='a')
 a[0]++;
 if (s[i]=='b')
 a[1]++;
 if(s[i]=='c')
 a[2]++;}
 if (a[0]==1 and a[1]==1 and a[2]==1)
 cout<<"Yes";
 else
 cout<<"No"; 
 system("pause");
 return 0;
}        


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

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

    string s, t;
    cin >> s >> t;

    vector< vector<int> > dp((int)s.size() + 1, vector<int>((int)t.size() + 1, 0));
    vector< vector< P > > prev((int)s.size() + 1, vector< P >((int)t.size() + 1, make_pair(-1, -1)));
    rep(i, s.size()){
        rep(j, t.size()){
            if(chmax(dp[i + 1][j + 1], dp[i][j + 1])){
                prev[i + 1][j + 1] = {i, j + 1};
            }
            if(chmax(dp[i + 1][j + 1], dp[i + 1][j])){
                prev[i + 1][j + 1] = {i + 1, j};
            }
            if(s[i] == t[j] && chmax(dp[i + 1][j + 1], dp[i][j] + 1)){
                prev[i + 1][j + 1] = {i, j};
            }
        }
    }

    string ans = "";
    int y = (int)s.size(), x = (int)t.size();
    while(y > 0 && x > 0){
        P tmp = prev[y][x];
        if(0 <= tmp.first && tmp.first < y && 0 <= tmp.second && tmp.second < x){
            ans.push_back(s[y - 1]);
        }
        y = tmp.first;
        x = tmp.second;
    }
    reverse(ans.begin(), ans.end());

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 105984
#include<stdio.h>
#include<string.h>

typedef struct{
	int num[6];
}saikoro;

int num_1,num_2;
saikoro s_1;

void set_s_num(int *a){
	int i;
	for(i=0;i<6;i++){
		s_1.num[i]=a[i];
	}
}

void n(saikoro *a){
	int tmp;
	tmp=a->num[4];
	a->num[4]=a->num[0];
	a->num[0]=a->num[1];
	a->num[1]=a->num[5];
	a->num[5]=tmp;
}

void s(saikoro *a){
	int tmp;
	tmp=a->num[1];
	a->num[1]=a->num[0];
	a->num[0]=a->num[4];
	a->num[4]=a->num[5];
	a->num[5]=tmp;
}

void e(saikoro *a){
	int tmp;
	tmp=a->num[2];
	a->num[2]=a->num[0];
	a->num[0]=a->num[3];
	a->num[3]=a->num[5];
	a->num[5]=tmp;
}

void w(saikoro *a){
	int tmp;
	tmp=a->num[3];
	a->num[3]=a->num[0];
	a->num[0]=a->num[2];
	a->num[2]=a->num[5];
	a->num[5]=tmp;
}

int main(){
	int i,j,k,nt,slen,num[6],f_br;
	char input[128];
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d %d %d %d %d %d",&num[0],&num[1]
		,&num[2],&num[3],&num[4],&num[5]);
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d",&nt);
	
	for(i=0;i<nt;i++){
		f_br=0;
		set_s_num(num);
		fgets(input,sizeof input,stdin);
		sscanf(input,"%d %d",&num_1,&num_2);
		
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				
				if(num_1==s_1.num[0]&&num_2==s_1.num[1]){
					printf("%d\n",s_1.num[2]);
					f_br=1;
				}else if(num_1==s_1.num[1]&&num_2==s_1.num[2]){
					printf("%d\n",s_1.num[0]);
					f_br=1;
				}
				
				if(f_br==1){
					break;
				}
				
				e(&s_1);
			}
			
			if(f_br==1){
					break;
				}
			n(&s_1);
		}
		  
	}
	
	return 0;
}

Measured memory_bytes: 2676
/*----------------*/
/* 	^_HAR HAR MAHADEV_^
   	|Om namah shivaya|
*/
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pb(temp) push_back(temp)
#define mp make_pair
#define mod 1000000007
#define br "\n"
//using namespace boost::multiprecision;
using namespace std ;
typedef unsigned long long int ulli;

ulli gcd(ulli x,ulli y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
ulli factorial(ulli n)
{
    if (n == 0)
    return 1;
    return n * factorial(n - 1);
}
ll findS(ll s)
{
	return (sqrtl(8*s + 1) - 1)/2;
}
ll prime(ll a){
    if(a==1)return 0;
    if(a==2 || a==3)return true;
    if(a%2==0 ||a%3==0)return 0;
    for(ll i=5;i<=sqrt(a);i+=6)
        if(a%i==0 || a%(i+2)==0)
            return 0;

    return 1;
}
ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % mod;
    p = (p * p) % mod;

    return (y%2 == 0)? p : (x * p) % mod;
}
ll nCr(ll n,ll k)
{
    ll C[k+1];
    //memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%(ll)(1e9 + 7);
    }
    return C[k];
}
ll LOGN(ll n , ll r){
	return (n > r-1) ? (1 + LOGN(n / r , r)) : 0 ;
}
void dfs(vector<ll> v[], bool visited[], ll current_node){
	visited[current_node]=true;
	for(ll nxt_node : v[current_node]){
		if(visited[nxt_node]==false){
			dfs(v , visited, nxt_node);
		}
	}
	return;
}

void bfs(vector<ll> v[], bool visited[], ll root){

    int current_node;
    queue<int> q;

    q.push(root);

    while(!q.empty()){

        current_node=q.front();

        visited[current_node]=true;

        for(int x:v[current_node])
            if(!visited[x])
                q.push(x);
    }
}
int main(){
	fast;
	int a , b ;
	cin >> a >> b ;
	f(i,0,max(a,b)){
		cout << min(a,b) ;
	}
}


Measured memory_bytes: 256
/*==============================================*\
ID:          shahidul_brur
 
Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh
 
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int logn = 20;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll n; cin>>n;
    cout << n*(n-1)/2;
    return 0;
}


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

int main() 
{
    int A, B;
    cin >> A >> B;
    int max_v;

    max_v = A + B;
    if (max_v < A-B) max_v = A-B;
    if (max_v < A*B) max_v = A*B;
    cout << max_v << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  string M;
  if(N == "Sunny"){M = "Cloudy";}
  if(N == "Cloudy"){M = "Rainy";}
  if(N == "Rainy"){M = "Sunny";}
  cout << M << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n;cin>>n;
  vector<ll> A(n);
  rep(i,n){
    cin>>A[i];
  }
  sort(all(A));
  ll ans = 0;
  rep(i,n){
    ll sa = A[i] - A[0];
    ans += sa / (n+1);
    A[i] -= (sa / (n+1)) * (n+1);
  }
  rep(i,n){
    A[i] += ans;
  }
  sort(all(A));
  ll sa = A[0] - (n-1);
  if(sa >= 0){
      ans += sa * n;
  rep(i,n){
    A[i] -= sa;
  }
  }

  bool update = true;
  while(update){
    update = false;
    REP(i,n){
      if(A[i] >= n){
        A[i] -= n+1;
        rep(j,n){
          A[j] += 1;
        }
        ans++;
        update = true;
      }
    }
    //cout<<A[n-1]<<endl;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = []
n.times do
    a << gets.chomp.to_i
end
b = a.sort.reverse  # 降順
max = b[0]

(0..n-1).each do |i|
    if a[i] != max
        puts max
    else
        puts b[1]
    end
end

Measured memory_bytes: 9820
#include <bits/stdc++.h>
using namespace std;
#define Endl endl
typedef long long ll;
const int MAXN = (int)2e5 + 5;
ll n;
string s;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n)
	{
		map<string, ll> m;
		for (int i = 1; i <= n&&cin >> s; ++i)
			sort(s.begin(), s.end()), m[s]++;
		ll ans = 0;
		for (auto i : m)
			if (i.second > 1)
				ans += i.second*(i.second - 1) / 2;
		cout << ans << endl;
	}
}
/*
3
acornistnt
peanutbomb
constraint

2
oneplustwo
ninemodsix

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
*/

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int sum = 0;
	for (int v : a) { sum += v; }
	int ans = max(-1, N - sum);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int h,w;
    cin >> h >>w;
    int i;
    string s;
    for(i=0;i<h;i++){
      cin >> s;
      cout << s << endl << s << endl;
    }
    return 0;
}


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

int main(){
  long N, M;
  cin >> N >> M;
  
  long max_L = 0;
  long min_R = N;
  
  for(int i = 0; i < M; i++){
    long tmpl, tmpr;
    cin >> tmpl >> tmpr;
    if(max_L < tmpl){
      max_L = tmpl;
    }
    if(min_R > tmpr){
      min_R = tmpr;
    }
  }
  long ans;
  if(max_L > min_R){
    ans = 0;
  } else { 
    ans = min_R - max_L + 1;
  }
  cout << ans << endl;
 
}

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

int main() {
    int w, h;
    char c;
    cin >> w >> h >> c;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == 0 || i == h - 1) {
                if (j == 0 || j == w - 1) {
                    cout << '+';
                }
                else cout << '-';
            }
            else {
                if (j == 0 || j == w - 1) cout << '|';
                else if (i == h / 2 && j == w / 2) cout << c;
                else cout << '.';
            }
        }
        cout << endl;
    }
    return 0;
}


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

const int MAXN = 20001;
const int MAXM = 16;
const int MAXX = 256;
const int INF = 1<<28;

int N, M;
int C[MAXM], x[MAXN];
int dp[2][MAXX];

int main() {
  while(cin >> N >> M && (N|M)) {
    for(int i = 0; i < M; ++i) cin >> C[i];
    for(int i = 0; i < N; ++i) cin >> x[i];
    fill(dp[0], dp[2], INF);
    dp[0][128] = 0;
    for(int i = 0; i < N; ++i) {
      const int now = i & 1, next = 1 - now;
      for(int j = 0; j < MAXX; ++j) dp[next][j] = INF;
      for(int j = 0; j < MAXX; ++j) {
        for(int k = 0; k < M; ++k) {
          int nj = max(0, min(MAXX - 1, j + C[k]));
          dp[next][nj] = min(dp[next][nj],
                             dp[now][j] + (x[i] - nj) * (x[i] - nj));
        }
      }
    }
    cout << *min_element(dp[N&1], dp[N&1] + MAXX) << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
def main
  islands_num, m = gets.split.map(&:to_i)

  pairs = []
  m.times do |i|
    pairs << gets.split.map(&:to_i)
  end

  # 右側の島番号で昇順ソートする
  pairs.sort_by! { |(_, i1)| i1 }

  split_cnt = 0
  last_split = 0
  pairs.each do |(i0, i1)|
    if last_split <= i0
      split_cnt += 1
      last_split = i1
    end
  end

  puts split_cnt
end

if __FILE__ == $0
  main
end

Measured memory_bytes: 12664
s = list(input())
n = len(s)

def dfs(i , f , s_sum):
    if i == n-1:
        if s_sum == 7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1 , f + "+" + s[i+1] , s_sum + int(s[i+1]))
        dfs(i+1 , f + "-" + s[i+1] , s_sum - int(s[i+1]))

dfs(0 , s[0] , int(s[0]))

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

int main()
{
       int n,m,s1=0,s2=0;
        cin>>n>>m;
        if(n>=2){
            s1=(n*(n-1))/2;
        }
        if(m>=2){
            s2=(m*(m-1))/2;
        }
        cout<<s1+s2;

}





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;
typedef pair<int,int> P;

int main()
{
	int N;
	string S;
	cin >> N >> S;
	rep(i,S.size())
	{
		//cout << int(S[i] - 'A') << endl;
		//cout << int(S[i] - 'A') + N << endl;
		if (S[i] - 'A' +  N >= 26)
		{
			cout << char(S[i] - (26 - N));
		}
		else
		{
			cout << char(S[i] + N);
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll f[ohara], fr[ohara];

ll mod_pow(ll xx, ll nn, ll mod) {
  ll ret = 1;
  while (nn > 0) {
    if (nn & 1) ret = ret * xx % mod;
    xx = xx * xx % mod;
    nn >>= 1;
  }
  return ret;
}

ll ncr(ll nn, ll r) {
  if (nn < r) return 0;
  return f[nn] * fr[r] % MOD * fr[nn - r] % MOD;
}

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

  cin >> n >> k;
  f[0] = 1;
  rrep(i, 1, n + 3) { f[i] = f[i - 1] * i % MOD; }
  fr[n + 2] = mod_pow(f[n + 2], MOD - 2, MOD);
  rrrep(i, n + 1, 0) { fr[i] = fr[i + 1] * (i + 1) % MOD; }
  ans = 1;
  rrep(i, 1, min(n, k + 1)) {
    ans += ncr(n, i) * ncr(n - 1, i);
    ans %= MOD;
  }
  Cout(ans);
  return 0;
}


Measured memory_bytes: 5888