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

// (Generalised) Chinese remainder theorem (for arbitrary moduli):
// Solves x from system of equations x == a_i (mod m_i),
// giving answer modulo m = lcm(m_1,...,m_n)
// Runs in O(log(m)+n) time
// Overflows only if m overflows
// Returns {1, {x, m}} if solution exists, and {-1, {0,0}} otherwise
ll ee(ll ca, ll cb, ll xa, ll xb, ll&x) {
	if (cb) return ee(cb, ca%cb, xb, xa-(ca/cb)*xb, x);
	x = xa;
	return ca;
}
pair<int, pair<ll, ll>> crt(vector<ll> as, vector<ll> ms) {
	ll aa = 0, mm = 1, d, a, x;
	for (int i = 0; i < (int) as.size(); i++) {
		d = ee(ms[i], mm, 1, 0, x);
		if ((aa-as[i])%d) return {-1,{0,0}};
		a = ms[i]/d;
		mm *= a;
		aa = (as[i] + (aa-as[i])*(((lll)a*x)%mm))%mm;
	}
	if (aa < 0) aa += mm;
	return {1, {aa, mm}};
}

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

	ll n;
	cin >> n;
	if (n == 1) {
		cout << 1 << '\n';
		return 0;
	}
	ll res = n;

	// \sum_{i = 1}^{k} i = k(k+1)/2

	// For prime powers p^t:
	//	either k or k-1 is a multiple of p^t
	// We can loop for 

	// Can we efficiently find the smallest integer K such that K = 0 (mod A) and K = -1 (mod B)
	// Obviously, this is just the chinese remainder theorem!

	vector<ll> parts;
	for (ll k = 2; k*k <= n; ++k) {
		if (n % k == 0) {
			ll val = k;
			while (n % (val*k) == 0) {
				val *= k;
			}
			n /= val;
			if (val % 2 == 0) val *= 2; // to account for /2
			parts.push_back(val);
		}
	}
	if (n > 1) parts.push_back(n);

	int h = parts.size();
	for (int mask = 0; mask < (1 << h); ++mask) {
		ll a = 1, b = 1;
		for (int i = 0; i < h; ++i) {
			if (mask & (1 << i)) a *= parts[i];
			else b *= parts[i];
		}
		// Min integer that is 0 (mod a) and -1 (mod b)
		if (a == 1) res = min(res, b-1);
		else if (b == 1) res = min(res, a);
		else {
			auto tmp = crt({0, b-1}, {a, b});
			res = min(res, tmp.second.first);
		}
	}
	cout << res << '\n';
}


Measured memory_bytes: 3660
package main

import (
	"fmt"
	"sort"
)

func main() {
	var s string
	var k int
	fmt.Scan(&s, &k)
	mp := map[string]bool{}
	sr := make([]string, 0, len(s)*k)
	for i := 0; i < len(s); i++ {
		for j := 0; j < k; j++ {
			if i+j < len(s) {
				if !mp[s[i:i+j+1]] {
					sr = append(sr, s[i:i+j+1])
					mp[s[i:i+j+1]] = true
				}
			}
		}
	}
	sort.Strings(sr)
	fmt.Println(sr[k-1])
}


Measured memory_bytes: 2304
import sys
from collections import Counter

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

c = Counter(A)

num = len(c)

if num <= K:
    print(0)
else:
    ans = 0
    c = list(c.items())
    c.sort(key=lambda x: x[1])
    for i in c:
        ans += i[1]
        num -= 1
        if num <= K:
            print(ans)
            sys.exit()


