akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
  vector<vector<int> > v;
  while (true) {
    int x,y;
    vector<int> a;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      break;
    } else {
      a.push_back(x);
      a.push_back(y);
      sort(a.begin(),a.end());
      v.push_back(a);
    }
  }

  for (int i=0; i<v.size(); i++) {
    printf("%d %d\n", v[i][0], v[i][1]);
  }
  return 0;
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int a,b,c;
signed main(){
    cin>>a>>b>>c;
    int sum=a+b+c;
    if(sum>=22)puts("bust");
    else puts("win");
    return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
p = list(map(int, input().split()))

max_set = sum(p[:k])
pair = sum(p[:k])
for i in range(n-k):
    pair -= p[i]
    pair += p[i+k]
    if max_set < pair:
        max_set = pair

print((max_set+k)/2)

Measured memory_bytes: 24816
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  int C[8][8];
  for(int i = 0; i < 8; ++i){
    for(int j = 0; j < 8; ++j){
      if(i%2 == 0 and j%2 == 1) C[i][j] = 0;
      else C[i][j] = 1;
    }
  }
  while(q--){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a,--b;
    int ans = 0;
    for(int i = a; i < c; ++i){
      for(int j = b; j < d; ++j){
        ans += C[i][j];
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3216
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class AHarmony {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a, b;
    cin >> a >> b;
    int c = (a + b) / 2;

    if (abs(a - c) == abs(b - c))
        cout << c << endl;
    else
        cout << "IMPOSSIBLE" << endl;
}
};

int main() {
	AHarmony solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: Allen
 *
 * Created on January 12, 2019, 5:13 PM
 */

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <climits>
using namespace std;
typedef long long int lli;
/*
 * 
 */
int main(int argc, char** argv) {
    lli n,w;
    cin>>n>>w;
    lli a,b;
    lli dp[100001];
    for(lli i=1;i<=100000;i++){
        dp[i]=LLONG_MAX-100000000000;
    }
    dp[0]=0;
    for(lli i=0;i<n;i++){
        cin>>a>>b;
        for(lli j=100000;j>=b;j--){
            dp[j]=min(dp[j],dp[j-b]+a);
        }
    }
    lli ans=0;
    for(lli i=0;i<=100000;i++){
        if(dp[i]<=w){
            ans=i;
        }
    }
    printf("%lli",ans);
    return 0;
}



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

using namespace std;
typedef long long ll;

int main(void) {
	ll num, ans = 0;
	cin >> num;
	ans = (num + 1) * num / 2;
	ans -= num;
	cout << ans << "\n";
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int m = n;
    int fx = 0;
    while(m > 0){
        fx += m%10;
        m /= 10;
    }
    string rs;
    if(n%fx == 0) rs = "Yes";
    else rs = "No";
    cout << rs << endl; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  long long X, K, D;
  cin >> X >> K >> D;
  //

  if(X<0)
    X =-X;

  long long after;
  if(X/D < K)
    after = X%D;
  else{
    cout << X-K*D << endl;
    return 0;
  }
  
  long long rest = K-(X/D);

  if(rest%2 == 0) 
    cout << after << endl;
  else
    cout << abs(after-D) << endl;


  return 0;
}


Measured memory_bytes: 3616
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        Scanner sc = new Scanner(is);
        /* read */
        int n = sc.nextInt();

        Map<Integer, List<Integer>> lists = new HashMap<>();

        for (int i = 0; i < n; i++) {
            String s = sc.next();
            List<Integer> list = new ArrayList<>();

            for (int j = 0; j < n; j++) {
                if (s.charAt(j) == '1') {
                    // matrix[i][j] = true;
                    list.add(j);
                }
            }
            lists.put(i, list);
        }

        int max = -1;
        for (int i = 0; i < n; i++) {
            max = Math.max(depth(i, lists, n), max);
        }

        os.println(max);
    }

    private static class Node {
        int node;
        Set<Integer> parents = new HashSet<>();
    }

    private static int depth(int start, Map<Integer, List<Integer>> lists, int N) {
        HashMap<Integer, List<Integer>> tempLists = new HashMap<>();
        for (int j = 0 ; j < N ; j++) {
            tempLists.put(j, new ArrayList<>(lists.get(j)));
        }
        Set<Integer> visited = new HashSet<>();
        Set<Node> curr = new HashSet<>();
        Node s = new Node();
        s.node = start;
        curr.add(s);

        int count = 0;
        while (visited.size() < tempLists.size()) {
            count++;
            Map<Integer, Node> next = new HashMap<>();
            for (Node n : curr) {
                List<Integer> nexts = tempLists.get(n.node);
                for (int nx : nexts) {
                    if (n.parents.contains(nx)) {
                        // parent. ignore
                        continue;
                    }
                    if (visited.contains(nx)) {
                        // visiting again
                        return -1;
                    }
                    Node node;
                    if (next.containsKey(nx)) {
                        node = next.get(nx);
                    } else {
                        node = new Node();
                        node.node = nx;
                        next.put(nx, node);
                    }
                    node.parents.add(n.node);
                }
//                for (Node c : curr) {
                    visited.add(n.node);
//                }
            }
            for (Node n : curr) {

            }
            curr = new HashSet<>(next.values());
        }
        return count;
    }
}

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

template<class T> struct SegmentTree {
    using F = function<T(T, T)>;
private :
    int n;          // size
    T id;           // identity element
    vector<T> node; // data
    F f;            // operation
    F g;            // update
public :
    // sz : size, f : operation, g : update, def : identity
    SegmentTree(int sz, F f, F g, T id) : n(1), f(f), g(g), id(id) {
        while (n < sz) n *= 2;
        node = vector<T>(2*n-1, id);
    }

    // v : vector, f : operation, g : update, def : identity
    SegmentTree(vector<T> v, F f, F g, T id) : n(1), f(f), g(g), id(id) {
        while (n < (int)v.size()) n *= 2;
        node = vector<T>(2*n-1, id);
        for (int i = 0; i < (int)v.size(); i++) node[i+n-1] = v[i];
        for (int i = n-2; i >=0; i--) node[i] = f(node[i*2+1], node[i*2+2]);
    }

    // update
    void update (int i, T x) {
        i += n - 1;
        assert(i < node.size());
        node[i] = g(node[i], x);
        while (i > 0) {
            i = (i-1)/2;
            node[i] = f(node[2*i+1], node[2*i+2]);
        }
    }

    // query [a, b)
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return id;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }

    T query (int a, int b) { return query(a, b, 0, 0, n); }

    T operator[] (int i) const { return node[i+n-1]; } 

};

int main() {
    int n;
    cin >> n;
    vector<long long> h(n), a(n);
    for (auto& e : h) cin >> e;
    for (auto& e : a) cin >> e;
    
    auto f = [](long long a, long long b) { return max(a, b); };
    auto g = [](long long a, long long b) { return a + b; };
    SegmentTree<long long> seg(n+1, f, g, 0);
    
    for (int i = 0; i < n; i++) {
        long long nax = seg.query(0, h[i]);
        seg.update(h[i], nax + a[i]);
    }
    
    cout << seg.query(0, n+1) << endl;
    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> a(N), b(N);
    vector<ll> c(M), d(M);
    // studnets
    REP(i, N) { cin >> a[i] >> b[i]; }
    // checkpoints
    REP(i, M) { cin >> c[i] >> d[i]; }
    REP(i, N) {
        int ans;
        ll dist = INF;
        REP(j, M) {
            if(abs(a[i] - c[j]) + abs(b[i] - d[j]) < dist) {
                dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                ans = j;
            }
        }
        cout << ans + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
nums = [int(input()) for i in range(5)]
ans = 0
min_n = 10
idx = 0
for i in range(5):
    if nums[i] % 10  and min_n > abs(nums[i]%10):
        min_n = abs(nums[i]%10)
        idx = i
for i in range(5):
    if i == idx:
        ans += nums[i]
    else:
        if nums[i] % 10:
            ans += nums[i] + abs(10-nums[i]%10)
        else:
            ans += nums[i]
print(ans)

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

using namespace std;

int main() {
    int n, cnt[26][50] = {};
    string s;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        for (auto c : s) {
            cnt[c - 'a'][i]++;
        }
    }
    for (int i = 0; i < 26; ++i) {
        int k = *min_element(&cnt[i][0], &cnt[i][n]);
        while (k--)
            cout << (char)('a' + i);
    }
    cout << endl;

    return 0;
}

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

using namespace std;


int main() {
    char b;
    cin >> b;

    switch(b) {
        case 'A':
            cout << "T" << endl;
            break;

        case 'T':
            cout << "A" << endl;
            break;

        case 'C':
            cout << "G" << endl;
            break;

        case 'G':
            cout << "C" << endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static int[] Z(string s, int stt)
    {
        var ary = new int[s.Length - stt];
        for (int i = 1, j = 0; i < ary.Length; ++i)
        {
            if (i + ary[i - j] < j + ary[j])
            {
                ary[i] = ary[i - j];
            }
            else
            {
                var k = Math.Max(0, j + ary[j] - i);
                while (i + k < ary.Length && s[k + stt] == s[i + k + stt]) ++k;
                ary[i] = k;
                j = i;
            }
        }
        ary[0] = ary.Length;
        return ary;
    }
    static void Main()
    {
        var sp = ReadLine().Split();
        var k = Parse(sp[1]);
        var s = ReadLine().ToCharArray();
        char c = s[0];
        bool b = false;
        for(int i = 1; i < s.Length; ++i)
        {
            if (c == s[i])
            {
                if (b)
                {
                    b = false;
                    if (--k == 0) break;
                }
            }
            else
            {
                s[i] = c;
                b = true;
            }
        }
        int result = 0;
        for(int i = 0; i < s.Length-1; ++i)
        {
            if (s[i] == s[i + 1]) ++result;
        }
        WriteLine(result);
    }
}


Measured memory_bytes: 13176
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    N = INT()
    xbin = input()
    xdec = int(xbin, 2)
    m = xbin.count('1')

    a = xdec % (m+1)
    b = xdec % (m-1) if m > 1 else 0

    num = [0]*N
    for i in range(1, N):
        num[i] = num[i % bin(i).count('1')] + 1

    for i in range(N):
        if xbin[i] == '0':
            y = ( a + pow(2, N-i-1, m+1) ) % ( m+1 )
            print(num[y] + 1)
        elif m <= 1:
            print(0)
        else:
            y = ( b - pow(2, N-i-1, m-1) ) % ( m-1 )
            print(num[y] + 1)

if __name__ == '__main__':
    solve()

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

typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define all(obj) (obj).begin(), (obj).end()
const ll INF = 1e16;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

ll aN[3000];
// メモ[左端位置][右端位置] = この局面からの結果
ll memo[3010][3010];
bool visited[3010][3010];

ll rec(int turn, int l, int r) {
	// 全部取り切ったので終了
	if (l > r) return 0;
	// 既に見た局面ならメモの内容を返す
	if (visited[l][r]) return memo[l][r];
	// 先手番
	if (!turn) {
		ll mx = -INF;
		chmax(mx, rec(1, l+1, r) + aN[l]);
		chmax(mx, rec(1, l, r-1) + aN[r]);
		// 訪問済にする
		visited[l][r] = true;
		// ここより深い所を探し終わったので結果をメモする
		return memo[l][r] = mx;
	// 後手番
	} else {
		ll mn = INF;
		chmin(mn, rec(0, l+1, r) - aN[l]);
		chmin(mn, rec(0, l, r-1) - aN[r]);
		visited[l][r] = true;
		return memo[l][r] = mn;
	}
}

int main() {
	int N;
	cin >> N;
	rep(i, 0, N) cin >> aN[i];
	cout << rec(0, 0, N-1) << endl;
	return 0;
}


Measured memory_bytes: 78464
from collections import deque
H, W = map(int, input().split())
grid_graph = [list(input()) for _ in range(H)]
# 幅優先で最短経路を求めるだけ
q = deque()
q.append([0, 0])
distance = [[1000]*W for _ in range(H)]
distance[0][0] = 0
adjacent = [[1, 0], [0, 1], [-1, 0], [0, -1]]
while len(q):
    cy, cx = q.popleft()
    for dy, dx in adjacent:
        ny, nx = cy+dy, cx+dx
        if ny < 0 or ny >= H or nx < 0 or nx >= W:
            continue
        if distance[ny][nx] != 1000:
            continue
        if grid_graph[ny][nx] == "#":
            continue
        distance[ny][nx] = distance[cy][cx] + 1
        q.append([ny, nx])
black = 0
if distance[H-1][W-1] == 1000:
    print(-1)
    exit()
for i in range(H):
    for j in range(W):
        if grid_graph[i][j] == "#":
            black += 1
print(H*W - distance[H-1][W-1] - black - 1)  # 最後の-1は出発地点のマスを黒くできない分


Measured memory_bytes: 3316
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n / 2];
        int[] b = new int[n / 2];
        for (int i = 0; i < n / 2; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        int[] oddrec = new int[100000 + 5];
        int[] evenrec = new int[100000 + 5];
        for (int i = 0; i < n / 2; i++) {
            oddrec[a[i]]++;
            evenrec[b[i]]++;
        }
        int[][] odd = new int[100000 + 5][];
        int[][] even = new int[100000 + 5][];
        for (int i = 0; i < oddrec.length; i++) {
            odd[i] = new int[]{i, oddrec[i]};
            even[i] = new int[]{i, evenrec[i]};


        }
        mycom mc = new mycom();
        Arrays.sort(odd, mc);
        Arrays.sort(even, mc);
        int len = odd.length;
        int ans;
        if (odd[len - 1][0] != even[len - 1][0]) {
            ans = n - odd[len - 1][1] - even[len - 1][1];
        } else {
            ans = Math.min(n - odd[len - 1][1] - even[len - 2][1], n - odd[len - 2][1] - even[len - 1][1]);
        }

        System.out.println(ans);

    }
    static class mycom implements Comparator<int[]> {
        public int compare(int[] a, int[] b) {
            return a[1] - b[1];
        }
    }
}

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

int main() {
  int n;
  string s;

  cin >> n >> s;

  int x = 0, max = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'I') x++;
    if(s[i] == 'D') x--;
    if(max < x) max = x;
  }

  cout << max << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

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

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








