akhauriyash/Code-Regression huggingface dataset:
def eval(d,mask):
    s = ''
    for i in xrange(len(mask)):
        s += d[i]
        if mask[i] == '1':
            s += '+'
    s += d[-1]
    l = s.split('+')
    res = sum(map(int,l))
    return res

d = list(raw_input())
tot = 0
for i in xrange(2**(len(d)-1)):
    mask = bin(2**(len(d)-1)+i)[3:]
    tot += eval(d,mask)
print tot

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

int main() {
  vector<int> h(10000), w(10000);
  int idx = 0;
  while(true) {
    cin >> h.at(idx) >> w.at(idx);
    if (h.at(idx) == 0 && w.at(idx) == 0) break;
    idx++;
  }
  idx = 0;
  while(!(h.at(idx) == 0 && w.at(idx) == 0)) {
    for(int i = 0; i < h.at(idx); i++) {
      for(int j = 0; j < w.at(idx); j++) {
        cout << '#';
      }
      cout << endl;
    }
    idx++;
    cout << endl;
  }
}


Measured memory_bytes: 3156
#include <iostream>
#include <cmath>
using namespace std;
bool sqr(int n)
{
    return pow(round(sqrt(n)),2) == n;
}
int main()
{
    int n;
    cin >> n;
    for(int i = n;;i--)
    {
        if(sqr(i))
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

const int N = 1e5+5;

int n, tmp;
map<int, int> dat;

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin>>n;
  for(int i=0; i< n; i++){
    cin>>tmp;
    dat[tmp]++;
  }
  int ec = 0;
  for(auto it : dat){
    //cout<<it.first<<" "<<it.second<<"\n";
    if(it.second%2 ==0)
      ec++;
  }
  //cout<<ec<<"\n";
  int ans =dat.size();
  if(ec%2==1)
    ans--;
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m; cin>>n>>m;
	int lo=0,hi=n+1;
	int l,r;
	while(m--)
	{
		cin>>l>>r;
		lo=max(lo,l);
		hi=min(hi,r);
	}
	cout<<max(hi-lo+1,0ll)<<"\n";
	return 0;
}















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);	
	int n, k;
	cin >> n >> k;
	priority_queue<int> pq;
	for(int i=0; i<n; ++i){
		int x; cin >> x;
		pq.push(x);
	}
	while(k and not pq.empty()){
		pq.pop(), --k;
	}
	ll ans = 0;
	while(not pq.empty()) ans += pq.top(), pq.pop();
	cout << ans << endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
    if(x<0){putchar('-'),write(-x);}
    else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=105;
int f[N][5][2],n,k;
char s[N];

int dp(int x,int k,bool op){
	if(x==n+1) return k==0;
	int &now=f[x][k][op];
	if(now!=-1) return now;
	now=0;
	if(s[x]=='0') now+=dp(x+1,k,op);
	else now+=dp(x+1,k,1);
	if(!k||(s[x]=='0'&&!op)) return now;
	if(op) now+=9*dp(x+1,k-1,1);
	else now+=(s[x]-'0'-1)*dp(x+1,k-1,1)+dp(x+1,k-1,0);
	return now;
}

signed main(){
	scanf("%s",s+1);read(k);n=strlen(s+1);
	memset(f,-1,sizeof f);
	write(dp(1,k,0));
}

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

