akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];

struct BinaryIndexTree {
public:
    BinaryIndexTree(int n)
            : mN(n) {
        mPow = 1;
        while (mPow < n)
            mPow <<= 1;
        node.resize(n + 1);
        REP(i, n + 1) {
            node[i] = 0;
        }
    }

    ~BinaryIndexTree() {
        node.resize(0);
    }

    //! 1-index get
    ll sum(int index) {
        ll sum = 0;
        for (int i = index; i > 0; i -= i & (-i))
            sum += node[i];
        return sum;
    }

    //! 1-index add
    void add(int index, ll value) {
        for (int i = index; i <= mN; i += i & (-i))
            node[i] += value;
    }

    int lowerBound(ll value) {
        if (value <= 0)
            return 0;
        int x = 0;
        for (int k = mPow; k > 0; k >>= 1) {
            if (x + k <= mN && node[x + k] < value) {
                value -= node[x + k];
                x += k;
            }
        }
        return x + 1;
    }

private:
    vector<ll> node;
    ll mN;
    ll mPow;
};

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

    ll N, K;
    cin >> N >> K;
    vector<ll> v;
    ll s = 0;
    REP(i, N) {
        cin >> A[i];
        s += A[i];
        v.push_back(s - (i + 1) * K);
    }
    v.push_back(0);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    BinaryIndexTree bit(v.size() + 5);
    ll ans = 0;
    bit.add((lower_bound(v.begin(), v.end(), 0) - v.begin()) + 1, 1);
    s = 0;
    REP(i, N) {
        s += A[i];
        ll n = s - K * (i + 1);
        ll index = lower_bound(v.begin(), v.end(), n) - v.begin();

        ans += bit.sum(index + 1);
        bit.add(index + 1, 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5104
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    ll ans=0,n;cin>>n;
    map<string,int> s;
    for(ll i=0;i<n;i++){
        string a;cin>>a;
        sort(a.begin(),a.end());
        if(s[a]>0){
            ans+=s[a];
        }
        s[a]++;
    }
    // for (auto const& x : s){
    //     ll k=1;
    //     if(x.second>1){
    //         for(;;){
    //             if(k!=x.second){
    //                 ans+=x.second-k;
    //                 k++;
    //             } else {
    //                 break;
    //             }
    //         }
    //     }
    // }
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
n,k=map(int,input().split())
l = []
for i in range(n):
  a,b=map(int,input().split())
  l.append((a,b))
l = sorted(l)
c = 0
i = 0
while c < k:
  c += l[i][1]
  i += 1

print(l[i-1][0])


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

const int maxn = 105;

int n;
pair<int, int> red[maxn], blue[maxn];
set<int> wr;

void Init()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &red[i].first, &red[i].second);
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &blue[i].first, &blue[i].second);
	}
}

void Solve()
{
	int p = 0;
	int Ans = 0;
	sort(red + 1, red + 1 + n);
	sort(blue + 1, blue + 1 + n);
	for (int i = 1; i <= n; ++i) {
		while (p < n && red[p + 1].first < blue[i].first) {
			wr.insert(red[++p].second);
		}
		set<int>::iterator tmp = wr.lower_bound(blue[i].second);
		if (tmp == wr.begin()) {
			continue;
		}
		else {
			--tmp;
			wr.erase(tmp);
			++Ans;
		}
	}
	printf("%d\n", Ans);
}

