akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), k = inp.nextInt();
            long[][] dp = new long[n][k+1];
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = inp.nextInt();
            for (int i = 0; i <= a[0]; i++) dp[0][i] = 1;
            long MOD = 1000000007;

            for (int i = 1; i < n; i++) {
                int l = 0, r = -1;
                long sum = 0;
                for (int j = 0; j <= k; j++) {
                    r++;
                    sum += dp[i-1][r];
                    if (r - l > a[i]) {
                        sum -= dp[i-1][l];
                        l++;
                    }
                    dp[i][j] = sum % MOD;
                }
            }
            out.print(((dp[n-1][k] % MOD) + MOD) % MOD);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}




Measured memory_bytes: 126548
def main():
    N, M, K=map(int, input().split())
    friend_or_block = [0 for _ in range(N)]
    friends_chain = UnionFindTree(N)

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        friends_chain.unite(a, b)
        friend_or_block[a] += 1
        friend_or_block[b] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if friends_chain.same(c, d):
            friend_or_block[c] += 1
            friend_or_block[d] += 1

    print(' '.join(map(str, [friends_chain.count(i) - friend_or_block[i] - 1 for i in range(N)])))

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def root(self, x):
        p, seq = self.parent[x], list()
        while p >= 0:
            seq.append(x)
            x, p = p, self.parent[p]
        for c in seq: self.parent[c] = x
        return x

    def same(self, x, y): return self.root(x) == self.root(y)

    def count(self, x): return -self.parent[self.root(x)]

    def unite(self, x, y):
        if self.count(x) < self.count(y): x, y = y, x
        xr, yr = self.root(x), self.root(y)
        if xr == yr: return
        self.parent[xr] += self.parent[yr]
        self.parent[yr] = xr

if __name__ == '__main__':
    main()



Measured memory_bytes: 18144
from fractions import gcd
import copy


def coprime2(a, b):
    return gcd(a, b) == 1


def main():
    A, B = [int(i) for i in input().split()]

    A_l = divisor(A)
    B_l = divisor(B)
    AB_l = set()
    for a in A_l:
        if a in B_l:
            AB_l.add(a)
    AB_l = sorted(list(AB_l))
    tmp = set(AB_l)
    ans = []
    for i, a in enumerate(AB_l):
        if a not in tmp:
            continue
        try:
            tmp.remove(a)
        except:
            pass
        for b in list(tmp):
            if gcd(a, b) != 1:
                try:
                    tmp.remove(b)
                except:
                    pass
        else:
            ans.append(a)

    print(len(ans))


