akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 * 
 * lower_boundとupper_boundの実装は https://qiita.com/taskie/items/b4e45e2005aa38e90bcb に参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Integer[] a = new Integer[n], b = new Integer[n], c = new Integer[n];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.nextInt());
			IntStream.range(0, n).forEach(i -> b[i] = scanner.nextInt());
			IntStream.range(0, n).forEach(i -> c[i] = scanner.nextInt());
			Arrays.sort(a);
			Arrays.sort(c);
			System.out.println(
					IntStream.range(0, n).mapToLong(i -> getLessCount(b[i], a) * getGreaterCount(b[i], c)).sum());
		}
	}

	/**
	 * 配列の中で入力数字より小さい数字の数を返す
	 * 
	 * @param i 数字
	 * @param a 配列
	 * @return 配列の中で入力数字より小さい数字の数
	 */
	private static long getLessCount(int i, Integer[] a) {
		int result = Arrays.binarySearch(a, i, (x, y) -> (x.compareTo(y) >= 0) ? 1 : -1);
		if (result < 0) {
			result = ~result;
		}
		return result;
	}

	/**
	 * 配列の中で入力数字より大きい数字の数を返す
	 * 
	 * @param i 数字
	 * @param a 配列
	 * @return 配列の中で入力数字より大きい数字の数
	 */
	private static long getGreaterCount(int i, Integer[] a) {
		int result = Arrays.binarySearch(a, i, (x, y) -> (x.compareTo(y) > 0) ? 1 : -1);
		if (result < 0) {
			result = ~result;
		}
		return a.length - result;
	}
}


Measured memory_bytes: 66928
#include<stdio.h>
#include<string.h>

int main(){
  char s[51];
  int n;
  scanf("%d",&n);
  scanf("%s",s);

  int count=0;
  int pos=0;//A:1,AB:2,ABC:3
  for(int i=0;i<n;i++){
    if('A'==s[i]){
      pos=1;
      continue;}
    if('B'==s[i] && pos==1){
      pos=2;
      continue;}
    if('C'==s[i] && pos==2){
      pos=0;
      count++;
      continue;}
    pos=0;}

  printf("%d\n",count);

  return 0;
}


Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b, c, d = na()
kouho = [a * c, a * d, b * c, b * d]
print(max(kouho))


Measured memory_bytes: 10828
from itertools import accumulate
from collections import Counter

N, K, *A = map(int, open(0).read().split())

S = [0] + [a % K for a in accumulate(a - 1 for a in A)]

C = Counter()
ans = 0
for i, s in enumerate(S):
    ans += C[s]
    C[s] += 1
    if i - K + 1 >= 0:
        C[S[i - K + 1]] -= 1

print(ans)

Measured memory_bytes: 40672
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

void chmin(int *a, int b)
{
	if (b < *a)
		*a = b;
}

int n;
int h[100010];
int dp[100010];

int rec(int i)
{
	if (dp[i] < INT_MAX)
		return dp[i];
	
	if (i == 0)
		return 0;
	int res = INT_MAX;

	chmin(&res, rec(i - 1) + abs(h[i] - h[i - 1]));
	if (i > 1) chmin(&res, rec(i - 2) + abs(h[i] - h[i - 2]));

	return dp[i] = res;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &h[i]);
	for (int i = 0; i < 100010; i++) dp[i] = INT_MAX;

	printf("%d", rec(n-1));
	return 0;
}


Measured memory_bytes: 4096
N = int(input())
h = list(map(int,input().split()))
dp = [-1]*N

def rec_dp(i,dp):
    if i==0:
        return 0
    elif i==1:
        return abs(h[1]-h[0])
    else:
        onestepmin = dp[i-1] + abs(h[i-1] - h[i])
        twostepmin = dp[i-2] + abs(h[i-2] - h[i])
        return min([onestepmin,twostepmin])

for i in range(N):
    dp[i] = rec_dp(i,dp)