int main()
{
	Init();
	Solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353,N=1e7+5;
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1;
	}
	return res;
}
int fac[N],inv[N];
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);
	for(int i=n-1;i>=0;--i)
		inv[i]=(i+1)*inv[i+1]%mod;
}
int C(int n,int m){
	if(n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void add(int &x,int y){
	x=(x+y)%mod;
}
void dec(int &x,int y){
	x=(x+mod-y)%mod;
}
signed main(){
	int n,m,ans=0;
	cin>>n>>m;
	init(n+3*m);
	for(int i=0;i<=m;++i)
		if((3*m-i)%2==0) add(ans,C(n,i)*C((3*m-i)/2+n-1,n-1)%mod);
	for(int i=2*m+1;i<=3*m;++i)
		dec(ans,n*C(3*m-i+n-2,n-2)%mod);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 42652
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, n;
	cin >> x >> n;
	set<int> st;
	rep(i,n){
		int p;
		cin >> p;
		st.insert(p);
	}
	for(int i = 0; i <= 101; ++i){
		if(st.find(x-i) == st.end()){
			cout << x-i << endl;
			return 0;
		}
		if(st.find(x+i) == st.end()){
			cout << x+i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3608
N, M = map(int, input().split())

isACs = [0] * N
numWAs = [0] * N
numPenalty = 0
for _ in range(M):
    p, res = input().split()
    p = int(p) - 1
    if res == 'AC':
        if not isACs[p]:
            numPenalty += numWAs[p]
        isACs[p] = 1
    else:
        numWAs[p] += 1

numAC = sum(isACs)
print(numAC, numPenalty)


Measured memory_bytes: 10344
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;
int main(){
  int a,b,c,aa,bb,cc,aaa,bbb,ccc;
  cin>>a>>b>>c>>aa>>bb>>cc>>aaa>>bbb>>ccc;
  bool ok=false;
  bool o=false;
  bool k=false;
  bool ko=false;
  if((a-b)==(aa-bb) and (a-b)==(aaa-bbb))
    ok=true;
  if((b-c)==(bb-cc) and (b-c)==(bbb-ccc))
    o=true;
  if((a-aa)==(b-bb) and (a-aa)==(c-cc))
    k=true;
  if((aa-aaa)==(bb-bbb) and (aa-aaa)==(cc-ccc))
    ko=true;
  if(ok and o and k and ko)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
  using namespace std;
  int main()
  {
    int n, q, num, m;
    int A[2001]={};
    A[0]=1;
      cin>>n;
    for(int i=0; i<n; i++){
      cin>>num;
      for(int j=2000-num; j>=0; j--){
        if(A[j]) A[j+num] = 1;
      }
    }

      cin>>q;
    for(int i=0; i<q; i++){
      cin>>m;
      if(A[m])
        cout<<"yes"<<endl;
      else
        cout<<"no"<<endl;
    }

    return 0;
  }


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a==b) cout << c << endl;
  if (a==c) cout << b << endl;
  if (c==b) cout << a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int num;
	scanf("%d",&num);
	switch((int)(num/200))
	{
		case 2 : printf("8");break;
		case 3 : printf("7");break;
		case 4 : printf("6");break;
		case 5 : printf("5");break;
		case 6 : printf("4");break;
		case  7 : printf("3");break;
		case 8 : printf("2");break;
		case 9 : printf("1");break;
	}
	
	return 0;
 } 

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

const int N = 2010;
const int Mod = 1e9 + 7;

int n, m, K;
int dp[N << 1][N][2];

void add(int &x, int y){
	if((x += y) >= Mod) x -= Mod;
}

int main(){
	scanf("%d%d%d", &n, &m, &K);

	--K;
	int l = (n + m) / K + 1, ans = 0;
	dp[0][0][0] = 1;

	For(i, 0, l - 1){
		For(j, 0, n) For(v, 0, 1){
			int val = dp[i][j][v];
			if(!val) continue;
			For(u, j, std::min(j + K, n)) add(dp[i + 1][u][u > j], val);
		}
		For(j, 0, n){
			int x = (i + 1) * K - j + 1;
			if(x <= m && j % K == n % K && x % K == m % K) add(ans, dp[i + 1][j][1]);
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 61696
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long Q, long long H, long long S, long long D, long long N) {
  // 0.25 0.5 1 2
  ll z[4] = {};
  z[0] = Q * 4;
  z[1] = H * 2;
  z[2] = S * 1;
  z[3] = D / 2;

  ll a[4] = {25, 50, 100, 200};
  N *= 100;
  ll ans = 0;

  while (N) {
    ll mi = 1000000000;
    int in = 0;
    REP(i, 4) if (N >= a[i] && mi > z[i]) {
      in = i;
      mi = z[i];
    }
    ll aa = N / a[in];
    N -= aa * a[in];
    dump(in);
    dump(aa);
    dump(N);
    if (aa == 0)
      break;

    if (in == 0) {
      ans += Q * aa;
    } else if (in == 1) {
      ans += H * aa;
    } else if (in == 2) {
      ans += S * aa;
    } else {
      ans += D * aa;
    }
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long Q;
  long long N;
  long long S;
  long long D;
  long long H;
  cin >> Q;
  cin >> H;
  cin >> S;
  cin >> D;
  cin >> N;
  solve(Q, H, S, D, N);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.next();
        String res = "";
        for (char c : num.toCharArray()) {
            if (c == '1') res += "9";
            else if (c == '9') res += "1";
            else res += c;
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for (int i=1; i<n; i++)
using namespace std;
using f=float; using ll=long long; using ld=long double;
using ull=unsigned long long; using vi=vector<int>; using pii=pair<int, int>;

int main() {
    int n, flag_n = 0;
    cin >> n;
    // Option 1:
    //string s = to_string(n);
    //rep(i, s.size()) {
    //    if ( s.at(i) == '7') {
    //        flag_n = 1;
    //    }
    //}
    //if (flag_n) cout << "Yes" << endl;
    //else cout << "No" << endl;

    //Option 2:
    if ( n %10 == 7 || (n/10)%10 == 7 || (n/100)==7)
        cout << "Yes" << endl;
    else
        cout << "No" << endl; 
    return 0;
} 


Measured memory_bytes: 3560
//D
#include <iostream>
using namespace std;
uint64_t combi2(int n) {
	return (uint64_t)n * ((uint64_t)n - 1) / 2;
}
int main(void) {
	int amount;
	cin >> amount;
	long data[amount];//ボールの整数の情報
	long amountArray[amount + 1];//個数カウント
	for (int i = 0; i < amount + 1; i++) {//初期化ループ
		amountArray[i] = 0;
	}
	for (int i = 0; i < amount; i++) {//個数一覧作成
		cin >> data[i];
		amountArray[data[i]]++;
	}
	uint64_t fullPtnSum = 0;//全通りの数
	for (int i = 0; i < amount + 1; i++) {
		fullPtnSum += combi2(amountArray[i]);
	}
	for (int i = 0; i < amount; i++) {
		uint64_t ballAmount = amountArray[data[i]];//そのときのボールと同じ整数のボールの個数
		cout << fullPtnSum + combi2(ballAmount - 1) - combi2(ballAmount) << endl;
	}

}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int A, B, C, K; cin >> A >> B >> C >> K;
    for (int i = 0; i < K; i++) {
        if (A >= B) {
            B *= 2;
        } else if (B >= C) {
            C *= 2;
        }
    }

    if (A < B && B < C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

for i in cnt.values():
    total += i * (i - 1) // 2

for a in A:
    print(total - (cnt[a] - 1))


Measured memory_bytes: 25764
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << 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...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 1e3 + 10;
const int M = 30;
int dp[M][N];
int C[N][N];

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int main() {
  for (int i = 0; i < N; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
    }
  }
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; ++i) cin >> a[i];
  dp[0][0] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (dp[i][j] == 0) continue;
      for (int k = 0; j + k <= n && k <= a[i]; ++k) {
        add(dp[i + 1][j + k], 1LL * dp[i][j] * C[n - j][k] % MOD * C[n - k][a[i] - k] % MOD);
      }
    }
  }
  cout << dp[m][n] << '\n';
  return 0;
}


Measured memory_bytes: 7248
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int main()
{
    int n;
    int flag=1;
    cin>>n;
    while(n--)
    {
        int tmp;
        cin>>tmp;
        if(tmp%2==0)
        {
            if(tmp%3==0||tmp%5==0)
                ;
            else
                flag=0;
        }
    }
    if(flag)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define INF 0x3fffffff
using namespace std;
 
int n,m;
int d[10005];
struct node
{
    int e,len,cost;
    node(){}
    node(int a,int b,int c)
    {
        e=a,len=b,cost=c;
    }
    bool operator < (const node &a) const
    {
        return len>a.len;
    }
};
vector <node> E[10005];
priority_queue <pair<int,int> > q;
 
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
    while(~scanf("%d%d",&n,&m)&&n)
    {
        for(int i=1;i<=n;i++)
            d[i]=INF,E[i].clear();
        for(int i=1;i<=m;i++)
        {
            int s,e,cost,len;
            scanf("%d%d%d%d",&s,&e,&len,&cost);
            E[s].push_back(node(e,len,cost));
            E[e].push_back(node(s,len,cost));
        }
        q.push(make_pair(1,0));
        d[1]=0;
        while(!q.empty())
        {
            pair <int,int> t=q.top();
            q.pop();
            int v=t.first;
            //printf("*%d-%d\n",t.first,t.second);
            if(d[v]<t.second)
                continue;
            for(int i=0;i<E[v].size();i++)
            {
                node e=E[v][i];
                if(d[e.e]>d[v]+e.len)
                {
                    d[e.e]=d[v]+e.len;
                    q.push(make_pair(e.e,d[e.e]));
                }
            }
        }
        int ans=0;
        for(int i=2;i<=n;i++)
        {
            int mine=INF;
            for(int j=0;j<E[i].size();j++)
                if(E[i][j].len+d[E[i][j].e]==d[i]&&mine>E[i][j].cost)
                    mine=E[i][j].cost;
			if(mine!=INF)
            ans+=mine;
        }
        printf("%d\n",ans);
    }
} 

Measured memory_bytes: 4616
#include <iostream>

using namespace std;

int main(){
  long long int N, A, B;
  long long int answer;
  cin >> N >> A >> B;

  answer = N/(A+B)*A;

  if(N%(A+B)>A){
    answer+= A;
  }else{
    answer+=N%(A+B);
  }

  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

S0 = 0
S1 = sum(A[i] for i in range(K))
S2 = sum(A[i] for i in range(K, N) if A[i] > 0)
A.append(0)

ans = sum(A)
for i in range(N-K+1):
#     print(i, i+K, S0, S1, S2)
    ans = max(ans, S0 + max(S1, 0) + S2)
    if A[i] > 0:
        S0 += A[i]
    if A[i+K] > 0:
        S2 -= A[i+K]
    S1 = S1 - A[i] + A[i+K]
print(ans)

Measured memory_bytes: 14608
#include<iostream>
using namespace std;
int p[1000000];
int main(){
  int k,n;
  int m=0;
  cin>>k>>n;
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  for(int i=1;i<n;i++){
    if(m<p[i]-p[i-1]){
      m=p[i]-p[i-1];
    }
  }
  if(k-p[n-1]+p[0]>m) m=k-p[n-1]+p[0];
  cout<<k-m<<endl;
}


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N, K;
  std::cin >> N >> K;

  std::vector<int> p(N);
  std::vector<double> sum_exp(N + 1);
  rep(i, N) {
    std::cin >> p[i];
    double expect = 0.5 * (p[i] + 1);
    sum_exp[i + 1] = sum_exp[i] +  expect;
  }

  double ans = 0;
  for(int i = 0; i <= N - K; ++i) {
    ans = std::max(ans, sum_exp[i + K] - sum_exp[i]);
  }
  std::cout << std::fixed << std::setprecision(10) << ans << '\n';
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int dp[150010];
int par[300010],sz[300010];
int init(int n){
	for(int i=0;i<n;i++){
		par[i] = i; sz[i] = 1;
	}
}

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

void unite(int x, int y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	sz[x] += sz[y]; par[y] = x;
}

bool same(int x, int y){
	return find(x)==find(y);
}
int b[300010] = {};
vector<int> v,u;
int main(){
	int i,j,k,n,r,sum = 0;
	cin >> n >> r;
	r = min(r,n - r);
	init(n);
	for(i=0;i<n;i++){
		int a; cin >> a; a--;
		unite(i,a);
	}
	for(i=0;i<n;i++){
		if(par[i]==i && sz[i]!=1){
			b[sz[i]]++;
			sum += sz[i];
		}
	}
	for(i=0;i<=150000;i++) dp[i] = -1;
	for(i=0;i<=n;i++){
		if(b[i]!=0){
			v.push_back(b[i]);
			u.push_back(i);
		}
	}
	dp[0] = 0;
	for(i=0;i<v.size();i++){
		for(j=0;j<=r;j++){
			if(dp[j]>=0){
				dp[j] = v[i];
			}else if(j - u[i]>=0 && dp[j - u[i]]>=0){
				dp[j] = dp[j - u[i]] - 1;
			}else{
				dp[j] = -1;
			}
		}
	}
	for(i=r;i>=sum + r - n && i>=0;i--){
		if(dp[i]>=0 && sum - i<=n - r){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}



Measured memory_bytes: 6108
S = input()
x, y = int(S[:2]),int(S[2:])

if (1<=y<=12) or (1<=x<=12):
    if x >= 1 and x <= 12 and y >= 1 and y <= 12:
        print('AMBIGUOUS')
    elif x >= 1 and x <= 12 and y >= 0:
        print('MMYY')
    elif x >= 0 and y >= 1 and y <= 12:
        print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
NOT_FOUND = nil
n = gets.to_i
set = gets.split.map(&:to_i)
q = gets.to_i
set_t = gets.split.map(&:to_i)

def binary_search(set, set_t, key)
  left = 0
  right = set.length
  while left < right
    mid = (left + right) / 2
    if set[mid] == key
      return mid
    elsif key < set[mid]
      right = mid
    else
      left = mid + 1
    end
  end
  return NOT_FOUND
end

def count(set, set_t, count=0)
  for i in 0..set_t.length - 1
    count += 1 if binary_search(set, set_t, set_t[i])
  end
  count
end

puts count(set, set_t)



Measured memory_bytes: 15344
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=1; i<n; i++)

using namespace std;
using vi = vector<int>;

int main(){
    int n;
    cin >> n;
    if (n >= 400 && n < 600)cout << 8 << endl;
    else if (n >= 600 && n < 800)cout << 7 << endl;
    else if (n >= 800 && n < 1000)cout << 6 << endl;
    else if (n >= 1000 && n < 1200)cout << 5 << endl;
    else if (n >= 1200 && n < 1400)cout << 4 << endl;
    else if (n >=1400 && n < 1600)cout << 3 << endl;
    else if (n >= 1600 && n < 1800)cout << 2 << endl;
    else if (n >= 1800 && n < 2000)cout << 1 << endl;


    

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
  int N = inputValue();
  int p[50];
  REP(i,N)
    p[i] = inputValue();
  int sort = 0;
  REP(i,N){
    if(p[i] != i+1){
      if(sort==0){
        int tmp = p[p[i]-1];
        p[p[i]-1] = p[i];
        p[i] = tmp;
        sort++;
      }
      else{
        sort++;
        break;
      } 
    }
  }
  if(sort<2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a,b;
	cin >> a>>b;
	if (b%a == 0) cout << a + b << endl;
	else cout << b - a << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fap(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;

const int N = 1e5 + 7;
pii a[N];
map<int, vector<pii>> st, en;

inline int front(multiset<int> &x) {
	assert(!x.empty());
	return *(x.begin());
}

inline int back(multiset<int> &x) {
	assert(!x.empty());
	return *(--x.end());
}

inline void erase(multiset<int> &x, int val) {
	x.erase(x.find(val));
}

inline void insert(multiset<int> &x, int val) {
	x.insert(val);
}

multiset<int> fr[2], to[2];

int calval() {
	if(fr[0].empty() or fr[1].empty()) return 0;
	int ret = max(0, front(to[0]) - back(fr[0]) + 1) + max(0, front(to[1]) - back(fr[1]) + 1);
	return ret;
}

int main() {
	FastIO;

	int n;
	cin >> n;
	for(int i=0; i<n; ++i) cin >> a[i].first >> a[i].second;
	
	vector<int> pos;
	for(int i=0; i<n; ++i) {
		st[a[i].first].push_back(a[i]);
		en[a[i].second].push_back(a[i]);
		pos.push_back(a[i].first);
		pos.push_back(a[i].second);
	}
	sort(all(pos));
	pos.erase(unique(all(pos)), pos.end());

	for(int i=0; i<n; ++i) {
		insert(to[1], a[i].second);
		insert(fr[1], a[i].first);
	}

	int res = 0;
	for(int i=0; i<n; ++i) {
		auto &ran = a[i];
		
		erase(fr[1], ran.first);
		erase(to[1], ran.second);
		insert(fr[0], ran.first);
		insert(to[0], ran.second);
		
		res = max(res, calval());
		
		erase(fr[0], ran.first);
		erase(to[0], ran.second);
		insert(fr[1], ran.first);
		insert(to[1], ran.second);
	}

	for(int p : pos) {
		auto &vec = en[p];
		sort(all(vec));
		for(auto ran : vec) {
			erase(fr[0], ran.first);
			erase(to[0], ran.second);
			insert(fr[1], ran.first);
			insert(to[1], ran.second);
			res = max(res, calval());
		}

		vec = st[p];
		sort(all(vec), [&] (pii &p, pii &q) { return p.second > q.second; } );
		for(auto ran : vec) {
			erase(fr[1], ran.first);
			erase(to[1], ran.second);
			insert(fr[0], ran.first);
			insert(to[0], ran.second);
			res = max(res, calval());
		}
	}

	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 51896
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  // input
    int n,m;cin >> n >> m;
    vector<int> a(n + 1);
    vector<int> b(n + 1);
    vector<int> c(m + 1);
    vector<int> d(m + 1);

    for(int i = 1;i < n + 1; i++) {
        cin >> a[i] >> b[i];
    }
    for(int i = 1;i < m + 1; i++) {
        cin >> c[i] >> d[i];
    }

  // compute 
    vector<int> ans(n + 1);
    vector<int> mi(n + 1);
    vector<vector<int>> mk(n + 1, vector<int>(m + 1));
    for(int i = 1;i < n + 1 ; i++) {
        for(int j = 1; j < m + 1; j++){
            mk[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        } 
    }

    for(int i = 1;i < n + 1 ; i++){
        ans[i] = 1;
        mi[i] = mk[i][1];
    }

    for(int i = 1;i < n + 1 ; i++) {
        for(int j = 1; j < m + 1; j++){
            if(mk[i][j] < mi[i]){
                ans[i] = j;
                mi[i] = mk[i][j];
            }
        } 
    }

  // output  
    for(int i = 1;i < n + 1; i++) {
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define REP(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 60;

int MOD = 1000000007;


int main(){
    std::ios_base::sync_with_stdio(false);

    int n; ll A,B; cin >> n >> A >> B;
    std::vector<ll> x(n); REP(i,n) cin >> x[i];
    std::vector<ll> d;

    ll ans = 0;

    REP(i,n-1) d.push_back(x[i+1]-x[i]);
    REP(i,n-1) d[i]*A > B ? ans+=B : ans+=d[i]*A;

    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 2168
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[30],b[30];
int c=0,sum=0;
int main(){
	a[0]='C';a[1]='O';a[2]='D';a[3]='E';a[4]='F';a[5]='E';
	a[6]='S';a[7]='T';a[8]='I';a[9]='V';a[10]='A';a[11]='L';
	a[12]='2';a[13]='0';a[14]='1';a[15]='6';
	cin>>b;
	c=strlen(b);
	for(int i=0;i<c;i++){
		if(b[i]!=a[i]) sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

int main(){
    char a, b, c;
    cin>>a>>b>>c;
    Yes((a-b)||(b-c)||(c-a));

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=45;
int n;
char s[maxn];
bool d[maxn][maxn];
ll dp[maxn][maxn][maxn],ans;
void update(ll &x,ll y) {
	x+=y;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); n*=2;
	for (int i=1;i<=n;i++) {
		scanf("%s",s+1);
		for (int j=1;j<=n;j++) d[i][j]=s[j]-'0';
	}
	for (int l=n;l>=2;l--) {
		dp[l][l][l]=1;
		for (int r=l+1;r<=n;r++)
		for (int m=l+1;m<r;m++) {
			for (int i=l;i<m;i++)
			for (int j=m+1;j<=r;j++)
				if (d[i][j]) {
					for (int s=i;s<m;s++)
					for (int t=m+1;t<=j;t++)
						update(dp[l][r][m],dp[l][s][i]*dp[s+1][t-1][m]*dp[t][r][j]);
				}
			//printf("%d %d %d %d\n",l,r,m,dp[l][r][m]);
		}
	}
	for (int i=2;i<=n;i++)
		if (d[1][i]) update(ans,dp[2][n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
    #define N 155555
    #define F(i,l,r) for(int i=l;i<=r;++i)
    #define D(i,r,l) for(int i=r;i>=l;--i)
    #define Fs(i,l,r,c) for(int i=l;i<=r;c)
    #define Ds(i,r,l,c) for(int i=r;i>=l;c)
    #define MEM(x,a) memset(x,a,sizeof(x))
    #define FK(x) MEM(x,0)
    #define Tra(i,u) for(int i=G.Start(u),__v=G.To(i);~i;i=G.Next(i),__v=G.To(i))
    #define p_b push_back
    #define sz(a) ((int)a.size())
    #define iter(a,p) (a.begin()+p)
    void R1(int &x)
    {
        x=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x=(f==1)?x:-x;
    }
    void Rd(int cnt,...)
    {
        va_list args;
        va_start(args,cnt);
        F(i,1,cnt) 
        {
            int* x=va_arg(args,int*);R1(*x);
        }
        va_end(args);
    }

    int n;
    void Input()
    {
        R1(n);
    }
    void Add(int u,int v){printf("%d %d\n",u,v);}
    void Soviet()
    {
        F(i,0,20) if ((1<<i)==n)
        {
            puts("No");return;
        }
        puts("Yes");
        Add(1,2);
        Add(2,3);
        Add(3,n+1);
        Add(n+1,n+2);
        Add(n+2,n+3);
        Fs(i,5,n,i+=2)
        {
            Add(1+n,i);
            Add(i,i-1);
            Add(1+n,i-1+n);
            Add(i-1+n,i+n);
        }
        if (n%2==0)
        {
            int p2;
            F(i,0,20) if ((1<<i)<n) p2=(1<<i);

            Add(n,p2+n);
            Add(2*n,n^p2^1);
        }


    }

    #define Flan void
    Flan IsMyWife()
    {
        Input();
        Soviet();
    }
}
int main()
{
    Flandre_Scarlet::IsMyWife();
    getchar();getchar();
    return 0;
}

Measured memory_bytes: 2816
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    X = int(input())
    ans = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if i * 500 + j * 100 + k * 50 == X:
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

long getPrice(long orig, long r) {
  double d = double(orig) * (100 + r) / 100;
  return floor(d);
}

long getOrig(long pr, long r) {
  double d = double(pr) / (100 + r) * 100;
  if (getPrice(floor(d), r) == pr) {
    return floor(d);
  }
  if (getPrice(ceil(d), r) == pr) {
    return ceil(d);
  }
  return -1;
}

void solve(long x, long y, long s) {
  long ans = 0;
  for (int pr1 = 1; pr1 < s; pr1++) {
    long or1 = getOrig(pr1, x);
    long or2 = getOrig(s - pr1, x);
    if (or1 != -1 && or2 != -1) {
      ans = max(ans, getPrice(or1, y) + getPrice(or2, y));
    }
  }
  cout << ans << endl;
}

int main() {
  long x, y, s;
  while (1) {
    cin >> x >> y >> s;
    if (x + y + s) {
      solve(x, y, s);
    } else {
      return 0;
    }
  }
}



Measured memory_bytes: 3124
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var P = Number(lines[0].split(" ")[0]);
    var Q = Number(lines[0].split(" ")[1]);
    var R = Number(lines[0].split(" ")[2]);

    var a = P + Q;
    var b = P + R;
    var c = Q + R;
    var d = Q + P;
    var e = R + P;
    var f = R + Q;

    console.log(Math.min(a, b, c, d, e, f))

}); 

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    while(K){
        if(A >= B){
            B *= 2;
            K--;
        }
        else break;
    }
    while(K){
        if(B >= C){
            C *= 2;
            K--;
        }
        else break;
    }
    if(A < B && B < C){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

vector<lint> prime_factorization(lint N) {
	//素因数分解して配列で返す
	vector<lint> R;
	if (N < 2)return R;
	for (lint i = 2; i * i <= N; i++) {
		while (N % i == 0) {
			R.push_back(i);
			N /= i;
		}
	}
	if (N != 1) {
		R.push_back(N);
	}
	return R;
}

lint f(lint N) {
	lint sum = 0;
	lint i = 1;
	lint cnt = 0;
	while (1) {
		sum += i;
		i++;
		if (sum > N) {
			return cnt;
		}
		cnt++;
	}
}

int main() {
	lint N;
	cin >> N;
	if (N == 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<lint>V = prime_factorization(N);
	sort(V);
	lint cnt = 1;
	lint ans = 0;
	rep(i, V.size() - 1) {
		if (V[i] == V[i + 1]) {
			cnt++;
		}
		else {
			ans += f(cnt);
			cnt = 1;
		}
	}
	ans += f(cnt);
	cout << ans << enld;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using pll = pair<ll, ll>;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> s;
}

bool is0(int x){
    string s = to_string(x);
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i]=='0') return true;
    }
    return false;    
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

int solve(){
    int N=s.length();
    vector<int> sum(N+1);
    sum[0] = 0;
    for (int i = 0; i < N; i++)
    {
        sum[i+1] = sum[i]*10 + s[i]-'0';
        sum[i+1] %= 2019;
    }
    DBG(sum)
    map<int,int> cnt;
    cnt[0]++;
    for (int i = 0; i < N; i++)
    {
        sum[i+1] *= mod_pow(10,N-i,2019);
        sum[i+1] %= 2019;
        cnt[sum[i+1]]++;
    }    
    DBG(sum)
    ll ans=0;
    for(auto c:cnt) ans+=c.second*(c.second-1)/2;
    cout << ans << endl;    
    return 0;
}   

void test(){
    for (int i = 0; i < 10000; i++)
    {
        int x = 2019*i;
        if(is0(x)) continue;
        DBG(make_pair(i,2019*i))
    }
}

int main()
{
    input();
    solve();
    return 0;
}


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

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> a(h);
  for(int i=0; i<h; i++)cin>>a.at(i);

  for(int i=0; i<w+2; i++)cout<<'#';
  cout<<endl;

  for(int i=0; i<h; i++)cout<<'#'<<a.at(i)<<'#'<<endl;;

  for(int i=0; i<w+2; i++)cout<<'#';
  cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    int a, b, c, d, e, f, t;
    double x, y;
    while(scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF){
        t = 1.0*a*e - 1.0*b*d;
        x = (1.0*e*c - 1.0*b*f)/t + 0.0001;
        y = (1.0*a*f - 1.0*d*c)/t + 0.0001;
        printf("%.3f %.3f\n", x, y);
    }
     
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll a,b; cin>>a>>b;

    ll n = b-a-1;
    cout<<n*(n+1)/2 - a<<endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int c = a + b;
        if (c >= 10) {
            System.out.println("error");
        } else {
            System.out.println(c);
        }
    }

}

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

vector<vector<bool>> seen;
int H, W;
int d_h[8] = {1,1,1,0,0,-1,-1,-1};
int d_w[8] = {1,0,-1,1,-1,1,0,-1};

void dfs(const vector<vector<int>> &m, int h, int w){
    seen[h][w] = true;

    //cout << h << ' ' << w <<  ' ' << m[h][w] << endl;
    
    for(int i = 0; i < 8; i++){
        if(1 <= h+d_h[i] && h+d_h[i] <= H && 1 <= w+d_w[i] && w+d_w[i] <= W && (!seen[h+d_h[i]][w+d_w[i]]) && m[h+d_h[i]][w+d_w[i]] == 1){
            dfs(m, h+d_h[i], w+d_w[i]);
        }
    }
}

int main(){
    while(1){
        cin >> W >> H;
        seen.assign(H+1, vector<bool>(W+1, false));
        if(H == 0 && W == 0) break;
        vector<vector<int>> m(H+1, vector<int>(W+1,0));
        for(int i = 1; i <= H; i++){
            for(int j = 1; j <= W; j++){
                cin >> m[i][j];
            }
        }

        int cnt = 0;
        for(int i = 1; i <= H; i++){
            for(int j = 1; j <= W; j++){
                if(!seen[i][j] && m[i][j] == 1) {
                    //cout << i << ' ' << j << endl;
                    cnt++;
                    dfs(m, i, j);
                }
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3280
A, B, C, D = (int(i) for i in input())


def print_ans(op1, op2, op3):
    print('{}{}{}{}{}{}{}=7'.format(A, op1, B, op2, C, op3, D))


# +++
if A + B + C + D == 7:
    print_ans('+', '+', '+')
# ++-
elif A + B + C - D == 7:
    print_ans('+', '+', '-')
# +-+
elif A + B - C + D == 7:
    print_ans('+', '-', '+')
# +--
elif A + B - C - D == 7:
    print_ans('+', '-', '-')
# -++
elif A - B + C + D == 7:
    print_ans('-', '+', '+')
# -+-
elif A - B + C - D == 7:
    print_ans('-', '+', '-')
# --+
elif A - B - C + D == 7:
    print_ans('-', '-', '+')
# ---
else:
    print_ans('-', '-', '-')


Measured memory_bytes: 3064
def sum_cnt(max_num):
    cnt = 0
    for i in range(max_num):
        cnt += (i+1)
    return cnt
def sum_cal(n, num):
    q = n//num
    return num*sum_cnt(q)

n = int(input())
sum_all = n*(n+1)//2
sum_5 = sum_cal(n, 5)
sum_3 = sum_cal(n, 3)
sum_15 = sum_cal(n, 15)
print(sum_all - (sum_5+sum_3) + sum_15)

Measured memory_bytes: 9224
S = input()
x, y = map( int, input().split())
c = 0
ver = []
row = []
l = 0
for s in S:
    if s == "F":
        c += 1
    else:
        if l%2 == 0:
            row.append(c)
        else:
            ver.append(c)
        l += 1
        c = 0
if l%2 == 0:
    row.append(c)
else:
    ver.append(c)

x -= row.pop(0)
row.sort( key = None, reverse = True)
ver.sort( key = None, reverse = True)
nx, ny = 0, 0
for a in row:
    if a >= 0:
        if nx <= x:
            nx += a
        else:
            nx -= a
    else:
        if nx > x:
            nx += a
        else:
            nx -= a
for a in ver:
    if a >= 0:
        if ny <= y:
            ny += a
        else:
            ny -= a
    else:
        if ny > y:
            ny += a
        else:
            ny -= a

if x == nx and y == ny:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3188
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	ll a,b;
	cin>>a>>b;
	ll cnt=0,soc=1;
	while(soc<b)
	{
		cnt++;
		soc+=a-1;
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, H)
  {
    cin >> a[i];
  }
  cout << string(W + 2, '#') << endl;
  rep(i, H)
  {
    string s = "#" + a[i] + "#";
    cout << s << endl;
  }
  cout << string(W + 2, '#') << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int n;

int main() {
  cin >> n;
  int a[n];
  int y_ij[15][15] = {-1};
  rep(i, 15) rep(j, 15) y_ij[i][j] = -1;
  int x, y;
  
  rep(i, n) {
    cin >> a[i];
    rep(j, a[i]) {
      cin >> x >> y;
      x--;
      y_ij[i][x] = y;
    }
  }
      
  int is_honest_arr[n] = {1};
  int ans = 0;
  bool satisfy, satisfy2;
  rep(i, n) {
    rep(j, n) {
      if (j < i) {
	      is_honest_arr[j] = 0;
      } else {
        is_honest_arr[j] = 1;
      }
    }
    
    do {
      satisfy = true;
      rep(i, n) {
        if(is_honest_arr[i] == 1) {
          rep(j, n) {
            if (y_ij[i][j] == -1) continue;
            if (y_ij[i][j] != is_honest_arr[j]) {
              satisfy = false;
              break;
            }
            if (satisfy==false) break;
          }
          if (satisfy==false) break;
        }
      }
      if (satisfy == true) {
        ans = n - i;
        break;
      }
    } while(next_permutation(is_honest_arr, is_honest_arr+n));
   
    if (satisfy == true) break;
  }
  cout << ans;
}

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

int main(){
   int n,x;
   cin >> n >> x;
   int l[n];
   int ans = 1;
   int d = 0;
   for (int i=1; i<n+1; i++){
      cin >> l[i-1];
      if(d+l[i-1]<=x){ans++;}
      d = d+l[i-1];
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
def solve():
    from collections import deque
    from sys import stdin
    f_i = stdin
    
    H, W = map(int, f_i.readline().split())
    
    maze = '#' * (W + 2)
    for i in range(H):
        line = f_i.readline().rstrip()
        maze += '#' + line + '#'
    maze += '#' * (W + 2)
    
    move = (1, -1, W + 2, -W - 2)
    
    counts = []
    starts = (i for i in range(len(maze)) if maze[i] == '.')
    for start in starts:
        unvisited = [True] * len(maze)
        unvisited[start] = False
        
        q = deque([(start, 0)])
        while q:
            pos, cnt = q.popleft()
            
            for mv in move:
                next_pos = pos + mv
                if maze[next_pos] == '.' and unvisited[next_pos]:
                    q.append((next_pos, cnt + 1))
                    unvisited[next_pos] = False
            
            counts.append(cnt)
    
    print(max(counts))

solve()

Measured memory_bytes: 4724