akhauriyash/Code-Regression huggingface dataset:
/*
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculations
*/
/*
*/
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,0),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n;
    cin>>n;
    vector<int> v(n);
    f(i,n)
    {
        cin>>v[i];
    }
    sort(all(v));
    int diff=v[n/2]-v[n/2-1];
    cout<<diff<<endl;
}



Measured memory_bytes: 4224
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, K = map(int, input().split())

ans = 0
for k in range(K, N + 2):
    min_ = k * (k - 1) // 2 % MOD
    max_ = k * (2 * N - k + 1) // 2 % MOD
    # print (max_, min_)
    ans = (ans + max_ - min_ + 1) % MOD

print (ans)

Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

int n,m;

void solve(){
  cin >> n >> m;
  int ans=1;
  for(int i=1;i*i<=m;i++){
    if(m%i!=0)continue;
    if(i<=m/n)ans=max(i,ans);
    if(m/i<=m/n)ans=max(m/i,ans);
  }
  cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()

	x := sc.ReadInt()
	n := sc.ReadInt()

	ps := make([]int, n)
	for i := 0; i < n; i++ {
		ps[i] = sc.ReadInt()
	}

	numRemoved := make([]bool, 102)
	for _, p := range ps {
		numRemoved[p] = true
	}

	minDelta := 105
	minNum := 0
	for i := 0; i <= 101; i++ {
		if numRemoved[i] {
			continue
		}
		delta := Abs(x - i)
		if delta < minDelta {
			minDelta = delta
			minNum = i
		}
	}

	fmt.Println(minNum)
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1764
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<LL>res;

int main()
{
	in >> N;
	res.push_back(2);
	res.push_back(1);
	for (int i = 2; i <= N; ++i)
	{
		res.push_back(res[i - 1] + res[i - 2]);
	}
	out << res[N] << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long int
using namespace std;

int main(){
    string s;
    ll n;
    int ans;
    char cnt;
    cin>>s>>n;
    for(int i=0;i<s.length();i++){
        if(s[i]!='1'){
            ans = i+1;
            cnt = s[i];
            break;
        }
    }
    if(n<ans){
        cout<<"1"<<endl;
    }else{
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def knapsack_weight(single=True):
    """
    重さが小さい時のナップサックDP
    :param single: True = 重複なし
    """
    """ dp[weight <= W] = 重さを固定した時の最小価値 """
    weight_max = max(weight_list)
    price_max = max(price_list)
    W2 = W + weight_max
    dp_max = float("inf")  # 総和価値の最大値
    dp = [dp_max] * W2
    dp[0] = 0               # 重さ 0 の時は価値 0

    for item in range(N):
        if single:
            S = range(W2, weight_list[item] - 1, -1)
        else:
            S = range(weight_list[item], W2)
        for weight in S:
            dp[weight] = min2(dp[weight], dp[weight - weight_list[item]] + price_list[item])
    return min(dp[w] for w in range(W, W2))

#######################################################################################################
import sys
input = sys.stdin.readline


def max2(x, y):
    """ pythonの組み込み関数 max は2変数に対しては遅い！！ """
    if x > y:
        return x
    else:
        return y

def min2(x, y):
    """ pythonの組み込み関数 min は2変数に対しては遅い！！ """
    if x < y:
        return x
    else:
        return y


W, N = map(int, input().split())                                # N: 品物の種類 W: 重量制限

price_list = []
weight_list = []
for _ in range(N):
    """ price と weight が逆転して入力されている場合有り """
    weight, price = map(int, input().split())
    price_list.append(price)
    weight_list.append(weight)


print(knapsack_weight(single=False))


############################################################################################


Measured memory_bytes: 73828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll q, b, e;
    cin >> q;
    rep(i, q) {
        cin >> b >> e;
        reverse(a.begin() + b, a.begin() + e);
    }

    rep(i, a.size() - 1) {
        cout << a[i] << " ";
    }
    cout << a[a.size() - 1] << endl;
}


Measured memory_bytes: 3236
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int a1=sc.nextInt();
        int a2=sc.nextInt();
        int a3=sc.nextInt();
        int sum=a1+a2+a3;

        if(sum>=22){
            System.out.println("bust");
        }
        else{
            System.out.println("win");
        }
    }
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

ll dp[110][110][500];

signed main() {
    // dp[i][j][k]: i(1~N)番目までのアイテムを使い、重さが w_0 *j + k のときの最大の価値
    rep(i,0,110) rep(j,0,110) rep(k,0,500) dp[i][j][k]=-1;

    ll N, W;
    cin>>N>>W;
    vector<ll> w(N+1),v(N+1);
    rep(i,1,N+1)
        cin>>w[i]>>v[i];
    
    dp[0][0][0]=0;
    
    rep(i,1,N+1) rep(j,0,110) rep(k,0,500) {
        if (dp[i-1][j][k]!=-1){
            dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k]);
            // printf("i=%d w=%d -> dp=%d\n", i, w[1]*j+k, dp[i][j][k]);

            dp[i][j+1][k + w[i] - w[1] ] = max(dp[i][j+1][k + w[i] - w[1] ],  dp[i-1][j][k] + v[i]);
            // printf("i=%d w=%d -> dp=%d\n", i, w[1]*(j+1) + k+w[i]-w[1],dp[i][j+1][k + w[i] - w[1] ]);
        }
    }
    
    ll ans = 0;
    rep(j,0,110) rep(k,0,500) {
        if (w[1]*j + k <= W){
            ans = max(ans, dp[N][j][k]);
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 47488
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(_t) ll _t;cin>>_t;while(_t--)
ll max(ll a,ll b) {
    return a>b?a:b;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,ans=0;cin>>n;ll a[n];
    f(i,0,n) cin>>a[i];
    f(i,0,n-1) {ans+=max(0,a[i]-a[i+1]);
        if(a[i]>a[i+1]) a[i+1]=a[i];           
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5144
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int table[105][105];
int check(int i, int j){
  for(int a=i-1; a<i+2; a++){
    for(int b=j-1; b<j+2; b++){
      if(table[a][b]==1){
        table[a][b]=0;
        check(a,b);
      }
    }
  }
  return 0;
}
int main(){
  int w,h;
  while(1){
    cin >> w >> h;
    if(w==0 && h==0) break;
    table[w+2][h+2]={};
    rep(i,h) rep(j,w) cin >> table[i+1][j+1];
    rep(i,h+1){
      rep(j,w+1){
        if(table[i][j]==1){
          table[i][j]=2;
          check(i,j);
        }
      }
    }
    int count=0;
    for(int i=1; i<h+1; i++) for(int j=1; j<w+1; j++) if(table[i][j]==2) count++;
    cout << count << endl;
    /*rep(i,h+2){
      rep(j,w+2) cout << table[i][j] << " ";
      cout << endl;
    }*/
  }
  return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n, z, w, ans;
    cin >> n >> z >> w;

    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    if(n == 1) {
        ans = abs(a[0] - w);
    }
    else {
        ans = max(abs(a[n-1] - w), abs(a[n-2] - a[n-1]));
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e6;
ll comb[1005][1005]={0};
vector<ll> node[1005];
void comb_set(ll n){
  comb[1][0]=1;
  comb[1][1]=1;
  for(int i=2;i<=n;i++){
    comb[i][0]=1;
    for(int j=1;j<=n;j++) comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
  }
}
P dfs(int pos){
  if(node[pos].size()==0){
    return P(1,1);
  }
  ll node_num=0,ans=1;
  vector<P> son_data;
  for(int i=0;i<node[pos].size();i++){
    int son=node[pos][i];
    son_data.push_back(dfs(son));
    node_num+=son_data[i].second;
  }

  ll ret2=node_num+1;

  int n=son_data.size();
  for(int i=0;i<n;i++){
    ans*=comb[node_num][son_data[i].second];
    ans%=mod;
    ans*=son_data[i].first;
    ans%=mod;
    node_num-=son_data[i].second;
  }

  return P(ans,ret2);
}
int main(){
  ll n;
  cin>>n;
  comb_set(n);

  bool lose[1005];
  for(int i=0;i<1005;i++) lose[i]=true;

  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    lose[b]=false;
    node[a].push_back(b);
  }

  int st;
  for(int i=1;i<=n;i++) if(lose[i]) st=i;

  cout<<dfs(st).first<<endl;
}



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

using namespace std;

using LL = long long;

const int N = (int)2e5 + 5, A = (int)1e6 + 5, mod = 998244353;
int n, num[A], mulSum[A];

int add(int _a, int _b) {
    _a += _b;
    if (_a >= mod) _a -= mod;
    return _a;
}
int sub(int _a, int _b) { return add(_a, mod - _b); }
int mul(int _a, int _b) { return (int)( (LL)_a * _b % mod); }

int binPow(int _a, int _n) {
    int ret = 1;
    for (; _n; _n >>= 1, _a = mul(_a, _a) ) if (_n & 1) ret = mul(ret, _a);
    return ret;
}

int main() {
    scanf("%d", &n);
    while (n --) {
        int a; scanf("%d", &a);
        ++num[a];
    }

    for (int i = 1; i < A; ++i) {
        int sum = 0;
        for (int j = i; j < A; j += i) if (num[j]) {
            mulSum[i] = add(mulSum[i], mul(mul(j, j), (int)( (LL)num[j] * (num[j] - 1) / 2 % mod) ) );
            mulSum[i] = add(mulSum[i], mul(mul(j, sum), num[j]) );
            sum = add(sum, mul(j, num[j]) );
        }
    }

    for (int i = A - 1; i > 0; --i) {
        for (int j = (i << 1); j < A; j += i) mulSum[i] = sub(mulSum[i], mulSum[j]);
    }

    int ans = 0;
    for (int i = 1; i < A; ++i) {
        ans = add(ans, mul(binPow(i, mod - 2), mulSum[i]) );
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 8064
using System;
using System.Text;

namespace CGL_2_C_CrossPoint
{
	class Program
	{
		static void Main ( string[] args )
		{
			int inputCount = int.Parse (Console.ReadLine ());
			StringBuilder output = new StringBuilder (inputCount * 10 * 2);

			for (int lp = 0; lp < inputCount; lp++)
			{
				decimal[] inputNum = Array.ConvertAll (Console.ReadLine ().Split (' '), decimal.Parse);

				Vector2 point1 = new Vector2 (inputNum[0], inputNum[1]);
				Vector2 point2 = new Vector2 (inputNum[2], inputNum[3]);
				Vector2 point3 = new Vector2 (inputNum[4], inputNum[5]);
				Vector2 point4 = new Vector2 (inputNum[6], inputNum[7]);

				Vector2 result = Vector2.CrossPoint (point1, point2, point3, point4);

				output.Append (result.X);
				output.Append (" ");
				output.Append (result.Y);
				output.AppendLine ();
			}

			Console.Write (output);
		}
	}

	class Vector2
	{
		public Vector2 ( decimal x, decimal y )
		{
			this.X = x;
			this.Y = y;
		}

		public decimal X { private set; get; }
		public decimal Y { private set; get; }

		public static Vector2 operator + ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X + ob2.X, ob1.Y + ob2.Y);
		}
		public static Vector2 operator - ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X - ob2.X, ob1.Y - ob2.Y);
		}
		public static Vector2 operator * ( Vector2 ob, decimal scalar )
		{
			return new Vector2 (ob.X * scalar, ob.Y * scalar);
		}

		public static decimal CrossProduct ( Vector2 line1, Vector2 line2 )
		{
			return line1.X * line2.Y - line1.Y * line2.X;
		}

		public static Vector2 CrossPoint ( Vector2 line1Point1, Vector2 line1Point2, Vector2 line2Point1, Vector2 line2Point2 )
		{
			Vector2 baseLine = line2Point2 - line2Point1;

			Vector2 line1 = line1Point1 - line2Point1;
			Vector2 line2 = line1Point2 - line2Point1;

			decimal distance1 = Math.Abs (Vector2.CrossProduct (baseLine, line1));
			decimal distance2 = Math.Abs (Vector2.CrossProduct (baseLine, line2));

			decimal ratio = distance1 / (distance1 + distance2);

			return line1Point1 + (line1Point2 - line1Point1) * ratio;
		}
	}
}

Measured memory_bytes: 9780
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a,b,ct=0;
	cin>>a>>b;
	map<int,int> m;
	int t[100];
	memset(t,-1,sizeof(t));
	int flag=0;
	forr(i,0,b)
	{
		int x,y;
		cin>>x>>y;
		if(!m.count(x))	
		{
			m[x]=y;
			t[x]=y;
		}
		else
		{
			int z=m[x];
			if(z!=y)
			{flag=1; 
			}
		}
	}
	if(t[1]==0 and a>1) flag=1;
	if(flag)
	{
		cout<<-1; return 0;
	}
	if(a==1 or a==0)
	{
		if(t[1]==-1)	cout<<0;
		else
			cout<<t[1];
		return 0;
	}
	forr(i,0,a)
	{
		if(t[i+1]==-1 and i==0)	cout<<1;
		else if(t[i+1]==-1 and i>0)	cout<<0;
		else cout<<t[i+1];
	}
	
	return 0;	
}

Measured memory_bytes: 256
dp = 21.times.map{ 11.times.map{ [0] * 156 } }

(1..20).each do |n|
  (1..10).each do |j|
    (1..155).each do |k|
      dp[n][j][k] += dp[n - 1][j][k]
      dp[n][j][n + k] += dp[n - 1][j - 1][k] if n + k <= 155
    end
  end
  dp[n][1][n] = 1
end
 
loop do
  n, k, s = gets.split.map(&:to_i)
  break if n == 0
  p dp[n][k][s]
end

Measured memory_bytes: 8936
#include <iostream>
int binarySerch(int *S, int n, int key){
    int left = 0;
    int right = n;
    int mid;
    while(left<right){
        mid = (left + right) / 2;
        if(S[mid]==key){
            return mid;
        }else if(S[mid]<key){
            left = mid + 1;
        }else{
            right = mid;
        }
    }
    return -1;
}

int main(){
    int n,q,cnt=0;
    std::cin >> n;
    int S[n];
    for(int i=0;i<n;i++){
        std::cin >> S[i];
    }
    std::cin >> q;
    int T[q];
    for(int i=0;i<q;i++){
        std::cin >> T[i];
    }

    for(int i=0;i<q;i++){
        if(binarySerch(S,n,T[i])!=-1){
            cnt++;
        }
    }

    std::cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 3672
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300IQ as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N+1];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i+1] = Integer.parseInt(st.nextToken());
         int[] pos = new int[N+1];
         for(int i=0; i < N; i++)
            pos[arr[i+1]] = i+1;
         TreeSet<Integer> active = new TreeSet<Integer>();
         active.add(0); active.add(N+1);
         long res = 0L;
         for(int v=N; v >= 1; v--)
         {
            int loc = pos[v];
            int left = active.floor(loc-1);
            int right = active.ceiling(loc+1);
            int farleft = 0;
            int farright = N+1;
            if(left > 0)
               farleft = active.floor(left-1);
            if(right < N+1)
               farright = active.ceiling(right+1);
            long cnt = (long)(left-farleft)*(right-loc);
            cnt += (long)(farright-right)*(loc-left);
            //cnt -= (long)(right-loc)*(loc-left);
            res += cnt*v;
            active.add(loc);
         }
         System.out.println(res);
      }
   }

