akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll 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 gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	int n;
	cin>>n;
	vector<pair<ll,ll>>p(n);
	rep(i,n){
		int x;
		cin>>x;
		p[i]={x,i};
	}
	sort(rall(p));
	multiset<ll>st;
	st.emplace(-1);
	st.emplace(-1);
	st.emplace(n);
	st.emplace(n);
	ll ans=0;
	rep(i,n){
		st.emplace(p[i].second);
		auto itr=st.lower_bound(p[i].second);
		ll a=*prev(itr,2),b=*prev(itr),c=*next(itr),d=*next(itr,2),x=*itr;
		//cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<x<<"\n";
		ans+=p[i].first*((d-c)*(x-b)+(b-a)*(c-x));
	}
	cout<<ans<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 9424
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	int t = 1;
	// cin >> t;
	while (t--) {
		int n;
		cin >> n;

		n %= 1000;
		n = 1000 - n;
		if (n == 1000)n =0;
		cout << n;


	}
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x,ans;

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

int main()
{
	cin>>n>>x;
	cout<<(n-gcd(n,x))*3<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,K;
	string S;
	cin>>N>>K>>S;
	if(S[K-1]=='A')S[K-1]='a';
	if(S[K-1]=='B')S[K-1]='b';
	if(S[K-1]=='C')S[K-1]='c';
	cout<<S<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
neighbours = [[] for i in range(N)]
for i in range(M):
    A, B = map(lambda x:int(x)-1,input().split())
    neighbours[A].append(B)

visited = [False for i in range(N)]
def bfs(node):
    parents = [None for i in range(N)]
    stack = [node]
    while stack:
        item = stack.pop(0)
        orig = item
        for neighbour in neighbours[item]:
            if visited[neighbour]:
                if parents[neighbour] == None:
                    parents[neighbour] = item
                try:
                    graph = {neighbour}
                    while item != neighbour:
                        graph.add(item)
                        item = parents[item]
                        if item == orig and item != neighbour:
                            1/0
                    print(len(graph))
                    for item in graph:
                        print(item+1)
                    return True
                except:
                    pass
            if not visited[neighbour]:
                parents[neighbour] = item
                visited[neighbour] = True
                stack.append(neighbour)
            
for i in range(N):
    if not visited[i]:
        if bfs(i):
            break
else:
   print(-1)


Measured memory_bytes: 44908
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>

using namespace std;

template<typename T>
class SegTree
{
public:
  SegTree(const int size);
  void set(const int index, const T value);
  T query(const int a, const int b, const int l, const int r, const int k) const;
  T query(const int a, const int b) const;
  void print() const;
private:
  int left(const int parent) const;
  int right(const int parent) const;
  int parent(const int child) const;

  std::vector<T> array;
  int size_2;
};

template<typename T>
SegTree<T>::SegTree(const int size)
{
  size_2 = 1;
  while(size_2 < size) size_2 *= 2;

  array.resize(size_2 * 2 - 1);
  std::fill(array.begin(), array.end(), std::numeric_limits<T>::max());
}

template<typename T>
int SegTree<T>::left(const int parent) const
{
  return parent * 2 + 1;
}

template<typename T>
int SegTree<T>::right(const int parent) const
{
  return parent * 2 + 2;
}

template<typename T>
int SegTree<T>::parent(const int child) const
{
  return (child - 1) / 2;
}   

template<typename T>
void SegTree<T>::set(int index, const T value)
{
  index += size_2 - 1;
  array[index] = value;
  while(index > 0)
  {
	index = parent(index);
	array[index] = min(array[left(index)], array[right(index)]);
  }
}

template<typename T>
void SegTree<T>::print() const
{
  for(auto v : array)
  {
	cerr << v << ", ";
  }
  cerr << endl;
}

template<typename T>
T SegTree<T>::query(const int a, const int b) const
{
  return query(a, b, 0, size_2, 0);
}

// [l, r)?????¨??????k????????????[a, b)???????°????????±????????????¨???????????????
template<typename T>
T SegTree<T>::query(const int a, const int b, const int l, const int r, const int k) const
{
  if(r <= a || b <= l)
  {
	return std::numeric_limits<T>::max();
  }
  else if(a <= l && r <= b)
  {
	return array[k];
  }
  else
  {
	int l_val = query(a, b, l, (l + r) / 2, left(k));
	int r_val = query(a, b, (l + r) / 2, r, right(k));
	return std::min(l_val, r_val);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, q;
  cin >> n >> q;

  SegTree<int> tree(n);
  
  for(int i = 0; i < q; i++)
  {
	int com, x, y;
	cin >> com >> x >> y;

	if(com == 0)
	{
	  tree.set(x, y);
	}
	else if(com == 1)
	{
	  cout << tree.query(x, y + 1) << endl;
	}
  }
}	

Measured memory_bytes: 3760
# ABC097C - K-th Substring (ARC097C)
def get_substring(a: str, x: int) -> set:
    ret = set()
    for i in range(N - x + 1):
        ret |= {a[i : i + x]}
    return ret


def main():
    global N
    S = input()
    K = int(input())
    N, x = len(S), set()
    for i in range(1, K + 1):
        x |= get_substring(S, i)
    ans = sorted(x)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 4832
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++) {
      if (i % K == 0) {
        cout << "OK";
        return 0;
      }
    }
    cout << "NG";

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/




signed main() {
	int a, b; cin >> a >> b;
	int now = 1;
	for (int i = 0;; i++) {
		if (now >= b) {
			cout << i << endl; return 0;
		}
		now += a - 1;
	}
}


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

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int dp[s1.length()+1][s2.length()+1];
    for (int i = 0; i < s1.length()+1; ++i)
    {
        dp[i][0]=0;
    }
    for (int i = 0; i < s2.length()+1; ++i)
    {
        dp[0][i]=0;
    }
    for (int i = 1; i <= s1.length(); ++i)
    {
        for (int j = 1; j <= s2.length(); ++j)
        {
            if(s1[i-1]!=s2[j-1])
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            else
                dp[i][j]=1+dp[i-1][j-1];
        }
    }
    int index=dp[s1.length()][s2.length()];
    //cout<<index;
    vector<char> v;
    int y=s1.length(),x=s2.length();
    while(y>0 && x>0)
    {
        if(s1[y-1]==s2[x-1])
        {
            v.push_back(s1[y-1]);
            y--;
            x--;
            index--;
        }
        else if(dp[y-1][x]>dp[y][x-1])
            y--;
        else
            x--;
    }
    if(v.size()==0)
        cout<<"";
    else
    {
        for (int i = v.size()-1; i >= 0; i--)
        {
            cout<<v[i];
        }
    }
}


Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdint.h>
#include <math.h>
using namespace std;

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

