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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define line printf("\n")
#define pq priority_queue
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long
#define ALL(a) a.begin(),a.end()
#define vi vector<int> 

using namespace std;

double EPS = 1e-9;
int INF = 1e9+7;;
long long INFLL = 1e17;
double pi = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

clock_t first_attempt = clock();
inline void cek_time(){
	clock_t cur = clock()- first_attempt;
	cerr<<"TIME : "<<(double) cur/CLOCKS_PER_SEC<<endl;
}
inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of template

const int maxn =1e5+5;

int n;

vector<pii> edges;
pii arr[maxn];

int X(int a,int b){return arr[a].fi<arr[b].fi;}
int Y(int a,int b){return arr[a].se<arr[b].se;}

int val(pii a){return min(abs(arr[a.fi].fi-arr[a.se].fi),abs(arr[a.fi].se-arr[a.se].se));}
int cmp(pii a,pii b){return val(a)<val(b);}
int id[maxn];

int par[maxn];
int root(int a){if(par[a]==a)return a;return par[a] = root(par[a]);}
void join(int a,int b){
	a = root(a),b = root(b);
	if(a!=b)par[a] = b;
}
int main(){
	scanf("%d",&n);
	
	rep(k,0,n)scanf("%d%d",&arr[k].fi,&arr[k].se),id[k] = k;
	
	sort(id,id+n,X);
	rep(k,1,n)edges.pb(mp(id[k-1],id[k]));
	sort(id,id+n,Y);
	rep(k,1,n)edges.pb(mp(id[k-1],id[k]));
	
	sort(edges.begin(),edges.end(),cmp);
	ll ret = 0;
	rep(k,0,n)par[k] = k;
	for(pii a : edges){
		if(root(a.fi)!=root(a.se))join(a.fi,a.se),ret += val(a);
	}
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 3572
import math

def main():
    N = int(input())
    sqrt = math.sqrt(N)
    ans = len(str(N))
    for i in range(1, int(sqrt) + 1):
        if N % i == 0:
            b = N // i
            ans = len(str(b))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();
		int d = s.nextInt();
		int busBudget = 0;
		int trainBudget = 0;

		if (a == b) {
			trainBudget = a;
			busBudget = c < d ? c : d;
		} else if (c == d) {
			trainBudget = a < b ? a : b;
			busBudget = c;
		} else {
			trainBudget = a < b ? a : b;
			busBudget = c < d ? c : d;
		}
		System.out.println(busBudget + trainBudget);
	}
}


Measured memory_bytes: 21716
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	n, a, b := readInt(), readInt(), readInt()

	train := n * a
	taxi := b

	fmt.Println(min(train, taxi))
}


Measured memory_bytes: 1768
# -*- coding: utf-8 -*-
y, m, d = map(int, input().split("/"))
if y < 2019:
    print("Heisei")
elif y == 2019 and m < 4:
    print("Heisei")
elif y == 2019 and m == 4 and d <= 30:
    print("Heisei")
else :
    print("TBD")


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

int main(){
  int n;
  cin >> n;
  int d[n];
  rep(i,n) cin >> d[i];
  int a = 10;
  rep(i,n){
    a -= 10;
    if(a < 0){
      cout << "no" << endl;
      return 0;
    }
    a = max(a,d[i]);
  }
  a = 10;
  reverse(d,d+n);
  rep(i,n){
    a -= 10;
    if(a<0){
      cout << "no" << endl;
      return 0;
    }
    a = max(a,d[i]);
  }
  cout << "yes" << endl;
  return 0;
}



