akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n; 
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ll ans;
  if (n % 2) {
    ll l = a[n / 2];
    ll r = b[n / 2];
    ans = r - l + 1;
  } else {
    ll l = a[n / 2] + a[n / 2 - 1];
    ll r = b[n / 2] + b[n / 2 - 1];
    ans = r - l + 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4848
N,T=list(map(int,input().split()))
cost_list=[]
time_list=[]
for i in range(N):
    c,t=list(map(int,input().split()))
    cost_list.append(c)
    time_list.append(t)
while 1:
    min_cost=min(cost_list)
    min_index=cost_list.index(min_cost)
    if time_list[min_index]<=T:
        print(min_cost)
        break
    else:
        del time_list[min_index]
        del cost_list[min_index]
        if cost_list==[]:
            print("TLE")
            break

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class I_Coins {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            double[] p = new double[n];
            for (int i = 0; i < n; i++) {
                p[i] = Double.parseDouble(in.ns());
            }
            double[][] dp = new double[n + 1][n + 1];
            dp[0][0] = 1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j <= n; j++) {
                    dp[i + 1][j] = dp[i][j] * (1 - p[i]);
                    if (j > 0)
                        dp[i + 1][j] += dp[i][j - 1] * p[i];
                }
            }
            double ans = 0;
            for (int i = 0; i < (n + 1) / 2; i++) {
                ans += dp[n][n - i];
            }
            out.println(ans);

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



Measured memory_bytes: 131920
package main

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

type dlist struct {
	value int
	prev  *dlist
	next  *dlist
}

var head, last *dlist

func main() {
	var (
		str string
		ary []string
		x   int
	)

	head = new(dlist)
	last = new(dlist)
	head.next = last
	last.prev = head

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	for i := 0; i < n; i++ {
		sc.Scan()
		str = sc.Text()
		switch str {
		case "deleteFirst":
			head.next = head.next.next
			head.next.prev = head
		case "deleteLast":
			last.prev.prev.next = last
			last.prev = last.prev.prev
		default:
			ary = strings.Split(str, " ")
			x, _ = strconv.Atoi(ary[1])
			switch ary[0] {
			case "insert":
				insert(x)
			case "delete":
				delete(x)
			}
		}
	}

	dl := head.next
	fmt.Print(dl.value)
	dl = dl.next
	for {
		if dl == last {
			break
		}
		fmt.Print(" ", dl.value)
		dl = dl.next
	}
	fmt.Println()
}

func insert(v int) {
	dl := new(dlist)
	dl.value = v
	dl.prev = head
	dl.next = head.next

	head.next = dl
	dl.next.prev = dl
}

func delete(v int) {
	dl := head.next
	for dl != last {
		if dl.value == v {
			dl.prev.next = dl.next
			dl.next.prev = dl.prev
			return
		}
		dl = dl.next
	}
}



Measured memory_bytes: 61180
import           Control.Monad
import           Control.Applicative

main :: IO ()
main = do
  [a, b, c] <- map read . words <$> getLine

  putStrLn $ if ds a b c then "YES" else "NO"

ds :: Int -> Int -> Int -> Bool
ds a b c = elem c $ f a b [] [1 .. b]

f :: Int -> Int -> [Int] -> [Int] -> [Int]
f a b d (idx : idxs) | (a * idx) `mod` b == 0 = d ++ [0]
                     | otherwise = f a b (d ++ [(a * idx) `mod` b]) idxs

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();

        long num = Math.max(b / x, 0) - Math.max((a - 1) / x, 0);
        if (a == 0) num++; 
        System.out.println(num);
    }
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  string s, t, ans;
  cin >> n >> s >> t;
  
  /*
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  */
  
  rep (i,n) {
    ans += s.at(i);
    ans += t.at(i);
  }
    
  cout << ans << "\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5005];
