akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(void){
        int A, B, ans = 0;
        cin >> A >> B;
        for(int i = 0; i < 2; i++){
                if(A > B) ans += A--;
                else if(B > A) ans += B--;
                else ans += A--;
        }
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int[] a = new int[3];
        for (int i = 0; i < 3; i++) a[i] = sc.NextInt();
        Array.Sort(a);

        int d = a[2] * 2 - a[0] - a[1];
        Console.WriteLine(d / 2 + (d % 2 == 1 ? 2 : 0));
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
import scala.io.StdIn._

object Main extends App {

  val A = Array.fill(3)(readLine().split(" ").map(_.toInt))
  val n = readInt()
  val B = Array.fill(n)(readInt())



  def solve(): String = {
    val r = Array.fill(3, 3)(0)
    for {
      i <- 0 until 3
      j <- 0 until 3
      k <- 0 until n
    } {
      if(A(i)(j) == B(k)) r(i)(j) = 1
    }

    var ans = "No"
    for(i <- 0 until 3) {
      var cnt = 0
      for(j <- 0 until 3)
        cnt += r(i)(j)
      if(cnt == 3) ans = "Yes"
    }
    for(i <- 0 until 3) {
      var cnt = 0
      for(j <- 0 until 3)
        cnt += r(j)(i)
      if(cnt == 3) ans = "Yes"
    }
    {
      var cnt = 0
      for(i <- 0 until 3) {
        cnt += r(i)(i)
        if(cnt == 3) ans = "Yes"
      }
    }
    {
      var cnt = 0
      for(i <- 0 until 3) {
        cnt += r(i)(2-i)
        if(cnt == 3) ans = "Yes"
      }
    }
    ans
  }

  println(solve())

}



Measured memory_bytes: 55032
#include <stdio.h>

long gcd(long a, long b)
{
  long tmp;

  while (b) {
    tmp = b;
    b = a % b;
    a = tmp;
  }

  return a;
}

long lcm(long a, long b)
{
  return a / gcd(a, b) * b;
}

int main(void)
{
  long a, b;

  while (~scanf("%ld %ld", &a, &b)) {
    printf("%ld %ld\n", gcd(a, b), lcm(a, b));
  }

  return 0;
}

Measured memory_bytes: 596
input()
listnum = list(map(int, input().split()))
for i in range(int(input())):
    eachq = list(map(int, input().split()))
    if eachq[0] == 0:
        print(min(listnum[eachq[1]:eachq[2]]))
    elif eachq[0] == 1:
        print(max(listnum[eachq[1]:eachq[2]]))



Measured memory_bytes: 5704
import heapq
N=int(input())
s=set()
q=[0,0]
for a in map(int,input().split()):
    if a>q[0]:
        try:
            s.remove(a)
            heapq.heapreplace(q,a)
        except:
            s.add(a)
print(q[0]*q[1])

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

double pi = 3.14159265359;

int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double ta = pi*(60.0*h+(double)m)/360.0;
    double tb = pi*m/30.0;
    double al = abs(ta-tb);
    double x2 = a*a+b*b-2.0*a*b*cos(al);

    double ans = sqrt(x2);
    printf("%.9lf", ans);

    return 0;
}

Measured memory_bytes: 4192
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

// 入力
int n, W;
int weight[3010], value[3010]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
int dp[3010][3010] = {0}; // テーブルの初期値はすべて 0 にしておきます

// 復元用テーブル
int prev_w[3010][3010];

int main() {
    // 入力受け取り
    cin >> n >> W;
    W--;
    for (int i = 0; i < n; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= W; ++w) {

            // i 番目の品物を選ぶ場合を考える
            if (w >= weight[i]) {
                if (dp[i+1][w] < dp[i][w-weight[i]] + value[i]) {
                    dp[i+1][w] = dp[i][w-weight[i]] + value[i];
                    prev_w[i+1][w] = w - weight[i];
                }
            }

            // i 番目の品物を選ばない場合を考える
            if (dp[i+1][w] < dp[i][w]) {
                dp[i+1][w] = dp[i][w];
                prev_w[i+1][w] = w;
            }
        }
    }

    // 最適値の出力
    //cout << dp[n][W] << endl;


    // 復元
    //cout << "Selected items are..." << endl;
    vector<bool> used(n, false);
    int cur_w = W;
    for (int i = n-1; i >= 0; --i) {
        // 選んでいた場合
        if (prev_w[i+1][cur_w] == cur_w - weight[i]) {
            used[i] = true;
            //cout << i << " th item (weight = " << weight[i] << ", value = " << value[i] << ")" << endl;
        }

        // 復元テーブルをたどる
        cur_w = prev_w[i+1][cur_w];
    }

    int ma = 0;
    for(int i=0; i<n; i++){
        if(!used[i]) ma = max(ma, value[i]);
    }

    cout << dp[n][W] + ma << endl;
    return 0;
}

