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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> red(N), blue(N);
  vector<bool> used(N, false);
  for (int i = 0; i < N; i++) {
    int a, b; cin >> a >> b;
    red[i] = {b, a};
  }  
  for (int i = 0; i < N; i++) {
    int c, d; cin >> c >> d;
    blue[i] = {c, d};
  }
  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end());

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int b_x = blue[i].first, b_y = blue[i].second;
    for (int j = N - 1; j >= 0; j--) {
      int r_x = red[j].second, r_y = red[j].first;
      if (used[j]) continue;
      if (r_x >= b_x) continue;
      if (r_y < b_y) {
        ans++;
        used[j] = true;
        break;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main(void){
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  vector<int> h(H), w(W);
  for(int i = 0; i < H; i++){
    cin >> a[i];
    for(int j = 0; j < W; j++){
      if(a[i][j] == '#'){
        h[i]++;
        w[j]++;
      }
    }
  }
  for(int i = 0; i < H; i++){
    if(h[i] == 0) continue;
    for(int j = 0; j < W; j++){
      if(w[j] == 0) continue;
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

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

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H+1);
    rep(i, 0, H) {
        cin >> a[i];
    }
    ll dp[H+1][W+1];
    rep(h, 0, H) {
        rep(w, 0, W) {
            dp[h][w] = -1;
            if (a[h][w] == '#') {
                dp[h][w] = 0;
            }
        }
    }
    rep(i, 0, W) {
        bool flag = false;
        if (a[0][i] == '#') {
            flag = true;
        }
        if (flag) {
            dp[0][i] = 0;
        }
    }

    rep(i, 0, H) {
        bool flag = false;
        if (a[i][0] == '#') {
            flag = true;
        }
        if (flag) {
            dp[i][0] = 0;
        }
    }
    dp[0][0] = 1;
    rep(h, 0, H) {
        rep(w, 0, W) {
            if (a[h][w] == '.') {
                if (w == 0 && h == 0) continue;
                ll res1 = 0;
                if (w-1 >= 0) {
                    res1 = dp[h][w-1];
                }

                ll res2 = 0;
                if (h-1 >= 0) {
                    res2 = dp[h-1][w];
                }
                if (h-1 >=0 || w-1 >= 0) {
                    dp[h][w] = (res1 + res2) % MOD;
                }
            }
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 9088
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]

def check(p):
    global n,k,w
    j = 0
    for i in range(k):
        sum = 0                  # 新たなトラックになるたび,トラックに積まれている積載量を0に更新するよ
        while (sum + w[j]) <= p: # もし次の荷物を載せたら最大積載量を超えないか？？(まだsumは更新しないよ！)
            sum += w[j]          # 超えなかったからsumに加算するよ
            j += 1               # 載せられたから,jをインクリメントするよ
            if j == n:
                return n
    return j
left = 0
right = 10**9 - 1
while (right - left) > 1:
    mid = (left + right) // 2
    v = check(mid)
    if v >= n:
        right = mid
    else:
        left = mid
print(right)


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int Gab = abs(A - B);
  int Gbc = abs(B - C);
  int Gca = abs(C - A);
  
  if (Gca <= D) cout << "Yes" << endl;
  else if (Gab <= D && Gbc <= D) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 384
#include<cstdio>
int c[3003][3003];
int n,mod,p2[3003],pp2[3003];
int add(int x,int y){
	return (int)(((long long int)(x)+y)%mod);
}
int sub(int x,int y){
	return add(x, mod-y);
}
int mul(int x,int y,int mod){
	return (int)((long long int)x*y%mod);
}
int mul(int x,int y){
	return mul(x,y,mod);
}
int s2[3003][3003];
int calc(int x){
	int w = p2[n-x], res = 0;
	for(int k=x; k>=0; k--){
		res = add(mul(res, p2[n-x]), s2[x][k]);
	}
	res = mul(res, pp2[n-x]);
	return res;
}
int main(){
	scanf("%d%d",&n,&mod);
	p2[0] = 1; pp2[0] = 2;
	for(int i=1; i<=n; i++){
		p2[i] = add(p2[i-1], p2[i-1]);
		pp2[i] = mul(pp2[i-1], pp2[i-1]);
	}
	for(int i=0; i<=n; i++)
		for(int j=0; j<=i; j++){
			c[i][j] = j==0||j==i?1:add(c[i-1][j],c[i-1][j-1]);
			s2[i][j] = j==0||j==i?1:add(s2[i-1][j-1], mul(s2[i-1][j],j+1));
		}
	int res = 0;
	for(int i=0; i<=n; i++){
		int tmp = mul(c[n][i], calc(i));
		if(i%2)
			res = sub(res, tmp);
		else
			res = add(res, tmp);
	}
	printf("%d\n",res);
	return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int a,b,A,B;cin>>a>>b>>A>>B;

    cout<<(a-A)*(b-B)<<endl;

}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j)
      printf("%d ", __builtin_ctz(i ^ j) + 1);
    putchar('\n');
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 512
class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    @property
    def eye(self):
        return self._eyes[1]

    def roll(self, direction):
        old = self._eyes
        new = ['dummy'] * 7
        if direction == 'N':
            new[1] = old[2]
            new[2] = old[6]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[1]
            new[6] = old[5]
        elif direction == 'S':
            new[1] = old[5]
            new[2] = old[1]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[6]
            new[6] = old[2]
        elif direction == 'W':
            new[1] = old[3]
            new[2] = old[2]
            new[3] = old[6]
            new[4] = old[1]
            new[5] = old[5]
            new[6] = old[4]
        elif direction == 'E':
            new[1] = old[4]
            new[2] = old[2]
            new[3] = old[1]
            new[4] = old[6]
            new[5] = old[5]
            new[6] = old[3]
        else:
            raise ValueError('NEWS箱推し')
        self._eyes = new


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)



Measured memory_bytes: 5576
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 300010;
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int cnt = 0, n;
	cin >> n;
	int mx = 0;
	while (n--) {
		int a, b;
		cin >> a >> b;
		if (a == b) ++cnt;
		else cnt = 0;
		mx = max(mx, cnt);
	}
	puts(mx >= 3 ? "Yes": "No");

}



Measured memory_bytes: 3560
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    int x = tx - sx;
    int y = ty - sy;

    REP(i, x){
        cout << 'R';
    }

    REP(i, y){
        cout << 'U';
    }

    REP(i, x){
        cout << 'L';
    }

    REP(i, y){
        cout << 'D';
    }

    cout << 'D';

    REP(i, x+1){
        cout << 'R';
    }
    
    REP(i, y+1){
        cout << 'U';
    }

    cout << 'L';
    cout << 'U';

    REP(i, x+1){
        cout << 'L';
    }

    REP(i, y+1){
        cout << 'D';
    }

    cout << 'R';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
	cin>>a>>b;
    if(a>0)
		cout<<"Positive";
    else if(a==0||(a<0&&b>0))
		cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)
		cout<<"Positive";
    else
		cout<<"Negative";
	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int64
	fmt.Scan(&N)

	for n := int64(1); n <= 3500; n++ {
		for w := int64(1); w <= 3500; w++ {
			q := int64(N * n * w)
			p := int64(4*n*w - N*w - N*n)
			if p < 1 {
				continue
			}
			if q%p == 0 {
				fmt.Println(q/p, n, w)
				return
			}
		}
	}
}

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

