akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

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

int N;
vint data;
vpint ans;

void solve(int left, int right) {
	// [left, right)
	if (left + 1 >= right) return;
	int ind = -1;
	int record = 0;
	repr(i, left, right-1) if (abs(data[i]) > record) {
		record = abs(data[i]);
		ind = i;
	}
	if (ind == -1) return;
	bool updated = false;
	if (data[ind] < 0) {
		repr(i, left, ind-1) if (data[i] > data[ind]) {
			ans.pb(mp(ind, i));
			data[i] += data[ind];
			updated = true;
		}
	}
	else {
		repr(i, ind+1, N-1) if (data[i] < data[ind]) {
			ans.pb(mp(ind, i));
			data[i] += data[ind];
			updated = true;
		}
	}
	if (updated) {
		solve(left, right);
	}
	else {
		solve(left, ind);
		solve(ind + 1, right);
	}
}

int main() {
	N = in();
	data.resize(N);
	rep(i,N) data[i] = in();
	
	int ind = -1;
	int record = 0;
	repr(i, 0, N-1) if (abs(data[i]) > record) {
		record = abs(data[i]);
		ind = i;
	}
	
	if (ind == -1) {
		cout << 0 << endl;
		return 0;
	}
	if (data[ind] > 0) {
		rep(i,N) if(i != ind) ans.pb(mp(ind, i));
		rep(i,N-1) ans.pb(mp(i,i+1));
	}
	else {
		rep(i,N) if(i != ind) ans.pb(mp(ind, i));
		for (int i = N-1; i >= 1; i--) ans.pb(mp(i, i-1));
	}
	// solve(0, N);
	cout << ans.size() << endl;
	rep(i, ans.size()) cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String input = scanner.next();
    boolean result = input.endsWith("s");  //末尾が"s"と一致するか判定
    StringBuilder sb = new StringBuilder();
    sb.append(input);
    if(result) sb.append("es");
    else sb.append("s");
    String output = new String(sb);  // "abcdefghi"
    System.out.println(output);
  }
}

Measured memory_bytes: 35740
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int amountToRoll = Integer.parseInt(scan.nextLine());
		
		int streak = 0;
		
		for (int i = 0; i < amountToRoll; i++)
		{
			String[] array = scan.nextLine().split("\\s");
			
			if(array[0].equals(array[1])) 
			{
				streak++;
			}
			
			else 
			{
				streak = 0;
			}
			
			if(streak == 3) 
			{
				System.out.println("Yes");
				break;
			}
			
		}
		
		
		
		if(streak != 3) 
		{
			System.out.println("No");
		}
		
		scan.close();

	}

}


Measured memory_bytes: 35908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
    
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a,b) << " " << max(0, a+b-n);
 
}





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