Measured memory_bytes: 37760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int A[] = new int[M];
		for (int i=0;i<N;i++) {
			int K =sc.nextInt();
			for (int j =0;j<K;j++) {
				int t = sc.nextInt();
				A[t-1]++;
			}
		}
		int count=0;
		for (int i=0;i<M;i++) {
			if (A[i]==N) {
				count ++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 38460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader buf= new BufferedReader(new InputStreamReader(System.in));
		String str =buf.readLine(); //入力する桁数
		int count=Integer.parseInt(str);
		
		int[] a=new int[count];
		int[] b=new int[count];
		int[] c=new int[count];
		
		for(int i=0;i<count;i++){
			str=buf.readLine();
			a[i]=Integer.parseInt(str.split(" ")[0]);
			b[i]=Integer.parseInt(str.split(" ")[1]);
			c[i]=Integer.parseInt(str.split(" ")[2]);
		}
		buf.close();
		for(int i=0;i<count;i++){
			if(
				(a[i]< (b[i]+c[i]) )&& /*三角形の成立条件（一つの辺は、他の２辺の長さの和よりも小さい）*/
				(b[i]< (a[i]+c[i]) )&&
				(c[i]< (a[i]+b[i]) )
			){
				if(
					(a[i]*a[i]+b[i]*b[i]==c[i]*c[i])|| /*直角三角形の成立条件（ピタゴラスの定理、a＾2 + b＾2 = c＾2）*/
					(a[i]*a[i]+c[i]*c[i]==b[i]*b[i])||
					(b[i]*b[i]+c[i]*c[i]==a[i]*a[i])
				){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
			}else{
				System.out.println("NO");
			}

		}
	}
}

Measured memory_bytes: 23676
A,B = input().split()
A = int(A)
B = int(B)
if A ==1 or B ==1:
    if A == 1 and B==1:
        print("Draw")
    elif A==1 and B!=1:
        print("Alice")
    elif A!=1 and B==1:
        print("Bob")
else:
    if A>B:
        print("Alice")
    elif A<B:
        print("Bob")
    elif A==B:
        print("Draw")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

void solve() {
    ll t1, t2, a1, a2, b1, b2, ans;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    if((a1*t1+a2*t2)==(b1*t1+b2*t2)) {
        cout<<"infinity";
        return;
    }
    if((a1*t1+a2*t2)<(b1*t1+b2*t2)) {
        swap(a1, b1);
        swap(a2, b2);
    }

    ll x = (a1-b1)*t1, y = (a2-b2)*t2, k;
    if(x>0) {
        cout<<0;
        return;
    }
    ll z = x + y;
    x = (-1ll * x);
    k = 2ll * ( x / z ) + ( x % z > 0 );
    cout<<k;
}

int main()
{
    fastIO;ll t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
string s;
int ans;
int main(void){
    cin>>n>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            ans++;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3644
nm=list(map(int,input().split()))
ps=[]
for i in range(nm[1]):
    ps.append(list(input().split()))
    ps[-1][0]=int(ps[-1][0])
ac=[0]*nm[0]
wa=[0]*nm[0]
for i in range(nm[1]):
    if ps[i][1]=="AC":
        if ac[ps[i][0]-1]==0:
            ac[ps[i][0]-1]=1
        else:
            pass
    else:
        if ac[ps[i][0]-1]==0:
            wa[ps[i][0]-1]+=1
        else:
            pass
ans=0
for i in range(nm[0]):
    if ac[i]==1:
        ans+=wa[i]
print(sum(ac),ans)


Measured memory_bytes: 25052
using System;

namespace v0_0008
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while (!string.IsNullOrEmpty(line = Console.ReadLine()))
            {
                int n = int.Parse(line);
                int count = 0;
                for (int a = 0; a < 10; a++)
                {
                    if ((n - a) > 27) { continue; }
                    for (int b = 0; b < 10; b++)
                    {
                        if ((n - a - b) > 18) { continue; }
                        for (int c = 0; c < 10; c++)
                        {
                            if ((n - a - b - c) > 9) { continue; }
                            if (((n - (a + b + c)) >= 0) && ((n - (a + b + c)) < 10)) { count++; }
                        }
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 8992
#include<bits/stdc++.h>
 
using namespace std;
 
 
 
int main() {
	
	int K;
	string S;
	cin >> K >> S;
 
	int sz = S.size();
 
	if (sz <= K)
		cout << S << '\n';
	else {
		cout << S.substr(0, K) << "...\n";
	}
 
	return 0;	
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL << 60;
const int MOD = 1000000007;
struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
signed main(void){
    int n,m; cin>>n>>m;
    int x;
    UnionFind tree(100010);
    map<int,int> ma;
    rep(i,n){
        int k; cin>>k;
        int tmp = -1;
        rep(j,k){
            int l; cin>>l;
            ma[l-1]++;
            if(tmp==-1) {tmp = l; x=l; continue;}
            else {
                tree.unite(tmp-1, l-1);
            }
        }
    }
    map<int,int> ma2;
    rep(i,m){
        int r = tree.root(i);
        ma2[r]++;
    }
    int r = tree.root(x-1);
    if(ma2[r] != ma.size()) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}


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

int main(){
	string s; cin >> s;
	ll q; cin >> q;
	ll r = 1; //反転判定
	deque<char> front;
    deque<char> back;
	rep(i,q){
		ll t; cin >> t;
		if(t == 1)r *= -1;
		else {
			ll f; char c;
			cin >> f >> c;
			if(f == 1){
				if(r == 1) front.push_front(c);
				else back.push_back(c);
			}
			else {
				if(r == 1)back.push_back(c);
				else front.push_front(c);
			}
		}
	}
	if(r == -1){
		while(!back.empty()){
			cout << back.back();
			back.pop_back();
		}
		reverse(s.begin(), s.end());
		cout << s;
		while(!front.empty()){
			cout << front.back();
			front.pop_back();
		}
	}
	else {
		while(!front.empty()){
			cout << front.front();
			front.pop_front();
		}
		cout << s;
		while(!back.empty()){
			cout << back.front();
			back.pop_front();
		}

	}
}

Measured memory_bytes: 896
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll a, b, n;
  cin >> a >> b >> n;

  ll x;
  if (n < b)
    x = n;
  else {
    ll k = (n + 1) / b;
    x = b * k - 1;
  }

  ll ans = ((a * x) / b) - a * (x / b);

  cout << ans << endl;

  return 0;
}


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

#define forw(m,i,n) for(i=m; i<n; i++)
#define done return 0
#define in(x) cin >> x
#define out(x) cout << x << endl
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;

vector<int>digit;

int sizes(int n) {
    int count=0;
    while(n) {
        n=n/10;
        count++;
    }
    return count;
}


int main() {
    //freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    int n,dig,temp;
    in(n),in(dig);
    int i,x;
    forw(0,i,dig) {
        in(x);
        digit.pb(x);
    }
    int siz;
    while(1) {
        dig=n;
        siz=sizes(dig);
        bool yes=true;
        for(i=0; i<siz; i++) {
            x=dig%10;
            if(binary_search(digit.begin(),digit.end(),x)) {
                yes=false;
                break;
            }
            dig/=10;
        }

        if(yes) {
            out(n);
            return 0;
        }
        n++;
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main()
{
	int n;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
    ll dp[n+1][n+1]={0};
    

    for(int i=n-1;i>=0;i--)
    {
    	for(int j=i;j<n;j++)
    	{
    		if(i==j)
    			dp[i][j]=arr[i];
    		else
    		dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1]);
    	}
    }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main(){
    char s;
    cin>>s;
    if(s=='A'){
        cout<<'T'<<endl;
    }
    else if(s=='C'){
        cout<<'G'<<endl;
    }
    else if(s=='G'){
        cout<<'C'<<endl;
    }
    else if(s=='T'){
        cout<<'A'<<endl;
    }
}

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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int n;

int a[Sz];

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort (a + 1, a + n + 1);
  int l = 2, r = n-1;
  int left = a[1], right = a[n];
  ll ans = abs (a[1] - a[n]); 
  priority_queue <pair <int, int> > q;
  q.push ({abs (a[1] - a[r]), r});
  q.push ({abs (a[n] - a[l]), l});
  while (l <= r) {
    int x = q.top().x;
    int y = q.top().y;
    ans += x;

    int v1 = abs (left - a[y]);
    int v2 = abs (right - a[y]);
    if (v1 == x)
      left = a[y];
    else
      right = a[y];
    
    if (y == l) l++;
    else  r--;

    while (!q.empty()) q.pop();
    q.push ({abs (a[l] - left), l});
    q.push ({abs (a[r] - left), r});
    q.push ({abs (a[l] - right), l});
    q.push ({abs (a[r] - right), r});
  }
  cout << ans;
  return 0;
}






// Coded by Z..


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, L;
string S[100];

int main() {
	cin >> N >> L;
	for (int i = 0; i != N; ++i) {
		cin >> S[i];
	}
	sort(S, S + N);
	for (int i = 0; i != N; ++i) {
		cout << S[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        bool flag=false;
        int four=0,one=0,two=0;
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&a[i]);
            {
                if(a[i]%4==0) four++;
                else if(a[i]%2==0) two++;
                else one++;
            }
        }
        if(one>four+1||(one==four+1&&two!=0)) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int dp[4096][1001];
bool key[1001][12];
int price[1001];



int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++){
		int a, b;
		cin >> a >> b;
		price[i] = a;
		for (int j = 0; j < b; j++){
			int c;
			cin >> c;
			key[i][c] = true;
		}
	}
	for (int i = 0; i < 4096; i++){
		for (int j = 0; j <= 1000; j++){
			dp[i][j] = MOD;
		}
	}

	for (int i = 0; i <= m; i++) dp[0][i] = 0;
	
	for (int i = 1; i <= m; i++){
		for (int j = 0; j < (1<<n); j++){
			//choose
			int temp = 0;
			for (int k = 0; k < n; k++){
				if ((j & (1<<k)) | key[i][k+1]){
					temp += (1<<k);
				}
			}
			dp[temp][i] = min(dp[temp][i], dp[j][i-1] + price[i]);
			//not choose
			dp[j][i] = min(dp[j][i], dp[j][i-1]);
		}
	}

	if (dp[(1<<n)-1][m] != MOD) cout << dp[(1<<n)-1][m] << endl;
	else cout << -1 << endl;

	return 0;
}


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

int main(){

    ll a,b,n;
    
    cin >> a >> b >> n ;

    if(b == 1){
        
        cout << 0 << endl;
        return 0;
    }

    if(n < b){
        
        cout << (a*(n))/b << endl;
        return 0;
    }else{
        cout << a - 1 - (a/b) << endl;
    }
    
    
    return 0;
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n;
    long long int ans=0;
    cin>>n;
    for (int i=1;i*i<=n;i++) {
        if (i*i<=n&&ans<i*i) {
            ans=i*i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;

vector<int> cost(1000000);
vector<vector<int>> data(1000000);


int main(){
    int n;
    cin >> n;
    int x = (2000 - n - 1) / 200;
    cout << x+1 << endl;
}

Measured memory_bytes: 30572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.File;
import java.util.*;

public class Main {

    public static StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next().trim();
        Solver solver = new Solver();
        solver.solve(s);
        System.out.println(output.reverse());
    }

}

class Solver {
    public void solve(String s) {
        String ans = "";
        int count = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == 'B') {
                count++;
            } else {
                if (count > 0) {
                    count--;
                    continue;
                } else {
                    ans = ans.concat(Character.toString(s.charAt(i)));
                }
            }
        }
        Main.output.append(ans);
    }
}

Measured memory_bytes: 35432
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()


ans = 0
for i in B:
    tmpa = bisect.bisect_left(A, i)
    tmpc = N - bisect.bisect_right(C, i)
    ans += tmpa*tmpc
print(ans)

Measured memory_bytes: 23360
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <unordered_map>

#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

const int GETA = 502;

bool isprime[1000010];
pair<int, int> dp[1004][1004];

map<int, pair<short, short>> map1;
map<pair<short, short>, int> map2;

pair<int, int> solve(int n, int m) {
    if (n > m) return make_pair(0, 0);

    pair<short, short> &pos = map1[n];
    if (dp[pos.first][pos.second].first != -1) return dp[pos.first][pos.second];

    pair<int, int> ret = make_pair(0, 0);
    REP(i, -1, 1) {
	pair<short, short> nt = make_pair(pos.first + i, pos.second + 1);
	if (map2.find(nt) == map2.end()) continue;
	pair<int, int> res = solve(map2[nt], m);
	if (res.first > ret.first
		|| (res.first == ret.first && res.second > ret.second)) {
	    ret = res;
	}
    }
    if (isprime[n]) {
	ret.first++;
	if (ret.first == 1) {
	    ret.second = n;
	}
    }
    dp[pos.first][pos.second] = ret;
    return ret;
}

signed main() {
    rep(i, 1000001) isprime[i] = true;
    isprime[1] = false;
    REP(i, 2, 1000000) {
	if (!isprime[i]) continue;
	for (int j = 2 * i; j <= 1000000; j += i) {
	    isprime[j] = false;
	}
    }

    int x = GETA, y = GETA;
    int dir;
    int size = 1;
    int left;
    for (int pt = 1; pt <= 1000000; pt++) {
	pair<short, short> pr = make_pair(x, y);
	map1[pt] = pr;
	map2[pr] = pt;
	if (pt == size * size) {
	    x++;
	    size += 2;
	    dir = 0;
	    left = size - 2;
	} else {
	    x += dx[dir];
	    y += dy[dir];
	    left--;
	    if (left == 0) {
		dir++;
		left = size - 1;
	    }
	}
    }

    int m, n;
    while (cin >> m >> n) {
	if (m == 0) break;

	REP(i, 1, m) {
	    pair<short, short> &pr = map1[i];
	    dp[pr.first][pr.second] = make_pair(-1, 0);
	}

	pair<int, int> ret = solve(n, m);

	cout << ret.first << ' ' << ret.second << endl;
    }

    return 0;
}

Measured memory_bytes: 105680
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int n;
    cin>>n;
    int ans=0;
    int m=0;
    while(n--)
    {
    	 int x;
    	 cin>>x;
    	 m=max(m,x);
    	 ans+=x;
    }
    ans-=m/2;
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)  (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007

double tick() {
	static clock_t oldt; clock_t newt = clock(); double diff =

		1.0*(newt - oldt) / CLOCKS_PER_SEC; oldt = newt; return diff;
}
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL moduloMultiplication(LL x, LL y) {
	return (x%mod * 1LL * y%mod) %

		mod;
}
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}
inline LL inv(LL a) { return power(a, mod - 2) % mod; }
LL gcd(LL a, LL b)
{
	if (!a)
		return b % mod;
	return gcd(b%a, a) % mod;
}


int main()
{
	string s;
	cin >> s;
	rep(i, s.length()) {
		cout << 'x';
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

ll N, M;
vector<ll> A(100001, 0);

int main(void){
    
    scanf("%lld %lld", &N, &M);
    for(int i = 1; i <= N; ++i) scanf("%lld", &A[i]);
    
    map<int, int> mp;
    mp[0] = 1;
    ll ans = 0, sum = 0;
    for(int i = 1; i <= N; ++i){
        sum = (sum + A[i]) % M;
        ans += mp[sum];
        ++mp[sum];
    }
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 3968
fn main() {
    let d: i32 = read();
    let n: i32 = read();
    let s: i32 = if d == 0 { 1 } else if d == 1 { 100 } else { 10000 };

    let mut t = s;
    let mut count = 0;
    while count < n-1 {
        t += s;
        count += 1;
    }
    if t % (100 * s) != 0 {
        println!("{}", t);
    } else {
        println!("{}", t + s);
    }
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 1_000_000_007;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

pub fn max(n: i32, m: i32) -> i32 {
    if n >= m {
        n
    } else {
        m
    }
}

pub fn min(n: i32, m: i32) -> i32 {
    if n <= m {
        n
    } else {
        m
    }
}

pub fn factorial(n: u32) -> u32 {
    if n == 0 {
        return 1;
    }
    let mut r = n;
    for i in 0..n - 1 {
        r *= n - i - 1;
    }
    r
}

pub fn combination(n: u32, m: u32) -> u32 {
    factorial(n) / factorial(m) / factorial(n - m)
}


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

int main() {
	string S, T;
	cin >> S >> T;
	bool ans = 1;
	map<int,int> s, t;
	for (int i = 0; i < S.size(); i++) {
		s[S[i]]++;
		t[T[i]]++;
	}
	for (int i = 'a'; i <= 'z'; i++) {
		if (s[i] != t[i]) {
			for (int j = 'a'; j <= 'z'; j++) {
				if (s[i] == t[j]) {
					t[j] = 0; break;
				}
				if (j == 'z'){ans = 0; continue;}
			}
		}
		else t[i] = 0;
		
	}
	if(ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll X[506][506];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,M,Q;
    cin >> N >> M >> Q;
    rep(i,M){
        int l,r;
        cin >> l >> r;
        X[l][r]++;
    }
    for(int i=0;i<505;i++){
        for(int j=0;j<505;j++){
            X[i+1][j] += X[i][j];
        }
    }
    for(int i=0;i<505;i++){
        for(int j=0;j<505;j++){
            X[i][j+1] += X[i][j];
        }
    }
    rep(i,Q){
        int l,r;
        cin >> l >> r;
        cout << X[r][r] + X[l-1][l-1]  - X[r][l-1] - X[l-1][r] << endl;
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define int long long
#define M 1000000007
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    int k, n;
    cin >> k >> n;
    vi a(n);
    rep(i, 0, n)
    {
        cin >> a[i];
    }
    sort(all(a));
    int s = 0;
    for (int i = 0; i < n - 1; i++)
    {
        s = max(s, a[i + 1] - a[i]);
    }
    cout << min(k - s, (a[n - 1] - a[0]));
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  string S; cin >> S;
  int ans = 0;
  int N = S.size();
  
  vector<int> ten(N);
  ten[0] = 1;
  rep(i, N-1) ten[i+1] = (ten[i]*10)%2019;
  
  vector<int> amari(N, 0);
  unordered_map<int, int> map;
  amari[N-1] = S[N-1]-'0';

  for(int i=N-2; i>=0; i--) {
    amari[i] = (S[i]-'0')*ten[N-i-1];
    amari[i] += amari[i+1];
    amari[i] %= 2019;
  }
  
  map[0]++;
  rep(i, N) {
    map[amari[i]]++;
  }
  
  for(auto p : map) {
    int g = p.second;
    ans += g*(g-1)/2;
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 6644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) 
		cin >> A[i];
	
	vector<int> B(N + 1);
	for (int i = 0; i < N + 1; i++) 
	{
		if (i == 0) 
			B[i] = A[i];
		else if (i == N) 
			B[i] = -A[i-1];
		else 
			B[i] = A[i] - A[i - 1];
	}
	int S = 0;
	for (int i = 0; i < N + 1; i++)
	{
		S += abs(B[i]);
	}

	for (int i = 0; i < N; i++)
	{
		int ans = S - abs(B[i]) - abs(B[i + 1]) + abs(B[i] + B[i + 1]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2048
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  map<string, int> mp;
  int mx = -1;
  for (int i = 0; i < n; ++i) {
    mp[s[i]]++;
    mx = max(mx, mp[s[i]]);
  }
  vector<string> ans;
  for (auto a : mp) {
    if (a.second == mx) {
      ans.push_back(a.first);
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 28404
//B - ∵∴∵.cpp 2017/04/08
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef unsigned long long ull;

int main(){
    string o,e;
    cin >> o >> e;
        for(int i=0;i<o.length()*2;++i){
            if(i%2==0) cout << o[i/2];
            else if(i%2==1 && o.length()-e.length()==0) cout << e[i/2];
            else if(i%2==1 && o.length()-e.length()==1 && i!=o.length()*2-1) cout << e[i/2];
            else {}
        }
    cout << endl;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
K,X = map(int,input().split(' '))

st = X-(K-1)
if st<-10**6:
    st = -10**6
las = X+(K-1)
if las>10**6:
    las = 10**6

l = []
for i in range(st,las+1):
    l.append(str(i))

print(" ".join(l))

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll r;cin>>r;
  cout<<3*r*r<<endl;
  return 0;
}


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

int main()
{
	ll i,j,n,s,p=0;
	cin>>s>>n;
	for(i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		p=p+a;
	}
	if((s-p)>=0) cout<<s-p;
	else cout<<-1;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...) 
#define end_time()
#endif
 
 
#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); } 
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007
pair<int,pair<int,int>> max2(pair<int,pair<int,int>> a, pair<int,pair<int,int>> b){
	if(a.ff >= b.ff) return a;
	else return b;
}
void solve(){
	string s,t;
	cin>>s>>t;
	int n = s.length();
	int m = t.length();
	vector<vector<pair<int,pair<int,int>>>> dp(n+1,vector<pair<int,pair<int,int>>>(m+1,mp(0,mp(0,0))));
	dp[0][0] = {0,{0,0}};
	for(int i = 0; i<n; i++){
		for(int j = 0; j<m; j++){
			if(s[i]==t[j]) {
				int res = dp[i][j].ff;
				dp[i+1][j+1] = max2(dp[i+1][j+1],mp(res+1,mp(i+1,j+1)));
			}
			dp[i+1][j+1] = max2(dp[i+1][j+1],max2(dp[i][j+1],dp[i+1][j]));
		}
	}
	trace(dp[n][m].ff);
	string ans;
	int x = dp[n][m].ss.ff;
	int y = dp[n][m].ss.ss;
	for(int i = 0; i<dp[n][m].ff; i++){
		ans.pb(s[x-1]);
		int tx = dp[x-1][y-1].ss.ff;
		int ty = dp[x-1][y-1].ss.ss;
		x = tx;
		y = ty;
		trace(x,y);
	}
	reverse(all(ans));
	cout<<ans<<"\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}


Measured memory_bytes: 214336
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
//#include<chrono>
#include<random>
using namespace std;
typedef long long int llint;
const int big=1e9+100000;
const int mod=924844033;
const long double pai=3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	llint n,k,h,i,j;
	cin>>n>>k;
	vector<llint>ans(n+1);
	vector<llint>fac(n+1);
	fac[0]=1;
	for(i=1;i<=n;i++){
		fac[i]=fac[i-1]*i;
		fac[i]%=mod;
	}
	ans[0]=1;
	for(i=0;i<k;i++){
		llint sen=(n-1-i)/k;
		vector<llint>dp(sen+1),ddp(sen+1);
		dp[0]=1;//ラインが引ける
		for(j=0;j<sen;j++){
			for(h=j;h>=0;h--){
				ddp[h+1]=dp[h];
				dp[h]+=ddp[h];
				dp[h]%=mod;
				ddp[h]%=mod;
			}
		}
		for(h=0;h<=sen;h++){dp[h]+=ddp[h];}
		vector<llint>iti(2*n+1);
		for(j=0;j<=n;j++){
			for(h=0;h<=sen;h++){
				iti[j+h]+=ans[j]*dp[h];
				iti[j+h]%=mod;
			}
		}
		swap(iti,ans);
	}
	for(i=0;i<k;i++){
		llint sen=(n-1-i)/k;
		vector<llint>dp(sen+1),ddp(sen+1);
		dp[0]=1;//ラインが引ける
		for(j=0;j<sen;j++){
			for(h=j;h>=0;h--){
				ddp[h+1]=dp[h];
				dp[h]+=ddp[h];
				dp[h]%=mod;
				ddp[h]%=mod;
			}
		}
		for(h=0;h<=sen;h++){dp[h]+=ddp[h];}
		vector<llint>iti(2*n+1);
		for(j=0;j<=n;j++){
			for(h=0;h<=sen;h++){
				iti[j+h]+=ans[j]*dp[h];
				iti[j+h]%=mod;
			}
		}
		
		swap(iti,ans);
	}
	llint ret=fac[n];
	for(i=1;i<=n;i++){
		//cout<<"de ans["<<i<<"]="<<ans[i]*fac[n-i]<<endl;
		if(i%2==0){ret+=ans[i]*fac[n-i];}
		else{ret-=ans[i]*fac[n-i];}
		ret%=mod;
	}
	ret+=mod;
	ret%=mod;
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1 << 13 + 1;
const int M = 1e3 + 1;
const int inf = 1e9 + 7;
int dp[M][N];
int cost[M];
int add_mask[M];
signed main () {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> cost[i];
        int k;
        cin >> k;
        int mask = 0;
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            x--;
            mask |= (1 << x);
        }
        add_mask[i] = mask;
    }
    int fmask = (1 << n) - 1;
    for (int j = 0; j < m; j++) {
        for (int i = 0; i <= fmask; i++) {
            dp[j][i] = inf;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
        for (int mask = 0; mask <= fmask; mask++) {
            dp[i + 1][mask] = min(dp[i][mask], dp[i + 1][mask]);
            dp[i + 1][mask | add_mask[i]] = min(dp[i + 1][mask | add_mask[i]],
                                            dp[i][mask] + cost[i]);
        }
    }
    if (dp[m - 1][fmask] == inf) dp[m - 1][fmask] = -1;
    cout << dp[m - 1][fmask] << '\n';
}


Measured memory_bytes: 126080
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 n;
str a[500];

i32 main()
{
    cin >> n;
    times(n, i) {
        cin >> a[i];
    }
    i32 mink = INT_MAX;
    times(n, i) {
        i32 dotcnt = 0;
        times(n, j) {
            dotcnt += a[i][j] == '.' ? 1 : 0;
        }
        bool fillable = false;
        times(n, j) {
            if (a[j][i] == '#') {
                fillable = true;
                break;
            }
        }
        if (!fillable)
            dotcnt++;
        mink = min(mink, dotcnt);
    }
    if (mink == n+1) {
        cout << -1 << endl;
        return 0;
    }
    i32 ans = mink;
    times(n, i) {
        times(n, j) {
            if (a[j][i] == '.') {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 105;
const int MAXK = 100005;

ll n, k, a[MAXN], mod = 1e9 + 7, dp[MAXN][MAXK], pref[MAXN][MAXK];     // First val1 children have been given candies and total candies used till now is val2

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

	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<=a[0];i++) dp[0][i] = 1;
	pref[0][0] = 1;
	for(int i=1;i<=k;i++) pref[0][i] = (pref[0][i-1] + dp[0][i]) % mod;
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=k;j++)
		{
			ll st = 0;
			if(j - a[i] > 0) st = pref[i-1][j - a[i] - 1];
			dp[i][j] = (pref[i-1][j] - st + mod) % mod;
		}
		pref[i][0] = dp[i][0];
		for(int j=1;j<=k;j++) pref[i][j] = (pref[i][j-1] + dp[i][j]) % mod;
	}
	cout << dp[n-1][k] << endl;
    return 0;
}

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

using namespace std;
#define ll long long

int main() {
    int n, tmp;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int q, b, e;
    cin >> q;
    while (q--) {
        cin >> b >> e;
        reverse(a.begin() + b, a.begin() + e);
    }
    for (int i = 0; i < n; i++) {
        if (i == 0) cout << a[i];
        else cout << " " << a[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 200005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
	int out = 0,flag = 1; char c = getchar();
	while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
	while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
	return flag ? out : -out;
}
int n,k,A[maxn];
int main(){
	n = read(); k = read();
	REP(i,n) A[i] = read();
	for (int i = k + 1; i <= n; i++){
		if (A[i] > A[i - k]) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 4416
n = int(input())
h = list(map(int,input().split(" ")))
plsl = []
plsn = 0
for i in range(n-1):
    if h[i]>= h[i+1]:
        plsn += 1
    else: #i<i+1の時
        plsl.append(plsn)
        plsn = 0
plsl.append(plsn)
plsl.sort(reverse = True)
print(plsl[0])


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

int n, cnt[5];

/*
K = (X+1)*p0 + (Y+1)*p1 + (Z+1)*p2 + (K+1)*p3
K - Kp3 = (X+1)*p0 + (Y+1)*p1 + (Z+1)*p2 + p3
K (1 - p3) = (X+1)*p0 + (Y+1)*p1 + (Z+1)*p2 + p3
K = ((X+1)*p0 + (Y+1)*p1 + (Z+1)*p2 + p3) / (1 - p3)
*/

double dp[305][305][305];

double solve(int a, int b, int c){
    if(a < 0 || b < 0 || c < 0) return 0;
    if(a+b+c == 0) return 0;
    if(dp[a][b][c] != -1) return dp[a][b][c];
    double x = (1 + solve(a-1, b, c)) * a * 1.0/n;
    double y = (1 + solve(a+1, b - 1, c)) * b * 1.0/n;
    double z = (1 + solve(a, b+1, c-1)) * c * 1.0/n;
    
    double prob = (n-a-b-c) * 1.0/n;
    double k = (x+y+z+prob)/(1 - prob);
    return dp[a][b][c] = k;
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        cnt[x]++;
    }
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
            for(int k = 0; k <= n; k++)
                dp[i][j][k] = -1;
    //cout << cnt[1] << " " << cnt[2] << " " << cnt[3] << endl;
    printf("%.9lf\n", solve(cnt[1], cnt[2], cnt[3]));
	return 0;
}



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

using namespace std;

typedef long long ll;

const int N = 2e5 + 10;
int arr[N][2];
ll tree[4 * N];

void update(int node, int l, int r, int idx, ll val)
{
    if(idx > r || idx < l)
      return;
    if(l == r)
    {
      tree[node] = val;
      return;
    }
    int mid = (l + r) / 2;
    update(node * 2, l, mid, idx, val);
    update(node * 2 + 1, mid + 1, r, idx, val);
    tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}

ll query(int node, int l, int r, int st, int en)
{
  if(st > r || en < l || st > en)
    return 0;
  if(st <= l && r <= en)
    return tree[node];
  int mid = (l + r) / 2;
  return max(query(node * 2, l, mid, st ,en), query(node * 2 + 1, mid + 1, r, st, en));
}

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    cin >> arr[i][0];
  }
  for(int i = 0; i < n; i++)
  {
    cin >> arr[i][1];
  }
  for(int i = 0; i < n; i++)
  {
    ll have = query(1, 1, n, 1, arr[i][0]);
    update(1, 1, n, arr[i][0], arr[i][1] + have);
  }
  cout << query(1, 1, n, 1, n);
  return 0;
}


Measured memory_bytes: 7936