akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,(n))
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	char b;
	cin >> b;
	switch (b) {
	case 'A':
		cout << 'T' << endl;
		break;
	case 'T':
		cout << 'A' << endl;
		break;
	case 'G':
		cout << 'C' << endl;
		break;
	case 'C':
		cout << 'G' << endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [[int(i) for i in input().split()] for i in range(2)]
list = [0 for i in range(n)]
for i in range(n):
    for j in range(i + 1):
        list[i] += a[0][0+j]
    for k in range(n - i):
        list[i] += a[1][i+k]
print(max(list))


Measured memory_bytes: 3060
n, m = gets.split.map(&:to_i)

pair = Struct.new("Pair", :a, :b)
ans = []
if n % 2 == 1
    l = 2
    r = n
    while l < r
        ans.push(pair.new(l,r))
        l += 1
        r -= 1
    end
else
    l = 1
    r = n
    flag = false
    while l < r
        if !flag && (r-l) <= n/2
            l += 1
            flag = true
        end
        ans.push(pair.new(l,r))
        l += 1
        r -= 1
    end
end

for i in 0...m do
    puts ans[i].a.to_s + " " + ans[i].b.to_s
end


Measured memory_bytes: 19776
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, k; cin >> n >> k;
  vector<int> h(n), dp(n, INF);
  rep(i, n) cin >> h[i];
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 1; j <= k; j++){
      if(i+j >= n)continue;
      dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << dp[n-1] << endl;
  system("pause");
}