int a[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

int main(){
  int x, y;
  cin >> x >> y;
  if (a[x] == a[y]) printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

using namespace std;

long long n, m, ipt, maximum;
priority_queue<long long> a;

int main()
{
	long long sum;
	
	cin >> n >> m;
	for (long long i = 0; i < n; i++)
	{
		cin >> ipt;
		a.push(ipt);
	}
	
	for (long long i = 0; i < m; i++)
	{
		maximum = a.top();
		a.pop();
		a.push(maximum / 2);
	}
	
	sum = 0;
	for (long long i = 0; i < n; i++)
	{
		sum += a.top();
		a.pop();
	}	
	
	cout << sum << endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef complex<double> cd;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

signed main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) cin >> a[i];
    vector<int> odd;
    for (int i = 0; i < m; i++)
    {
        if (a[i] % 2 == 1)
        {
            odd.push_back(i);
        }
    }
    if (odd.size() > 2)
    {
        cout << "Impossible";
        return 0;
    }
    if (m == 1)
    {
        cout << a[0] << "\n";
        if (a[0] == 1) cout << 1 << "\n" << 1 << "\n";
        else cout << 2 << "\n" << a[0] - 1 << " " << 1 << "\n";
        return 0;
    }
    if (m == 2)
    {
        cout << a[0] << " " << a[1] << "\n";
        if (a[0] == 1) cout << 1 << "\n" << n << "\n";
        else cout << 2 << "\n" << a[0] - 1 << " " << a[1] + 1 << "\n";
        return 0;
    }
    vector<int> x;
    if (odd.size() > 0) x.push_back(a[odd[0]]);
    for (int i = 0; i < m; i++) if (a[i] % 2 == 0) x.push_back(a[i]);
    if (odd.size() > 1) x.push_back(a[odd[1]]);
    for (auto e : x) cout << e << " "; cout << "\n";
    vector<int> y;
    y.push_back(x[0] + 1);
    for (int i = 1; i < m - 1; i++) y.push_back(x[i]);
    if (x[m - 1] != 1) y.push_back(x[m - 1] - 1);
    cout << y.size() << "\n";
    for (auto e : y) cout << e << " "; cout << "\n";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 3668
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll a[N], step[N];
int main() {
    ll n, k;
    scanf("%lld%lld",&n,&k);
    for(int i = 1; i <= n; ++i)
        scanf("%lld",&a[i]), step[i] = -1;
    ll t = 1, s = 0, r;

    while(1) {
        //printf("t = %lld s = %lld\n",t,s);
        if(step[t] != -1) {
            r = step[t] + (k-step[t])%(s-step[t]);
            break;
        } else step[t] = s, s++, t = a[t]; 
    }
    
    if(k < s) {
        for(int i = 1; i <= n; ++i)
            if(step[i] == k) {
                printf("%d\n",i);
                break;
            }
    } else {
        for(int i = 1; i <= n; ++i) 
            if(step[i] == r) {
                printf("%d\n",i);
                break;
            }
    }
return 0;
}

Measured memory_bytes: 6900
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

temp = [[i] for i in range(M)]
lsts = []
while temp:
    q = temp.pop()
    if len(q) == N:
        lsts.append(q)
        continue
    for i in range(q[-1], M):
        q1 = q[:]
        q1.append(i)
        temp.append(q1)
lsts.sort()  
ans = []
for lst in lsts:
    cnt = 0
    for k in abcd:
        if lst[k[1]-1] - lst[k[0]-1] == k[2]:
            cnt += k[3]
    ans.append(cnt)
print(max(ans))

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

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

    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    
    ll ans=0;
    rep(i,0,n){
        auto num = lower_bound(a.begin(),a.end(),b[i])-a.begin();
        auto num1 = n - (upper_bound(c.begin(),c.end(),b[i])-c.begin());
        ans+=num*num1;
    }
    cout<<ans<<endl;

    return 0;
}



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

int main( void )
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if ( ( ( e - a ) <= ( 4 * k ) ) && ( ( d + e - a - b ) <= ( 3 * k ) ) &&
         ( ( d + e - a - b ) <= ( 2 * k ) ) && ( ( e - a ) <= ( k ) ) )
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
p=list(map(int,input().split()))
p=[(1+i)/2 for i in p]
ans=sum(p[0:K])
A=[ans]

for i in range(N-K):
  ans-=p[i]
  ans+=p[K+i]
  A.append(ans)
print(max(A))

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

int main()
{
  	int x;
  	cin>>x;
  	int ans=0;
  	for(int i=1 ; (i*i)<=x ; ++i)
    {
    	int tmp=i;
      	while((tmp*i)<=x)
        {
            if(tmp==1)
            break;
        	tmp*=i;
        }
      	ans=max(ans,tmp);
    }
    cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,greater<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define bs binary_search
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

const ll MAXN=200005;
ll parent[MAXN],siz[MAXN],ran[MAXN];

void make_set(ll v) {
    parent[v] = v;
    siz[v]=1;
}

ll find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v]=find_set(parent[v]);
}

void union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b)
    {
        if(ran[a]>=ran[b])
        {
            parent[b] = a;
            siz[a]+=siz[b];
            if(ran[a]==ran[b])
                ran[a]++;
        }
        else
        {
            parent[a] = b;
            siz[b]+=siz[a];
        }
    }
}

int main() 
{
    FAST;
    ll n,m,a,b;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        make_set(i);
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        union_sets(a,b);
    }
    ll ans=1;
    for(int i=1;i<=n;i++)
        ans=max(ans,siz[find_set(i)]);
    cout<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

ll d;
vector<ll> c(26);
vector<vector<ll>> s(365, vector<ll>(26));
vector<ll> t(365);

vector<ll> calc() {
  vector<ll> nsc(26);
  vector<ll> score(d);
  vector<ll> last(26, -1);
  rep(i, d) {
    last[t[i]] = i;
    rep(j, 26) {
      if (t[i] == j) nsc[j] += s[i][j];
      else nsc[j] -= c[j]*(i-last[j]);
    }
    ll sum = 0;
    rep(j, 26) sum += nsc[j];
    score[i] = sum;
  }
  return score;
}

