akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    if (n == 1) {
        cout << 0 << endl;
        exit(0);
    }

    map<lint, int> mp;

    lint i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            mp[i]++;
            n /= i;
        }
        else {
            i++;
        }
    }
    if (n > 1) mp[n]++;

    lint res = 0;

    for (auto [k, v] : mp) {
        int tv = v;
        for (int i = 1; tv >= i; i++) {
            tv -= i;
            res++;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}

int main(){
FIO
 ll n;
 cin>>n;
 ll mod=pow(10,9)+7;
 ll a;
 ll sum1=0;
 ll sum2=0;
 for(ll i=0;i<n;i++){
    cin>>a;
    sum1=(sum1+a)%mod;
    ll x=power(a,2,mod)%mod;
    sum2=(sum2+x)%mod;
 }
// cout<<sum1<<" "<<sum2<<endl;
 sum1=power(sum1,2,mod);

 ll temp=power(2,mod-2,mod);
 //cout<<temp<<endl;
 ll ans=(sum1-sum2+2*mod)%mod;
 ans=(ans*temp)%mod;
 cout<<ans<<endl;
}


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

using namespace std;

int a[111111];
int n;

int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
        scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);

	int an = 0;
	for(int i=1; i<=n; i++){
		int l = i, r = n;
		while(l <= r){
			int md = (l + r) >> 1;
            if(a[md] - a[i] > 2)
                r = md - 1;
			else
                l = md + 1;
		}
		an = max(an, l - i);
	}
	printf("%d",an);
	return 0;
}


Measured memory_bytes: 640
import collections
n = int(input())

array = list(map(int, input().split()))

array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()


if array_0[0][0] == array_1[0][0]:
    if len(array_0) * len(array_1) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        print(len(array) - array_1[1][1] - array_0[0][1])
        exit()
    elif array_0[0][1] < array_1[0][1]:
        print(len(array) - array_1[0][1] - array_0[1][1])
        exit()
    else:
        print(min(len(array) - array_1[0][1] - array_0[1][1], len(array) - array_1[1][1] - array_0[0][1]))
        exit()
print(len(array) - array_1[0][1] - array_0[0][1])


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

int main(){
	int n, m, l;
	cin >> n >> m >> l;

	int a[n+1][m+1] = {};
	int b[m+1][l+1] = {};

	for (int i = 1; i < n+1; i++){
		for (int j = 1; j < m+1; j++){
			cin >> a[i][j];
		}
	}

	for (int i = 1; i < m+1; i++){
		for (int j = 1; j < l+1; j++){
			cin >> b[i][j];
		}
	}

	long long int c[n+1][l+1] = {};
	for (int i = 1; i < n+1; i++){
		for (int j = 1; j < l+1; j++){
			for (int k = 1; k < m+1; k++){
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}

	for (int i = 1; i < n+1; i++){
		for (int j = 1; j < l+1; j++){
			cout << c[i][j];
			if (j != l) cout << " ";
		}
		cout << "\n";
	}

	return 0;
}


Measured memory_bytes: 3240
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		boolean flg = false;
//		高橋体力
		int A = sc.nextInt();
//		高橋攻撃力
		int B = sc.nextInt();
//		青木体力
		int C = sc.nextInt();
//		青木攻撃力
		int D = sc.nextInt();
		while(true) {
			C = C - B;
			if(C <= 0) {
				break;
			}
			A = A - D;			
			if(A <= 0) {
				flg = true;
				break;
			}
		}
		if(flg) {
			System.out.println("No");						
		}else {
			System.out.println("Yes");									
		}
	}
}

Measured memory_bytes: 27040
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>


