akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,y;
  cin >> n >> y;
  int a = -1, b = -1, c = -1;
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= n; ++j){
      int k = n - i - j;
      if(k < 0){
        continue;
      }
      if(10000*i + 5000*j + 1000*k == y){
        a = i;
        b = j;
        c = k;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 3596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            boolean ok = false;
            if (S.matches("^A?KIHA?BA?RA?$")) {
                ok = true;
            }
            out.println(ok ? "YES" : "NO");

        }

    }
}



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

#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ford1(i, n) for(int i = (int)(n); i>=1; --i)
#define fored(i, a, b) for(int i = (int)(b); i >= (int)(a); --i)
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define clr(v) memset(v, 0, sizeof(v))
#define clr1(v) memset(v, 0xFF, sizeof(v))
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long i64;
typedef unsigned long long u64;
typedef long double ld;
typedef vector<ld> vld;

typedef vector<i64> vi64;

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

i64 f(i64 a, i64 b) {
  i64 r = 0;
  if (a == b)
    r = a;
  else {
    if (b > a) swap(a, b);
    i64 c = a / b;
    if (c * b == a) c -= 1;
    r = c * 2 * b + f(b, a - c * b);
  }
  // cerr << a << ' ' << b << '=' << r << '\n';
  return r;
}

void solve() {
  i64 x, n;
  cin >> n >> x;
  cout << n + f(x, n - x) << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed; cout.precision(15);
  cerr << fixed; cerr.precision(15);
#ifdef HOME
  freopen("input.txt", "r", stdin);
#endif
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main{
	static int N,Q;
	static Node[] ns;
	static boolean type[];
	static int no[];
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String input[] = br.readLine().split(" +");
			N = new Integer(input[0]);
			Q = new Integer(input[1]);
			if(N==0 & Q==0) break;

			ns = new Node[N+1];
			type = new boolean[Q];
			no = new int[Q];

			ns[1] = new Node(0);
			ns[1].marked = true;
			for(int i = 2; i <= N; i++){
				ns[i] = new Node(new Integer(br.readLine()));
			}
			for(int i = 0 ; i < Q; i++){
				input = br.readLine().split(" +");
				if(input[0].equals("Q")){
					type[i] = true;
				}else{
					type[i] = false;
				}
				no[i] = new Integer(input[1]);
			}
			
			long sum = 0;
			for(int i = 0 ; i < Q; i++){
				if(type[i]){
					sum += findmark(no[i]);
				}else{
					ns[no[i]].marked = true;
				}
			}
			System.out.println(sum);
		}
	}
	static int findmark(int no){
		while(true){
			if(ns[no].marked) return no;
			else no = ns[no].par;
		}
	}
}

class Node{
	int par;
	boolean marked = false;
	Node(int par){
		this.par = par;
	}
}

Measured memory_bytes: 166096
#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<int, int>;

int main(){
    string s, t, t2;
    cin >> s >> t;

    t2 = t.substr(0, t.size()-1);
    if(t2 == s) cout << "Yes" << endl;
    else cout << "No" <<endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int
lli dp[5005][5005];
void solve(long long N, std::vector<long long> A)
{
  vector<lli> v = A;
  iota(vall(v), 0);
  sort(v.begin(), v.end(), [&](lli l, lli r) { return A[l] > A[r]; });
  for (int i = 0; i < N; i++)
  {
    rep(j, i + 1)
    {
      lli left = i - j;
      lli right = j;
      // iを右に配置
      chmax(dp[left][right + 1], A[v[i]] * (N - 1 - right - v[i]) + dp[left][right]);
      chmax(dp[left + 1][right], A[v[i]] * (v[i] - left) + dp[left][right]);
    }
  }
  lli ans = 0;
  rep(i, N + 1) rep(j, N + 1)
  {
    if (i + j == N)
      chmax(ans, dp[i][j]);
  }
  cout << ans << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b)
{
  cout << (b ? "YES" : "NO") << endl;
}
void YesNo(bool b)
{
  cout << (b ? "Yes" : "No") << endl;
}

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 27376
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            String str = scan.next();
            if (str.equals("-")){
            	break;
            }
            int n = scan.nextInt();
            for (int i = 0; i < n; ++i) {
                int h = scan.nextInt();
                str = str.substring(h, str.length()) + str.substring(0, h);
            }
            System.out.println(str);
        }
    }
}

