akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

using vvc = vector<vector<char>>;
using vpii = vector<pair<int, int>>;

vpii next_step(vpii const& step, vvc& a) {
    int const h = a.size(), w = a.front().size();
    int const d[][2] = { -1, 0, 1, 0, 0, -1, 0, 1 };
    vpii r;
    for (auto const& x : step) {
        for (auto const& y : d) {
            int i = x.first + y[0], j = x.second + y[1];
            if (i >= 0 && i < h && j >=0 && j < w && a[i][j] == '.') {
                a[i][j] = '#';
                r.emplace_back(i, j);
            }
        }
    }
    return r;
}

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

    int h, w;
    cin >> h >> w;
    vvc a(h);
    vpii step;

    for (int i = 0; i < h; i++) {
        a[i].resize(w);
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
            if (a[i][j] == '#')
                step.emplace_back(i, j);
        }
    }

    int n = h * w - step.size();
    int ans = 0;
    while (n > 0) {
        ans++;
        step = next_step(step, a);
        n -= step.size();
    }

    cout << ans << '\n';

    return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

	vi v(n), c(n);
	rep(i, 0, n) cin >> v[i];
	rep(i, 0, n) cin >> c[i];

	int ans = 0;
	rep(i, 0, n){
		chmax(ans, ans+v[i]-c[i]);
	}

	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define mod 1000000007

int main() {
  int n, x;
  cin >> n >> x;
  pair<long long, long long> v;
  v.second = x;
  v.first = 0;
  for (int i = 1; i < n; i++) {
    cin >> x;
    v.first = (v.first + (v.second * x) % mod) % mod;
    v.second += x;
    v.second %= mod;
  }
  cout << v.first << endl;
}