int main(){
  int a,b,c,d,e;
  bool ans;
  cin >> a >> b >> c >> d;
  if(b<c||d<a){
    ans=false;
  }else{
    e=min(b,d)-max(a,c);
    ans=true;
  }
  if(ans){
    cout << e << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x,y,z=gsmi
puts [z,x,y].join(" ")

Measured memory_bytes: 3836
N = int(input())
A = list(map(int, input().split()))
each = [0] * N

for i in range(N):
  if i + 1 == A[i]:
    each[i] = 1
    
#print(each)
ans = 0
for i in range(N):
  if i < N - 1:
    if each[i] == 1:
      if each[i + 1] == 1:
        ans += 1
        each[i + 1] = 0
      else:
        ans += 1
  else:
    if each[i] == 1:
      ans += 1
  #print(each, ans)      
print(ans)


Measured memory_bytes: 20604
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
  ll n;
  std::cin >> n;
  VEC(ll,a,n);
  VEC(ll,b,n);
  ll c1=0,c2=0;
  rep(i,n){
    if(a[i]>b[i])c2+=(a[i]-b[i]);
    if(a[i]<b[i])c1+=(b[i]-a[i])/2;
  }

  if(c2>c1)std::cout << "No" << std::endl;
  else std::cout << "Yes" << std::endl;
}

Measured memory_bytes: 384
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



def div(a, b):
    if a % b:
        return a // b + 1
    return a // b


def main():
    n = I()
    xy = LIR(n)
    x, y = 1, 1
    for nxt_x, nxt_y in xy:
        ratio_x = div(x, nxt_x)
        ratio_y = div(y, nxt_y)
        mul = math.ceil(max(ratio_x, ratio_y))
        x = mul * nxt_x
        y = mul * nxt_y
    return x + y


print(main())

Measured memory_bytes: 40560
#include <stdio.h>
#define max(X, Y) ((X)>(Y)?(X):(Y))

double p[32][10010];
int main(void)
{
    int N, M, K;
    while (scanf("%d%d%d", &N, &M, &K), N) {
        int i, j, k;
        double res;
        for(i=0;i<=N;++i) for(j=0;j<=N*M;++j) p[i][j]=0;
        p[0][0]=1;
        for(i=1;i<=N;++i) {
            for(j=1;j<=N*M;++j) {
                p[i][j]=0;
                for(k=1;k<=M;++k) if (j>=k) p[i][j]+=p[i-1][j-k];
                p[i][j]/=M;
            }
        }
        res=0;
        for(i=1;i<=N*M;++i) res+=max(i-K, 1)*p[N][i];
        printf("%.8f\n", res);
    }
    return 0;
}

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

int main(){
    int N, res=0;
    
    cin >> N;
    vector<vector<int>> vr(N,vector<int> (2)),vb(N,vector<int> (2));
    for (int i=0;i<N;i++){
        cin >> vr[i][0] >> vr[i][1];
        }
    for (int i=0;i<N;i++){
        cin >> vb[i][0] >> vb[i][1];
        }


    sort(vb.begin(),vb.end(), [](auto& x, auto& y){return x[0] < y[0];});
    sort(vr.rbegin(),vr.rend(), [](auto& x, auto& y){return x[1] < y[1];});
    for (int i=0;i<N;++i){
        int x = vb[i][0],y = vb[i][1];
        for (int j=0;j<vr.size();++j){
            if (vr[j][0] >= x | vr[j][1] >= y){
                continue;
            }
            else {
                vr.erase(vr.begin()+j);
                res += 1;
                break;
            }

        }
    }
    cout << res << endl;

    //sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});

}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[])
{
    long mtxA[101][101] = {0};
    long mtxB[101][101] = {0};

    int n, m, l;
    scanf("%d %d %d", &n, &m, &l);

    // input matrixA[n][m]
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++)
            scanf("%ld", &mtxA[x][y]);

    // input matrixB[m][l]
    for (int i = 0; i < m; i++)
        for (int j = 0; j < l; j++)
            scanf("%ld", &mtxB[i][j]);

    long row[101] = {0};
    long col[101] = {0};
    for (int mtxArow = 0; mtxArow < n; mtxArow++)
    {
        for (int mtxAcol = 0; mtxAcol < m; mtxAcol++)
            row[mtxAcol] = mtxA[mtxArow][mtxAcol];

        for (int y = 0; y < l; y++)
        {
            for (int x = 0; x < m; x++)
                col[x] = mtxB[x][y];

            long sum = 0;
            for (int s = 0; s < m; s++)
                sum += row[s] * col[s];

            printf("%lld", sum);

            if (y != l - 1)
                printf(" ");
            else
                printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int N, M; 
cin >> N >> M; 
long long int X[114514] = {}; 
long long int Y[114514] = {}; 
long long int P[114514] = {}; 
long long int Q[114514] = {};
long long int H, W;  
for (long long int i = 0; i < N; ++i){
cin >> X[i];
}
for (long long int j = 0; j < M; ++j){
cin >> Y[j];
}
for (long long int i = 1; i < N; ++i){
P[i] = X[i] - X[i-1];
H = (H + (((i * (N-i)) % 1000000007) * P[i]) % 1000000007) % 1000000007; 
}
for (long long int j = 1; j < M; ++j){
Q[j] = Y[j] - Y[j-1];
W = (W + (((j * (M-j)) % 1000000007) * Q[j]) % 1000000007) % 1000000007; 
}
cout << (H * W) % 1000000007 << endl; 
}

Measured memory_bytes: 2556
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m,x,y=INTM()
    xs=LIST()
    xs.append(x)
    ys=LIST()
    ys.append(y)
    #print(xs,ys)
    if max(xs)>=min(ys):
        print('War')
    else:
        print('No War')
    
    
if __name__ == '__main__':
    do()

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

typedef long long ll ;

const ll MOD = 1000000007;

ll dp[2100][2100];
ll sum[2100][2100];

int main() {

  int N,M;
  cin >> N >> M;
  vector< int > S(N+3),T(M+3);
  REP(i,N) cin >> S[i];
  REP(i,M) cin >> T[i];

  dp[0][0] = 1;
  sum[0][0] = 1;

  // dp[i][j] : S[i-1],T[j-1]で終わる部分文字列数
  //            i=0,j=0 は 空文字 に充てる
  // sum[i][j] : dp[i][j]位置までの2次元累積和
  for(int i=0; i<N+1; ++i) {
    for(int j=0; j<M+1; ++j) {
      if ( i!=0 && j!=0 ) {
        if (S[i-1] == T[j-1]) dp[i][j] = sum[i-1][j-1];

        sum[i][j] = (sum[i-1][j] + sum[i][j-1]) % MOD;
        sum[i][j] = (sum[i][j] + dp[i][j]) % MOD;
        sum[i][j] -= sum[i-1][j-1];
        if ( sum[i][j] < 0 ) {
          sum[i][j] += MOD;
        }
      } else {
        sum[i][j] = 1;
      }
    }
  }
  cout << sum[N][M] << endl;

}


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

int main(){
  long N;cin>>N;
  string S;cin>>S;
  vector<vector<int>> appeared_l(N,vector<int>(10,0));
  for(int i=1;i<N;i++){
    appeared_l[i]=appeared_l[i-1];
    appeared_l[i][(char)S[i-1]-48]=1;
  }
  vector<vector<int>> appeared_r(N,vector<int>(10,0));
  for(int i=N-2;i>=0;i--){
    appeared_r[i]=appeared_r[i+1];
    appeared_r[i][(int)S[i+1]-48]=1;
  }
  vector<int> aw(10*10*10,0);
  
  for(int i=1;i<N-1;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        if(appeared_l[i][j]&&appeared_r[i][k]){
          aw[j*100+((int)S[i]-48)*10+k]=1;
        }
      }
    }
  }
  int ans=0;
  for(int i:aw)ans+=i;
  cout<<ans;
}