def divisor(n):
    i = 1
    table = set()
    while i * i <= n:
        if n % i == 0:
            table.add(i)
            table.add(n//i)
        i += 1
    return table


if __name__ == "__main__":
    main()


Measured memory_bytes: 7224
#include <stdio.h>

/* Macro definition */
#define MAX 20001

/* Struct declaration */
struct pair {
  int x;
  int ar;
};

/* Prototype declaration */
void push_stack1(int);
void push_stack2(int, int);
int returnTopElement(void);
int pop_stack1(void);
struct pair pop_stack2(void);

/* Grobal variable */
int top_stack1 = 0, top_stack2 = 0;

/* Stack */
int stack1[MAX];
struct pair stack2[MAX];

int main() {
  int i, j;
  int sum = 0, a;
  struct pair c;
  char input[MAX];

  /* Input */
  scanf("%s", input);

  /* Process */
  for (i = 0; input[i] != '\0'; i++) {
    if(input[i] == '\\') push_stack1(i);
    else if((input[i] == '/') && (top_stack1 > 0)) {
      j = pop_stack1();
      sum += i - j;
      a = i - j;
      while ((top_stack2 > 0) && stack2[top_stack2 - 1].x > j) {
        a += stack2[top_stack2 - 1].ar ;
        c = pop_stack2();
      }
      push_stack2(j, a);
    }
  }

  /* Output */
  printf("%d\n", sum);
  printf("%d", top_stack2);
  for(i = 0; i < top_stack2; i++) {
    if(i < top_stack2) printf(" ");
    printf("%d", stack2[i].ar);
  }
  printf("\n");


  return 0;
}

void push_stack1(int x) {
  stack1[top_stack1] = x;
  top_stack1++;
}

void push_stack2(int j, int a) {
  stack2[top_stack2].x = j;
  stack2[top_stack2].ar = a;
  top_stack2++;
}

int pop_stack1(void) {
  int r = 0;

  top_stack1--;
  
  if(top_stack1 < 0) {
    top_stack1 = 0;
    return 0;
  }
  r = stack1[top_stack1];
  return r;

}

struct pair pop_stack2(void) {
  struct pair s;

  top_stack2--;
  
  if(top_stack2 < 0) {
    top_stack2 = 0;
    return;
  }
  s = stack2[top_stack2];
  return s;

}

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007

typedef long long ll;

ll get_gcd(ll a, ll b) {
  if(b == 0) return a;
  return get_gcd(b, a%b);
}

int main() {
  ll first, second;
  cin >> first >> second;
  vector<ll> yaku_f, yaku_s;
  
  ll count = 1;
  ll c = get_gcd(first, second);
  if(c % 2 == 0) {
    count++;
    while(c % 2 == 0) {
      c = c / 2;
    }
  }
  for(ll i = 3; i*i <= c; i+=2) {
    if(c%i != 0) continue;
    count++;
    while(c % i == 0) {
      c = c / i;
    }
  }
  if(c!=1) count++;

  printf("%d\n", count);
  return 0;
}

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

int main (){
	int a,b,c,d;cin>>a>>b>>c>>d;
	if(abs(a-c)<=d) puts("Yes");
	else if(abs(a-b)<=d&&abs(b-c)<=d) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

int main() {
    cin >> N >> K;
    ll a = (N/K)*(N/K)*(N/K);
    if(K%2==1){
        cout << a;
    }else{
      ll b = (N/(K/2)) - N/K;
        cout << a+b*b*b;
    }
} 



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

int main() 
{
    int N;
    cin>>N;
    deque<int>W;
    for (int i = 0; i < N; i++)
    {
        int w;
        cin>>w;
        W.push_back(w);
    }

    int front=W.front();
    W.pop_front();
    auto T=abs(front-(accumulate(W.begin(),W.end(),0)));
    for (int i = 1; i < N; i++)
    {
        front+=W.front();
        W.pop_front();
        auto t=abs(front-(accumulate(W.begin(),W.end(),0)));
        if (T>t)
        {
            T=t;
        }   
    }
    
    cout<<T<<endl;
    
    return 0;
}

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

int main() {

  ll H;
  cin >> H;

  ll n = 0;
  do {
    n++;
  } while (pow(2, n) <= H);

  ll ret = (1 - pow(2, n)) / (1 - 2);
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

const int MaxN = 2e5 + 5;

char S[MaxN];
long long Pred[MaxN][26], L, R, T;
int Next[MaxN], n;

void InitPred()
{
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < 26; j++) Pred[i][j] = Pred[i - 1][j];
		Pred[i][S[i] - 'a']++;
	}
}

void Kmp()
{
	Next[1] = 0;
	for (int j = 0, i = 2; i <= n; i++)
	{
		for (; j > 0 && S[j + 1] != S[i]; j = Next[j]);
		if (S[j + 1] == S[i])
			j++;
		Next[i] = j;
	}
}

void SwapOffset(long long &a, long long &b)
{
	long long tmp = b;
	b += a;
	a = tmp;
}

long long Fib(long long len, int c)
{
	if (len <= n)
		return Pred[len][c];
	if (len <= n * 2)
		return Pred[n][c] + Pred[len - n][c];
	long long f1 = Pred[n][c], f2 = Pred[n][c] + Pred[T][c], l1 = n, l2 = n + T, tmp;
	while (len > l1 + l2)
	{
		SwapOffset(f1, f2);
		SwapOffset(l1, l2);
	}
	return f2 + Fib(len - l2, c);
}

long long Calc(long long len, int c)
{
	if (len <= n)
		return Pred[len][c];
	if (len <= n * 2)
		return Pred[n][c] + Pred[len - n][c];
	if (n % T == 0)
	{
		long long res = 1LL * (len - n) / T * Pred[T][c] + Pred[n][c];
		len -= n, len %= T;
		return res + Pred[len][c];
	}
	else
		return Fib(len, c);
}

int main()
{
	scanf("%s%lld%lld", S + 1, &L, &R);
	n = strlen(S + 1) / 2;
	InitPred();
	Kmp();
	T = n - Next[n];
	for (int i = 0; i < 26; i++)
		printf("%lld%c", Calc(R, i) - Calc(L - 1, i), i == 25 ? '\n' : ' ');
#ifdef GLOBAL_DEBUG
	system("pause");
#endif
	return 0;
}

Measured memory_bytes: 22528
N, K = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0 for i in range(K+10)] for j in range(N+10)]
mod = int(1e9) + 7
dp[0][0] = 1
for i in range(N):
    pSum = [0 for _ in range(K+10)]
    for j in range(K+1):
        pSum[j + 1] = (pSum[j] + dp[i][j]) % mod
    for j in range(K+1):
        if i >= len(a):
            continue
        dp[i+1][j] = (pSum[j+1] - pSum[max(0, j - a[i])]) % mod
