akhauriyash/Code-Regression huggingface dataset:
H,W = map(int,input().split())
Ss = [["."]+[j for j in input()]+["."] for i in range(H)]
Ss.insert(0,["."]*len(Ss[0]))
Ss.append(["."]*len(Ss[0]))
ans = []
for i in range(1,len(Ss)-1):
    nums = []
    for j in range(1,len(Ss[i])-1):
        num = 0
        if Ss[i][j]==".":
            if Ss[i+1][j]=="#":
                num+=1
            if Ss[i+1][j+1]=="#":
                num+=1
            if Ss[i+1][j-1]=="#":
                num+=1
            if Ss[i-1][j]=="#":
                num+=1
            if Ss[i-1][j+1]=="#":
                num+=1
            if Ss[i-1][j-1]=="#":
                num+=1
            if Ss[i][j+1]=="#":
                num+=1
            if Ss[i][j-1]=="#":
                num+=1
            nums.append(str(num))
        else:
            nums.append("#")
    print("".join(nums))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rrep(i, b, a) for(int (i) = (b); (i) > (a); (i)--)
using namespace std;

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


int arr[200'005];

int main() {
	FASTIO;

	char a;
	cin >> a;
	if ('a' <= a && a <= 'z') cout << 'a';
	else cout << 'A';

	return 0;
}




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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  string n,ans;
  long long int k,i=0,cnt=0;
  cin>>n>>k;
  while(i<n.size()){
    if(n[i]=='1'){
      cnt++;
    }else{
      ans=n[i];
      break;
    }
    i++;
  }
  if(k<=cnt){
    cout<<1<<endl;
  }else{
    cout<<ans<<endl;
  }
  
  
  
  
  
}
///////////////////////////




Measured memory_bytes: 256
import sys

N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    X[p] += x

stack = [1]
visited = [False for _ in range(N + 1)]
visited[1] = True

while stack:
    i = stack.pop()
    for j in E[i]:
        if visited[j]:
            continue
        visited[j] = True
        stack.append(j)
        X[j] += X[i]

print(*X[1:])


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

int main() {
	std::string s;
	std::cin >> s;
	std::cout << (s[0] == s[2] ? "Yes" : "No") << std::endl;
}

Measured memory_bytes: 256
S = input()

cnt0 = 0
prev = '1'
for s in S:
  if s == prev:
    cnt0 += 1
  prev = '1' if prev == '0' else '0'

cnt1 = 0
prev = '0'
for s in S:
  if s == prev:
    cnt1 += 1
  prev = '1' if prev == '0' else '0'

print(min(cnt0, cnt1))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;

    for (;;) {
        cin >> n;
        if (n == 0) break;

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

        sort(s.begin(), s.end());
        int sum = 0;
        for (int i = 1; i < n - 1; i++) {
            sum += s[i];
        }

        cout << sum / (n - 2) << endl;
    }
}

Measured memory_bytes: 1208
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k, s;
    cin >> n >> k >> s;

    if (s == 1) {
        for (int i = 0; i < k; i++) cout << 1 << ' ';
        for (int i = k; i < n; i++) cout << 2 << ' ';
        cout << '\n';
        return 0;
    }

    if (k == 1) {
        cout << s << ' ';
        if (s == 1000000000) {
            for (int i = 1; i < n; i++) cout << 1 << ' ';
        } else {
            for (int i = 1; i < n; i++) cout << s + 1 << ' ';
        }
        cout << '\n';
        return 0;
    }

    if (k == n) {
        for (int i = 0; i < n; i++) cout << s << ' ';
        cout << '\n';
        return 0;
    }

    int cur = 1;
    for (int i = 0; i <= k; i++) {
        cout << cur << ' ';
        cur = s - cur;
    }

    if (s == 1000000000) {
        for (int i = k + 1; i < n; i++) cout << 2 << ' ';
    } else {
        for (int i = k + 1; i < n; i++) cout << s + 1 << ' ';
    }

    return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python3
import sys
from collections import defaultdict


MOD = 1000000007  # type: int

memo = dict()

