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

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

const ll MOD = 1e9+7;

inline void in() {}
template<class T, class... Ts>
inline void in(T& x, Ts&... xs) {
	int c, s=0; x=0;
	while (c=getchar(), c!='-'&&(c<'0'||c>'9'));
	if (c=='-') s=1, c=getchar();
	do x=x*10+(c-'0'); while (c=getchar(), c>='0'&&c<='9');
	if (s) x=-x;
	in(xs...);
}
inline void ins(char *s) {
    char c; while(c=getchar(), c<33); do *s++=c; while(c=getchar(), c>32); *s=0;
}
int n,k;
int a[100000];
vector<int> cs[100000];
int ans;
int dfs(int x) {
	int md=0;
	for(int y:cs[x]) {
		int d=dfs(y);
		if(d==k)ans++;
		else md=max(md,d);
	}
	return md+1;
}
int main() {
	in(n,k);
	rep(i,0,n)in(a[i]),a[i]--;
	rep(i,1,n)cs[a[i]].push_back(i);
	ans=a[0]!=0;
	for(int x:cs[0])dfs(x);
	printf("%d\n",ans);
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    bool zero = false;
    rep(i,n) {
        cin>>a[i];
        if (a[i]==0) zero = true;
    }
    if (zero) {
        cout << 0 << '\n';
        return 0;
    }

    ll ans = 1ll;
    rep(i,n) {
        if (ans > LINF/a[i]) {
            cout << -1 << '\n';
            return 0;
        }
        else {
            ans *= a[i];
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3988
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = 1
c = [0] * n
c[0] = 1
m = 0
while c[b-1] < 2 and k > 0:
	b = a[b-1]
	c[b-1] += 1
	k -= 1
while c[b-1] < 3 and k > 0:
	b = a[b-1]
	c[b-1] += 1
	m += 1
if k == 0:
	print(b)
else:
	o = k % m
	for i in range(o):
		b = a[b-1]
	print(b)

Measured memory_bytes: 32380
#include <stdio.h> 
using namespace std; 
int main(){ int n,m,tmp; 
scanf("%d %d",&n,&m); 
int** A = new int*[n]; 
for(int i = 0; i < n; i++) A[i] = new int[m];
int b[m]; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ scanf("%d",&tmp); 

A[i][j] = tmp; }
}
for(int i = 0; i < m; i++){ scanf("%d",&tmp); 
b[i] = tmp; } long long int sum; for(int i = 0; i < n; i++){ sum = 0;
for(int j = 0; j < m; j++){ sum += A[i][j] * b[j]; } printf("%lld\n",sum); 
    
} 
for(int i = 0; i < n; i++){ 
    delete[] A[i]; 
    
} 
delete A;
}


Measured memory_bytes: 2776
#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;
const double PI = acos(-1);

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;
}
struct UnionFind {
  vector<int> p;
  vector<int> s;
  void init(int n) {
    p.resize(n, -1);
    s.resize(n, 1);
  }
  int find(int n) {
    if(p[n] == -1) return n;
    else return find(p[n]);
  }
  int size(int n) {
    return s[find(n)];
  }
  void unite(int n, int m) {
    int pn = find(n);
    int pm = find(m);
    if(pn == pm) return;
    if(s[pn] > s[pm]) {
      s[pn] = s[pn] + s[pm];
      p[pm]= pn;
    } else {
      s[pm] = s[pm] + s[pn];
      p[pn] = pm;
    }
  }
};

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