Measured memory_bytes: 70912
#include <stdio.h>

int main()
{
	long long int a,b,c,d,r,gcd,lcm;
	while(scanf("%llu %llu",&a,&b)!=EOF){
	c=a; d=b; r=1;
	while(r)
	{ r=c%d; c=d; d=r; }
	gcd=c; lcm=a*b/gcd;
	printf("%llu %llu\n",gcd,lcm);
	}
	return 0;
}

Measured memory_bytes: 604
/**
 * @author torith
 * @date 2018-11-02
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    ll l, r;
    for (int i = 0; i < N; ++i) {
        ll T,A;
        cin >> T >> A;

        if(i == 0){
            l = T;
            r = A;
            continue;
        }


        ll a = max((l + (T - 1)) / T, (r + (A - 1)) / A);
        l = a * (ll) T;
        r = a * (ll) A;

    }

    cout << l + r << "\n";

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
      	Set<Integer> num = new HashSet<>();
      	for(int i=0;i<K;i++){
          int di = sc.nextInt();
          for(int j=0;j<di;j++){
            int Ai = sc.nextInt();
            num.add(Ai);
          }
        }
 	      System.out.println(N - num.size());
    }
}

Measured memory_bytes: 47464
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	cout << accumulate(A, A + N, 0) - N << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>	
 
#define f first
#define s second
#define pb push_back
                         	
#define ll long long
 
#define int ll
 
#define ull unsigned long long
 
#define mp make_pair
                          
  
using namespace std;
                       
 
const int inf = 1e9 + 7;
 
const ll ll_inf = 1e18;
const int K = 2e6 + 50;
const int N = 3e5 + 200;
 
const int bl = 320;
 
const int ep = 1e-7;
 
const int pro = 31;
 
const double pi = 3.141592653589793238462643;
                                         
ll binpow (ll a, ll n)
{
	if(n == 0)
		return 1ll;           
    ll res = 1;
    while (n) {
        if (n & 1)                                          
        {
            res *= a;
            res %= inf;
        }      	
        a *= a;
        n >>= 1;
        a %= inf;
    }                          
    return res;
}   
          
  
 
void boost()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);                                        
}
 
void fr()
{
    freopen("road-to-work.in","r",stdin);
    freopen("road-to-work.out","w",stdout);
}

 
void solve() 
{
	int n;           	
	cin >> n;
	if (n < 600)
	{
		cout << 8;
	}	
	else if (n < 800)
	{
		cout << 7;
	}
	else if (n < 1000)
	{
		cout << 6;
	}
	else if (n < 1200)
	{
		cout << 5;
	}
	else if (n < 1400)
	{
		cout << 4;
	}
	else if (n < 1600)
	{
	  	cout << 3;
	}
	else if (n < 1800)
	{
		cout << 2;
	}
	else
	{
		cout << 1;
	}              
}   	                        	
 
main()
{
	//boost();
	int q = 1;
	//cin >> q;
	while(q--)
	{
		solve();
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

int cous(int a) {
	int ret = 0;
	while (a) {
		ret += a % 10;
		a /= 10;
	}
	return ret;
}


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

	vector<pii> ku(n);
	multiset<pii, greater<pii>> lt,ltb;
	multiset<pii> rt,rtb;
	REP(i, n) {
		int l, r;
		scanf("%d %d", &ku[i].first, &ku[i].second);
		lt.insert({ku[i].first,ku[i].second});
		rt.insert({ ku[i].second,ku[i].first});
	}

	
	ll ans = 0;
	{
		ll k = 0;
		bool cp = true;
		ltb = lt;
		rtb = rt;
		int pp = 0;
		REP(i, n) {
			if (cp) {
				pii cur = *lt.begin();

				if (cur.first > pp || cur.second < pp) {

					k += cur.first - pp;
					pp = cur.first;
				}

				lt.erase(lt.find(cur));
				rt.erase(rt.find({ cur.second,cur.first }));
			}
			else {
				pii cur = *rt.begin();
				swap(cur.first, cur.second);
				if (cur.first > pp || cur.second < pp) {

					k += pp - cur.second;
					pp = cur.second;
				}

				lt.erase(lt.find(cur));
				rt.erase(rt.find({ cur.second,cur.first }));
			}
			cp = !cp;
		}

		ans = k + abs(pp);
	}


	{
		ll k = 0;
		bool cp = false;
		lt = ltb;
		rt = rtb;
		int pp = 0;
		REP(i, n) {
			if (cp) {
				pii cur = *lt.begin();

				if (cur.first > pp || cur.second < pp) {

					k += cur.first - pp;
					pp = cur.first;
				}

				lt.erase(lt.find(cur));
				rt.erase(rt.find({ cur.second,cur.first }));
			}
			else {
				pii cur = *rt.begin();
				swap(cur.first, cur.second);
				if (cur.first > pp || cur.second < pp) {

					k += pp - cur.second;
					pp = cur.second;
				}

				lt.erase(lt.find(cur));
				rt.erase(rt.find({ cur.second,cur.first }));
			}
			cp = !cp;
		}
		ans = max(ans, k + abs(pp));
	}

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


Measured memory_bytes: 19840
#include <stdio.h>
 
#define PutChar(c) ; *p = (char)(c); ++p;
 
#define MAX_N (2000001)
#define MAX_Ai (10001)
#define STR_SIZE (10000010)
 
int getNum(void);
void putNum(int n);
void CountingSort(int A[], int B[], int k, int len);
 
int A[MAX_N];
int B[MAX_N];
char str[STR_SIZE];
char *p = str;
 
int main(void) {
    register int i;
    int n;
 
    fread(str, 1, STR_SIZE, stdin);
     
    n = getNum();
    for (i = 1; i <= n; ++i) {
        A[i] = getNum();
    }
     
    CountingSort(A, B, MAX_Ai, n);
     
    p = str;
    --n;
    for (i = 1; i <= n; ++i) {
        putNum(B[i]);
        PutChar(' ');
    }
    putNum(B[i]);
    PutChar('\0');
     
    puts(str);
     
    return 0;
}
 
int getNum(void) {
    int n = 0;
    while ((*p >= '0') && (*p <= '9')) {
        n = n * 10 + (int)(*p - '0');
        ++p;
    }
    ++p;
    return n;
}
 
void putNum(int n) {
    int d;
    if (n < 10) {
        PutChar('0' + n);
        return;
    }
    d = n / 10;
    if (d) putNum(d);
    PutChar('0' + (n - (d * 10)));
}
 
void CountingSort(int A[], int B[], int k, int len) {
    int C[MAX_Ai] = { 0 };
    int i, j;
    for (j = 1; j <= len; ++j) {
        ++C[A[j]];
    }
    for (i = 1; i <= k; ++i) {
        C[i] += C[i - 1];
    }
    for (j = len; j > 0; --j) {
        B[C[A[j]]] = A[j];
        --C[A[j]];
    }
}

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

typedef long long LL;

const int N=200000,C=20;

int n,m,a[N+9];

void into(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i){
	scanf("%d",&a[i]);
	++a[i];
  }
}

int mx[N+9][C],mn[N+9][C],lg[N+9];

void Get_mxn(){
  for (int i=2;i<=n;++i) lg[i]=lg[i>>1]+1;
  for (int i=1;i<=n;++i) mx[i][0]=mn[i][0]=a[i];
  for (int i=1;i<C;++i)
    for (int j=1;j+(1<<i)-1<=n;++j){
	  mx[j][i]=max(mx[j][i-1],mx[j+(1<<i-1)][i-1]);
	  mn[j][i]=min(mn[j][i-1],mn[j+(1<<i-1)][i-1]);
	}
}

int Query_max(int l,int r){int len=lg[r-l+1];return max(mx[l][len],mx[r-(1<<len)+1][len]);}
int Query_min(int l,int r){int len=lg[r-l+1];return min(mn[l][len],mn[r-(1<<len)+1][len]);}

int cnt[N+9];

void Get_cnt(){
  for (int i=1;i<=n;++i) cnt[i]=a[i-1]<a[i]?cnt[i-1]+1:1;
}

int ans;

void Get_ans(){
  int flag=0;
  for (int i=1;i+m-1<=n;++i){
	if (cnt[i+m-1]>=m) {flag=1;continue;}
	if (i==1) {++ans;continue;}
	int x=Query_min(i,i+m-2),y=Query_max(i,i+m-2);
	ans+=a[i-1]>x||a[i+m-1]<y;
  }
  ans+=flag;
}

void work(){
  Get_mxn();
  Get_cnt();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 37356
package main

import "fmt"

func main() {
	var n, totalTime int //cost num, total time
	tmpNums := scanNums(2)
	n = tmpNums[0]
	totalTime = tmpNums[1]

	var minCost = 2000
	for i := 0; i < n; i++ {
		var c, t int
		tmpNums := scanNums(2)
		c = tmpNums[0]
		t = tmpNums[1]
		if t <= totalTime && c < minCost {
			minCost = c
		}
	}

	if minCost < 2000 {
		fmt.Printf("%d\n", minCost)
	} else {
		fmt.Printf("TLE")
	}
}

/**
 * １行に空白区切りで数字を読み込み
 */
