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

int main(){
  string S ; 
  cin >> S ; 
  int N = S.size() ; 
  int cnt = 0 ; 
  int total = 0 ; 
  
  if(S.at(0) != 'A'){
    cout << "WA" << endl ; 
    return 0 ; 
  }
  
  for(int i = 2 ; i < N-1 ; i++){
    if(S.at(i) == 'C'){
      cnt++ ; 
    }
   
  }
  
  
  for(int i = 0 ; i< N ; i++){
     if(isupper(S.at(i))){
      total++ ; 
    }
  }
  
  if(cnt != 1){
    cout << "WA" << endl ; 
    return 0 ; 
  }  
  
  if(total > 2){
    cout << "WA" << endl ; 
    return 0 ; 
  } 
  
  
  cout << "AC" << endl ; 

  
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
    if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; }
    return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
}
constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
    return (a * mpow(b, mod - 2, mod)) % mod;
}

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

    int64_t ans = 0;
    for (int a = 1; a < n; ++a) {
        ans += n / a - (n % a == 0);
    }

    cout << ans << endl;
}



Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#define MN 200000
#define N 262144
#define mod 1000000007
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,a[MN+5],num[MN+5],b[MN+5],T1[N*2+5],T2[N*2+5],T3[N*2+5],T4[N*2+5],ans,la[MN+5],ne[MN+5];
int suf0[MN+5],pre1[MN+5],inv[MN+5],pinv1[MN+5],pre0[MN+5],sinv1[MN+5],suf1[MN+5],S[MN+5];
int Query(int*T,int l,int r)
{
    int res=0;if(l>r) return 0;
    for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1)
    {
        if(~l&1) res=(res+T[l+1])%mod;
        if( r&1) res=(res+T[r-1])%mod;
    }
    return res;
}
void Renew(int*T,int x,int v){for((T[x+=N]+=v)%=mod;x>>=1;)T[x]=(T[x<<1]+T[x<<1|1])%mod;}
int main()
{
    n=read();suf0[n+1]=pre1[0]=pinv1[0]=inv[0]=inv[1]=pre0[0]=sinv1[n+1]=suf1[n+1]=1;ne[n+1]=n+1;
    for(int i=2;i<=n;++i) inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<=n;++i) a[i]=read(),++num[a[i]];
    for(int i=n,j=0;i;b[i--]=j--)
    {
        j+=num[i];
        if(j<1) return 0*puts("0");
    }
    for(int i=1;i<=n;++i)
        pre1[i]=1LL*pre1[i-1]*max(1,b[i]-1)%mod,
        pinv1[i]=1LL*pinv1[i-1]*inv[b[i]-1]%mod,
        pre0[i]=1LL*pre0[i-1]*b[i]%mod,
		la[i]=b[i]==1?i:la[i-1];
    for(int i=n;i;--i)
        suf0[i]=1LL*suf0[i+1]*b[i]%mod,
        suf1[i]=1LL*suf1[i+1]*max(1,b[i]-1)%mod,
        sinv1[i]=1LL*sinv1[i+1]*inv[b[i]-1]%mod,
		ne[i]=b[i]==1?i:ne[i+1];
    for(int i=1;i<=n;++i) S[i]=(S[i-1]+1LL*suf1[i+1]*pre0[i-1])%mod;
   // Build(1,1,n);
    for(int i=n;i;--i)
    {
        int x=1LL*Query(T1,a[i],ne[a[i]+1]-1)*pinv1[a[i]]%mod*pre0[a[i]]%mod*(mod+1)/2%mod;
        ans=(ans+x)%mod;
        if(a[i]>1)
        {
            int y=1LL*Query(T2,la[a[i]],a[i]-1)*sinv1[a[i]+1]%mod*suf0[a[i]+1]%mod*(mod+1)/2%mod;
            ans=(ans+y)%mod;
            int z=(1LL*(S[a[i]]-S[la[a[i]]-1]+mod)%mod*Query(T3,1,la[a[i]]-1)
				  +1LL*Query(T3,la[a[i]],a[i]-1)*S[a[i]]+Query(T4,la[a[i]],a[i]-1))%mod;
            ans=(ans+1LL*sinv1[a[i]+1]*z%mod*suf0[a[i]+1])%mod;
        }
        Renew(T1,a[i],1LL*pre1[a[i]]*suf0[a[i]+1]%mod);
        Renew(T2,a[i],1LL*pre0[a[i]]*suf1[a[i]+1]%mod);
        Renew(T3,a[i],1);
        Renew(T4,a[i],mod-S[a[i]]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 18560
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;


int main() {

    int n;
    cin>>n;

    int a[30];
    int b[30];
    int c[30];
    set<int>s;
    int ans=0;
    for(int i=1;i<=n;i++){cin>>a[i];
    }
    for(int i=1;i<=n;i++){cin>>b[i];ans+=b[i];}
    for(int i=1;i<=n-1;i++)cin>>c[i];

    for(int i=1;i<=n-1;i++){
        if(a[i]==(a[i+1]-1)){
            ans+=c[a[i]];
        }


        }

    cout<<ans;

	return 0;
}


/*
ll  modularExponentiation(ll x,ll n,ll M)
{

    ll result=1;

    while(n>0)
    {

	if(n%2==1)

 result=(result*x)%M;

  x=(x*x)%M;

  n=n/2;

}

  return result;
}



*/




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

struct Process {
	string name;
	int time;
};

const int MAX = 100000;
Process Queue[MAX+1];
int head, tail;

void initialize() {
	head = 0;
	tail = 0;
}

bool isEmpty() {
	return head == tail;
}

bool isFull() {
	return (tail - head == MAX || tail - head == -1);
}

void enqueue(Process p) {
	if (isFull()) return;
	Queue[tail] = p;
	tail++;
	if (tail > MAX) tail = 0;
	return;
}

Process dequeue() {
	Process ret = Queue[head];
	head++;
	if (head > MAX) head = 0;
	return ret;
}

int main() {
	int n, q;
	cin >> n >> q;
	initialize();
	for (int i = 0; i < n; i++) {
		Process p;
		cin >> p.name >> p.time;
		enqueue(p);
	}

	int cur_time = 0;
	while(!isEmpty()) {
		Process p = dequeue();
		if (q >= p.time) {
			cur_time += p.time;
			cout << p.name << ' ' << cur_time << endl;
		}
		else {
			cur_time += q;
			p.time -= q;
			enqueue(p);
		}
	}
}



Measured memory_bytes: 6952
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

using namespace std;

int fac(int n) {
    if (n > 0) {
        return n * fac(n - 1);
    } else {
        return 1;
    }
}

int main() {
 
   int N;

   cin >> N;
   int *P = new int[N]();
   int *Q = new int[N]();

   int a=0;
   int b=0;
   for(int i=0;i<N;i++){
      cin >> P[i];
   }
   for(int i=0;i<N;i++){
      cin >> Q[i];
   }
  // cout << N << endl;
   int cnt=0;
   for(int i=0;i<N;i++){
      cnt=0;
      for(int j=i;j<N;j++){
         if(P[j]<P[i]){
            //cout << j<< " " << P[i] << endl;
            cnt+=1;
         }
      }
      //cout << cnt << " " << fac(N-i-1) << endl;
      a+=cnt*fac(N-i-1);
   }
   a++;
   //cout << a << endl;
   cnt=0;
   for(int i=0;i<N;i++){
      cnt=0;
      for(int j=i;j<N;j++){
         if(Q[j]<Q[i]){
            cnt+=1;
         }
      }
      //cout << cnt << " " << fac(N-i-1) << endl;
      b+=cnt*fac(N-i-1);
   }
   b++;
   //cout << b << endl;

   cout << (a>b?a-b:b-a) << endl;
}

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

int main(void){
    int r = 0, w, cnt = 0;
    cin >> w;
    string s;
    cin >> s;
    w -= 1;
    while(r<w){
        while(r<w && s.at(r)=='R') r++;
        while(w>r && s.at(w)=='W') w--;
        if(w<=r) break;
        cnt++;
        r++;
        w--;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3732
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

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

const int max_N = 1e5 + 10;
int inp[max_N];

int main()
{
	fast_cin();
	int N, x;
	cin >> N >> x;
	for (int i = 1; i <= N; ++i) {
		cin >> inp[i];
	}
	ll ans = 0;
	for (int i = 1; i < N; ++i) {
		while(inp[i] + inp[i + 1] > x) {
			int curr = inp[i] + inp[i + 1];
			if (inp[i + 1] > 0) {
				int diff = min(curr - x, inp[i + 1]);
				inp[i + 1] -= diff;
				ans += diff;
			} else {
				int diff = min(curr - x, inp[i]);
				inp[i] -= diff;
				ans += diff;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdint>

int main(void) {
    int N;
    uint64_t a, comp;
    uint64_t sum = 0;

    std::cin >> N;


    for(int i = 0; i < N; i++) {
        std::cin >> a;
        
        comp = 1;
        while(comp <= 1000000000) {
            if(comp & a)
                break;
            sum++;
            comp *= 2;
        }
        
    }

    std::cout << sum << std::endl;
    return 0;
}



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

vector<int> pre, in, post;
int pos=0;

void reconstruct(int l, int r) {
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	reconstruct(l, m);
	reconstruct(m + 1, r);
	post.push_back(root);
	return;
}

void solve() {
	pos = 0;
	reconstruct(0, pre.size());
	for (int i = 0; i < pre.size(); i++){
		if (i) cout << ' ';
		cout << post[i];
	}
	cout << endl;
	return;
}

int main() {
	int n = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		pre.push_back(tmp);
	}
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		in.push_back(tmp);
	}

	solve();
	return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long m = sc.NextLong();

        long answer = 0;

        answer = Math.Min(n, m / 2);
        if (m - answer * 2 > 0)
        {
            answer += (m - answer * 2) / 4;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;
int n,m;
int a[N];
int main()
{
	cin>>n>>m;
	int s = 0;
	rep(i , 1 , n + 1)
		cin>>a[i], s += a[i];
	int mx = (s - 1)/(4*m) + 1;
	int cc = 0;
	rep(i , 1 , n + 1){
		if(a[i] >= mx)cc++;
	}
	if(cc>=m)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, N;
  cin >> N;
 
  a = N/1000;
  b = (N%1000)/100;
  c = ((N%100))/10;
  d = N%10;
 
if (a==b && b==c){
	  cout << "Yes";
	}else if(b==c && c==d){
	  cout << "Yes";
	}else{
	  cout << "No";
	}
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int s = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        set.add(s);
        int i = 1;
        while (true) {
            i++;
            if (s % 2 == 0) {
                s = s / 2;
            } else {
                s = 3 * s + 1;
            }
            if (set.contains(s)) {
                System.out.println(i);
                return;
            } else {
                set.add(s);
            }
        }
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define N 110000
#define ll long long
ll n,L,T;
ll a[N],b[N],p[N<<1],ans[N];
int main()
{
	scanf("%lld%lld%lld",&n,&L,&T);
	for(ll i=1;i<=n;i++)
		scanf("%lld%lld",&a[i],&b[i]);
	for(ll i=1;i<=n;i++)
	{
		if(b[i]==1)p[i]=(a[i]+T)%L;
		else p[i]=((a[i]-T)%L+L)%L;
	}
	ll tp=p[1];
	sort(p+1,p+1+n);
	for(ll i=1;i<=n;i++)p[i+n]=p[i];
	ll sum=0;
	for(ll i=2;i<=n;i++)
		if(b[i]!=b[1])
		{
			ll t;
			if(b[1]==1)t=a[i]-a[1];
			else t=L-(a[i]-a[1]);
			t=T*2-t-1;
			if(t<0)continue;
			sum+=t/L+1;
		}
	ll tar,p1;
	if(b[1]==2)tar=(1-sum%n+n)%n;
	else tar=(1+sum%n)%n;
	if(tar==0)tar=n;
	if(b[1]==1)
		p1=upper_bound(p+1,p+1+n,tp-1)-p;
	else 
		p1=upper_bound(p+1,p+1+n,tp)-p-1;
	for(ll i=1;i<=n;i++)
	{
		ans[tar]=p[p1];
		p1++;tar++;
		if(tar>n)tar=1;
	}
	for(ll i=1;i<=n;i++)
		printf("%lld\n",ans[i]);
	return 0;
}


Measured memory_bytes: 5376
#include <iostream>
using namespace std;
#define ll long long int 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
	

	ll n;
	cin>>n;
	
	ll ans=0;
	for(int i=2;i<=10000010;i++)
	{
		if(n%i==0)
		{
			
			ll num=0;
			while(n%i==0)
			{
				n/=i;
				num++;
			}	

			for(int j=1;j< 10000;j++)
			{
				if(num<j)
					break;
				num-=j;
				ans++;
			}
		}
	}
	if(n!=1)
		ans++;
	cout<<ans;

	
	 

	return 0;
	
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

void fnInput(vector<int>& rvnNum)
{
  int nSize;
  cin >> nSize;
  rvnNum.resize(nSize);

  for (int& rnElm : rvnNum)
    cin >> rnElm;
}

llong fnSignChgTimes(const vector<int>& cnrvnNum)
{ 
  vector<llong> vnTimes(2);

  for (int nParity = 0; nParity < vnTimes.size(); nParity++)
  {
    llong nTimes = 0;
    llong nSum   = 0;
    for (int n = 0; n < cnrvnNum.size(); n++)
    {
      nSum += cnrvnNum[n];
      if (n % 2 == nParity)
        if (nSum > 0);
        else
        {
          nTimes += 1 - nSum;
          nSum = 1;
        }
      else
        if (nSum >= 0)
        {
          nTimes += 1 + nSum;
          nSum = -1;
        }
        else;
    }
    vnTimes[nParity] = nTimes;
  }
  auto itElm = min_element(begin(vnTimes), end(vnTimes));
  return *itElm;
}

int main()
{
  vector<int> vnNum;

  fnInput(vnNum);
  cout << fnSignChgTimes(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 640
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

//ll modexp(ll x, ll y, ll p)
//{
//	ll res = 1;
//	x = x % p;
//	while (y > 0)
//	{
//		if (y & 1)
//			res = (res * x) % p;
//		y = y >> 1;
//		x = (x * x) % p;
//	}
//	return res;
//}

//ll mulmod(ll a, ll b,ll m)
//{
//	return ((a % m) * (b % m)) % m;
// }

// ll sub_mod(ll a, ll b, ll m){
//    if (a >= b)
//        return a - b;
//    else
//        return m - b + a;
// }

// ll add_mod(ll a, ll b){
//    if (0 == b)
//        return a;

//    b = mod - b;
//    if (a >= b)
//        return a - b;
//    else
//        return mod - b + a;
// }

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

// ll modInv(ll a)
// {
//     ll g = gcd(a, mod);
//     if (g != 1)
//         return -1;
//     else
//         return modexp(a, mod-2, mod);
// }

int main()
{
	fastio;
    ll r=0;
    cin>>r;
    cout<<r*r;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int H,W,N;
int t[500*500];
int u[500*500][50];
int sp[500*500];

bool check(ll tm){
  set<int> st;
  for(int i=0;i<N;i++){
    int p=sp[i];
    for(int j=0;j<50;j++)
      if(tm>>j&1)
        p=u[p][j];
    if(st.count(p)>0)return true;
    st.insert(p);
  }
  return false;
}

int main(){
  scanf("%d %d %d",&H,&W,&N);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int y,x;
      scanf("%d %d",&y,&x);
      t[i*W+j]=y*W+x;
    }
  }

  for(int i=0;i<N;i++){
    int y,x;
    scanf("%d %d",&y,&x);
    sp[i]=y*W+x;
  }
    
  for(int i=0;i<H*W;i++){
    u[i][0]=t[i];    
  }
  
  for(int k=1;k<50;k++)
    for(int i=0;i<H*W;i++)
      u[i][k]=u[u[i][k-1]][k-1];

  ll left=0,right=(1LL<<45),mid;

  if(check(right)==false){
    printf("-1\n");
    return 0;
  }
  
  while(left<right){
    mid=(left+right)/2;
    if(check(mid))right=mid;
    else left=mid+1;
  }

  printf("%d\n",left);
  return 0;
}

Measured memory_bytes: 65636
#include<iostream>
using namespace std;
void swap (int& a, int& b) {
  int t = a;
  a = b;
  b = t;
}
int euc (int a, int b) {
  if (b < a) swap(a, b);
  while (a) {
    b = b % a;
    swap(a, b);
  }
  return b;
}
int main () {
  int A, B, K;
  cin >> A >> B >> K;
  int t = euc(A, B);
  int j = t;
  for (int i = 0; i < K;) {
    if (!(t % j)) i ++;
    j --;
  }
  cout << j + 1 << endl;
}
  



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,N=520;
int H,W,h,w,dat,a[N][N];
int main(){
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(H%h==0&&W%w==0)puts("No"),exit(0);
	dat=(inf-1)/(h*w-1);puts("Yes");
	for(int i=1;i<=H;i++,puts(""))
		for(int j=1;j<=W;j++)
			printf("%d ",i%h||j%w?dat:-inf);
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n, d;
  cin >> n >> d;
  int ans = 0;
  d *= d;
  rep(i, n){
    ll x, y;
    cin >> x >> y;
    ll xy = x*x + y*y;
    if(xy <= d) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair

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

int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    ll a[50];
    ll n;

    cin >> n;
    for (int i=0;i<n;++i)
    {
        cin >> a[i];
    }
    ll ans = 0;
    for (;;)
    {
        bool flag = false;
        for (int i=0;i<n;++i)
        {
            if (a[i] >= n) flag = true;
        }
        if (!flag) break;
        for (int i=0;i<n;++i)
        {
            ans += a[i] / n;
        }
        ll buf[50];
        memset(buf, 0, sizeof(buf));
        for (int i=0;i<n;i++)
        {
            buf[i] = a[i] % n;
            for (int j=0;j<n;++j)
            {
                if (i == j) continue;
                buf[i] += a[j] / n;
            }
        }

        for (int i=0;i<n;++i) a[i] = buf[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int x, y, z;
	int dp[N][3];
	cin >> dp[0][0] >> dp[0][1] >> dp[0][2];
	rep1(i, N) {
		cin >> x >> y >> z;
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + x;
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + y;
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + z;
	}
	cout << max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]) << '\n';
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  int mn = 1000000000;
  int mx = 1;

  int a;
  rep(i, N)
  {
    cin >> a;
    if (mn > a)
      mn = a;
    if (mx < a)
      mx = a;
  }

  cout << mx - mn << endl;

  return 0;
}


Measured memory_bytes: 256
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect

# from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
n += 1

sum_mat = [0]
for i in range(1, 2*(10**5)+3):
    sum_mat.append(sum_mat[i-1]+i)


ans = 0
for i in range(k, n + 1):
    top = sum_mat[i]
    bottom = sum_mat[i-1] - 1
    ans += (i * n - top - bottom) % MOD
    ans %= MOD

print(ans)


Measured memory_bytes: 20968
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
        public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int A = Integer.parseInt(arr[1]);
        int B = Integer.parseInt(arr[2]);
        ans = Math.min(N * A, B);

        out.println(ans);
        out.close();
    }
}


Measured memory_bytes: 21204
#pragma GCC optimize "O3"

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

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

long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  long long t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }

  sort(t, t + n);
  long long tmp = t[0];

  for (int i = 0; i < n; i++) {
    tmp = lcm(tmp, t[i]);
  }
  cout << tmp << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),a.end()
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a*b % 2 == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;
}


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

using namespace std;

const int N = 3005;
const int mod = 1e9 + 7;

int n, res;
string s;
int sum[N], dp[N][N];

int add(int x, int y) {
	x += y;
	if (x > mod) {
		x -= mod;
	}
	return x;
}

int sub(int x, int y) {
	x -= y;
	if (x < 0) {
		x += mod;
	}
	return x;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> s;
	s = '#' + s;
	dp[0][1] = 1;
	for (int i = 1; i < n; i++) {
		memset(sum, 0, sizeof(sum));
		for (int j = 1; j <= n; j++) {
			sum[j] = add(sum[j - 1], dp[i - 1][j]);
		}
		for (int j = 1; j <= i + 1; j++) {
			if (s[i] == '>') {
				dp[i][j] = sub(sum[n], sum[j - 1]);
			} else {
				dp[i][j] = sum[j - 1];
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		res = add(res, dp[n - 1][i]);
	}
	cout << res << '\n';
	return 0;
}

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

int main() {
  int n,a=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    int b;
    cin>>b;
    if(i!=b) a++;
  }
  if(a<3) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

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

  return gcd(b, a % b);
}

long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
} 

int main() {
  long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  long long int ans = 0;
  long long int x = lcm(c, d);
  a--;

  ans = (b - ((b / c) + (b / d) - (b / x))) - (a - ((a / c) + (a / d) - (a / x)));
  cout << ans << endl;
}

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

int main(void){
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            int num = n - r*i - g*j;
            if(num >= 0 && num % b == 0){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int N;
    string s;
    cin >> N >> s;

    s.insert(0, "_");

    vector<int> left(N+2), right(N+2);
    for(int i=1; i<=N; i++) {
        left[i] = left[i-1];
        if(s[i] == 'W') left[i]++;
    }
    for(int i=N; i; i--) {
        right[i] = right[i+1];
        if(s[i] == 'R') right[i]++;
    }

    int ans = numeric_limits<int>::max();
    for(int i=0; i<=N; i++) {
        ans = min(ans, max(left[i], right[i+1]));
    }

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


Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
int dp[1000005][2];
int main() {
	string s;
	cin>>s;
	s='0'+s;
	dp[0][1]=1;
	int sz=s.size();
	for(int i=1; i<sz; i++){
		int num=int(s[i]-'0');
		dp[i][0]=min(dp[i-1][0]+num, dp[i-1][1]+10-num);
		dp[i][1]=min(dp[i-1][0]+num+1, dp[i-1][1]+(10-num-1));
	}
	cout<<dp[sz-1][0];
	return 0;
}

Measured memory_bytes: 12152
#include <iostream>
using namespace std;
int main()
{
    long long a;
    cin>>a;
    long long i;
    long long s=0;
    for(i=1;i<=a;i++)
    {
        if(i%3!=0&&i%5!=0)
            s+=i;
    }
    cout<<s<<endl;
}


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


int N;
int W[100];


int main() {
    int sum = 0;
    cin >> N;
    for ( int i = 0; i < N; i++ ) cin >> W[i];
    for ( int i = 0; i < N; i++ ) sum += W[i];
    int s1 = 0;
    int s2 = sum;
    int ans = abs(s1 - s2);
    for ( int t = 0; t < N-1; t++ ) {
        s1 += W[t];
        s2 -= W[t];
        if ( ans > abs(s1 - s2) ) ans = abs( s1 - s2 );
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	int a;
	int b;
	cin >> a >> b;
	if (a + b >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << a + b << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, m, a[1005], b[1005], c[1005], dis[105][105], ans;

int main(){
    scanf("%d%d", &n, &m);
    rep(i,n) rep(j,n) dis[i][j] = i == j ? 0 : 1e8;
    rep(i,m){
        scanf("%d%d%d", a+i, b+i, c+i);a[i]--;b[i]--;
        dis[a[i]][b[i]] = dis[b[i]][a[i]] = c[i];
    }
    rep(i,n) rep(j,n) rep(k,n) dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
    rep(i,m) if(dis[a[i]][b[i]] < c[i]) ans++;
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
int N, X  , c=1;
cin >> N>> X;
int L[N];
int D[N];
D[1]=0;
for(int i =1; i<=N;i++)
    cin >> L[i];
    for(int i =2; i<=N+1;i++)
      {
          D[i]=D[i-1]+L[i-1];
          if(D[i]<=X)
            c++;
      }

cout << c;


    return 0;
}

Measured memory_bytes: 256
n,k=list(map(int,input().split()))
if k>(n-1)*(n-2)/2:
    print("-1")
else:
    s=int((n-1)*(n-2)/2-k)
    a=[]
    for i in range(n):
        for j in range(i+1,n):
            a.append([i+1,j+1])
    print(n-1+s)
    for i in range(n-1+s):
        print("%d %d" %(a[i][0],a[i][1]))

Measured memory_bytes: 3844
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)

bool isACGT(char c) {
  string ACGT = "ACGT";
  rep(i, ACGT.size()) {
    if(c == ACGT[i]) return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  rep(i, s.size()) {
    if(isACGT(s[i])) {
      cnt++;
      ans = max(ans, cnt);
    } else {
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll inf = 5e15;

int main() {
    ll H, W;
    cin >> H >> W;
    priority_queue<ll, V<ll>, greater<ll>> pq_h, pq_w;
    for(ll i = 0; i < H; i++) {
        ll a;
        cin >> a;
        pq_w.push(a);
    }
    for(ll i = 0; i < W; i++) {
        ll a;
        cin >> a;
        pq_h.push(a);
    }

    ll rest = (H + 1) * (W + 1) - 1;
    ll cnt_h = 0, cnt_w = 0;
    pq_h.push(inf);
    pq_w.push(inf);

    ll ans = 0;
    while(rest) {
        ll a = pq_h.top();
        ll b = pq_w.top();
        if(a < b) {
            pq_h.pop();
            ll cnt = min(H + 1 - cnt_w, rest);
            cnt_h++;
            ans += cnt * a;
            rest -= cnt;
        } else {
            pq_w.pop();
            ll cnt = min(W + 1 - cnt_h, rest);
            cnt_w++;
            ans += cnt * b;
            rest -= cnt;
        }
    }

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


Measured memory_bytes: 2676
#include <cstdio>
#include <vector>
#include <algorithm>

typedef long long i64;

const int N = 90, MOD = 1000000007;

i64 n, m, fib[N];

std::vector<std::pair<i64, i64>> pool[N];

int main() {
  fib[0] = fib[1] = 1;
  for (int i = 2; i < N; ++i) fib[i] = fib[i - 1] + fib[i - 2];
  pool[1].emplace_back(1, 2);
  pool[1].emplace_back(1, 3);
  for (int i = 2; i + 2 < N; ++i)
    for (auto it : pool[i - 1])
      for (i64 y = it.first + it.second; y <= fib[i + 2]; y += it.second)
        pool[i].emplace_back(it.second, y);
  int q;
  for (scanf("%d", &q); q--;) {
    scanf("%lld%lld", &n, &m);
    if (n > m) std::swap(n, m);
    if (n == 1) {
      printf("1 %d\n", m % MOD);
    } else if (n == 2 && m == 2) {
      puts("1 4");
    } else {
      int k = 1;
      while (fib[k + 1] <= n && fib[k + 2] <= m) ++k;
      int ans = 0;
      for (auto it : pool[k - 1]) {
        if (it.second <= n) ans = (ans + (m - it.first) / it.second) % MOD;
        if (it.second <= m) ans = (ans + (n - it.first) / it.second) % MOD;
      }
      printf("%d %d\n", k, ans);
    }
  }
  return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000
#define ll long long
using namespace std;
int main()
{
    int a, b, ans = 0;
    cin >> a;
    b = (a * 100) / 108;
    if (a == int(b * 1.08))
    {
        cout << int(b) << "\n";
    }
    else if (a == int((b + 1) * 1.08))
    {
        cout << int(b + 1) << "\n";
    }
    else
        cout << ":("
             << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,c;
    cin >> a >> b >> c;

    if(a == b && b == c && c == a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

n = int(input())
evenflag = n%2==0
a = list(map(int, input().split()))
kouho = [0 for i in range(n)]
for num in a:
    if (evenflag and num%2==0) or (not evenflag and num%2==1):
        print(0)
        sys.exit()
    x = (n-1+num)//2
    y = n-1-x
    kouho[min(x,y)]+=1
ans = 0
if n%2 == 1:
    if kouho[n//2] != 1:
        print(0)
        sys.exit()
for i in range(n//2):
    if kouho[i] == 2:
        ans+=1
    else:
        print(0)
        sys.exit()

print(power(2,ans,mod))

Measured memory_bytes: 56172
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int m1 = in.nextInt();
		int d1 = in.nextInt();
		int m2 = in.nextInt();
		int d2 = in.nextInt();
		if(d2==1) System.out.println(1);
		else System.out.println(0);
	}

}

Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main(){
long i,j,a,b,c;
for(i=0;i<200;i++){
cin>>a>>b;
if(cin.eof())break;
c=a+b;
for(j=0;j<6;j++){c/=10;if(c==0)break;}
cout<<j+1<<endl;
}
return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		for(int i = 0; i < s.length(); i += 2) {
			System.out.print(s.charAt(i));
		}
		System.out.println();
	}
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
        private static int s_maxWater;
        private static int s_maxSugar;
        private static double s_maxDensity = double.MinValue;
        static void SolveA()
        {
            int n = ReadAndParseInt();
            var a = ReadAndParseIntArr();
            var dic = new Dictionary<int, int>();
           
            for(int i=0;i<a.Length;++i)
            {
                int t = a[i];
                if (!dic.ContainsKey(t)) { dic.Add(t, 0); }
                if (!dic.ContainsKey(t + 1)) { dic.Add(t + 1, 0); }
                if (!dic.ContainsKey(t - 1)) { dic.Add(t - 1, 0); }

                dic[t]++;
                dic[t + 1]++;
                dic[t - 1]++;
            }

            int maxNum = 0;
            foreach(var pair in dic)
            {
                if(pair.Value > maxNum)
                {
                    maxNum = pair.Value;
                }
            }

            Console.WriteLine(maxNum);

        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

long fac(long n)
{
	long ans=1;
	int i;
	
	if(n==0 || n==1)
		return 1;
	
	for(i=1;i<=n;i++)
		ans *= i;
	return ans;
}

long num(long n, int a[], int i)   //returns order
{
	int j;
	int count=0;
	long ans;
	
	if(i==n)
		return 0;
	
	for(j=0;j<n-i;j++)
		if(a[i]>a[i+j])
			count++;
	ans = count*fac(n-i-1) + num(n,a,i+1);
	return ans;
}
	
	


int main(void)
{
	int n;
	int i;
	int a[8]={0};
	int b[8]={0};
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
	
	printf("%ld",labs(num(n,a,0)-num(n,b,0)));
	return 0;
}
	
	

Measured memory_bytes: 128
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

ans = 0
for k in range(K, N + 2):
    MIN = (k - 1) * k // 2 % MOD
    MAX = (2 * N - k + 1) * k // 2 % MOD
    ans += MAX - MIN + 1
    ans %= MOD

print (ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,M, kk, ss, pp;cin>>N>>M;
    int cnt = 0; int ans=0; bool ok=true;
    std::vector<int> k; std::vector<std::vector<int> > s(M+1); std::vector<int> p;
    for(int i=0; i<M;i++){
      cin>>kk;  k.push_back(kk);
      for(int j=0; j<kk;j++) {
        cin>>ss; s[i].push_back(ss-1);
      }
    }
    for(int i=0; i<M;i++){
      cin>>pp; p.push_back(pp);
    }

    for (int bit = 0; bit < (1<<N); ++bit){
      for(int i=0; i<M;i++){
        for(int j=0; j<k[i];j++){
          if(bit & (1<<s[i][j])){
            cnt++;
          }
        }
        if(cnt%2!=p[i]) ok=false;
        cnt=0;
      }
      if(ok) ans++;
      ok = true;
    }

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


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
long long D[1010000], S[1010000], Mod = 1000000007;
int n, H, d;
long long Sum(int b, int e) {
	if (b <= 0)return S[e];
	return (S[e] - S[b - 1] + Mod) % Mod;
}
int main() {
	scanf("%d%d%d", &n, &H, &d);
	D[0] = 1;
	int i;
	long long s = 0;
	for (i = 1; i <= n; i++) {
		D[0] = D[0] * i%Mod;
		s = (s + D[0]) % Mod;
	}
	S[0] = D[0];
	for (i = 1; i <= H; i++) {
		D[i] = Sum(i - d, i - 1)*s%Mod;
		S[i] = (S[i - 1] + D[i]) % Mod;
	}
	printf("%lld\n", Sum(H - d, H - 1));
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct E{int to,co,ti;};
struct P{
  int tim,idx,res;
};
bool operator <(const P &a,const P &b){
  return a.tim<b.tim;
}
bool operator >(const P &a,const P &b){
  if(a.tim!=b.tim)return a.tim>b.tim;
  return a.res<b.res;
}
int ans[50][5001];
const long long LINF=1e18;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}

signed main(){
  memset(ans,-1,sizeof(ans));
  int n,m,s;cin>>n>>m>>s;chmin(s,5000LL);
  vector<E> edge[n];
  while(m--){
    int u,v,a,b;cin>>u>>v>>a>>b;u--;v--;
    edge[u].push_back({v,a,b});
    edge[v].push_back({u,a,b});
  }
  vector<int> c(n),d(n);
  for(int i=0;i<n;i++)cin>>c[i]>>d[i];
  priority_queue<P,vector<P>,greater<P>> que;
  que.push({0,0,s});
  vector<int> fans(n,-1);
  int cnt=0;
  while(que.size()){
    P p=que.top();que.pop();//cout<<p.idx<<" "<<p.res<<" "<<p.tim<<" "<<cnt<<endl;
    if(~ans[p.idx][p.res])continue;
    ans[p.idx][p.res]=p.tim;
    if(fans[p.idx]<0){
      fans[p.idx]=p.tim;
      if(++cnt==n)break;
    }
    for(auto q:edge[p.idx]){
      if(p.res<q.co||~ans[q.to][p.res-q.co])continue;
      que.push({p.tim+q.ti,q.to,p.res-q.co});
    }
    if(p.res+c[p.idx]<5000)que.push({p.tim+d[p.idx],p.idx,p.res+c[p.idx]});
  }
  for(int i=1;i<n;i++)cout<<fans[i]<<endl;
}


Measured memory_bytes: 17456
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h , n , ans , temp , x ,i;
	cin>>h>>n;
	for(i=0;i<n;i++)
		{
			cin>>x;
			temp+=x;
		}
	if(temp>=h)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;		
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 1005, INF = 1e9;


int n;
int A[N][N], cur[N];

struct NODE {
    int x, y;
} ;

queue < NODE > Q;
int mark[N][N], li[N], t;

void Push(int u) {
    if (cur[u] >= n) return ;
    int v = A[u][cur[u]];
    if (A[v][cur[v]] == u && !mark[u][v] && !mark[v][u])
        Q.push((NODE) { u, v }), mark[u][v] = mark[v][u] = true;
}

int main() {
    n = read<int>();
    rep (i, 1, n) {
        rep (j, 1, n - 1) A[i][j] = read<int>();
        cur[i] = 1;
    }
    rep (i, 1, n) Push(i);
    int cnt = 0;
    rep (i, 1, n * (n - 1) / 2) {
        t = 0;
        while (!Q.empty()) {
            int x = Q.front().x, y = Q.front().y; Q.pop();
            ++cur[x], ++cur[y], ++cnt;
            li[++t] = x, li[++t] = y;
        }
        rep (j, 1, t) Push(li[j]);
        if (cnt == n * (n - 1) / 2) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 8192
public class Hello{
    public static void Main(){

        int N = int.Parse(System.Console.ReadLine());
        int K = int.Parse(System.Console.ReadLine());
        int X = int.Parse(System.Console.ReadLine());
        int Y = int.Parse(System.Console.ReadLine());

        if(N <= K){
            System.Console.WriteLine(N * X);
        }else{
            System.Console.WriteLine(K * X + (N - K) * Y);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int strength[14]={-1,13,1,2,3,4,5,6,7,8,9,10,11,12};
int main(){
    int A,B;
    cin>>A>>B;

    if(strength[A]>strength[B])cout<<"Alice"<<"\n";
    else if(strength[A]<strength[B])cout<<"Bob"<<"\n";
    else cout<<"Draw"<<"\n";

    return 0;
}


Measured memory_bytes: 256
N = int(input())
ta = [list(map(int, input().split())) for _ in range(N)]
t = 1
a = 1
for i in range(N):
    if t % ta[i][0] != 0:
        ttmp = t // ta[i][0] + 1
    else:
        ttmp = t // ta[i][0]

    if a % ta[i][1] != 0:
        atmp = a // ta[i][1] + 1
    else:
        atmp = a // ta[i][1]
    n = max(ttmp, atmp)
    t = (n * ta[i][0])
    a = (n * ta[i][1])

print(t + a)

Measured memory_bytes: 3188
s = int(input())
a = [s]
i = 1

while a.count(a[i-1]) <= 1:
    if a[i-1] % 2 == 0:
        a.append(int(a[i-1]/2))
    else:
        a.append(a[i-1]*3+1)
    i += 1

print(i)


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define pb emplace_back

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

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

Measured memory_bytes: 256