akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s[555][555];
int main(){
 DRII(n,m);
 REP(i,n)RS(s[i]);
 REP(i,n){
  REP(j,m){
   if(j&&(i%2==0||s[i][j]=='#'||j==m-1))printf("#");
   else printf(".");
  }
  puts("");
 }  
 puts("");
 REP(i,n){
  REP(j,m){
   if(j!=m-1&&(i%2==1||s[i][j]=='#'||j==0))printf("#");
   else printf(".");
  }
  puts("");
 }  
 return 0;
}

Measured memory_bytes: 1024
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	canDiv2 := 0
	canDiv4 := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		if a[i]%4 == 0 {
			canDiv4++
		} else if a[i]%2 == 0 {
			canDiv2++
		}
	}

	l := canDiv4*2 + canDiv2
	if canDiv2 == 0 {
		l++
	}

	if l >= N {
		out("Yes")
	} else {
		out("No")
	}
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    Int K; cin >> K;
    Int t = (K + 49) / 50;
    vector<Int> A(50);
    REP(i, 50) A[i] = t + i;
    if (K % 50 != 0) REP(i, 50 - K % 50) {
        int maxi = max_element(A.begin(), A.end()) - A.begin();
        REP(j, A.size()) A[j]++;
        A[maxi] -= A.size() + 1;
    }
    cout << "50\n";
    REP(i, 50) cout << A[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
    
    
public class Main {
	static int INF = 2 << 27;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			String name = sc.next();
			char type   = sc.next().charAt(0);
			StringBuilder sb = new StringBuilder();
			if(type == 'X') break;
			else if(type == 'U') {
				sb.append(Character.toUpperCase(name.charAt(0)));
				for(int i = 1; i < name.length(); i++) {
					if(name.charAt(i) == '_') {
						sb.append(Character.toUpperCase(name.charAt(i+1)));
						i++;
					}
					else {
						sb.append(name.charAt(i));
					}
				}
			}
			else if(type == 'L') {
				sb.append(Character.toLowerCase(name.charAt(0)));
				for(int i = 1; i < name.length(); i++) {
					if(name.charAt(i) == '_') {
						sb.append(Character.toUpperCase(name.charAt(i+1)));
						i++;
					}
					else {
						sb.append(name.charAt(i));
					}
				}
			}
			else if(type == 'D') {
				sb.append(Character.toLowerCase(name.charAt(0)));
				for(int i = 1; i < name.length(); i++) {
					if(Character.isUpperCase(name.charAt(i))) {
						sb.append("_");
						sb.append(Character.toLowerCase(name.charAt(i)));
					}
					else {
						sb.append(name.charAt(i));
					}
				}
			}
			System.out.println(sb.toString());
		}
	}
}

Measured memory_bytes: 26036
#!/usr/bin/env python3
import sys
from bisect import bisect_right

INF = 10e11

def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    b, d = bisect_right(s, x), bisect_right(t, x)
    ret = INF

    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            ret = min(ret, d1, d2)
    print(ret)


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = [-INF] + [int(next(tokens)) for _ in range(A)] + [INF]  # type: "List[int]"
    t = [-INF] + [int(next(tokens)) for _ in range(B)] + [INF]  # type: "List[int]"

    for x in range(Q):
        x = int(input())
        solve(A, B, Q, s, t, x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14012
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define rndf(d) (ll)((double)(d) + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)(x) ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define rnddiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) * 2 >= (ll)(b) ? 1 : 0))
#define ceildiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

int main() {
	int n; cin >> n;
	vi a(n);
	vi b(n);
	Loop(i, n) {
		cin >> a[i];
		a[i]--;
		b[a[i]] = i;
	}
	vi c(n, 0);
	Loop(i, n) {
		if (a[i] - 1 >= 0) c[a[i]] = c[a[i] - 1] + 1;
		else c[a[i]] = 1;
	}
	int buf = 0;
	Loop(i, n) {
		buf = max(buf, c[i]);
	}
	cout << n - buf << endl;
}

Measured memory_bytes: 2560
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
    if a[i] in dic:
        dic[a[i]]+=1
    else:
        dic.setdefault(a[i],1)