int main()
{
  cin>>d;
  rep(i, 26) cin>>c[i];
  rep(i, d) rep(j, 26) cin>>s[i][j];

  rep(i, d) {
    ll tmp = 0;
    ll ma = -inf;
    rep(j, 26) {
      if (s[i][j] > ma) {
        ma = s[i][j];
        tmp = j;
      } else if (s[i][j] == ma) {
        if (c[j] < c[tmp]) {
          tmp = j;
        }
      }
    }
    t[i] = tmp;
  }
  vector<ll> fsc = calc();
  // for (auto v:fsc) cout << v << endl;
  // cout << endl;

  {
    vector<ll> last(26, -1);
    vector<ll> nsc(26);
    rep(i, d) {
      ll idx = 0;
      ll sum = 0;
      rep(j, 26) {
        nsc[j] -= c[j]*(i-last[j]);
        sum += nsc[j];
      }
      rep(j, 26) {
        ll aa = sum + c[j]*(i-last[j]) + s[i][j];
        ll bb = sum + c[idx]*(i-last[idx]) + s[i][idx];
        if (aa > bb && aa >= fsc[i]) {
          idx = j;
        }
      }
      nsc[idx] += c[idx]*(i-last[idx]) + s[i][idx];
      last[idx] = i;
      t[i] = idx;
    }
  }
  rep(i, d) cout << t[i]+1 << endl;


  return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<vector<int>> vec(11);
int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int s;
			cin >> s;
			vec[i].emplace_back(s - 1);
		}
	}
	int p[11];
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	bool b[11];
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				b[j] = true;
			}
			else {
				b[j] = false;
			}
		}
		int co = 0;
		for (int j = 0; j < m; j++) {
			int co1 = 0;
			for (int k = 0; k < vec[j].size(); k++) {
				if (b[vec[j][k]]) {
					co1++;
				}
			}
			if (co1 % 2 == p[j] % 2) {
				co++;
			}
		}
		if (co == m) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define inf ll(10e16)
#define mod ll(10e8+7)
#define ff first
#define ss second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll a,b,c,k;
        cin>>a>>b>>c>>k;

        ll sum=0;
        if(k<a)
            sum=k;
        else{
            sum=a;
            k-=a;
        }
        k-=b;
        if(k>0)
        {
            sum-=k;
        }
        cout<<sum;

    }
    return 0;
}


Measured memory_bytes: 3652
import queue
import heapq

class point:
    def __init__(self):
        self.num = 0
        self.line = [0 for _ in range(3)]

    def __lt__(self, other):
        return self.num > other.num


ABC = list(map(int, input().split()))
K = ABC[-1]
ABC.pop()
ABCL = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ABCL[i] = sorted(ABCL[i])
    ABCL[i] = list(reversed(ABCL[i]))
s = set()
p = point()
p.num = sum([ABCL[i][0] for i in range(3)])
s.add(tuple(p.line))
que = []
heapq.heappush(que, p)
for _ in range(K):
    c = heapq.heappop(que)
    print(c.num)
    for i in range(3):
        d = point()
        d.num = c.num
        for j in range(3):
            d.line[j] = c.line[j]
        if d.line[i] + 1 == ABC[i]:
            continue
        d.num -= ABCL[i][d.line[i]]
        d.line[i] += 1
        d.num += ABCL[i][d.line[i]]
        if tuple(d.line) in s:
            continue
        s.add(tuple(d.line))
        heapq.heappush(que, d)


Measured memory_bytes: 6476
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

long long solve(long long N) {
    auto div1 = calc_divisor(N);
    auto div2 = calc_divisor(N-1);

    long long res = 0;
    for (auto d : div1) {
        if (d == 1) continue;
        long long NN = N;
        while (NN % d == 0) NN /= d;
        if ((NN-1) % d == 0) ++res;
    }
    for (auto d : div2) {
        if (d == 1) continue;
        ++res;
    }
    return res;
}

int main() {
    long long K;
    while (cin >> K) cout << solve(K) << endl;
}

















Measured memory_bytes: 384
n = int(input())
cards = list()
pattern = ["S", "H", "C", "D"]
for i in range(n):
    s,r = input().split()
    r = int(r)
    if s == "S":
        cards.append(0+r)
    elif s == "H":
        cards.append(13+r)
    elif s == "C":
        cards.append(26+r)
    elif s == "D":
        cards.append(39+r)