int main() {
  vector<int> input({1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51});
  int k;
  cin >> k;
  cout << input[k-1] << endl;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String[] w = new String[n];

		for (int i=0; i<n; i++){
			w[i] = sc.next();
		}

		String beforeWord = "";
		String currentWord = "";
		HashSet<String> pastWord = new HashSet<String>();

		for (int i=0; i<n; i++){
			beforeWord = currentWord;
			currentWord = w[i];
			if (i > 0){
				String befLast = beforeWord.substring(beforeWord.length()-1);
				String curStart = currentWord.substring(0, 1);
				if (!befLast.equals(curStart)){
					System.out.println("No");
					return;
				}
			}
			if (pastWord.contains(currentWord)){
				System.out.println("No");
				return;
			}
			pastWord.add(currentWord);
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        string tmp = to_string(i);
        if ((int)tmp.size() % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,n;
  int j=0,flug=0;
  cin>>n;
  for(int a=1;a<n;a++){
    for(b=1;b<n;b++){
      //cout<<a<<" "<<b<<endl;
      if(a*b<n) j++;
      else if(a*b>=n)break;
    }
  }
  
  cout<<j;
return 0;
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n%2==1){
    cout<<"No"<<endl;
    return 0;
}
string s;
cin>>s;
 
int a = n/2;
for(int i = 0; i<a; i++){
        if(s[i]!=s[i+a]){
            cout<<"No"<<endl;
            return 0;
        }
}

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

Measured memory_bytes: 256
N = int(input())
A_list = [int(input()) for x in range(N)]

sorted_list = sorted(A_list, reverse = True)
max_1st = sorted_list[0]
max_2nd = sorted_list[1]

for num in A_list:
    if num != max_1st:
        print(max_1st)
    else:
        print(max_2nd)

Measured memory_bytes: 14112
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int ll
using namespace std;
typedef long long ll;
signed main(){
  string s;
  int k;
  cin >> s >> k;
  
  int size = s.size();
  
  string check;
  rep(i,size) check += s[0];
  if(check == s){ cout << size*k/2 << endl; return 0; }
  
  int mae = 1, usiro = 1;
  if(s[0] == s[size-1]){
    int i = 1;
    while(s[0] == s[i]){
      mae++; i++; 
    }
    
    i = size -2;
    while(s[size-1] == s[i]){
      usiro++; i--;
    }
  }
  
  int ans = 0, temp = 1;
  rep(i,size-1){
    if(s[i] == s[i+1]) temp++;
    else{ ans += temp/2; temp = 1; }
  }
  ans += temp/2;
  //cout << ans << endl;
  ans *= k;
  //cout << ans << endl;
  if(mae != 1 || usiro != 1){
  ans = ans - (mae/2)*(k-1) -(usiro/2)*(k-1) + ((mae+usiro)/2)*(k-1);
  }
  //cout << mae << endl << usiro << endl;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	string ans = "";
	if (a <= 0 && b >= 0) ans = "Zero";
	if (ans == "") {
		if (a > 0) ans = "Positive";
		else {
			if ((b - a) & 1) ans = "Positive";
			else ans = "Negative";
		}
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

const int MAXN = 105000;
const int INF = (int) 1e9;

int n, a, b;
vector<int> g[MAXN];
int distA[MAXN], distB[MAXN];
queue <int> q;

void bfsA() {
  for (int i = 0; i < n; i++) {
    distA[i] = INF;
  }
  distA[a] = 0;
  q.push(a);
  while (!q.empty()) {
    int cur = q.front(); q.pop();
    for (int to : g[cur]) {
      if (distA[to] == INF) {
        distA[to] = distA[cur] + 1;
        q.push(to);
      }
    }
  }
}

void bfsB() {
  for (int i = 0; i < n; i++) {
    distB[i] = INF;
  }
  distB[b] = 0;
  q.push(b);
  while (!q.empty()) {
    int cur = q.front(); q.pop();
    for (int to : g[cur]) {
      if (distB[to] == INF) {
        distB[to] = distB[cur] + 1;
        q.push(to);
      }
    }
  }
}

int f(int x) {
  return x - 1;
}

int main() { 

  scanf("%d", &n);
  scanf("%d %d", &a, &b);
  a--; b--;

  for (int i = 0; i < n - 1; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    from--; to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }

  bfsA();
  bfsB();

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (distA[i] < distB[i]) {
      int curAns = distA[i];
      int rem = distB[i] - distA[i];

      curAns += f(rem);

      ans = max(ans, curAns);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
    public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
    public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}
static class MyMath
{
    static private long gcdInner(long a, long b) => (a % b == 0) ? b : gcdInner(b, a % b);
    static public long GCD(long a, long b) => (a > b) ? gcdInner(a, b) : gcdInner(b, a);
    static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a);
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
    
    static void Main()
    {
        int n = Console.ReadLine().ToInt();

        var pList = Console.ReadLine().ToIntArray();
        int ans = 0;

        for(int i = 1; i < pList.Length - 1; i++)
        {
            int a = pList[i - 1];
            int b = pList[i];
            int c = pList[i + 1];

            if ((a < b && b <= c) || (c < b && b <= a))
            {
                ans++;
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int n;
main()
{
	cin>>n;
	int k,m=0;
	cin>>k;
	for(;k--;)
	{
		int b;cin>>b;m|=1<<b;
	}
	for(int i=m;i<1<<n;i=i+1|m)
	{
		cout<<i<<":";
		for(int j=0;j<n;j++)if(i>>j&1)cout<<" "<<j;
		cout<<endl;
	}
}



Measured memory_bytes: 3104
#include<iostream>
#include<map>
using namespace std;
int main(){
    map<string,string>w;
    w["Sunny"]="Cloudy";
    w["Cloudy"]="Rainy";
    w["Rainy"]="Sunny";
    string s;
    cin>>s;
    cout<<w[s]<<endl;
    return 0;
}

Measured memory_bytes: 256
/*  CREATED BY
    Stream_Cipher
    13-sep-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif 	
        int x,k,dis;
        cin>>x>>k>>dis;
        // x=abs(x);
        if(abs(x)/dis>=k)
        	cout<<abs(x)-k*dis<<endl;
        else
        {
        	// cout<<"ASF\n";
        	int mx=abs(x)-(abs(x)/dis)*dis;
        	int mn=abs(mx-dis);
        	int ans;
        	k-=abs(x)/dis;
        	if(k%2==0)
        		ans=mx;
        	else
        		ans=mn;
        	cout<<ans<<endl;
        }
}

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

int main() {
  string s;
  cin >> s;
  int size = s.size();
  bool flag = true;

  if (s.at(0) != 'A') {
    flag = false;
  }

  int count = 0;
  char c = s.at(1);
  if (isupper(c)) {
    flag = false;
  }
  for (int i = 2; i < size; i++) {
    if (s.at(i) == 'C') {
      count++;
      continue;
    }
    if (isupper(s.at(i))) {
      flag = false;
    }
  }
  if (s.at(size-1) == 'C') {
    flag = false;
  }
  if (count != 1) {
    flag = false;
  }
  if (flag) {
    cout << "AC" << endl;
  }
  else {
    cout << "WA" << endl;
  }
}


Measured memory_bytes: 256
object Main {
    val mod: Long = (1e9 + 7).toLong
    val fct: Array[Int] = new Array[Int]( (1e5 + 5).toInt )
    val ifct: Array[Int] = new Array[Int]( (1e5 + 5).toInt )

    def power(x: Long, y: Long):Long = {
        if(y <= 0)  return 1
        var ans: Long = power( (x * x) % mod, y >> 1 )
        if( (y & 1) > 0 ) ans = (ans * x) % mod
        return ans
    }

    def factorials(n: Int) = {
        fct(0) = 1
        for(i <- 1 to n) fct(i) = ((1L * i * fct(i-1)) % mod).toInt
        ifct(n) = power(fct(n), mod - 2).toInt
        for(i <- (n-1) to 0 by -1) ifct(i) = ( (1L * (i+1) * ifct(i+1)) % mod ).toInt
    }

    def cmb(n: Int, k: Int): Int = {
        if(n < 0 || k < 0 || n < k) return 0
        var ans: Long = (1L * fct(n) * ifct(k)) % mod
        ans = (ans * ifct(n-k)) % mod
        return ans.toInt
    }

    def main(args: Array[String]) = {
        import scala.io.StdIn.readLine
        var Array(n, k) = readLine.split(" ").map(_.toInt)
        var a: Array[Int] = readLine.split(" ").map(_.toInt)
        factorials(n)

        a = a.sorted
        var ans: Int = 0
        for(i <- 0 until n) {
            val maxes = cmb(i, k - 1)
            val mins = cmb(n - i - 1, k - 1)
            ans = ans + ((1L * maxes * a(i)) % mod).toInt
            if(ans >= mod)  ans = ans - mod.toInt

            ans = ans - ((1L * mins * a(i)) % mod).toInt
            if(ans < 0)  ans = ans + mod.toInt
        }
        printf("%d\n", ans)
    }
}


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

long long func(long long N, long long x)
{
    if(N<0)
        return 0;

    return N/x + 1;
}

int main()
{
    long long a, b, x;
    cin >> a >> b >> x;

    cout << func(b, x) - func(a-1, x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>


int main( ){

  int a, b, c, d, l, e, f;

  scanf("%d\n %d\n %d\n %d\n %d", &l, &a, &b, &c, &d);

  if(a%c == 0)
    e = a/c;
  else
    e = a/c+1;
  
  if(b%d == 0)
    f = b/d;
  else
    f = b/d+1;

  if(e > f)
    printf("%d\n", l-e);
  else
    printf("%d\n", l-f);
  


  return 0;
}

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;



int main(){

    int a,b, k;
    cin >> k;
    cin >> a >> b;

    bool ans = false;

    for(int i = a; i <= b; i++){
        if(i % k == 0){
            ans = true;
            break;
        }
    }

    cout << (ans ? "OK" : "NG") << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define endl  "\n"
const ll MAX=4e3+3;
const ll mod=1e2+7;
vi a(MAX);
ll dp[MAX][MAX];
/*
ll fun(ll i,ll j)
{
    if(i>j)
        return 0;
        if(dp[i][j]!=-1)
            return dp[i][j];
            ll x,y;
    x=a[i]+min(fun(i+2,j),fun(i+1,j-1));
    y=a[j]+min(fun(i+1,j-1),fun(i,j-2));
    dp[i][j]=max(x,y);
    return dp[i][j];

}
*/
ll fun(ll n)
{
    memset(dp,0,sizeof(dp));
    for(ll i=0;i<n;i++)
    {
        dp[i][i]=a[i];
    }
    ll x,y,z,j;
    for(ll len=2;len<=n;len++)
    {
        for(ll i=0;i<=n-len;i++)
        {
            j=i+len-1;
            x=i+2<=j?dp[i+2][j]:0;
            y=i+1<=j-1?dp[i+1][j-1]:0;
            z=i<=j-2?dp[i][j-2]:0;
            dp[i][j]=max(a[i]+min(x,y),a[j]+min(y,z));
        }
    }
    return dp[0][n-1];
}
int main()
{
   FASTIO
   int t=1;
   //cin>>t;
   while(t--)
  {
        ll n,c;cin>>n;
        ll sum=0;
        rep(i,0,n)
        {
            cin>>a[i];
            sum+=a[i];
        }
        memset(dp,-1,sizeof(dp));
        ll ans=fun(n);
        ans=2*ans-sum;
        cout<<ans;
   }
 return 0;
}


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

int main()
{
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1) ans += 300000;
    else if(X == 2) ans += 200000;
    else if(X == 3) ans += 100000;
    if(Y == 1) ans += 300000;
    else if(Y == 2) ans += 200000;
    else if(Y == 3) ans += 100000;
    if(X == 1 && Y == 1) ans += 400000;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>

int main (){
	int n;

	scanf ("%d",&n);
	long long int out=0;
	for (int i=1; i<=n; i++){
		if (i%3==0 || i%5==0){
		}
		else {
			out+=i;
		}
	}
	
	printf ("%lld",out);
	return 0;
}

Measured memory_bytes: 3228
#/usr/bin/ruby
#encoding: utf-8

# input
n = gets.to_i
s = gets.split

p_flag = false
w_flag = false
g_flag = false 
y_flag = false

# compute
(0..n-1).each do |i|
  case s[i]
  when 'P' then
    p_flag = true
  when 'W' then
    w_flag = true
  when 'G' then
    g_flag = true
  when 'Y' then
    y_flag = true
  end
end

#puts "p_flag = #{p_flag}"
#puts "w_flag = #{w_flag}"
#puts "g_flag = #{g_flag}"
#puts "y_flag = #{y_flag}"


cnt = 0
[p_flag,w_flag,g_flag,y_flag].each do |i|
  if i == true
    cnt += 1
  end
end

if cnt == 3 
  puts "Three"
else 
  puts "Four"
end


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

const int maxn = 1e5 + 10;

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a + b >= c - 1) cout << b + c << endl;
    else{
        cout << b + min(c,a + b + 1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
s = list(input())
c,max = 0,0
for i in range(0,len(s)):
  if s[i] in "ATCG":
    c=1
    for j in range(i,len(s)):
      if s[j] in "ATCG":
        if j!=i:
          c+=1
      else:
        break
  if max < c:
    max=c      
print(max) 

Measured memory_bytes: 3060
import java.util.*;

public class Main{
    
    public static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long n = Long.parseLong(sc.next());
        
        long x = Math.min(n, b-1);
        
        System.out.println(a*x/b - a*(x/b));
    }
}


Measured memory_bytes: 26964
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

int main()
{
    int n,l;
    cin>>n>>l;
    double sum=(l+l+n-1)*n/2;
    if(l>0)cout<<sum-l<<endl;
    else if(l+n-1<0)cout<<sum-(l+n-1)<<endl;
    else cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h){
        cin >> s[i];
    }
    vector<int> col(w, 1), row(h, 1);
    rep(i, h){
        bool ok = false;
        rep(j, w){
            if (s[i][j] == '#'){
                ok = true;
                break;
            }
        }
        if (!ok) row[i] = 0;
    }
    rep(i, w){
        bool ok = false;
        rep(j, h){
            if (s[j][i] == '#'){
                ok = true;
                break;
            }
        }
        if(!ok) col[i] = 0;
    }
    rep(i, h){
        if (row[i] != 1) continue;
        rep(j, w){
            if(col[j] != 1) continue;
            cout << s[i][j];
        }
        cout << endl;
    }
}

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

int main() {
	char a;
	cin >> a;
	if(a=='a' || a=='i'||a=='u'||a=='e'||a=='o'){
		cout << "vowel" <<endl;
	}else{
		cout << "consonant" << endl;
	}
	return 0;
}

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

int main()
{
	long long int N,i;
    cin>>N;
  	long long int sum=0;
  	for(int i=1;i<=N;i++)
    {
    	if( i%3!=0 && i%5!=0 )
        {
        	sum=sum+i;
        }
    	
    }
  cout<<sum;

	return 0;
}

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

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

    int ans = 1;

    for(int i = 1; i <= sqrt(n); i++){
        if(i * i <= n){
            ans = i * i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 35000;
const int K = 19;
int mod =  998244353;

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    for (int i = 0; i < n; i++) if (s[i] == 'R') r++;
    int b = n - r;
    if (r > b) cout << "Yes"; else cout << "No";
}


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

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long

using namespace std;

int32_t main() {
	fast
	int n;
	cin >> n;
	int amt = 100, cnt = 0;
	while (amt < n) {
		amt += (amt / 100);
		cnt++;
	}

	cout << cnt;
}

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

#define pb push_back
#define sz size

const int N = 1e3 + 123, MOD = 1e9 + 7;
int n, m, dp[N][N];
char a[N][N];

int main() {
	//freopen("input.txt", "r", stdin);
	cin >> n >> m;
	dp[0][1] = 1;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> a[i][j];
			if(a[i][j] == '.') {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			}
		}
	}
	cout << dp[n][m];
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>=b;i--)
#define FILL(a,b,c) for(ll i=0;i<c;i++) a[i]=b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\n"
#define setpri(x) setprecision(x)
#define vp(x) cout<<#x<<" : "<< (x)<<" | "
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define forf(i,a,b) for(int i=a;i<b;i++)

#define INF 1e17+4
#define MINF 
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) { n %= MOD; if (n < 0) return n + MOD; else return n;}
// vector<int> adj[1000002];
// int vis[1000002],dep[1000002],siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }    
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b) 
// { 
//     return ;


void solve()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int cnt=0;
    cnt+=min(a,k);
    k=k-min(a,k);
    if(k==0)
    {    cout<<cnt;return;}
    k-=min(b,k);
    if(k==0)
    {    cout<<cnt;return;}
    cnt-=min(c,k);
    {    cout<<cnt;return;}
    
    
}


signed main()
{
    FAST;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int join(int a, int b) {
  int bk = floor(log10(b)) + 1;
  return a * pow(10, bk) + b;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i=0; i<n; i++) cin >> a[i];
  
  sort(a, a + n);
  
  int lil = n * min(n-1, 3), lii = 0;
  int li[lil];
  if (n <= 4) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	if (i != j) li[lii++] = join(a[j], a[i]);
      }
    }
  } else {
    // 上は小さいほうから3項に限定
    for (int i=0; i<n; i++) { // 下
      int ji = 0;
      for (int j=0; j<4; j++) { // 上
	if (i != j) li[lii++] = join(a[j], a[i]);
	if (ji++ > 3) break;
      }
    }
  }
  
  sort(li, li + lil);
  
  cout << li[2] << endl;
  
  return 0;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, ans=0;
    cin >> n;
    REP(i,1,n){
        ans += (n-1)/i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
N = int(input())
S_N = [input() for i in range(N)]
print('AC x ' + str(S_N.count('AC')))
print('WA x ' + str(S_N.count('WA')))
print('TLE x ' + str(S_N.count('TLE')))
print('RE x ' + str(S_N.count('RE')))

Measured memory_bytes: 82820
/** 
  If comrades that you trust gather around you, hope can take physical form and become visible. That’s what I believe.
  */
#include <bits/stdc++.h>
using namespace std;
/**
  (▀̿Ĺ̯▀̿ ̿) (ง ͠° ͟ل͜ ͡°)ง
  */
const int N = 2e5 + 10;
int f[N], a[N], ans[N];
vector<int> g[N];
int n;
auto dfs(int idx, int p = -1) -> void {
    int pos = lower_bound(f, f + n, a[idx]) - f;
    int pp = f[pos];
    f[pos] = a[idx];
    ans[idx] = lower_bound(f, f + n, 1 << 30) - f;
    for (auto v : g[idx]) {
        if (v == p) continue;
        dfs(v, idx);
    }
    f[pos] = pp;
}
auto main() -> int {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
    vector<int> tt;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        tt.emplace_back(a[i]);
    }
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    fill(f, f + n, 1 << 30);
    dfs(1);
    for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';

	return 0;
}


Measured memory_bytes: 31500
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def eprint(s):
    if type(s) != type('str'):
        s=str(s)

    sys.stderr.write(s+'\n')
    return

def check(s, idx):
    s1 = set(s[:idx])
    s2 = set(s[idx:])

    return len(s1 & s2)

def main():
    n = int(input())
    s = input()[:-1]

    ma = -1 * 10**9
    
    for i in range(1, n):
        c = check(s, i)
        if c > ma:
            ma = c

    print(ma)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 63980
fn main() {
  let n = get::chars();
  let n = n.iter().map(|&c|c as isize - '0' as isize).collect::<Vec<_>>();

  let ans = match (n[0], n[1], n[2], n[3]) {
    (a,b,c,d) if a+b+c+d==7 => format!("{}+{}+{}+{}", a, b, c, d),
    (a,b,c,d) if a-b+c+d==7 => format!("{}-{}+{}+{}", a, b, c, d),
    (a,b,c,d) if a+b-c+d==7 => format!("{}+{}-{}+{}", a, b, c, d),
    (a,b,c,d) if a-b-c+d==7 => format!("{}-{}-{}+{}", a, b, c, d),
    (a,b,c,d) if a+b+c-d==7 => format!("{}+{}+{}-{}", a, b, c, d),
    (a,b,c,d) if a-b+c-d==7 => format!("{}-{}+{}-{}", a, b, c, d),
    (a,b,c,d) if a+b-c-d==7 => format!("{}+{}-{}-{}", a, b, c, d),
    (a,b,c,d) if a-b-c-d==7 => format!("{}-{}-{}-{}", a, b, c, d),
    _ => unreachable!()
  };

  println!("{}=7", ans)
}


#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N,0);
    vector<ll> B(M+1,0);
    ll ans = 0;
    REP(i,N){
        cin >> A[i];
        if(i>=1) A[i] += A[i-1];
    }
    REP(i,M){
        cin >> B[i];
        if(i>=1) B[i] += B[i-1];
    }
    B[M] = 3000000000000000;
    std::vector<ll>::iterator iter = upper_bound(B.begin(),B.end(),K);
    int pos = std::distance(B.begin(), iter);
    ll newans = pos;
    ans = newans;
    REP(i,N){
        if(A[i]<=K){
            ll search = K - A[i];
            std::vector<ll>::iterator iter = upper_bound(B.begin(),B.end(),search);
            int pos = std::distance(B.begin(), iter);
            ll newans = pos + i + 1;
            if(newans > ans) ans = newans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _11179
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();

            for (int i = 0 ; i < n ; i++)
            {
                int[] line = ReadIntAr();
                int res = 0;
                for (int j = 999 ; line[0] <= j ; j--)
                {
                    if (j != line[0]) res += (j % 3 == 0) ? 200 : 195;
                    else
                    {
                        for (int k = 10 ; line[1] <= k  ; k--)
                        {
                            if (k != line[1]) res += (j % 3 == 0 || k % 2 == 1) ? 20 : 19;
                            else
                            {
                                res += (j % 3 == 0 || k % 2 == 1) ? 20 - line[2] + 1 : 19 - line[2] + 1;
                            }
                        }

                    }
                }
                Console.WriteLine(res.ToString());
            }
            
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15888
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef pair<int,int> pii;
static const int INF = 1ll<<60;

int t[10001];
int N,A,B;
int ans;
bool stop=false;

signed main(){
    cin>>N>>A>>B;
    for(int i=0;i<N;++i)cin>>t[i];
    sort(t,t+N);
    for(int i=0;i<N;++i){
        if(!stop&&t[i]>=A&&t[i]<B){
            stop=true;
            continue;
        }
        else if(stop&&t[i]<B&&t[i]>=A){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import numpy as np
S = input().split() 
L = int(S[0])
R = int(S[1])
ans = 2019*2019
if(R-L >=2019):
    print(0)
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans = np.minimum(ans,(i*j)%2019)
            if(ans == 0):
                print(0)
                exit()
    print(ans)

Measured memory_bytes: 12396
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    private static readonly Scanner sc = new Scanner();
    static void Main(string[] args)
    {
        int a = sc.Int;
        int b = sc.Int;
        int c = sc.Int;

        if (a <= c && c <= b)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

class Scanner
{
    private string[] _str = new string[0];
    private int _i;

    public string Str
    {
        get
        {
            if (_i >= _str.Length)
            {
                _str = Console.ReadLine().Split(' ');
                _i = 0;
            }
            return _str[_i++];
        }
    }

    public int Int { get { return int.Parse(Str); } }
    public long Long { get { return long.Parse(Str); } }
    public double Double { get { return double.Parse(Str); } }
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll rsl1 = 0, rsl2 = 0, rsl3 = 0, rsl = 0;
  int tmp1 = (y - x >= 0) ? y - x : 0;
  int tmp2 = (x - y >= 0) ? x - y : 0;
  rsl1 = c * 2 * x + b * tmp1;
  rsl2 = c * 2 * y + a * tmp2;
  rsl3 = a * x + b * y;
  rsl = min(rsl1, min(rsl2, rsl3));
  cout << rsl << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int n; cin>>n;
  int ans=0;
  int a,b;
  for (int i=0;i<n;i++){
      cin>>a>>b;
      ans =ans+((b-a)+1);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long n,a,b;
    cin>>n>>a>>b;
    long long s,p,q,r,t;
    s = a+b;
    p=n/s;
    q=p*a;
    r=n-s*p;
    if(r>=a){
        q+=a;
        cout<<q<<endl;
    }else{
        q+=r;
        cout<<q<<endl;
    }
}

Measured memory_bytes: 384
use std::str::FromStr;
use std::io::*;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = AtRead::from(i);
    let (n, k) = i.read2::<usize, usize>();
    let d = i.read_vec::<usize>(k);
    writeln!(o, "{}", solve(n, &d)).unwrap();
}
fn solve(mut n: usize, d: &[usize]) -> usize {
    let mut t = [true; 10];
    for &d in d {
        t[d] = false;
    }

    let mut uppers = [None; 10];
    let mut min = None;
    for i in 0..10 {
        let i = 9 - i;
        if t[i] {
            min = Some(i);
        }
        uppers[i] = min;
    }

    let mut rs = Vec::new();
    while n != 0 {
        rs.push(n % 10);
        n /= 10;
    }
    if rs.is_empty() {
        rs.push(0);
    }

    let mut i = 0;
    let mut i_up = 0;
    let mut is_up = false;
    loop {
        if i == rs.len() {
            if is_up {
                rs.push(0);
            } else {
                break;
            }
        }
        let mut r = rs[i];
        if is_up && r < 9 {
            is_up = false;
            r = r + 1;
            i_up = i;
        }
        if !is_up & !t[r] {
            if let Some(u) = uppers[r] {
                i_up = i;
                r = u;
            } else {
                is_up = true;
            }
        }
        rs[i] = r;
        i += 1;
    }
    for i in 0..i_up {
        rs[i] = min.unwrap();
    }
    let mut result = 0;
    rs.reverse();
    for &r in &rs {
        result *= 10;
        result += r;
    }
    result
}

mod utils {
    #![allow(dead_code)]
    use super::*;

    pub struct AtRead<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        {$f:ident($($v:ident: $t:ident),*)} => {
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                $(
                    let $v = next(i);
                )*
                ($($v),*)
            }
        };
    }

    impl<R: BufRead> AtRead<R> {
        pub fn from(r: R) -> Self {
            AtRead {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(v1: T1, v2: T2) }
        fn_read! { read3(v1: T1, v2: T2, v3: T3) }
        fn_read! { read4(v1: T1, v2: T2, v3: T3, v4: T4) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }

    fn next<'a, T: FromStr, I: std::iter::Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main(){
    int n, maior = 0;
    cin >> n;
    
    int a, b, temp = 0;
    
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        if(a == b){
            temp++;
        } else{
            if(temp > maior)
                maior = temp;
            
            temp = 0;
        }
    }
    
    if(temp > maior)
        maior = temp;
    
    if(maior >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

const ll MaxN=1e5+5;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main(){
	ll a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	REP(i,a+b+1){
		if(i==a){
			if(s[i]!='-'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		else if(s[i]-'0'<0||s[i]-'0'>9){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict as dd
H, W, N = map(int, input().split())
res = [0] * 10
res[0] = H * W - 2 * H - 2 * W + 4
p = dd(int)
d = [-1, 0, 1]
for _ in range(N):
  y, x = map(int, input().split())
  for i in d:
    for j in d:
      if 1 < y + i < H and 1 < x + j < W:
        p[(y + i) * (H * W + 1) + x + j] += 1
for k in p.keys():
  res[p[k]] += 1
  res[0] -= 1
for r in res:
  print(r)

Measured memory_bytes: 104872
n = int(input())
s = list(input())
t = list(input())
cnt = 0
for i in range(min(len(s), len(t))):
    c = 0
    for j in range(i + 1):
        if s[len(s) - 1 - i + j] == t[j]:
            c += 1
    cnt = max(cnt, c)
ans = len(s) + len(t) - cnt
if ans < n:
    ans = n
print(ans)

Measured memory_bytes: 64768
/*https://atcoder.jp/contests/agc024/tasks/agc024_a*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	long long a, b, c, d, e, f, k;
	cin >> a >> b >> c >> k;
	if (a == b && a == c)
	{
		cout << "0";
		return 0;
	}
	if (k % 2 == 0)
		cout <<a - b;
	else
		cout <<b-a;

}

Measured memory_bytes: 3612