comb={}
banned={}
for i in dic.keys():
    if dic[i]>1:
        comb.setdefault(i,dic[i]*(dic[i]-1)//2)
        banned.setdefault(i,(dic[i]-1)*(dic[i]-2)//2)
    else:
        comb.setdefault(i,0)
        banned.setdefault(i,0)
sumComb=sum(comb.values())
for i in range(n):
    print(sumComb-comb[a[i]]+banned[a[i]])

Measured memory_bytes: 39400
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  int n;
  scanf("%d",&n);
  set<int>s;
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    if(s.count(x))s.erase(x);
    else s.insert(x);
  }
  printf("%d\n",int(s.size()));
  return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define print(x) cout<<x;
#define printl(x) cout<<x<<endl;
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
using namespace std;
typedef long long int ll;



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    for(int i=0;i<n;i++){
        cout<<a[i]<<b[i];
    }
    
    return 0;
}

Measured memory_bytes: 256
a=input().split(" ")
N=int(a[0])
K=int(a[1])
Q=int(a[2])
list1=[]
list2=[]
for i in range(Q):
    list1.append(int(input()))
for i in range(N):
    list2.append(-Q+K)
for i in range(Q):
    list2[list1[i]-1]+=1
for i in range(N):
    if list2[i]>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 11768
a=[],m=l=n=c=0;require("fs").readFileSync("/dev/stdin","utf8").trim().split(' ').map(function(i){a[i]?++a[i]>m?m=a[n=i]:0:a[i]=1;(t=i.length)>l?(c=i,l=t):0});console.log(n+' '+c)

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