int main() {
    int n, h, w;
    scanf("%d %d %d", &n, &h, &w);
    printf("%d\n", (n - h + 1) * (n - w + 1));
}

Measured memory_bytes: 256
N,M = map(int,input().split())
ans=0
while True:
    if N > 0 and M >= 2*N:
        ans += N
        M -= 2*N
        N -= N
    elif N > 0 and M < 2*N:
        ans += M//2
        break
    else:
        if M >= 4:
            N += M//4
            M -= M//2
        else:
            break
print(ans)

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

using namespace std;

int main()
{
    string w;                                                  
    cin >> w;
    
    int char_num;
    for (int i = 0; i < w.size(); i++){
        char_num = 0;
        for (int j = 0; j < w.size(); j++){       
            if(w[i] == w[j]){
                char_num += 1;
            }   
        }   
        if(char_num % 2 != 0){
            cout << "No" << endl;
            return 0;
        }   
    }   
    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int cnt[5] = {};
  REP(i, 6) {
    int a; cin >> a;
    cnt[a]++;
  }

  for (int i = 1; i <= 4; ++i) {
    if (cnt[i] > 2) {
      cout << "NO" << endl;;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<int> s(n);
	rep(i,n) cin >>s[i];
	ll sm = accumulate(all(s), 0LL);
	if(sm%10 != 0 ){ cout << sm << endl; return 0;}
	sort(all(s));
	rep(i,n){
		if(s[i]%10 >0){ cout << sm - s[i] << endl; return 0;}
	}
	puts("0");
	return 0;
}



Measured memory_bytes: 256
N = int(input())
dp = [0 for i in range(N+1)]
dp[1] = 1
kazu = [1]
i = 6
while i <= N:
    kazu.append(i)
    i*=6
i = 9
while i <= N:
    kazu.append(i)
    i*=9
kazu.sort()
kazulazor = len(kazu)
temp = [1]
lentemp = 1
index = 1
for i in range(2, N+1):
    kouho = []
    if index < kazulazor and i == kazu[index]:
        temp.append(i)
        index += 1
        lentemp += 1
    for j in range(lentemp):
        kouho.append(dp[i-temp[j]]+1)
    dp[i] = min(kouho)
print(str(dp[N]))

Measured memory_bytes: 3992
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int acCnt = 0;
        int waCnt = 0;
        int tleCnt = 0;
        int reCnt = 0;
        for (int i = 0; i < n; i++) {
            String result = sc.next();
            switch (result) {
                case "AC":
                    acCnt++;
                    break;
                case "WA":
                    waCnt++;
                    break;
                case "TLE":
                    tleCnt++;
                    break;
                case "RE":
                    reCnt++;
                    break;
                default:

            }
        }
        sc.close();
        System.out.println("AC x " + String.valueOf(acCnt));
        System.out.println("WA x " + String.valueOf(waCnt));
        System.out.println("TLE x " + String.valueOf(tleCnt));
        System.out.println("RE x " + String.valueOf(reCnt));
    }
}


