akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define M 1000000007
using namespace std;

typedef long long int ll;
int main()
{
string s;
cin>>s;
vector<pair<char,ll> > v;
for(ll i=0;i<s.size();)
{
    ll cnt=0;
    ll r=i;
    while(r!=s.size()&&s[i]==s[r])
    {
        cnt++;
        r++;
    }
    v.push_back({s[i],cnt});
    i = r;
}
ll sum=0;
ll val=0;
for(ll i=0;i<v.size();i++)
{
    if(v[i].first=='<')
    {
        ll x=0;
        if(i==0)
        {

            while(x!=v[i].second)
            {
                sum+=val;
                val++;
                x++;
            }
            if(i+1!=v.size())
             {
                    if(val<v[i+1].second)
                    {
                     val = v[i+1].second;
                    sum+=val;
                     val--;
                    }
                    else
                    {
                        sum+=val;
                        val = v[i+1].second -1;
                    }
             }
             else
                sum+=val;


        }
        else
        {
            val++;
            while(x!=v[i].second-1)
            {
                sum+=val;
                x++;
                val++;
            }
            if(i+1!=v.size())
            {
                if(val<v[i+1].second)
                {
                    val = v[i+1].second;
                    sum+=val;
                    val--;
                }
                else
                {
                    sum+=val;
                    val = v[i+1].second - 1;;
                }
            }
            else
            {
                sum+=val;
            }
        }

    }
    else
        {
            if(i==0)
            {
                val = v[i].second;
                while(val)
                {
                    sum+=val;
                    val--;
                }
            }
            else
            {
            ll x = v[i].second-1;
            while(x)
            {
                sum+=val;
                val--;
                x--;
            }
                val=0;
            }

        }
}
cout<<sum<<endl;
}