Measured memory_bytes: 47264
#include <bits/stdc++.h>
using namespace std;
string s,w; 
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='B'){
			if(w.size()>0)w.erase(w.size()-1,1);
		}
		else w.push_back(s[i]);
	}
	cout<<w;
	return 0;
}

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

using namespace std;

#define int long long

void solve(){
    int n;
    cin>>n;
    vector<int> arr(n,0);

    for (int i = 0; i < n; i++)
    {
        cin>>arr[i];
    }
    int min_stool=0,prev_max=arr[0];
    for (int i = 1; i < n; i++){
        if(arr[i]<prev_max){
            min_stool+=prev_max-arr[i];
        }else{
            prev_max=arr[i];
        }
    }

    cout<<min_stool<<endl;

    
}

signed main(){
    int t=1;
    for (int i = 0; i < t; i++)
    {
        solve();
    }
    
    return 0;
}

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

#define INF 1e9
int a[500010],mem[500010];

int main(){
	string s;
	char c;
	int index, tmp;
	long long ans;
	
	index = ans = 0;
	
	cin>>s;
	for(int i=1;i<s.size();i++)	if(s[i-1] != s[i])
			mem[index++] = i;
	mem[index++] = s.size();
	
	for(int i=0;i<index;i++){
		tmp = 0;
		if(s[mem[i-1]] == '<')
			for(int j=mem[i-1];j<=mem[i];j++)
				a[j] = max(a[j], tmp++);
		else
			for(int j=mem[i];j>=mem[i-1];j--)
				a[j] = max(a[j], tmp++);
	}
	
	for(int i=0;i<=s.size();i++){
		ans += a[i];
		//cout<<a[i]<<" ";
	}
	
	cout<<ans;
	
} 

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

