akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const int MAX = 510000;
const ll MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll binarypow(ll a, ll n, ll mod) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
    ll n, m, k; cin >> n >> m >> k;
    COMinit();
    ll ans = 0;
    rep(i, k+1) ans += COM(n-1, i) * m % MOD * binarypow(m-1, n-i-1, MOD) % MOD;
    cout << ans % MOD << endl;
}

Measured memory_bytes: 15564
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int h,w;
  cin >> h >> w;
  vector<string> f(h);
  for(auto &s:f) cin >> s;
  queue<pair<int,int> > q;
  REP(i,h) REP(j,w) {
    if(f[i][j]=='#') q.emplace(i,j);
    f[i][j]='.';
  }
  q.emplace(-1,-1);
  int answer = 0;
  int tmp = 0;
  while(q.size()>1) {
    int y,x;
    tie(y,x) = q.front();
    q.pop();
    if(y < 0) {
      tmp = -y;
      q.emplace(y-1,y-1);
      continue;
    } else if(f[y][x]!='#') {
      f[y][x]='#';
      if(y>0) q.emplace(y-1,x);
      if(y<h-1) q.emplace(y+1,x);
      if(x>0) q.emplace(y,x-1);
      if(x<w-1) q.emplace(y,x+1);
      answer = tmp;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 34064
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]
def gcd(a, b):
    if a < b: return gcd(b, a)
    if b == 0: return a
    return gcd(b, a%b)
def lcm(a, b):
    return a * b // gcd(a, b)

n, m = il()
s = input()
t = input()
aa = gcd(n, m)
bb = lcm(n, m)
cc = aa // bb
for i in range(aa):
    if s[n//aa*i] != t[m//aa*i]:
        print(-1)
        exit()
print(bb)


Measured memory_bytes: 3444
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.nextLine();
		String b ="";
		if(a.equals("a")) {
			b="vowel";
		}else if(a.equals("i")) {
			b="vowel";
		}else if(a.equals("u")) {
			b="vowel";
		}else if(a.equals("e")) {
			b="vowel";
		}else if(a.equals("o")) {
			b="vowel";
		}else {
			b="consonant";
		}

		System.out.println(b);

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <utility>
#include <set>
#include <vector>
#include <queue>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)

int main(){

    string s;
    int k;
    cin>>s>>k;
    
    loop(i,s.size()){
        if(s[i]!='a' && s[i]+k>'z'){
            k-='z'+1-s[i];
            s[i]='a';
        }
    }
    
    s[s.size()-1]+=k%26;
    
    cout<<s<<endl;
    
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>

int main(void) {
	// input
	int h, w;
	std::cin >> h >> w;
	std::vector<std::string> c(h);
	for(int i = 0; i < h; ++i) std::cin >> c[i];

	// out
	for(int i = 0; i < h; ++i) {
		std::cout << c[i] << std::endl;
		std::cout << c[i] << std::endl;
	}

	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[105][100005];

void Main() {
    int N, W;
    cin >> N >> W;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;

    rep(i, N) {
        P item = items[i];
        rep(j, W + 1) {
            if (j - item.first >= 0) {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - item.first] + item.second);
            }
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp[N][W] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
string S;
bool dp[33000][11][11][11];
signed main() {
    cin >> N >> S;
    dp[0][10][10][10] = true;
    rep(i, N) {
        rep(j, 11) {
            rep(k, 11) {
                rep(l, 11) {
                    dp[i + 1][j][k][l] |= dp[i][j][k][l];
                    if (j == 10) { dp[i + 1][S[i] - '0'][k][l] |= dp[i][j][k][l]; }
                    if (j != 10 && k == 10) { dp[i + 1][j][S[i] - '0'][l] |= dp[i][j][k][l]; }
                    if (k != 10 && l == 10) { dp[i + 1][j][k][S[i] - '0'] |= dp[i][j][k][l]; }
                }
            }
        }
    }
    int ans = 0;
    rep(j, 10) {
        rep(k, 10) {
            rep(l, 10) {
                ans += dp[N][j][k][l];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 41216
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    ll X;
    cin >> X;

    ll m = 100;
    int c = 0;
    while(m < X){
        c++;
        m *= 1.01;
    }

    cout << c << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
	int N; std::cin >> N;
	std::vector<long long> X(N);
	long long sum{ 0 };
	long long ans{ 1000000000000000000 };
	for (auto& r : X) std::cin >> r;
	for (long long i{ 1 }; i <= 200; ++i) {
		sum = 0;
		for (auto r : X) {
			sum += (r - i) * (r - i);
		}
		if (sum < ans) ans = sum;
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int main(void){
	int N;
	int minus=0;
	long long ans = 0;
	cin >> N;
	int A[N];
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(A[i]<0)minus++;
	}
	int min = abs(A[0]);
	for(int i=0;i<N;i++){
		min = std::min(min,abs(A[i]));
	}
	for(int i=0;i<N;i++){
		ans += abs(A[i]);
	}
	if(minus%2==0){
	}else{
		ans -=2*min;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
a_list = list(map(int, input().split()))
dic_A = {}
for i in range(N):
    if a_list[i] in dic_A:
        dic_A[a_list[i]] += 1
    else:
        dic_A[a_list[i]] = 1
ans = 0
for k, v in dic_A.items():
    ans += v*(v-1)//2
#print(dic_A, ans)
for i in range(N):
    tmp = dic_A[a_list[i]]
    if tmp <= 1:
        print(ans)
    else:
        print(ans-tmp*(tmp-1)//2+(tmp-1)*(tmp-2)//2)

Measured memory_bytes: 26268
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
count=0
lis=LI()
for i in range(n):
    if i%2==0 and lis[i]%2==1:
        count+=1
print(count)

Measured memory_bytes: 9412
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
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>;

#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


string to_string(string s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(char ch) {
	return string("'")+ch+string("'");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <class InputIterator>
string to_string (InputIterator first, InputIterator last) {
	bool start = true;
	string res = "{";
	while (first!=last) {
		if (!start) {
			res += ", ";
		}
		start = false;
		res += to_string(*first);
		++first;
	}
	res += "}";
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



const int mod=1e9+7;

int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
	return res;
	}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=300005;

void solve()
{  
int a,b,t;
cin>>a>>b>>t;
cout<<(t/a)*b;

} 
	
	
   
	
	

signed main()
{   
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//cin>>tc;
    for(int i=0;i<tc;i++)
	{
		//cout<<"Case #"<<i+1<<": "; 
        solve();
		}
	
	}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

namespace IO {
    template <typename _T>
    inline bool read (_T& x) {
        x = 0;
        _T y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return false;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return true;
    }

    template <typename _T>
    inline _T input () {
        _T x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return x;
    }
};
using namespace IO;

namespace modular {
    const int MOD = 1000000007;

    inline int add (int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }

    inline void inc (int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }

    inline int mul (int x, int y) { return 1LL * x * y % MOD; }

    inline int qpow (int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x);
        return ans;
    }
};
using namespace modular;

#define reg register
#define MAX_N 200007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define lep(i, l, r) for(int i = l; i < r; ++i)
#define irep(i, r, l) for(int i = r; i >= l; --i)
#define ilep(i, r, l) for(int i = r; i > l; --i)
typedef long long ll;

int N;
ll a[MAX_N], A, B;
int f[MAX_N], R[MAX_N], s[MAX_N];

inline void init () {
    rep (i, 2, N) {
        R[i] = R[i - 1];
        while (R[i] < i - 1 && a[i] - a[R[i] + 1] >= A) R[i]++;
    }
}

inline void solve () {
    f[0] = s[0] = 1;
    int l = 0, r = 0;
    rep (i, 1, N) {
        r = R[i];
        if (l <= r) f[i] = add(s[r], l == 0 ? 0 : MOD - s[l - 1]);
        // printf("%d l%d r%d %d\n", i, l, r, f[i]);
        s[i] = add(s[i - 1], f[i]);
        if (a[i] - a[i - 1] < B) l = i - 1;
    }
    printf("%d\n", f[N]);
}

int main () {
#ifdef LOCAL
    FIN("in");
#endif
    read(N), read(A), read(B);
    if (A < B) std::swap(A, B);
    rep (i, 1, N) read(a[i]);
    rep (i, 1, N - 2)
        if (a[i + 1] - a[i] < B && a[i + 2] - a[i + 1] < B && a[i + 2] - a[i] < B) return puts("0"), 0;
    a[++N] = (2e18) + 2;
    init();
    solve();
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const auto& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const int max_n = 1e5;
int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(max_n + 1);
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    c[x]++;
  }
  V<> r(m), p(m);
  for (int i = 1; i < max_n + 1; i++) {
    r[i % m] += c[i];
    p[i % m] += c[i] / 2;
  }
  int res = r[0] / 2;
  for (int i = 1; i < (m + 1) / 2; i++) {
    if (r[i] > r[m - i]) res += r[m - i] + min((r[i] - r[m - i]) / 2, p[i]);
    else res += r[i] + min((r[m - i] - r[i]) / 2, p[m - i]);
  }
  if (!(m & 1)) res += r[m / 2] / 2;
  cout << res << '\n';
}

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


int N;

double dp[303][303][303];

double rec(int i, int j, int k)
{
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i - 1, j, k) * i;
    if (j > 0) res += rec(i + 1, j - 1, k) * j;
    if (k > 0) res += rec(i, j + 1, k - 1) * k;
    res += N;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main ()
{
    cin >> N;
    int one = 0, two = 0, three = 0;
    for(int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        if(a == 1) one++;
        else if (a == 2) two++;
        else three++;
    }

    memset(dp, -1, sizeof(dp));

    cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

Measured memory_bytes: 217600
# -*- coding:utf-8 -*-

from collections import deque

result = deque()

def operation(command):
    if command[0] == "insert":
        result.appendleft(command[1])
    elif command[0] == "delete":
        if command[1] in result:
            result.remove(command[1])
    elif command[0] == "deleteFirst":
        result.popleft()
    elif command[0] == "deleteLast":
        result.pop()

n = int(input())
for i in range(n):
    command = input().split()
    operation(command)
print(*result)

Measured memory_bytes: 71940
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int max(int a, int b);
int min(int a, int b);

int main(int argc, char const* argv[])
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) 
    {
        int n;
        cin >> n;
        int min_num=0;
        int max_num=0;
        int pre=0;
        int next=0;
        cin >> pre;
        for (int j = 0; j < n-1; j++) 
        {
            next = pre;
            cin >> pre;
            max_num = max( max_num, next-pre);
            min_num = min( min_num, next-pre);
        }
        //cout << max_num << " " << -1 * min_num << endl;
        cout << -1 * min_num << " " << max_num << endl;
    }
    return 0;
}

int max(int a, int b)
{
    if (a > b) 
    {
        return a;
    }
    else{
        return b;
    }
}
int min(int a, int b)
{
    if (a > b) 
    {
        return b;
    }
    else{
        return a;
    }
}

Measured memory_bytes: 1164
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b!=c)
    {
        cout<<"Yes";
    }
    else if(b==c&&b!=a)
    {
        cout<<"Yes";
    }
    else if(c==a&&a!=b)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";
    return 0;

}

Measured memory_bytes: 256
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_ = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res


MAX = 400001

fac  = [0 for _ in range(MAX)]
finv = [0 for _ in range(MAX)]
inv  = [0 for _ in range(MAX)]

def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;

def mod_COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;

COMinit()


n, k = l_in()

if k >= n-1:
    print(mod_COM(2*n-1, n-1))
else:
    res = 0
    for r in range(0, k+1):
        res = mod_add(res, mod_mul(mod_COM(n-1, r), mod_COM(n, r)))

    print(res)


Measured memory_bytes: 74968
/*
Author:		CraZYali
LANG: 		C++
FileName:	.cpp

CopyRIGHT!!!
*/

#define REP(i, s, e) for(register int i = s; i <= e ;i++)

#include <bits/stdc++.h>

using namespace std;
const int maxn = 205, inf = 1 << 30;
int d[maxn][maxn], a[maxn], n, m, r;

int c[maxn], ans = inf;
bool vis[maxn];
inline void dfs(int x, int l) {
	if (x == r) {
		int res = 0;
		REP(i, 2, r) res += d[c[i-1]][c[i]];
		ans = min(ans, res);
		return;
	}
	if (x > r) return;
	REP(i, 1, r)
		if (!vis[i]) {
			vis[i] = 1;
			x++;
			c[x] = a[i];
			dfs(x, i);
			x--;
			vis[i] = 0;
		}
}

int main() {
	cin >> n >> m >> r;
	REP(i, 1, r) scanf("%d", &a[i]);
	REP(i, 1, n)
		REP(j, 1, n)
			d[i][j] = inf;
	while (m--) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		d[x][y] = d[y][x] = min(d[x][y], z);
	}
	REP(i, 1, n) d[i][i] = 0;
	REP(k, 1, n)
		REP(i, 1, n)
			REP(j, 1, n)
				if (d[i][k] != inf && d[k][j] != inf)
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	dfs(0, 0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int x;
	cin >> x;
	if(x==0)print(1);
	else print(0);
}

Measured memory_bytes: 3624
import scala.io.StdIn
import scala.collection.mutable

object Main extends App {
  val n = StdIn.readLine().toInt
  val s: String = StdIn.readLine()
  var prev = s(0)

  val ans = s.foldLeft(1) { (acc, v) =>
    if (prev != v) {
      prev = v
      acc + 1
    } else {
      acc
    }
  }

  println(ans)
}


Measured memory_bytes: 29360
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int[] A=cin.ReadIntArray(2);
            int N = A[0];
            int M = A[1];
            var L = new List<int>();
            var R = new List<int>();
            int answer = 0;
            for(int i = 0; i < M; i++)
            {
                int[] B=cin.ReadIntArray(2);
                L.Add(B[0]);
                R.Add(B[1]);
            }
            int LMax = L.Max();
            int RMax = R.Min();

            if (RMax < LMax)
            {
                 answer = 0;
            }
            else
            {
                 answer = RMax - LMax + 1;
            }
            
            Console.WriteLine(answer);
        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 19396
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLine

object Main extends App {
  val pushBack = 0
  val dump     = 1
  val clear    = 2

  val Array(n, q) = readLine().split(" ").map { _.toInt }
  val lines       = Iterator.fill(q)(readLine())

  val orders = lines.map { _.split(" ").map { _.toInt } }

  val xss = Array.fill(n)(Vector.empty[Int])
  orders.foreach {
    case Array(`pushBack`, t, x) => xss(t) = xss(t) :+ x
    case Array(`dump`, t)        => println(xss(t).mkString(" "))
    case Array(`clear`, t)       => xss(t) = Vector.empty[Int]
  }
}



Measured memory_bytes: 450836
//A - The Number of Even Pairs

#include <iostream>
#include <algorithm>

using namespace std;

int calcNumOfCombination(int n, int r){
    int num = 1;
    for(int i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int main()
{
    int n, m;

    cin >> n >> m;

    int nn =calcNumOfCombination(n,2);
    int mm =calcNumOfCombination(m,2);
    
    cout << nn+mm << endl;

    return 0;
}


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

int main() {

    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && B != C || A != B && B == C || A == C && C != B)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
M=998244353
n,m,k=map(int,input().split())
p,c=[m],[1]
for i in range(1,n):
  p+=[p[-1]*(m-1)%M]
  c+=[c[-1]*(n-i)*pow(i,-1,M)%M]
print(sum(p[n-i-1]*c[i] for i in range(k+1))%M)

Measured memory_bytes: 24948
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }
std::vector<std::vector<int> > radj;
std::vector<set<int> > adj;
int maxdist[100003];
int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	int m; cin >> m;
	radj.resize(n);
	adj.resize(n);
	for (int i = 0; i < m; ++i) {
		int u; cin >> u;u--;
		int v; cin >> v;v--;
		adj[u].insert(v);
		radj[v].pb(u);
	}
	queue<int> q;
	for (int i = 0; i < n; ++i) {
		if (adj[i].empty()) q.push(i);
	}

	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (int v : radj[u]) {
			maxdist[v] = max(maxdist[u] + 1, maxdist[v]);
			adj[v].erase(u);
			if (adj[v].empty()) q.push(v);
		}
	}
	for (int i = 0; i < n; ++i) {
		maxdist[0] = max(maxdist[0], maxdist[i]);
	}
	cout << maxdist[0];
}

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

int main() {
  int n;
  cin >> n;
  bool check1 = 0;
  bool check2 = 0;
  vector<int>num(n);
  vector<int>ans(n);
  for (int i = 0; i < n; i++) {
    cin >> num.at(i);
  }
  for (int i = 0; i < n; i++) {
    ans.at(i) = num.at(i);
  }
  sort(ans.begin(),ans.end());
  if (num == ans) cout << "YES";
  else {
  for (int i = 0; i < n; i++) {
    for(int j = i+1; j < n; j++) {
      swap(num.at(i),num.at(j));
      if (ans == num) {
        cout << "YES";
        check1 = 1;
        check2 = 1;
         break;
      }
      swap(num.at(i),num.at(j));
      if (check2 == 1) break;
    } 
  }
  if (check1 == 0) cout << "NO";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  ll c = n;
  ll m = 0;
  string s = to_string(c);
  rep(i, sz(s)){
    ll a = s[i] - '0';
    m += a;
  }
  if(n%m==0){
    print("Yes");
  }
  else{
    print("No");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string  s;
    cin>>s;
    if(s[0]=='S'&&s[1]=='U')cout<<7<<endl;
    else if(s[0]=='S')cout<<1<<endl;
    else if(s[0]=='M')cout<<6<<endl;
    else if(s[0]=='T'&&s[1]=='U')cout<<5<<endl;
    else if(s[0]=='W')cout<<4<<endl;
    else if(s[0]=='T')cout<<3<<endl;
    else cout<<2<<endl;

    return 0;
}


Measured memory_bytes: 256
L, R = map(int,input().split())
MOD = 2019
ans = float("inf")
for i in range(L,min(L+2019,R+1)):
  for j in range(i,min(i+2019,R+1)):
    if i == j:
      continue
    ans = min(ans,i * j % MOD)
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	int a,b,c; cin>>a>>b>>c;
	swap(a,b); swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: usize = scan(tokens);
    let b: usize = scan(tokens);
    for _ in 0..std::cmp::max(a, b) {
        print!("{}", std::cmp::min(a, b));
    }
    println!("");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;

int n;
string s[501],ans;
vector<int> v[28];
bool visited[28],checked[28];

void init(){
  for(int i=0;i<28;i++){
    v[i].clear();
    visited[i]=false;
    checked[i]=false;
  }
}

pair<char,char> func(string a,string b){
  pair<char,char> pcc;
  a+='A';b+='A';
  for(int i=0;i<a.length();i++){
    if(a[i]!=b[i]){
      pcc.f=a[i];
      pcc.s=b[i];
      break;
    }
  }
  return pcc;
}

void dfs(int num){
  if(visited[num]){
    ans="no";
    return;
  }
  visited[num]=true;
  for(int i=0;i<v[num].size();i++){
    if(!checked[v[num][i]])dfs(v[num][i]);
  }
  checked[num]=true;
  visited[num]=false;
}

int main()
{

  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++)cin>>s[i];
    ans="yes";
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(s[i]==s[j])continue;
	pair<char,char> pcc=func(s[i],s[j]);
	int a,b;
	if(pcc.f=='A')a=27;
	else a=pcc.f-'a';
	if(pcc.s=='A')b=27;
	else b=pcc.s-'a';
	if(b==27)ans="no";
	v[a].push_back(b);
      }
    }

    for(int i=0;i<28;i++){
      if(!checked[i])dfs(i);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 6572
#include <stdio.h>
int main(void){
  long long a, b, x; scanf("%lld %lld %lld", &a, &b, &x);
  if(a == 0) printf("%lld", b / x + 1);
  else printf("%lld", (b / x + 1) - ((a - 1) / x + 1));
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

const ll AMAX = 1000000;
ll cnt[AMAX+1];

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll w[AMAX+1];

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    REP(i, AMAX+1) cnt[i] = 0;
    REP(i, N) cnt[A[i]]++;

    for(int i=1;i<=AMAX;i++){
    	w[i] = modinv(i, mod);
    }

    for(int i=1;i<=AMAX;i++){
    	for(int j=2*i;j<=AMAX;j+=i){
    		w[j] -= w[i];
    		w[j] += mod;
    		w[j] %= mod;
    	}
    }


    ll res = 0;
    for(int i=1;i<=AMAX;i++){
    	ll A=0, B=0;
    	for(int j=i;j<=AMAX;j+=i){
    		A += (cnt[j] * j)%mod;
    		A %= mod;
    		B += ((cnt[j] * j)%mod * j)%mod;
    		B %= mod;
    	}
    	ll tmp = A*A-B;
    	tmp += mod;
    	tmp %= mod;
    	tmp *= modinv(2, mod);
    	tmp %= mod;
    	tmp *= w[i];
    	tmp %= mod;
    	res += tmp;
    	res %= mod;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 17408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main(){
long long a,b,k;cin>>a>>b>>k;
if(k>=a&&b-k+a>=0)cout<<0<<" "<<b-(k-a);
else if(k>=a)cout<<0<<" "<<0;
else cout<<a-k<<" "<<b;
}


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

const int mxN = 1e2 + 3, mxK = 1e5 + 3, MOD = 1e9 + 7;
int n, k, candies[mxN];
int dp[mxN][mxK], prefix[mxK];

int calc(int i)
{
    if (i < 0)
        return 0;
    return prefix[i];
}

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> candies[i];
    
    dp[0][0] = 1;
    for (int i = 0; i <= mxK; i++)
    {
        prefix[i] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int c = 0; c <= k; c++)
        {
            int ret = 0;
            // for (int use = 0; use <= candies[i]; use++)
            // {
            //     if (c - use >= 0)
            //     {
            //         ret += dp[i - 1][c - use];
            //         ret %= MOD;
            //     }
            // }

            ret = ((calc(c) - calc(max(c - candies[i], 0) - 1)) % MOD + MOD) % MOD;
            dp[i][c] = ret;
        }

        prefix[0] = dp[i][0];
        for (int a = 1; a <= k; a++)
        {
            prefix[a] = prefix[a - 1] + dp[i][a];
            prefix[a] %= MOD;
        }
    }

    cout << dp[n][k];
}

Measured memory_bytes: 43040
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size()-8;i++) putchar(s[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e5+10;

int n,a,b;

int32_t main(){
    cin>>n>>a>>b;
    if(a<b) swap(a,b);
    if((a-b)%2==0){
	cout<<"Alice\n";
    }else{
	cout<<"Borys\n";
    }	
}


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

int h,w,s;
int map[32][32];
int all;
pair<int,int> memo[32][32][33][33];

pair<int,int> rec(int y1,int x1,int y2,int x2,int sum){
  pair<int,int> res,hoge1,hoge2;
  int a=1,b=0;
  int tmp;
  bool flag = false;

  if(memo[y1][x1][y2][x2].first>=0)return memo[y1][x1][y2][x2];

  tmp = 0;
  for(int i=x1+1;i<x2;i++){

    for(int j=y1;j<y2;j++)tmp += map[j][i-1];

    if( all-tmp <= s && all-(sum-tmp) <= s){
      flag = true;
      hoge1 = rec(y1,x1,y2,i,tmp);
      hoge2 = rec(y1,i,y2,x2,sum-tmp);
      if(hoge1.first+hoge2.first > a){
	a = hoge1.first + hoge2.first;
	b = max(hoge1.second,hoge2.second);
      }else if(hoge1.first + hoge2.first == a && max(hoge1.second,hoge2.second) < b){
	b = max(hoge1.second,hoge2.second);
      }
    }
    if(all-(sum-tmp) >s)break;
  }

  tmp = 0;
  for(int i=y1+1;i<y2;i++){

    for(int j=x1;j<x2;j++)tmp += map[i-1][j];

    if( all-tmp <= s && all-(sum-tmp) <= s){
      flag = true;
      hoge1 = rec(y1,x1,i,x2,tmp);
      hoge2 = rec(i,x1,y2,x2,sum-tmp);
      if(hoge1.first+hoge2.first > a){
	a = hoge1.first + hoge2.first;
	b = max(hoge1.second,hoge2.second);
      }else if(hoge1.first + hoge2.first == a && max(hoge1.second,hoge2.second) < b){
	b = max(hoge1.second,hoge2.second);
      }
    }
    if(all-(sum-tmp) >s)break;
  }

  if(!flag){
    res.first = 1;
    res.second = all - sum;
  }else{
    res.first = a;
    res.second = b;
  }
  memo[y1][x1][y2][x2] = res;
  return res;
}


int main(){
  pair<int,int> ans;
  while(1){
    cin >> h >> w >> s;
    if(!h && !w && !s)break;

    all = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> map[i][j];
	all += map[i][j];
      }
    }
 
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=0;k<=h;k++){
	  for(int l=0;l<=w;l++){
	    memo[i][j][k][l].first = -1;
	    memo[i][j][k][l].second = -1;
	  }
	}
      }
    }

    ans = rec(0,0,h,w,all);
    cout << ans.first << " " << s - ans.second << endl;
  }
}

Measured memory_bytes: 9588
n = int(input())
d, x = map(int, input().split())
ans = 0
 
for _ in range(n):
  a = int(input())
  j = 0
  while True:
    if j*a + 1 <= d:
      ans += 1
      j += 1
      
    else:
      break
      
print(ans+x)

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

void maxHeapify(vector<int>& S, int i)
{
	int l = i * 2;
	int r = i * 2 + 1;
	int H = S.size() - 1;

	int largest;
	if (l <= H && S[i] < S[l]) largest = l;
	else largest = i;
	if (r <= H && S[largest] < S[r]) largest = r;

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

void insert(vector<int>& S, int k)
{
	S.push_back(k);
	int H = S.size()-1;
	while (H > 1 && S[H] > S[H / 2])
	{
		swap(S[H], S[H / 2]);
		H /= 2;
	}
}

int extract(vector<int>& S)
{
	int max = S[1];
	S[1] = S.back();
	maxHeapify(S, 1);

	S.pop_back();
	return max;
}

int main(void)
{
	int k, ans;
	string p;
	vector<int> S(1,0);

	while (p != "end")
	{
		cin >> p;
		if (p == "insert") {
			cin >> k;
			insert(S, k);
		}
		else if (p == "extract") { 
			cout << extract(S) << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 7068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 2e5 + 10;
const int MAXM = 2e6 + 10;
const ll mod = 1e9 + 7;



int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    ll a,b;
    scanf("%lld%lld",&a,&b);
    if(a % b == 0) {
        puts("-1");
        return 0;
    }
    ll ans = a * b;
    ans -= a;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
// -------- START : snippet -------- //

#include <bits/stdc++.h>
using namespace std;
#define rep1(i,n) for(int i=1;i<=int(n);++i)

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint pow(const modint x, ll r) {
        return x^r;
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int i = size; i <= n; i++) {
                factorial[i] = factorial[i-1] * modint(i);
            }
        }
        return factorial[n];
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


// -------- END : snippet -------- //

int main(void) {
    int s;
    cin >> s;
    modint res = 0;
    rep1(i,s){
        int rem = s - 3*i;
        if (rem >= 0) res += H(rem, i-1);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3656
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Data.Monoid
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  tasks <- fmap (mergeSortBy (\(a,b) (a',b') -> compare b b' <> compare a a')) $ U.replicateM n $ do
    [a,b] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a,b :: Int)
  let (as,bs) = U.unzip tasks
  let xs = U.tail $ U.scanl' (+) 0 as
  putStrLn $ if U.and $ U.zipWith (<=) xs bs
             then "Yes"
             else "No"

---

mergeSortBy :: (U.Unbox a) => (a -> a -> Ordering) -> U.Vector a -> U.Vector a
mergeSortBy !cmp !vec = doSort vec
  where
    doSort vec | U.length vec <= 1 = vec
               | otherwise = let (xs, ys) = U.splitAt (U.length vec `quot` 2) vec
                             in merge (doSort xs) (doSort ys)
    merge xs ys = U.create $ do
      let !n = U.length xs
          !m = U.length ys
      result <- UM.new (n + m)
      let loop !i !j
            | i == n = U.copy (UM.drop (i + j) result) (U.drop j ys)
            | j == m = U.copy (UM.drop (i + j) result) (U.drop i xs)
            | otherwise = let !x = xs U.! i
                              !y = ys U.! j
                          in case cmp x y of
                               LT -> do UM.write result (i + j) x
                                        loop (i + 1) j
                               EQ -> do UM.write result (i + j) x
                                        UM.write result (i + j + 1) y
                                        loop (i + 1) (j + 1)
                               GT -> do UM.write result (i + j) y
                                        loop i (j + 1)
      loop 0 0
      return result


Measured memory_bytes: 18940
/*
  挿入ソート
  2018/03/23
*/

#include<stdio.h>

void print(int *x,int n)
{
  int i;
  for(i=0;i<n-1;i++)
    printf("%d ",x[i]);
  printf("%d\n",x[i]);
}
int main(void)
{
  int a[100];
  int n;/*配列の要素数*/
  int temp;/*一時保存*/
  int i,j;
  fscanf(stdin,"%d",&n);
  
  for(i=0;i<n;i++)
    fscanf(stdin,"%d",&a[i]);
  print(a,n);
  
  for(i=1;i<n;i++){
    temp = a[i];
    j = i-1;
    while(j >= 0 && a[j] > temp){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = temp;
    print(a,n);
  }
  return 0;
}


Measured memory_bytes: 2096
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = []
# きっちりK回しなくていいみたい
for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N:
            break

        li = V[:left] + V[N - right :]
        li = sorted(li)

        d = K - left - right
        if d < 0:
            break

        c = sum(li)
        for i in range(min(d, len(li))):
            if li[i] < 0:
                c -= li[i]
            else:
                break

        ans.append(c)

print(max(ans))



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

int main()
{
    long long H;
    scanf("%lld", &H);
    long long W;
    scanf("%lld", &W);
    std::vector<std::string> S(H);
    for (int i = 0; i < H; i++)
    {
        std::cin >> S[i];
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i].at(j) == '#')
            {
                cout << "#";
            }
            else
            {

                int cnt = 0;
                for (int k = -1; k < 2; k++)
                {
                    for (int l = -1; l < 2; l++)
                    {
                        if ((i + k) < 0 || H <= (i + k) || (j + l) < 0 || W <= (j + l))
                        {
                            continue;
                        }
                        else if (S[i + k].at(j + l) == '#')
                        {
                            cnt++;
                        }
                    }
                }
                cout << cnt;
            }

            if(j == W-1){
                cout << endl;
            }

        }
    }
    return 0;
}


Measured memory_bytes: 256