akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    X = int(input())

    s = 0
    a = 0

    while s < X:
        a += 1
        s += a

    print(a)


main()


Measured memory_bytes: 5032
import java.util.*;
 public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String s=sc.next();
  long sum=0;
  for(int i=0;i<s.length();i++){
  sum+=Integer.parseInt(s.substring(i,i+1));
  }
  if(sum%3==0) System.out.println("Yes");
  else System.out.println("No");
}}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int d;
  while (cin >> d) {
    int ans = 0;
    for (int i = d; i <= 600 - d; i += d) {
      ans += i * i * d;
    }
    cout << ans << endl;
  }
  return 0;
}


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

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

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N = 0;
    cin >> N;

    int page = N / 2;

    if ( N % 2 == 0 )
    {
        cout << page << endl;
    }
    else if ( N % 2 != 0 )
    {
        cout << page + 1 << endl;
    }

}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
l_odd = []
count = 0

for i in range(n):
  if l[i] % 2 == 0:
    l_odd.append(l[i])
    
for i in range(len(l_odd)):
  if l_odd[i] % 3 == 0 or l_odd[i] % 5 == 0:
    count += 1
if count == len(l_odd):
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 9196
import java.util.Scanner

fun main(args: Array<String>){
	val s = Scanner(System.`in`).nextLine()
	val S = s.split(" ")

	val A = Integer.parseInt(S[0])
	val B = Integer.parseInt(S[1])

	if(A > 8 || B > 8) println(":(")
	else println("Yay!")
}

Measured memory_bytes: 36080
//53
#include<iostream>
#include<string>
#include<sstream>

using namespace std;

int main(){
  for(string s;getline(cin,s),s!="0";){
    stringstream ss(s);
    int p=0,o=0;
    for(int c;ss>>c;){
      if(c==1){
	o++;
      }else if(c>=10){
	p+=10;
      }else{
	p+=c;
      }
    }
    while(o&&p+11+o-1<=21){
      p+=11;
      o--;
    }
    p+=o;
    cout<<((p>21)?0:p)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h> 
using namespace std;
int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    int horizontal = tx - sx;
    int low = ty - sy;

    for(int i = 0; i < low;i++) {
      cout << 'U';
    }

    for(int i = 0; i < horizontal;i++){
      cout << 'R';
    }

    for(int i = 0; i < low;i++) {
      cout << 'D';
    }

    for(int i = 0; i < horizontal;i++){
      cout << 'L';
    }

    cout << 'L';
    for(int i = 0; i < low + 1;i++) {
      cout << 'U';
    }
    for(int i = 0; i < horizontal + 1;i++){
      cout << 'R';
    }
    cout << 'D';

    cout << 'R';
    for(int i = 0; i < low + 1;i++) {
      cout << 'D';
    }
    for(int i = 0; i < horizontal + 1;i++){
      cout << 'L';
    }
    cout << 'U' << endl; 
 }

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

int64_t getResult(const std::vector<int> &org, int m) {
  std::vector<int64_t> mods(org.size());
  mods[0] = org[0] % m;
  for (int i = 1; i < static_cast<int>(org.size()); ++i) {
    mods[i] = (org[i] + mods[i - 1]) % m;
  }
  std::sort(mods.begin(), mods.end());
  mods.push_back(std::numeric_limits<int64_t>::max());
  int64_t total = 0;
  int64_t current_value = 0;
  int64_t current_count = 1;
  for (int i = 0; i < static_cast<int>(mods.size()); ++i) {
    if (current_value == mods[i]) {
      ++current_count;
    } else {
      if (current_count >= 1) {
        total += (current_count * (current_count - 1) / 2);
      }
      current_value = mods[i];
      current_count = 1;
    }
  }
  return total;
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> values(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> values[i];
  }
  std::cout << getResult(values, m) << std::endl;
}

Measured memory_bytes: 2176
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main(void){
    char a;
    char b;
    
    cin >> a >> b;
    
    int k = (a - 'A') - (b - 'A');
    
    if(k > 0)
        cout << ">" << endl;
    if(k == 0)
        cout << "=" << endl;
    if(k < 0)
        cout << "<" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int H, W;
    cin >> H >> W;
    int count = 0;
    vector<vector<char>> Aij(H, vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            char tmp;
            cin >> tmp;
            Aij[i][j] = tmp;
            if(tmp=='#'){count++;}
        }
    }

    typedef tuple<int, int, int> XY;
    queue<XY> que;
    que.push(XY(0,0,1));

    int dxl[2] = {1, 0};
    int dyl[2] = {0, 1};

    while(!que.empty()){
        XY coords = que.front(); que.pop();
        int x = get<0>(coords);
        int y = get<1>(coords);
        int tmpCount = get<2>(coords);

        if( x+1==W && y+1==H && tmpCount==count){
            cout << "Possible" << endl;
            return 0;
        }

        for(int i=0; i<2; i++){
            int dx = dxl[i];
            int dy = dyl[i];
            
            if(y+dy < H && x+dx < W && Aij[y+dy][x+dx] == '#'){
                que.push(XY(x+dx, y+dy, tmpCount+1));
            }
        }
    }

    cout << "Impossible" << endl;
    return 0;
    
}