Measured memory_bytes: 4480
N, X, M = map(int, input().split())
Memo = [-1] * M
Cumsum = [0] * M
cumsum = X
x = X

for i in range(N):
    if Memo[x] != -1:
        break
    Memo[x] = i
    Cumsum[x] = cumsum
    x = x * x % M
    cumsum += x
else:
    print(cumsum-x)
    exit()
loop_length = i - Memo[x]
init_sum = Cumsum[x]
loop_sum = cumsum - init_sum

n_from_init = N - i - 1
n_loops, n_from_loopend = divmod(n_from_init, loop_length)
cumsum += n_loops * loop_sum

for i in range(n_from_loopend):
    x = x * x % M
    cumsum += x

print(cumsum)


Measured memory_bytes: 14100
A, B = map(int, input().split())
cards = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "1"]

for i in range(13):
    if int(cards[i]) == A:
        alice = i
    if int(cards[i]) == B:
        bob = i

if alice > bob:
    print("Alice")
elif bob > alice:
    print("Bob")
else:
    print("Draw")


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

int main()
{    
    int i,j;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++){
        if(s[i]=='A')
        break;
    }
    for(j=s.size()-1;j>=0;j--){
        if(s[j]=='Z')
        break;
    }
    cout<<j-i+1<<endl;
    return 0;
  }

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
const int INF = 100000000;

