akhauriyash/Code-Regression huggingface dataset:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defstruct (queue (:constructor make-queue
                    (&optional list &aux (tail (last list)))))
  (list nil :type list)
  (tail nil :type (or null (cons t null))))

(declaim (inline enqueue))
(defun enqueue (obj queue)
  (symbol-macrolet ((list (queue-list queue))
                    (tail (queue-tail queue)))
    (if (null list)
        (setf tail (list obj)
              list tail)
        (setf (cdr tail) (list obj)
              tail (cdr tail))))
  queue)

(declaim (inline enqueue-front))
(defun enqueue-front (obj queue)
  (symbol-macrolet ((list (queue-list queue))
                    (tail (queue-tail queue)))
    (if (null list)
        (setf tail (list obj)
              list tail)
        (push obj list))
    queue))

(defun read-fixnum+ (&optional (in *standard-input*))
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let ((result (loop (let ((byte (%read-byte)))
                          (cond ((<= 48 byte 57)
                                 (return (- byte 48)))
                                ((zerop byte) ; #\Nul
                                 (return-from read-fixnum+ 0)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return nil))))
      result)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (queue (make-queue)))
    (declare (uint31 n))
    (if (evenp n)
        (dotimes (i n)
          (if (evenp i)
              (enqueue (read-fixnum+) queue)
              (enqueue-front (read-fixnum+) queue)))
        (dotimes (i n)
          (if (oddp i)
              (enqueue (read-fixnum+) queue)
              (enqueue-front (read-fixnum+) queue))))
    (let ((i 0))
      (declare (uint31 i))
      (dolist (x (queue-list queue) (terpri))
        (write (the uint31 x))
        (incf i)
        (when (< i n)
          (write-char #\ ))))))

#-swank(main)


Measured memory_bytes: 16996
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define ri register int
using namespace std;
typedef double db;
typedef long double ld;
typedef long long ll;
typedef vector <int> poly;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef unsigned long long ulll;
typedef unsigned int uii;
typedef string strr;
#define fi first
#define se second
#define pb push_back
#define ppp pop_back
#define rez resize
const ll Inf = 1e18;
const int rlen = 1 << 20, inf = 0x3f3f3f3f;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib =  buf) + fread(buf, 1, rlen, stdin)), ib == ob) ? -1 : *ib++)
inline int read() {
  static int ans, f;
  static char ch;
  ans = 0, ch = gc(), f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = gc();
  return f ? ans: -ans;
}
inline ll readl() {
  static ll ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
inline int Read(char *s) {
  static int top;
  static char ch;
  top = 0, ch = gc();
  while (!isalpha(ch) && !isdigit(ch)) ch = gc();
  while (isalpha(ch) || isdigit(ch)) s[++top] = ch, ch = gc();
  return top;
}
namespace modular {
  const int mod = 998244353;
  int ret;
  inline int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod; }
  inline void Dec(int &a, int b) { a = a < b? a - b + mod : a - b; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) {
    for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1);
    return ret;
  }
  inline int Inv(int a) { return ksm(a, mod - 2); }
  inline int sqr(int a) { return (ll) a * a % mod; }
  inline int cub(int a) { return (ll) a * a % mod * a % mod; }
} using namespace modular;
template <typename T> inline void ckmax(T &a, T b) { a < b ? a = b : 0; }
template <typename T> inline void ckmin(T &a, T b) { a > b ? a = b : 0; }
template <typename T> inline T Abs(T a) { return a < 0 ? -a : a; }
template <typename T> inline T gcd(T a, T b) {
  T t;
  while (b) t = a, a = b, b = t - t / a * a;
  return a;
}
const int N = 2e5 + 5;
int n, ps[N][100];
bool vs[N];
ll K;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read(), K = readl();
  for (ri i = 1; i <= n; ++i) ps[i][0] = read();
  for (ri i = 1; i <= 63; ++i) for (ri j = 1; j <= n; ++j) ps[j][i] = ps[ps[j][i - 1]][i - 1];
  int x = 1;
  for (ri i = 63; ~i; --i) if (K >> i & 1) x = ps[x][i];
  cout << x;
  return 0;
}

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n;
    cin >> m;
    int a[m];
    rep(i, m) a[i] = 0;
    
    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int b;
            cin >> b;
            a[b-1]++;
        }
    }
    
    int ans = 0;
    rep(i, m){
        if(a[i] == n) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

using namespace std;
typedef long long ll;

const ll M = a7;

vector<ll> fac(2000000); //n!(mod M)
vector<ll> ifac(2000000); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分
ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main()
{
  ll x,y;cin>>x>>y;
  ll ans;
  if((x+y)%3==0&&x<=2*y&&y<=2*x){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<1500000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ans=comb((x+y)/3,x-(x+y)/3);
  }
  else ans=0;
  cout<<ans%a7<<endl;
  return 0;
}


Measured memory_bytes: 31488
def solve(ns)
  a = []
  r = []
  ns.each do |n|
    if n == 0
      a.push(r.pop)
    else
      r.push(n)
    end
  end
  a
end

ns = gets(nil).split("\n").map(&:to_i)
solve(ns).each {|a| puts a}

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

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define REP(i, n) for(int i=1; i<=(int)(n); i++)

using namespace std;

int main(){
    int N, K;
    double ret=0.0;

    cin >> N >> K;

    REP(i, N){
        double temp = 1.0/N;
        int now = i;
        while (now < K){
            now *= 2;
            temp /= 2;;
        }
        ret += temp;
    }

    printf("%.12f\n", ret);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

# C - Tsundoku

from itertools import accumulate, chain

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
assert len(a) == n
assert len(b) == m

def lister(a, b, k):
    """sequence of i+j while sum(a[:i]) + sum(b[:j]) <= k"""
    j = len(b)
    sumb = sum(b)
    for i, suma in enumerate(chain([0], accumulate(a))):
        if suma > k:
            break
        while suma + sumb > k and j > 0:
            j -= 1
            sumb -= b[j]
        if suma + sumb <= k:
            yield i + j

print(max(lister(a, b, k)))


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


int main() {
  int n;
  cin >> n;
  priority_queue<int> que;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    que.push(a);
  }
  bool ok = true;
  
  for (int i = 0; i < n-1; i++) {
    int p = que.top();
    que.pop();
    int q = que.top();
    if (p == q) {ok = false;}
  }
  
  if (ok) {cout << "YES" << endl;}
  else {cout << "NO" << endl;}
}
    

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const float eps=1e-6;
const ll mod=1e8;
int main()
{
    ll i,j;
    string s,t;
    cin>>s>>t;
    ll ssize=s.size(),tsize=t.size();
    ll dp[ssize+1][tsize+1]={0};
    for(i=0;i<=ssize;i++)
    {
        for(j=0;j<=tsize;j++)
        {
            if(i==0||j==0) dp[i][j]=0;
            else if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    //cout<<dp[ssize][tsize]<<endl;
    i=ssize;
    j=tsize;
    stack<char> st;
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            st.push(s[i-1]);
            i--;
            j--;
        }
        else if(dp[i-1][j]>=dp[i][j-1])
        {
            i--;
        }
        else j--;
    }
    while(!st.empty())
    {
        cout<<st.top();
        st.pop();
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    ll a,b;
    cin>>a>>b;
    char c[a+2][b+2];
    rep(i,a+2)rep(j,b+2)c[i][j]='.';
    rep(i,a)rep(j,b)cin>>c[i+1][j+1];
    rep(i,a)rep(j,b){
        if(c[i][j]=='#'){
            if(c[i-1][j]=='.'&&c[i][j-1]=='.'&&c[i+1][j]=='.'&&c[i][j+1]=='.')cout<<"No\n",exit(0);
        }
    }
    cout<<"Yes\n";

    return 0;
}


Measured memory_bytes: 256
a, b, c  = map(int,input().split())









"""
Aの倍数の集合を考える
s1 = a*1
s2 = a*2
s3 = a*3
・・・



Bで割ってC余る数の集合を考える
k0 = C
k1 = C + B
k2 = C + 2B
k3 = C + 3B
・・・
k999 = c + 999B

k0からk999まで、1000個の整数がひとつもAの倍数でないとしたら、
「Aの倍数ではない」とはつまり
Aで割ると1余る or 
Aで割ると2余る or
Aで割ると3余る or 
・・・
Aで割ると(A-1)余る
つまりパターンとしては A-1 通りしかない

Aで割ったときの余りが
k0 ... 1
k1 ... 3
k2 ... 1






for で回せば,YESの判定はなんとなくできそうだが
NOの判定はどうやればいい？





"""


k = []
result = 'NO'

for i in range(a+1):
    ## Bで割ってC余る数の集合を作る

    k.append(c + b*i)

for i in range(a+1):
    p,q = divmod(k[i],a)   ## Aで割った商と余りを求める
    if q==0:
        result = 'YES'


print(result)






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

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

    for (int i = 0; i < 3; i++) {
        if (n[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

int n,m,i,j,cnt[100005];

int main(){
	scanf("%d%d", &n, &m);
	
	for(i = 0; i < m; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		cnt[x]++;
		cnt[y]++;
	}
	
	bool flag = 1;
	
	for(i = 1; i <= n; i++)
	flag &= (cnt[i] % 2 == 0);
	
	if(flag)
	printf("YES\n");
	else
	printf("NO\n");
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		for (int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		int[] p = new int[m];
		int[] x = new int[m];
		for (int i = 0; i < m; i++) {
			p[i] = sc.nextInt();
			x[i] = sc.nextInt();
		}

		int sum = 0;

		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (j == p[i] - 1) {
					sum += x[i];
				} else {
					sum += t[j];
				}
			}
			System.out.println(sum);
			sum = 0;
		}

	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b; cin >> a >> b;
  if ( a%3==0 or b%3==0 or (a+b)%3==0 ) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n):
        if a[a[i]-1] == i+1:
            ans +=1
    print(ans//2)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20824
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<int,ll> p;
typedef pair<pii,int> P;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
vector<ll> fac(1e6),inv(1e6),finv(1e6);
void initcom(){
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
vector<int> prime_factor(int m){
    vector<int> res(1e6,0);
    for(int i=2;i*i<=m;++i){
        if(m%i==0){
            while(m%i==0){
                m/=i;
                res[i]++;
            }
        }
    }
    if(m>1){
        if(m>1e6) res.push_back(1);
        else res[m]++;
    }
    return res;
}
int main(){
    initcom();
    int n,m;cin>>n>>m;
    auto fact=prime_factor(m);
    ll ans=1;
    for(int i=0;i<(int)fact.size();++i){
        ans=ans*com(n+fact[i]-1,fact[i])%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 34224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	long long val;
	int ord;
} ll;

int llintcmp(const void *a, const void *b) {
	long long c = (*(ll *)a).val - (*(ll *)b).val;
	if (c>0) return 1;
	else if (c==0) return 0;
	else return -1;
}

int main() {
	int flag=0, i, j, N;
	ll A[100010];
	long long T=0;
	scanf("%d", &N);
	for (i=0;i<N;i++) {
		scanf("%lld", &(A[i].val));
		A[i].ord = i;
	}

	qsort(A, N, sizeof(ll), llintcmp);

	for (i=0;i<(N+1)/2;i++) {
		if ((A[2*i]).ord %2) T++;
	}

	printf("%lld\n", T);

	return 0;
}


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

using ll = long long; 

int main() {
        int i, j;
        int n, l;
        ll t;
        cin >> n >> l >> t;
        vector<int> x(n), d(n);
        //vector<pair<int, int>> y(n);
        for (i = 0; i < n; i ++) { 
                cin >> x[i] >> d[i];
                //y[i] = make_pair(x[i], i);
        }
        vector<ll> p;
        ll nc = 0;
        for (i = 0; i < n; i ++) {
                int dir = d[i] == 2 ? -1 : 1;
                ll pos = x[i] + dir * t;
                ll fp = ((pos % l) + l) % l;
                ll g = pos > 0 ? pos / l : (pos - l + 1) / l;
                nc += g;
                p.push_back(fp);
        }
        nc = ((nc % n) + n) % n;
        sort(p.begin(), p.end());
        vector<ll> ans(n);
        for (i = 0; i < n; i ++) ans[i] = p[(i + nc) % n];
        for (i = 0; i < n; i ++) cout << ans[i] << endl;
        return 0;
}


Measured memory_bytes: 3700
#include <cstdio>
#include <algorithm>

const int maxn = 260000;

char str1[maxn], str2[maxn];

int main()
{
	int h, w, len;
	int x, y;
	scanf("%d%d%d",&h, &w, &len);
	scanf("%d%d",&x, &y);
	scanf("%s", str1 + 1);
	scanf("%s", str2 + 1);

	int l1, r1, u1, d1;
	int l2, r2, u2, d2;
	l1 = r1 = u1 = d1 = l2 = r2 = u2 = d2 = 0;
	for (int i = 1;i <= len;i++){
		if (str1[i] == 'L') l1++;
		else if (str1[i] == 'R') r1++;
		else if (str1[i] == 'U') u1++;
		else d1++;
		if (y + r1 - l2 > w || y - l1 + r2 <= 0 || x + d1 - u2 > h || x - u1 + d2 <= 0){
			printf("NO\n");
			return 0;
		} 
		if (str2[i] == 'L') {
			if (y + r1 - l2 > 1) l2++;
		}
		else if (str2[i] == 'R') {
			if (y - l1 + r2 < w) r2++;
		}
		else if (str2[i] == 'U') {
			if (x + d1 - u2 > 1) u2++;
		}
		else {
			if (x - u1 + d2 < h) d2++;
		}
	}
	printf("YES\n");
    return 0;
}



Measured memory_bytes: 512
from sys import stdin
from collections import deque
n, e = map(int, stdin.readline().split())
G = [[] for _ in [0] * n]
indeg = [0] * n
out = []
V = [False] * n
def bfs(s):
    dq = deque([s])
    V[s] = True
    while dq:
        u = dq.popleft()
        out.append(u)
        for i in range(len(G[u])):
            v = G[u][i]
            indeg[v] -= 1
            if indeg[v] == 0 and not V[v]:
                V[v] = True
                dq.append(v)
def tsort():
    for u in range(n):
        for i in range(len(G[u])):
            indeg[G[u][i]] += 1
    for u in range(n):
        if indeg[u] == 0 and not V[u]:
            bfs(u)
    print(*out, sep='\n')
for _ in [0] * e:
    s, t = map(int, stdin.readline().split())
    G[s].append(t)
tsort()

Measured memory_bytes: 11388
def main(s,t):
    n = len(s)
    for i in range(n):
        if t[i]!=s[i]:
            rep =s[i]
            s=s.replace(rep,"A")
            s=s.replace(t[i],rep)
            s=s.replace("A",t[i])
            if t[:i] !=s [:i]:
                return "No"
    if s == t:
        return "Yes"
    else:
        return "No"
s=input()
t=input()
print(main(s,t))


Measured memory_bytes: 4016
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char s[1000005];
int n;
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=1;i<=n;++i) putchar('x');
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    cout<<N * (N + 1) / 2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,ans = 0,sum=0,tmp;
  cin >> a;
  int up[a],down[a];
  rep(i,a){
    cin >> up[i];
    sum += up[i];
  }
  rep(i,a){
    cin >> down[i];
    sum += down[i];  
  }
  for(int i = 1;i<a;i++){
      ans += up[i];
  }
   tmp = ans;
  for(int i = 1;i<a;i++){
      ans = ans-up[i]+down[i-1];
      tmp = min(ans,tmp);
  }
  cout << sum - tmp << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVVld = vector<VVld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

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

int main() {
  int N; cin >> N;
  V cnt(3);
  rep(i, N) {
    int x; cin >> x;
    cnt[x-1]++;
  }
  
  VVVld dp(N+1, VVld(N+1, Vld(N+1)));

  rep(i3, N+1) rep(i2, N+1) rep(i1, N+1) {
    int sum = i1 + i2 + i3;
    if (sum == 0 || sum > N) continue;
    dp[i1][i2][i3] = ld(N)/sum;
    if (i1 > 0) dp[i1][i2][i3] += ld(i1)/sum * dp[i1-1][i2][i3];
    if (i2 > 0) dp[i1][i2][i3] += ld(i2)/sum * dp[i1+1][i2-1][i3];
    if (i3 > 0) dp[i1][i2][i3] += ld(i3)/sum * dp[i1][i2+1][i3-1];
  }

  ld ans = dp[cnt[0]][cnt[1]][cnt[2]];
  cout << setprecision(12);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 431360
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();

        if(u.equals(s)) {
            System.out.println((a-1) + " " + b);
        } else {
            System.out.println(a + " " + (b-1));
        }

    }


}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll N;

void dfs(ll x, string d){
    if(d.size()==N) {cout<<d<<endl; return;}
    rep(i,x) {
        string p=d;
        p.pb('a'+i);
        dfs(x,p);
    }
    d.pb('a'+x);
    dfs(x+1,d);
    return;

}

int main(){
    cin>>N;
    dfs(1,"a");
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin>>s;
  if(s.at(5)!='0') cout<<"TBD"<<endl;
  else if(s.at(6)!='1'&&s.at(6)!='2'&&s.at(6)!='3'&&s.at(6)!='4') cout<<"TBD"<<endl;
  else cout<<"Heisei"<<endl;
}

Measured memory_bytes: 3580
void main() {
    int[] tmp = readln.split.to!(int[]);
    int h = tmp[0], w = tmp[1];
    string[] a = new string[h];
    foreach (i; 0 .. h) {
        a[i] = readln.chomp;
    }
    string row = '#'.repeat(w+2).to!string;
    row.writeln;
    foreach (x; a) {
        writeln('#', x, '#');
    }
    row.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n,k=input2()
p=input_array()
sp=sorted(p)

print(sum(sp[:k]))

Measured memory_bytes: 9208
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)
//string s = to_string(i);;;;;;;;;;;;;;;;;

int a = 0, b = 0, x = 0, y = 0, z = 0, n = 0;
string s = ""; asas; cncn;

int main(void) {
	cin >> n;
	if (n < 3)cout << 0 << rt;
	else cout << n / 3 << rt;
	please AC;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int juice[] =new int[a];
		int ans =0;
		
		for(int i =0;i<a;i++) {
			juice[i] = sc.nextInt();
		}
		
		Arrays.sort(juice);
		
		
		for(int i =0;i<b;i++) {
			ans =ans+juice[i];
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 38596
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

const long long MOD = 998244353;
// const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n,k;
  std::cin>>n>>k;

  std::string s;
  std::cin>>s;

  ll num=s[k-1]-'A';
  s[k-1]='a'+num;

  std::cout<<s<<"\n";

  return 0;
}


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

const int N = 55;
int l[N];
int n, k;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> l[i];
    }
    sort(l + 1, l + 1 + n);
    reverse(l + 1, l + 1 + n);
    int ans = 0;
    for(int i = 1; i <= k; i++) {
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, k, q = [int(i) for i in input().split()]
a = [int(input()) for _ in range(q)]

point = [k-q]*n

ans_point = [0]*n
for cur_a in a:
    ans_point[cur_a - 1] += 1

point = [point[i] + ans_point[i] for i in range(n)]

for cur_point in point:
    if cur_point > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 12588
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
di = Counter(A)
S = sum(A)
for q in range(int(input())):
    b, c = map(int, input().split())
    di[c] += di[b]
    S += (c-b) * di[b]
    di[b] = 0
    print(S)

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

typedef long long ll;
typedef long double ld;

using namespace std;
ll p = 998244353;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(100);
    string s;
    int n;
    cin >> n >> s;
    ll ans = 0;
    ll lastsize = 2 * n;
    for (int i = 0; i < n; i++) {
        ans *= 2;
        ans += s[i] - '0';
        ans %= p;
    }
    ans++;
    vector<pair<int, ll>> a;
    a.emplace_back(2 * n, ans);
    ans *= (2LL) * n;
    ans %= p;
    int x = 2 * n - 1;
    while (x > 0) {
        if (2 * n % x == 0 && n % x != 0) {
            string g0, g1;
            ll locans = 0;
            for (int i = 0; i < x / 2; i++) {
                locans *= 2;
                locans += s[i] - '0';
                locans %= p;
                g0 += s[i];
                g1 += '1' - (s[i] - '0');
            }
            string g = g0;
            for (int i = 0; i < n / x; i++) {
                g += g1;
                g += g0;
            }
            if (g <= s) {
                locans++;
            }
            int h = 0;
            for (int i = a.size() - 1; i >= 0; i--) {
                if (a[i].first % x == 0) {
                    h = a[i].first;
                    break;
                }
            }

            a.emplace_back(x, locans);
        }
        x--;
    }
    int nn = a.size();
    for (int i = nn - 1; i >= 0; i--) {
        for (int j = 0; j < i; j++) {
            if (a[j].first % a[i].first == 0) {
                a[j].second -= a[i].second;
                a[j].first %= p;
            }
        }
    }
    ans = 0;
    for (int i = 0; i < nn; i++) {
        ans += a[i].first * a[i].second;
    }

    ((ans %= p) += p) %= p;
    cout << ans;
    return 0;
}

Measured memory_bytes: 1088
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

long N,i,x,ans;
string S;
inline void solve(){
  IN2(N,S);
  REP(i,N){
    x+=(S[i]=='I'?1:-1);
    chmax(ans,x);
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a == b:
  print('YES')
else:
  if v <= w:
  	print('NO')
  else:
    if abs(a-b) / (v - w) <= t:
      print('YES')
    else:
      print('NO')

Measured memory_bytes: 9180
import java.util.Scanner;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int x =nextInt();
        if(x>=30){
            print("Yes");
        }
        else print("No");
    }


    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }

    //print
    public static void print(Object a){
        System.out.println(a);
    }


    //gcd
    public static int gcd (int a, int b){
        int tmp;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return b;
    }


    //lcm
    public static int lcm(int a,int b){
        int tmp;
        long c = a;
        c *= b;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return (int)(c/b);
    }
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int N, Q;
const int MAX = 200005;
int P[MAX]; // P[i] = j => iの親j
int C[MAX];
Graph G(MAX);

void dfs(int i) {
    for (auto j : G[i]) {
        if (P[j] == -1) {
            P[j] = i;
            C[j] += C[i];
            dfs(j);
        }
    }
}

int main() {
    cin >> N >> Q;

    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i = 0; i < N; ++i) C[i] = 0;

    for (int i = 0; i < Q; ++i) {
        int p;
        ll x;
        cin >> p >> x;
        --p;
        C[p] += x;
    }

    memset(P, -1, sizeof(P));
    P[0] = 0;
    dfs(0);

    for (int i = 0; i < N; ++i) {
        if (i) cout << ' ';
        cout << C[i];
    }
    cout << endl;
}

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

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

    if ((S / 3600) >= 1) {
        h = (int)(S /3600);
    } else {
        h = 0;
    }

    if ((S -  (3600 * h)) / 60 >= 1) {
       m = (int)((S -  (3600 * h)) / 60); 
    } else {
        m = 0;
    }

    s = S -  3600 * h -  60 * m;

    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] xi = new int[N];
      int[] yi = new int[N];
   for(int i=0;i<N;i++ )
   {
     xi[i] = sc.nextInt(); 
     yi[i] = sc.nextInt(); 
   }
   int[] Ni = new int[N];
   for(int i=0;i<N;i++ )
   {
     Ni[i] = i+1;
   }
   double sum = 0;
   for(int i = 0 ; i < N ;i++)
   {
     for(int k = i+1;k < N ;k++)
     {
       sum += Math.sqrt((xi[i] - xi[k]) * (xi[i] - xi[k]) + (yi[i] - yi[k]) * (yi[i] - yi[k])); 
     }
   }
   System.out.println(2*sum/N);
 }
}

Measured memory_bytes: 21716
import sys

n, m = map(int, input().split())

matrix = [[0 for x in range(m + 1)] for y in range(n + 1)]

for i in range(n):
	arr = list(map(int, input().split()))
	for j in range(m):
		matrix[i][j] = arr[j]
		
for i in range(n):
	sum = 0
	for j in range(m):
		sum += matrix[i][j]
	matrix[i][m] = sum

for i in range(m + 1):
	sum = 0
	for j in range(n):
		sum += matrix[j][i]
	matrix[n][i] = sum
	
for i in range(n + 1):
	for j in range(m + 1):
		sys.stdout.write(str(matrix[i][j]))
		if j != m:
			sys.stdout.write(' ')
	print()



Measured memory_bytes: 6188
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NIL NULL

struct node{
  int key;
  struct node *p,*l,*r;
};

typedef struct node * Node;

Node root;

void pre(Node u){
  if (u == NIL) return;
  printf(" %d",u->key);
  pre(u->l);
  pre(u->r);
}

void in(Node u){
  if (u == NIL) return;
  in(u->l);
  printf(" %d",u->key);
  in(u->r);
}

void insert(int c){
  Node z,y,x;

  z = (struct node *)malloc(sizeof(struct node));
  z->key = c;
  z->l = NIL;
  z->r = NIL;

  y = NIL;
  x = root;
  while(x  != NIL){
    y = x;
    if (z->key < x->key) x = x->l;
    else x = x->r;
  }
  z->p = y;

  if (y == NIL) root = z;
  else if (z->key < y->key) y->l = z;
  else y->r = z;
}

Node find(Node x,int f){
  while(x != NIL && f != x->key){
    if (f < x->key) x = x->l;
    else x = x->r;
  }
  return x;
}

Node minimum(Node x){
  while(x->l != NIL) x = x->l;
  return x;
}

Node successor(Node x){
  if(x->r != NIL) return minimum(x->r);

  Node y = x->p;
  while (y != NIL && x == y->r){
    x = y;
    y = y->p;
  }
  return x;
}

void delete(Node x){
  Node y,z;

  if(x->l == NIL || x->r == NIL) y = x;
  else y = successor(x);

  if(y->l != NIL) z = y->l;
  else z = y->r;

  if(z != NIL) z->p = y->p;

  if(y->p == NIL) root = z;
  else if(y == y->p->l) y->p->l = z;
  else y->p->r = z;

  if(y != x) x->key = y->key;
}

int main(){
  int n,c,f,d;
  char word[7];
  int i;
  Node t;

  scanf("%d",&n);

  for (i=0; i<n; i++){
    scanf("%s",word);
    if (strcmp(word,"insert") == 0){
      scanf("%d",&c);
      insert(c);
    }
    else if (strcmp(word,"print") == 0){
      in(root);
      printf("\n");
      pre(root);
      printf("\n");
    }
    else if (strcmp(word,"find") == 0){
      scanf("%d",&f);
      t = find(root,f);
      if (t == NIL) printf("no\n");
      else if (t->key == f) printf("yes\n");
    }
    else if (strcmp(word,"delete") == 0){
      scanf("%d",&d);
      delete(find(root,d));
    }
  }

  return 0;
}


Measured memory_bytes: 20440
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// -----------------------------------------------------------------------------
// main
// -----------------------------------------------------------------------------
fn main(){
    input!{
        n: usize,
        m: usize,
        q: usize,
        lr: [[usize; 2]; m],
        pq: [[usize; 2]; q]
    }
    let mut a = vec![vec![0;n+1];n+1];
    for lr in lr{
        let (l,r) = (lr[0],lr[1]);
        a[l-1][r-1] += 1;
    }
    for l in 0..n{
        for r in 0..n{
            a[n-l-1][r] += a[n-l][r];
        }
    }
    for r in 0..n{
        for l in 0..n{
            a[l][r+1] += a[l][r];
        }
    }
    for pq in pq{
        let (p,q) = (pq[0]-1,pq[1]-1);
        println!("{}", a[p][q]);
    }
}


Measured memory_bytes: 18684
N, K = map(int, input().split())

ans = 0
for i in reversed(range(1, N+1)):
    n = 1
    # i番目のサイコロの目（=i）がKを超えるには何回コインで面を出す必要があるか
    while i < K:
        # 2倍にしている
        n = n*2
        i = i*2
    # Kを超える確率（=超えるために必要なコインが連続で表になる確率をansに加算する）
    ans += 1/n

# ansには各目が出る確率の合計が格納されているので値をN（サイコロの目の数）で割る
print(ans/N)


Measured memory_bytes: 2940
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  read<T>(parser: (v: string) => T): () => T {
    return () => {
      const ret = parser(this.input[this.pointer]);
      this.pointer++;
      return ret;
    };
  }
  int = this.read(str => parseInt(str, 10));
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  bint = (): bigint => {
    const ret = BigInt(this.input[this.pointer]);
    this.pointer++;
    return ret;
  };
  bints = (length: number): bigint[] => {
    let ret: bigint[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.bint());
    }
    return ret;
  };
}
function rep(a: number, b: number) {
  let arr = [];
  for (let i = a; i < b; i++) arr.push(i);
  return arr;
}