Measured memory_bytes: 4260
import java.util.Scanner;
class Main {
	int a,b,c;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		if(a < b){
			if(b < c){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}else{
			System.out.println("No");
		}
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) (n)*(n)

using namespace std;
typedef long long ll;

int main() {
    FAST;

    double r;
    cin >> r;
    cout << (2*PI*r) << endl;

    return 0;
}


Measured memory_bytes: 3800
#include <stdlib.h>
#include <stdio.h>
int compare(const void *a,const void *b)
{
    if(*(long long *)a>*(long long *)b)return -1;
    return 1;
}
int main()
{   int x,y,z,k,i,j,l;
    long long min;
    scanf("%d%d%d%d",&x,&y,&z,&k);
    if(x*y*z<3000)min=x*y*z;else min=3000;
    long long a[x],b[y],c[z];
    for(i=0;i<x;i++)scanf("%lld",&a[i]);
    for(j=0;j<y;j++)scanf("%lld",&b[j]);
    for(l=0;l<z;l++)scanf("%lld",&c[l]);
    qsort(a,x,sizeof(long long),compare);
    qsort(b,y,sizeof(long long),compare);
    qsort(c,z,sizeof(long long),compare);
    long long cnt=0,set[110000];
    for(i=0;i<x;i++){
        for(j=0;j<y;j++){
            for(l=0;l<z;l++){
                if((i+1)*(j+1)*(l+1)<=k){
                    set[cnt]=a[i]+b[j]+c[l];
                    cnt++;
                }else{
                    break;
                }
            }
        }
    }
    qsort(set,cnt,sizeof(long long),compare);
    for(i=0;i<k;i++){
        printf("%lld\n",set[i]);
    }

    return 0;
}


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  int first = false;
  for(int i=0;i<n;i++) {
    int a;
    cin >> a;
    if(a % 2 == 1) first = true;
  }
  if(first) cout << "first" << endl;
  else cout << "second" << endl;
}



Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
//const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}

ll min(ll a, ll b) {

	if (a < b)
		return a;
	else
		return b;

}


int main() {
	double a, b, x;
	double pi = 3.141592653589793;
	cin >> a >> b >> x;

	if (x <= a * a * b / 2) {

		double t = 2 * x / (b * a);

		printf("%.10f", 180.0 / pi * atan(b / t));
		
	}

	else {
		double h = 2 * (a * a * b - x) / (a * a);

		printf("%.10f", 180.0 / pi * atan(h / a));


	}

	
	return 0;
}

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

#define ll long long

using namespace std;

signed main() {
	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	int cnt_even, cnt_odd;
	cnt_even = cnt_odd = 0;

	for (auto ai : a) {
		if (ai & 1)
			++cnt_odd;
		else
			++cnt_even;
	}

	if (cnt_even == 0 || cnt_odd == 0) {
		cout << 0 << endl;
		return 0;
	}
	if (cnt_odd == 1) {
		cout << n - 1 << endl;
		return 0;
	}
	if (cnt_odd & 1) {
		cout << n - 1 << endl;
		return 0;
	}
	if (cnt_odd % 2 == 0) {
		cout << n - 2 << endl;
	}

	return 0;
}


Measured memory_bytes: 4392
from itertools import product

N, M, Q = map(int, input().split())
table = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    table[l][r] += 1
cum_sum2 = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i, j in product(range(1, N+1), repeat=2):
    cum_sum2[i][j] += table[i][j] + cum_sum2[i-1][j] + cum_sum2[i][j-1] - cum_sum2[i-1][j-1]
for _ in range(Q):
    p, q = map(int, input().split())
    ans = cum_sum2[q][q] - cum_sum2[p-1][q] - cum_sum2[q][p-1] + cum_sum2[p-1][p-1]
    print(ans)

Measured memory_bytes: 15552
import java.util.*;

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

		if (c >= a && c <= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}



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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 1e5 + 41;

ll ans;
int n, s;
int x[MAX];
ll p[MAX];

void solve() {
	deque<int> a, b;
	fi(1, n) {
		if (x[i] < s) {
			a.pb(i);
		} else {
			b.pb(i);
		}
	}
	vi per;
	while (sz(a) && sz(b)) {
		int x = a.front();
		int y = b.back();
		if (p[x] >= p[y]) {
			per.pb(y);
			p[x] += p[y];
			b.pop_back();
		} else {
			per.pb(x);
			p[y] += p[x];
			a.pop_front();
		}
	}
	while (sz(a)) {
		per.pb(a.front());
		a.pop_front();
	}
	while (sz(b)) {
		per.pb(b.back());
		b.pop_back();
	}
	reverse(per.begin(), per.end());
	fi(0, n - 1) {
		if (i == 0) {
			ans += abs(x[per[i]] - s);
		} else {
			ans += abs(x[per[i - 1]] - x[per[i]]);
		}
	}
	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d %d", &n, &s);
	fi(1, n) {
		scanf("%d %lld", &x[i], &p[i]);
	}  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){

	ll n;
	cin >> n;
	ll a[100010],b[100010];
	ll cnt=0;
	FOR(i,n+1){
		cin >> a[i];
		cnt+=a[i];
	}
	FOR(i,n){
		cin >> b[i];
	}

	FOR(i,n){
		if(b[i]>a[i]){
			a[i+1]=max(a[i+1]-(b[i]-a[i]),0ll);
						a[i]=0;

		}else{
			a[i]-=b[i];
		}
	}
	ll sum=0;
	FOR(i,n+1){
		sum+=a[i];
	}
	cout << cnt-sum << endl;
	
}

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