print(dp[N][K])

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M, K = map(int, readline().split())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

A_cum = [0]
B_cum = [0]

for i in range(N):
    A_cum.append(A_cum[i] + A[i])
for i in range(M):
    B_cum.append(B_cum[i] + B[i])

cnt, j = 0, M

for i in range(N + 1):
    if A_cum[i] > K:
        break
    while B_cum[j] > K - A_cum[i]:
        j -= 1
    cnt = max(cnt, i + j)

print(cnt)


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

int main() {
    int N, D, X;
    std::cin >> N >> D >> X;

    int cnt = X;
    int A;
    for (int i = 0; i < N; ++i) {
        std::cin >> A;

        const int a = (D - 1) / A;
        cnt += (1 + a);
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
import re
import sys

s = sys.stdin.readline()
while s:
    for i in range(10):
        tmp = s.replace("X",str(i))
        a,b,c = map(int,re.split("[+=]",tmp))
        if a+b-c == 0:
            if len(str(a)+str(b)+str(c))+2 == len(tmp.rstrip()):
                print(i)
                break
            else:
                continue
    else:
        print("NA")
    s = sys.stdin.readline()

Measured memory_bytes: 7816
from collections import OrderedDict
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
X = OrderedDict([(i + 1, []) for i in range(N)])
for a, b in L:
    X[a].append(b)
    X[b].append(a)
for _, x in X.items():
    print(len(x))


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) {
        print("bust");
    } else {
        print("win");
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
long long pow[10 + 5];
string s;int len;
long long ans = 0;
void dfs(int pos, long long now, long long res) {
	if( pos == len ) {
		ans = ans + res + now;
		return ;
	}
	dfs(pos+1, now*10+s[pos]-'0', res);
	dfs(pos+1, s[pos]-'0', res+now);
}
int main() {
	pow[0] = 1;
	for(int i=1;i<=11;i++)
		pow[i] = pow[i-1] * 10;
	cin >> s;len = s.size();
	dfs(1, s[0]-'0', 0);
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1010;
int n;
LL x[maxn],y[maxn],u[maxn],v[maxn],bs[35];

LL power_int(int a, int b) {
//  LL x = 1;
//  while (b > 0) {x *= a;b--;}
//  return x;
  return bs[b];
}

void work() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

  LL parity = (x[0] + y[0]) % 2;

  for (int i = 0; i < n; i++) if ((x[i] + y[i] - parity) % 2 != 0) {cout<<"-1"<<endl;return;}

    if (parity == 0) {
        cout << 32 << endl;
        for (int i = 30; i > -1; i--) cout << power_int(2, i) << " ";
        cout << 1 << endl;
        for (int i = 0; i < n; i++) x[i]++;
    } else {
        cout << 31 << endl;
        for (int i = 30; i > -1; i--) cout << power_int(2, i) << " ";
        cout << endl;
    }

    for (int i = 0; i < n; i++) u[i] = x[i] + y[i], v[i] = x[i] - y[i];

    for (int i = 0; i < n; i++) {
        for (int j = 30; j > -1; j--) {
            if (u[i] > 0 && v[i] > 0) {cout << 'R'; u[i] -= power_int(2, j); v[i] -= power_int(2, j); }
            else if (u[i] > 0 && v[i] < 0) { cout << 'U'; u[i] -= power_int(2, j); v[i] += power_int(2, j); }
            else if (u[i] < 0 && v[i] > 0) { cout << 'D'; u[i] += power_int(2, j); v[i] -= power_int(2, j); }
            else { cout << 'L'; u[i] += power_int(2, j); v[i] += power_int(2, j);}
        }
        if (parity == 0) cout << 'L';
        cout << endl;
    }
}
int main(){
    bs[0] = 1;
    for (int i=1;i<32;i++) bs[i] = bs[i-1] << 1;
    work();
    return 0;
}


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

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    long[] a = sc.nextLongList(N * 3);
    Arrays.sort(a);
    long ret = 0;
    for (int i = 0; i < N; i ++) {
      ret += a[N * 3 - i * 2 - 2];
    }
    System.out.println(ret);
  }
}




