akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;

    // hの読込;
    vector<int> h(N);
    rep(i, N)   cin >> h.at(i);

    //DPの実行
    vector<int> cost(N);
    for (int i = 0; i < N; i++) {
        cost.at(i) = INT_MAX;
    }
    cost.at(0) = 0;
    for (int i = 0; i < N; i++) {
        for(int j = 1; j <= K; j++) {
            if (i + j >= N) break;
            cost.at(i + j) = min(cost.at(i + j), cost.at(i) + abs(h.at(i) - h.at(i + j)));
        }
    }
    cout << cost.at(N - 1);
}

Measured memory_bytes: 1024
ABCD =  list(map(int, input().split()))
A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]

if A % D == 0:
    TA = A // D - 1
else:
    TA = A // D 

if C % B == 0:
    AO = C // B - 1
else:
    AO = C // B
    

if TA >= AO:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define mov(x) (1ll<<(x))

using namespace std;

typedef long long ll;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

const int MX = 1005;

int n;
int px[MX], py[MX];

void input()
{
	read(n);
	for(int i=1; i<=n; i++) read(px[i]), read(py[i]);
}

ll dis(ll x, ll y)
{
	return abs(x) + abs(y);
}

void get_seq(ll x, ll y, ll step, int rem)
{
	if(!step) step = 1;
	ll dr = dis(x-step, y), dl = dis(x+step, y);
	ll du = dis(x, y-step), dd = dis(x, y+step);
	ll mnd = min(min(dl, dr), min(dd, du));
	if(!rem) putchar('\n');
	else if(mnd == dr) putchar('R'), get_seq(x-step, y, step/2, rem-1);
	else if(mnd == dl) putchar('L'), get_seq(x+step, y, step/2, rem-1);
	else if(mnd == du) putchar('U'), get_seq(x, y-step, step/2, rem-1);
	else if(mnd == dd) putchar('D'), get_seq(x, y+step, step/2, rem-1);
	else assert(0);
}

void work()
{
	bool tag = (px[1]&1) ^ (py[1]&1);
	int step = tag ? 31 : 32;
	for(int i=2; i<=n; i++)
		if(((px[i]&1)^(py[i]&1)) != tag)
			puts("-1"), exit(0);
	printf("%d\n", step);
	for(int i=30; i>=0; i--) printf("%d ", mov(i));
	if(!tag) printf("%d", mov(0));
	putchar('\n');
	for(int i=1; i<=n; i++) get_seq(px[i], py[i], mov(30), step);
}

int main()
{
	input();
	work();
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    set<int> st;
    rep(i,N){
        int A;
        cin >> A;
        st.insert(A);
    }
    cout << (N == st.size() ? "YES" : "NO") << endl;
    
    return 0;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

void solver() {
    cin.tie(0);
    ios::sync_with_stdio(0);
	ll n,x,t;
	cin >> n >> x >> t;
	
	ll y = n/x;
	if (n % x != 0) y++;

	cout << y*t << endl; 
}

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


Measured memory_bytes: 3632
#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;

llong gcd(llong a, llong b) {
	return b == 0 ? a : gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	return a * b / gcd(a, b);
}

int main() {
	IOS;
	int n; cin >> n;
	vector<int> a(n);
	int cnt = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == cnt) {
			cnt++;
		}
	}
	if (cnt == 1) cout << -1;
	else cout << n - (cnt - 1);
}

Measured memory_bytes: 4000
S = input()

dp = [ [ 0 for _ in range(4)] for _ in range(len(S)+10) ]
dp[0][0] = 1

mod = 10**9+7

for i in range(len(S)):
    for j in range(4):
        if S[i] != '?':
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= mod
        else:
            dp[i+1][j] += dp[i][j]*3
            dp[i+1][j] %= mod

    if S[i] == 'A' or S[i] == '?':
        dp[i+1][1] += dp[i][0]
        dp[i+1][1] %= mod

    if S[i] == 'B' or S[i] == '?':
        dp[i+1][2] += dp[i][1]
        dp[i+1][2] %= mod

    if S[i] == 'C' or S[i] == '?':
        dp[i+1][3] += dp[i][2]
        dp[i+1][3] %= mod

print (dp[len(S)][3])