int main(void)
{
    int64_t N;
    std::cin >> N;

    double v = 1000 * 1000 * 1000;

    double sum = 0;
    for (int64_t i = 0; i < N; ++i) {
        int64_t a;
        std::cin >> a;
        sum += v / a;
    }

    std::cout << std::setw(6) << (v/sum) << std::endl;

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize(3)

#include<bits/stdc++.h>
#define MST(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i = a ; i < b ; ++i)
#define per(i,a,b) for(int i = a ; i > b ; --i)
#define ALL(v) v.begin(),v.end()
#define ft first
#define sd second
using namespace std;
namespace fast_IO{
    const int maxbuff = 1<<17;
    char ibuff[maxbuff],obuff[maxbuff];
    inline char Getchar(){
        static char *p1=ibuff,*p2=ibuff;
        if(p1 == p2) {
            p1 = ibuff;
            p2 = ibuff+fread(ibuff,1,maxbuff,stdin);
            if(p1 == p2) return -1;
        }
        return *p1++;
    }

    int optr = 0;
    inline void Putchar(char c) {
        if(optr == maxbuff) {fwrite(obuff,1,optr,stdout);optr = 0;}
        obuff[optr++] = c;
    }

    inline void Flush() {
        fwrite(obuff,1,optr,stdout);
    }

    template<class T>
    inline int read(T &x) {
        x = 0;
        char c = Getchar();
        if(c == EOF) return -1;
        for( ; (c < '0' || c > '9') && c != EOF ; c = Getchar());
        if(c == EOF) return -1;
        for( ; c >= '0' && c <= '9' ; c = Getchar()) x = x*10+c-'0';
        return 0;
    }

    template<class T>
    inline void write(const T &x,int tag = 0) {
        if(!x) {
            if(!tag) Putchar(x+'0');
            return ;
        }
        write(x/10,1);
        Putchar(x%10+'0');
    }

    template<class T>
    inline void writeln(const T &x) {
        write(x);Putchar('\n');
    }

    template<class T>
    inline void writesp(const T &x) {
        write(x);Putchar(' ');
    }
}
template<class T> void show(T *x,int len,int s = 0) {for(int i = s ; i < s+len-1 ; ++i) cerr << x[i] << ' ';cerr << x[s+len-1] << endl;}
void debug() {cerr << endl;}
template <typename T, typename... Args> void debug(T x,Args... args) {cerr << x << ' ';debug(args...);}
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
typedef __gnu_pbds::priority_queue<pii,greater<>,pairing_heap_tag> heap;
typedef heap::point_iterator iter;

template<class T>
inline void cmin(T &A,const T &B) {A = (A<B?A:B);}
template<class T>
inline void cmax(T &A,const T &B) {A = (A>B?A:B);}

void solve() {
    LL a,b;
    string x,y;
    cin >> a >> b;
    for(int i = 1 ; i <= a ; ++i)
        x.push_back(b+'0');
    for(int i = 1 ; i <= b ; ++i)
        y.push_back(a+'0');
    cout << min(x,y) << endl;
}
signed main() {
#ifdef LOCAL
    //freopen("input","r",stdin);
    //freopen("output","w",stdout);
#endif
    srand((int)time(0));
    ios::sync_with_stdio(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int k = Integer.parseInt(strArr[1]);
		System.out.println((N - k + 1));
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 21076
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {
    static final int UNCALC = -1;
    static final long INF = (long) 1e18;
    static final int mod = (int) (1e9 + 7);
    static int n, m;
    static char[][] grid;
    static int memo[][];

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        m = sc.nextInt();
        grid = new char[n][m];
        for (int i = 0; i < n; i++)
            grid[i] = sc.next().toCharArray();
        memo = new int[n][m];
        for (int[] a : memo)
            Arrays.fill(a, UNCALC);
        out.println(Math.max(0,dp(0, 0)));
        out.flush();
        out.close();

    }

    static int dp(int x, int y) {
        if (x == n - 1 && y == m - 1) return 1;
        if (!valid(x, y)) return 0;
        if (memo[x][y] != UNCALC) return memo[x][y];
        int right = dp(x + 1, y);
        int down = dp(x, y + 1);
        return memo[x][y] = add(right,down);
    }

    static boolean valid(int x, int y) {
        return x < n && y < m && grid[x][y] != '#';
    }

    static int add(int a, int b) {
        return ((a+b) % mod);
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }


    }

}

Measured memory_bytes: 35284
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 0.000000000001
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A; cin >> A;
	long double B; cin >> B;
	cout << (int)(A*B) << endl;
	return 0;
}



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

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

  string S; cin >> S;
  vector<int> cnt(26, 0);
  for (int i = 0; i < S.size(); i++) {
    cnt[S[i] - 'a']++;
    if (cnt[S[i] - 'a'] > 1) {
      cout << "no" << '\n';
      return 0;
    }
  }
  cout << "yes" << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int MAXN = 200005;
char S[MAXN];

int main(){
  	scanf("%s", S);
  	int lastZ;
    int firstA = -1;
  	for ( int i=0; S[i]; ++i ){
    	if ( S[i] == 'A' && firstA == -1 )
          	firstA = i;
      	if ( S[i] == 'Z' )
          	lastZ = i;
    }
  	printf("%d\n", lastZ - firstA + 1);
	return 0;
}


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

int main(){
  string a = "abcdefghijklmnopqrstuvwxyz";
  char C;
  cin >> C;
  for(int i = 0; i < 25; i++){
    if(C == a[i]){
      cout << a[i+1] << endl;
      break;
    }
  }
}



Measured memory_bytes: 3552
#include <iostream>

