akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch 81 | diff 81.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address 81.cpp && ./a.out

/*
 
 10/27/2019
 
 5:02-
 
 */

int N;

void solve() {
  FORE(a,1,9)FORE(b,1,9)if(a*b==N) {
    cout<<"Yes"<<endl;
    return;
  }
  cout<<"No"<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const ll mod = 7 * 17 * (1 << 23) + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int w, h, n, x, y;
string a, b;
bool go(char aa, char bb, int z, int r, int ai, int bi) {
	for (int i = 0; i < n; i++) {
		if (a[i] == aa)
			z += ai;
		if (z < 1 || z > r)
			return true;
		if (b[i] == bb)
			z = max(1, min(z + bi, r));
	}
	return false;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> w >> h >> n >> x >> y >> a >> b;
	bool c = go('L', 'R', y, h, -1, 1) || go('R', 'L', y, h, 1, -1)
			|| go('U', 'D', x, w, -1, 1) || go('D', 'U', x, w, 1, -1);
	cout << (c?"NO":"YES");
	return 0;
}


Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
//purvikaurraina
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n,sum=0;
    scanf("%d",&n);
    int a[2][101],b[101]={0},i,j;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[0][i]);
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[1][i]);
    }
    sum=sum+a[0][0]+a[1][n-1];//purvikaurraina
    for(i=0;i<n-1;i++)//purvikaurraina
    {
        for(j=i;j<n-1;j++)
        {
            b[i]=b[i]+a[1][j];//purvikaurraina
        }
        for(j=0;j<i;j++)
        {
            b[i]=b[i]+a[0][j+1];//purvikaurraina
        }
    }
    sort(b,b+(n-1),cmp);
    sum=sum+b[0];//purvikaurraina
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

int main(int argc, const char * argv[]) {
    int n, mw;
    SCD(n);
    SCD(mw);
    int w[n], v[n];
    FOR(i, 0, n, 1) {
        SCD(w[i]);
        SCD(v[i]);
    }
    ull dp[mw + 1][n];
    MEM(dp, 0);
    FOR(i, 1, mw + 1, 1) {
        FOR(j, 0, n, 1) {
            if (j == 0) {
                dp[i][j] = (w[j] <= i) ? v[j] : 0;
            } else {
                if (w[j] < i) {
                    dp[i][j] = max(v[j] + dp[i - w[j]][j - 1], dp[i][j - 1]);
                } else if (w[j] == i) {
                    dp[i][j] = max((ull)v[j], dp[i][j - 1]);
                } else {
                    dp[i][j] = dp[i][j - 1];
                }
            }
        }
    }

    printf("%lld\n", dp[mw][n - 1]);
}