int main() {
  int N, A, B, riyou;
  cin >> N >> A >> B;

  riyou = N * A;

  if (riyou >= B) {
    cout << B << endl;
  }
  else{
    cout << riyou << endl;
  }
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

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

    V<ll> v(n);
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        v[i] = a - (i + 1);
    }
    sort(all(v));
    ll b = v[n / 2];

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += abs(v[i] - b);
    }
    cout << ans << endl;

}


Measured memory_bytes: 4848
N = int(input())
ans = {i:0 for i in range(N+1)}
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            n = i*i + j*j + k*k + i*j + j*k + k*i
            if n in ans: ans[n] += 1
for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 68988
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),M=sc.nextInt(),ans=0;
		int[] counter = new int[M+1];
		for(int i=0; i<N;i++) {
			int num = sc.nextInt();
			for(int j=0 ;j<num; j++) {
				counter[sc.nextInt()]++;
			}
		}
		for (int i : counter) {
			if(i == N) ans++;
		}
		System.out.println(ans);
	}
}


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

int n,s,ans;

void solve(int i,int j,int t){

  if(j == s && t == n){
    ans++;
    return;
  }

  if(i == 10) return;

  solve(i+1,j,t);
  solve(i+1,j+i,t+1);
}


int main(){

  while(true){
    cin >> n >> s;
    if(!n && !s) break;

    ans = 0;
    solve(0,0,0);

    cout << ans << endl;
  }
}

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

