akhauriyash/Code-Regression huggingface dataset:
#define B
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
#if A
        var XY = ReadLine().Split().Select(int.Parse).ToArray();
        var X = XY[0];
        var Y = XY[1];
        var ans = Max(0, 4 - X) + Max(0, 4 - Y) + (X == 1 && Y == 1 ? 4 : 0);
        WriteLine(ans * 100000);
#endif
#if B
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(long.Parse).ToArray();
        var a = new long[N + 1];
        for (int i = 0; i < N; i++)
        {
            a[i + 1] = 2 * A[i] + a[i];
        }
        var m = a[N] / 2;
        var ans = long.MaxValue;
        for (int i = 0; i <= N; i++)
        {
            ans = Min(ans, Abs(a[i] - m));
        }
        WriteLine(ans);
#endif
#if C
        var HWK = ReadLine().Split().Select(int.Parse).ToArray();
        var H = HWK[0];
        var W = HWK[1];
        var K = HWK[2];
        var s = new bool[H, W];
        for (int i = 0; i < H; i++)
        {
            var line = ReadLine();
            for (int j = 0; j < W; j++)
            {
                s[i, j] = line[j] == '#';
            }
        }
        var ha = new bool[H];
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (s[i, j]) ha[i] = true;
            }
        }
        var ans = new int[H, W];
        var k = 0;
        for (int i = 0; i < H; i++)
        {
            if (ha[i])
            {
                var b = false;
                k++;
                for (int j = 0; j < W; j++)
                {
                    if (s[i, j])
                    {
                        if (b) k++;
                        b = true;
                    }
                    ans[i, j] = k;
                }
            }
            else
            {
                for (int j = 0; j < W; j++)
                {
                    if (i != 0) ans[i, j] = ans[i - 1, j];
                }
            }
        }
        if (!ha[0])
        {
            for (int j = 0; j < W; j++)
            {
                ans[0, j] = ans[1, j];
            }
        }

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                Write(ans[i, j]);
                if (j != W - 1) Write(" ");
            }
            WriteLine();
        }
#endif
    }
}