print(dp[N-1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n , m;
  scanf("%d%d",&n,&m);
  int t = 0 , ans = 0;
  for(int i = 0 ; i < n ; i++)
  {
    int te;scanf("%d",&te);
    if(t > m) {printf("%d\n",i);return 0;}
    t += te;
  }
  if(t <= m)  cout<<n+1<<endl;
  else cout<<n<<endl;
}

Measured memory_bytes: 256
length = int(input())
li = list(input())
i = 0
for n in li[:]:
    if i + 1 == len(li):
        print(len(li))
        break
    if li[i] == li[i + 1]:
       del (li[i + 1])
    else:
        i = 1 + i
        continue

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

using namespace std;

long long x, k, d, ans;

int main() {
    scanf("%lld%lld%lld", &x, &k, &d);
    x = abs(x);
    auto p = x % d, q = p - d;
    if ((x - p) / d % 2 == k % 2) {
        ans = (x - p) / d <= k ? p : x - d * k;
    } else {
        ans = (x - q) / d <= k ? -q : x - d * k;
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 3820
use std::io::*;

fn main() {
  let input = {
    let mut buf = vec![];
    stdin().read_to_end(&mut buf);
    unsafe { String::from_utf8_unchecked(buf) }
  };
  let mut lines = input.split('\n').map(|s| s.parse::<i32>().unwrap());

  let a = lines.next().unwrap();
  let b = lines.next().unwrap();
  let c = lines.next().unwrap();
  let d = lines.next().unwrap();
  let e = lines.next().unwrap();

  let sec =
    if a <= 0 { -a * c + d + b * e }
    else { (b - a) * e };

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



Measured memory_bytes: 5020
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {

	ll n, k, m = 0;

	cin >> n >> k;

	ull num[100000] = { 0 };

	rep(i, 0, n) {
		ll a, b;
		cin >> a >> b;
		num[a - 1] += b;
		m = max(m, a);
	}

	rep(i, 0, m) {
		k = k - num[i];
		if (k <= 0) {
			cout << i + 1 << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

//bubble sort


int main() {

    int n, tmp;
    int a[100];
    int count = 0;
    int flag = 1;

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

    }


    while (flag) {
        flag = 0;
        for (int j=n-1; j>=1; j--){
            if (a[j] < a[j-1]) {
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
    }

    for(int i=0; i<n; i++) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << count << endl;

    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

int main(){
    int N; cin >> N;
    vector<ll> a(N); REP(i, N) cin >> a[i];

    int cnt_four = 0;
    int cnt_two = 0;
    int cnt_one = 0;
    for(int j = 0; j < N; ++j) {
        if(a.at(j) % 4 == 0) {
            cnt_four++;
        }

        if(a.at(j) % 2 == 0 && a.at(j) % 4 != 0) {
            cnt_two++;
        }

        if(a.at(j) % 2 != 0 && a.at(j) % 4 != 0) {
            cnt_one++;
        }
    }

    if(cnt_two == 0) {
        if(cnt_one <= cnt_four + 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if(cnt_one <= cnt_four) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int result = k*(int)Math.pow(k - 1, n - 1);
		System.out.println(String.valueOf(result));
	}
}

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

using namespace std;

typedef unsigned long long ll;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define II pair <int,int>

const int N=2e5+10;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while (a>0&&c>0) {
        c-=b;
        if (c<=0) {cout << "Yes";exit(0);}
        a-=d;
        if (a<=0) {cout << "No";exit(0);}
    }
}
    

Measured memory_bytes: 3652
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
print(':(' if a > 8 or b > 8 else 'Yay!')















Measured memory_bytes: 27168
#include <iostream>

using namespace std;

int N;
int a[100005];
bool used[100005];

int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> a[i];
	
	int ans = 0, now = 1;
	while(1){
		if(used[now]){
			ans = -1;
			break;
		}
		if(now == 2) break;
		
		used[now] = true;
		now = a[now];
		ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
	int n, K, min = 0, max = 0, P;
	scanf("%d %d", &n, &K);
	vector<int> w(n);
	for (int &x: w) {
		scanf("%d", &x);
		min = min > x ? min : x;
		max += x;
	}
	min--;
	
	for (;;) {
		P = (max + min) / 2;
		auto i = w.begin(), e = w.end(), last = e - 1;
		int k = 0, p = 0;
		for (; i != e && k < K; i++) {
			int tmp = p + *i;
			if (tmp > P) {
				p = *i, k++;
				if (i == last)
					k++;
			} else if (tmp == P)
				p = 0, k++;
			else {
				if (i == last) k++;
				p = tmp;
			}
		}
		if (i == e && k <= K)
			max = P;
		else
			min = P;

		if (max == min + 1) {
			P = max;
			break;
		}
	}
	printf("%d\n", P);
}



Measured memory_bytes: 2760
// https://atcoder.jp/contests/abc075/tasks/abc075_b
#include <bits/stdc++.h>
using namespace std;

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> field(H);
  rep(i, 0, H) { cin >> field[i]; }

  rep(i, 0, H) {
    rep(j, 0, W) {
      if (field[i][j] == '.') {
        int mine = 0;
        rep(x, -1, 2) {
          if (j + x < 0 || W <= j + x) continue;
          rep(y, -1, 2) {
            if (i + y < 0 || H <= i + y) continue;
            if (field[i + y][j + x] == '#') mine++;
          }
        }
        field[i][j] = '0' + mine;
      }
    }
    cout << field[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;



public class Main {
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int calc = 1000 - n %1000;
		System.out.println(calc == 1000 ? 0 : calc);
		sc.close();
	}
 
}

Measured memory_bytes: 35860
#include <array>
#include <iostream>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::array;
using std::for_each;
using std::min_element;

int main() {
	array<int,3> p;
	array<int,2> j;
	for_each(p.begin(),p.end(),[](int &x){cin >> x;});
	for_each(j.begin(),j.end(),[](int &x){cin >> x;});
	cout << *min_element(p.begin(),p.end()) + *min_element(j.begin(),j.end()) - 50 << endl;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

ll nck(ll n, ll k) {
    ll ret = 1;
    for (ll i = 0; i < k; i++) {
        ret *= n - i;
        ret /= i + 1;
    }
    return ret;
}

int main() {
    int n, p; cin >> n >> p;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    ll even = 0, odd = 0;
    rep(i, n) {
        if (a[i] % 2 == 0) even++;
        else odd++;
    }

    ll ne = 0, no = 0;
    for (ll i = 0; i <= even; i++) {
        ne += nck(even, i);
    }
    for (ll i = 0; i <= odd; i++) {
        if (i % 2 == p) no += nck(odd, i);
    }
    cout << ne * no << endl;
}


Measured memory_bytes: 256
import sys
from itertools import count, takewhile

def dfs(n, d={}):
  if n < 6:
    return n
  if n in d:
    return d[n]

  max9 = max(takewhile(lambda x: x<=n, (9**i for i in count())))
  max6 = max(takewhile(lambda x: x<=n, (6**i for i in count())))
  d[n] = min(dfs(n-max9), dfs(n-max6)) + 1
  return d[n]


def main():
  input = sys.stdin.readline
  N = int(input())
  print(dfs(N))
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigDecimal;

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
      int n = in.nextInt();
      int[] R = new int[n];
      int max = -1000000000;
      
      
      for (int i = 0; i < n; i++) {
        R[i] = in.nextInt();
      }
      int min = R[0];
      
      for (int j = 1; j < n; j++) {
       max = Math.max(max, R[j] - min);
       min = Math.min(min, R[j]);
      }
      
      out.println(max);
//      End solve()
    }
    
    
    
//    End Solution
}


  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}


  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

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

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(...) cout << __VA_ARGS__ << endl
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int main() {
  int a, b, c;
  scanf("%d/%d/%d", &a, &b, &c);
  printf("2018/%02d/%02d\n", b, c);
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))

for i in range(1,n):
  a[i]+=a[i-1]
a=[0]+a
b=[q%m for q in a]
from collections import Counter
c=Counter(b).items()
ans=0
for i,j in c:
  ans+=(j*(j-1)//2)
print(ans)

Measured memory_bytes: 22404
#include <bits/stdc++.h>
#define LL long long 
#define N 1000005
using namespace std;
int n,m,ar[N],k,l,a,b,sum,mk;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&ar[i]);
	for(int i=1;i<n;i++)
	{
		if(ar[i+1]+ar[i]>mk)
			mk=ar[i]+ar[i+1],k=i,l=i+1;
	}	
	//~ printf("%d\n",mk);
	if(mk<m)
	{
		printf("Impossible");
		return 0;
	}
	printf("Possible\n");
	for(int i=1;i<=k-1;i++)
		printf("%d\n",i);
	for(int i=n;i>=l+1;i--)
		printf("%d\n",i-1);
	printf("%d\n",k);	
}


Measured memory_bytes: 1152
package main
import "fmt"
func main(){
  var a,b int
  fmt.Scanf("%d %d",&a,&b)
  if a>b {
    fmt.Println("a > b")
  }else if a<b {
    fmt.Println("a < b")
  }else {
    fmt.Println("a == b")
  }
}




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

long abss(long a)
{
  return a > 0 ? a:-a;
}
 
int main()
{
  long x,k,d;
  
  cin >> x >> k >> d;
  
  x = abss(x);
  
  long ndiv = x / d;
  if (ndiv > k) ndiv = k;
  x = x - ndiv*d;
  k -= ndiv;
  k = k%2;
  
  
  for(long i=0;i<k;i++)
  {
    long m = x - d;
    long p = x + d;
    
    if(abss(m) < abss(p))
    {
      x = m;
    }
    else
    {
      x = p;
    }
  }
  
  cout << abss(x) << endl;
  
  return 0;
}

Measured memory_bytes: 3624
from collections import deque

N = int(input())
A = deque(map(int, input().split()))
first = A.popleft()


def round(a):
        B = list(A)
        eval = 0
        pre = first
        post = a
        B.remove(a)
        num = N - 2
        while num != 0:
                c = pre ^ post
                try:
                        B.remove(c)
                        pre = post
                        post = c
                        num -= 1
                except:
                        return 0
                        eval = 1
                        break
        
        if eval == 0 and post ^ first == a:
                return 1
        elif eval == 0:
                return 0

val = first
for i in range(N - 1):
        val = val ^ A[i]

if val != 0:
        print('No')
else:
        ans = 0
        for i in range(0, N - 1):
                ans = round(A[i])
                if ans == 1:
                        print('Yes')
                        break
                        

        if ans == 0:
                print('No')




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

int main() {
	ll X, K, D;
	cin >> X >> K >> D;
	ll a = K / 2 - X / (2 * D);
	if (a < 0) a = 0;
	if (a > K) a = K;
	ll b = (a < K ? a + 1 : K);
	ll c = (a > 0 ? a - 1 : 0);
//	cout << a << " " << b << " " << c << endl;
	ll aa = abs(X + D * (2 * a - K));
	ll bb = abs(X + D * (2 * b - K));
	ll cc = abs(X + D * (2 * c - K));
	aa = (aa < bb ? aa : bb);
	aa = (aa < cc ? aa : cc);
	cout << aa << endl;
	return(0);
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int ll
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using pii = pair<int, int>;
using ppp = pair<int , pii>;
const int mod = 1000000007;
int v[303030];
int cbs[66];
int pm[66];
int32_t main()
{
	pm[0] = 1;
	for (int i = 1; i<65; i++)
		pm[i] = pm[i-1]*2 % mod;
	int n;
	cin >> n;
	for (int i = 1; i<=n; i++)
		cin >> v[i];
	for (int i = 1; i<=n; i++)
		for (int j = 0; j<64; j++)
			if (v[i] & (1LL << j))
				cbs[j]++;
	int ans = 0;
	for (int i = 0; i<64; i++)
	{
		int ct = (cbs[i] * (n-cbs[i]))%mod;
		ans += (ct*pm[i])%mod;
		ans %= mod;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 2560
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long

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

    int h,w; cin >> h >> w;
    vector<vector<char> > s(h+2,vector<char> (w+2));

    for(int i = 1;i < h+1;i ++){
        for(int j = 1;j < w + 1;j ++){
            cin >> s.at(i).at(j);
        }
    }

    vector<vector<int> > ans(h+2,vector<int>(w+2));

    for(int i = 0;i < h+2;i ++){
        for(int j = 0;j < w + 2;j ++){
            ans.at(i).at(j) = 100000;
        }
    }

    if(s.at(1).at(1) == '.') ans.at(1).at(1) = 0;
    else ans.at(1).at(1) = 1;

        for(int i = 1;i < h+1;i ++){
            for(int j = 1;j < w+1;j ++){
                
                if(s.at(i).at(j) == '.'){
                    ans.at(i).at(j) = min(ans.at(i).at(j),ans.at(i).at(j-1));
                    ans.at(i).at(j) = min(ans.at(i).at(j),ans.at(i-1).at(j));
                }else if(s.at(i).at(j) == '#'){
                    if(s.at(i).at(j-1) == '.'){
                        ans.at(i).at(j) = min(ans.at(i).at(j),ans.at(i).at(j-1)+1);
                    }else if(s.at(i).at(j-1) == '#'){
                        ans.at(i).at(j) = min(ans.at(i).at(j),ans.at(i).at(j-1));
                    }

                    if(s.at(i-1).at(j) == '.'){
                        ans.at(i).at(j) = min(ans.at(i).at(j),ans.at(i-1).at(j)+1);
                    }else if(s.at(i-1).at(j) == '#'){
                        ans.at(i).at(j) = min(ans.at(i).at(j),ans.at(i-1).at(j));
                    }
                }
            }
        }

    cout << ans.at(h).at(w) << endl;

}


Measured memory_bytes: 384
import math

a,b,c = map(float,input().split())

sinc = math.sin(c*math.pi/180)
cosc = math.cos(c*math.pi/180)
c = math.sqrt(a**2+b**2-2*a*b*cosc)
s = a*b*sinc/2.0

print(s)
print(a+b+c)
print(s/a*2.0)


Measured memory_bytes: 5688
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define Jehian using
#define Norman namespace
#define Saviero std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

Jehian Norman Saviero;

/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n")
#define sp printf(" ")

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y
#define SQR(x) (x)*(x)
#define CUBE(x) SQR(x)*(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)

set<ll> data;
int main(){
	ll N;
	scll(N);
	while (N--){
		ll tmp;
		scll(tmp);
		data.insert(tmp);
	}
	cout << data.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
	int n;
	
	int count = 0;
	int max = 0;
	scanf("%d", &n);
	char s[105];
	scanf("%s", &s);
	for (int i = 0; i < n; i++) {
		
		if (s[i] == 'I') {
			max++;
		}
		else if (s[i] == 'D') {
			max--;
		}
		if ( max > count) {
			count = max;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n+1];
  ll mi=1000000000000;
  ll ma=-1000000000000;
  for(ll i=1;i<=n;i++){
    cin>>a[i];
    a[i]-=i;
    mi=min(mi,a[i]);
    ma=max(ma,a[i]);
  }
  ll u=ma+1;
  ll d=mi-1;
  while(u-d>2){
    ll r=(2*u+d)/3;
    ll l=(2*d+u)/3;
    ll sumr=0,suml=0;
    for(ll i=1;i<=n;i++){
      sumr+=abs(a[i]-r);
      suml+=abs(a[i]-l);
    }
    if(sumr<=suml){
      d=l;
    }
    else{
      u=r;
    }
    //cout<<u<<" "<<d<<endl;
  }
  ll ansu=0,ansd=0,ansm=0;
  for(ll i=1;i<=n;i++){
    ansu+=abs(a[i]-u);
    ansd+=abs(a[i]-d);
    ansm+=abs(a[i]-(u-1));
  }
  ansd=min(ansd,ansm);
  cout<<min(ansu,ansd)<<endl;
}

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

int main(){
  ll N, i;
  string S, T;
  cin >> S >> T;

  cout << T + S << endl;
  return 0;
}

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

typedef long long ll;

inline ll f(ll x) { return ll(floor(x/2.)); }
inline ll c(ll x) { return ll(ceil(x/2.)); }
inline ll min3(ll a, ll b, ll c) { return min(a, min(b,c)); } 

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long x,y,z;
    while(cin >> x >> y >> z) {
        cout << min3(llabs(x*y*f(z) - x*y*c(z)), 
                     llabs(x*f(y)*z - x*c(y)*z),
                     llabs(f(x)*y*z - c(x)*y*z)) << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long dp[110][4][4][4] = { 0 };
//0=A 1=G 2=C 3=T
int main() {
	int n;
	cin >> n;
	dp[0][3][3][3] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				for (int l = 0; l < 4; l++) {
					if (k == 0 && l == 1) {
						for (int m = 0; m < 4; m++) {
							if (m == 2) {
								continue;
							}
							dp[i][k][l][m] += dp[i - 1][j][k][l];
							dp[i][k][l][m] %= 1000000007;
						}
					}
					else if (k == 0 && l == 2) {
						for (int m = 0; m < 4; m++) {
							if (m == 1) {
								continue;
							}
							dp[i][k][l][m] += dp[i - 1][j][k][l];
							dp[i][k][l][m] %= 1000000007;
						}
					}
					else if (k == 1 && l == 0) {
						for (int m = 0; m < 4; m++) {
							if (m == 2) {
								continue;
							}
							dp[i][k][l][m] += dp[i - 1][j][k][l];
							dp[i][k][l][m] %= 1000000007;
						}
					}
					else if (j == 0 && l == 1) {
						for (int m = 0; m < 4; m++) {
							if (m == 2) {
								continue;
							}
							dp[i][k][l][m] += dp[i - 1][j][k][l];
							dp[i][k][l][m] %= 1000000007;
						}
					}
					else if (j == 0 && k == 1) {
						for (int m = 0; m < 4; m++) {
							if (m == 2) {
								continue;
							}
							dp[i][k][l][m] += dp[i - 1][j][k][l];
							dp[i][k][l][m] %= 1000000007;
						}
					}
					else {
						for (int m = 0; m < 4; m++) {
							dp[i][k][l][m] += dp[i - 1][j][k][l];
							dp[i][k][l][m] %= 1000000007;
						}
					}
				}
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				ans += dp[n][i][j][k];
				ans %= 1000000007;
			}
		}
	}
	cout << ans << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> table.at(i).at(j);
    }
  }
  vector<bool> row(H,false),col(W,false);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(table.at(i).at(j)=='#'){
        break;
      }
      else if(j==W-1){
        row.at(i)=true;
      }
    }
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(table.at(i).at(j)=='#'){
        break;
      }
      else if(i==H-1){
        col.at(j)=true;
      }
    }
  }
  for(int i=0;i<H;i++){
    if(row.at(i)==true){
      continue;
    }
    for(int j=0;j<W;j++){
      if(col.at(j)==true){
        continue;
      }
      cout << table.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
n = int(input())-1
a = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    t = 0
    for c,s,f in a[i:n]:
        if t<=s: t = s+c
        else:t = s+-(-(t-s)//f)*f+c
    print(t)
print(0)

Measured memory_bytes: 42220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, 3) if (s[i] == '1') cnt++;
  cout << cnt << endl;
}

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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define reunique(a) (a).resize(unique(all(a)) - (a).begin())
#define ld long double
#define int long long

void SOLVE(){
    int n, k;
    cin >> n >> k;
    int ct = 0;
    while (n){
        n /= k;
        ct++;
    }
    cout << ct << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int Q = 1;
    //cin >> Q;
    while (Q--){
        SOLVE();
    }

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = input()
a = input()
b = input()
c = input()

count = 0
for ai, bi, ci in zip(a, b, c):
    if ai == bi == ci:
        continue
    elif (ai == bi) or (ai == ci) or (bi == ci):
        count += 1
    else:
        count += 2

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll gcd(ll x,ll y){
    while(1){
        if(x<y)swap(x,y);
        if(!y)break;
        x%=y;
    }
    return x;
}
int main(void){
    // Your code here!
    ll n;
    cin>>n;
    ll a;
    cin>>a;
    ll ans=a;
    rep(0,i,n){
        cin>>a;
        ans=gcd(ans,a);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<atcoder/all>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;
using namespace atcoder;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

// segtree
// 型 S, 二項演算 S op(S a, S b), 単位元 S e() を設定
// segtree<int, op, e> seg(10); // 要素数n、segという名前で作成
// seg.set(int p, S x) // a[p]にxを代入
// S seg.get(int p) // a[p]を返す
// S seg.prod(int l, int r) // op(a[l], ..., a[r - 1])を返す
// S seg.all_prod() // op(a[0], ..., a[n - 1])を返す
// int seg.max_right<f>(int l) // f(op(a[l], a[l + 1], ..., a[r - 1])) = trueとなる最大のr


int op(int a, int b){
    return a+b;
}

int e(){
    return 0;
}

signed main(){
    int n,q;
    cin >> n >> q;
    segtree<int, op, e> seg(n);
    REP(i,n){
        int a1;
        cin >> a1;
        seg.set(i,a1);
    }
    
    REP(i,q){
        int q1;
        int q2,q3;
        cin >> q1 >> q2 >> q3;
        if(q1==0){
            seg.set(q2,seg.get(q2)+q3);
        }
        else{
            cout << seg.prod(q2,q3) << endl;
        }

    }



    return 0;
}

Measured memory_bytes: 15352
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
// #define M           1000000007
 
using namespace std;
 
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x);
        x=(x*x);
        n=n/2;
    }
    return result;
}
 
class dsu{
    vi p,rank;
    vi set_count;
  
  public:
    dsu(int n){
        p.assign(n,0); 
        rank.assign(n,0);
        set_count.assign(n,1);
        for(int i=0;i<n;i++) p[i] = i;
    }
    int findSet(int x){
        return (p[x] == x) ? x:(p[x] = findSet(p[x]));
    }
    bool isSame(int i, int j){
        return (findSet(i) == findSet(j));
    }
    void unionSet(int i, int j){
        if(!isSame(i,j)){
            int x = findSet(i), y = findSet(j);
            if(rank[x] > rank[y]) {p[y] = x; set_count[x]+=set_count[y];}
            else{
                p[x] = y;
                set_count[y]+=set_count[x];
                if(rank[x] == rank[y]) rank[y]++;
            }
        }
    }
    int count(int x){
        return set_count[findSet(x)];
    }
};

int mat[105][105][15];
int dp[105][105][15];
 
signed main()
{
    tezz
 
    int n;
    cin>>n;
    vi v1(n), v2(n);
    for(int &x:v1) cin>>x;
    for(int &x:v2) cin>>x;

    vi tempv1 = v1, tempv2 = v2;
    sort(all(tempv1));
    sort(all(tempv2));

    int count1 = 0,count2=0;
    do{
        count1++;
        if(tempv1 == v1) break;
    } while(next_permutation(all(tempv1)));

    do{
        count2++;
        if(tempv2 == v2) break;
    } while(next_permutation(all(tempv2)));

    cout<<abs(count1 - count2);
} 

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int task[3];

  int a=scanf("%d %d %d",&task[0],&task[1],&task[2]);

  int i,j;

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(task[i]<task[j]){
        int a=task[i];
        task[i]=task[j];
        task[j]=a;
      }
    }
  }
  /*for(i=0;i<3;i++){
    printf("%d,",task[i]);
  }*/
  int sum;
  sum=(task[1]-task[0])+(task[2]-task[1]);
  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 128
/**
 *    author:  math2do
 *    created: 03.05.2020 00:15:04 IST
**/

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(const char &ch) {
  return "'" + string(1, ch) + "'";
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  reverse(res.begin(), res.end());
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const long long upto = 10000000;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, n;
  cin >> a >> b >> n;
  auto func = [&] (long long x) -> long long {
    return (a * x) / b - a * (x / b);
  };
  long long x = b - 1;
  if (x > n) x = n;
  cout << func(x) << endl;
  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define pb push_back
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define diff(a,b) (a>b?a-b:b-a)
#define F first
#define S second
const int N=1e6+5;
int mod = 1e9+7;
void pairsort(int a[], int b[], int n){
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++) 
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++) 
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll pow1(ll n,ll p)
{
    if(p==0)    return 1;
    ll x=pow1(n, p/2);
    x=(x*x)%mod;
    if(p%2==0)
        return x;
    else
        return (x*n)%mod;
}
ll binarySearch(ll arr[], ll l, ll r,ll x) 
{ 
    if (r >= l) 
    { 
        ll mid = l + (r - l) / 2;  
        if (arr[mid] == x) 
        return mid; 
        if (arr[mid] > x) 
        return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    }
    return -1; 
}
bool compare(const pair<ll, ll>&p1, const pair<ll,ll>&p2)
{
    if(p1.F < p2.F) return true;
        if(p1.F == p2.F) return p1.S < p2.S;
        return false;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
int isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r>n-r) 
        r=n-r;
    long long ans=1;
    for(int i=1;i<=r;i++){
        ans*=n-r+i;
        ans/=i;
    }
    return ans;
}
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

int n;
vector<int>a;
vector<vector<int>>dp;
int game(int start, int end){

	if(start>end)return 0;
    if(dp[start][end]!=-1)return dp[start][end];
	int ans = 0;

	ans = max(a[start]+min(game(start+2, end), game(start+1, end-1)), a[end]+min(game(start, end-2), game(start+1, end-1)));
	return dp[start][end] = ans;
}
int32_t main()
{
    IOS;
    cin>>n;
    a.resize(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    dp.resize(n+1, vector<int>(n+1));
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)dp[i][j] = -1;
    }
    int ans1 = game(1, n);
    int ans2 = min(game(2,n), game(1,n-1));
	cout<<ans1-ans2<<endl;
    return 0;
}