int a[200005], b[200005];
vector<int> su;

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    su.resize(n);
    int ans = 0;
    for(int j=0;j<=28;j++){
        int cnt = 0;
        for(int i=0;i<n;i++){
            su[i] = a[i] % (1 << (j+1));
        }
        sort(su.begin(), su.end());
        for(int i=0;i<n;i++){
            int mod = (b[i] % (1 << j));
            auto it1 = lower_bound(su.begin(), su.end(), (1 << j) - mod);
            auto it2 = lower_bound(su.begin(), su.end(), (1 << (j+1)) - mod);
            int now = distance(it1, it2);
            if(b[i] & (1 << j)) now = n - now;
            cnt = (cnt + now) % 2;
        }
        if(cnt % 2) ans += (1 << j);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 2560
#include <stdio.h>
char s[200];
int n, d, ans;
int x[100];
int y[100];
void solve1(void) {
	int i = 0;
	for (int j = 0; j < 100; j++) {
		if (y[j])i = j;
	}
	ans += y[i] + i * 9;
}
void solve2(void) {
	int i = 0;
	for (int j = 0; j < 100; j++) {
		if (y[j])i = j;
	}
	ans += 81 * i * (i - 1) / 2;
	ans += (y[i] - 1) * 9 * i;
	y[i] = 0;
	solve1();
}
void solve3(void){
	int i = 0;
	for (int j = 0; j < 100; j++) {
		if (y[j])i = j;
	}
	ans += 729 * i * (i - 1) * (i - 2) / 6;
	ans += (y[i] - 1) * 81 * i * (i - 1) / 2;
	y[i] = 0;
	solve2();
}
int main() {
	scanf(" %s", s);
	scanf("%d", &n);
	while (s[d] != NULL)d++;
	for (int i = 0; i < d; i++) {
		x[i + 100 - d] = s[i] - '0';
	}
	for (int i = 0; i < 100; i++) {
		y[i] = x[99 - i];
	}
	if (n == 3)solve3();
	if (n == 2)solve2();
	if (n == 1)solve1();
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
int c=a*b;
if (c%2==0) cout<<"Even"<<endl;
else cout<<"Odd"<<endl;
return 0;
} 

Measured memory_bytes: 256
o = gets.chomp.chars
e = gets.chomp.chars
total_length = o.length + e.length
ans = []

(0...total_length).each do |i|
  if i % 2 == 0
    ans.push(o[i/2])
  else
    ans.push(e[(i-1)/2])
  end
end

puts ans.join

Measured memory_bytes: 1916
H, W = map(int, input().split())
S = [[1 if i == '#' else 0 for i in input()] for _ in range(H)]

Hdp = [[0] * W for _ in range(H)]
Wdp = [[0] * W for _ in range(H)]

for i in range(H) :
    start = 0
    count = 0
    for j in range(W) :
        if S[i][j] == 1 :
            for k in range(start, j) :
                Hdp[i][k] = count
            start = j + 1
            count = 0
        else :
            count += 1
            
    for k in range(start, j + 1) :
        Hdp[i][k] = count
        
for i in range(W) :
    start = 0
    count = 0
    for j in range(H) :
        if S[j][i] == 1 :
            for k in range(start, j) :
                Wdp[k][i] = count
            start = j + 1
            count = 0
        else :
            count += 1
            
    for k in range(start, j + 1) :
        Wdp[k][i] = count

ret = 0  
for i in range(H) :
    for j in range(W) :
        ret = max(ret, Hdp[i][j] + Wdp[i][j])
        
print(ret - 1)

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

const int MAXN = 25010;
const int MAXM = 410;
const int mod = 1000000007;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int pow(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}

int n, K, M, A[MAXN];
int judge() {
	static int B[MAXM];
	for (int i = 1; i + K - 1 <= M; ++i) {
		memset(B, 0, K + 1 << 2);
		for (int j = i; j <= i + K - 1; ++j) ++B[A[j]];
		bool can = true;
		for (int j = 1; j <= K; ++j) can &= B[j] == 1;
		if (can) return 0;
	}
	memset(B, 0, K + 1 << 2);
	for (int i = 1; i <= M; ++i) ++B[A[i]];
	int ma = *std::max_element(B + 1, B + 1 + K);
	return ma == 1 ? 1 : 2;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K >> M;
	for (int i = 1; i <= M; ++i) std::cin >> A[i];
	int typ = judge(), all = pow(K, n - M, n - M + 1);
	if (typ == 0) {
		std::cout << all << std::endl;
		return 0;
	}
	static int f[MAXN][MAXM], g[MAXN][MAXM];
	static int sf[MAXN][MAXM], sg[MAXN][MAXM];
	if (typ == 1) {
		sf[0][0] = f[0][0] = 1;
		for (int i = 1; i <= n; ++i) {
			for (int j = 0; j < K; ++j) {
				if (j + 1 < K)
				reduce(f[i][j + 1] += mul(f[i - 1][j], K - j) - mod);
				if (j + 1 < K)
				reduce(g[i][j + 1] += mul(g[i - 1][j], K - j) - mod);
				if (j) reduce(f[i][j] += sf[i - 1][j] - mod);
				if (j) reduce(g[i][j] += sg[i - 1][j] - mod);
			}
			for (int j = K; ~j; --j) {
				if (j >= M) reduce(g[i][j] += f[i][j] - mod);
				reduce(sf[i][j] = f[i][j] + sf[i][j + 1] - mod);
				reduce(sg[i][j] = g[i][j] + sg[i][j + 1] - mod);
			}
		}
		int ans = sg[n][0], B = 1;
		for (int i = 1; i <= K - M; ++i) ans = mul(ans, i);
		for (int i = 1; i <= K; ++i) B = mul(B, i);
		reduce(ans = all - pow(B, mod - 2, ans));
		std::cout << ans << std::endl;
	} else {
		static int B[MAXM];
		int px = 0;
		for (int i = 1; i <= M; ++i)
			if (B[A[i]]) break; else ++px, ++B[A[i]];
		f[0][px] = 1;
		memset(B, 0, K + 1 << 2); px = 0;
		for (int i = M; i; --i)
			if (B[A[i]]) break; else ++px, ++B[A[i]];
		g[0][px] = 1;
		for (int i = K; ~i; --i) {
			reduce(sf[0][i] = sf[0][i + 1] + f[0][i] - mod);
			reduce(sg[0][i] = sg[0][i + 1] + g[0][i] - mod);
		}
		for (int i = 1; i <= n; ++i) {
			for (int j = 0; j < K; ++j) {
				if (j + 1 < K)
				reduce(f[i][j + 1] += mul(f[i - 1][j], K - j) - mod);
				if (j + 1 < K)
				reduce(g[i][j + 1] += mul(g[i - 1][j], K - j) - mod);
				if (j) reduce(f[i][j] += sf[i - 1][j] - mod);
				if (j) reduce(g[i][j] += sg[i - 1][j] - mod);
			}
			for (int j = K; ~j; --j) {
				reduce(sf[i][j] = f[i][j] + sf[i][j + 1] - mod);
				reduce(sg[i][j] = g[i][j] + sg[i][j + 1] - mod);
			}
		}
		int ans = all;
		for (int i = 1; i + M - 1 <= n; ++i)
			reduce(ans -= mul(sf[i - 1][0], sg[n - M - i + 1][0]));
		std::cout << ans << std::endl;
	}
	return 0;
}


Measured memory_bytes: 160512
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
bool compare(pair<ll,ll> p1,pair<ll,ll> p2){
return p1.se<p2.se;
}
ll sum(ll n){
return (n*(n+1))/2;
}
void solve(){
ll n;
cin>>n;
ll three=n/3,five=n/5,fifteen=n/15;
ll sum3=3*sum(three),sum5=5*sum(five),sum15=15*sum(fifteen);
ll s=sum(n);
cout<<s-sum3-sum5+sum15<<endl;

}
int main()
{   fast;
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3648
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	cout.precision(10);
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	double s = (double)w * (double)h * 0.5;
	cout << s << " " << (w == x * 2 && h == y * 2) << endl;
	return 0;
}


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

int main() {
    int n;
    cin>>n;
    vector<float> a(n);
    for(int i=0;i<n;i++) cin>>a.at(i);
    sort(a.begin(), a.end(), greater<float>());
    for(int i=n-1;i>=1;i--) a.at(i-1)=(a.at(i)+a.at(i-1))/2.0;
    cout<<a[0]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int,int> MP;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,ans,l[51],p[51];
void dfs(int d,Int x){
    if(d<0||x<=0)return;
    if(x<=d)return;
    if(x>=l[d]-d){ans+=p[d]; return;}
    if(x>=l[d-1]+2){ans+=p[d-1]+1; dfs(d-1,x-l[d-1]-2); return;}
    if(x>=l[d-1]+2-d){ans+=p[d-1]; return;}
    dfs(d-1,x-1);
    return;
}

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

    cin>>n>>m; l[0]=1,p[0]=1;
    for (int i = 0; i < n; i++){
        l[i+1]=l[i]*2+3,p[i+1]=p[i]*2+1;
    }
    dfs(n,m);
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2-h1)*60+m2-m1-k << newl;
  return 0;
}