bitset<5000005>dp;
int main()
{
	int n,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	dp.set(0);
	for(int i=1;i<=n;++i)
			dp|=dp<<a[i];
	for(int i=sum/2;;--i)if(dp[i])return !printf("%d\n",sum-i);
	return 0;
}

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

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

    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    rep(i, k) cin >> l[i] >> r[i];

    const int mod = 998244353;
    vector<int> dp(n+1, 0), dps(n+1, 0);
    dp[1] = dps[1] = 1;

    for(int i = 2; i < n+1; ++i){
        rep(j, k){
            dp[i] = ((dp[i] + (i-l[j]>=0? dps[i-l[j]]: 0)%mod)%mod - (i-(r[j]+1)>=0? dps[i-(r[j]+1)]: 0)%mod + mod) % mod;
        }
        dps[i] = dps[i-1] + dp[i];
        dps[i] %= mod;
    }

    // rep(i, n+1) cout << dp[i] << " ";
    // cout << endl;

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 4756
#include<iostream>
#include<set>

using namespace std;

int main()
{
	string s;
	cin >>s;
	
	int mn = 1e9;
	for(auto c : s){
		string cur = s;
		int stps = 0;
		
		while(true){
			
			set<char> st;
			for(auto ch : cur)
				st.insert(ch);
			if(st.size() == 1){
				break;
			}
			
			string nxt = "";
			++stps;
			for(int i = 0; i < cur.size() - 1; ++i){
				if(cur[i] == c || (i + 1 < cur.size() && cur[i + 1] == c)){
					nxt += c; 
				}
				else{
					nxt += cur[i];
				}
			}
			
			cur = nxt;
		}
		mn = min(mn, stps);
	}
	
	cout <<mn <<'\n';
	return 0;
}


Measured memory_bytes: 3600
N = int(input())
a = list(map(int, input().split()))
dp = [[0]*N for _ in range(N)]
if N%2 == 0:
    for i in range(N):
        dp[0][i] = -a[i]
else:
    for i in range(N):
        dp[0][i] = a[i]

for i in range(1, N):
    for j in range(N-i):
        if (N-i)%2 == 1:
            dp[i][j] = max(dp[i-1][j]+a[i+j], dp[i-1][j+1]+a[j])
        else:
            dp[i][j] = min(dp[i-1][j]-a[i+j], dp[i-1][j+1]-a[j])
print(dp[-1][0])

Measured memory_bytes: 112860
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int w,h,r,x,y;

bool ok(){
    if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h) return true;
    else return false;
}

int main(){

    cin >> w >> h >> x >> y >> r;
    if(ok()) cyes;
    else cno;
    return 0;
}


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