Measured memory_bytes: 6264
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
int n;
ll a[210000];
int main()
{
    cin>>n;
    for (int i=0; i<n; ++i)
    {
        cin>>a[i];
        a[i]-=(i+1);
    }
    sort(a,a+n);
    ll b=a[n/2];
    ll s=0;
    for (int i=0; i<n; ++i)
        s+=abs(a[i]-b);
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


int N, Q;
string S;
int main() {
	cin >> S;
	if (S == "ARC") cout << "ABC" << endl;
	else cout << "ARC" << endl;
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<P>vec;
int n;
int main(){
	cin>>n;rep(i,n){int a;scanf("%d",&a);vec.pb(mp(a,i));}
	sort(vec.begin(),vec.end(),greater<P>());
	rep(i,n){
		if(vec[0].sc != i) printf("%d\n",vec[0].fi);
		else printf("%d\n",vec[1].fi);
	}
}

Measured memory_bytes: 3312
package main

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

type Process struct {
	name string
	time int
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n, q int
	fmt.Fscan(r, &n)
	fmt.Fscan(r, &q)

	procs := make([]Process, n)
	for i := 0; i < n; i++ {
		var name string
		var time int
		fmt.Fscan(r, &name)
		fmt.Fscan(r, &time)
		procs[i] = Process{name, time}
	}

	var p Process
	elapsedtime := 0
	for len(procs) > 0 {
		p, procs = procs[0], procs[1:]
		if p.time > q {
			elapsedtime += q
			p.time -= q
			procs = append(procs, p)
		} else {
			elapsedtime += p.time
			fmt.Fprintf(w, "%s %d\n", p.name, elapsedtime)
		}
	}
}



Measured memory_bytes: 6720
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;
using ll=long long;

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    auto maxNumber = max({a, b, c});
    int minSum;
    
    if (a == maxNumber)
    {
        minSum = b + c;
    }
    else if (b == maxNumber)
    {
        minSum = a + c;
    }
    else
    {
        minSum = a + b;
    }
    
    printf("%d\n", minSum);
    
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    march = [0]*5
    for _ in range(n):
        s = input()[0]
        if s == 'M':
            march[0] += 1
        elif s == 'A':
            march[1] += 1
        elif s == 'R':
            march[2] += 1
        elif s == 'C':
            march[3] += 1
        elif s == 'H':
            march[4] += 1
    ans = 0
    for idx in itertools.combinations([0, 1, 2, 3, 4], 3):
        ans += march[idx[0]] * march[idx[1]] * march[idx[2]]
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 74540
function main(input) {
  input = input.trim();
  const [a, b] = input.split(" ").map(n => Number(n));
  let result = "IMPOSSIBLE";
  const dif = Math.abs(a - b);
  if (dif%2 === 0) {
    result = a < b ? a + dif/2 : b + dif/2;
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextUint64() uint64 {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.ParseUint(sc.Text(), 0, 64)
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func minUint64(a ...uint64) uint64 {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] {
			res = a[i]
		}
	}
	return res
}

func GCD(a, b uint64) uint64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func LCM(a, b uint64, integers ...uint64) uint64 {
	result := a * b / GCD(a, b)

	for i := 0; i < len(integers); i++ {
		result = LCM(result, integers[i])
	}

	return result
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	a := nextUint64()
	b := nextUint64()
	c := nextUint64()
	d := nextUint64()
	ans := uint64(0)

	e := LCM(c, d)
	// 4 5 6 7 8 9
	// 6 9
	// 3 - 1
	cn := ((b / c) - ((a - 1) / c))
	// 4 6 8
	// 4 - 1
	dn := ((b / d) - ((a - 1) / d))
	// 6
	en := ((b / e) - ((a - 1) / e))
	//
	ans = (b - a + 1) - cn - dn + en
	debugf("ans: %d, cn: %d, dn: %d, en: %d (e: %d)\n", ans, cn, dn, en, e)

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
s,a,b=[set(map(int,input().split()))for j in[0]*3];c=1;N=M=0;x=max(a)
for k in range(x,0,-1):
 A=k in a;B=k in b
 if A and B:M+=1;N+=1
 elif A:c*=M;N+=1
 elif B:c*=N;M+=1
 else:c*=M*N-x+k
 c%=10**9+7
print(c)

Measured memory_bytes: 3316
#include <iostream>

void solve() {
    int n;
    std::cin >> n;

    int m;
    std::cin >> m;
    while (m--) {
        int x;
        std::cin >> x;
        n -= x;
    }

    std::cout << std::max(n, -1) << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3640
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    p,q,r = LI()
    print(p+q+r-max(p,q,r))
    return

#B
def B():
    n = I()
    w = LI()
    ans = float("inf")
    for i in range(n):
        m = sum(w[:i])
        l = sum(w[i:])
        ans = min(ans,abs(m-l))
    print(ans)
    return

#C
def C():
    n,m = LI()
    f = [1 for i in range(n+10000)]
    for i in range(m):
        a = I()
        f[a] = 0
    dp = [0 for i in range(n+10000)]
    dp[0] = 1
    for i in range(n):
        if f[i+1]:
            dp[i+1] += dp[i]
            dp[i+1] %= mod
        if f[i+2]:
            dp[i+2] += dp[i]
            dp[i+2] %= mod
    print(dp[n])
    return

#D
def D():
    h,w = LI()
    s = SR(h)
    vi = [[0 for j in range(w)] for i in range(h)]
    ho = [[0 for j in range(w)] for i in range(h)]
    q = deque()
    for y in range(h):
        for x in range(w):
            if s[y][x] == "#":
                l = len(q)
                while q:
                    i,j = q.pop()
                    vi[i][j] = l
            else:
                q.append((y,x))
        l = len(q)
        while q:
            i,j = q.pop()
            vi[i][j] = l
    for x in range(w):
        for y in range(h):
            if s[y][x] == "#":
                l = len(q)
                while q:
                    i,j = q.pop()
                    ho[i][j] = l
            else:
                q.append((y,x))
        l = len(q)
        while q:
            i,j = q.pop()
            ho[i][j] = l
    ans = 0
    for y in range(h):
        for x in range(w):
            ans = max(ans,vi[y][x]+ho[y][x]-1)
    print(ans)
    return

#E
def E():
    b = S()
    l = len(b)
    for i in range(l):
        b[i] = int(b[i])
    dp = [[0 for j in range(2)] for i in range(1000002)]
    dp[0][0] = 1
    for i in range(l):
        for j in range(2):
            x = 1 if j else b[i]
            for d in range(x+1):
                if d:
                    dp[i+1][j or d < b[i]] += 2*dp[i][j]
                    dp[i+1][j or d < b[i]] %= mod
                else:
                    dp[i+1][j or d < b[i]] += dp[i][j]
                    dp[i+1][j or d < b[i]] %= mod
    ans = 0
    for j in range(2):
        ans += dp[l][j]
        ans %= mod
    print(ans)
    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    E()


Measured memory_bytes: 152804
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();

		int N = fs.nextInt();
		int K = fs.nextInt();

		int count = 0;
		for(int i = 1;i <= N;i++) {
			int h = fs.nextInt();
			if(h >= K) count++;
		}

		System.out.println(count);

	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

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


 
int main() {

    string s,t;
    cin>>s>>t;

    int cnt_max=0;
    for(int i=0;i<s.size()-t.size()+1;i++){
        int cnt=0;
        for(int j=0;j<t.size();j++){
            if(s.at(i+j)==t.at(j))
                cnt++;
        }
        cnt_max=max(cnt,cnt_max);
    }

    cout<<t.size()-cnt_max<<endl;

 	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	lint A[100010]={};
	lint B[100010]={};
	
	cin >> N;
	for(int i=0;i<N;i++)
		cin >> A[i] >> B[i];
	
	lint sum=0;
	for(int i=N-1;i>=0;i--)
	{
		if((A[i]+sum)%B[i]==0)
			continue;
		
		lint x;
		x=(A[i]+sum)/B[i]+1;
		x=x*B[i]-(A[i]+sum);
		sum+=x;
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 1792
#include "iostream"
#include <stdio.h>
#include "cctype"
#include <string>
using namespace std;

 

//PowerPointのコード

 


int main()
{
    char st;
    while (1){
        scanf("%c", &st);
        //cin >> st;
        if (islower(st)!=0){//小文字を大文字に変換
            st = toupper(st);
        }
        else if (isupper(st) != 0){//大文字を小文字に変換
            st = tolower(st);
        }
        //cout << st;
        printf("%c",st);
        if (st == '\n') break;
    }
    return 0;
}


Measured memory_bytes: 3140
// ------------------------------------
// Date:2018/ 3/ 7
// Problem:ABC 078 ISU b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  int X, Y, Z;
  cin >> X >> Y >> Z;

  X -= Z;
  int ans = X / (Y + Z);
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
# 歩く部分は連結。左から右としてよい。
# 結局ワープも左から右としてよい。

N,A,B=map(int,input().split())
X = [int(x) for x in input().split()]

ans = 0
for a,b in zip(X[:-1],X[1:]):
  ans += min((b-a)*A,B)
  
print(ans)


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
main()
{
    long int n,m,k;
    cin>>n>>m;
    long int ar[m],i,c=0;
    for(i=0;i<m;i++){
        cin>>ar[i];
        c+=ar[i];
    }
    k=n-c;
    if(k>=0) cout<<k;
    else cout<<"-1";
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	if(a==b){
	    System.out.println(c);
	}else if(a==c){
	    System.out.println(b);
	}else{
	    System.out.println(a);
	}
    }
}


Measured memory_bytes: 23636
import java.util.Scanner;


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

		if(x == 1){
			System.out.println(1);
			return;
		}

		int result = 0;
		for(int i = (int) Math.sqrt(x); i > 1; i--){
			int max = 0;
			int j = i;
			while(max <= x ){
				j *= i;
				if(j > x) break;
				if(max < j) max = j;
			}
			if(result < max) result = max;
		}
		System.out.println(result);
	}
}

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

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;

  string t = "";
  for ( int i = 0; i < s.size(); i++ ) {
    if ( t.size() >= s.size() ) break;
    t += "hi";
  }

  if ( s == t ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define int long long
using namespace std;
 int32_t main(){
	ios_base::sync_with_stdio(false),cin.tie(nullptr);
	int n,s=0,t;
	cin>>n;
	int v[n+1];
	for(int i=0;i<n;i++)
	{
		cin>>t;
      	v[i]=t;
        s^=t;
	}
	for(int i=0;i<n;i++)
		cout<<(v[i]^s)<<" ";
	return 0;
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0]; var K = NK[1];
            var hasTreat = new bool[N + 1];
            for (int i = 0; i < K; i++)
            {
                var d = int.Parse(Console.ReadLine());
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                foreach (int n in read)
                {
                    hasTreat[n] = true;
                }
            }
            var result = 0;
            foreach(bool b in hasTreat)
            {
                if(!b)result++;
            }
            Console.WriteLine(result-1);
        }
    }
}


Measured memory_bytes: 27592
N = int(input())
X = list(map(int, input().split()))
X.sort()

ans = 100000000000000000000000
res = 0
for i in range(1, 101):
    for x in X:
        res += (x - i) ** 2
    ans = min(ans, res)
    res = 0

print(ans)


Measured memory_bytes: 38512
//ABC173
#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() {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  rep(i, n){
    string s;
    cin >> s;
    if(s == "AC") ac++;
    else if(s == "WA") wa++;
    else if(s == "TLE") tle++;
    else if(s == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}



Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;

int main(void){
	int N,M,i,j,ans;
	int X[200000],Y[200000];
	cin >> N;
	for (i = 0; i < N; ++i){
		cin >> X[i];
	}
	for (i = 0; i < N; ++i){
		Y[i]=X[i];
	}
	sort(X,X+N);
	for (i = 0; i <N ; ++i){
		if(Y[i]<X[N/2]){
			cout << X[N/2] << endl;
		}else{
			cout << X[N/2-1] << endl;
		}
	}
}

Measured memory_bytes: 3712
def sum_of_digits_while(x):
    total = 0

    while x > 0:
        total += x % 10
        x //= 10

    return total


def actual(N):
    total = sum_of_digits_while(N)

    if N % total == 0:
        return 'Yes'
    else:
        return 'No'

N = int(input())
print(actual(N))

Measured memory_bytes: 2940
#include <stdio.h>

int main()
{

    long a,b,n;
    
    scanf("%ld %ld %ld", &a, &b,&n);

    long x;
    x = 1;
    x = b - 1;
    if(n<x)
        x = n;

    long fb = x / b;
    long fa = (a * x) / b;
    long ans = fa - a * fb;

    printf("%ld",ans);
    

    printf("\n");
}

Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
    ll n,k; cin >> n >> k;
    ll ans = 100000000000;

    vector<ll> d(n-1),x(n);

    rep(i,n){
        cin >> x[i];
    }

    for(int i = 0; i < n-(k-1); i ++){
        if(x[i] < 0 && x[i+(k-1)] < 0){
            ans = min(ans,abs(x[i]));
        }else if(x[i] > 0 && x[i+(k-1)] > 0){
            ans = min(ans,x[i+(k-1)]);
        }else{
            ll left = abs(x[i]);
            ll right = abs(x[i+(k-1)]);

            ans = min(ans,min(left,right) + left + right);
        }
    }

    cout << ans;

}

Measured memory_bytes: 4724
program main
    implicit none
    integer sunuke(100), a(100,100), n, k, d, i, j, count
    read(*,*) n,k
    do i = 1, n
        sunuke(i)=0
    end do
    do i = 1, k
        read(*,*) d
        read(*,*) (a(i,j), j = 1, d)
        ! do j = 1, d
        !     write(*,fmt='(I4)',advance='no') a(i,j)
        ! end do
        ! write(*,*)
        do j = 1, d
            sunuke(a(i,j))=1
        end do
    end do
    count=0
    do i = 1, n
        if ( sunuke(i)==0 ) then
            count=count+1
        end if
    end do
    write(*,*) count
end program main

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

namespace test01
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = System.Console.ReadLine();

            int[] nums = line.Split(' ').Select(x => int.Parse(x)).OrderBy(x => x).ToArray();

            int a = nums[0];
            int b = nums[1];
            int c = nums[2];

            Console.WriteLine("{0} {1} {2}", a, b, c);
        }
    }
}