Measured memory_bytes: 3668
def main():
    s = input()

    cnt = 0
    restore = []
    i = 0
    length = len(list(s))
    while i < length:
        if i == 0:
            restore.append(s[i])
            cnt += 1
            i += 1
        else:
            j = 0
            while j < length:
                if  j == 0:
                    string = s[i]
                else:
                    string = s[i:i+j+1]
                if restore[-1] == string:
                    j += 1
                else:
                    cnt += 1
                    #print(string)
                    restore.append(string)
                    break
            i += j + 1
    #print(restore)
    print(cnt)
 
if __name__ == '__main__':
    main()

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

int X;

void solve()
{
	vector<bool> dp(100010, false);
	dp[0]=true;
	for(int i=100;i<=X;++i){
		for(int j=0;j<=5;++j)if(!dp[i]){
			if(i>=100+j && dp[i-100-j]){
				dp[i]=true;
				break;
			}
		}
	}
	if(dp[X]) cout << 1 << "\n";
	else cout << 0 << "\n";
}

int main()
{
	cin >> X;
	solve();
	return 0;
}

Measured memory_bytes: 256
x, y = map(int,input().split())

def comb(n,k,mod,fac,ifac):
    k = min(k,n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

def make_tables(mod,n):
    fac = [1,1]
    ifac = [1,1]
    inverse = [0,1]

    for i in range(2,n+1):
        fac.append((fac[-1]*i)%mod)
        inverse.append((-inverse[mod%i]* (mod//i)) % mod)
        ifac.append((ifac[-1]* inverse[-1])%mod)
    return fac, ifac

if x > y:
    x, y = y, x
d = x+y
if d % 3 != 0:
    print(0)
else:
    s = (x+y)//3
    t = x - s

    if y > 2 * x:
        print(0)
    else:
        mod = 10**9+7

        fac, ifac = make_tables(mod,s)
        ans = comb(s,t,mod,fac,ifac)
        print(ans)

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

using namespace std;
int a[25],b[25];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]<=b[i])ans+=0;
		else ans+=(a[i]-b[i]);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i=0;i< int (n);i++)

int main(void)
{
    int  A, B, C, N;
    cin >> N;
    vector<int> vec(N, 0);
    vector<int>::iterator itr;

    cin >> A;

    rep(i, A)
    {
        cin >> B >> C;
        
        if (N!=1 && B==1 && C==0)
        {
            cout << -1 << endl;
            return 0;
        }
        if (vec[B - 1] != 0 && vec[B - 1] != C)
        {
                cout << -1 << endl;
                return 0;
           

        }
        vec[B - 1] = C;
    }

    if (N!=1 && vec[0] == 0)
    {
        vec[0] = 1;
    }

    rep(i, N)
    {
        cout << vec[i];
    }
    cout << endl;
}
    


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    string s; cin >> s;
    int ans = 0;
    if (s[0] == '1') ans++;
    if (s[1] == '1') ans++;
    if (s[2] == '1') ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, first;
    
    scanf("%d",&n);
    first = n % 10;
    
    switch(first){
    	case 0:
    	case 1:
    	case 6:
    	case 8:
    		printf("pon\n");
    		break;
    		
    	case 3:
    		printf("bon\n");
    		break;
    	
    	default:
    		printf("hon\n");
    		break;
    }

    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

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

	if(k==1){
		cout<<0<<endl;
	}else{
		cout<<n-k<<endl;
	}

}