Measured memory_bytes: 3608
using System;
class p0003
{
    static void Main(string[] args)
    {
        int cnt = int.Parse(Console.ReadLine());
        while (0 < cnt--)
        {
            int[] intAry = new int[3];
            var ary = Console.ReadLine().Split(' ');

            intAry[0] = (int)Math.Pow(int.Parse(ary[0]), 2);
            intAry[1] = (int)Math.Pow(int.Parse(ary[1]), 2);
            intAry[2] = (int)Math.Pow(int.Parse(ary[2]), 2);
            Array.Sort(intAry);
            Console.WriteLine(intAry[0] + intAry[1] == intAry[2] ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 5592
def main():

    N, M = input_ints()

    A = input_int_list_in_line()

    day = N - sum(A)

    if day < 0:
        print('-1')
    else:
        print(day)


def input_int():
    return int(input())


def input_ints():
    return map(int, input().split())


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int, q: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()


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

#define scd(t) scanf("%d", &t)
#define scld(t) scanf("%ld", &t)
#define sclld(t) scanf("%lld", &t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define scc(t) scanf("%c", &t)
#define scw(t) cin >> t
#define scs(t) getline(cin, t)
#define fori(t) for (int i = 0; i < t; i++)
#define forij(t, p)             \
    for (int i = 0; i < t; i++) \
        for (int j = 0; j < p; j++)
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    int n;
    scd(n);

    int count = 0;
    while(n>=5){
        if(n>=500){
            n-=500;
            count += 1000;
        } else {
            n -= 5;
            count += 5;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import math

N,K = map(int,input().split())
result = 0
N1 = 1.0/N
for i in range(N):
    k = i+1
    cnt = 0
    while(k<K):
        k = k*2
        cnt += 1
    result += math.pow(0.5, cnt)

print(result*N1)

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

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

int main(){
    int i,j,k,l;
    
    int ans = 0;
    
    int n;

    while(cin >> n){
        ans = 0;
    
        for(i=0;i<10;i++){
        
            if(i>n)break;
            for(j=0;j<10;j++){
                    
                    for(k=0;k<10;k++){
                        for(l=0;l<10;l++){
                            if((i+j+k+l)==n){
                                    ans++;
                            }
                        }
                    }
            }
        }
cout << ans << endl;
    }
    
    

    return 0;
}

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

#define MAX 50000

bool is_prime[MAX+1];

void Sieve(){
  fill( is_prime, is_prime + MAX, true );
  is_prime[0] = is_prime[1] = false;
  
  for(int i=0; i<=MAX; i++) {
    if( is_prime[i] ) {
      for(int j=2*i; j<=MAX; j+=i) {
	is_prime[j] = false;
      }
    }
  }
}

int main() {
  int n;

  Sieve();

  while(cin >> n, n) {
    int cnt = 0;
    for(int i=2; i<=n/2; i++) {
      if( is_prime[i] && is_prime[n-i] ) {
	cnt ++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  for (int i=0; i<N; i++) cin >> a[i];
  for (int i=0; i<N; i++) cin >> b[i];
  long long OP = 0, asum = 0, bsum = 0;
  for (int i=0; i<N; i++){
    asum += a[i];
    bsum += b[i];
  }
  OP = bsum-asum;
  long long add1 = 0, add2=0, lstop=0;
  for (int i=0; i<N; i++){
    if (a[i] < b[i]){
      add2 += (b[i]-a[i])/2;
      if ((b[i]-a[i])%2==1) add2++;
    } else if (a[i] > b[i]){
      add1 += (a[i]-b[i])/2;
    }
  }
  lstop=max(add1, add2);
  if (lstop<=OP){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<String> ans = new ArrayList<String>();
		
		while(true){
			int gn = Integer.parseInt(sc.nextLine());
			if(gn == 0) {
				break;
			}
			
			int[][] xy = new int[21][21];
			for(int i=0; i < 21; i++){
				for(int j=0; j < 21; j++){
					xy[i][j] = 0;
				}
			}
			
			for(int i=0; i < gn; i++){
				String[] gp = sc.nextLine().split(" ");
				xy[Integer.parseInt(gp[0])][Integer.parseInt(gp[1])] = 1;
			}
				
			int mn = Integer.parseInt(sc.nextLine());
			String[] mt = new String[mn];
			int[] mc = new int[mn];
					
			for(int i=0; i < mn; i++){
				String[] mp = sc.nextLine().split(" ");
				mt[i] = mp[0];
				mc[i] = Integer.parseInt(mp[1]);
			}
			
			ans.add(run(xy,mt,mc));
		}	
		
		for(int i=0; i < ans.size(); i++){
			System.out.println(ans.get(i));
		}
		sc.close();
	}
	
	
	static String run(int[][] xy,String[] mt,int[] mc){
		int xpoint = 10;
		int ypoint = 10;
		for(int i=0; i < mt.length; i++){
			if(mt[i].equals("N")){
				for(int j=0;  j < mc[i]; j++){
					xy[xpoint][++ypoint] = 0;
				}
		    }else if(mt[i].equals("E")) {
				for(int j=0; j < mc[i]; j++){
					xy[++xpoint][ypoint] = 0;
				}
			}else if(mt[i].equals("S"))	{
				for(int j=0; j < mc[i]; j++){
					xy[xpoint][--ypoint] = 0;
				}
			}else if(mt[i].equals("W")) {
				for(int j=0; j < mc[i]; j++){
					xy[--xpoint][ypoint] = 0;
				}
			}
		}
		return check(xy);
	}
	
	static String check(int[][] xy){
		for(int i=0; i < xy[0].length; i++){
			for(int j=0; j < xy.length; j++){
				if(xy[i][j] == 1) return "No";
			}
		}
		return "Yes";
	}
	
}

Measured memory_bytes: 56884
n,C,*H=map(int,open(0).read().split());p=[0];P=[0]
for i in range(1,n):
 h=H[i];f=lambda I:p[I]+H[I]*(H[I]-2*h)
 while len(P)>1and f(P[0])>f(P[1]):P.pop(0)
 p+=[f(P[0])+h*h+C];h=0
 while len(P)>1and(H[P[-1]]-H[P[-2]])*(f(P[-1])-f(i))>(H[i]-H[P[-1]])*(f(P[-2])-f(P[-1])):P.pop()
 P+=[i]
print(p[-1])

Measured memory_bytes: 27236
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 500050;
const int mod = 1e9+7;
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ans+=n/i*i*(n/i+1)/2; 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3560
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		
		
		Scanner sc = new Scanner(System.in);
		
		int number = Integer.parseInt(sc.next());
		List<Integer> x_numbers = new ArrayList<>();
		List<Integer> y_numbers = new ArrayList<>();
		
		for(int i = 0 ; i< number;i++){
			
			x_numbers.add(Integer.parseInt(sc.next()));
		}
		
		for(int i = 0 ; i< number;i++){
			
			y_numbers.add(Integer.parseInt(sc.next()));
		}
		
		int p = 1;
		double value1  =computeMinkowskiDistance(x_numbers,y_numbers,p);
		System.out.println(String.format("%.6f",value1));
		p = 2;
		double value2  =computeMinkowskiDistance(x_numbers,y_numbers,p);
		System.out.println(String.format("%.6f",value2));
		
		p = 3;
		double value3  =computeMinkowskiDistance(x_numbers,y_numbers,p);
		System.out.println(String.format("%.6f",value3));
		
		p = 10000000;
		double valueInfinite  =computeMinkowskiDistance(x_numbers,y_numbers,p);
		System.out.println(String.format("%.6f",valueInfinite));
		
		
		
		sc.close();
	}

	private static double computeMinkowskiDistance(List<Integer> x_numbers,
			List<Integer> y_numbers, double p) {
		
		if(x_numbers.size() != y_numbers.size()){
			throw new IllegalArgumentException();
		}
		
		double sum = 0.0;
		
		List<Double> x_minus_y_absList = new ArrayList<>();
		for(int i = 0;i<x_numbers.size();i++){
			
			double x_minus_y_abs = Math.abs(x_numbers.get(i) - y_numbers.get(i));
			x_minus_y_absList.add(x_minus_y_abs);
			sum += Math.pow(x_minus_y_abs,p);
		}
		
		if(Double.isInfinite(sum)){
			
			sum = max(x_minus_y_absList);
			return sum;
		}
		
		return Math.pow(sum, 1/p);
	}

	private static double max(List<Double> x_minus_y_absList) {
		
		double ans = 0.0;
		for(int i = 0; i<x_minus_y_absList.size();i++){
			
			if(ans < x_minus_y_absList.get(i)){
				
				ans = x_minus_y_absList.get(i);
				
			}
			
		}
		
		
		return ans;
	}
}



Measured memory_bytes: 26420
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int N;
    cin >> N;
    vector<int> d;
    int D;
    

    for(int i = 0; i < N;i++){
        cin >> D;
        d.push_back(D);
    }
    VSORT(d);

    int foward = d[N/2-1];
    int next = d[N/2];

    if(foward == next) cout << 0 << endl;
    else cout << (next - foward) << endl;




    

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define ld long double
int x[1000], y[1000];
ld dist(int i, int j){
	ld xxx = (x[i] - x[j])*(x[i] - x[j]);
	ld yyy = (y[i] - y[j])*(y[i] - y[j]);
	return sqrt(xxx + yyy);
}
int main(){
	int n;
	cin >> n;
	ld ans = 0;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i!=j)
				ans += dist(i, j);
		}
	}
	cout << fixed << setprecision(9)<< ans / n << '\n';
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;

  map<pii,int> m; // e_ij (i<j) の長さ 
  map<int, ll> dist; // Kからの距離

  for(int i = 0; i < N; i++){
    dist[i] = -1;
  }

  vector<vector<int>> v(N); // 隣接リスト

  for(int i = 0; i < N-1; i++){
    int a,b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    if(a>b) swap(a,b);

    m[make_pair(a,b)] = c;

    v.at(a).push_back(b);
    v.at(b).push_back(a);
  }

  int Q,K;
  cin >> Q >> K;
  K--;
  dist[K] = 0;

  queue<int> q;
  q.push(K);

  // cerr << K << endl;

  while(!q.empty()){
    int now = q.front();
    q.pop();
    for(auto next: v.at(now)){
      if(dist[next] != -1){
        continue;
      } else { 
        int tmp_a,tmp_b;
        tmp_a = min(now,next);
        tmp_b = max(now,next);
        ll tmp_c = m[make_pair(tmp_a, tmp_b)];
        dist[next] = dist[now] + tmp_c;
        q.push(next);
      }
    }
  }

  // answer
  for(int i = 0; i < Q; i++){
    int x,y;
    cin >> x >> y;
    x--; y--;
    cout << dist[x] + dist[y] << endl;
  }
/* 
  for(auto x: dist){
    // cerr << "dist from K to " << x.first << " is " << x.second << endl;
  }
 */

}


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

int main() {
    int N, M; cin >> N >> M;
    vector<long long> X(M);
    for (int i = 0; i < M; ++i) cin >> X[i];
    sort(X.begin(), X.end());
        
    vector<long long> diffs;
    for (int i = 1; i < X.size(); ++i) diffs.push_back(X[i] - X[i-1]);
    sort(diffs.begin(), diffs.end(), greater<long long>());
        
    long long res = X.back() - X[0];
    for (int i = 0; i < min((int)diffs.size(), N-1); ++i) res -= diffs[i];
    cout << res << endl;
}

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

typedef long long ll;

using namespace std;

ll n;

struct segment_tree {
  vector <int> val;
  vector <int> mod;
  segment_tree (int n) {
    val.resize(n << 2, n - 1);
    mod.resize(n << 2, n - 1);
  }
  void push(int v) {
    mod[v * 2] = min(mod[v * 2], mod[v]);
    mod[v * 2 + 1] = min(mod[v * 2 + 1], mod[v]);
  }
  void update(int v, int tl, int tr, int l, int r, int value) {
    if (l > r) return;
    if (l == tl && r == tr) {
      mod[v] = min(mod[v], value);
      val[v] = min(mod[v], value);
      return;
    }
    int tm = (tl + tr) / 2;
    update(v * 2, tl, tm, l, min(r, tm), value);
    update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, value);
    val[v] = min({val[v], val[v * 2], val[v * 2 + 1]});
  }
  int get(int v, int tl, int tr, int l, int r) {
    if (l > r) return n - 1;
    if (l == tl && r == tr)
      return min(val[v], mod[v]);
    push(v);
    int tm = (tl + tr) / 2;
    int x = get(v * 2, tl, tm, l, min(r, tm));
    int y = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    return min(x, y);
  }
};

int main () {
  cin >> n;
  segment_tree se_v(n), se_h(n);
  ll ans = (n - 2) * (n - 2);
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int x;
      cin >> x;
      x--;
      int pos = se_v.get(1, 0, n - 1, x, x);
      ans -= pos - 1;
      se_h.update(1, 0, n - 1, 0, pos - 1, x);
    }
    if (type == 2) {
      int x;
      cin >> x;
      x--;
      int pos = se_h.get(1, 0, n - 1, x, x);
      ans -= pos - 1;
      se_v.update(1, 0, n - 1, 0, pos - 1, x);
    }
  }
  cout << ans;
  return 0;
}


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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  long C1[(N+1)/2+1], C2[N/2+1], max_sum[N/2+1];
  C1[0] = C2[0] = max_sum[0] = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      C1[i/2+1] = C1[i/2] + A[i];
    else
      C2[i/2+1] = C2[i/2] + A[i];
  }
  for (int i = 0; i < N/2; i++)
    max_sum[i+1] = max(max_sum[i] + A[2*i+1], C1[i+1]);
  if (N % 2 == 0) cout << max_sum[N/2] << endl;
  else {
    long max_s = -(1L<<60);
    for (int i = 0; i <= N/2; i++) {
      max_s = max(max_s, max_sum[i] + (C1[N/2+1] - C1[i+1]));
    }
    cout << max_s << endl;
  }
}


