akhauriyash/Code-Regression huggingface dataset:
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def insert(T, z):
    y = None
    x = T
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y

    if y is None:
        T = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

    return T


def preorder(T, ret):
    ret.append(T.key)

    if T.left is not None:
        preorder(T.left, ret)

    if T.right is not None:
        preorder(T.right, ret)


def inorder(T, ret):
    if T.left is not None:
        inorder(T.left, ret)

    ret.append(T.key)

    if T.right is not None:
        inorder(T.right, ret)


def find(T, key):
    if key == T.key:
        return T

    elif key < T.key:
        if T.left is not None:
            ret = find(T.left, key)
            if ret is not None:
                return ret
    else:
        if T.right is not None:
            ret = find(T.right, key)
            if ret is not None:
                return ret

    return None


def delete(T, key):
    if T is None:
        return None
    if key < T.key:
        delete(T.left, key)
    elif key > T.key:
        delete(T.right, key)
    else:
        _delete(T, key)


def _delete(T, key):
    parent = T.parent
    if T.left is None and T.right is None:
        if parent.left == T:
            parent.left = None
        else:
            parent.right = None
        T = None
    elif T.left is None or T.right is None:
        if parent.left == T:
            if T.left:
                parent.left = T.left
                T.left.parent = parent
            else:
                parent.left = T.right
                T.right.parent = parent
        else:
            if T.left:
                parent.right = T.left
                T.left.parent = parent
            else:
                parent.right = T.right
                T.right.parent = parent
        T = None
    else:
        nextnode = T.right
        while nextnode.left:
            nextnode = nextnode.left
        T.key = nextnode.key
        delete(nextnode, nextnode.key)


def main():
    m = int(input())
    Tree = None
    for i in range(m):
        cmd, *v = input().split()
        if cmd == "print":
            print(" ", end="")
            inans = []
            inorder(Tree, inans)
            print(*inans)
            print(" ", end="")
            preans = []
            preorder(Tree, preans)
            print(*preans)
        elif cmd == "insert":
            z = int(v[0])
            znode = Node(z)
            Tree = insert(Tree, znode)
        elif cmd == "find":
            z = int(v[0])
            if find(Tree, z) == None:
                print("no")
            else:
                print("yes")
        else:
            z = int(v[0])
            delete(Tree, z)


if __name__ == '__main__':
    main()



Measured memory_bytes: 94628
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
typedef long long ll;

int N, M;
int P[100000], Y[100000];
vector<int> yd[100001];
int main() {
    scanf("%d %d ", &N, &M);
    for (int i = 0; i < M; i++) {
        scanf("%d %d ", &P[i], &Y[i]), yd[P[i]].push_back(Y[i]);
    }

    for (int i = 0; i < N; i++) sort(yd[i + 1].begin(), yd[i + 1].end());

    for (int i = 0; i < M; i++) {
        int rank = lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) -
                   yd[P[i]].begin() + 1;
        printf("%06d%06d\n", P[i], rank);
    }
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int W, H, N;
	cin >> W >> H >> N; 
	int L = 0, R = W, D = 0, U = H; 
	for(int i = 0; i < N; i++){
		int X, Y, A; 
		cin >> X >> Y >> A; 
		if(A == 1){L = max(L, X);}
		else if(A == 2){R = min(R, X);}
		else if(A == 3){D = max(D, Y);}
		else if(A == 4){U = min(U, Y);}
	}
	cout << max(R - L, 0) * max(U - D, 0) << endl; 
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#define dprintf(...) printf(__VA_ARGS__)
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#define dprintf(...)
#endif

#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 RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

template <class T>
vec2<T> vec2_init(int n0, int n1, T x = 0) {
    return vec2<T>(n0, vector<T>(n1, x));
}

template <class T>
vec3<T> vec3_init(int n0, int n1, int n2, T x = 0) {
    return vec3<T>(n0, vec2_init(n1, n2, x));
}

/*
 *           U P
 *           - x
 *            ^
 *            |
 * LEFT -y <--+--> +y RIGHT
 *            |
 *            v
 *           + x
 *         D O W N
 */

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

enum {
    DOWN,
    RIGHT,
    UP,
    LEFT,
};

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

    string N;
    cin >> N;
    ll s = 0;
    for (char c: N) {
        s += (c - '0');
    }
    if (s % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3772
cs = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
c = gets.chomp
puts cs[cs.find_index(c) + 1]


Measured memory_bytes: 3836
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>     
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#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 F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)5e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, fact[N], inv[N], ans;

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   if (a < 0) a += mod;
   return a;
}

inline int mult (int a, int b) {
   return 1ll * a * b % mod;
}

