akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 4003
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int bit[2][mx],dep[2003][2003],a[mx],tempatb[mx],tempatw[mx],putih[mx][2003],hitam[mx][2003],col[mx],n;

void upd(int c,int idx){
	for(;idx<=n;idx+=idx&-idx)
		bit[c][idx]++;
}

int query(int c,int idx){
	int ret=0;
	for(;idx;idx-=idx&-idx)ret+=bit[c][idx];
	return ret;
}

int dp(int black,int white){
	if(black==n && white==n)return 0;
	int&ret=dep[black][white];
	if(ret!=-1)return ret;
	ret=1e9;
	if(black<n){
		ret=min(ret,dp(black+1,white)+hitam[tempatb[black+1]][black]+putih[tempatb[black+1]][white]);
	}
	if(white<n){
		ret=min(ret,dp(black,white+1)+hitam[tempatw[white+1]][black]+putih[tempatw[white+1]][white]);
	}
	//cout<<black<<' '<<white<<' '<<ret<<endl;
	return ret;
}


int main(){
	cin>>n;
	for(int i=1;i<=n*2;i++){
		char c;
		cin>>c>>a[i];
		if(c=='B')col[i]=0,tempatb[a[i]]=i;
		else col[i]=1,tempatw[a[i]]=i;
	}	
	//putih
	//di kiri lebih besar
	for(int di=1;di<=n*2;di++){
		for(int j=0;j<=n;j++){
			putih[di][j]=query(1,n)-query(1,j);
		//	cout<<di<<' '<<j<<' '<<putih[di][j]<<endl;
		}
		for(int j=0;j<=n;j++){
			hitam[di][j]=query(0,n)-query(0,j);
		}
		upd(col[di],a[di]);
	}
	reset(dep,-1);
	cout<<dp(0,0)<<endl;
}




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

using namespace std;
using ll=long long;
template <class T> using vec=vector<T>;
template <class T> using vvec=vec<vec<T>>;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define en "\n"

void solve(ll t,ll p,ll r){
    vvec<ll> wa(t,vec<ll> (p,0));
    vvec<ll> pena(t,vec<ll> (p,-1));

    REP(i,r){
        ll tt,pp,time;
        string s;
        cin>>tt>>pp>>time>>s;
        tt--;pp--;
        if(s=="CORRECT"){
            if(pena[tt][pp]==-1){
                pena[tt][pp]=1200*wa[tt][pp]+time;
            }
        }else{
            wa[tt][pp]++;
        }
    }

    vec<pair<ll,pair<ll,ll>>> num;
    REP(tt,t){
        ll ac=0,pen=0;
        REP(pp,p){
            if(pena[tt][pp]!=-1){
                ac++;
                pen+=pena[tt][pp];
            }
        }
        num.push_back({-ac, {pen,(ll)tt}});
    }

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

    for(auto i:num){
        ll ac=i.first;
        ll pen=i.second.first;
        ll tt=i.second.second;
        cout<<tt+1<<" "<<-ac<<" "<<pen<<en;
    }
}

int main(void){
    while(true){
        ll a,b,c;
        cin>>a>>b>>c;
        if(a==0)break;
        solve(a,b,c);
    }
    return 0;
}


Measured memory_bytes: 3228
while True:
    (a, op, b) = [int(i) if i.isdigit() else i for i in input().split()]
    if op == '?':
        break
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)

Measured memory_bytes: 7676
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)998244353) 
#define INF ((int)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

class Tree{
public:
	int n;
	vector<int> p;
	vector<int> l;
	vector<int> r;
	vector<int> d;
	vector<int> h;

	Tree(int N){
		n=N;
		p.resize(N, -1);
		l.resize(N, -1);
		r.resize(N, -1);
		d.resize(N, -1);
		h.resize(N, -1);
	}

	void add(int pa, int left, int right){
		if(left>=0){
			l[pa]=left;
			p[left]=pa;
		}
		if(right>=0){
			r[pa]=right;
			p[right]=pa;
		}
	}

	int get_brother(int id){
		if(p[id]==-1)return -1;
		int ll = l[p[id]];
		if(ll>=0&&ll!=id)return ll;
		int rr = r[p[id]];
		if(rr>=0&&rr!=id)return rr;
		return -1;
	}
	
	int get_depth(int id){
		if(p[id] == -1)return 0;
		if(d[id] >= 0)return d[id];
		return d[id] = get_depth(p[id]) + 1;
	}

	int get_height(int id){
		if(h[id]>=0)return h[id];
		int res = 0;
		if(r[id]>=0)res=max(res, get_height(r[id])+1);
		if(l[id]>=0)res=max(res, get_height(l[id])+1);
		return h[id]=res;
	}