Measured memory_bytes: 16492
F = lambda{|s|
	z = s.size
	r = l = i = 0
	r = i = s.index(?(,0)||z if s[0] == ?)
	until i == z
		j = s.index(?),i)||z # i(((j
		k = s.index(?(,j)||z # j)))k

		rr = k-j-j+i-l
		if 0<rr
			r += rr
			l = 0
		else
			l = -rr
		end

		i = k
	end
	return r,l # ),(
}
N = gets.to_i

n = ll = r = l = rr = 0
r_min = []
l_min = []
until N < n+=1
	r_,l_ = F[gets.chomp]

	if r_ == 0
		ll += l_
	elsif l_ == 0
		rr += r_
	else
		r += r_
		l += l_
		r_min = r_min.push([r_,n]).min_by(2){|_,|_}
		l_min = l_min.push([l_,n]).min_by(2){|_,|_}
	end
end

if ll+l == rr+r and r_min.empty? || r_min.product(l_min).any?{|(r,ri),(l,li)| ri!=li && ll>=r && l<=rr }
	puts'Yes'
else
	puts'No'
end


Measured memory_bytes: 14380
import sys
sys.setrecursionlimit(10 ** 6)


class Tree:
    WHITE = 0
    GRAY = 1
    BLACK = 2

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def dfs(self, u):
        if self.colors[u] == self.BLACK:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v, w in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.depth += w
                self.dfs(v)
                self.depth -= w

        self.colors[u] = self.BLACK