template <typename T>
void print(const T &v);

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    vector<bool> seen(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    int cnt = 0;
    int now = 0;
    for (int i = 0; i < N; i++)
    {
        cnt++;
        now = a[now];
        if (now == 1)
        {
            cout << cnt << endl;
            return 0;
        }
        if (seen[now] == true)
        {
            cout << -1 << endl;
            return 0;
        }
        seen[now] = true;
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	double x;
	cin >> x;
	if (x == 0)	cout << "1";
	else if (x == 1)	cout << "0";
	return 0;
}

Measured memory_bytes: 3796
N=int(input())
A=[0]
A=list(map(int,input().split()))

A.sort(reverse=True)
wa=A[0]
i=0
amari=len(A)%2

while(1):

    if(amari==0):

        if(len(A)-1==1+2*i):
            print(wa)
            break
        wa=A[i+1]*2+wa


    elif(amari==1):
        if(len(A)-2==1+2*i):
            print(A[i+1]+wa)
            break
        wa=A[i+1]*2+wa

    i=i+1


Measured memory_bytes: 105108
def main():
	N, M = [int(x) for x in input().split(" ")]
	route = [[] for i in range(N)]
	for i in range(M):
		A, B = [int(y) for y in input().split(" ")]
		route[A - 1] += [B]
		route[B - 1] += [A]

	checked = [1] + [0] * (N - 1)
	to_check = [{"src" : s, "dst" : 1} for s in route[0]]
	signal = [-1] + [0] * (N - 1)

	for r in route[0]:
		checked[r - 1] = 1

	while len(to_check) > 0:
		checking = to_check.pop(0)
		src = checking["src"]
		signal[src - 1] = str(checking["dst"])
		rooms = route[src - 1]
		for r in rooms:
			if checked[r - 1] == 0:
				to_check.append({"src": r, "dst": src})
				checked[r - 1] = 1

	if signal.count(0) > 0:
		print("No")
	else:
		print("Yes")
		print("\n".join(signal[1:]))

main()

Measured memory_bytes: 56932
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
            c[i] = in.nextInt();
        }
        int[][] dp = new int[n][3];
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i - 1][1], dp[i - 1][2]) + a[i];
            dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][2]) + b[i];
            dp[i][2] = Math.max(dp[i - 1][0], dp[i - 1][1]) + c[i];
        }
        int ans = dp[n - 1][0];
        ans = Math.max(ans, Math.max(dp[n - 1][1], dp[n - 1][2]));
        out.println(ans);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


Measured memory_bytes: 47548
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
ans=0

for i in range(0,n):
  if t[i]=="r":
    ans+=p
  elif t[i]=="s":
    ans+=r
  elif t[i]=="p":
    ans+=s

for i in range(0,n-k):
  if t[i]==t[i+k]:
    t[i+k]="M"
    if t[i]=="r":
      ans-=p
    elif t[i]=="s":
      ans-=r
    elif t[i]=="p":
      ans-=s   
print(ans)

Measured memory_bytes: 4084
#include <stdio.h>
#include <stdlib.h>
#define MAX_NODES 500000
#define INF 1010001000

typedef struct edge {
    int to, cost;
    struct edge *next;
}edge;

typedef struct vertex {
    int value, edges;
    struct edge *head;
}vertex;

typedef struct pair {
    int f, s;
}pair;

vertex graph[MAX_NODES];
pair queue[MAX_NODES];
int sz, V, E, start;

pair pop(void);
void push(pair x);
void add_edge(int from, int to, int cost);
void dijkstra(int st);


int main(void)
{
    int i, s, t, d;
    pair a;
    scanf("%d %d %d", &V, &E, &start);
    for (i = 0; i < E; i++) {
        scanf("%d %d %d", &s, &t, &d);
        add_edge(s, t, d);
        queue[i].f = INF;
    }
    for (i = 0; i < V; i++) {
        graph[i].value = INF;
    }
    dijkstra(start);
    for (i = 0; i < V; i++) {
        if (graph[i].value == INF) {
            puts("INF");
        } else {
            printf("%d\n", graph[i].value);
        }
    }
    return 0;
}


void dijkstra(int st)
{
    int i, j, v;
    pair tmp;
    edge *now;
    //Queueの初期化
    for (i = 0; i < 100; i++) {
        queue[i].f = INF;
    }
    graph[st].value = 0;

    tmp.f = 0; tmp.s = st;
    push(tmp);

    while (queue[0].f != INF) {
        if (sz==0) {
            break;
        }
        tmp = pop();
        //printf("poped:%d %d\n", tmp.f, tmp.s);
        v = tmp.s;      //現在見ているノードの番号
        now = graph[v].head;
        if (graph[v].value < tmp.f) { 
            continue;
        }
        while (now != NULL) {
            if (graph[now->to].value > graph[v].value + now->cost) {
                graph[now->to].value = graph[v].value + now->cost;
                tmp.f = graph[now->to].value; tmp.s = now->to;
                push(tmp);
            }
            now = now->next;
        }
    }
}