Measured memory_bytes: 27564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
long long a, b, k;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> a >> b >> k;
	if(a > k) a -= k;
	else if(a+b > k){
		b += a - k;
		a = 0;
	}else a = b = 0;
	cout << a << ' ' << b << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;


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

		int i;
		int j;

		int r = sc.nextInt();
		int c = sc.nextInt();

		int result[][] = new int[r + 1][c + 1];

		for(i = 0; i < r; i++) {
			for(j = 0; j < c; j++) {
				int a = sc.nextInt();
				result[i][j] = a;
				result[i][c] += a;
				result[r][j] += a;
				result[r][c] += a;
			}
		}

		for(i = 0; i < r + 1; i++) {
			for(j = 0; j < c + 1; j++) {

				if(j == c) {
					System.out.print(result[i][j]);
				} else {
					System.out.print(result[i][j] + " ");
				}

			}
			System.out.println();
		}

	}
}

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

const int MAX = 100;
const long long int INFTY = (1LL << 32);

int n;
long long d[MAX][MAX];

void floyd() {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			if (d[i][k] == INFTY) continue;
			for (int j = 0; j < n; j++) {
				if (d[k][j] == INFTY) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}	

int main() {
	int e, u, v, c;
	cin >> n >> e;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) {
				d[i][j] = 0;
			}
			else d[i][j] = INFTY;
		}
	}

	for (int i = 0; i < e; i++) {
		cin >> u >> v >> c;
		d[u][v] = c;
	}

	floyd();

	bool negative = false;
	for (int i = 0; i < n; i++) if (d[i][i] < 0) negative = true;

	if (negative) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (j) cout << " ";
				if (d[i][j] == INFTY) cout << "INF";
				else cout << d[i][j];
			}
			cout << endl;
		}
	}
	return 0;

}


Measured memory_bytes: 3176
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/
int main(){
    char b;
    cin>>b;
    if(b == 'A') cout<<'T'<<endl;
    else if(b == 'T') cout<<'A'<<endl;
    else if(b == 'G') cout<<'C'<<endl;
    else cout<<'G'<<endl;
    return 0;
}


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

int N, K;
double ans = 0.0;

double p(double a, int b) {
    if (b==0) return 1.0;
    else {
        double temp = p(a, b/2);
        if (b%2==0)
            return temp*temp;
        else
            return temp*temp*a;
    }
}

int main () {
    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        int a=i, num=0;
        while(a<K) {
            a *= 2;
            num++;
        }
        ans += (1.0/N)*p(1.0/2.0, num);
    }
    cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"