Measured memory_bytes: 3624
#include <stdio.h>

int n, s, count = 0,cur;
int digits[10] = {};

void dfs(int cur){
	if(cur == n){
		int sum = 0;
		for(int i = 0; i < n; i++) {
			sum += digits[i];
		}
		if(sum == s) {
			count++;
		}
		return;
	}
	for (int i = 0; i < 10; i++) {
		// for (int j = 0; j < 10; j++) {
		// 	printf("%d ", digits[j]);
		// }
		// printf("\n");
		if (cur == 0) {
			digits[cur] = i;
			dfs(cur+1);
		} else {
			if (digits[cur-1] < i) {
				digits[cur] = i;
				dfs(cur+1);
			// } else {
			// 	digits[cur] = cur;
			}
		}
		// dfs(cur+1);
	}
}

int main(void){
	while(scanf("%d %d",&n,&s)!= EOF){
		if(n == 0 && s == 0){
			break;
		}
		count = 0;
		dfs(0);
		printf("%d\n", count);
		for(int i = 0; i < 10; i++) digits[i] = 0;
	}
	return 0;
}



Measured memory_bytes: 2048
import math
import sys
import bisect
input=sys.stdin.readline

MAX = 1000001
  
# structure to store queries 
class Query: 
    def __init__(self, l, r, idx): 
        self.l = l 
        self.r = r 
        self.idx = idx 
  
# updating the bit array 
def update(idx, val, bit, n): 
    while idx <= n: 
        bit[idx] += val 
        idx += idx & -idx 
  
# querying the bit array 
def query(idx, bit, n): 
    summ = 0
    while idx: 
        summ += bit[idx] 
        idx -= idx & -idx 
    return summ 
  
def answeringQueries(arr, n, queries, q): 
  
    # initialising bit array 
    bit = [0] * (n + 1) 
  
    # holds the rightmost index of  
    # any number as numbers of a[i] 
    # are less than or equal to 10^6 
    last_visit = [-1] * MAX
  
    # answer for each query 
    ans = [0] * q 
  
    query_counter = 0
    for i in range(n): 
  
        # If last visit is not -1 update -1 at the 
        # idx equal to last_visit[arr[i]] 
        if last_visit[arr[i]] != -1: 
            update(last_visit[arr[i]] + 1, -1, bit, n) 
  
        # Setting last_visit[arr[i]] as i and  
        # updating the bit array accordingly 
        last_visit[arr[i]] = i 
        update(i + 1, 1, bit, n) 
  
        # If i is equal to r of any query store answer 
        # for that query in ans[] 
        while query_counter < q and queries[query_counter].r == i: 
            ans[queries[query_counter].idx] =query(queries[query_counter].r + 1, bit, n) - query(queries[query_counter].l, bit, n) 
            query_counter += 1
  
    # print answer for each query 
    for i in range(q): 
        print(ans[i]) 



#t=int(input())
t=1
for _ in range(t):
    #n=int(input())
    n,q=map(int,input().split())
    l=list(map(int,input().split()))
    queries=[]
    for __ in range(q):
        le,ri=map(int,input().split())
        le-=1
        ri-=1
        queries.append(Query(le,ri, __))

    queries.sort(key = lambda x: x.r) 
    answeringQueries(l, n,queries, q) 
  
            
            

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

bool f(const long kind, const long n, const vector<long>& a){
    map<long,long> c;
    for(long i=0; i<n-1; i++){
        if(a[i]>=a[i+1]){
            /*
            while(!c.empty() && c.rbegin()->first >= a[i+1]){
                c.erase(c.rbegin()->first);
            }
            */
            const auto it = c.lower_bound(a[i+1]);
            c.erase(it, c.end());
            long j = a[i+1]-1;
            c[j]++;
            while(c[j]>=kind){
                c.erase(j);
                if(j<=0){
                    return false;
                }
                c[j-1]++;
                j--;
            }
        }
    }
    return true;
}