def comb(n, k):
    if k < 0:
        return 0
    if n < k:
        return 0
    
    if (n, k) in memo:
        pass
    elif k == 0:
        memo[(n, k)] = 1
    elif 2 * k > n:
        memo[(n, k)] = comb(n, n-k)
    else:
        memo[(n, k)] = (comb(n, k-1) * (n - k + 1) // k)
    return memo[(n, k)]
    

def solve(N: int, K: int):
    for n in range(1, K+1):
        blue = comb(K-1, n-1)
        red = comb(N-K+1, n)
        print((blue * red) % MOD)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 43632
from collections import deque
import sys

input = sys.stdin.readline

n,m = map(int,input().split())

dis = [10**10] * n
edges = [[] for _ in range(n)]

for _ in range(m):
    l,r,d = map(int,input().split())
    edges[l-1].append((r-1, d))
    edges[r-1].append((l-1, -d))

for i in range(n):
    if dis[i] == 10**10:
        dis[i] = 0
        q = deque([i])
        while q:
            l = q.popleft()
            for r,d in edges[l]:
                if dis[r] == 10**10:
                    dis[r] = dis[l] + d
                    q.append(r)
                else:
                    if dis[r] - dis[l] != d:
                        print('No')
                        exit()

print('Yes')


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

using Pi = pair<int, int>;
using ll = long long;

constexpr ll mod = 1000000007;

int N;
ll A[300005];
ll sum[300005];
ll sumsa[66][300005];

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> A[i];

    sum[0] = 0;
    for (int i = 1; i <= N; i++) sum[i] = (sum[i - 1] + A[i]) % mod;
    
    for (ll b = 0; b < 61; b++) {
        ll s = 0;
        ll mask = (1ll << b);
        for (int i = 1; i <= N; i++) {
            (s += (A[i] ^ mask)) %= mod;
            sumsa[b][i] = (s + mod - sum[i]) % mod;
        }
    }
    
    ll ans = 0;
    for (int i = 2; i <= N; i++) {
        ll elem = sum[i - 1];
        for (ll b = 0; b < 61; b++) {
            if ((A[i] >> b) & 1) {
                (elem += sumsa[b][i - 1]) %= mod;
            }
        }
        (ans += elem) %= mod;
    }
    
    cout << ans << endl;
    return (0);
}


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