int main() {
  
  string N,M;
  int a=0;
  
  cin>>N>>M;

   for(int i=0; i<3; i++){
     if(N.at(i)==M.at(i)){a++;}}
     
	cout<<a<<endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto N = readInt();
		if(N == 0) {
			return;
		}
		auto WH = readInts();
		auto W = WH[0];
		auto H = WH[1];
		auto m = new int[][](W, H);
		for(int i; i < N; ++i) {
			auto xy = readInts();
			m[xy[0]-1][xy[1]-1] = 1;
		}
		auto st = readInts();
		auto s = st[0];
		auto t = st[1];
		auto dp = new int[][](W, H);
		for(int i; i < H; ++i) {
			for(int j; j < s; ++j) {
				dp[0][i] += m[j][i];
			}
			for(int j = 1; j+s-1 < W; ++j) {
				dp[j][i] = dp[j-1][i] - m[j-1][i] + m[j+s-1][i];
			}
		}
		auto dp2 = new int[][](W, H);
		for(int i; i < W; ++i) {
			for(int j; j < t; ++j) {
				dp2[i][0] += dp[i][j];
			}
			for(int j = 1; j+t-1 < H; ++j) {
				dp2[i][j] = dp2[i][j-1] - dp[i][j-1] + dp[i][j+t-1];
			}
		}
		int ans;
		for(int i; i < W; ++i) {
			for(int j; j < H; ++j) {
				ans = max(dp2[i][j], ans);
			}
		}
		writeln(ans);
	}
}

Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(q);
    int cnt = 0;
    for(;q--;){
      ll d;
      scanf("%lld", &d);
      d = d * 2 + 1;
      if((d & 1) == 0){
        ++cnt; continue;
      }
      ll t;
      for(t = 3;t * t <= d;t+=2){
        if(d % t == 0)break;
      }
      if(t * t > d)++cnt;
    }
    pri(cnt);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define SW 0