inline int binpow (int a, int b) {
   int res = 1;
   while (b) {
      if (b & 1) res = mult (res, a);
      a = mult (a, a);
      b >>= 1;
   }
   return res;
}
   
inline int C (int n, int k) {
   if (n < k) return 0;
   return mult (fact[n], mult (inv[k], inv[n - k]));
}

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n >> m;
   inv[0] = fact[0] = 1;
   for (int i = 1; i <= max (n, m); i ++) fact[i] = mult (fact[i - 1], i), inv[i] = binpow (fact[i], mod - 2);
   for (int same = 0; same <= n; same ++) {
      if (same & 1) {
         ans = add (ans, mod - mult (mult (fact[same], mult (C (n, same), C (m, same))), mult (mult (fact[n - same], C (m - same, n - same)), mult (fact[n - same], C (m - same, n - same)))));
      }
      else {
         ans = add (ans, mult (mult (fact[same], mult (C (n, same), C (m, same))), mult (mult (fact[n - same], C (m - same, n - same)), mult (fact[n - same], C (m - same, n - same)))));
      }
      //cout << ans << ' ';
   }
   cout << ans;
}               
 
signed main () {                                       
   //#ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 7448
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>
#define ll long long int
#define l long int
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
	  start;
	  cout.precision(4);
	   int R;
	   cin >> R;
	   cout << 2*3.14159*R << endl;

	  return 0;
}


Measured memory_bytes: 3800
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0

for i in range(n):
      if a[i] >= b[i]:
            ans += b[i]
      else:
            ans += a[i]
            b[i] -= a[i]
            if a[i+1] >= b[i]:
                  ans += b[i]
                  a[i+1] -= b[i]
            else:
                  ans += a[i+1]
                  a[i+1] = 0
print(ans)

Measured memory_bytes: 24220
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	char ch; cin >> ch;
	if (ch == 'a' || ch == 'e' || ch == 'o' || ch == 'i' || ch == 'u') cout << "vowel" << endl;
	else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){

	int n;
	double get=0.0;
	double x;
	string u;

	cin>> n;

	for(int i=0;i<n;i++){
		cin>> x >> u;
		if(u=="BTC") x*=380000.0;
		get+=x;
	}

	cout<< get << "\n";
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

    ll n;cin >> n;
    REP(i, 1000000){
        ll now = i * 1.08;
        if(now == n){
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int from = 0;
        int to = n - 1;
        System.out.println(from);
        System.out.flush();
        
        String fromState = sc.next();
        if (fromState.equals("Vacant")) {
            return;
        }
        
        System.out.println(to);
        System.out.flush();
        
        String toState = sc.next();
        if (toState.equals("Vacant")) {
            return;
        }

        int mid;
        int count = 0;
        while (count < 20) {
            count++;
            mid = (from + to) / 2;
            System.out.println(mid);
            System.out.flush();
            
            String midState = sc.next();
            if (midState.equals("Vacant")) {
                return;
            }
            
            // 前半の区間に注目
            boolean isSameState = midState.equals(fromState);
            boolean isDiffEven = (mid - from) % 2 == 0;
            
            if (isSameState && !isDiffEven || !isSameState && isDiffEven) {
                to = mid;
                toState = midState;
            } else {
                from = mid;
                fromState = midState;
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 24740
import java.util.Arrays;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			String[] s = new String[n];
			for(int i = 0 ; i < n ; i++) {
				s[i] = sc.next();
			}
			TreeMap<String, Integer> map = new TreeMap<>();
			Arrays.stream(s).forEach(value -> {
				map.put(value, map.getOrDefault(value, 0) + 1);
			});
			int max = 0;
			PriorityQueue<String> maxList = new PriorityQueue<>();
			for(Map.Entry<String, Integer> entry : map.entrySet()) {
				if(entry.getValue() > max) {
					maxList.clear();
					maxList.add(entry.getKey());
					max = entry.getValue();
				} else if(entry.getValue() == max) {
					maxList.add(entry.getKey());
				}
			}
			maxList.stream().forEach(System.out::println);
		}

	}

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<ll, int>;
using Q = pair<int, P>;

#define INF 1001001001

int main() {
  int h, w;
  cin >> h >> w;
  int ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector< vector<int> > cost(h, vector<int>(w,INF));
  vector< vector<bool> > visit(h, vector<bool>(w));

  auto fill = [&](int x, int y, int k) {
    int dx[4] = { 0, 1,  0, -1};
    int dy[4] = { 1, 0, -1,  0};

    queue<P> q;
    q.push({x,y});
    cost[x][y] = k;
    while (!q.empty()) {
      int xx, yy;
      tie(xx,yy) = q.front(); q.pop();
      rep(i,4) {
        int nx = xx+dx[i];
        int ny = yy+dy[i];
        if (nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny]=='#' || cost[nx][ny]!=INF) continue;
        cost[nx][ny] = k;
        q.push({nx,ny});
      }
    }
  };

  priority_queue<Q, vector<Q>, greater<Q>> q;
  q.push({0,{ch,cw}});
  cost[ch][cw] = 0;
  visit[ch][cw] = true;
  fill(ch,cw,0);
  while (!q.empty()) {
    int c, x, y; P p;
    tie (c,p) = q.top(); q.pop();
    tie (x,y) = p;

    if (c != cost[x][y]) continue;

    for (int nx = x-2; nx <= x+2; nx++) {
      for (int ny = y-2; ny <= y+2; ny++) {
        if (nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny] == '#' || visit[nx][ny]) continue;
        if (cost[nx][ny]==INF) fill(nx,ny,cost[x][y]+1);
        visit[nx][ny] = true;
        q.push({cost[nx][ny],{nx,ny}});
      }
    }
  }
  int ans = cost[dh][dw];
  if (ans==INF) ans = -1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9820
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, a, cur[3];
long long ans = 1;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
      	bool flag = false;
        for (int j = 0; j < 3; j++) {
            if (cur[j] == a) {
                int cnt = 1;
                for (int k = j + 1; k < 3; k++) {
                    if (cur[k] == cur[j]) cnt++;
                }
                ans *= cnt;
                ans %= MOD;
                cur[j]++;
              	flag = true;
                break;
            }
        }
      	if (!flag) {
          cout << 0 << E;
          return 0;
        }
    }
    cout << ans << E;
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<double> a(n);
	double ans=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += 1 / a[i];
	}
	cout << 1 / ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i