int  main()
{
	int a,b;
	cin >> a >> b;
	int ans = max(a + b, max(a * b, a - b));
	cout << ans ;
	return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1<<20;
int n, a, x;
ll sx[N], s0[N], z[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  fill(s0, s0+N, 1);
  cin >> n;
  FOR(i, 0, n){
    cin >> a;
    x ^= a;
    if(x){
      (s0[x] += sx[x]*(z[0]-z[x])) %= MOD;
      (sx[x] += s0[x]) %= MOD;
      z[x] = z[0];
    }else{
      z[0]++;
    }
  }
  if(x){
    cout << s0[x] << endl;
    return 0;
  }
  ll ans = modPow(2, z[0]-1, MOD);
  FOR(i, 1, N) ans += sx[i];
  cout << ans%MOD << endl;
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	cout << min(A * N, B) << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int h, w, n;
    std::cin >> h >> w >> n;
    std::vector<std::set<int>> vv(h + 1);
    std::set<std::pair<int, int>> bl;
    for (int i = 0; i < n; i++) {
        int x, y;
        std::cin >> x >> y;
        vv[x].insert(y);
        bl.emplace(x, y);
    }

    int p = 1;
    int q = 1;
    while (p < h) {
        auto it = vv[p + 1].upper_bound(q);
        if (it != vv[p + 1].begin() && *(--it) <= q) break;

        p++;
        if (bl.find({ p, q + 1 }) == bl.end()) q++;
        // std::cout << p << " " << q << std::endl;
    }

    std::cout << p << std::endl;

    return 0;
}

Measured memory_bytes: 28416
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;
LL v[111];

LL dp[111][55][55];

int main(){
    cin >> n >> k;
    REP(i, n){
        cin >> v[i];
    }
    REP(i, 111)REP(j, 55)REP(l, 55)dp[i][j][l] = -HINF<int>();
    dp[0][0][n] = 0;
    for(int i = 0;i < k;i++){
        REP(j, n){
            for(int l = j + 1;l <= n;l++){
                dp[i + 1][j + 1][l] = max(dp[i + 1][j + 1][l], dp[i][j][l] + v[j]);
                dp[i + 1][j][l - 1] = max(dp[i + 1][j][l - 1], dp[i][j][l] + v[l - 1]);
                dp[i + 2][j + 1][l] = max(dp[i + 2][j + 1][l], dp[i][j][l]);
                dp[i + 2][j][l - 1] = max(dp[i + 2][j][l - 1], dp[i][j][l]);
            }
        }
    }
    LL ans = 0;
    REP(i, k + 1)REP(j, n)for(int l = 0;l <= n;l++){
        //if(dp[i][j][l] >= 0)cout << i << " " << j << " " << l << " " << dp[i][j][l] << endl;
        ans = max(dp[i][j][l], ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2816
/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/abc162_d

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    char[] geto(char c) {
        char a, b;
        if(c=='R') {
            a = 'G'; b = 'B';
        } else if(c=='G') {
            a = 'R'; b = 'B';
        } else {
            a = 'G'; b = 'R';
        }
        return new char[]{a, b};
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        char[] s = in.next().trim().toCharArray();
        long rs = 0;
        for(int i=0; i<n; i++) {
            char curr = s[i];
            char[] o = geto(curr);
            int[] cnt = new int[2];

            // show("i", i, s[i]);

            for(int j=0; j<i; j++) {
                // show("j", j, s[j], o, cnt);
                int l = i - j + 1;
                int k = j - l + 1;
                if(s[j]==o[0]) {
                    rs += cnt[1];
                    if(k>=0 && s[k]==o[1]) {
                        rs--;
                    }
                    cnt[0]++;
                } else if(s[j]==o[1]) {
                    rs += cnt[0];
                    if(k>=0 && s[k]==o[0]) {
                        rs--;
                    }
                    cnt[1]++;
                }
            }
            // show("rs", rs);
        }
        out.println(rs);
    }
    

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        out.close();
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
    }
}

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

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

    int N, K;
    cin >> N >> K;

    cout << ceil(1.0 * (N - 1) / (K - 1)) << endl;
    exit(0);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

int A[MAX];
int kaishi[MAX];
int B[MAX];


int root(int x){
    if(B[x] == x) return x;
    else{
        int tmp = root(B[x]);
        B[x] = tmp;
        return tmp;
    }

}

signed main(){
    int n,k;
    cin >> n >> k;


    REP(i,MAX) kaishi[i] = -1;
    REP(i,n){
        cin >> A[i];
        if(kaishi[A[i]] == -1) kaishi[A[i]] = i + 1;
    }
    kaishi[0] = 0;

    REP(i,n+1) B[i] = i;
    int tyousa[MAX];
    REP(i,MAX) tyousa[i] = -1;
    REP(i,n){
        if(tyousa[A[i]] == -1){
            tyousa[A[i]] = i;
        }
        else{
            B[tyousa[A[i]]] = i+1;
            tyousa[A[i]] = i;
        }
    }
    
    ///cout << "kaishi" << endl;
    ///REP(i,10) cout << kaishi[i] << endl;

    ///cout << "sentou" << endl;
    ///REP(i,n) cout << B[i] << endl; 

    REP(i,n){
        B[i] = root(i);
    }


    ///cout << "kaishi" << endl;
    ///REP(i,10) cout << kaishi[i] << endl;

    ///cout << "sentou" << endl;
    ///REP(i,n) cout << B[i] << endl; 


    ///cout << endl;
    int syuuki = 0;
    int sentou = 0;
    int kaishiiti[n+1];
    while(1){
        kaishiiti[syuuki] = kaishi[sentou];
        syuuki ++;
        if(B[kaishiiti[syuuki-1]] == n){
            break;
        }
        sentou = A[B[kaishiiti[syuuki-1]]];
    }

    
    //REP(i,syuuki)  cout << kaishiiti[i] << endl;

    k-= 1;
    k%= syuuki;

    bool vis[MAX];
    REP(i,MAX) vis[i] = false;
    int ans[n];
    int ansid = 0;
    int id = kaishiiti[k];
    FOR(i,id,n){
        //cout << A[i] << endl;
        if(vis[A[i]] == false){
            ans[ansid] = A[i];
            ansid ++;
            vis[A[i]] = true;
        }
        else{
            while(1){
                ansid--;
                vis[ans[ansid]] = false;
                if(ans[ansid] == A[i]){
                    vis[A[i]] = false;
                    break;
                }
            }
        }
    }
    REP(i,ansid){
        cout << ans[i] << " ";
    }
    cout << endl;




}

Measured memory_bytes: 11008
<?php
//$K = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

for($i=0;$i<$M;$i++) {
  list($a,$b) = array_map('intval',explode(" ",trim(fgets(STDIN))));
  $A[]=$a--;
  $B[]=$b--;
  $G[$a][]=$b;
  $G[$b][]=$a;
}

$q = new SplQueue();
$q->enqueue(0);
while(!$q->isEmpty()) {
  $v = $q->dequeue();
  foreach($G[$v] as $u) {
    if (isset($dist[$u])) continue;
    $dist[$u]=$dist[$v]+1;
    $pre[$u]=$v;
    $q->enqueue($u);
  }
}
printf("Yes\n");
for($i=1;$i<$N;$i++) {
  $ans = $pre[$i];
  ++$ans;
  printf("%d\n",$ans);
}


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

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

using namespace std;

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

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

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll n, k;
  cin >> n >> k;

  ll ans = 0;

  ll minv = 0;
  ll maxv = 0;
  rep(i, k) minv += i;
  rep(i, k) maxv += n - i;
  ans += (maxv - minv + 1);
  ans %= mod;

  rep(i, n - k + 1) { 
    minv += k + i;
    maxv += n - k - i;
    ans += (maxv - minv + 1);
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
};

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)
#define MOD (1000000007LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

#define vv(t) vector< vector< T > >
#define pb push_back
#define pu push
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define EQ(a,b) (abs((a)-(b))<EPS)

int main(void){
  ios_base::sync_with_stdio(0);
  int n;
  while(cin >> n, n){
    int tail = 1, sum = 1, cnt = 0;
    for(int head = 2; head <= (n - 1) / 2 + 1; head++){
      if(sum < n) sum += head;

      if(sum >= n){
        if(sum == n) cnt++;
        sum -= tail++;
        if(sum >= n) head--;
      }
    }
    cout << cnt << endl;
  }
  return 0; 
}

Measured memory_bytes: 1192
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
N = int(input())
string_list=[input() for i in range(N)]

if len(string_list) != len(set(string_list)):
  print("No")
else:
  flag = True
  for i in range(N-1):
    if string_list[i][-1] != string_list[i+1][0]:
      flag = False
      break
  if flag:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _135B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] p = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
            int[] sortedP = p.OrderBy(x => x).ToArray();
            int i = 0;
            int j = 0;
            int chigautokoro = 0;
            bool iNiDainyuuShitaka=false;
            bool ans = true ;

            for (int a = 0; a < n && chigautokoro <= 2; a++)
            {
                if (p[a] != sortedP[a])
                {
                    chigautokoro++;
                    if (!iNiDainyuuShitaka)
                    {
                        i = a;
                    }
                    else
                    {
                        j = a;
                    }
                }
            }

            if (chigautokoro == 0)
            {
                ans = true;
            }else if (chigautokoro == 2)
            {
                int a = p[i];
                p[i] = p[j];
                p[j] = a;

                for(int b = 0; b < n; b++)
                {
                    if (p[b] != sortedP[b])
                    {
                        ans = true;
                    }
                }
            }
            else
            {
                ans = false;
            }

            if (ans)
            {
                Console.WriteLine("YES");
            }
            else Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;