typedef long long ll;
using namespace std;
int scnt,tcnt,n,ans;
char a[200100];
void input()
{
    scanf("%s",&a[1]);
    n=strlen(&a[1]);
}
void process()
{
    int i;
    for(i=1;i<=n;i++){
        if(a[i]=='T'){
            if(scnt>0){
                scnt--;
                ans++;
            }
        }
        else
            scnt++;
    }
    printf("%d",n-ans*2);
}
void output()
{

}
int main()
{
#if SW==1
freopen("input.txt","r",stdin);
#endif // SW
    input();
    process();
    output();
    return 0;
}




Measured memory_bytes: 384
import copy

H, W, K = map(int, input().split())

hw = []
for _ in range(H):
    tmp = list(input())
    hw.append(tmp)

ans = 0
for hi in range(2**H):
    tmp_hw = copy.deepcopy(hw)
    for hj in range(H):
        if ((hi >> hj) & 1):
            # bitが立っている時の操作
            for i in range(W):
                tmp_hw[hj][i] = 'x'

    tmp_cnt = 0
    for i in range(H):
        tmp_cnt += tmp_hw[i].count('#')
    if tmp_cnt < K:
        continue

    for wi in range(2**W):
        tmp_hw2 = copy.deepcopy(tmp_hw)
        for wj in range(W):
            if ((wi >> wj) & 1):
                # bitが立っている時の操作
                for i in range(H):
                    tmp_hw2[i][wj] = 'x'
        cnt = 0
        for i in range(H):
            cnt += tmp_hw2[i].count('#')
        if cnt == K:
            ans += 1