Measured memory_bytes: 256
n, m, l = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(n)]
b = [[int(i) for i in input().split()] for j in range(m)]
for i in range(n):
    ans = []
    for j in range(l):
        ans.append(str(sum([a[i][k] * b[k][j] for k in range(m)])))
    print(' '.join(ans))


Measured memory_bytes: 6248
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)         cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)      cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)   cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int N = 300000 , mod = 1000000007;
int main()
{
    fastio;
    int x,y;
    cin>>x>>y;
    int b = y - 2*x;
    if(b<0 || b&1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    b/=2;
    int a = x - b;
    if(a>=0 && b>=0)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3608
n, k = map(int,input().split())
alg = set([0,1,2,3,4,5,6,7,8,9])
numeros = set(map(int, input().split()))

def contem(num, numeros):
	
	for l in str(num):
		if int(l) in numeros:
			return False
	return True
	

target = n


while not contem(target,numeros):
	target += 1

print(target)


Measured memory_bytes: 40796
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------


main :: IO ()
main = do
  x:xs <- (map read <$> map (:[]) <$> getLine) :: IO [Int]
  let f a (x, s) = [(x+a, s ++ "+" ++ show a), (x-a, s ++ "-" ++ show a)]
      (_, ans) = head $ filter ((==) 7 . fst) $ foldl' (>>=) [(x, show x)] $ map f xs
  putStrLn $ ans ++ "=7"

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

const long long INF = 1e18; 
const int mod = 200003;//1e9 + 7;//786433;//998244353;//1e9 + 7
const double Pi = acos(-1);
  
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int h, w, H, W;

signed main()
{
	Fastio();
	cin >> H >> W >> h >> w;
	if(H % h == 0 && W % w == 0)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes\n";
	if(H % h != 0)
	{
		for(int i = 1; i <= H; i++)
		{
			for(int j = 1; j <= W; j++)
			{
				if(i % h == 0)
				{
					cout << -2000 * (h - 1) - 1 << ' ';
				}
				else
				{
					cout << 2000 << ' ';
				}
			}
			cout << '\n';
		}
	}
	else
	{
		for(int i = 1; i <= H; i++)
		{
			for(int j = 1; j <= W; j++)
			{
				if(j % w == 0)
				{
					cout << -2000 * (w - 1) - 1 << ' ';
				}
				else
				{
					cout << 2000 << ' ';
				}
			}
			cout << '\n';
		}
	}
}

Measured memory_bytes: 3596
n = int(input())
a = list(map(int, input().split()))
s = 0
def cal(k,s):
    for i in range(k):
        if a[i]%2==0:
            a[i] = a[i]//2
        else: return s
    s += 1
    return cal(k,s)

print(cal(n,s))

    

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

#define int int64_t

using namespace std;

#define MAX 3005

int n;
double a[MAX], dp[MAX][MAX];

double f(int i, int r)
{
    if (r < 0)
        return 0;
    if (i == n && r > 0)
        return 0;
    if (i == n)
        return 1;
    if (dp[i][r] != -1)
        return dp[i][r];
    return dp[i][r] = f(i + 1, r) * (1 - a[i]) + f(i + 1, r - 1) * a[i];
}

signed main()
{
    scanf("%lld", &n);
    for (int i = 0; i < n; i++)
        scanf("%lf", a + i);
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            dp[i][j] = -1;
    double be = 0;
    for (int i = n; i > n / 2; i--)
        be += f(0, i);
    printf("%.10lf\n", be);
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c)&&a!=b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a!=b && b!=c && c!=a){
        if(a<b && a<c){
            if(b<c){
                printf("%d %d %d\n", a, b, c);
            }else if(b>c){
                printf("%d %d %d\n", a, c, b);
            }
        }else if(b<a && b<c){
            if(a<c){
                printf("%d %d %d\n", b, a, c);
            }else if(a>c){
                printf("%d %d %d\n", b, c, a);
            }
        }else if(c<a && c<b){
            if(a<b){
                printf("%d %d %d\n", c, a, b);
            }else if(a>b){
                printf("%d %d %d\n", c, b, a);
            }
        }
    }else if(a==b || b==c || c==a){
        if(a==b && a<c){
            printf("%d %d %d\n", a, a, c);
        }else if(a==b && a>c){
            printf("%d %d %d\n", c, a, a);
        }else if(b==c && a<b){
            printf("%d %d %d\n", a, b, b);
        }else if(b==c && a>b){
            printf("%d %d %d\n", b, b, a);
        }else if(c==a && a<b){
            printf("%d %d %d\n", a, a, b);
        }else if(c==a && a>b){
            printf("%d %d %d\n", b, a, a);
        }
    }else if(a==b && b==c){
        printf("%d %d %d\n", a, a, a);
    }
    return 0;
}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define elif else if
#define ff first
#define ss second
#define pii pair<ll int,ll int>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define pb push_back
#define IN(A, B, C) assert( B <= A && A <= C)
#define MOD 1000000007
#define CLEAR(array, value) memset(ptr, value, sizeof(array));
#define si(a)     scanf("%d", &a)
#define sl(a)     scanf("%lld", &a)
#define pi(a)     printf("%d", a)
#define pl(a)     printf("%lld", a)
#define pn       printf("\n")
int main()
{
  
  int a,b,c,d,f=0;
 

cin>>a>>b>>c;
d=b+c;
if(d<a)
{
  cout<<f<<"\n";
}
else{
  cout<<(b+c)-a<<"\n";
}
d=0;

  return 0;
}

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

    typedef long long int ll;
    #define pb         push_back
    #define mp         make_pair
    #define F          first
    #define S          second
    #define fl(i,a,b)  for(ll i=a;i<b;i++)
    #define pll        pair<ll,ll>
    #define pii        pair<int,int>
    #define all(v)     v.begin(),v.end()
    #define M 1000000007
    #define tr(v, it) for(auto it = v.begin(); it != v.end(); it++)
    #define fast   ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed;
    using namespace std;
    ll dp[3005][3005];
    ll dfs(ll arr[], int i , int j)
    {
        if(i==j)
            return arr[i];
        if(j==i+1)
            return max(arr[i],arr[j]);
        if(dp[i][j]!=-1)
            return dp[i][j];
        ll ans;
        ans = max((arr[i]+min(dfs(arr, i+2, j),dfs(arr,i+1, j-1))), arr[j]+min(dfs(arr,i+1,j-1),dfs(arr,i, j-2)));
        return dp[i][j]=ans;
    }
    int main()
    {
            fast
         int n;
         cin>>n;
         ll arr[n];
         ll sum=0;
         for(int i=0; i<n; i++)
         {
             cin>>arr[i];
             sum = sum+arr[i];
         }
         memset(dp,-1,sizeof(dp));
        ll x =dfs(arr,0,n-1);
        ll y  = sum-x;
        cout<<x-y;
        return 0;

    }



