akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,W,V=0;
	cin>>n>>W;
	vector<int> w(n),v(n);
	rep(i,n){
		cin>>w[i]>>v[i];
		V+=v[i];
	}
	vector<vector<int>> dp(n+1,vector<int>(V+1,INF));
	dp[0][0]=0;
	rep(i,n){
		rep(j,V+1){
			chmin(dp[i+1][j],dp[i][j]);
			if(j-v[i]>=0){
				chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
			}
		}
	}
	int ans=0;
	rep(i,n+1)rep(j,V+1){
		if(dp[i][j]<=W){
			chmax(ans,(int)j);
		}
	}
	cout<<ans<<endl;
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    ll K; cin >> K;
    PQR<ll> pq;
    pq.push(1);
    pq.push(2);
    pq.push(3);
    pq.push(4);
    pq.push(5);
    pq.push(6);
    pq.push(7);
    pq.push(8);
    pq.push(9);
    vector<ll> ans;
    while(pq.size()) {
        ll x = pq.top();
        pq.pop();
        if(ans.size()<K){
            ans.push_back(x);
        }
        else continue;

        ll c = x % 10;
        for(int i = 0; i < 10; ++i) {
            if(abs(i-c)<=1){
                pq.push(x*10+i);
            }
        }
    }
    cout << ans.back() << endl;
    return 0;
}


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

void solve() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	multiset<int> p, q, r, ans;
	for (int i = 0; i < a; i++) {
		int x;
		cin >> x;
		p.insert(x);
	}
	for (int i = 0; i < b; i++) {
		int x;
		cin >> x;
		q.insert(x);
	}
	for (int i = 0; i < c; i++) {
		int x;
		cin >> x;
		r.insert(x);
	}
	int i = 0;
	for (auto it = p.rbegin(); i < x; i++, it++) {
		ans.insert(*it);
	}
	i = 0;
	for (auto it = q.rbegin(); i < y; i++, it++) {
		ans.insert(*it);
	}
	while (c--) {
		auto rit = --r.end();
		auto ait = ans.begin();
		if (*rit > *ait) {
			ans.erase(ait);
			ans.insert(*rit);
			r.erase(rit);
		} else {
			break;
		}
	}
	long long sum = 0;
	for (auto it = ans.begin(); it != ans.end(); it++) {
		sum += *it;
	}
	cout << sum << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	solve();
	return 0;
}

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