n.times do
	snake = gets.chomp!
    
    if (snake =~ /^>'(=+)#\1~$/)
    	puts 'A'
    elsif (snake =~ /^>\^(Q=)+~~$/)
    	puts 'B'
    else
    	puts 'NA'
    end
    
end

Measured memory_bytes: 8852
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	int res = 0;
	if (B % A == 0) {
		res = A + B;
	}
	else {
		res = B - A;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,m,a[10000],b[10000],x[501],i;
	while(1)
	{
		scanf("%d %d", &n, &m);
		if(n==0)
		break;
		for(i=0; i<m; i++)
		{
			scanf("%d %d", &a[i], &b[i]);
			if(a[i]==1)
			x[b[i]]=1;
		}
		for(i=0; i<m; i++)
		{
			if(x[a[i]]==1&&x[b[i]]<1)
			x[b[i]]=2;
			if(x[b[i]]==1&&x[a[i]]<1)
			x[a[i]]=2;
		}
		m=0;
		for(i=2; i<=n; i++)
		{
			if(x[i]>0)
			{
				m++;
				x[i]=0;
			}
		}
		printf("%d\n", m);
	}
	
	return 0;
}


Measured memory_bytes: 2024
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define reg register
#define in cin>>
#define out cout<<
using namespace std;
int main(){
	reg int n;
	in n;
	while(n--){
		reg int t,x,y;
		in t>>x>>y;
		if(t<x+y){
			out "No\n";
			return 0;
		}
		if(t%2!=(x+y)%2){
			out "No\n";
			return 0;
		}
	}
	out "Yes\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=1e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,a[N];
ll l[N],r[N];

int main() {
	cin>>n;
	for(int i=0;i<=n;i++) a[i]=gi();
	if(!n) {
		if(a[0]==1) cout<<1;
		else cout<<-1;
		return 0;
	}
	if(a[0]!=0) return cout<<-1,0;
	l[0]=r[0]=1;
	for(int i=1;i<=n;i++) {
		l[i]=max(0ll,l[i-1]-a[i]);
		r[i]=min((ll)4e18,2ll*r[i-1]-a[i]);
		if(l[i]>r[i]) return cout<<-1,0;
	}
	if(!(l[n]<=0&&0<=r[n])) return cout<<-1,0;
	ll t=0,ans=0;
	for(int i=n-1;~i;i--) {
		t=min(t+a[i+1],r[i]);
		ans+=t;
	}
	for(int i=0;i<=n;i++) ans+=a[i];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5576
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define pb push_back
#define vi vector<int>
#define translow transform(s.begin(),s.end(),s.begin(),::tolower);
#define transup transform(s.begin(),s.end(),s.begin(),::toupper);
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;
int main() {
				fast
				
					
						ll n,x;
				cin>>n>>x;
				ll arr[n];
				for(ll i=0;i<n;i++)
				cin>>arr[i];
				sort(arr,arr+n);
				ll count=0;
				for(ll i=0;i<n;i++)
				{
					if(x>=arr[i])
					{
						x-=arr[i];
						count++;
					}
					else
					break;
				}
				count+=x/arr[0];
				cout<<count;
				
				
				
	return 0;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

class com:
    def __init__(self,max, mod = 1000000007):
        self.fac = [0] * max
        self.inv = [0] * max
        self.finv = [0] * max
        self.mod = mod

        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1

        for i in range(2,max):
            self.fac[i] = self.fac[i-1] * i % mod
            self.inv[i] = mod - self.inv[mod%i] * (mod//i) % mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % mod

    def com(self, n, k):
        if n < k: return 0
        if n < 0 or k < 0: return 0
        return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.mod) % self.mod
    

def main():
    x,y = mi()
    if (x+y) % 3 != 0:
        print(0)
        return

    step = (x+y)//3
    if x < step or y < step:
        print(0)
        return
    
    c = com(step+1)

    ans = c.com(step, x - step)

    print(ans)

main()

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 998244353;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);


    ll n, s;
    cin >> n >> s;
    vector<ll> a(n);
    for(auto &e: a) cin >> e;
    vector<vector<ll>> dp(n+1, vector<ll>(s+1));
    vector<vector<ll>> dq(n+1, vector<ll>(s+1));
    dp[0][0] = 1;
    for(ll i=1; i<=n; i++)
        for(ll j=0; j<=s; j++) {
            (dp[i][j] = dp[i-1][j] * 2) %= MOD;
            if(j-a[i-1]>=0)
                (dp[i][j] += dp[i-1][j-a[i-1]]) %= MOD;
        }

    dq[n][0] = 1;
    for(ll i=1; i<=n; i++)
        for(ll j=0; j<=s; j++) {
            dq[n-i][j] = dq[n+1-i][j];
            if(j-a[i-1]>=0)
                (dq[n-i][j] += dq[n+1-i][j-a[i-1]]) %= MOD;
        }


    ll res = dp[n][s];
    cout << res << endl;
    for(ll t=0; t<=s; t++) {
        for(ll i=1; i<=n; i++) {
            (res += dp[i-1][s-t] * dq[n+1-i][t]) %= MOD;
        }

    }
}


Measured memory_bytes: 144172
#include<bits/stdc++.h>
using namespace std;
int a,b[200010],c;
long long sum;
int main(){
	scanf("%d",&a);
	for(int i=1;i<=a;i++){
		scanf("%d",&b[i]);
		b[i]-=i;
	}
	sort(b+1,b+a+1);
	if(a%2==0){
		for(int i=1;i<=a;i++){
			sum+=abs(b[i]-b[a/2]);
		}
		printf("%lld",sum);
	}
	else{
		for(int i=1;i<=a;i++) {
			sum+=abs(b[i]-b[(a+1)/2]);
		}
		printf("%lld",sum);
	}
}
	


Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
    int A,B,C;
    scanf("%d\n%d",&A,&B);
    if (A==1) {
        if (B==2) {
            C=3;
        }
        else {
            C=2;
        }
    }
    if (A==2) {
        if (B==1) {
            C=3;
        }
        else {
            C=1;
        }
    }
    if (A==3) {
        if (B==1) {
            C=2;
        }
        else {
            C=1;
        }
    }
    printf("%d\n",C);
    return 0;
}

Measured memory_bytes: 128
# B - Problem Set
def is_create(dic_d, t):
	for ti in t:
		if not ti in dic_d.keys():
			return False
		elif dic[ti] == 0:
			return False
		else:
			dic[ti] -= 1	
	
	return True


n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

dic = dict()

for di in d:
	dic.setdefault(di, 0)
	dic[di] += 1
	'''if di in dic.keys():
		dic[di] += 1
	else:
		dic[di] = 1'''

if is_create(dic, t):
	print('YES')
else:
	print('NO')

Measured memory_bytes: 41316
#include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<(int)n;i++)
typedef long long ll;
inline ll read(){
	ll k=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		k=k*10+c-'0';
		c=getchar();
	}
	return k*f;
}
int main(){
	int x=read(),y=read(),a=read(),b=read(),c=read();
	vector<ll>p(a),q(b),r(c);
	forn(i,a)p[i]=read();
	forn(i,b)q[i]=read();
	forn(i,c)r[i]=read();
	
	sort(p.begin(),p.end(),greater<ll>());
	sort(q.begin(),q.end(),greater<ll>());
	sort(r.begin(),r.end(),greater<ll>());
	
	priority_queue<ll>qq;
	forn(i,x)qq.push(p[i]);
	forn(i,y)qq.push(q[i]);
	forn(i,c)qq.push(r[i]);
	
	ll ans=0;
	forn(i,x+y){
		ans+=qq.top();
		qq.pop();
	} 
	printf("%lld\n",ans);
}