for i in range(1,53):
    if not (i in cards):
        print(pattern[(i-1)//13], (i-1)%13+1)


Measured memory_bytes: 5612
function solve()
    n, k = [parse(Int, x) for x in split(readline())]
    a = [parse(Int, x) for x in split(readline())]

    current = 1
    path = [1]
    visited = Set{Int}(1)

    while a[current] ∉ visited
        current = a[current]
        append!(path, current)
        push!(visited, current)
    end
    append!(path, a[current])

    if k < length(path)
        path[k+1]
    else
        cycle_start = findfirst(x->(x==path[end]), path)
        k = k - cycle_start
        path = path[cycle_start+1:end]
        k = k % length(path) + 1
        path[k]
    end
end

println(solve())

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

int main(){
  long long a,b,k;
  cin>>a>>b>>k;
  if(a>=k){
    cout<<a-k<<" "<<b;
  }else if(a+b>=k){
    cout<<"0 "<<a+b-k;
  }else{
    cout<<"0 0";
  }
}

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

const int mod = 1000000007;

long long modpow(long long x, int y) {
	if (y == 0) return 1;
	if (y == 1) return x;
	long long z = modpow(x, y/2);
	z = z*z % mod;
	if (y % 2) z = z*x % mod;
	return z;
}

long long modinv(long long x) {
	return modpow(x, mod-2);
}

long long modfact(int n) {
	long long r = 1;
	for (int i = 1; i <= n; ++ i) r = r*i % mod;
	return r;
}

long long modcomb(int n, int k) {
	return modfact(n) * modinv(modfact(k)) % mod * modinv(modfact(n-k)) % mod;
}

struct BComp {
	const vector<vector<int>>& G;
	vector<int> ord;
	vector<int> low;
	vector<pair<int,int>> S;
	vector<vector<pair<int,int>>> bcomp;

	BComp(const vector<vector<int>>& G) : G(G), ord(G.size(),-1), low(G.size()) {
		for (int u = 0; u < (int)G.size(); ++ u) if (ord[u] == -1) {
			ord[u] = low[u] = 0;
			dfs(u, -1);
		}
	}

	int dfs(int u, int p) {
		int cnt=1;
		for (int v : G[u]) if(v != p) {
			if (ord[v] < ord[u])
				S.emplace_back(u,v);
			if (ord[v] == -1) {
				ord[v] = low[v] = ord[u]+cnt;
				cnt += dfs(v, u);
				low[u] = min(low[u],low[v]);
				if (ord[u] <= low[v]) {
					bcomp.emplace_back();
					for (;;) {
						auto e = S.back(); S.pop_back();
						bcomp.back().push_back(e);
						if(e == make_pair(u,v)) break;
					}
				}
			} else {
				low[u] = min(low[u],ord[v]);
			}
		}
	}
};

bool iscycle(const vector<pair<int,int>>& x) {
	set<int> s;
	for (auto p : x) {
		s.insert(p.first);
		s.insert(p.second);
	}
	return s.size() == x.size();
}

int main() {
	int N, M, K;
	vector<vector<int>> G;
	cin >> N >> M >> K;
	G.resize(N);
	for (int i = 0; i < M; ++ i) {
		int x, y;
		cin >> x >> y;
		-- x; -- y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	BComp a(G);
	long long r = 1;
	for (const auto& x : a.bcomp) {
		if (x.size() == 1) {
			r = (r * K) % mod;
		} else if (iscycle(x)) {
			int n = x.size();
			long long rr = 0;
			for (int i = 0; i < n; ++ i) {
				rr = (rr + modpow(K, __gcd(n, i))) % mod;
			}
			rr = rr * modinv(n) % mod;
			r = (r * rr) % mod;
		} else {
			int m = x.size();
			r = (r * modcomb(m+K-1, K-1)) % mod;
		}
	}
	cout << r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
using mat2d_t = std::vector<std::vector<int64_t>>;


int main(int argc, char **argv) {
    i64 k, q;
    cin >> k >> q;

    std::vector<i64> ds(k);

    for (int i=0; i<k; ++i) {
        cin >> ds[i];
    }

    for (int i=0; i<q; ++i) {
        i64 n, x, m;
        cin >> n >> x >> m;

        i64 ans=n-1;

        std::vector<i64> mod_ds = ds;
        i64 sum_ds{0}, num_zero{0}, an;
        for (i64& d : mod_ds) {
            d = d%m;
            sum_ds += d;
            if (d == 0) {
                ++num_zero;
            }
        }
        //cout << "  "<< sum_ds << endl;
        an = sum_ds * ((n-1)/k);
        num_zero = num_zero * ((n-1)/k);
        i64 n2 = (n-1)%k;
        for (int j=0; j<n2; ++j) {
            an += mod_ds[j];
            if (mod_ds[j] == 0) ++num_zero;
        }
        //cout << "  "<< (an+x)/m << " " << x/m<<endl;
        ans -= ((an+x)/m-x/m);
        ans -= num_zero;

        cout << ans << endl;
    }

    return 0;
}

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

int main() {
    char ymd[10];
    scanf("%s", ymd);
    int iymd;
    int i;
    char cymd[8];
    for(i=0; i<4; i++) {
        cymd[i] = ymd[i];
    }
    for(i=5; i<7; i++) {
        cymd[i-1] = ymd[i];
    }
    for(i=8; i<10; i++) {
        cymd[i-2] = ymd[i];
    }
    iymd = atoi(cymd);

    if(iymd <= 20190430) {
        printf("%s\n", "Heisei");
    } else {
        printf("%s\n", "TBD");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  string s;
  cin>>s;
  int ans=0;
  int l=0,r=0;
  rep(i,s.size()){
    if(i<s.size()-1&&s[i]=='>'&&s[i+1]=='<'){
      l++;
      ans+=l*(l-1)/2;
      ans+=r*(r-1)/2;
      ans+=max(l,r);
      //cout<<l<<' '<<r<<endl;
      l=0;r=0;
      //cout<<ans<<endl;
    }else if(s[i]=='>') l++;
    else r++;
  }

  ans+=l*(l-1)/2;
  ans+=r*(r-1)/2;
  ans+=max(l,r);

  cout<<ans<<endl;


}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << ' ' << X << ' ' << Y << endl;
  
}

Measured memory_bytes: 256
N = int(input())
S = str(input())


s = list(S)
s_new =[]
for i in range(len(S)):
    if ord(s[i])+N<91:
        s[i] = chr(ord(s[i])+N)
        s_new.append(s[i])
    else:
        s[i] = chr(ord(s[i])+N-26)
        s_new.append(s[i])
print(''.join(s_new))


Measured memory_bytes: 3188
#include<stdio.h>

int selectionSort(int A[], int N) {
    int minj, i, j, v;
    int count = 0;

    for (i=0; i<N; i++) {
        minj = i;
        for (j=i+1; j<N; j++) {
            if (A[minj]>A[j]) minj = j;
        }
        if (minj != i) {
            v = A[i];
            A[i] = A[minj];
            A[minj] = v;
            count++;
        }        
    }

    return count;
}

int main() {
    int i, A[100], N;

    scanf("%d", &N);
    for (i=0; i<N; i++) scanf("%d", &A[i]);

    int count = selectionSort(A, N);

    for (i=0; i<N; i++) {
        if (i>0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d", count);
    printf("\n");
}


Measured memory_bytes: 2740
<?php
$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$r = 0;

$i = 0;
while($i < $n){
    if($s[$i] == "("){
        ++$r;
    }else{
        if($r > 0){
            --$r;
        }else{
            echo "(";
        }
    }
    ++$i;
}

echo $s;

if($r > 0){
    echo str_repeat(")",$r);
}

Measured memory_bytes: 3828
#include<iostream>
#include<queue>
#include<stdio.h>
using namespace std;
float Y(double x){
  return (double)(x+1.000)/2.000;
}
int main(){
  queue<double> q;
  int N,K;
  double p,sum=0.000,t=0.000,KIT;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    cin >> p;
    KIT = Y(p);
    q.push(KIT);
    t += KIT;
    if(i >= K){
      t -=q.front();
      q.pop();
    }
    sum = max(t,sum);
  }
  printf("%lf",sum);
}

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

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

    int a[3100];
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }

    int ans = 0;
    for (int i = 0; i < N; i++){
        ans += a[i] - 1;
    }

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

Measured memory_bytes: 888
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
//#include<numeric>
#include<functional>
#include<deque>
#include<queue>
#include<string>
#include<iostream>

using namespace std;
const int one = 1;
const int big = (one<<30);
typedef long long int llint;
vector<int> E[100010];

int is2sai(int ter){
	int i,j,kore,gk;
	map<int,int> isg;
	queue<pair<int,int>> que;
	//isg[ter]=0;
	que.push(make_pair(ter,0));
	while(!que.empty()){
		kore=que.front().first;
		gk=que.front().second;
		que.pop();
		if(isg.count(kore)>0){//あった
			if(isg[kore]==gk){continue;}
			else{return 1;}
		} else{
			isg[kore]=gk;
		}
		for(i=0;i<E[kore].size();i++){
			que.push(make_pair(E[kore][i],(gk+1)%2));
		}
	}
	return 0;
}
int main(void){
	int i,j,gen=0,N,M,a,b;
	llint Ko=0,ren=0,s2ren=0,ans=0;
	vector<int> go;
	vector<int> rAnk;//rankだとstlの何かとと被る
	vector<int> cheak;
	scanf("%d %d",&N,&M);
	for(i=0;i<N;i++){
		go.push_back(i);
		rAnk.push_back(0);
	}
	for(i=0;i<M;i++){
		scanf("%d %d",&a,&b);
		a--;b--;//0-begin化
		E[a].push_back(b);
		E[b].push_back(a);
		while(a!=go[a]){a=go[a];}//根にたどる
		while(b!=go[b]){b=go[b];}
		if(a==b){continue;}//同じ根なら無視する
		if(rAnk[a]<rAnk[b]){swap(a,b);}
		if(rAnk[a]==rAnk[b]){rAnk[a]++;}
		go[b]=a;
	}
	for(i=0;i<N;i++){
		if(i!=go[i]){ continue; }
		if(rAnk[i]==0){ Ko++; } else{cheak.push_back(i); }
	}
	for(i=0;i<cheak.size();i++){
		if(is2sai(cheak[i])==0){
			s2ren++;
		} else{
			ren++;
		}
	}
	ans=(2*N-Ko)*Ko;
	ans+=s2ren*s2ren;
	ans+=(s2ren+ren)*(s2ren+ren);
	printf("%lld\n",ans);
	/*
	printf("Ko=%d\n",Ko);
	printf("ren=%d\n",ren);
	printf("s2ren=%d\n",s2ren);
	*/
	return 0;

}

Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair

int main() {
	ll n;
	cin >> n;
	ll a[n];
	for(ll i=0;i<n;i++) cin >> a[i];
	ll mod=1e9+7;
	ll ans=0;
	ll two_factor=1;
	for(int d=0;d<60;d++){
		ll even=0,odd=0;
		for(int i=0;i<n;i++){
			if(a[i]&(1LL<<d)) odd++;
			else even++;
		}
		ll add=(odd*even)%mod*two_factor%mod;
		ans=(ans+add)%mod;
		two_factor=(two_factor*2)%mod;
	}
	cout << ans%mod << endl;
}


Measured memory_bytes: 5948
N = int(input())

N_MAX = 10 ** 4
cnt = [0] * (N_MAX + 1)

for x in range(1, N + 1):
    if x ** 2 > N:
        break
    for y in range(1, N + 1):
        if x ** 2 + y ** 2 + x * y > N:
            break
        for z in range(1, N + 1):
            a = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + x * z
            if a > N:
                break
            cnt[a] += 1

for i in range(1, N + 1):
    print(cnt[i])


Measured memory_bytes: 69220
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;


int main() {
	int h, w;
	cin >> h >> w;
	string s;
	for (int i = 1; i <= h; i++) {
		for (int j = 'A'; j < 'A' + w; j++) {
			cin >> s;
			if (s == "snuke") {
				cout << char(j) << i << endl;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 10000000000
typedef long long C;
typedef complex<C> P; 
#define X real() 
#define Y imag()


									// nestedcode
ll dp[1000004];

 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll h,n,i;
   cin>>h>>n;
   for(i=1;i<=h+10000;i++){
   	dp[i] = INF;
   }
   ll a[n+5],b[n+5];
   for(i=0;i<n;i++){
   	cin>>a[i]>>b[i];
   	for(ll j=a[i];j<=h+10000;j++){
   		dp[j] = min(dp[j-a[i]] + b[i] , dp[j]);
   	
	   }//cout<<endl;
   }
   ll ans = LLONG_MAX;
	for(i=h;i<=h+10000;i++){
		ans = min(ans,dp[i]);
	}
	cout<<ans;
   
   
}

Measured memory_bytes: 384
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, X, T = il()
    d, m = divmod(N, X)
    print(d * T if m == 0 else (d + 1) * T)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9888
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    println!("{}",if v[0] <= v[2] && v[0]+v[1] >= v[2] { "YES" } else { "NO" });
}


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

const int MOD = 1000000000 + 7;

const int MAX = 200010;

long long fac[MAX], finv[MAX], inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long mod_comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    comb_init();
    long long c;
    if (k == 2) c = 1;
    else  c = mod_comb(n * m - 2, k - 2);

    long long ans = 0;
    for (int d = 1; d <= n - 1; d++)
    {
        ans += (d * (n - d) * m * m) % MOD;
        ans %= MOD;
    }
    for (int d = 1; d <= m - 1; d++)
    {
        ans += (d * (m - d) * n * n) % MOD;
        ans %= MOD;
    }
    
    ans *= c % MOD;
    ans %= MOD;

    cout << ans << endl;
}


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

int n;

bool solve(int k,int d){

  if(k < 0) return false;
  else if(k+d > n) return false;
  else if(k+d == n) return true;

  else if(k+d < n) solve(k-1,d+k);
}

int main(){

  while(cin >> n, n){

    int ans = 0;
    for(int i=n-1;i>0;i--){
      bool p = solve(i,0);
      if(p) ans++;
    }

    cout << ans << endl;
  }

}

Measured memory_bytes: 1160
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1, n-1):
    if p[i-1] > p[i] and p[i] > p[i+1]:
        ans += 1
    elif p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1

print(ans)
    


Measured memory_bytes: 3060
n, a, b, c, d = (int(x) for x in input().split())
flag = False
for i in range(n):
    j = n - 1 - i
    upper = a + i * d - j * c
    lower = a + i * c - j * d
    if lower <= b <= upper:
        flag = True
print("YES" if flag else "NO")

Measured memory_bytes: 65328
N,X,Y=map(int,input().split())

Ans=[0]*N

i=1
d=0
while i<=N:
    j=i+1
    while j<=N:
        d=(min(j-i,abs(X-i)+1+abs(j-Y)))
        Ans[d]+=1
        j+=1
    i+=1

k=1
while k<=N-1:
    print(Ans[k])
    k+=1

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

ll W[55];
ll P[55];

ll patee(ll l, ll n){
    ll whole = W[l];
    ll pate = P[l];
    if(l == 0){
        return 1;
    }
    if(n == 1){
        return 0;
    }
    if(n > 1 && n < (whole/2) + 1){
        return patee(l-1, n-1);
    }
    if(n == (whole/2) + 1){
        return P[l-1]+1;
    }
    if(n < whole){
        return P[l-1]+1 + patee(l-1, n-((whole/2)+1));
    }

    return pate;
}

int main() {
    ll N, X; cin >> N >> X;
    W[0] = 1;
    P[0] = 1;
    for (int i = 1; i <= N; i++){
        W[i] = W[i-1]*2 + 3;
        P[i] = P[i-1]*2 + 1;
    }
    cout << patee(N, X) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  string s;
  int n;
  while(cin >> s >> n && (s!="0" || n)) {
    map<string,int> m;
    m[s]=0;
    while(s.size()<n) s='0'+s;
    while(1) {
      string a,b;
      sort(all(s),greater<char>());
      a=s;
      sort(all(s));
      b=s;
      stringstream ss1,ss2,ss3;
      ss1 << a;
      ss2 << b;
      int a2,b2;
      ss1 >> a2;
      ss2 >> b2;
      a2-=b2;
      ss3 << a2;
      ss3 >> s;
      if(m.count(s)==0) m[s]=m.size()-1;
      else break;
      while(s.size()<n) s='0'+s;
    }
    cout << m[s] << " " << s << " " << m.size()-m[s] << endl;
  }
  return 0;
}


Measured memory_bytes: 1268
#include <iostream>
typedef long long ll;
#define rep(i,k,n) for(ll i=k;i<=n;++i)
#define REP(i,k,n) for(ll i=k;i<n;)

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    ll x;
    std::cin >> x;
    ll y=0;
    REP(i,100,x){
        i*=1.01;
        y++;
    }
    std::cout << y << std::endl;
    return 0;
}

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

int main()
{
  long a, b;
  cin >> a >> b;
  long r = min(a, b);
  long p = max(a, b);
  long cnt, ans = 0;
  while (true)
  {
    ans += r;
    if (ans % p == 0)
      break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int k;
    scanf("%d",&k);

    if(k==1) printf("1\n");
    else if(k==2) printf("1\n");
    else if(k==3) printf("1\n");
    else if(k==4) printf("2\n");
    else if(k==5) printf("1\n");
    else if(k==6) printf("2\n");
    else if(k==7) printf("1\n");
    else if(k==8) printf("5\n");
    else if(k==9) printf("2\n");
    else if(k==10) printf("2\n");
    else if(k==11) printf("1\n");
    else if(k==12) printf("5\n");
    else if(k==13) printf("1\n");
    else if(k==14) printf("2\n");
    else if(k==15) printf("1\n");
    else if(k==16) printf("14\n");
    else if(k==17) printf("1\n");
    else if(k==18) printf("5\n");
    else if(k==19) printf("1\n");
    else if(k==20) printf("5\n");
    else if(k==21) printf("2\n");
    else if(k==22) printf("2\n");
    else if(k==23) printf("1\n");
    else if(k==24) printf("15\n");
    else if(k==25) printf("2\n");
    else if(k==26) printf("2\n");
    else if(k==27) printf("5\n");
    else if(k==28) printf("4\n");
    else if(k==29) printf("1\n");
    else if(k==30) printf("4\n");
    else if(k==31) printf("1\n");
    else  printf("51\n");
    return 0;

}


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

int main(){
  long long N,T;
  long long D=0;
  cin>>N>>T;
  vector<long long>vec(N);
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
    if(X>0 && vec.at(X)-vec.at(X-1)>T){
      D+=vec.at(X)-vec.at(X-1)-T;
    }
  }
  cout<<vec.at(N-1)+T-D<<endl;
}

Measured memory_bytes: 4680
#include <stdio.h>
int main(void){
    int i, j, n, dummy; //nは持っているトランプの枚数
    char mark;
    int num; //numは持っているトランプのランク（トランプ上の数字）
    char marks[4] = {'S', 'H', 'C', 'D'};
    int cards[4][13] = {0};

    scanf("%d", &n);
    scanf("%d", &dummy);

    for(i = 1; i <= n; i++){
        scanf("%c %d ", &mark, &num);
        for(j = 0; j < 4; j++){
            if(mark == marks[j]){
                cards[j][num - 1] = 1;
            }
        }
    }

    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            if(!cards[i][j]) printf("%c %d\n", marks[i], j + 1);
        }
    }
    return 0;
}


Measured memory_bytes: 2144
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    string s, t; cin >> s >> t;
    for(int i = 0; i < s.length(); i++){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        s = s.back() + s.substr(0, s.length()-1);
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int low[100005],mid[100005],upe[100005];
long long lowtomid[100005],midtoupe[100005];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=3;i++)
	 for(int j=1;j<=n;j++)
	    if(i==1)scanf("%d",&upe[j]);
	    else if(i==2) scanf("%d",&mid[j]);
	    else scanf("%d",&low[j]);
	sort(low+1,low+n+1);
	sort(mid+1,mid+n+1);
	sort(upe+1,upe+n+1);
	int midlow=0,midupe=0;
	for(int i=1;i<=n;i++)
	{
		while(mid[midlow+1]<low[i]&&midlow<n)midlow++;
		lowtomid[i]=midlow;
		while(upe[midupe+1]<mid[i]&&midupe<n)midupe++;
		midtoupe[i]=midupe;
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
		midtoupe[i]+=midtoupe[i-1];
	for(int i=1;i<=n;i++)
	    ans+=midtoupe[lowtomid[i]];
	cout<<ans;
}


Measured memory_bytes: 2944
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int h = sc.nextInt();
        int w = sc.nextInt();
        int data[][] = new int[h][w];

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                data[i][j] = sc.nextInt() % 2;
            }
        }
        sc.close();

        List<String> ans = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (data[i][j] == 1) {
                    if (j + 1 < w) {
                        data[i][j + 1] ^= 1;
                        ans.add(toString(i, j, i, j + 1));
                    } else if (i + 1 < h) {
                        data[i + 1][j] ^= 1;
                        ans.add(toString(i, j, i + 1, j));
                    }
                    data[i][j]--;
                }
            }
        }

        System.out.println(ans.size());
        ans.forEach(s -> System.out.println(s));
    }

    private String toString(int sx, int sy, int gx, int gy) {
        return ++sx + " " + ++sy + " " + ++gx + " " + ++gy;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
    }
}


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