void add_edge(int from, int to, int cost)
{
    //fromからtoへ辺を張る
    edge *new, *now = graph[from].head;
    new = (edge *)malloc(sizeof(edge));
    new->to = to;
    new->cost = cost;
    new->next = NULL;
    if (now == NULL) {
        graph[from].head = new;
    } else {
        while (now->next != NULL) {
            now = now->next;
        }
        now->next = new;
    }
    graph[from].edges++;
}

void push(pair x)
{
    int i = sz++, p;
    //queue[sz++] = x;
    while (i > 0) {
        p = (i - 1) / 2;
        if (queue[p].f <= x.f) {
            break;
        }
        queue[i].f = queue[p].f;
        queue[i].s = queue[p].s;
        i = p;
    }
    queue[i] = x;
}

pair pop(void)
{
    int i = 0, a, b;
    pair ans = queue[0], x = queue[--sz];
    //printf("sz:%d\n", sz);
    while (i * 2 + 1 < sz) {
        a = i * 2 + 1;
        b = i * 2 + 2;
        if (b < sz && queue[b].f < queue[a].f) { 
            a = b;
        }
        if (queue[a].f >= x.f) {
            break;
        }
        queue[i] = queue[a];
        i = a;
    }
    queue[i] = x;
    //queue[sz].f = INF;
    return ans;
}

Measured memory_bytes: 22060
import math
A, B, H, M = list(map(int, input().split()))

hun = H*60 + M
zisin = hun * 0.5
hunsin = hun * 6
kakusa = (hunsin - zisin) % 360

if kakusa >= 180:
    kakusa = 360 - kakusa

ans = math.sqrt(A*A + B*B - 2*A*B*math.cos(math.radians(kakusa)))

print(ans)


Measured memory_bytes: 9568
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m, a[maxn], sum;
signed main() {
	n = read(), m = read();
	rep(i, 1, m) a[i] = read(), sum += a[i];
	if(sum >= n) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1024
# B - Trained?
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    cnt = 0
    x = 1

    if 2 in a:
        for _ in range(n-1):
            x = a[x-1]
            cnt += 1

            if x == 2:
                print(cnt)
                exit()
        else:
            print(-1)
    else:
        print(-1)
        

if __name__ ==  "__main__":
    main()

Measured memory_bytes: 12944
a = input()
b = ""
i = len(a)
code = "No"
if a == a[::-1]:
  i = int((len(a)-1)/2)
  b = a[0:i]
  if b == b[::-1]:
    i = int((len(a)+3)/2)
    b = a[i-1:]
    if b == b[::-1]:
      code = 'Yes'
print(code)

Measured memory_bytes: 3064
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n , k = map(int, input().split())
    a = list(map(int, input().split()))
    
    def check(m):
        cnt = 0
        for x in a:
            cnt += (x-1)//m
        return cnt <= k
        
    l, r = 0, max(a)
    while r-l > 1:
        m = (r+l)//2
        if check(m): r = m
        else: l = m
    print(r)

    


if __name__ == '__main__':
    main()

Measured memory_bytes: 30832
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_2-C: Stable Sort

#include <cstring>
#include <algorithm>
#include <iostream>

struct Card {
  char suit;
  unsigned int rank;
  bool operator<(const Card& rhs) { return rank < rhs.rank; }
  bool same(const Card& rhs) { return rank == rhs.rank && suit == rhs.suit; }
};

std::ostream& operator<<(std::ostream& os, const Card& card)
{
  return os << card.suit << card.rank;
}

std::istream& operator>>(std::istream& is, Card& card)
{
  return is >> card.suit >> card.rank;
}

static void print_cards(const Card cards[], const unsigned int n)
{
  const char* sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::cout << sep << cards[i];
    sep = " ";
  }
  std::cout << std::endl;
}

static void copy_cards(Card dst[], const Card src[], const unsigned int n)
{
  std::memcpy(dst, src, sizeof(dst[0])*n);
}

static bool is_equal_cards(const Card cards1[], const Card cards2[], const unsigned int n)
{
  //std::memcmp(cards1, cards2, sizeof(cards1)) == 0
  for (auto i = 0u; i < n; ++i) {
    if (!(cards1[i].rank == cards2[i].rank &&
          cards1[i].suit == cards2[i].suit)) {
      return false;
    }
  }
  return true;
}