int main(){
    int k, x;
    cin >> k >> x;

    if(500*k >= x){
        cout <<"Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
int main()
{ 
    cool;
    int n,i,ans=0;
    cin>>n;
    int a[n+1],b[n+1],c[n];
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    cin>>b[i];
    for(i=1;i<=(n-1);i++)
    cin>>c[i];
    a[0]=-1;
    for(i=1;i<=n;i++)
    {
    	if((a[i]-a[i-1])!=1)
    	{
    		ans+=b[a[i]];
		}
		else if((a[i]-a[i-1])==1)
		{
			ans+=(b[a[i]]+c[a[i-1]]);
		}
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        a: i64,
        v: i64,
        b: i64,
        w: i64,
        t :i64
    }

    if a == b {
        println!("YES");
    } else if a > b {
        let away = b - w * t;
        let oni = a - v * t;

        if oni <= away {
            println!("YES");
        } else {
            println!("NO");
        }
    } else {
        let away = b + w * t;
        let oni = a + v * t;

        if oni >= away {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

int needChanging(string s, string t, int offset){
  int ret=0;
  for(int i=0;i<(int)(t.length());i++){
    if(s[i+offset]!=t[i]){
      ret++;
    }
  }
  return ret;
}

int main(){
  string s,t;
  cin>>s>>t;
  int res=t.length();
  for(int i=0;i<=(int)(s.length()-t.length());i++){
    int temp=needChanging(s, t, i);
    if(res>temp){
      res=temp;
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		int max = 0;
		for(int i = 0;i < S.length()/2;i++) {
			String key = S.substring(0,i+1);
			if(2*i > S.length()) {
				continue;
			}
			if((key.equals(S.substring(i+1, 2*i+2)))
					&&key.length() != S.length()/2) {
				max = 2 * key.length();
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string s;
    cin >> s;
    if (s <= "2019/04/30") {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include "stdio.h"

long long int GCD(long long int a, long long int b)   //最大公?数
{
	long long int n=1,a1,b1;
	a1 = a; b1 = b;
	while (n != 0)
	{
		n = a1%b1;
		a1 = b1;
		b1 = n;
	}
	return a1;
}
long long int LCM(long long int a, long long int b)    //最小公倍数
{
	long long int n ;
	n = (a*b) / GCD(a, b);
	return n;
}
int main()
{
	long long int a, b;
	while ((scanf("%lld %lld", &a, &b)) != EOF)
	{
		printf("%lld ", GCD(a, b));
		printf("%lld\n", LCM(a, b));
	}
	return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, K; cin >> N >> K;
    vector<string> P(N); for (auto &p : P) cin >> p;
    int cnt[26] = {};
    for (auto &p : P) {
        cnt[p[0] - 'A']++;
    }
    int ans = 0;
    for (int i = 0; i <= N / K; i++) {
        int t = 0;
        for (int j = 0; j < 26; j++) {
            t += min(i, cnt[j]);
        }
        if (t >= i * K) {
            ans = max(ans, i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
n, m, X = map(int, input().split())

ans = 10**9

price = []
a = []
for _ in range(n):
    c = [int(x) for x in input().split()]
    price.append(c[0])
    a.append(c[1:])

for i in range(1 << n):
    l = [0]*m
    tmp = 0
    for j in range(n):
        if (i >> j) & 1:
            tmp += price[j]
            for x in range(m):
                l[x] += a[j][x]
    if all(x >= X for x in l):
        ans = min(ans, tmp)

print(-1 if ans == 10**9 else ans)


Measured memory_bytes: 69076
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> v;
    int ans = 1;
    fact();
    for(int i = 2; i * i <= 1000000000; i++) {
        int cnt = 0;
        while(m % i == 0) {
            cnt++;
            m /= i;
        }
        ans = Mul(ans, H(n, cnt));
    }
    if(m > 1) ans = Mul(ans, H(n, 1));
    cout << ans << endl;

    return 0;
}
// 2 * 2 * 3
// ||22 * ||3

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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	cout << (H-h)*(W-w) << endl;
	return 0;
}

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

#define endl "\n"

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

const ll D = 100007;
const ll Inf = 1000000007;
ll dp[D];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n,m;
    ll v[D];
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
        if(i-v[j]>=0)if(dp[i-v[j]]==0)dp[i]=1;
    if(dp[m])cout<<"First";else cout<<"Second";
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>

const int MAX_N = 1e5, A = 1e9 + 7;
int n;
char s[2 * MAX_N + 1];
int dp[2 * MAX_N];

int main() {
    scanf("%d", &n);
    scanf("%s", s);

    int l = strlen(s);
    dp[0] = 1;
    if (s[0] == 'W') {
        printf("0\n");
        return 0;
    }
    for (int i = 1, cnt = 1; i < l; i++) {
        bool cj = cnt % 2;
        if ((s[i] == 'W' && !cj) || (s[i] == 'B' && cj)) {
            if (--cnt < 0) {
                printf("0\n");
                return 0;
            }
            dp[i] = static_cast<long>((cnt + 1)) * dp[i - 1] % A;
        }
        else if ((s[i] == 'W' && cj) || (s[i] == 'B' && !cj)) {
            if ((i - cnt) + 2 * cnt >= 2 * n) {
                printf("0\n");
                return 0;
            }
            cnt++;
            dp[i] = dp[i - 1];
        }
    }
    int per = 1;
    for (int i = 2; i <= n; i++) per = static_cast<long>(per) * i % A;
    int ans = static_cast<long>(per) * dp[l - 1] % A;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

//Unweighted graph (adjacency matrix)
//Initialize : vector<vector<int>>(N, vector<int>(N, 0))
template <typename T>
using UnweightedGraph = vector<vector<T>>;

//distance matrix
template <typename T>
using Matrix = vector<vector<T>>;

int main()
{
    int N, ans = 0;
    cin >> N;
    UnweightedGraph<int> G(N);
    vector<int> c(N), deg(N), d(N);
    for (int i = 0; i + 1 < N; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++, deg[b]++;
    }
    for (int i = 0; i < N; i++)
    {
        cin >> c[i];
        ans += c[i];
    }
    sort(c.begin(), c.end());
    ans -= c[N - 1];
    for (int i = 0; i < N; i++)
    {
        int min = (1 << 20), v = 0;
        for (int j = 0; j < N; j++)
        {
            if (deg[j] < min && d[j] == 0)
                min = deg[j], v = j;
        }
        d[v] = c[i];
        for (auto &p : G[v])
        {
            deg[p]--;
        }
    }
    cout << ans << endl;
    for (int i = 0; i < N; i++)
    {
        cout << d[i] << (i == N - 1 ? "\n" : " ");
    }
}

Measured memory_bytes: 1024
# 2020/05/22
# AtCoder Beginner Contest 072 - D

# Input
n = int(input())
p = list(map(int,input().split()))

i = 0
cnt = 0
while i < n:
    if p[i] == i+1:
        cnt = cnt + 1
        i = i + 2
    else:
        i = i + 1

# Output
print(cnt)


Measured memory_bytes: 14008
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] red = new int[n][2];
        int[][] blue = new int[n][2];
        for (int i = 0; i < n; i++) {
            red[i][0] = sc.nextInt();
            red[i][1] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            blue[i][0] = sc.nextInt();
            blue[i][1] = sc.nextInt();
        }

        Arrays.sort(red, Comparator.comparingInt(x -> x[1]));
        Arrays.sort(blue, Comparator.comparingInt(x -> x[0]));

        int count = 0;
        boolean[] paired = new boolean[n];
        for (int i = 0; i < n; i++) {
            int blueX = blue[i][0];
            int blueY = blue[i][1];
            for (int j = n - 1; j >= 0; j--) {
                int redX = red[j][0];
                int redY = red[j][1];
                if (paired[j] || redX >= blueX || redY >= blueY) {
                    continue;
                }
                count++;
                paired[j] = true;
                break;
            }
        }
        System.out.println(count);
    }

}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

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>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
ll n;
void dfs(string str,char mx)
{
    if(SZ(str)==n)
        cout<<str<<endl;
    else
    {
        for(char x='a';x<=mx;x++)
        {
            dfs(str+x,(x==mx)?(char)(mx+1):mx);
        }
    }
    return;
}
void solve()
{
    //ll n;
    cin>>n;
    dfs("",'a');
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3576
import fractions
from functools import reduce
 
n = int(input())
a = list(map(int,input().split()))
 
#累積GCD
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i + 1] = (fractions.gcd(left[i],a[i]))
    right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))
 
ans = 0
for i in range(n):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)

Measured memory_bytes: 16120
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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() {
  ll x, y;
  cin >> x >> y;
  ll base = x;
  int ans = 1;
  rep (i, INF) {
    if (base * 2 > y) break;
    else {
      base *= 2;
      ans++;
    }
  }
  P(ans);
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int l,a,b,c,d,ja,ma;
  scanf("%d%d%d%d%d",&l,&a,&b,&c,&d);
  ja = (a + c -1) / c;
  ma = (b + d -1) / d;
  if(ja > ma){
    printf("%d\n",l - ja);
  }else{
    printf("%d\n",l - ma);
  }
  return 0;
}
  

Measured memory_bytes: 596
// https://atcoder.jp/contests/abc133/tasks/abc133_f

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

template <int mod> struct ModInt {
    static const int Mod = mod;
    unsigned x;
    ModInt() : x(0) {}
    ModInt(signed sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) {
        if ((x += that.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt that) {
        if ((x += mod - that.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator*=(ModInt that) {
        x = (unsigned long long)x * that.x % mod;
        return *this;
    }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const {
        long long a = x, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            std::swap(a, b);
            u -= t * v;
            std::swap(u, v);
        }
        return ModInt(u);
    }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const {
        ModInt t;
        t.x = x == 0 ? 0 : Mod - x;
        return t;
    }
};
template <int mod> ostream &operator<<(ostream &st, const ModInt<mod> a) {
    st << a.get();
    return st;
};
template <int mod> ModInt<mod> operator^(ModInt<mod> a, unsigned long long k) {
    ModInt<mod> r = 1;
    while (k) {
        if (k & 1)
            r *= a;
        a *= a;
        k >>= 1;
    }
    return r;
}
typedef ModInt<MOD> mint;

int n, k;
vector<vector<int>> v;

mint dfs(int now, int from) {
    mint ret = 1;
    ll cnt = (from == -1 ? k - 1 : k - 2);
    for (auto x : v[now]) {
        if (from != x) {
            ret *= dfs(x, now);
            ret *= (cnt--);
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    cout << dfs(0, -1) * k << endl;

    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for(int i=0; i<N; i++) cin >> p.at(i);
    sort(p.begin(), p.end());
    int sum = 0;
    for(int i=0; i<K; i++) sum += p.at(i);
    cout << sum << endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());

		long ans = solve(H, W, h, w);
		System.out.println(ans);
	}

	private static long solve(int H, int W, int h, int w) {
		return (H - h) * (W - w);
	}
}


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

int main()
{
	int W, H, x, y, r;

	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	W = W-r, H = H-r;
	if (x <= W && r <= x && y <= H && r <= y) printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int i,j,n,sz,cnt=1;
   string s;
   cin>>n>>s;
   for(i=1; i<n; i++)
   {
      if(s[i-1]==s[i]) continue;

      cnt++;
   }
   cout<<cnt<<endl;

   return 0;
}

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

using namespace std;

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

#define ll long long

int main()
{
	int n;
	cin >> n;
	for (;;n++) {
		string s = to_string(n);
		auto itr = find_if(all(s), [s](char c){ return s[0] != c; });
		if (itr == s.end()) {
			cout << s << endl;
			break;
		}
	}
}



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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	string s; cin >> s;

	vector<int> w(n + 1, 0); {
		rep(i, s.size()) {
			if (s[i] == 'W') w[i + 1]++;
		}
		rep(i, n) w[i + 1] += w[i];
	}
	vector<int> e(n + 1, 0); {
		rep(i, s.size()) {
			if (s[i] == 'E') e[i + 1]++;
		}
		rep(i, n) e[i + 1] += e[i];
	}

	int ans = 1e9;
	rep(i, n) {
		if (i == 0) {
			ans = min(ans, e[n] - e[0]);
		} else if (i == n - 1) {
			ans = min(ans, w[n - 1] - w[0]);
		} else {
			ans = min(ans, (w[i] - w[0]) + (e[n] - e[i]));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 50 + 5, mod = 1e9 + 7;

int n, vis[N];
vector<int> adj[N];
ll ans[N];
map< pair<int, int>, ll> mp;

vector<int> bfs(int src){
    vector<int> dis(n + 1);
    memset(vis, 0, sizeof vis);
    vis[src] = 1;
    dis[src] = 0;
    queue<int> q;
    q.push(src);
    while(q.size()){
        int node = q.front();
        q.pop();
        for(auto i: adj[node]){
            if(vis[i]) continue;
            vis[i] = 1;
            dis[i] = dis[node] + 1;
            q.push(i);
        }
    }
    return dis;
}

ll fp(int b, int p){
    if(!p) return 1;
    ll ret = fp(b, p >> 1);
    ret = ret * ret;
    if(p & 1) ret = ret * b;
    return ret;
}

ll get(int u, int v){
    auto dis_u = bfs(u);
    auto dis_v = bfs(v);
    memset(vis, 0, sizeof vis);
    int node = u;
    vis[node] = 1;
    ll x = 0;
    while(node != v){
        for(auto i: adj[node]){
            if(vis[i]) continue;
            if(dis_u[i] + dis_v[i] == dis_u[v]){
                x |= mp[{node, i}];
                node = i;
                vis[node] = 1;
                break;
            }
        }
    }
    return x;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    ll x = 1;
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        mp[{u, v}] = mp[{v, u}] = x;
        x *= 2;
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        ans[i] = get(u, v);
    }
    ll res = 0;
    for(int i = 0; i < (1 << m); i++){
        ll total = 0;
        for(int j = 0; j < m; j++){
            if(i >> j & 1){
               total |= ans[j];
            }
        }
        int pw = n - 1 - __builtin_popcountll(total);
        ll tmp = fp(2, pw);
        int kam = __builtin_popcount(i);
        if(kam % 2 == 0) res = res + tmp;
        else res = res - tmp;
    }
    cout << res;

    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

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


const string NA = "NA";
string s;

bool isValid( char c, char l, char r ) {
    return l <= c && c <= r;
}

const string T[6] = {
    "abcde",
    "fghij",
    "klmno",
    "pqrst",
    "uvwxy",
    "z.?! "
};

string solve() {
    string res;
    int n = s.size();
    for ( int i = 0; i < n; i += 2 ) {
        if ( i + 1 >= n ) return NA;
        if ( ! isValid( s[i], '1', '6' ) ) return NA;
        if ( ! isValid( s[i+1], '1', '5' ) ) return NA;
        int a = s[i] - '1';
        int b = s[i+1] - '1';
        res += T[a][b];
    }
    return res;
}

int main() {
    while ( getline( cin, s ) ) cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    char arr[1300];
    scanf("%[^\n]",arr);
    for(int i=0;i<strlen(arr);i++){
        if(arr[i]==' ')continue;
        else{
            if(isupper(arr[i]))arr[i]=tolower(arr[i]);
            else arr[i]=toupper(arr[i]);
        }
    }
    printf("%s\n",arr);
}



Measured memory_bytes: 3156