akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, T = map(int, readline().split())
    t = list(map(int, readline().split()))
    ans = T
    for i in range(N-1):
        ans += min(T, t[i+1]- t[i])
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 22000
import java.util.*;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String[] restaurants = new String[n];
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int score = Integer.parseInt(sc.next());
            restaurants[i] = name + String.format("%010d", 100-score) + "/" + (i + 1);
        }

        Arrays.sort(restaurants);
        StringBuilder sb = new StringBuilder();
        for (String target : restaurants) {
            String[] info = target.split("/");
            sb.append(info[1]);
            sb.append("\n");
        }

        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
int b, n[3005];
long long r[3005][3005];
int main()
{
    cin >> b;
    for(int i = 0; i < b; i++)
    {
    	cin >> n[i];
	}
	for(int i = 0; i < b; i++)
	{
		r[i][i] = n[i];
	}
	for(int i = 1; i < b; i++)
	{
		int l = 0;
		for(int d = i; d < b; d++)
		{
			r[l][d] = max(n[l] - r[l+1][d], n[d] - r[l][d-1]);
			l++;
		}
	}
	cout << r[0][b-1] << endl;
}



Measured memory_bytes: 70016
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int jud = 0;
		
		for(int i = 0; i <= 25; i++) {
			for(int j = 0; j <= 14; j++) {
				if((4 * i) + (7 * j) == N) {
					jud = 1;
				}
			}
		}
		if(jud == 1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23892
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  vl A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A), REV(ll));
  ll ans = 0;
  REP(i, N) {
    ll yo = 0;
    REP(j, N) {
      if (i != j && A[j] + yo < K)
        yo += A[j];
    }
    if (yo + A[i] < K)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			int n = Integer.parseInt(br.readLine());
			String buf = br.readLine();
			StringTokenizer tnz = new StringTokenizer(buf);
			int[] numbers = new int[n];
			for (int i=0;i<n;i++) {
				numbers[i] = Integer.parseInt(tnz.nextToken());
			}
			Arrays.sort(numbers);
			if (n==2) {
				System.out.println(1);
				for (int i=2;i<=(numbers[0]/2);i++) {
					if (numbers[0]%i==0&&numbers[1]%i==0) {
						System.out.println(i);
					}
				}
				if (numbers[1]%numbers[0]==0) {
					System.out.println(numbers[0]);
				}
			}
			else if (n==3) {
				System.out.println(1);
				for (int i=2;i<=(numbers[0]/2);i++) {
					if (numbers[0]%i==0&&numbers[1]%i==0&&numbers[2]%i==0) {
						System.out.println(i);
					}
				}
				if (numbers[1]%numbers[0]==0&&numbers[2]%numbers[0]==0) {
					System.out.println(numbers[0]);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}



Measured memory_bytes: 25116
def main():
    N = int(input())
    As = list(map(int, input().split()))
    ans = 0
    kei = 0
    for i in range(len(As)-1):
        kei += As[-1-i]
        ans += kei*As[-2-i]



    return ans % (10**9 +7)

if __name__ == '__main__':
    print(main())

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

int main() {
   ll H, W; cin >> H >> W;

   ll ans = 1e18;
   for (int k = 0; k < 2; k++) {
      for (int i = 1; i < H; i++) {
         ll a = i*W; // 一番上のやつの面積
         // 縦と横に3分割したとき 
         ll b = (W/2) * (H-i);
         ll c = ((W+1)/2) * (H-i);
         ans = min(ans, abs(max({a, b, c}) - min({a, b, c})));
         // 縦に3分割したとき 
         b = ((H-i)/2) * W;
         c = ((H-i+1)/2) * W;
         ans = min(ans, abs(max({a, b, c}) - min({a, b, c})));
      }
      swap(H, W);
   }

   cout << ans << endl;

   return 0;
}


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n, m;
    string s;
    cin >> n >> m >> s;
    reverse(s.begin(), s.end());
    vector<Int> res;
    Int prev = 0;
    Int last = 0;
    Int tmp = m;
    for (Int i = 1; i <= n; i++) {
        if (s[i] == '0') {
            last = i;
        }
        if (i == m || i == n) {
            if (!(i - m + 1 <= last && last <= m)) {
                dump(-1);
                return 0;
            }
            res.push_back(last - prev);
            prev = last;
            m = last + tmp;
        }
        //dump(m);
    }
    for (Int i = (Int)res.size() - 1; i >= 0; i--) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1528
#include <stdio.h>
int main()
{
	int a,b[100],c[100],i,j,sum=0;
	scanf("%d\n",&a);
	for(i=0;i<a-1;i++)
	{
		scanf("%d\n",&b[i]);
	}
	c[0]=b[0];
	c[a-1]=b[a-2];
	for(i=1;i<a-1;i++)
	{
		if(b[i]>b[i-1])
		{
			c[i]=b[i-1];
			}else
			{
				c[i]=b[i];
			}
			}
			for(i=0;i<a;i++)
			{
				sum=sum+c[i];
				
			}
			printf("%d\n",sum);
			return 0;
			}


Measured memory_bytes: 128
import java.util.Scanner;

// A - Round One
// https://atcoder.jp/contests/abc148/tasks/abc148_a
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        scanner.close();

        if (A == 1 && B == 2) {
            System.out.println("3");
        } else if (A == 1 && B == 3) {
            System.out.println("2");
        } else if (A == 2 && B == 1) {
            System.out.println("3");
        } else if (A == 2 && B == 3) {
            System.out.println("1");
        } else if (A == 3 && B == 1) {
            System.out.println("2");
        } else if (A == 3 && B == 2) {
            System.out.println("1");
        }
    }
}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;


