akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  if (sy == ty) {
    rep(i,tx-sx) {
      cout << 'R';
    }
    cout << 'D';
    rep(i,tx-sx) {
      cout << 'L';
    }
    cout << "UU";
    rep(i,tx-sx) {
      cout << 'R';
    }
    cout << "DRDD";
    rep(i,tx-sx) {
      cout << 'L';
    }
    cout << "UUR\n";
    return 0;
  }
  if (sx == tx) {
    rep(i,ty-sy) {
      cout << 'U';
    }
    cout << 'R';
    rep(i,ty-sy) {
      cout << 'D';
    }
    cout << "LL";
    rep(i,ty-sy) {
      cout << 'U';
    }
    cout << "RURR";
    rep(i,ty-sy) {
      cout << 'D';
    }
    cout << "LLU\n";
    return 0;
  }
  string s_to_g = "", g_to_s = "";
  rep(i,ty-sy) {
    cout << 'U';
    s_to_g += 'U';
  }
  rep(i,tx-sx) {
    cout << 'R';
    s_to_g += 'R';
  }
  rep(i,ty-sy) {
    cout << 'D';
    g_to_s += 'D';
  }
  rep(i,tx-sx) {
    cout << 'L';
    g_to_s += 'L';
  }
  cout << "LU" + s_to_g + "RD";
  cout << "RD" + g_to_s + "LU\n";
  return 0;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  int N;

  void init() {
    cin >> N;
  }

  void solve() {
    REPC(i, 1, 3500) REPC(j, 1, 3500) {
      ll h = i, n = j;
      ll denom = 4*h*n-N*n-N*h;
      if(denom == 0 || (N*h*n)%denom != 0) continue;
      ll w = N*h*n/denom;
      if(w > 0 && N*(h*n+n*w+w*h) == 4*h*n*w) {
        cout << h << " " << n << " " << w << "\n";
        return;
      }
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Point{
  int next;
  struct Point *P,*L,*R;
};

struct Point *squrt,*setsu;
void inorder(struct Point *st);
void preorder (struct Point *st);
void insert (int a);
struct Point *find (struct Point *st,int b);
struct Point *treeMinimum(struct Point *x);
struct Point *treeSuccessor(struct Point *x);
void Delete (struct Point *z);

int main()
{
  int i,n,p;
  char hi[10];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",hi);
    if( hi[0] == 'f'){
     scanf("%d",&p);
     struct Point *q =find(squrt,p);
     if(q!=setsu)
       printf("yes\n");
     else printf("no\n");
    }
    else  if(hi[0]=='i'){        /*insert*/
      scanf("%d",&p);
      insert(p);
    }else if(hi[0]=='p'){   /*print*/
      inorder(squrt);
      printf("\n");
      preorder(squrt);
      printf("\n");
    }
    else if(hi[0]=='d'){    /*print*/
      scanf("%d",&p);
      Delete(find(squrt,p));
    }
  }
  return 0;
}

void inorder(struct Point *st){
  if(st==setsu)
    return;
  inorder(st->L);
  printf(" %d",st->next);
  inorder(st->R);
  
}

void preorder(struct Point *st){
  if(st==setsu)
    return;
  printf(" %d",st->next);
  preorder(st->L);
  preorder(st->R);

}

void insert (int a){
  struct Point *x=squrt;
  struct Point *y=setsu;
  struct Point *z;

  z=(struct Point *)malloc(sizeof(struct Point));
  z->next=a;
  z->L=setsu;
  z->R=setsu;

  while(x!=setsu){
    y=x;
    if(x->next > z->next){
      x=x->L;
    }else
      x=x->R;
    
  }

  z->P=y;
  if(y==setsu){
    squrt=z;
  }else{
    if(y->next > z->next){
      y->L=z;
    }else
      y->R=z;
    
  }
}
    
    
struct Point *find (struct Point *st,int b){     /*keyの存在を見つける*/
  while(st !=setsu && b !=st->next){
    if(b < st->next)
      st=st->L;
    else st=st->R;
  }
  return st;
}

struct Point *treeMinimum(struct Point *x){

  while(x->L!=setsu)
    x=x->L;

  return x;
}


struct Point *treeSuccessor(struct Point *x){   
  if(x->R!=setsu)
    return treeMinimum (x->R);

  struct Point *y =x->P;
  
  while(y!=setsu && x==y->R){
    x=y;
    y=y->P;
  }

  return y;
}
    
void Delete (struct Point *z){
  struct Point *y;                   /*削除*/
  struct Point *x;                   /*子*/

  if(z->L == setsu || z->R == setsu )
    y=z;
  else 
    y=treeSuccessor(z);

  if(y->L!=setsu){
    x=y->L;
  }else{
    x=y->R;
  }

  if (x!=setsu){
    x->P=y->P;
  }

  if(y->P==setsu){
    squrt=x;
  }else{
    if(y==y->P->L){
      y->P->L=x;
    }else{
      y->P->R=x;
    }
  }
  if(y!=z){
    z->next = y->next;
  }

  free(y);

}
  



Measured memory_bytes: 20508
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main()
{
    int n, ans = 0;
    cin >> n;
    int in;
    vector<int> a(n), b(n), c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n){
        cin >> b[i];
        ans += b[i];
    }
    rep(i,n-1) cin >> c[i];
    for(int i = 1; i < n; i++){
        if(a[i]-a[i-1] == 1) ans += c[a[i]-2];
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  string str;
  cin >> str;
  //str = "akasaka";
  int N = str.size();
  bool flag = true;
  for (int i = 0; i < (N - 1) / 2; ++i)
  {
    if (str.at(i) != str.at(i + (N + 1) / 2))
    {
      flag = false;
    }
  }
  if (flag)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

typedef long long ll;
//{
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define dumo dump
#define sysp system("pause")
//}

#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 0

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}
inline long long digitsum(long long v){long long d=0;while(v){d+=v%10;v/=10;}return d;};
//}

string lis[4]={"eraser","dreamer","erase","dream"};
string s;

int main(){
	cin>>s;
	reverse(all(s));
	for(int i=0;i<4;i++){
		reverse(all(lis[i]));
	}
	for(int i=0;i<s.size();){
		if(s.substr(i,6)==lis[0])i+=6;
		else if(s.substr(i,7)==lis[1])i+=7;
		else if(s.substr(i,5)==lis[2])i+=5;
		else if(s.substr(i,5)==lis[3])i+=5;
		else{
			dump("NO");
			system("pause");
			return 0;
		}
		debug(i);
	}
	dump("YES");
	system("pause");
}
 

Measured memory_bytes: 760
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val s = new Array[(Int, Int)](N)
  val l = new Array[(Int, Int)](N)

  for(i <- 0 until N) {
    val a, b = in.next().toInt
    s(i) = (a, b)
  }

  for(i <- 0 until N) {
    val c, d = in.next().toInt
    l(i) = (c, d)
  }

  val bm = new BipartiteMatching(N*2)

  for(a <- 0 until N) {
    val (sx, sy) = s(a)
    for(b <- 0 until N) {
      val (lx, ly) = l(b)
      if (sx < lx && sy < ly)
        bm.addEdge(a, b+N)
    }
  }

  println(bm.bipartiteMatching())
}