Measured memory_bytes: 38784
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		int ans = 0;

		sc.nextLine();
		String C = sc.nextLine();

		int cntR = 0;
		int cntW = 0;

		//RR|WWにする

		for(int i=0; i<N; i++) {
			if(C.charAt(i) == 'R') {
				cntR++;
			}
		}
		ans = Math.max(cntR, cntW);

		for(int i=0; i<N; i++) {
			if(C.charAt(i) == 'R') {
				cntR--;
			} else {
				cntW++;
			}
			if(Math.max(cntR, cntW) < ans) {
				ans = Math.max(cntR, cntW);
			}
		}

		// 出力
		System.out.println(ans);
	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 41440
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X >> K;
    for (int i = K - X + 1; i < K + X; i++) {
        cout << i;
        if (i != K + X - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 1000500

bool prime[MAX];

void is_prime(){
    fill(prime,prime+MAX,true);
    prime[0] = prime[1] = false;
    
    for(int i = 2 ; i*i < MAX ; i++)
        if(prime[i])
            for(int j = i*i ; j < MAX ; j += i)
                prime[j] = false;
}

int main(){
    int a,d,n;
    
    is_prime();
    
    while(cin >> a >> d >> n , a+d+n){
        int cnt = 0,i;
        
        for(i = a ; i < MAX ; i += d){
            if(prime[i]) cnt++;
            if(cnt == n) break;
        }
        cout << i << endl;
    }
    
    return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   string s; cin >> s;
   vector<char> v;
   for(int i = 0; i < s.size(); i++)
   {
      if(s[i] != 'B')
         v.push_back(s[i]);
      else if( !v.empty())
         v.pop_back();
   }
   for(auto u : v)
      cout << u;


	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

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

    vector<int> dest(N,1e9);
    dest[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int vs = que.front();
        que.pop();
        for(int i=0; i<S[vs].size(); i++){
            int vg = S[vs][i];
            if(dest[vg] > dest[vs]+1){
                dest[vg] = dest[vs] + 1;
                que.push(vg);
            }
        }
    }

    int root = 0;
    for(int i=0; i<N; i++){
        if(dest[root] < dest[i]){
            root = i;
        }
    }

    dest = vector<int>(N, 1e9);
    dest[root] = 0;
    que.push(root);
    while(!que.empty()){
        int vs = que.front();
        que.pop();
        for(int i=0; i<S[vs].size(); i++){
            int vg = S[vs][i];
            if(dest[vg] > dest[vs]+1){
                dest[vg] = dest[vs] + 1;
                que.push(vg);
            }
        }
    }

    int L = 0;
    for(int i=0; i<N; i++){
        L = max(L, dest[i]);
    }

    if(L%3==1){
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }
}


Measured memory_bytes: 14324
from heapq import heappop, heappush
import sys

q = []
ans = []
while True:
    s = sys.stdin.readline()
    if s[0] == 'i':
        heappush(q, -int(s[7:]))
    elif s[2] == 't':
        ans.append(-heappop(q))
    else:
        break
print('\n'.join(map(str, ans)))


Measured memory_bytes: 99148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    int n;
        cin >> n;
    vec num(n);
    vector <pair<int, int>> v(n);
        for(int i=0; i<n; i++){
            int a, b;
            cin >> a >> b;
            v.at(i) = make_pair(a,b);
        }
        for(int i=0; i<n; i++) num.at(i)=i;
        double sum=0, cnt=0;
        do{
            for(int i=0; i<n-1; i++){
                double dx = v.at(num.at(i)).first-v.at(num.at(i+1)).first;
                double dy = v.at(num.at(i)).second-v.at(num.at(i+1)).second;
                sum += sqrt(dx*dx+dy*dy);
            }
            cnt += 1;
        }while(next_permutation(num.begin(), num.end()));

        cout << fixed << setprecision(15) << sum/cnt << endl;
}

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

int main()
{
    int A,B;
    cin>>A>>B;
    if(A<10 && B<10)
    {
        cout<<A*B<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }
    return 0;
}


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

int N;
int A[100010];
int a,b;

char S[2][100010] = {"First","Second"};

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

int main()
{
    int cnt = 0;
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",&A[i]);

    int k = 1;
    while(1)
    {
        k = 1 - k;
        cnt = 0;
        for(int i = 0; i < N; i++)if(A[i] % 2 == 0)cnt++;
        if(cnt % 2){printf("%s\n",S[k]);return 0;}
        cnt = N - cnt;
        if(cnt > 1){printf("%s\n",S[1 - k]);return 0;}
        for(int i = 0; i < N; i++)if(A[i] == 1){printf("%s\n",S[1 - k]);return 0;}
        for(int i = 0; i < N; i++)if(A[i] % 2)A[i]--;
        int GDC = A[0];
        for(int i = 1; i < N; i++)GDC = gdc(GDC,A[i]);
        for(int i = 0; i < N; i++)A[i] /= GDC;
    }
    return 0;
}


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

int main() {
  int N, A, a, b;
  cin >> N >> A;
  a = N / 500;
  b = N - 500 * a;
	if (b <= A) {
      cout << "Yes" << endl;
    }else {
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
package main

import "fmt"
import "bufio"
import "os"
import "strconv"
import "sort"

var _sw = bufio.NewScanner(os.Stdin)

func main() {
	N := NextInt()
	A := NextInts(N)

	cnts := map[int]int{}
	nums := []int{}
	for _, a := range A {
		if cnts[a] == 0 {
			nums = append(nums, a)
		}
		cnts[a]++
	}

	var ok bool
	var x, y, z int
	switch len(nums) {
	case 1:
		ok = (nums[0] == 0)

	case 2:
		if N%3 != 0 {
			fmt.Println("No")
			return
		}

		x, z = nums[0], nums[1]
		if z != 0 {
			z, x = x, z
			if z != 0 {
				fmt.Println("No")
				return
			}
		}
		ok = (cnts[0]*2 == cnts[x])
	case 3:
		if N%3 != 0 {
			fmt.Println("No")
			return
		}

		x, y, z = nums[0], nums[1], nums[2]
		ok = (x^y == z && cnts[x] == cnts[y] && cnts[y] == cnts[z])
	default:
		fmt.Println("No")
		return
	}

	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func NextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func NextInts(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = NextInt()
	}
	return a
}

func NextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func Bounded(lower, n, upper int) int {
	return Min(upper, Max(lower, n))
}

func SortInts(xs []int) {
	sort.Sort(sort.IntSlice(xs))
}

func ReverseSortInts(xs []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(xs)))
}


Measured memory_bytes: 8960
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int MOD = (int)1e9 + 7;
void sadd(int &a, int b){
    a += b;
    if(a >= MOD)a -= MOD;
    else if(a < 0)a += MOD;
}

int dp[70][3];

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

    cin >> N;
    vi d;
    while(N)d.push_back(N % 2), N /= 2;
    reverse(all(d));
    int D = sz(d);
    dp[0][0] = 1;

    rep(i, D)rep(j, 3) {
        rep(x, 3) {
            int nj = j * 2 + d[i] - x;
            if(nj >= 0)sadd(dp[i + 1][min(2, nj)], dp[i][j]);
        }
    }

    int ans = 0;
    rep(i, 3)sadd(ans, dp[D][i]);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a;
  for(int i = 0; i < n; i++){
	  int b;
	  cin >> b;
	  a.push_back(b);
  }
  sort(a.begin(), a.end());
  decltype(a)::iterator point = unique(a.begin(), a.end());
  unique(a.begin(), a.end());
  a.erase(point, a.end());
  cout << a.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int ans = 1;
    for (int i = 0; i < N; i++)
    {
        if (ans * 2 < ans + K)
        {
            ans *= 2;
        }
        else
        {
            ans += K;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N,D;
    cin >> N >> D;
    ll ans = 0;
    rep(i,N){
        ll X,Y;
        cin >> X >> Y;
        if (X * X + Y * Y <= D * D) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<int> bi(n-1);
  for(int i=0; i<n-1; i++){
    std::cin >> bi[i];
  }

  reverse(bi.begin(), bi.end());

  vector<int> ans(n,999999999);
  for(int i=0; i<n-1; i++){
    ans[i] = min(ans[i], bi[i]);
    ans[i+1] = min(ans[i+1], bi[i]);
  }

  long long answer = 0;
  for( int i=0; i<n; i++){
    answer += ans[i];
  }
  std::cout << answer << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
namespace IO{
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc(){
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread(){}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls){
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do{
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    inline void flush(){
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x){
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite(){}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls){
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    struct Flusher_{~Flusher_(){flush();}}io_flusher;
}
using namespace IO;
ll n, x, t;
int main(){
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void){
  int x,y,group[12]={0,2,0,1,0,1,0,0,1,0,1,0};

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

  if(group[x-1]==group[y-1]){
    printf("Yes\n");
    return 0;
  }
  printf("No\n");

  return 0;
}


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


void countStr(char ser[], char* arr[],int n)
{
    int coun =0;

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


        if(strcmp(arr[i],ser) ==0)
        {
            coun++;
        }

    }
    cout<<ser<<" "<<"x"<<" "<<coun<<endl;

}

int main()
{
    int n;
    cin>>n;
    char* arr[n];
    char x[3]="AC";


    if(n>0 && n<10^5)
    {
        cin.ignore();
        for(int i=0 ; i<n; i++)
        {
            arr[i]= new char[4];


            cin.getline(arr[i],4);

            arr[i][4]='\n';
            // cout<<arr[i]<<endl;
            if(strcmp(arr[i],x)!=0   &&  strcmp(arr[i],(char*)"WA")!=0    &&  strcmp(arr[i],(char*)"TLE")!=0   &&  strcmp(arr[i],(char*)"RE")!=0)
            {

                return 0;
            }


        }

        countStr("AC", arr,n);
        countStr("WA", arr,n);
        countStr("TLE",arr,n);
        countStr("RE", arr,n);


    }


    return 0;
}


Measured memory_bytes: 7528
N,A,B=map(int,input().split())
cnt=0
for i in range(1,N+1):
    num1=i%10
    #print(num1)
    num2=int(i/10)%10
    num3=int(i/100)%10
    num4=int(i/1000)%10
    num5=int(i/10000)%10
    if A<=(num1+num2+num3+num4+num5)<=B:
        cnt+=i
    #print(cnt)
print(cnt)
   


Measured memory_bytes: 3060
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    H = [ii() for _ in range(N)]
    H = sorted(H, reverse=True)
    cnt = len(H)-K+1
    ret = [0]*cnt
    for i in range(cnt):
        ret[i] = H[i] - H[i+K-1]
    print(min(ret))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11488
N,W = map(int, input().split())

vw = []

for i in range(N):
    w,v = map(int, input().split())
    vw.append((w,v))


dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
#i番目までで重さｊを作るときの最大価値
for i in range(N):
    for j in range(W+1):

        if vw[i][1] > j:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j - vw[i][1]] + vw[i][0])


print(dp[-1][-1])


Measured memory_bytes: 16132
N, M = map(int, input().split())
S = input()
T = input()
#from math import gcd
from fractions import gcd

g = gcd(N, M)
ans = N*M//g
n = ans//N
m = ans//M

for i in range(g):
    if S[i*m] != T[i*n]:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 5688
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int N;



int main() {
    cin >> N;
    vector<int> A(N);

    for (int i = 0; i < N; i++) { 
        cin >> A[i];
        A[i] -= (i+1);
    }
    sort(A.begin(),A.end());

    int b = A[N/2];
    ll res = 0;
    for (int i = 0; i < N; i++) {
        res += (ll)abs(A[i]-b);
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;
long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	int i, ans=0;
	int R, G, B, N;
	vector<int> A(100000),L(100000);
	cin >> R >> G >> B >> N;
	for (i = 0; i <= N / R; i++) {
		for (int j = 0; j <= (N - R * i)/G; j++) {
			if ((N - R * i - G * j) % B == 0)
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
n = gets.to_i
a = gets.split.map(&:to_i)
q = gets.to_i
s = q.times.map {|_| gets.chomp.split.map(&:to_i)}

g = a.group_by{|i| i}.map{|k,v| [k, v.length]}.to_h

sum = g.map{|k, v| k * v}.sum
q.times do |i|
  sum += s[i][1] * g[s[i][0]].to_i - s[i][0] * g[s[i][0]].to_i
  g[s[i][1]] = g[s[i][1]].to_i + g[s[i][0]].to_i
  g.delete(s[i][0])
  p sum
end

Measured memory_bytes: 40144
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int m1, d1, m2, d2; cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2) outl("0");
  else outl("1");
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;

int main()
{
    long int N;
    cin >> N;
    long int ans = 1e18;
    for (long int i = 1; i <= sqrt(N); ++i)
    {
        if( N%i == 0){
            long int j = N / i;
            ans = min(ans, i + j - 2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll h[100010];
    rep(i,0,N){
        cin >> h[i];
    }
    sort(h, h+N);
    ll ans = INF;
    rep(i,0,N-K+1){
        ans = min(ans, h[i+K-1] - h[i]);
    }
    print(ans);
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
using namespace std;
const int MAXN = 25+5;
struct tre{
	int fa,le,ri;
}tr[MAXN];
int n,rot;
void init(){
	memset(tr,-1,sizeof(tr));
	cin>>n;
	for(int i=0;i<n;i++){
		int id,left,right;
		cin>>id>>left>>right;
		tr[id].le=left;
		tr[id].ri=right;
		if(left!=-1) tr[left].fa=id;
		if(right!=-1) tr[right].fa=id;
	}
	for(int i=0;i<n;i++)
	    if(tr[i].fa==-1){
	    	rot=i;
	    	break;
	    } 
}
void qx(int x){
	if(x==-1) return;
	cout<<' '<<x;
	qx(tr[x].le);
	qx(tr[x].ri);
}
void zx(int x){
	if(x==-1) return;
	zx(tr[x].le);
	cout<<' '<<x;
	zx(tr[x].ri);
}
void hx(int x){ 
    if(x==-1) return;
    hx(tr[x].le);
	hx(tr[x].ri);
	cout<<' '<<x;
}
void sol(){
	cout<<"Preorder"<<endl;
	qx(rot);
	cout<<endl<<"Inorder"<<endl;
	zx(rot);
	cout<<endl<<"Postorder"<<endl;
	hx(rot);
	cout<<endl;
}
int main(){
	init();
	sol();
	return 0;
}

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

using namespace std;

vector<int>pos,neg;

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

    int n,i,x,tot=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>x;
        if(x>=0)pos.push_back(x);
        else neg.push_back(abs(x));
    }
    if(n==1){cout<<x<<'\n';return 0;}
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end());
    if(neg.empty()){
        for(i=2;i<pos.size();i++)tot+=pos[i];
        tot += (pos[1]-pos[0]);
        cout<<tot<<'\n';
        if(n==2)cout<<pos[1]<<' '<<pos[0]<<'\n';
        else{
            cout<<pos[0]<<' '<<pos[1]<<'\n';
            int cur = pos[0] - pos[1];
            for(i=2;i<(int)pos.size()-1;i++){
                cout<<cur<<' '<<pos[i]<<'\n';
                cur-=pos[i];
            }
            cout<<pos[pos.size()-1]<<' '<<cur<<'\n';
        }
    }
    else if(pos.empty()){
        for(i=2;i<neg.size();i++)tot+=neg[i];
        tot += (neg[1]-neg[0]);
        cout<<tot<<'\n';
        cout<<neg[0]*(-1)<<' '<<neg[1]*(-1)<<'\n';
        int cur = neg[1] - neg[0];
        for(i=2;i<neg.size();i++){
            cout<<cur<<' '<<neg[i]*(-1)<<'\n';
            cur += neg[i];
        }
    }
    else{
        for(i=0;i<pos.size();i++)tot+=pos[i];
        for(i=0;i<neg.size();i++)tot+=neg[i];
        cout<<tot<<'\n';
        int cur = neg[0]*(-1);
        for(i=1;i<pos.size();i++){
            cout<<cur<<' '<<pos[i]<<'\n';
            cur-=pos[i];
        }
        cout<<pos[0]<<' '<<cur<<'\n';
        cur=pos[0]-cur;
        for(i=1;i<neg.size();i++){
            cout<<cur<<' '<<neg[i]*(-1)<<'\n';
            cur+=neg[i];
        }
    }
    return 0;
}


Measured memory_bytes: 2424
/// You just can't beat the person who never gives up
/// ICPC next year

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ,u ,v ;
vector<int> adj[N] ;
int leave ,diamater ;
void dfs(int p,int gp,int d){
    if(d>diamater) diamater = d ,leave = p ;
    for(int ch:adj[p]) if(ch!=gp) dfs(ch,p,d+1);
}

int mem[N][2] ;
int solve(int d,int cur){
    if(d==0) return 1-cur ;
    if(d==1) return cur ;
    if(d==2) return 1-cur ;
    int&ret=mem[d][cur];
    if(~ret) return ret;
    int a = solve(d-1,1-cur);
    int b = solve(d-2,1-cur);
    if(a==cur) return ret = cur ;
    if(b==cur) return ret = cur ;
    return ret = 1-cur ;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,1,1);
    dfs(leave,leave,1);
    memset(mem,-1,sizeof mem);
    int x = solve(diamater,0) ;
    puts(x==0?"First":"Second");
    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int N; string S;
    cin >> N >> S;
    set<int> r,g,b;
    for(int i=0; i<N; i++){
        if(S[i] == 'R') r.insert(i);
        else if(S[i] == 'G') g.insert(i);
        else b.insert(i);
    }
    ll ans = r.size()*g.size()*b.size();
    for(int i=1; i<=N; i++){
        for(int j=i+1; j<=N; j++){
            ll k = 2*j-i;
            if(k>N) break;
            set<char> x;
            x.insert(S[i-1]);
            x.insert(S[j-1]);
            x.insert(S[k-1]);
            if(x.size() == 3) ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3744
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
	int a, b, c, d, e, k;
	long long m[5];
	long long m_last[5];

	//cin >> a >> b >> c >> d >> e >> k;
	long long N;
	cin >> N;
	long long min = 1000000000000000;
	for (int i = 0; i < 5; i++) {
		cin >> m[i];
		if (m[i] < min) {
			min = m[i];
		}
	}
	
	if (N%min == 0) {
		cout << N / min + 4 << endl;
	}
	else {
		cout << N / min + 5 << endl;
	}
	
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string> s;
int main() {
    scanf("%d%d%d",&a,&b,&c);
    for (int i=1;i<=a;++i) s.insert("a");
    for (int i=1;i<=b;++i) s.insert("b");
    for (int i=1;i<=c;++i) s.insert("c");
    for (int i=1;i<a+b+c;++i) {
        auto l=s.begin(),r=s.end();r--;
        s.insert(*l+*r);
        s.erase(l);s.erase(r);
    }
    printf("%s\n",s.begin()->c_str());
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <ctype.h>

int H, W;
char map[1024][1024];
char mark0[1024][1024];
char mark1[1024][1024];
int target0[1024 * 1024][2];
int target1[1024 * 1024][2];
int houkai[1024 * 1024][2];

int houkaisuru(int y, int x) {
	int count = 0;
	int i, j;
	if (map[y][x] <= 0) return 0;
	for (i = -1; i <= 1; i++) {
		for (j = -1; j <= 1; j++) {
			if (i == 0 && j == 0) continue;
			if (map[y + i][x + j] == 0) count++;
		}
	}
	return map[y][x] <= count;
}

int main(void) {
	int i, j, k;
	int count = 0;
	int (*current_target)[2] = target0, ct_num = 0;
	int (*next_target)[2] = target1, nt_num = 0;
	char (*current_mark)[1024] = mark0;
	char (*next_mark)[1024] = mark1;
	int (*target_temp)[2];
	char (*mark_temp)[1024];
	int houkai_num = 0;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%1023s", map[i]) != 1) return 1;
		for (j = 0; j < W; j++) {
			if (isdigit((unsigned char)map[i][j])) {
				map[i][j] -= '0';
			} else {
				map[i][j] = 0;
			}
		}
	}
	for (i = 1; i < H - 1; i++) {
		for (j = 1; j < W - 1; j++) {
			current_target[ct_num][0] = i;
			current_target[ct_num][1] = j;
			ct_num++;
		}
	}
	for (;;) {
		nt_num = 0;
		houkai_num = 0;
		for (i = 0; i < ct_num; i++) {
			int y = current_target[i][0];
			int x = current_target[i][1];
			current_mark[y][x] = 0;
			if (houkaisuru(y, x)) {
				houkai[houkai_num][0] = y;
				houkai[houkai_num][1] = x;
				houkai_num++;
				for (j = -1; j <= 1; j++) {
					for (k = -1; k <= 1; k++) {
						if (j == 0 && k == 0) continue;
						if (next_mark[y + j][x + k] == 0) {
							next_mark[y + j][x + k] = 1;
							next_target[nt_num][0] = y + j;
							next_target[nt_num][1] = x + k;
							nt_num++;
						}
					}
				}
			}
		}
		if (houkai_num == 0) break;
		count++;
		for (i = 0; i < houkai_num; i++) {
			map[houkai[i][0]][houkai[i][1]] = 0;
		}
		ct_num = nt_num;
		target_temp = current_target;
		current_target = next_target;
		next_target = target_temp;
		mark_temp = current_mark;
		current_mark = next_mark;
		next_mark = mark_temp;
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 14916
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var input = input.split("")
    
    var ans = "Yes"
    
    
    
    for(var i in input){
      
      if(Number(i) % 2 == 1 && input[i] == "R"){
      	ans = "No"
      }
      if(Number(i) % 2 == 0 && input[i] == "L"){
      	ans = "No"
      }
    }
  console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<ll,ll>
typedef long long ll;
const int maxn=1e6+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
ll kpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
int main()
{
	ll n,i,j,a[maxn]={0},la=1,ans=0,f[maxn]={0};
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		ll b=a[i];
		for(j=2;j*j<=b;j++)
		{
			if(b%j==0)
			{
				ll cnt=0;
				while(b%j==0)b/=j,cnt++;
				f[j]=max(f[j],cnt);
			}
		}
		if(b>1)f[b]=max(f[b],1ll);
	}
	for(i=2;i<=1e6;i++)la=(la*kpow(i,f[i]))%mod;
	for(i=1;i<=n;i++)ans=(ans+la*kpow(a[i],mod-2)%mod)%mod;
	printf("%lld\n",ans);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

ll sum;

void fn2(string S,ll subsum){
	int i=S.find("+");

	if(i==-1) sum+=subsum+(ll)stol(S);
	else{
		subsum+=(ll)stol(S.substr(0,i));
		fn2(S.substr(i+1),subsum);
	}
}

void fn(string S,int position,int maxlength){
	if(position==maxlength) fn2(S,0);
	else{
		fn(S,position+1,maxlength);
		S=S.substr(0,position)+"+"+S.substr(position);
		fn(S,position+2,maxlength+1);
	}
	return;
}

int main(void){
	sum=0;
	string S;
	cin>>S;
	fn(S,1,(int)S.length());

	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


//imos
int main(){
    string s;
    cin >> s;

    int a[30] = {};

    string res = "Yes";

    REP(i,s.size())
    {
        a[s[i] - 'a']++;
    }
    REP(i,3)
    {
        if(a[i] != 1)res = "No";
    }

    cout << res << endl;

    return 0;    
}



Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>

using namespace std;

int main() {
  int i;
  int N, K;
  int nums[200010] = {};
  scanf("%d %d", &N, &K);
  for (i = 0; i < N; i++) {
    int a;
    scanf("%d", &a);
    nums[a] += 1;
  }
  sort(nums, nums+N+1, greater<int>());
  for (i = 0; i < K; i++) {
    N -= nums[i];
  }
  printf("%d", N);
  return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










const double PI = 3.14159265;





int main(){
    ll h, a;
    cin >> h >> a;
    cout << ((h % a == 0)? h / a : h / a + 1) << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  kyougi
//
//  Created by 寺林 一旭 on 2018/08/27.
//  Copyright © 2018年 寺林 一旭. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <map>
using namespace std;
int main() {
    
    long num;
    int inputValue;
    vector<int> list;
  
    while(cin >> num) //getline(cin, num))
    {
        long ans=1;
        for( int i = 1; i <= num ; i++)
        {
            ans = ans * i;
        }
        cout << ans << endl;
      //  cout << digit << endl;
   //     cout << a-b <<endl;
    }
  
    
    return 0;
}



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

int main() {
int x,y,z,n,p,ans;
x = y = z = p =  0;
cin >> n;
string s;
  Rep(i,n){
    cin >> s;
    Rep(j,s.length()-1)
    {
      if(s.at(j)=='A' && s.at(j+1)=='B')
      {
        p++;
      }
    }


    if(s.at(0)=='B')
    {
      if(s.at(s.length()-1) == 'A')
      z++;
      else
      x++;
    }
    else if(s.at(s.length()-1) == 'A')
    y++;

  }
if( x== 0 && y== 0 && z > 0)
ans = z-1+p;
else
ans = p + z + min(x,y);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;

static const int N = 100;

int main(void) {
	int M[N][N];
	int n, u, k, v;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		scanf("%d%d", &u, &k);
		u--;//0オリジンへ変換する
		for (int j = 0; j < k; j++) {
			scanf("%d", &v);
			v--;
			M[u][v] = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) printf(" ");
			printf("%d", M[i][j]);
		}
		printf("\n");
		}

	return 0;
}


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

using namespace std;

#define MAX 100001
typedef vector<int> Vec;
typedef vector<Vec> Vecs;

int main(){
    int N,D,X;
    cin >> N >> D >> X;
    Vecs p(D,vector<int>(N));
    for(int i = 0 ; i < D ; i++){
	for(int j = 0 ; j < N ; j++){
	    cin >> p[i][j];
	}
    }
    Vecs dp(N+1,vector<int>(MAX));
    for(int i = 0 ; i < D-1 ; i++){
	for(int j = 0 ; j < N ; j++){
	    for(int k = 0 ; k <= X ; k++){
		dp[j][k] = k;
	    }
	}
	for(int j = 0 ; j < N ; j++){
	    for(int k = 0 ; k <= X ; k++){
		if(k < p[i][j]){
		    dp[j+1][k] = dp[j][k];
		}else{
		    dp[j+1][k] = max(dp[j][k],
				     dp[j+1][k-p[i][j]]+p[i+1][j]);
		}
	    }
	}
	int maxi = 0;
	for(int j = 0 ; j <= X ; j++){
	    maxi = max(maxi,dp[N][j]);
	}
	X = max(X,maxi);
    }
    cout << X << endl;
    return 0;
}

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

int main(void){
  int n, k;
  cin >> n >> k;
  int ans = 1;
  while(n / k != 0) {
    n /= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(void)
{
    string s;
    cin >> s;

    int cnt = 0;
    for (int i = 0; i < s.length()-1; i++)
    {
        if (s.at(i)==s.at(i+1))
            continue;
        else
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
   double a,b,h,m,kakudo=0,ans=0,rad=0;
   double pi = acos(-1);
   cin >> a >> b >> h >> m;
   kakudo=abs((h*30+0.5*m)-m*6);
   if(kakudo>=180){
      kakudo = 360-kakudo;
   }
   rad=kakudo*(pi/180);
   ans=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(rad));
   
   cout << fixed << setprecision(15) << ans << endl;
return 0;
}

Measured memory_bytes: 4232
#include<stdio.h>

int main(void)


{


long long int a[10000],min=1000000,max=-1000000,sum=0;


int n,i;


scanf("%d",&n);


for(i=0;i<n;i++){


scanf("%lld",&a[i]);


if(a[i]>=max){


max=a[i];


}


if(a[i]<=min){


min=a[i];


}


sum+=a[i];


}


printf("%lld %lld %lld\n",min,max,sum);


return 0;


}

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

int main() {
  int x;
  int y = 1;
  while(1) {
    cin >> x;
    if (x == 0) break;
    cout << "Case " << y << ": " << x << endl;
    y++;
  }
  
  return 0;
  
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

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

  // check for star-shaped graph (no path with distance of 3)
  for (int i = 0; i < n; i++) {
    if (edge[i].size() == n-1) {
      for (int j = 1; j <= n; j++) cout << j << " ";
      cout << endl;
      return 0;
    }
  }

  vector<bool> parity(n);
  queue<Pii> que;
  vector<bool> visited(n);
  que.emplace(0, 0);
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if (visited[now.first]) continue;
    visited[now.first] = true;
    parity[now.first] = (now.second % 2 == 0);
    for (auto &x: edge[now.first]) {
      if (!visited[x]) que.emplace(x, now.second + 1);
    }
  }

  int evenCount = 0;
  int oddCount = 0;
  for (int i = 0; i < n; i++) {
    if (parity[i]) evenCount++;
    else oddCount++;
  }

  vector<int> ans(n);
  int smallCount = min(evenCount, oddCount);
  if (smallCount < (n + 1) / 3) {
    int nextNum = 3;
    vector<bool> unused(n+2, true);
    if (evenCount < oddCount) {
      for (int i = 0; i < n; i++) {
        if (parity[i]) {
          ans[i] = nextNum;
          unused[nextNum] = false;
          nextNum += 3;
        }
      }
    }
    else {
      for (int i = 0; i < n; i++) {
        if (!parity[i]) {
          ans[i] = nextNum;
          unused[nextNum] = false;
          nextNum += 3;
        }
      }
    }
    nextNum = 1;
    for (int i = 0; i < n; i++) {
      if (ans[i] == 0) {
        ans[i] = nextNum;
        unused[nextNum] = false;
        while (!unused[nextNum]) nextNum++;
      }
    }
  }
  else {
    int nextNum = 1;
    for (int i = 0; i < n; i++) {
      if (parity[i]) {
        ans[i] = nextNum;
        nextNum += 3;
        if (nextNum > n) break;
      }
    }
    nextNum = 2;
    for (int i = 0; i < n; i++) {
      if (!parity[i]) {
        ans[i] = nextNum;
        nextNum += 3;
        if (nextNum > n) break;
      }
    }
    nextNum = 3;
    for (int i = 0; i < n; i++) {
      if (ans[i] == 0) {
        ans[i] = nextNum;
        nextNum += 3;
        if (nextNum > n) break;
      }
    }
  }

  for (auto &x: ans) cout << x << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 15216
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  vector<int> ans(n + 1);
  int m = 0;
  for (int i = n; i >= 1; --i) {
    int cnt = 0;
    for (int j = 1; i * j <= n; ++j) {
      if (ans[i * j]) cnt++;
    }
    cnt %= 2;
    if (cnt != a[i]) {
      m++;
      ans[i]++;
    }
  }
  cout << m << endl;
  if (m) {
    for (int i = 1; i <= n; ++i) {
      if (ans[i]) cout << i << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2432
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = input()
    l = len(n)

    ans = 0
    x = int(n)
    while x > 0:
        ans += x % 10
        x //= 10

    else:
        for i in range(l):
            score = 0
            for j in range(i):
                score += int(n[j])
            score += int(n[i]) - 1
            score += 9 * (l - (i + 1))
            ans = max(score, ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62008
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import itertools as ite
import math
import random
import sys
import codecs
from collections import defaultdict

INF = 10 ** 18
MOD = 10 ** 9 + 7

sys.setrecursionlimit(1000000)

N, D = map(int, raw_input().split())
print N / (2 * D + 1) + (N % (2 * D + 1) != 0)


Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

const ll MOD = 1e9+7;

int main() {
    string S;
    cin >> S;
    string abc = "ABC";
    int l = S.size();
    vector<vector<ll> > dp(l+1, vector<ll>(4, 0));
    dp[l][3] = 1;

    for(int i = l-1; i >= 0; i--) {
        int m1 = S[i] == '?' ? 3 : 1;
        dp[i][3] = m1 * dp[i+1][3] % MOD;
        for(int j = 2; j >= 0; j--) {
           int m2 = (S[i] == '?' | S[i] == abc[j]) ? 1 : 0;
           dp[i][j] = ((m1 * dp[i+1][j] % MOD) + (m2 * dp[i+1][j+1]) % MOD) % MOD;
        }
    }

    cout << dp[0][0] << endl;

    return 0;
}

Measured memory_bytes: 7424
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as B
import Data.Attoparsec.ByteString.Char8

type Input = B.ByteString

input :: Parser B.ByteString
input = takeTill isSpace

main :: IO ()
main = B.interact
  $ B.pack . show . either (error "parse err") solve . parseOnly input

solve :: Input -> Int
solve xs = 2 * (ts `min` (B.length xs - ts))
  where
    ts = B.length $ B.filter (== '1') xs

Measured memory_bytes: 892
n,m=map(int,input().split())
l_max=0
r_min=10**5+1
for i in range(m):
    l,r=map(int,input().split())
    l_max=max(l_max,l)
    r_min=min(r_min,r)
print(max(0,r_min-l_max+1))

Measured memory_bytes: 9020
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=117;
const int MM=100 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n,s;
LL dp[NN][NN][NN]={};
LL tp[NN][NN]={};
LL mod;
LL fact[NN]={};
LL rev[NN]={};
LL mi[NN][NN*NN]={};
LL ksm(LL a,LL b){
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ret=ret*a%mod;
	return ret;
}
void prefact(int n){
	fact[0]=1;
	for(int i=1;i<=n;++i){
		fact[i]=fact[i-1]*i%mod;
	}
	rev[n]=ksm(fact[n],mod-2);
	for(int i=n;i>=1;--i){
		rev[i-1]=rev[i]*i%mod;
	}
}
LL c[NN][NN]={};
int main(){
	//open();
	n=read();
	m=read();
	s=read();
	mod=read();
	prefact(max(n,m));
	for(int i=0;i<=s;++i){
		mi[i][0]=1;
		for(int j=1;j<=n*m;++j){
			mi[i][j]=mi[i][j-1]*i%mod;
		}
	}
	dp[1][n][m]=1;
	for(int i=1;i<=s;++i){
		for(int j=0;j<=n;++j){
			for(int l=0;l<=m;++l){
				c[j][l]=rev[l]*mi[i][j*l]%mod*mi[s-i+1][(n-j)*l]%mod;
			}
		}
		for(int j=0;j<=n;++j){
			for(int k=0;k<=m;++k){
				tp[j][k]=0;
				for(int l=0;l+k<=m;++l){
					tp[j][k]+=dp[i][j][k+l]*c[j][l];
					tp[j][k]%=mod;
				}
			}
		}
		for(int l=0;l<=n;++l){
			for(int k=0;k<=m;++k){
				c[l][k]=rev[l]*mi[i][k*l]%mod*mi[s-i+1][(m-k)*l]%mod;
			}
		}
		for(int j=0;j<=n;++j){
			for(int k=0;k<=m;++k){
				dp[i][j][k]=0;
				for(int l=0;l+j<=n;++l){
					dp[i][j][k]+=tp[j+l][k]*c[l][k];
					dp[i][j][k]%=mod;
				}
			}
		}
		for(int j=0;j<=n;++j){
			for(int l=0,sym=1;l<=m;++l,sym=-sym){
				c[j][l]=rev[l]*mi[i][j*l]*sym%mod*mi[s-i][(n-j)*l]%mod;
			}
		}
		for(int j=0;j<=n;++j){
			for(int k=0;k<=m;++k){
				tp[j][k]=0;
				for(int l=0;l+k<=m;++l){
					tp[j][k]+=dp[i][j][k+l]*c[j][l];
					tp[j][k]%=mod;
				}
			}
		}
		for(int l=0,sym=1;l<=n;++l,sym=-sym){
			for(int k=0;k<=m;++k){
				c[l][k]=rev[l]*mi[i][k*l]*sym%mod*mi[s-i][(m-k)*l]%mod;
			}
		}
		for(int j=0;j<=n;++j){
			for(int k=0;k<=m;++k){
				dp[i+1][j][k]=0;
				for(int l=0;l+j<=n;++l){
					dp[i+1][j][k]+=tp[j+l][k]*c[l][k];
					dp[i+1][j][k]%=mod;
				}
			}
		}
	}
	LL ans=dp[s+1][0][0]*fact[n]%mod*fact[m]%mod;
	ans=(ans+mod)%mod;
	printf("%lld\n",ans);
	close();
	return 0;
}


Measured memory_bytes: 24320