int main() {
  int n,x;
  cin >> n >> x;
  int count=1;
  int temp=0;
  for(int i=0;i<n;i++) {
    int num;
    cin >> num;
    temp+=num;
    if(temp<=x) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[100];
long long gcd(long long a, long long b) { return !b?a:gcd(b, a%b); }
int main() {
	long long n;
	cin>>n;
	for (long long i=0; i<n;i++) cin>>a[i];
	sort(a, a+n);
	for (long long i=2; i<n; i++) a[i]=a[i]<<(i-1);
	
	long long s=0;
	for (long long i=0; i<n; i++) s=s+a[i];
	long long t=(1LL<<(n-1));
	long long g = gcd(s, (1LL<<(n-1)));
	s/=g;
	t/=g;
	double ans = s/t + (double)(s%t)/t; 
	printf("%lf", ans);
	return 0;
}

Measured memory_bytes: 256
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

func check(st []int, N int, s []byte) bool {

	for i := 2; i < N; i++ {
		a := st[i-2]
		b := st[i-1]
		if b == 0 { // 羊
			if s[i-1] == 'o' {
				st[i] = a
			} else {
				if a == 0 {
					st[i] = 1
				} else {
					st[i] = 0
				}
			}
		} else { // 狼
			if s[i-1] == 'x' {
				st[i] = a
			} else {
				if a == 0 {
					st[i] = 1
				} else {
					st[i] = 0
				}
			}
		}
	}

	ans0 := false
	// 先頭が正しいかチェック
	x := st[1]
	y := st[N-1]
	if st[0] == 0 {
		if s[0] == 'o' && x == y {
			ans0 = true
		} else if s[0] == 'x' && x != y {
			ans0 = true
		}
	}
	if st[0] == 1 {
		if s[0] == 'x' && x == y {
			ans0 = true
		} else if s[0] == 'o' && x != y {
			ans0 = true
		}
	}

	ans1 := false
	// 先頭が正しいかチェック
	x = st[N-2]
	y = st[0]
	if st[N-1] == 0 {
		if s[N-1] == 'o' && x == y {
			ans1 = true
		} else if s[N-1] == 'x' && x != y {
			ans1 = true
		}
	}
	if st[N-1] == 1 {
		if s[N-1] == 'x' && x == y {
			ans1 = true
		} else if s[N-1] == 'o' && x != y {
			ans1 = true
		}
	}

	return (ans0 && ans1)
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 100000)

	var N int
	fmt.Scan(&N)
	s, _, _ := r.ReadLine()

	//out(N, string(s))

	st0 := make([]int, N)

	st0[0] = 0
	st0[1] = 0
	res := check(st0, N, s)
	if res == false {
		st0[0] = 1
		st0[1] = 0
		res = check(st0, N, s)
	}
	if res == false {
		st0[0] = 0
		st0[1] = 1
		res = check(st0, N, s)
	}
	if res == false {
		st0[0] = 1
		st0[1] = 1
		res = check(st0, N, s)
	}

	if res == false {
		out(-1)
	} else {
		w := bufio.NewWriter(os.Stdout)
		for i := 0; i < N; i++ {
			if st0[i] == 0 {
				fmt.Fprint(w, "S")
			} else {
				fmt.Fprint(w, "W")
			}
		}
		fmt.Fprint(w, "\n")
		w.Flush()
	}
}


Measured memory_bytes: 3328
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[100000];
int main(){
  int i=0, res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
    }
  }
  while(i != 1 && res < N){
    res++;
    i = A[i];
  }
  if(res==N){
    wt_L(-1);
    wt_L('\n');
  }
  else{
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int N, A[1d5];
// {
//   int i = 0, res = 0;
//   rd(N,(A--)(N));
//   while(i != 1 && res < N){
//     res++;
//     i = A[i];
//   }
//   wt( if[res==N, -1, res] );
// }


Measured memory_bytes: 640
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int s = in.nextInt() + in.nextInt() + in.nextInt() + in.nextInt();
        int t = in.nextInt() + in.nextInt() + in.nextInt() + in.nextInt();
        System.out.println(Math.max(s, t));
    }
}


Measured memory_bytes: 26180
d[1001],c;
main(w,n,i,C,W,b)
{
  for(;scanf("%d",&w),w;printf("Case %d:\n%d\n%d\n",++c,d[w],b),bzero(d,4004))
    for(scanf("%d",&n);i=n--;)
        for(i=w,scanf("%d,%d",&C,&W);i>=W;i--)
            d[i]=fmax(d[i],d[i-W]+C),b=d[i]-d[w]?b:i;
}

Measured memory_bytes: 0
n = int(input())
h = list(map(int, input().split()))
x = h[-1]
ans = "Yes"
for i in reversed(range(n - 1)):
    hi = h[i]
    if hi <= x:
        pass
    else:
        if abs(x - hi) >= 2:
            ans = "No"
        else:
            h[i] -= 1
    x = h[i]
print(ans)


Measured memory_bytes: 14396
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    K = int(input())
    A, B = map(int, input().split())
    ok = 0
    for k in range(A, B+1):
        if k % K == 0:
            ok = 1
            break
    if ok:
        print("OK")
    else:
        print("NG")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62088
import itertools

N, M, X = [int(i) for i in input().split()]
CA = [] # (C, A)
A = []
for i in range(N):
    c, *a = [int(i) for i in input().split()]
    CA.append((c, a))

min_c = 12 * 10**5 + 1
for x in range(1, N+1):
    for ca in itertools.combinations(CA, x):
        tmp_a = [0 for _ in range(M)]
        tmp_c = 0
        for s in ca:
            tmp_c += s[0]
            tmp_a = [tmp_a[j]+s[1][j] for j in range(M)]
        if min(tmp_a) >= X:
            min_c = min(min_c, tmp_c)

if min_c == 12 * 10**5 + 1:
    print(-1)
else:
    print(min_c)