Measured memory_bytes: 74316
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#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...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)
#define pi 3.141592653589793238462643

void solve(){
    ll n;
    cin>>n;
    string s, t;
    cin>>s>>t;
    loop(i,0,n){
        cout<<s[i]<<t[i];
    }
    cout<<endl;
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
 
}


Measured memory_bytes: 256
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret



num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break


if FLG == True:
    print("Yes")
else:
    print("No")


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

using namespace std;

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

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int n,inv[N],pre[N],a[N],fac[N],ans;

inline int add(int x,int y) {
  return (x + y) % MOD;
}

inline int mul(int x,int y) {
  return (ll) x * y % MOD;
}

int fast_pow(int x,int y) {
  if (y == 0)
    return 1;
  int res = fast_pow(x,y / 2);
  res = mul(res,res);
  if (y & 1)
    res = mul(res,x);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n;
  for (int i = 1 ; i <= n ; i++)
    cin >> a[i];
  fac[0] = 1;
  for (int i = 1 ; i <= n + 1 ; i++) {
    fac[i] = mul(fac[i - 1],i);
    inv[i] = fast_pow(i,MOD - 2);
    pre[i] = add(pre[i - 1],inv[i]);
  }

  for (int i = 1 ; i <= n ; i++)
    ans = add(ans,mul(a[i],add(pre[i],pre[n - i + 1] - 1)));
  cout << mul(fac[n],ans) << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str!="-"){
    cin >> m;
    for(i=0;i<m;i++){
      cin >> b;
      str=str.substr(b,str.size()-b)+str.substr(0,b);
    }
    cout << str << endl;
    cin >> str;
  }
  
}



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