Measured memory_bytes: 58792
#include <bits/stdc++.h>
using namespace std;
const int N = 200;

int n, a[N], b[N], f[2][N];

int main()
{
	memset( f, 0, sizeof( f ) );
	scanf( "%d", &n );
	for( int i = 1; i <= n; i ++ )
		scanf( "%d", &a[i] );
	for( int i = 1; i <= n; i ++ )
		scanf( "%d", &b[i] );
		
	f[0][1] = a[1];
	for( int i = 2; i <= n; i ++ )
		f[0][i] = f[0][i-1] + a[i];
	for( int i = 1; i <= n; i ++ )
		f[1][i] = max( f[0][i], f[1][i-1] ) + b[i];
		
	printf( "%d\n", f[1][n] );
	
	return 0;
}

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

int main(){
  ll n,a,b;
  ll na=1,nb=1;
  
  cin>>n;
  while(n--){
    cin>>a>>b;
    ll m = na/a;
    if(na%a) m++;
    if(m<=nb/b){
      m=nb/b;
      if(nb%b) m++;
    }
    na=a*m;
    nb=b*m;
  }
  cout<<na+nb<<endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);

using P = pair<ll, ll>;

int count(const vector<P>& p, const ll& x1, const ll& y1, const ll& x2, const ll& y2) {
  int ans = 0;
  for (auto& d : p) {
    ll x = d.first;
    ll y = d.second;
    if (x1 <= x && x <= x2 && y1 <= y && y <= y2) ans++;
  }
  return ans;
}

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

  int n, k;
  cin >> n >> k;

  vector<P> p;
  vector<ll> x, y;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    p.push_back({a, b});
    x.push_back(a);
    y.push_back(b);
  }

  sort(ALL(x));
  x.erase(unique(x.begin(), x.end()), x.end());
  sort(ALL(y));
  y.erase(unique(y.begin(), y.end()), y.end());

  ll ans = INFLL;
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      for (int s = 0; s < n-1; s++) {
        for (int t = s+1; t < n; t++) {
          if (s == t) continue;
          ll x1 = min(x[i], x[j]);
          ll x2 = max(x[i], x[j]);
          ll y1 = min(y[s], y[t]);
          ll y2 = max(y[s], y[t]);
          if (count(p, x1, y1, x2, y2) >= k) {
            chmin(ans, (x2 - x1) * (y2 - y1));
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

struct R {
  string city;
  int point;
  int index;
  bool operator<(const R& r) const {
    return make_pair(city, -point) < make_pair(r.city, -r.point);
  }
};

int main() {
  in(int, n);
  vector<R> v(n);
  rep(i, n) {
    cin >> v[i].city >> v[i].point;
    v[i].index = i;
  }
  sort(all(v));
  rep(i, n) out(v[i].index + 1);
}


Measured memory_bytes: 3592
from collections import deque
h, w = map(int, input().split())
field = []
check = [[False for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = list(input().strip())
    field.append(s)

sx, sy = 0, 0
d = deque()
dirx = [0, 1, 0, -1]
diry = [1, 0, -1, 0]
d.append([sx, sy])
# 離れ島がないかのチェック
while (d):
    nowx, nowy = d.popleft()
    check[nowx][nowy] = True
    for x, y in zip(dirx, diry):
        nx = nowx + x
        ny = nowy + y
        if nx in range(h) and ny in range(w) and (
                not check[nx][ny]) and field[nx][ny] == '#':
            d.append([nx, ny])
for i in range(h):
    for j in range(w):
        if not check[i][j] and field[i][j] == '#':
            print('Impossible')
            exit()

# 右or下のみの最短でいけるかチェック
d.append([sx, sy])
check = [[False for _ in range(w)] for _ in range(h)]
while (d):
    nowx, nowy = d.pop()
    check[nowx][nowy] = True

    for x, y in zip(dirx[0:2], diry[0:2]):
        nx = nowx + x
        ny = nowy + y
        if nx in range(h) and ny in range(w) and field[nx][ny] == '#':
            d.append([nx, ny])
    for x, y in zip(dirx[2:4], diry[2:4]):
        nx = nowx + x
        ny = nowy + y
        if nx in range(h) and ny in range(
                w) and field[nx][ny] == '#' and not check[nx][ny]:
            print('Impossible')
            exit()

    if len(d) == 2:
        print('Impossible')
        exit()
    if nowx == h - 1 and nowy == w - 1:
        print('Possible')
        exit()

print('Impossible')


Measured memory_bytes: 9440
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<double> p(n);
    for (int i = 0; i < n; i++) std::cin >> p[i];

    std::vector<std::vector<double>> dp(n, std::vector<double>(n + 1));
    dp[0][1] = p[0];
    dp[0][0] = 1 - p[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= i + 1; j++) {
            dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
        }
    }

    double ret = 0;
    for (int i = (n + 1) / 2; i <= n; i++) {
        ret += dp[n - 1][i];
    }
    printf("%.10lf\n", ret);

    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const long double eps = 1e-10;
//const double PI = M_PI; 
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding Space. */
int main(){
  string ans[] = {"Christmas Eve Eve Eve","Christmas Eve Eve","Christmas Eve","Christmas"};
  int d; cin >> d;
  cout << ans[d-22] << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int w = sc.nextInt();

    for(int i = 0 ; i < s.length() ; i++){
      System.out.print(s.charAt(i));
      i += w-1;
    }

  }
}

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

int main() {
int A,B,count=0;
cin>>A>>B;
for(int i=A;i<B+1;i++){
if(10*((i/1000)%10)+i/10000==i%100){
count++;
}
}
cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  int a,b,c;

  cin >> a >>b>>c;

  if(b-a==c-b){
    cout << "YES" << endl;
  }else if(a-b==b-c){
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
    





  return 0;
}
 


Measured memory_bytes: 256
N,K = map(int,input().split())
p = list(map(int,input().split()))

E = []
value=0
#期待値の計算,累積和の計算
for P_i in p:
    value += (1+P_i)/2
    E.append(value)

flag = E[K-1]
#隣接するK項の計算
for k in range(K,N):
    S = E[k] - E[k-K]
    if flag < S:
        flag = S
print(format(flag,'.12f'))

Measured memory_bytes: 24812
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


//??????????????°?????????(????????´??°or?????? , ????°????or?????§???or???) verified AOJ DSL_2,DSL_3
template<class T>
class segtree{
private:
    vector<T> dat;
    int _size;  //the number of leaves
    T _init;
    
public:
    segtree(int __size=0 , T init=numeric_limits<T>::max() ):_size(__size) , _init(init) , dat(4*__size,init){
        if(__size==0)return ;
        int x=1;
        while(x<_size)x*=2;
        _size = x;
    }
    
    void update(int m,T x){
        int i = m+_size;
//        dat[i] += x;    //addition
        dat[i] = x;     //initialize
        while(i!=1){
            dat[i/2] = min(dat[i],dat[i^1]);    //minimum
//            dat[i/2] = max(dat[i],dat[i^1]);    //maximum
//            dat[i/2] = dat[i]+dat[i^1];         //sum
            i/=2;
        }
    }
    
    // call find(s,t)
    T find(int s,int t,int num=1,int a=0,int b=-1){
        if(b==-1)b=_size-1; //I couldn't "int b=_size".
        if(b<s||t<a)return _init;
        if(s<=a&&b<=t)return dat[num];
        return min( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );    //minimum
//        return max( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );    //maximum
//        return find(s,t,num*2,a,(a+b)/2) + find(s,t,num*2+1,(a+b)/2+1,b);           //sum
    }
    int size(){return _size;}
};

/*
 segtree<int> x(100);                                                //100 datas
 segtree<pair<int,int>> x( 100,make_pair( 1<<31-1 , 1<<31-1 ) );     //100 datas
 */



int main(){
    int n,q;
    cin>>n>>q;
    segtree<int> st(n);
    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        
        if(com==0)st.update(x,y);
        else cout<<st.find(x,y)<<endl;
    }
}

Measured memory_bytes: 4412
#pragma warning (disable:4996)
#include <stdio.h>
#include <math.h>

double calc(double *p){
	return sqrt(pow((p[2] - p[0]), 2) + pow((p[3] - p[1]), 2));
}
int main(void){
	double p[4];
	unsigned int i;
	for (i = 0; i < 4; i++)scanf("%lf", &p[i]);
	printf("%lf\n", calc(p));
	return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , m , s;
int l[MAXX];

int main()
{
    _FastIO;
    cout.precision(10);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> l[i];
        s += l[i];
        m = max(m , l[i]);
    }
    string ans = "Yes";
    s -= m;
    if(m >= s){
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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;
}

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

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    int l = 0, r = 0;
    int ll = 0, rr = 0;

    int ans = 0;
    REP(i, n - 1) {
        if (s[i] == 'L') l++; else r++;
        int j = n - i - 1;
        if (s[i] == 'L' and s[i] == s[i + 1]) ans++;
        if (s[j] == 'R' and s[j - 1] == s[j]) ans++;
    }
    if (s.back() == 'L') l++; else r++;

    int x = 0;
    REP(i, n - 1) {
        if (s[i] != s[i + 1]) x++;
    }

    int y = x % 2;
    x = x / 2;

    // cout << ans << " " << x << " " << y << endl;

    ans += 2 * min(k, x);
    k -= x;
    if (k > 0) ans += y;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <map>
#include<algorithm>
using namespace std; 
long long an(long long a){
    if (a==0) return 1;
    else return an(a-1)+pow(2,a);
}
int main(){
    long long h; cin >> h;
    long long s=0;
    long long ans = 0;
    while(h>1){
        h=h/2;
        s+=1;
    }
    ans=an(s);
    cout << ans << "\n";
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
  ll n;cin>>n;
  cout<<n*(n-1)/2<<endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
A=[]
for i in range(h):
    A.append(list(input()))
kabe=0
for i in range(h):
    for j in range(w):
        if A[i][j]=="#":
            kabe+=1
def bfs():
    while queue:
        x,y,d=queue.pop()
        #print("xyd",x,y,d)
        for i in range(4):
            xx=x+dx[i] ; yy=y+dy[i]
            if xx==h-1 and yy==w-1:
                print(h*w-d-2-kabe);exit()
            if 0<=xx<h and 0<=yy<w and A[xx][yy]==".":
                A[xx][yy]="#"
                queue.appendleft([xx,yy,d+1])


from collections import deque
dx=[-1,0,1,0] ;dy=[0,1,0,-1]
queue=deque([[0,0,0]])
bfs()
print(-1)


Measured memory_bytes: 9460
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {
	double A, B;
	cin >> A >> B;
	int C;

	floor(A / 0.08)==A/0.08 ? C = A / 0.08 : C = A / 0.08 + 1;
				if ((int)(C * 0.1) != B) {

		
						C = B / 0.1;

					
		if ((int)(C * 0.08) != A) {
										cout << -1;
									}
								else {
									cout << C;
								}		
						}
						else {
						cout << C;
					}
	
	
	
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef  long long   ll;
typedef  long double ld;
#define ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
ll n, weight;
vector<ll> w, v;
vector<vector<ll>> dp;
ll solve(int idx, ll val) {
	if (val < 0)
		return 1e18;
	if (!val)
		return 0;
	if (idx == n)
		return 1e18;
	ll& ret = dp[idx][val];
	if (~ret)
		return ret;
	ll p1 = solve(idx + 1, val);
	ll p2 = w[idx] + solve(idx + 1, val - v[idx]);
	return ret = min(p1, p2);

}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	cin >> n >> weight;
	w = vector<ll>(n);
	v = vector<ll>(n);
	dp = vector<vector<ll>>(n, vector<ll>(1e5 + 7, -1));
	for (int i = 0; i < n; ++i)
		cin >> w[i] >> v[i];
	//cout << solve(0, 90);
	for (int i = 1e5 + 6; i >= 1; --i)
		if (solve(0, i) <= weight)
			return cout << i, 0;


}


Measured memory_bytes: 82372
n = gets.chomp.to_i
numbers = gets.chomp.split(' ').map(&:to_i)

answer = 0
n.times do |i|
  next if i-1 < 0 || i+1 >= n
  a = numbers[i-1]
  b = numbers[i]
  c = numbers[i+1]
  answer += 1 if [a, b, c].sort[1] == b 
end

puts answer


Measured memory_bytes: 1788
n, u, v = gets.split.map(&:to_i)

edge = Array.new(n+1){[]}
(n-1).times do
    a, b = gets.split.map(&:to_i)
    edge[a] << b
    edge[b] << a
end

aoki = Array.new(n+1)
aoki[v] = 0
que = [v]
while x = que.shift
    edge[x].each do |y|
        next if aoki[y]
        aoki[y] = aoki[x] + 1
        que << y
    end
end

taka = Array.new(n+1)
taka[u] = 0
que = [u]
leaf = v
while x = que.shift
     leaf = x if edge[x].size == 1 && aoki[leaf] < aoki[x]

    edge[x].each do |y|
        next if taka[y] || taka[x] + 1 >= aoki[y]
        taka[y] = taka[x] + 1
        que << y
    end
end

puts aoki[leaf] - 1

Measured memory_bytes: 13144
#include <iostream>

using namespace std;

#define mill 196471

void solve(int y, int m, int d)
{
	long long Y, M, D;
	long long ans;
	
	if(y % 3 == 1) Y = (y - 1) / 3 * (195 * 3 + 5);
	else if(y % 3 == 2) Y = (y - 2) / 3 * (195 * 3 + 5) + 195;
	else Y = (y - 3) / 3 * (195 * 3 + 5) + 390;
	//cout << Y << endl;
	
	if(y % 3 == 0){
		M = (m - 1) * 20;
	}
	else{
		if(m % 2 == 1) M = (m - 1) / 2 * 39;
		else M = (m - 2) / 2 * 39 + 20;
	}
	//cout << M << endl;
	
	D = d;
	//cout << D << endl;
	
	ans = Y + M + D;
	
	cout << mill - ans << endl;
}

int main()
{
	int n;
	int y, m ,d;
	cin >> n;
	while(n--){
		cin >> y >> m >> d;
		solve(y, m, d);
	}
	return 0;
}

Measured memory_bytes: 1160
let n = stdin.ReadLine() |> int

let a =
  [for _ in 1 .. n -> stdin.ReadLine() |> (fun x -> (int x) - 1) ]
  |> List.toArray

let ans =
  [
    let mutable tmp = 0
    yield tmp
    for i in 1 .. n do
      tmp <- a.[tmp]
      yield tmp
  ]
  |> List.tryFindIndex (fun i -> i = 1)
  |> (fun x ->
        match x with
        | Some i -> i
        | None -> -1 )

ans |> stdout.WriteLine

Measured memory_bytes: 22860
#include <stdio.h>

int main(){
    int h,i,j,n,min,max;
    max = -9999999999;
    
    scanf("%d",&n);
    
    scanf("%d",&h);
    min = h;
	
    for(j = 1;j < n;j++){
      scanf("%d",&i);
      
      if(max > i-min)
         max = max;
      else
         max = i-min;

      if(i > min)
         min = min;
      else 
         min = i;
    }

    printf("%d\n",max);

    return 0;
}
         
      
      

Measured memory_bytes: 1856
solve :: String -> Int
solve = head . foldl rpn [] . words
  where
    rpn (x:y:zs) "*" = y * x : zs
    rpn (x:y:zs) "-" = y - x : zs
    rpn (x:y:zs) "+" = y + x : zs
    rpn zs numstring = read numstring:zs

main = getLine >>= print . solve



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

vector<vector<int> > bfs(vector<string> &s,int sy,int sx,char wall,int dir){
  int h=s.size(),w=s.front().size();
  vector<vector<int> > dp(h,vector<int>(w,-1));
  using P = pair<int, int>;
  queue<P> q;

  dp[sy][sx]=0;
  q.emplace(sy,sx);
  
  int dy[]={1,-1,0,0,1,1,-1,-1};
  int dx[]={0,0,1,-1,1,-1,1,-1};
  auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};
  
  while(!q.empty()){
    int y,x;
    tie(y,x)=q.front();q.pop();
    for(int k=0;k<dir;k++){
      int ny=y+dy[k],nx=x+dx[k];
      if(!in(ny,nx)||s[ny][nx]==wall) continue;
      if(~dp[ny][nx]) continue;
      dp[ny][nx]=dp[y][x]+1;
      q.emplace(ny,nx);
    }
  }
  
  return dp;
}

//INSERT ABOVE HERE
signed main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++) cin>>s[i];
  auto dp=bfs(s,0,0,'#',4);
  
  if(dp[h-1][w-1]<0){
    cout<<-1<<endl;
    return 0;
  }
  
  int cnt=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cnt+=s[i][j]=='.';
  cout<<cnt-(dp[h-1][w-1]+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  double q, h;
  ll s, d, n;
  cin >> q >> h >> s >> d >> n;

  ll ans = 0;
  ll qq = q * 4;
  ll hh = h * 2;
  ll v = min({qq, hh, s});

  ans = min(n * v, (n / 2) * d + (n % 2) * v) ;

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;
int main()
{
    fio;
    ll t, a, n, q, k, i, l, m, c, u, f, j, p, x, y, b, d;
 ll s;
 cin>>d>>t>>s;
 if((float)d/s <= t)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

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

        for (int i=0;i<10;i++) {
            x = r * x - d;
            System.out.println(x);
        }
    }
}

Measured memory_bytes: 21204
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		boolean[] isPrime = new boolean[100005];
		Arrays.fill(isPrime, true);
		isPrime[0] = false;
		isPrime[1] = false;
		for (int i = 2; i < isPrime.length / 2; i++) {
			if (!isPrime[i]) continue;

			for (int j = 2; i * j < isPrime.length; j++) {
				isPrime[i * j] = false;
			}
		}

		long[] a = new long[100005];
		a[2] = a[1] + (isPrime[1] ? 1 : 0);
		for (int i = 3; i < a.length - 1; i++) {
			if (i % 2 == 0) a[i] = a[i - 1];
			else a[i] = a[i - 1] + ((isPrime[i] && isPrime[(i + 1) / 2]) ? 1 : 0);
		}

		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < q; i++) {
			sb.append(a[r[i]] - a[l[i] - 1]);
			sb.append("\n");
		}
		System.out.print(sb.toString());
	}
}