print(ans)


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

int main() {
    int N, Q;
    cin >> N >> Q;

    vector<int> a(N + 1), b(N + 1);
    for (int i = 1; i <= N; ++i) a[i] = b[i] = N;

    ll black = ll(N - 2) * (N - 2);

    int H = N, W = N;

    while (Q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            if (x < W) {
                for (int i = x; i < W; ++i) {
                    b[i] = H;
                }
                W = x;
            }
            black -= b[x] - 2;

        } else {
            if (x < H) {
                for (int i = x; i < H; ++i) {
                    a[i] = W;
                }
                H = x;
            }
            black -= a[x] - 2;
        }
    }
    cout << black << endl;

    return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    bool arr = false;
    int Q;
    cin >> Q;
    S.reserve(S.size()+Q+10);
        REP(i,Q){
            int T,F;
            char C;
            cin >> T;
            if(T==1)arr= !arr;
            else{
                cin >> F>> C;
                if(F-1^arr==0) S.insert(S.begin(),C);
                else S.append(1,C);
            }
                            
        }
        if(arr == true)reverse(S.begin(),S.end());
        cout << S << "\n";
        return 0;
    }

Measured memory_bytes: 1004
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = numeric_limits<ll>::max();

int main(){
    double R;
    cin >> R;
    cout << 2 * M_PI * R << endl;

    return 0;
}


