akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	cin >> n;
	rep(x, 0, n) {
		vi d(10);
		rep(i, 0, 10) {
			cin >> d[i];
		}
		int t1 = 0, t2 = 0;
		bool ans = true;
		rep(i, 0, 10) {
			if (t1 < d[i]) t1 = d[i];
			else if (t2 < d[i]) t2 = d[i];
			else ans = false;
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 1184
package main

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

func main() {
	a := getInt()
	b := getInt()
	h := getInt()

	fmt.Println((a + b) * h / 2)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define MOD 998244353

using namespace std;

int n, now[3], hav[3];
ll ans = 1;
string s; 

int main()
{
	cin >> n >> s;
	for (int i = n * 3 - 1; ~i; i--)
	{
		int x;
		switch (s[i])
		{
			case 'R':
				x = 0; break;
			case 'G':
				x = 1; break;
			default:
				x = 2; break;
		}
		if (hav[x])
		{
			ans = ans * hav[x] % MOD;
			hav[x]--;
		}
		else
		{
			bool flag = false;
			for (int j = 0; j < 3; j++)
				if (x != j && now[j])
				{
					ans = ans * now[j] % MOD, now[j]--;
					hav[3 - x - j]++;
					flag = 1;
				}
			if (!flag) now[x]++;
		}
	}
	for (int i = 1; i <= n; i++)
		(ans *= i) %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 900
import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.Collections;
	import java.util.Comparator;
	import java.util.HashMap;
	import java.util.HashSet;
	import java.util.List;
	import java.util.Map;
	import java.util.Map.Entry;
	import java.util.PriorityQueue;
	import java.util.Queue;
	import java.util.Scanner;
	import java.util.Set;

	public class Main{

		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		}
		public static long gcd(long x, long y) {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		}

		public static long minbai(long x, long y) {

			return x * y / gcd(x,y);

		}

	}

Measured memory_bytes: 35576
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
rest = 0
for a, b in zip(B, A):
  b_ = b - rest
  if b_ > a:
    ans += rest + a
    rest = 0
  elif b_ > 0:
    rest = a - b_
    ans += b
  elif b_ <= 0:
    rest = a
    ans += b
b = A[-1]
if rest > b:
  ans += b
else:
  ans += rest
print(ans)

Measured memory_bytes: 24156
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve(){
	int i, j, k,c=0,ans=INT_MAX;
    string s,t;
    int l1,l2;
    cin>>s>>t;
    l1=s.length();
    l2=t.length();
    for(i=0;i<=l1-l2;i++){
        c=0;
        for(j=0;j<l2;j++){
            if(s[i+j]!=t[j]){
                c++;
            }
        }
        ans=min(ans,c);
    }
    cout<<ans<<endl;


}

int main() {
	ios_base::sync_with_stdio(0);
	int i,t=1;
	//cin>>t;
	for(i=1;i<=t;i++){
		solve();
	}
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




Measured memory_bytes: 10692
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ab = a + b;
  ll syou = n /ab;
  ll amari = n % ab;
  if(amari > a) amari = a;
  if(a == 0) {
    cout << 0 << endl;
  } else {
    cout << (a * syou + amari) << endl;
  }


  return 0;
}


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

int main(){
    int ans;
    int n;
    cin >> n;
    if(n % 2){
        ans = n/2+1;
    }
    else{
        ans = n/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
   int n;
   cin >> n;
   vector<int> a(n);
   for(int i=0; i<n; i++){
       cin >> a[i];
   }
   int dp[n+1]={0};
   dp[0]=0;
   dp[1]=abs(a[0]-a[1]);
   for(int i=2; i<n; i++){
       dp[i]=  min( dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]) );
   }
  cout << dp[n-1] << endl;
  
   return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <stack>
#include <map>

using namespace std;

class myCalc {
private:
	std::map<char, int> mOperator;
public:
	myCalc( void ) {
		mOperator['('] = -2;
		mOperator[')'] = -1;
		mOperator['+'] = 0;
		mOperator['-'] = 1;
		mOperator['/'] = 2;
		mOperator['*'] = 2;
	}
	std::string ToRPN( std::string str ) {
		std::string ret;
		std::stack<char> st;
		int len = str.size(), i = 0;
		while(i < len) {
			switch(str[i]) {
			case '+' :
				while(!st.empty() && mOperator[st.top()] > mOperator[str[i]]) {
						ret += st.top(); st.pop();
				}
			case '(':
				st.push(str[i++]);
				break;
			case '-': case '/': case '*':
				while(!st.empty() && mOperator[st.top()] >= mOperator[str[i]]) {
					ret += st.top(); st.pop();
				}
				st.push(str[i++]);
				break;
			case ')':
				while(!st.empty() && st.top() != '(') {
					ret += st.top();
					st.pop();
				}
				st.pop();
				++i;
				break;
			default:
				ret += '[';
				while('0' <= str[i] && str[i] <= '9') ret += str[i++];
				ret += ']';
				break;
			}
		}
		while(!st.empty()) { ret += st.top(); st.pop(); }
		return ret;
	}
	int Calculate( std::string str ) {
		std::stack<int> st;
		int len = str.size(), i = 0;
		while(i < len) {
			int a, b;
			switch(str[i]) {
			case '+':
				a = st.top(); st.pop();
				b = st.top(); st.pop();
				st.push(a+b);
				break;
			case '-':
				a = st.top(); st.pop();
				if(!st.empty()) {b = st.top(); st.pop();}
				else b = 0;
				st.push(b-a);
				break;
			case '*':
				a = st.top(); st.pop();
				b = st.top(); st.pop();
				st.push(a*b);
				break;
			case '/':
				a = st.top(); st.pop();
				b = st.top(); st.pop();
				st.push(b/a);
				break;
			default:
				++i; a = 0;
				while(str[i] != ']') {
					a *= 10;
					a += (str[i++] - '0');
				}
				st.push(a);
				break;
			}
			++i;
		}
		return st.top();
	}
};

int main( void )
{
	long long n;
	myCalc calc;
	cin >> n;
	while(n--) {
		string in;
		cin >> in;
		in.erase(in.size()-1);
		//cout << in << ' ' << calc.ToRPN(in) << endl;
		cout << calc.Calculate(calc.ToRPN(in)) << endl;
	}
	return 0;
}

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

using namespace std;

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

  long long a, b, c;
  cin >> a >> b >> c;
  if (c < a + b) {
    cout << "No";
    return 0;
  }
  cout << ((c - a - b) * (c - a - b) > 4 * a * b? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace bla
{
    class Program
    {
        static void Main()
        {
            List<char> s = Console.ReadLine().ToCharArray().ToList();
            if(s[0] != 'A')
            {
                Console.WriteLine("WA");
                return;
            }
            int c = 0;
            int cp = 0;
            for (int i = 2; i < s.Count - 1; i++)
            {
                if (s[i] == 'C')
                {
                    c++;
                    cp = i;
                }
            }
            if(c != 1)
            {
                Console.WriteLine("WA");
                return;
            }
            for (int i = 0; i < s.Count; i++)
            {
                if(i != 0 && i != cp && char.IsUpper(s[i]))
                {
                    Console.WriteLine("WA");
                    return;
                }
            }
            Console.WriteLine("AC");
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;


int ar[ms]={0};

int main()
{
    idfc;
    int n;
    int t;
    cin>>n;
    t=n;
    while(--n)
    {
        int i;
        cin>>i;
        ar[i]++;
    }
    for(int i=1;i<=t;i++)cout<<ar[i]<<"\n";
    return 0;
}

Measured memory_bytes: 4376
import java.util.Scanner; 
public class Main {
	public static void main(String[] args) {
	try (Scanner sc = new Scanner(System.in)) {
	String line = sc.nextLine();
	String answer = "";
	char b;
	int length = line.length();
	for (int i = 0; i < length; i++) {
	char ch = line.charAt(i);
    if(Character.isLowerCase(ch)==true)
    {
    	 b=Character.toUpperCase(ch);
    }
    else
    {
    	b=Character.toLowerCase(ch);
    }
	answer=answer+b;
	}
	System.out.println(answer);
	}
	}
	}


Measured memory_bytes: 31468
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	s := ""
	kuji := make(map[string]struct{})
	for i := 0; i < N; i++ {
		fmt.Scan(&s)
		kuji[s] = struct{}{}
	}
	fmt.Println(len(kuji))
}


Measured memory_bytes: 18380
a,b=list(map(int,input().split())),0
for i in range(a[0]):
    for j in range(a[1]):
        if len(str(j))==2:
            if (int(str(j)[0]))*(int(str(j)[1])+1)==i+1 and int(str(j)[0])>=2 and int(str(j+1)[1])>=2:
                b+=1
print(b)

Measured memory_bytes: 3060
use proconio::*;
use std::collections::BinaryHeap;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    };
    let mut ascent = vec![false; n];
    let mut money = 1000;
    let mut kb = 0;

    let mut pre = a[0];
    for i in 1..a.len() {
        if a[i - 1] < a[i] {
            ascent[i - 1] = true;
        }
    }

    let mut buy = false;

    for i in 0..a.len() {
        if buy {
            if !ascent[i] {
                money += kb * a[i];
                kb = 0;
                buy = false;
            }
        } else {
            if ascent[i] {
                let n = money / a[i];
                money -= n * a[i];
                kb = n;
                buy = true;
            }
        }
    }

    println!("{}", money);
}


Measured memory_bytes: 2184
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main(){
	scanf("%lld%lld",&a,&b);
	if(a<=((a*2)+b)/4)
		cout<<((a*2)+b)/4<<endl; 
    else 
		cout<<b/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long long n, cnt=0;
    cin >> n;
    for(long long i=1; i*i<=n; i++){
        if(n % i != 0){
            continue;
        }
        long long a = i, m = n / i - 1;
        if(m > a) cnt += m;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3592
D, G = map(int, input().split())
table = []
for i in range(D):
    p,c = map(int, input().split())
    table.append((i+1,p,c))

ans = 10**3
for i in range(1<<D):
    score = 0
    count = 0
    remain = []
    for j in range(D):
        a,p,c = table[j]
        if i & (1<<j):
            score += a*100*p+c
            count += p
        else:
            remain.append((a,p,c))
    if score >= G:
        ans = min(count,ans)
    else:
        remain.sort(reverse=True)
        a,p,c = remain[0]
        for k in range(p):
            score += a*100
            count += 1
            if score >= G:
                ans = min(count,ans)
print(ans)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int query(int n){
	cout << n << endl;
	string s;
	cin >> s;
	if( s == "Male" ) return 0;
	if( s == "Female" ) return 1;
	return -1;
}

int main(){
	//ios_base::sync_with_stdio(false);
	int N, ans=0;

	cin >> N;

	int l=0, r=N-1;
	int lq = query(l);
	if( lq == -1 ) return 0;
	int rq = query(r);
	if( rq == -1 ) return 0;
	while(r-l>1){
		int m = (l+r) / 2;
		int q = query(m);
		if( q == -1 ) return 0;
		if( (m-l)%2 != q^lq ){
			r = m;
			rq = q;
		}else{
			l = m;
			lq = q;
		}
	}

	return 0;
}

Measured memory_bytes: 852
#include<algorithm>
#include<iostream>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
//{{{ read()
inline int read(){
	register int x=0,f=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x*f;
}
//}}}
const int N=2e3+5;
int n,m,q,a[N][N],b[N][N],c[N][N],d[N][N];
int calc(int c[N][N],int x1,int y1,int x2,int y2){
	if(x1>x2||y1>y2)	return 0;
	return c[x2][y2]+c[x1-1][y1-1]-c[x1-1][y2]-c[x2][y1-1];
}
int main(){
	n=read(),m=read(),q=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			register int ch=getchar();
			while(ch!='0'&&ch!='1')	ch=getchar();
			if(ch=='1')	a[i][j]=1;
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			b[i][j]=b[i][j-1]+a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			b[i][j]+=b[i-1][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			c[i][j]=c[i][j-1]+(a[i][j]&&a[i][j-1]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			c[i][j]+=c[i-1][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			d[i][j]=d[i][j-1]+(a[i][j]&&a[i-1][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			d[i][j]+=d[i-1][j];
	while(q--){
		int x1=read(),y1=read(),x2=read(),y2=read();
		int ans=calc(b,x1,y1,x2,y2);
		ans-=calc(c,x1,y1+1,x2,y2);
		ans-=calc(d,x1+1,y1,x2,y2);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 64640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int N,M;  cin>>N>>M;
  vector<int> v(N, 0);
  rep(i,0,M){
    int x,y;  cin>>x>>y;
    --x;  --y;
    v[x]++; v[y]++;
  }
  bool ok = true;
  rep(i,0,N) if(v[i]%2==1) ok = false;
  if(ok){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

using namespace std;

long long dp[3005][3005];
long long arr[3005];

int main(){
    int N;
    cin >> N;
    for(int i = 1; i<=N; i++){
        cin >> arr[i];
    }
    for(int le = 1; le<=N; le++){
        for(int l = 1; l+le-1 <= N; l++){
            int r = l+le-1;
            if(N%2 == le%2){
                dp[l][r] = max(dp[l+1][r] + arr[l], dp[l][r-1] + arr[r]);
            }
            else{
                dp[l][r] = min(dp[l+1][r] - arr[l], dp[l][r-1] - arr[r]);
            }
        }
    }
    cout << dp[1][N] << endl;
}


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

int i=0,j=0,k,l,m;
ll mod=1000000007;

int main(){    
    int a,b,c,d;cin>>a>>b>>c>>d;
    
    while(a>0){
        a-=d;
        i++;
    }
    while(c>0){
        c-=b;
        j++;
    }

    if(i>=j){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}

    return 0;
}

Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt();
        }

        int r = N - K;
        System.out.println(r / (K - 1) + 1 + (r % (K - 1) != 0 ? 1 : 0));
    }

}


Measured memory_bytes: 48580
#include <stdio.h>

int A[100000], n;

int binarySearch(int key)  {
  int left = 0, right = n, mid;
  while (left < right)  {
    mid = (left + right) / 2;
    if ( key == A[mid])
      return 1;
    if (key > A[mid]) 
      left = mid+1;
    else if (key < A[mid]) right = mid;
  }
  return 0;
}
  
int main(void)  {
  int i, j, q, k, sum=0;

  scanf("%d", &n);
  for (i = 0; i < n; i++)  {
    scanf("%d", &A[i]);
  }
  
  scanf("%d", &q);
  for (i = 0; i < q; i++)  {
    scanf("%d", &k);
    if (binarySearch(k) != 0)
      sum++;
  }
  printf("%d\n", sum);

  return 0;
}
  

Measured memory_bytes: 2092
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.*;
import java.text.*;
public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(6);
        nf.setGroupingUsed(false);
        int vector = Integer.parseInt(br.readLine());
        String[] tmpx1 = br.readLine().split(" ");
        String[] tmpy1 = br.readLine().split(" ");
        double[] vecx1 = new double[vector];
        double[] vecy1 = new double[vector];
        for(int i=0;i<vector;i++) {
            vecx1[i] = Double.parseDouble(tmpx1[i]);
            vecy1[i] = Double.parseDouble(tmpy1[i]);
        }
        double p1 = 0;//p1の答え
        double p2 = 0;
        double p3 = 0;
        double pin = 0;
        double pinmax = 0;
        double tmp = 0;
        //p1
        for(int i=0;i<vector;i++){
            p1 += Math.abs(vecx1[i]-vecy1[i]);
            p2 += Math.pow(Math.abs(vecx1[i]-vecy1[i]),2);
            p3 += Math.pow(Math.abs(vecx1[i]-vecy1[i]),3);
            tmp = Math.abs(vecx1[i]-vecy1[i]);
            if(pinmax < tmp) pinmax = tmp;
        }
        p2 = Math.sqrt(p2);
        p3 = Math.cbrt(p3);
        System.out.println(nf.format(p1));
        System.out.println(nf.format(p2));
        System.out.println(nf.format(p3));
        System.out.println(nf.format(pinmax));
    }
}

Measured memory_bytes: 17276
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
15 8 5
)");
#define cin input
#endif

int main()
{
	int h, w, k;
	cin >> h >> w >> k;

    vector<ll> r(w);
    r[0] = 1;

    REP (i, h)
    {
        vector<ll> t(w);
        REP (j, 1 << (w - 1))
        {
            if ((j << 1) & j)
                continue;
            
            REP (k, w)
            {
                if (k && ((1 << (k - 1)) & j))
                    t[k] += r[k - 1];
                else
                    if ((1 << k) & j)
                        t[k] += r[k + 1];
                    else
                        t[k] += r[k];
                t[k] %= 1000000007;
            }
        }

        swap(r, t);
    }

	cout << r[k - 1] << endl;

	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
void ng(){
  puts("-1");
  exit(0);
}
typedef vector<int> vi;
typedef vector<pi> vp;

const int M=5e8;

void rot(vp& res){
  for(auto& p:res){
    pi nxt=mp(-p.sc,p.fr);
    p=nxt;
  }
}

vp solve(vi ar){
  int n=ar.size();
  if(n==4){
    vp res={{0,0},{1,0},{1,1},{0,1}};
    return res;
  }

  bool suc=false;
  vi pvar=ar;
  vector<int> pv;
  REP(i,n) if(ar[i]==1 && ar[(i+1)%n]==1 && ar[(i+2)%n]==3){
    REP(j,i) pv.pb(ar[j+1]);

    rotate(ar.begin(),ar.begin()+i,ar.end());
    suc=true;
    break;
  }
  assert(suc);
  vi chil=ar;
  ar.erase(ar.begin()+1);
  ar.erase(ar.begin()+1);

  vp res=solve(ar);
  prl;
  debug(ALL(ar));
  debug(ALL(res));
  int y=res[0].sc,x=res[0].fr;

  for(auto& p:res){
    if(p.sc<y) --p.sc;
    if(p.fr>x) ++p.fr;
  }

  res[0].sc--;
  res.insert(res.begin()+1,res[0]);
  res[1].fr++;
  res.insert(res.begin()+2,res[1]);
  res[2].sc++;
    debug(ALL(res));

  if(!pv.empty()){
    rotate(res.begin(),res.begin()+res.size()-pv.size(),res.end());
    int sign=0;
    for(auto e:pv){
      if(e==3) --sign;
      else ++sign;
    }
    sign=(sign%4+4)%4;
    REP(_,sign) rot(res);
  }
  debug(ALL(pvar));
  debug(ALL(res));
  return res;
}
int main(){
  int n;
  cin>>n;
  int one=0,thr=0;
  vi ar(n);
  REP(i,n){
    cin>>ar[i];
    if(ar[i]==90) ++one;
    else ++thr;
    ar[i]/=90;
  }
  if(n&1) ng();
  if(one-thr!=4) ng();

  vp res=solve(ar);

  for(auto p:res){
    printf("%d %d\n",p.fr+M,p.sc+M);
  }






  return 0;
}





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

int main() {
  long res = 0;
  long N;
  cin >> N;
  long a[N+1];
  long b[N];
  for(int i=0;i<=N;i++) cin >> a[i];
  for(int i=0;i<N;i++) cin >> b[i];
  
  for (int i = 0;i<N;i++){
    long c = min(a[i], b[i]);
    b[i] -=c;
    res += c;
    //cout << res << endl;
    c = min(a[i+1], b[i]);
    a[i+1] -=c;
    res += c;
  }
  cout << res;
}

Measured memory_bytes: 1792
from collections import defaultdict

N,K = map(int, input().split())
A = list(map(int, input().split()))
BMAX = 40
"""
・K以下の非負整数の範囲で〜：桁DP感ある
・XORをとる：桁ごとに確認できる
・Xを選んで、f = X xor A1 + X xor A2 + ... + X xor AN
　 -> それぞれのAと毎回 xor 取るのではなく、桁ごとに xor を取ることができる　←　超重要のはず
　 -> A1 ~ AN の各桁（2進数の時の）に1が立っているのが何個あるか数えておく


遷移
dp[i][1] -> dp[i+1][1] : i-1桁目まででK未満が確定していれば、i桁目に1,0どちらを選んでもK未満
dp[i][0] -> dp[i+1][1]  : i-1桁目まででKと一致している場合、Kのi桁目が1なら、Xで0を選べば遷移できる
dp[i][0] -> dp[i+1][0]  : i桁目まで一致させる場合
"""

d = [0] * BMAX
for a in A:
  for i in range(BMAX):
    if a & (1 << i):
      d[i] += 1

# dp[i+1][0] : Xをi桁目まで決めた時に、Kのi桁目までと厳密に一致する　ときの最大値
# dp[i+1][1] : Xをi桁目まで決めた時に、Kのi桁目までと厳密に一致しないときの最大値

dp = [[-1 for _ in range(2)] for _ in range(BMAX+1)]


dp[0][0] = 0

for i in range(BMAX):
  now = BMAX-1-i
  # Xの左からnow桁目に1,0を設定した時にfが増加する量
  p0 = (2**now) * d[now]
  p1 = (2**now) * (N - d[now])
  
  # Kの左からnow番目に1が立ってるかどうか
  if K & (1 << now):
    is_one = True
  else:
    is_one = False

  # dp[i][1] -> dp[i+1][1] はXのi桁目に1,0を使えるから、より多い方を採用
  if dp[i][1] != -1:
    dp[i+1][1] = dp[i][1] + max(p1, p0)

  # dp[i][0] -> dp[i+1][1] はKのi桁目が1なら可能
  if dp[i][0] != -1 and is_one:
    dp[i+1][1] = max(dp[i+1][1], dp[i][0] + p0)

  # dp[i][0] -> dp[i+1][0] 
  if dp[i][0] != -1:
    dp[i+1][0] = dp[i][0] + (p1 if is_one else p0)    

print(max(dp[-1]))


Measured memory_bytes: 20700
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
#define ull unsigned long long int
#define ld long double
//Make sure no overflow problems
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define endl '\n'
//#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define addmod(a,b,mod) (a%mod + b%mod)%mod
#define submod(a,b,mod) (a%mod - b%mod + mod)%mod
const ll mod = 1000000007; 
const ld EPS = 10e-9;
const int MAX = 1e6;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//const long long INFLL = (ll)INF * (ll)INF;

int main(){
    ios_base:: sync_with_stdio(0); 
    cin.tie(0);
    
    string k;
    set<string> s;
    int n;
    cin >> n;
    FOR(i,0,n){
    	cin >> k;
    	s.insert(k);
	}
	cout << s.size();
    return 0; 
}

Measured memory_bytes: 19276
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vi go;
    for (int i = 0; i <= n; i++) {
        char c;
        cin >> c;
        if (c == '0') {
            go.push_back(i);
        }
    }

    vi ans;
    for (int i = go.size() - 1; i > 0; ) {
        int x = i;
        while (x >= 0 && go[i] - go[x] <= m) {
            x--;
        }

        x++;
        if (x == i) {
            cout << -1 << endl;
            return 0;
        }

        ans.push_back(go[i] - go[x]);
        i = x;
    }

    for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i] << " \n"[i==0];
    }

    return 0;
}


Measured memory_bytes: 1400
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def intread():
    return int(sysread())
def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())


def get_ideal(s, target, s_val, N):
    dic = {'Male' : 0, 'Female' :1}
    rev = {0 : 'Male', 1: 'Female'}
    dist = min([abs(target - s), s + N - target, target + N - s])
    v = (dic[s_val] + (dist % 2)) % 2
    #print(s, target, s_val, rev[v])
    return rev[v]

def check(v):
    return True if v == 'Vacant' else False

from time import sleep
def query(x, L):
    print(x)
    #print('query: ', x)
    #print('')
    #sleep(1)
    v = input()
    #sleep(1)
    L[x] = v
    if check(v):
        #printout('end')
        #sprint()
        return True



def run():
    N = int(input())
    L = [''] * N
    check_lists = deque([])

    if query(0, L): return
    if query(N-1, L): return

    check_lists.append((0, N-1))
    while check_lists:
        #print(check_lists)
        a, b = check_lists.popleft()
        if abs(a-b) == 1:continue
        x = (a + b) // 2

        if query(x, L): return
        pred_a = get_ideal(a, x, L[a], N)
        pred_b = get_ideal(b, x, L[b], N)
        #print(pred_a, pred_b)
        if pred_a == pred_b == L[x]:
            check_lists.append((a, x))
            check_lists.append((x, b))
        elif pred_a != L[x]:
            check_lists = deque([])
            check_lists.append((a, x))
        elif pred_b != L[x]:
            check_lists = deque([])
            check_lists.append((x, b))

if __name__ == "__main__":
    run()


Measured memory_bytes: 9840
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] sub = new int[n + 1];
		for(int i = 0; i < n - 1; i++) sub[in.nextInt()] += 1;
		for(int i = 1; i <= n; i++) System.out.println(sub[i]);
	}
} 


Measured memory_bytes: 60492
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
	int a = to!int(chomp(readln()));
	int b = to!int(chomp(readln()));
	int h = to!int(chomp(readln()));
	
	int surface = (a + b) * h / 2;
	surface.writeln;
}


Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 4e18 + 9;
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int l, r;
	cin >> l >> r;
	if(r-l+1 >= 2019)
		return cout << 0, 0;
	int ans = inf;
	for(int i = l; i < r; i++){
		for(int j = i+1; j <= r; j++)
			ans = min(ans, (i*j)%2019);
	}
	cout << ans;
	return 0;
}

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