if __name__ == "__main__":
    n = int(input())
    uvw = [list(map(int, input().split())) for _ in range(n - 1)]

    g = [[] for _ in range(n)]

    for u, v, w in uvw:
        u -= 1
        v -= 1
        g[u].append((v, w))
        g[v].append((u, w))

    tree = Tree(g)
    tree.dfs(0)
    ans = [x % 2 for x in tree.depths]
    print(*ans, sep="\n")


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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;
    int K;
    ist >> N >> K;

    vector<int> h;

    for (int i = 0; i < N; i++)
    {
        int input;
        ist >> input;
        h.emplace_back(input);
    }

    /* ------- 計算 ------- */

    vector<int> dp;

    dp.emplace_back(0);

    for (int i = 1; i < N; i++)
    {
        int min_route = INT_MAX;
        for (int step = 0; step < min(i, K); step++)
        {
            int step_j_jump = dp.at(i - step - 1) + abs(h.at(i) - h.at(i - step - 1));
            min_route = min(step_j_jump, min_route);
        }

        dp.emplace_back(min_route);
    }

    ost << dp.at(N - 1) << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 4248
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#include <math.h>


int main(){
  int a, b, x;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&x);
  //printf("gomi\n");
  if (x<0.5*a*a*b){
    //printf("hoge");
    printf("%lf\n",180/M_PI*atan(0.5*(double)a*b*b/(double)x));
    return 0;
  } else {
    //printf("aho");
    printf("%lf\n",180/M_PI*atan(2.0*(double)(a*a*b-x)/((double)a*a*a)));
    return 0;
  }
}