Measured memory_bytes: 9216
line = input().split()
setl = set(line)
data = list(setl)
value = [0] * len(setl)
dic = {}
i = maxlen = 0
maxstr = ""
for s in setl:
  if len(s) > maxlen:
    maxlen = len(s)
    maxstr = s
  dic.update({s: i})
  i += 1
for l in line:
  value[dic[l]] += 1
m = max(value)
for i in range(len(data)):
  if value[i] == m:
    print(data[i], maxstr)
    break



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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,q,d[100001];
long long s=0;

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        int x;
        scanf("%d",&x);
        d[x]++;
        s+=x;
    }
    scanf("%d",&q);
    while (q--)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        s+=d[u]*v-d[u]*u;
        d[v]+=d[u];
        d[u]=0;
        cout<<s<<"\n";
    }
}

int main()
{
    nhap();
    return 0;
}


Measured memory_bytes: 4092
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	x := io.NextInt()
	found := false
	for a := 1; pow(a, 5)-pow(a-1, 5) <= x; a++ {
		if found {
			break
		}
		for b := a - 1; pow(a, 5)-pow(b, 5) <= x; b-- {
			if pow(a, 5)-pow(b, 5) == x {
				io.Println(a, b)
				found = true
				break
			}
		}
	}
}

func pow(base, n int) int {
	ret := 1
	for n > 0 {
		if n&1 == 1 {
			ret *= base
		}
		base *= base
		n >>= 1
	}
	return ret
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1776
#include<stdio.h>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
  int N, Y;
  scanf("%d %d", &N, &Y);
  for (int x = 0 ; x <= N ; x++) {
    for (int y = 0 ; y <= N - x ; y++) {
      if (10000 * x + 5000 * y + 1000 * (N - x - y) == Y) {
        printf("%d %d %d\n", x, y, N - x - y);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = getInt(sc);
		int b = getInt(sc);

		if (a * b % 2 == 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n, k;
  cin >> n >> k;
  vi h(n);
  rep (i, n) {
    cin >> h[i];
  }
  vi dp(n, inf);
  dp[0] = 0;
  rep1 (i, n - 1) {
    rep1 (j, k) {
      if (i - j < 0) continue;
      chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[n - 1] << endl;
}
  


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
set<char> st;
string s;
int main(int argc,char const* argv[])
{
  int a,b;
  cin >> a >> b;
  int c1=a+b,c2=a-b,c3=a*b;
  int ans=max(c1,c2);
  ans=max(ans,c3);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int P = 998244353;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, S;
    cin >> N >> S;
    vector<int> nums(N);
    for(int i = 0 ; i < N ; ++i){
        cin >> nums[i];
    }
    vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(S+1, vector<int>(3, 0)));
    dp[0][0][1] = 1;
    for(int i = 1 ; i < N+1 ; ++i){
        dp[i][0][0] = 1;
        dp[i][0][1] = 1 + dp[i-1][0][1];
        dp[1][0][1] = 1;
        for(int j = 1 ; j < S+1; ++j){
            dp[i][j][1] = dp[i-1][j][1];
            if(j-nums[i-1] >= 0){
                dp[i][j][1] += dp[i-1][j-nums[i-1]][1];
                dp[i][j][1] += dp[i-1][j-nums[i-1]][0];
                dp[i][j][1] %= P;
            }
            dp[i][j][2] = dp[i-1][j][2] + dp[i][j][1];
            dp[i][j][2] %= P;
        }
    }
    
    int ret = 0;
    ret = dp[N][S][2];
/*
    for(int i = 0 ; i < N+1; ++i){
        cout << dp[i][S][2] << endl; 
        ret += dp[i][S][2];
        ret %= P;
    }
*/
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 493056
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
 
int main()
{
    int q, lim, query, x, incubatorcnt;
    vector<int> List;
    vector<int>::iterator it;
    while(scanf("%d %d", &q, &lim) && q > 0)
    {
		incubatorcnt = 0;
        for(int f1 = 1; f1 <= q; f1++){
            scanf("%d %d",&query, &x);
            switch(query)
            {
                case 0:
                    List.push_back(x);
					incubatorcnt++;
					#if 0
                    if((int)List.size() > lim){
                        it = List.begin();
                        List.erase(it);
                    }
					#else
					if(incubatorcnt > lim){
                        it = List.begin();
                        List.erase(it);
						incubatorcnt--;
                    }
					#endif
                break;
                case 1:     
                    it = List.begin() + (x - 1);
                    List.erase(it);
					incubatorcnt--;
                break;
                case 2:
                    it = List.begin() + (x - 1);
                    printf("%d\n", *it);
                break;
				default:
					#if 0
					it = List.begin();
                    while(*it != x)
                        it++;
					#else
					it = find(List.begin(), List.end(), x);
					#endif
                    List.erase(it);
					incubatorcnt--;
                break;
            }
        }
        printf("end\n");
        List.clear();
    }
    return 0;
}

Measured memory_bytes: 1720
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

map<int, int> prime_fac(int n) {
  map<int, int> ret;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

signed main() {
  int n;
  cin >> n;
  vector<int> cnt(101, 0);
  loop(i, 1, n + 1) {
    auto tmp = prime_fac(i);
    for (auto x : tmp) cnt[x.first] += x.second;
  }

  int ans = 0;
  loop(i, 1, n + 1) if (74 <= cnt[i]) ans++;
  loop(i, 1, n + 1) loop(j, 1, n + 1) if (i != j && 24 <= cnt[i] && 2 <= cnt[j]) ans++;
  loop(i, 1, n + 1) loop(j, 1, n + 1) if (i != j && 14 <= cnt[i] && 4 <= cnt[j]) ans++;
  loop(i, 1, n + 1) loop(j, 1, n + 1) loop(k, j + 1, n + 1) if (i != j && i != k && 2 <= cnt[i] && 4 <= cnt[j] && 4 <= cnt[k]) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer(16) :: n,i,s_n,ans=0

read*, n

s_n = int(sqrt(real(n,8)),16) + 1

do i = 1, s_n, 1
  if ( mod(n,i) == 0 ) then
    if ( i /= 1 ) then
      if ( mod(n,i-1) == n/(i-1) ) then
        ans = ans + (i-1)
      end if
    end if
    if ( n/i /= 1 ) then
      if ( mod(n,n/i-1) == n/(n/i-1) ) then
        ans = ans + (n/i-1)
      end if
    end if
  end if
end do

print'(i0)', ans

END PROGRAM ATCODER

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

using namespace std;

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

    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];

    vector<int> v_sort(n);
    copy(v.begin(), v.end(), v_sort.begin());
    sort(v_sort.begin(), v_sort.end());

    for (int i = 0; i < n; ++i) {
        if (v[i] == v_sort[n - 1])
            cout << v_sort[n - 2] << '\n';
        else
            cout << v_sort[n - 1] << '\n';
    }
}


Measured memory_bytes: 3200
function main(input){
    let lines = input.split("\n");
    let length = parseInt(lines[0]);
    let nums = lines[1].split(" ").map(item=>parseInt(item));
    let answer = [];
    for(let i=0;i<length;i++){
        answer.push(nums.pop());
    }
    console.log(answer.join(" "));

}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 15388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;
const long double PI=3.14159265358979323846264;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	long double A,B,H,M; cin>>A>>B>>H>>M;
	M+=H*60;
	long double ang=5.5*M;
	cout<<fixed<<setprecision(25);
	cout<<sqrt(A*A+B*B-2*A*B*cos(ang*PI/180.0));
	return 0;
}

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

int main() {
int P;
  int Q;
  int R;
  cin>>P>>Q>>R;
  if(P+Q<=P+R&&P+Q<=Q+R){
    cout<<P+Q<<endl;
  }
  else if(P+R<=P+Q&&P+R<=Q+R){
    cout<<P+R<<endl;
  }
  else if(Q+R<=P+Q&&Q+R<=P+R){
    cout<<Q+R<<endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var input = Reads();
        var n = input[0];
        var m = input[1];


        var count =new long[m];
        for (int l = 0; l < n; l++)
        {
            var input1 = Reads();
            var k = input1[0];
            var a = new long[k];
            for (int i = 0; i < k; i++)
            {
                a[i] = input1[i + 1];
                for (int j = 0; j < m; j++)
                {
                    if (a[i] == j + 1)
                        count[j]++;
                }
            }
        }
        int count1 = 0;
        for(int i = 0; i < m; i++)
        {
            if (count[i] == n)
                count1++;
        }
        Console.WriteLine(count1);
        Console.Out.Flush();
    }
}

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

int main(int argc, char const *argv[])
{

	int a, b;
	std::string symb;

	std::cin>>a>>b;
	
	if (a<b) {
		symb = "<";
	}
	else if (a>b) {
		symb = ">";
	}
	else {
		symb = "==";
	}

	std::cout<<"a "<<symb<<" b"<<std::endl;
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

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

    sort(a, a+n);

    int cnt = 0;
    reps(i, 1, n){
        if(a[i] == a[i-1]){
            cnt++;
        }
    }

    if(cnt % 2 == 1) cnt++;

    cout << n - cnt << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main(void){
	char t[101];
	int i,n,ans=0;
	while(scanf("%s",t)!=EOF){
		n=strlen(t);
		for(i=0;i<n/2;i++){if(t[i]!=t[n-i-1])break;}
		if(i==n/2)ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 540
while True:
    s = input().split()
    H = int(s[0])
    W = int(s[1])
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            print("#",sep="",end="") #end="" eliminates '\n' 
        print("")

    #print blank
    print("")    



Measured memory_bytes: 7012
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll k, n;
	ll fs = -1, ls;
	ll a,pa=-1,df=0;
	cin >> k >> n;
	for (size_t i = 0; i < n; i++) {
		cin >> a;
		if (fs == -1)
			fs = a;
		else {
			df = max(df, a - pa);
		}
		ls = a;
		pa = a;
	}
	ll a1 = fs + k - (ls);
	cout << k-max(a1, df) << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N-1)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &B[i])
	}
	for i := 0; i < N-1; i++ {
		fmt.Scanf("%d", &C[i])
	}

	sum := 0
	for i := 0; i < N; i++ {
		sum += B[A[i]-1]
		if i < N-1 && A[i]+1 == A[i+1] {
			sum += C[A[i]-1]
		}
	}
	fmt.Println(sum)
}


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

int main() {
	int n; scanf("%d", &n);
	int cnt = 0;
	rep(i, n) {
		int a; scanf("%d", &a);
		if (a == 1)continue;
		bool ok = true;
		for (int j = 2; j*j <= a; j++) {
			if (a%j == 0) { ok = false; break; }
		}
		if (ok)cnt++;
	}
	printf("%d\n", cnt);
}

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

int main(){
	int N;
	long ans=0;
	long total=0;
	long mod=1000000007;
	cin >> N;
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin >> A.at(i);
		total+=A.at(i);
        total%=mod;
	}
	for(int i=0;i<N;i++){
		if(total<A.at(i))
          total+=mod;
      	total-=A.at(i);
		ans+=(total*A.at(i))%mod;
	}
	cout << ans%mod <<endl;
}


Measured memory_bytes: 4008
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = sorted(LI())
    for i in range(n//2):
        if a[i*2+1] <= 0:
            a[i*2] *= -1
            a[i*2+1] *= -1
        else:
            if a[i*2] * -1 > a[i*2+1]:
                a[i*2] *= -1
                a[i*2+1] *= -1
            break

    return sum(a)


print(main())



Measured memory_bytes: 16812
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N, Q;
	ll K;
	cin >> N >> K >> Q;
	vector<int> A(Q);
	for(int i=0; i<Q; i++) cin >> A[i];

	vector<int> x(N);
	for(int i=0; i<Q; i++) x[A[i]-1]++;

	for(int i=0; i<N; i++){
		cout << (K-Q+x[i]>0?"Yes":"No") << endl;
	}

	return 0;
}


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

using namespace std;

int main() {
	string S;
	int K;

	cin >> K >> S;

	if (S.size() <= K) cout << S << endl;
	else {
		for (int i = 0; i < K; i++) {
			cout << S[i];
		}
		cout << "..." << endl;
 	}

	return 0;
}


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

using namespace std;

void mark(int a[3][3], int b) {
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (a[i][j] == b) {
        a[i][j] = 0;
        return;
      }
    }
  }
}
bool check(int a[3][3]) {
  // check rows
  for (int i = 0; i < 3; ++i) {
    if (a[i][0] + a[i][1] + a[i][2] == 0) return true;
  }
  // check columns
  for (int i = 0; i < 3; ++i) {
    if (a[0][i] + a[1][i] + a[2][i] == 0) return true;
  }

  if (a[0][0] + a[1][1] + a[2][2] == 0) return true;
  if (a[0][2] + a[1][1] + a[2][0] == 0) return true;

  return false;
}

int main() {
  int a[3][3];
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }
  int n, b;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> b;
    mark(a, b);
  }
  if (check(a)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3592
#region using
using System;
using System.Collections.Generic;
using System.Linq;
using IEnumerable = System.Collections.IEnumerable;
using IEnumerator = System.Collections.IEnumerator;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;
#endregion

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            return Math.Abs(consoleReader.Long - consoleReader.Long) > 1 ? "Alice" : "Brown";
        }


        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    static class Ext
    {
        public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count());
        public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i);
    }
    public class ConsoleReader { private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); private string[] line = Array.Empty<string>(); private int linePosition; private TextReader textReader; public ConsoleReader(TextReader tr) { textReader = tr; } public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string String { get { if (linePosition >= line.Length) { linePosition = 0; line = ReadLineSplit(); } return line[linePosition++]; } } public class SplitLine { private string[] splited; public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); } public int[] Int => String.Select(x => int.Parse(x)).ToArray(); public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray(); public long[] Long => String.Select(x => long.Parse(x)).ToArray(); public double[] Double => String.Select(x => double.Parse(x)).ToArray(); public string[] String => splited; } public SplitLine Split => new SplitLine(this); public class RepeatReader : IEnumerable<ConsoleReader> { ConsoleReader cr; int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public IEnumerable<string> String => this.Select(cr => cr.String); public IEnumerable<int> Int => this.Select(cr => cr.Int); public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1); public IEnumerable<long> Long => this.Select(cr => cr.Long); public IEnumerable<double> Double => this.Select(cr => cr.Double); } public RepeatReader Repeat(int count) => new RepeatReader(this, count); }
    #endregion
}


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