int main(){
    string s1,s2;
    cin >> s1 >> s2;
    sort(s1.begin(),s1.end());
    sort(s2.begin(),s2.end(),greater<>());
    if(s1<s2)COUT("Yes");
    else COUT("No");
    return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/c.in", "r", stdin);
//  freopen("../IO/c.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


int numLen(int K){

  // If K is a multiple of 2 or 5
  if (K % 2 == 0 || K % 5 == 0)
    return -1;

  int number = 0;

  int len = 1;

  for (len = 1; len <= K; len++) {

    // Instead of generating all possible numbers
    // 1, 11, 111, 111, ..., K 1's
    // Take remainder with K
    number = (number * 10 + 1) % K;

    // If number is divisible by k
    // then remainder will be 0
    if (number == 0)
      return len;
  }

  return -1;
}
void solve(std::istream &in, std::ostream &out) {
  int K;
  in >> K;
  if (K % 7 == 0) K /= 7;
  out << numLen(K) << '\n';
}

Measured memory_bytes: 3628
#include <stdio.h>
int arr[31];
int main(){
	int N,M;
	scanf("%d %d",&N,&M);
	for(int i=0;i<N;i++){
		int num;
		scanf("%d",&num);
		for(int j=0;j<num;j++){
			int tmp;
			scanf("%d",&tmp);
			arr[tmp]++;
		}
	}
	int cnt=0;
	for(int i=0;i<=M;i++) cnt+=arr[i]==N;
	printf("%d",cnt);
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    ll a;
    cin >> a;
    string s;
    cin >> s;

    if(a < 3200){
        s = "red";
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3600
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, k = geta(int)
    s = gete()

    print(s[:k-1] + s[k-1].lower() + s[k:])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    string s;
    cin >> n >> s;
    stack<char> st;
    for(int i = n-1; i >= 0; --i) {
        if(s[i] == '(') {
            if(st.empty()) st.push(s[i]);
            else if(st.top() == ')') st.pop();
            else st.push(s[i]);
        }
        else if(s[i] == ')') {
            st.push(s[i]);
        }
    }
    int cr = 0;
    int cl = 0;
    while(!st.empty()){
        char x = st.top(); st.pop();
        if(x == '(') cr++;
        else cl++;
    }
    string r = "";
    string l = "";
    REP(i,cr) r += ")";
    REP(i,cl) l += "(";
    cout << l << s << r << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


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

  int cnt[4] = {};
  for(int i=0;i<3;i++){
    int a, b;
    cin>>a>>b; a--, b--;
    cnt[a]++;
    cnt[b]++;
  }

  int ans = (*max_element(cnt, cnt+4)) <= 2;
  cout<<(ans? "YES":"NO")<<endl;
  
  return 0;
}


Measured memory_bytes: 256
s = input()
t = input()
s_lst = [i for i in s]
ans = 0
for i in range(len(s_lst)):
    tmp = s_lst[len(s_lst)-1]
    s_lst.pop()
    a = []
    a.append(tmp)
    for j in s_lst:
        a.append(j)
    s_lst = a
    b = "".join(a)
    if b == t:
        ans += 1
if ans >=1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	c, b, _ := intScanner(), intScanner(), intScanner()
	fmt.Println(c * b / 2)
}


Measured memory_bytes: 1772
v = []
e = ''
for i in range(6):
    v.append(int(input()))

for i in range(len(v)) :
    for j in range(i+1, len(v)):
        if(abs(v[i] - v[j]) > v[-1]):
            e = ':('

if e != '':
    print(e)
else:
    print('Yay!')
        

Measured memory_bytes: 3316
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class T5 {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int n = in.nextInt();
            int[] data = in.na(n);
            Map<Long, Integer> ct = new HashMap<>();
            long cur = 0;
            ct.put(0L, 1);
            long res = 0;
            for (int i : data) {
                cur += i;
                res += ct.getOrDefault(cur, 0);
                ct.merge(cur, 1, Math::addExact);
            }
            out.println(res);

        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = nextInt();
            }
            return k;
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 48204
#include "bits/stdc++.h"
using namespace std;

#define F(i, a, n) for(int i=a;i<n;i++)
#define REP(i, n) F(i, 0, n)
#define REP1(i, n) for(int i=1;i<=n;i++)
#define MOD 1000000007

typedef long long ll;

const int MAX = 2e6 + 5;

string a,b,c;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b>>c;
	if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    int N;
    cin >> N;
    ll ans = 1;
    ll A[N];
    bool b = true;
    bool c = true;
    ll m = pow(10, 18);
    for(int i = 0; i < N; i++){
        ll a;
        cin >> a;
        A[i] = a;
        if(a == 0){
            b = false;
            break;
        }
    }
    if(b){
        for(int i = 0; i < N; i++){
            ans *= A[i];
            if(ans >= m+1 || ans <= 0){
                c = false;
                break;
            }
        }
    }
    if(b && c){
        cout << ans << endl;
    } else if (b){
        cout << -1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	string s,t;
	cin>>s>>t;
	rep(i,sz(s)){
		if(s[i]!=t[i]){
			cout<<"No";
			return;
		}
	}
	cout<<"Yes";
	
}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int A[100][100];
int B[100][100];
bool dp[81][81][55000];

void solve() {
    int h, w;
    cin >> h >> w;
    REP(i, 1, h + 1) REP(j, 1, w + 1) cin >> A[i][j];
    REP(i, 1, h + 1) REP(j, 1, w + 1) cin >> B[i][j];
    REP(i, 1, h + 1) REP(j, 1, w + 1) {
        A[i][j] -= B[i][j];
    }

    const int x = 27500;
    dp[1][1][x + A[1][1]] = 1;
    dp[1][1][x - A[1][1]] = 1;

    REP(i, 1, h + 1) REP(j, 1, w + 1) {
        rep(a, 55000) {
            if (a + A[i][j] >= 0 && a + A[i][j] < 55000) {
                dp[i][j][a + A[i][j]] |= dp[i - 1][j][a];
                dp[i][j][a + A[i][j]] |= dp[i][j - 1][a];
            }
            if (a - A[i][j] >= 0 && a - A[i][j] < 55000) {
                dp[i][j][a - A[i][j]] |= dp[i - 1][j][a];
                dp[i][j][a - A[i][j]] |= dp[i][j - 1][a];
            }
        }
    }
    int ans = INF;
    rep(i, 55000) if (dp[h][w][i]) chmin(ans, abs(i - x));
    cout << ans << endl;
}

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


Measured memory_bytes: 347748
#include<stdio.h>
#include<stdlib.h>
int asc(const void* a, const void* b)
{
	if (*(int*)a > * (int*)b)return 1;
	if (*(int*)a < *(int*)b)return -1;
	return 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	qsort(a, n, sizeof(int), asc);
	int ans = 0;
	int u[200005];
	for (i = 0; i < n; i++)
		u[i] = 0;
	int p, min, mid, max;
	for (i = n - 1; i > 0; i--)
	{
		if (u[i] > 0)
			continue;
		p = 1;
		while (p <= a[i])
			p *= 2;
		min = 0;
		max = i;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (a[mid] + a[i] > p)
				max = mid;
			else
				min = mid;
		}
		while (a[min] + a[i] == p && u[min] > 0)
		{
			min--;
			if (min < 0)
				break;
		}
		if (min >= 0)
		{
			if (a[min] + a[i] == p)
			{
				ans++;
				u[min] = 1;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1788
let n = Scanf.scanf " %d" (+) 0
let ws = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref max_int
let _ =
  for t = 1 to n - 1 do
    let s1, s2 = ref 0, ref 0 in
    Array.iteri (fun i w -> if i + 1 <= t then s1 := !s1 + w else s2 := !s2 + w) ws;
    ans := min !ans @@ abs @@ !s1 - !s2 done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.equals("Sunny")){
            System.out.println("Cloudy");
        } else if (s.equals("Cloudy")) {
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }
    }
}



Measured memory_bytes: 20688
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos and *pos <= '9') n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos and *pos <= '9') a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos and *pos <= '9') pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos and *pos <= '9') b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    int now = nn;
    int ans = now;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
    } while(ans);
    do { putchar_unlocked(*(--pos)); } while(pos != reader);
}