Measured memory_bytes: 3788
MAX_PLACE = 2019
def sugoroku(N, X, M, A):
    X.append(MAX_PLACE + 1)
    for a in A:
        if(X[a - 1] + 1 == X[a]):
            pass
        else:
            X[a-1] += 1
    X.pop()
    for i in range(N):
        print(X[i])

#sugoroku(3, [2, 3, 6], 2, [1, 3])
#sugoroku(2, [1, 2016], 4, [2,2,2,2])
#sugoroku(4, [1001, 1002, 1003, 1004], 7, [1, 2, 3, 4, 3, 2, 1])

def main():
    N = int(input())
    X = list(map(int, input().split()))
    M = int(input())
    A = list(map(int, input().split()))
    sugoroku(N, X, M, A)

main()


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const int inf = 1<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main () {
  int N; cin >> N;
  vi x(N), y(N), h(N); rep(i,N) cin >> x[i] >> y[i] >> h[i];

  int MAX = 100;

  rep(Cy,MAX+1) {
    rep(Cx,MAX+1) {
      int needH = -1;
      rep(i,N) {
        if(h[i] > 0) {
          int tmp = h[i] + abs(Cy-y[i]) + abs(Cx-x[i]);
          if(needH == -1) {
            needH = tmp;
          }
          else {
            if(needH != tmp) {
              needH = -2;
              break;
            }
          }
        }
      }

      if(needH == -2) continue;

      rep(i,N) {
        if(h[i] == 0) {
          int dist = abs(Cy-y[i]) + abs(Cx-x[i]);
          if(needH > dist) {
            needH = -2;
            break;
          }
        }
      }
      if(needH == -2) continue;

      cout << Cx << " " << Cy << " " << needH << endl;
      return 0;
    }
  }

}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    let mut v = sc.vec::<u32>(3);
    v.sort();

    print!("{}", v[0]);
    for x in &v[1..] {
        print!(" {}", x);
    }
    println!();
}

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }
}



Measured memory_bytes: 5032
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

bool between(int x, int y1, int y2) {
	if(y1 > y2) swap(y1, y2);
	if(x % 3 == 1) {
		 if(y2 - y1 >= 2) return true;
	}
	return false;
}

int extra(int x1, int y1, int x2, int y2) {
	int res = 0;
	int three = 1;
	rep(i, 32) {
		if(x1 / three == x2 / three and between(x1 / three, y1 / three, y2 / three)) {
			int tmp = min(min(x1 % three, x2 % three) + 1, min(three - x1 % three, three - x2 % three));
			chmax(res, tmp);
		}
		three *= 3;
	}
	return res;
}

int dist(int x1, int y1, int x2, int y2) {
	return abs(x1 - x2) + abs(y1 - y2) + 2 * max(extra(x1, y1, x2, y2), extra(y1, x1, y2, x2));
}