std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main()
{
  int n, a, b;
  std::vector<long long> v;
  
  std::cin >> n >> a >> b;
  
  for(int i = 0; i < n; ++i) 
  {
    long long _v;
    std::cin >> _v;
    v.push_back(_v);
  }
  
  std::sort(v.begin(), v.end(), std::greater<long long>());
  long long s = 0;
  for(int i = 0; i < a; ++i)
  {
    s += v[i];
  }
  //std::cout << (double)s / a << "\n";
  printf("%.6lf\n", (double)s / a);
  
  int l, r;
  {
    auto range = std::equal_range(v.begin(), v.end(), v[a - 1], std::greater<long long>());
    l = std::distance(v.begin(), range.first);
    r = std::distance(v.begin(), range.second);
  }

  long long combination = 0;
  int nn = r - l;
  if(v[0] != v[a - 1])
  {
    int rr = a - l;
    auto c = comb(nn, rr);
    combination += c[nn][rr];
  }
  else
  {
    int e = std::min(b, r);
    for(int aa = a; aa <= e; ++aa)
    {
      int rr = aa - l;
      auto c = comb(nn, rr);
      combination += c[nn][rr];
    }
  }
  std::cout << combination;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    ll A,B,K; cin >> A >> B >> K;
    vector<ll> ans;
    for(int i = A; i <= B; i++){
        if(i < A + K || B - K < i){
            ans.push_back(i);
        }
    }
    sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++){
        if(i == 0) cout << ans[i] << endl;
        else{
            if(ans[i-1] != ans[i]){
                cout << ans[i] << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int ans = MAX;
int c[12],a[12][12];
int n,m,x;
int exp1[12];

void func(int num, int cost){
  if(num == -1){
    bool flag = true;
    rep(i,m){
      //cout << exp1[i] << " ";
      if(exp1[i] < x){
	flag = false;
      }
    }
    //cout << endl;
    if(flag && cost < ans){
      //cout << "aaaaaaaaaaaaaa";
      ans = cost;
    }
    return;
  }
  rep(i,m){
    exp1[i] += a[num][i];
  }
  func(num-1,cost+c[num]);
  rep(i,m){
    exp1[i] -= a[num][i];
  }
  func(num-1,cost);
}

int main(void){
  
  cin >> n >> m >> x;

  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
    exp1[i] = 0;
  }
  
  func(n-1,0);

  if(ans == MAX)cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
 
int main(){
  int N;
  int A[210];
  int res = 0;
  cin >> N;
  for(int i=0;i<N;i++)cin >> A[i];
  
  while(true){
  	bool ext_odd = false;
    for(int i=0;i<N;i++){
    	if(A[i] % 2 == 1) ext_odd = true;
    }
    if(ext_odd) break;
    for(int i=0;i<N;i++){
      A[i] = A[i] / 2;
    }
    ++res;
  }
  
  cout << res << endl;
  
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll x, y, a, b;
  cin >> x >> y >> a >> b;
  ll p = a - x;
  ll q = b - y;
  //if(p > 0 && q > 0)
    cout << a - q spa b + p spa x - q spa y + p << endl;
 
  return 0;
}

Measured memory_bytes: 256
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

const int MAX_V = 1e5;
vector<int> es[MAX_V];
ll A[MAX_V];
bool able = true;

//parからnowに流れてくる量
int dfs(int now, int par){
    vector<ll> v;
    for(auto &e: es[now]){
        if(e != par) v.pb(dfs(e, now));
    }
    if(v.empty()) return A[now];
    ll cnt = 0, M = 0;
    for(auto &e: v){
        cnt += e;
        M = max(M, e);
    }
    //nowより下の部分木の葉同士で結んだ回数、結べる回数
    ll x = cnt-A[now], k;
    if(2*M > cnt) k = cnt-M;
    else k = cnt/2;
    if(x < 0 || x > k) able = false;
    if(par == -1 && (2*k != cnt || A[now] != k)) able = false;
    return max(cnt-2*x, 0ll);
}

int main(){
    int N; cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N-1){
        int u, v; cin >> u >> v; u--, v--;
        es[u].pb(v), es[v].pb(u);
    }
    if(N == 2){
        if(A[0] == A[1]) cout << "YES" << endl;
        else cout << "NO" << endl;
        return 0;
    }
    rep(i, N){
        if(es[i].size() >= 2){
            dfs(i, -1);
            break;
        }
    }
    if(able) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 14464
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int N;
long long M;
std::vector<long long > A(100000);
//std::vector<int > A(100000);
std::vector<long long > kumisuu(200000, 0); // A_i>=x を満たすiの数
std::vector<long long > souwa(200000, 0); // A_i>=x を満たすiについてA_iの総和

long long get_possible_count(int value){ // 値がvalue以上となる組み合わせ総数を求める
  long long count = 0;
  for (int i=0; i<N; i++){
    count += kumisuu[std::max(value-A[i], (long long)0)];
  }
  return count;
}

int main(){
  scanf("%d",&N);
  scanf("%lld",&M);

  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    kumisuu[A[i]]++;
  }
  sort(A.begin(), A.end(), std::greater<long long>());

  for (int i=0; i<N; i++){
    souwa[i+1] = souwa[i] + A[i];
  }

  /*  累積和を求める */
  for (int i=200000; i>0; i--){
    kumisuu[i-1] += kumisuu[i];
  }

  int left = 0;
  int right = 200001;
  int mid;
  long long ans = 0;
  std::map<long long, long long> mp;
  while(right-left>1){
    ans = 0;
    mid = (left+right)/2;
    if (get_possible_count(mid)>=M){ // 
      left = mid;
    } else {
      right = mid;
    }
    for (int i=0; i<N; i++){
      ans += souwa[kumisuu[std::max(mid-A[i],(long long)0)]];
      ans += A[i]*kumisuu[std::max(mid-A[i],(long long)0)];
    }
    mp[mid] = get_possible_count(mid);
  }


  if (left == mid){
    //std::cout << ans+abs(M-get_possible_count(left))*left << std::endl;
    std::cout << ans-abs(M-mp[left])*left << std::endl;
  } else if (right==mid){
    std::cout << ans+abs(M-mp[right])*left << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll n;
vector<ll> a;

void input(){
    cin >> n;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        a.push_back(x);
    }
}

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    ll ans;
    ans = GCD(a[0], a[1]);
    for(int i=2;i<n;i++){
        ans = GCD(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	String S;
	int N;
	public void solve() {
		S = next();
		N = S.length();


		int i = 0;
		char pre = '.';
		int ans = 0;
		while(i < N){
			if(S.charAt(i) != pre){
				ans++;
				pre = S.charAt(i);
			}
			i++;
		}

		out.println(ans - 1);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e9, maxn = 200000;

void solve(int ci)
{
   int k;
   string s;
   cin >> k >> s;
   cout << s.substr(0, min(k, (int)s.size()));
   if(s.size() > k) cout << "...";
}

main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    f(t) solve(i + 1);
}


Measured memory_bytes: 3616
#C - Rally
N = int(input())
X = list(map(int, input().split()))

P_list = []
for P in range(1, max(X)+1):
    P_list.append(P)

HP_min =10**8#取りうるHPの最大値    
for i in range(len(P_list)):#Pに関する繰り返し
    HP = 0
    for j in range(N):#Xに関する繰り返し
        HP += (X[j] - P_list[i])**2#Pごとに終わらせたい
    #あるPに対しての処理 
    if HP < HP_min:
        HP_min = HP
print(HP_min)

Measured memory_bytes: 63880
s = input()
t = input()

d = len(s) - len(t)
min_c = int(1e4)
for i in range(d+1):
    st = s[i:i+len(t)]
    c = 0
    for j in range(len(t)):
        if st[j] != t[j]:
            c += 1
            if c > min_c:
                break
    min_c = min(c, min_c)

print(min_c)


Measured memory_bytes: 9112
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  s=S()
  a=['S','W']
  aa=(['S','S'],['S','W'],['W','S'],['W','W'])

  for ans in aa:
    for i in range(1,N-1):
      if ans[i]=='S':
        if s[i]=='o':
          ans.append(ans[i-1])
        else:
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
      else:
        if s[i]=='o':
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
        else:
          ans.append(ans[i-1])
    stress=''.join(str(x) for x in ans)
    f=True
    for i in range(N):
      if stress[i]=='S':
        if i==0:
          if s[i]=='o':
            if not (stress[-1]==stress[i+1]):
              # return 'aaa1'+' '+stress
              f=False
          else:
            if not (stress[-1]!=stress[i+1]):
              # return 'aaa2'
              f=False
        elif i==N-1:
          if s[i]=='o':
            if not (stress[i-1]==stress[0]):
              # return 'aaa3'
              f=False
          else:
            if not (stress[i-1]!=stress[0]):
              # return 'aaa4'
              f=False
        else:
          if s[i]=='o':
            if not (stress[i-1]==stress[i+1]):
              # return 'aaa5'
              f=False
          else:
            if not (stress[i-1]!=stress[i+1]):
              # return 'aaa6'
              f=False
      else:
        if i==0:
          if s[i]=='o':
            if not (stress[-1]!=stress[i+1]):
              # return 'bbb1'
              f=False
          else:
            if not (stress[-1]==stress[i+1]):
              # return 'bbb2'
              f=False
        elif i==N-1:
          if s[i]=='o':
            if not (stress[i-1]!=stress[0]):
              # return 'bbb3'
              f=False
          else:
            if not (stress[i-1]==stress[0]):
              # return 'bbb4'
              f=False
        else:
          if s[i]=='o':
            if not (stress[i-1]!=stress[i+1]):
              # return 'bbb5'
              f=False
          else:
            if not (stress[i-1]==stress[i+1]):
              # return 'bbb6'
              f=False

    if f:
      return ''.join(str(x) for x in ans)

  return -1

# main()
print(main())


Measured memory_bytes: 14840
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int N;
    cin >> N;
    VEC(int) A(3 * N);
    READVEC(A);

    VEC(lint) L(3 * N);

    multiset<int> bag1, bag2;
    lint total = 0;
    FOR(i, 0, 3 * N) {
        bag1.insert(A[i]);
        total += A[i];
        if (SZ(bag1) > N) {
            auto it = bag1.begin();
            total -= *it;
            bag1.erase(it);
        }

        L[i] = total;
    }

    total = 0;
    lint ret = -(1LL << 55);
    FORD(i, 3 * N - 1, -1) {
        total += A[i];
        bag2.insert(A[i]);
        if (SZ(bag2) > N) {
            auto it = bag2.end();
            it--;
            total -= *it;
            bag2.erase(it);
        }

        if (3 * N - i >= N && i >= N) {
            ret = max(ret, L[i - 1] - total);
        }
    }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 13184
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int H, W, ret, dp[400][400], r[400][400]; char c[400][400];
int solve(vector<int>a1, vector<int>a2) {
	for (int i = 0; i < 400; i++) { for (int j = 0; j < 400; j++)dp[i][j] = 1e9, r[i][j] = -1; }
	dp[a1.size()][a2.size()] = 0;
	for (int i = a1.size(); i >= 0; i--) {
		for (int j = a2.size(); j >= 0; j--) {
			if (r[i][j] != -1)continue;
			int c = 0;
			for (int k = min(i, j) - 1; k >= 0; k--) {
				c += (a1[a1.size() - i + k] == a2[a2.size() - j + k]);
				r[i - k][j - k] = c;
			}
			r[i][j] = c;
		}
	}
	for (int i = a1.size(); i >= 0; i--) {
		for (int j = a2.size(); j >= 0; j--) {
			if (i >= 1)dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] + r[i][j]);
			if (j >= 1)dp[i][j - 1] = min(dp[i][j - 1], dp[i][j] + r[i][j]);
		}
	}
	return dp[0][0];
}
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++)cin >> c[i][j]; }
	for (int i = 0; i < W - 1; i++) {
		vector<int>p1, p2;
		for (int j = H - 1; j >= 0; j--)p1.push_back(c[j][i]);
		for (int j = H - 1; j >= 0; j--)p2.push_back(c[j][i + 1]);
		ret += solve(p1, p2);
	}
	cout << ret << endl;
	return 0;
}

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

