akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	char *S[]={"Rock","Gun","Lightning","Devil","Dragon","Water","Air","Paper","Sponge","Wolf","Tree","Human","Snake","Scissors","Fire"},s[64];
	map<string,int>M;
	int i,j,n,x,y;
	for(i=0;i<15;++i)M[S[i]]=i;
	while(scanf("%d",&n),n)
	{
		vector<int>h;
		int w[15]={0},l[15]={0};
		while(n--)scanf("%s",&s),h.push_back(M[s]);
		sort(h.begin(),h.end());
		h.erase(unique(h.begin(),h.end()),h.end());
		for(i=0;i<h.size();++i)for(j=0;j<h.size();++j)
		{
			x=h[i],y=h[j];
			if(x>y)y+=15;
			if(y-x)
			{
				if(y-x<8)l[i]++;
				else w[i]++;
			}
		}
		for(x=i=0;i<h.size();++i)if(w[i]&&!l[i])printf("%s\n",S[h[i]]),++x;
		if(!x)puts("Draw");
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    LL(x, k, d);
    if(x < 0) x = -x;
    ll c = x / d;
    if(k <= c){
        print(x - d * k);
        return 0;
    }
    else{
        k -= c;
        x -= d * c;
        if(k % 2) print(min(abs(x + d), abs(x - d)));
        else print(abs(x));
    }
}

Measured memory_bytes: 3656
#abc089d

h,w,d=map(int,raw_input().split())
a=[]
for i in xrange(h):
 a.append(list(map(int,raw_input().split())))
q=int(raw_input())
p=[0 for i in xrange(h*w+1)]
for i in xrange(h):
 for j in xrange(w):
  p[a[i][j]]=(i,j)
dt=[0 for i in xrange(h*w+1)]
for i in xrange(d+1,h*w+1):
 dt[i]=dt[i-d]+abs(p[i][0]-p[i-d][0])+abs(p[i][1]-p[i-d][1])
l=[]
r=[]
while q:
 l,r=map(int,raw_input().split())
 print dt[r]-dt[l]
 q-=1


Measured memory_bytes: 16744
using System;
using System.Linq;

class C
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int k = h[0], n = h[1];
		var a = Read();
		Console.WriteLine(k - Enumerable.Range(0, n).Max(i => (k + a[(i + 1) % n] - a[i]) % k));
	}
}


Measured memory_bytes: 43924
#include<stdio.h>