void solve() {
	int q; cin >> q;
	rep(i, q) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		-- a, -- b, -- c, -- d;
		cout << dist(a, b, c, d) << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string s;
int lim,n;
int mn[305][305][26],mx[305][305][26],dp[305][305][155];
int rec(int a,int b,int c){
	if(dp[a][b][c] >= 0) return dp[a][b][c];
	if(a>b) return 0;
	int &ret = dp[a][b][c];
	int len = (a==b?1:2);
	if(c) ret=max(ret,rec(a+1,b-1,c-1)+len);
	for(int k=0;k<26;k++){
		if(mx[a][b][k] == -INF) continue;
		int d = mn[a][b][k]-a;
		int e = b-mx[a][b][k];
		d = min(d,e);
		int len = (mn[a][b][k]==mx[a][b][k]?1:2);
		ret = max(ret,len+rec(mn[a][b][k]+1,mx[a][b][k]-1,c-min(c,d))+min(c,d)*2);
	}
	return ret;
}
int main(){
	cin>>s>>lim;
	n = s.size();
	rep(a,305)rep(b,305)rep(c,26){
		mn[a][b][c] = INF;
		mx[a][b][c] = -INF;
	}
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			for(int k=i;k<=j;k++){
				mx[i][j][s[k]-'a'] = max(mx[i][j][s[k]-'a'],k);
				mn[i][j][s[k]-'a'] = min(mn[i][j][s[k]-'a'],k);
			}
		}
	}
	lim = min(n/2+1,lim);
	rep(a,305)rep(b,305)rep(c,155)dp[a][b][c] = -INF;
	cout << rec(0,n-1,lim) << endl;
}

