akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<int> > a(n,vector<int>(n));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> a.at(i).at(j);
    }
  }

  vector<vector<int> > s(n+1,vector<int>(n+1));
  for(int i=0;i<n+1;i++) s.at(i).at(0) = 0;
  for(int i=0;i<n+1;i++) s.at(0).at(i) = 0;
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
      s.at(i).at(j) = s.at(i).at(j-1) + a.at(i-1).at(j-1);
    }
  }

  vector<vector<int> > t(n+1,vector<int>(n+1));
  for(int i=0;i<n+1;i++) t.at(i).at(0) = 0;
  for(int i=0;i<n+1;i++) t.at(0).at(i) = 0;
  for(int j=1;j<n+1;j++){
    for(int i=1;i<n+1;i++){
      t.at(j).at(i) = t.at(j).at(i-1) + s.at(i).at(j);
    }
  }

  int ans = t.at(1).at(1);
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
      for(int k=1;k<=i;k++){
        for(int l=1;l<=j;l++){
          ans = max(t.at(i).at(j)-t.at(i).at(l-1)-t.at(k-1).at(j)+t.at(k-1).at(l-1),ans);
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3284
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

signed main(void){
  string s;
  cin >> s;
  char c = 'a';
  for(c = 'a'; c <= 'z'; c++){
    int cnt = 0;
    REP(i,s.size()){
      if(s[i] == c){
	cnt++;
      }
    }
    if(cnt>0)
      if(cnt%2!=0){
	cout << "No" << endl;
	return 0;
      }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  ll a,b,c;
  
  cin>>a>>b>>c;
  
  Ans(c>a+b && 4*a*b<(c-(a+b))*(c-(a+b)));
}

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

int main() {
  int N;
  cin >> N;
  set<string> st;
  string sp;
  for (int i = 0; i < N; i++) {
    string sn;
    cin >> sn;
    if (st.count(sn) || (i > 0 && sn[0] != sp[sp.size()-1]) ) {
      cout << "No" << endl;
      return 0;
    }
    st.insert(sn);
    sp = sn;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int a,b,c,d;

bool f()
{
    while(true){
        c-=b;
        if(c<=0)return true;
        a-=d;
        if(a<=0)return false;
    }
}

int main()
{
    cin>>a>>b>>c>>d;
    cout<<(f()?"Yes":"No");
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define INT 1.01

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

    ll X; // llと比較して実行時間が大幅に速い (2205ms->2ms)
    cin >> X;

    ll v = 100;
    //while(true){ //while, for文では実行時間は変わらない
    rep(ret, INF){
        if(X<=v){
            cout << ret << endl;
            break;
        }
        //v *= INT; // 実行時間が2ms->6msへと伸びる
        v += 0.01*v;
    }

    //cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();int K=in();
	int x[n],y[n];
	for(int i=0;i<n;i++){x[i]=in();y[i]=in();}
	int ans=4e18;int ct=0;
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	{
		if(x[i]>=x[j])continue;
		
		for(int k=0;k<n;k++)
		for(int l=0;l<n;l++)
		{
			if(y[k]<=y[l])continue;
			ct=0;
			for(int g=0;g<n;g++)
			{
				if(x[i]<=x[g] and x[g]<=x[j] and y[l]<=y[g] and y[g]<=y[k])ct++;
			}
			if(ct>=K)ans=min(ans,(x[j]-x[i])*(y[k]-y[l]));
		}	
	}
	cout<<ans;
	
}


Measured memory_bytes: 3620
#!/usr/bin/env python3
n = int(input())
# 4/N = 1/h+1/n + 1/w を満たすh,n,wを求めよ
# h,n,wは3500いかになる解が存在することは保証
# h,n,wを全探索で回したいがTLEなので、それを効率化して治める
# 順序は付けれるのでh<=n<=wとして良い
# ２つを固定できると二分探索を使って、O(log3500)に落とすことはできるが、それでも足りない
# 整数論的に考えると、ab+bc+ca/abcが4/nになるので
# gcd(ab+bc+ca,abc)がNがそれなりに大きい時結構大きくないといけないことがわかる。
# 解説をみるとh,nを固定するとwは一意に定まるので3500**2のオーダーでいける
for a in range(1,3501):
    for b in range(1,3501):
        if 4*a*b-n*b-n*a == 0: continue
        w = n*a*b/(4*a*b-n*b-n*a)
        # 整数判定
        if w == int(w) and w > 0:
            print(a,b,int(w))
            exit()

Measured memory_bytes: 40812
N=int(input())
A=list(map(int,input().split()))
V=max(A)
mod=998244353
data=[0]*(V+1)
data[1]=1
for i in range(2,V+1):
    data[i]=-(mod//i)*data[mod%i]%mod
for i in range(1,V+1):
    for j in range(2,V//i+1):
        data[i*j]=(data[i*j]-data[i])%mod
lst=[0]*(V+1)
for a in A:
    lst[a]+=1
mod_2=pow(2,mod-2,mod)
ans=0
for i in range(1,V+1):
    sum_1=0
    sum_2=0
    for j in range(1,V//i+1):
        zzz=i*j
        sum_1+=zzz*lst[zzz]
        sum_2+=zzz**2*lst[zzz]
    ans=(ans+(sum_1**2-sum_2)*data[i]*mod_2)%mod
print(ans)

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

int main(void){
    int i,n,s[1000];
    double h,sum;
    
    while(1){

        scanf("%d",&n);
        if(!n) break;
        
        sum = 0;
        h = 0;
        
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum += s[i];
        }
    
        sum /= n;
    
   //     printf("%lf ",sum);
        
        for(i=0;i<n;i++){
            h += pow(s[i]-sum, 2.0);
        }
            
        h /= n;

   //     printf("%lf ",h);

        printf("%lf\n",pow(h,1.0/2.0));
    
    }
    
    return 0;
}


 



Measured memory_bytes: 2052
package main

import (
	"fmt"
)

func main() {
	var t, s string
	fmt.Scan(&s)
	fmt.Scan(&t)

	n := 0
	T := []rune(t)
	for i, a := range s {
		if a != T[i] {
			n++
		}
	}
	fmt.Println(n)
}


Measured memory_bytes: 5308
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int ans = 0;
ll n;

int cnt_k(string s){
	set<char> st;
	rep(i,s.size())st.insert(s[i]);
	return st.size();
}

void dfs(string s){
	if(s.size()>11)return ;
	if(atoll(s.c_str())>n)return;
	if(cnt_k(s)==3){ans++;}
	dfs(s+'7'); dfs(s+'3'); dfs(s+'5');
}

int main(){
	cin>>n;
	dfs("");
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int R = cin.nextInt();
	  int D = cin.nextInt();
	  long init = cin.nextInt();
	  for( int i = 0; i < 10; ++i ) {
		  init = Math.max(0, init * R - D);
		  System.out.println(init);
	  }
  }

}


Measured memory_bytes: 20948
/*
Original problem: https://atcoder.jp/contests/dp/tasks/dp_b
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)


#define PII pair<int,int>
#define PLL pair<ll,ll>

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const int inf = 1e9+7;
namespace SOLVE {
	void main() {
        // dp[i] is min(dp[i-x] + c) for x in (1, k)
        int n, k;
        cin >> n >> k;
        VI A(n);
        VI dp(n); // dp[i] is the cost to land on i

        REP(i, 0, n) {
            cin >> A[i];
        }

        dp[0] = 0;

        REP(i, 1, n) {
            int best = inf;
            REP(x, 1, k+1) {
                if (i - x >= 0) {
                    best = min(best, dp[i-x] + abs(A[i] - A[i-x]));
                }
            }
            dp[i] = best;
        }

        cout << dp[n - 1] << endl;

    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int imos[100005]; CLR(imos);
  FOR(i,0,N) {
    int a, b; cin >> a >> b;
    imos[a]++;
    imos[b+1]--;
  }
  int ans = 0;
  FOR(i,0,N+2) {
    imos[i+1] += imos[i];
    if(imos[i] >= i - 1) {
      ans = max(ans, i - 1);
    }
  }
  cout << ans << endl;
  return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int N,W;
  cin >> N >> W;
  int w[N],v[N];
  for(int i=0;i<N;i++){
    cin >> w[i] >> v[i];
  }
  int64_t dp[N+1][W+1] = {};
  
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      if(w[i]>j) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}




Measured memory_bytes: 82460
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 998244353;

void main() {
    auto N = readln.chomp.to!int;
    auto P = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    int parity = abs(P[0][0] + P[0][1]) % 2;

    foreach (p; P) {
        if (abs(p[0] + p[1]) % 2 != parity) {
            writeln(-1);
            return;
        }
    }

    int M = 32;
    long[] D = M.iota.map!(i => 1L << i).array;
    if (parity == 0) D = 1 ~ D;
    D.length.writeln;
    D.map!(to!string).join(" ").writeln;
    D.reverse();


    foreach (p; P) {
        long x = p[0];
        long y = p[1];
        dchar[] ans;
        foreach (d; D) {
            if (abs(x) >= abs(y)) {
                if (x >= 0) {
                    x -= d;
                    ans ~= 'R';
                } else {
                    x += d;
                    ans ~= 'L';
                }
            } else {
                if (y >= 0) {
                    y -= d;
                    ans ~= 'U';
                } else {
                    y += d;
                    ans ~= 'D';
                }
            }
        }
        ans.reverse();
        ans.writeln;
    }
}


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

int main() {
	int n;
	cin>>n;
	
	vector<double> probs(n);
	for(auto &p: probs) cin>>p;
	
	vector<vector<double> > grid(n+1, vector<double>(n+1));
	grid[1][0] = 1-probs[0];
	grid[1][1] = probs[0];
	
	for(int i=2; i<=n; i++) {
		grid[i][0] = grid[i-1][0]*(1-probs[i-1]);
		grid[i][i] = grid[i-1][i-1]*probs[i-1];
	}
	
	for(int i=2; i<=n; i++) {
		for(int j=1; j<i; j++) {
			grid[i][j] = grid[i-1][j-1]*probs[i-1] + grid[i-1][j]*(1-probs[i-1]);
		}
	}
	
	double final_res = 0;
	for(int i=n/2+1; i<=n; i++) final_res+=grid[n][i];
	cout<<fixed<<setprecision(10)<<final_res<<endl;
	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

bool cmpPair(const std::pair<int, int> &l, const std::pair<int, int> &r)
{
    return l.second>r.second;
}

int main()
{
    typedef unsigned long long ull;
    ull n,m;
    std::cin>>n>>m;
    std::vector<ull> a(n);
    std::vector<std::pair<int,int> > c(m);
    for (int i=0; i<n; i++) std::cin>>a[i];
    std::vector<ull> tmp(n);
    for (ull i=0; i<m; i++)
        std::cin>>c[i].first>>c[i].second;
    std::sort(a.begin(),a.end());
    std::sort(c.begin(),c.end(),cmpPair);
    ull k=0;
    for (int i=0; i<m; i++)
    {
        while (c[i].second>a[k] && c[i].first)
        {
            if (c[i].second>a[k]) a[k++]=c[i].second;
            c[i].first--;
        }
    }
    ull s=0;
    for (int i=0; i<n; i++) s+=a[i];
    std::cout<<s;
    return 0;
}


Measured memory_bytes: 5576
from math import log10

N = int(input())
d = int(log10(N))+1
ans = (d-1)*9 + max(0, N//10**(d-1)-1)
if (N+1)%10**(d-1) == 0:
    ans = max(ans, N//10**(d-1)+(d-1)*9)
print(ans)





Measured memory_bytes: 3060
#!/usr/bin/env python3
#SoundHound C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m,d = LI()
ans = 0
if d == 0:
    for i in range(m-1):
        ans += n/pow(n,2)
    print(ans)
else:
    for i in range(m-1):
        ans += (2*(n-d))/pow(n,2)
    print(ans)


Measured memory_bytes: 40172
import sys
input = sys.stdin.buffer.readline

def find_cycle(adj, start = 0):
    """
    有効グラフ上で、0-indexedが前提の実装。
    あれば、適当なサイクルをリストで返す。
    参考1: https://qiita.com/drken/items/a803d4fc4a727e02f7ba
    参考2: https://qiita.com/Kiri8128/items/2b0023bed9af642c751c
    """
    global arrived, finished
    stack = [~start, start]
    history = []
    while stack:
        v = stack.pop()
        if v >= 0:
            arrived[v] = True
            history.append(v)
            for nv in adj[v]:
                if not arrived[nv]:
                    stack.append(~nv)
                    stack.append(nv)
                elif not finished[nv]: #arrived but not finished -> a cycle exists.
                    index = history.index(nv)
                    return history[index:]
        else:
            finished[~v] = True
            history.pop()
    return []

N, M = map(int, input().split())
adj = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    adj[A-1].append(B-1)


arrived = [False] * N
finished = [False] * N
while False in arrived:
    start = arrived.index(False)
    cycle = find_cycle(adj, start)
    if cycle:
        break

if not cycle:
    print(-1)
    exit()
else:
    cycle_updated = True
    while cycle_updated:
        cycle_updated = False
        cycle_index = {v:i for i, v in enumerate(cycle)}
        l = len(cycle)
        for i, v in enumerate(cycle):
            cv = cycle[i+1-l]
            for nv in adj[v]:
                if nv != cv and nv in cycle_index:
                    cycle_updated = True
                    j = cycle_index[nv]
                    if i < j:
                        cycle = cycle[:i+1] + cycle[j:]
                    else:
                        cycle = cycle[j:i+1]
                    break
            if cycle_updated:
                break
    print(len(cycle))
    print(*[elem+1 for elem in cycle], sep = '\n')
    

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

/**
 * Prime Number II
 */
public class Main {

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

		int N = 50000;
		int overN;
		boolean[] prims;

		// prim number of over 50000
		for (int i = N + 1; ; i++) {
			int count = 0;
			for (int j = 2; j < i; j++) {
				if (i % j == 0) {
					count++;
					break;
				}
			}
			if (count == 0) {
				overN = i;
				break;
			} else {
				continue;
			}
		}

		prims = new boolean[overN + 1];
		for (int i = 2; i < overN / 2 + 1; i++) {
			if (!prims[i]) {
				for (int j = 2; j < overN / i + 1; j++) {
					prims[i * j] = true;
				}
			}
		}

		int primU = 0, primL = 0;
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			//U
			for (int i = n + 1; ; i++) {
				if (!prims[i]) {
					primU = i;
					break;
				}
			}
			//L
			for (int i = n - 1; ; i--) {
				if (!prims[i]) {
					primL = i;
					break;
				}
			}
			System.out.println(primL + " " + primU);
		}
	}
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> dp(n + 1, 0);
  dp[n] = 1;
  for(int i = n - 1; i >= 0; i--)
  {
    if(i <= n - 5)
    {
      string t = s.substr(i, 5);
      if(t == "dream" || t == "erase") dp[i] |= dp[i + 5];
    }
    if(i <= n - 6)
    {
      string t = s.substr(i, 6);
      if(t == "eraser") dp[i] |= dp[i + 6];
    }
    if(i <= n - 7)
    {
      string t = s.substr(i, 7);
      if(t == "dreamer") dp[i] |= dp[i + 7];
    }
  }
  if(dp[0] == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 848
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);
    int x=0, y=0;
    for(int i=0; i<n; i+=2) {
        x += a[i];
        if(i!=n-1) y += a[i+1];
    }
    cout << abs(x-y) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
 
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000
 
using namespace std;
 
int main(void) {
	int total;
	int n;
	cin >> n;
 
	for(int i=1;i*i<=n;i++) {
		total = i*i;
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b, c, d, e, n;
	cin>>a>>b>>c>>d>>e;
	if(a==0) n=b-1;
	if(b==0) n=a+1;
	if(c==0) n=b+1;
	if(d==0) n=c+1;
	if(e==0) n=d+1;
	cout<<n;
	return 0;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
#define int long long int

int gcd(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  while (b != 0) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

void solve() {
  int N, X;
  cin >> N >> X;

  vector<int> v(N);
  for (auto &x : v) {
    cin >> x;
  }
  v.push_back(X);
  sort(v.begin(), v.end());

  int d = v[1] - v[0];
  for (int i = 1; i < v.size() - 1; i++) {
    int n = v[i + 1] - v[i];
    d = gcd(d, n);
  }
  cout << d << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

int main(){
  int a[6] = {500,100,50,10,5,1};
  int n;
  while(std::cin>>n){
    if(!n)break;
    n=1000-n;
    int res = 0;
    for(int i=0;i<6;i++){
      res = res + n / a[i];
      n = n % a[i];
    }
    std::cout<<res<<std::endl;
  }
}

Measured memory_bytes: 0
a, b = map(int,input().split())
x, y = abs(a), abs(b)

if a >= 0:
    if b > 0:
        if a > b:
            ans = abs(x-y) + 2
        else:
            ans = abs(x-y)
            
    else:
        ans = abs(x-y) + 1

else:
    if b >= 0:
        ans = min(abs(x-y)+1, b - a)
    else:
        if b > a:
            ans = abs(x-y)
        else:
            ans = abs(x-y) + 2

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n;
    cin >> n;
    vector<i64> v(n);
    for (int i=0; i<n; ++i)
        cin >> v[i];
    std::sort(v.begin(), v.end(), std::greater<i64>());

    i64 ans{0};
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            for (int k=j+1; k<n; ++k) {
                if (v[i] < v[j]+v[k]) {
                    if (v[i]!=v[j] && v[j]!=v[k] && v[i]!=v[k])
                        ++ans;
                } else {
                    break;
                }
            }
        }
    }

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

Measured memory_bytes: 3628
#include<bits/stdc++.h>￼
using namespace std;
int main(){
  int n,p=0,q=0;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a,a+n);
  for(int i=0;i<n;i++){
    if(i%2==0)p+=a[i];
    else q+=a[i];
  }
  cout << abs(p-q);
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = [[""]*(w+2)]
for i in range(h):
    _s = list(input())
    _s.insert(0, "")
    _s.append("")
    s.append(_s)
s.append([""]*(w+2))

dx = [1, -1,  1,  0, -1,  1,  0, -1]
dy = [0,  0,  1,  1,  1, -1, -1, -1]

ans = [[float("inf")]*(w+2) for _ in range(h+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == "#":
            continue

        b = 0
        for _dx, _dy in zip(dx, dy):
            x = i+_dx
            y = j+_dy
            if s[x][y] == "#":
                b += 1

        ans[i][j] = b

for i in range(1, h+1):
    for j in range(1, w+1):
        print("#" if ans[i][j] == float("inf") else ans[i][j], end="")
    print()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
    int main(void){
        int N;
            cin >> N;
        vector<int> a(N, 0);
            for(int i = 0; i < N; i++){
                cin >> a.at(i);
            }
        int alice = 0;
        int bob = 0;
        int max = 0;
        int map = 0;
            for(int j = 0; j < N; j++){
                for(int k = 0; k < N; k++){
                    if(a.at(k) > max){
                        max = a.at(k);
                            map = k;
                    }
                }
                        if(j % 2 == 0){
                            alice += max;
                        }else{
                            bob += max;
                        }
                            max = 0;
                                a.at(map) = 0;
                //}
            }
                if(alice > bob){
                    cout << alice - bob;
                }else{
                    cout << bob - alice;
                }
    return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<(*i)<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;






int main() {
    
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;

    for(int i=l;i<r+1;i++){
        if(i%d==0)ans++;
    }
    fin(ans);
}



Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, a[11];
    cin >> n;
    int cnt = 0;
    REP(i, n)
    {
        cin >> a[i];
        cnt += a[i] % 2 == 0;
    }

    cout << (pow(3, n) - pow(2, cnt)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int> l;
    int x;
    for (int i=0;i<n;++i){
        cin>>x;
        l.push_back(x);
    }
    sort(l.begin(),l.end());
    int sum=0;
    for(int i=0;i<n-1;++i)
        sum+=l[i];
    if (sum>l.back())
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int n;
    cin >> n;
    int ans;
    ans = n % 1000;
    if(!ans) ans = 0;
    else ans = 1000 - ans;
    cout << ans << endl;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    vector<int> a = h;
    sort(a.begin(), a.end());
    //座圧 -> id 復元 -> res
    map<int, int> id;
    map<int, int> res;
    int now = 1;
    for (int i = 0; i < n; i++){
        if (id[a[i]] == 0) {
            id[a[i]] = now;
            res[now] = a[i];
            now++;
        }
    }
    long long INF = 1e15;
    //dp[みた数][とった数][前の数]
    vector<vector<vector<long long>>> dp(n + 1, vector<vector<long long>>(n - k + 1, vector<long long>(n + 1, INF)));
    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= n - k; j++){
            for (int m = 0; m <= n; m++){
                if (dp[i][j][m] == INF) continue;
                dp[i + 1][j][m] = min(dp[i + 1][j][m], dp[i][j][m]);
                if (j == n - k) continue;
                dp[i + 1][j + 1][id[h[i]]] = min(dp[i + 1][j + 1][id[h[i]]], dp[i][j][m] + max(0, h[i] - res[m]));
            }
        }
    }
    long long ans = INF;
    for (int i = 0; i <= n; i++) ans = min(ans, dp[n][n - k][i]);
    cout << ans << endl;
}

Measured memory_bytes: 216832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,res=0;
    scanf("%d",&n);
    n*=2;
    vector<int>arr(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr.begin(),arr.end());
    for(int i=0;i<n;i+=2)
    {
        res+=arr[i];
    }
    printf("%d",res);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define MAX 1000005
#define MAX_NIGHTS 301
#define MOD 998244353
#define EPS 0
int main()
{
    long long int a,c,b;
    scanf("%lld %lld %lld",&a,&b,&c);
    if(c-a-b<=0)
    {
        printf("No");
        return 0;
    }
    long long int rhs=c-a-b;
    rhs=rhs*rhs;
    long long int lhs=a*b*4;
    if(rhs>lhs)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 256
# encoding: utf-8
Sd = input()
T = input()

LSd = len(Sd)
LT = len(T)

ans = "UNRESTORABLE"
for i in range(LSd - LT + 1):
    for si, ti in zip(Sd[LSd - LT - i: LSd - i], T):
        if si != ti and si != "?": break
    else:
        ans = Sd[:LSd - LT - i].replace("?", "a") + T + Sd[LSd - i:].replace("?", "a")
        break

print(ans)
        

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

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

map<string,int> ma;

int main(){
	int n,m;
	cin>>n;
	rep(i,n){
		string tmp;
		cin>>tmp;
		ma[tmp]=1;
	}
	cin>>m;
	int lock=0;
	rep(i,m){
		string tmp;
		cin>>tmp;
		if(ma[tmp]==1){
			if(lock==0){
				cout<<"Opened by ";
				lock=1;
			}
			else{
				cout<<"Closed by ";
				lock=0;
			}
		}
		else{
			cout<<"Unknown ";
		}
		cout<<tmp<<endl;
	}
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (b % a) cout << b - a << endl;
    else cout << b + a << endl;
    return 0;
}


Measured memory_bytes: 256
a = []
for i in range(5):
    inp = int(input())
    a.append(inp)

b = []
for i in range(len(a)):
    k = int(a[i] / 10)
    sel = abs((k+1)*10 -a[i])
    if sel ==10:
        b.append(0)
    else:
        b.append(sel)
    
order_list= sorted(range(len(b)), key=lambda k: b[k])

count = 0
for i in range(len(order_list)):
    count += a[order_list[i]]
    remain = int(count %10)
    if remain != 0 and i != len(order_list)-1:
        count += (10- remain)

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int a = 0; int b = 100000;
	cin >> a;
	for (int i = 0; i < a; i++)
	{
		b += (b / 20);
		while (b % 1000 != 0)
		{
			b++;
		}
	}
	cout << b << endl;

	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A+B;
  int R = C+D;
    
  if (L < R) cout << "Right" << endl;
  else if (L > R) cout << "Left" << endl;
  else cout << "Balanced" << endl;
}

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

int main(){
    int x;
    cin>>x;
    int n1=x/500;
    x%=500;
    int n2=x/5;
    x%=5;
    n1*=1000;
    n2*=5;
    cout<<n1+n2<<endl;
    return 0;
}

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

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

int main(){
    long long x;
    cin>>x;

    long long res=0;

    for(long long i=1;;i++){
        res+=i;
        if(res>=x){
            cout<<i<<endl;
            return 0;
        }
    }


}

Measured memory_bytes: 256
class Array
  def +(ary)
    self[0] += ary[0]
    self[1] += ary[1]
    self
  end
end
hash = {"A": [0, 0], "B": [0, 0], "C": [0, 0], "D": [0, 0]}
until (ary = gets) == nil
  eyesight = ary.split.map(&:to_f)
  eyesight.each_with_index do |item, index|
    case
    when item >= 1.1
      hash[:A] += index == 0 ? [1, 0] : [0, 1]
    when item >= 0.6
      hash[:B] += index == 0 ? [1, 0] : [0, 1]
    when item >= 0.2
      hash[:C] += index == 0 ? [1, 0] : [0, 1]
    when item < 0.2
      hash[:D] += index == 0 ? [1, 0] : [0, 1]
    end
  end
end
hash.each {|k, v| puts v.join(" ")}

Measured memory_bytes: 8636
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

 
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n;
	
	cin >> n;
	
	int a[n+5];
	
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int cnt = 0;
	
	for(int i = 1; i < n-1; i++){
		if(a[i] != min({a[i], a[i-1], a[i+1]}) && a[i] != max({a[i], a[i-1], a[i+1]})) cnt++;
	}
	
	cout << cnt << "\n";
	
	return 0;
}


Measured memory_bytes: 256
// AOJ
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	int a, b, c;
	for(; n > 0; n--){
		scanf("%d %d %d", &a, &b, &c);
		if(a*a == b*b+c*c || b*b == a*a+c*c || c*c == a*a+b*b)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 580
N, M = gets.chomp.split().map(&:to_i)
a = gets.chomp.split().map(&:to_i).sort
bc = M.times.map { gets.chomp.split().map(&:to_i) }.sort_by { |b, c| -c }
ct = 0

bc.each do |b, c|
  while ct < N && b > 0 && c > a[ct]  do
    a[ct] = c
    b -= 1
    ct += 1
  end
end

puts a.inject(:+)

Measured memory_bytes: 20448
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 2e9
const int maxn=500000+10;
int n;
int a[maxn];
int L[maxn/2+2],R[maxn/2+2];
int cnt=0;
void merge(int a[],int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=a[left+i];
    for(int i=0;i<n2;i++) R[i]=a[mid+i];
    L[n1]=R[n2]=INF;
    int i=0,j=0;
    for(int k=left;k<right;k++)
    {
        cnt++;
        if(L[i]<=R[j])
        {
            a[k]=L[i];
            i++;
        }
        else
        {
            a[k]=R[j];
            j++;
        }
    }


}
void merge_sort(int a[],int left,int right)
{
    if(right-left>1)
    {
        int mid=(left+right)/2;
        merge_sort(a,left,mid);
        merge_sort(a,mid,right);
        merge(a,left,mid,right);
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    merge_sort(a,0,n);
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n",cnt);

    return 0;
}

Measured memory_bytes: 7036
#include <bits/stdc++.h>
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
using namespace std;
int main(){
    int D, T, S;
    cin >> D >> T >> S;
    if(1.0*D/S <= T) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

// x番目のゴーレムをk番目のマスに移動させられるか確認する
bool checkLeft(int x, int k, string &s, vector<char> &t, vector<char> &d)
{
	for(int i = 0; i < t.size(); ++i)
	{
		if(t[i] == s[x])
		{
			x += (d[i] == 'L' ? -1 : 1);
		}

		if(s[x] == '_')
		{
			return x == k;
		}
	}

	return false;
}

int main()
{
	int n, q;
	string s;

	cin >> n >> q;
	cin >> s;

	s = "_" + s + "_";

	vector<char > t(q);
	vector<vector<char> > d(2, vector<char>(q));
	for(int i = 0; i < q; ++i)
	{
		cin >> t[i] >> d[0][i];
		d[1][i] = (d[0][i] == 'L' ? 'R' : 'L');
	}

	int golem = n;
	for(int i = 0; i < 2; ++i)
	{
		int lb = 0, m, ub = n + 1;
		while(ub - lb > 1)
		{
			m = (ub + lb) / 2;
			(checkLeft(m, 0, s, t, d[i]) ? lb : ub) = m;
		}

		reverse(s.begin(), s.end());

		golem -= lb;
	}

	cout << golem << endl;
}

Measured memory_bytes: 1280
def read_input():
    n = int(input())
    plist = list(map(int, input().split()))

    return plist


def submit():
    plist = read_input()

    count = 0
    for p1, p2, p3 in zip(plist, plist[1:], plist[2:]):
        if p1 < p2 < p3:
            count += 1
        elif p3 < p2 < p1:
            count += 1

    print(count)
    return


if __name__ == '__main__':
    submit()


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int n, i;
  cin >> n >> i;
  int res = n - i + 1;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(n-1,0));
    rep(i,n)rep(j,n-1) {cin>>a[i][j];a[i][j]--;}
    vector<int> now(n,0);
    int ans=-1;
    int cnt=1;
    while(cnt){
        cnt=0;
        vector<bool> bat(n,false);
        rep(i,n){
            if(now[i]==n-1) continue;
            int op=a[i][now[i]];
            if(bat[op] || bat[i]) continue;
            if(a[ op ][ now[op] ] != i) continue;
            cnt ++;
            now[i] ++;
            now[op] ++;
            bat[i] =true;
            bat[op]=true;
        }
        ans ++;
    }
    rep(i,n){
        if(now[i]<n-1){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 7512
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0

for i in range(N-1,-1,-1):
	if A[i+1] + A[i] <= B[i]:
		count += A[i+1] + A[i]
		A[i] = 0
	elif A[i+1] <= B[i]:
		count += B[i]
		A[i] -= B[i] - A[i+1]
	else:
		count += B[i]
print(count)


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

const ll N = 2e5 + 5;
vector<ll>adj[N];
ll C[N];

void dfs(ll n, ll A, ll p){
    C[n] += A;
    for(auto x : adj[n]){
        if(x != p){
            dfs(x,C[n],n);
        }
    }
}

void doit(){
    ll n, i, q, x, y;
    cin >> n >> q;
    rep(i,0,n-1){
        cin >> x >> y;
        adj[x-1].pb(y-1);
        adj[y-1].pb(x-1);
    }
    while(q--){
        cin >> x >> y;
        C[x-1] += y;
    }
    dfs(0,0,-1);
    rep(i,0,n){
        cout << C[i] << " ";
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(500005);

int main() {
  int n, m;
  cin >> n >> m;
  mint ans = 0;
  rep(i, n+1) {
    mint temp = c(n, i);
    temp *= c.p(m-i, n-i);
    if (i&1) temp = -temp;
    ans += temp;
  }
  ans *= c.p(m, n);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 10944
while 1:
    n=int(input())
    if n==0:break
    dp=[1]+[0]*3000
    for i in range(n):
        a,b=map(int,input().split())
        for j in range(1001,-1,-1):
            for k in range(1,b+1):
                dp[j+a*k]+=dp[j]
    for _ in range(int(input())):
        print(dp[int(input())])


Measured memory_bytes: 5652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] a = new int[n];
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if(flag) {
				if(s[i] == 'C') {
					a[i] += 1;
					flag = false;
				}else if(s[i] == 'A') flag = true;
				else flag = false;
			}else {
				if(s[i] == 'A') flag = true;
			}
			a[i] += (i>0)?a[i-1]:0;
		}
		int l = 0, r = 0;
		for (int i = 0; i < q; i++) {
			l = sc.nextInt()-1;
			r = sc.nextInt()-1;
			if(l == 0) {
				System.out.println(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				System.out.println(a[r]-a[l-1]-n);
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 68200
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from operator import mul
from functools import reduce

input = sys.stdin.readline

def cmb(n,r):
    r = min(n-r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def comb(a, b):
    n = a
    for _ in range(b):
        n -= 1
        a *= n

    for i in range(1, b):
        b *= i
    return int(a / b)


def main():
    n = int(input())
    m = {}
    for l in sys.stdin:
        s = ''.join(sorted(l.strip()))
        if s in m:
            m[s] += 1
        else:
            m[s] = 1
    cnt = 0
    for k, v in m.items():
        if v == 1:
            continue
        if v == 2:
            cnt += 1
        else:
            cnt += cmb(v, 2)
    print(cnt)

main()


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

seta = set(a)

counta = {a : 0 for a in seta}

for i in a:
    if i in seta:
        counta[i] += 1

lines = [i for i in counta.keys() if counta[i] >= 2]

if len(lines) >= 1:
    countsameValue = 0
    a = max(lines)
    secondmax = 0
    for l in lines:
       if(l != a):
           secondmax = max(secondmax, l)

    if (counta[a] > 3):
        print(a**2)
    else:
        print(a * secondmax)
else:
    print(0)


Measured memory_bytes: 23692