Measured memory_bytes: 256
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def dfs(n):
    visited = [False] * N
    stack = [[n, 0]]
    longest = [-1, -1]

    while stack:
        node, weight = stack.pop()
        if visited[node]:
            continue
        visited[node] = True
        if longest[1] < weight:
            longest = [node, weight]

        for n in T[node]:
            if not visited[n]:
                stack.append([n, weight + 1])

    return longest


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


xn, xw = dfs(0)
yn, yw = dfs(xn)
diameter = yw

d = bfs(0)
ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        dist = bfs(i)
        ans = min(ans, len(list(filter(lambda x: K / 2 < x, dist))))
else:
    # 全ての辺について全探索
    for a, b in E:
        dist1 = bfs(a)
        dist2 = bfs(b)
        dist = [min(d1, d2) for d1, d2 in zip(dist1, dist2)]
        ans = min(ans, len(list(filter(lambda x: (K-1) / 2 < x, dist))))

print(ans)


Measured memory_bytes: 80344
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N){
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    if(i%3 != 0 && i%5 != 0)ans+=i;
  }
  cout << ans << endl;
}

int main(){
    long long N;
	scanf("%lld",&N);
    solve(N);
}


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

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

  int count = 0;
  for (int i = 0; i < 6; i++) {
    if (S[i] == '1') count++;
  }

  cout << count << endl;

  return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 99999
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool shortestPath(const Graph g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF+INF); dist[s] = 0;
  prev.assign(n, -2);
  bool negative_cycle = false;
  REP(k, n) REP(i, n) FOR(e,g[i]) {
    if (dist[e->dst] > dist[e->src] + e->weight) {
      dist[e->dst] = dist[e->src] + e->weight;
      prev[e->dst] = e->src;
      if (k == n-1) {
        dist[e->dst] = -INF;
        negative_cycle = true;
      }
    }
  }
  return !negative_cycle;
}