static void bubble_sort(Card cards[], const unsigned int n)
{
  for (auto j = 0u; j < n-1; ++j) {
    for (auto i = n-1; i > j; --i) {
      if (cards[i] < cards[i-1]) {
        std::swap(cards[i], cards[i-1]);
      }
    }
  }
}

static void selection_sort(Card cards[], const unsigned int n)
{
  for (auto i = 0u; i < n-1; ++i) {
    auto min_j = i;
    for (auto j = i+1; j < n; ++j) {
      if (cards[j] < cards[min_j]) {
        min_j = j;
      }
    }
    if (i != min_j) {
      std::swap(cards[i], cards[min_j]);
    }
  }
}

int main()
{
  unsigned int n;
  std::cin >> n;
  Card cards1[n], cards2[n];
  for (auto i = 0u; i < n; ++i) {
    std::cin >> cards1[i];
  }
  copy_cards(cards2, cards1, n);
  bubble_sort(cards1, n);
  print_cards(cards1, n);
  std::cout << "Stable" << std::endl; // bubble sort is stable

  selection_sort(cards2, n);
  print_cards(cards2, n);

  if (is_equal_cards(cards1, cards2, n)) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
}

// eof

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

class C
{
	static void Main()
	{
		var n = Console.ReadLine();

		var r = 0;
		var s = new[] { "" };
		for (int i = 1; i <= n.Length; i++)
		{
			s = "753".SelectMany(c => s.Select(x => c + x)).ToArray();
			r += s.Count(x => (i < n.Length || x.CompareTo(n) <= 0) && "753".All(x.Contains));
		}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 19804
num_500 = int(input())
num_100 = int(input())
num_50 = int(input())
X = int(input())
count = 0
for i in range(0, num_500 + 1):
  for n in range(0, num_100 + 1):
    for m in range(0, num_50 + 1):
      if (i*500 + n*100 + m*50) == X:
        count += 1
print(count)

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;  
  if(C - ( A - B ) > 0){
  cout << C - ( A - B ) << endl;
  } 
  else {
  cout << 0 << endl;
  }
}


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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()

ans = pow(10, n, mod)
ans -= pow(9, n, mod)
ans -= pow(9, n, mod)
ans += pow(8, n, mod)
ans %= mod
print(ans)

Measured memory_bytes: 65436
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
void fff()
{
	ll k;
	cin >> k;
	ll cur = 7, co = 1;
	set<int>SET;
	while(SET.find(cur) == SET.end())
	{
		if(cur%k == 0)
		{
			cout << co << ln;
			return;
		}
		SET.insert(cur);
		cur *= 10;
		cur %= k;
		cur += 7;
		cur %= k;
		co++;
		// debug(co);
	}	
	cout << -1 << ln;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 50492
def yakusu(n):
    m = 1
    re = []
    while m ** 2 < n:
        a, md = divmod(n, m)
        if md == 0:
            re.append(m)
            re.append(a)
        m += 1
    if m ** 2 == n:
        re.append(m)
    return re

n, k = map(int, input().split())
aa = list(map(int, input().split()))
yk = yakusu(sum(aa))
yk.sort(reverse=True)
for y in yk:
    rs = [a % y for a in aa if a % y]
    if not rs:
        print(y)
        exit()
    if len(rs)==1:continue
    rs.sort()
    l = 0
    sl = rs[0]
    r = len(rs) - 1
    sr = y - rs[r]
    while 1:
        if l + 1 == r:
            if sl == sr and sl <= k:
                print(y)
                exit()
            else:
                break
        if sl > sr:
            r -= 1
            sr += y - rs[r]
            if sr > k: break
        else:
            l += 1
            sl += rs[l]
            if sl > k: break
print(1)


Measured memory_bytes: 3188
def solve(a, b):
    f = lambda x, i: int(str(x)[i])
    fl1, fr1 = (f(a, 0), f(b, 0))
    fl2, fr2 = (f(a, 1), f(b, 1)) if fl1 == fr1 else (0, 9)
    fl3, fr3 = (f(a, 2), f(b, 2)) if fl2 == fr2 else (0, 9)
    return sum(
        a <= int('{0}{1}{2}{1}{0}'.format(i, j, k)) <= b
        for i in range(fl1, fr1 + 1)
        for j in range(fl2, fr2 + 1)
        for k in range(fl3, fr3 + 1)
    )

_a, _b = map(int, input().split())
print(solve(_a, _b))

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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

int main() {
  int N; cin >>N;
  vll A(N);
  vll B(N+1);
  rep(i,0,N) {
    cin >>A[i];
    B[i+1]=B[i]+A[i];
  }
  map<ll,ll> m;
  rep(i,0,N+1) {
    m[B[i]]++;
  }
  ll ans=0;
  for (auto p : m) {
    ll v=p.second;
    ans+=v*(v-1)/2;
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 18768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define PB push_back
#define be(v) v.begin(), v.end()
#define MOD 1000000007
#define endl "\n"
void solve(){
	ll n; cin>>n;
	ll total = 0;
	std::vector<ll> v(n,0);
	std::vector<ll> pre(n,0);
	for(ll i = 0; i<n; i++){
		cin>>v[i];
		total+=v[i];
		pre[i] = total;
	}
	ll sum = 0;
	for(ll i = 0; i<n; i++){
		sum += ((v[i]%MOD)*((total-pre[i])%MOD))%MOD;
		sum%=MOD;
	}
	cout<<(sum%MOD)<<endl;
}
int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	// cin>>t;
	while(t-->0){
		solve();
	}
	return 0;
}


Measured memory_bytes: 6364
#define lld long long int
#include<bits/stdc++.h>
using namespace std;
lld n,k;
lld a[200001];

lld fin(lld num,lld length)
{
    lld start=1,end=1000000000,ans;
    while(start<=end)
    {
        double mid=start+(end-start)/2;
        if(ceil(num/mid)<=length)
        {
            ans=mid-1;
            end=mid-1;
        }
        else
        {
            start=mid+1;
        }
    }
    return ans;
}


bool isPossible(lld length)
{
    lld times=0;
    for(lld i=0;i<n;i++)
    {
        if(a[i]<length)
        {
            continue;
        }
        else
        {
            
            times=times+fin(a[i],length);
                //cout<<"in = "<<times<<endl;
                if(times>k)
                {
                    return false;
                }
        }
        //cout<<"i = "<<i<<" times = "<<times<<endl;
    }
    return true;
}


int main()
{
    cin>>n>>k;
    lld m=0;
    for(lld i=0;i<n;i++)
    {
        cin>>a[i];
        m=max(m,a[i]);
    }
    lld start=1,end=m,ans;
    while(start<=end)
    {
        lld mid=start+(end-start)/2;
        //cout<<"mid = "<<mid<<endl;
        if(isPossible(mid))
        {
            //cout<<"ans = "<<mid<<endl;
            ans=mid;
            end=mid-1;
        }
        else
        {
            start=mid+1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5180
#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>;
using Graph = vector<vector<int>>;

int main() {
  ll N,K;
  cin >> N >> K;
  cout << min(N, min(N%K, K-N%K)) << endl;
  return 0;
}


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

mod = int(1e9+7)

##O(K)
upper = 0
for i in reversed(range(N+1-K,N+1)):
    upper += i
upper_point = N-K
##O(K)
lower = 0
for i in range(K):
    lower += i
lower_point = K
ans = 0

for i in range(K,N+2):
    ##print("N:",i,upper-lower+1)
    
    ans += upper - lower + 1
    upper += upper_point
    lower += lower_point

    upper_point -= 1
    lower_point += 1

print(ans%mod)


Measured memory_bytes: 67544
def main():
    n, k = map(int, input().split())
    if k % 2 != 0:
        print((n // k) ** 3)
    else:
        q = n // k
        print(q ** 3 + (n // (k // 2) - q) ** 3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define PI 3.14159265358979323846264338327950L
using namespace std;

typedef long long ll;
typedef long double ld;

long long myGcd(long long a, long long b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

int myGcd(int a, int b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

long long myLcm(long long a, long long b)
{
	return a * b / myGcd(a, b);
}

int myLcm(int a, int b)
{
	return a * b / myGcd(a, b);
}


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

	int H1, M1, H2, M2, K;

	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int offset = H1 * 60 + M1;
	int total = H2 * 60 + M2 - offset;

	cout << total - K << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ld> numbers(n);
    for (int i = 0; i < n; i++) cin >> numbers[i];
    vector<ld> tnumbers(n);
    transform(numbers.begin(), numbers.end(), tnumbers.begin(), [](ld x) -> ld { if (x == 0) return 0; else return (1/x); });
    ld ans = accumulate(tnumbers.begin(), tnumbers.end(), 0.0);
    if (ans == 0) {
        cout << 0 << endl;
    } else {
        cout << 1/ans << endl;
    }


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int lose = 0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='o') {
				
			}else {
				lose++;
			}
		}
		if(lose>=8) System.out.println("NO");
		else System.out.println("YES");
		
		
		in.close();

	}

}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp55
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());//.Split(' ').Select(int.Parse)
            var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
 
            for ( var i = 1; i< 1000; i++)
            {
                var r = check(N * i, ab);
                if (r== 1)
                {
                    Console.WriteLine("OK");
                    return;
                }
                
            }
            Console.WriteLine("NG");
 
 
 
        }
        static int  check (int c ,int[] ab ){
 
            if ( ab[1]< c)
                return -1;
            return ab[0] <= c && c <= ab[1] ? 1 :  0;
 
 
            }
    }
}

Measured memory_bytes: 28248
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val l = Array(2 * n) { sc.nextInt() }

    l.sort()
    var ans = 0
    for (i in 0 until n) {
        ans += Math.min(l[2 * i], l[2 * i + 1])
    }
    println(ans)
}


Measured memory_bytes: 33992
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		boolean[] bad = new boolean[N];
		for (int i = 0; i < M; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			if (h[a] <= h[b]) {
				bad[a] = true;
			}
			if (h[a] >= h[b]) {
				bad[b] = true;
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (!bad[i]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 59120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n), b(n - 1);
	rep(i,n - 1) cin >> b.at(i);
	a.at(0) = b.at(0);
	a.at(n - 1) = b.at(n - 2);
	rep(i,n - 2){
		a.at(i + 1) = min(b.at(i), b.at(i + 1));
	}
	ll ans = 0;
	rep(i,n) ans += a.at(i);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <stack>

using namespace std;

#define long long long
#define fi first
#define se second
typedef pair<int,int> ii;

int n;
int jar[200003];
vector<int> vec[200003];

void dfs(int u)
{
	for(auto v : vec[u])
	{
		if(jar[v] == -1)
		{
			jar[v] = jar[u]+1;
			dfs(v);
		}
	}
}

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	memset(jar, -1, sizeof jar);
	jar[1] = 0;
	dfs(1);

	int mx = -1, u;
	for(int i = 1; i <= n; i++)
	{
		if(jar[i] > mx)
		{
			mx = jar[i];
			u = i;
		}
	}

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

	mx = -1;
	for(int i = 1; i <= n; i++)
		mx = max(mx, jar[i]);

	printf("%s", (mx%3 == 1)? "Second\n" : "First\n");
}










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

const ll INF = 1e9;

int main() {

    ll N;
    cin >> N;

    ll all = 0;
    vl a(N);
    rep(i, N) {
        cin >> a[i];
        all = all^a[i];
    }

    ll ans;
    rep(i, N) {
        ans = all^a[i];
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 4796
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	while(scan.hasNext())
	    {
		double f,t;
		
		f=scan.nextDouble();
		t=scan.nextDouble();
		String str="";
		if(f>=1*60+10.0 || t>=2*60+28.0)str="NA";
		if(f<1*60+10.0 && t<2*60+28.0) str="E";	    
		if(f<55.0 && t<1*60+56.0)str="D";
		if(f<50.0 && t<1*60+45.0)str="C";
		if(f<43.0 && t<1*60+29.0)str="B";
		if(f<40.0 && t<1*60+23.0)str="A";
		if(f<37+0.5 && t<1*60+17.0)str="AA";
		if(f<35+0.5 && t<1*60+11.0)str="AAA";
		
		System.out.println(str);
	    }
    }
}

Measured memory_bytes: 20512
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        long K;
        long X;

        try (Scanner sc = new Scanner(System.in)) {
            K = sc.nextLong();
            X = sc.nextLong();
        }
        StringBuilder sb = new StringBuilder();

        for(int i = -1000000;i < 1000001;i++){
            if( i <= X &&i + (K-1) >= X ){
                sb.append(i).append(" ");
            }else if(i >= X && i -(K-1) <= X){
                sb.append(i).append(" ");
            }
        }
        System.out.println(sb.toString());
        return;

    }
}


Measured memory_bytes: 21716
MOD = 2019

l, r = gets.split.map(&:to_i)

ans = MOD
# この場合，lとrの間で一回modが0になってるはずなので0
if (r%MOD) - (l%MOD) <= 0
  ans = 0
elsif (r%MOD) - (l%MOD) > 0
  if r - l >= MOD
    ans = 0
  else
    "point:2019は合成数なのでi,jが最小→i*jが最小ではない"
    # 繰り返し回数は高々2019^2=だいたい2*10^6くらいなので耐え
    l.upto r-1 do |i|
      (i+1).upto r do |j|
        ans = [ans, i*j % MOD].min
      end
    end
  end
end
puts ans

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

using namespace std;

void solve()
{
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    if (a > b) {
        printf("0\n");
    }
    else if (a == b) {
        printf("1\n");
    }
    else {
        if (n >= 2) {
            n -= 2;
            printf("%lld\n", n*b - n * a + 1);
        }
        else {
            printf("0\n");
        }
    }
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 128
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    cout<<800*n-200*(n/15)<<"\n";
}


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

int main()
{
    //A
    int N, R, x;
    cin >> N >> R;

    if (N >= 10)
    {
        x = R;
    }
    else
        x = R + 100 * (10 - N);
    cout << x << endl;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let n_c = read_t_in_line::<i32>();
    let (n, cn) = (n_c[0], n_c[1]);

    const MAX_TIME : usize = 200020;
    const MAX_N : usize    = 100010;

    let mut ss = [0 ; MAX_N];
    let mut tt = [0 ; MAX_N];
    let mut cc = [0 ; MAX_N];

    for i in 0..(n as usize) {
        let s_t_c = read_t_in_line::<i32>();
        let (s, t, c) = (s_t_c[0], s_t_c[1], s_t_c[2]);
        ss[i] = s;
        tt[i] = t;
        cc[i] = c;
    }


    // s * 2 -> + 1
    // t * 2 + 1 -> -1
    let mut sum = [0 ; MAX_TIME];

    for ci in 1..((cn + 1) as usize) {
        let mut mark = [0 ; MAX_TIME];
        for i in 0..(n as usize) {
            let s = ss[i];
            let t = tt[i];
            let c = cc[i];
            if c == ci as i32 {
                // println!("{} {}", ci, i);
                mark[(2*s-1) as usize]+=1;
                mark[(2*t-1) as usize]-=1;
            }
        }
        // 残ったマイナスマークの位置をひとつずらす　
        for i in 0..(MAX_TIME-1) {
            if mark[i] < 0 {
                sum[i+1] += mark[i]
            }
            else{
                sum[i] += mark[i];
            }
        }
    }    

    for i in 1..MAX_TIME {
        sum[i] += sum[i-1];
    }
    let mut ans = 0;

    for i in 0..MAX_TIME {
        ans = max::<i32>(ans, sum[i]);
    }

    println!("{}", ans);

}


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

int main(){
    int N;
    cin >> N;
    char C[N];

    int NR, nR;

    NR=0;
    nR=0;

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

        if(C[i]=='R'){
            NR++;
        }
    }

    for(int i=0; i<NR; i++){
        if(C[i]=='R') nR++;
    }

    cout << NR-nR << endl;


    return 0;
}

Measured memory_bytes: 3796
#!/usr/bin/env python3
import os

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


def input():
    return sys.stdin.readline().rstrip()


class UnionFind:
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1] * (n + 1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0] * (n + 1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if x == y:
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


def main():
    n, m = list(map(int, input().split()))

    uf = UnionFind(n)

    for i in range(m):
        a, b = list(map(int, input().split()))
        uf.Unite(a, b)

    for i in range(1, n + 1):
        uf.Find_Root(i)

    count = -1
    # print("----------")
    # print(uf.root)
    for rt in uf.root:
        if rt < 0:
            count += 1

    if count > 0:
        count -= 1

    print(count)


main()


Measured memory_bytes: 29368
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;

    int total = 0;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        total |= a;
    }

    int cnt = 0;
    while ((total&1) == 0) {
        total >>= 1;
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    p = 0
    idx = partition(A, p, n - 1)
    A = [str(e) for e in A]
    A[idx] = "[{}]".format(A[idx])
    return " ".join(A)


print(main())

Measured memory_bytes: 18432
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int mountCount = int.Parse(Console.ReadLine());
          
            string[] damWater = Console.ReadLine().Split(' ');
          
            int allRain = 0;
          
			for(int i = 0; i < damWater.Length; i++)
            {
             	 allRain += int.Parse(damWater[i]);
            }
          
            allRain = allRain;
          
            int x1 = allRain;
          
            for(int i = 1; i < mountCount; i += 2)
            {
               x1 -= (int.Parse(damWater[i]) * 2);
            }
          
            int[] answer = new int[mountCount] ;
          
            answer[0] = x1;
          
            for(int i = 1; i < mountCount; i++)
            {
               answer[i] = (int.Parse(damWater[i - 1]) * 2) - answer[i - 1];
            }
          
            Console.WriteLine(string.Join( " ", answer));
        }
    }
}