	int get_degree(int id){
		int res = 0;
		if(r[id]>=0)++res;
		if(l[id]>=0)++res;
		return res;
	}

	int get_parent(int id){
		return p[id];
	}

	int get_root(int id){
		if(p[id]==-1)return id;
		return get_root(p[id]);
	}

	vector<int> get_preorder(int id){
		if(id==-1)return vector<int>(0);
		vector<int> res;
		res.push_back(id);
		vector<int> d;
		d = get_preorder(l[id]);
		res.insert(res.end(), ALL(d));
		d = get_preorder(r[id]);
		res.insert(res.end(), ALL(d));
		return res;
	}
	
	vector<int> get_inorder(int id){
		if(id==-1)return vector<int>(0);
		vector<int> res;
		vector<int> d;
		d = get_inorder(l[id]);
		res.insert(res.end(), ALL(d));
		res.push_back(id);
		d = get_inorder(r[id]);
		res.insert(res.end(), ALL(d));
		return res;
	}
	vector<int> get_postorder(int id){
		if(id==-1)return vector<int>(0);
		vector<int> res;
		vector<int> d;
		d = get_postorder(l[id]);
		res.insert(res.end(), ALL(d));
		d = get_postorder(r[id]);
		res.insert(res.end(), ALL(d));
		res.push_back(id);
		return res;
	}
};

int main(){
	int N;
	cin >> N;
	Tree t(N);
	REP(i, N){
		int a, b, c;
		cin >> a >> b >> c;
		t.add(a, b, c);
	}

	vector<int> line;
	cout << "Preorder" << endl;
	line=t.get_preorder(t.get_root(0));
	foreach(i, line)cout << " " << i;
	cout << endl;
	cout << "Inorder" << endl;
	line=t.get_inorder(t.get_root(0));
	foreach(i, line)cout << " " << i;
	cout << endl;
	cout << "Postorder" << endl;
	line=t.get_postorder(t.get_root(0));
	foreach(i, line)cout << " " << i;
	cout << endl;
	return 0;
}