Measured memory_bytes: 6720
import sys
from itertools import accumulate

def main():
    
    # sys.stdin = open('input154d.txt')

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    
    s = [0] + p
    s = list(accumulate(s))

    # print(p)
    # print(s)
    maxp = 0
    idx = 0
    for i in range(n - k + 1):
      nowp = s[i + k] - s[i]
      # print(i)
      # print(nowp)
      if maxp < nowp:
        maxp = nowp
        idx = i

    # print(idx)

    sump = 0
    for j in range(idx, idx+k):
      sump += p[j] * (p[j] + 1) / 2 / p[j]

    print(sump)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 25152
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, a, b;
    cin >> n;
    int cnt = 0;
    bool succ = false;
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        if (a == b) {
            cnt += 1;
            if (cnt >= 3)
                succ = true;
        } else {
            cnt = 0;
        }
    }
    cout << (succ ? "Yes" : "No") << endl;
    return 0;
}


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

string shuffle (string str, int h){

    string head = str.substr(0, h);
    string tail = str.substr(h, str.size() - h);

    return tail + head;
}

int  main(){
    string cards;
    int m,h;

    while(1){

        cin >> cards;

        if (cards == "-"){
            break;
        }

        cin >> m;

        for (int i = 0; i < m; i++){

            cin >> h;
            
            cards = shuffle(cards, h);
    
        }

        cout << cards << endl;
    
    }

    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <iomanip>
#include <cassert>

#include <utility>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
using namespace std;

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

constexpr int INF = numeric_limits<int>::max();

void Main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N)
	{
		cin >> a[i];
		--a[i];
	}

	vector<bool> seen(N, false);
	int i = 0;
	int count = 0;
	while (true)
	{
		if (seen[i])
		{
			count = -1;
			break;
		}

		seen[i] = true;

		if (i == 1) break;
		++count;

		i = a[i];
	}

	cout << count << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int l = 0, r = s.size()-1;
    int ans = 0;
    while (l <= r) {
        if (s[l] != s[r]) ans++;
        l++; r--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
if c*2<=a and c*2<=b:
  print(c*2*max(x,y))
  exit()
if c*2<=a:
  print(c*2*x+max(0,b*(y-x)))
  exit()
if c*2<=b:
  print(c*2*y+max(0,a*(x-y)))
  exit()
if c*2>=a+b:
  print(a*x+b*y)
  exit()
if x>=y:
  print(2*c*y+(x-y)*a)
else:
  print(2*c*x+(y-x)*b)

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

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> dn(n);
  for (auto& di : dn) {
    cin >> di;
  }
  sort(dn.begin(), dn.end(), std::greater<int>());
  int total = 1;
  for (int i = 0; i < n; ++i) {
    if (i > 0 && dn[i - 1] > dn[i]) {
      total++;
    }
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 256
r,g,b,n=list(map(int,input().split()))
count=0
for i in range(n//r+1):
  tn = n
  tn = tn - r*i
  
  if tn < 0: break
  if tn == 0:
    #print(i)
    count+=1
    continue
  for j in range(tn//g+1):
    tnn = tn
    tnn -= g*j
    if tnn < 0: break
    if tnn==0:
      #print(i,j)
      count+=1
      continue
    if tnn%b == 0:
      count+=1
      #print(i,j,tn//b)

print(count)

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    set<string> S{};
    rep(i, N) {
        string s;
        cin >> s;

        S.insert(s);
    }
    cout << S.size() << endl;
    return 0;
}


Measured memory_bytes: 19224
def main():
    N, H = map(int, input().split())
    ma = 0
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        ma = max(ma, a)
        B.append(b)
    B.sort(reverse=True)
    ans = 0
    for b in B:
        if 0 >= H:
            print(ans)
            return
        if ma >= b or 0 >= H:
            break
        H -= b
        ans += 1
    if H > 0:
        ans += H // ma
        if H % ma != 0:
            ans += 1
    print(ans)


main()


Measured memory_bytes: 7388
//
// Created by kuribohkute on 20/04/2019.
//
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define mp make_pair
#define X first
#define Y second


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


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
        int n,i,flag=0;
        char a;
        scanf("%d",&n);
        for(i=0;i<n;i++){
                scanf("%c",&a);
                if(a=='Y')flag=1;
        }
        if(flag==0)printf("Three");
        else printf("Four");
        return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
const int MAX = 100000;
bool isPrime[MAX];

int main(void) {
  
  for(int i = 0 ; i < MAX ; i++)
    isPrime[i] = true;
  
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0 ; i < MAX ; i++)
    if(isPrime[i] == true)
      for(int j = i + i ; j < MAX ; j += i)
	isPrime[j] = false;
  
  int input;
  while(scanf("%d", &input) != EOF) {
    for(int i = input - 1 ; i > 0 ; i--)
      if(isPrime[i] == true) { printf("%d ", i); break; }
    
    for(int i = input + 1 ; i < MAX ; i++)
      if(isPrime[i] == true){ printf("%d\n", i); break; }
  } 
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(int argc, char* argv[])
{
  int a[200], n;
  int i, j, w, mini, swc;

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

  swc = 0;
  for(i = 1; i < n; i++){
    mini = i;
    for(j = i; j <= n; j++){
      if(a[j] < a[mini]){
        mini = j;
      }
    }
	if(mini != i){
      w = a[i];
      a[i] = a[mini];
      a[mini] = w;
      swc++;
	}
  }

  for(i = 1; i < n; i++){
    printf("%d ", a[i]);
  }
  printf("%d\n", a[i]);
  printf("%d\n", swc);

  return(0);
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int f(ll N) {
	int ret = 0;
	while (N > 0) {
		ret += N % 10;
		N /= 10;
	}
	return ret;
}
ll tonum(string s) {
	reverse(all(s));
	ll dgt = 1;
	ll ret = 0;
	rep(i, 0, s.size()) {
		ret += dgt * (s[i] - '0');
		dgt *= 10;
	}
	return ret;
}

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

	ll N;
	cin >> N;
	int temp = f(N);
	string S = to_string(N);
	S[0] = S[0] - 1;
	int temp2 = 0;
	for (int i = 1; i < S.size(); i++) {
		S[i] = '9';
	}
	temp2 = f(tonum(S));
	puts(max(temp, temp2));

	
	return 0;
}

Measured memory_bytes: 256
a,b,c=map(int, input().split())
#たこ焼きが余るかの場合分け
if a%b==0:
    Q=a//b
    #ちょうど焼ききる
else:
    Q=a//b+1
    #余る
print(Q*c)#回数×時間
#完了


Measured memory_bytes: 8992
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)
c=gets.split.map(&:to_i)
ans=0
bef=-2
a.each do |i|
  ans+=b[i-1]
  ans+=c[bef] if bef+1 == i-1
  bef=i-1
end
p ans

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    int L, R, d;
    cin >> L >> R >> d;
    if( R < d){
        cout << 0 << endl;
        return;
    }
    int first, last;
    if( L % d == 0){
        first = L / d ;
    }else{
        first = L / d + 1;
    }
    last = R / d;
    cout << last - first + 1  << endl;

}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a,b;
    cin >> a >> b;
    int ans = max({a*b,a+b,a-b});
    cout << ans <<endl;
    return 0;

}

