akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#define MN 2000
#define MOD 1000000007
int F[MN+5][MN+5],f[MN*MN+5],rf[MN*MN+5];
inline int inv(int x)
{
	int y=MOD-2,r=1;
	for(;y;y>>=1,x=1LL*x*x%MOD)if(y&1)r=1LL*r*x%MOD;
	return r;
}
inline int C(int n,int m){return 1LL*f[n]*rf[m]%MOD*rf[n-m]%MOD;}
int main()
{
	int n,k,i,j;
	scanf("%d%d",&n,&k);
	if(k<2)return 0*puts("1");
	for(f[0]=i=1;i<=n*k;++i)f[i]=1LL*f[i-1]*i%MOD;
	for(rf[i=n*k]=inv(f[n*k]);i--;)rf[i]=1LL*rf[i+1]*(i+1)%MOD;
	for(F[0][0]=1,i=0;i<=n;++i)for(j=0;j<=i;++j)
	{
		if(i<n)F[i+1][j]=(F[i+1][j]+F[i][j])%MOD;
		if(j<i)F[i][j+1]=(F[i][j+1]+1LL*F[i][j]*(n-j)%MOD*C((n-j-1)*(k-1)+n-i+k-2,k-2))%MOD;
	}
	printf("%d",F[n][n]);
}