Measured memory_bytes: 1272
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	s := getNextString(scanner)
	n := len(s)
	m := map[byte]int{
		'N': 0,
		'W': 0,
		'S': 0,
		'E': 0,
	}

	for i := 0; i < n; i++ {
		m[s[i]] = 1
	}

	if m['S']^m['N'] == 1 {
		fmt.Println("No")
		return
	}
	if m['E']^m['W'] == 1 {
		fmt.Println("No")
		return
	}
	fmt.Println("Yes")
	writer.Flush()
}


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

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

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    ll N, M; cin >> N >> M;
    vector<pair<ll, ll>> A(N);
    vector<pair<ll, ll>> B(M + 1);
    REP(i, N) {
        ll x, y; cin >> x >> y;
        A[i] = make_pair(x, y);
    }
    FOR(j, 1, M + 1) {
        ll x, y; cin >> x >> y;
        B[j] = make_pair(x, y);
    }
    REP(i, N) {
        ll sx = A[i].first, sy = A[i].second;
        ll ans = 0;
        ll min_d = INF;
        FOR(j, 1, M + 1) {
            ll tx = B[j].first, ty = B[j].second;
            ld d = abs(tx - sx) + abs(ty - sy);
            if(d < min_d) {
                min_d = d;
                ans = j;
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3580
n = int(input())
a = list(map(int, input().split()))
cost = [0]
for p in a:
	cost.append(cost[-1] + p)
def get_cost(l, r):
	return cost[r+1] - cost[l]

dp = [[float("inf") for _ in range(n)] for _ in range(n)]
for i, p in enumerate(a):
	dp[i][i] = 0

for g in range(1, n):
	for l in range(n-g):
		r = l + g
		for m in range(l, r):
			dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + get_cost(l, r))

#print(dp)
print(dp[0][n-1])

Measured memory_bytes: 49244
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli cur=100,ans=0;
    
    while(cur<n)
    {
        ans++;
        cur=cur+(cur/100);
    }
    cout<<ans;
    return 0;
}

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

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

const int INF = 1e9;
const int mod = 1e9+7;

ll zzz(ll a,ll b){
    ll aa = a,bb =b;
    if(a < b) swap(a,b);
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return aa/b*bb;
}

int main()
{
    int n;
    cin >> n;
    vector<ll> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];
    ll ans = t[0];
    for(int i = 1; i < n; i++){
        ans = zzz(ans,t[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())
B = list(map(int, sys.stdin.readline().rsplit()))

res = []
for _ in range(N):
    tmp = -1
    for i, b in enumerate(B):
        if i + 1 == b:
            tmp = i
    if tmp == -1:
        print(-1)
        exit()
    res.append(B.pop(tmp))

print("\n".join(map(str, res[::-1])))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)

bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
}
int gcd(int a, int b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 


//3111111111111111111111111111111


int dp[3100];




void solve(){


	ini(n);
	ini(n1);
	FOR(i,0,1132)dp[i] = -INF;
	dp[0] = 0;
	FOR(i,0,n){
		ini(x);
		ini(x1);
		for(int i1 = 1032;i1>=0;i1--){
			FOR(i2,1,x)dp[i1+i2] = max(dp[i1+i2],dp[i1]+i2*(i+1)*100);
			dp[i1+x] = max(dp[i1+x],dp[i1]+x*(i+1)*100+x1);
		}
	}
	FOR(i,0,1032){
		//out(dp[i]);
		if(dp[i]>= n1)return out(i);
	}
	













}

































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 +7;

int main() {
    

    ll n;
    cin >> n;
    
    cout << (n * (n - 1ll)) / 2ll << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const int inf = INT_MAX;
int n, k, q;
int A[2005], sorted_A[2005], temp[2005];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k >> q;
	int ans = inf;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
		sorted_A[i] = A[i];
	}
	sort(sorted_A, sorted_A + n);
	for (int i = 0; i < n; i++)
	{
		int begin = 0, end = 0;
		temp[0] = 0;
		while (begin <= end)
		{
			while (A[begin] < sorted_A[i] && begin<n)
			{
				begin++;
			}
			end = begin;
			while (A[end] >= sorted_A[i] && end<n)
			{
				end++;
			}
			if (end - begin >= k) {
				int *tmp = new int[end - begin + 1];
				for (int j = 0; j < end - begin; j++)
					tmp[j] = A[begin + j];
				sort(tmp, tmp + end - begin);
				for (int j = 0; j <= end - begin - k; j++)
					temp[++temp[0]] = tmp[j];
				delete[] tmp;
			}
			begin = end;
			if (end == n)break;
		}
		if (temp[0] >= q) {
			sort(temp + 1, temp + 1 + temp[0]);
			ans = min(ans, temp[q] - sorted_A[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int n;
string field[260];

bool isIn(int x, int y){
    return 0 <= x && x < n && 0 <= y && y < n;
}

int getLength(int x, int y, int dx, int dy){
    int count = 1;
    while(isIn(x+dx*count, y+dy*count) && field[y+dy*count][x+dx*count] == '1') count++;
    return count;
}

int main(){
    while(cin >> n, n){
        rep(i, n) cin >> field[i];

        int res = 0;
        rep(i, n) rep(j, n){
            if(field[j][i] == '1'){
                for(int k=-1; k <=0; k++)for(int l=-1; l <=1; l++){
                    if(k == 0 && l == 0) continue;
                    res = max(res, getLength(i, j, k, l));
                }
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1292
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Class1
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int A = int.Parse(Console.ReadLine());

        N %= 500;
        if (N <= A)
        {
            System.Console.WriteLine("Yes");
        }
        else
        {
            System.Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 27464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

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

    string s; cin >> s;
    int cnt1 = 0;
    int cnt2 = 0;

    rep(i,s.size()){
        if(i % 2 == 0) {
            if(s[i] == '1') cnt1++;
            if(s[i] == '0') cnt2++;
        }
        if(i % 2 == 1){
            if(s[i] == '1') cnt2++;
            if(s[i] == '0') cnt1++;
        }
    }
    cout << min(cnt1,cnt2) << endl;
    return 0;
}

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

int main(){
  int n,k;
  cin>>n>>k;
  vector<pair<int,int>> g;
  rep(i,n-2) for(int j=i+1;j<n-1;j++) g.pb({i,j});
  rep(i,n-1) g.pb({i,n-1});
  if(k>n*(n-1)/2-(n-1)){
    cout<<-1<<endl;
    return 0;
  }
  rep(i,k){
    g.erase(g.begin());
  }
  cout<<g.size()<<endl;
  rep(i,(int)g.size()) cout<<g[i].first+1<<" "<<g[i].second+1<<endl;
} 

Measured memory_bytes: 3696
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100
using namespace std;
int a[MAXN+5];
int main()
{
	int n,x;
	scanf("%d %d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int ans=0,i;
	for(i=1;i<=n;i++)
	{
		if(x>=a[i])
		{
			x-=a[i];
			ans++;
		}
		else
			break;
	}
	if(x!=0&&i==n+1)
		ans--;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
//const int mod = 998244353;
int add(int a, int b)
{
	a+=b;
	while(a>=mod) a-=mod;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%mod;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,mod-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}


void raushan_kumar(){
	init(1000);
	int a,b;cin>>a>>b;
	cout<<choose(a,2)+choose(b,2);
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<vector<int>> Graph;

int main() {

	int N, M;
	cin >> N >> M;

	priority_queue<int>a;

	rep(i, N) {
		int b;
		cin >> b;
		a.push(b);
	}

	rep(i, M) {
		int ma = a.top();
		a.pop();
		a.push(ma / 2);
	}

	long long ans = 0;
	rep(i, N) {
		ans += a.top();
		a.pop();
	}

	cout << ans << endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

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

map<long long,long long> prime_factor(long long n) {
    map<long long,long long> ret;
    for(long long i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main()
{
	ll ans=0,cnt=0;
	string s;
	cin >> s;
	rep(i,SIZE(s)){
		if(s[i]=='W'){
			ans+=i-cnt;
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
S=input()

A=list(S)

sets={}
for i in A:
    if i in sets:
        sets[i]+=1
    else:
        sets[i]=1

x_remove =S.replace("x","")

if len(x_remove)==1:
    central_index=S.index(x_remove)
    right_x=S[:central_index].count("x")
    left_x=S[central_index:].count("x")
    
    if right_x >= left_x:
        print(right_x-left_x)
    else:
        print(left_x - right_x)

elif len(x_remove)%2==1:
    central_index =len(x_remove)//2 

    if x_remove[:central_index] == x_remove[-central_index:][::-1]:
        string=x_remove[:central_index]
        
        left=S
        left_count=[]
        
        right=S[::-1]
        right_count=[]
        
        l_count=0
        r_count=0
            
        for i in right:
            if i=="x":
                r_count+=1
            else:
                right_count.append(r_count)
                r_count=0
                if len(right_count)==central_index+1:
                    break

        for i in left:
            if i=="x":
                l_count+=1
            else:
                left_count.append(l_count)
                l_count=0
                if len(left_count)==central_index+1:
                    break
        count=0
        for l,r in zip(left_count, right_count):
            if l+r>=1:
                if l>r:
                    count+=(l-r)
                else:
                    count+=(r-l)
        print(count)
            
    else:
        print(-1)
    
else:
    central_index =len(x_remove)//2 

    if x_remove[:central_index] == x_remove[-central_index:][::-1]:
        left=S
        left_count=[]
        
        right=S[::-1]
        right_count=[]
        
        l_count=0
        r_count=0
            
        for i in right:
            if i=="x":
                r_count+=1
            else:
                right_count.append(r_count)
                r_count=0
                if len(right_count)==central_index+1:
                    break

        for i in left:
            if i=="x":
                l_count+=1
            else:
                left_count.append(l_count)
                l_count=0
                if len(left_count)==central_index+1:
                    break
        count=0
        for l,r in zip(left_count, right_count):
            if l+r>=1:
                if l>r:
                    count+=(l-r)
                else:
                    count+=(r-l)
        print(count)
    else:
        print("-1")

Measured memory_bytes: 5192
mod = 10 ** 9 + 7
n = gets.to_i

fac = [1]
1.upto(n+1) {|i| fac << fac.last * i % mod}

b = "111011100110101100101000000101".reverse
x = fac.last
r_fac = [1]
b.each_char do |c|
    r_fac[0] = r_fac[0] * x % mod if c == "1"
    x = x ** 2 % mod
end

n.times {|i| r_fac.unshift(r_fac.first * (n - i + 1) % mod)}
r_fac.unshift(1)

s = 0
jud = Array.new(n+1,-1)
gets.split.map(&:to_i).each_with_index do |e,i|
    if jud[e] == -1
        jud[e] = i
    else
        s = jud[e] + n - i
    end
end

1.upto(n+1) do |i|
    ans = fac[n+1] * r_fac[i] % mod * r_fac[n-i+1] % mod

    if s >= i - 1
        x = fac[s] * r_fac[i-1] % mod * r_fac[s-i+1] % mod
        ans = (ans - x) % mod
    end

    puts ans
end

Measured memory_bytes: 14152
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N;
    cin >> N;
    cout << (N/2)*((N+1)/2) << endl;
    return 0;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    rep(i, 1, n + 1){
        if(i * (i + 1) / 2 == n){
            queue<ll> x;
            queue<ll> t[i + 1];
            rep(i, 0, n){
                x.push(i + 1);
            }
            cout << "Yes" << endl;
            cout << i + 1 << endl;
            rep(j, 0, i + 1){
                cout << i;
                rep(k, 0, j){
                    cout << " " << t[k].front();
                    t[k].pop();
                }
                rep(k, 0, i - j){
                    cout << " " << x.front();
                    t[j].push(x.front());
                    x.pop();
                }
                cout << endl;
            }
            cout << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL memo[5];
char first_c[] = {'M', 'A', 'R', 'C', 'H'};

int main(){
    int N;
    cin >> N;
    string s;
    REP(i, N) {
        cin >> s;
        REP(j, 5) if(first_c[j] == s[0]) memo[j]++;
    }

    LL ans = 0;
    REP(i, 5) REP2(j, i+1, 5) REP2(k, j+1, 5) ans += memo[i] * memo[j] * memo[k];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){

  int n,i;
  int a,m,M;
  long s;


  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(i==0){
      m=a;
      M=a;
      s=a;
    }else{
      if(m>a)
	m=a;
      if(M<a)
	M=a;
      s+=a;
    }
  }
  printf("%d %d %ld\n",m,M,s);


  return 0;
}

Measured memory_bytes: 1808
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <cstdio>
using namespace std;

typedef complex<double> P;

const double pi = acos(-1);
const double eps = 1e-8;

bool equals(double a, double b) { return abs(a-b) < eps; }
double dot(P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }
double cross(P a, P b) { return a.real()*b.imag() - a.imag()*b.real(); }
double norm(P a) { return dot(a,a); }

int ccw(P p0, P a, P b) {
  a -= p0;
  b -= p0;
  if(cross(a,b) > eps) return 1;
  if(cross(a,b) < -eps) return -1;
  if(dot(a,b) < -eps) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

double getArea(vector<P> G) {
  int n = G.size();
  double S = 0;
  for(int i = 0; i < n; ++i) {
    S += cross(G[i], G[(i+1)%n]);
  }
  return S/2.0;
}

// ¼üÆ¼üÌð_B
P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  // cross ÌÖW è
  return a1 + a * cross(b, b1 - a1)/cross(b, a);
}

vector<P> convex_cut(vector<P> ps, P p1, P p2, int dir = -1) {
  vector<P> v;
  for(int i = 0; i < ps.size(); ++i) {
    P a = ps[i];
    P b = ps[(i+1)%ps.size()];
    if(ccw(p1, p2, a) != dir) v.push_back(a);
    if(ccw(p1, p2, a)*ccw(p1, p2, b) == -1)
      v.push_back(getCrossP(a, b, p1, p2));
  }
  return v;
}


int N;
vector<P> ps;

P solve() {
  double l, r;
  l = 0.0;
  r = pi;
  double S = getArea(ps);
  if(2.0*getArea(convex_cut(ps,P(0.0,0.0),P(cos(l),sin(l)))) - S > 0.0) {
    swap(l,r);
    l += 2.0*pi;
  }

  while(1) {
    double rad = (l+r)/2.0;
    double tmp = 2.0*getArea(convex_cut(ps,P(0.0,0.0),P(cos(rad),sin(rad))))-S;
    if(equals(tmp,0.0)) return P(cos(rad),sin(rad));
    else if(tmp > 0.0) {
      r = rad;
    } else {
      l = rad;
    }
  }
}

int main() {
  while(cin >> N && N) {
    ps.clear();
    for(int i = 0; i < N; ++i) {
      P p;
      scanf("%lf %lf", &p.real(), &p.imag());
      ps.push_back(p);
    }
    P ans = solve();
    printf("%.20f %.20f\n", ans.real(), ans.imag());
  }
  return 0;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#define N 1000000
using namespace std;
int n;
int k[201];
int main(){
    cin>>n;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>k[i];
        if(k[i]%2==0)
            cnt++;
    }
    if(cnt!=n){
        cout<<0<<endl;
        return 0;
    }
    int mi=100;
    for(int i=0;i<n;i++){
        int sum=0;
        int a=k[i];
        while(a%2==0&&a){
            sum++;
            a>>=1;
        }
        mi=min(mi,sum);
        if(!mi)
            break;
    }
    cout<<mi<<endl;
    return 0;
}


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

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

/**
 * Fenwick Tree 
 *
 * 0-indexed
 */
template <int N>
struct FenwickTree {
    using D = int; /// ????´???????
    D seg[N+1];
    
    /// ????´???????????????????
    void init() {
        fill_n(seg, N+1, 0);
    }

    /// i?????????????´????x???????????????
    void add(int i, D x) {
        i++;
        while (i <= N) {
            seg[i] += x;
            i += i & -i;
        }
    }

    /// [0, i)???sum
    D sum(int i) {
        D s = 0;
        while (i > 0) {
            s += seg[i];
            i -= i & -i;
        }
        return s;
    }

    /// [a, b)???sum
    D sum(int a, int b) {
        return sum(b) - sum(a);
    }
};


const int N = 1<<17;
const int BS = 1<<8;
const int BN = N/BS;


P V[N];
int yv[BN][BS];
P p[BN][BS];
int p2idx[BN][BS];
ll rngsm[BN];
int psm[BN][BS];

//Node* st[BN];
FenwickTree<BS> st[BN];

void init() {

    for (int i = 0; i < N; i++) {
        p[i/BS][i%BS] = V[i];
    }

    static int idx[BS];
    for (int i = 0; i < BN; i++) {
        sort(p[i], p[i]+BS, [&](const P &l, const P &r){
            return l.second < r.second;
        });
        for (int j = 0; j < BS; j++) {
            yv[i][j] = p[i][j].second;
        }

    }

    for (int i = 0; i < BN; i++) {
        rngsm[i] = 0;
//        st[i] = new Node(BS);
        st[i].init();
    }
}

void add(int r, int l) {
    int i;
    for (i = 0; (i+1)*BS <= r; i++) {
//        st[i]->add(lower_bound(yv[i], yv[i]+BS, l)-yv[i], BS, 1);
        st[i].add(lower_bound(yv[i], yv[i]+BS, l)-yv[i], 1);
        rngsm[i] += BS - (lower_bound(yv[i], yv[i]+BS, l)-yv[i]);
    }
    if (r % BS == 0) return;
    for (int j = 0; j < BS; j++) {
        if (p[i][j].first < r and l <= p[i][j].second) {
//            st[i]->add(j, 1);
            psm[i][j]++;
            rngsm[i]++;
        }
    }
}

ll get(int r) {
    ll sm = 0;
    int i;
    for (i = 0; (i+1)*BS <= r; i++) {
        sm += rngsm[i];
    }
    if (r % BS == 0) return sm;
    for (int j = 0; j < BS; j++) {
        if (p[i][j].first < r) {
            sm += st[i].sum(j+1);
            sm += psm[i][j];
//            sm += st[i].sum(j);
        }
    }
    return sm;
}
ll get(int l, int r) {
    return get(r) - get(l);
}


const int MN = 1<<17;
int a[MN];
vector<P> qv[MN];
ll res[MN*2];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a+i); a[i]--;
        V[i] = P(i, a[i]);
    }
    for (int i = n; i < N; i++) {
        V[i] = P(i, i);
    }

    init();

    int q;
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        int l, r;
        scanf("%d %d", &l, &r); l--; r--;
        qv[r].push_back(P(l, i));
    }

    for (int i = 0; i < n; i++) {
        add(i, a[i]+1);
        for (auto qu : qv[i]) {
            res[qu.second] = get(qu.first, i);
        }
    }
    for (int i = 0; i < q; i++) {
        printf("%lld\n", res[i]);
    }
}

Measured memory_bytes: 15100
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	int a,b;
	int main(){
		read(a);read(b);
		R int x=a*b;
		if((a*b)&1)puts("Yes");
		else puts("No");
		return 0;
	}
}
int main(){
	return Night::main();
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import itertools
import sys


def solve(N: int):
    sN = str(N)
    lN = len(sN)
    if lN == 1:
        print(N)
        return
    l1 = int(sN[0])
    l2 = int(sN[-1])
    d = {}
    for k1, k2 in itertools.product(range(1, 10), repeat=2):
        p = 10 ** (lN - 2) // 9
        if k1 == k2:
            p += 1
        if k1 < l1:
            p += 10 ** (lN - 2)
        elif k1 == l1:
            p += int(sN[1:-1] or "0")
            if k2 <= l2:
                p += 1
        d[k1, k2] = p

    ans = 0
    for k1, k2 in itertools.product(range(1, 10), repeat=2):
        ans += d[k1, k2] * d[k2, k1]
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())
A = list(map(int,input().split()))

Ans,xorA,Li,Ri = 0,0,0,0
# 右端がN未満なら順次伸ばす
while Ri < N:
    # 条件を満たすなら答えを更新
    if xorA ^ A[Ri] == xorA + A[Ri]:
        Ans += Ri-Li+1
        xorA ^= A[Ri]
    # 条件を満たさないなら左端を調整
    else:
        # 条件を満たすまで左端を縮める
        while xorA ^ A[Ri] != xorA + A[Ri]:
            xorA ^= A[Li]
            Li += 1
        xorA ^= A[Ri]
        Ans += Ri-Li+1
    Ri += 1
print(Ans)

Measured memory_bytes: 24712
#include<stdio.h>
int main(){
    int n,i,str[1001]={0,};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&str[i]);
    }
    for(i--;i>=0;i--){
        if(i==0){
            printf("%d",str[i]);
        }else{
            printf("%d ",str[i]);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int counter = 0;
    int down = 2;
    int a;
    for (int i = 0; i < 3; i++)
    {
        cin >> a;
        if (a == 5)
        {
            counter++;
            down--;
        }
        if (a == 7)
            counter++;
    }
    if (counter == 3 && down == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k; 
    int sum = 0;
    for (int i = 0; i < n; i++){
        int s;
        cin >> s;
        if (s >= k){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define mod 1000000007

long int waru(long int ue, long int sita){
  if(ue==sita){
    return 1;
  }
  if(ue%sita==0){
    return (ue/sita)%mod;
  }
  return waru(ue+mod,sita);
}


long int comb(int q,int N){
  long int ue=1;
  long int sita=1;
  int i;
  for(i=0;i<q;i++){
    ue=ue*(q+N-1-i)%mod;
    sita=sita*(q-i)%mod;
  }
  
  return waru(ue,sita)%mod;
}
  

int main(){
  int N;
  long long int M;
  scanf("%d%lld",&N,&M);
  int i,t;
  long long int ans=1;
  for(i=2;i<=M;i++){
    if(M%i==0){
      t=0;
      while(M%i==0){
	M=M/i;
	t=t+1;
      }
      ans=ans*(comb(t,N))%mod;
    }
  }

  printf("%lld",ans);
  return 0;
}



Measured memory_bytes: 128
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn main() {
    let mut sc = Scanner::new();

    let inf: i32 = 100000000;
    let mut memo = vec![vec![inf; 1100]; 1100];
    memo[0][0] = 0;

    let n: usize = sc.cin();
    let ma: usize = sc.cin();
    let mb: usize = sc.cin();

    for _ in 0..n {
        let a: usize = sc.cin();
        let b: usize = sc.cin();
        let c: i32 = sc.cin();

        for ma in (0..1100).rev() {
            for mb in (0..1100).rev() {
                if ma + a >= 1100 { continue }
                if mb + b >= 1100 { continue }
                memo[ma + a][mb + b] = min(memo[ma + a][mb + b], memo[ma][mb] + c);
            }
        }
    }

    // for ma in (0..9).rev() {
    //     for mb in (0..9).rev() {
    //         print!("{} ", memo[ma][mb]);
    //     }
    //     println!("");
    // }

    let mut ans = inf;
    for a in (1..1100).rev() {
        for b in (1..1100).rev() {
            if ma * b == mb * a {
                ans = min(ans, memo[a][b]);
            }
        }
    }
    println!("{}", if ans == inf { -1 } else { ans });
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <cassert>
#include <functional>
#include <numeric>
#include <chrono>
#include <random>
#include <optional>

using namespace std;
typedef long long ll;

const int MAXN = 2e5+10;
int n;
ll preSum[MAXN], a[MAXN];

// [i, j]
inline ll sumRange(int i, int j) {
  assert(i <= j);
  return i == 0 ? preSum[j] : preSum[j] - preSum[i-1];
}

ll getBest(ll k) {
  ll sum = sumRange(0, k);
  int lo = 0;
  int hi = k;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (sumRange(0, mid) >= sum/2) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  int i = hi;

  sum = sumRange(k+1, n-1);
  lo = k+1;
  hi = n-1;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (sumRange(k+1, mid) >= sum/2) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  int j = hi;

  ll res = 1e18;
  // cerr << "i: " << i << " k: " << k << " j: " << j << endl;
  for (int izq = i-2; izq <= i+1; izq++) {
    for (int der = j-2; der <= j+1; der++) {
      if (izq > 0 && der > k+1 && izq <= k && der <= n-1) {
        ll P = sumRange(0, izq-1);
        ll Q = sumRange(izq, k);
        ll R = sumRange(k+1, der-1);
        ll S = sumRange(der, n-1);
        ll mx = max({P, Q, R, S});
        ll mn = min({P, Q, R, S});
        res = min(res, mx - mn);
        // cerr << izq << "  " << der << endl;
        // cerr << P << " " << Q << " " << R << " " << S << endl;
        // cerr << mx - mn << endl;
      }
    }
  }
  return res;
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  preSum[0] = a[0];
  for (int i = 1; i < n; i++) preSum[i] = preSum[i-1] + a[i];

  ll ans = 1e18;
  for (int k = 1; k < n-2; k++) {
    ll op = getBest(k);
    ans = min(ans, op);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6636
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,N,M,K,odd=0,sum=0;
  cin >> N >> M;
  vector<int>P(N,0),Q(N,0);
  int DP[N+1][M+1];
  rep(i,0,N)cin >> Q[i] >> P[i];
  rep(i,0,M+1)DP[N][i]=0;
  for(int i=N-1;i>-1;i--)rep(j,0,M+1){
    if(j<P[i])DP[i][j]=DP[i+1][j];
    else DP[i][j]=max(DP[i+1][j],DP[i+1][j-P[i]]+Q[i]);
  }
  Out(DP[0][M]);
}


Measured memory_bytes: 7036
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define mci       	  map<char,int>  	
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define pii           pair<int ,int >
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define mp            make_pair
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN   		  1000000
#define f(n) for(int i=0;i<n;i++)
using namespace std;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
	return 0;
}


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

using namespace std;
using ll = long long;

const int MAX_K = 100000;


int K;

ll solve()
{

    queue<ll> que;
    for (int i = 1; i <= 9; i++) que.push(i);
    if(K <= 9) return K;
    for(int i = 1; i < K;)
    {   
        ll q = que.front(); que.pop();
        ++i;
        int res = q % 10;
        //cout << res << endl;
        for(int j = -1; j <= 1; ++j)
        {
            int d = res + j;
            if(d < 0 || d > 9) continue;
            ll nx = 10*q + d;
            que.push(nx);
            
        } 
    }

    return que.front();
}

int main()
{
    cin >> K;
    
    cout << solve() << endl;


    return EXIT_SUCCESS;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int H, W;
  cin >> H >> W;
  vector<int> dy = {1, 1, 1, -1, -1, -1, 0, 0};
  vector<int> dx = {0, 1,-1, 0, 1, -1, 1, -1};
  vector<string> grid(H);
  REP(i, H) {
    cin >> grid[i];
  }
  
  REP(i, H) {
    int j = 0;
    REP(j, W) {
      if (grid[i][j] == '#') {
        cout << '#';
        continue;
      }
      int k = 0;
      int cnt = 0;
      REP(k, 8) {
        int ny = i + dy[k];
        int nx = j + dx[k];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) {
          continue;
        }
        if (grid[ny][nx] == '#') {
          cnt++;
        }
      }
      cout << cnt;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int n;
int si[SIZE];
pair<int, int> query[SIZE];

bool check(int now, int d2){

  for(auto v : query){
    int t = v.first;
    int d = v.second;

    if (si[now] == t) {
      if(d == 0) now++;
      else now--;
    }

    if(now == n) return d2 == 0;
    if(now == -1) return d2 == 1;
  }

  return false;
}

int main(){
  int q;
  char s[SIZE];

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

  scanf("%s", s);

  for(int i=0;i<n;i++) si[i] = s[i] - 'A';

  for(int i=0;i<q;i++){
    char t, d;
    scanf(" %c %c", &t, &d);
    query[i] = {t-'A', d == 'L'};
  }

  int L = -1, R = n;

  int l = -1, r = n;

  while(l < r){
    int mid = (l + r + 1 + 2) / 2 - 1;

    if(check(mid, 1))
      l = mid;
    else
      r = mid - 1;
  }

  L = l;


  l = -1, r = n;

  while(l < r){
    int mid = (l + r + 2) / 2 - 1;

    if(check(mid, 0))
      r = mid;
    else
      l = mid + 1;
  }

  R = l;

  int ans = 0;


  debug(L); debug(R);

  for(int i=0;i<n;i++) {
    ans += i <= L || R <= i;
  }


  cout << n - ans << endl;

  return 0;
}


Measured memory_bytes: 2816