akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;

int main()
{
    int n;
    while(cin >>n,n)
    {
        //schedule
        int s[50][31]={0};

        rep(i,n)
        {
            int f;
            cin >>f;
            rep(j,f)
            {
                int d;
                cin >>d;
                s[i][d]=1;
            }
        }

        int ans=-1;
        vector<vi> v(n,vi(n,0));

        //i-th day
        for(int i=1; i<=30; ++i)
        {
            rep(j,n)rep(k,j)
            {
                if(s[j][i] && s[k][i])
                {
                    v[j][j]=1;
                    v[k][k]=1;
                    v[j][k]=1;
                    v[k][j]=1;

                    rep(x,n)
                    {
                        v[j][x]|=v[k][x];
                        v[k][x]|=v[j][x];
                    }
                }
            }

            /*
            printf("day %d\n", i);
            rep(j,n)
            {
                rep(k,n) printf(" %d", v[j][k]);
                printf("\n");
            }
            */
            
            rep(j,n)
            {
                int ct=0;
                rep(k,n) ct+=v[j][k];
                if(ct==n)
                {
                    ans=i;
                    break;
                }
            }

            if(ans>0) break;
        }

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

Measured memory_bytes: 3280
n = int(input())
s = input()

l = 0
r = 1
ans = 0
# 順番に見ていく

while r < n:
  if s[l:r] in s[r:]:
    ans = max(ans, r - l)
    r += 1
  else:
    l += 1
  if l == r:
    l += 1
    r += 2
print(ans)


Measured memory_bytes: 3060
s = gets.chomp
n = s.length
num1 = ((n-1)/2)
num2 = ((n+3)/2)-1
 
str1 = s[0,num1]
str2 = s[num2,n]
 
print s == s.reverse && str1 == str1.reverse && str2 == str2.reverse ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template<class T>
class Dinic {
    struct edge {
        int to{}, rev{};
        T cap;
        edge() = default;
        edge(int to, T cap, int rev):to(to), cap(cap), rev(rev) {}
    };
    int n{};
    vector<vector<edge>> G;
    vector<int> level, iter;
public:
    Dinic() = default;
    explicit Dinic(int sz): n(sz), G(n), level(n), iter(n){}
    void add_edge(int from, int to, T cap){
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, 0, G[from].size()-1);
    }

    void bfs(int s){
        fill(level.begin(), level.end(), -1);
        queue<int> Q;
        level[s] = 0;
        Q.emplace(s);
        while(!Q.empty()){
            int v = Q.front(); Q.pop();
            for (auto &&e : G[v]) {
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v]+1;
                    Q.emplace(e.to);
                }
            }
        }
    }

    T dfs(int v, int t, T f){
        if(v == t) return f;
        for (int &i = iter[v]; i < G[v].size(); ++i) {
            edge &e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                T d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T flow(int s, int t, T lim = INF<T>){
        T fl = 0;
        while(true){
            bfs(s);
            if(level[t] < 0 || lim == 0) return fl;
            fill(iter.begin(), iter.end(), 0);
            T f;
            while((f=dfs(s,t, lim))>0){
                fl += f;
                lim -= f;
            }
        }
    }

    bool back_edge(int s, int t, int from, int to){
        for (auto &&e : G[from]) {
            if(e.to == to) {
                if(e.cap == 0 && flow(from, to, 1) == 0){
                    flow(from, s, 1);
                    flow(t, to, 1);
                    return true;
                }
            }
        }
        return false;
    }

};

int main() {
    int n, m;
    cin >> n >> m;
    Dinic<int> fl(n);
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        fl.add_edge(u, v, c);
    }
    cout << fl.flow(0, n-1) << "\n";
    return 0;
}