Measured memory_bytes: 47104
N, M, R = map(int, input().split())
*r, = map(lambda x:int(x)-1, input().split())
D = [[float('inf')]*N for _ in range(N)]
for i in range(N): D[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    D[a-1][b-1] = c
    D[b-1][a-1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            D[i][j] = min(D[i][j], D[i][k] + D[k][j])

import itertools
ans = float('inf')
for s in itertools.permutations(r, R):
    tot = [D[s[i]][s[i+1]] for i in range(R-1)]
    tot = sum(tot)
    ans = min(ans, tot)

print(ans)

Measured memory_bytes: 75948
#include<stdio.h>
int main(void)
{
        int n,k,s=0;
        scanf("%d%d",&n,&k);
        n-=k;
        s++;
        while(n>0){
                n-=k-1;
                s++;
        }
        printf("%d\n",s);
        return 0;
}


Measured memory_bytes: 128
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    ll sum = 0;
    for(ll i = 1; i * i <= n; i++){
        ll r = n - i;
        if(r % i) continue;
        ll d = r / i;
        if(d <= i) continue;
        sum += d;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
long long int d[100005];
int asc(const void* a, const void* b)
{
	if (d[*(int*)a] < d[*(int*)b])return 1;
	if (d[*(int*)a] > d[*(int*)b])return -1;
	return 0;
}
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i;
	int t[100005];
	for (i = 0; i < n; i++)
		scanf("%d %lld", &t[i], &d[i]);
	int c[100005];
	for (i = 0; i < n; i++)
		c[i] = i;
	qsort(c, n, sizeof(int), asc);
	int used[100005];
	for (i = 0; i <= n; i++)
		used[i] = 0;
	long long int x = 0, sum = 0;
	long long int ans;
	long long int q[100005], l = 0;
	for (i = 0; i < k; i++)
	{
		sum += d[c[i]];
		if (used[t[c[i]]] == 0)
		{
			used[t[c[i]]] = 1;
			x++;
		}
		else
		{
			q[l] = d[c[i]];
			l++;
		}
	}
	ans = sum + x * x;
	for (i = k; i < n; i++)
	{
		if (l == 0)
			break;
		if (used[t[c[i]]] == 0)
		{
			used[t[c[i]]] = 1;
			l--;
			sum -= q[l];
			sum += d[c[i]];
			x++;
			if (ans < sum + x * x)
				ans = sum + x * x;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <cstdio>
#include <string>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 100;

int N;
int X[MAX_N], Y[MAX_N], H[MAX_N];

signed main()
{
    int N;
    cin >> N;
    if(N == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A >> B;
        cout << A+B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 111111111
int main(){
  int n;
  cin>>n;
  int mi[30];
  for(int i=0;i<30;i++)mi[i]=MAX;
  for(int i=0;i<n;i++){
    int t[30]={};
    string s;
    cin>>s;
    for(int j=0;j<s.size();j++)t[s[j]-'a']++;
    for(int j=0;j<='z'-'a';j++)mi[j]=min(mi[j],t[j]);
  }
  for(int i=0;i<='z'-'a';i++){
    if(mi[i]==MAX)continue;
    for(int j=0;j<mi[i];j++)cout<<((char)(i+'a'));
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  int sum = 0;
  int l[55];
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> l[i];
  sort(l, l + N, greater<int>());
  for (int i = 0; i < K; i++) sum += l[i];
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int i,j,k;
    int board[9][9];
    int n;
    char ans[10][10];

    scanf("%d",&n);
    while(n--){
        for(i = 0;i < 9;i++){
            for(j = 0;j < 9;j++){
                scanf("%d",&board[i][j]);
            }
        }

        for(i = 0;i < 9;i++){
            for(j = 0;j < 9;j++){
                ans[i][j] = ' ';
            }
        }

        for(i = 0;i < 9;i++){
            for(j = 0;j < 9;j++){
                for(k = j+1;k < 9;k++){
                    if(board[i][j] == board[i][k]){
                        ans[i][j] = '*';
                        ans[i][k] = '*';
                    }
                    if(board[j][i] == board[k][i]){
                        ans[j][i] = '*';
                        ans[k][i] = '*';
                    }
                    if(board[i%3*3+j/3][j%3+i/3*3] == board[i%3*3+k/3][k%3+i/3*3]){
                        ans[i%3*3+j/3][j%3+i/3*3] = '*';
                        ans[i%3*3+k/3][k%3+i/3*3] = '*';
                    }
                }
            }
        }

        /*
        for(i = 0;i < 9;i++){
            for(j = 0;j < 9;j++){
                printf(" %d",board[i%3*3+j/3][j%3+i/3*3]);
                if(j%3==2)puts("");
            }
            puts("");
        }
        puts("");
        */

        for(i = 0;i < 9;i++){
            for(j = 0;j < 9;j++){
                printf("%c%d",ans[i][j],board[i][j]);
            }
            puts("");
        }
        if(n)puts("");
    }
    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
int dp[100005];
int fun(int n){
    if(n==0){
        return dp[n]=0;
    }
    if(n==1){
        return dp[n]=1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    else{
        int A=1+fun(n-1);
        int mul=6;
        int B=1e18;
        while(n-mul>=0){
            B=min(B,1+fun(n-mul));
            mul*=6;
        }
        mul=9;
        int C=1e18;
        while(n-mul>=0){
            C=min(C,1+fun(n-mul));
            mul*=9;
        }
        return dp[n]=min(A,min(B,C));
    }
}
int32_t main(){
	ios::sync_with_stdio(false);
    int n;
    memset(dp,-1,sizeof(dp));
    cin>>n;
    cout<<fun(n)<<"\n";



	return 0;
}

Measured memory_bytes: 8832
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

const int LOG = 17;

void solve() {
    int n;
    cin >> n;
    vi x(n);
    forn(i, n) cin >> x[i];
    int l;
    cin >> l;
    vvi to(LOG, vi(n));
    int j = 0;
    forn(i, n) {
        while (j + 1 < n && x[j + 1] <= x[i] + l) j++;
        to[0][i] = j;
    }
    forn1(k, LOG) {
        forn(i, n) {
            to[k][i] = to[k - 1][to[k - 1][i]];
        }
    }
    int q;
    cin >> q;
    forn(i0, q){
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        a--, b--;
        int ans = 0;
        forr(i, LOG - 1){
            if (to[i][a] >= b) continue;
            a = to[i][a];
            ans += 1 << i;
        }
        if (a < b) ans++;
        cout << ans << '\n';
    }
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 10524
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
 int n;
 cin>> n ;
 int k= n%10 ;
 if(k==2||k==4||k==5||k==7||k==9)
 cout <<"hon"<<endl ;
 else if(k==0||k==1||k==6||k==8)
 cout << "pon"<<endl ;
 else
 cout <<"bon" <<endl ;
     return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    cin >> n;
    int a[n], b[n];
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }

    int ans = INF;
    int col[n];
    rep(iii, 1<<n){
        rep(j, n) col[j] = (iii>>j) & 1;

        vector<P> podd, peven;
        rep(i, n){
            if(i%2==0){
                if(col[i]==0){
                    podd.emplace_back(make_pair(a[i], i));
                }else{
                    peven.emplace_back(make_pair(b[i], i));
                }
            }else{
                if(col[i]==0){
                    peven.emplace_back(make_pair(a[i], i));
                }else{
                    podd.emplace_back(make_pair(b[i], i));
                }
            }
        }
        if(peven.size()!= n/2) continue;
        
        sort(podd.begin(), podd.end());
        sort(peven.begin(), peven.end());

        vector<P> p;
        int ido = 0, ide = 0;
        rep(i, n){
            if(i%2==0){
                p.push_back(podd[ido]);
                ido++;
            }else{
                p.push_back(peven[ide]);
                ide++;
            }
        }

        bool ok = true;
        rep(i, n-1){
            if(p[i].first > p[i+1].first) ok = false;
        }
        if(!ok) continue;

        int cnt = 0;
        rep(i, n){
            rep(j, n){
                if(i<j){
                    if(p[i].second > p[j].second) cnt++;
                }
            }
        }
        chmin(ans, cnt);
    }

    if(ans==INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
use std::collections::HashSet;
use whiteread::parse_line;

fn main() {
    let _n: usize = parse_line().unwrap();
    let s: String = parse_line().unwrap();
    let s: Vec<u8> = s.into_bytes();
    let mut setl: HashSet<u8> = HashSet::new();
    let mut setr: HashSet<u8> = HashSet::new();
    let mut ans = 0;

    for i in 1..s.len() - 1 {
        setl.clear();
        setr.clear();
        for &c in &s[..i] {
            setl.insert(c);
        }
        for &c in &s[i..] {
            setr.insert(c);
        }
        ans = ans.max(setl.intersection(&setr).count());
    }
    println!("{}", ans);
}


Measured memory_bytes: 2132
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    long k = 1;

    for (int i = 1; i <= n; i++) {
      k *= i;
      k %= (1000000000+7);
    }

    System.out.println(k);

  }

}


Measured memory_bytes: 21844
#include <stdio.h>

int main()
{
	int n,A,B,C;
	int pm,pe,pj;
	int i;

	scanf("%d",&n);

	while(n != 0){
		A = 0; B = 0; C = 0;
		for(i = 0; i < n; i++){
			scanf("%d%d%d",&pm,&pe,&pj);	
			if(pm == 100 || pe == 100 || pj == 100){
				printf("A\n");
			}
			else if((pm+pe)/2 >= 90){
				printf("A\n");
			}
			else if((pm+pe+pj)/3 >= 80){
				printf("A\n");
			}
			else if((pm+pe+pj)/3 >= 70){
				printf("B\n");
			}
			else if((pm+pe+pj)/3 >= 50 && (pm >= 80 || pe >= 80)){
				printf("B\n");
			}
			else{
				printf("C\n");
			}
		}

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

	return 0;
}

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

int main(int argc, char* argv[]) {
    int n, cnt = 0;
    cin >> n;
    int nums[n];
    bool flag;

    for (int i = 0; i < n; i++) cin >> nums[i];

    for (int i = 0; i < n; i++){
        flag = false;
        if (nums[i] == 1) continue;
        if (nums[i] != 2 && nums[i] != 3){
            for (int j = 2; j <= (int)sqrt(nums[i]); j++){
                if (nums[i] % j == 0){
                    flag = true;
                    break;
                }
            }
        }
        if (flag == false) cnt++;
    }
    cout << cnt << "\n";
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

static const int T_MAX = (2e+5) + 10;

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

    vector<vector<int>> dp(C, vector<int>(
        T_MAX, 0
    ));

    for (int i = 0; i < N; ++i) {
        int s, t, c;
        cin >> s >> t >> c;
        --c;

        dp[c][2*s-1] += 1;
        dp[c][2*t+1] -= 1;
    }

    for (int c = 0; c < C; ++c) {
        for (int i = 0; i < T_MAX-1; ++i) {
            dp[c][i+1] += dp[c][i];
        }
    }

    int ans = 0;

    for (int i = 0; i < T_MAX; ++i) {
        int num = 0;
        for (int c = 0; c < C; ++c) {
            if (dp[c][i]) {
                ++num;
            }
        }
        ans = max(ans, num);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 24576
#include <iostream>

using namespace std;

int N;
long long T;
long long t[200000];

int main(){
    cin >> N >> T;
    for(int i=0;i<N;i++) cin >> t[i];
    long long count = T;
    for(int i=0;i<N-1;i++){
        if(t[i+1] >= t[i] + T) count += T;
        else count += t[i+1] - t[i];
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
//using namespace __gnu_pbds;

//template<typename T>
//using ordered_set =
//tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
const int N = 2e5 + 4;

int n , a[N];
ll memo[N][3];
bool v[N][3];
ll solve(int idx , int r){
   if(idx >= n)
      return (r <= 1 ? 0 : -LLONG_MAX / 2);
   ll &ret = memo[idx][r];
   if(v[idx][r])
      return ret;
   v[idx][r] = true;
   ret = -LLONG_MAX / 2;
   ret = max(ret , a[idx] + solve(idx + 2 , r));
   if(r)ret = max(ret , solve(idx + 1 , r - 1));
   return ret;
}
int main() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
#endif
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   cin >> n;
   for(int i = 0 ; i < n ;++i)
      cin >> a[i];
   cout << solve(0 , 1 + (n & 1)) << "\n";
}

Measured memory_bytes: 14388
gets
A,B,C=3.times.map{gets.split.map(&:to_i).sort}

s=B.map{|b|
  i=C.bsearch_index{|c|b<c}
  i ? C.size-i : 0
}

s<<0
(s.size-1).downto(1){|i|s[i-1]+=s[i]}

p A.map{|a|
  i=B.bsearch_index{|b|a<b}
  i ? s[i] : 0
}.inject(:+)


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

string S; int cnt = 700;

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'o') cnt += 100;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
def f(n):
    if n % 2 == 0:
        return int(n / 2)
    return 3*n + 1

s = int(input())


memo = set()
memo.add(s)
for i in range(2, 1000000):
    tmp = f(s)
    if tmp in memo:
        print(i)
        break
    memo.add(tmp)
    s = tmp


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

int main()
{
    int r;

    cin >> r;
    float l = 2 * 3.1415 * r;
    cout << l;
    return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 1e5+100;
Int dp[30][MAX];
signed main(){
  Int n,k;
  cin>>n>>k;
  if(k>=25){
    cout<<0<<endl;
    return 0;
  }
  memset(dp,0,sizeof(dp));
  for(Int i=1;i<=n;i++){
    dp[1][i]=1;
    for(Int x=1;x+1<30;x++){
      for(Int j=i+i;j<=n;j+=i){
        dp[x+1][j]+=dp[x][i];
      }
    }
  }
  Int ans=0;
  for(Int i=1;i<=n;i++) ans+=dp[k][i];
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 26564
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fe(x) for(int i=be[x];i;i=e[i].ne)
using namespace std;
int n,K,be[110000],Q,x,y,z,et;
long long d[110000];
struct edg{
	int y,z,ne;
};
edg e[210000];
inline void add_edge(int x,int y,int z){
	e[++et].y=y;
	e[et].z=z;
	e[et].ne=be[x];
	be[x]=et;
}
void dfs(int x,int fa){
	fe(x){
		int &y=e[i].y;
		if (y!=fa){ 
			d[y]=d[x]+e[i].z;
			dfs(y,x);
		}
	}
}
int main(){
	scanf("%d",&n);
	fo(i,2,n){
		scanf("%d%d%d",&x,&y,&z);
		add_edge(x,y,z);
		add_edge(y,x,z);//add_edge(y,z,x);
	}
	scanf("%d%d",&Q,&K);
	dfs(K,-1);
	fo(i,1,Q){
		scanf("%d%d",&x,&y);
		printf("%lld\n",d[x]+d[y]);
	}
	return 0;
}

Measured memory_bytes: 9984
#include <cstdio>


int main(){
	unsigned n,b,f,r;
	int v,res[4][3][10];

	for(auto &v : res){
		for(auto &v1 : v){
			for(auto &v2 : v1){
				v2 = 0;
			}
		}
	}

	scanf("%u",&n);
	for(int i=0;i<n;i++){
		scanf("%u %u %u %d",&b,&f,&r,&v);
		res[b-1][f-1][r-1]+=v;
	}

	for(int i=0;i<4;i++){

		if(i)
			printf("####################\n");

		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				printf(" %d",res[i][j][k]);
			}
			putchar('\n');
		}
	}
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N;
ll A[50];

int main() {
    fastio();
    cin >> N;
    REP(i, N) cin >> A[i];
    ll ans = 0, tmp, prev = 0, res, M = N + 1;
    while (true) {
        tmp = 0;
        REP(i, N) {
           A[i] += prev;
           res = A[i] / N;
           tmp += res;
           A[i] -= res * M;
        }
        if(tmp==0) break;
        ans += tmp;
        prev = tmp;
    }
    cout << ans << "\n";
	return 0;
}

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

int main()
{
	int N;
	std::cin >> N;
	std::vector<int> A(N);
	for(int i=0; i<N; i++)
	{
		std::cin >> A[i];
	}

	bool isOk = true;
	for(int i=0; i<N; i++)
	{
		if( A[i] % 2  == 0 )
		{
			if( A[i] % 3 != 0 ) 
			{
				if( A[i] % 5 != 0 )
				{
					isOk = false;
					break;
				}
			}
		}
	}

	if(isOk)
	{
		std::cout << "APPROVED" << std::endl;
	}
	else
	{
		std::cout << "DENIED" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#include <bitset>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
    int n;
    cin >> n;
    vector<char> C(n);
    for(int i=0;i<n;i++) cin >> C[i];
    int l=0,r=n-1;
    int ans=0;
    for(;l<r;l++){
        if(C[l]=='W'){
            for(;l<r;r--){
                if(C[r]=='R'){
                    C[l]='R';
                    C[r]='W';
                    ++ans;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    string s;
    cin >> s;
    int ans = 7-(s[0]-'0');
    vi num(3);
    FOR(i, 1, 4) num[i-1] = s[i]-'0';

    string res = "";
    res += s[0];
    FOR(i, 0, 1<<3) {
        int temp = 0;
        int ti = i;
        rep(j, 3) {
            if(ti&1) temp += num[j];
            else temp -= num[j];
            ti >>= 1;
        }
        if(temp == ans) {
            rep(j, 3) {
                if(i&1) res += "+";
                else res += "-";
                res += s[j+1];
                i>>=1;
            }
            res += "=7";
            break;
        }
    }

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

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

int main(){
  	int n,k;
  	cin>>n>>k;
	string s;cin>>s;
  	
  	for(int i=0;i<n;i++){
    	if(i+1 == k){
        	int x = s[i]-'A';
          	s[i] = 'a' + x;
        }
    }
  	cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  bool ret = false;
  for(int i=0; i<N; i++){
    char in;
    cin >> in;
    if(in == 'Y'){
      ret = true;
      break;
    }
  }
  if(ret)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 1010

using namespace std;
int n, k;
int a[M];

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	/*char s;
	cin >> s;
	if ('a' <= s && s <= 'z') puts("a");
	else if ('A' <= s && s <= 'Z') puts("A");*/
	n = read(), k = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	sort(a + 1, a + n + 1);
	int ans = 0;
	for (int i = 1; i <= k; i++) ans += a[i];
	cout << ans;
}

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

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define SQR(x)              ((x)*(x))
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)

#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
///******************************************START******************************************

/// Constants
#define MAX                 200005
#define MOD                 1000000007
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f // 4,557,430,888,798,830,399
#define inf                 0x3f3f3f3f // 1,061,109,567
#define PI                  acos(-1.0)  // 3.1415926535897932
#define VT                  int

int n, m;
int ar[12];
pii DP[MAX];
bool cc[MAX];
int pp[MAX];
int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

pii solve(int n){
    if(n<0) return {0, 0};
    if(!n) return {0, 1};
    auto &ret = DP[n];
    if(cc[n]) return ret; cc[n] = 1;
    ret = {0, 0};
    FOR(i, 0, m){
        auto tmp = solve(n - cost[ar[i]]);
        tmp.ff++;
        if(tmp>=ret and tmp.ss){
            ret = tmp;
            pp[n] = ar[i];
        }
    }
    return ret;
}

void pathPrint(int n){
    if(!n) return void();
    printf("%d", pp[n]);
    pathPrint(n - cost[pp[n]]);
}

int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    sf("%d %d", &n, &m);
    FOR(i, 0, m) si(ar[i]);
    sort(ar, ar+m);
    auto ans = solve(n);
    // printf("%d %d\n", ans.ff, ans.ss);
    pathPrint(n);
    printf("\n");

    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long;
#define dbg(x) cout<<#x<<"--------------"<<x<<endl;
#define dl cout<<"LINE"<<__LINE__<<endl;
using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int k;
	cin>>k;
	int mod=7%k;
	if(k==1||k==7){
		cout<<1<<endl;
		exit(0);
	}
	for(int i=1;i<=9999999;i++){
		mod=(mod*10+7)%k;
		if(!mod){
			cout<<i+1<<endl;
			exit(0);
		}
	}
	cout<<-1<<endl;
	
	
	
	
		
	return 0;
}

Measured memory_bytes: 3656
N = int(input())
A = list(map(int,input().split()))

A.sort()
ans = 1
mod = 10**9+7

if len(A)%2==0:
    for i in range(N//2):
        if A[i*2] == A[i*2+1] == i*2+1:
            ans *= 2
            ans %= mod
        else:
            ans = 0
            break
else:
    for i in range((N-1)//2):
        if A[i*2+1] == A[i*2+2] == (i+1)*2:
            ans *= 2
            ans %= mod
        else:
            ans = 0
            break
    if A[0]!=0:
        ans = 0

print(ans)

Measured memory_bytes: 13812
k = int(input())
a, b = map(int, input().split())
if a == b == k:
    print('OK')
elif a == b and a % k == 0:
    print('OK')
else:
    for i in range(a, (b+1)):
        if i % k == 0:
            print('OK')
            break
    else:
        print('NG')

Measured memory_bytes: 9036
#include <iostream>
#include <algorithm>

using namespace std;

int D;
const int n_type = 26;
int s_temp[n_type];
int main() {
    cin >> D;
    for(int i = 0; i < 26; i++){
        int x;
        cin >> x;
    }
    for(int d = 0; d < D; d++){
        for(int i = 0; i < 26; i++){
            cin >> s_temp[i];
        }
        int max_idx = max_element(s_temp, s_temp+n_type) - s_temp + 1;
        cout << max_idx << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
N = int(input())
A = list(map(int,input().split()))

bi = [a for a in A if a % 2 == 0]
qu = [b for b in bi if b % 4 == 0]

num_4 = len(qu)
num_2 = len(bi) - num_4

if num_2 >= 1:
	if N-num_2 <= num_4*2 or N <= num_4*2+1:
		print("Yes")
	else:
		print("No")
else:
	if N-num_2 <= num_4*2+1:
		print("Yes")
	else:
		print("No")	

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}


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


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


  vector<int> a(N);

  for(unsigned int i = 0; i < N; i++) {
      cin >> a.at(i);
  }

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int alice = 0, bob = 0;

  for(unsigned int i = 0; i < N; i++) {
      if(i % 2 == 0)
        alice += a.at(i);
      else
        bob += a.at(i);
  }

  cout << alice - bob << endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin >> n;
	cin >> s;
	int ans = 0;
	int i = 0;
	while (i < n-1) {
		size_t pos = s.find("ABC", i);
		if (pos != string::npos) {
			i = pos + 1;
			ans++;
		}
		i++;
	};
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#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;}
void dfs(ll s,vector<ll>*adj,bool*vis,ll&count){
  count++;
  vis[s]=true;
  for(auto l:adj[s]){
    if(!vis[l]){
        dfs(l,adj,vis,count);
    }
  }
  return ;
}
int main(){
FIO
 ll n,m,a,b;
 cin>>n>>m;
 vector<ll> adj[n+1];
 for(ll i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
 }
 bool vis[n+1]={false};
 ll ans=0;
 for(ll i=1;i<=n;i++){
    if(!vis[i]){
            ll count=0;
        dfs(i,adj,vis,count);
        ans=max(ans,count);
    }
 }
 cout<<ans<<endl;
}


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

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

	int ans = 0;
	if (a == b) {
		ans = 1;
	}
	else if (b == c) {
		ans = 1;
	}
	else if (a == c) {
		ans = 1;
	}
	else {
		ans = 0;
	}
	if (a == b & b == c & a == c)ans = 0;

	if (ans == 1)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// (x,y)∈[x-k+1, x]*[y-k+1, y]の範囲でimos[i][j]+=1と累積されるように値をセットする
void set_square(int x, int y, int k, vector<vector<int>> &imos){
    if(x<0 || y<0 || x>=3*k-1 || y>=3*k-1) return;
    imos[ max(0, x-k+1) ][ max(0, y-k+1) ] += 1;
    imos[ max(0, x-k+1) ][ min(y+1, 2*k) ] -= 1;
    imos[ min(x+1, 2*k) ][ max(0, y-k+1) ] -= 1;
    imos[ min(x+1, 2*k) ][ min(y+1, 2*k) ] += 1;
}

void set_imos(int x, int y, int k, vector<vector<int>> &imos){
    set_square(x, y, k, imos);
    set_square(x+2*k, y, k, imos);
    set_square(x+k, y-k, k, imos);
    set_square(x-k, y-k, k, imos);
    set_square(x+k, y+k, k, imos);
    set_square(x-k, y+k, k, imos);
    set_square(x, y+2*k, k, imos);
}

int main(){
    int n, k; cin >> n >> k;
    // 入力を受け取り、扱いやすいように希望を同値変形して座標を圧縮する
    // 具体的には全ての希望を、「(x,y)∈[0,2k)*[0,2k)を黒に塗りたいな」という希望に同値変形する
    vector<int> x(n), y(n);
    rep(i, 0, n){
        cin >> x[i] >> y[i];
        char c; cin >> c;
        if(c=='W') x[i] += k;
        x[i]%=2*k; y[i]%=2*k;
    }

    // 市松模様は[0,2k)*[0,2k)のどこを黒い部分の左下にするかという情報で一意に定まる（全単射）ので、そのように表す
    // imos[i][j] := (i,j)が黒い部分の左下になるような市松模様を塗った時に叶えられる希望の数
    vector<vector<int>> imos(2*k+5, vector<int>(2*k+5, 0));
    rep(i, 0, n){
        // (x[i],y[i])を黒に塗れるような市松模様(X, Y)について、最後に累積した時に imos[X][Y]+=1 になるように重みを加算する
        set_imos(x[i], y[i], k, imos);
    }

    // 左→右へ累積
    rep(i, 0, 2*k) rep(j, 1, 2*k) imos[i][j] += imos[i][j-1];
    // （問題文の画像で）下→上へ累積
    rep(j, 0, 2*k) rep(i, 1, 2*k) imos[i][j] += imos[i-1][j];

    // 最大値の検索
    int ans=0;
    rep(i, 0, 2*k) rep(j, 0, 2*k) chmax(ans, imos[i][j]);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 16768
//fifer a tak luboin
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mp make_pair
#define pb push_back
#define s second
#define f first
#define endl "\n"

// using namespace __gnu_pbds;
using namespace std;
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

const ll inf = (ll)1e14;
const double eps = 1e-10;                                     
const double pi = acos(-1.0);

pair <int, int> a[10];
double dist(pair<int, int> A, pair<int, int> B) {
    double x1 = A.f;
    double y1 = A.s;
    double x2 = B.f;
    double y2 = B.s;
    return (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    vector <int> v;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].f >> a[i].s;
        v.pb(i);
    }

    double sum = 0;
    int cnt = 0;
    do {
        cnt++;
        for (int i = 1; i < v.size(); i++) {
            sum += dist(a[v[i - 1]], a[v[i]]);
        }
    } while (next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(7) << sum / (cnt * 1.0)  << endl;

    return 0; 
}

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

using namespace std;

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

#define X first
#define Y second

const int N=2e3+10;


int n,m;
string s;
int a[N][N],be[3][N][N];

int get(int type,int xa,int ya,int xb,int yb){
    if (xa>xb||ya>yb) return 0;
    return be[type][xb][yb]+be[type][xa-1][ya-1]-be[type][xa-1][yb]-be[type][xb][ya-1];
}
int cal(int xa,int ya,int xb,int yb){
    return get(2,xa,ya,xb,yb)-get(1,xa,ya+1,xb,yb)-get(0,xa+1,ya,xb,yb);
}
int main(){
    int test;
    cin>>n>>m>>test;
    for(int i=1;i<=n;i++){
        cin>>s;
        for(int j=1;j<=m;j++) a[i][j]=s[j-1]-'0';
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) be[2][i][j]=a[i][j]+be[2][i-1][j]+be[2][i][j-1]-be[2][i-1][j-1];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            for(int k=0;k<=1;k++)
                be[k][i][j]=be[k][i-1][j]+be[k][i][j-1]-be[k][i-1][j-1];
            if (a[i][j]){
                if (a[i][j]==a[i-1][j]) be[0][i][j]++;
                if (a[i][j]==a[i][j-1]) be[1][i][j]++;
            }
        }
    while (test--){
        int xa,ya,xb,yb;
        cin>>xa>>ya>>xb>>yb;
        printf("%d\n",cal(xa,ya,xb,yb));
    }
}


Measured memory_bytes: 64896
#define _'			'
A[_];long P[_],M=1e9+7,F[_],I[_],X;i,j,k,t;p(a,b){return b?p(a%M*a%M,b/2)*(b%2?a:1L)%M:1;}f(a,b){return F[a+b]*I[a]%M*I[b]%M;}main(s){for(*I=1;++X<_;~scanf("%d",A+i)&&i++%2&&gets(P))I[X]=p(s=F[X]=X*s%M,M-2);for(qsort(A,i/2,8,"H\x8bH+tH\x99\x92 Ð");j<i;P[j++-1]=X)for(X=f(t=--A[++j],s=--A[k=j]);k;X=s<A[k-=2]?X:(X-f(s-A[k],t-A[k+1])*P[k]%M+M)%M);printf("%d",X);}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const ll mod = 1e9+7;
const int N = 2e5+5;
void solve(){
    string s;
    cin>>s;
    for(auto x:s){
        if(x=='?')cout<<'D';
        else cout<<x;
    }
    cout<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    scanf("%d",&t);
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3748
X=int(input())

f=False
a=X
if X==2 or X==3:
    print(X)
    exit()
while f==False:
    for i in range(2,int(a**0.5)+1):
        if a%i==0:
            break
        if i==int(a**0.5):
            f=True
    a+=1
print(a-1)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

#define ran 202222

struct BIT {
    int max_val;
    int a[ran];
    const static int mo = 1000000007;

	BIT() { max_val = ran; }
    BIT(int maxv) { max_val = maxv; }

    inline int lowbit(int x) { return x & (-x); }
    inline int madd(int a, int b) {
		return a+b;
        return (a+=b) >= mo ? a-mo : (a<0 ? a+mo : a);
    }

    void clear() { memset(a, 0, sizeof(a)); }
    void clear(int max_id) {
        for(int i=0;i<=max_id;i++) a[i]=0;
    }

    void add(int pos, int val) {
        for (pos = max(1, pos); pos <= max_val; pos += lowbit(pos))
            a[pos] = madd(a[pos], val);
    }

    int query(int pos) {
        int res = 0;
        for (; pos; pos -= lowbit(pos))
            res = madd(res, a[pos]);
        return res;
    }

    int query(int l, int r) {
        return query(r) - (l ? query(l-1) : 0);
    }
} b;

int n;
char s[ran];
vector<int> v[33];
int st[33], ed[33];

int get_st(int id) {
	return v[id][st[id]];
}
int get_ed(int id) {
	return v[id][ed[id]];
}

void rm(int id) {
	b.add(get_st(id), -1);
	b.add(get_ed(id), -1);
	st[id]++; ed[id]--;
}

int main() {
	scanf("%s", s);
	n = strlen(s);
	
	b.clear();
	for(int i=0;i<n;i++) {
		int id = s[i] - 'a';
		v[id].push_back(i+1);
	}
	int odd = 0;
	for(int i=0;i<26;i++) {
		if ((int)v[i].size()%2==1) odd++;
		st[i] = 0; ed[i] = (int)v[i].size()-1;
	}
	if (odd > 1) {
		puts("-1");
		return 0;
	}
	
	long long ans = 0;
	for(int i=1;i<=n;i++) b.add(i, 1);
	for(int l = 1, r = n; l<r; l++, r--) {
		int vl = -1, vr = -1;
		for(int i=0;i<26;i++) {
			if (st[i] > ed[i]) continue;
			if (vl == -1 || get_st(vl) > get_st(i)) vl = i;
			if (vr == -1 || get_ed(vr) < get_ed(i)) vr = i;
		}
		if (vl==vr) {
			rm(vl);
			continue;
		}
		
		int costl = ed[vl] > st[vl] ? b.query(get_ed(vl), n)-1 : n+1;
		int costr = ed[vr] > st[vr] ? b.query(1, get_st(vr))-1 : n+1;
		// printf("%c %c %d %d\n", vl+'a', vr+'a', costl, costr);
		if (costl < costr) {
			ans += costl;
			rm(vl);
		} else {
			ans += costr;
			rm(vr);
		}
	}
	printf("%lld\n", ans);
	
	return 0;
}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

bool compare_second_disc(pair<int,int> a,pair<int,int> b){
    if(a.second != b.second) return a.second > b.second;
    else a.first > b.first;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> R(n);  //(x,y)
    vector<pair<int,int>> B(n);  //(x,y)
    rep(i,0,n) cin >> R[i].first >> R[i].second;
    rep(i,0,n) cin >> B[i].first >> B[i].second;
    sort(all(R),compare_second_disc);
    sort(all(B));
    int cnt = 0;
    vector<bool> use(n,false);

    rep(i,0,n){
        rep(j,0,n){
            if(use[j]) continue;
            if(R[j].first < B[i].first && R[j].second < B[i].second){
                cnt++;
                use[j] = true;
                break;
            }
        }
    }
    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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


#include<atcoder/all>
using namespace atcoder;

int main(){
    int n;
    cin >> n;
    n *= 2;
    map<int,int> mp;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }
    vector<int> p;
    for(auto x:mp){
        p.push_back(x.second);
    }
    vector<modint998244353> fac(100001);
    vector<modint998244353> two(100001);
    fac[0] = 1;
    two[0] = 1;
    for(int i=1;i<=100000;i++){
        fac[i] = fac[i-1] * i;
    
        two[i] = two[i-1]*2;
    }
    priority_queue<pair<int,int> > pq;
    vector<vector<modint998244353> > A;
    int id = 0;
    for(auto m:p){
        int xx = m/2;
        vector<modint998244353> s;
        for(int i=0;i<=m/2;i++){
            s.push_back(fac[m]/(two[i]*fac[m-2*i]*fac[i]));
        }
        A.push_back(s);
        pq.push({-(int)s.size(),id});
        id++;
    }
    while(pq.size()!=1){
        auto x = pq.top();
        pq.pop();
        auto y = pq.top();
        pq.pop();
        int aa = x.second;
        int bb = y.second;
        A[aa] = convolution(A[aa],A[bb]);
        pq.push({-(int)A[aa].size(),aa});
    }
    auto dp  = A[pq.top().second];
    int N = dp.size();
    modint998244353 res=0;
    rep(i,N){
        if(i%2==0){
            res += dp[i] * fac[n-2*i]/(two[(n-2*i)/2]*fac[(n-2*i)/2]);
        }else{
            res -= dp[i] * fac[n-2*i]/(two[(n-2*i)/2]*fac[(n-2*i)/2]);
        }
    }
    cout << res.val() << endl;
    return 0;
}

Measured memory_bytes: 15436
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}

Measured memory_bytes: 892