Measured memory_bytes: 18276
#include<bits/stdc++.h>
using namespace std;
#define int long long


signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    
    string s;
    cin>>s;
    int n = s.length();
    if (s[n-1]=='s') s.append("es");
    else s.push_back('s');
    
    cout<<s<<endl;
    

    return 0;
}





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

using namespace std;
typedef long long ll;

const int MX = 51;
bool dp[MX][MX];

void pre() {
	for (int i = 0; i < MX; i++) {
		dp[i][i] = true;
	}
	
	for (int i = 0; i < MX; i++) {
		for (int bit = 1; bit <= i; bit++) {
			dp[i][i%bit] = 1;
		}
	}
	
	for (int z = 0; z < MX; z++) {
		for (int i = 0; i < MX; i++) {
			for (int l = 0; l < MX; l++) {
				for (int j = 0; j < MX; j++) {
					dp[i][j] = dp[i][j] or (dp[i][l] and dp[l][j]);
				}
			}
		}
	}
	
}

int a[MX];
int b[MX];
vector<ll> ways[MX];

void genOne(int id, int numb, ll thisOne) {
	if (numb == b[id]) {
		ways[id].push_back(thisOne);
		//cout << thisOne << endl;
	}
	else {
 		for (int x = 1; x <= numb; x++) {
			if (dp[numb][b[id]]) {
				genOne(id, numb % x, thisOne + (1LL << x));
			}
		}
	}
}

void gen(int x) {
	genOne(x,a[x],0);
}

int main() {
	pre();
	
	
	int n;
	ignore = scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) {
		ignore = scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n; i++) {
		ignore = scanf("%d", &b[i]);
	}
	
	for (int i = 1; i <= n; i++) {
		if (dp[a[i]][b[i]] == false) {
			cout << -1 << endl;
			return 0;
		}
		else {
			gen(i);
		}
	}
	/*
	for (int i = 1; i <= n; i++) {
		cout << "I = " << i << endl;
		for (auto x : ways[i] ) {
			cout << x << endl;
		}
		cout << "-------" << endl;
	}
	*/
	

	ll ans = 0;
	for (int bit = 50; bit >= 0; bit--) {
		bool ok = true;
		for (int i = 1; i <= n; i++) {
			bool thisOne = false;
			
			for (auto x : ways[i]) {
				if ( x < (1LL << bit) )
					thisOne = true;
			}
			
			if (!thisOne) ok = false;
		}
		
		//cout << bit << " - " << ok << endl;
		
		if (!ok) {
			ans += 1LL << bit;
			for (int i = 1; i <= n; i++) {
				vector<ll> tmp;
				for (auto x : ways[i] ) {
					if ( ( x & (1LL << bit) ) != 0)
						tmp.push_back (x - (1LL << bit));
					else
						tmp.push_back(x);
				}
				swap ( ways[i] , tmp);
			}
		}
		else {
			
			for (int i = 1; i <= n; i++) {
				vector<ll> tmp;
				for (auto x : ways[i]) {
					if (x < (1LL<<bit))
						tmp.push_back(x);
				}
				swap(ways[i],tmp);
			}
			
		}
		
	}
	
	cout << ans << endl;
	
	
}