int main(){
	int T,V,E,s,t,e;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d%d",&V,&E);
		Graph g(V);
		vector<Weight> dist;
		vector<int> prev;
		for(;E--;)scanf("%d%d",&s,&t),g[s].push_back(Edge(s,t,-1));
		puts(shortestPath(g,0,dist,prev)?"0":"1");
	//}
}

Measured memory_bytes: 1056
import java.io.IOException;
import java.util.*;

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

		Stack<Integer> st = new Stack<>();
		int ch;
		int sum = 0;
		List<Integer> lakes = new ArrayList<>();
		Stack<Pair<Integer, Integer>> lakeStack = new Stack<>(); // first: left's \ pos, right: the lake's size
		for(int i=0; (ch = System.in.read()) != -1; i++) {
			if (ch == '\n' || ch == '\r') {
				break;
			}

			if(ch == '\\') {
				st.push(i);
			} else if(ch == '/') {
				if(st.empty() == true) {
					continue;
				}
				int top = st.pop();
				sum += i - top;

				int lakePoint = i - top;

				while(lakeStack.empty() == false) {
					Pair<Integer, Integer> p = lakeStack.pop();
					if(p.fst >= top) {
						lakePoint += p.snd;
					} else {
						lakeStack.push(p);
						break;
					}
				}
				lakeStack.push(new Pair<>(top, lakePoint));
			}
		}

		while(lakeStack.empty() == false) {
			Pair<Integer, Integer> p = lakeStack.pop();
			lakes.add(p.snd);
		}
		Collections.reverse(lakes);

		System.out.println(sum);
		System.out.print(lakes.size());
		for(int i=0;i<lakes.size();i++) {
			System.out.print(" " + lakes.get(i));
		}

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

class Pair<TK,TV> {
	public TK fst;
	public TV snd;
	public Pair(TK fst, TV snd) {
		this.fst = fst;
		this.snd = snd;
	}
}

Measured memory_bytes: 27988
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)
 
def comb(n,r):
    return perm(n,r)//factorial(r)

n,a,b=nm()
v=sorted(nl(), reverse=True)

if v[0]==v[a-1]:
    n = 0
    for vv in v:
        if vv!=v[0]: break
        n += 1

    ans = 0
    for k in range(a, min(b,n)+1):
        ans += comb(n, k)

else:
    n = k = 0
    for i,vv in enumerate(v):
        if vv==v[a-1]:
            if i<a: k += 1
            n += 1
    ans = comb(n,k)