Measured memory_bytes: 8432
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

MOD = 1000000000 + 7

def powmod(x,y):
    res = 1
    for i in range(y):
        res = res*x%MOD

    return res

N = ini()

ans = powmod(10,N)-powmod(9,N)-powmod(9,N)+powmod(8,N)
ans %= MOD
ans = (ans+MOD)%MOD
print(ans)

Measured memory_bytes: 9108
#include <iostream>
using namespace std;
 
int main(){
  long long x, y;
  cin >> x >> y;
  long long a[] = {x-1, 1, x, 0};
  long long b[] = {y, 1, y+1, 0};
  cout << (b[y % 4] ^ (x == 0 ? 0 : a[(x-1) % 4]));
}

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

typedef long long ll;

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

    if (((c -a) * (c-b)) <= 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void) 
{
   int W, H, x, y, r;
     scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
     if (W >= (x + r) && 0 <= (x - r))
     { 
     if (H >= (y + r) && 0 <= (y - r))
     {
       printf("Yes\n");
     } 
     else
     {
       printf("No\n");
     }
     }
     else
     {
     printf("No\n");
     }
     return 0;
} 

Measured memory_bytes: 584
#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()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  cin >> a;
  vector<ll> x(n);
  x[0] = 0;
  rep(i, n) x[0] += (i % 2 == 0 ? a[i] : -a[i]);
  x[0] /= 2;
  rep3(i, 1, n) x[i] = a[i - 1] - x[i - 1];
  rep(i, n) x[i] *= 2;
  cout << x << endl;
}