bool strict_increasing(const vector<long>& a){
    size_t n = a.size();
    for(size_t i=1; i<n; i++){
        if(a[i-1]>=a[i]){
            return false;
        }
    }
    return true;
}

int main(void){
    long n;
    cin >> n;
    vector<long> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    if(strict_increasing(a)){
        cout << 1 << endl;
        return 0;
    }
    long left=1, right=n;
    for(;;){
        const long mid = (left+right)/2;
        if(right-left<=1){
            if(f(right, n, a)){
                cout << right << endl;
            }else{
                cout << left << endl;
            }
            return 0;
        }
        const bool b = f(mid, n, a);
        //printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
        if(b){
            right=mid;
        }else{
            left=mid;
        }
    }
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==m){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    
    ll n,d,x;
    cin >> n >> d >> x;

    vll a(n);
    rep(i,n) cin >> a[i];

    rep(day,d){
        rep(i,n){
            if(day % a[i] == 0){
                x++;
            }
        }
    }

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
#include<fstream>
#include <chrono>
using namespace std;
typedef long long LL;


int main(void)
{
	/*
	chrono::system_clock::time_point start, end;
	start = chrono::system_clock::now();
	end = chrono::system_clock::now();
	double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
	//printf("time %lf[ms]\n", time);
	*/

	LL D;
	
	
	vector<int> c(27);
	cin >>D;
	for (int i = 1; i <= 26; i++) {
		cin >>c[i];
	}
	vector<vector<LL>> s(D+1,vector<LL>(27,0));
	vector<LL> t(D+1);
	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >>s[i][j];
		}
	}
	for (int i = 1; i <= D; i++) {
		cin >>t[i];
	}
	LL m;
	cin >>m;
	vector<LL> ad(m);
	vector<LL> q(m);
	for (int i = 0; i < m; i++) {
		cin >>ad[i]>>q[i];
	}
	for (int k = 0; k < m; k++) {
		vector<LL> last(27, 0);
		t[ad[k]]=q[k];
		LL man = 0;
		for (int i = 1; i <= D; i++) {
			LL dis = 0;
			man += s[i][t[i]];
			last[t[i]] = i;
			for (int j = 1; j <= 26; j++) {
				dis += (c[j] * (i - last[j]));
			}
			man -= dis;
			//cout <<man<<endl;
		}
		cout << man << endl;
	}
	return 0;
}


Measured memory_bytes: 4784
/*
 * Matheus Oliveira
 * 01:55:36 14/04/2019
 * abc124d.cpp
*/

#include <bits/stdc++.h>
using namespace std;