print(sum(v[:a])/a)
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<int> A(N);
    vector<int> s(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        s[i] = A[i];
    }
    sort(s.begin(),s.end(),greater<int>());
    int m=s[0];
    int a=s[1];
    for(int i=0;i<N;i++){
        if(A[i]==m){
            cout << a << endl;
        }else{
            cout << m << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,h;cin >> n >> h;
    vector<int> a(n),b(n);
    int mx = 0;
    rep(i,n){
        cin >> a[i] >> b[i];
        mx = max(mx,a[i]);
    }
    sort(b.rbegin(),b.rend());
    
    int rest = 0;
    int ans = 0;
    
    
    rep(i,n){
        if(rest >= h)break;
        if(b[i]  < mx)break;
        rest += b[i];
        ans++;

    }
    ans += (max(h-rest,0ll) + mx-1)/mx;
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;


int main(){
    ll ans[101]={},n,x[111];
    cin>>n;
    rep(i,n){
        cin>>x[i];
        rep(j,101){
            ans[j]+=(j-x[i])*(j-x[i]);
        }
    }
    rep(i,101){
        MIN(ans[0],ans[i]);
        
    }
    cout<<ans[0]<<endl;
    

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
#define F first
#define S second

int w[114514], m[114514], ma = 0, n, we, memo[114][11451];

int dp(int i, int j) {
	if (memo[i][j] > 0) return memo[i][j];
	if (i == n) return 0;
	else if (j >= w[i]){
	return memo[i][j] = max(dp(i + 1, j - w[i]) + m[i], dp(i + 1, j));
	}
	else {
		return memo[i][j] = dp(i + 1, j);
	}
}

int main(){
	cin >> n >> we;
	REP(i, n) cin >> m[i] >> w[i];
	cout << dp(0, we) << endl;
}





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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int H,W; cin >> H >> W;
    char s[H][W]; REP(i,H)REP(j,W) cin >> s[i][j];

    REP(i,H)REP(j,W){
        if(s[i][j] == '.') continue;
        bool flag = true;
        if(i && s[i-1][j] == '#') flag = false;
        if(j && s[i][j-1] == '#') flag = false;
        if(i<H-1 && s[i+1][j] == '#') flag = false;
        if(j<W-1 && s[i][j+1] == '#') flag = false;
        if(flag){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int read();
void Add(int &x, int y) { (x += y) > mod ? x -= mod : x; }
int fsp(long long bs, int p) {
    int rt = 1;
    while (p) {
        if (p & 1) rt = bs * rt % mod;
        bs = bs * bs % mod, p >>= 1;
    }
    return rt;
}
int n, m, S, a[102];
int bit[100005], f[20][100005];
int fac[100005], caf[100005], lim = 100000;
int C(int x, int y) { return 1ll * fac[x] * caf[y] % mod * caf[x - y] % mod; }
void init() {
    fac[0] = 1;
    for (int i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
    caf[lim] = fsp(fac[lim], mod - 2);
    for (int i = lim; i >= 1; --i) caf[i - 1] = 1ll * caf[i] * i % mod;
}
int main() {
    n = read(), m = read(), S = 1 << n, init();
    for (int i = bit[0] = 1; i < S; ++i) bit[i] = mod - bit[i ^ (i & -i)];
    for (int i = 1; i <= m; ++i) a[i] = read();
    f[m + 1][0] = 1;
    for (int i = m; i >= 1; --i) {
        int x = a[i];
        for (int j = 0, sum = S - x; j < S; ++j)
            if (f[i + 1][j]) {
                Add(f[i][j], f[i + 1][j]);
                for (int k = 0; k < n && j + (1 << k) - 1 <= sum; ++k)
                    if (~j >> k & 1)
                        Add(f[i][j | (1 << k)], 1ll * f[i + 1][j] *
                                                    C(sum - j, (1 << k) - 1) %
                                                    mod * fac[1 << k] % mod);
            }
    }
    int res = 0;
    for (int i = 0; i < S; ++i)
        Add(res, 1ll * bit[i] * f[1][i] % mod * fac[S - i - 1] % mod);
    printf("%d\n", 1ll * res * S % mod);
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

Measured memory_bytes: 8704
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

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

using namespace std;

int r[100005];
int w[100005];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> r[i];
	int a = r[0];
	int p = 0;
	for (int i = 0; i < n - 1; i++) {
		int b = r[i + 1];
		if (a != b)w[p]++;
		else p++;
		a = b;
	}
	if (p <= 2) {
		cout << n << endl;
		return 0;
	}
	int g = 0;
	for (int i = 0; i < n; i++) {
		int h = w[i] + w[i + 1] + w[i + 2];
		g = max(g, h);
	}
	cout << g+3 << endl;

	return 0;
	
}

Measured memory_bytes: 3652
l = list(map(int,input().split()))
X = l[0]
Y = l[1]

a = (Y-2*X)/2
b = (4*X-Y)/2
flag_1 = ((Y - 2*X) % 2 == 0)
flag_2 = ((4*X - Y) % 2 == 0)
flag_3 = ((Y - 2*X) >= 0 and (4*X - Y) >= 0)
flag_4 = not (a == 0 and b == 0)

if (flag_1 and flag_2 and flag_3 and flag_4):
    print("Yes")
else:
    print("No")

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

#define int long long 
const int MAXN = 1e6 + 100 ; 

int a[MAXN] ; 
int32_t main() {
	ios_base::sync_with_stdio(0) ; 
	cin . tie(0) ; cout . tie(0) ; 
	
	int n ; cin >> n ;
	for(int i = 0 ; i < n ; i ++)
		cin >> a[i] ; 
	int ans = 0 , h = 0 ; 
	while(h < n){
		ans ++ ; 
		int a1 = a[h ++] ; 
		while(a[h] == a1 && h < n) h ++ ; 
		int a2 = a[h ++] ; 
		while((a1 - a2) * (a[h - 1] - a[h]) >= 0 && h < n)h ++ ; 
	}
	cout << ans ; 
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll a, b;
	cin >> n >> a >> b;
	vector<ll> h(n);
	rep(i,n) cin >> h[i];
	ll ok = 1e9 + 1, ng = 0;
	while(ok - ng > 1){
		ll mid = (ok + ng) / 2;
		ll cost = 0;
		rep(i,n){
			ll x = (h[i] - b * mid + a - b - 1) / (a - b);
			chmax(x, 0LL);
			cost += x;
		}
		if(cost <= mid) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
	return 0;
}

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

int main()
{
    std::string s;
    std::string ans;
    std::cin >> s;

    if (s == "Sunny")
        ans = "Cloudy";
    else if (s == "Cloudy")
        ans = "Rainy";
    else
        ans = "Sunny";
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n,s;
    const int mod=998244353;
    cin>>n>>s;
    vector<int> ar(n+1);
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    vector<vector<int>> dp(n+1,vector<int>(s+1,0));
    dp[0][0]=1;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=s;j++)
        {
            //  00 and 01 case
            if(i>=1)
                dp[i][j]+=dp[i-1][j]*2;
            dp[i][j]%=mod;
            //11 case 
            if(i>=1 && j-ar[i]>=0)
                dp[i][j]+=dp[i-1][j-ar[i]];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][s];
}
int32_t main()
{
    solve();
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/


Measured memory_bytes: 73724
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
int main(int argc, char *argv[]) {
	int n, m;
	vector<int> lefts, rights;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if(x > 0)
		{
			lefts.push_back(x);
		} else if (x < 0)
		{
			rights.push_back(-x);
		} else {
			m--;
		}
	}
	lefts.push_back(0);
	rights.push_back(0);
	sort(lefts.begin(), lefts.end());
	sort(rights.begin(), rights.end());
	long long ans = 0x3f3f3f3f3f3f3f3f;
	if(m == 0)
	{
		ans = 0;
	} else {
		for(int i = 0; i <= min((size_t)m, lefts.size() - 1); i++)
		{
			long long left_len = 0;
			long long right_len = 0;
			left_len = lefts[i];
			if(m - i >= rights.size())
				continue;
			right_len = rights[m - i];
			ans = min(ans, min(2 * left_len + right_len, left_len + 2 * right_len));
			
		}
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=5e5+10;
const ll mod=1e9+7;
int main()
{
	int n,a,b,ans,now,i,j;
	while(~scanf("%d%d%d",&n,&a,&b))
	{
		ans=0;
		for(i=1;i<=n;i++)
		{
			int temp=i;
			now=0;
			while(temp)
			{
				now+=temp%10;
				temp/=10;
			}
			if(now>=a&&now<=b) ans+=i;
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 256