const int MAX = 2000;
const bool DEBUG = false; // デバッグ表示用、提出時にfalseにするよ

int main() {
	int N, K, Q, A[MAX];
	cin >> N >> K >> Q;
	int up[MAX];
	for (int i = 0;i < N;i ++) {
		cin >> A[i];
		up[i] = A[i];
	}
	sort(up, up+N);
	
	int ans = up[N - 1];
	int dat[MAX], dat2[MAX], tmp;
	for (int Y = 0;Y < N - Q + 1;Y ++) {
		if (DEBUG) cout << "下限:" << up[Y] << endl;
		tmp = 0;
		for (int l = 0, r = 0;r <= N;r ++) {
			if (r >= N || A[r] < up[Y]) { // 使用不可
				if (DEBUG) cout << "範囲:[" << l << "," << r << ")" << endl;
				for (int i = l;i < r;i ++) dat2[i - l] = A[i]; // まず要素取得
				sort(dat2, dat2 + r - l);
				for (int i = 0;i < r - l - K + 1;i ++) {
					dat[tmp] = dat2[i]; // 小さかった奴は取得可能なので入れておく
					tmp ++;
				}
				l = r + 1;
			}
		}
		sort(dat, dat+tmp);
		if (DEBUG) {
			cout << "使用可能:";
			for (int i = 0;i < tmp;i ++) cout << dat[i] << " ";
			cout << endl;
		}
		if (tmp >= Q) ans = min(ans, dat[Q - 1] - dat[0]);
	}
	cout << ans;
	
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、1回の操作で必ず1個は取り除かれる
Q回操作するのでQ個必ず取り除かれる
ここで、XとYを決め打ってみる(O(N^2))
この時、Y以上X以下の要素を取り除くことができる
さて、となると困るのはYより小さい要素だ
連続したK個の間にYより小さい要素があればその瞬間に不可能が証明できる
また、そうでない時
例えば 4 4 4 4 4 4 1 5 5 5 でK=4の時
左側の方からは最大で3個、右側からは0個取れる→連続したY以上の範囲からは最大で連続数-K+1個取れる
この時、この中からは小さい順に取ることができる
……Xを決め打つ必要は無さそう、Yだけ決め打つ(O(N))
この時、取れる範囲の要素を取り出していってソート、(O(NlogN))、その時の範囲を見れば分かる
*/

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long LL;

const int maxn = 2e5;
const LL inf = 1e15;

int a[maxn+10];

int main()
{
    int n;
    LL sum, ans, res;
    while(~scanf("%d", &n)) {
        sum = res = 0;
        ans = inf;
        for(int i = 0;i < n;i++) {
            scanf("%d", &a[i]);
            sum += a[i];
        }
        for(int i = 0;i < n-1;i++) {
            res += a[i];
            sum -= a[i];
            ans = min(ans, abs(res - sum));
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-13

#define INF 2e9 + 20
int const MaxSize = 50 + 10;
LL N, A, B, C, D;

bool goodDU() {
	LP(tp, 1, N)
	{
		LL tpMaxV = A - tp * C;
		LL tpMinV = A - tp * D;

		tpMaxV += (N - 1 - tp) * D;
		tpMinV += (N - 1 - tp) * C;

		if (tpMaxV >= B && tpMinV <= B) {
			//	cout << "DU: tp at" << tp << " " << tpMaxV << " " << tpMinV << endl;
			return true;
		}
	}

	return false;
}

bool goodUD() {
	LP(tp, 1, N)
	{
		LL tpMaxV = A + tp * D;
		LL tpMinV = A + tp * C;

		tpMaxV -= (N - 1 - tp) * C;
		tpMinV -= (N - 1 - tp) * D;

		if (tpMaxV >= B && tpMinV <= B) {
			//	cout << "UD: tp at" << tp << " " << tpMaxV << " " << tpMinV << endl;
			return true;
		}
	}

	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);

	cin >> N >> A >> B >> C >> D;

	if (goodUD() || goodDU())
		cout << "YES";
	else
		cout << "NO";

	return 0;
}


Measured memory_bytes: 384