int main()
{
    string s;
    cin >> s;
    int chars[26];
    rep(i, 26) chars[i] = 0;
    rep(i, s.length())
    {
        chars[s[i] - 'a']++;
    }
    bool NO = false;
    rep(i, 26)
    {
        if (chars[i] & 1)
        {
            NO = true;
            break;
        }
    }
    cout << (NO ? "No" : "Yes") << endl;
    return 0;
}

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

int main() {

  int x; cin >> x;
  
  int mini = 200000;
  int c = 0;
  for(int i=0; i<x; i++){
    
    int a; cin >> a;
      
    if (a <= mini) {
      c++;
      mini = a;
    }
    
  }
  
  cout << c << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int64_t& f(int *i) {
    return *(int64_t *)i;
}

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    char s[3][2001] = {};
    int k = 1;
    vector<int[2001]> v(n + 1);
    vector<int[2001][2]> e(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> s[k];
        int t = 0;
        for (int j = 0; j < m; j++) {
            v[i + 1][j + 1] = v[i][j + 1] + (t += (s[k][j] -= '0'));
            f(e[i + 1][j + 1]) = f(e[i][j + 1]) + f(e[i + 1][j]) - f(e[i][j]) + (s[k][j] & s[k][j - 1]) + ((int64_t)(s[k][j] & s[k ^ 3][j]) << 32);
        }
        k ^= 3;
    }

    for (int i = 0; i < q; i++) {
        int x0, y0, x1, y1;
        scanf("%d%d%d%d", &y0, &x0, &y1, &x1);
        int x2 = x0 - 1, y2 = y0 - 1;

        printf("%d\n", (v[y1][x1] - v[y1][x2] - v[y2][x1] + v[y2][x2]) - (e[y1][x1][0] - e[y1][x0][0] - e[y2][x1][0] + e[y2][x0][0]) - (e[y1][x1][1] - e[y1][x2][1] - e[y0][x1][1] + e[y0][x2][1]));
    }

    return 0;
}