Measured memory_bytes: 32348
# coding: utf-8


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())

    ret = 1
    while 1 <= n/(k**ret):
        ret += 1
    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int ans = 0,n;
		String str;
		str = bf.readLine();
		n = Integer.parseInt(str);
		ans = n*n*n;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  // val n = in.next().toInt
  val N, M = in.next().toInt
  val _H = new Array[(Int, Int)](N)
  val high = new Array[Int](N+1)
  for (i <- 0 until N) {
    val h = in.next().toInt
    _H(i) = (h, i+1)
    high(i+1) = h
  }

  val graph = Array.fill[List[Int]](N+1)(Nil)
  for (i <- 1 to M) {
    val A, B = in.next().toInt
    graph(A) = B :: graph(A)
    graph(B) = A :: graph(B)
  }

  val H = _H.sorted.reverse

  // 
  val dp = new Array[Boolean](N+1)
  var ans = 0
  for ((h, node) <- H) {
    if (!dp(node)) {
      ans += 1

      dp(node) = true

      var flag = false
      for (e <- graph(node)) {
        if (!dp(e))
          dp(e) = true

        // 同一 h のチェック
        if (high(e) >= h)
          flag = true
      }

      if (flag)
        ans -= 1
    }
  }

  println(ans)

}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 73012
#include <iostream>