Measured memory_bytes: 70912
#include<iostream>
using namespace std;
int main(){
    string s;
 	cin>>s;
  	if(s[0]=='S'){cout<<"Cloudy"<<endl;}
  	else if(s[0]=='C'){cout<<"Rainy"<<endl;}
	else if(s[0]=='R'){cout<<"Sunny"<<endl;}
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

right_min = [0] * N
tmp = H[-1]

if len(H) == 1:
    print("Yes")
else:
    for i in reversed(range(N)):
        if tmp > H[i]:
            tmp = H[i]
        right_min[i] = tmp
    for i in range(N-1):
        if H[i] - right_min[i+1] > 1:
            print("No")
            exit()
    print("Yes")    

Measured memory_bytes: 14224
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    now = []
    increase_status = 0
    INCREASE = 0
    DECREASE = 1
    NOTDEFINE = 2

    ans = 0
    for a in A:
        if(now):
            if(increase_status == INCREASE):
                if(now<=a):
                    now = a
                else:
                    ans += 1
                    now = a
                    increase_status = NOTDEFINE
            elif(increase_status == DECREASE):
                if(now>=a):
                    now = a
                else:
                    ans += 1
                    now = a
                    increase_status = NOTDEFINE
            else:
                if(now>a):
                    increase_status = DECREASE
                elif(now<a):
                    increase_status = INCREASE
                now = a

        else:
            now = a
            ans += 1
            increase_status = NOTDEFINE
    print(ans)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 17480
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  int point=0;
  cin >> a>>b;
if(a>b){
  point+=a;
  a=a-1;
  
}else{ 
  point+=b;
  b=b-1;
  
}
  
 if(a>b){
  point+=a;
  a=a-1;
  
}else{ 
  point+=b;
  b=b-1;
  
}
cout << point <<endl;

}


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