Measured memory_bytes: 48768
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*200000
for i in a:
    l[i-1] += 1
l = sorted(l)
s = len(list(set(a)))
ret = 0
for i in range(s-k):
    ret += l[-s+i]
print(ret)


Measured memory_bytes: 26784
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  cin >> s;
  int n = s.length();
  int cnt1 = 0, cnt2 = 0;
  rep(i,n) {
    if (i % 2 == 0) {
      if (s[i] == '0') cnt1++;
      else cnt2++;
    }
    else {
      if (s[i] == '1') cnt1++;
      else cnt2++;
    }
  }
  cout << min(cnt1,cnt2) << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

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

int main(void)
{
    int n,k;
    vector<int> a;

    cin>>n>>k;
    for(int i = 0;i < n;i++)
    {
	int temp;
	cin>>temp;
	a.push_back(temp);
    }

    sort(a.begin(),a.end());

    int m = a[a.size()-1];

    int mod = 0;
    for(int i = 0;i < a.size();i++)
	mod = gcd(a[i],mod);

    if(k % mod == 0 && k <= m)
	cout<<"POSSIBLE"<<endl;
    else
	cout<<"IMPOSSIBLE"<<endl;


    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

typedef long long int llint;



void solve(void){

  llint n;
  std::cin >> n;
  std::map<llint, llint> cnt;

  llint ret = 0;
  for(int i=0; i<n; i++){
    llint tmp;
    std::cin >> tmp;
    if(cnt.find(tmp) == cnt.end()) cnt[tmp] = 0;
    cnt[tmp]++;
    ret += tmp;
  }

  llint q;
  std::cin >> q;
  for(int i=0; i<q; i++){
    llint b, c;
    std::cin >> b >> c;
    if(cnt.find(b) != cnt.end()){
      if(cnt.find(c) == cnt.end()) cnt[c] = 0;
      cnt[c] += cnt[b];
      ret += (c-b) * cnt[b];
      cnt.erase(b);
      
    }
    std::cout << ret << std::endl;
  }

}

int main(void){

  solve();
  
  return 0;
}


Measured memory_bytes: 7580
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2000000000
#define ninf -2000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int h[100005];
int dp[100005];
int n;
int k;
int compute(int i)
{
    if(i>n-1) return inf;
    if(i==n-1) return 0;
    if(dp[i]!=-1) return dp[i];
    int ans = inf;
    int j ;
    FOR(j, 1, k+1)
        ans = MIN2(ans, abs(h[i] - h[i+j])+compute(i+j));
    return dp[i] = ans;
}
int main()
{
    she_told_me_dont_worry
    cin>>n>>k;
    int i;
    FOR0(i, n) cin>>h[i];
    FOR0(i, n) dp[i] = -1;
    cout<<compute(0);
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

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

const ll INF = pow(10, 9) + 7;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  
  int sum = 0;
  rep(i,n){
    for(int j = i + 1;j < n;j++){
    sum += d[i]*d[j];
    }
  }
  cout << sum << endl;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

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

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll K, N;
    cin >> K >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    ll dist = 0;
    for (int i = 0; i < N - 1; ++i) {
        ll tmp = A[i + 1] - A[i];
        chmax(dist, tmp);
    }

    chmax(dist, A[0] + K - A[N - 1]);

    cout << K - dist << endl;
}

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

int solve0(string &s) {
    int cnt = 0, n = s.size();
    for (auto &x: s) cnt += (x != 'x');
    if (cnt == 0) {
        cout << 0 << "\n";
        return 0;
    }
    cnt /= 2;
    int lf, rg;
    for (int i = 0; i < n; i++) {
        if (s[i] != 'x') {
            if (cnt == 1) lf = i;
            if (cnt == 0) {
                rg = i;
                break;
            }
            cnt--;
        }
    }
    vector<pair<char, int>> l, r;
    for (int i = lf; i >= 0; i--) {
        if (s[i] - 'x') l.emplace_back(s[i], lf-i);
    }
    for (int i = rg; i < n; i++) {
        if (s[i] - 'x') r.emplace_back(s[i], i-rg);
    }
    if (l.size() != r.size()) cout << -1 << "\n";
    else {
        int ladd = 0, radd = 0, ans = 0;
        for (int i = 0; i < l.size(); i++) {
            if (l[i].first != r[i].first) {
                cout << -1 << "\n";
                return 0;
            }
            int maxi = max(ladd+l[i].second, radd+r[i].second);
            ans += (maxi - ladd - l[i].second) + (maxi - radd - r[i].second);
            ladd = maxi - l[i].second, radd = maxi - r[i].second;
        }
        if (l.empty()) {
            l.emplace_back(0, 0); r.emplace_back(0, 0);
        }
        int tail = abs((lf-l.back().second)-(n-rg-1-r.back().second));
        cout << ans + tail << "\n";
    }
    return 0;
}

int solve1(string s, int c) {
    int cnt = 0, n = s.size();
    for (auto &x: s) cnt += (x - 'a' == c);
    cnt = (cnt + 1) / 2;
    for (int i = 0; i < n; i++) {
        if (s[i] - 'a' == c) cnt--;
        if (cnt == 0) {
            c = i; break;
        }
    }
    vector<pair<char, int>> l, r;
    for (int i = c-1; i >= 0; i--) {
        if (s[i] - 'x') l.emplace_back(s[i], c-1-i);
    }
    for (int i = c+1; i < n; i++) {
        if (s[i] - 'x') r.emplace_back(s[i], i-c-1);
    }
    if (l.size() != r.size()) cout << -1 << "\n";
    else {
        int ladd = 0, radd = 0, ans = 0;
        for (int i = 0; i < l.size(); i++) {
            if (l[i].first != r[i].first) {
                cout << -1 << "\n";
                return 0;
            }
            int maxi = max(ladd+l[i].second, radd+r[i].second);
            ans += (maxi - ladd - l[i].second) + (maxi - radd - r[i].second);
            ladd = maxi - l[i].second, radd = maxi - r[i].second;
        }
        if (l.empty()) {
            l.emplace_back(0, 0); r.emplace_back(0, 0);
        }
        int tail = abs((c-1-l.back().second)-(n-c-2-r.back().second));
        cout << ans + tail << "\n";
    }
    return 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    vector<int> cnt(26, 0);
    for (int i = 0; i < s.size(); i++) cnt[s[i]-'a']++;
    int odd = 0;
    for (int i = 0; i < 26; i++) odd += (cnt[i] % 2) * (i != ('x' - 'a'));
    if (odd >= 2) cout << -1 << "\n";
    else if (odd == 0) return solve0(s);
    else {
        for (int i = 0; i < 26; i++) {
            if (i != 'x' - 'a') {
                if (cnt[i] % 2) return solve1(s, i);
            }
        }
    }
    return 0;
}

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

using namespace std;

using ll=long long;

ll dp[111][111111];

const ll maxn=1000*100+100;

int main()
{
    ll n,W;
    cin>>n>>W;
    vector<pair<ll,ll>>v;
    v.push_back({-1,-1});
    for(int i=0;i<n;i++)
    {
        ll w,va;
        cin>>w>>va;
        v.push_back({w,va});
    }

    for(ll j=1;j<=maxn;j++)
    {
        dp[0][j]=(ll)(1e18);
    }

    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<=maxn;j++)
        {
            dp[i][j]=dp[i-1][j];

            if(j-v[i].second>=0)

                dp[i][j]=min(dp[i][j],dp[i-1][j-v[i].second]+v[i].first);

        }
    }

    ll ans=0;

    for(ll j=0;j<=maxn;j++)
    {
        if(dp[n][j]<=W)
            ans=max(ans,j);
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 88192
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


int main() {
	ll N, A, B; cin >> N >> A >> B;
	ll x[100100];
	REP(i, N)cin >> x[i];
	ll ans = 0;
	ll now = x[0];
	for (int i = 1; i < N; ++i) {
		ans += min(B, (x[i] - now)*A);
		now = x[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import Data.Function
import Data.List

type Dice = (Int, Int, Int, Int, Int, Int)

topd :: Dice -> Int
topd (a, _, _, _, _, _) = a

frontd :: Dice -> Int
frontd (_, b, _, _, _, _) = b

rightd :: Dice -> Int
rightd (_, _, c, _, _, _) = c

spinl :: Dice -> Dice
spinl (a, b, c, d, e, f) = (a, d, b, e, c, f)

spinr :: Dice -> Dice
spinr (a, b, c, d, e, f) = (a, c, e, b, d, f)

moven :: Dice -> Dice
moven (a, b, c, d, e, f) = (b, f, c, d, a, e)

moves :: Dice -> Dice
moves (a, b, c, d, e, f) = (e, a, c, d, f, b)

movee :: Dice -> Dice
movee (a, b, c, d, e, f) = (d, b, a, f, e, c)

movew :: Dice -> Dice
movew (a, b, c, d, e, f) = (c, b, f, a, e, d)

move :: Char -> Dice -> Dice
move 'N' = moven
move 'S' = moves
move 'E' = movee
move 'W' = movew

allMoves :: Dice -> [Dice]
allMoves d = concatMap spins $ map ($d) [id, moven, moves, movee, movew, moven . moven]
  where
    spins x = [x, spinl x, spinr x, spinl (spinl x)]

normalize :: Dice -> Dice
normalize = minimum . allMoves

makeDice [a, b, c, d, e, f] = (a, b, c, d, e, f)

main = on (==) (normalize . makeDice . map read . words) <$> getLine <*> getLine >>= \p -> putStrLn (if p then "Yes" else "No")



Measured memory_bytes: 3724
#include <iostream>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
int main(){
    int n; double sum=0; cin >> n;
    double a,i; string s;
    rep(i,n){
        cin >> a >> s;
        if (s == "JPY" ) sum += a;
        else sum += 380000.0*a;
    }
    cout << sum << endl;
}

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


def solve(x: int, a: int, b: int):
    if abs(x - a) > abs(x - b):
        print("B")
    else:
        print("A")
    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()
    x = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(x, a, b)


if __name__ == '__main__':
    main()


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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
    return power((a*a)%mod,n/2)%mod;
}*/
//const int md = 998244353;

/*int inverse(int x){

    return power(x,mod-2)%mod;//little fermat....
}*/
//const int inf = (int) 1e18+100;
//const int md = (int) 1e9+21;

int cnt[30];

signed main()
{
    showoff;
    int n;
    cin >> n;
    string s;
    cin >> s;
    FOR(i,0,n){
        cnt[s[i]-'a']++;
    }
    int ans = 1;
    FOR(i,0,30){
        ans = ans*(cnt[i]+1);
        ans %= mod;
    }
    cout << (ans-1)%mod;
    return 0;

}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Measured memory_bytes: 512
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main(){
int x=0,y=0,z=0,w=0;
std::cin >> x>>y;
std::cout << x*y << '\n';
}



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

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<llint,vector<llint>,greater<llint>> que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
llint n,x;
llint a[55],b[55];

llint calc(llint N,llint X){
	if(X<=0)return 0;
	if(N<=0)return 1;
	if(X>a[N]/2){
		return b[N-1]+1+calc(N-1,X-1-a[N]/2);
	}
	else{
		return calc(N-1,X-1);
	}
}

void solve(){
	cin >> n >> x;

	a[0]=1;
	b[0]=1;
	for(int i=1;i<51;i++){
		a[i]=2*a[i-1]+3;
		b[i]=2*b[i-1]+1;
	}
	cout << calc(n,x) << endl;
}

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


Measured memory_bytes: 256
/* ex7_1
   UMAboogie */

#include<stdio.h>

//座標用の構造体を宣言
typedef struct point{
    int x_elem;
    int y_elem;
}point;

//座標をずらす関数を定義
point shift_point(point a, int x, int y){
  point b;
  b.x_elem = a.x_elem + x;
  b.y_elem = a.y_elem + y;
  return b;
}


int main(void){
  point vertex_1,vertex_2,vertex_3,vertex_4;
  int x_gap,y_gap;
  //2点の座標を入力
  scanf("%d %d %d %d", &vertex_1.x_elem, &vertex_1.y_elem, &vertex_2.x_elem, &vertex_2.y_elem);
  //2点がx方向、y方向にどれだけずれているかを計算し、それぞれx_gap,y_gapに代入
  x_gap = vertex_2.x_elem - vertex_1.x_elem;
  y_gap = vertex_2.y_elem - vertex_1.y_elem;

  //3点目は2点目をx方向に-y_gap,y方向にx_gapずらした点
  vertex_3 = shift_point(vertex_2, -y_gap, x_gap);
  //4点目は1点目をx方向に-y_gap,y方向にx_gapずらした点
  vertex_4 = shift_point(vertex_1, -y_gap, x_gap);

  //答えを入力
  printf("%d %d %d %d", vertex_3.x_elem, vertex_3.y_elem, vertex_4.x_elem, vertex_4.y_elem);

  return 0;
}


Measured memory_bytes: 1696
n = int(input())
S = input()

rw = S.count('.')
rb = S.count('#')
lw = 0
lb = 0

ans = min(rb, rw)
for s in S:
    if s == '.':
        lw += 1
        rw -= 1
    else:
        lb += 1
        rb -= 1
    ans = min(ans, lb+rw)
print(ans)


Measured memory_bytes: 9424
#include <stdio.h>

int main(void) {
    int n,ans;
    scanf("%d",&n);
    if (n < 105) {
        ans = 0;
    } else if (n < 135) {
        ans = 1;
    } else if (n < 165) {
        ans = 2;
    } else if (n < 189) {
        ans = 3;
    } else if (n < 195) {
        ans = 4;
    } else {
        ans = 5;
    }
    printf("%d\n",ans);
    return 0;
}


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

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

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


struct Edge { int to, cap, rev, cost; };
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;




struct MaxFlow {
	Graph G;
	vi level, iter;
	MaxFlow(Graph g) {
		int n = g.size();
		level.resize(n);
		iter.resize(n);
		G = g;
	}
	void add_edge(int from, int to, int cap, int cost = 0) {
		G[from].push_back(Edge{ to, cap, (int)G[to].size(),cost });
		G[to].push_back(Edge{ from,0,(int)G[from].size() - 1,-cost });
	}

	void bfs(int s) {
		fill(ALL(level), -1);
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (int i = 0; i < G[v].size(); i++) {
				Edge &e = G[v][i];
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}
	int dfs(int v, int t, int f) {
		if (v == t)return f;
		for (int &i = iter[v]; i < G[v].size(); i++) {
			Edge &e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	int max_flow(int s, int t) {
		int flow = 0;
		for (;;) {
			bfs(s);
			if (level[t] < 0)return flow;
			fill(ALL(iter), 0);
			int f;
			while ((f = dfs(s, t, INF)) > 0) {
				flow += f;
			}
		}
	}
};



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n), b(n), c(n), d(n);
	REP(i, n)cin >> a[i] >> b[i];
	REP(i, n)cin >> c[i] >> d[i];
	Graph g(2 * n + 2);
	MaxFlow mf(g);
	REP(i, n) {
		REP(j, n) {
			if (a[i] < c[j] && b[i] < d[j]) {
				mf.add_edge(i + 1, j + n + 1, 1);
			}
		}
	}
	REP(i, n) {
		mf.add_edge(0, i + 1,1);
		mf.add_edge(i + n + 1, 2 * n + 1,1);
	}
	cout << mf.max_flow(0, 2 * n + 1) << endl;
}


Measured memory_bytes: 384
//B - Judge Status Summary


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	int ac = 0, wa = 0, tle = 0, re = 0;

	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		string s;
		cin >> s;
		if (s == "AC")
		{
			ac++;
		}
		else if (s == "WA")
		{
			wa++;
		}
		else if (s == "TLE")
		{
			tle++;
		}
		else
		{
			re++;
		}
	}
	cout << "AC " << "x " << ac << endl;
	cout << "WA " << "x " << wa << endl;

	cout << "TLE " << "x " << tle << endl;
	cout << "RE " << "x " << re << endl;



	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main() {
	int t, i=0, j, k;
	int a, b, c=0 ,d,n,F=0,M=0,m=1000;
	string A,D,E;
	char B,C;
	cin >> a ;
	vector <int> V(a);
	for (i = 0; i < a; i++) {
		cin >> V[i];
	}
	for (i = 0; i < a; i++) {
		if (M < V[i]) {
			M = V[i];
		}
		if (m > V[i]) {
			m = V[i];
		}
	}
	c = M - m;
	cout << c << endl;
	return 0;
}

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

int t[200][200], u[200][200];
int main() {
  while (1) {
    int n, h, w, H, W, ans = 0;
    cin >> n;
    if (n == 0) break;
    cin >> W >> H;
    for (int i = 0; i < 200; i++)
      for (int j = 0; j < 200; j++) t[i][j] = u[i][j] = 0;

    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      t[x][y] = 1;
    }

    for (int i = 1; i < 200; i++)
      for (int j = 1; j < 200; j++)
        u[i][j] = t[i][j] + u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1];

    cin >> w >> h;
    w--, h--;
    for (int i = 1; i + w <= W; i++) {
      for (int j = 1; j + h <= H; j++) {
        int cnt = u[i + w][j + h] - u[i - 1][j + h] - u[i + w][j - 1] +
                  u[i - 1][j - 1];
        ans = max(ans, cnt);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3344
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EDivisibleSubstring solver = new EDivisibleSubstring();
        solver.solve(1, in, out);
        out.close();
    }

    static class EDivisibleSubstring {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int p = in.nextInt();
            String x = in.next();
            HashMap<Long, Long> map = new HashMap<>();
            map.put(0L, 1L);
            long m = 0;
            long ans = 0;
            long xx = 1;
            if (p == 2) {
                for (int i = 0; i < n; i++) {
                    if ((x.charAt(i) - '0') % 2 == 0) {
                        ans += i + 1;
                    }
                }
                out.println(ans);
                return;
            }
            if (p == 5) {
                for (int i = 0; i < n; i++) {
                    if ((x.charAt(i) == '0') || x.charAt(i) == '5') {
                        ans += i + 1;
                    }
                }
                out.println(ans);
                return;
            }
            for (int i = n - 1; i >= 0; i--) {
                long c = x.charAt(i) - '0';
                m = ((((c % p) * (xx)) % p) + m) % p;
                ans += map.getOrDefault(m, 0L);
                map.put(m, map.getOrDefault(m, 0L) + 1);
                xx *= 10;
                xx %= p;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 46956
from itertools import accumulate
S=list(map(len,input().split("T")))
x,y=map(int,input().split())
x=abs(x-S[0])
y=abs(y)
L=S[2::2]
R=S[1::2]
La=list(accumulate(L))
Ra=list(accumulate(R))
sumL=sum(L)
sumR=sum(R)
flag=0
if sumL>=x and sumR>=y and (sumL-x)%2==0 and (sumR-y)%2==0 and flag==0:
    setL1={0}
    setR1={0}
    gL=(sumL-x)//2
    gR=(sumR-y)//2
    if gL==0:
        flag=1
    else:
        for i in L:
            setL=setL1
            setL1=set()
            s=setL1.add
            for j in setL:
                k=i+j
                s(k)
                s(j)
                if k==gL:
                    flag=1
                    break
            if flag==1:
                break
    if flag==1:
        if gR==0:
            flag=2
        else:
            for i in R:
                setR=setR1
                setR1=set()
                s=setR1.add
                for j in setR:
                    k=i+j
                    s(k)
                    s(j)
                    if k==gR:
                        flag=2
                        break
                if flag==2:
                    break
if flag==2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3692
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long K = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        if (B <= A+2) {
            System.out.println(K+1);
            return;
        } else {
            long Kres = K+1-A;
            System.out.println(A+(B-A)*(Kres/2)+Kres%2);
            return;
        }
    }
}

Measured memory_bytes: 35728
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// i日目, 訪れた頂点数j, 頂点1に戻れる頂点数k
ll dp[301][302][301];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    dp[0][1][1] = 1;
    rep(i, M) rep(j, N + 1) rep(k, N + 1) {
        (dp[i + 1][j + 1][k] += dp[i][j][k] * (N - j)) %= mod;
        if(j >= k) (dp[i + 1][j][k] += dp[i][j][k] * (j - k)) %= mod;
        (dp[i + 1][j][j] += dp[i][j][k] * k) %= mod;
    }
    
    output(dp[M][N][N]);
    
    
    return 0;
}

Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n, t, s; cin >> n >> t >> s;
    vector<ll> value(n), time(n);

    rep(i,n) cin >> value[i] >> time[i];
    vector<vector<ll>> dp1(n+1, vector<ll> (s+1,0));
    vector<vector<ll>> dp2(n+1, vector<ll> ((t-s)+1,0));

    for(int i = 0; i < n; i++){
        for(int T = 0; T <= s; T++){
            if(T >= time[i]) dp1[i+1][T] = max(dp1[i][T-time[i]] + value[i],dp1[i][T]);
            else dp1[i+1][T] = dp1[i][T];
        }
    }

    for(int i = 0; i < n; i++){
        for(int T = 0; T <= t-s; T++){
            if(T >= time[n-i]) dp2[i+1][T] = max(dp2[i][T-time[n-i]] + value[n-i],dp2[i][T]);
            else dp2[i+1][T] = dp2[i][T];
        }
    }

    ll ans = 0;
    rep(i,n){
        ans = max(dp2[i][t-s] + dp1[n-i][s], ans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 73656
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   int n;
   cin>>n;
   double a[n];
   for(int i=0;i<n;i++){
      cin>>a[i];
   }
   double sum=0;
   for(int i=0;i<n;i++){
      sum+=1/a[i];
   }
   cout<<1/sum<<endl;
   return 0;
}

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

int N;

int dfs(string s){
  if(s!= "" && stol(s) > N){
    return 0;
  } else {
    if(s.find("3") != string::npos
    && s.find("5") != string::npos
    && s.find("7") != string::npos){
      return dfs(s+"3")
          + dfs(s+"5")
          + dfs(s+"7")
          + 1;
    }else {
      return dfs(s+"3")
          + dfs(s+"5")
          + dfs(s+"7");
    }
  }
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
  x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL||k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }
  Node y;
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;

  if(y==NIL){
    root=z;
  }
  else if(z->key < y->key){
    y->left=z;
  }
  else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20452
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  long long h[N];
  bool changed[N];
  for (int i = 0; i < N; ++i) {
    cin >> h[i];
    changed[i] = false;
  }

  --h[0];
  changed[0] = true;
  for (int i = 1; i < N - 1; ++i) {
    if (h[i] >= h[i + 1] && h[i] - 1 >= h[i - 1]) {
      --h[i];
      changed[i] = true;
    }
  }

  for (int i = 0; i < N - 1; ++i) {
    if (h[i] > h[i + 1]) {
      //if (!changed[i]) {
      //  --h[i];
      //  changed[i] = true;
      //}
      if (h[i] > h[i + 1]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;

}

Measured memory_bytes: 1152
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Bits
import Data.List
import qualified  Data.ByteString as B


bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt


cnt :: BS.ByteString -> Int -> [[Int]]
cnt rgbs' n' = cn rgbs' (n'-1) [0] [0] [0]
    where
    cn rgbs (-1) rs gs bs = [rs, gs, bs]
    cn rgbs n rs@(r:_) gs@(g:_) bs@(b:_)
        | BS.index rgbs n == 'R' = cn rgbs (n-1) (1+r:rs) (  g:gs) (  b:bs) 
        | BS.index rgbs n == 'G' = cn rgbs (n-1) (  r:rs) (1+g:gs) (  b:bs)
        | BS.index rgbs n == 'B' = cn rgbs (n-1) (  r:rs) (  g:gs) (1+b:bs)


main :: IO ()
main = do 
    n <- bsToInt <$> BS.getLine  :: IO Int
    rgbs <- BS.getLine :: IO BS.ByteString
    let cnts = cnt rgbs n
    let ucnts = map  (listArray (0, n)) cnts ::[UArray Int Int]

    let t2 = 
            [ after - minus
            | i <- [0..n-3]
            , j <- [i+1..n-2]
            , let ci = BS.index rgbs i
            , let cj = BS.index rgbs j
            , ci /= cj
            , let rgbi
                    | notElem 'R' [ci, cj] = 0
                    | notElem 'G' [ci, cj] = 1
                    | notElem 'B' [ci, cj] = 2
                    ::Int
            , let after = ucnts !! rgbi ! (j+1)
            , let minus 
                    | after > 0 && 2*j - i < n && notElem (BS.index rgbs (2*j-i)) [ci, cj] = 1
                    | otherwise                = 0
            ]

    print $ sum t2


Measured memory_bytes: 4888
#include<stdio.h>
#include<string.h>
int main (){
	
	char strS[52];
	int smpe;
	int mana;
	
	1<=smpe<=50;
	1<=mana<=smpe;
	scanf("%d %d", &smpe, &mana);
	
	scanf("%s", &strS);
	mana = mana -1;
	strS [mana] +=32 ;
	printf("%s", strS);
	
	
	return 0;
}

Measured memory_bytes: 1700