class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else 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;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		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() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 26444
n, m = map(int, input().split())
import math
def fac(x,y):
    z = (math.factorial(x))*(math.factorial(y))
    return z
if abs(n-m) > 1:
    print(0)
else:
    if n-m == 0:
        print((fac(m,n)*2)%(10**9+7))
    else:
        print((fac(m,n))%(10**9+7))
        

Measured memory_bytes: 5176
#include<stdio.h>
long long n,m,k,kk;
int main(void)
{
	scanf("%lld%lld",&n,&m);
	if(m<=n*2)
	{
		printf("%lld",m/2);
	}
	else if(m>2*n)
	{
		k=m-2*n;
		kk=k/4;
		printf("%lld\n",n+kk);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    #define int long long
    int a,b;
    cin>>a>>b;
    int x=0,y=0;

    for(int i=0;i<a;i++)
    {
        x*=10;
        x+=b;
    }

    for(int i=0;i<b;i++)
    {
        y*=10;
        y+=a;
    }

    if(a<b)cout<<y;
    else cout<<x;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		bool win = false;
		rep(i, N) if (A[i] % 2 == 1) win = true;
		cout << (win ? "first" : "second") << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 640
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);


void solve() {
    int n,m;cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }

    int dp[n+1][m+1];
    memset(dp,0, sizeof(dp));
    dp[1][1]=(s[0][0]=='#');
    for(int i=1;i<m;i++){
        if((s[0][i]=='#' && s[0][i-1]=='#') || s[0][i]=='.'){
            dp[1][i+1]=dp[1][i];
        }
        else
            dp[1][i+1]=1+dp[1][i];
    }
    for(int i=1;i<n;i++){
        if((s[i][0]=='#' && s[i-1][0]=='#') || s[i][0]=='.'){
            dp[i+1][1]=dp[i][1];
        }
        else
            dp[i+1][1]=1+dp[i][1];
    }
    for(int i=2;i<=n;i++){
        for(int j=2;j<=m;j++){
            if(s[i-1][j-1]=='.'){
                dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
            }else{
                int op1=INT_MAX,op2=INT_MAX;
                if(s[i-1][j-2]=='#'){
                    op1=dp[i][j-1];
                } else{
                    op1=1+dp[i][j-1];
                }

                if(s[i-2][j-1]=='#'){
                    op2=dp[i-1][j];
                } else{
                    op2=dp[i-1][j]+1;
                }
                dp[i][j]=min(op1,op2);
            }
        }
    }
    cout<<dp[n][m]<<endl;
//    for(int i=0;i<=n;i++){
//        for(int j=0;j<=m;j++){
//            cout<<dp[i][j]<<" ";
//        }
//        cout<<endl;
//    }


}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 2, W = 1e5+5;

long long dp[2][W];
int main(){
	int n, ww;
	cin >> n >> ww;
	vector<int> v(n), w(n);
	for(int i = 0; i < n; ++i)
		cin >> w[i] >> v[i];
	for(int i = n-1; i >= 0; --i){
		for(int j = 0; j <= ww; ++j){
			dp[i&1][j] = dp[(i+1)&1][j];
			if(j - w[i] >= 0)
				dp[i&1][j] = max(dp[i&1][j], dp[(i+1)&1][j-w[i]] + v[i]);
		}
	}
	cout << dp[0][ww];
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    string O, E;
    cin >> O >> E;
    if (O.size() != E.size()) E += ' ';
    rep(i, 0, O.size()){
        cout << O.at(i) << E.at(i);
    }
    cout << endl;
}

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

struct st{
    int first,second,ident;
    bool operator < (st obj) const{
        return this->second < obj.second;
    }
};

signed main(){
    int n;
    while(cin>>n&&n){
        set<pii> free;
        set<st> used;
        free.insert(pii(0,1e9+1));
        rep(i,n){
            char ch;
            cin>>ch;
            if(ch=='W'){
                int num,len;
                cin>>num>>len;
                while(len>0){
                    pii tmp = *(free.begin());
                    free.erase(free.begin());
                    if(tmp.second-tmp.first<=len){  //????????????
                        len -= tmp.second-tmp.first;
                        used.insert(st{tmp.first,tmp.second,num});
                    }
                    else{                           //????????????????????????
                        used.insert(st{tmp.first,tmp.first+len,num});
                        free.insert(pii(tmp.first+len,tmp.second));
                        len = 0;
                    }
                }
            }
            if(ch=='D'){
                int num;
                cin>>num;
                auto itr = used.begin();
                while (itr != used.end()) {
                    if (itr->ident==num) {
                        st tmp = *itr;
                        free.insert(pii(tmp.first,tmp.second));
                        used.erase(itr++);
                    }
                    else itr++;
                }
            }
            if(ch=='R'){
                int pos;
                cin>>pos;
                auto res = used.upper_bound(st{0,pos,0});
                if(res==used.end() || res->first>pos)cout<<"-1"<<endl;
                else{
                    st tmp = *(res);
                    cout<<tmp.ident<<endl;
                }
            }
        }
        cout<<endl;
    }
    
}