int main(){
  int w,h,n,l=0,d=0;
  cin>>w>>h>>n;
  for(int i=0; i<n; i++){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1) l=max(x,l);
    if(a==2) w=min(x,w);
    if(a==3) d=max(y,d);
    if(a==4) h=min(y,h);
  }
  if(w-l<=0 || h-d<=0) cout<<0;
  else cout<<(w-l)*(h-d);
}

Measured memory_bytes: 256
#include <iostream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int huiwenshu(int a,int b)
{
    int i,num=0,m,k;
    for(i=a;i<b+1;i++)
    {
        m=0;
        k=i;
        while(k>0)
        {
            m=m*10+k%10;
            k=k/10;
        }
        if(m==i)
        {
            num++;
        }
    }
    return num;
}
int main()
{
    int A,B,num;
    scanf("%d %d",&A,&B);
    num=huiwenshu(A,B);
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	ans := 0
	for i := a; i <= b; i++ {
		arr := strconv.Itoa(i)
		if arr[0] == arr[4] && arr[1] == arr[3] {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  bool directly = abs(a - c) <= d;
  bool indirectly = abs(a - b) <= d && abs(b - c) <= d;

  cout << ((directly || indirectly) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <climits>

using namespace std;

int main()
{
    int N, M;
    scanf("%d %d\n", &N, &M);
    vector<unordered_map<int, int>> edges(N);
    for (int i = 0; i < M; ++i){
        int a, b, c;
        scanf("%d %d %d\n", &a, &b, &c); --a; --b;
        edges[a].emplace(b, c);
        edges[b].emplace(a, c);
    }
    auto dijkstra = [&](int start, int goal){
        unordered_map<int, int> costs;
        costs.emplace(start, 0);
        while (true){
            int next_node;
            int next_cost = INT_MAX;
            for (auto& elem : costs){
                auto& i = elem.first;
                auto& cost = elem.second;
                for (auto& elem2 : edges[i]){
                    auto& j = elem2.first;
                    auto& cost2 = elem2.second;
                    if (costs.count(j)) continue;
                    int temp_cost = cost + cost2;
                    if (temp_cost < next_cost){
                        next_node = j;
                        next_cost = temp_cost;
                    }
                }
            }
            if (next_cost == INT_MAX) break;
            costs.emplace(next_node, next_cost);
            if (next_node == goal) break;
        }
        return ((costs.count(goal)) ? costs[goal] : INT_MAX);
    };
    int result = 0;
    for (int i = 0; i < N; ++i){
        for (auto& elem : edges[i]){
            auto& j = elem.first;
            auto& cost = elem.second;
            if (j <= i) continue;
            if (dijkstra(i, j) < cost) ++result;
        }
    }
    printf("%d\n", result);
}


Measured memory_bytes: 384
#include<stdio.h>
 int main(){
   int i;
   int x;
   for(i = 0 ;i < 10000 ;i++ ){
     scanf("%d",&x);
     if (x == 0) break;
     
     printf("Case %d: %d\n",i+1, x);
      }return 0;
 }


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#ifdef _DEBUG
#define PRE_COMMAND             \
    std::cin.rdbuf(in.rdbuf()); \
    std::cout << fixed << setprecision(15);
#else
#define PRE_COMMAND cout << fixed << setprecision(15);
#endif
const double EPS = 1e-10, PI = acos(-1.0);
template <class T> auto MAX(T& seq) {
    return *max_element(seq.begin(), seq.end());
}
template <class T> auto MIN(T& seq) {
    return *min_element(seq.begin(), seq.end());
}
template <class T> auto SUM(T& seq) {
    T temp{0};
    auto& temp2 = temp[0];
    return accumulate(seq.begin(), seq.end(), temp2);
}
template <class T> void SORT(T& seq) { sort(seq.begin(), seq.end()); }
template <class T, class S> void SORT(T& seq, S& sort_order) {
    sort(seq.begin(), seq.end(), sort_order);
}
template <class T> void SORTR(vector<T>& seq) {
    sort(seq.begin(), seq.end(), greater<T>());
}
template <class T, class S, class R> long long pow(T n_0, S k_0, R mod_0) {
    long long n = n_0, k = k_0, mod = mod_0, now = 1;
    while (true) {
        if (k & 1) { now = now * n % mod; }
        if ((k >>= 1) == 0) { return now; }
        n = (n * n) % mod;
    }
}

struct unionfind {  // size:要素数,tree：unionfind木
    int n;
    vector<int> tree_root;
    vector<int> tree_depth;
    unionfind(int temp) {
        n = temp;
        tree_root.assign(n, 0);
        tree_depth.assign(n, 1);
        for (int i = 0; i < n; i++) { tree_root[i] = i; }
    }

    // rootを探す
    int root(int index) {
        vector<int> temp_list(0);
        int temp = tree_root[index];
        while (index != temp) {
            temp_list.push_back(index);
            index = temp;
            temp = tree_root[index];
        }
        for (int i : temp_list) { tree_root[i] = index; }
        return index;
    }
    //結合
    void unite(int index1, int index2) {
        int r1 = root(index1);
        int r2 = root(index2);
        if (r1 != r2) {
            int d1 = tree_depth[r1];
            int d2 = tree_depth[r2];
            if (d1 <= d2) {
                tree_root[r1] = r2;
                tree_depth[r2] = max(d1 + 1, d2);
            } else {
                tree_root[r2] = r1;
                tree_depth[r1] = max(d2 + 1, d1);
            }
        }
    }
    //同じか判定
    bool same(int index1, int index2) {
        int r1 = root(index1);
        int r2 = root(index2);
        return r1 == r2;
    }
    //連結成分の個数
    int component() {
        set<int> s;
        for (int i : tree_root) { s.insert(i); }
        return (int)s.size();
    }
};

int main() {
    PRE_COMMAND
    int n, q, t, u, v;
    cin >> n >> q;
    unionfind uf(n);
    for (int i = 0; i < q; i++) {
        cin >> t >> u >> v;
        if (t == 0) { uf.unite(u, v); }
        if (t == 1) { cout << uf.same(u, v) << endl; }
    }
}


Measured memory_bytes: 4740
#include <iostream>
using namespace std;
void dfs(int,int);
int data[52][52];
int main(){
  int w,h,i,j,cnt;
  while(1){
    cnt=0;
    cin >> w >> h;
    if(w==0&&h==0) break;
    for(i=0;i<=h+1;i++){
      for(j=0;j<=w+1;j++){
	data[i][j]=0;
      }
    }
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	cin >> data[i][j];
      }
    }
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
        if(data[i][j]==1){
	  dfs(i,j);
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
void dfs(int i,int j){
  if(data[i][j]==0) return ;
  data[i][j]=0;
  dfs(i-1,j);
  dfs(i+1,j);
  dfs(i,j-1);
  dfs(i,j+1);
  dfs(i-1,j-1);
  dfs(i-1,j+1);
  dfs(i+1,j-1);
  dfs(i+1,j+1);
}

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

int N;

bool same(vector<int> a,vector<int> b){
  for(int i=0;i<N;i++){
    if(a[i]!=b[i]) return false;
  }
  return true;
}
int kaijo(int N){
  int ans=1;
  for(int i=1;i<=N;i++){
    ans*=i;
  }
  return ans;
}
int main() {

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


  int da=0,db=0;
  for(int i=0;i<kaijo(N);i++){
    if(same(a,d)) da=i;
    if(same(b,d)) db=i;
    next_permutation(d.begin(),d.end());
  }
  cout<<abs(da-db)<<endl;


  }


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

long pow2(int i){
  return (long)1 << i;
}

int main(){
  long A, B;
  cin >> A >> B;
  long ans = 0;
  long diff = B - A;
  
  long count = 0;
  
  if( (A % 2 == 0 && (diff % 4 == 1 || diff % 4 == 2))
     || (A % 2 == 1 && (diff % 4 == 0 || diff % 4 == 1))){
       ans = 1;
  }
    
  int i=1;
  for (i=1; i < 64; ++i){
    
    // to max B
    if (B > pow2(i) -1){
      // count "1" in A to B
      
      // offset
      long offset = A & (pow2(i+1) - 1);
      
      long extra = offset + (diff + 1) % pow2(i+1);
      
      
      long first = max(offset - pow2(i), (long)0);
      long second;
      if (extra > pow2(i+1))
        second = max(extra - pow2(i) * 3, (long)0);
      else
        second = min(pow2(i+1) - extra, pow2(i)) + pow2(i);
      count =  pow2(i+1) - first - second;
       /*
      if( i > 50)
      {
      cout << "**" << i << "** ";
        cout << (1 << i);
      cout << " offset:" << offset;
      cout << " extra:" << extra;
      cout << " first:" << first;
      cout << " second:" << second;
      cout << " count:" << count << endl;
      }
        // */
      if (count % 2 == 1){
        ans |= pow2(i );
      }
    }
    else{
      break;
    }
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
if a<=b<=c:
    print(a,b,c)
elif a<=c<=b:
    print(a,c,b)
elif b<=a<=c:
    print(b,a,c)
elif b<=c<=a:
    print(b,c,a)
elif c<=a<=b:
    print(c, a, b)
else:
    print(c,b,a)



Measured memory_bytes: 5596
n = int(input())
w = list(map(int,input().split()))
res = 1 << 30
for t in range(n - 1):
    less = sum([w[i] for i in range(t + 1)])
    over = sum([w[i] for i in range(t + 1, n)])
    res = min(res,abs(less - over))
print(res)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, 0, n)

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	int k;
	cin >> k;
	if (k % 2 == 0) {
		cout << (k / 2)*(k / 2);
	}
	else {
		cout << (k / 2)*(k / 2 + 1);
	}

	system("pause");
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<ll> X(N), Y(N);
    set<ll> st1, st2;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
        st1.insert(X[i]+Y[i]);
        st2.insert(X[i]-Y[i]);
    }
    auto it1 = st1.begin(), it2 = st1.end(), it3 = st2.begin(), it4 = st2.end();
    it2--;
    it4--;
    ll ans = max((*it2)-(*it1), (*it4)-(*it3));
    cout << ans << endl;
}


Measured memory_bytes: 25168
#include <iostream>
#include <vector>

using i64 = int64_t;
//
// O(N)で二項係数(mod)を求める
//
// ref: http://drken1215.hatenablog.com/entry/2018/06/08/210000
struct Comb {
    const i64 mod;
    std::vector<i64> fact;     // a!
    std::vector<i64> factinv;  // (a!)^-1
    std::vector<i64> inv;
    Comb(int maximum, i64 m)
        : mod(m), fact(maximum, 0), factinv(maximum, 0), inv(maximum, 0) {
        // テーブルを作る前処理
        fact[0] = factinv[0] = 1;
        fact[1] = factinv[1] = 1;
        inv[1] = 1;
        for (i64 i = 2; i < maximum; ++i) {
            fact[i] = fact[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            factinv[i] = factinv[i - 1] * inv[i] % mod;
        }
    }
    i64 comb(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fact[n] * (factinv[k] * factinv[n - k] % mod) % mod;
    }
};

using namespace std;

int main() {
    i64 x, y;
    cin >> x >> y;
    i64 s, t;
    bool flag = false;
    for (i64 a = 0; a < x + 1; ++a) {
        if (a % 2 == 0 && (x - a) * 2 + a / 2 == y) {
            s = a / 2;
            t = x - a;
            flag = true;
        }
    }
    if (!flag) {
        cout << 0 << endl;
        return 0;
    }
    i64 n = s + t;
    i64 k = s;
    Comb c(1'000'100, 1'000'000'007);
    cout << c.comb(n, k) << endl;

    return 0;
}

Measured memory_bytes: 23680
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

bool ham(int n){
	while(n%2==0)n/=2;
	while(n%3==0)n/=3;
	while(n%5==0)n/=5;
	return n==1;
}

int main() {
	int n,m;
	while(n=in()){
		m=in();
		int res=0;
		for(;n<=m;n++){
			if(ham(n))res++;
		}
		cout<<res<<endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    string s;
    cin>>s;

  	string ans="Good";
	repa(i,1,4)if(s[i-1]==s[i])ans="Bad";

  	cout<<ans<<"\n";
  
    return 0;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int x[10000];
	for (int i = 0; i < 10000; i++){
		cin >> x[i];
		if (x[i] == 0){
			break;
		}
	}
	for (int i = 0; i < 10000; i++){
		if (x[i] == 0){
			break;
		}
		cout << "Case "<<i+1<<": "<<x[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3020
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
const int mod = 1e9+7;

using ll = long long;

pair<ll, ll> a[N];
ll ans;
int n;

ll fast_pw(ll x, ll y) {
	x %= mod;
	ll ret = 1;

	for(;y;y>>=1) {
		if(y&1) ret = (ret * x) % mod;
		x = (x*x) % mod;
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;

	int t1 = 0, t2 = 0, t3 = 0;

	for(int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;

		if(a[i].first == 0 && a[i].second) t1++;
		if(a[i].second == 0 && a[i].first) t2++;
		if(a[i].first == 0 && a[i].second == 0) t3++;
	}

	map<pair<ll,ll>, int> neg, pos;

	for(int i = 0; i < n; i++) {

		if(a[i].first == 0 || a[i].second == 0) continue;

		bool f = true;
		pair<ll,ll> now = a[i];
		
		if( (now.first < 0) != (now.second < 0) ) f = false;

		now.first = abs(now.first);
		now.second = abs(now.second);

		ll g = __gcd(now.first, now.second);

		now.first /= g;
		now.second /= g;

		if(f) {
			pos[now]++;
		}
		else {
			neg[now]++;
		}

	}

	vector<pair<int,int>> vp;

	for(auto &x : pos) {
		vp.emplace_back(x.second, neg[make_pair(x.first.second, x.first.first)]);
	}

	for(auto &x : neg) {
		if(pos.find(make_pair(x.first.second, x.first.first)) != pos.end()) continue;
		
		vp.emplace_back(x.second, 0);

	}

	if(t1 || t2) vp.emplace_back(t1, t2);

	ans = 1;

	for(auto &p : vp) {
		ll x = ans * ((fast_pw(2, p.first) - 1 + mod ) % mod + (fast_pw(2, p.second) - 1 + mod) % mod  ) % mod;
		x %= mod;
		ans = (ans + x) % mod;
	}

	cout << (ans - 1 + mod + t3) % mod;

	
	return 0;
}


Measured memory_bytes: 27172
/*input
141421 356237
*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
 
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        return fact[n]*ifact[n-k];
    }
} c(1000005);

int main() {
    int n, m;
    cin >> n >> m;
    mint ans = 0;
    rep(i, n+1) {
        mint now = c(n, i); // which nums are the same
        now *= c.p(m-i, n-i); // which nums to choose for B
        if (i&1) now = -now;
        ans += now;
    }
    ans *= c.p(m, n); // which nums to choose for A
    cout << ans << endl;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

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

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

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


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


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

//    AGC 005 B Minimum Sum
    /**
     * Ai が最小値をとる区間はいくつある？
     * Al ~ Ai ~ Ar という列を考える
     * ここでAlはAiより左にあるうちAiに一番近い、Aiより小さい要素である
     * ここでArはAiより右にあるうちAiに一番近い、Aiより小さい要素である
     * そうすると、Aiが最小となる区間はAl+1 ~ AiとAi ~ Ar-1の区間から作られると分かる
     * (ここでAiは必ず含むがAl+1 ~ Ai-1, Ai+1 ~ Ar-1は含まなくともよい)
     *
     * ここでAiの数値が小さいものから見ていけば、
     * setで管理するものを "使われた(Aiより小さい)要素の位置" だけにして、
     * Aiが最小値になるような区間が探しやすい.
     *
     */

    i32 n; cin >> n;

    i32 a;
    vi place(n+1);
    rep(i,n) {
        cin >> a;
        place[a] = i;
    }

    set<i32> used_a_places;
    used_a_places.insert(-1), used_a_places.insert(n);
    i64 cnt = 0;
    for(i32 val = 1; val <= n; ++val) {
        i32 plc = place[val];
        auto iter = used_a_places.lower_bound(plc);
        i32 R = *iter, L = *(--iter);

        i32 num_of_right_boundary = R - plc;
        i32 num_of_left_boundary = plc - L;
        cnt += val * (num_of_left_boundary * num_of_right_boundary);

        used_a_places.insert(plc);
    }

    cout << cnt << '\n';

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


Measured memory_bytes: 11264
#include <stdio.h>
#include <string.h>

#define DEF_ELEM_MAX 2000001

typedef long long llong;

int A[DEF_ELEM_MAX];
int B[DEF_ELEM_MAX];
int C[DEF_ELEM_MAX];
int N;

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
void CountingSort(int *A, int *B, int k)
{
	int i;
    for ( i = 0 ; i <= k ; i++ ) {
        C[i] = 0;
    }

    // C[i] ??? i ???????????°????¨??????????
    for ( i = 0 ; i < N ; i++ ) {
        C[A[i]]++;
    }

    // C[i] ??? i ??\????????°???????????°????¨??????????
    for ( i = 1 ; i <= k ; i++ ) {
        C[i] += C[i-1];
    }

    for ( i = N-1 ; i >= 0 ; i-- ) {
        B[C[A[i]]-1] = A[i];
        C[A[i]]--;
	}
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int i;
	int maxv = 0;
//
	scanf("%d", &N);
	for ( i = 0 ; i < N ; i++ ) {
		scanf("%d", &A[i] );
		if (A[i] > maxv) {
			maxv = A[i];
		}
	}

	CountingSort(A, B, maxv);

	for ( i = 0 ; i < N ; i++ ) {
		printf("%d", B[i]);
		if ( i < N-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 17896
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(A: int, B: int, C: int):
    if B >= C:
        print(B+C)
    if B < C:
        res = 2 * B
        res += C-B if A >= (C-B) else A+1
        print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5308