#define EPS
#define INF
#define MAXN 100100
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, ini, fim) printf("%s: ", #x); for(int i = ini; i <= fim; i++) printf("%d%c", x[i], (i == fim) ? '\n' : ' ');

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

char inp[MAXN];
vector<pii> ilhas0, ilhas1;

int main() {
	int n, k, ans, extra1, actual;
	ans = 0;

	scanf("%d %d", &n, &k);
	getchar();

	scanf("%s", inp);

	int counter0 = 0, counter1 = 0;
	for(int i = 0; i < n; i++) {
		if(inp[i] == '1') {
			if(counter0 > 0) {
				ilhas0.pb( mp(counter0, counter1) );
				counter1 = 1;
			}
			else counter1++;
			counter0 = 0;
		} 
		else counter0++;
	}

	extra1 = 0;
	if(counter0 > 0) {
		ilhas0.pb( mp(counter0, counter1) );
		counter1 = 1;
	}
	else extra1 = counter1;

//	for(int i = 0; i < ((int) ilhas0.size()); i++) {
//		printf("%d 0's, %d 1's\n", ilhas0[i].first, ilhas0[i].second);
//	}

	if(k >= (int) ilhas0.size()) printf("%d\n", n);
	else {
		int p1, p2;
		p1 = p2 = 0;

		ans = 0;
		actual = ilhas0[p1].first + ilhas0[p1].second;

		if(p1 + 1 < ((int) ilhas0.size())) actual += ilhas0[p1+1].second;
		else actual += extra1;

		while(p1 < ((int) ilhas0.size())) {
			//printf("p1: %d, p2: %d, actual: %d\n", p1, p2, actual);

			if(p2 - p1 + 1 < k and p2 < ((int) ilhas0.size())) {
				p2++;

				actual += ilhas0[p2].first; // + ilhas0[p1].second;

				if(p2 + 1 < ((int) ilhas0.size())) actual += ilhas0[p2+1].second;
				else actual += extra1;
				
				ans = max(ans, actual);
			}
			else {
				ans = max(ans, actual);
				actual -= ilhas0[p1].first + ilhas0[p1].second;
				//if(p1 == ((int) ilhas0.size()) - 1) actual -= extra1;
				p1++;
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 1020
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CRemainderMinimization2019 {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            long l = s.nextInt(), r = s.nextInt(), ans = 2018;
            for (long i = l; i < Math.min(l + 2021, r); i++) {
                for (long j = i + 1; j <= Math.min(l + 2021, r); j++) {
                    ans = Math.min(ans, (i * j) % 2019);
                }
            }
            w.println(ans);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int h, w;

	cin >> h >> w;

	string ans[h + 2];
  	string s;

	ans[0] = string(w + 2, '#');
	ans[h + 1] = string(w + 2, '#');

	int i, j;

	rep(i, h) {
		cin >> s;

		ans[i + 1] = "#";

		rep(j, w) ans[i + 1] += s[j];

		ans[i + 1] += "#";
	}

	rep(i, h + 2) Out(ans[i]);
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	int n;
	int t[10010];
	
	scanf("%d",&n);
	rep(i,n-1){
		scanf("%d",&t[i]);
	}
	
	int dp[2][5010];
	rep(i,2)rep(j,5010)dp[i][j] = INF;
	dp[0][1] = 0;
	
	rep(i,n-1){
		rrep1(j,n/2){
			dp[1][j] = min ( dp[0][j] + t[i] , dp[1][j] );
			dp[0][j] = min ( dp[0][j-1] , dp[1][j-1] + t[i] );
		}
	}
	
	printf("%d\n",min ( dp[0][n/2] , dp[1][n/2] ) );
}

Measured memory_bytes: 1252
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a[100100];

ll solve() {
    map<ll, int> m;
    for (int i = 0; i < n; i++) {
        m[a[i]]++;
    }

    vector<ll> vec;
    for (auto& v: m) {
        if (v.second >= 2)
            vec.push_back(v.first);
    }
    sort(RALL(vec));

    if (vec.size() < 2) return 0;
    if (m[vec[0]] >= 4) return vec[0] * vec[0];
    return vec[0] * vec[1];
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 7296
#include<iostream>
using namespace std;
int main() {
	int n, cnt = 0, mx = 0, ans = 1; cin >> n;
	for (int i = 1; i <= n; i++) {
		int x = i;
		while (x % 2 == 0) {
			x /= 2;
			cnt++;
		}
		if (mx < cnt) {
			mx = cnt;
			ans = i;
		}
		cnt = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3464
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    vector<int> num(100000, 0);
    repi(i, n, 0)
    {
        int a;
        cin >> a;
        num[a]++;
    }
    int cnt = num[0] + num[1];
    repi(i, 100000, 1)
    {
        if (cnt < num[i - 1] + num[i] + num[i + 1])
        {
            cnt = num[i - 1] + num[i] + num[i + 1];
        }
    }
    if (cnt < num[100000 - 1] + num[100000 - 2])
    {
       cnt = num[100000 - 1] + num[100000 - 2];
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines[0]);
  var vs = [];
  for(var i=0;i<N;i++){
    var line = lines[i+1].split(' ').map(x => parseInt(x));
    vs.push(line);
  }

  if(N==1){
    console.log(vs[0].join(' '));
    return;
  }

  const one_vs = vs.filter(v => v[2]>0);
  if(one_vs.length==1){
    console.log(one_vs[0].join(' '));
    return;
  }


  var candidates = [];
  for(var x=0;x<=100;x++){
    for(var y=0;y<=100;y++){
      var one_v = one_vs[0];
      var height = Math.abs(x - one_v[0]) + Math.abs(y - one_v[1]) + one_v[2]
      candidates.push([x,y,height]);
    }
  }

//console.log(candidates);

  var highest = [0,0,0];
  for(var j=0;j<candidates.length;j++){
    var candidate = candidates[j];
    var detected=true;
    for(var i=0;i<one_vs.length;i++){
      var one_v = one_vs[i];
      var tmp_height = Math.abs(candidate[0] - one_v[0]) + Math.abs(candidate[1] - one_v[1]) + one_v[2];
      if(candidate[2]!=tmp_height){detected=false;}
    }
    if(detected && candidate[2] > highest[2]){highest = candidate}
  }
  console.log(highest.join(' '));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 8524
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		try {
			String[] inputStr = new String[Integer.parseInt(input.readLine())];
			inputStr = (input.readLine()).split(" ");
			int min = getMin(getIntArray(inputStr));
			int max = getMax(getIntArray(inputStr));
			long sum = getSum(getIntArray(inputStr));

			System.out.println(min + " " + max + " " + sum);
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}

	public static int getMin(int[] inputInt) {
		int min = 1000000;

		for (int i = 0; i < inputInt.length; i++) {
		  if (min > inputInt[i]) {
		    min = inputInt[i];
		  }
		}
		return min;
	}

	public static int getMax(int[] inputInt) {
		int max = -1000000;

		for (int i = 0; i < inputInt.length; i++) {
		  if (max < inputInt[i]) {
			  max = inputInt[i];
		  }
		}
		return max;

	}

	public static long getSum(int[] inputInt) {
		long sum = 0;
		for (int i : inputInt) {
			sum += i;
		}
		return sum;
	}

	public static int[] getIntArray(String[] inputStr) {
		int[] inputInt = new int[inputStr.length];
		for (int i = 0; i < inputInt.length; i++) {
			inputInt[i] = Integer.parseInt(inputStr[i]);
		}
		return inputInt;
	}


}



Measured memory_bytes: 28904
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin>>n;
	double sum=0;
	double a[105];
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=0;i<n;i++){
		a[i]-=sum/n;
	}
	double minn=999;
	int k=0;
	for(int i=0;i<n;i++){
		if(abs(a[i])<minn){
			k=i;
			minn=abs(a[i]);
		}
	}
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  stack<int> stk;
  while (n) {
    stk.push(n & 1);
    n = -(n >> 1);
  }
  if (stk.empty()) {
    cout << 0 << '\n';
    return 0;
  }
  while (!stk.empty()) {
    cout << stk.top();
    stk.pop();
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
 
  if (S == "RRR") {
    cout << 3 << endl;
  }
 
  if (S == "RRS" || S == "SRR") {
    cout << 2 << endl;
  }
 
  if (S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR") {
    cout << 1 << endl;
  }
  
  if (S == "SSS") {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3620
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b=MI()
    print((a+b)%24)
main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int n;
	cin >> n;
	cout << 800 * n - 200 * (n / 15) << endl;
	return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int main()
{
  int a, b;
  scanf("%d %d", &a, &b);
  if(a - 2 * b >= 0)
  {
    printf("%d", a - 2 * b);
  }
  else
  {
    printf("0");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
	int a, n, ans = 0;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> a;
		while((a & 1) == 0){
			a /= 2;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
#include <queue>
using namespace std;

#define ll long long
#define ld long double
#define pi 3.14159265359;
// %llu %lf

// v:vector  type:型  order:greater(大きい順) or less(小さい順)
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 特定コンテナの中から特定の値をカウントする
#define _count(v,value) count(v.begin(),v.end(),value)

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//                                                              member.emplace(2)とかも同じ
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
template<typename T>
static T _abs(const T x) { return  (x > 0 ? x : -x); }

// 最大公約数
int64_t gcd(int64_t a, int64_t b) { while (b) { int64_t c = b; b = a % b; a = c; } return a; }
// 最小公倍数
int64_t lcm(int64_t a, int64_t b) { if (!a || !b) return 0; return a * b / gcd(a, b); }

// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// ■
// UINT32_MAX
// 4294967295 ≒ 4 * 1e9

// ■
// 割り算した結果との比較での丸め対処時 
// ABC 161 B
// https://atcoder.jp/contests/abc161/tasks/abc161_b
// double   border = _sum(v, 0 / (double)(4 * m);
//            ↓
// uint32_t border = (_sum(v, 0) + (4 * m) - 1) / (4 * m);

// ■
// N の数が与えられた場合の組合せ N * (N - 1) / 2


/*
*/
// ABC 156 A
// https://atcoder.jp/contests/abc157/tasks/abc156_a
#include <sstream>

int main()
{
	uint32_t n, r;
	cin >> n >> r;

	if (n >= 10) {
		printf("%d\n", r);
		return 0;
	}

	uint32_t add = 100 * (10 - n);
	printf("%d\n", r + add);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,f[100009][5], a[100009][5], kq = -1;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> a[i][1] >> a[i][2] >> a[i][3];
    }
    f[0][1] = 0;
    f[0][2] = 0;
    f[0][3] = 0;
    for(int i = 1; i <= n; ++ i)
    {
        f[i][1] = max(f[i - 1][2], f[i - 1][3]) + a[i][1];
        f[i][2] = max(f[i - 1][1], f[i - 1][3]) + a[i][2];
        f[i][3] = max(f[i - 1][2], f[i - 1][1]) + a[i][3];
    }
    kq = max(kq, f[n][1]);
    kq = max(kq, f[n][2]);
    kq = max(kq, f[n][3]);
    cout << kq;
    return 0;
}


Measured memory_bytes: 4224
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,t;
  cin >> n >> t;
  ll cost_min = INF;
  REP(i,n){
    ll c,t1;
    cin >> c >> t1;
    if(t1<=t&&c<cost_min){
      cost_min = c;
    }
  }
  if(cost_min==INF){
    cout << "TLE" << endl;
  }else{
    cout << cost_min << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	int A, B, C, K;
	std::cin >> A >> B >> C >> K;
	if (A >= K) {
		std::cout << K;
	}
	else {
		if (A + B < K) {
			std::cout << A+A+B-K;
		}
		else {
			std::cout << A;
		}
	}
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        int[][] board = new int[8][8];
        
        for(int i = 0; i < 8 ; i++){
        	Arrays.fill(board[i], 0);
        }
        
        for(int i = 0; i < n; i++){
        	String[] tmpArray = br.readLine().split(" ");
        	int r = Integer.parseInt(tmpArray[0]);
        	int c = Integer.parseInt(tmpArray[1]);
        	board[r][c] = 1;
        }
        
        int nextC = getAvailableColumn(board, 8);
        if(nextC >= 0){
        	for(int i = 0; i < 8; i++){
        		boolean result = putQueen(board, 8, i, nextC);
        		if(result == true){
        			break;
        		}
        	}
        }
        //print
        for(int i = 0; i < 8; i++){
        	for(int j = 0; j < 8 ; j++){
        		if(board[i][j] == 1){
        			System.out.print("Q");
        		}
        		else{
        			System.out.print(".");
        		}
        	}
        	System.out.println();
        }
	}
	
	static int getAvailableColumn(int[][] board, int n){
		int j;
		for(j = 0; j < n ; j++){
			int queen = 0;
			for(int i = 0; i < n; i++){
				if(board[i][j] == 1){
					queen++;
					break;
				}
			}
			if(queen == 0){
				break;
			}
		}
		
		if(j >= n){
			return -1;
		}
		
		else {
			return j;
		}
	}
	
	static boolean putQueen(int[][] board, int n, int r, int c){
		//System.out.println("n "+n + " r "+r+" c "+c);
		//????????????????????????????????????????????????????????¨??????????????£??????
		for(int i = 0; i < n ; i++){
			if(board[i][c] == 1 && i != r){
				//System.out.println("error 1");
				return false;
			}
			if(board[r][i] == 1 && i != c){
				//System.out.println("error 2");
				return false;
			}
		}
		for(int i = 0; i < n; i++){
			if(  r+i < n && c+i < n && board[r+i][c+i] ==1){
				//System.out.println("error 3");
				return false;
			}
			if( r+i < n && c-i >= 0 && board[r+i][c-i] ==1 ){
				//System.out.println("error 4");
				return false;
			}
			if(  r-i >= 0 && c+i < n && board[r-i][c+i] ==1){
				//System.out.println("error 5");
				return false;
			}
			if( r-i >= 0 && c-i >= 0 && board[r-i][c-i] ==1 ){
				//System.out.println("error 6");
				return false;
			}
		}
		//System.out.println("("+r+","+c+") is OK");
		board[r][c] = 1;
		
		int nextColumn = getAvailableColumn(board, 8);
		if(nextColumn < 0){
			return true;
		}
		for(int i = 0; i < n ; i++){
			boolean result = putQueen(board, n, i, nextColumn);
			if(result == true){
				return true;
			}
		}
		board[r][c] = 0;
		return false;
	}

}

Measured memory_bytes: 24332
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a < b){
            if(b < c){
                System.out.printf("%d %d %d\n",a,b,c);
            }else if(a < c){
                System.out.printf("%d %d %d\n",a,c,b);
            }else{
                System.out.printf("%d %d %d\n",c,a,b);
            }
        }else{
            if(c < b){
                System.out.printf("%d %d %d\n",c,b,a);
            }else if(c < a){
                System.out.printf("%d %d %d\n",b,c,a);
            }else{
                System.out.printf("%d %d %d\n",b,a,c);
            }
        }
    }
}


Measured memory_bytes: 26224
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  int L=a+b;
  int R=c+d;
  
  if (L>R){
	cout<<"Left"<<endl;
  }
  else if(L<R){
    cout<<"Right"<<endl;
  }
  else if(L==R){
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

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

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  int sx,sy,gx,gy;
  cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--;
  vector<string> c(h);
  rep(i,h){
    cin >> c[i];
  }

  vector<vector<int>> d(h, vector<int>(w,inf));
  queue<P> q;
  q.push(P(sx,sy));
  d[sx][sy]=0;
  c[sx][sy] = '@';
  while(!q.empty()){ 
    auto p = q.front(); q.pop();
    c[p.F][p.S] = '@';
    if(p==P(gx,gy)){ break; }
    rep(i,4){
      REP(j,1,k+1){
        int nx = p.F + dx[i]*j,  ny = p.S + dy[i]*j;
        if(nx<0 || h<=nx || ny<0 || w<=ny) break;
        if(c[nx][ny]=='@'){ break; } 
        if(d[nx][ny]<=d[p.F][p.S]) break;
        if(d[nx][ny]>d[p.F][p.S]+1){
          d[nx][ny] = d[p.F][p.S]+1;
          q.push(P(nx,ny));
        }        
      }
    }
  }
  int ans = d[gx][gy];
  if(ans==inf) ans=-1;
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 12156
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;
int N;

int main() {
    cin >> N;

    vector<ll> A(N);
    for (int i = 0; i < N; i++) { 
        scanf("%lld", &A[i]);
    }

    // 累積和と連想配列
    vector<ll> s(N+1, 0);
    map<ll, ll> nums;
    for (int i = 0; i < N; i++) s[i+1] = s[i] + A[i];
    for (int i = 0; i < N+1; i++) nums[s[i]]++;

    // 集計処理
    ll res = 0;
    for (auto it : nums) {
        auto num = it.second;
        res += num * (num - 1) / 2;
    }
    cout << res << '\n';

}



Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int n, m;
  cin >> n >> m;

  vector<int> p(m);
  for(int i = 0; i < m; i++){
    cin >> p[i];
    --p[i];
  }
  
  // テ」ツつ、テ」ツδ「テ」ツつケテヲツウツ陛」ツ?ァテ・ツ青?ィツキツッテァツキツ堙」ツ?ョテ、ツケツ療ィツサツ甘・ツ崢榲ヲツ閉ーテ」ツつ津ィツィツ暗ァツョツ?
  vector<long long int> trip(n, 0);
  for(int i = 1; i < m; i++){
    trip[min(p[i], p[i - 1])]++;
    trip[max(p[i], p[i - 1])]--;
  }
  for(int i = 1; i < n; i++)
    trip[i] += trip[i - 1];
  
  // ic[i]: ティツキツッテァツキツ喨テ」ツつ津」ツ?禿」ツ?ョテ・ツ崢榲ヲツ閉ーテ、ツサツ・テ、ツクツ甘、ツケツ療」ツつ凝」ツ?ェテ」ツつ迂Cテ」ツ?ョテ」ツ?サテ」ツ??」ツ?古」ツ?甘・ツセツ?!!
  vector<int> a(n - 1), b(n - 1), c(n - 1), ic(n - 1);
  for(int i = 0; i < n - 1; i++){
    cin >> a[i] >> b[i] >> c[i];
    ic[i] = (c[i] + a[i] - b[i] - 1) / (a[i] - b[i]);
    /*
      x: テ、ツケツ療ィツサツ甘・ツ崢榲ヲツ閉ー
      ax >= bx + c
      (a - b)x >= c
      x >= c / (a - b)
    */
  }

  // テ」ツ?甘・ツセツ療」ツ?ェテ」ツ?サテ」ツ??」ツ?ァテ、ツケツ療ィツサツ?
  long long int ans = 0;
  for(int i = 0; i < n - 1; i++)
    ans += (trip[i] >= ic[i])
      ? (b[i] * trip[i] + c[i])
      : (a[i] * trip[i]);

  // テ・ツ?コテ・ツ環?
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 5432
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

cnt = 0
for i in range(N):
    if B[i] <= A[i]:
        cnt += B[i]
        A[i] = A[i]-B[i]
        B[i] = 0
    else:
        cnt += min(B[i],A[i]+A[i+1])
        A[i+1] = max(0,A[i+1]-(B[i]-A[i]))
        A[i] = 0
        B[i] = B[i] - min(B[i],A[i]+A[i+1])
    # print(A)
    # print(B)
print(cnt)


Measured memory_bytes: 19004
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define MOD 10000000070
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)

 int main(){

 	lli n,k;
 	cin>>n>>k;
 	vector<lli> s(n);
 	vector<lli> d[2];
 	REP(i,n){
 		char tmp;
 		cin>>tmp;
 		s[i] = tmp-'0';
 	}

 	/*0と1の連続列を数える*/
 	/*最初が0の場合、虚無の1を先頭に生み出す*/
 	/*最後が0の場合、虚無の1を最後に生み出す*/
 	lli before=1;
 	lli cnt=0;
 	for(lli i=0;i<n;i++){
 		if(before != s[i]){
 			d[before].push_back(cnt);
 			before=s[i];
 			cnt=1;
 		}
 		else{
 			cnt++;
 		}
 	}
 	
 	d[before].push_back(cnt);
 	if(before==0)d[1].push_back(0);


 	/*0の分裂列何個?*/
 	lli zeroCnt = d[0].size();
 	if(DEBUG){
 		cout<<"d0"<<endl;
 		REP(i,d[0].size())cout<<d[0].at(i)<<" ";
 		cout<<endl<<"d1"<<endl;
 		REP(i,d[1].size())cout<<d[1].at(i)<<" ";
 	}

 	if(DEBUG)cout<<"zeroCnt="<<zeroCnt<<endl;

 	lli ans=0;

 	lli next=0;
 	lli length = min(zeroCnt,k);
 	for(lli i=0;i<length;i++){
 		next += d[0].at(i)+d[1].at(i);
 	}
 	next+=d[1].at(length);

 	ans = max(ans,next);

 	/*前つながりを削除し、次のつながりを追加する*/
 	for(lli i=0;i+length<zeroCnt;i++){
 		next -= d[0].at(i)+d[1].at(i);
 		next += d[0].at(i+length)+d[1].at(i+length+1);
 		ans   = max(ans,next);
 	}
 	cout<<ans<<endl;

	return 0;
 
}

Measured memory_bytes: 2044
ans = []
while True :
    try :
        s = input()
        a, b, c, d, e, f = map(int, s.split())
        
        y = (((d * c) / a - f) / ((d * b) / a - e))
        x = ((c - (b * y)) / a)
        
        ans.append([x, y])
    except :
        for a in ans :
            print('{:.3f} {:.3f}'.format(round(a[0], 3), round(a[1], 3)))
        break



Measured memory_bytes: 5628
#include<iostream>
#include<cstdio>
using namespace std;
int main(void) {
	int a, b;
	char c;
	while (cin >> a >> c >> b && c != '?') {
		if (c == '+') {
			cout << a + b;
		}
		else if (c == '-') {
			cout << a - b;
		}
		else if (c == '*') {
			cout << a * b;
		}
		else {
			cout << a / b;
		}
		cout << endl;
	}
}


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

int main(){
    int n;
    std::cin >> n;
    std::vector<int> d(n);
    for(int i = 0; i < n; i++){
        std::cin >> d[i];
    }
    std::sort(d.begin(), d.end());

    int ind = n / 2 - 1;
    std::cout <<  std::max(d[ind + 1] - (d[ind] + 1) + 1, 0) << std::endl;
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define cn cout<<"\n"
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repr(i,a,b) for(int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>
#define flush fflush(stdout)

const int INF = 1e8;
const ll MOD = 1e9 + 7;

using namespace std;

int main(){
	_

	int t = 1;

	// cin>>t;

	int a, b;
	rep(nc, 0, t){
		cin>>a>>b;
		if(a <= 5) cout<<"0\n";
		else if(a > 5 && a <= 12) cout<<b / 2<<"\n";
		else cout<<b<<"\n";
	}

	return 0;
}

Measured memory_bytes: 256