Measured memory_bytes: 896
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(a-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num * pow(den,c-2,c) % c

mod = 10**9+7
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
c = cmb(n-1,k-1,mod)
if k == 1:
    print(0)
    exit()
for i in range(n-k+1):
    ans -= a[i] * c
    ans += a[-i-1] * c
    ans %= mod
    c = (c * (n-k-i) * pow(n-i-1,mod-2,mod)) % mod
if ans < 0:
    ans += mod
print(ans)


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 200010;
int N;
vector<int> X;
vector<int> s,r;

int main(){
	cin >> N;
	X.resize(N);
	s.resize(N);
	r.resize(N);
	repp(i,0,N){
		cin >> X[i];
		s[i] = i;
	}
	sort(s.begin(),s.end(),[&](const int &a , const int &b){return X[a] < X[b];});
	repp(i,0,N) r[s[i]] = i;
	repp(i,0,N) cout << X[s[r[i]<N/2?N/2:(N/2-1)]] << endl;
	return 0;
}


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

int main(){
  int a, b, c, k; cin >> a >> b >> c >> k;
  if(k <= a) cout << k << endl;
  if(k > a && k <= a + b) cout << a << endl;
  if(k > a+b) cout << a-k+a+b << endl;
}

Measured memory_bytes: 3632
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

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

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

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

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	W := readInt()
	H := readInt()
	x := readInt()
	y := readInt()
	printf("%f ", float64(W)*float64(H)/2.0)
	if x*2 == W && y*2 == H {
		println(1)
	} else {
		println(0)
	}
}

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


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int n = s.length();
            int[] dp = new int[n + 1];
            dp[0] = 0;
            for (int i = 0; i < s.length(); ++i) {
                dp[i + 1] = dp[i] ^ (1 << (s.charAt(i) - 'a'));
            }
            Map<Integer, Integer> map = new HashMap<>();
            map.put(0, 0);
            int[] resdp = new int[n + 1];
            Arrays.fill(resdp, Integer.MAX_VALUE);
            resdp[0] = 0;
            for (int i = 0; i < n; ++i) {
                if (map.containsKey(dp[i + 1])) {
                    resdp[i + 1] = map.get(dp[i + 1]) + 1;
                }
                int mask;
                for (int j = 0; j < 26; ++j) {
                    mask = dp[i + 1] ^ (1 << j);
                    if (map.containsKey(mask)) {
                        resdp[i + 1] = Math.min(resdp[i + 1], map.get(mask) + 1);
                    }
                }
                if (map.containsKey(dp[i + 1])) {
                    map.put(dp[i + 1], Math.min(map.get(dp[i + 1]), resdp[i + 1]));
                } else {
                    map.put(dp[i + 1], resdp[i + 1]);
                }
            }

            out.println(resdp[n]);
        }

    }
}