typedef long long ll;

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

int main() {
  ll x;
  cin >> x;
  ll ans;
  ans = 2*(x/11);
  x = x%11;
  if ((1 <= x) && (x <= 6)) {
    ans++;
  }
  else if ((7 <= x) && (x <= 10)) {
    ans += 2;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define REP(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define DREP(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define FOR(i, a, n) for (int i = a, _n = n; i < _n; ++i)
#define EREP(i, a) for (int i = first[a]; i; i = edge[i].nxt)
#define debug(x) cout << #x << " = " << x << endl

int n, d;
vector<int> V[100];
int main () {
	scanf ("%d%d", &n, &d);

	REP (i, 1, n) 
		REP (j, 1, d) {
			int a;
			scanf ("%d", &a);
			V[i].push_back(a);
		}

	int ans = 0;
	REP (i, 1, n) REP(j, i + 1, n) {
		long long s = 0;
		FOR (k, 0, d) {
			s += (V[i][k] - V[j][k]) * (V[i][k] - V[j][k]);
		}
		int tem = sqrt(s);
		if (tem * tem == s) ++ans;
	}
	printf ("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	static int N;
	public static void main(String[] args) {
		int i, j, k;
		Scanner sc = new Scanner(System.in);
		N = parseInt(sc.next());
		sc.close();
		sc = null;
		int cnt=0;
		if(N>=357) {
			cnt = m753("3");
			cnt += m753("5");
			cnt += m753("7");
		}
		out.println(cnt);
	}
	static int m753(String s) {
//		out.println(s);
		if(parseLong(s) > N) return 0;
		int i;
		int c3=0;
		int c5=0;
		int c7=0;
		int co=0;
		int ret = 0;
		for (i = 0; i < s.length(); i++) {
			switch(s.charAt(i)) {
			case '3':
				c3++;
				break;
			case '5':
				c5++;
				break;
			case '7':
				c7++;
				break;
			default:
				co++;
				break;
			}
		}
		if(c3 > 0
		&& c5 > 0
		&& c7 > 0
		&& co ==0) {
			ret = 1;
		}
		String[] s753 = {"3","5","7"};
		for(i=0;i<s753.length; i++) {
			ret += m753(s+s753[i]);
		}
		return ret;
	}
}


Measured memory_bytes: 34728
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) (a)<=(n)&&(n)<(b)
typedef long long ll;
using namespace std;
const int inf=1e9;

int main() {
	string a="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	cout<<a[s1[0]-'a'];
	cout<<a[s2[0]-'a'];
	cout<<a[s3[0]-'a'];
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        char[] s = sc.next().toCharArray();

        int n = s.length - 1;
        int l = 0;
        int r = (n - 1) / 2;
        boolean isAns = true;

        for (int i = l; i <= r / 2; i++) {
            if (s[i] != s[r - i]) {
                isAns = false;
                break;
            }
        }

        l = (n + 3) / 2;
        r = n;

        for (int i = l; i <= r; i++) {
            if (s[i] != s[r - i]) {
                isAns = false;
                break;
            }
        }

        System.out.println(isAns ? "Yes" : "No");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <ostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

const int INF = 1000000;

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int maxh = a[0];
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		if (maxh <= a[i]) {
			count++;
			maxh = a[i];
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
a,b,k = map(int,input().split())
t = []

for i in range(a,a+k):
    if i <= b:
        t.append(i)
for i in range(b-k+1,b+1):
    if i >= a:
        t.append(i)

t = list(set(t))
t.sort()

for i in range(len(t)):
    print(t[i])

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    int x;
    cin>>x;
    if(x==1)
    {
        cout<<"0"<<'\n';
    }
    else
    {
        cout<<"1"<<'\n';
    }
    
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)
int main(){
	int n,m,a,b,c,d;
	cin >> n,m;
	int wf[20][20];
	rep(i,20)rep(j,20)wf[i][j] = (i==j?0:INF);
	cin >> m;
	rep(i,m){
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		a--,b--;
		wf[a][b] = c , wf[b][a] = d;
	}
	rep(k,n)rep(i,n)rep(j,n)wf[i][j] = min(wf[i][j],wf[i][k]+wf[k][j]);
	scanf("%d,%d,%d,%d",&a,&b,&c,&d);
	a--,b--;
	cout << c-d-wf[a][b]-wf[b][a] << endl;
}

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

int main() {
	int A, B, C, D;
cin>>A>>B>>C>>D;
int x=max(A,C) ;
int y=min(B,D) ;
if((y-x)<=0 ) {
cout<<0 ;
} else {
cout<<y-x;
} 
	return 0;;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, A, B;

int dp[5001][5001][2][2];
int dp1[5002][5002][2];
int dp2[5002][5002][2];

signed main(){
    cin >> N >> A >> B;
    if(A < B) swap(A, B);
    for(short n=N; n>=0; n--){
        for(short k=N; k>=0; k--){
            for(short b=0; b<2; b++){
                for(short a=0; a<2; a++){
                    if(n == N){
                        if(a == 1 || k >= A) dp[n][k][b][a] = 1;
                        else dp[n][k][b][a] =  0;
                        continue;
                    }
                    bool a2 = a;
                    if(k >= A) a2 = true;
                    ll ret = dp[n+1][k+1][0][a2];
                    if(b == 0){
                        ret += dp1[n+1][0][a2] - dp1[n+min(B, N-n+1)][0][a2];
                        ret += dp2[n+min(B, N-n+1)][k+min(B, N-n+1)][a2] - dp2[N+1][k+N-n+1][a2];
                    }
                    if(ret < 0) ret += MOD;
                    if(ret < 0) ret += MOD;
                    if(ret >= MOD) ret -= MOD;
                    if(ret >= MOD) ret -= MOD;
                    dp[n][k][b][a] = ret;
                }
            }

            for(short a=0; a<2; a++){
                int ret = dp[n][k][1][a] + dp1[n+1][k][a];
                if(ret >= MOD) ret -= MOD;
                dp1[n][k][a] = ret;
            }

            for(short a=0; a<2; a++){
                int ret = dp[n][k][1][a] + dp2[n+1][k+1][a];
                if(ret >= MOD) ret -= MOD;
                dp2[n][k][a] = ret;
            }
        }
    }
    cout << dp[0][0][0][0] << endl;
}

Measured memory_bytes: 785268
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, a: [usize; n + 1], b: [usize; n]);

    let mut cap = 0;

    let mut count = 0;

    for i in 0..n {
        count += if a[i] < b[i] + cap { a[i] } else { b[i] + cap };

        cap = if a[i] < b[i] + cap {
            if a[i] > cap {
                b[i] - (a[i] - cap)
            } else {
                b[i]
            }
        } else {
            0
        };
    }

    count += if a[n] < cap { a[n] } else { cap };

    println!("{}", count);
}


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

int main() {
int n;
cin>>n;
vector<P>list(n);
rep(i,n)
{int x,l;
cin >> x >>l;
P p;
  //firstに、アームを一番右側に伸ばしたときの数字
  p.first=x+l;
  //secondに、アームを一番左側に伸ばした時の数字(かぶってはいけないので)
  p.second=x-l;
  list.at(i)=p;
}
sort(list.begin(),list.end());

int nowx=-1e9;
int ans=0;
rep(i,n)
{P p=list.at(i);
  if(nowx<=p.second)
  {ans++; nowx=p.first;}
}

cout << ans << endl;



}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

#define int long long int

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif
//!

int32_t main()
{
	GO
	//fioe();
	int n;
	cin>>n;
	int ans = 0;
	for(int i=1;i<=n;i++){
		if(i%3==0 || i%5 == 0)
			continue;
		ans += i;
	}	
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    ll X;
    cin >> X;
    for (ll i = -200; i <= 200; i++) {
        for (ll j = -200; j <= 200; j++) {
            if (i*i*i*i*i - j*j*j*j*j == X) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a[N];
    
    double mean = 0;
    
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        mean += (double)a[i] / N;
    }
    
    int ans = 0;
    int val = a[0];
    for(int i = 1; i < N; ++i){
        if(abs(val - mean) > abs(a[i] - mean)){
            ans = i;
            val = a[i];
        }
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll k,a,b;
	cin>>k>>a>>b;
	bool ok=false;
	range(i,a,b+1){
		if(i%k==0)ok=true;
	}
	cout<<(ok?"OK":"NG")<<endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll mod=1e9+7;
vector<vector<ll> > dp(1002, vector<ll> (1002,-1));
vector<vector<char> > v(1002, vector<char> (1002));

ll val(ll i,ll j,ll n,ll m){
    if(i==n || j==m || v[i][j]=='#')
    return 0;
    if(i==n-1 && j==m-1) return dp[i][j]=1;
    
    if(dp[i][j]!=-1) return dp[i][j]%mod;
    
    return dp[i][j]=(val(i+1,j,n,m)+val(i,j+1,n,m))%mod;
}

int main() {
    fastio
    
	ll n,i,j,x,k,y;
	cin>>x>>y;
	string s;
	
	for(j=0;j<x;j++){
	    cin>>s;
	    for(k=0;k<y;k++)
	    v[j][k]=s[k];
	}
	
	cout<<val(0,0,x,y)%mod;
	
	return 0;
}



Measured memory_bytes: 12644
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
for _ in range(n):
	x = int(input())
	for i in range(3):
		for j in range(3):
			if a[i][j] == x: a[i][j] = -1

flag = 0
for i in range(3):
	if a[i][0] == -1 and a[i][1] == -1 and a[i][2] == -1:
		flag = 1
	if a[0][i] == -1 and a[1][i] == -1 and a[2][i] == -1:
		flag = 1

if a[0][0]+a[1][1]+a[2][2] == -3 or a[0][2]+a[1][1]+a[2][0] == -3:
	flag = 1

print("No" if flag == 0 else "Yes")

Measured memory_bytes: 3064