Measured memory_bytes: 7892
n = int(input())
p = [int(input()) for i in range(n)]

max_diff = -float('inf')
min_n = p[0]

for i in range(1, n):
  max_diff = max(max_diff, p[i] - min_n)
  min_n = min(min_n, p[i])

print(max_diff)

Measured memory_bytes: 15632
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=3e3+10,mod=998244353;

int main ()
{
    FASTIO;
    ll n;
    cin >> n;
    vll a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));
    ll mid1 = a[n/2];
    ll mid2 = b[n/2];
    if(n%2==0) mid1 += a[n/2-1],mid2 += b[n/2-1];
    cout << mid2 - mid1 + 1 << endl;
    return 0;
}
/**


*/


Measured memory_bytes: 6304
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;
typedef long long ll;

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

int main(){
    string s;
    cin>>s;
    bool f1 = false;
    bool f2 = false;
    if(s[2]==s[3])f1 = true;
    if(s[4]==s[5])f2 = true;
    if(f1 && f2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 888
n,a,b=map(int,input().split())
h=[int(input()) for _ in [0]*n]
f=lambda n:lambda x:x-b*n

def calc(n):
  g=f(n)
  k=lambda x:1+x//(a-b) if x%(a-b) else x//(a-b)
  o=filter(lambda x:x>0,map(g,h))
  *p,=map(k,o)
  if not p:
    return True
  else:
    return sum(p)<=n

l,r=0,max(h)
while r-l>1:
  m=(r+l)//2
  if calc(m):
    r=m
  else:
    l=m
print(r)

Measured memory_bytes: 10908
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int sum=0;
int jie[100005];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    int all=0;
    for(int i=2;i<=n;i+=2){
        all+=a[i];
    }
    jie[1]=(sum/2-all);
    cout<<jie[1]*2<<" ";
    for(int i=2;i<=n;i++){
        jie[i]=a[i-1]-jie[i-1];
        cout<<jie[i]*2<<" ";
    }
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define TC int tt; cin >> tt; for(int t=0; t<tt; t++)
#define ll long long
#define pb push_back
#define Mod 1000000007
#define limit 1000008
using namespace std;

void solve()
{
    int a,k,i,j,n,sum=0,mx=0,ind,ct=1;
    int ac=0,wa=0,tle=0,re=0;
    string s;
    cin >> n;
    while(n--)
    {
        cin >> s;
        if(s[0]=='A')ac++;
        if(s[0]=='W')wa++;
        if(s[0]=='T')tle++;
        if(s[0]=='R')re++;
    }
    cout <<"AC x "<<ac<<endl;
    cout <<"WA x "<<wa<<endl;
    cout <<"TLE x "<<tle<<endl;
    cout <<"RE x "<<re<<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
 //   TC
        solve();
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  vector<int> Rate(N);
  
  for (int i = 0; i < N; i++) {
    cin >> Rate.at(i);
  }
  
  int minR = Rate.at(0);
  int maxP = -2000000000;
  
  for (int j = 1; j < N; j++) {
    maxP = max(maxP, Rate.at(j) - minR);
    minR = min(minR, Rate.at(j));
  }
  
  cout << maxP << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
  int N,T; cin >> N >> T;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  
  map<int, int, greater<int>> dic;
  int Amax;
  rep(i,N) {
    if (i == 0) Amax = A[N-1];
    else {
      dic[max(0,Amax - A[N-1-i])]++;
      chmax(Amax,A[N-1-i]);
    }
  }
  cout << dic.begin()->second << endl;
}

Measured memory_bytes: 5376
def f(n):
    if (n % 2) == 0:
        return n // 2
    else:
        return 3 * n + 1

s = int(input())
#コラッツ予想を認める
n = 1
b4 = 0
b2 = 0
while s!=1:
    if s == 4:
        b4 = 1
    elif s==2:
        b2 = 1
    s = f(s)
    n += 1
k = 3
if b4 == 1:
    k = 1
elif b2 == 1:
    k = 2
print(n+k)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 31
#define INF (1e9)
using namespace std;
typedef pair<double,int> P;
typedef  pair<P,int> PP;
struct dat{
  double cost;
  int pos,pre,v;
  bool operator > (dat x)const{return cost>x.cost;}
};
int n,m;
vector<dat> G[N];

double dijkstra(int s,int g){
  double D[N][N][N];
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      for(int k=0;k<N;k++)D[i][j][k]=INF;
  priority_queue<dat,vector<dat>,greater<dat> >Q;
  Q.push((dat){0,s,-1,0});
  D[s][s][1]=0;
  while(!Q.empty()){
    dat t=Q.top();Q.pop();
    double cost=t.cost;
    int pos=t.pos;
    int pre=t.pre;  
    int v=t.v;
    if(D[pos][pre][v]<cost)continue;
    if(pos==g&&v==1) return cost;
    
    for(int i=max(1,v-1);i<=v+1;i++){
      for(int j=0;j<G[pos].size();j++){
	double ncost=cost+G[pos][j].cost/i;
	int mxv=G[pos][j].v;
	int nx=G[pos][j].pos;
	if(nx==pre||mxv<i||D[nx][pos][i]<=ncost)continue;
	Q.push((dat){ncost,nx,pos,i});
	D[nx][pos][i]=ncost;
      }
    }
  }
  return -1;
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    int s,g;
    cin>>s>>g;s--,g--;
    for(int i=0;i<n;i++)G[i].clear();
    for(int i=0,a,b,d,c;i<m;i++){
      cin>>a>>b>>d>>c;a--,b--;
      G[a].push_back((dat){d,b,-1,c});
      G[b].push_back((dat){d,a,-1,c});
    }
    double ans=dijkstra(s,g);
    if(ans==-1) cout<<"unreachable"<<endl;
    else printf("%.12f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3872
#include<stdio.h>
int main(){
    int n,k,i;
    char s[11]; 
    scanf("%d%s%d",&n,s,&k);
    for(i=0;s[i]!='\0';i++)if(s[i]!=s[k-1])s[i]='*';
    printf("%s\n",s);
    return 0;
}

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

using namespace std;

int main() {
    int n;

    cin >> n;
    int a[n];

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

    double sum;

    for (int i = 0; i < n; ++i) sum += 1.0/a[i];

    sum = 1/sum;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         10^9+7
#define endl 	    '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
using namespace std;
int gcd(int a, int b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int power(int x,  int y, int p){
    int res = 1;      // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1; // y = y/2
            x = (x*x) % p;
    }
    return res;
}

int mod_inv(int a,int m){
    a=a%m;
    return power(a,m-2,m)%MOD;
}

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

bool mod(double a,double b) {
    return a/b - floor(a/b);}

int logb(int base, int x) {
    return (log(x) / log(base));
}
char ToLower(char c)
{
    if ((c >= 'A') && (c <= 'Z')) return (char)((int)c - 'A' + 'a');
    else return c;
}

int Vowel(char c)
{
    c = ToLower(c);
    return (c == 'a') || (c == 'o') || (c == 'i') || (c == 'y') || (c == 'u') || (c == 'e');
}
signed main()
{
   int a;
   cin>>a;
   cout<<a+pow(a,2)+pow(a,3)<<endl;
}


Measured memory_bytes: 4268
def solve():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))

    right = K
    left = 0
    mx = 0
    for p in P[left:right]:
        mx += getExpected(p)
    now = mx

    while right < N:
        now = now - getExpected(P[left]) + getExpected(P[right])
        
        mx = max(now,mx)
        left += 1
        right += 1
    
    print(mx)

def getExpected(n):
    retval = 0
    for i in range(1,n+1):
        retval += (1/n) * i
    return retval

if __name__ == '__main__':
    solve()

Measured memory_bytes: 71792
#include <stdio.h>
#include <string.h>
#define bufsize 1<<22
char ibuf[bufsize];
char *ptr=ibuf;

void readint(int *i)
{
    *i=0;
    while(*ptr>='0')
    {
        *i=*i*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
}

int h,w;
int obs(int i,int j)
{
    if(i<0 || j<0 || i>=h || j>=w) return 1;
    return ptr[i*(w+1)+j]=='@';
}

main()
{
    fread(ibuf,1,bufsize,stdin);

    int k,sx,sy,tx,ty;
    readint(&h);
    readint(&w);
    readint(&k);
    readint(&sx);
    readint(&sy);
    readint(&tx);
    readint(&ty);
    sx--,sy--,tx--,ty--;

    struct po {int x,y;};
    struct po qu[1<<20];
    struct po *beg=qu,*end=qu+1;
    beg->x=sx,beg->y=sy;
    unsigned int dist[1<<20];
    memset(dist,-1,sizeof(dist));
    dist[sx*w+sy]=0;
    while(beg!=end)
    {
        int x=beg->x,y=beg->y;
        unsigned int d=dist[x*w+y];
        ++beg;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a++,z+=w;
            if(obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b++,z++;
            if(obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a--,z-=w;
            if(obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b--,z--;
            if(obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
    }
    puts("-1");
}


Measured memory_bytes: 11356
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
const ll INF = 1<<30;

int main(){
    ll N,W;
    cin  >> N >> W;
    vector<ll> w(N+1),v(N+1);
    rep(i,N) cin >> w[i] >> v[i];
    vector<vector<ll> > dp(N+10,vector<ll>(100100,INF));
    dp[0][0] = 0;
    rep(i,N){
        rep(sumv,100100){
            // i番目の品物を選ぶ場合
            if(sumv - v[i] >= 0) dp[i+1][sumv] = min(dp[i+1][sumv],dp[i][sumv - v[i]] + w[i]);

            // i番目の品物を選ばない場合
            dp[i+1][sumv] = min(dp[i+1][sumv],dp[i][sumv]);
        }
    }
    ll ans = 0;
    rep(sumv,100100){
        if(dp[N][sumv] <= W) ans = sumv;
    }
    cout << ans << endl;
}

Measured memory_bytes: 87296
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n, m;
	while (2 == scanf("%d%d", &n, &m)) {
		printf("%d %d\n", __gcd(n, m), n / __gcd(n, m) * m);
	}
	return 0;
}

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

using namespace std;

int main(){
    string a;
    cin >> a;
    
    int max = 0;
    int i = 0;
    for (char b : a) {
        switch(b) {
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                i++;
                break;
            default:
                if(max < i) {
                    max = i;
                }
                i = 0;
                break;
        }
    }
    if(max < i) {
        max = i;
    }
    cout << max;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<< name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_time()
#endif


#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	int k,x;
	cin>>k>>x;
	int l = 1000000;
	for(int i = max(-l, x-k+1); i<=min(l, x+k-1); i++){
		cout<<i<<" ";
	}
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	end_time();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n);
    rep(i,n) {
        vector<int> dist(n,INF);
        dist[i] = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            if (v-1 >= 0) {
                if (dist[v-1] == INF) {
                    dist[v-1] = dist[v]+1;
                    q.push(v-1);
                }          
            }
            if (v+1 <= n-1) {
                if (dist[v+1] == INF) {
                    dist[v+1] = dist[v]+1;
                    q.push(v+1);
                }
            }
            if (v == x) {
                if (dist[y] == INF) {
                    dist[y] = dist[x]+1;
                    q.push(y);
                }
            }
            if (v == y) {
                if (dist[x] == INF) {
                    dist[x] = dist[y]+1;
                    q.push(x);
                }
            }
        }
        rep(j,n) ans[dist[j]]++;
    }
    rep(i,n) ans[i] /= 2;
    for (int i = 1; i <= n-1; i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	string s1, s2;
	cin >> s1 >> s2 ; ll x = 0;
	for(ll i = 0; i < s1.size(); i++){
		if(s1 == s2){
			cout << "Yes";
			return 0;
		}
		s1 += s1[0];
		s1.erase(s1.begin());
	}
	cout << "No";
	return 0;
}

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

int main() {
    string a;
    while(cin >> a) {
        string b;
        cin >> b;
        int ans = 0;
        rep (va, 2) {
            string & s = va ? a : b,
                   & t = va ? b : a;

            for (int i = s.size() - 1; i >= 0; i--) {
                string tmp = "";
                range (j, i, s.size()) tmp += s[j];
                int cnt = 0;
                rep (j, tmp.size()) {
                    if (tmp[j] == t[j]) {
                        cnt++;
                        ans = max(ans, cnt);
                    }
                    else {
                        cnt = 0;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include<stdio.h>
#include<stdlib.h>
#define M 25

struct Node_struct{int id, par, dep, left, right, sib, height;};
typedef struct Node_struct Node;
Node node[200000];

int dfs(int pos, int dep){
  node[pos].dep = dep;
  int a = 0, b = 0;
  if(node[pos].left != -1) a = dfs(node[pos].left, dep + 1);
  if(node[pos].right != -1) b = dfs(node[pos].right, dep + 1);
  node[pos].height = a < b? b:a;
  return node[pos].height + 1;
}

int main(){
  int i, j, k;
  int n;
  int id, left, right;
  int deg;
  int root;
  scanf("%d", &n);
  if(n < 0 || n > M)exit(1);
  for(int i = 0 ; i < n ; i++) node[i].par = node[i].left = node[i].right = node[i].sib = -1;

  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d", &id, &left, &right);
    node[id].id = id;
    node[id].left = left;
    node[id].right = right;
    if(left != -1) node[left].par = id, node[left].sib = right;
    if(right != -1) node[right].par = id, node[right].sib = left;
  }

  for(i = 0 ; i < n ; i++) if(node[i].par == -1) root = i;
  dfs(root, 0);

  for(i = 0 ; i < n ; i++){
    deg = (node[i].left != -1) + (node[i].right != -1);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
	   node[i].id, node[i].par, node[i].sib, deg, node[i].dep, node[i].height);
    if(node[i].par == -1) printf("root\n");
    else if(node[i].left == -1 && node[i].right == -1) printf("leaf\n");
    else printf("internal node\n");

  }
  return 0;
}



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

using namespace std;

int main(){
	int n, w, d, p, s;
	while(cin >> n >> w >> d){
		if(!w) break;
		vector < pair<int, int> > cake;
		cake.push_back(make_pair(w, d));
		for(int i=0;i<n;i++){
			cin >> p >> s;
			int nw = cake[p-1].first, nd = cake[p-1].second;
			for(int j=p-1;j<i;j++) cake[j] = cake[j+1];
			s %= (nw+nd);
			if(s < nw){
				cake[i] = make_pair(min(s, nw-s), nd);
				cake.push_back(make_pair(max(s, nw-s), nd));
			} else {
				s -= nw;
				cake[i] = make_pair(nw, min(s, nd-s));
				cake.push_back(make_pair(nw, max(s, nd-s)));
			}
		}
		vector <int> S;
		for(int i=0;i<n+1;i++) S.push_back(cake[i].first*cake[i].second);
		sort(S.begin(), S.end());
		for(int i=0;i<n;i++) cout << S[i] << " ";
		cout << S[n] << endl;
	}
}

Measured memory_bytes: 0