int main(){
	int k,n;
	cin>>k>>n;
	int a[n+1];
	
	for(int i=1;i<=n;++i)
		cin>>a[i];
	
	int b[n+1];
	for(int i=1;i<=n-1;++i)
		b[i]=a[i+1]-a[i];
	
	b[n]=k-a[n]+a[1];
	
	int maxv=0;
	for(int i=1;i<=n;++i)
		maxv=max(maxv,b[i]);
	
	cout<<k-maxv<<endl;
	return 0;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for(auto& x : a)
        for(auto& y : x){
            cin >> y;
            --y;
        }

    auto f = [&](int val){
        // n:人数 m:試合数
        vector<queue<int>> que(n);
        for(int i = 0; i < n; ++i)
            for(auto& x : a[i])
                que[i].emplace(x);
        // スポーツ毎に人物を入れている
        vector<unordered_set<int>> s(m);
        unordered_set<int> deleted;
        for(int i = 0; i < n; ++i){
            s[que[i].front()].insert(i);
            que[i].pop();
        }
        while(1){
            // 条件を満たせない物があった場合、それを削除する
            // 削除するのはスポーツの方で、人物は削除しない
            int flag = -1;
            for(int i = 0; i < m; ++i){
                if(s[i].size() > val){
                    flag = i;
                    break;
                }
            }
            if(flag == -1)
                break;
            // 削除すると決めた要素に対して
            for(auto& x : s[flag]){
                while(1){
                    if(que[x].empty())
                        return false;
                    int fr = que[x].front();
                    que[x].pop();
                    if(deleted.find(fr) != deleted.end())
                        continue;
                    s[fr].insert(x);
                    break;
                }
            }
            s[flag].clear();
            deleted.insert(flag);
        }
        return true;
    };
    int st, en;
    for(st = 0, en = n; en - st > 1; (f((st + en) >> 1) ? en : st) = (st + en) >> 1);
    cout << en << endl;
}


Measured memory_bytes: 2176
X = int(input())

def isPrime(n) : 
  
    # Corner cases 
    if (n <= 1) : 
        return False
    if (n <= 3) : 
        return True
  
    # This is checked so that we can skip  
    # middle five numbers in below loop 
    if (n % 2 == 0 or n % 3 == 0) : 
        return False
  
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
  
    return True

def nextPrime(N): 
  
    # Base case  
    if (N <= 1): 
        return 2
  
    prime = N 
    found = False
  
    # Loop continuously until isPrime returns  
    # True for a number greater than n  
    while(not found): 
        prime = prime + 1
  
        if(isPrime(prime) == True): 
            found = True
  
    return prime 

if (isPrime(X)) : 
    print(X) 
else : 
    X = nextPrime(X)
    print(X)

Measured memory_bytes: 3064
N = int(input())
t = [0]
x = [0]
y = [0]
for a in range(1,N+1):
    S = list(map(int,input().split()))
    t.append(S[0])
    x.append(S[1])
    y.append(S[2])
for b in range(0,N):
    t_dist = t[b+1] - t[b]
    x_dist = x[b+1] - x[b]
    y_dist = y[b+1] - y[b]
    step = abs(x_dist) + abs(y_dist)
    if t_dist - step >= 0 and (t_dist - step)%2 ==0:
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 12060