int main() {
	ll n, ac = 0, wa = 0, tle = 0,re=0;
	string s;
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> s;
		if (s == "AC")ac++;
		else if (s == "WA")wa++;
		else if (s == "TLE")tle++;
		else if (s == "RE")re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n;
	cin >> n;
	vector<ll> x(n);
	rep(i,n){
		cin >> x[i];
		--x[i];
	}

	ll res = 1e9;

	rep(i,100){
		ll tmp = 0;
		rep(j,n){
			tmp += (x[j]-i)*(x[j]-i);
		}
		res = min(res,tmp);

	}

	cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			a.begin(), a.end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define	MAX_QWORD		((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	};
	sort(ALL(a));

	int diff = 0;
	P ans;
	REPN(i, 1, n) {
		int maxVal = a[i];
		auto idx = lower_bound(a.begin(), a.end(), (maxVal + 1) / 2) - a.begin();
		int temp = maxVal - a[idx];
		if (diff <= temp) {
			diff = temp;
			ans = make_pair(a[idx], maxVal);
		}
		if (0 < idx) {
			temp = maxVal - a[idx - 1];
			temp = min(temp, a[idx - 1]);
			if (diff <= temp) {
				diff = temp;
				ans = make_pair(a[idx - 1], maxVal);
			}
		}
	}
	cout << ans.second << " " << ans.first << endl;
	return 0;
}



Measured memory_bytes: 640
import sys

N, K = map(int, sys.stdin.readline().rstrip().split())
D = set(map(str, sys.stdin.readline().rstrip().split()))


for i in range(N, N*10+1):
    price_str = str(i)
    for num_str in price_str:
        if num_str in D:
            break
    else:
        print(price_str)
        sys.exit()

Measured memory_bytes: 40412
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    int ans=0;
    for(int i=0; i<n; i++){
        while(a[i]==a[i+1]) i++;
        if(a[i]<a[i+1]){
            while(a[i]<=a[i+1]) i++;
        }
        else if(a[i]>a[i+1]){
            while(a[i]>=a[i+1]) i++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3916
while True:
	a,op,b = raw_input().split()
	if op == '?':
		break
	elif op == '+':
		print int(a) + int(b)
	elif op == '-':
		print int(a) - int(b)
	elif op == '*':
		print int(a) * int(b)
	else:
		print int(a) / int(b)

Measured memory_bytes: 4204
/*author:anshumanc007
created on:12/05/2019*/

//            :(



#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
typedef pair<long long int,long long int>pa;
#define pb push_back
#define MAX 1000005
long long int MOD=1e9+7;
long long int INF=1e18;


int main()
{
       ios_base::sync_with_stdio(false);
       cin.tie(NULL);
       cout.tie(NULL);
long long int i,j,k=0,l=0,r=0,m=0,n,a,b,c,p=0,cnt=0,cnt1=0,low,mid,high,ans=0,maxi=0,mini=INF,t;
cin>>n;
long long int dp[n][2]={0};
long long int A[n];
for(i=0;i<n;i++)
{
  cin>>A[i];
}
dp[0][0]=A[0];
dp[0][1]=A[0]*-1;
for(i=1;i<n-1;i++)
{
  dp[i][1]=max(dp[i-1][1]+A[i],dp[i-1][0]-A[i]);
  dp[i][0]=max(dp[i-1][1]-A[i],dp[i-1][0]+A[i]);
}
cout<<max(dp[n-2][0]+A[n-1],dp[n-2][1]-A[n-1])<<endl;



}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a > c) cout << 0 << endl;
  else if(a+b < c) cout << "NA" << endl;
  else cout << c-a << endl;
  return (0);
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
main(){
	daman;
	lli n;
	cin>>n;
	string str = "";
	while(n > 0)
	{
		int rem = n%26;
		if(rem == 0)
			rem = 26;
		n -= rem;
		str += 96+rem;
		n /= 26;
	}
	for(int i=0;i<str.length();i++)
		cout<<str[str.length()-i-1];
		
	cout<<"\n";
	
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    cin>>N;
    vector<int> as(N);
    rep(i, N) cin>>as[i];

    bool flag = true;
    int cnt = 0;
    while (flag) {
        flag = false;
        rep(i, N - 1) {
            if (as[i] > as[i + 1]) {
                swap(as[i], as[i + 1]);
                flag = true;
                cnt++;
            }
        }
    }

    rep(i, N - 1) cout<<as[i]<<" ";
    cout<<as[N - 1]<<endl;
    cout<<cnt<<endl;
}


Measured memory_bytes: 3132
N, X, M = map(int, input().split())

G = {X: 0}
a = X
while True:
    na = pow(a, 2, M)
    if na in G:
        s = G[na]
        sa = na
        g = G[a]
        break
    else:
        G[na] = G[a] + 1
        a = na

if N <= s:
    ans1 = 0
    a = X
    for i in range(N):
        ans1 += a
        a = pow(a, 2, M)
    print(ans1)
else:
    ans1 = 0
    a = X
    for i in range(s):
        ans1 += a
        a = pow(a, 2, M)

    L = g - s + 1
    S = [0] * (L + 1)
    a = sa
    for i in range(L):
        S[i + 1] = S[i] + a
        a = pow(a, 2, M)

    rest = N - s
    x, y = divmod(rest, L)
    ans2 = S[-1] * x + S[y]

    print(ans1 + ans2)


Measured memory_bytes: 75852
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Use __builtin_popcountll for ll;
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

signed main(){
    FASTER;
    int n;cin>>n;
    vi v(n);cin>>v;
    vi nw(all(v));sort(all(nw));
    int mx1=nw[n-1];
    int mx2=nw[n-2];
    for(int i:v){
        if(i==mx1){
            cout<<mx2<<"\n";
        }else cout<<mx1<<"\n";
    }
}



Measured memory_bytes: 6368
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int main(){
	string S;
	long int K;
	cin >> S >> K;
	long int length = (long int)S.size();
	char ans = '1';
	for(int i=0;i<min(length,K);i++){
		if(*(S.begin() + i) != '1'){
			ans = *(S.begin() + i);
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
mod = 10**9+7

def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

from collections import defaultdict as dd

d = dd(int)

for i in range(1, N+1):
    a = factorize(i)
    for j in a:
        d[j] += 1

ans = 1
for k, v in d.items():
    ans = ans * (v+1) % mod
print(ans)


Measured memory_bytes: 41436
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    ll K, A, B;
    cin >> K >> A >> B;
    ll ans = 1;
    if (K - A + 1 > 0)
    { // A枚になるまで叩く
        ans = A;
        K -= A - 1;
    }
    else
    {
        cout << 1 + K << endl;
        return 0;
    }
    if (B - A >= 3)
    {
        ll cnt = K / 2;
        ans += (cnt * (B - A));
        ans += K % 2;
        cout << ans << endl;
        return 0;
    }
    else
    {
        cout << ans + K << endl;
        return 0;
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
# AtCoder Beginner Contest 148
# D - Brick Break

N=int(input())
a=list(map(int,input().split()))

targetnum=1
breaknum=0

for i in range(N):
    if a[i]==targetnum:
        targetnum+=1
    else:breaknum+=1
if breaknum==N:
    print(-1)
else:
    print(breaknum)


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

int main() {
  int x, y, a[1000], b[1000], c[1000]={}, z = 0;	
	cin >> x >> y;

	for (int i = 0; i <= x - 1; i++){
		cin >> a[i];
	}
	for (int j = 0; j <= y - 1; j++){
		cin >> b[j];
	}
	for (int j = 0; j <= y - 1; j++){
		for (int i = 0; i <= x - 1; i++){
			if (a[i] <= b[j]) {
				c[i]++;
				break;
			}
		}
	}
	int mx=c[0];
	for (int i = 1; i <= x - 1; i++){
		if (c[0] < c[i]){
		  c[0]=c[i];
		  z = i;
		}
	}		
	cout << z + 1<< endl;
}



Measured memory_bytes: 3076
import java.util.*;

class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      int x = Integer.parseInt(sc.next());
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      if(Math.abs(a - x) < Math.abs(b - x)){
        System.out.println("A");
      }else{
        System.out.println("B");
      }
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
using less_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
using great_set = tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update>;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const int N = 2e3+69;
#define ALL(x) begin(x),end(x)
#define sz(x) (ll)x.size()
const int OO = 0x3f3f3f3f;
const int mod = 1e9+7;

ll fac[500069];

long long power(long long x, int y, int p)
{
    long long res = 1;

    x = x % p;

    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
long long modInverse(long long n, int p)
{
    return power(n, p - 2, p);
}

long long nCr(long long n, int r, int p)
{
    if (r == 0)
        return 1;
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

ll nPr(ll n, ll r, int p)
{
    ll f = 1;
    for(int i = 0; i< n; i++)
    {
        f = (f%p * (r-i)%p)%p;
    }
    return f;
}



ll n, m;
int main()
{
    FIO
    cin >> n >> m;
    fac[0] = 1;
    for (int i = 1; i <= m; i++)
        fac[i] = (fac[i - 1] * i) % mod;
    //cout << nCr(2, 1, mod) << "\n";
    ll ans = 0;
    ll allc = nPr(n, m, mod);
    //cout << allc << "\n";
    bool pos = 0;
    if(n&1)
        pos = 1;
    ll lst = 1;
    //cout << lst << "\n";
    for(int i = n; i >= 1; i--)
    {
        if(pos)
        {
            ans = (ans%mod + (nCr(n, i, mod) * (lst%mod))%mod)%mod;
            //cout << "pos " << nCr(n, i, mod) << " " << lst << " " << ans << "\n";
            pos = !pos;
        }
        else
        {
            ans = (ans%mod - (nCr(n, i, mod) * (lst%mod))%mod)%mod;
            //cout << "neg " << nCr(n, i, mod) << " " << lst << " " << ans << "\n";
            pos = !pos;
        }
        lst = ((lst%mod) * (m-i+1))%mod;
        //cout << ans << "\n";
    }

    cout << (ll)(((allc%mod) * ((allc%mod) - (ans%mod) + mod)%mod)%mod) << "\n";
    return 0;
}


Measured memory_bytes: 7512
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
ll a[120];
int main()
{
    ft
    ll t,i,j,n,m,l=0,r,z=0;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        cin>>a[i];
    }
    z+=a[0];
    for(i=1;i<n-1;i++)
    {
        if(a[i]<a[i-1])
        {
            a[i-1]=a[i];
        }
    }
    for(i=0;i<n-1;i++)
    {
        z+=a[i];
    }
    cout<<z<<"\n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> cnt(3);
  rep(i, n) {
    int t;
    cin >> t;
    if(t <= a) cnt[0]++;
    else if(t <= b) cnt[1]++;
    else cnt[2]++; 
  }
  int ans = INF;
  rep(i, 3) ans = min(cnt[i], ans);
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rp(i,j) for(long long i=0;i<j;i++)
#define rep(i,j,k) for(long long i=j;i<k;i++)
#define mod 1000000007
#define NIL -1
#define white 0
#define gray 1
#define black 2
typedef long long ll;
int n,tt=0,d[100],f[100];
int a[100][100]={0};
int nt[100]={1};
int color[100]={0};
void dfs_visit(int u){
    color[u]=gray;
    d[u]=++tt;
    rp(v,n){
        if(a[u][v]==0)continue;
        if(color[v]==white){
            dfs_visit(v);
        }
    }
    color[u]=black;
    f[u]=++tt;
}
void dfs(){
    rp(u,n){
        if(color[u]==white)dfs_visit(u);
    }
    rp(u,n){
        cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl; 
    }
}
int main(){
    int u,k,v;
    cin>>n;
    rp(i,n){
        cin>>u>>k;
        u--;
        rp(j,k){
            cin>>v;
            v--;
            a[u][v]=1;
        }
    }
    dfs();
    return 0;
}


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

#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
    int l,r,largest;
    l = 2 * i;
    r = 2 * i + 1;

    //??????????????????????????????????????????????????§????????????????????¶
    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;

    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

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

    for(int i=H/2;i>=1;i--) maxHeapify(i);
    
    for(int i=1;i<=H;i++){
        printf(" %d",A[i]);
    }
    printf("\n");
}

Measured memory_bytes: 5116
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int k;
    cin >> k;
    vector<ll> v(k);
    for(int i = 0; i < k; i++)  cin >> v[i];
    if(v[k-1] != 2){
        cout << -1 << endl;
        return 0;
    }
    ll low = 2, high = 3;
    for(int i = k-2; i >= 0; i--){
        if(high < v[i]){
            cout << -1 << endl;
            return 0;
        }
        high = high / v[i] * v[i] + v[i]-1;
        low = (low + v[i] - 1) / v[i] * v[i];
    }
    if(low > high)  cout << -1 << endl;
    else            cout << low << " " << high << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
ll A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
struct katana {
	ll s;
	ll t;
	int i;
};

bool compt(const katana &left, const katana &right) {
	if (left.t == right.t) {
		return left.s > right.s;
	}
	return left.t > right.t;
}

void KatanaThrower() {
	cin >> N >> H;

	katana k[100010];
	ll maxs = 0;
	for (size_t i = 0; i < N; i++)
	{
		cin >> k[i].s >> k[i].t;
		k[i].i = i;
		maxs = max(k[i].s, maxs);
	}

	sort(k, k + N,compt);
	ll res = (ll)10e9 + 10;
	ll sumD = 0;
	ll i = 0;
	for (; i <= N; i++)
	{
		if (H < sumD) break;
		ll sc = (H - (sumD)) / maxs;
		ll rem = (H - (sumD)) % maxs;
		if (rem > 0) {
			sc++;
		}
		res = min(res, sc + i);

		if (i == N) break;
		sumD += k[i].t;
	}
	if (H < sumD) {
		res = min(res, i);
	}
	cout << res << endl;
}
int main() {
	KatanaThrower();
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int x[100010], y[100010];
pair<int,int> a[100010], b[100010];
vector <pair<int,pair<int,int>> > v;
int par[100010];
int pa(int x){
  if(par[x]==x)
    return x;
  par[x]=pa(par[x]);
  return par[x];
}
void join(int x, int y){
  par[pa(x)]=pa(y);
}
int main(){
  int n, ans;
  while(cin>>n){
    for(int i=0; i<n; ++i){
      scanf("%d%d",&x[i],&y[i]);
      a[i]=mk(x[i],i);
      b[i]=mk(y[i],i);
      par[i]=i;
    }
    sort(a, a+n);
    ans=0;
    for(int i=1; i<n; ++i){
      v.push_back(mk(abs(a[i].fs-a[i-1].fs), mk(a[i].sc, a[i-1].sc)));
    }
    sort(b, b+n);
    for(int i=1; i<n; ++i){
      v.push_back(mk(abs(b[i].fs-b[i-1].fs), mk(b[i].sc, b[i-1].sc)));
    }
    sort(v.begin(), v.end());
    int tmp1, tmp2;
    for(int i=0; i<v.size(); ++i){
      tmp1=v[i].sc.fs;
      tmp2=v[i].sc.sc;
      if(pa(tmp1)==pa(tmp2)){
        continue;
      }
      ans+=v[i].fs;
      join(tmp1, tmp2);
    }
    cout<<ans<<endl;
  }
  return 0;
}





Measured memory_bytes: 7668
n =10**5+1
p = [False] * 2 + [True] * (n-2)
for i in range(2,n):
    if p[i]:
        for j in range(i*2,n,i):
            p[j] = False
a=[p[i]==True and p[(i+1)//2]==True for i in range(n)]
b=[0]*n
b[0]=a[0]
for i in range(1,n):
    b[i]=b[i-1]+a[i]
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(b[r]-b[l-1])

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

long long N;
string S;
int P;

long long solve() {
  vector<long long> val(P, 0);
  long long tenfactor = 1;
  long long cur = 0;
  val[cur]++;
  for (int i = 0; i < N; ++i) {
    cur = (cur + (S[N - i - 1] - '0') * tenfactor) % P;
    tenfactor = (tenfactor * 10) % P;
    val[cur]++;
  }
  long long res = 0;
  for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
  return res;
}

int main() {
  cin >> S;
  N = S.length();
  P = 2019;
  cout << solve() << endl;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
int main(void)

{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (abs(a - e) > k)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
}


Measured memory_bytes: 3620