Measured memory_bytes: 3448
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define inf (1LL<<31)
#define int long long
typedef long long ll;
#define ld long double
#define N 401 


int n,m;
int rnk[N*N],par[N*N];
vector<pair<int,int>> edge;

void addEdge(int a,int b)
{
    edge.push_back({a,b});
}

int root(int u)
{
    while(u != par[u])
    {
        par[u] = par[par[u]];
        u = par[u];
    }
    return u;
}
void merge(int r1,int r2)
{
    if(rnk[r1] < rnk[r2])
        swap(r1,r2);
    par[r2] = r1;
    if(rnk[r2] == rnk[r1])
        rnk[r1]++;
}
int32_t main()
{
    IOS;

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

    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            if(i+1 < n and v[i+1][j] != v[i][j])
                addEdge((i)*m+j,((i+1)*m)+j);
            if(j+1 < m and v[i][j+1]!=v[i][j])
                addEdge((i)*m+j,(i)*m + j+1);
            rnk[(i)*m+j] = 1;
            par[(i)*m + j] = (i)*m+j;
        }
    }
    for(auto it : edge)
    {
        int a = it.first;
        int b = it.second;
        int r1 = root(a);
        int r2 = root(b);
        if(r1!=r2)
        {
            merge(r1,r2);
        }
    }
    int black[n*m];
    int white[n*m];
    memset(black,0,sizeof(black));
    memset(white,0,sizeof(white));
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
           // cerr << i << " " << j << " " << root((i)*m+j) <<endl;
            if(v[i][j] == '#')
                black[root((i)*m+j)]++;
            else
                white[root((i)*m+j)]++;

        }
    }
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            ans += black[(i)*m+j]*white[(i)*m+j];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 12788
#include <iostream>
using namespace std;
 
int main() {
  int H, W;
  int h, w;
  int calc;
  
  cin >> H;
  cin >> W;
  cin >> h;
  cin >> w;
  
  calc = (H - h) * (W - w);
  
  cout << calc << endl;
  
  return 0;
}

Measured memory_bytes: 256
open Scanf
let rec list_init n f = if n <= 0 then [] else let x = f () in x :: list_init (n-1) f
let () =
  let a = scanf " %d" (fun n -> list_init n (fun _ -> scanf " %s" (fun x -> x))) in
  let b = scanf " %d" (fun m -> list_init m (fun _ -> scanf " %s" (fun x -> x))) in
  List.sort_uniq compare a
  |> List.map (fun x ->
      List.length (List.filter ((=) x) a) - List.length (List.filter ((=) x) b))
  |> List.fold_left max 0
  |> Printf.printf "%d\n"

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