#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>

using namespace std;
//const char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
// input - given string
// You need to update in the given string itself i.e. in input. No need to return or print.


void solver() {
    // Write your code here
    string s;
    cin>>s;
    int n=s.size();
    string my="";

    for(int i=0;i<n;i++)
    {
        if(s[i]=='0' || s[i]=='1')
        {
            my+=s[i];
        }
        else if(s[i]=='B' && my.empty()== false)
        {
            my.pop_back();
        }
    }
    cout<<my;






















}


int main() {
    int n=1;
    //cin>>n;
    while(n--)
    {
        solver();
    }
}


Measured memory_bytes: 3052
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	fmt.Println(resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	n := scanInt(sc)
	return n
}

func resolve(n int) int {
	if n < 2 {
		return 0
	}
	if isPrime(n) {
		return 1
	}
	initPow()
	num := n
	terms := map[int]int{}
	for p := range primes(n) {
		pNum := numP(n, p)
		if pNum != 0 {
			terms[p] = pNum
			num /= pow(p, pNum)
		}
	}
	if num != 1 {
		terms[num] = 1
	}
	result := 0
	for k, iN := range terms {
		if iN == 0 {
			continue
		}
		for j := 1; j <= iN; j++ {
			d := pow(k, j)
			if n%d != 0 {
				break
			}
			n /= d
			result++
		}
	}
	return result
}

var powTable map[int]map[int]int

func initPow() {
	powTable = map[int]map[int]int{}
}

func pow(n, i int) int {
	v, ok := powTable[n]
	if ok {
		if r, ok := v[i]; ok {
			return r
		}
	} else {
		powTable[n] = map[int]int{}
	}

	if i == 1 {
		return n
	}
	if i%2 == 0 {
		r := pow(n, i/2) * pow(n, i/2)
		powTable[n][i] = r
		return r
	}
	r := pow(n, i/2) * pow(n, i/2) * n
	powTable[n][i] = r
	return r
}