Measured memory_bytes: 2944
#include <iostream>
#define MOD 1000000007

using namespace std;
long long table[30];
int main() {
    long long N;
    char S[100000];
    cin >> N;
    cin >> S;
    for (int i=0; i<N; i++) {
        table[S[i] - 'a']++;
    }
    long long x = 1;
    for (int i=0; i<30; i++) {
        x = (x * (table[i]+1)) % MOD;
    }
    cout << x-1 << endl;
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<cmath>
#include<queue>
using namespace std;

template<typename Type> class RMQ {
private:
	unsigned size_; std::vector<Type> dat;
	inline Type query_(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return make_pair(1 << 30, 1 << 30);
		if (a <= l && r <= b) return dat[k];
		Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return std::min(lc, rc);
	}
public:
	RMQ() : size_(0), dat(std::vector<Type>()) {};
	RMQ(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, make_pair(1 << 30, 1 << 30));
	}
	template<class T>
	RMQ(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, make_pair(1 << 30, 1 << 30));
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
		}
	}
	inline Type query(int l, int r) {
		return query_(l, r, 1, 0, size_);
	}
};

int n, m, l[400000], r[400000], cnt; vector<pair<int, int>>E; vector<int>F;
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; r[i] = m + 1 - r[i]; E.push_back(make_pair(l[i], r[i])); }
	sort(E.begin(), E.end()); RMQ<pair<int, int>>X(n + 1);
	for (int i = 0; i < n; i++)X.update(i, make_pair(r[i], i)); X.update(n, make_pair(1 << 30, n));
	for (int i = m; i >= 1; i--) {
		int pos1 = lower_bound(E.begin(), E.end(), make_pair(i, 0)) - E.begin();
		pair<int, int>R = X.query(pos1, n + 1);
		if (R.first < 1e9) { X.update(R.second, make_pair(1 << 30, R.second)); cnt++; }
	}
	for (int i = 0; i < n; i++) { if (X.query(i, i + 1).first < 1e9)F.push_back(r[i]); }
	int T = 1; sort(F.begin(), F.end());
	for (int i = 0; i < F.size(); i++) {
		if (F[i] >= T) { cnt++; T++; }
	}
	cout << max(n - m, n - cnt) << endl;
	return 0;
}

Measured memory_bytes: 9328
def main():
    N = int(input())
    S = ["" for i in range(N)]
    T = ["" for i in range(N)]

    for i in range(N):
        s_t = input().split()
        S[i] = s_t[0]
        T[i] = int(s_t[1])

    X = input()

    total = 0
    sleep = False

    for i in range(N):
        if sleep:
            total += T[i]
        if not sleep and S[i] == X:
            sleep = True

    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.math.BigDecimal;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            // Input
            BigDecimal A = new BigDecimal(sc.next());
            BigDecimal B = new BigDecimal(sc.next());
            System.out.println(A.multiply(B).longValue());
        }
    }
}


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