int main(){
  int N;
  string s, t;
  cin >> N >> s >> t;
  string ans(2*N,'?');
  for(int i = 0; i < N; ++i){
    ans[2*i] = s[i];
    ans[2*i+1] = t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int H, W,j,k;
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) break;
        for(j = 0; j < H;j++){
            for(k = 0;k < W; k++){
                if((j % 2 == 1 && k % 2 == 1) || (j % 2 == 0 && k % 2 == 0)) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}




Measured memory_bytes: 1796
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split().Select(elem => long.Parse(elem)).ToArray();
            var answer = 0;
            var moveCount = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (H[i] >= H[i + 1])
                {
                    moveCount++;
                }
                else
                {
                    answer = Math.Max(answer, moveCount);
                    moveCount = 0;
                }
            }

            answer = Math.Max(answer, moveCount);
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 25436
package main

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

var rd = bufio.NewReader(os.Stdin)

// 標準入力から1行読み込む。
func readLine() string {
	buf := make([]byte, 0)
	for {
		l, p, e := rd.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

// 渡された文字列(空白区切りの整数の並び)をintのスライスにする。
func intsFromLine(line string) []int {
	slice := make([]int, 0)
	for _, str := range strings.Split(line, " ") {
		num, err := strconv.Atoi(str)
		if err != nil {
			panic(err)
		}
		slice = append(slice, num)
	}
	return slice
}

func main() {
	_ = intsFromLine(readLine())[0]
	nums := intsFromLine(readLine())
	Q := intsFromLine(readLine())[0]
	count := make([]int, 100001)
	total := 0
	totals := make([]int, 0)

	for _, num := range nums {
		total += num
		count[num]++
	}

	for i := 0; i < Q; i++ {
		buf := intsFromLine(readLine())
		B, C := buf[0], buf[1]
		total += (C - B) * count[B]
		count[C] += count[B]
		count[B] = 0
		totals = append(totals, total)
	}

	for _, t := range totals {
		fmt.Println(t)
	}
}


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

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

    int N;
    cin >> N;

    vector<long> A(N + 1);
    for (int n = 0; n < N + 1; n++) {
        cin >> A[n];
    }

    vector<long> B(N);
    for (int n = 0; n < N; n++) {
        cin >> B[n];
    }

    long count = 0;
    for (int n = 0; n < N; n++) {
        if (B[n] >= A[n]) {
            count += A[n];
            count += min(A[n + 1], B[n] - A[n]);
            A[n + 1] = A[n + 1] - min(A[n + 1], B[n] - A[n]);
        } else {
            count += B[n];
        }
    }

    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 1792
void main(){
	string[] val = inln!string();
	bool a = val[0]=="H";
	bool b = val[1]=="H";
	writeln( a^b?'D':'H');

}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


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


int main()
{
    int n;cin>>n;
    map<char, int> s;
    for(int i = 0; i < n; i++){
        char t;cin>>t;
        s[t]++;
    }
    cout << (s.size() == 4 ? "Four":"Three") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    edges[u-1].append((w, v-1))
    edges[v-1].append((w, u-1))

next_v = deque([(0, 0)])
color = [-1]*n
while next_v:
    d, v = next_v.popleft()
    color[v] = d & 1
    for d2, v2 in edges[v]:
        if color[v2] != -1:
            continue
        next_v.append((d+d2, v2))
print(*color, sep='\n')


Measured memory_bytes: 40824
#include<stdio.h>
int main()
{
  int h,w,i,j;
  while(scanf("%d%d",&h,&w) != EOF)
    {
      if((h==0)&&(w==0)) break;
      for(i=0; i<h; i++)
	{
	  for(j=0; j<w; j++)
	    {
	      printf("#");
	    }
	  printf("\n");
	}
      printf("\n");
    }
   return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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 gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  int ans = 1;
  int now = a;
  if (b == 1){
    cout << 0 << endl;
    return 0;
  }
  while(now<b){
    now += a - 1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}



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

int main(){
  int N;
  bool B;
  cin >> N;

  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      if(N == i * j){
        B = true;
        break;
      }
      else
      B = false;
    }
    if(B)
    break;
  }
  if(B)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> H){
  bool valid = true;
  long long cur_height = H.back();

  for (int i=H.size()-2; i>=0; --i) {
    if (H[i] > cur_height + 1) {
      valid = false;
      break;
    }
    cur_height = std::min(cur_height, H[i]);
  }

  if (valid)
    std::cout << YES << std::endl;
  else
    std::cout << NO << std::endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, std::move(H));
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(int argc, const char *argv[]) {
  int sum = 0;
  vector<int> t(5);
  vector<int> diff(5);
  for(int i = 0; i<5; i++){
    cin >> t[i];
  }

  for(int i = 0; i<5; i++){
    t[i] % 10 == 0 ? diff[i] = 0 : diff[i] = 10 - (t[i] % 10);
    sum += t[i] + diff[i];
  }
  vector<int>::iterator iter = max_element(diff.begin(), diff.end());
  size_t index = distance(diff.begin(), iter);

  cout << sum - diff[index] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char** argv)
{
	while (true)
	{
		int height, width;
		std::cin >> height >> width;

		if (height == 0 && width == 0)
		{
			break;
		}

		for (int h = 0; h < height; ++h)
		{
			for (int w = 0; w < width; ++w)
			{
				if ((h == 0 || h == (height - 1)) ||
					(w == 0 || w == (width - 1)))
				{
					std::cout << "#";
				}
				else
				{
					std::cout << ".";
				}
			}
			std::cout << std::endl;
		}

		std::cout << std::endl;
	}
}


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

int main(){
	ll n ; cin >> n ;
	vector<pair<ll,ll>> vec(n) ;
	for(int i=0;i<n;i++){
		ll a,b ;
		cin >> a >> b ;
		vec.at(i) = make_pair(b,a) ;
	}
	sort(vec.begin(),vec.end()) ;
	ll t = 0 ;
	bool ok = true ;
	for(int i=0;i<n;i++){
		t += vec.at(i).second ;
		if(t>vec.at(i).first){
			ok = false ;
			break ;
		}
	}
	if(ok) cout << "Yes" << endl ;
	else cout << "No" << endl ;
}


Measured memory_bytes: 3328
def main():
  n,x=map(int,input().split())
  from functools import lru_cache
  
  @lru_cache()
  def dfs(n,l,x): #レベルnバーガーで下からx番目までのパティの数
    if n==0:
      return 1
    else:
      t=(l-3)//2
      if x==1:
        return 0
      elif x<=l//2:
        return dfs(n-1,t,x-1)
      elif x==l//2+1:
        return dfs(n-1,t,x-2)+1
      else:
        return dfs(n-1,t,t)+1+dfs(n-1,t,x-t-2)
  print(dfs(n,2**(n+2)-3,x))
if __name__=='__main__':
  main()

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll r;cin>>r;
  cout<<3*r*r<<endl;
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#define NIL -1

using namespace std;

struct Node {
  int parent = NIL, left = NIL, right = NIL;
} T[100];
int n, root;

void preorderTreeWalk (int u) {
  cout << " " << u;

  if (T[u].left != NIL)
    preorderTreeWalk(T[u].left);
  if (T[u].right != NIL)
    preorderTreeWalk(T[u].right);
}

void inorderTreeWalk (int u) {
  if (T[u].left != NIL)
    inorderTreeWalk(T[u].left);

  cout << " " << u;
  
  if (T[u].right != NIL)
    inorderTreeWalk(T[u].right);
}

void postorderTreeWalk (int u) {
  if (T[u].left != NIL)
    postorderTreeWalk(T[u].left);
  
  if (T[u].right != NIL)
    postorderTreeWalk(T[u].right);

  cout << " " << u;
}

int main () {
  int id, left, right;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> id >> left >> right;

    T[id].left = left;
    T[id].right = right;
    
    if (left != NIL)
      T[left].parent = id;
    if (right != NIL)
      T[right].parent = id;
  }

  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) {
      root = i;
      break;
    }
  }

  cout << "Preorder" << endl;
  preorderTreeWalk(root);
  cout << endl;

  cout << "Inorder" << endl;
  inorderTreeWalk(root);
  cout << endl;

  cout << "Postorder" << endl;
  postorderTreeWalk(root);
  cout << endl;

  return 0;
}