function Main({ int, str, strs, ints, bint, bints }: NormalInput) {
  const k = bint();
  const [a, b] = bints(2);
  for (let i = a; i <= b; ++i) {
    if (i % k === 0n) {
      console.log(`${"OK"}`);
      return 0;
    }
  }
  console.log(`${"NG"}`);
}
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29608
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

const inf = 1000000

func makeBit(n, N int) []bool {
	f := make([]bool, N)
	idx := 0
	for n > 0 {
		if n%2 == 1 {
			f[idx] = true
		}
		idx++
		n /= 2
	}
	return f
}

func main() {
	sc.Split(bufio.ScanWords)
	D, G := getInt(), getInt()/100
	p := make([]int, D)
	c := make([]int, D)
	s := make([]int, D)
	for i := 0; i < D; i++ {
		p[i] = getInt()
		c[i] = getInt() / 100
		s[i] = p[i]*(i+1) + c[i]
	}

	N := 1 << uint(D)
	ans := inf
	for i := 0; i < N; i++ {
		f := makeBit(i, D)
		// out("loop", i, f)
		g := G
		cnt := 0
		for j, v := range f {
			if v == true {
				g -= s[j]
				cnt += p[j]
			}
		}
		if g > 0 {
			// out("pass----")
			for j := D - 1; j >= 0; j-- {
				if f[j] == false {
					rest := (g + j) / (j + 1)
					rest = min(rest, p[j])
					g -= rest * (j + 1)
					cnt += rest
					// out(j+1, rest, g)
				}
				if g < 0 {
					break
				}
			}
		}
		ans = min(ans, cnt)
		// out("cnt=", cnt, "g = ", g)
	}

	out(ans)
}


