akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pll, pii> P;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

struct UnionFind {
	vector<int> par, rank;
	
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		REP(i, n) {
		 par[i] = i;
		 rank[i] = 0;
		}
	}
	
	int operator[] (int x) {
		return find(x);
	}
	
	int find(int x) {
		if (x == par[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 (rank[x] < rank[y]) swap(x, y);
		
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	
};

int main() {
	int N, M;
	cin >> N >> M;
	UnionFind uf(N + M);
	REP(i, N) {
		int K; cin >> K;
		REP(j, K) {
			int L;
			cin >> L;
			uf.unite(i, N + L - 1);
		}
	}
	
	set<int> ss;
	REP(i, N) ss.insert(uf[i]);
	puts(ss.size() == 1 ? "YES" : "NO");
	
	return 0;
}


Measured memory_bytes: 1792
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, p = LI()
    A = LI()

    sum_a = sum(A)
    # dp[i][j]: a_iまでを使ってjを作る組み合わせの総数（iは省略）
    dp = [0] * (sum_a + 1)
    dp[0] = 1
    for i in range(n):
        for j in range(sum_a + 1)[::-1]:
            if j - A[i] < 0:
                break
            if dp[j - A[i]]:
                dp[j] += dp[j - A[i]]

    return sum([dp[i] if i % 2 == p else 0 for i in range(sum_a + 1)])


print(main())


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int n,sum=0,ans=0,memo;
  cin>>n;
  vec s(n);
  rep(i,n) {cin>>s[i]; sum+=s[i];}
  
  sort(s.begin(),s.end());
  
  if(sum%10!=0)cout<<sum;
  else{
    memo=sum;
    rep(i,n){
    if(s[i]%10!=0){memo=s[i];break;}  
    }
    
    cout<<sum-memo;

  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	int x,y,z,a;
	while(~scanf("%d %d %d",&x,&y,&z))
	{
		for(a = 0; a <= (x - z)/(z + y) ; )
		{
			 a = a + 1;
		}
		a = a - 1;
		printf("%d\n",a);
	}
	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;cin>>n;
	int arr[n], dp[n];
	for(int i = 0; i <n; ++i) cin>>arr[i];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for(int i = 2; i < n;++i){
		dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}



Measured memory_bytes: 1024
N = int(input())
plan = [[0,0,0]] + [list(map(int, input().split())) for i in range(N)]
f = True
for i in range(N):
    time = plan[i+1][0]-plan[i][0]
    dist = abs(plan[i+1][1]-plan[i][1])+abs(plan[i+1][2]-plan[i][2])
    if dist>time or dist%2 != time%2:
        f = False    
print('Yes' if f else 'No')

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

int gcd(int a,int b){
	if(a<b) swap(a,b);
	while(b){
		int t = a%b;
		a = b;
		b = t;
	}
	return a;
}
int main(){
	int k;
	cin>>k;
	long long ret = 0;
	for(int i=1; i<=k; i++){
		for(int j=1; j<=k; j++){
			for (int r = 1; r<=k; r++){
				ret+=gcd(i,gcd(j,r));
			}
		}
	}
	cout<<ret;
}

Measured memory_bytes: 3600
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s == "Sunny") cout << "Cloudy" << endl;
  else if(s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" <<endl;
  
  return 0;
}

Measured memory_bytes: 256
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve(){
    string s; cin>>s;
    if(s[2] == s[3] && s[4] == s[5]) cout<<"Yes\n";
    else cout<<"No\n";
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1e5+5;
const int mod=1e9+7;
int fac[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	const int n=nxi(),m=nxi();
	if(n>m+1||m>n+1){
		puts("0");
		return 0;
	}
	fac[0]=1;
	for(int i=1; i<=std::max(n,m); ++i){
		fac[i]=(lint)fac[i-1]*i%mod;
	}
	if(n==m){
		printf("%lld\n",2ll*fac[n]%mod*fac[n]%mod);
	}
	else{
		printf("%lld\n",(lint)fac[m]*fac[n]%mod);
	}
	return 0;
}


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

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

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

    while (s.size() > 3) {
        const int N = s.size();
        string next;
        vector<int> num(3, 0);
        int star = 0;
        for (int i = 0; i < N; i++) {
            if (i < N - 2) {
                if (s.substr(i, 3) == "ABC") {
                    next.push_back('*');
                    star++;
                    i += 2;
                } else {
                    next.push_back(s[i]);
                    num[s[i] - 'A']++;
                }
            } else {
                next.push_back(s[i]);
                num[s[i] - 'A']++;
            }
        }
        int zero = 0;
        char zerochar = '%';
        for (int i = 0; i < 3; i++) {
            if (num[i] == 0) {
                zero++;
                zerochar = 'A' + i;
            }
        }
        if (star > 0 and zero == 1) {
            s = next;
            for (char& c : s) {
                if (c == '*') {
                    c = zerochar;
                }
            }
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    if (s == "ABC") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3236
require "set"
n = gets.chomp.to_i
dp = Hash.new{1_000_000}

6.times do |i|
  dp[i + 1] = i + 1
end
dp[7] = 2
dp[8] = 3

set_for_once = Set.new({})
7.times.reduce(set_for_once){|memo, attr| memo.add 6 ** attr}
6.times.reduce(set_for_once){|memo, attr| memo.add 9 ** attr}
set_for_once = set_for_once.sort

set_for_once.each{|attr| dp[attr] = 1}


10.upto(n) do |i|
  next if dp[i] != 1_000_000
  idx = set_for_once.index{|attr| attr > i} || set_for_once.size - 1
  idx.times do |j|
    dp[i] = [dp[i - set_for_once[j]] + 1, dp[i]].min
  end
end
puts dp[n]




Measured memory_bytes: 8316
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int H, W, N;
  std::cin >> H >> W >> N;
  int startRow;
  int startCol;
  std::cin >> startRow >> startCol;

  std::string S, T;
  std::cin >> S;
  std::cin >> T;

  // Main
  bool drop = false;

  // 右落ちチェック
  int j = startCol;
  for (int k = 0; k < N; ++k) {
    if (S[k] == 'R') {
      j += 1;
      if (j == W + 1)
        drop = true;
    }
    if (T[k] == 'L' and j > 1) {
      j -= 1;
    }
  }

  // 左落ちチェック
  j = startCol;
  for (int k = 0; k < N; ++k) {
    if (S[k] == 'L') {
      j -= 1;
      if (j == 0)
        drop = true;
    }
    if (T[k] == 'R' and j < W) {
      j += 1;
    }
  }

  // 上落ちチェック
  int i = startRow;
  for (int k = 0; k < N; ++k) {
    if (S[k] == 'U') {
      i -= 1;
      if (i == 0)
        drop = true;
    }
    if (T[k] == 'D' and i < H) {
      i += 1;
    }
  }

  // 下落ちチェック
  i = startRow;
  for (int k = 0; k < N; ++k) {
    if (S[k] == 'D') {
      i += 1;
      if (i == H + 1)
        drop = true;
    }
    if (T[k] == 'U' and i > 1) {
      i -= 1;
    }
  }


  // Output
  if (drop)
    std::cout << "NO" << std::endl;
  else
    std::cout << "YES" << std::endl;

  return 0;
}


Measured memory_bytes: 776
N = int(input())
F = []
for _ in range(N):
    f = input().split()
    fn = int("".join(f), 2)
    F.append(fn)
P = [list(map(int, input().split())) for _ in range(N)]

ans = -100000000000
for k in range(1, 2 ** 10):
    val = 0
    for i in range(N):
        c = bin(k & F[i]).count("1")
        val += P[i][c]
    ans = max(ans, val)
print(ans)


Measured memory_bytes: 73940
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

std::string X;

int main(int argc, char **argv) {
    std::cin >> X;

    std::list<char> lst;

    for (int i = 0; i < X.size(); i++) {
        lst.push_back(X[i]);
    }

    auto itr = lst.begin();
    int act_num = 0;
    char prev;
    while (true) {
        if (itr == lst.end()) {
            break;
        }
        char prev = (*itr);
        ++itr;

        if (itr == lst.end()) {
            break;
        }

        if (prev == 'S' && (*itr) == 'T') {
            itr = lst.erase(itr);
            --itr;
            itr = lst.erase(itr);
            if (itr != lst.begin()) {
                --itr;
            }
            act_num++;
        }
    }
    
    std::cout << X.size() - act_num * 2 << std::endl;

    return 0;
}

Measured memory_bytes: 6660
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <iomanip>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

void dbgmat(vector< vector <long> > array,int n,int m){
    F(i, 0, n){
        F(j, 0, m){
            cout << array[i][j] << (j==m-1? "\r\n":" ");
        }
    }
}

int main() {
    int n,m,l;
    cin >> n >> m >> l;
    vvi mat1;
    vvi mat2;
    F(i, 0, n){
        vi temp;
        F(j, 0, m){
            int l;
            cin >> l;
            temp.pb(l);
        }
        mat1.pb(temp);
    }
    F(i, 0, m){
        vi temp;
        F(j, 0, l){
            int l;
            cin >> l;
            temp.pb(l);
        }
        mat2.pb(temp);
    }
    vector< vector<long> > ans;
    F(i, 0, n){
        vector<long> temp;
        F(j, 0, l){
            long sum = 0;
            F(k, 0, m){
                // i-th row and j-th colmn sum
                sum += mat1[i][k] * mat2[k][j];
            }
            // add sum to vec
            temp.pb(sum);
        }
        // add vec to mat
        ans.pb(temp);
    }
    dbgmat(ans, n, l);
}



Measured memory_bytes: 3276
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int a,b;
cin >> a >> b;
cout << max({a+b,a-b,a*b}) << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a+b) * c / 2 << endl;
}

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

int main() {
  int n, m; cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  int ans[n] = {};
  for (int i = 0; i < m; i++) {
    ans[a[i]]++; ans[b[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;

typedef long long ll;



int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    string S;
    cin >> S;

    ll count=0,bc=0;
    for(ll i=0;i<N;i++){
        if(S[i] == 'a'){
            if(count < A+B){
                count++;
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
            
        }else if(S[i] == 'b'){
            if(count < A+B && bc < B){
                bc++;
                count++;
                cout << "Yes" << endl; 
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int maxn = 605;
int n, a[maxn], f[maxn][maxn][maxn];
bool vis[maxn], mark[maxn];

const int mod = 1e9 + 7;
inline int inc(int x, int y) {x += y; return x >= mod ? x - mod : x;}
inline int mul(int x, int y) {return (ll)x * y % mod;}

int main()
{
	n = read(); n = n * 2;
	for (int i = 1; i <= n; i ++) a[i] = read();
	for (int i = 1; i <= n; i += 2)
	{
		if (~a[i] && ~a[i + 1]) mark[a[i]] = mark[a[i + 1]] = 1;
		else if (~a[i]) vis[a[i]] = 1; else if (~a[i + 1]) vis[a[i + 1]] = 1;
	}
	f[n + 1][0][0] = 1;
	for (int i = n + 1; i > 1; i --)
	{
		if (mark[i - 1])
			memcpy(f[i - 1], f[i], sizeof f[i]);
		else
		{
			if (vis[i - 1])
			{
				for (int j = 0; j <= n; j ++)
					for (int k = 0; k <= n; k ++) if (f[i][j][k])
					{
						if (j) f[i - 1][j - 1][k] = inc(f[i - 1][j - 1][k], f[i][j][k]);
						f[i - 1][j][k + 1] = inc(f[i - 1][j][k + 1], f[i][j][k]);
					}
			}
			else
			{
				for (int j = 0; j <= n; j ++)
					for (int k = 0; k <= n; k ++) if (f[i][j][k])
					{
						if (j) f[i - 1][j - 1][k] = inc(f[i - 1][j - 1][k], f[i][j][k]);
						if (k) f[i - 1][j][k - 1] = inc(f[i - 1][j][k - 1], (ll)k * f[i][j][k] % mod);
						f[i - 1][j + 1][k] = inc(f[i - 1][j + 1][k], f[i][j][k]);
					}
			}
		}
	}
	int ans = f[1][0][0], cnt = 0;
	for (int i = 1; i <= n; i += 2)
		if (a[i] == -1 && a[i + 1] == -1) ++ cnt;
	while (cnt) ans = mul(ans, cnt --);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 859008
#include <iostream>
#include <string>
using namespace std;
 
 
long serach9(long n)
{
  long temp, ret;
  ret = 1;
  temp=n;
  while(1){
    temp=temp/9;
    if(temp==0) break;
    ret=ret*9;
  }
  return ret;
}
 
long serach6(long n)
{
  long temp, ret;
  ret = 1;
  temp=n;
  while(1){
    temp=temp/6;
    if(temp==0) break;
    ret=ret*6;
  }
  return ret;
}
 
long dp(int n)
{
  int h9, h6;
  if(n<=5) return n;
  h9 = dp( n-serach9(n) )+1;
  h6 = dp( n-serach6(n) )+1;
  if(h9<h6) return h9;
  return h6;
}
 
int main() {
  long a, ans;
    cin>>a;
    ans = dp(a);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,k,l;
int main()
{
  cin>>a>>b>>k;
  l=k;
  k-=a;
  if(k>=0){ b-=k; a=0; }
  else a-=l;

  if(b<0) b=0;

  cout<<a<<" "<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------

vector<ll> graph[100005];
vector<bool> vis(100005);
int dp[100005];
void dfs(int src)
{
    vis[src]=true;
    for(int i=0;i<graph[src].size();i++)
    {
        if(!vis[graph[src][i]])
            dfs(graph[src][i]);
        dp[src]=max(dp[src],1+dp[graph[src][i]]);
    }
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    ll a,b;
    for(ll i=0;i<m;i++)
    {
        cin>>a>>b;
        graph[a].push_back(b);
    }
    for(int i=1;i<=n;i++)
    {
        dp[i]=0;
        vis[i]=false;
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
            dfs(i);
    }
    int ans=0;
    for(int i=0;i<=n;i++)
        ans=max(ans,dp[i]);
    cout<<ans<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 12128
//
//  main.cpp
//  ABC085C_otoshidama
//
//  Created by 岡本 朋大 on 2019/06/18.
//  Copyright © 2019年 岡本　朋大. All rights reserved.
//

#include <iostream>
using namespace std;

int main() {
    int N,Y = 0;
    cin >> N >> Y;
    bool answer_exs = 0;
    int A = 0;
    int B = 0;
    for(int a = 0; a <= N; a++){
        for(int b = 0; b + a<= N; b++){
            if(10000*a + 5000*b + 1000 * (N-a-b) == Y){
                A = a;
                B = b;
                answer_exs = 1;
            }
        }
    }
    if(answer_exs) cout << A << " "<< B << " "<< N - A - B << endl;
    else cout << -1 <<" "<< -1 << " "<< -1 << endl;
}


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

int main(void){
        int x,i,flg=0;
        cin >> x;
        while(flg==0){
                if(x==2||x==3||x==5||x==7){
                        cout << x << endl;
                        return 0;
                }
                if(x%2==0){
                        x += 1;
                        continue;
                }
                for(i=3;i<x/2;i+=2){
                        if(x%i==0){
                                x += 1;
                                flg = 1;
                                break;
                        }
                }
                if(flg==1){flg = 0;}
                else{flg = 1;}
        }
        cout << x << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
struct node
{
    int val,type;
    friend bool operator < (node a,node b){
        return a.val>b.val;
    }
}a[maxn*3];
int main()
{
    int x,y,r,g,b;
    cin>>x>>y>>r>>g>>b;
    int tot = 0;
    for(int i = 1;i <= r;++i)
    {
        tot++;
        a[tot].type=1;
        scanf("%d",&a[tot].val);
    }
    for(int i = 1;i <= g;++i)
    {
        tot++;
        a[tot].type=2;
        scanf("%d",&a[tot].val);
    }
    for(int i = 1;i <= b;++i)
    {
        tot++;
        a[tot].type=3;
        scanf("%d",&a[tot].val);
    }
    sort(a+1,a+1+tot);
    int cnt1,cnt2;
    cnt1=cnt2=0;
    ll sum = 0;
    for(int i = 1;i <= x+y;++i)
    {
        if(a[i].type==1)cnt1++;
        else if(a[i].type==2)cnt2++;
        if(a[i].type==1&&cnt1>x)continue;
        if(a[i].type==2&&cnt2>y)continue;
        sum+=a[i].val;
    }
    if(cnt1>x)
    {
        int res = cnt1-x;
        for(int i = x+y+1;i <= x+y+r&&res;++i)
        {
            if(a[i].type!=1)sum+=a[i].val,res--;
        }
    }
    if(cnt2>y)
    {
        int res = cnt2-y;
        for(int i = x+y+1;i <= x+y+r&&res;++i)
        {
            if(a[i].type!=2)sum+=a[i].val,res--;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t)cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    string ACL="ACL";
    int k;
    cin >> k;

    rep(i,k) cout << ACL;
    cout << endl;

    
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n,h; cin >> n >> h;
  vector<int> a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];
  
  int max_a = 0;
  rep(i,n){
    chmax(max_a,a[i]);
  }
  
  sort(b.begin(),b.end(),greater<int>());
  int time = 0;
  rep(i,n){
    if(b[i] > max_a && h > 0){
      h -= b[i];
      time++;
    }
  }
  
  if(h > 0) time += (h+max_a-1)/max_a;
  
  cout << time << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

LL mod = 1000000007;

int main()
{
	LL a, b;
	cin >> a >> b;

	cout << 6-a-b << endl;

}

Measured memory_bytes: 256
g=[]
h=[]
a,b,k=gets.split.map &:to_i
for c in 1..a
  if(a%c==0)
g<<c
end
end
for d in 1..b
  if(b%d==0)
g<<d
end
end
h=g.select{|n|g.count(n)>1}.uniq
j=h.sort.reverse
puts j[k-1]

Measured memory_bytes: 14344
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
		cerr << (*i) << " ";
    }
    cerr << "\n";
}
map<vector<int>, int> mm;
map<vector<int>, int> mm2;
int x, y, z;
int n;

vector<int> vvg;

int ch() {
	int st = 0;
	int sum = 0;
	for (int i = 0; i < vvg.size(); ++i) {
		sum += vvg[i];
		if (st == 0) {
			if (sum > x)
				return 0;
			if (sum == x)
				st = 1, sum = 0;
		}
		else if (st == 1) {
			if (sum > y)
				return 0;
			if (sum == y)
				st = 2, sum = 0;
		}
		else if (st == 2) {
			if (sum > z)
				return 0;
			if (sum == z) {
				return 2;
			}
		}
	}
	return 1;
}

int opti() {
	while (true) {
		int x = ch();
		if (x == 2)
			return 1;
		if (x == 1)
			return 0;
		vvg.erase(vvg.begin());
	}
	return 0;
}
const ll MOD = 1e9 + 7;

int main() {
	cin >> n >> x >> y >> z;
	ll ans = 0;
	mm[vector<int>()] = 1;
	for (int i = 0; i < n; ++i) {
		mm2.clear();
		for (auto it: mm) {
			for (int j = 1; j <= 10; ++j) {
				vvg = it.first;
				vvg.push_back(j);
				if (!opti()) {
					mm2[vvg] = (mm2[vvg] + it.second) % MOD;
				}
				else {
					ll now = it.second;
					for (int j = i + 1; j < n; ++j)
						now = (now * 10) % MOD;
					ans = (ans + now) % MOD;
				}
			}
		}
		mm = mm2;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 4608
#include<iostream>
#include<cstdio>
#include<vector>

#define int long long

using namespace std;

const int p=1000000007;
int f[302][301][301],N,M,l,r,x,ans;
vector<pair<int,int>> vec[301];

main(){
	scanf("%lld%lld",&N,&M);for(int i=1;i<=M;++i)scanf("%lld%lld%lld",&l,&r,&x),vec[r].push_back(make_pair(l,x));
	for(int i=f[1][0][0]=1;i<=N;++i){
		for(pair<int,int> pr:vec[i])for(int j=0;j<i;++j)for(int k=0;k<=(j>0?j-1:j);++k)if(pr.second==1){if(pr.first<=j)f[i][j][k]=0;}else if(pr.second==2){if(pr.first<=k||j<pr.first)f[i][j][k]=0;}else if(k<pr.first)f[i][j][k]=0;
		for(int j=0;j<i;++j)for(int k=0;k<=(j>0?j-1:j);++k)(f[i+1][j][k]+=f[i][j][k])%=p,(f[i+1][i][k]+=f[i][j][k])%=p,(f[i+1][i][j]+=f[i][j][k])%=p;
	}for(int i=0;i<N;++i)for(int j=0;j<=(i>0?i-1:i);++j)(ans+=f[N][i][j])%=p;
	printf("%lld",ans*3%p);
}

Measured memory_bytes: 211968
a = gets.chomp.split(" ").map(&:to_i)[0]
b = gets.chomp.split(" ").map(&:to_i)[0]
c = gets.chomp.split(" ").map(&:to_i)[0]
x = gets.chomp.split(" ").map(&:to_i)[0]

ans = 0
for ai in 0..a
    for bi in 0..b
        for ci in 0..c
            if (ai * 500) + (bi * 100) + (ci * 50) == x
                ans += 1
            end
        end
    end
end

puts ans


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

int main(){

  int a,b,c;
  cin >> a >> b >> c;
  int ans[6];
  ans[0] = abs(a-b) + abs(b-c);
  ans[1] = abs(a-c) + abs(c-b);
  ans[2] = abs(b-c) + abs(c-a);
  ans[3] = abs(b-a) + abs(a-c);
  ans[4] = abs(c-a) + abs(a-b);
  ans[5] = abs(c-b) + abs(b-a);
  sort(ans,ans+6);
  cout << ans[0] << endl;

  return 0;

}


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

using namespace std;

typedef long long ll;

#define int ll

const int mod=1000000000+7;

int bin_pow(int x,int y){
  if(y==0)return 1;
  if(y==1)return x;
  int q=bin_pow(x,y/2);
  if(y&1) return (ll)q*q%mod*(ll)x%mod;
  else return (ll)q*q%mod;
}

int fact(int x){
  int ans=1;
  for(int i=2;i<=x;i++){
    ans=(ll)ans*i%mod;
  }
  return ans;
}

int c(int n, int k){
  int a=fact(n);
  int b=fact(k);
  int c=fact(n-k);
  int d=(ll)c*b%mod;
  return (ll)a*bin_pow(d,mod-2)%mod;
}

signed main() {
  int x0,y0;
  cin>>x0>>y0;
  if((2*x0-y0)%3!=0){
   cout<<0;
   return 0; 
  }
  int y=(2*x0-y0)/3;
  int x=x0-2*y;
  if(x<0||y<0){
    cout<<0;
    return 0;
  }
  //cout<<x<<" "<<y<<endl;
  cout<<c(x+y,x);
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())

if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(N - 90)
elif N < 10000:
    print(909)
elif N < 100000:
    print(N - 9090)
else:
    print(90909)

Measured memory_bytes: 2940
def comb(n, k, mod):
    if k > (n // 2):
        k = n - k
    a = 1
    for i in range(k):
        a *= (n - i)
        a %= mod
    for i in range(k - 1):
        a = (a * pow(k - i, mod - 2, mod)) % mod

    return a

X, Y = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
if X > Y:
    X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
    ans = 0
else:
    n = (X + Y) // 3
    d = Y - X
    a = 2*n - X
    ans = comb(n, a, mod)
print(ans)


Measured memory_bytes: 38768
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  cout<<h*w-a*w-b*h+a*b<<endl;
  return 0;
}


Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  deque<ll> dq;
  int q;
  cin >> q;
  rep(i, q){
    int x;
    cin >> x;
    if(x == 0){
      int d;
      ll y;
      cin >> d >> y;
      if(d == 0)dq.push_front(y);
      else dq.push_back(y);
    }else if(x == 1){
      int p;
      cin >> p;
      cout << *(dq.begin() + p) << endl;
    }else{
      int d;
      cin >> d;
      if(d == 0)dq.pop_front();
      else dq.pop_back();
    }
  }
	return 0;
}



Measured memory_bytes: 6168
a,b=map(int, input().split())

if a > b:
    tmp = a % b
    tmp2 = -1 * (tmp - b)
    if tmp > tmp2:
        print(tmp2)
    else:
        print(tmp)
elif a < b:
    tmp = -1 * (a - b)
    if a < tmp:
        print(a)
    else:
        print(tmp)
elif a == b:
    print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
	int n;
	cin>>n;
	int a[n];
	int b[n-1];
	rep(i,n-1)cin>>b[i];
	int r=b[0]+b[n-2];
	rep(i,n-2){
		r+=min(b[i],b[i+1]);
	}
	cout<<r<<endl;	
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  string s;
  cin >> s;
  
  vector<int> a=suffix_array(s);
  //for(ll i=0;i<a.size();i++)cout << a[i] << endl;
  ll ans=(s.size()+1)*s.size()/2;
  //cout << ans << endl;
  for(auto x:lcp_array(s,a)){
    ans-=x;
  }
  cout << ans << endl;


}

Measured memory_bytes: 15648
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
	string s;
	cin >> s;

	int n1 = stoi(s.substr(0, 2));
	int n2 = stoi(s.substr(2, 2));

	bool month1, month2;
	month1 = (1 <= n1 && n1 <= 12);
	month2 = (1 <= n2 && n2 <= 12);
	if (month1 && month2) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (month1) {
		cout << "MMYY" << endl;
	}
	else if (month2) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}
		

	return 0;
}

Measured memory_bytes: 760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N=scan.nextInt();
		int result=0;
		if(N%2==0) {
			result=N;
		}else {
			result=N*2;
		}
		System.out.println(result);
	}

}

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

ll solve() {
    ll N;
    cin >> N;
    map<string, ll> num;
    string s;
    for ( int i = 0; i < N; i++ ) {
        cin >> s;
        sort(s.begin(), s.end());
        num[s]++;
    }
    ll ans = 0;
    for( auto x : num ) {
        if ( x.second > 1 ) {
            ans += x.second * (x.second - 1) / 2;
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main()
{
  int N;scanf("%d",&N);
  int A[N],B[N],C[N];long long ans=0;
  for(int i=0;i<N;i++)scanf("%d ",&A[i]);
  for(int i=0;i<N;i++)scanf("%d ",&B[i]);
  for(int i=0;i<N;i++)scanf("%d ",&C[i]);
  sort(A,A+N);sort(B,B+N);sort(C,C+N);
  for(int i=0;i<N;i++)
  {
    ans+=((lower_bound(A,A+N,B[i])-A)*(N-(upper_bound(C,C+N,B[i])-C)));
  }
  printf("%lld",ans);
}


Measured memory_bytes: 4968
s = input()
ans = [-1, -1]

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans = [i+1, i+2]
        break

for i in range(len(s)-2):
    if s[i] == s[i+2]:
        ans = [i+1, i+3]
        break

print(ans[0], ans[1])

Measured memory_bytes: 3188
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

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

    int t = 0;
    int i = 0;
    while(i < x){
        ++t;
        i += t;
    }
    cout << t << endl;
}

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


int main()
{
    int a,b;cin>>a>>b;
    int ans = 0;
    for(int i = 1; i< 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                int sum = 10001 * i + 1010 * j+ 100 * k;
                if(a <= sum&&sum <= b) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
int main() {
	string s;
	cin >> s;
	vector<int> a(4);
	rep(i,4) a[i] = s[i]-'0';

	for(int bit = 0; bit<(1<<3); bit++){
		string t = to_string(a[0]);
		int sum = a[0];
		for(int i = 0; i<3; i++){
			if(bit&(1<<i)){
				sum+=a[i+1];
				t+=("+" + to_string(a[i+1]));
			}else{
				sum-=a[i+1];
				t+=("-" + to_string(a[i+1]));
			}
		}

		if(sum == 7){
			cout << t << "=7" <<endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353

using namespace std;

int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	if (n < b) {
		cout << a * n / b - a * (n / b) << endl;
	}
	else {
		cout << a * (b - 1) / b << endl;
	}
} 

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
const int N = 2005;

int n, a[2*N], c[2*N], id[2][N], sum[2][N][2*N], dt[N][N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) {
		char T[2];
		scanf("%s%d",T,&a[i]);
		c[i] = (T[0] == 'B');
		id[c[i]][a[i]] = i;
		for(int j=a[i];j<=n;j++) {
			sum[c[i]][j][i]++;
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=2*n;j++) {
			sum[0][i][j] += sum[0][i][j-1];
			sum[1][i][j] += sum[1][i][j-1];
		}
	}
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=n;j++) {
			int A = id[0][i], B = id[1][j];
			if(i == 0 && j == 0) continue;
			else if(i == 0) {
				dt[i][j] = dt[i][j-1] + B-1 - sum[0][i][B] - sum[1][j-1][B];
			}
			else if(j == 0) {
				dt[i][j] = dt[i-1][j] + A-1 - sum[0][i-1][A] - sum[1][j][A];
			}
			else {
				dt[i][j] = min(dt[i-1][j] + A-1 - sum[0][i-1][A] - sum[1][j][A], dt[i][j-1] + B-1 - sum[0][i][B] - sum[1][j-1][B]);
			}
		}
	}
	printf("%d\n",dt[n][n]);
}


Measured memory_bytes: 78720
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b;
  cin >> a >> b;
  int ans=0;
  if(a>b){
    ans+=a;
    a--;
  }else{
    ans+=b;
    b--;
  }
  if(a>b){
    ans+=a;
  }else{
    ans+=b;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#include <fstream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int H,W,D;
int X[90001],Y[90001];
int d[90001];
int main(){
  cin>>H>>W>>D;
  FOR(i,0,H){
    FOR(j,0,W){
      int num;
      cin>>num;
      X[num]=i;Y[num]=j;
    }
  }
  FOR(i,D+1,H*W+1){
    d[i]=d[i-D]+abs(X[i]-X[i-D])+abs(Y[i]-Y[i-D]);
  }
  int Q;
  cin>>Q;
  FOR(i,0,Q){
    int L,R;
    cin>>L>>R;
    cout<<d[R]-d[L]<<endl;
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
//  cout << N << endl;

  uint64_t tmp0 = 2;
  uint64_t tmp1 = 1;
  uint64_t result = 1;
    
  for (int i=1; i<N; ++i) {
    result = tmp1 + tmp0;
    tmp0 = tmp1;
    tmp1 = result;
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 3568
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 深さ
        self.size = [1] * n  # size[i]はiを根とするグループのサイズ

    def find(self, x):  # xの親を返す
        if self.par[x] == x:
            return x
        else:
            return self.find(self.par[x])

    def unite(self, x, y):  # x,yの属する集合をマージする
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
                self.size[y] += self.size[x]
            else:
                self.par[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def same(self, x, y):  # x,yが同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # xが属する集合の大きさを返す
        return self.size[self.find(x)]


N, M, K = map(int, input().split())
A, B = [0] * M, [0] * M
C, D = [0] * K, [0] * K

# 全部 0-indexed に合わせる

g_direct =[[] for _ in range(N)]
uf = UnionFind(N)  # 友達関係をまとめた UnionFind 木

for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1
    g_direct[A[i]].append(B[i])
    g_direct[B[i]].append(A[i])
    uf.unite(A[i], B[i])

for i in range(K):
    C[i], D[i] = map(int, input().split())
    C[i] -= 1
    D[i] -= 1
    if uf.same(C[i], D[i]):  # 同じ連結成分内にない場合は無視してもよい
        g_direct[C[i]].append(D[i])
        g_direct[D[i]].append(C[i])


ans = [0] * N
# i と j が同じ連結成分に含まれて、 i と j が友達関係もしくはブロック関係にあるような j の個数
for i in range(N):
    ans[i] = uf.group_size(i) - len(g_direct[i]) - 1
print(*ans)


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

using namespace std ;

int n , m , k ; 

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>m>>k ;
	n = 1 << m ;
	if(k >= n)
		return cout<<-1<<"\n" , 0 ;
	if(n == 2)
	{
		if(k == 0)
			return cout<<"0 0 1 1\n" , 0 ;
		else
			return cout<<-1<<"\n" , 0 ;
	}
	vector<int>v ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(i == k)
			continue ;
		v.push_back(i) ;
	}
	v.push_back(k) ;
	for(int i = n-1 ; i >= 0 ; --i)
	{
		if(i == k)
			continue ;
		v.push_back(i) ;
	}
	v.push_back(k) ;
	for(auto &i : v)
		cout<<i<<" ";
	return 0 ;
}

Measured memory_bytes: 2932
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
map<ll,int> mp;
int main(){
ll n;
cin>>n;
mp[n]++;
ll cnt=1;
ll t;
while(1){
  if(n%2==0)t=n/2;
  else t=3*n+1;
  cnt++;
  if(mp[t]){
       cout<<cnt<<endl;
       return 0;
  }
  mp[t]++;
  n=t;
}
}

Measured memory_bytes: 256