Measured memory_bytes: 3120
import sys

input = sys.stdin.readline

N = int(input())
S = input().strip()

dic = {}
ans = 0

for i in range(N-2):
    dic['R'] = S[i+1:].count('R')
    dic['G'] = S[i+1:].count('G')
    dic['B'] = S[i+1:].count('B')
    for j in range(i+1, N-1):
        dic[S[j]] -= 1
        arr = ['R', 'G', 'B']
        if S[i] != S[j]:
            arr.remove(S[i])
            arr.remove(S[j])
            ans += dic[arr[0]]
            if j+j-i <= N-1 and S[j+j-i] == arr[0]:
                ans -= 1

print(ans)

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

#define IOS ios::sync_with_stdio(0)
#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 2e6;
long long int r[N], g[N], cl[N], ans, p1, p2, p3;

void do1 () {
     p3--;
    ans-=r[p1];
    ans+=cl[p3];
    p1++;
}

void do2() {
    p3--;
    ans-=g[p2];
    ans+=cl[p3];
    p2++;
}

int main () {
    IOS;
    long long int n, x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for(int i = 0 ; i < a ; i++ ) cin >> r[i];
    for(int i = 0 ; i < b ; i++ ) cin >> g[i];
    for(int i = 0 ; i < c ; i++ ) cin >> cl[i];
    sort(r,r+a);
    sort(g,g+b);
    sort(cl,cl+c);
    p1 = a, p2 = b, p3 = c;
    for(int i = 0 ; i < x ; i++ ) {
        p1--;
        ans+=r[p1];
    }
    for(int i = 0 ; i < y ; i ++ ) {
        p2--;
        ans+=g[p2];
    }
    while(p3>0) {
        if(p1<a&&cl[p3-1]>r[p1]&&(!(p2<b&&cl[p3-1]>g[p2]))) {
            do1();
        }
        else if(p2<b&&cl[p3-1]>g[p2]&&(!(p1<a&&cl[p3-1]>r[p1]))) {
            do2();
        }
        else if(p2<b&&cl[p3-1]>g[p2]&&p1<a&&cl[p3-1]>r[p1]) {
            if(g[p2]>r[p1])do1();
            else do2();
        }
        else break;
    }
    cout << ans;
}


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