Measured memory_bytes: 3172
#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 endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename 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=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> x(n);
	rep(i,n){
		cin>>x[i];
	}
	int ans=INF;
	FOR(i,-100,200){
		int now=0;
		rep(j,n){
			now+=(x[j]-i)*(x[j]-i);
		}
		chmin(ans,now);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_1-D: Maximum Profit

#include <algorithm>
#include <cstdio>

static int max_profit(int const rs[], const unsigned int n)
{
  auto r0 = rs[0], r1 = rs[1];

  auto cur_p = r1 - r0;
  auto max_p = cur_p;
  auto min_r = std::min(r0, r1);

  for (auto i = 2u; i < n; ++i) {
    const auto r = rs[i];
    cur_p = r - min_r;
    max_p = std::max(max_p, cur_p);
    min_r = std::min(min_r, r);
  }

  return max_p;
}

int main()
{
  unsigned int n;
  std::scanf("%d", &n);
  int rs[n];
  for (unsigned int i = 0; i < n; ++i) {
    std::scanf("%d", &rs[i]);
  }

  const int max_p = max_profit(rs, n);
  std::printf("%d\n", max_p);
}

// eof

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

int main() {
    int n;
    cin >> n;
    bool y = false;
    for(int i=0;i<n;i++) {
        char tmp;
        cin >> tmp;
        if(tmp == 'Y') {
            y = true;
        }
    }
    if(y) {
        cout << "Four" << endl;
    }
    else {
        cout << "Three" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){
	
	int a;
	scanf("%d",&a);
	
	if(a >= 64)printf("64\n");
	else if(a >= 32)printf("32\n");
	else if(a >= 16)printf("16\n");
	else if(a >= 8)printf("8\n");
	else if(a >= 4)printf("4\n");
	else if(a >= 2)printf("2\n");
	else if(a == 1)printf("1\n");
	
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  switch(N % 10) {
    case 3:
      cout << "bon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
  }
  return 0;
}

Measured memory_bytes: 3572
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

//2にん
// 0,1
// 1,1

//6にん
// 0,1,2,3,4,5
// 5,3,1,1,3,5

//7にん
// 0,1,2,3,4,5,6
// 6,4,2,0,2,4,6

int main(){
    ll mod = 1000000007;
    ll N,ans,a;
    cin >> N;
    ll A[N+2];
    ll cnt[N+2];
    llrep(i,N+2){
        cnt[i] = 0;
    }
    llrep(i,N){
        cin >> a;
        cnt[a] ++;
    }
    if (N%2==0){//even
        for(ll i=1; i<=N-1; i+=2){
            if (cnt[i]!=2){
                cout << 0 << endl;
                return 0;
            }
        }
        ans = 1;
        llrep(i,N/2){
            ans *= 2;
            ans %= mod;
        }
        cout << ans << endl;
        return 0;
    }else{//odd
        if (N==1){
            if (cnt[0]==1){
                cout << 1 << endl;
                return 0;
            }else{
                cout << 0 << endl;
                return 0;
            }
        }else{
            if (cnt[0]!=1){
                cout << 0 << endl;
                return 0;
            }
            for(ll i=2; i<N; i+=2){
                if (cnt[i] != 2){
                    cout << 0 << endl;
                    return 0;
                }
            }
            ans = 1;
            llrep(i,N/2){
                ans *= 2;
                ans %= mod;
            }
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int x, a, b;
    cin >> x >> a >> b;

    cout << (x - a) % b << endl;


    return 0;
}

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

using namespace std;

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

    int n, k, c;
    cin >> n >> k >> c;
    bool b[n];
    int most[n], most1[n];
    c++;

    for (int i = 0; i < n; i++) {
        char cc;
        cin >> cc;
        b[i] = (cc == 'o');
    }

    if (n == 1) {
        if (b[0] && k == 1)
            cout << 1 << '\n';
    } else {
        most[0] = b[0];
        for (int i = 1; i < c; i++)
            most[i] = max((int)b[i], most[i - 1]);
        for (int i = c; i < n; i++)
            most[i] = max(b[i] + most[i - c], most[i - 1]);

        most1[n - 1] = b[n - 1];
        for (int i = n - 2; i > n - c - 1; i--)
            most1[i] = max((int)b[i], most1[i + 1]);
        for (int i = n - c - 1; i >= 0; i--)
            most1[i] = max(b[i] + most1[i + c], most1[i + 1]);

        if (b[0] && most1[1] == k - 1)
            cout << 1 << '\n';

        for (int i = 1; i < n - 1; i++)
            if (b[i] && most[i - 1] + most1[i + 1] == k - 1)
                cout << i + 1 << '\n';

        if (most[n - 2] == k - 1 && b[n - 1])
            cout << n << "\n";
    }

    return 0;
}

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


def solve(S: str, T: str, A: int, B: int, U: str):
    if S == U:
        print("{0} {1}".format(A - 1, B))
    else:
        print("{0} {1}".format(A, B - 1))


# Generated by 1.1.6 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()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    U = next(tokens)  # type: str
    solve(S, T, A, B, U)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<double,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int x,y;cin >> x >> y;
    int r = 0;
    if(x==1) r += 300000;
    else if(x==2) r += 200000;
    else if(x==3) r += 100000;
    if(y==1) r += 300000;
    else if(y==2) r += 200000;
    else if(y==3) r += 100000;
    if(x==1&&y==1) r += 400000;
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
s = input()
 
RGB = s.count("R") * s.count("G") * s.count("B")
 
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    k = 2 * j - i
    if ( k >= n ):
      break
    if (s[i] != s[j]) & (s[j] != s[k]) & (s[i] != s[k]):
      RGB -= 1
print(RGB)


Measured memory_bytes: 9108
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)
#define ll long long

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

ll lcm(ll a, ll b){
  return a*b/gcd(a,b);
}

ll f(ll a,ll c,ll d){
  ll cnt=a;
  cnt-=a/c;
  cnt-=a/d;
  cnt+=a/lcm(d,c);
  return cnt;
}

int main(void){
  ll a,b,c,d,cnt=0,dd,x;
  cin>>a>>b>>c>>d;


  cnt=f(b,c,d)-f(a-1,c,d);
  

  cout<<cnt<<endl;



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    vector<pair<int,int>>jobs;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;

        cin>>a>>b;
        jobs.push_back({b,a});
    }
    sort(jobs.begin(),jobs.end());

    int sum=0;

    for(int i=0;i<n;i++){
        sum+=jobs[i].second;
        if(sum>jobs[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;

}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005;
vi v[N];
int p[N],child[N];
bool mark[N];
void dfs(int u,int par)
{
  p[u]=par;
  for(int v1:v[u])
    if(v1!=par) 
      dfs(v1,u);
}
void dfs2(int u,int root,int par=-1)
{
  child[root]++;
  for(int v1:v[u])
    if(!mark[v1] && v1!=par)
      dfs2(v1,root,u);
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,x,y;
  cin>>n;
  rep(i,1,n)
    {
      cin>>x>>y;
      v[x].pb(y); v[y].pb(x);
    }
  dfs(1,-1);
  vi path;
  int curr=n;
  while(curr!=-1)
    {
      path.pb(curr);
      mark[curr]=true;
      curr=p[curr];
    }
  reverse(all(path));
  rep(i,1,n+1)
    if(mark[i]) dfs2(i,i);
  int sum1=0,sum2=0;
  rep(i,0,sz(path))
    {
      if(i<(sz(path)+1)/2) sum1+=child[path[i]];
      else sum2+=child[path[i]];
    }
  if(sum1<=sum2) cout<<"Snuke"<<endl;
  else cout<<"Fennec"<<endl;
  return 0 ;
}


Measured memory_bytes: 11768
N = int(input())
L = [0]*N
R = [0]*N

for i in range(N):
	L[i],R[i] = map(int,input().split(" "))
L.sort(reverse=True)
R.sort()
ans = 0
acc = 0
for i in range(N):
	ans = max(ans,acc+2*L[i])
	acc += (2*(L[i]-R[i]))
	ans = max(ans,acc)

acc = 0
for i in range(N):
	ans = max(ans,acc+2*(-R[i]))
	acc += (2*(L[i]-R[i]))
	ans = max(ans,acc)

print(ans)



Measured memory_bytes: 13360
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_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(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  //https://atcoder.jp/contests/abc076/tasks/abc076_c
  string r,t; cin >> r >> t;
  string rr(r);
  string s;
  int n=r.size(), m=t.size();
  bool un = true;
  rep(i,n-m+1) {
    bool ok = true;
    rep(j,m) {
      if(r[i+j] == '?') continue;
      if(r[i+j] == t[j]) continue;
      ok=false;
      break;
    }
    if(ok) {
      string ss(r);
      rep(k, n) {
        if(k<i) ss[k] = rr[k];
        else if(k<i+m) ss[k] = t[k-i];
        else if(rr[k]=='?') ss[k] = 'a';
        else ss[k] = rr[k];
      }
      if(un) s=ss;
      else umin(s, ss);
      un=false;
    }
    if(rr[i]=='?') rr[i] = 'a';
  }
  if(un) puts("UNRESTORABLE");
  else cout << s << endl;
}


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

using namespace std;

int down(int st, vector<int>& vec) {
    auto c = 0;
    for (auto i = st ; i < vec.size() - 1 ; i++) {
        if (vec[i] >= vec[i + 1]) c++;
        else return c;
    }
    return c;
}

int main() {
    int count;
    cin >> count;

    vector<int> vec;
    for (auto i = 0 ; i < count ; i++) {
        int a;
        cin >> a;
        vec.push_back(a);
    }

    // 一番前から順に走査
    auto c = 0;
    auto i = 0;
    while(i < count - 1) {
        // 進めるまで進んで、その次のマスからサーチする
        auto ret = down(i, vec);
        if (c < ret) c = ret;

        // 進めているならその分を進める。進めていないなら、次の要素から
        if (ret > 0) i += ret;
        else i++;
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define ll          long long
#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
#define track(x)                cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define ed(i)       i.end()
#define mem(a)      memset(a, 0, sizeof(a))
#define MOD         1000000007
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int &b) {a = max(a, b); }
void self_min(int &a, int &b) {a = min(a, b); }
#define hell        1000000007
bool isPrime(long int n) 
{
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}


ll power(int x, unsigned int y, int p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
        // y must be even now 
        y = y>>1; // y = y/2
        x = (x*x) % p;  
    } 
    return res;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vi res(n+1, 0);
	rep(i, 1, n+1) {
		if(s[i-1] == 'C' && s[i - 2] == 'A') {
			res[i] = res[i - 1] + 1;
		}
		else {
			res[i] = res[i - 1];
		}
	}

	
	while(q--) {
		int a, b;
		cin >> a >> b;

		int ans = res[b] - res[a];
		cout << ans << endl;
	}

}
int main() {
	// freopen("input.txt", "rt", stdin);
	// freopen("output.txt", "wt", stdout);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
}



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

using namespace std;
int  m,st1, dr1,st2,dr2;
int main()
{

	long long a, b, n,p,k;
	cin >> a >> b >> n;
	if(b == 1)
	{
		cout << 0;
		return 0;
	}

	else if(n<=b-1)
	{
		cout << (a * n) / b - a * (n / b);
		return 0;
	}

	p = (b - 1);
	k = n / p;
	p = k * p;
	cout << (a * p) / b - a * (p / b) << '\n';
return 0;

//	cin >> n >> m;
//
//    st1 = 1;
//    dr1 = n;
//
//    st2 = n/2;
//    dr2 = n/2+1;
//    if(n%2) ++dr2;
//
//    for(int i=1;i<=m;++i)
//    {
//        if(i%2)
//        {
//            cout<<st1<<' ' <<dr1<<'\n';
//            ++st1;
//            --dr2;
//        }
//        else
//        {
//            cout<<st2<<' '<<dr2<<'\n';
//            --st1;
//            ++dr2;
//        }
//    }

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}

int main(){
    int n;
    cin >> n;
    ll l[2] = {2, 1};
    rep(i, n - 1){
        l[i % 2] = l[0] + l[1];
    }
    cout << l[n % 2] << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  cout << A.at(N-1) - A.at(0) << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m; cin >>n >>m;
    cout <<((n*(n-1))/2) + ((m*(m-1))/2) <<endl;

    return 0;
}


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

using i64 = int64_t;

int main(){
    int n;
    string s;
    cin >> n >> s;
    for(char c: s){
        int nc = c + n;
        if(nc > 'Z')nc -= 26;
        cout << (char)nc;
    }
    cout << endl;

    return 0;
}


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

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    ll N,K,res;

    res = 0;
    string tmp;
    cin >> N >> K;

    ll ans1 = N/K;
    //Kが奇数なら、a  b  cすべてがわりきれる
    if(K % 2 == 1 || N < K/2)
    {
        cout << ans1*ans1*ans1 << endl;
    }
    else
    {
        //Kが偶数ならすべてわりきれるか すべて k/2あまる

        //N == 15,K == 4の場合  6,6,6   6,10,14など
        ll ans2 = (N-K/2)/K+1;
        cout << ans1*ans1*ans1 + ans2*ans2*ans2 << endl;
    }    

    return 0;

}



Measured memory_bytes: 256
// AOJ 2123: Divisor Function
// 2017.12.29 bal4u@uu

#include <stdio.h>
 
long long tbl[89] = {
1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,10080,15120,25200,27720,55440,
110880,166320,277200,332640,554400,665280,720720,1441440,2162160,3603600,4324320,7207200,8648640,
10810800,21621600,36756720,61261200,73513440,122522400,147026880,183783600,367567200,698377680,
735134400,1102701600ll,1163962800ll,1396755360ll,2327925600ll,2793510720ll,3491888400ll,6983776800ll,
13967553600ll,20951330400ll,27935107200ll,41902660800ll,48886437600ll,80313433200ll,160626866400ll,
321253732800ll,481880599200ll,642507465600ll,963761198400ll,1124388064800ll,1927522396800ll,
2248776129600ll,3373164194400ll,4497552259200ll,4658179125600ll,6746328388800ll,9316358251200ll,
13974537376800ll,18632716502400ll,27949074753600ll,32607253879200ll,55898149507200ll,65214507758400ll,
97821761637600ll,130429015516800ll,144403552893600ll,195643523275200ll,288807105787200ll,
433210658680800ll,577614211574400ll,866421317361600ll,1010824870255200ll};

double ans[89] = {
1.000000,1.500000,1.750000,2.000000,2.333333,2.500000,2.527778,2.583333,2.800000,3.000000,
3.033333,3.100000,3.250000,3.358333,3.428571,3.466667,3.542857,3.714286,3.838095,3.900000,
3.936508,3.966032,4.051948,4.187013,4.254545,4.294372,4.326580,4.363636,4.396364,4.398268,
4.509091,4.581818,4.624709,4.659394,4.699301,4.734545,4.736597,4.778866,4.855944,4.896750,
4.933476,4.975730,5.013048,5.015220,5.059975,5.141588,5.154474,5.182394,5.184434,5.193133,
5.237611,5.276893,5.279179,5.326290,5.412198,5.455152,5.457299,5.476629,5.500611,5.508844,
5.557868,5.647511,5.692332,5.694573,5.714743,5.739768,5.748359,5.762366,5.793981,5.796262,
5.816792,5.842252,5.842264,5.888619,5.890938,5.911803,5.937691,5.946578,5.961068,5.993773,
5.996133,6.017371,6.030712,6.043722,6.078575,6.080968,6.102506,6.129230,6.138403};

int bsch(long long x)
{
	int m, l = 0, r = 89;

    while (l < r) {
        m = (l + r) >> 1;
		if (tbl[m] == x) return m;
        if (tbl[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
    long long n;

	while(scanf("%lld", &n) && n > 0) {
        printf("%.6lf\n",ans[bsch(n)]);
    }
	return 0;
}

Measured memory_bytes: 1808
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;


#include <stdio.h>
#include <string.h>
 
int main(void)
{
	int num[11];	
	long long ans=0;
	
    string S;
	cin >> S;
	
	int len=S.length();
	for(int i=0;i<len;i++){
        num[i] = S[i] - 48;
	}
	
	for(int i=0;i<(1<<len-1);i++){
		long long temp=num[0];
        long long sum = 0;

		for(int j=0;j<len-1;j++){
			if(i&1<<j){
				temp=temp*10+num[j+1];
			}else{
				sum=sum+temp;
				temp=num[j+1];
			}
		}
		
		sum += temp;
		ans += sum;
	}
	
    cout << ans << endl;
	//printf("%ld",ans);
	
	return 0;
}

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

bool	issmall(char c)
{
	return (c >= 'a' && c <= 'z');
}

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

	string	o, e;
	cin >> o >> e;
	rep(i, e.size())
		cout << o.at(i) << e.at(i);
	if (o.size() > e.size())
		cout << o.back();
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define fr(i,p,n) for(int i=p;i<n;i++)
#define fr1(i,p,n) for(int i=p;i>=n;i--)
#define FAST ios::sync_with_stdio(0);
#define sz(v) (ll)v.size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 998244353
#define precise cout << std::setprecision(12) << std::fixed;
#define endl "\n"
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FAST
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int ans=n%1000;
        cout<<(1000-ans)%1000<<endl;    
    }
    return 0;
}


Measured memory_bytes: 3648
from collections import deque

def run():
  N, M = map(int, input().split())
  vertex_dict = {}
  for m in range(M):
    a, b = map(int, input().split())
    vertex_dict.setdefault(a, []).append(b)
    vertex_dict.setdefault(b, []).append(a)
  all_m_list = range(M)
  q = deque([])
  q.append((1, [1]))
  total = 0
  while True:
    #print(q)
    if len(q) == 0: break
    now_vertex, visited_list = q.popleft()
    if len(visited_list) == N:
      total += 1
      continue
    next_list = vertex_dict[now_vertex]
    for next_vertex in next_list:
      for visited_vertex in visited_list:
        if next_vertex == visited_vertex: break
      else:
        q.append((next_vertex, visited_list+[next_vertex]))
  print(total)
        
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 4460
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [a,b] = stdin.split('\n')[0].split(' ').map(Number)

const diff = b - a

let tower = 0
let towers = []
for (let i = 1; i <= 999; i++) {
  tower += i

  towers.push(tower)
}

let res = 0
towers.forEach((e, i) => {
  if(i > 0){
    if(e - towers[i-1] === diff){
      res = e - b
    }
  }
})

console.log(res)

Measured memory_bytes: 7500
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
ll dp[1000000];

ll solve(ll a[],ll n){
    if(n==0)
    {
        return 0;
    }
    if(n==1)
    {
        return abs(a[0]-a[1]);
    }
    else
    {
        if(dp[n]!=-1)
        {
            return dp[n];
        }
        else
        {
            dp[n]=min(solve(a,n-1)+abs(a[n]-a[n-1]),solve(a,n-2)+abs(a[n]-a[n-2]));
            return dp[n];
        }
    }
    

}

int main(){
   ll n;
   cin>>n;
   ll a[n];
   for(ll i=0;i<n;i++)
   {
       cin>>a[i];
   }
   for(ll i=0;i<100000;i++)
{
    dp[i]=-1;
}
   cout<<solve(a,n-1)<<"\n";
   return 0;
}

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

using namespace std;

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main() {
  int N, Q;
  scanf("%d %d", &N, &Q);
  BinaryIndexedTree< int > bit(N);
  while(Q--) {
    int T, X, Y;
    scanf("%d %d %d", &T, &X, &Y);
    if(T == 0) bit.add(X - 1, Y);
    else printf("%d\n", bit.sum(Y - 1) - bit.sum(X - 2));
  }
}


Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long N, sum = 0;
  cin >> N;
  for (int i = 0; i <= N; i++)
  {
    if (i % 3 == 0)
      continue;
    if (i % 5 == 0)
      continue;
    sum += i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))
up = 0
down = 1
for ai in a:
    down *= ai

for i in range(n)[::-1]:
    # print(i)
    mul = 1
    for j in range(n-1):
        mul *= a[i-j]
    up += mul
    # print(up)

ans = down / up
print(ans)

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

using namespace std;

int main() {
    int n, mx = 0, mn = 1e9;
    cin >> n;
    for(int i = 0, z; i < n; ++i) {
        cin >> z;
        mx = max(mx, z), mn = min(mn, z);
    }
    cout << mx - mn << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
int n;
string s;

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

    cin >> s;
    n = s.length();
    int act = 0;
    ll ans = 0;
    F0R(i, n){
        if(s[i] == 'A') ++act;
        else if(i != n-1 && s[i] == 'B' && s[i+1] == 'C'){
            ans += act;
            ++i;
        } else{
            act = 0;
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m;
ll a,b,c,d;
ll ans=0;
char s[200005];


int main(){
	
	cin>>s;
	n=strlen(s);
	for(i=0;i<n;i++){
		if(s[i]=='N')a++;
		if(s[i]=='E')b++;
		if(s[i]=='W')c++;
		if(s[i]=='S')d++;
	}
	n=0;m=0;
	if(a==d && a==0)n++;
	if(a*d!=0)n++;
	if(b==c && c==0)m++;
	if(b*c!=0)m++;
	if(n>0 && m>0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

const LL mod = 1000000007;

LL exgcd(LL a,LL b,LL &x,LL &y)
{
    if(b==0)
    {          
        x=1;
        y=0;
        return a;
    }
    LL r=exgcd(b, a%b, x, y);
    LL t=y;
    y=x-(a/b)*y;    
    x=t;
    return r;
}
LL ny(LL x) {
	if (x == (LL)(0)) {
		return 1;
	}
	LL xx, yy;
	exgcd(x, mod, xx, yy);
	while (xx < (LL)(0)) {
		xx += mod;
	}
	return xx;
}

LL getF(LL n) {
	if (n == (LL)(0)) {
		return 1;
	}
	LL res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
		res %= mod;
	}
	return res;
}

LL getC(LL n, LL k) {
	// cout << n << ' ' << k << endl;
	LL res = (LL)(1);
	for (LL i = n - k + 1; i <= n; i += (LL)(1)) {
		// cout << i << endl;
		res *= i;
		res %= mod;
	}
	for (LL i = 1; i <= k; i += (LL)(1)) {
		res *= ny(i);
		res %= mod;
	}
	return res;
	/*LL res = getF(n);
	LL fk = getF(k);
	res *= ny(fk);
	res %= mod;
	LL fnk = getF(n - k);
	res *= ny(fnk);
	res %= mod;
	return res;*/
}

LL divide(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
LL posDivide(LL n, LL k) {
	return getC(n - 1, k - 1);
}

int n, k;

vector<LL> calcC(int n) {
	LL c = 1;
	vector<LL> res;
	res.clear();
	res.push_back(c);
	for (int i = 1; i <= n; ++i) {
		c *= (n - i + 1);
		c %= mod;
		c *= ny(i);
		c %= mod;
		res.push_back(c);
	}
	return res;
}

int main() {
	cin >> n >> k;
	if (k >= n - 1) {
		cout << divide(n, n) << endl;
		return 0;
	}
	vector<LL> cn = calcC(n), cnp = calcC(n - 1);
	LL res = 0;
	for (int i = 0; i <= k; ++i) {
		res += (cn[i] * cnp[i]);
		res %= mod;
	}
	cout << res << endl;
	return 0;
}



/* int main() {
	cin >> n >> k;
	if (k >= n - 1) {
		LL res = getC((LL)(n + n - 1), (LL)(n - 1));
		cout << res << endl;
		return 0;
	}
	LL res = divide(n, n);
	for (int i = n - 1; i > k; --i) {
		res -= posDivide(i, n - i + 1);
		res += mod;
		res %= mod;
	}
	cout << res << endl;
	return 0;
} */

Measured memory_bytes: 4848
#include<iostream>
#include <vector>
using namespace std;
const int N = 2e5 + 10;
int ans=0,res=0;
int n , m ;
int vist[N];
bool cycle;
vector<vector<int> > v(N);
void dfs(int n , int p){
    vist[n] = true;
    for(int i = 0; i < v[n].size() ;i++){
        int cur = v[n][i];
        if(!vist[cur])
            {ans++;dfs(cur , n);}
        else if(cur != p)cycle = true;
    }
}
int main(){
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int x , y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    // finding number of components
    int number_of_component = 0;
	for(int i = 1; i <= n ; i++){
		if(!vist[i]){
		    ans=1;
			dfs(i , -1);
			res=max(res,ans);
			number_of_component++;
		}
	}
	cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 23884
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int n,t;
int main(){
    string s;
    cin >> s;
    for(int i=0; i<3; i++){
        if(s[i]=='1'){
            cout << "9";
        }else{
            cout << "1";
        }
    }
    cout <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define NUMBER 200000

int main(void)
{
    int n;
    int p[NUMBER];
    int i;
    int c = 1;
    
    scanf("%d",&n);
    for (i = 0;i < n;i++){
        scanf("%d",&p[i]);
        }
    
    int f[n];
    
    f[0] = p[0];
    for (i = 1;i < n;i++){
        if (p[i] <= f[i-1]){
            f[i] = p[i];
            c++;
        }
        else {
            f[i] = f[i-1];
        }
    }
    
    printf("%d\n",c);
    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>

using namespace std;

int solve(int n,int a,int b);

int main()
{
    int N,A,B,ans;

    cin >> N>>A>>B;
    ans=solve(N,A,B);
    cout<<ans;

}

int solve(int n,int a,int b){
    int sum=0,tmp=0,ans=0;
    for(int i=1;i<=n;i++){
        sum=0;
        tmp=i;
        sum+=tmp/10000;
        
        tmp=tmp-((tmp/10000)*10000);
        sum+=tmp/1000;
        
        tmp=tmp-((tmp/1000)*1000);
        sum+=tmp/100;
        
        tmp=tmp-((tmp/100)*100);
        sum+=tmp/10;
        
        tmp=tmp-((tmp/10)*10);
        sum+=tmp;
        
        
        if((a<=sum)&(sum<=b))ans+=i;
    }
    return ans;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n;
	cin >> n;
	double p[n];
	int i, j;
	for (i = 0; i < n; i++)cin >> p[i];

	double dp[n + 1][n + 1];
	for (j = 0; j <= n; j++)dp[0][j] = 0;
	for (i = 0; i <= n; i++)dp[i][0] = 1;

	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			dp[i][j] = (p[i - 1] * dp[i - 1][j - 1]) + ((1 - p[i - 1]) * dp[i - 1][j]);
		}
	}

	cout << setprecision(10) << dp[n][(n / 2) + 1] << endl;
	return;
}

int32_t main() {

	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	while (t--)solve();
	return 0;
}

Measured memory_bytes: 74136
#include<stdio.h>  
#include<algorithm>  
#include<string.h>  
#include<limits.h>  
#include<stdlib.h>  
#include<math.h>  
#include<queue>  
#include<map>  
using namespace std;
int  main()
{
	long long a[5];
	scanf("%lld%lld%lld",&a[1],&a[2],&a[3]);
	if(a[1]%2==0 || a[2]%2==0 || a[3]%2==0)
	printf("0\n");
	else
	{
		sort(a+1,a+4);
		printf("%lld\n",a[1]*a[2]);
	}
}

Measured memory_bytes: 128
local function upper_bound(key,ary)
    local n=#ary
    if n==0 then
        return 1 
    end
    if key<ary[1] then
        return 1
    end
    if key>=ary[n] then
        return n+1
    end
    local min,max=1,n
    while 1<max-min do
        local mid=(min+max)//2
        if key>=ary[mid] then
            min=mid
        else
            max=mid
        end
    end
    return max
end

n=io.read("*n","*l")
l={}
for i=1,n do
    l[i]=io.read("*n")
end
table.sort(l)
counter=0
for i=n,3,-1 do
    large=l[i]
    for j=i-1,2,-1 do
        middle=l[j]
        if middle*2<=large then
            break
        end
        local smallmin=upper_bound(large-middle,l)
        if smallmin<j then
            counter=counter+j-smallmin
        end
    end
end
print(counter)

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

using namespace std;

int main(void) {
	int h, n; cin >> h >> n;
	int a[n], b[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	
	int dp[h + 1] = {};
	fill_n(dp, h, INT_MAX);
	
	for (int i = 0; i < n; i++) {
		for (int j = h; j >= 0; j--) {
			if (dp[j] != INT_MAX)
				dp[max(0, j - a[i])] = min(dp[max(0, j - a[i])], dp[j] + b[i]);
		}
	}
	
	cout << dp[0] << "\n";
	
	return 0;
}

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

int main(){
  int n=0;
  long power=1;
  cin >> n;
  for(int i=1; i<n+1;i++){
    power = (i*power) %((long)pow(10, 9) + 7);
    //cout << power << endl;
  }
  //long long wari = pow(10, 9) + 7;
  //cout << wari << endl;
  cout << power << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi l(n);
    rep(i,n)cin>>l[i];
    SORT(l);
    int ans=0;
    rep(i,n){
        Rep(j,i+1,n){
            Rep(k,j+1,n){
                if(l[i]!=l[j]&&l[j]!=l[k]&&l[i]!=l[k]&&l[i]+l[j]>l[k])ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3648
using System;

namespace testes
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int ans = N * N * N;
            Console.WriteLine(ans);
        }
    }

}

/*
int a, b, c;
a = int.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = int.Parse(str[1]);
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力

string[] str = Console.ReadLine().Split(' ');
int[] a = new int[N];
for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]);
 */
 

Measured memory_bytes: 13140