Measured memory_bytes: 103868
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class mint:
    def __init__(self, x):
        self.__x = x % md

    def __str__(self):
        return str(self.__x)

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

md = 10 ** 9 + 7
def main():
    n, m = MI()
    xx = LI()
    yy = LI()
    byi = mint(0)
    byj = mint(0)
    for j in range(m - 1):
        byj += (j + 1) * (m - j - 1) * (yy[j + 1] - yy[j])
    for i in range(n - 1):
        byi += (xx[i + 1] - xx[i]) * (i + 1) * (n - i - 1)
    print(byi * byj)

main()


Measured memory_bytes: 19504
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b,c;
    cin>>a>>b;
    c=a-(b*2);
    c=max(c,0);
    cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const double PI=acos(-1.0);
bool aa[26],ab[26];
int cmp(string a,string b,int lena,int lenb)
{
	int res=0;
	memset(aa,false,sizeof(aa));
	memset(ab,false,sizeof(ab));
	for(int i=0;i<lena;i++)	aa[a[i]-'a']=true;
	for(int i=0;i<lenb;i++)	ab[b[i]-'a']=true;
	for(int i=0;i<26;i++)	res+=(aa[i]&&ab[i]);
	return res;
}
int main()
{
	int n,ans;
	string s,a,b;
	while( cin>>n )
	{
		cin>>s;
		ans=0;
		for(int i=1;i<n;i++)
		{
			a=s.substr(0,i);
			b=s.substr(i,n-i);
			ans=max(ans,cmp(a,b,i,n-i));
		}
		cout<<ans<<endl;
	}
}


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