Measured memory_bytes: 78336
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int x,i,n,m,a,b,c;
    while(~scanf("%d %d",&n,&m))
    {
        x=(n-1)*(m-1);
        printf("%d\n",x);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int H, W, K;
    cin >> H >> W >> K;
    int sh, sw, gh, gw;
    cin >> sh >> sw >> gh >> gw;
    --sh, --sw, --gh, --gw;
    vector<string> fi(H);
    REP(i,H) cin >> fi[i];

    queue<pair<int, int>> q;
    q.emplace(sh, sw);
    vector<vector<int>> dist(H, vector<int>(W, INF));
    dist[sh][sw] = 0;
    while(!q.empty()){
        auto [h, w] = q.front(); q.pop();
        REP(i,4){
            for(int l=1;l<=K;l++){
                int nh = h + l * dx[i], nw = w + l * dy[i];
                if(nh < 0 || nh >= H || nw < 0 || nw >= W) break;
                if(fi[nh][nw] == '@') break;
                if(dist[nh][nw] <= dist[h][w]) break;
                if(dist[nh][nw] > dist[h][w] + 1){
                    dist[nh][nw] = dist[h][w] + 1;
                    q.emplace(nh, nw);
                }
            }
        }
    }

    if(dist[gh][gw] == INF) dist[gh][gw] = -1;
    cout << dist[gh][gw] << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 12120
from heapq import heappush, heappop, heappushpop
import sys
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

Q = int(input())
L = []
R = []

B = 0
M = 0

for _ in range(Q):
    q = inpl()
    if len(q) == 3:
        B += q[2]
        if len(R) == 0:
            L.append(-q[1])
            R.append(q[1])
            continue

        M += min(abs(-L[0] - q[1]), abs(R[0] - q[1])) * (not (-L[0] <= q[1] <= R[0]))
        if q[1] < R[0]:
            heappush(L, -q[1])
            heappush(R, -heappushpop(L, -q[1]))
        else:
            heappush(R, q[1])
            heappush(L, -heappushpop(R, q[1]))
    else:
        print(-L[0], B+M)

Measured memory_bytes: 19040
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int bit=0; bit<(1<<3); ++bit){
    int sum = s[0]-'0';
    for(int i=1; i<=3; ++i){
      if(bit & (1<<(i-1))) sum += s[i]-'0';
      else sum -= s[i]-'0';
    }
    if(sum == 7){
      cout << s[0];
      for(int i=1; i<=3; ++i){
        if(bit & (1<<(i-1))) cout << "+" << s[i];
        else cout << "-" << s[i];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d,n,ans;
    cin>>d>>n;
    if(d==0)
    {

if(n<100)
        ans=n;

    else ans=101;
    }
    if(d==1)
    {
        if(n<100)ans=n*100;
        else ans=10100;
    }
    if(d==2)
    {
        if(n<100)ans=n*10000;
        else ans=101*10000;
    }
    cout<<ans<<'\n';

    return 0;
}


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

#define MOD 1000000007
template<typename ty1,typename ty2>
inline int add(ty1 x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x += y; return x < MOD ? x : x - MOD;
}
template<typename ty1,typename ty2>
inline void addto(ty1 &x, ty2 y) {
		  if(y>=MOD)y%=MOD;
		  if(x>=MOD)x%=MOD;
	      x += y; if (x >= MOD) x -= MOD;
}
template<typename ty1,typename ty2>
inline int sub(ty1 x, ty2 y) {
		if(y>=MOD)y%=MOD;
		 if(x>=MOD)x%=MOD;
        x -= y; return x < 0 ? x + MOD : x;
}
template<typename ty1,typename ty2>
inline void subto(ty1 &x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x -= y; if (x < 0) x += MOD;
}
template<typename ty1,typename ty2>
inline int mul(ty1 x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        return 1ll * x * y % MOD;
}
template<typename ty1,typename ty2>
void multo(ty1 &x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        x=1ll * x * y % MOD;
}
#define MAX 200002
int n;
int t;

vector<pair<long long int,long long int> > v;


vector<int> z;
long long int dp[200002][30];

int main(){
	cin>>n>>t;
	z.clear();
	for(int i=0;i<n;i++){
		long long int a,b;
		scanf("%lld%lld",&a,&b);
		if(a==0){
			z.push_back(b);
		}
		else{
			v.push_back(make_pair(a,b));
		}
	}
	auto cmp=[&](auto a,auto b)->bool{
		return a.first*(b.second+1)-(a.second+1)*b.first>0LL;
	};
	sort(v.begin(),v.end(),cmp);
	memset(dp,-1,sizeof(dp));
	dp[0][0]=1;
	for(int i=0;i<v.size();i++){
		for(int j=0;j<30;j++){
			dp[i+1][j]=dp[i][j];
			if(j&&dp[i][j-1]!=-1){
				long long int tmp=dp[i][j-1]+v[i].first*dp[i][j-1]+v[i].second;
				if(tmp<=t){
					if(dp[i+1][j]==-1||dp[i+1][j]>tmp+1){
						dp[i+1][j]=tmp+1;
					}
				}
			}
		}
	}
	sort(z.begin(),z.end());
	for(int i=1;i<z.size();i++){
		z[i]+=z[i-1]+1;
	}
	int ans=0;
	for(int j=0;j<30;j++){
		if(dp[v.size()][j]==-1)break;
		long long int cur=dp[v.size()][j];
		long long int res=t-cur;
		int id=upper_bound(z.begin(),z.end(),res)-z.begin();
		ans=max(ans,j+id);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 51180
#include <stdio.h>

int main(void)
{
	float w;
	
	while (scanf("%f", &w) != EOF){
		if (w <= 48){
			printf("light fly\n");
		}
		else if (w > 48 && w <= 51){
			printf("fly\n");
		}
		else if (w > 51 && w <= 54){
			printf("bantam\n");
		}
		else if (w > 54 && w <= 57){
			printf("feather\n");
		}
		else if (w > 57 && w <= 60){
			printf("light\n");
		}
		else if (w > 60 && w <= 64){
			printf("light welter\n");
		}
		else if (w > 64 && w <= 69){
			printf("welter\n");
		}
		else if (w > 69 && w <= 75){
			printf("light middle\n");
		}
		else if (w > 75 && w <= 81){
			printf("middle\n");
		}
		else if (w > 81 && w <= 91){
			printf("light heavy\n");
		}
		else if (w > 91){
			printf("heavy\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String W = in.nextLine();
		W = W.toLowerCase();
		int ans = 0;
		while(in.hasNext()) {
			String s = in.nextLine();
			if(s.equals("END_OF_TEXT")) break;
			s = s.toLowerCase();
			String sp[] = s.split(" ");
			for(int i=0;i<sp.length;i++) {
				if(sp[i].equals(W)) ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 26144
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

int main() {
    Int n;
    cin >> n;
    vector<Int> d(n);
    for (Int i = 0; i < n; i++) cin >> d[i];
    sort(d.begin(), d.end());
    if (n % 2 == 1) {
        dump(0);
    }
    else {
        dump(d[n / 2] - d[n / 2 - 1]);
    }
    return 0;
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline
write = sys.stdout.write

EPS = 1e-9
def line_cross_point(P1, P2, Q1, Q2):
    x0, y0 = P1; x1, y1 = P2
    x2, y2 = Q1; x3, y3 = Q2

    dx0 = x1 - x0; dy0 = y1 - y0
    dx1 = x3 - x2; dy1 = y3 - y2

    s = (y0-y2)*dx1 - (x0-x2)*dy1
    sm = dx0*dy1 - dy0*dx1
    if -EPS < sm < EPS:
        return None
    return x0 + s*dx0/sm, y0 + s*dy0/sm

def bisector(P1, P2, Q1, Q2):
    x0, y0 = P1; x1, y1 = P2
    x2, y2 = Q1; x3, y3 = Q2

    dx0 = x1 - x0; dy0 = y1 - y0
    dx1 = x3 - x2; dy1 = y3 - y2

    cp = line_cross_point(P1, P2, Q1, Q2)
    if cp is None:
        return None

    cx, cy = cp

    d0 = (dx0**2 + dy0**2)**.5
    d1 = (dx1**2 + dy1**2)**.5
    return [
        ((cx, cy), (cx + (dx0*d1 + dx1*d0), cy + (dy0*d1 + dy1*d0))),
        ((cx, cy), (cx + (dx0*d1 - dx1*d0), cy + (dy0*d1 - dy1*d0))),
    ]

def line_point_dist2(p1, p2, q):
    x, y = q

    x1, y1 = p1; x2, y2 = p2
    dx = x2 - x1; dy = y2 - y1
    dd = dx**2 + dy**2
    sv = (x - x1) * dy - (y - y1) * dx
    return abs(sv / dd**.5)


def check(LS, q):
    ds = [line_point_dist2(p1, p2, q) for p1, p2 in LS]
    return all(abs(ds[0] - e) < EPS for e in ds)

def solve():
    N = int(readline())
    if N == 0:
        return False
    P = []
    for i in range(N):
        x1, y1, x2, y2 = map(int, readline().split())
        P.append(((x1, y1), (x2, y2)))
    if N <= 2:
        write("Many\n")
        return True

    s = []
    for i in range(N):
        p1, p2 = P[i]
        for j in range(i):
            q1, q2 = P[j]
            bs = bisector(p1, p2, q1, q2)
            if bs is None:
                continue
            s.append(bs)
            if len(s) > 1:
                break
        else:
            continue
        break
    if len(s) < 2:
        write("None\n")
        return True
    ans = []
    b1, b2 = s
    for p1, p2 in b1:
        for q1, q2 in b2:
            cp = line_cross_point(p1, p2, q1, q2)
            if cp is None:
                continue
            if check(P, cp):
                cx, cy = cp
                for ax, ay in ans:
                    if abs(cx - ax) < EPS and abs(cy - ay) < EPS:
                        break
                else:
                    ans.append(cp)
    if len(ans) == 0:
        write("None\n")
    elif len(ans) > 1:
        write("Many\n")
    else:
        write("%.16f %.16f\n" % ans[0])
    return True
while solve():
    ...


Measured memory_bytes: 5704
def main():
    import sys

    input = sys.stdin.readline
    n, k = map(int, input().split())
    nt = tuple(range(n))
    kt = tuple(range(1, k + 1))
    h = tuple(map(int, input().split()))
    dp = [10 ** 9] * n
    dp[0] = 0
    for i in nt:
        for j in kt:
            i_j = i + j
            if i_j < n:
                x = dp[i] + abs(h[i] - h[i_j])
                if dp[i_j] > x:
                    dp[i_j] = x
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 23908
#include<stdio.h>
 
int face[7][7][4] = {
{{0},{0},{0},{0},{0},{0},{0}},
{{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
{{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
{{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
{{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
{{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
{{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int assign[7];
 
int main()
{
    int q,i,t,f;
 
    for(i=1;i<=6;i++) scanf("%d", assign+i);
    scanf("%d",&q);
    while(q--){
        scanf("%d%d",&t,&f);
        for(i=1;i<=6;i++){
            if(assign[i]==t)t=i;
            if(assign[i]==f)f=i;
        }
        printf("%d\n",assign[face[t][f][3]]);
    }
    return 0;
}


Measured memory_bytes: 2052
import numba as nb
@nb.njit
def solve(n,k,a):
    dp=[0]*n
    dp[1]=abs(a[1]-a[0])
    for i in range(2,n):
        mi=10**9
        temp=1
        for j in range(i-1,-1,-1):
            if temp>k:
                break
            else:
                temp+=1
            if abs(a[i]-a[j])+dp[j]<mi:
                mi=abs(a[i]-a[j])+dp[j]
        dp[i]=mi
    print(dp[n-1])
n,k=map(int,input().split())
a=list(map(int,input().split()))
solve(n,k,a)

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

int main() {
  int A,B;
  int K;
  cin >> K >> A >>B;
  for(int i=A;i<=B;i++){
    if(i % K == 0){
      cout << "OK" << endl;
      return(0);
    }
  }
  
  cout << "NG" << endl;
  
  return(0);
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long


const int maxn = 1e5+5;
vector<int> adj[maxn];
list< pair<int, int> > q;  // a fringe
int dist[maxn][3];


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

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

    int n,m; cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u,v; cin >> u >> v;
        adj[u].push_back(v);
    }

    int s,t; cin >> s >> t;
    q.emplace_back(s, 0);
    dist[s][0] = 0;
    
    while (!q.empty()) {
        int curr, d;
        tie(curr, d) = q.front();
        q.pop_front();
        for (int nei : adj[curr]) {
            if (dist[nei][(d+1) % 3] == -1) {
                q.emplace_back(nei, (d+1) % 3);
                dist[nei][(d+1) % 3] = dist[curr][d] + 1;
            }
        }
    }

    if (dist[t][0] == -1) {
        cout << -1 << endl;
    } else {
        cout << dist[t][0] / 3 << endl;
    }

}


Measured memory_bytes: 7164
mod = 10**9+7
K = input()
D = int(input())
dp = [0] * D
s = 0
for i in range(len(K)):
    ndp = [0] * D
    for j in range(D):
        for d in range(10):
            ndp[(j+d) % D] = (ndp[(j+d) % D] + dp[j]) % mod
    for d in range(int(K[i])):
        ndp[(s+d) % D] += 1
    dp = ndp
    s = (s + int(K[i])) % D
print((dp[0] - 1 + (s == 0)) % mod)

Measured memory_bytes: 43740
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long l,r;
  cin >> l >> r;

  long long ans=2020;
  int flg = 0;
  for (long long i = l; i < r; i++)
  {
    for (long long j = l+1; j <= r; j++)
    {
      long long res = i*j;
      ans=min(ans,res%2019);
      if(ans==0){
        flg=1;
        break;
      }
    }
    if(flg) break;
  }
  cout << ans << endl;
}

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

#define rep(i, u) for (int i = 0; i < u; i++)

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

int main() {
  int n;
  double d1 = 0, d2 = 0, d3 = 0, d = 0;
  int x[100] = {}, y[100] = {}, xy[100] = {};
  cin >> n;
  rep(i, n) cin >> x[i];
  rep(i, n) cin >> y[i];
  rep(i, n) xy[i] = abs(x[i] - y[i]);
  rep(i, n) d1 += xy[i];
  cout << fixed << setprecision(10) << d1 << endl;
  rep(i, n) d2 += pow(xy[i], 2);
  cout << fixed << setprecision(10) << sqrt(d2) << endl;
  rep(i, n) d3 += pow(xy[i], 3);
  cout << fixed << setprecision(10) << cbrt(d3) << endl;
  rep(i, n) if (d < xy[i]) d = xy[i];
  cout << fixed << setprecision(10) << d << endl;
  return 0;
}



Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a<b){
        swap(a, b);
    }
    if(b<c){
        swap(b, c);
    }
    if (a < b)
    {
        swap(a, b);
    }
    int ans = 0;
    b = a - b;
    c = a - c;
    if((b%2 == 0)^(c%2==0)){
        ans += b / 2;
        ans += c / 2;
        ans += 2;
    }else{
        ans += b / 2;
        ans += c / 2;
        if(b%2!=0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!
ll sum(const string &s){
  if(s.length()==1) return s[0] - '0';
  ll ret = 0;
  int i=0;
  while(s[i]!='+'){
    ret *= 10;
    ret += s[i] - '0';
    i++;
    if(i==s.length()) return ret;
  }
  auto t = s.substr(i+1);
  dump(t);
  ret += sum(t);
  return ret;
}
// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  string s; cin >> s;
  int n = s.length()-1;
  int N = 1;
  ll ret = 0;
  rep(i,n) N *= 2;
  rep(b_,N){
    string S;
    int b = b_;
    rep(i,n){
      S += s[i];
      if(b&1) S += "+";
      b >>= 1;
    }
    S += s[n];
    //dump(S);
    ret += sum(S);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
	IOS;
	int K;
	cin>>K;
	ll ans=0;
	for(int i=1;i<=K;i++)
	{
		for(int j=1;j<=K;j++)
		{
			ll p=__gcd(i,j);
			for(int k=1;k<=K;k++)
			{
				ans+=__gcd((ll)k,p);
			}
		}
	}
	cout<<ans;
}


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

// template<typename T> T gcd(T a, T b){
//   if(b==0){
//     return a;
//   }
//   return gcd(b, a%b);
// }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int k;
  cin>>k;
  ll ans=0;
  FOR(i, 1, k+1){
    FOR(j, 1, k+1){
      FOR(l, 1, k+1){
        ans+=gcd(i, gcd(j, l));
      }
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 3648
N,M,C=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]

cnt=0

for n in range(N):
    ans=0
    A=[int(x) for x in input().split()]    
    for m in range(M):
        ans += A[m]*B[m]
    if (ans+C>0):
        cnt+=1
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

class DisjointSet {
private:
	vector<int> rank, size, p;
	int num = 0;
public:
	DisjointSet() {}
	DisjointSet(int n) {
		num = n;
		rank.assign(n, 0);
		size.assign(n, 1);
		p.assign(n, 0);
		for (int i = 0; i < n; i++) p[i] = i;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return;
		num--;
		if (rank[x] > rank[y]) {
			p[y] = x;
			size[x] += size[y];
		} else {
			p[x] = y;
			size[y] += size[x];
			if (rank[x] == rank[y]) rank[y]++;
		}
	}

	int root(int x) {
		return p[x] == x ? x : p[x] = root(p[x]);
	}

	int get_size(int x) {
		return size[root(x)];
	}

	int forest_size() {
		return num;
	}
};

int main() {
	int n, m, k; cin >> n >> m >> k;
	DisjointSet dj(n);
	vector<vector<int> > G(n);
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		dj.unite(a, b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for (int i = 0; i < k; ++i) {
		int c, d; cin >> c >> d;
		--c, --d;
		G[c].push_back(d);
		G[d].push_back(c);
	}
	for (int i = 0; i < n; ++i) {
		if (i) cout << " ";
		int ans = dj.get_size(i) - 1;
		for (auto v : G[i])
			if (dj.same(i, v)) --ans;
		cout << ans;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 8704
#include<stdio.h>

int main(void){
  int x,i = 1;
 
  while(1){
    int x = 0;
    scanf("%d",&x);
    if(x == 0){
      break;
    }
    printf("Case %d: %d\n",i,x);
    i++;
  }
  return 0;
}


Measured memory_bytes: 2032
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<int>x(n, 0); stack<int>s;
	vector < vector<pair<int, int>>>l(n), r(n);
	for (int i = 0, L, R, d; i < m; i++) {
		cin >> L >> R >> d; L--; R--;
		l[R].push_back({ L,d }); r[L].push_back({ R,d });
	}
	for (int i = 0; i < n; i++) {
		if (l[i].size() == 0) { x[i] = 1; s.push(i); }
	}
	bool ok = true;
	while (!s.empty()) {
		int node = s.top(); s.pop();
		for (int i = 0; i < r[node].size(); i++) {
			int next = r[node][i].first, xd = x[node] + r[node][i].second;
			if (x[next] == 0) { x[next] = xd; s.push(next); }
			else if (x[next] != xd) { ok = false; break; }
		}
	}
	for (int i = 0; i < n; i++) if (x[i] == 0)ok = false;
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 12288
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

H, W = reads()
N = read()
A = reads()

field = [[0] * W for _ in range(H)]
ls = sorted(product(range(H), range(W)), key=lambda p: (p[0], (-1)**p[0] * p[1]))
for i, j in ls:
  field[i][j] = len(A)
  A[-1] -= 1
  if A[-1] == 0:
    A.pop()

for i in range(H):
  print(" ".join(str(x) for x in field[i]))


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,M;
ll ma[10];
const ll mn[]={0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<pll> mv;
ll c1,c2,c3;
ll am[10], mr, an[10];
ll i,j;
void ga(ll a,ll r,ll n){
    //printf("%lld,%lld,%lld", a, r, n);
    ll i;
    if(n==0){
        if(mr<r){
            mr = r;
            fornum(i,0,9){
                an[1+i] = am[1+ i];
            }
        }else if(mr==r){
            ll ff = 0;
            fornum(i,0,9){
                if(am[9-i]==an[9-i])
                    continue;
                ff = am[9 - i] > an[9 - i] ? 1 : 0;
                break;
            }
            if(ff==0)
                return;
            fornum(i,0,9){
                an[1+i] = am[1+ i];
            }
        }
        return;
    }
    if(a==mv.size())
        return;
    ll num = -mv[a].second;
    ll an = mv[a].first;
    for (ll ii = 0; ii*an <= n;ii++){
        am[num] = ii;
        ga(a + 1, r + ii, n - ii * an);
    }
    am[num] = 0;
    return;
}

int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,M){
        ll aa = 0;
        scanf("%lld", &aa);
        mv.push_back(mp(mn[aa], -aa));
    }
    sort(mv.begin(), mv.end());
    c1 = -mv[0].second;
    c2 = mv[0].first;
    am[c1]=an[c1] = N / c2;
    N = N % c2;
    fornum(i,0,9){
        ga(1, am[c1], N + i * c2);
        am[c1]--;
    }
    fornum(i,0,9){
        fornum(j,0,an[9-i]){
            printf("%lld", 9ll - i);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;
const float EPS = 1e-9;

using namespace std;

void init()
{
}

void solve()
{
	ll a;
	double b;
	cin >> a >> b;

	ll c = (ll)(b * 100 + EPS);

	ll mul = a * c;
	ll ans = mul / 100;

	cout << ans << endl;
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3188
import heapq
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

h = []
heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0)))

ans = []
e = set()
for _ in range(K):
    p, v = heapq.heappop(h)
    i, j, k = v
    ans.append(p)
    if i + 1 < X and j < Y and k < Z and not (-(A[i+1] + B[j] + C[k]), (i+1, j, k)) in e:
        heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i+1, j, k)))
        e.add((-(A[i + 1] + B[j] + C[k]), (i+1, j, k)))
    if i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j+1] + C[k]), (i, j+1, k)) in e:
        heapq.heappush(h, (-(A[i] + B[j+1] + C[k]), (i, j+1, k)))
        e.add((-(A[i] + B[j+1] + C[k]), (i, j+1, k)))
    if i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k+1]), (i, j, k+1)) in e:
        heapq.heappush(h, (-(A[i] + B[j] + C[k+1]), (i, j, k+1)))
        e.add((-(A[i] + B[j] + C[k+1]), (i, j, k+1)))

for a in ans:
    print(-a)

Measured memory_bytes: 6000
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, q;
    cin >> n >> q;
    vector<priority_queue<int>> pq(n);
    while (q--) {
        int com, t;
        cin >> com >> t;
        if (com == 0) {
            int x;
            cin >> x;
            pq[t].push(x);
        } else if (com == 1) {
            if (!pq[t].empty()) cout << pq[t].top() << endl;
        } else {
            if (!pq[t].empty()) pq[t].pop();
        }
    }
}



Measured memory_bytes: 3992
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

ll f(ll x, ll y)
{
    if (x == 0 || y == 0)
        return 0;

    if (x < y && y % x == 0)
        return (y / x) * x * 2 - x;
    if (y < x && x % y == 0)
        return (x / y) * y * 2 - y;

    if (x < y)
        return f(x, y - (y / x) * x) + (y / x) * x * 2;
    else if (x > y)
        return f(x - (x / y) * y, y) + (x / y) * y * 2;
    else
        return x;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, X;
    cin >> N >> X;
    ll ans = N + f(N - X, X);
    cout << ans << endl;
    return 0;
}

// X + (N - X) + X + X + (N - X)
// http://tutuz.hateblo.jp/entry/2018/09/06/224654
// 平行四辺形の短辺をa，長辺をbとする平行四辺形から進む光の距離func(a, b)はfunc(a, b) = 2a + func(a, b - a)である．


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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK (cerr <<"OK"<< endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

vector<vector<int>> adj((int)2e5);
vector<vector<int>> adj2((int)2e5);
vector<int> vis((int)2e5);

set<int> g;
void dfs(int u) {
  g.insert(u);
  vis[u] = true;

  for(int v: adj[u]) {
    if(!vis[v])
      dfs(v);
  }
}

signed main () {
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m, k;

  cin >> n >> m >> k;

  while(m--) {
    int u, v;

    cin >> u >> v;

    adj[u].pb(v);
    adj[v].pb(u);
  }

  while(k--) {
    int u, v;

    cin >> u >> v;

    adj2[u].pb(v);
    adj2[v].pb(u);
  }

  vector<int> ans(n + 1);
  for(int i = 1; i <= n; i++) {
    if(!vis[i]) {
      g.clear();
      dfs(i);
      for(int x: g) {
        ans[x] = (int)g.size() - (int)adj[x].size() - 1;
        for(int v: adj2[x])
          if(g.count(v))
            ans[x]--;
      }
    }
  }  

  for(int i = 1; i <=n; i++)
    cout << ans[i] << " \n"[i == n];
}

Measured memory_bytes: 24692
N=int(input())
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

if N==1:
  print(1)
  exit()
else:
  D=[0]*(N+1)
  for i in range(2,N+1):
    A=factorization(i)
    for j in A:
      D[j[0]]+=j[1]
  ans=1
  for i in D:
    ans*=(i+1)
    ans%=10**9+7
  print(ans)

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


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;


lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli a[100], b[100] = {};

int main(void) {

	lli N;
	cin >> N;
	FOR(N)
		cin >> b[i];

	FOR(N) {
		bool can = false;
		for (int j = N - i - 1; j >= 0; j--) {
			if (b[j] == j + 1) {
				a[i] = j + 1;
				for (int k = j; k < N - i - 1; k++) {
					b[k] = b[k + 1];
				}
				can = true;
				break;
			}
		}
		if (!can) {
			COUT(-1);
			return 0;
		}
	}

	reverse(a, a + N);

	FOR(N) {
		COUT(a[i]);
	}

	return 0;
}

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

const int mod = 1000000007;

struct mint {
    ll x;

    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
    }

    mint &operator-=(const mint a) {
      if ((x += mod - a.x) >= mod) x -= mod;
      return *this;
    }

    mint &operator*=(const mint a) {
      (x *= a.x) %= mod;
      return *this;
    }

    mint operator+(const mint a) const {
      mint res(*this);
      return res += a;
    }

    mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
    }

    mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
    }

    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
    }

    mint inv() const {
      return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
      return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
    }
};

const int N = 2000020;
mint table[N];

void init() {
  table[0] = table[1] = 1;
  for (ll i = 2; i < N; i++) {
    table[i] = table[i - 1] * i;
  }
}

mint nCr(int n, int r) {
  return table[n] / table[r] / table[n - r];
}

signed main() {
  ll n,m;
  cin >> n >> m;

  init();
  mint answer = 0;
  // i個A[j] == B[j]になるものがある時
  for (ll i = 0; i <= n; i++) {
    answer += table[m - i] / table[(m - i) - (n - i)] * nCr(n, i) * (i % 2 == 0 ? +1 : -1);
  }
  answer = answer * table[m] / table[m - n];
  cout << answer.x << '\n';
}


Measured memory_bytes: 19264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    vector<int> can;
    for(int i = 0; i < (int)S.size(); i++){
        if(S[i] == 'o') can.push_back(i + 1);
    }
    vector<int> L(K), R(K);
    int size = can.size();
    L[0] = can[0];
    int ind = 0;
    for(int i = 1; i < K; i++){
        while(can[ind] - L[i - 1] <= C) ind++;
        L[i] = can[ind];
    }
    R[K - 1] = can[size - 1];
    ind = size - 1;
    for(int i = K - 2; i >= 0; i--){
        while(R[i + 1] - can[ind] <= C) ind--;
        R[i] = can[ind];
    }
    for(int i = 0; i < K; i++){
        if(L[i] == R[i]){
            cout << L[i] << endl;
        }
    }
}

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

ll absll(ll a){
  if(a<0){
    return a * -1;
  }
  return a;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n,0);
  ll count = 0;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i]<0){
      count++;
      sum += a[i] * -1;
      a[i] *= -1;
    }else{
      sum += a[i];
    }
  }
  sort(a.begin(), a.end());
  if(count%2==0){
    cout << sum << endl;
  }else{
    cout << sum + a[0]*-2 << endl;
  }
  return 0;
}

Measured memory_bytes: 4024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		int m = sc1.nextInt();
		int x = sc1.nextInt();
		int[] a = new int[m];
		int cost1 = 0;
		int cost2 = 0;

		for (int i = 0 ; i < m ; i++ ) {
			a[i] = sc1.nextInt();
			if (a[i] < x) {
				cost1++;
			}
			else if (a[i] > x) {
				cost2++;
			}
		}

		if (cost1 < cost2) {
			System.out.println(cost1);
		}
		else {
			System.out.println(cost2);
		}

		sc1.close();
	}

}


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

int find(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main() {
	int N ;
	cin >> N ;
	
		int sum = find(N);

		if (N %sum  != 0) cout << "No" << endl;
		else cout << "Yes" << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    
    int n, k;
    cin >> n >> k;
    double ans = 0;
    rep3(i, 1, n + 1) {
        int cur = i;
        double tmp = 1.0 / n;
        while (cur < k) {
            cur *= 2;
            tmp *= 1.0 / 2;
        }
        ans += tmp;
        // cout << tmp << '\n';
    }
    cout << fixed << setprecision(10) << ans << '\n';
}


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

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int ans;
	if (n < k) {
		ans = n * x;
	}
	else {
		ans = k * x;
	}
	if (n > k) {
		ans += (n - k)*y;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long a, b;
    scanf("%ld%ld", &a, &b);
    if(a+b==15) {
        printf("+\n");
    }
    else if (a*b==15) {
        printf("*\n");
    }
    else {
        printf("x\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    int n;
    cin >> n;

    double ans = 0;
    rep(i, n){
        double a;
        cin >> a;
        ans += 1.0 / a;
    }

    ans = 1.0 / ans;
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//Binary Search Tree 2
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Node{
	int key;
	struct Node *parent;
	struct Node *left;
	struct Node *right;
}Node;

void Insert(int);
void Inorder(Node*);
void Preorder(Node*);
Node * Find(Node*,int);

Node *Root;


int main(){
	int m,i,k;
	char order[8];


	//input
	scanf("%d",&m);

	for(i=0;i<m;i++){
		scanf("%s",order);


		if(!strcmp("find",order)){
			scanf("%d",&k);
			Node *t=Find(Root,k);
			if(t!=NULL){
				printf("yes\n");
			}
			else{
				printf("no\n");
			}
		}
		if(!strcmp("insert",order)){
			scanf("%d",&k);
			Insert(k);
		}
		else if(!strcmp("print",order)){
			Inorder(Root);
			printf("\n");
			Preorder(Root);
			printf("\n");
		}
	}
	return 0;
}


void Insert(int k){
	Node *y=NULL;
	Node *x=Root;
	Node *new;

	new=(Node *)malloc(sizeof(Node));
	new->key=k;
	new->left=NULL;
	new->right=NULL;

	while(x != NULL){
		y=x;
		if(new->key < x->key){
			x=x->left;
		}
		else{
			x=x->right;
		}
	}
	new->parent=y;
	if(y==NULL){
		Root=new;
	}
	else if(new->key < y->key){
		y->left=new;
	}
	else{
		y->right=new;
	}
}


//Torigake-zyun (root-> L -> R)
void Inorder(Node *u){
	if(u==NULL){
		return;//todo
	}
	Inorder(u->left);
	printf(" %d",u->key);
	Inorder(u->right);
}


//Ikigake-zyun(L -> root -> R)
void Preorder(Node *u){
	if(u==NULL){
		return;//todo
	}

	printf(" %d",u->key);
	Preorder(u->left);
	Preorder(u->right);
}


Node * Find(Node *u,int k){
	while(u!=NULL && k!=u->key){
		if(k<u->key){
			u=u->left;
		}
		else{
			u=u->right;
		}
	}
	return u;
}






//2時までかかった…つらTT
//アルゴ単位ください(..)



Measured memory_bytes: 20452
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,p,d[1<<17];
main()
{
	cin>>n>>m>>p;
	for(int i=0;i<m;i++)
	{
		cin>>d[i];
		d[i]=(d[i]+n-p)%n;
	}
	sort(d,d+m);
	int ans=min(d[m-1],n-d[0]);
	for(int i=0;i<m-1;i++)
	{
		int x=d[i],y=n-d[i+1];
		ans=min(ans,x+y+min(x,y));
	}
	cout<<ans*100<<endl;
}


Measured memory_bytes: 3156
ret [] k = k
ret (a:as) k 
  | a * k > 1000000000000000000 = -1
  | otherwise = ret as (a * k)

main = do
  n <- getLine
  as <- (map read . words) <$> getLine
  putStrLn $ show $ if (0 `elem` as ) then 0 else ret as 1


Measured memory_bytes: 64168