int main(){
	int n;
	while (std::cin >> n, n){
		int a, sum = 0;
		for (int i = 0; i < n / 4; ++i){
			std::cin >> a;
			sum += a;
		}
		std::cout << sum << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <unordered_map>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define rep(i,min,max) for(int i = min; i < max; i++)
#define rrep(i,max,min) for(int i=max; min <= i; i--)

#define inf 1e+6

string N;

int main(){
  int ans = 0;
  cin >> N;
  for(char c: N)if(c == '2') ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

class Tenka_b{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    string S = Console.ReadLine();
    int K = int.Parse(Console.ReadLine());
    char ch = S[K - 1];
    for (int i = 0; i < N; i++){
      if (S[i] == ch) Console.Write(ch);
      else Console.Write("*");
    }
  }
}

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

int main(){
    int n;
    char ch;
    int num;
    cin >> n;
    vector<vector<int>> vv(4,vector<int>(13,0));
    for(int i=1; i<=n; i++){
        cin >> ch >> num;
        switch(ch){
            case 'S': vv[0][num-1]=1; break;
            case 'H': vv[1][num-1]=1; break;
            case 'C': vv[2][num-1]=1; break;
            case 'D': vv[3][num-1]=1; break;
        }
    }
    for(int i=0; i<4; i++)
        for(int j=0; j<13; j++)
            if(vv[i][j] == 0){
                switch(i){
                    case 0: cout << "S " << j+1 << endl; break;
                    case 1: cout << "H " << j+1 << endl; break;
                    case 2: cout << "C " << j+1 << endl; break;
                    case 3: cout << "D " << j+1 << endl; break;
                }
            }
            
}


Measured memory_bytes: 3112