int main() {
    char C;
    cin >> C;
    printf("%c\n", C+1);

    return 0;
}

Measured memory_bytes: 256
#include 	<ext/pb_ds/assoc_container.hpp> 
#include 	<ext/pb_ds/tree_policy.hpp> 
#include 	<iostream>
#include 	<queue>
#include 	<tuple>
#include 	<vector>
#include	<bits/stdc++.h>
#include	<algorithm>
#include 	<cmath>
#include 	<map>
#include 	<string>
#include 	<iomanip> 
#include 	<ctype.h>
#define 	ll  long long int
#define		read(a) long long int a; cin>>a;
#define 	readstr(s) string s; cin>>s;
#define 	readc(c) char c; cin>>c;
#define 	readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define 	loop(i,a,b) for(ll i=a;i<b;i++)
#define 	rloop(i,a,b) for(ll i=a;i>b;i--)
#define 	loopchar() for(char c='a';c<='z';c++)
#define 	printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define		printv(v) for (int i: v) cout << i << " "; cout << endl;
#define 	loopitr(vec) for(auto itr=vec.begin();itr!=vec.end();itr++)
#define 	ff first
#define 	ss second
#define 	readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define 	all(a) a.begin(), a.end()
#define 	yes cout <<"YES"<<endl;
#define 	no cout <<"NO"<<endl;
#define 	sc(x) cout << (#x) << " is " << (x) << endl;
#define 	fast ios_base::sync_with_stdio(false);cin.tie(0);
#define 	pb(p) push_back(p)
#define 	mp make_pair
#define 	fsort(vec) sort(vec.begin(),vec.end())
#define 	rsort(vec) sort(vec.begin(),vec.end(),compare)
#define 	Endl endl
#define 	ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define 	roundoff std::cout << std::setprecision(15)
#define 	inf 9223372036854775807
#define 	infn -9223372036854775807
#define 	pi 3.14159265358979323846
const 		int mod = 1e9+7; 
#define 	intsize ll size = trunc(log10(num)) + 1
#define 	REVERSE(vec) reverse(vec.begin(),vec.end())
using 		namespace __gnu_pbds; 
using 		namespace std;

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

//code start from here 

int main() {
	fast;
	read(a)
	read(b)
	ll arr[a+1]={0};
	loop(j,1,a+1) cin>>arr[j];
	vector<pair<ll,ll>>vec;
	while(b--){
		read(c)
		read(d)
		vec.pb(mp(c,d));
		vec.pb(mp(d,c));
	}
	fsort(vec);
	map<ll,ll>mp1;
	map<ll,ll>mp2;
	loop(j,0,vec.size()) mp2[vec[j].ff]++;
	loop(j,0,vec.size()){
		if(arr[vec[j].ff]>arr[vec[j].ss]){
			mp1[vec[j].ff]++;
		}
	}
	ll sum=0;
	loop(j,1,a+1){
		if(mp2[j]==mp1[j] && mp2[j]!=0) sum++;
		if(mp2[j]==0) sum++;
	}
	cout<<sum<<endl;
	return 0;
}

//ends here 

Measured memory_bytes: 19516