Measured memory_bytes: 3120
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> x(N, vector<int>(D));
    rep(i, N) {
        rep(j, D) {
            cin >> x.at(i).at(j);
        }
    }

    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {  // 2点選択
            double sum = 0;
            for (int k = 0; k < D; k++) {  // 点の距離を計算
                sum += pow(x.at(i).at(k) - x.at(j).at(k), 2);
            }
            for (int l = 1; l <= sum; l++) {
                if (sum == l * l) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	string s;
	cin >> s;
	for (int i = 0; i < SZ(s); i += 2)
		cout << s[i];
	return 0;
}


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int M, K;
    cin >> M >> K;
    if(M == 1){
        if(K == 0){
            cout << "0 0 1 1" << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    int MX = 1<<M;
    if(K >= MX){
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    for(int i=0; i<MX; i++) if(i != K) ans.push_back(i);
    ans.push_back(K);
    for(int i=MX-1; i>=0; i--) if(i != K) ans.push_back(i);
    ans.push_back(K);
    for(int i=0; i<2*MX; i++) cout << ans[i] << " \n"[i==2*MX-1];
    return 0;
}


Measured memory_bytes: 2932
n=int(input())
h=list(map(int, input().split()))

ans = 0
for cheight in range(101):
	renz = False
	for x in range(n):
		if h[x] > cheight:
			if not renz:
				renz = True
				ans += 1
		else:
			renz = False

print(ans)


Measured memory_bytes: 2940
A,B,C,D=map(int,input().split())
i=0
while(A>0 and C>0):
    if(i%2==0):
        C-=B
    else:
        A-=D
    if(A<=0 or C<=0):
        if(i%2==0):
            print('Yes')
        else:
            print('No')
        exit()
    i+=1

Measured memory_bytes: 9116
#include <stdio.h>
int main(void){
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    if(a < b){
    printf("a < b\n");
    }
    else if(a > b){
    printf("a > b\n");
    }
    else if(a == b){
    printf("a == b\n");
    }
    return 0;
}



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

int main()
{
    bool check = false;

    int N;
    cin >> N;

    for (int a = 1; a < 10; a++)
        for (int b = 1; b < 10; b++)
        {
            if (a * b == N)
            {
                puts("Yes");
                return 0;
            }
        }

    puts("No");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2425&lang=jp
typedef long long ll;
#define INF 1<<30
#define MAXL 256
#define CENTER 128
int d[MAXL][MAXL][6];
bool masu[MAXL][MAXL];
int dx[7] = { 0,1,1,0,-1,-1,0 };
int dy1[7] = { 1,0,-1,-1,-1,0,0 };
int dy2[7] = { 1,1,0,-1,0,1,0 };
void init(int lx, int ly) {
	for (int i = -ly - 1; i <= ly + 1;i++) {
		masu[CENTER + lx + 1][CENTER + i] = true;
		masu[CENTER - lx - 1][CENTER + i] = true;
	}
	for (int i = -lx - 1; i <= lx + 1;i++) {
		masu[CENTER + i][CENTER + ly + 1] = true;
		masu[CENTER + i][CENTER - ly - 1] = true;
	}

	for (int i = 0; i < MAXL; i++) {
		for (int j = 0; j < MAXL;j++) {
			for (int k = 0; k < 6;k++) {
				d[i][j][k] = INF;
			}
		}
	}
}
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
	sx += CENTER; sy += CENTER; gx += CENTER; gy += CENTER;
	int n; cin >> n;
	for (int i = 0; i < n;i++) {
		int x, y; cin >> x >> y;
		masu[CENTER + x][CENTER + y] = true;
	}
	int lx, ly; cin >> lx >> ly;
	init(lx, ly);

	/*                 x    y    t   */
	using Key = tuple<int, int, int>;
	d[sx][sy][0] = 0;
	queue<Key> q; q.push(Key(sx,sy, 0));
	while (!q.empty()) {
		int x, y, t; tie(x, y, t) = q.front(); q.pop();
		int dir = abs((x - CENTER)*(y - CENTER)*t) % 6;
		//int dir = t % 6;
		int nx, ny;
		int nt = t + 1;
		for (int i = 0; i < 7;i++) {
			nx = x + dx[i];
			if (x % 2 == 0) { ny = y + dy1[i]; }
			else { ny = y + dy2[i]; }

			int cost = 1;
			if (masu[nx][ny])continue;
			
			if (i == dir) cost = 0;

			//int next_dir = abs((nx - CENTER)*(ny - CENTER)*nt) % 6;
			//int next_dir = nt % 6;
			if (d[nx][ny][nt % 6] > d[x][y][t % 6] + cost) {
				d[nx][ny][nt % 6] = d[x][y][t % 6] + cost;
				if (nx == gx && ny == gy) continue;
				q.push(Key(nx, ny, nt));
			}
		}
	}
	int ans = INF;
	for (int i = 0; i < 6;i++) {
		ans = min(ans, d[gx][gy][i]);
	}
	cout << (ans == INF ? -1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 4880
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

int main(){
	string S,T;
	cin >> S;
	cin >> T;
	S.push_back(*T.rbegin());
	if(S==T){
		cout << "Yes";
	}else{
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 3572
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve(n int, s []byte) int {
	mMax := n / 2
	mMin := 0
	for true {
		if mMax == mMin {
			return mMax
		}
		m := (mMax + mMin + 1) / 2
		for i := 0; ; i++ {
			s1 := s[i : i+m]
			s2 := s[i+m:]
			if len(s2) < m {
				mMax = m - 1
				break
			}
			if bytes.Contains(s2, s1) {
				mMin = m
				break
			}
		}
	}
	return 0
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()
	s := nextStringAsBytes(n)
	res := solve(int(n), s)
	fmt.Fprintln(out, res)
}

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

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


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

int main(){
double a,b,c,d,e,f;
double x,y;

while(cin >> a >> b >> c >> d >> e >> f){
y = (f*a-c*d)/(e*a-b*d);
x = (c-b*y)/a;
printf("%.3lf %.3lf\n",x,y);
}
}


Measured memory_bytes: 3108
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
	PrintWriter out;
    StringTokenizer st;
    BufferedReader br;
 	
 	class Pair implements Comparable<Pair>
	{
	    int f;
	    int s;
 
	    Pair(int t, int r) {
	       f = t;
	       s = r;
	    }
	    public int compareTo(Pair p)
	    {
	    	if(this.f!=p.f)
	    		return this.f-p.f;
 
	    	return this.s-p.s;
	    }
 	}
 // 	class Sort implements Comparator<String> 
	// { 
	//     public int compare(String a, String b) 
	//     { 
	//     	return (a+b).compareTo(b+a);
	//     } 
	// }
 
	String ns() {
        while (st == null || !st.hasMoreElements()) {
 
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    String nextLine() throws Exception {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }
 
    int nextInt() {
        return Integer.parseInt(ns());
    }
 
    long nextLong() {
        return Long.parseLong(ns());
    }
 
    double nextDouble() {
        return Double.parseDouble(ns());
    }
	
	int upperBound(long a[],long key)
	{
		int l=0,r=a.length-1;
		int i=-1;
 
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid]<key)
				l=mid+1;
 
			else{
				i=mid;	
				r=mid-1;
			}
			
		}
		return i;
	}
	int lowerBound(Pair[] a , long key)
	{
		int l = 0, r = a.length- 1;
		int i = -1;
 	
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid].f<key)
			{
				i=mid;
				l=mid+1;	
			}
 
			else
				r=mid-1;
			
		}
		return i;
	}
 
	long power(long x,long y)
	{
	    long ans=1;
	    
	    while(y!=0)
	    {
	        if(y%2==1) ans=(ans*x)%mod;
	        x=(x*x)%mod;
	        y/=2;
	    }
	    return ans%mod;
	}
	
 
	int mod= 1000000007;
	long gcd(long x ,long y)
	{
		if(y==0)
			return x;
		return gcd(y,x%y);
	}
 
	// ArrayList<Integer> a[];
	// TreeMap<Integer, Long> map;
	// int vis[];
	// long d[];
	// void dfs(int ver, int m)
	// {
	// 	map.put(ver, d[m % 3]);
	// 	for(int v : a[ver])
	// 	{
	// 		if(vis[v] == 0){
	// 			vis[v] = vis[ver] + 1;
	// 			dfs(v, m + 1);
	// 		}
	// 	}
	// }
 
 	int countSetBits(long n) 
    { 
        int count = 0; 
        while (n > 0) { 
            n &= (n - 1); 
            count++; 
        } 
        return count; 
    }

	void solve() throws IOException{
		int n = nextInt();
		Long d = nextLong();
		int cnt = 0;
		while(n -- > 0)
		{
			long x = nextLong();
			long y = nextLong();
			long f = x*x + y*y;
			if(f <= d * d)
				cnt++;
		}
		out.println(cnt);
	}
	
    void run() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
		solve();
		out.flush();
 
		out.close();
	}
 
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
}



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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define N 100010
#define M 200010
#define A 110
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int n, arr[M];
	
	cin >> n;
	for(int i = 0; i <= 200000; i++){
		arr[i] = 0;
	}
	
	for(int i = 0; i < n - 1; i++){
		int x;
		
		cin >> x;
		arr[x]++;
	}
	
	for(int i = 1; i <= n; i++){
		cout << arr[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int q; cin >> q;
    vector<ll> v;
    for(int i=0; i<q; i++){
        int a = -1; cin >> a;
        ll x;
        if(a==0){
            cin >> x;
            v.push_back(x);
        }else if(a==1){
            cin >> x;
            cout << v.at(x) << endl;
        }else{
            v.pop_back();
        }
    }
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(A)  begin((A)),end((A))
#define RALL(A) (A).rbegin(), (A).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(A) int((A).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/11  Problem: ARC 091 C / Link: http://arc091.contest.atcoder.jp/tasks/arc091_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N,A,B;

LL ans = 0LL;
LL sz, arr[1000005];

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

	cin >> N >>A >>B;
	//Erdos-Szekeres theorem
	cin >> N >> A >> B;

	if (N < A + B - 1 || N > A*B) {
		cout << "-1\n";
		return 0;
	}
	map<LL, int> compress;
	LL rem = N - (A + B - 1);
	sz = 0;
	for (LL i = B; i >= 1; i--) {
		arr[++sz] = i;
		compress[i];
	}
	for (LL i = 2; i <= A; i++) {
		arr[++sz] = i*B;
		compress[i*B];
		for (LL j = i*B - 1; j>(i - 1)*B&&rem>0; j--, rem--) {
			arr[++sz] = j;
			compress[j];
		}
	}

	int cc = 0;
	for (map<LL, int>::iterator it = compress.begin(); it != compress.end(); it++)
		it->second = ++cc;

	for (int i = 1; i <= N; i++)
		cout << compress[arr[i]] << " ";

	return 0;
}


Measured memory_bytes: 25088
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
    int N;
    cin >> N;
    cout << setprecision(10) << fixed;
    if(N%2 == 0){
        cout << 0.5 << endl;
    }else{
        cout << (double)((N+1)/2)/(double)N << endl;
    }
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc096/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    char m[51][51];
    int H, W;
    cin >> H >> W;
    rep(i, H){
        rep(j, W){
            cin >> m[i][j];
        }
    }

    int ok[51][51];
    rep(i, H){
        rep(j, W){
            ok[i][j] = 0;
        }
    }
    rep(i, H){
        rep(j, W){
            if(m[i][j] == '.') continue;

            if(i <= H - 2){
                if(m[i + 1][j] == '#'){
                    ok[i][j] = 1;
                    ok[i + 1][j] = 1;
                }
            }
            if(j <= W - 2){
                if(m[i][j + 1] == '#'){
                    ok[i][j] = 1;
                    ok[i][j + 1] = 1;
                }
            }

            if(ok[i][j] == 0){
                cout << "No" << "\n";
                return 0;
            }
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using lld = long long int ;
#define mod 1000000007; 

typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    ans%=M;
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}


int main(){
    lld N;
    cin >> N;
    if(N<3){
        std::cout << 0 ;
        return 0;
    }
    lld ans=0;

    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }


    for(int i=2;3*i<=N;i++){
        lld temp=1;
        temp*=(comb(N-2*i-1,i-1));
        temp%=mod;
        ans+=temp;
        ans%=mod;
    }
    ans+=1;
    ans%=mod;
    std::cout << ans <<endl;
    return 0;
    return 0;
}

Measured memory_bytes: 7836
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int n;
vector<vector<P>> G;
vector<ll> es;
bool dfs(int i, int p, int to, int r) {
    if (to == i) {
        return true;
    }
    for (auto &e : G[i]) {
        if (e.first == p) {
            continue;
        }
        es[r] |= (1LL << e.second);
        if (dfs(e.first, i, to, r)) {
            return true;
        }
        es[r] ^= (1LL << e.second);
    }
    return false;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    G.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(P(b, i));
        G[b].push_back(P(a, i));
    }
    int m;
    cin >> m;
    es.resize(m);
    vector<int> u(m), v(m);
    for (int i = 0; i < m; i++) {
        cin >> u[i] >> v[i];
        --u[i];
        --v[i];
        dfs(u[i], -1, v[i], i);
    }
    ll res = 0;
    for (int i = 0; i < (1 << m); i++) {
        ll c = 0;
        for (int j = 0; j < m; j++) {
            if ((i >> j) & 1) {
                c |= es[j];
            }
        }
        ll s = 1;
        for (int j = 0; j < n - 1; j++) {
            if (((c >> j) & 1LL) == 0) {
                s *= 2LL;
            }
        }
        if (__builtin_popcount(i) % 2) {
            res -= s;
        } else {
            res += s;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
    init();
    ll N;cin>>N;
    ll ans=INF;
    for(int i=0;i<N;i++){
      ll a;cin>>a;
      ll num=0;
      while(a%2==0){
        a/=2;
        num++;
      }
      ans=min(num,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>

#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)

using namespace std;

typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;

ll n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll dp[maxn][5];

int main()
{
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    repd(i,2,n)
    {
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

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

int main() {
    int H, W;
    std::cin >> H >> W;
    
    char s[H][W];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            std::cin >> s[i][j];
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (s[i][j] == '#') {
                if (!((0 < i       && s[i-1][j] == '#') ||
                      (i < (H - 1) && s[i+1][j] == '#') ||
                      (0 < j       && s[i][j-1] == '#') ||
                      (j < (W - 1) && s[i][j+1] == '#'))
                ) {
                    std::cout << "No\n";
                    return 0;
                }

            }
        }
    }

    std::cout << "Yes\n";


    return 0;
}


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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int sum = 0;
	for (int i = 0; i < M; i++) {
		int A;
		cin >> A;
		sum += A;
	}

	int ans;
	if (N < sum) {
		ans = -1;
	}
	else {
		ans = N - sum;
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3672
//
// Created by Huang,Zhiqiang on 2018/7/1.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef  long long ll;

const int max_arr = 200005;
ll A[max_arr];
int n;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        A[i] -= i;
    }
    sort(A + 1, A + n + 1);
    ll ans1 = 0, ans2 = 0;
    ll mid1 = 0, mid2 = 0;
    if (n % 2 == 1) {
        mid1 = A[(n + 1) / 2];
        mid2 = mid1;
    } else {
        mid1 = (A[(n / 2)] + A[n / 2 + 1]) / 2;
        mid2 = (A[(n / 2)] + A[n / 2 + 1] + 1) / 2;
    }
    for (int i = 1; i <= n; i++) {
        ans1 += abs(A[i] - mid1);
        ans2 += abs(A[i] - mid2);
    }
    ll ans = ans1 > ans2 ? ans1 : ans2;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  vector<double> v(n);
  for(int i=0;i<n;i++){
    cin>>v.at(i);
  }
  double gyaku=0;
  for(int j=0;j<n;j++){
    gyaku=gyaku+1/v.at(j);
  }
  cout << fixed << setprecision(7);
  cout<<1/gyaku<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A, B, C, K, qw = 0;
	cin >> A >> B >> C >> K;
	if(K - A >= 0){
		qw = qw + A;
		K = K - A;
		if(K - B >= 0){
			K = K - B;
			if(K - C >= 0){
				qw = qw - C;
            } else{
				qw = qw - K;
            }
        }
    } else {
		qw = qw + K;
    }
	cout << qw;
}

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

using namespace std;

const int N = 50;

bool used[N], data[N][N];
int n, k, r, m, in, in2;

main(){
  fill(used, used+N, false);
  fill(data[0], data[N], false);
  cin >> n >> k;
  for(int i=0;i<k;i++){
    cin >> m;
    for(int j=0;j<m;j++){
      cin >> in;
      data[i][in-1] = true;
    }
  }
  cin >> r;
  for(int i=0;i<r;i++){
    cin >> in >> in2;
    for(int j=0;j<k;j++){
      if(data[j][in-1] && data[j][in2-1]) used[in-1] = used[in2-1] = true;
    }
  }
  int ans = 0;
  for(int i=0;i<n;i++) if(used[i]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 1160
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class C
{
	public static void Main()
	{
		int n = GetInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++)
			a[i] = GetInt();
		
		LinkedList<int> b = new LinkedList<int>();
		for(int i = 0; i < n; i += 2)
			b.AddLast(a[i]);
		for(int i = 1; i < n; i+= 2)
			b.AddFirst(a[i]);

		if(n % 2 == 0)
		{
			for(LinkedListNode<int> node = b.First; node != null; node = node.Next)
				Console.Write("{0} ", node.Value);
		}
		else
		{
			for(LinkedListNode<int> node = b.Last; node != null; node = node.Previous)
				Console.Write("{0} ", node.Value);
		}
		Console.WriteLine();
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 43032
#include <stdio.h>

int main()
{
  int n;
  scanf("%d",&n);
  int i,j;
  i = 1;
  while (i <= 9)
  {
    j = 1;
    while (j <= 9)
    {
      if (i * j == n)
      {
        printf("Yes");
        return (0);
      }
      j++;
    }
    i++;
  }
  printf("No");
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int n, m, l;
	int matrix[105][105], matrix1[105][105];
	long long int hasil[105][105], s;
	scanf("%d%d%d", &n, &m, &l);
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			scanf("%d", &matrix[i][j]);
		}
	}
	for(int i=0; i<m; i++){
		for(int j=0; j<l; j++){
			scanf("%d", &matrix1[i][j]);
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<l; j++){
			s=0;
			for(int k=0; k<m; k++){
				s+= matrix[i][k]*matrix1[k][j];
			}
			hasil[i][j] = s;
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<l; j++){
			if(j==0) printf("%lld", hasil[i][j]);
			else printf(" %lld", hasil[i][j]);
		}
		printf("\n");
	}
}


Measured memory_bytes: 2932
#include"bits/stdc++.h"
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	bool ch=false;
	for(int i=0;i!=a.size();++i){
		if(a==b){
			ch=true;
			break;
		}
		a.push_back(a[0]);
		a.erase(0,1);
	}
	if(ch)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
using namespace std;
struct Edge
{
	int to;
	int nxt;
}e[200005];
int p[100005],n,m,edgenum,head[100005],tmp[100005],top;
ll a[100005],b[100005];
bool flag[100005],used[100005];
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >q;
void add(int u,int v)
{
	e[++edgenum].to=v;
	e[edgenum].nxt=head[u];
	head[u]=edgenum;
}
bool cmp(int x,int y)
{
	return a[x]<a[y];
}
bool bfs(int st,ll v)
{
	while(!q.empty()) q.pop();
	top=0;
	q.push(make_pair(a[st],st));
	while(!q.empty())
	{
		if(q.top().first>v)break;
		int node=q.top().second;
		q.pop();
		if(flag[node])continue;
		tmp[++top]=node;
		v+=b[node];
		flag[node]=used[node]=1;
		for(int hd=head[node];hd;hd=e[hd].nxt)
		{
			int to=e[hd].to;
			if(flag[to])continue;
			q.push(make_pair(a[to],to));
		}
	}
	for(int i=1;i<=top;i++)flag[tmp[i]]=0;
	return top==n;
}
bool check(ll v)
{
	for(int i=1;i<=n;i++)p[i]=i;
	random_shuffle(p+1,p+n+1);
	memset(used,0,sizeof(used));
	memset(flag,0,sizeof(flag));
	for(int i=1;i<=n;i++)
	{
		if(used[p[i]])continue;
		if(bfs(p[i],v))return 1;
	}
	return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		a[i]-=b[i];
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	ll l=0,r=1e15;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	for(int i=1;i<=n;i++)l+=b[i];
	printf("%lld\n",l);
	return 0;
}

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

using namespace std;

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

    int s1 = 0, s2 = 0;
    for (int i = 0; i < n; ++i) {
        int d;
        cin >> d;
        s1 += d;
        s2 += d * d;
    }

    cout << (s1 * s1 - s2) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func StrStdin() (stringReturned string) {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	var n int
	var a int
	var b int
	fmt.Scanf("%d %d %d", &n, &a, &b)

	if ((n * a) >= b) {
		fmt.Printf("%d", b)
	} else {
		fmt.Printf("%d", n * a)
	}

}


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


int main() {
    unsigned long n,a,b,s,t,u,v;
    cin>>n>>a>>b;
    
    s = n/(a+b);
    t = n%(a+b);
    if(t<a)v=t;
    else v=a;
    
    u = s*a+v;
    
    cout<<u<<endl;
    
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <stdio.h>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <queue>

using namespace std;

#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define MP make_pair
#define EPS      1e-9
#define F        first
#define S        second
#define sc(x)     scanf("%d",&x)
#define scl(x)     scanf("%I64d",&x)
#define sq(x)     (x)*(x)
#define INF (1000000000)
#define oo (1ll<<60)
#define PI acos(-1)
#define POW(x) ((x)*(x))

typedef stringstream ss;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<int, int> ii;
typedef vector<int> rows;
typedef vector<rows> matrix;

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

const int MOD = 1000000007;
const int N = 1e5 + 10;


int main() {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
	int n,k;
	cin>>n>>k;
	int ans = 1;
	for(int i=0;i<n;++i)
	{
		if(ans*2<=ans+k)
			ans*=2;
		else ans+=k;
	}
	cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 256
import numpy as np

n, k = [int(i) for i in input().split()]

dp = np.zeros(n, dtype=int)

steps = np.array([int(i) for i in input().split()])

for i in range(1, n):
    start = max(0, i-k)
    dp[i] = (dp[start:i] + abs(steps[i] - steps[start:i])).min()

print(dp[-1])

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

const int MOD = 1000 * 1000 * 1000 + 7;

const int LIMIT = (2 * 80 - 1) * 80;

int my_abs(int x) {
	if (x < 0) return -x;
	return x;
}

void solve_test() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(m));
	vector<vector<int>> b(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> b[i][j];

	vector<vector<vector<int>>> dp(n, vector<vector<int>>(m, vector<int>(LIMIT * 2 + 1, INT_MAX)));
	for (int s = -LIMIT; s <= LIMIT; s++)
		dp[n - 1][m - 1][s + LIMIT] = my_abs(s);
	for (int i = n - 1; i >= 0; i--)
		for (int j = m - 1; j >= 0; j--)
			for (int s = -LIMIT; s <= LIMIT; s++) {
				if (i == n - 1 && j == m - 1)
					continue;

				if (i + 1 < n) {
					int diff = a[i + 1][j] - b[i + 1][j];
					if (-LIMIT <= s + diff && s + diff <= LIMIT)
						dp[i][j][s + LIMIT] = min(dp[i][j][s + LIMIT], dp[i + 1][j][s + diff + LIMIT]);
					if (-LIMIT <= s - diff && s - diff <= LIMIT)
						dp[i][j][s + LIMIT] = min(dp[i][j][s + LIMIT], dp[i + 1][j][s - diff + LIMIT]);
				}
				if (j + 1 < m) {
					int diff = a[i][j + 1] - b[i][j + 1];
					if (-LIMIT <= s + diff && s + diff <= LIMIT)
						dp[i][j][s + LIMIT] = min(dp[i][j][s + LIMIT], dp[i][j + 1][s + diff + LIMIT]);
					if (-LIMIT <= s - diff && s - diff <= LIMIT)
						dp[i][j][s + LIMIT] = min(dp[i][j][s + LIMIT], dp[i][j + 1][s - diff + LIMIT]);
				}
			}
	int diff = a[0][0] - b[0][0];
	cout << min(dp[0][0][diff + LIMIT], dp[0][0][-diff + LIMIT]) << '\n';
}

int main() {
	int T;
	T = 1;
	for (int t = 1; t <= T; t++)
		solve_test();

	return 0;
}


Measured memory_bytes: 647688
n = int(input())
a = list(map(int,input().split()))
mode = 0
ans = 1
for i in range(1,n):
    d = a[i]-a[i-1]
    if mode == 0:
        mode = d
        continue
    if mode>0:
        if d<0:
            ans += 1
            mode = 0
    elif mode<0:
        if d>0:
            ans += 1
            mode = 0
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// 剰余演算クラス
struct ModInt{
    static const LL MOD = 998244353;
    LL v;
    ModInt():v(0){}
    ModInt(LL op):v(op % MOD){}
    ModInt operator+(ModInt op) const{ return (v + op) % MOD; }
    ModInt operator-(ModInt op) const{ return (v - op + MOD) % MOD; }
    ModInt operator*(ModInt op) const{ return (v * op) % MOD; }
    ModInt operator/(ModInt op) const{ return (v * op.inverse()) % MOD; }
    ModInt operator%(LL op) = delete;
    ModInt operator+=(ModInt op){ return v = (v + op) % MOD; }
    ModInt operator-=(ModInt op){ return v = (v - op + MOD) % MOD; }
    ModInt operator*=(ModInt op){ return v = (v * op) % MOD; }
    ModInt operator/=(ModInt op){ return v = (v * op.inverse()) % MOD; }
    ModInt operator-() const{ return MOD - v; }
    bool operator==(ModInt op) const{ return v == op.v; }
    bool operator!=(ModInt op) const{ return v != op.v; }
    ModInt inverse() const{ return pow(MOD-2); }
    ModInt pow(LL n) const{
        if(n < 0) return pow(MOD-1 + n);
        if(n == 0) return 1;
        ModInt res = pow(n/2);
        return res * res * ((n&1)?ModInt(v): ModInt(1));
    }
    LL get() const{ return v; }
private:
    operator LL() const{ return v; }
};
istream& operator>>(istream& st, ModInt& m){ st>>m.v; return st; }
ostream& operator<<(ostream& st, const ModInt& m){ st<<m.v; return st; }


vector<ModInt> factorial(LL n){
    vector<ModInt> res(n, 1);
    for(LL i = 2; i < n; ++i) res[i] = res[i-1] * ModInt(i);
    return res;
}

ModInt permutation(LL n, LL m, vector<ModInt>& factorial){
    if(m < 0 || n < m) return 0;
    if(m == 0) return 1;
    return factorial.at(n) / factorial.at(n-m);
}

ModInt combination(LL n, LL m, vector<ModInt>& factorial){
    if(m < 0 || n < m) return 0;
    if(m == 0) return 1;
    return factorial.at(n) / factorial.at(n-m) / factorial.at(m);
}


int main(){
    LL n, a, b, k;
    cin >> n >> a >> b >> k;
    vector<ModInt> f = factorial(1000010);
    vector<ModInt> comb(500000);
    for(LL i = 0; i < 500000; ++i){
        comb[i] = combination(n, i, f);
    }
    ModInt ans(0);
    for(LL cnt_a = 0; cnt_a <= n; ++cnt_a){
        LL rest = k - a * cnt_a;
        if(rest < 0) continue;
        if(rest % b != 0) continue;
        LL cnt_b = rest / b;
        if(cnt_b > n) continue;
        ans += comb[cnt_a] * comb[cnt_b];
    }
    cout << ans.get() << endl;
    return 0;
}



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

typedef long long ll;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    int ans = 0;
    int mx_pr = min(k, n);
    for (int l = 0; l < mx_pr + 1; l++) {
        for (int r = 0; r < mx_pr + 1 - l; r++) {
            vector<int> hand;
            int sum = 0;
            for (int i = 0; i < l; i++) {
                hand.emplace_back(v[i]);
                sum += v[i];
            }
            for (int i = 0; i < r; i++) {
                hand.emplace_back(v[n - i - 1]);
                sum += v[n - i - 1];
            }
            sort(hand.begin(), hand.end());
            int left_counts = min(k - l - r, l + r);
            for (int i = 1; i <= left_counts; i++) {
                if (hand[i - 1] > 0) {
                    break;
                }
                sum -= hand[i - 1];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  map<char, int> charmap;
  
  REP(i,s.size()){
    charmap[s[i]]++;
  }
  
  REP(i,s.size()){
    if(charmap[s[i]] != 2){
        cout << "No" << endl;
        return 0;
    }
  }
  cout << "Yes" << endl;
  
  //cout << CX << " " << CY << " " << H << "\n";
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem1142 : Organize your Train part II **/
int main()
{
	int m;
	cin>>m;
	rep(k, m) {
		set<string> ans;
		string s;
		cin>>s;
		for (int i=1; i<=s.size(); i++) {
			string s1 = s.substr(0, i);
			string s2 = s.substr(i, s.size());
			
			ans.insert(s1+s2);
			ans.insert(s2+s1);
			
			reverse(s1.begin(), s1.end());
			ans.insert(s1+s2);
			ans.insert(s2+s1);
			
			reverse(s2.begin(), s2.end());
			reverse(s1.begin(), s1.end());
			ans.insert(s1+s2);
			ans.insert(s2+s1);
			
			reverse(s1.begin(), s1.end());
			ans.insert(s1+s2);
			ans.insert(s2+s1);
		}
		cout << ans.size() << endl;
	}
}

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

int main() {
    int n, m; scanf("%d %d", &n, &m);
    int in[10000], out[10000];
    for (int i = 0; i < n; i++) scanf("%d %d", in+i, out+i);
    int ans = m;
    int c = m;
    for (int i = 0; i < n; i++) {
        c = c + in[i] - out[i];
        if (c < 0) {
            ans = 0;
            break;
        }
        ans = max(ans, c);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1096
fun main(args: Array<String>) {
  val sc = java.util.Scanner(System.`in`)
  val A = sc.nextInt()
  val B = sc.nextInt()
  val C = sc.nextInt()
  val D = sc.nextInt()
  println(arrayOf(A, B).min()!! + arrayOf(C, D).min()!!)
}


Measured memory_bytes: 35912
mod = 998244353

A, B, C, D = map(int, input().split())

dp = [0] * (D + 1)
dp[B:D + 1] = [pow(A, i, mod) for i in range(D + 1 - B)]

for a in range(A + 1, C + 1):
    T = [0] * (D + 1)
    for b in range(B, D + 1):
        T[b] = (a * T[b - 1] + b * dp[b] - (a - 1) * (b - 1) * dp[b - 1]) % mod
    dp = T

print(dp[D])

Measured memory_bytes: 68420