Measured memory_bytes: 512
// 2015/12/14 Tazoe

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

	for(int i=0; i<n; i++){
		string s;
		cin >> s;

		int m[8];
		for(int j=0; j<8; j++){
			m[j] = (int)(s[j]-'0');
		}

		sort(m, m+8);

		int m_max = 0;
		int m_min = 0;

		for(int j=0; j<8; j++){
			m_max *= 10;
			m_max += m[7-j];
			m_min *= 10;
			m_min += m[j];
		}

		cout << m_max-m_min << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;


const int MAX_N = 1e5+10;
ll dp[MAX_N];

int main(){
    int n, k;
    cin >> n >> k;
    vl h(n);
    rep(i, n) cin >> h[i];
    rep(i, MAX_N) dp[i] = 1e18;
    dp[0] = 0;
    rep(i, n-1) {
        for(int j = 1; j <= k && i + j < n; ++j) {
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
from sys import stdin
import numpy as np
H, W, K = map(int, input().split())

maze = [list(input()) for i in range(H)]
ans = 0

for bith in range(1 << (H)):
    for bitw in range(1<<(W)):
                black = 0
                for i in range(H):
                    for j in range(W):
                        if ((bith >>i) & 1 ) & ((bitw >> j) & 1 ) & (maze[i][j] == "#") :
                           black += 1 
                if black == K:
                    ans += 1
                        # if bit & (1 << i)で、bitにiが含まれているか（フラグが立っているか）を判定してくれるらしい
print(ans)

Measured memory_bytes: 26980
N = int(input())
P = list(map(int,input().split()))

order = [None] * N
for i,p in enumerate(P):
    order[p-1] = i

bit = [0] * (N+2)
def bit_add(x,w):
    while x <= N+1:
        bit[x] += w
        x += (x & -x)
def bit_sum(x):
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

def bisect_right(k):
    def is_ok(i):
        if i < 1: return True
        if i > N+1: return False
        return bit_sum(i) <= k
    ok = 0
    ng = N+2
    while ng-ok > 1:
        m = (ok+ng) // 2
        if is_ok(m):
            ok = m
        else:
            ng = m
    return ok

ans = 0
for q,i in enumerate(reversed(order)):
    bit_add(i+2, 1)
    #print([bit_sum(i) for i in range(1,N+2)])
    k = bit_sum(i+2)
    a = bisect_right(k-3)
    b = bisect_right(k-2)
    c = bisect_right(k-1)
    d = bisect_right(k)
    e = bisect_right(k+1)
    ans += ((b-a)*(d-c) + (c-b)*(e-d)) * (N-q)
print(ans)

Measured memory_bytes: 61804
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

int main() {
	ll N, M, A[100000], S[100001] = { 0 }, ans = 0;

	cin >> N >> M;
	REP(i, N) {
		cin >> A[i];
	}

	FOR(i, 1, N + 1) {
		S[i] += (S[i - 1] + A[i - 1]) % M;
	}

	map<ll, ll> vec;
	REP(i, N + 1) {
		auto itr = vec.find(S[i]);
		if (itr != vec.end()) {
			vec[S[i]]++;
		}
		else {
			vec[S[i]] = 1;
		}
	}
	

	for (auto itr = vec.begin();itr!= vec.end();++itr) {
		ans += itr->second*(itr->second - 1) / 2;
	}
		
	

	cout << ans << endl;

	return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> v[51];
    for(int i=0;i<M;i++){
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1;i<=N;i++){
        cout << v[i].size() << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*Filename: aoj0018.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <algorithm>

using namespace std;

const int SIZE = 5;

int main(){
	int firstNum = 0;

    while(cin >> firstNum){
        int num[SIZE];

        num[0] = firstNum;
        for(int i = 1; i < SIZE; ++i){
        	cin >> num[i];
        }

        sort(num, num + SIZE, greater<int>());
        
        cout << num[0];
        for(int i = 1; i < SIZE; ++i){
        	cout << " " << num[i];
        }
        cout << endl;
    }

	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

const int MAX = 202020;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<ll>dev;

void devisor(ll n) {
	for (ll i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			if (i == n / i) {
				dev.push_back(i);
			}
			else {
				dev.push_back(i);
				dev.push_back(n / i);
			}
		}
	}
}
bool prime(ll n) {
	if (n == 1) {
		return false;
	}
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			return false;
		}
	}
	return true;
}

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


	combinit();
	devisor(m);

	ll ans = 1;
	fore(i, dev) {
		if (i != 1 && prime(i)) {
			ll temp = 0;
			ll mul = i;
			while (1) {
				if (m % mul == 0) {
					temp++;
					mul *= i;
				}
				else break;
			}
			ans *= comb(n - 1 + temp, temp);
			ans %= MOD;
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long N, std::vector<long long> a){
    ll ans = 0;
    REP(i, N){
        if(i % 2 == 0 && a[i] % 2) ans ++;
    }
    cout<<ans<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 3236
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;

template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a,T  b) { return a<b?(a=b,true):false; }
#define forn(i,x,y) for(int i=(x);i<(int)(y);i++)
#define rep(i,y) for(int i=0;i<(int)(y);i++)
#define repb(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)

int main() {
    int x;
    cin >> x;
    cout << !x << endl;
}

Measured memory_bytes: 3192
n = gets.to_i
min = 10000000
(n+1).times do |i|
	t = i	
	cc = 0

	while t > 0
		cc += t % 6
		t /= 6
	end

	t = n - i
	while t > 0
		cc += t % 9
		t /= 9
	end
	min = cc if cc < min
end

puts min

Measured memory_bytes: 3836
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()

	s := float64(1)
	ans := 1
	for _, ai := range a {
		s *= float64(ai)
		ans *= ai
	}
	if s > 1E18 || ans > 1e18 {
		ans = -1
	}
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 9396
line = input().rstrip().split(' ')
n = int(line[0])
a = int(line[1])
b = int(line[2])

i = 0
ans = 0

t = int(n / (a + b))
ans = t * a

if n > (a + b) * t:
    t2 = n - (a + b) * t
    if t2 > a:
        ans += a
    else:
        ans += n - (a + b) * t

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, k, h[100100], dp[100100];

int main() {
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < 100100; i++) dp[i] = inf;

    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
n=gets.to_i
count = 0
(1..n).each do |val|
  tempCount = 0
  next if val.even?
  (1..val).each do |val2|
      next if val2.even?
      tempCount += 1 if val % val2 == 0
  end
  count += 1 if tempCount == 8
end
puts count

Measured memory_bytes: 3836
#include <stdio.h>

int main (void){
  int a, b, sum, unko, pow, max;
  scanf("%d %d", &a, &b);
  sum = a + b;
  unko = a - b;
  pow = a * b;
  max = sum;
  if(max < unko) max = unko;
  if(max < pow) max = pow;
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

template <class T> struct FordFulkerson {

    struct  Edge {
        int to,rev; T cap;
        Edge(int t, int r, T c) : to(t), rev(r), cap(c) {}
    };
    
    const T INF = numeric_limits<T>::max() / 2;
    vector< vector< Edge > > G;
    vector< bool > used;
    FordFulkerson (int n) : G(n+1), used(n+1) {}
   
    void add_edge(int from, int to, T cap) {
        G[from].push_back(Edge(to,(int)G[to].size(),cap));
        G[to].push_back(Edge(from,(int)G[from].size()-1,0));
    }
    
    T dfs(int v, int t, T f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            Edge &e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                T d = dfs(e.to, t, min(f,e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
   
    T get_max (int source, int sink) {
        T flow = 0;
        while (true) {
            for (int i = 0; i < used.size(); i++) used[i] = false;
            T f = dfs(source, sink, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
    
};


bool isPrime(long long n) {
    if (n <= 2) return false;
    for (long long i = 2; i * i <= n; i++) if (n % i == 0) return false;
    return true;
}

bool flip[10000010];

int main ()
{
    int N;
    cin >> N;
    vector < int > x(N);
    REP(i,N) cin >> x[i];

    REP(i,N) {
        flip[x[i]] = !flip[x[i]];
        flip[x[i] + 1] = !flip[x[i] + 1];
    }

    vector < int > xt;
    for (int i = 0; i < 10000010; i++) {
        if (flip[i]) xt.push_back(i);
    }

    FordFulkerson < int > inst(1000);
    vector < int > odd, even;
    REP(i,xt.size()) {
        if (xt[i] % 2) odd.push_back(i);
        else even.push_back(i);
    }

    for (int i = 0; i < odd.size(); i++) {
        for (int j = 0; j < even.size(); j++) {
            int diff = abs(xt[odd[i]] - xt[even[j]]);
            if (isPrime(diff)) {
                inst.add_edge(odd[i], even[j] + 500, 1);
            }
        }
    }

    REP(i,odd.size())  inst.add_edge(990, odd[i], 1);
    REP(i,even.size()) inst.add_edge(even[i] + 500, 991, 1);

    int maxt = inst.get_max (990, 991);

    int ot = odd.size() - maxt;
    int et = even.size() - maxt;

    int two = ot / 2 + et / 2;
    int three = ot % 2;
    
    cout << maxt + two * 2 + three * 3 << endl;

    return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int r, g, b, n;
	cin >> r >> g >> b >> n;

	int ans = 0;
	for (int i = 0; i <= 3000; ++i) {
		for (int j = 0; j <= 3000; ++j) {
			int k = n - i * r - j * g;
			if (k >= 0) {
				if (k % b == 0) {
					++ans;
				}
			}
		}
	}

	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int i,j,num;

scanf("%d",&num);

for(i=num;;i++){
for(j=2;j<num;j++){
if(i%j==0){
  break;
}
}
if(j==num){break;}
}

printf("%d",i);

return 0;
}


Measured memory_bytes: 1680
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#define INF 1<<29
#define MAX 3000
using namespace std;
int cost[MAX][MAX],V,d[MAX][MAX];
bool used[MAX][MAX];

void dijkstra(int);

int main(){
  int m,s,g1,g2,b1,b2,c;

  while(true)
    {
      cin >> V >> m >> s >> g1 >> g2;
      if(V == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)break;
      for(int i=1;i<=V;i++)
	{
	  for(int j=1;j<=V;j++)
	    {
	      cost[i][j]=INF;
	      d[i][j] = INF;
	    }
	}

	  for(int i=0;i<m;i++)
	{
	  cin >> b1 >> b2 >> c;
	  cost[b1][b2]=c;
	}

      int ans = INF;
      //cout << ans << endl;
      for(int i=1;i<=V;i++)
	{
	  dijkstra(i);
	  // cout << ans << endl;
	  /*cout << "i = " << i << endl;
	    for(int j=1;j<=V;j++)
	    {
	      for(int k=1;k<=V;k++)cout << d[j][k] << " " ;
	      cout << endl;
	    }
	  */
	}
      for(int i=1;i<=V;i++)
	{
	  ans = min(ans,d[s][i]+d[i][g1]+d[i][g2]);
	}

      cout << ans << endl;
    }
}

void dijkstra(int s)
{
  for(int i=1;i<=V;i++)
    {
	  d[s][i]=INF;
	  used[s][i]=false;
    }
  d[s][s] = 0;

  while(true)
    {
      int v=-1;
      for(int u=1;u<=V;u++)
	{
	  if(!used[s][u] && (v == -1 || d[s][u] < d[s][v]))v = u;
	}
      if(v == -1)break;
      used[s][v]=true;
      for(int u=1;u<=V;u++)
	{
	  d[s][u]=min(d[s][u],d[s][v]+cost[v][u]);
	}
    }
}

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

int main()
{
  int n;
  string x;
  cin >> n;
  for(int i=1; i<=n; i++)
  {
    cin >> x[i-1];
  }
    int c=0;
  for (int i=0; i<n; i++)
  {
    if (x[i]=='P') 
    {c++;
    break;}
  }
  for (int j=0; j<n; j++)
  {
    if (x[j]=='W') {c++;
    break;}
  }
  for (int k=0; k<n; k++)
  {
    if (x[k]=='G') {c++;
    break;}
  }
    for (int l=0; l<n; l++)
  {
    if (x[l]=='Y'){ c++;
    break;}
  }

  if(c==3) cout <<"Three"<<endl;
  else if(c==4) cout <<"Four"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int X = s.nextInt();
	Queue<Integer> prime = new ArrayDeque<Integer>();
	List<Integer> list = new ArrayList<Integer>();
	for(int i = 1; i <= 120000; i++){
		prime.add(i);
	}

	while(true){
		if(prime.peek() == 1){
			prime.poll();
			prime.add(1);
		}
		if(prime.peek() == 100003){
			list.add(100003);
			break;
		}
		int count = prime.peek();
		list.add(count);
		while(prime.peek() != 1){
			if(prime.peek()%count == 0){

			}else{
				prime.add(prime.peek());
			}
			prime.poll();
		}
	}
	
	for(int i = 0; i < list.size(); i++){
		if(X <= list.get(i)){
			System.out.println(list.get(i));
			break;
		}
	}

    
  }
}

Measured memory_bytes: 41700
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  VI a(n); for (int i = 0; i < n; i++) cin >> a[i];
  vector<lint> c(n + 1);
  for (int i = 0; i < n; i++) {
    c[i + 1] = c[i] + a[i];
  }

  lint res = 9e18;
  for (int dm = 2; dm < n - 1; dm++) {
    int dl = lower_bound(c.begin(), c.begin() + dm, c[dm] / 2) - c.begin();
    int dr = lower_bound(c.begin() + dm, c.end(), (c[n] + c[dm]) / 2) - c.begin();
    lint tmp;
    for (int ddl = -2; ddl <= 2; ddl++) {
      for (int ddr = -2; ddr <= 2; ddr++) {
        if (dl + ddl < 1 or dl + ddl >= dm or dr + ddr <= dm or dr + ddr >= n) continue;
        tmp = max({c[dl + ddl], c[dm] - c[dl + ddl], c[dr + ddr] - c[dm], c[n] - c[dr + ddr]}) - min({c[dl + ddl], c[dm] - c[dl + ddl], c[dr + ddr] - c[dm], c[n] - c[dr + ddr]});
        res = min(res, tmp);
      }
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> Guide(N);
  for (int i = 0; i < N; i++) {
    string s;
    int p;
    cin >> s >> p;
    Guide.at(i) = make_tuple(s, -p, i);
  }
  sort(Guide.begin(), Guide.end());
  for (int i = 0; i < N; i++) {
    cout << get<2>(Guide.at(i)) + 1 << endl;
  }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
const long double E = 0.00000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int x;
    cin >> x;
    cout << 360/__gcd(x, 360LL) << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    REP(i,b){
        if(i*a%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();


      if(a+b+c>=22) {
        System.out.println("bust");
      }else{
        System.out.println("win");
      }

  }
}


Measured memory_bytes: 19924
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val a = get[Int]
    val b = get[Int]
    val c = get[Int]
    val d = get[Int]
    val e = get[Int]
    val k = get[Int]

    out.println(
      if (e - a <= k) {
        "Yay!"
      } else {
        ":("
      }
    )

    out.flush()
  }
}

Measured memory_bytes: 25292
n = input()

hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]

s = int(n[-1])

if s in hon:
    ans = "hon"
elif s in pon:
    ans = "pon"
else:
    ans = "bon"

print(ans)


Measured memory_bytes: 9168
// 参考: https://atcoder.jp/contests/abc166/submissions/12755325
// fumiyakkさんありがとうございました。

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	// すぬけ君の数
	n := nextInt()
	// お菓子の種類
	k := nextInt()

	// 各すぬけ君の所持お菓子数を収納するスライスを作成
	sunuke := make([]int, n)

	// 注意！2行にわたってお菓子ごとのデータがかかれている！
	for i := 1; i <= k; i++ {
		// そのお菓子を持っている人
		d := nextInt()
		for j := 0; j < d; j++ {
			tmp := nextInt()
			sunuke[tmp-1] += 1
		}
	}

	count := 0
	// 一つもお菓子を持っていない人をカウント
	for _, v := range sunuke {
		if v == 0 {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 1756
#include<iostream>
using namespace std;
int main()
{
    int k,n;
    cin>>k>>n;
    int *a=new int[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    int max=a[0]+(k-a[n-1]);
    for(int i=0;i<n;i++)
    {
        if(a[i]-a[i-1]>max)
        max=a[i]-a[i-1];

    }
    cout<<k-max<<endl;

    return 0;
}

Measured memory_bytes: 1024
/*input
5 15
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long k,s,ans=0;
	cin>>k>>s;
	for(int x=0;x<=k;++x) for(int y=0;y<=k;++y){
		if(s-x-y>=0 && s-x-y<=k) ++ans;
	}
	cout<<ans;
}

Measured memory_bytes: 256
N = int(input())
min_T, min_A = 1,1

for _ in range(N):
    T, A = map(int,input().split())
    i =max(-(-min_A // A) , -(-min_T // T))
    min_T = T * i
    min_A = A * i
print(min_T+min_A)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D)
    cout<<"Left"<<endl;
  if(A+B==C+D)
    cout<<"Balanced"<<endl;
  if(A+B<C+D)
    cout<<"Right"<<endl;
}

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

struct dice{
	vector<int>d;
	void insert(){
		for(int i=0;i<6;++i){
			int n; cin>>n;
			d.emplace_back(n);
		}
	}
	void roll(char c){
		int&top=d.at(0),&dow=d.at(1),&rig=d.at(2)
		,&lef=d.at(3),&upp=d.at(4),&btm=d.at(5);
		if(c=='N')swap(top,upp),swap(top,btm),swap(top,dow);
		else if(c=='E')swap(top,rig),swap(top,btm),swap(top,lef);
		else if(c=='S')swap(top,dow),swap(top,btm),swap(top,upp);
		else if(c=='W')swap(top,lef),swap(top,btm),swap(top,rig);
	}
	void prtop(){
		cout<<d.at(0)<<"\n"s;
	}
};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	dice a; a.insert();
	string s; cin>>s;
	for(auto&&i:s)a.roll(i);
	a.prtop();
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    ll a,b; cin >> a >> b;
    ll c,d; cin >> c >> d;
    bool ok = false;
    rep(i,n){
        ok |= ((c*(n-1-i) - d*i) <= (b-a) && (b-a) <= (d*(n-1-i) - c*i));
    }
    cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
day = (
       'Sunday',
       'Monday',
       'Tuesday',
       'Wednesday',
       'Thursday',
       'Friday',
       'Saturday',
)
mm = {1:4,
      2:0,
      3:1,
      4:4,
      5:6,
      6:2,
      7:4,
      8:0,
      9:3,
      10:5,
      11:1,
      12:3,
      }
while 1:
    m, d = list(map(int, input().split()))
    if m == 0:
        break
    print(day[(mm[m] + d - 1)%7])

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

using namespace std;
int main(void) {
 long long int n,sum=0;cin>>n;
  for(int i=1;i<n+1;i++){
    if( (i%3 !=0) && (i%5 != 0) )sum+=i;
  }
  cout<<sum;
  }


Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

const int P = 1000 * 1000 * 1000 + 7;

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

    int n, m;
    cin >> n >> m;

    vector<vector<pair<int, int>>> lx(n);
    for (int i = 0; i < m; ++i) {
    	int l, r, x;
    	cin >> l >> r >> x;
    	--l, --r;
    	lx[r].pb(mp(l, x));
    }

    vector<vector<int>> num(n + 1, vector<int>(n + 1, 0));
    num[n][n] = 3;
    for (int i = 0; i < n; ++i) {
    	for (int j = 0; j < sz(lx[i]); ++j) {
    		int len = i - lx[i][j].fs;
    		if (lx[i][j].sc == 1) {
    			for (int i1 = 1; i1 <= len; ++i1) {
    				for (int i2 = i1; i2 <= n; ++i2) {
    					num[i1][i2] = 0;
    				}
    			}
    		} else if (lx[i][j].sc == 2) {
    			for (int i1 = len + 1; i1 <= n; ++i1) {
    				for (int i2 = i1; i2 <= n; ++i2) {
    					num[i1][i2] = 0;
    				}
    			}
    			for (int i1 = 1; i1 <= len; ++i1) {
    				for (int i2 = i1; i2 <= len; ++i2) {
    					num[i1][i2] = 0;
    				}
    			}
    		} else {
    			for (int i1 = 1; i1 <= n; ++i1) {
    				for (int i2 = max(len + 1, i1); i2 <= n; ++i2) {
    					num[i1][i2] = 0;
    				}
    			}
    		}
    	}

    	if (i + 1 < n) {
    		vector<vector<int>> num_new(n + 1, vector<int>(n + 1, 0));
            for (int i1 = 1; i1 <= n; ++i1) {
            	int j1 = min(i1 + 1, n);
            	for (int i2 = i1; i2 <= n; ++i2) {
            		int j2 = min(i2 + 1, n);
            		num_new[j1][j2] = (num_new[j1][j2] + num[i1][i2]) % P;
            		num_new[1][j1] = (num_new[1][j1] + num[i1][i2]) % P;
            		num_new[1][j2] = (num_new[1][j2] + num[i1][i2]) % P;
            	}
            }
            num = num_new;
    	}
    }

    int res = 0;
    for (int i1 = 1; i1 <= n; ++i1) {
    	for (int i2 = i1; i2 <= n; ++i2) {
    		res = (res + num[i1][i2]) % P;
    	}
    }

    cout << res << endl;
	return 0;
}


Measured memory_bytes: 1072
/*
    Code written by Talant I.D.
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9	
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
 
bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2) 
		if(n % i == 0) return false;
	return true;
}

int main(){
    do_not_disturb
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ll n, cnt = 0, k = 10;
	cin >> n;
	if(n&1){
		cout << 0;
		return 0;
	}
	while(k <= n){
		cnt += n/k;
		k *= 5;
	}
	cout << cnt;
	
    return 0;
} // What is to be written here?


Measured memory_bytes: 256
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
l=[i for i in range(1,n+1)]
ite=list(itertools.permutations(l,n))
for x in range(len(ite)):
    if ite[x]==p:y=x
    if ite[x]==q:z=x
print(abs(y-z))

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

// why am I so weak

int n;

typedef pair<long long, long long> P;

#define ft first
#define sd second

P p[1055];

struct edge {int to; double cost;};

vector<edge> g[1055];

inline void add_edge(int from, int to, double cost) {
	g[from].push_back((edge){to, cost});
}
inline double dist(int i, int j) {
	return sqrt(1. * (p[i].ft - p[j].ft) * (p[i].ft - p[j].ft) + (p[i].sd - p[j].sd) * (p[i].sd - p[j].sd));
}

double d[1055];

struct node {
	double key;
	int u;

	bool operator < (const node &u) const {
		return key > u.key;
	}
};

double radius[1055];
bool used[1055];

double dijk() {
	priority_queue<node> pq;

	for (int i = 1; i < n; i++) d[i] = 1e17;

	pq.push((node){0., 0});
	d[0] = 0;

	while (!pq.empty()) {
		int v = pq.top().u; pq.pop();

		if (used[v]) continue;

		used[v] = true;

		for (auto e : g[v]) {
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				pq.push((node){d[e.to], e.to});
			}
		}
	}

	return d[1];
}
int main() {
	{
		long long x, y;

		scanf("%lld %lld", &x, &y);

		p[0] = P(x, y);

		scanf("%lld %lld", &x, &y);

		p[1] = P(x, y);
	}

	scanf("%d", &n);

	n += 2;

	for (int i = 2; i < n; i++) {
		scanf("%lld %lld %lf", &p[i].ft, &p[i].sd, &radius[i]);
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;

			add_edge(i, j, max(0., dist(i, j) - (radius[i] + radius[j])));
		}
	}

	printf("%.12lf\n", dijk());

	return 0;
}


Measured memory_bytes: 20592
#include <iostream>

using namespace std;
bool jsh(int i)
{
    if(i%2==0)return false;
    else return true;
}

bool judge(int n)
{
    int ans=0;
    for(int i=1;i<=n;i++)
        if(n%i==0)  ans++;
    if(ans==8)return true;
    else return false;
}

int main()
{
    int a;
    cin>>a;
    int aas=0;
    for(int i=1;i<=a;i++){
        if(!jsh(i)) continue;
        if(judge(i))   aas++;
    }
    cout<<aas<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 10010
int main(){
    int H;
    int W;
   
while(true){
    scanf("%d %d",&H,&W);
    if(W==0 && H == 0)break;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(i !=0 && i != H-1 && j !=0 && j != W-1)putchar('.');
            else putchar('#');
        }
    printf("\n");
    }
    printf("\n");
}
return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <math.h>
#include<vector>
#include<cstdio>
#include<string.h>
using namespace std;
const int N=2e5+5;
int num[N];

int main(){
    int n,m,a,b,flag=0;
    cin>>n>>m;
    memset(num,0,sizeof(num));
    for(int i=0;i<m;++i){
        cin>>a>>b;
        if(a==1||a==n) ++num[b];
        if(b==1||b==n) ++num[a];
        if(num[a]==2||num[b]==2) flag=1;
    }

    if(flag) cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007
#define hell 1000000009
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;


int main()
{
    string str;
    cin>>str;
    ll k;
    cin>>k;
    int x = 1;
    int n = str.size();
    ll cnt = 0;
    for(int i=0; i<n; i++)
    {
        if(str[i] > '1')
        {
            x = str[i] - '0';
            break;
        }
        cnt++;
    }
    if(k <= cnt)
        cout<<1<<endl;
    else
        cout<<x<<endl;
    return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const ll inf = (ll)1e9 + 7;
int main()
{
    ll i, j, n;
    double l, k, t;
    cin >> l;
    k = l * l * l;
    t = 3 * 3 * 3;
    printf("%0.6f", (k / t));
    //cout << (k / t);

    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int H, W;
	cin >> H >> W;
	int h, w;
	cin >> h >> w;
	cout << (H - h) * (W - w) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
using namespace std;
typedef long long int llint;
int main() {
	int a, b;
	cin >> a;
	if (a < 1000) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ABD" << endl;
	}
	return 0;
}

Measured memory_bytes: 256