int main() {
  ll x;
  cin >> x;
  
  for (int i=-120; i<=120; i++) {
    for (int j=-120; j<=120; j++) {
      if (i*i*i*i*i - j*j*j*j*j == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
vector<int>g[mx];
int a[mx];
multiset<int>s;
bool vis[mx];
void dfs(int u){
  vis[u]=true;
  s.insert(a[u]);
  for(int v:g[u])if(!vis[v])dfs(v);  
}
int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++)
    scanf("%d",a+i);  
  for(int i=0;i<m;i++){
    int u,v;
    scanf("%d %d",&u,&v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int>o;
  multiset<int>rem;
  uli ans=0;
  uli minis=0;
  int k=0;
  vector<int>mini;
  for(int i=0;i<n;i++)if(!vis[i]){
    s.clear();
    dfs(i);
    if(s.size()==1)o.push_back(*s.begin());
    else{
      minis+=uli(*s.begin());
      mini.push_back(*s.begin());
      for(int x:s)rem.insert(x);
      k++;
    }    
  }
  if(k>1){
    ans+=minis;
    for(int x:mini)rem.erase(rem.find(x));
  }
  for(int i=0;i<k-2;i++){
    ans+=*rem.begin();
    rem.erase(rem.begin());
  }
  if(!rem.empty()){
    if(o.size()>rem.size()){
      puts("Impossible");
      return 0;
    }
    auto it=rem.begin();
    for(int v:o){
      ans+=uli(v+*it);
      it++;
    }
  }
  else{
    if(o.size()>2){
      puts("Impossible");
      return 0;    
    }
    if(o.size()==2)for(int x:o)ans+=uli(x);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  string s,t,u;
  cin>>s>>t>>u;

  s[0] += 'A' - 'a';
  t[0] += 'A' - 'a';
  u[0] += 'A' - 'a';

  cout << s[0] << t[0] << u[0] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int cn[100005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		int a;
		ll s=0;
		FOR(i,0,n)
		{
			cin>>a;
			cn[a]++;
			s+=a;
		}
		int q;
		cin>>q;
		int b;
		FOR(i,0,q)
		{
			cin>>a>>b;
			s+=(cn[a]*(b-a));
			cn[b]+=cn[a];
			cn[a]=0;
			cout<<s<<'\n';
		}
	}
	return 0;
}

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

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

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

    // dp[c3][c2][c1]: 寿司が1個,2個,3個の皿がそれぞれc1,c2,c3個あるときの期待値
    // dp[c3][c2][c1] =
    //   (c1 / N) * (dp[c3][c2][c1-1] + 1) +
    //   (c2 / N) * (dp[c3][c2-1][c1+1] + 1) +
    //   (c3 / N) * (dp[c3-1][c2+1][c1] + 1) +
    //   ((N-c1-c2-c3)/N) * (dp[c3][c2][c1] + 1)
    // ∴ (1 - (N-c1-c2-c3)/N) dp[c3][c2][c1] = (c1 / N) * ... + (N-c1-c2-c3)/N
    // ∴ dp[c3][c2][c1] = N / (c1+c2+c3) * { (c1 / N) * ... + (N-c1-c2-c3)/N }
    vector dp(N+1, vector(N+1, vector(N+1, double())));

    REP(c3, N+1) REP(c2, N+1) REP(c1, N+1) {
        if (c1+c2+c3 == 0) continue;
        if (c1+c2+c3 > N) continue;
        double E = double(N-c1-c2-c3) / N;
        if (c1 > 0) E += ((double)c1 / N) * (dp[c3][c2][c1-1] + 1);
        if (c2 > 0) E += ((double)c2 / N) * (dp[c3][c2-1][c1+1] + 1);
        if (c3 > 0) E += ((double)c3 / N) * (dp[c3-1][c2+1][c1] + 1);
        dp[c3][c2][c1] = ((double)N / (c1+c2+c3)) * E;
    }

    int c[3] = {};
    REP(i, N) c[a[i]-1]++;
    cout << fixed << setprecision(15) << dp[c[2]][c[1]][c[0]] << '\n';
}


Measured memory_bytes: 219972
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		String t = "CODEFESTIVAL2016";
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int c = 0;
		for (int i = 0; i < 16; i++) {
			if (s.charAt(i) != t.charAt(i)) {
				c++;
			}
		}
		System.out.println(c);
	}
}


Measured memory_bytes: 9684
#include <bits/stdc++.h>
using namespace std;
#define ll              long long int
#define int             ll
#define ff              first
#define ss              second
#define pb              emplace_back
#define mpair           make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sbits(x)      __builtin_popcountll(x)
#define zbits(x)      __builtin_popcountlliltin_ctzll(x)
#define w(t)            int t;cin>>t;while(t--)
#define uset            unordered_set
#define forr(i, a, b)   for(int i =int(a);i<=int(b);i++)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
    template <typename Arg1>
     void __f(const char* name,Arg1&& arg1){
        cout<<name<<" : "<<arg1<<std::endl;
     }
     template <typename Arg1, typename... Args>
     void __f(const char* names,Arg1&& arg1,Args&&... args){
        const char* comma = strchr(names+1 ,',');
        cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
     }
#else
#define trace(...)
#endif
/*     
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
double pi = 2.0*acos(0);
void fast(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);}
int max2(int a,int b){ if(a>b) return a;return b;}
int min2(int a,int b){ if(a<b)return a;return b;}
int max3(int a,int b,int c){ return max2(a,max2(b,c));}
int min3(int a,int b,int c){ return min2(a,min2(b,c));}

///////////////////////////////////////////////////////////////////////////////////////////////


void solve(){
  
     int n,k;cin>>n;
     map<int,int>mp;int inp;int res = 0;
     for(int  i =1;i<=n;i++)
     {
        cin>>k;
        inp = k+i;
        if(mp.find(i-k)!=mp.end())
            res+=mp[(i-k)];
        mp[inp]++;
     }
     cout<<res<<endl;     
      
 }


signed main(void)
{
      fast();
      //w(t)
      solve();

}

Measured memory_bytes: 16012
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, M, D = sc.nextLong()

    // 数列の美しさを、隣り合う２項の組であって、差の絶対値がdであるものの個数として定義します
    // 1以上n以下の整数が各要素の長さmの数列は n^m通り存在
    // この全ての数列全ての美しさを求め, それらの平均を出力
    // 美しさが0の数列の方が多そう
    // i番目の要素がa_iの時に, の場合に美しさが1増える
    // a_{i+1} = a_i + d (a_i <= n - d)
    //         = a_i - d (a_i >= d)
    // 最初の要素を1つ決めた時
    // 残りの(m - 1)の要素について, 2 * ((n - d) - d) = 2(n - 2d)回美しさが増える
    // d = 0の時, 美しさ1となるペアの確率は, (0, 0), (1, 1),..., (n, n), n / n * n = 1/n
    // これが (m - 1) 個である, これを足し上げて, n^m 通りで割る
    // (m - 1) / n / n^m
    // d != 0の時, (1, 1 + d), (2, 2 + d), ..., (n - d, n), (n, n - d), ..., (2 + d, 2), (1 + d, 1)
    // で 2*(n - d)通り, 2(n - d)/n^2
    def solve(N: Long, M: Long, D: Long): Double = {
      (if (D == 0) (1 / N.toDouble)
      else 2 * (N - D) / (N * N).toDouble) * (M - 1)
    }

    println(solve(N, M, D))
  }

}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()

template <class T = int>
T in()
{
    T x;
    cin >> x;
    return (x);
}

void sort2vectors(vector<int> &av, vector<int> &bv)
{
    int n = av.size();
    vector<int> p(n), av2(n), bv2(n);
    iota(all(p), 0);
    sort(all(p), [&](int a, int b) { return av[a] < av[b]; });
    rep(i, n)
    {
        av2[i] = av[p[i]];
        bv2[i] = bv[p[i]];
    }
    av = av2;
    bv = bv2;
}

int main()
{
    vector<int> red_xs, red_ys, blue_xs, blue_ys;
    int n;
    cin >> n;
    rep(i, n)
    {
        red_xs.push_back(in());
        red_ys.push_back(in());
    }
    rep(i, n)
    {
        blue_xs.push_back(in());
        blue_ys.push_back(in());
    }
    int ans = 0;
    rep(i, 2)
    {
        rep(j, 2)
        {
            if (i == 0)
            {
                sort2vectors(red_xs, red_ys);
                sort2vectors(red_ys, red_xs);
            }
            else
            {
                sort2vectors(red_ys, red_xs);
                sort2vectors(red_xs, red_ys);
            }
            if (j == 0)
            {
                sort2vectors(blue_xs, blue_ys);
                sort2vectors(blue_ys, blue_xs);
            }
            else
            {
                sort2vectors(blue_ys, blue_xs);
                sort2vectors(blue_xs, blue_ys);
            }
            reverse(all(blue_xs));
            reverse(all(blue_ys));

            vector<int> rxs = red_xs;
            vector<int> rys = red_ys;
            vector<int> bxs = blue_xs;
            vector<int> bys = blue_ys;
            int cnt = 0;
            while (rxs.size() > 0)
            {
                for (int k = bxs.size() - 1; k >= 0; k--)
                {
                    if (rxs.back() < bxs[k] && rys.back() < bys[k])
                    {
                        rxs.pop_back();
                        rys.pop_back();
                        bxs.erase(bxs.begin() + k);
                        bys.erase(bys.begin() + k);
                        cnt++;
                        break;
                    }
                    if (k == 0)
                    {
                        rxs.pop_back();
                        rys.pop_back();
                    }
                }
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
  int Q;
  cin >> Q;
  vector<int> ans;
  vector<int> B(100001);
  int sum=0;
  B[0]=0;
  FOR(i,1,100001){
    if(i%2==1){
      if(IsPrime(i)&&IsPrime((i+1)/2)){
        sum++;
      }
    }
    B[i]=sum;
  }

  REP(i,Q){
    int l,r;
    cin >> l >> r;
    ans.push_back(B[r]-B[l-1]);
  }

  for(auto p:ans){
    cout << p << endl;
  }
}

Measured memory_bytes: 1528
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

int main() {
	while (true) {
		int N;
		cin >> N;
		if (N == 0)break;
		vi a(N);
		rep(i, N)cin >> a[i];
		vvi dp(N, vi(N + 1, 0));
		repl(w, 1, N + 1) {
			rep(i, N) {
				int j = i + w;
				if (j > N)continue;
				if (w >= 2 && dp[i + 1][j - 1] == (w - 2) && abs(a[i] - a[j - 1]) <= 1) {
					dp[i][j] = w;
				}
				else {
					repl(k, i + 1, j) {
						dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j]);
					}
				}
			}
		}
		/*
		rep(i, N) {
			repl(j, 1, N + 1) {
				cout << dp[i][j];
			}
			cout << endl;
		}
		*/
		cout << dp[0][N] << endl;
	}

	return 0;
}