int main(){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x >= r && y >= r && x + r <= W && y + r <= H){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2100
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#ifndef U_L_LONG
typedef unsigned long long U_L_LONG;
#endif
#ifndef L_LONG
typedef long long L_LONG;
#endif


static void ABC120C_Unification();

int main()
{
	ABC120C_Unification();
	
	fflush(stdout);
	return 0;
}

static void ABC120C_Unification()
{
	static char szS[100004] = { 0 };

	scanf(" %s", szS);
	int szlen = strlen(szS);
	std::vector<char> vCube;
	for (int i = 0; i <= szlen; i++) {	//	番兵 0 を仕込む
		vCube.push_back(szS[i]);
	}
	
//	char bfrC = 0;
	int nextIdx = 0, removeCnt = 0, bfrIdx = 0;


	auto nextItr = vCube.begin();
	auto bfrItr = vCube.begin();
	bool renew = false;
	while (*nextItr != 0) {
		if (*nextItr != *bfrItr) {
			removeCnt += 2;
			auto removeTarg = bfrItr;

			if (bfrItr != vCube.begin()) {
				bfrItr--;
			}
			else {
				renew = true;
			}
			//	対象のキューブを消す
			vCube.erase(removeTarg + 1);
			vCube.erase(removeTarg);

			if (renew) {
				bfrItr = vCube.begin();
			}
			nextItr = bfrItr;
		}
		else {
			bfrItr = nextItr;
			nextItr++;
		}
	}
	
	printf("%d\n", removeCnt);
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main (String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	Node root = new Node();
	TreeWalker walker = new TreeWalker();
	int n = Integer.parseInt(br.readLine());
	String[] input;
	for (int i = 0; i < n; i++) {
	    input = br.readLine().split(" ");
	    if (input.length == 1) {
		walker.runPrintInorder(root.right);
		walker.runPrintPreorder(root.right);
	    } else if (input.length == 2) {
		if (input[0].equals("insert")) {
		    root.insert (root, Integer.parseInt(input[1]));
		} else if (input[0].equals("find")) {
		    root.find (root, Integer.parseInt(input[1]));
		}
	    }
	}
	
    }
}
class Node {
    int key;
    Node left;
    Node right;
    Node () {
	key = 2000000001 * (-1);
	left = null;
	right = null;
    }
    Node (int key) {
	this.key = key;
	left = null;
	right = null;
    }
    void insert (Node root, int key) {
	Node node = root;
	Node parent = null;
	while (node != null) {
	    parent = node;
	    if (key < node.key) {
		node = node.left;
	    } else {
		node = node.right;
	    }
	}
	if (parent == null) {
	    parent = new Node (key);
	} else if (key < parent.key) {
	    parent.left = new Node (key);
	} else {
	    parent.right = new Node (key);
	}
    }
    void find (Node root, int key) {
	Node node = root;
	boolean isFind = false;
	while (node != null) {
	    if (key == node.key) {
		isFind = true;
		break;
	    }
	    if (key < node.key) {
		node = node.left;
	    } else {
		node = node.right;
	    }
	}
	if (isFind) {
	    System.out.println("yes");
	} else {
	    System.out.println("no");
	}
    }
}
class TreeWalker {
    void runPrintInorder (Node root) {
	StringBuilder sb = new StringBuilder();
	printInorder(root, sb);
	System.out.println(sb);
    }
    void printInorder (Node node, StringBuilder sb) {
	if (node == null) {
	    return;
	}
	printInorder(node.left, sb);
	sb.append(" " + node.key);
	printInorder(node.right, sb);
    }
    void runPrintPreorder (Node root) {
	StringBuilder sb = new StringBuilder();
	printPreorder(root, sb);
	System.out.println(sb);
    }
    void printPreorder (Node node, StringBuilder sb) {
	if (node == null) {
	    return;
	}
	sb.append(" " + node.key);
	printPreorder(node.left, sb);
	printPreorder(node.right, sb);
    }
}

Measured memory_bytes: 120496
#include <stdio.h>

int main(void)
{
        int r,d,x,i,s;

        scanf("%d%d%d",&r,&d,&x);

        s=x;
        for(i=0;i<10;i++){
                s=r*s-d;
                printf("%d\n",s);
        }
        return 0;
}


Measured memory_bytes: 128
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    map<char, int> ten = {
        {'r', p},
        {'s', r},
        {'p', s}
    };
    ll result = 0;
    IFOR(mod, 0, k-1){
        char before = ' ';
        for(int i=mod;i<n;i+=k){
            if(i==mod || t[i] != before){
                result += ten[t[i]];
                before = t[i];
            }
            else{
                before = ' ';
            }
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i, m, n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(x) begin(x), end(x)
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int main() {
    int n; scanf("%d", &n);
    vector<int> t(n); repeat (i, n) scanf("%d", &t[i]);
    vector<int> v(n); repeat (i, n) scanf("%d", &v[i]);
    const int max_v = *max_element(whole(v));
    constexpr int zoom = 12;
    vector<double> cur(zoom * max_v + 3, - INFINITY);
    vector<double> prv(zoom * max_v + 3, - INFINITY);
    cur[0] = 0;
    repeat (i, n) {
        fill(cur.begin() + (zoom * v[i] + 1), cur.end(), - INFINITY);
        fill(prv.begin() + (zoom * v[i] + 1), prv.end(), - INFINITY);
        repeat (tick, zoom * t[i]) {
            cur.swap(prv);
            cur[0] = max(prv[0], prv[1] + 0.5 / zoom);
            repeat_from (a, 1, zoom * v[i] + 1) {
                cur[a] = max({ prv[a - 1] - 0.5 / zoom, prv[a], prv[a + 1] + 0.5 / zoom }) + a /(double) (zoom * zoom);
            }
        }
    }
    printf("%.12lf\n", cur[0]);
    return 0;
}


Measured memory_bytes: 256
# E - Crested Ibis vs Monster
def main():
    INF = 1 << 30

    H, N, *AB = map(int, open(0).read().split())
    dp = [INF] * (H + 10001)  # dp[i] := min magic points to decrease monster's health by i
    dp[0] = 0
    for a, b in zip(*[iter(AB)] * 2):
        for i in range(H):
            dp[i + a] = min(dp[i + a], dp[i] + b)
    print(min(dp[H:]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 39792
x = int(input())

flag = False
for ia in range(0, int(x/4) + 1):
    for ib in range(0, int(x/7) + 1):
        if 4 * ia + 7 * ib == x:
            flag = True
            break
    if flag:
        break

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9148
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	int cnt;
	int num[4];
	while(scanf("%d",&n)&&n){
		cnt = 0;
		if(n%1111==0){
			cout <<"NA"<<endl;
			continue;
		}
		while(n!=6174){
			cnt++;
			int tmp =n;
			for(int i =0;i <4;i++){
				num[i]=tmp%10;
				tmp /=10;
			}
			int x = 0;
			sort(num,num+4,greater<int>());
			for(int i =0;i <4;i++){
				x =x*10+num[i];
			}
			int L,S;
			L =x;
			sort(num,num+4);
			x = 0;
			for(int i =0;i <4;i++){
				x =x*10+num[i];
			}
			S =x;
			n =L-S;
		}
		cout <<cnt<<endl;
	}
	return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N+1);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> frm(N+1, -1);
    frm[1] = 0;
    queue<int> q;
    for (int x : G[1]) {
        frm[x] = 1;
        q.push(x);
    }
    while (!q.empty()) {
        int x = q.front(); q.pop();
        for (auto o : G[x]) {
            if (frm[o] == -1) {
                frm[o] = x;
                q.push(o);
            }
        }
    }
    bool f = true;
    for (int i = 2; i <= N; i++) {
        if (frm[i] == -1) f = false;
    }
    if (f) {
        cout << "Yes" << endl;
        for (int i = 2; i <= N; i++) cout << frm[i] << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 10240
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


// ----------------------------------------------------------------------------
// beetさんの素因数分解
template<typename T>
map<T, ll> factorize(T x){
  map<T, ll> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}
// 使用例
// vector<int> cnt(111,0);
// for(int i=1; i<=N; i++){
//   for(auto p: factorize(i)){
//     cnt[p.first] += p.second;
//   }
// }

int main(){
  int N;
  cin >> N;
  vector<int> cnt(111,0);
  for(int i=1; i<=N; i++){
    for(auto p: factorize(i)){
      cnt[p.first] += p.second;
    }
  }
  int ans=0;
  if(cnt[2] >= 74) ans++;

  for(int i=2; i<111; i++){
    for(int j=2; j<111; j++){
      if(i == j) continue;
      if(cnt[i] >= 24 && cnt[j] >= 2) ans++;
    }
  }

  for(int i=2; i<111; i++){
    for(int j=2; j<111; j++){
      if(i == j) continue;
      if(cnt[i]>=14 && cnt[j]>=4) ans++;
    }
  }

  for(int i=2; i<111; i++){
    for(int j=2; j<111; j++){
      for(int k=2; k<j; k++){
        if(i==j || i==k) continue;
        if(cnt[i]>=2 && cnt[j]>=4 && cnt[k]>=4) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	A := sc.nextInt()
	op := sc.nextStr()
	B := sc.nextInt()

	switch op {
	case "+":
		fmt.Println(A + B)
	case "-":
		fmt.Println(A - B)
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


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

int main() {
	int N, count = 0;
	cin >> N;

	for (int A = 1; A < 10000000; A++)
	{
		if (A > N) break;
		for (int B = 1; B < 10000000; B++)
		{
			if (A * B > N) break;
			if (N - A*B > 0) count++;
					
		}
	}

	cout << count << endl;

	return 0;
}

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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  string s;
  if (a >= b) {
    for (int i = 0; i < a; i++) {
      s += to_string(b);
    }
  } else {
    for (int i = 0; i < b; i++) {
      s += to_string(a);
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <array>
using namespace std;
int main() {
    array<array<int, 3>, 3> c;
    for (auto& v : c) for (auto& i : v) cin >> i;
    cout << (
        c[1][0] - c[0][0] == c[1][1] - c[0][1] &&
        c[1][1] - c[0][1] == c[1][2] - c[0][2] &&
        c[2][0] - c[0][0] == c[2][1] - c[0][1] &&
        c[2][1] - c[0][1] == c[2][2] - c[0][2] ?
        "Yes" : "No"
    ) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        while (true) {
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            int ans = 0;

            switch (op) {
                case "+":
                    ans = a + b;
                    break;
                case "-":
                    ans = a - b;
                    break;
                case "*":
                    ans = a * b;
                    break;
                case "/":
                    ans = a / b;
                    break;
                case "?":
                    return;
            }

            System.out.println(ans);
        }
    }
}


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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
//		freopen("input.txt","r",stdin);
	#endif
	int a,b;
	cin>>a>>b;
	cout << (a+b-1)/b << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

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

typedef pair<int, int> P;
ll modnum = 1e9+7;

const int MAX = 1e5+5;

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


ll modpow(ll a, ll n, ll m)
{
    if(n == 0) return 1;
    ll t = modpow(a, n >> 1, m);
    t = t * t % m;
    if(n & 1) t = t * a % m;
    return t; 
}

ll modinv(ll a, ll m)
{
    return modpow(a, m - 2, m);
}

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

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

ll ans(ll n, ll k, vec a) {
    // 二項係数テーブルを作成しておく
    COMinit();

    sort(a.begin(), a.end());
    ll ans = 0;
    REP(i,0,n) {
        if(i >= k-1) {
            ans += COM(i, k-1) * a[i];
            ans %= modnum;
        }
        if(n-i-1 >= k-1) {
            ans -= COM(n-i-1, k-1) * a[i];
            ans %= modnum;
        }
    }

    return ans < 0 ? ans + modnum : ans;
}


int main()
{

    srand(time(NULL));

    ll N, K;
    cin >> N >> K;
    vec A(N+1, -INF);
    REP(i,1,N+1) {
        cin >> A[i];
        //A[i] = rand() % (1000000000LL) - 2000000000LL;
    }

    if(K >= 2 && N >= 2) {

        ASC(A);

        vec S(N+1, 0);
        REP(i,0,N) S[i+1] = S[i] + A[i+1];

        vec C(N+1, 0);
        C[K-2] = 1;
        REP(i,K-2,N) {
            C[i+1] = (C[i] * (i+1)) % MOD;
            C[i+1] = (C[i+1] * modinv(i-K+3, MOD)) % MOD;
        }

        ll sum = 0;
        REP(i,K,N+1) {
            sum = (sum + C[i-2] * (S[N] - S[i-1] - S[N-i+1])) % MOD;
        }
        sum = (sum < 0 ? sum + MOD : sum);

        //PR(sum);
    
    }
    else {
        //PR(0);
    }

    vec _A(N);
    REP(i,0,N) _A[i] = A[i+1];

    PR(ans(N,K,_A));

    return 0;
}

/*



*/

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

#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
bool Setmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;

int main() {
  rd(ll, n, c);
  V<ll> x(n), v(n);
  rep(i, n) cin >> x[i] >> v[i];
  auto f = [&n](const V<ll>& x, const V<ll>& v) {
    V<ll> y(n + 1);
    ll p = 0;
    ll c = 0;
    rep(i, n) {
      c = c + v[i] - (x[i] - p);
      p = x[i];
      y[i + 1] = max(y[i], c);
    }
    return y;
  };
  V<ll> rx = x;
  reverse(all(rx));
  rep(i, n) rx[i] = c - rx[i];
  V<ll> rv = v;
  reverse(all(rv));

  V<ll> l = f(x, v);
  V<ll> r = f(rx, rv);

  ll ans = max(l[n], r[n]);
  for (int i = 1; i < n; ++i) {
    ans = max(ans, l[i] - x[i - 1] + r[n - i]);
    ans = max(ans, r[i] - rx[i - 1] + l[n - i]);
  }

  /*
  rep(i, n - 1) {
    int j = n - i;
    ll d = numeric_limits<ll>::max();
    if (i > 0) d = min(d, x[i - 1]);
    if (j > 0) d = min(d, rx[j - 1]);
    ans = max(ans, l[i] + r[j] - d);
  }
  */
  wt(ans);
}


Measured memory_bytes: 8004
#include <bits/stdc++.h>
#define N 86400
//#define double long double
#define int long long
using namespace std;
const int INF = 1LL<<55;
const double EPS = 1e-6;
int n;
double vol;
int A[N];

bool check(double x){
  double tank = vol;
  vector<double> his(N);
  for(int i=0;i<N;i++){
    tank -= A[i%N];
    tank=min(vol,tank+x);   
    if(tank < 0) return 0;
  }
  
  for(int i=0;i<N;i++){
    tank -= A[i%N];
    tank=min(vol,tank+x);
    his[i]  = tank;
    if(tank < 0) return 0;
  }
  
  for(int i=0;i<N;i++){
    tank -= A[i%N];
    tank=min(vol,tank+x);
    if(his[i] > tank) return 0;
  }
  
  return 1;
}  
double search(){
  double L=0,M,R=(1e6)+10,cnt=50;
  while(cnt--){
    M = (L+R)/2;
    if(check(M)) R = M;
    else L = M;
  }
  return L;
}

signed main(){
  while(1){
    cin>>n>>vol;
    if(!n&&vol==0)break;
    memset(A,0,sizeof(A));  
    for(int i=0,s,t,u;i<n;i++){
      cin>>s>>t>>u;
      while(s < t) A[s++] = u;
    }
    printf("%.10lf\n",search());
  }  
  return 0;
}

Measured memory_bytes: 4520
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ", "
#define de(x) cout << #x << "=" << x << endl
#define ds() puts("---stop here---")
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;

int main()
{
    int a,b,c,d;
    scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
    if(a==b && a==c&&a==d) puts("Yes");
    else if(a==b&&a==c&&a!=d) puts("Yes");
    else if(a!=b&&b==c&&c==d) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
const int maxn = 1e5 + 5;
bool visited[maxn];
vector<int>adj[maxn];


void dfs(int v) {
	visited[v] = true;

	for (auto it : adj[v]) {
		if (!visited[it]) {
			dfs(it);
		}
	}
}


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

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

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

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		if (!visited[i]) {
			dfs(i);
			ans++;
		}
	}

	cout << ans - 1 << endl;
}


Measured memory_bytes: 9632
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll t[100001],a[100001];
ll hi[100001];
const int MAX_N=200001;
const int mod=1000000007;
int main(){
    int n;
    cin>>n;
    int mx=0,l,r;
    rep(i,n){
        cin>>t[i];
        if(mx<t[i]) mx=t[i],l=i;
    }
    int mx2=0;
    rep(i,n){
        cin>>a[i];
    }
    for(int i=n-1;i>=0;--i){
        if(mx2<a[i]) mx2=a[i],r=i;
    }
    if(mx!=mx2||l>r){
        cout<<0<<endl;
        return 0;
    }
    mx=0;
    rep(i,l+1){
        if(mx<t[i]){
            mx=t[i];
            hi[i]=-1;
        }
        else hi[i]=mx;
    }
    mx=0;
    for(int i=n-1;i>=r;--i){
        if(mx<a[i]){
            mx=a[i];
            hi[i]=-1;
        }
        else hi[i]=mx;
    }
    FOR(i,l+1,r) hi[i]=mx;
    //rep(i,n) cout<<hi[i];
    ll ans=1;
    rep(i,n){
        if(hi[i]!=-1){
            ans*=hi[i];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int up[100005];
int dow[100005];
int cmp(int x,int y){
    return x>y;
}
int main()
{
    int n;
    while(~scanf("%d",&n)){
        memset(up,0,sizeof(up));
        memset(dow,0,sizeof(dow));
        int x;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            if(i%2==0)
                up[x]++;
            else
                dow[x]++;
        }
        int max1=0,max2=0,val1,val2;
        for(int i=1;i<100001;i++){
            if(up[i]>max1)
            {
                max1=up[i];
                val1=i;
            }
            if(dow[i]>max2)
            {
                max2=dow[i];
                val2=i;
            }
        }
        sort(up+1,up+100001,cmp);
        sort(dow+1,dow+100001,cmp);
        if(val1!=val2)
            printf("%d\n",n-up[1]-dow[1]);
        else{
            if(up[1]>dow[1])
                printf("%d\n",n-up[1]-dow[2]);
            else if(up[1]==dow[1])
                printf("%d\n",n-up[1]-max(up[2],dow[2]));
            else
                printf("%d\n",n-dow[1]-up[2]);
        }
    }
    return 0;
}


Measured memory_bytes: 896
A,B,C,D,E,F=map(int,input().split())

water=set()
for a in range(0,F+1,100*A):
  for b in range(0,F+1,100*B):
    if a+b<=F: water.add(a+b)
water=sorted(list(water))
suger=set()
for c in range(0,F+1,C):
  for d in range(0,F+1,D):
    if c+d<=F: suger.add(c+d)
suger=sorted(list(suger))

kosa,ans1,ans2=0,0,0
for w in water:
  for s in suger:
    if (w//100)*E<s or w+s>F: break
    if w+s!=0 and kosa<=(100*s) / (w+s):
      kosa=(100*s) / (w+s)
      ans1,ans2=w+s,s
print(ans1,ans2)

Measured memory_bytes: 3188
#define IO std::ios::sync_with_stdio(false);
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,k,mi,mx;
int a[15]={0,2,5,5,4,5,6,3,7,6};
ll gcd(ll x,ll y){
	return x%y==0?y:gcd(y,x%y);
}
int b[15];
int c[1000005];
int d[100],d1[100],f[100];
void dfs(int x,int h){
	if(x<mi){
		if(x!=0)return;
		int z=h-1;
		if(z>mx){
			mx=z;
			for(int i=1;i<=z;i++){
				f[i]=d[i];
			}
		}
		else if(z==mx){
			for(int i=1;i<=z;i++){
				d1[i]=d[i];
			}
			sort(d1+1,d1+1+z);
			sort(f+1,f+1+z);
			int flag=0;
			for(int i=z;i>=1;i--){
				if(d1[i]>f[i]){
					flag=1;
					break;
				}
				else if(d1[i]<f[i])break;
			}
			if(flag){
				for(int i=1;i<=z;i++){
					f[i]=d1[i];
				}
			}
		}
		return;
	}
	for(int i=2;i<=7;i++){
		if(x>=i&&b[i]){
			d[h]=b[i];
			dfs(x-i,h+1);
		}
	}
}
int main(){
	IO;
	cin>>n>>m;
	mi=999;
	for(int i=1;i<=m;i++){
		cin>>k;
		mi=min(mi,a[k]);
		b[a[k]]=max(b[a[k]],k);
	}
	//for(int i=4;i<=6;i++)cout<<b[i];
	int cnt=0;
	ll h=0,x=n;
	for(int i=2;i<=7;i++){
		if(n<=30)break;
		if(b[i]){
			h=(n-30)/i;
			x=n-h*i;
			for(int j=1;j<=h;j++){
				c[++cnt]=b[i];
			}
			break;
		}
	}
	dfs(x,1);
	for(int i=1;i<=mx;i++){
		c[++cnt]=f[i];
	}
	sort(c+1,c+1+cnt);
	for(int i=cnt;i>=1;i--){
		cout<<c[i];
	}
	cout<<endl;
}
/*2: 1
3: 7
4: 4
5: 5
6: 9
7: 8*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int N;
    cin >> N;
    int ans = 0;
    map<string, int> m;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        if(m.count(s) == 0) {
            ans++;
            m.insert({s, 1});
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19096
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let x: i64 = read();

    println!("{}", 1 - x);
}


Measured memory_bytes: 2096
def calc(N, K):
    if K == 0:
        return N**2
    result = 0
    for b in range(K + 1, N + 1):
        n, m = divmod(N, b)
        result += (b - K) * n
        if m >= K:
            result += m - K + 1
    return result

N, K = [int(_) for _ in input().split()]
print(calc(N, K))


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 0, b = 0, c, d, n, k = 0, ans = 0;
string s, t;


int main()
{
	cin >> n;
	int sum = 0; vector<int> time(n);
	rep(i, n) { cin >> a; sum += a; time[i] = a; }
	int m; cin >> m;
	vector<int> ans(m);
	rep(i,m)
	{
		cin >> b >> c;
		ans[i] = sum - time[b - 1] + c;
	}
	rep(i, m)cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
n=999999
prime = [1]*(n+1)
(prime[0],prime[1])=(0,0)
for i in [v for v in xrange(2,n+1) if v*v<n+1]:
        for j in xrange(i*i,n+1,i):
            prime[j]=0

for inp in sys.stdin:
    print prime[:int(inp)+1].count(1)

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

int main(int argc, char **argv) {
	int N,A,B;
	cin >> N >> A >> B;
	int cnt0 = 0;
	int cnt1 = 0;
	int cnt2 = 0;
	for (int i=0; i<N; i++) {
		int tmp;
		cin >> tmp;
		if (tmp<=A) cnt0++;
		else if (tmp<=B) cnt1++;
		else cnt2++;
	}
	if (cnt0>cnt1) cnt0=cnt1;
	if (cnt0>cnt2) cnt0=cnt2;
	cout << cnt0 << endl;
	return 0;
}

Measured memory_bytes: 384
M = [int(i) for i in input()][::-1] + [0]
ans = 0
flag = 0
for i in range(len(M)):
    if M[i] > 5:
        if M[i-1] == 5:
            ans += 10-M[i]+4
            M[i-1] = 0
            M[i] = 0
            M[i+1] += 1
        else:
            ans += 10-M[i]
            M[i+1] += 1
            M[i] = 0
    elif M[i] == 5 and M[i-1] == 5:
        M[i-1] = 0
        M[i] = 0
        M[i+1] += 1
        ans += 9
print(sum(M)+ans)


Measured memory_bytes: 20460
program fractal_shortest_path
  implicit none
  integer, parameter :: n = 30
  integer :: q, i, k
  integer(8) :: a, b, c, d, pow(0:n) = 0, p, x, y, z, w, m, s, t
  logical :: fx, fy
  pow(0) = 1
  do i = 1, n
    pow(i) = pow(i - 1) * 3
  end do
  read(*,*) q
  do i = 1, q
    read(*,*) a, b, c, d
    a = a - 1
    b = b - 1
    c = c - 1
    d = d - 1
    do k = n, 0, -1
      p = pow(k)
      x = a / p
      y = b / p
      z = c / p
      w = d / p
      fx = x == z .and. mod(x, 3) == 1 .and. abs(y - w) >= 2
      fy = y == w .and. mod(y, 3) == 1 .and. abs(x - z) >= 2
      if (fx .or. fy) then
        if (fx) then
          s = mod(a, p)
          t = mod(c, p)
          m = abs(d - b)
        else
          s = mod(b, p)
          t = mod(d, p)
          m = abs(c - a)
        end if
        m = m + min(s + t + 2, p * 2 - s - t)
        goto 100
      end if
    end do
    m = abs(c - a) + abs(d - b)
    100 write(*,'(i0)') m
  end do
end program fractal_shortest_path

Measured memory_bytes: 2888
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  vector<ll> l(87);
  l[0] = 2;
  l[1] = 1;
  FORe(i, 2, 86){
    l[i] = l[i-1] + l[i-2];
  }
  cout << l[n] << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

R = ["AAA","AA","A","B","C","D","E","NA"]


for i in sys.stdin:
    t1,t2 = map(float,i.split())
    t5 = t10 = 0
    if   t1 < 35.5: t5 = 0
    elif t1 < 37.5: t5 = 1
    elif t1 < 40  : t5 = 2
    elif t1 < 43  : t5 = 3
    elif t1 < 50  : t5 = 4
    elif t1 < 55  : t5 = 5
    elif t1 < 70  : t5 = 6
    else          : t5 = 7

    if   t2 < 71  : t10 = 0
    elif t2 < 77  : t10 = 1
    elif t2 < 83  : t10 = 2
    elif t2 < 89  : t10 = 3
    elif t2 < 105 : t10 = 4
    elif t2 < 116 : t10 = 5
    elif t2 < 148 : t10 = 6
    else          : t10 = 7

    t = max(t5,t10)
    print(R[t])


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
int32_t main(){
	//digit DP
	//f(index,sum,same)
	string k;
	cin>>k;
	int d; cin>>d;
	int f[k.length()+5][d+5][2];
	memset(f,0,sizeof(f));
	for(int j=0; j<=k[0]-'0'; j++){
		int v = j%d;
		if(j < k[0]-'0') f[0][v][0]++;
		else if(j==k[0]-'0')  f[0][v][1]=1;
		//cout<<0<<' '<<j<<' '<<f[0][j][0]<<' '<<f[0][j][1]<<endl;
	}
	for(int i=1; i<k.length(); i++){
		for(int j=0; j<=d; j++){
			for(int ne=0; ne<=9; ne++){ //new value
				int pv = j-ne; //prev sum
				while(pv < 0) pv+=d;
				
				if(ne == k[i]-'0') f[i][j][1] += f[i-1][pv][1];
				if(ne < k[i]-'0') f[i][j][0] += f[i-1][pv][1];
				
				f[i][j][0] += f[i-1][pv][0];
				f[i][j][0] %= MOD;
				f[i][j][1] %= MOD;
				//cout<<i<<' '<<j<<' '<<ne<<' '<<f[i][j][0]<<' '<<f[i][j][1]<<endl;
			}
			//cout<<i<<' '<<j<<' '<<f[i][j][0]<<' '<<f[i][j][1]<<endl;
		}
	}
	int t=f[k.length()-1][0][0] + f[k.length()-1][0][1];
	//cout<<f[k.length()-1][0][0] << ' '<<f[k.length()-1][0][1]<<endl;
	t%=MOD;
	t--;
	if(t<0) t+=MOD;
	cout<<t;
}

Measured memory_bytes: 16640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var count = 0L;

            for(int i = 0; i < 1000; i++) {
                var ans = i.ToString("000");
                var index = 0;
                for(int j = 0; j < n; j++) {
                    if(s[j] == ans[index]) {
                        index++;
                    }

                    if(index == 3) {
                        count++;
                        break;
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27640
#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>;

// 最大公約数を計算
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> xx(n);
  rep(i, n) cin >> xx[i];
  int result = 0;
  rep(i, n) {
    xx[i] = abs(xx[i] - x);
  }
  rep(i, n) {
    result = gcd(result, xx[i]);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
ll n,k,Ans,X;
inline ll Read()
{   rg ll a=0,c=1;   rg char b=getchar();
	while(b!='-'&&(b<'0'||b>'9'))b=getchar();
	if(b=='-')c=-1,b=getchar();
	while(b>='0'&&b<='9')a=a*10+b-48,b=getchar();
	return a*c;
}
int main()
{   scanf("%lld%lld",&n,&k);
	X=n/k;   Ans+=X*X*X;
	if(k%2==0)
	{   if(n%k>=k/2) X=n/k+1;
		else X=n/k;
		Ans+=X*X*X;
	}
	printf("%lld\n",Ans);
}


Measured memory_bytes: 256
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0 for i in[0]*n];d=0;k=n*(n-1)
while sum(a)<k and -1<d<9999:
 L=[0 for i in[0]*n];y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if l[x][a[x]]-1==i and L[x]+L[i]<1:
    a[i]+=1;a[x]+=1;L[i]=L[x]=y=1
 if y<1:d=-1
print([k//2,d][d<9999])

Measured memory_bytes: 56156
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = input().split()
ss = len(set(A))
if ss <= 3:
    print('Three')
else:
    print('Four')

Measured memory_bytes: 65428
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();
	private int N;

	void solve(Supplier<String> sc) {
		N = Integer.parseInt(sc.get());
		for (int i = 0; i < N + 1; i++) {
			dp.add(new HashMap<>());
		}
		System.out.println(dfs(0, "TTT"));
	}

	List<Map<String, Integer>> dp = new ArrayList<>();
	int dfs(int index, String prefix){
		if (dp.get(index).containsKey(prefix)) return dp.get(index).get(prefix);
		if (index == N) return 1;
		int result = 0;
		String p = prefix.substring(1);
		if (isOk(prefix + 'A')) result = add(result, dfs(index + 1, p + 'A'));
		if (isOk(prefix + 'G')) result = add(result, dfs(index + 1, p + 'G'));
		if (isOk(prefix + 'C')) result = add(result, dfs(index + 1, p + 'C'));
		if (isOk(prefix + 'T')) result = add(result, dfs(index + 1, p + 'T'));
		dp.get(index).put(prefix, result);
		return result;
	}

	boolean isOk(String subseq){
		for (int i = 0; i < 4; i++) { // simulate
			char[] chars = subseq.toCharArray();
			if (i >= 1) {
				char temp = chars[i];
				chars[i] = chars[i - 1];
				chars[i - 1] = temp;
			}
			if (String.valueOf(chars).contains("AGC")) {
				return false;
			}
		}
		return true;
	}

	static final int MOD = 1000000007;
	int mod(long val) {
		return (int) Math.floorMod(val, MOD);
	}

	int add(long a, long b) {
		return mod(a + b);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				try {
					return (line = line != null && line.hasMoreTokens() ? line : new StringTokenizer(reader.readLine())).nextToken();
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 35540
st = input()
li = list(st)
an = abs(int(li[0]+li[1]+li[2]) - 753)
for i in range(1,len(li)-2):
    x = int(li[i]+li[i+1]+li[i+2])
    y = abs(x - 753)
    an = min(an,y)
print(an)

Measured memory_bytes: 9132
// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ████━████   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━

// Author        : WhyWhy
// Created Time  : 2017年04月20日 星期四 19时55分15秒
// File Name     : D.cpp

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

const int mod=1000000007;

inline long long _pow(long long a,long long n) {
	long long ret=1;
	for(;n;n>>=1,(a*=a)%=mod)
		if(n&1) (ret*=a)%=mod;
	return ret;
}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	int N,M;
	long long x0,x1;
	long long a=0,b=0;

	scanf("%d %d",&N,&M);

	scanf("%lld",&x0);
	for(int i=1;i<N;++i) {
		scanf("%lld",&x1);
		(a+=i*(0LL+N-i)%mod*(x1-x0)%mod)%=mod;
		x0=x1;
	}

	scanf("%lld",&x0);
	for(int i=1;i<M;++i) {
		scanf("%lld",&x1);
		(b+=i*(0LL+M-i)%mod*(x1-x0)%mod)%=mod;
		x0=x1;
	}

	printf("%lld\n",a*b%mod);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
using namespace std;
char str[105];
int main(void)
{
	scanf("%s", str);
	int len = strlen(str);
	if (len % 2) {
		printf("No\n");
		return 0;
	}
	bool flag = 0;
	for (int i = 0; i < len; i+=2)
		if (!((str[i] == 'h') && (str[i + 1] == 'i'))) {
			flag = 1;
			break;
		}
	if (flag)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

ll divup(ll x, ll y){
  if(x %y == 0) return x/y;
  else return x/y + 1;
}

int main(){
  int n; cin >> n;
  ll p_a, p_b; cin >> p_a >> p_b;
  ll a, b;
  for(int i=1;i<n;i++){
    cin >> a >> b;
    ll t = max(divup(p_a, a), divup(p_b, b));
    a = a*t; b = b*t;
    p_a = a; p_b = b;
  }
  // 0 is false
  if(n-1) cout << a+b << endl;
  else cout << p_a+p_b << endl;
}

Measured memory_bytes: 256