int main() {
  long double a, b; cin >> a >> b;
  cout << (ll)(a * b) << endl;
  return 0;
}

Measured memory_bytes: 3732
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        long n =int.Parse(System.Console.ReadLine());
        string[] s = System.Console.ReadLine().Split(' ');
        string[] s2 = System.Console.ReadLine().Split(' ');
        long[] a = new long[n+1];
        long[] b = new long[n];
        for(int i=0 ; i<n ; i++){
            a[i] = int.Parse(s[i]);
            b[i] = int.Parse(s2[i]);
        }
        a[n] =int.Parse(s[n]);
        
        long x=0;
        for(int i=0 ; i<n ; i++){
            if(a[i]-b[i]>=0){
                a[i] -= b[i];
                x+=b[i];
                b[i]=0;
            }else{
                b[i] -= a[i];
                x+=a[i];
                a[i]=0;
            }
            if(b[i]>0){
                if(a[i+1]-b[i]>=0){
                    a[i+1] -= b[i];
                    x+=b[i];
                    b[i]=0;
                }else{
                    b[i] -= a[i+1];
                    x+=a[i+1];
                    a[i+1]=0;
                }
            }
        }
        System.Console.WriteLine(x);
    }
}

Measured memory_bytes: 36052
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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; }
int gcd(int a,int b){
	return (a%b==0?b:gcd(b,a%b));
}

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