int main() {
  string s;
  cin >> s;
  bool yymm = true;
  bool mmyy = true;

  if(!(s[2] == '0' || s[2] == '1')) {
    yymm = false;
  }

  if(s[2] == '0') {
    if(s[3] == '0'){
      yymm = false;
    }
  }

  if(s[2] == '1') {
    if(!(s[3] == '0' || s[3] == '1' || s[3] == '2')) {
      yymm = false;
    }
  }

if(!(s[0] == '0' || s[0] == '1')) {
    mmyy = false;
  }

  if(s[0] == '0') {
    if(s[1] == '0'){
      mmyy = false;
    }
  }

  if(s[0] == '1') {
    if(!(s[1] == '0' || s[1] == '1' || s[1] == '2')) {
      mmyy = false;
    }
  }

  if(mmyy == true && yymm == false) {
    cout << "MMYY" << endl;
  } else if(mmyy == false && yymm == true) {
    cout << "YYMM" << endl;
  } else if(mmyy && yymm) {
    cout << "AMBIGUOUS" << endl;
  } else {
    cout << "NA" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    W,n = LI()
    a = LI()
    for i in range(n):
        a[i] -= 1
    a.sort(reverse = True)
    b = [2,5,5,4,5,6,3,7,6]
    dp = [-float("inf")]*(W+1)
    dp[0] = 0
    for i in range(n):
        v = a[i]+1
        w = b[a[i]]
        for j in range(W):
            nj = j+w
            if nj > W:
                continue
            nd = dp[j]*10+v
            if dp[nj] < nd:
                dp[nj] = nd
    print(dp[W])
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
  int K;
  cin >> K;
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[K-1] << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, x; cin >> n >> x;
  vector<int> a(n);
  REP(i, n) {
    cin >> a[i];
  }

  int count = 0;
  REP(i, n-1) {
    if(a[i] + a[i+1] > x && a[i+1] > a[i] + a[i+1] - x) {
      count += a[i] + a[i+1] - x;
      a[i+1] = x - a[i];
    } else if(a[i] + a[i+1] > x) {
      count += a[i] + a[i+1] - x;
      a[i] = x;
      a[i+1] = 0;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 1024
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

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

		char[][] c = new char[h][w];
		int numCandidateSite = 0;
		for(int y = 0;y < h;y++) {
		    char[] line = sc.next().toCharArray();
		    for(int x = 0;x < w;x++) {
		        c[y][x] = line[x];
		        if(line[x] == '.') numCandidateSite++;
		    }
		}

		int result = bfs(0, 0, h, w, c);
		int answer = result == -1 ? result : numCandidateSite - result;
		System.out.println(answer);
    }

    private static int bfs(int startX, int startY, int h, int w, char[][] c) {
        Deque<Point> q = new ArrayDeque<>();
        q.offer(new Point(startX, startY));
        boolean[][] footprints = new boolean[h][w];
        footprints[startY][startX] = true;

        int[] dx = {0, 0, 1, -1};
        int[] dy = {1, -1, 0, 0};
        int[][] costMap = new int[h][w];
        for(int y = 0;y < h;y++) {
            for(int x = 0;x < w;x++) costMap[y][x] = Integer.MAX_VALUE;
        }
        costMap[0][0] = 0;

        while(!q.isEmpty()) {
            Point p = q.poll();

            for(int i = 0;i < 4;i++) {
                int nextX = p.x + dx[i];
                int nextY = p.y + dy[i];
                if(canGo(nextX, nextY, h, w, c, footprints)) {
                    q.offer(new Point(nextX, nextY));
                    footprints[nextY][nextX] = true;
                    int pScore = costMap[p.y][p.x];
                    if(pScore + 1 < costMap[nextY][nextX]) costMap[nextY][nextX] = pScore + 1;
                }
            }
        }

        int shortestTime = costMap[h - 1][w - 1];
        if(shortestTime == Integer.MAX_VALUE) return -1;
        else return shortestTime + 1;
    }

    private static boolean canGo(int x, int y, int h, int w, char[][] c, boolean[][] footprints) {
        if(x < 0 || x >= w || y < 0 || y >= h) return false;
        if(footprints[y][x]) return false;
        if(c[y][x] == '#') return false;

        return true;
    }

}

Measured memory_bytes: 22228
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int N = 2e5 + 7;
vector <pair <int, int>> prz[N];
long long dp[N];
int n, m;

const int M = (1 << 18);
long long D[2 * M];
long long W[2 * M];

long long inf = 1e18;

void insert(int a, int b, long long w, int v = 1, int p = 0, int k = M - 1) {
    if (a <= p && k <= b) {
        W[v] += w;
        return;
    }
    W[2 * v] += W[v];
    W[2 * v + 1] += W[v];
    W[v] = 0;
    int s = (p + k) / 2;
    if (a <= s) insert(a, b, w, 2 * v, p, s);
    if (s + 1 <= b) insert(a, b, w, 2 * v + 1, s + 1, k);
    D[v] = max(W[2 * v] + D[2 * v], W[2 * v + 1] + D[2 * v + 1]);
}

int main() {
    scanf("%d %d", &n, &m);
    long long wynik = 0;
    for (int i = 1; i <= m; ++i) {
        int l, r, c;
        scanf("%d %d %d", &l, &r, &c);
        prz[r].push_back({l, -c});
        wynik += c;
    }
    
    for (int i = 0; i < 2 * M; ++i) {
        D[i] = -inf;
    }
    
    insert(0, 0, inf);
    
    long long sum = 0;
    for (int i = 1; i <= n; ++i) {
        for (auto u : prz[i]) {
            if (u.first >= 2) insert(0, u.first - 2, u.second);
            sum += u.second;
        }
        
        dp[i] = max(sum, D[1]);
        insert(i, i, inf + dp[i]);
    }
    
    printf("%lld\n", wynik + dp[n]);
    return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll MOD=1e9+7;
ll sum(ll x, ll y)
{
	x += y;
	if (x >= MOD)
		return x - MOD;
	return x;
}
ll mult(ll x, ll y)
{
	return (x * y) % MOD;
}
ll N=50;
struct Matrix
{
	vvl a;
 
	Matrix(ll N)
	{		
		a.resize(N,vl(N,0));
/*
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				a[i][j] = 0;*/
	}
 
	Matrix operator * (const Matrix &X) const
	{
		Matrix res(N);
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
			{
				res.a[i][j] = 0;
				for (int h = 0; h < N; h++)
				{
					res.a[i][j] = sum(res.a[i][j], mult(a[i][h], X.a[h][j]));
				}
			}
		return res;
	}
};
 
Matrix bin_pow(Matrix x, ll pow)
{
	if (pow == 1) return x;
	if (pow == 2) return x * x;
	if (pow & 1) return x * bin_pow(x, pow - 1);
	return bin_pow(bin_pow(x, pow / 2), 2);
}
 
Matrix generate()
{
	Matrix A(N);
	A.a={{10,-1,-4},{1,0,1},{0,0,1}};
	return A;
}
int main()
{
  	IOS
	ll k;
	cin>>N>>k;
	Matrix A(N);
	for(ll i=0;i<N;i++)
	{
		for (ll j=0;j<N;j++)
		{
			cin>>A.a[i][j];
		}
	}
	A=bin_pow(A,k);
	ll sum=0;
	for(ll i=0;i<N;i++)
	{
		for(ll j=0;j<N;j++)
		{
			sum+=(A.a[i][j]);
			sum%=MOD;
		}
		//cout<<endl;
	}
	cout<<sum<<endl;



}
    
 
    
    


Measured memory_bytes: 2816
#include <iostream>

int main() {
int S;
int h, m, s;

std::cin >> S;
s = S % 60;
m = ((S % 3600) - s) / 60;
h = (S - s -m) / 3600;
std::cout << h << ':' << m << ':' << s << std::endl;

}

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

int main()
{
    int K;
    cin >> K;

    int N = 11;
    vector<vector<int>> dp(N, vector<int>(10, 0));
    for (int i = 0; i < 10; i++)
    {
        dp[0][i] = 1;
    }

    int digit = 0;
    for (int i = 0; i < N; i++)
    {
        int sum = 0;
        for (int j = 0; j < 10; j++)
        {
            if (j > 0)
            {
                sum += dp[i][j];
            }
            dp[i + 1][j] += dp[i][j];
            if (j - 1 >= 0)
            {
                dp[i + 1][j - 1] += dp[i][j];
            }
            if (j + 1 < 10)
            {
                dp[i + 1][j + 1] += dp[i][j];
            }
        }
        if (sum >= K)
        {
            digit = i + 1;
            break;
        }
        else
        {
            K -= sum;
        }
    }
    dp[digit - 1][0] = 0;

    int sum = 0;
    int prev;
    for (int i = 1; i < 10; i++)
    {
        if (sum + dp[digit - 1][i] >= K)
        {
            prev = i;
            K -= sum;
            break;
        }
        else
        {
            sum += dp[digit - 1][i];
        }
    }
    cout << prev;
    for (int i = digit - 2; i >= 0; i--)
    {
        int tmp = 0;
        for (int j = max(0, prev - 1); j <= min(9, prev + 1); j++)
        {
            if (tmp + dp[i][j] >= K)
            {
                prev = j;
                K -= tmp;
                break;
            }
            else
            {
                tmp += dp[i][j];
            }
        }
        cout << prev;
    }
    cout << endl;
}


Measured memory_bytes: 256
//binary tree
//2019-01-09
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>

#define N 100000

struct Node {int p, l, r; };
struct Node T[N];
int D[N];
int H[N];
int n;

void Depth(int, int);
int Height(int);
int Sbling(int);
void Print_tree(int);

int main (){
  int i, j;
  int root;
  int v, r, l;

  root = 0;
  scanf("%d", &n);
  if(n < 1 || n > 25){
    printf("節点の情報が適当ではありません。/n");
    exit(1);
  }
  
  for(i = 0 ; i < n ; i++)
    T[i].p = -1;
  
  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;

    if(l != -1)
      T[l].p = v;
    if(r !=-1)
      T[r].p = v;
  }

  for(i = 0 ; i < n ; i++){
    if(T[i].p == -1)
      root = i;
  }

  Depth(root, 0);
  Height(root);
  for(i = 0 ; i < n ; i++){
    Print_tree(i);
  }

  return 0;
}
    
void Depth(int root, int i){
  if(root == -1)
    return;

  D[root] = i;
  Depth(T[root].l, i+1);
  Depth(T[root].r, i+1);

}

int Height(int root){
  int h_a, h_b;
  h_a = 0;
  h_b = 0;

  if(T[root].l != -1)
    h_a = Height(T[root].l) + 1;
  if(T[root].r != -1)
    h_b = Height(T[root].r) + 1;
  
  
  return H[root] = (h_a > h_b ? h_a : h_b);
}


int Sibling(int i){
  if(T[i].p == -1)
    return -1;
  if(T[T[i].p].l != i && T[T[i].p].l != -1)
    return T[T[i].p].l;
  if(T[T[i].p].r != i && T[T[i].p].r != -1)
    return T[T[i].p].r;

  return -1;
}

void Print_tree(int i){
  printf("node %d: ", i);
  printf("parent = %d, ", T[i].p);
  printf("sibling = %d, ", Sibling(i));

  int d = 0;
  if(T[i].l != -1)
    d++;
  if(T[i].r != -1)
    d++;

  printf("degree = %d, ", d);
  printf("depth = %d, ", D[i]);
  printf("height = %d, ", H[i]);

  if(T[i].p == -1)
    printf("root\n");
  else if(T[i].l == -1 && T[i].r == -1)
    printf("leaf\n");
  else
    printf("internal node\n");

}



Measured memory_bytes: 2108
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(n) scanf("%s",&n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof a)
#define mem(a,b,n) memset(a,b,n*sizeof(int))
#define uint unsigned int

const  int N = 1e5 + 1000;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int n;
int m;
struct ac
{
	int a, b;
	bool operator<(ac const&c) const
	{
		return a > c.a || (a == c.a && b > c.b);
	}
}p[N];

struct wc
{
	int a, b;
	bool operator<(wc const&c) const
	{
		return  b > c.b;
	}
};

priority_queue<wc> q;

int main()
{
	sc(n);
	sc(m);
	fo(i, 1, n)
		scanf("%d%d", &p[i].a, &p[i].b);
	sort(p + 1, p + n + 1);
	int ans = 0;
	fo(i, 1, n)
	{
		if (p[i].a <= m - q.size())
			q.push(wc{ p[i].a,p[i].b });
		else if (!q.empty() && p[i].b > q.top().b)
		{
			q.pop();
			q.push(wc{ p[i].a,p[i].b });
		}
	}
	while (!q.empty())
	{
		ans += q.top().b;
		q.pop();
	}
	cout << ans << endl;

}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios::sync_with_stdio(false);
#define pi 3.14159265358979323846264338327950288419716939937510
#define pb push_back
typedef long long ll;
ll a[100000000]={0};
using namespace std;
int main()
{

      fast
        ll n;
        cin>>n;


        for(int i=1;i<=n;i++)
        {
            for(int j=1;i*j<=n;j++)
                {
                    a[i*j]++;
                }
        }

      ll ans=0;
      for(int i=1;i<=n;i++)
        ans+=a[i]*i;

     cout<<ans<<endl;
return 0;

}


Measured memory_bytes: 81732
import java.util.*;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        int answer = 0;
        int i = 1;
        while(i <= n){
            for(int j = 1; j <= i; j++){
                if(i % j == 0){
                    count++;
                }
            }
            if(count == 8){
                answer++;
            }
            count = 0;
            i = i+2;
        }
        System.out.print(answer);
    }
}

Measured memory_bytes: 23892