Measured memory_bytes: 640
def main():
    N, X = map(int, input().split())
    L = list(map(int, input().split()))
    D = 0
    i = 0
    while True:
        D += L[i]
        i += 1
        if D > X:
            print(i)
            return
        if i == N:
            print(i+1)
            return

if __name__ == '__main__':
    main()

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

int main(void){
    int N, ans=0;
    std::string S;
    std::cin >> S;
    N = S.size();

    if (N == 1){
        ans = stoi(S);
    } else if (S.at(0) != '9'){
        bool flg = true;
        for (int i=1; i<N; ++i){
            if (S.at(i) != '9'){
                flg = false;
                break;
            }
        }
        if (flg) ++ans;
        ans += (int)S.at(0) - '1';
        ans += 9 * (N - 1);
    } else {
        for (int i=0; i<N; ++i){
            if (S.at(i) == '9'){
                ans += 9;
            } else {
                ans += 9 * (N - i) - 1;
                break;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3612
#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 push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int sum=0;
    FOR(i,1,n+1){
        int cnt=0;
        int m=i;
        while(m){
            cnt+=m%10;
            m/=10;
        }
        if(cnt>=a&&cnt<=b) sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/08/20 03:55:25
// -----------------------------------

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;

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

  int n,k; cin>>n>>k;
  atcoder::mcf_graph<int, ll> mcf(n+n+2);
  int qs = n+n, qg = n+n+1;
  constexpr int INF = 1e9;
  mcf.add_edge(qs, qg, n*k, INF);
  for (int i = 0; i < n; i++) {
    mcf.add_edge(qs, i, k, 0);
    mcf.add_edge(n+i, qg, k, 0);
  }
  for (int i = 0; i < n*n; i++) {
    int a; cin>>a;
    mcf.add_edge(i/n, n + i%n, 1, INF-a);
  }
  auto [flow, cost] = mcf.flow(qs, qg, n*k);
  cout << ((ll)INF * n*k) - cost << endl;
  vector<string> ans(n, string(n, '.'));
  for (auto [s, t, c, f, w] : mcf.edges()) {
    if (f == 0 or s == qs or t == qg) continue;
    ans[s][t-n] = 'X';
  }
  for (auto& l : ans)
    cout << l << endl;

  return 0;
}


Measured memory_bytes: 3936
# coding: utf-8
import re
from datetime import datetime as dt
if __name__ == '__main__':
    n = input()
    sum = 0.0
    for i in range(n):
        x, u = raw_input().split()
        if u == 'JPY':
            sum += int(x)
        else:
            sum += float(x) * 380000
    print sum


Measured memory_bytes: 2692
import os
import math
import itertools
INF, MOD = float("inf"), 1e9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]

def get_int():
    return int(input())

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

while(True):
    try:
        n = get_int()
        s, t = [input() for _ in range(2)]
        for i in range(n + 1):
            if s[i:] == t[:n - i]:
                print(n + i)
                exit()
    except EOFError:
        exit()


Measured memory_bytes: 3064