signed main() {
  INIT;
	VAR(int,n,m);
	VAR(string,s,t);
  int len = n*m/gcd(n,m);

	map<int,char> str;
	bool ok = true;
	REP(ni,n){
		str[ni*len/n] = s[ni];
	}
	
	REP(mi,m){
		if(str.count(mi*len/m)) ok &= str[mi*len/m] == t[mi];
		str[mi*len/m] = t[mi];
	}
	
	OUT(ok?len:-1)BR;
  return 0;
}


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

int main() {
  int n, k, i, j, l[51], dp[55][55];
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> l[i];
  }
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= k; j++) {
      dp[i][0] = 0;
      dp[0][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < k; j++) {
      dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i][j] + l[i]);
    }
  }
  cout << dp[n][k] << "\n";
  return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var k = int.Parse(Console.ReadLine());
            var key = s[k-1];
            
            var ans = "";
            foreach (var c in s) {
               ans += c == key ? c.ToString() : "*";
            }
            
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define setbits(x) (__builtin_popcount(x))
int mod=1000000007;
int INF64=mod*mod+1;

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

	vector<int> d1(n);
	vector<int> d2(n);

	cin>>d1[0]>>d2[0]>>d1[1]>>d2[1];
	bool ans=false;
	for(int i=2;i<n;i++){
		cin>>d1[i]>>d2[i];
		if(d1[i]==d2[i]&&d1[i-1]==d2[i-1]&&d1[i-2]==d2[i-2])
			ans=true;
	}

	if(ans)
		cout<<"Yes";
	else
		cout<<"No";

}