Measured memory_bytes: 3220
from collections import defaultdict

dX = [1, 0, -1, 0]
dY = [0, 1, 0, -1]

def bfs(m, c):
    q = []
    d = defaultdict(lambda: 0xffffffff)
    q.append(c)
    d[c] = 0
    while len(q) != 0:
        c = q.pop(0)
        for dx, dy in zip(dX, dY):
            nx = dx + c[0]
            ny = dy + c[1]
            if ny < 0 or ny >= len(m):
                continue
            if nx < 0 or nx >= len(m[0]):
                continue
            if m[ny][nx] == "#":
                continue
            if d[(nx, ny)] != 0xffffffff:
                continue
            d[(nx, ny)] = d[c] + 1
            q.append((nx, ny))
    return d

H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))

maxi = 0
for sx, sy in [(x, y) for x in range(0, W) for y in range(0, H)]:
    if S[sy][sx] == "#":
        continue
    d = bfs(S, (sx, sy))
    for x, y in [(x, y) for x in range(0, W) for y in range(0, H)]:
        if S[y][x] == "#":
            continue
        maxi = max(maxi, d[(x, y)])
print(maxi)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s1, s2;
  cin >> s1 >> s2;
  reverse(s2.begin(), s2.end());
  if (s1 == s2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  vector<i64> tmp = a;
  sort(tmp.begin(), tmp.end(), greater<i64>());
  for (i64 i = 0; i < n; i++)
    if (a[i] == tmp[0])
      cout << tmp[1] << endl;
    else
      cout << tmp[0] << endl;
  return 0;
}


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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int n, x[109];

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin >> n;
	rep(i, 0, n)
	{
		cin >> x[i];
	}
	int mini = LLONG_MAX, ans;
	rep(i, 0, 101)
	{
		int is = 0;
		rep(j, 0, n)
		{
			is += (x[j] - i) * (x[j] - i);
		}
		if (is < mini)
		{
			mini = is;
		}
	}
	cout << mini << endl;
	return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    string s; cin >> s;
    deque<char> sss;
    for(auto ch : s) sss.push_back(ch);

    int q; cin >> q;
    int revtime = 0;
    rep(_,q) {
        int z; cin >> z;
        if(z==1) {
            revtime++;
        }
        else {
            int f; cin >> f;
            if(f==1) {
                char ch; cin >> ch;
                if(revtime%2==0) sss.push_front(ch);
                else sss.push_back(ch);
            }
            else {
                char ch; cin >>ch;
                if(revtime%2==0) sss.push_back(ch);
                else sss.push_front(ch);
            }
        }
    }