class BipartiteMatching(V: Int) {

  val G = Array.fill[List[Int]](V)(Nil) // グラフの隣接リスト表現
  val matching = Array.fill[Int](V)(-1) // マッチングのペア
  val used = new Array[Boolean](V)      // DFSで既に調べたかのフラグ

  // uとvを結ぶ辺をグラフに追加する
  def addEdge(u: Int, v: Int): Unit = {
    G(u) = v :: G(u)
    G(v) = u :: G(v)
  }

  // 増加パスをDFSで探す
  private[this] def dfs(v: Int): Boolean = {
    used(v) = true
    for(i <- 0 until G(v).length) {
      val u = G(v)(i)
      val w = matching(u)
      if(w < 0 || (!used(w) && dfs(w))) {
        matching(v) = u
        matching(u) = v
        return true
      }
    }
    return false
  }

  // 二部グラフの最大マッチングを求める
  def bipartiteMatching(): Int = {
    var res = 0
    for(v <- 0 until V) {
      if(matching(v) < 0) {
        for(i <- 0 until V)
          used(i) = false
        if(dfs(v)) {
          res += 1
        }
      }
    }

    res
  }
}




class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



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

int64_t Lucas(int n, vector<int64_t> &ans){

  if(ans.at(n) != 0){
    return ans.at(n);
  }

  if (n == 0){
    ans.at(n) = 2L;
  }
  else if(n == 1){
    ans.at(n) = 1L;
  }
  else{
    ans.at(n) = Lucas(n-2,ans) + Lucas(n-1,ans);
  }
  return ans.at(n);
}