Measured memory_bytes: 75520
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int		main(void)
{
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if (u == s)
		a--;
	else
		b--;
	cout << a << " " << b << endl;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        a[x] = i;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << a[i] << " ";
    }
    cout << "\n";
    return 0;
}

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int main(){
    ll N;
    map<string, int> S;
    
    cin >> N;
    REP(i,0,N){
        string s;
        cin >> s;
        S[s]++;
    }
    ll max_val = 0;

    for(pair<string, ll> p : S){
        max_val = max(max_val, p.second);
    }

    for(pair<string, ll> p : S){
        if(p.second == max_val){
            cout << p.first << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 25216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <deque>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define x first
#define y second
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int work()
{
  int a , b  , c , k ;
  scanf("%d%d%d%d" , &a , &b , &c , &k) ;
  while(a >= b) {
    if(!k) break ;
    b *= 2 ;
    k -- ;
  }
  while(b >= c) {
    if(!k) break ;
    c *= 2 ;
    k -- ;
  }
  if(a < b && b < c) return 0 * puts("Yes") ;
  return 0 * puts("No") ;
}
int main()
{

  work() ;
  return 0 ;
}
/*
*/


Measured memory_bytes: 3168
#include <stdio.h>

int main(void) {
    int m,r,f;
    int x;

    while (1) {
        scanf("%d %d %d",&m,&r,&f);
        x=m+r;
        if(m == -1 && r == -1 && f== -1){
            break;
        }
    
    if (m == -1 || r == -1) {
        printf("F\n");
    }else if(x >= 80){
        printf("A\n");
    }else if(80 > x && x >= 65){
            printf("B\n");
    }else if(65 > x && x >= 50){
        printf("C\n");
    }else if(50 > x && x >=30){
        if(f>=50){printf("C\n");
    }else {
            printf("D\n");
          }
    }else if(30 > x){
        printf("F\n");
    }
    }
    return 0;
}

Measured memory_bytes: 584
#include <iostream>

int main(int argc, char const *argv[]) {

        int A,B,C,D;
        std::cin >> A >> B >> C >> D;

        if(C > B || D < A)
        {
            std::cout << 0 << '\n';
            return 0;
        }

        int min_push_time = std::max(A,C);
        int max_push_time = std::min(B,D);
        int answer = max_push_time - min_push_time;

        std::cout << answer << '\n';

        return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int n,k,a[55],i,s;

ll memo[55][55][55*50];

ll solve(int indx,int cnt,int curr){
	if(cnt>i)return 0;
	if(curr>s)return 0;
	if(indx==n){
		return ((s==curr) && (cnt==i));
	}
	ll &ret = memo[indx][cnt][curr];
	if(~ret)return ret;
	ret = solve(indx+1,cnt,curr)+solve(indx+1,cnt+1,curr+a[indx]);
	return ret;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
	scanf("%d %d",&n,&k);

	for(i=0;i<n;i++)scanf("%d",&a[i]);
	ll ans = 0;
	for(i=1;i<=n;i++){
		for(s = 0;s<=50*n;s++){
			if(((double)s/i) == k){
				memset(memo,-1,sizeof(memo));
				ans += solve(0,0,0);
			}
		}
	}
	printf("%lld\n",ans );
}		


Measured memory_bytes: 65280
#include<stdio.h>

int main(void)
{
    int n,ch_count=0;
    scanf("%d",&n);

    int p[n],i;

    for(i=0;i<n;i++)
    {
        scanf("%d",&p[i]);
        if(p[i]!=i+1)
        {
            ch_count++;
        }
    }

    if(ch_count<=2)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }

    return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int total = accumulate(a.begin(), a.end(), 0);
    float threshold = (float)total / (4 * m);

    vector<int> c;
    copy_if(a.begin(), a.end(), back_inserter(c), [=](int i){
        return (float)i >= threshold;
    });

    if(c.size() >= m)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
s = input().split(" ")
n = int(s[0])
m = int(s[1])
q = int(s[2])
path_list =[]
rank = [0 for i in range(n)]
multi = []

for i in range(q):
    sp = input().split(" ")
    path = [int(pstr) for pstr in sp]
    path_list.append(path)

par = [i for i in range(n)]



#union-find
#xの木の根を得る
def root_find(x):
    if par[x] != x:
        par[x] = root_find(par[x])
        return par[x]
    else:
        return x

#併合する
def unite(x,y):
    rx = root_find(x)
    ry = root_find(y)

    if rx != ry:
        if rank[x] > rank[y]:
            par[y] = rx
        elif rank[x] == rank[y]:
            par[y] = rx
            rank[x] += 1
        else:
            par[x] = ry


for i in range(q):
    a = path_list[i][0]
    b = path_list[i][1]
    c = path_list[i][2]
    
    if c == 0 :
        pa = root_find(a)
        pb = root_find(b)
        if pa != pb:
            unite(pa,pb)
    else:
        multi.append((a,b))
        

"""
だめなじょうけん
・a,bが木であるはずなのに閉路がある
・ありうる辺の上限よりもMが大きい、もしくは辺の下限N-1よりもMが小さい
"""

for a,b in multi:
    if root_find(a) == root_find(b):
        print("No")
        exit(0)
        
k = 0
for i in range(n):
    if root_find(i) == i:
        k += 1



if len(multi) > 0:
    min_edge = n

else:
    min_edge = n - 1

max_edge = n + k * (k - 3) // 2

if min_edge <= m <= max_edge:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 33128
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

s = input().strip()
t = input().strip()
n = len(s)
ans = 0
for i in range(n):
    if s[i] != t[i]:
        ans += 1
print(ans)
    


Measured memory_bytes: 73580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> ba(n,vector<int>(2));
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>ba[i][1]>>ba[i][0];
        sum+=ba[i][1];
    }
    sort(ba.begin(),ba.end(),greater<>());
    for(int i=0;i<n;i++){
        if(sum>ba[i][0]){
            cout<<"No"<<endl;
            return 0;
        }else{
            sum-=ba[i][1];
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define E "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAX = 1e18;
const int N = 2*1e5+10;

void solve()
{
    int n;
    cin>>n;
    vi dp(n+1,0), a(n+1,0);
    rep(i,1,n+1) cin>>a[i];
    dp[2]=abs(a[1]-a[2]);
    rep(i,3,n+1) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n]<<E;
}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    ll a,b,n;
    cin >> a >> b >>n;
    ll mini = min(b,n);
    ll ans = 0;
    if(a<b){
        ll maxi=0;
        if(mini%b==0)maxi=b-1;
        else maxi = mini%b;
        // rrep(i,mini){
        //     maxi=i;
        //     if(i%b==0)break;
        // }
        ans = ceil(a*maxi/b) - ceil(maxi/b)*a;
    }
    else{
        ll x1,x2;
        x1=x2 = 0;
        x1 = n;
        // rep(i,mini){
        //     x2 = i;
        //     if(i%b==0)break;
        // }
        if(mini%b==0)x2 = b-1;
        else x2 = mini%b;
        ans = max(ceil(a*x1/b) - ceil(x1/b)*a,ceil(a*x2/b) - ceil(x2/b)*a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636