//    cout << sss.size() << '\n';




    string ans;
    rep(i,sss.size()) ans.push_back('o');
    if(revtime%2==0) {
        for(int i = 0; i < sss.size(); ++i) ans[i] = sss[i];
    }else {
        for(int i = 0; i < sss.size(); ++i) ans[i] = sss[sss.size() - i - 1];
    }
    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 1368
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,ans[101010];
map<int,map<int,int> > m; 
vi ed[101010];
void dfs(int x,int y,int c){
	int cg=1;
	fo(i,0,ed[x].size()) if(ed[x][i]!=y){
		if(cg==c)cg++;
		ans[m[x][ed[x][i]]]=cg;
		dfs(ed[x][i],x,cg);
		cg++;
	}
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n-1){
		int u,v;
		cin>>u>>v;
		u--;v--;
		ed[u].pb(v);
		ed[v].pb(u);
		m[u][v]=m[v][u]=i;
	}
	int num=0;
	fo(i,0,n)num=max(num,(int)ed[i].size());
	cout<<num<<endl;
	dfs(0,-1,-1);
	fo(i,0,n-1)cout<<ans[i]<<endl;
	return 0;
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int x, y;
  cin >> x >> y;
  cout << ((y & 1 || y < x * 2 || y > x * 4) ? "No" : "Yes");

  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define MAXN 505
 int num[26];