int main() {
  string s; cin>>s;
  int n=s.size();
  if (n==2) {
    if (s[0]==s[1]) cout<<"1 2"<<endl;
    else cout<<"-1 -1"<<endl;
    return 0;
  }

  for(int i=0;i<n-2;i++) {
    if (s[i]==s[i+1]) {
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    } else if (s[i]==s[i+2]) {
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    } else if (s[i+1]==s[i+2]) {
      cout<<i+2<<" "<<i+3<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
}

Measured memory_bytes: 512
//It's time to be who I am, rather than who I am supposed to be.
#include<bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 1e5+10;
const int mod = 998244353;
const int inf = 1e18;
int n, h[N], dp[N];

int solve(int n){
	if(n <= 0)
		return inf;

	int &ans = dp[n];
	if(ans != inf)
		return ans;
	ans = min(abs(h[n] - h[n-1]) + solve(n-1), abs(h[n] - h[n-2]) + solve(n-2));
	return ans;
}

int32_t main(){
	ios::sync_with_stdio(false);
   cin.tie(NULL); cout.tie(NULL);

 

    fill(dp, dp + N, inf);
    cin >> n;
    for(int i = 1; i <= n; i++)
    	cin >> h[i];
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    cout << solve(n) << '\n';

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt[2] = {};
    for (char c : s) {
        if (c == 'R') ++cnt[0];
        else ++cnt[1];
    }
    int ans = 1e9, cur = 0;
    for (int i = 0; i <= n; i++) {
        int red = i, white = n - i;
        int res = abs(red - cnt[0]);
        int C = max(0ll, red - cnt[0]);
        ans = min(ans, res + max(0ll, cur - C));
        if (i < n) {
            if (s[i] == 'W') ++cur;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3736
X,K,D=map(int,input().split())
if X>0 and abs(X)>abs(K*D):
  print(X-K*D)
  exit()
elif X<0 and abs(X)>abs(K*D):
  print(abs(X)-abs(K*D))
  exit()
d,r=divmod(abs(X),D)
if (K-d)%2==0:
  print(abs(r))
else:
  print(abs(D-r))

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

constexpr double D_INF = 1e+60;

using Pos = array<double, 2>;
using Pi = pair<double, ll>;

double distance(const Pos& a, const Pos& b) {
    double dx = a[0] - b[0];
    double dy = a[1] - b[1];
    return sqrt(dx * dx + dy * dy);
}

double dist[1005][1005];

void solve() {
    Pos xs, xt;
    cin >> xs[0] >> xs[1];
    cin >> xt[0] >> xt[1];
    ll N;
    cin >> N;
    vector<pair<Pos, double>> bs(N);
    for (ll i = 0; i < N; i++) {
        Pos c;
        double r;
        cin >> c[0] >> c[1] >> r;
        bs[i] = {c, r};
    }

    for (ll i = 0; i < N + 2; i++) {
        for (ll j = 0; j < N; j++) {
            dist[i][j] = D_INF;
        }
    }
    for (ll i = 0; i < N + 2; i++) {
        dist[i][i] = 0.0;
    }

    // バリア同士
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            double d = distance(bs[i].first, bs[j].first) - bs[i].second - bs[j].second;
            if (d > 0.0) {
                dist[i][j] = dist[j][i] = d;
            }
            else {
                dist[i][j] = dist[j][i] = 0.0;
            }
        }
    }

    // スタートとバリア
    for (ll i = 0; i < N; i++) {
        double d = distance(xs, bs[i].first) - bs[i].second;
        if (d > 0.0) {
            dist[i][N] = dist[N][i] = d;
        }
        else {
            dist[i][N] = dist[N][i] = 0.0;
        }
    }

    // ゴールとバリア
    for (ll i = 0; i < N; i++) {
        double d = distance(xt, bs[i].first) - bs[i].second;
        if (d > 0.0) {
            dist[i][N + 1] = dist[N + 1][i] = d;
        }
        else {
            dist[i][N + 1] = dist[N + 1][i] = 0.0;
        }
    }

    // スタートとゴール
    {
        double d = distance(xs, xt);
        dist[N][N + 1] = dist[N + 1][N] = d;
    }

    vector<double> costs(N + 2, D_INF);
    priority_queue<Pi, vector<Pi>, greater<Pi>> pq;
    costs[N] = 0.0;
    pq.emplace(0.0, N);
    while (!pq.empty()) {
        double co;
        ll idx;
        tie(co, idx) = pq.top();
        pq.pop();
        if (co > costs[idx]) continue;
        for (ll i = 0; i < N + 2; i++) {
            double nco = co + dist[idx][i];
            if (nco >= costs[i]) continue;
            pq.emplace(nco, i);
            costs[i] = nco;
        }
    }

    cout << setprecision(20) << costs[N + 1] << endl;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 13940
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    int n = sc.nextInt();
    if (n == 3 || n == 5 || n == 7) {
      out.println("YES");
    } else {
      out.println("NO");
    }

    out.flush();
    out.close();
  }

  /*
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 22612
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int a, b, h;

  std::cin >> a >> b >> h;

  std::cout << (a + b) * h / 2 << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	double a[11],d,sum=0;
	int i;
	
	while(scanf("%lf",&d)!=EOF){
	a[1]=d;
	for(i=2;i<11;i++){
		if(i%2==0)a[i]=a[i-1]*2;
		else a[i]=a[i-1]/3;
	}
	for(i=1;i<11;i++)sum=sum+a[i];
	printf("%0.8f\n",sum);
	sum=0;
	}
return 0;
}

Measured memory_bytes: 1080
import math

while True:
  n = int(input())

  if n == 0: break

  data = input().split()

  average = 0.0

  for i in data:
    average += int(i)

  average /= n 

  s_th_power = 0.0

  for i in data:
    s_th_power += (int(i)-average) * (int(i)-average)

  s_th_power /= n

  s = 0.0

  s = math.sqrt(s_th_power)

  print("%.8f"%s)


Measured memory_bytes: 5688