Measured memory_bytes: 64892
def main():
    n, k = map(int, input().split())
    x = n // k
    x2 = x + 1
    xr = abs(n - x * k)
    x2r = abs(n - x2 * k)
    r = min(xr, x2r)
    print(r)

if __name__ == '__main__':
    main()

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

using namespace std;

#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vb vector<bool>
#define vl vector<long>
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char dir[] = {'R', 'L', 'D', 'U'};
const int MOD = 1e9 + 7;

void solve()
{
    string s = "ACL";
    int k; cin >> k;
    for(int i = 0; i < k; i++) cout << s;
}

int main()
{
    fastio

    //ifstream fin(".in");
    //ofstream fout(".out");


    int t = 1;
    //cin >> t;

    while(t-- > 0) solve();
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(void){
    int num,a,sign,sum,temp,t;
    for(;t=0,sum=0,sign=1,scanf("%d",&num),num;){
        a=num/2+1;
        if(num == 1 || num == 2)
            sign=0;
        while(sum=0,temp=a,sign){
            while(temp){
                sum+=temp;
                if(sum == num){
                    t++;
                    break;
                }
                else if(sum > num)
                    break;
                temp--;
                if(temp == 0)
                    sign=0;
            }
            a--;
        }
        printf("%d\n",t);
    }
    return 0;
}

Measured memory_bytes: 600
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in reversed(range(len(sp)-len(t)+1)):
        for j in reversed(range(len(t))):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in reversed(range(len(t))):
                sp[i+j] = t[j]
            
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

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

int main() {
  int n, a, b, x;
  cin >> n >> a >> b;
  x = a * n;
  if (x >= b) {
    cout << b << endl;
  }
  if (x < b) {
    cout << x << endl;
  }
}

Measured memory_bytes: 256
s = str(input())
s +='0'
result = [0]
i = 0
counter = 0
while i+counter < len(s):
    counter = 0
    h = 1
    while i + counter < len(s) and h == 1:
        if s[i+counter] == 'A' or s[i+counter] == 'T' or s[i+counter] == 'G' or s[i+counter] == 'C':
            counter += 1
        else:
            result.append(counter)
            i += counter +1
            h = 0
print(max(result))

Measured memory_bytes: 3064