int main()
{
    string s;

    cin>>s;
    for(int i=0;i<s.size();i++){
        if(num[s[i]-'a']==0)num[s[i]-'a']=1;
        else{cout<<"no"<<endl;return 0;}
    }
    cout<<"yes"<<endl;
    return 0;
}


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

#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define LL long long
#define PII pair<int , int>
#define PLL pair<long long , long long>
#define INPUT freopen("/Users/amrfahmy/Documents/Problem solving/CF/CF/input.txt", "r", stdin);
using namespace std;
 
const LL MOD = 1000000007;
LL n,q,c,cnt,mx,m,temp,k;
string str;

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){
    return (a.first < b.first);
}

int main()
{
    cin>>n>>k;
    LL r , s , p;
    cin>>r>>s>>p;
    cin>>str;
    LL ans=0;
    vector<LL> score(n , 0);
    for(int i = 0 ; i < k ; i++){
        if(str[i]=='r'){
            score[i]=p;
        }else if(str[i]=='p'){
            score[i]=s;
        }else if(str[i]=='s'){
            score[i]=r;
        }
    }
    for(int i = (int) k ; i < n ; i++){
        if(str[i]=='r'){
            score[i]=p;
        }else if(str[i]=='p'){
            score[i]=s;
        }else if(str[i]=='s'){
            score[i]=r;
        }
        if(score[i]==score[i-k]  && str[i] == str[i - k])score[i]=0;
    }
    for(int i = 0 ; i < n ; i++){
        ans+=score[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();

      System.out.println(f(A - 1, B));
    }
  }

  public static long f(long a, long b) {
    return f(a) ^ f(b);
  }

  // f(a) = f(0, a)
  public static long f(long a) {
    long pair = (a + 1) / 2;

    if (pair % 2 == 1) {
      if (a % 2 == 0) {
        return 1 ^ a;
      } else {
        return 1; 
      }
    } else {
      if (a % 2 == 0) {
        return a; // 0 ^ a = a
      } else {
        return 0; 
      }
    }
  }
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
int a[110000];
signed main() {
    cin >> N >> M;
    rep(i, N) {
        cin >> a[i];
        a[i] /= 2;
    }
    int LCM = 1;
    rep(i, N) { LCM = lcm(LCM, a[i]); }
    rep(i, N) {
        if (LCM / a[i] % 2 != 1) { fin(0); }
    }
    cout << (M / LCM + 1) / 2 << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
int Q;
void func()
{
    string S, L = "", R = "";
    cin >> S;
    cin >> Q;
    int T[Q];
    int ans(0);
    rep(i, 0, Q)
    {
        cin >> T[i];
        if (T[i] == 1)
        {
            ++ans;
        }
        if (T[i] == 2)
        {
            int f;
            char tmp;
            cin >> f >> tmp;
            // if (f == 1 && ans % 2 == 0)
            //     S = tmp + S;
            // if (f == 1 && ans % 2 == 1)
            //     S.push_back(tmp);
            // if (f == 2 && ans % 2 == 0)
            //     S.push_back(tmp);
            // if (f == 2 && ans % 2 == 1)
            //     S = tmp + S;
            if (f == 1 && ans % 2 == 0)
                L.push_back(tmp);
            if (f == 1 && ans % 2 == 1)
                R.push_back(tmp);
            if (f == 2 && ans % 2 == 0)
                R.push_back(tmp);
            if (f == 2 && ans % 2 == 1)
                L.push_back(tmp);
        }
    }
    rep(i, 0, L.size() / 2)
    {
        swap(L[i], L[L.size() - i - 1]);
    }
    S = L + S + R;
    if (ans % 2)
    {
        rep(i, 0, S.size() / 2)
        {
            swap(S[i], S[S.size() - i - 1]);
        }
    }
    cout << S << '\n';
}
int main()
{
    func();
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<vector<ll>> dp(k, vector<ll>(n, LLINF));
    REP(i, n) dp[0][i] = -a[i];
    FOR(i, 1, k) {
        // cout << "i=" << i << endl;
        // スライド最大値
        deque<ll> deq;
        deq.push_back(0);
        FOR(j, 1, n) {
            // cout << "j=" << j << " deq=";
            // for(auto d: deq) cout << d << " ";
            // cout << endl;
            dp[i][j] = dp[i-1][deq.front()] - (i+1)*a[j];

            while(deq.size() && dp[i-1][deq.back()] >= dp[i-1][j]) {
                deq.pop_back();
            }
            deq.push_back(j);

            if(deq.size() && deq.front() == j-m) {
                deq.pop_front();
            }
        }
    }

    // REP(i, k) cout << dp[i] << endl;

    ll ret = 0;
    REP(i, n) chmax(ret, -dp[k-1][i]);
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 238320
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
#include <set>

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }

int main(){
  while(true){
    const int n = getInt();
    const int m = getInt();

    if(n + m == 0) break;

    const int MAX = 100000;
    vector<vector<int> > g(n, vector<int>(n, MAX));
    vector<vector<int> > dp(n, vector<int>(3, -1));

    REP(i,m){
      const int a = getInt() - 1;
      const int b = getInt() - 1;
      const int c = getInt();

      g[a][b] = min(g[a][b], c);
      g[b][a] = min(g[b][a], c);
    }

    typedef pair<int, pair<int, int> > data;
    priority_queue<data, vector<data>, greater<data> > pq;

    pq.push(make_pair(0, make_pair(0, 0)));

    while(pq.size()){
      const data d = pq.top(); pq.pop();
      const int cost = d.first;
      const int pos  = d.second.first;
      const int cnt  = d.second.second;

      if(cnt != 1 && pos == n - 1){
        printf("%d\n", cost);
        break;
      }

      if(dp[pos][cnt] != -1) continue;
      dp[pos][cnt] = cost;

      REP(i,n) if(g[pos][i] != MAX){
        if(cnt == 1){
          if(dp[i][2] == -1){
            pq.push(make_pair(cost, make_pair(i, 2)));
          }
        }else{
          if(cnt == 0){
            if(dp[i][1] == -1){
              pq.push(make_pair(cost, make_pair(i, 1)));
            }
          }
          if(dp[i][cnt] == -1){
            pq.push(make_pair(cost + g[pos][i], make_pair(i, cnt)));
          }
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let a = BigInt(input[0][0], 10);
    let b = BigInt(input[0][1], 10);
    let c = BigInt(input[0][2], 10);
    let d = BigInt(input[0][3], 10);
    let ans = a * c;
    if (ans < a * d) ans = a * d;
    if (ans < b * c) ans = b * c;
    if (ans < b * d) ans = b * d;
    console.log(ans.toString());

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29684
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


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<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(b, n*a) << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
template<typename ll_t,ll_t mod>
class basic_modint{
public:
    ll_t x_;
    basic_modint(ll_t x=0):x_((x%mod+mod)%mod){}
    basic_modint& operator+=(const basic_modint a)       { if((x_+=     a.x_)>=mod)x_-=mod; return *this; }
    basic_modint& operator-=(const basic_modint a)       { if((x_+= mod-a.x_)>=mod)x_-=mod; return *this; }
    basic_modint& operator*=(const basic_modint a)       { (x_*=a.x_)%=mod; return *this; }
    basic_modint  operator+ (const basic_modint a) const { basic_modint res(*this); return res+=a; }
    basic_modint  operator- (const basic_modint a) const { basic_modint res(*this); return res-=a; }
    basic_modint  operator* (const basic_modint a) const { basic_modint res(*this); return res*=a; }
    basic_modint  pow(ll_t t) const { if(t==0)return 1; basic_modint a = pow(t>>1); a*=a; if(t%2==1)a*=(*this); return a; }
    basic_modint  inv() const { return pow(mod-2); }
    basic_modint& operator/=(const basic_modint a)       { return (*this) *= a.inv(); }
    basic_modint  operator/ (const basic_modint a) const { basic_modint res(*this); return res/=a; }
    friend istream& operator>>(istream& ist, basic_modint& a) { ist>>a.x_; return ist; }
    friend ostream& operator<<(ostream& ost, basic_modint& a) { ost<<a.x_; return ost; }
};
using mint = basic_modint<ll,ll(1e9+7)>;
mint x[401][401]={},dp[401][401]={},const_pow[401][401];
int main(){
    int n,c;
    cin >> n >> c;
    vector<int> a(n),b(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep2(i,1,401){
        const_pow[i][0]=1;
        rep2(j,1,c+1)const_pow[i][j]=const_pow[i][j-1]*i;
    }
    //x[i][j]=a[i]^j+...+b[i]^j
    rep(i,n)rep(j,c+1)rep2(k,a[i],b[i]+1)x[i][j]+=const_pow[k][j];
    //dp[i][j]=i変数j次の単項式の和
    dp[0][0]=1;
    rep2(i,1,n+1){
        rep(j,c+1){
            rep(k,j+1){
                dp[i][j]+=dp[i-1][k]*x[i-1][j-k];
            }
        }
    }
    cout << dp[n][c] << endl;
    return 0;
}

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int b=0;
  for(int i=0;i<N;i++){
    if((i+1)%2==1 && S.at(i)=='L'){
      b=1;
    }
    if((i+1)%2==0 && S.at(i)=='R'){
      b=1;
    }
  }
  if(b==1){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

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

const int INF = 1e8;

int main(){
    int d, g;// (difficulty, goal)
    cin >> d >> g;

    vector<int> p(d), c(d);// (100 * (i+1) pts.) * p[i] problems + (complete bonus)
    for(int i=0; i<d; i++){
        cin >> p[i] >> c[i];
    }

    int ans = INF;
    for(int bit=0; bit<(1<<d); bit++){
        int score   =  0;
        int number  =  0;
        int maxleft = -1;
        for(int i=0; i<d; i++){
            if(bit>>i & 1){
                score  += 100 * (i+1) * p[i] + c[i];
                number += p[i];
            }else{
                maxleft = i;
            }
        }
        if(score < g){
            int more = (g - score + 100 * (maxleft+1) - 1) / (100 * (maxleft+1));
            if(more >= p[maxleft]) continue;
            number += more;
        }
        ans = min(ans, number);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%s", $S);

$Slen = strlen($S);
$ans = 0;

for ($i = 0; $i < $Slen-1; $i++) {
    if ($S[$i] != $S[$i+1]) $ans++;
}

echo $ans . PHP_EOL;


Measured memory_bytes: 3704
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
s = 0
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(d):
            s += abs(x[i][k] - x[j][k]) ** 2
        if s ** 0.5 == int(s ** 0.5):
            cnt += 1
        s = 0
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int h;
int b[10][5];

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

	while(cin >> h, h) {
		memset(b, 0, sizeof b);
		for(int y = 0; y < h; y++) {
			for(int x = 0; x < 5; x++) {
				cin >> b[y][x];
			}
		}

		int ans = 0;
		bool flag = true;
		while(flag) {
			flag = false;
			for(int y = 0; y < h; y++) {
				for(int len = 5; len >= 3; len--) {
					for(int s = 0; s + len <= 5; s++) {
						if(b[y][s] == 0) continue;
						bool same = true;
						for(int x = s; x < s + len - 1; x++) {
							same &= b[y][x] == b[y][x + 1];
						}
						if(same) {
							flag = true;
							ans += b[y][s] * len;
							for(int x = s; x < s + len; x++) {
								b[y][x] = 0;
							}
						}
					}
				}
			}

			for(int y = h - 1; y >= 1; y--) {
				for(int x = 0; x < 5; x++) {
					if(b[y][x] == 0) {
						int ny = y;
						while(ny >= 0 && b[ny][x] == 0) ny--;
						if(ny >= 0) {
							swap(b[ny][x], b[y][x]);
						}
					}
				}
			}
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 3152