int main() {
  int N;
  cin >> N;
  vector<int64_t> ans(N+1,0);

  cout << Lucas(N,ans) << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()
lis=[]

ans=0
lr=0
rl=0
for i in range(n-1):
    if s[i]==s[i+1]:
        ans+=1
    if s[i]=="L" and s[i+1]=="R":
        lr+=1
    if s[i]=="R" and s[i+1]=="L":
        rl+=1

if lr==rl:
    if k<rl:
        ans+=(2*k)
    else:
        ans+=(2*rl)
else:
    if rl>lr:
        if k<rl:
            ans+=(2*k)
        else:
            ans+=((2*lr)+1)
    else:
        if k<lr:
            ans+=(2*k)
        else:
            ans+=((2*rl)+1)


print(ans)


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    while(cin >> x) {
        ll y = (x + 10) / 11;
        ll z = 2 * y;
        if(y * 11 - 5 >= x) z--;
        cout << z << endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);

		if (a <= b * c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 32624
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h,n;
    cin >> h >> n;
    vector<int> arr(n);
    int tot=0;
    F0R(i,n)
    {
        cin >> arr[i];
        tot+=arr[i];
    }
    if(tot>=h)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>


using namespace std;


class Dice{
	private:
		int **dice;	// 複数のダイスのデータ

	public:
		// コンストラクタ
		Dice(int);
		// 全面一致するか調べる
		bool serch(int, int);
		// 様々な方向に回して同じ２つのサイコロかどうか調べる
		bool corocoro(int, int);
};


// コンストラクタ
Dice::Dice(int n)
{
	// 多次元配列ダイスの準備
	dice = new int*[n];
	for(int i = 0; i < n; i++)
		dice[i] = new int[6];

	// ダイスデータの入力
	for(int i = 0; i < n; i++)
		for(int  j = 0; j < 6; j++)
			cin >> dice[i][j];
}
// 全面一致するか調べる
bool Dice::serch(int x, int y)
{
	for(int i = 0; i < 6; i++)
		if(dice[x][i] != dice[y][i])
			return false;

	return true;
}
// 様々な方向に回して同じサイコロかどうか調べる(1つ目のサイコロ:x, 2つめのサイコロ:y)
bool Dice::corocoro(int x, int y)
{
	int mem, tmp;
	string code[6] = {"W", "W", "W", "N", "NN", ""};

	int i = 0;
	do{
		// 正面を固定してサイコロをくるくる回す
		for(int j = 0; j < 4 && dice[x][0] == dice[y][0]; j++){
			tmp = dice[y][4];
			dice[y][4] = dice[y][2];
			dice[y][2] = dice[y][1];
			dice[y][1] = dice[y][3];
			dice[y][3] = tmp;

			// 全面一致するか調べる
			if(dice[x][4] == dice[y][4])
				if(serch(x, y))
					return true;
		}

		// 調べる箇所を変更
		for(int j = 0; j < code[i].length(); j++){
			switch(code[i][j]){
				case 'N':
					tmp = dice[y][5];
					dice[y][5] = dice[y][4];
					dice[y][4] = dice[y][0];
					dice[y][0] = dice[y][1];
					dice[y][1] = tmp;
					break;
				case 'W':
					tmp = dice[y][5];
					dice[y][5] = dice[y][3];
					dice[y][3] = dice[y][0];
					dice[y][0] = dice[y][2];
					dice[y][2] = tmp;
					break;
			}
		}
	}while(++i < 6);

	return false;
}


int main()
{
	Dice *x;
	int n;

	cin >> n;
	x = new Dice(n);
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(x->corocoro(i, j)){
			// ２つのサイコロが同じ場合
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3200
import heapq

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

pay_list = []
heapq.heapify(pay_list)
ans = 0
AB = sorted(AB, reverse=True)
for i in range(1, M+1):
    # 実行可能なバイトリストを抽出
    for j in range(len(AB)-1, -1, -1):
        a = AB[j][0]
        b = AB[j][1]
        if a <= i:
            # heappopで最大値を取り出したいため、補正値の(-1)を乗じておく
            heapq.heappush(pay_list, b*(-1))
            AB.pop(j)
        else:
            break
    # 最大の報酬の値を取り出して足す
    if len(pay_list) > 0:
        ans += heapq.heappop(pay_list) * (-1)
print(ans)


Measured memory_bytes: 28660
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
double r,l,p,e,t;
int k;
double sum;
void dfs(double R,double L,double pp,int n)
{
    double a=t+e;
    double b=t-e;
    if(R>a||L<b)
    return;
    if(R>=b&&L<=a)
    {
        sum+=pp;
        return;
    }
    double h=(R+L)/2.0;
    if(k<n)
    {
        if(h>=b&&h<=a)
        {
            sum+=pp;
        }
        return;
    }
    if(h>=t)
    {
        dfs(R,h,pp*(1-p),n+1);
        dfs(h,L,pp*p,n+1);
    }
    else
    {
        dfs(R,h,pp*p,n+1);
        dfs(h,L,pp*(1-p),n+1);
    }
}

int main()
{
    scanf("%d%lf%lf",&k,&r,&l);
    scanf("%lf%lf%lf",&p,&e,&t);
    sum=0;
    dfs(r,l,1,1);
    printf("%.6lf\n",sum);
    return 0;
}

Measured memory_bytes: 1244
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	A,B = inputMap()

	ans = lcm(A,B)
	print(ans)



def gcd(a, b):
	if a > b:
		a, b = b, a

	while a > 0:
		a, b = b % a, a
	return b

def lcm(a, b):
	g = gcd(a, b)
	return a // g * b

if __name__ == "__main__":
	main()


Measured memory_bytes: 38504
using System;
        using System.Linq;
        using System.Collections.Generic;
        using static System.Math;
 
        public class Program
        {
            public static void Main(string[] args)
            {
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] sec = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int sum = input[1];

            for(int i = 1; i < input[0]; i++)
            {
                sum += Min(input[1], sec[i] - sec[i - 1]);
            }

            Console.WriteLine(sum);
            }
        }

Measured memory_bytes: 28768
#include <iostream>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

string Str;
unsigned int cur = 0;

int digit();
int number();
int term();
int facter();
int expression();

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cur = 0;
        cin >> Str;
        Str.resize(Str.size()-1);
        int ans = expression();
        cout << ans << endl;
    }
    return 0;
}

int digit()
{
    assert(isdigit(Str[cur]));
    int n = Str[cur] - '0';
    cur++;
    return n;
}

int number()
{
    int n = digit();
    while(cur < Str.size() && isdigit(Str[cur])) n = n*10 + digit();
    return n;
}

int factor()
{
    if(Str[cur] != '(') return number();
    cur++;
    int n = expression();
    assert(Str[cur] == ')');
    cur++;
    return n;
}

int term()
{
    int a = factor();
    while(cur < Str.size() && (Str[cur] == '*' || Str[cur] == '/')){
        char op = Str[cur++];
        int b = factor();
        if(op == '*') a *= b;
        else a /= b;
    }
    return a;
}

int expression()
{
    int a = term();
    while(cur < Str.size() && (Str[cur] == '+' || Str[cur] == '-')){
        char op = Str[cur++];
        int b = term();
        if(op == '+') a += b;
        else a -= b;
    }
    return a;
}

Measured memory_bytes: 1212
using System.Collections.Generic;
using static System.Console;
using System;

class Program {
	static void Main() {
		var N = NextInt();
		var K = NextInt();
		var t = 1;
		for (var i = 0; i < N; i++) {
			t = Math.Min(t * 2, t + K);
		}
		WriteLine(t);
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
ll gcd(ll x,ll y){
  if(x%y==0){return y;}
  return gcd(y,x%y);}

ll lcm(ll x,ll y){
  return (x*y)/gcd(x,y);}

ll ord(ll x){
  ll k=0;
  while(x%2==0){k++;
                x/=2;}
  return k;}
using namespace std;
int main(){
  ll n,m;
  cin>>n>>m;
  vector<int> a(n);
  rep(i,n){cin>>a[i];
          a[i]/=2;}
  bool ans=true;
  ll j=ord(a[0]);
  rep(i,n){if(ord(a[i])!=j){ans=false;
                            break;}}
  if(ans){ll l=a[0];
    REP(i,1,n){
      if(l<=m){l=lcm(l,a[i]);}}
  ll k=(m/l-1)/2+1;
  if(l>m){k=0;}
  cout<<k<<endl;}
  else{cout<<0<<endl;}
}

Measured memory_bytes: 640
n = int(input())
xs = list(map(int, input().split()))

ys = list(sorted(xs))
m1, m2 = (ys[i] for i in (n//2 - 1, n//2))

medians = [m2 if x < m2 else m1 for x in xs]
print('\n'.join(map(str, medians)))

Measured memory_bytes: 31892
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int ans = 0;
    for(int i=0; i<N-1; i++)
        if(S[i] == S[i+1])
            ans++;

    int cnt = N-1-ans;
    ans = (ans + min(cnt, 2*K));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        cnt = 0
        for j in range(i, len(s)):
            x = s[i:j+1]
            st.add(x)
            cnt += 1
            # print('cnt', cnt)
            if cnt > 5:
                break
    return sorted(list(st))

r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
# print(r)
print(ans)

Measured memory_bytes: 3188
#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 sum = 2*A[0];
    int p = -1;
    for(int i=1; i<=N-2; i++){
        sum = sum + p*2*A[i];
         p*= -1; 
    }

    long x[N];
    x[0] = (sum + 2*A[N-1]) / 2;
    for(int i=1; i<N ;i++){
        x[i] = 2*A[i-1] - x[i-1];
    }

    for(int i=0; i<N; i++){
        cout << x[i] << " ";
    }

    return 0;

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = 0;

    ans += (b/x);

    if(a % x == 0){
        ans -= (a/x) - 1;
    }else{
        ans -= (a/x);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))

int main(int argc, char *argv[]) {
  int N, K;
  std::cin >> N >> K;
  int xList[N];
  for (int i = 0; i < N; i++) std::cin >> xList[i];
  int sum = 0;
  for (int i = 0; i < N; i++) sum += MIN(xList[i], ABS(xList[i] - K));
  std::cout << sum * 2 << std::endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var s string
	con.Scan(&s)
	c := 0
	for i := 0; i < len(s)-1; i++ {
		if s[i] != s[i+1] {
			c++
		}
	}
	con.Println(c)
	return nil
}


Measured memory_bytes: 1280
#D問題
N, K = map(int, input().split())
A = list(map(int, input().split()))

check = [0] * N
time = [-1] * N
check[0] = 1
time[0] = 0
now = 1
t = 1
ex = 0
roop = 0
for i in range(N + 1):
  now = A[now - 1]
  if check[now - 1] == 0:
    check[now - 1] = 1
    time[now - 1] = t
  else:
    ex = time[now - 1]
    roop = t - time[now - 1]
    break
  t += 1
  
if K < t:
  ans = time.index(K) + 1
  print(ans)
else:
  K -= (t - 1)
  K %= roop
  if K == 0:
    K = roop
  #print(K)
  ans = time.index(ex + K - 1) + 1
  print(ans)
  #print(check, time, roop, t, ex)  



Measured memory_bytes: 32224
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc;// = new Scanner(System.in);
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        boolean S[] = new boolean[13];
        boolean H[] = new boolean[13];
        boolean C[] = new boolean[13];
        boolean D[] = new boolean[13];
        for(int i=0;i<13;i++){
            S[i] = true;
            H[i] = true;
            C[i] = true;
            D[i] = true;
        }

        for(int i=0; i<n; i++){
            String c = sc.next();
            int x = sc.nextInt();
            switch(c){
                case "S":
                    S[x-1] = false;
                    break;
                case "H":
                    H[x-1] = false;
                    break;
                case "C":
                    C[x-1] = false;
                    break;
                case "D":
                    D[x-1] = false;
                    break;
            }
        }

        for(int i=0;i<13;i++){
            if(S[i])System.out.println("S "+(i+1));
        }
        for(int i=0;i<13;i++){
            if(H[i])System.out.println("H "+(i+1));
        }
        for(int i=0;i<13;i++){
            if(C[i])System.out.println("C "+(i+1));
        }
        for(int i=0;i<13;i++){
            if(D[i])System.out.println("D "+(i+1));
        }
    }
}


Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pi;
 
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void solve()
{
    ll a;
    cin >> a;

    double ans = 2*3.14159265358979323846*a;
    printf("%.10f", ans);

    return;
}

int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastio

    ll t = 1;
    // cin >> t;

    FOR(i, 1, t){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

void dfs(vector<ll>* edges,ll ind,ll val,ll* arr,bool* visited){
	visited[ind] = 1;
	arr[ind] = val;
	for(auto it:edges[ind]){
		if(!visited[it])
			dfs(edges,it,val,arr,visited);
	}
}
int main() 
{
	ll n;
	cin>>n;
	cout<<(n+1)/2<<endl;
	return 0;
}



Measured memory_bytes: 256
N,M = [int(x) for x in input().split()]
xyz = [[int(x) for x in input().split()] for _ in range(N)]
ans = 0
for bit in range(1<<3):
  xyz1 = []
  a = 1
  b = 1
  c = 1
  if bit&1:
    a = -1
  if bit&1<<1:
    b = -1
  if bit&1<<2:
    c = -1
  for i in range(N):
    x,y,z = xyz[i]
    xyz1.append(x*a+y*b+c*z)
  xyz1 = sorted(xyz1,reverse = True)
  ans = max(ans,sum(xyz1[:M]))
print(ans)
    

Measured memory_bytes: 3304
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
	int n;
	char c[200000];
	cin>>n;
	priority_queue<int> r;
	priority_queue<int,vector<int>,greater<int> > w;
	for(int i=0;i<n;i++){
		cin>>c[i];
		if(c[i]=='R'){
			r.push(i);
		}else{
			w.push(i);
		}
	}
	if(r.empty()||w.empty()){
		cout<<0<<endl;
		return 0;
	}
	int ans=0;
	while(r.top()>w.top()){
		int R=r.top();
		r.pop();
		int W=w.top();
		w.pop();
		r.push(W);
		w.push(R);
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4576
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
    priority_queue<int>q;  
    int m,n,temp; 
    long long sum=0;
    cin>>n>>m;
    for(int i=0; i<n; i++)
    {
        cin>>temp;
        q.push(temp); 
    }
    while(m)
    {
        temp=q.top()/2;
        q.pop();
        q.push(temp);
        m--;
    }
    while(!q.empty())
    {
        sum+=q.top();
        q.pop();
    }
    cout<<sum<<endl; 
    return 0;
}



Measured memory_bytes: 892
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            long cash = 100;
            var rate = 1.01;

            long X = long.Parse(Console.ReadLine());

            int i = 0;

            while (cash < X)
            {
                cash = (long)Math.Floor(cash * rate);
                i++;
            }
            Console.WriteLine(i);
        }
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long N, long long K)
{
    if (N / K != 0)
    {
        ll temp = N / K;
        N = N - temp * K;
    }
    long long ans = min(N, abs(N - K));
    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    solve(N, K);
    return 0;
}


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

int main() {
  double W,H,x,y;
  cin >> W >> H >> x >> y;
  double ans = W*H/2;
  printf("%.9f ",ans);
  if(x == W/2 && y == H/2) cout << 1 << endl;
  else cout << 0 << endl;
}

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

int main(int argc, char** argv){
  int N;
  cin >> N;
  double x;
  string u;
  double sum = 0;
  const double bc = 380000.0;
  for(int cnt0=0; cnt0<N; cnt0++){
    cin >> x >> u;
    if(u == "JPY") sum+=x;
    else sum+= x*bc;
  }

  printf("%lf", sum);
  return 0;
  
}

Measured memory_bytes: 256
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///



#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

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


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


const int mx = 1e5+123;

int dp[mx], n, h[mx], k;


int solve ( int i )
{
	if ( i == n-1 ) return 0;
	if ( dp[i] != -1 ) return dp[i];

	int ret = inf;
	for ( int j = 1; j <= k; j++ ) {
		if ( i+j < n ) ret = min ( ret, abs ( h[i] - h[i+j] ) + solve ( i+j ) );
	}

	return dp[i] = ret;
}


int main()
{
	optimize();

	cin >> n >> k;
	for ( int i = 0; i < n; i++ ) cin >> h[i];

	mem ( dp, -1 );
	cout << solve ( 0 ) << endl;


	return 0;
}


















Measured memory_bytes: 12180
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; cin >> s;
  int n = s.length();
  if (n == 1) {
    cout << 1 << '\n';
    return 0;
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  dp[2] = (s[0] == s[1] ? 1 : 2);
  FOR(i, 2, n) {
    if (s[i] == s[i - 1]) {
      dp[i + 1] = dp[i - 2] + 2;
    } else {
      dp[i + 1] = dp[i] + 1;
    }
  }
  cout << dp[n] << '\n';
  return 0;
}


Measured memory_bytes: 1300
R, G, B, N = list(map(int, input().split()))
R, G, B = sorted([R, G, B], reverse=True)
ret = 0
for r in range(N//R+1):
    if G == 1:
        ret += N-r+1
    else:
        for g in range((N-r)//G+1):
            if N - (R*r+G*g) >= 0:
                if (N - (R*r+G*g)) % B == 0:
                    ret += 1
print(ret)

Measured memory_bytes: 3064
import numpy as np
import sys
from collections import Counter
W, H, N = map(int, input().split())

grid = np.array([[0] * W] * H)

for n in range(N):
    tmp_w, tmp_h, a = map(int, input().split())
    if a == 1:
        grid.T[: tmp_w] = 1
    if a == 2:
        grid.T[tmp_w:] = 1
    if a == 3:
        grid[0: tmp_h] = 1
    if a == 4:
        grid[tmp_h: ] = 1
    #print(grid)

print(Counter((grid.reshape(1, W * H).tolist())[0])[0])

Measured memory_bytes: 13212
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    ll gx,gy;
    cin >> gx >> gy;
    gx+=10000;gy+=10000;
    vector<bool> b_x(20001,false),b_y(20001,false);
    b_x[10000]=b_y[10000]=true;
    vl s_compe;
    ll now=0;
    rep(i,s.size()){
        if(s[i]=='T'){
            s_compe.pb(now);
            now=0;
            s_compe.pb(-1);
        }
        if(s[i]=='F'){
            now++;
        }
    }
    s_compe.pb(now);
    ll cnt=0;
    rep(i,s_compe.size()){
        if(s_compe[i]==-1){
            cnt++;
        }
        else if(i==0){
            b_x[10000]=false;
            b_x[10000+s_compe[i]]=true;
        }
        else{
            if(cnt%2==0){
                vector<bool> newdp(20001,false);
                rep(j,20001){
                    if((j-s_compe[i]>=0&&b_x[j-s_compe[i]])||(20000>=j+s_compe[i]&&b_x[j+s_compe[i]])){
                        newdp[j]=true;
                    }
                }
                swap(newdp,b_x);
            }
            else{
                vector<bool> newdp(20001,false);
                rep(j,20001){
                    if((j-s_compe[i]>=0&&b_y[j-s_compe[i]])||(20000>=j+s_compe[i]&&b_y[j+s_compe[i]])){
                        newdp[j]=true;
                    }
                }
                swap(newdp,b_y);
            }
        }
    }
    if(b_x[gx]&&b_y[gy]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
char s[105];
int main()
{
	int k;
	scanf("%d%s", &k, s + 1);
	for(int i = 1; i <= min(k, (int)strlen(s + 1)); ++i) printf("%c", s[i]);
	if(strlen(s + 1) > k) printf("...");
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>
#define N 100000
using namespace std;

int main(){
  int i,n,C;

  scanf("%d %d",&n,&C);

  int s,t,d;
  int c[C+1][N+1];

  for(i=0;i<C;i++){
    for(int j=0;j<=N;j++) c[i][j]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&s,&t,&d);
    for(int j=s;j<=t;j++) c[d-1][j]=1;
  }

  int maxl=0;
  for(i=0;i<=N;i++){
    int z=0;
    for(int j=0;j<C;j++){
      z+=c[j][i];
    }
    maxl=max(maxl,z);
  }
  printf("%d",maxl);
  return 0;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
#include <numeric>
#include <iterator>
#include <stdio.h>
#define ll long long
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fr(i,p,n) for(int i=p;i<n;i++)
#define precise cout << std::setprecision(10) << std::fixed;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
//ll M=1000000007;
//double pi=3.1415926535898;
ll M=  998244353;
typedef pair<int, int> pairs;
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main()
{
    fastio; //precise;

    int T=1;
    //cin>>T;
    while(T--){
        int n,ans=0;
        cin>>n;
        int h[n],dp[n]={0};
        fr(i,0,n){
            cin>>h[i];
        }
        dp[1]=abs(h[0]-h[1]);
        fr(i,2,n){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
        cout<<dp[n-1]<<endl;


    }
     return 0;
}



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

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


int main() {
  ll a,b,c,k,ans=0,x_1,x_2,x_3;
  cin >> a >> b >> c >> k;
  x_1 = min(a,k);
  x_2 = min(k-x_1,b);
  x_3 = min(k-x_1-x_2,c);
  ans = x_1 - x_3;
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void){
    int N = 0;
    int L[10] = {0};
    scanf("%ld", &N);
    for(int i = 0; i < N; i++){
        scanf("%ld", &L[i]);
    }
    int m = 0;
    for(int i = 0; i < N; i++){
        if(m < L[i]){
            m = L[i];
        }
    }

    int sum = 0;

    for(int i = 0; i < N; i++){
        sum += L[i];
    }
    sum -= m;

    if(sum > m){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N, T;
vector<long long> t;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> T;
	for(int i=0; i<N; i++){
		long long tmp;
		cin >> tmp;
		t.push_back(tmp);
	}

	long long ans = T;
	long long laststop = T;
	for(int i=1; i<N; i++){
		if(laststop < t[i]){
			ans = ans + T;
		}
		else{
			ans = ans + (t[i] - (laststop -T));
		}
		laststop = t[i] + T;
	}
	printf("%lld\n", ans);
	return 0;
}


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

const int N = 2e5+7;
struct node
{
	int a,b,c,d;
}Q[55];
int n,m,q;
int s[15],ans;

void check()
{
	int num=0;
	for(int i=0;i<q;i++){
		if(s[Q[i].b]-s[Q[i].a]==Q[i].c) num+=Q[i].d;
	}
	ans = max(ans,num);
}
void dfs(int pos,int val)
{
	s[pos] = val;
	if(pos==n) {
		check();return ;
	}
	for(int i=val;i<=m;i++){
		dfs(pos+1,i);
	}
}
int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<q;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		Q[i] = (node){a,b,c,d};
	}
	dfs(1,1);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3560
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  inp = inp[0];
  
  let ans = 1
  for (let i = 1; i < N; i++) {
    if (inp[i] !== inp[i-1]) ans++
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
from sys import stdin
input = stdin.readline
 
from itertools import accumulate
from bisect import bisect_left
 
N, K = map(int, input().split())
 
memo = [0] * 100010
for _ in range(N):
    a, b = map(int, input().split())
    memo[a] += b
 
print(bisect_left(list(accumulate(memo)), K))

Measured memory_bytes: 16872
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <set>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;
map <int,int> mp;
priority_queue<int> que;

int main(void){
    cin >> n;
    REP(i,n){
        int a;
        cin >> a;
        auto itr = mp.find(a);
        if(itr==mp.end()){
            mp[a]=1;
        }else{
            mp[a]++;
        }
        if(mp[a]>=2){
            que.push(a);
            mp[a]=0;
        }
    }
    if(que.size()>=2){
        int w = que.top();que.pop();
        int h = que.top();que.pop();
        put((ll)w*h);
    }else{
        put(0);
    }
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int mod=1e9+7;
long long ans;
int n,p,now,fac;
string s;
map<int,int>mp;
int main()
{
	cin>>n>>p>>s;
	
	if(p==2) {
		for(int i=0; i<n; ++i)
			if((s[i]-'0')%2==0)
				ans+=i+1;
	} else if(p==5) {
		for(int i=0; i<n; ++i)
			if((s[i]-'0')%5==0)
				ans+=i+1;
	} else {
		++mp[0];
		int t=0, p2=1;
		for(int i=n-1; ~i; --i) {
			t=(t+(s[i]-'0')*p2)%p;
			ans+=mp[t];
			mp[t]++;
			p2=p2*10%p;
		}//copy for test
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 900