int main(void) {
    int h, a;
    cin >> h >> a;

    cout << (h % a == 0 ? h / a : h / a + 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 30
#define NIL -1
struct node{
	int p,l,r;
}; 
struct node t[MAX];
int dep[MAX],hei[MAX];
void setDepth(int u,int d){
	dep[u]=d;
	if(t[u].l!=NIL)
	setDepth(t[u].l,d+1);
	if(t[u].r!=NIL)
	setDepth(t[u].r,d+1);
}
int setHeight(int u){
	int h1=0,h2=0;
	if(t[u].l!=NIL)
	h1=setHeight(t[u].l)+1;
	if(t[u].r!=NIL)
	h2=setHeight(t[u].r)+1;
	return hei[u]=(h1>h2?h1:h2);
}
void print(int u){
	int sibling,degree=0;
	if(t[u].p==NIL)
	sibling=-1;
	else if(t[t[u].p].l==u)
	sibling=t[t[u].p].r;
	else if(t[t[u].p].r==u)
	sibling=t[t[u].p].l;
	if(t[u].l+1)
	degree++;
	if(t[u].r+1)
	degree++;
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",u,t[u].p,sibling,degree,dep[u],hei[u]);
	if(t[u].p==NIL)
	printf("root");
	else if(degree==0)
	printf("leaf");
	else
	printf("internal node");
	printf("\n");
}
int main(){
	int i,j,n;
	for(i=0;i<MAX;i++){
		t[i].p=NIL;
		t[i].l=NIL;
		t[i].r=NIL;
	}//初始化
	scanf("%d",&n);
	int id[n+1];
	for(i=0;i<n;i++){
		scanf("%d",&id[i]);
		scanf("%d%d",&t[id[i]].l,&t[id[i]].r);
		if(t[id[i]].l+1)
		t[t[id[i]].l].p=id[i];
		if(t[id[i]].r+1)
		t[t[id[i]].r].p=id[i];
	}//输入
	for(i=0;i<n;i++){
		if(t[i].p==NIL)
		break;
	}
	setHeight(i);
	setDepth(i,0);
	for(i=0;i<n;i++)
	print(i);//输出 
	return 0;
}


Measured memory_bytes: 2148
/**
 *		author:  zvm
 *		created: 02.09.2020 20:00:28
**/

#include <bits/stdc++.h>

using namespace std ;

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	

	vector<int> v(3), good{5,5,7} ;
	for( int i = 0 ; i < 3 ; ++i ) {
		cin >> v[i] ;
	}

	sort(v.begin(),v.end());
	
	cout << ( v == good ? "YES" : "NO" ) << endl ;
}


Measured memory_bytes: 3636
i = 0
MAX = 1000
n = [0 for j in range(MAX)]
while True:
    d = int(input())
    if d == 0:
        break
    while d:
        n[i] += d%10
        d //= 10
    i += 1
    
for j in range(i-1):
    print(n[j])
print(n[i-1])


Measured memory_bytes: 5624
#include<iostream>
#include<vector>

using namespace std;

int N;
vector<int> streak;
int input[100 + 10];

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

	int length = 1;
	for (int i = 1; i < N; i++) {
		if (input[i] == input[i - 1])length++;
		else {
			streak.push_back(length);
			length = 1;
		}
	}
	streak.push_back(length);
	length = 1;

	int ans = 0;
	for (int i = 0; i < streak.size(); i++) {
		ans += streak[i] / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,k=map(int,input().split())
    for i in range(k):
        if i%2==0:
            a=a//2*2
            b+=a//2
            a=a//2
        else:
            b=b//2*2
            a+=b//2
            b=b//2           
    print(a,b)

if __name__=='__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
 
int main()
{
    int N;
    cin >> N;

    vector<int> V(N), C(N);
    rep(i,N) cin >> V[i];
    rep(i,N) cin >> C[i];

    int sum = 0;
    rep(i,N) {
        int tmp = V[i] - C[i];
        if (tmp >= 0) sum += tmp;
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
import sys
def input():
        return sys.stdin.readline()[:-1]

N,Q = map(int,input().split())
 
e_list = [[] for i in range(N)]
 
for i in range(N-1):
        a,b = map(int,input().split())
        a,b = a-1,b-1
        e_list[a].append(b)
        e_list[b].append(a)
 
add_list = [0]*N
 
for i in range(Q):
        p,x = map(int,input().split())
        p = p-1
        add_list[p]+=x
 
count_list = [0]*N
count_list[0] = add_list[0]
 
vi = 0 #時と場合によってここを変える
from collections import deque
Q = deque([vi])
checked_list = [False]*N
checked_list[vi]=True
while len(Q)>0:
    v = Q.pop()
    for v1 in e_list[v]:
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.appendleft(v1)
            count_list[v1] = count_list[v]+add_list[v1]
 
print(*count_list)

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

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

    static class DiceandCoin {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            double result = 0;
            for (int i = 1; i <= n; i++) {
                int t = i;
                double tmp = 1;
                while (t < k) {
                    tmp /= 2;
                    t *= 2;
                }
                result += tmp;
            }
            out.println(result / n);

        }

    }
}



Measured memory_bytes: 35832
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(vector<T> & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(vector<T>& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(vector<T>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>T Sum(vector<T> a, T init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	in(a, b);
	out(a == b ? a * 2 : max(a, b) * 2 - 1);
}

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

int main() {

	long long n, m; cin >> n >> m;

	long long ans = 0;
	
	if (2 * n <= m) {
		ans += n;
		m -= 2 * n;
		ans += m / 4;
	}
	else {
		ans = m / 2;
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(char a,char b)
{
	return a>b;
}

int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	if (s<t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

bool can[4][1000];
int main(void) {
    ll n;
    string s;
    cin >> n >> s;

    can[0][0] = true;
    REP(i, n) {
        for(ll j=3; j>=1; --j) REP(k, 1000) {
            if(can[j-1][k]) can[j][k*10+s[i]-'0'] = true;
        }
        // cerr << i << endl;
        // REP(j, 4) REP(k, 1000) {
        //     if(can[j][k]) cerr << j << " " << k << endl;
        // } 
    }

    // REP(i, 1000) if(can[3][i]) cerr << i << endl;

    ll ans = 0;
    REP(i, 1000) if(can[3][i]) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

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

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Person struct {
	large, small int
}

type Elem struct {
	value    interface{}
	priority int
	index    int
}

type PriorityQueue []*Elem

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	elem := x.(*Elem)
	elem.index = n
	*pq = append(*pq, elem)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(*pq)
	elem := old[n-1]
	old[n-1] = nil
	elem.index = -1
	*pq = old[0 : n-1]
	return elem
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	ans := a[0]
	pq := make(PriorityQueue, 0)
	heap.Push(&pq,
		&Elem{value: Person{a[0], a[1]}, priority: a[1]})
	heap.Push(&pq,
		&Elem{value: Person{a[0], a[1]}, priority: a[1]})
	for i := 2; i < n; i++ {
		p := heap.Pop(&pq).(*Elem).value.(Person)
		ans += p.small
		heap.Push(&pq,
			&Elem{value: Person{p.large, a[i]}, priority: a[i]})
		heap.Push(&pq,
			&Elem{value: Person{p.small, a[i]}, priority: a[i]})
	}

	puts(ans)
}


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

using namespace std;

const int N = 1e5 + 3;
char a[N];
int n, q, f[N];

int main() {
	scanf("%d%d", &n, &q);
	scanf("%s", a + 1);
	f[0] = 0;
	f[1] = 0;
	for (int i = 2; i <= n; ++i)
		f[i] = f[i - 1] + (a[i - 1] == 'A' && a[i] == 'C');
	while (q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", f[r] - f[l]);
	}
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( ll i = (a); i < (b); i++ )
#define per(i, a, b) for ( ll i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int n;
ll ans;
vector<ll> l, r;

int main(void) {
  cin >> n;
  rep (i, 0, n) {
    ll a, b;
    cin >> a >> b;
    l.pb(a);
    r.pb(b);
  }
  sort(all(l));
  sort(all(r));
  
  ll lm = (l[n/2] + l[(n-1)/2])*10;
  ll rm = (r[n/2] + r[(n-1)/2])*10;
  lm /= 2, rm /= 2;
  
  ans = rm - lm;
  if (n%2==0) ans *= 2;
  ans /= 10;
  
  cout << ans + 1 << endl;
   
    return 0;
}


Measured memory_bytes: 6604
N = int(input())
A = []
B = []
total_add = 0
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


inc = 0
for i in reversed(range(N)):
    a = A.pop(-1)
    a += total_add
    b = B.pop(-1)
    inc = b - a % b if a % b != 0 else 0
    total_add += inc

print(total_add)


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


int main() {
  int n;
  cin>>n;
  vector<vector<int>> G(n,vector<int> (0));
  vector<vector<int>> b(n,vector<int> (0));

  for(int i=0;i<n-1;i++){
    int a,s,w;
    cin>>a>>s>>w;
    a--;
    s--;
    G[a].push_back(s);
    G[s].push_back(a);
    b[a].push_back(w);
    b[s].push_back(w);
  }
  vector<int> co(n,-1);
  co[0]=0;
  queue<int> que;
  que.push(0);
  int j=0;
  while(!que.empty()){
    int v=que.front();
    que.pop();
    for(int nv=0;nv<G[v].size();nv++){
      int u=G[v][nv];
      int w=b[v][nv];
      if(co[u]!= (-1)) continue;
      co[u]=(co[v]+w)%2;
      que.push(u);
    }
  }
  for(int i=0;i<n;i++){
    cout<<co[i]<<endl;
  }
}
  


Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define INF 1000000000
using namespace std;
int n,h[100005],mem[100005];
int dp(int i){
  if(i==1) return 0;
  if(i<1) return INF;
  if(mem[i]!=-1) return mem[i];
  int a1=dp(i-1)+abs(h[i-1]-h[i]);
  int a2=dp(i-2)+abs(h[i-2]-h[i]);
  return mem[i]=min(a1,a2);
}
int main(){
  cin>>n;
  memset(mem,-1,sizeof(mem));
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }
  cout<<dp(n)<<'\n';
  return(0);
}


Measured memory_bytes: 4096
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long

bool bo[233];

inline bool read()
{
	char ch=getchar();
	while (ch!='Y'&&ch!='N') ch=getchar();
	return (ch=='Y');
}

int main()
{
	ll tot=0;
	for (ll i=1;i<=10000000000LL;i*=10)
	{
		cout<<"? "<<i<<endl;
		bo[++tot]=read();
	}
	if (bo[tot]==1)
	{
		for (ll s=10;;s*=10)
		{
			cout<<"? "<<s-1<<endl;
			if (read()) { cout<<"! "<<s/10;return 0; }
		}
	}
	for (ll i=0;i<tot;i++) if (!bo[i+1])
	{
		ll l=1,r=1,ans;
		for (ll j=1;j<=i;j++) l*=10;
		r=l;l/=10;
		while (l<=r)
		{
			ll mid=(l+r)>>1;
			cout<<"? "<<mid*10<<endl;
			if (read()) ans=mid,r=mid-1;
			else l=mid+1;
		}
		cout<<"! "<<ans;
		return 0;
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;

int main() {
    ll n, k;
    cin >> n >> k;
    vll nums(n);
    vll v(40);
    ll mask = 0;
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        for (int j = 39; j >= 0; --j) {
            mask = 1ll << j;
            if (mask & nums[i]) {
                ++v[j];
            }
        }
    }
    ll cur = 0;
    ll X = k;
    ll ans = 0;
    for (auto &num : nums) {
        cur += (X ^ num);
    }
    ans = max(cur, ans);
    for (int i = 39; i >= 0; --i) {
        X = k;
        cur = 0;
        mask = 1ll << i;
        X = X & ~(mask);
        if (X < k) {
            for (int j = 39; j >= 0; --j) {
                mask = 1ll << j;
                if (j >= i) continue;
                if (v[j] > n - v[j]) {
                    X = X & ~(mask);
                } else {
                    X = X | mask;
                }
            }
            for (auto &num : nums) {
                cur += (X ^ num);
            }
            ans = max(cur, ans);
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

	int* R = new int[n];

	for (int i = 0; i < n; ++i) {
		cin >> R[i];
	}

	int max = R[1] - R[0];
	int min = R[0];

	for (int i = 1; i < n; ++i) {
		if (max < R[i] - min) {
			max = R[i] - min;
		}

		if (min > R[i]) {
			min = R[i];
		}
	}

	cout << max << endl;
	delete[] R;

}


Measured memory_bytes: 3568
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define Speedforce boost();
#define fop(s1, s2) freopen(s1, "r", stdin);freopen(s2, "w", stdout);

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const ll inf = 1e9 + 7;
const ld PI = acos(-1);

ll bin_pow(ll x, ll y){
    ll res = 1, base = x;
    while(y){
        if(y & 1){
            res *= base;
            res %= inf;
        }
        base *= base;
        base %= inf;
        y /= 2;
    }
    return res;
}

int n, k;
int a[N];

int main(){
    Speedforce
    //fop("", "")
    cin >> k >> n;
    int ans = k;
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
    }
    for(int i = 1;i <= n;i ++){
        if(i < n){
            ans = min(ans, k - a[i + 1] + a[i]);
        }
        else{
            ans = min(ans, k - (k - a[i] + a[1]));
        }
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long int llint;

llint A, B;

int main() {
	cin >> A >> B;
	if (A < B) { swap(A, B); }
	llint x = A * B;
	llint r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	cout << x / B << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N,A,B=map(int,input().split())

ANS=10*N

if (B-A)%2==0:
    ANS=min(ANS,(B-A)//2)

ANS=min(ANS,((A-1)+(B-1)+1)//2)

ANS=min(ANS,((N-A)+(N-B)+1)//2)

print(ANS)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}
int correct(int x) {
    if (x < 0) x += MOD;
    return x;
}

vector< int >neg, pos;
int zero;

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

    int mx = 0;
    vector< int >sobai;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x > 0) pos.push_back(x);
        else if (x < 0) neg.push_back(x);
        else zero++;
        mx = max(mx, x);
        sobai.push_back(x);
    }

    if (k == 1) {
        if (mx < 0) mx += MOD;
        cout << mx << endl;
        return 0;
    }

    if (n-zero < k) {
        cout << 0 << endl;
        return 0;
    }

    if (pos.empty() && k%2 == 1) {
        int ans = 0;
        if (zero == 0) {
            sort(neg.rbegin(), neg.rend());
            ans = 1;
            for (int i = 0; i < k; i++) {
                ans = mul(ans, MOD+neg[i]);
//                cout << "take " << neg[i] << endl;
            }
        }
        cout << ans << endl;
        return 0;
    }


    sort(sobai.begin(), sobai.end(), [](int x, int y) {
        return abs(x) > abs(y);
    });

    int ans = 1;
    int choto = 0, boro = 0;
    int ng = 0;
    for (int i = 0; i < k; i++) {
        assert(sobai[i] != 0);
        if (sobai[i] > 0) {
            boro = sobai[i];
            ans = mul(ans, sobai[i]);
        } else {
            ng ^= 1;
            choto = sobai[i];
            ans = mul(ans, MOD+sobai[i]);
        }
    }

    if (ng == 0 || k == n) {
        cout << ans << endl;
        return 0;
    }

    if (sobai[k] == 0) {
        cout << 0 << endl;
        return 0;
    }

    int _choto = 0, _boro = 0;
    for (int i = k; i < n; i++) {
        if (sobai[i] > 0) {
            if (_choto == 0) _choto = sobai[i];
        } else if (sobai[i] < 0) {
            if (_boro == 0) _boro = sobai[i];
        }
    }

    if (choto != 0 && _choto != 0 && boro != 0 && _boro != 0) {
        if (abs(_choto)*1LL*abs(boro) >= abs(_boro)*1LL*abs(choto)) {
            ans = mul(ans, pw(MOD+choto, MOD-2));
            ans = mul(ans, _choto);
        } else {
            ans = mul(ans, pw(boro, MOD-2));
            ans = mul(ans, MOD+_boro);
        }
    } else if (choto != 0 && _choto != 0) {
        ans = mul(ans, pw(MOD+choto, MOD-2));
        ans = mul(ans, _choto);
    } else if (boro != 0 && _boro != 0) {
        ans = mul(ans, pw(boro, MOD-2));
        ans = mul(ans, MOD+_boro);
    } else {
        assert(false);
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int k, ans=0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i]=='A')
        {
            int k=i;
            for(int j = s.size()-1; j > i; j--)
            {
                if(s[j]=='Z')
                {
                    ans=max(ans, j-k+1);
                    break;
                }
            }
            break;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3704
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max (T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min (T &a, T b) {if(b<a) a=b;}
template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;}
template< typename T > inline T Abs(T &a) {if(a<0) return -a; else return a;}

const double   pi = acos(-1.0) ;
const int     MOD = (int)1e9+7 ;
const int     INF = (int)0x3f3f3f3f ;
const LL     LINF = (LL)INF<<32|INF ;
const int    SINF = (uint)(-1)>>1 ;
const LL    SLINF = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double  eps = 1e-5 ;
const int    maxn = (int) 2e5+20 ;
const int    maxm = (int) 25000+20 ;
const int    maxk = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------

int n;
char s[maxn];

void work()
{
    scanf("%s",s+1);
    n=strlen(s+1);

    int ans=n;

    for(int i=2;i<=n;i++) if(s[i-1]!=s[i]) Min(ans,max(i-1,n-i+1));

    cout <<ans <<endl;
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 384
N=gets.to_i
A=gets.split.map(&:to_i)
MOD=10**9+7
counter=[0,0,0]
ans=1

A.each do |a|
  if a==counter[0]
    if counter[0]==counter[2]
      ans=(ans*3)%MOD
    elsif counter[0]==counter[1]
      ans=(ans*2)%MOD
    end
    counter[0]+=1
  elsif a==counter[1]
    if counter[1]==counter[2]
      ans=(ans*2)%MOD
    end
    counter[1]+=1
  elsif a==counter[2]
    counter[2]+=1
  else
    ans=0
  end
end

p ans


Measured memory_bytes: 8068
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=1e4+5;

int n,k;
char st[N],an[N],tmp[N];

void chk() {
	fo(i,1,n) {
		if (an[i]<tmp[i]) return;
		if (tmp[i]<an[i]) {
			fo(j,1,n) an[j]=tmp[j];
			return;
		}
	}
}

int main() {
	scanf("%d%d",&n,&k);
	scanf("%s",st+1);
	char c='z';
	fo(i,1,n) c=min(c,st[i]);
	fo(i,1,n) st[2*n-i+1]=an[i]=st[i];
	if (st[n]==c) {
		int pos=n,len=0,y=k;
		for(;pos>=1&&st[pos]==c;pos--) len++;
		for(;len<n&&y;y--) len<<=1;
		if (len<n) {
			fo(i,1,len) tmp[i]=c;
			fo(i,len+1,n) tmp[i]=st[pos--];
		} else fo(i,1,n) tmp[i]=c;
		chk();
	}
	for(int l=n+1,r=n;l<=n*2;l=r+1) {
		while (r<n*2&&st[r+1]==st[l]) r++;
		if (st[l]==c) {
			int len=0,pos=r,y=k-1;
			for(;pos>=r-n+1&&st[pos]==c;pos--) len++; 
			for(;len<n&&y;y--) len<<=1;
			if (len<n) {
				fo(i,1,len) tmp[i]=c;
				fo(i,len+1,n) tmp[i]=st[pos--];
			} else fo(i,1,n) tmp[i]=c;
			chk();
		}
	}
	printf("%s\n",an+1);
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N, K, ans=0;
	int A[200005];

	cin >> N >> K;
	rep(i,N) cin >> A[i];

	map<int,int> mp;
	rep(i,N) mp[ A[i] ]++;

	vector<int> v;
	for(auto t: mp) v.emplace_back(-t.Y);

	sort(all(v));
	int sum = 0;
	rep(i,K) if(i<v.size()) sum += -v[i];

	ans = N - sum;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
 
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
int main(){
  ll N,T,LCM=1;
  cin>>N;
  while(cin>>T){
    LCM=lcm(T,LCM);
  }
  cout<<LCM<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    String S = scan.next();
    scan.close();

    int flag = 0;
    int count = 0;
    for(int i=0; i<N; i++) {
      switch(flag) {
        case 0:
          if(S.charAt(i) == 'A') {
            flag = 1;
          }
          break;
        case 1:
          if(S.charAt(i) == 'B') {
            flag = 2;
          }
          else if(S.charAt(i) == 'A') {
            flag = 1;
          }
          else {
            flag = 0;
          }
          break;
        case 2:
          if(S.charAt(i) == 'C') {
            count++;
            flag = 0;
          }
          else if(S.charAt(i) == 'A') {
            flag = 1;
          }
          else {
            flag = 0;
          }
          break;
      }
    }

    System.out.println(count);
  }
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	
	cin >> n;
	vector<vector<int>> activities(n, vector<int>(3));
	vector<vector<int>> points(n, vector<int>(3));

	for(int i = 0; i < n ; i++ )
	{
		cin >>  activities[i][0] >> activities[i][1] >> activities[i][2];
	}

	for(int i=0 ; i < 3; i++)
		points[0][i] = activities[0][i];

	for(int i = 1; i < n; i++)
	{
		points[i][0] = activities[i][0] + max(points[i-1][1], points[i-1][2]);
		points[i][1] = activities[i][1] + max(points[i-1][0], points[i-1][2]);
		points[i][2] = activities[i][2] + max(points[i-1][1], points[i-1][0]);
	}

	int res = max(max(points[n-1][0], points[n-1][1]), points[n-1][2]);
	cout << res << endl;

}

Measured memory_bytes: 11136
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int k = parseInt(sc.next());
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for (i = 0; i < n; i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		int[] d = new int[n];
		for (i = 0; i < n-1; i++) {
			d[i] = a[i+1] - a[i];
		}
		d[n-1] = k +a[0] - a[n-1];
		Arrays.parallelSort(d);
		int sum = 0;
		for (i = 0; i < n-1; i++) {
			sum += d[i];
		}
		out.println(sum);
	}
}


Measured memory_bytes: 61700
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = 1;
		
		while(true) {
			int i1 = sc.nextInt();
			int i2 = sc.nextInt();
			
			if(i1 == 0 && i2 == 0) {
				break;
			}else {
				if(i1 < i2) {
					System.out.println(i1 + " " + i2);
				}else {
					System.out.println(i2 + " " + i1);
				}
			}
		}
	}
}



Measured memory_bytes: 35320
#include <iostream>
#include <cstdio>
#include <cmath>

#define STUDENT_MAX 1000

using namespace std;

int main(void){
  int n;
  int s[STUDENT_MAX];
  double avg;
  double a;

  while(true){

    cin >> n;

    if(n == 0) break;

    for(int i = 0; i < STUDENT_MAX; i++){
      s[i] = 0;
    }

    avg = 0;
    a = 0;

    for(int i = 0; i < n; i++){
      cin >> s[i];
      avg += s[i];
    }

    avg = avg / n;

    for(int i = 0; i < n; i++){
      a += (s[i] - avg) * (s[i] - avg);
    }

    a = a / n;

    a = sqrt( a );

    printf("%lf\n", a);
    
  }

  return 0;
}

Measured memory_bytes: 1192
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := intScanner()
	if n%500 <= a {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1776
// ----------------------------------------------------------
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <numeric>

using namespace std;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;
    long cnt= 0;
    int flg = 0;
    
    cin >> S;
    
    flg = 0;
    for (int i=0;i<S.length(); i++){
        if(i<S.length() && S[i] == S[i+1] && flg == 0){
            flg = 1;
            i++;
        }else{
            flg = 0;
        }
        cnt++;
    }
    
    cout << cnt << endl;

    return 0;
}


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

using namespace std;

#define MAX_V 100
#define INF 1e9

struct edge{ int to,cap,rev; };

int V,E;
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,static_cast<int>(G[to].size())});
    G[to].push_back((edge){from,0,static_cast<int>(G[from].size()-1)});
}

int dfs(int v,int t,int f){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0 ; i < (int)G[v].size() ; i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to,t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow = 0;
    for(;;){
        memset(used,false,sizeof(used));
        int f = dfs(s,t,INF);
        if(f == 0) return flow;
        flow += f;
    }
}

int main(){
    int a,b,c;
    cin >> V >> E;
    for(int i = 0 ; i < E ; i++){
        cin >> a >> b >> c;
        add_edge(a,b,c);
    }
    cout << max_flow(0,V-1) << endl;
    return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=998244353;
const ll MAXN=1e4+5;
const ll inf=1e17;

int main()
{
    fastio;
    ll n, k;
    cin >> n >> k;
    ll x = 0, b =1;
    while(b <= n){
        b = b * k;
        x++;
    }
    cout << x << endl;
}


Measured memory_bytes: 256
N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0

pre = 2 * N

for i in A :
    ans += B[i-1]
    if (pre == (i-2) ):
        ans += C[i-2]
    pre = i-1

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
vector<pair<ll,ll>> vec[100000];
int main(){
  ll x;
  cin >> x;
  cout << 3 * x * x;

}


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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        ans += tmp - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

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

typedef long long ll;


int main(void) {
    int n;
    int x[200]={} , y[200]={};
    while (cin>>n && n){
        int l=0,r=0,u=0,d=0;
        REP(i,n-1){
            int k,p;
            cin >> k >> p;
            if (p==0){
                x[i+1] = x[k]-1;
                y[i+1] = y[k];
                l = min(l,x[i+1]);
            }
            if (p==1){
                x[i+1] = x[k];
                y[i+1] = y[k]-1;
                d = min(d,y[i+1]);
            }
            if (p==2){
                x[i+1] = x[k]+1;
                y[i+1] = y[k];
                r = max(r,x[i+1]);
            }
            if (p==3){
                x[i+1] = x[k];
                y[i+1] = y[k]+1;
                u = max(u,y[i+1]);
            }
        }
        cout << r-l+1 << " " << u-d+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int n,A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i,int m){
    if(m == 0) return 1;
    if(i >= n) return 0;
    return solve(i + 1,m) || solve(i + 1,m - A[i]);
}

int main(){
    int q,m;
    
    scanf("%d",&n);
    
    for(int i = 0;i < n;++i){
        scanf("%d",&A[i]);
    }
    
    scanf("%d",&q);
    
    for(int i = 0;i < q;++i){
        scanf("%d",&m);
        if(solve(0,m))printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



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

int main()
{  
   int n;
   cin>>n;
   int p[n];
   int sum=0,max_p=0;
   for(int i=0;i<n;i++){
       cin>>p[i];
       if(p[i]>max_p) max_p=p[i];
       sum+=p[i];
    }
   cout<<sum-max_p/2<<endl;
   
}

Measured memory_bytes: 256
class Main
  def self.run
    data_set = read_inputs
    data_set.map{|xy| xy.sort.join(" ")}.each{|answer| puts answer}
  end

  private

  def self.read_inputs
    data_set = []
    while true do
      xy = gets.split(" ").map(&:to_i)
      case xy
        when [0, 0] then break
        else data_set << xy
      end
    end
    data_set
  end
end

Main.run

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    string t;
    cin >> t;
    ll n = t.length();
    rep(i, n) {
        if (t[i] == 'P' | t[i] == 'D') {
            cout << t[i];
        } else {
            cout << 'D';
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3752
import math
def factorize(m):
    fct = []
    b = 2
    while b * b <= m:
        cnt = 0
        while m % b == 0:
            m //= b
            cnt += 1
        if cnt > 0:
            fct.append(cnt)
        b += 1
    if m > 1:
        fct.append(1)
    return fct

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    else:
        return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

N, M = map(int, input().split())
ans = 1
M_fct = factorize(M)

for mf in M_fct:
    #mf[1]個をN通りに分ける→comb(mf[1]+N-1,mf[1])
    ans *= comb(N + mf - 1, mf)
    ans %= 10**9+7
print(ans)

Measured memory_bytes: 114492