using namespace std;

int sqr(int x){
  return x*x;
}

short mem[1<<24];
int ud[24];

int dfs(int b){
  if(mem[b]>=0)return mem[b];
  mem[b]=0;
  for(int i=0;i<4;i++){
    for(int j=0;j<6;j++){
      for(int k=0;k<j;k++){
	int jx=i*6+j;
	int kx=i*6+k;
	if((b>>jx&1)&&(b>>kx&1)&&!(ud[jx]&b)&&!(ud[kx]&b)){
	  mem[b]=max<int>(mem[b],dfs(b&~(1<<jx)&~(1<<kx))+2);
	}
      }
    }
  }
  return mem[b];
}

int main(){
  for(int n;cin>>n,n;){
    int x[24],y[24],r[24],c[24];
    vector<int> u[24];
    vector<int> cs[4];
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i]>>r[i]>>c[i];
      cs[c[i]-1].push_back(i);
      for(int j=0;j<i;j++){
	if(sqr(x[i]-x[j])+sqr(y[i]-y[j])<sqr(r[i]+r[j])){
	  u[i].push_back(j);
	}
      }
    }
    int m[24];
    int b=0;
    for(int i=0;i<4;i++){
      for(int j=0;j<6;j++){
	if(j<cs[i].size()){
	  b|=1<<i*6+j;
	  m[cs[i][j]]=i*6+j;
	}
      }
    }
    fill(begin(ud),end(ud),0);
    for(int i=0;i<4;i++){
      for(int j=0;j<6;j++){
	if(j<cs[i].size()){
	  for(auto e:u[cs[i][j]]){
	    ud[i*6+j]|=1<<m[e];
	  }
	}
      }
    }
    fill(begin(mem),end(mem),-1);
    cout<<dfs(b)<<endl;
  }
}

Measured memory_bytes: 33980
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] b = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			b[i] = scanner.nextInt();
		}
		int sum = b[0] + b[n - 2];
		for (int i = 1; i < n - 1; i++) {
			sum += Math.min(b[i - 1], b[i]);
		}
		System.out.println(sum);
	}

}


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

using namespace std;

int main() {
    int dp[100005] = {1};

    string S;
    cin >> S;

	for (int i = 0; i < S.size(); i++) {
		if (dp[i] == 0) { continue; }
		if (i + 5 <= S.size() && S.substr(i, 5) == "dream") { dp[i + 5] = 1; }
		if (i + 7 <= S.size() && S.substr(i, 7) == "dreamer") { dp[i + 7] = 1; }
		if (i + 5 <= S.size() && S.substr(i, 5) == "erase") { dp[i + 5] = 1; }
		if (i + 6 <= S.size() && S.substr(i, 6) == "eraser") { dp[i + 6] = 1; }
	}

	if (dp[S.size()] == 1) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }

	return 0;
}

Measured memory_bytes: 896
<?php
  $n = trim(fgets(STDIN));
  $al = [];
  $a = "a";
  for($i=0; $i<26; $i++){
      $al[$i] = $a;
      $a++;
  }
  $ans = "";
  while($n > 0){
      $n--;
      $ans .= $al[$n%26];
      $n = intdiv($n,26);
  }
  echo strrev($ans);

Measured memory_bytes: 15768
#include<bits/stdc++.h>
using namespace std;
char a[2],b[2]; 
int main()
{
	scanf("%s%s",a,b);
	if(a[0]=='1'&&b[0]=='2')
		cout<<"3";
	if(b[0]=='1'&&a[0]=='2')
		cout<<"3";
	if(a[0]=='1'&&b[0]=='3')
		cout<<"2";
	if(b[0]=='1'&&a[0]=='3')
		cout<<"2";
	if(a[0]=='2'&&b[0]=='3')
		cout<<"1";
	if(b[0]=='2'&&a[0]=='3')
		cout<<"1";
	return 0;
}                                  

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

class Program {
    static void Main (string[] args) {
          //1000000007

        //int n = int.Parse(Console.ReadLine ());
        string[] p = Console.ReadLine ().Split(' ');
        int n = int.Parse(p[0]);
        int a = int.Parse(p[1]);
        int b = int.Parse(p[2]);
        
        int densya = n * a;
        int ans = 0;


        if(densya >= b){
            ans = b;
        }else{
            ans = densya;
        }


        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13140