func isPrime(n int) bool {
	max := int(math.Sqrt(float64(n)))
	for i := 2; i <= max+1; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func numP(n, p int) (i int) {
	for n > 0 {
		if n%p != 0 {
			break
		}
		i++
		n = n / p
	}
	return i
}

func primes(n int) chan int {
	max := int(math.Sqrt(float64(n))) + 1
	isPrime := make([]bool, max)
	for i := 2; i < len(isPrime); i++ {
		isPrime[i] = true
	}

	for i := 2; i < len(isPrime); i++ {
		if !isPrime[i] {
			continue
		}
		for j := 2; j*i < len(isPrime); j++ {
			isPrime[j*i] = false
		}
	}

	ch := make(chan int)
	go func() {
		for i := 2; i < len(isPrime); i++ {
			if !isPrime[i] {
				continue
			}
			ch <- i
		}
		close(ch)
	}()
	return ch
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int X;
	cin >> X;
	int a = (X - 400) / 200;
	cout << 8 - a << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    UL dp[1001][1001];

    void Solve() {
        string S, T; cin >> S >> T;
        rep(i, S.size() + 1) dp[i][0] = i;
        rep(i, T.size() + 1) dp[0][i] = i;
        rep(i, S.size()) {
            rep(j, T.size()) {
                UL tmp = -1;
                if (S[i] == T[j]) tmp = min(tmp, dp[i][j]);
                tmp = min(tmp, dp[i + 1][j] + 1);
                tmp = min(tmp, dp[i][j + 1] + 1);
                tmp = min(tmp, dp[i][j] + 1);
                dp[i + 1][j + 1] = tmp;
            }
        }
        cout << dp[S.size()][T.size()] << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    ll ans = 0;
    FOR(a,1,N){
        ans += (N-1)/a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
    cin>>a;
    b=a;
    reverse(a.begin(),a.end());//快捷方便而又亲民的反转。
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='b') a[i]='d';//按题目要求操作。
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) printf("Yes");//判断是否与原始字符串相同。
    else printf("No");
    return 0;
}

Measured memory_bytes: 512
/*************************************************************************
	> File Name: A.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Created Time: 2020/4/4 20:36:13
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
using namespace std;
#define LL long long
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
LL gcd(LL x,LL y){
	return !y?x:gcd(y,x%y);
}
int main()
{
	LL x,y,ans;
	cin>>x>>y;
	x=x%y;
	if(x>(y-x)) ans=y-x;
	else ans=x;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
items = []
for i in range(M):
    items.append(tuple(map(int, input().split())))
p_list = list(map(int, input().split()))

tar = []
def brute_force(s, remain):
    if remain == 0:
        tar.append(s)
    else:
        brute_force(s + "0", remain - 1)
        brute_force(s + "1", remain - 1)


brute_force("", N)

ans = 0
for T in tar:
    flag = True
    for i in range(M):
        p = p_list[i]
        k = items[i][0]
        s_list = items[i][1:]
        tmp = 0
        for s in s_list:
            t = T[s-1]
            if t == "1":
                tmp += 1
        if tmp % 2 == p:
            continue
        else:
            flag = False
            break
    if flag:
        ans += 1

print(ans)






Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long int lli;

template<class T>
class Vec
{
public:
	Vec() : x(0), y(0) {}
	Vec(T ax, T ay) : x(ax), y(ay) {}

	T x, y;

	T dot(const Vec & v) const
	{
		return x * v.x + y * v.y;
	}

	T operator*(const Vec & v) const
	{
		return dot(v);
	}

	T length() const
	{
		return dot(*this);
	}

	T sum2(const Vec & v) const
	{
		return x * v.y - y * v.x;
	}

	void dump()
	{
		cout << "debug " << x << " " << y << endl;
	}
};

int main()
{
	lli S;
	cin >> S;
	Vec<lli> A, B;
	lli a = (lli)sqrt(S);
	A.x = a;
	B.y = a;
	if (A.sum2(B) != S)
	{
		A.x++;
		B.y++;
		A.y = A.sum2(B) - S;
		B.x = 1;
	}
	cout << "0 0 " << A.x << " " << A.y << " " << B.x << " " << B.y << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll n; cin>>n;
   ll x,sum=0; 
   x = n/500;
   sum+=x*1000;
   n-=x*500;
   sum+=n-(n%5);
   cout<<sum<<"\n";
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := nextInt()
	// fmt.Println(n, sc.Text())
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	var cnt int
	var ans int
	for i := 0; i < n-1; i++ {
		if h[i] >= h[i+1] {
			cnt++
			ans = max(cnt, ans)
		} else {
			cnt = 0
		}
	}
	fmt.Println(ans)
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;
const int maxn = (int)-1;

const double eps = 1e-7;
bool eq(const double &a, double const &b) { return fabs(a - b) < eps; }
bool ls(const double &a, double const &b) { return a + eps < b; }

int main ()
{
    int n;
    scanf("%d",&n);
    rep(a,1,3501) {
        rep(b,1,3501) {
            ll son = (ll)n * a * b;
            ll mom = (ll)4 * a * b - (ll)n * (a + b);
            if (mom < 1) continue;
            //dd(son); de(mom);
            if (son % mom == 0) {
                ll c = son / mom;
                return 0 * printf("%d %d %lld\n",a,b,c);
            }

        }
    }


    return 0;
}


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

// f(x) = floor(Ax/B) - A floor(x/B)
// = Ax/B - (Ax % B) / B - A (x/B - (x%B)/B) ※ floor(X/Y) = (X-X%Y)/Y = X/Y - (X%Y)/Y を使いました。
// = -(Ax%B)/B + A(x％B)/B ※ ここで、y＝x%B とおくと、y<=min(N,B-1)
// = -((Ay)％B)/B + (Ay)/B ※ Ax%B = A(x%B)%B を使いました。
// = floor(Ay/B) ※ floorの式変形を逆に使いました。

int main(void) {
    long long A, B, N;
    cin >> A >> B >> N;
    long long y = min(N, B - 1);
    cout << static_cast<long long>(A*min(N, B-1)/B) << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    char c;
    scanf("%c", &c);
    puts(c < 'a' ? "A" : "a");
}

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

# for for c = ... exit

for a in range(N + 1):
    for b in range(N - a + 1):
        c = N - a - b

        if 0 <= c <= N and 10000 * a + 5000 * b + 1000 * c == Y:
            print(a, b, c)
            exit()

print(-1, -1, -1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
cout << 0 << endl;
string s;
cin>>s;
string t = s;
ll ok = 0;
ll ng = n+1;
if(s=="Vacant") return 0;
ll q =19;
while(q--){
ll mid = (ok + ng) / 2;
cout << mid << endl;
cin >> s;
if(s=="Vacant") return 0;
if(s==t){
            if((mid-ok)%2)ng=mid;
            else ok=mid, t = s;
        }
        else{
            if((mid-ok)%2)ok=mid, t = s;
            else ng=mid;
        }
}
return 0;}


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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int n, k;
	cin >> n >> k;
	std::vector<bool> s(n, false);
	for(int i = 0; i < k; ++i){
		Int d;
		cin >> d;
		RC(j, d){
			Int a;
			cin >> a;
			s[a - 1] = true;
		}
	}
	Int count = 0;
	RC(i, n){
		count += s[i] == false;
	}
	cout << count << endl;
}


Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



string s,t,u;
long long int N,A[200005];
int main() {
	cout << fixed << setprecision(18);
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	sort(A,A+N);
	for(int i=1;i<N;i++){
		if(A[i]==A[i-1]){
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
} 

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
	int n,*in,*table,cnt = 0;


	in = new int[100000];
	table = new int[100000];

	cin >> n;

	while(n != 0){

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

	for(int i = 0; i < n; i++){
		table[i] = in[i];
		if(i%2 == 1){
			for(int j = i-1; table[j] != in[i] && j >= 0; j--){
				table[j] = in[i];
			}
		}
	}

	cnt = 0;
	for(int i = 0; i < n; i++){
		if(table[i] == 0){
			cnt++;
		}
	}

	cout << cnt << endl;

	cin >> n;
	}

	return 0;
}

Measured memory_bytes: 1960
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void AIsing2019C();

#if 1
int main()
{
	AIsing2019C();
	fflush(stdout);
	return 0;
}
#endif

static void AIsing2019C()
{
	int H, W;
	getint(H, W);

	std::vector<std::string> grid(H);
	for (int i = 0; i < H; i++) {
		std::cin >> grid[i];
	}
	std::vector<std::vector<int>> flag(H, std::vector<int>(W, 0));
	std::vector<std::pair<int, int>> pairs;

	int dh[] = { 1, -1, 0, 0 };
	int dw[] = { 0, 0, -1, 1 };
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			if ((grid[h][w] == '#') && (flag[h][w] == 0)) {
				std::pair<int, int> bwPair(0, 0);

				std::queue<std::pair<int, int>> que;
				que.push(std::pair<int, int>(h, w));

				flag[h][w] = 1;
				bwPair.first++;

				while (!que.empty()) {
					bool nowBlack = false;
					std::pair<int, int> pos = que.front(); que.pop();

					if (grid[pos.first][pos.second] == '#') {
						nowBlack = true;
					}

					for (int i = 0; i < 4; i++) {
						int nh = pos.first + dh[i];
						int nw = pos.second + dw[i];

						if ((nh >= 0) && (nw >= 0) && (nh < H) && (nw < W) && (flag[nh][nw] == 0)) {
							if ((nowBlack && (grid[nh][nw] != '#')) || (!nowBlack && (grid[nh][nw] == '#'))) {
								if (nowBlack) {
									bwPair.second++;
								}
								else {
									bwPair.first++;
								}
								flag[nh][nw] = 1;
								que.push(std::pair<int, int>(nh, nw));
							}
						}
					}
				}
				if (bwPair.second != 0) {
					pairs.push_back(bwPair);
				}
			}
		}
	}
	LLONG ans = 0;
	for (auto it = pairs.begin(); it != pairs.end(); it++) {
		ans += (LLONG)(it->first) * (LLONG)(it->second);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1280
use proconio::input;

// (x,y,z) = (100, 1, 1) => x^2+y^2+z^2+xy+yz+zx=10203
fn main() {
    input! {
        n: usize,
    }
    let mut table = vec![0; n];
    for x in 1..=100 {
        for y in 1..=100 {
            for z in 1..=100 {
                let sum: usize = x * x + y * y + z * z + x * y + y * z + z * x;
                if sum <= n {
                    table[sum - 1] += 1;
                }
            }
        }
    }
    for fi in table {
        println!("{}", fi);
    }
}


Measured memory_bytes: 2096
import sys


class Node:
    __slots__ = ['key', 'parent', 'left', 'right']

    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None

    def replace(self, child, new_child):
        if child is self.left:
            self.left = new_child
        else:
            self.right = new_child
        if new_child:
            new_child.parent = self

    def __str__(self):
        return f'({str(self.left or "_")} {self.key} {str(self.right or "_")})'


def insert(root, z):
    if root is None:
        return z

    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right

    z.parent = y

    if z.key < y.key:
        y.left = z
    else:
        y.right = z

    return root


def find(node, key):
    while node and node.key != key:
        if key < node.key:
            node = node.left
        elif key > node.key:
            node = node.right
    return node


def next_node(node):
    while node.left:
        node = node.left
    return node


def delete(root, key):
    node = find(root, key)
    if not node:
        return root
    if node is root:
        return None

    delete_node(node)
    return root


def delete_node(node):
    if not node.left and not node.right:
        node.parent.replace(node, None)
    elif node.left and node.right:
        next = next_node(node.right)
        node.key = next.key
        delete_node(next)
    else:  # node.left xor node.right
        node.parent.replace(node, node.left or node.right)


def inorder(node):
    if not node:
        return
    yield from inorder(node.left)
    yield node.key
    yield from inorder(node.right)


def preorder(node):
    if not node:
        return
    yield node.key
    yield from preorder(node.left)
    yield from preorder(node.right)


def print_tree(root):
    print(''.join(' ' + str(key) for key in inorder(root)))
    print(''.join(' ' + str(key) for key in preorder(root)))


root = None

n = int(sys.stdin.readline())
for _ in range(n):
    command, *args = sys.stdin.readline().split()
    if command == 'insert':
        root = insert(root, Node(int(args[0])))
    elif command == 'find':
        print('yes' if find(root, int(args[0])) else 'no')
    elif command == 'delete':
        root = delete(root, int(args[0]))
    else:
        print_tree(root)



Measured memory_bytes: 78712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MOD = 1e9+7;
int n, x, p;
ll ac, m, ans;
ll inv(ll n){
	ll res = 1;
	for(ll m = MOD-2; m; m/=2,(n*=n)%=MOD) if(m%2) (res *= n) %= MOD;
	return res;
}
int main(){
	scanf("%d%d", &n, &p);
	rep(i,n-1){
		scanf("%d", &x);
		p = x - p;
		(m += inv((ll)i * (i+1) % MOD)) %= MOD;
		(ac += 1 - m + MOD) %= MOD;
		(ans += ac * p % MOD) %= MOD;
		p = x;
	}
	rep(i,n-1) (ans *= i+1) %= MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int N;
  cin >> N;
  if(N%2 == 0){
   cout << N/2 - 1 <<endl; 
  }else{
   cout <<(N-1)/2 << endl; 
  }
  
return 0;
} 

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

int main() {
	lli i,j,k,n,t;
	cin>>n>>t;
	lli w[n],v[n];
	for(i=0;i<n;i++)
	cin>>w[i]>>v[i];
	lli a[n+1][t+1];
	for(i=0;i<=n;i++)
	a[i][0]=0;
	for(i=0;i<=t;i++)
	a[0][i]=0;
	for(i=1;i<=n;i++)
	{
	    for(j=1;j<=t;j++)
	    {
	        if(w[i-1]>j)
	        a[i][j]=a[i-1][j];
	        else
	        a[i][j]=max(a[i-1][j],v[i-1]+a[i-1][j-w[i-1]]);
	    }
	}
	cout<<a[n][t];
	return 0;
}

Measured memory_bytes: 82480
package main

import "fmt"

var N, K int

// 尺取法の「ある左端における右端の最大値」
var rightMax = map[int]int{}

func main() {
	fmt.Scan(&N, &K)
	ans := 0
	for i := K; i <= N+1; i++ {
		ans += max(i) - min(i) + 1
	}
	fmt.Println(ans % (1000000000 + 7))
}

func max(sel int) int {
	return (N * (N + 1) / 2) - (N-sel)*(N-sel+1)/2
}

func min(sel int) int {
	return sel * (sel - 1) / 2
}


Measured memory_bytes: 1820
a, b, c, x, y = map(int, input().split())

a_pizza = a * x
b_pizza = b * y
ans_1 = a_pizza + b_pizza

ans_2 = c * max(x, y) * 2

if x > y:
    ab_pizza_a = a * (x - y)
    ab_pizza_b = c * 2 * y
    ans_3 = ab_pizza_a + ab_pizza_b
else:
    ab_pizza_a = c * 2 * x
    ab_pizza_b = b * (y - x)
    ans_3 = ab_pizza_a + ab_pizza_b

print(min(ans_1, ans_2, ans_3))

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

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, a, n, q, k, i, m, c, u, f, j, p, r, x, y, s, b, d;
    cin >> n>>k;
    vector<int> H, v;
    v.resize(n + 1, 0);
    for (i = 1; i <= n; i++)
        cin >> v[i];
    H.resize(n + 1);
    H[1] =0;
    H[2] =abs( v[2] - v[1]);
    for (i = 3; i <= n; i++)
     {  H[i] = INT_MAX; 
        for(j=1;j<=k && j<i;j++)
        H[i]=min(H[i],abs(v[i]-v[i-j])+H[i-j]);
    
     } cout << H[n];
    // for(auto h  : H)
    // cout<<h<<" ";
    return 0;
}


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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/home/max/alg/clion_main/input.txt", "rt", stdin);
    freopen("/home/max/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define CD complex<D>
#define ll long long

// ----------------------------- CODE NOW ------------------------



signed main() {
    doRoutine();

    string s;
    cin >> s;

    int n = s.size();
    int L = 4;
    vvi dp(n + 1, vi(L + 1));


    for (int i = 1; i <= n; ++i) {
        for (int l = 1; l <= min(L, i); ++l) {
            if (l == i) {
                dp[i][l] = max(dp[i][l], 1);
            }
            else {
                for (int l2 = 1; l2 <= min(i - l, L); ++l2) {
                    if (s.substr(i - l, l) != s.substr(i - l - l2, l2)) {
                        dp[i][l] = max(dp[i][l], dp[i - l][l2] + 1);
                    }
                }
            }
        }
    }


    int ans = 0;
    for (int l = 1; l <= L; ++l) {
        ans = max(ans, dp[n][l]);
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int W, H, x, y, b=0;
  cin >> W >> H >> x >> y;
  double s;
  s = W * H /2.0;
  
  if (W == x*2 && H == y*2 ) {
    b++;
  }
  
  cout << s << " " << b << endl;
  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007, maxn = 10000;
int mul(long long a, long long b){
	return a * b % mod;
}
int pwr(long long a, long long b){
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
int fat[maxn], ifat[maxn];
void init(){
	fat[0] = 1;
	for(int i = 1; i < maxn; i++) fat[i] = mul(i, fat[i - 1]);
	ifat[maxn - 1] = pwr(fat[maxn - 1], mod - 2);
	for(int i = maxn - 2; i >= 0; i--) ifat[i] = mul(i + 1, ifat[i + 1]);
	for(int i = 0; i < maxn; i++) assert(mul(fat[i], ifat[i]) == 1);
}
int ncr(int n, int r){
	if(n < r) return 0;
	return mul(fat[n], mul(ifat[r], ifat[n - r]));
}
using ii = pair<int,int>;
using ti = tuple<int,int,int>;
int main(){
	init();
	int n, m; cin >> n >> m;
	string s; cin >> s;
	vector<int> pref(n + 1, 0);
	for(int i = 0; i < n; i++) pref[i + 1] = pref[i] + (s[i] == '1');
	vector<ii> I;
	auto contains = [](ii a, ii b){
		return a.first <= b.first && b.second <= a.second;
	};
	auto count_ones = [&](int l, int r){
		return pref[r + 1] - pref[l];
	};
	int ans = 1;
	auto propagate = [&](){
		int len = I.size();
		for(int i = 0; i < len - 1; i++) assert(I[i].first <= I[i + 1].first && I[i].second <= I[i + 1].second);
		if(len == 1){
			ans = mul(ans, ncr(I[0].second - I[0].first + 1, count_ones(I[0].first, I[0].second)));
		} else {
			vector<ii> ni, na;
			for(int i = 0; i < len; i++){
				if(i != len - 1){
					ni.push_back({I[i].first, I[i + 1].first - 1});
				} else {
					ni.push_back(I[i]);
				}
			}
			vector<int> space, inc, let;
			for(int i = 0; i < len; i++){
				space.push_back(ni[i].second - ni[i].first + 1);
				if(i == 0){
					inc.push_back(count_ones(I[i].first, I[i].second));
				} else {
					inc.push_back(count_ones(I[i-1].second + 1, I[i].second));
				}
				if(i != len - 1){
					let.push_back(I[i].second - I[i + 1].first + 1);
				} else {
					let.push_back(0);
				}
			}
			int tot_ones = 0;
			for(int v : inc) tot_ones += v;
			vector<int> f(tot_ones + 1, 0), nf(tot_ones + 1, 0);
			f[0] = 1;
			for(int i = 0; i < len; i++){
				fill(nf.begin(), nf.end(), 0);
				for(int j = 0; j <= tot_ones; j++){
					if(f[j]){
						int mn = 0, mx = j + inc[i];
						mx = min(mx, space[i]);
						for(int k = mn; k <= mx; k++){
							int pass = j + inc[i] - k;
							if(pass <= tot_ones && pass <= let[i]){
								nf[pass] += mul(f[j], ncr(space[i], k));
								if(nf[pass] >= mod) nf[pass] -= mod;
							}
						}
					}
				}
				f = nf;
			}
			ans = mul(ans, f[0]);
		}
		I.clear();
	};
	for(int i = 0; i < m; i++){
		int l, r; cin >> l >> r; l--; r--;
		ii e = {l, r};
		if(I.empty()) I.push_back(e);
		else if(I.back().second < l){
			propagate();
			I.push_back(e);
		} else {
			if(contains(I.back(), e)) continue;
			else{
				while(!I.empty() && contains(e, I.back())) I.pop_back();
				I.push_back(e);
			}
		}
	}
	propagate();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
/*
 * FileName:     least_common_multiple_fix
 * CreatedDate:  2020-07-26 13:29:54 +0900
 * LastModified: 2020-07-26 13:41:11 +0900
 */

#include <stdio.h>
#include <stdlib.h>
long int max(long int s, long int t){
    if( s>t ) return s;
    return t;
}
long int min(long int s, long int t){
    if( s<t ) return s;
    return t;
}
long int GCD(long int s, long int t){
    if( s==0 ){
        return t;
    }
    else{
        return GCD( t%s, s);
    }
}
int main(void){
    int n;scanf("%d", &n);
    long int *a = malloc(n*sizeof(long int));
    for(int i=0; i<n; i++)scanf("%ld", a+i);
    long int gcd = 0, lcm = 0;
    for(int i=1; i<n; i++){
        if( i==1 ){
            gcd = GCD(min(a[i-1], a[i]), max(a[i-1], a[i]));
            lcm = a[i-1]*a[i] / gcd;
            continue;
        }
        gcd = GCD(min(lcm, a[i]), max(lcm, a[i]));
        lcm = a[i]*lcm / gcd;
    }
    printf("%ld\n", lcm);
    free(a);
    return 0;
}



Measured memory_bytes: 2116
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim s As String = Console.ReadLine()
    Dim ans As String = "No"
    If n Mod 2 = 0 Then
      Dim t As String = s.Substring(0, n / 2)
      If s = t & t Then ans = "Yes"
    End If
    Console.WriteLine(ans)
  End Sub
End Class

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

const long long int MOD=1e9+7;
int main(){
  long long int n;
  cin>>n;
  vector<long long int> dp(n,0); //dp[i]=(rest i+1 char);
  dp[0]=n;
  long long int sum=dp[0];
  if(n!=1) dp[1]=n*n,sum+=dp[1];
  for(int i=2;i<n;i++){
    dp[i]=sum-(i-2>=0 ? dp[i-2] : 0)+((n-1)*(n-1))%MOD+n-i+1;
    dp[i]%=MOD;
    sum+=dp[i];
    sum%=MOD;
  }
  dp[n-1]=(dp[n-1]+MOD)%MOD;
  cout<<dp[n-1]<<endl;
  return 0;
}


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

int main(){
    ll N ,sum = 1;
    cin >> N;
    vector<string> kei(N);
    for(int i = 0; i < N ; ++i){
        cin >> kei.at(i);
    }
    
    sort(kei.begin(),kei.end());
    for(int i = 1; i < N ; ++i){
        if(kei.at(i) != kei.at(i-1))
            sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 9600
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
typedef pair < int , int > Pii;
int m,n;

vector < Pii > Ws;
vector < Pii > Map;

bool f = false;
void solve(int index_s,int index_m,int x,int y){
	if(index_s == m){
		printf("%d %d\n",x,y);
		f = true;
		return ;
	}
	if(index_m >= n)return ;
	if(Map[index_m].first - Ws[index_s].first == x && Map[index_m].second - Ws[index_s].second == y)solve(index_s+1,index_m+1,x,y);
	else solve(index_s,index_m+1,x,y);
	return ;
}
int main(){
	while(scanf("%d",&m),m){
		Ws.clear();
		Map.clear();
		f = false;
		for(int i = 0; i < m; i++){
			Pii p;
			scanf("%d%d",&p.first,&p.second);
			Ws.push_back(p);
		}
		stable_sort(Ws.begin(),Ws.end());
		scanf("%d",&n);
		for(int i = 0; i < n; i++){
			Pii p;
			scanf("%d%d",&p.first,&p.second);
			Map.push_back(p);
		}
		stable_sort(Map.begin(),Map.end());
		for(int i = 0; i < n; i++){
			solve(1,i+1,Map[i].first-Ws[0].first,Map[i].second-Ws[0].second);
			if(f)break;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

bool issosu(int a){
    int b = sqrt(a);
    for(int i=2;i<=b;i++){
        if(a%i == 0) return 0;
    }
    return 1;
}

int main(){
    int X; cin >> X;
    while(!issosu(X)){
        X++;
    }
    cout << X << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char ch;
	cin>>ch;
	int flag=0;
	for(int i=0;i<a.size();i++){
		if(ch==a[i]){
			flag=1;break;
		}
	}if(flag==1){
		cout<<"A";
	}else{
		cout<<"a";
	}
}

Measured memory_bytes: 3548
k = int(input())
a, b = map(int, input().split())
if a == b and a%k == 0:
    print("OK")
elif a%k == 0 or b%k == 0:
    print("OK")
elif a != b and a//k != b//k:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9180