int32_t main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int T;
	// cin>>T;
	T=1;
	for(int i=1;i<=T;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}

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

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

    vector <vector<int>> x_y_a(n);
    for(int i = 0; i < n; i ++){
        int x, y, a;
        cin >> x >> y >> a;
        x_y_a[i].push_back(x);
        x_y_a[i].push_back(y);
        x_y_a[i].push_back(a);
    }
    vector <int> w_black(w, 0), h_black(h, 0);

    for (int i = 0; i < n; i ++){
        int a = x_y_a[i][2];
        if (a == 1){
            for (int j = 0; j < x_y_a[i][0]; j ++){
                w_black[j] = 1;
            }
        }
        else if (a == 2){
            for (int j = w - 1; j >= x_y_a[i][0]; j --){
                w_black[j] = 1;
            }
        }
        else if (a == 3){
            for (int j = 0; j < x_y_a[i][1]; j ++){
                h_black[j] = 1;
            }
        }
        else{
            for (int j = h - 1; j >= x_y_a[i][1]; j --){
                h_black[j] = 1;
            }
        }

    }

    size_t cnt_w, cnt_h;
    cnt_w = count_if(w_black.begin(), w_black.end(),
    [](int i)->bool{return (i == 0);}
    );
    cnt_h = count_if(h_black.begin(), h_black.end(),
    [](int i)->bool{return (i == 0);}
    );
    
    cout << cnt_w * cnt_h << endl;
}

Measured memory_bytes: 3612
a = input()
b = input()
n = max(len(a),len(b))

b = b.zfill(n)
a = a.zfill(n)

for i in range(n):
  if int(a[i])>int(b[i]):
    print("GREATER")
    exit()
  elif int(a[i])<int(b[i]):
    print("LESS")
    exit()

print("EQUAL")


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        private static string FindName(long n)
        {
            long thischar = 0;
            if (n % 26 == 0)
                thischar = 26;
            else
                thischar = n % 26;

            if (n == thischar)
                return ((char)(thischar + 96)).ToString();

            return FindName((n - thischar) / 26) + ((char)(thischar + 96)).ToString();
        }

        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            string res = FindName(n);

            Console.WriteLine(res);
        }


}
}


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

int main(){
    int a, b;
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b" << endl;
    }
    else if(a > b){
        cout << "a > b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

#define MOD 1000000007

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

  vi a(n);
  rep(i, n)
  {
    cin >> a[i];
    a[i]--;
  }

  // ループを求める
  vi arrives(n, -1);
  int now = 0;
  int num = -1;
  int repeat_num, start_pos;
  while(true) {
    num++;
    if (arrives[now] > -1) {
      // 訪れたことがある
      start_pos = now;
      repeat_num = num - arrives[now];
      break;
    }
    arrives[now] = num;
    now = a[now];
  }

  if (k < arrives[start_pos]) {
    now = 0;
    rep(i, k) {
      now = a[now];
    }
  } else {
    k = (k - arrives[start_pos]) % repeat_num;
    rep(i, k) {
      now = a[now];
    }
  }

  cout << (now + 1) << endl;
}


Measured memory_bytes: 4824
#include <cmath>
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
  ll n, b, c;
  c = 0;
  cin >> n;
  if(n%2==0){
  long long d = 0;
  do {
    d++;
    b = (n / (ll) (pow(5, d)*2));
    if (b == 0) {
      break;
    } else {
      c += b;
    }
  } while (true);
  }
  cout << c;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll int>
#define vs vector<string>
#define v vector<int>
#define vd vector<double>
#define mi map<int,int>
#define mc map<char,int>
//ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int a,b,c,d,e;
	cin>>a >>b;
	c=a+b;
	d=a-b;
	e=a*b;
	cout<<max(max(c,d),e) <<"\n";
}


Measured memory_bytes: 3592
n = int(input())
A = [int(input()) for i in range(n)]

ans = 0
for i in range(n):
    m = A[i] // 2
    ans += m
    A[i] -= 2*m
    if i <= n-2 and min(A[i], A[i+1]) == 1:
        ans += 1
        A[i] -= 1
        A[i+1] -= 1
print(ans)

Measured memory_bytes: 50168