func scanNums(len int) (nums []int) {
	nums = make([]int, len)
	for i := 0; i < len; i++ {
		fmt.Scan(&nums[i])
	}
	return
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  string a="ABC", b="ARC";
  string s; cin >> s;
  if(s==a) cout << b << endl;
  else cout << a << endl;


}

Measured memory_bytes: 3524
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n;
  cin>>n;
  vi a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  int sum=a[n-1]/2;
  for(int i=0;i<n-1;i++){
    sum+=a[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0

output:
4
"""
import sys


def solve():
    dp = [[0] * W for _ in range(H)]
    max_width = 0
    for m in range(H):
        for n in range(W):
            dp[m][n] = (int(carpet_info[m][n]) + 1) % 2
            max_width |= dp[m][n]

    for i in range(1, H):
        for j in range(1, W):
            if not int(carpet_info[i][j]):
                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
                max_width = max(max_width, dp[i][j])
                
    return pow(max_width, 2)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    H, W = map(int, _input[0].split())
    carpet_info = list(map(lambda x: x.split(), _input[1:]))
    print(solve())

Measured memory_bytes: 60296
#include <iostream>
#include <math.h>
#include <cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  int p = n;
  int q = 0;
  for (int i = 0; i < 3; i++){
    q += (n % 10)*pow(10, abs(i - 2));
    n /= 10;
  }
  if (p == q){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;


void solve(){
	int a,b;
	char c;
	cin >> a >> c >> b;
	if(c == '+') cout << a+b<<endl;
	else cout << a-b<<endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

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

int main() {

    long long H, W;

    cin >> H >> W;

    long long ans;

    if(W == 1 || H == 1) {
        cout << 1 << endl;
        return 0;
    }

    if(H % 2 == 0) {
        ans = H * W;
        ans /= 2;
    }
    else {
        ans = W * (H / 2);
        ans += W / 2 + W % 2;

    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>


int fpow(int b, int i, int m) {
	int r = 1;
	for (; i; i >>= 1, b = b * 1LL * b % m)
		if (i & 1) r = r * 1LL * b % m;
	return r;
}

const int N = 2e6 + 100;
const int M = 1e9 + 7;
int X[6], Y[6];
long long ans;
long long fac[N], ifac[N];

long long num(int x, int y) {
	//fprintf(stderr, "%d %d\n", x, y);
	return fac[x + y] * 1LL * ifac[x] % M * ifac[y] % M;
}

int numPath0(int x, int y) {
	//fprintf(stderr, "0: %d %d\n", x, y);
	long long ret = 0;
	ret += num(x - X[1], y - Y[1]);
	ret += num(x - X[0] + 1, y - Y[0] + 1);
	ret -= num(x - X[0] + 1, y - Y[1]);
	ret -= num(x - X[1], y - Y[0] + 1);
	return ((ret % M) + M) % M;
}

int numPath1(int x, int y) {
	//fprintf(stderr, "1: %d %d\n", x, y);
	long long ret = 0;
	ret += num(X[4] - x, Y[4] - y);
	ret += num(X[5] - x + 1, Y[5] - y + 1);
	ret -= num(X[4] - x, Y[5] - y + 1);
	ret -= num(X[5] - x + 1, Y[4] - y);
	return ((ret % M) + M) % M;
}


int main() {
#ifdef lol
	freopen("e.in", "r", stdin);
	freopen("e.out", "w", stdout);
#endif

	fac[0] = 1;
	for (int i = 1; i < N; ++i)
		fac[i] = 1LL * fac[i - 1] * i % M;
	ifac[N - 1] = fpow(fac[N - 1], M - 2, M);
	for (int i = N - 2; 0 <= i; --i)
		ifac[i] = ifac[i + 1] * 1LL * (i + 1) % M;

	for (int i = 0; i < 6; ++i)
		scanf("%d", X + i);
	for (int i = 0; i < 6; ++i)
		scanf("%d", Y + i);

	ans = 0;
	for (int i = X[2]; i <= X[3]; ++i) {
		(ans += 1LL * (M - (i + Y[2])) * numPath0(i, Y[2] - 1) % M * numPath1(i, Y[2]) % M) %= M;
		(ans += 1LL * (i + Y[3] + 1) * numPath0(i, Y[3]) % M * numPath1(i, Y[3] + 1) % M) %= M;
	}
	for (int i = Y[2]; i <= Y[3]; ++i) {
		(ans += 1LL * (M - (i + X[2])) * numPath0(X[2] - 1, i) % M * numPath1(X[2], i) % M) %= M;
		(ans += 1LL * (i + X[3] + 1) * numPath0(X[3], i) % M * numPath1(X[3] + 1, i) % M) %= M;
	}
	printf("%lld\n", ans);

	return 0;
}

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

int n, D, f[501000], g[501000], d[501000], Q;

int main(void) {
  scanf("%d%d", &n, &D);
  f[0] = D;
  for(int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    f[i] = min(f[i - 1], abs(f[i - 1] - x));
    d[i] = x;
  }

  g[n] = 1;
  for(int i = n - 1; i >= 1; i--) {
    if(g[i + 1] <= d[i + 1] / 2)
      g[i] = g[i + 1];
    else g[i] = d[i + 1] + g[i + 1];
    if(g[i] > 1e9) g[i] = 1e9 + 1;
  }

  scanf("%d", &Q);
  while(Q--) {
    int x;
    scanf("%d", &x);
    puts(f[x - 1] >= g[x] ? "YES" : "NO");
  }
  return 0;
}


Measured memory_bytes: 7808
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

#define ll long long
using namespace std;
const int N = 110;
int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b)) printf("A\n");
    else printf("B\n");
    return 0;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

int n, q;
string s;
vector<pair<char, char>> querys;

int simulation(int golem){
    rep(i, q){
        char t = querys[i].first, d = querys[i].second;
        if(s[golem] == t){
            if(d == 'L') -- golem;
            else ++ golem;
        }
    }

    return golem;
}

int search(int left, int right, int control){
    while(left < right){
        int result = simulation((left + right) / 2 + 1);
        if(control == 0){
            if(result < 0) left = (left + right) / 2 + 1;
            else right = (left + right) / 2;
        }else{
            if(result >= n) right = (left + right) / 2;
            else left = (left + right) / 2 + 1;
        }
    }

    return left;
}

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

    cin >> n >> q >> s;
    rep(i, q){
        char t, d;
        cin >> t >> d;
        querys.emplace_back(t, d);
    }

    cout << search(0, n - 1, 1) - search(0, n - 1, 0) << endl;
}

Measured memory_bytes: 1100
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    string s;
    int n, aux = 0, rta = 0;
    cin >> n;
    int h[n];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < n; i++){
        if(h[i] > aux) aux = h[i];
        if(aux == h[i]) rta++;
    }
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3572
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    X, N= list(map(int, _in[0].split(' ')))  # type:list(int)
    try:
        p_arr = list(map(int, _in[1].split(' ')))  # type:list(int)
    except:
        p_arr = []
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = float('inf')
    memo = None

    abs_ = 0
    while True:
        if X-abs_ not in p_arr:
            ans = X-abs_
            break
        if X+abs_ not in p_arr:
            ans = X+abs_
            break
        abs_ += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61792
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){

  int N; cin >> N;
  vector <int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  vector <int> ans;
  ans.push_back(A[N - 1]);


  for (int i = N - 2; i >= 0; i--){
    int T = A[i];

    if (ans[ans.size() - 1] <= T){
      ans.push_back(T);
    }else{
      int L = 0, R = ans.size() - 1;

      bool flag = true;      

      while (flag == true){
        int now = (L + R) / 2;

        if (T < ans[now]) R = now;
        else L = now;

        if (now == (L + R) / 2){
          if (T < ans[L]) ans[L] = T;
          else ans[R] = T;

          break;
        }
      }
    }

  }

  cout << ans.size() << endl;
  return 0;
}


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

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

  int64_t N;
  cin >> N;

  string c(N, 'a');
  cin >> c;

  int64_t cnt = 0;

  int64_t j = N - 1;
  int64_t i = 0;

  while (i < j and j >= 0 and i <= N - 1) {
    if (c.at(i) == 'W' and c.at(j) == 'W') {
      j--;
    }
    else if (c.at(i) == 'W' and c.at(j) == 'R') {
      i++;
      j--;
      cnt++;
    }
    else if (c.at(i) == 'R' and c.at(j) == 'W') {
      i++;
      j--;
    }
    else if (c.at(i) == 'R' and c.at(j) == 'R') {
      i++;
    }
  }
  cout << cnt;

  return 0;
}


Measured memory_bytes: 3616
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while b > 0:
        a, b = b, a % b
    return a

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0] * (n+1)
for i in range(n):
    b[i+1] = gcd(b[i], a[i])
if (k <= max(a)) & (k >= min(a)):
    if k % b[-1] == 0:
        ans = "POSSIBLE"
    else:
        ans = "IMPOSSIBLE"
else:
    ans = "IMPOSSIBLE"
print(ans)

Measured memory_bytes: 14108
from collections import deque;h,w,k=map(int,input().split());m=[input()for _ in[0]*h];v=[[-1]*w for _ in[0]*h];r=9**20
for i in range(h):
 if'S'in m[i]:j=m[i].index('S');q=deque([[i,j]]);v[i][j]=0
while q:
 y,x=q.popleft()
 r=min(r,y,x,h-1-y,w-1-x)
 for i,j in([1,0],[-1,0],[0,1],[0,-1]):
  t,u=y+i,x+j
  if t>=0and t<h and u>=0and u<w and m[t][u]=='.'and v[t][u]<0and v[y][x]<k:v[t][u]=v[y][x]+1;q.append([t,u])
print(1-(-r//k))

Measured memory_bytes: 58972
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);++i)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

int main(){
	string s; cin>>s;
	rp(i,s.size()){
		for(int j=i+1; j<s.size(); ++j){
			if(s[i]==s[j]){
				ote("no");
				return 0;
			}
		}
	}
	ote("yes");
}


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

using namespace std;

typedef long long ll;

const int MOD = int(1e9+7);

int main()
{
	string s;
	cin >> s;
	if (s[2]==s[3] && s[4]==s[5])
	{
		cout << "Yes";
	}
	else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string a,b;
    cin >> a >> b;
    int c = stoi(a+b);
    rep2(i,1,1000) {
        if(i*i == c) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

int a[200010], p[200010];
int main()
{
    int64_t n, k;
    cin>>n>>k;
    for(int i=1; i<=n; ++i) cin>>a[i];

    int i=1;
    if (k>2*n) for(int f=0, x=1; !f; ++x) {
        if (p[i]) {
            int c=x-p[i];
            k-=x;
            k%=c;
            f=1;
        }
        p[i]=x;
        i=a[i];
    }
    for(; k>0; --k, i=a[i]);
    cout<<i<<endl;
}


Measured memory_bytes: 5180
#!/usr/bin/env python3
# coding=utf-8

import sys

s = sys.stdin.readline().strip()
check = [_s is "1" for _s in list(s)]
index = 0
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
    if curr ^ next:
        index = max(index, i + 1)
check = check[::-1]
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
    if curr ^ next:
        index = max(index, i + 1)
print(len(s) - index)


Measured memory_bytes: 4852
// compile option: g++ -std=c++11
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  int sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  set<int> cand;  // 答えの候補(\sum{a}の約数)
  for (int i = 1; i * i <= sum; ++i) {
    if (sum % i == 0) {
      cand.insert(i);
      cand.insert(sum / i);
    }
  }
  int ans = 0;
  for (auto x : cand) {
    vector<int> r(n);  // a_1, ..., a_n をxで割ったあまり r_1, ..., r_n
    REP(i, n) r[i] = a[i] % x;
    sort(ALL(r));
    // 0 <= r_i < x
    // ソート済みの各rのうち，小さいものを0に，大きいものをxにするように操作する
    // 境界lを設定し，0~l-1のrは0にするため値を減らし，l~n-1のrはxにするため値を増やす
    int sum_r = 0;
    REP(i, n) sum_r += r[i];
    int l = n - (sum_r / x);
    int need = 0;  // aの全要素をxにするのに必要な最小操作回数
    REP(i, l) need += r[i];
    if (need <= k) ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,d,e,f,g,h,n,m,k,t;
string s;
char ch;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    cin>>s;
    map<char,ll>mm;
    for(int i=0;i<n;i++){
        mm[s[i]]++;
    }
    ll ans=1;
    for(auto it=mm.begin();it!=mm.end();it++){
        ans=ans*(it->second+1)%1000000007;
    }
    ans--;
    cout<<ans<<endl;
    return 0;
}

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

int main(int argc, const char * argv[]) {
    int n, x[100], y[100];
    double t = 0, d = 0, d1 = 0, d2 = 0, d3 = 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &x[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%d", &y[i]);
    }
    
    for(int i=0; i<n; i++){
        t = fabs(x[i]-y[i]*1.0);
        if(t > d){
            d = t;
        }
        d1 += t;
        d2 += t*t;
        d3 += t*t*t;
    }
    printf("%.6lf\n", d1);
    printf("%.6lf\n", sqrt((double)d2));
    printf("%.6lf\n", pow((double)d3, 1.0/3));
    printf("%.6lf\n", d);
    return 0;
}



Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  
  rep(i,(int)s.size()){
    string ss = s.substr(i,5);
    if(ss == "dream" || ss == "erase"){
      i += 4;
      if(i >= (int)s.size()) break;
      if(i+2 < (int)s.size()){
        bool flag = false;
        if(i+3 < (int)s.size()){
          flag = s[i+3] != 'a';
        }
        if(ss == "dream" && s[i+1] == 'e' && s[i+2] == 'r' && s[i+3] != 'a'){
          i+=2;
        }
      }
      if(ss == "erase" &&  s[i+1] == 'r') i++;
    }else{
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
	return 0;
}


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

int main() {
    int n, min = 1000000, max = -1000000;
    long long sum = 0;
    cin >> n;

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

        if (min > a) {
            min = a;
        }
        if (max < a) {
            max = a;
        }
        sum += a;
    }

    printf("%d %d %lld\n", min, max, sum);

    return 0;
}


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

int h,m,s,c,t;

int main(){
	while(~scanf("%d%d%d",&h,&m,&s)){
		if(h==-1)break;
		
		if(s==0){
			s=0;
			c=0;
		}else{
			s=60-s;
			c=1;
		}
		
		if(m==0 && c==0){
			m=0;
		}else{
			m=60-c-m;
			c=1;
		}
		
		if(h==0 && c==0){
			h=2;
		}else{
			h=2-c-h;
		}
		printf("%02d:%02d:%02d\n",h,m,s);
		t=3*s;
		s=(3*s)%60;
		c=t/60;
		t=3*m;
		m=(3*m+c)%60;
		c=t/60;
		h=3*h+c;
		printf("%02d:%02d:%02d\n",h,m,s);
	}
	return 0;
}

Measured memory_bytes: 0
using System;

namespace ConsoleApp34
{
    class Program
    {
        private static char[] c;
        static void Main(string[] args)
        {
            
             var str = Console.ReadLine();
            c = str.ToCharArray();
            if (char.IsLower(c[0]))
            {
                Console.WriteLine("a");
            }
            else
            {
                Console.WriteLine("A");
            }
        }
    }
}


Measured memory_bytes: 25872
# 2019-11-25 15:34:15(JST)
import sys
def main():
    x, y = map(int, sys.stdin.readline().split())
    
    if y == 0:
        if x > 0:
            ans = x + 1
        else:
            ans = -x
    elif y > 0:
        if x > y:
            ans = x - y + 2
        elif x >= 0:
            ans = y - x
        else:
            ans = abs(y + x) + 1
    else:
        if x >= 0:
            ans = abs(y + x) + 1
        elif x > y:
            ans = x - y + 2
        else:
            ans = y - x
    
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

const long long INF = 1LL << 60;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long h[110000];
    long long dp[110000];
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    rep(i,N) {
        rep2(j,K+1) chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }

    // 答え
    cout << dp[N-1] << endl;
    return 0;
}

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

void solve() {
	string a, b, res; cin >> a >> b;
	int n = a.size(), m = b.size();
	vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			if (a[i] == b[j]) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
			}
		}
	}
	int i = n, j = m;
	while (i > 0 and j > 0) {
		if (dp[i][j] > dp[i - 1][j] and dp[i - 1][j] == dp[i][j - 1]) {
			i--; j--;
			res = a[i] + res;
		} else if (dp[i - 1][j] > dp[i][j - 1]) {
			i--;
		} else {
			j--;
		}
	}
	cout << res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}


Measured memory_bytes: 70784
#include<stdio.h>
int main()
{
    int a,b,c,k,i,big;
    scanf("%d%d%d",&a,&b,&c);
    scanf("%d",&k);
    if(k>=1&&k<=10&&a>=1&&a<=50&&b>=1&&b<=50&&c>=1&&c<=50)
    {
        if(a>b&&a>c)
        {
            big=a;
            a=0;
        }
        else if(b>a&&b>c)
        {
            big=b;
            b=0;
        }
        else if(c>a&&c>b)
        {
            big=c;
            c=0;
        }
        else if(a==b&&b==c&&c==a)
        {
            big=a;
            a=0;
        }
        else if(a==b&&a>c)
        {
            big=a;
            a=0;
        }
        else if(a==c&&a>b)
        {
            big=a;
            a=0;
        }
        else if(c==b&&c>a)
        {
            big=c;
            c=0;
        }
        for(i=0; i<k; i++)
        {
            big=big+big;
        }
        printf("%d\n",big+a+b+c);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll MOD = (ll)1e9 + 7;
    string s; cin >> s;
    int n = s.length();
    vector<vector<ll>> dp(n + 1, vector<ll>(4)), tmp(3, vector<ll>(4));
    dp[0][0] = 1;
    rep (i, s.length()) {
        if (s[i] == '?') {
            dp[i + 1][0] = 3 * dp[i][0] % MOD;
            rep (k, 3) {
                rep (j, 3) {
                    dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j + 1] + (k == j ? dp[i][j] : 0)) % MOD;
                }
            }
        } else {
            dp[i + 1][0] = dp[i][0];
            rep (j, 3) {
                dp[i + 1][j + 1] = (dp[i][j + 1] + (s[i] == (char)('A' + j) ? dp[i][j] : 0)) % MOD;
            }
        }
    }
    cout << dp[n][3] << "\n";
    rep (i, n + 1) eprintf("%3lld %3lld %3lld %3lld\n", dp[i][0], dp[i][1], dp[i][2], dp[i][3]);
    return 0;
}

Measured memory_bytes: 10332
#include<iostream>
int main() {
	int vec=0;
	int n;
	int a=0;
	int b=0;
	int game_a, game_b;
	while (1) {
		std::cin >> n;
		if (n == 0)break;
		else {
			for (int i = 0; i < n; ++i) {
				std::cin >> game_a>>game_b;
				if (game_a == game_b) { a += game_a; b += game_b; }
				else if (game_a > game_b)a += game_a + game_b;
				else b += game_a + game_b;
			}
			std::cout << a << " " << b << std::endl; a = 0; b = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3004
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 X=sc.nextInt();
		int Y=sc.nextInt();
		
		if(K>N){
			System.out.println(N*X);
		}else{
		System.out.println((K*X)+((N-K)*Y));
		}
}
}

Measured memory_bytes: 10068
D, G = gets.chomp.split.map(&:to_i)

problem_count = []
bonus_list = []

D.times do
  p, c = gets.chomp.split.map(&:to_i)

  problem_count << p
  bonus_list << c
end

ans = Float::INFINITY

(0...(1 << D)).each do |mask|
  s = num = 0
  rest_max = -1

  (0...D).each do |i|
    if (mask >> i & 1) == 1
      s += 100 * (i + 1) * problem_count[i] + bonus_list[i]
      num += problem_count[i]
    else 
      rest_max = i
    end
  end

  if s < G
    s1 = 100 * (rest_max + 1)
    need = (G - s + s1 - 1) / s1
    next if need >= problem_count[rest_max]
    num += need
  end

  ans = [ans, num].min
end

puts ans


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

void Umn(auto &x,auto y){
    x=min(x,y);
}

ll n, a[555][555], s1[555][555], s2[555][555], f[555][555], g[555][555], inf=1e15;

int main(){
    cin>>n;
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j){
            if (i!=j) cin>>a[i][j];
            s1[i][j]=s1[i][j-1]+a[i][j];
            s2[i][j]=s2[i-1][j]+a[i][j];
        }
    memset(f,33,sizeof f);
    f[0][0]=0;
    for (int w=1;w<=n;++w){
        memset(g,33,sizeof g);
        for (int i=0;i<=n;++i)
            for (int j=0;j<=n;++j)
                if (f[i][j]<inf){
                    Umn(g[i][j],f[i][j]+s2[w-1][w]-s2[i][w]+s1[w][j]);
                    Umn(g[w-1][i],f[i][j]+s1[w][i]);
                }
        memcpy(f,g,sizeof f);
    }
    ll ans=inf;
    for (int i=0;i<=n;++i)
        for (int j=0;j<=n;++j)
            Umn(ans,f[i][j]);
    cout<<ans<<endl;
}

Measured memory_bytes: 12032
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    alist = list(map(int, input().split()))
    aset = set(alist)
    print('YES' if len(alist) == len(aset) else 'NO')


if __name__ == '__main__':
    main()


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

void toLowerCase(string& tar) {
    for (int i = 0; i < tar.length(); ++i) {
        tar[i] = (char) tolower(tar[i]);
    }
}

int main() {
//    freopen("in.txt", "r", stdin);

    string tar, tmp;
    int sum = 0;
    cin >> tar;
    toLowerCase(tar);

    while (1) {
        cin >> tmp;
        if (tmp != "END_OF_TEXT") {
            toLowerCase(tmp);
            if (tmp == tar) {
                ++sum;
            }
        } else {
            cout << sum << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3176
T = input()
ans = 0

if T[0] == "?":
    if len(T) == 1:
        ans = "D"
    elif T[1] == "D":
        ans = "P"
    else:
        ans = "D"
else:
    ans = T[0]

for i in range(len(T)-2):
    if T[i+1] == "?":
        if ans[i]  == "P":
            ans += "D"
        else:
            if T[i+2] == "P":
                ans += "D"
            else:
                ans += "P"
    else:
        ans += T[i+1]

if len(T) > 1:
    if T[-1] == "?":
        ans += "D"
    else:
        ans += T[-1]
            
print(ans)

Measured memory_bytes: 9536
//***Little by little one travels far***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main()
{
    ll n;
    cin>>n;
    if(n%2!=0){
        cout<<"0";
        return 0;
    }
    n=n/2;
    ll b=n,c=0;
    for(ll i=1;i<=27;i++){
        ll p=c;
        c+=(n/((ll)(pow((ll)5,i)+0.5)));
       // cout<<c-p<<" ";
    }
    for(ll i=1;i<=61;i++){
        b+=(n/((ll)(pow((ll)2,i)+0.5)));
    }
    //cout<<b<<" "<<c<<endl;
    cout<<min(b,c);
}

Measured memory_bytes: 256