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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B; cin >> A >> B;
    cout << max(A+B,max(A-B,A*B)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  string s;cin>>s;
  vector<int> a(s.size(),0);
  int tmp = 0;
  int isEven = true;
  rep(i,s.size()){
    isEven = !isEven;
    if(s[i] == 'L'){
      int num = tmp / 2;
      a[i]   += num;
      a[i-1] += num;
      if(!(tmp%2))a[i]  += tmp % 2;
      else       a[i-1]+= tmp % 2;
      tmp = 0;
    }else tmp++;
  }
  
  isEven = !(s.size()%2);
  for(int i = s.size()-1;i >= 0;--i){
    isEven = !isEven;
    if(s[i] == 'R'){
      int num = tmp / 2;
      a[i]   += num;
      a[i+1] += num;
      if(!(tmp%2))a[i]  += tmp % 2;
      else       a[i+1]+= tmp % 2;
      tmp = 0;
    }else tmp++;
  }
  rep(i,s.size())cout<<a[i]<<" \n"[i == s.size()-1];

  return 0;
} 

Measured memory_bytes: 1104
#include<stdio.h>

int main(void)
{
  int i, j, QQ;

  for(i = 1 ; i <= 9 ; i++ )
    {
      for(j = 1 ; j <= 9 ; j++ )
	{
	  QQ = i * j;
	  printf("%dx%d=%d\n", i, j, QQ);
        }
    }
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}
void solve()
{   int n,k;
    cin>>n>>k;
    int a[n];
    fi(i,0,n)
        cin>>a[i];
    int cost[n];
    mz(cost);
    cost[0] = 0;
    fi(i,1,n)
    {   cost[i] = INT_MAX;
        for(int j=i-1;j>=max(0,(i-k));--j)
            cost[i] = min(cost[i],abs(a[i] - a[j]) + cost[j]);
    }
    cout<<cost[n-1];
}
int main() {
   
        solve();

  
    return 0;
}


Measured memory_bytes: 1024
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    string s;
    int m;
    void solve()
    {
        cin>>n>>m;
        if(n<=m)
        fo(i,0,m)
        s.append(string(1,n+'0'));
        else
         fo(i,0,n)
        s.append(string(1,m+'0'));
        cout<<s<<endl;

        
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
      {
        
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        
        // cin>>t;while(t--)
        solve();
        
      return 0;
      }

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

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

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

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));

    ll ans = a[n-1];
    int itr = n-2;
    
    n -= 2;

    for (; n-2>=0; itr--) {
        ans += 2*a[itr];
        n -= 2;
    }
    ans += n*a[itr];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
#define n_l '\n'
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: "; cerr << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cerr << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cerr << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cerr << endl
#define run(a, b) cerr << fixed << setprecision(6) << (double) (b - a) / (double) (CLOCKS_PER_SEC) << " s" << endl;
#define ll long long
#define ld long double
#define INF (1e18L + 5)
#define MOD (ll)(1e9 + 7)

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector<bool> ans(101, false);
    for(int i = 1; i < 10; i++) {
        for(int j = 1; j < 10; j++) {
            ans[i*j] = true;
        }
    }
    int a;
    cin >> a;
    if(ans[a]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

bool cmp(pii a, pii b) {
    return 1ll * a.first * (b.second + 1) > 1ll * b.first * (a.second + 1);
}

int main() {
    ios::sync_with_stdio(false);
    int n, z = 0;
    ll t, d[42] = {};
    vector<int> b;
    for (int i = 1; i <= 40; i++) d[i] = mod;
    pii a[200005] = {};
    cin >> n >> t;
    for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= n; i++) if (a[i].first) {
        for (int j = 40; j; j--) {
            d[j] = min(d[j], d[j - 1] + 1 + (d[j - 1] + 1) * a[i].first + a[i].second);
        }
    }
    //for (int i = 0; i <= 10; i++) cout << d[i] << ' '; cout << '\n';
    for (int i = 1; i <= n; i++) if (!a[i].first) b.push_back(a[i].second);
    sort(b.begin(), b.end());
    for (int i = 0; i <= 40; i++) if (d[i] <= t) {
        int y = i;
        for (int j = 0; j < b.size(); j++) {
            if (d[i] + b[j] + 1 <= t) d[i] += b[j] + 1, y++;
            else break;
        }
        z = max(z, y);
    }
    cout << z;
}


Measured memory_bytes: 2936
#include "bits/stdc++.h"
using namespace std;

#define ll long long

int main() {
	ll n, k;
	ll a, b;
	ll ans;
	cin >> n >> k;

	if (n < k) {
		a = n;
		b = k - n;
		if (a < b)ans = a;
		else ans = b;
	}
	else {
		a = n % k;
		b = abs(a - k);
		if (a < b)ans = a;
		else ans = b;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vin a(n);rep(i,n)cin>>a[i];
    vin r(n),l(n);
    l[0]=a[0];r[0]=a[n-1];
    rep(i,n-1){
        l[i+1]=l[i]^a[i+1];
        r[i+1]=r[i]^a[n-2-i];
    }
    cout<<r[n-2]<<" ";
    rep2(i,1,n-1)cout<<(l[i-1]^r[n-2-i])<<" ";
    cout<<l[n-2]<<endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<vector>
#include<stdio.h>
typedef int long long ll;
using namespace std;
int main(){
    ll n;
    cin>>n;
    vector<ll> h(n);
    for(int i=0;i<n;i++){
        ll x;cin>>x;
        h[i]=x;
    }
    vector<ll> a(n);
    a[0]=0;
    a[1]=abs(h[1]-h[0]);
    if(n==2){cout<<a[1];return 0;}
    for(int i=2;i<n;i++){
        a[i]=min((abs(h[i]-h[i-1])+a[i-1]),abs(h[i]-h[i-2])+a[i-2]);
    }
    cout<<a[n-1]<<endl;
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 1792
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		//aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
	//		aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		printf("%d ", n);
		//aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
vector<int>a(55);
int mem[100][100][100];
LL solv(int l, int r, int k, int n) {
	if (k < 0) { return -1e9; }
	if (k == 0 or (l > r)) { return 0; }
	if (mem[l][r][k] != -1)
		return mem[l][r][k];
	if (mem[l][r][k] != -1)
		return mem[l][r][k];
		int x = solv(l + 1, r, k - 1, n) + a[l];
		int y = solv(l, r - 1, k - 1, n) + a[r];
		int z = solv(l + 1, r, k - 2, n);
		int t = solv(l, r - 1, k - 2, n);
		mem[l][r][k] = max({ 0,x,y,z,t });
		return mem[l][r][k];
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, k;
	memset(mem, -1, sizeof mem);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int ans= solv(0, n - 1, k, n);
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  int a[55],b[55],c[55],d[55];
  for (int i = 0; i < N; i++){
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < M; i++){
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < N; i++){
    int md = 1000000000;           //暫定のマンハッタン距離
    int ans;
    for (int j = 0; j < M; j++){
      int mdj =  abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (mdj < md){
        md = mdj;                //マンハッタン距離を更新
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

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

const ll maxn = 2e5+7;
ll num[maxn];
void solve(ll N, vector<ll> A)
{
    ll acc = 0;
    for(int x:A)num[x]++;
    for(int i=1;i<=N;++i)
        acc += num[i]*(num[i]-1)/2;
    for(int x:A)
    {
        ll preacc = acc;
        acc -= num[x]*(num[x]-1)/2;
        acc += (num[x]-1)*(num[x]-2)/2;
        cout<<acc<<endl;
        acc = preacc;
    }
}


int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0 ; i < N ; i++)
    {
        cin >> A[i];
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,m;
  cin >> n >> m;
  vector<P> dig;
  rep(i,m){
    int s,c;
    cin >> s >> c;
    dig.emplace_back(n-s,c);
  }

  int ans[n];
  rep(i,n) ans[i] = -1;
  for( P p : dig ){
    if (ans[p.first]!=-1 && p.second != ans[p.first]) {
      cout << "-1" << endl;
      return 0;
    }
    if (p.first == n-1 && p.second == 0 && n > 1) {
      cout << "-1" << endl;
      return 0;
    }
    ans[p.first] = p.second;
  }
  
  rep(i,n) {
    if (ans[i]==-1) {
      if (i==n-1 && n > 1) {
        ans[i] = 1;
      } else {
        ans[i] = 0;
      }
    }
  }

  rep(i,n) {
    cout << ans[n-i-1];
  }
  cout << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
#define ll long long int
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
vector<vector<int> >v;
vector<int>c;
vector<bool>vis;
int k=0;
vector<int>d;
int dfs(int i)
{
    vis[i]=true;
    int sum;
    d[i]=c[k];
    sum=d[i];
    k++;
    int j;
    for(j=0;j<v[i].size();j++)
        if(vis[v[i][j]]==false)
        sum+=dfs(v[i][j]);
    return sum;
}
int main()
{
    io;
    int n;
    int i,a,b;
    cin>>n;
    v.resize(n+1);
    c.resize(n);
    d.resize(n+1);
    vis.resize(n+1,false);
    for(i=1;i<n;i++)
    {
       cin>>a>>b;
       v[a].pb(b);
       v[b].pb(a);
    }
    for(i=0;i<n;i++)
        cin>>c[i];
        sort(c.begin(),c.end(),greater<int>());
    cout<<dfs(1)-c[0]<<"\n";
    for(i=1;i<=n;i++)
        cout<<d[i]<<" ";
    return 0;
}


Measured memory_bytes: 1408
//
// Created by Hideaki Imamura on 2020-03-16.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, K;
int a[110], dp[100100];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> a[i];

    // dp[j] = k個の石からなる山で、先手が勝つかどうか
    for (int k = 0; k <= K; ++k) {
        // lose = k に対して負け状態がいくつあるか
        // counter = k に対して遷移先がいくつあるか
        int lose = 0, counter = 0;
        for (int i = 0; i < N; ++i) {
            if (0 <= k - a[i]) {
                counter++;
                if (!dp[k - a[i]]) lose++;
            }
            // 遷移先が１つもないなら負けとする
            if (counter == 0) dp[k] = 0;
            // 遷移前に１つでも負け状態があるなら、勝ちとする
            else if (lose > 0) dp[k] = 1;
            // 遷移前が全て勝ち状態なら、負けとする
            else dp[k] = 0;
        }
    }

    if (dp[K]) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
	}
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x;
    while (y > 0) {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n;
	cin>>n;
	vector<vll> S(n, vll(2, 0));
	loop(i, 0, n)
		cin>>S[i][0]>>S[i][1];
	sort(S.begin(), S.end(), [](const vll& v1, const vll& v2){
		return v1[0] + v1[1] < v2[0] + v2[1];
	});
	vector<vll> dp(n+1, vll(n+1, 1e15));
	dp[0][0] = 0;
	loop(i, 1, n+1){
		loop(j, 1, n+1){
			if(dp[i-1][j-1] <= S[i-1][0])
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + S[i-1][1]);
			dp[i][j] = min(dp[i][j], dp[i-1][j]);
		}
	}
	loopb(i, n, 1){
		if(dp[n][i] < 1e15){
			cout<<i<<"\n";
			return 0;
		}
	}
	return 0;
}
int main(){
	// fastio;
	lli t;
	// cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 196096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string A,B,U;
    int n,m,l,c;
    cin >> A >> B;
    cin >> n >> m;
    cin >> U;
    l = A.compare(U);
    c = B.compare(U);
    if(l==0)
    {
        n = n-1;
    }
    else if(c==0)
    {
        m = m-1;
    }
    cout << n <<" " <<m;
    return 0;
}


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

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

	vector<int> v;
	v.push_back(1);
	if (N >= 6)
	{
		for (int i = 6; i <= N; i *= 6)
		{
			v.push_back(i);
		}
	}

	if (N >= 9)
	{
		for (int i = 9; i <= N; i *= 9)
		{
			v.push_back(i);
		}
	}

	sort(v.begin(), v.end(), less<int>());

	vector<int> dp(N+1);
	dp[0] = 0;

	for (int i = 1; i <= N; ++i)
	{
		int min_n = 100000;
		for (auto e : v)
		{
			if (i < e)
			{
				break;
			}

			min_n = min(min_n, dp[i-e] + 1);
		}

		dp[i] = min_n;
	}

	cout << dp[N] << endl;

	return 0;
}

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

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



Measured memory_bytes: 3044
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B, C);

// ===

fn main() {
    for i in 0..3 {
        let s: String = read();
        print!("{}", s.chars().nth(i).unwrap());
    }
    println!();
}


Measured memory_bytes: 4352
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = ""
    for _ in range(m):
        a = input().strip()
        ans += d.get(a, a)
    print(ans)

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

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

    int n, x;
    cin >> n >> x;
    
    int mini = 1e9;
    REP(i, n){
        int m;
        cin >> m;
        x -= m;
        mini = min(mini, m);
    }

    cout << n + x / mini << endl;

    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vi a(m), b(m), road(n);
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        road[a[i]]++;
        road[b[i]]++;
    }

    rep(i, n){
        cout << road[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
N , K , Q = map(int , input().split())
point = [K] * N
for _ in range(Q):
    answer = int(input())
    point[answer - 1] += 1
point = list(map(lambda x : x - Q , point))
for i in range(N):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")


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

using namespace std;

bool grid[401][401],vis[401][401];
long cntb,cntw,h,w;

void traverse(long i,long j)
{
    vis[i][j]=true;
    if(!grid[i][j])
    {
        cntw++;
        if(j+1<w && grid[i][j+1] && !vis[i][j+1])
            traverse(i,j+1);
        if(j-1>=0 && grid[i][j-1] && !vis[i][j-1])
            traverse(i,j-1);
        if(i+1<h && grid[i+1][j] && !vis[i+1][j])
            traverse(i+1,j);
        if(i-1>=0 && grid[i-1][j] && !vis[i-1][j])
            traverse(i-1,j);
    }
    else
    {
        cntb++;
        if(j+1<w && !grid[i][j+1] && !vis[i][j+1])
            traverse(i,j+1);
        if(j-1>=0 && !grid[i][j-1] && !vis[i][j-1])
            traverse(i,j-1);
        if(i+1<h && !grid[i+1][j] && !vis[i+1][j])
            traverse(i+1,j);
        if(i-1>=0 && !grid[i-1][j] && !vis[i-1][j])
            traverse(i-1,j);
    }

}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    char ch;
    cin>>h>>w;
    for(long i=0;i<h;i++)
    {
        for(long j=0;j<w;j++)
        {
            vis[i][j]=false;
            cin>>ch;
            if(ch=='#')
                grid[i][j]=true;
            else
                grid[i][j]=false;
        }
    }
    long cnt=0;
    for(long i=0;i<h;i++)
    {
        for(long j=0;j<w;j++)
        {
            if(!vis[i][j])
            {
                cntb=0;
                cntw=0;
                traverse(i,j);
                cnt+=(cntb*cntw);
                //cout<<i<<" "<<j<<" "<<cntb<<" "<<cntw<<endl;
            }
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 10624
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define LL long long
#define maxn 1000005
#define mod 1000000007
#define INF (LL)1e18
using namespace std;
typedef pair<LL,int> PLI;
LL n,ans,c[maxn],Siz,cnt[maxn],fact[maxn],inv[maxn],mnp[maxn],Mnp2,Mnp;
LL w[maxn],x,y,Mn=INF,Mn2=INF,mn[maxn];
bool vis[maxn];
vector<PLI> cw[maxn];
struct node { LL v; node *nxt; } edge[maxn*20],*head[maxn],*ncnt;
void addedge(LL u,LL v)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[u];
	head[u]=ncnt;
}
void dfs(LL u)
{
	vis[u]=true;
	cnt[c[u]]++,Siz++;
	for(node *p=head[u];p;p=p->nxt)
	{
		LL v=p->v;
		if(!vis[v]) dfs(v);
	}
}
int main()
{
	scanf("%lld%lld%lld",&n,&x,&y);
	fact[0]=1;
	for(LL i=1;i<maxn;i++) fact[i]=1ll*fact[i-1]*i%mod;
	inv[1]=1;
	for(LL i=2;i<maxn;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;
	for(LL i=1;i<maxn;i++) inv[i]=1ll*inv[i]*inv[i-1]%mod;
	ncnt=&edge[0];
	for(LL i=1;i<=n;i++) mn[i]=INF;
	for(LL i=1;i<=n;i++)
	{
		scanf("%lld%lld",&c[i],&w[i]);
		if(mn[c[i]]>w[i]) mn[c[i]]=w[i],mnp[c[i]]=i;
		if(Mn>w[i]) Mn=w[i],Mnp=i;//Mn=min(Mn,w[i]);
	}
	for(LL i=1;i<=n;i++)
		if(c[i]!=c[Mnp]&&Mn2>w[i]) Mn2=w[i],Mnp2=i;
	for(LL i=1;i<=n;i++)
		if(i!=mnp[c[i]]&&mn[c[i]]+w[i]<=x) { addedge(i,mnp[c[i]]); addedge(mnp[c[i]],i); }
	for(LL i=1;i<=n;i++)
	{
		if(i==Mnp) continue;
		else if(c[i]!=c[Mnp]&&Mn+w[i]<=y) { addedge(i,Mnp); addedge(Mnp,i); }
		else if(c[i]==c[Mnp]&&Mn2+w[i]<=y) { addedge(i,Mnp2); addedge(Mnp2,i); }
	}
	dfs(Mnp);
	ans=fact[Siz];
	for(LL i=1;i<=n;i++) ans=1ll*ans*inv[cnt[i]]%mod;
	printf("%lld\n",ans);
}


Measured memory_bytes: 69376
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;

#define INF 1145141919

struct L {
  int left, mid, right;
  L() : left(-1), mid(-1), right(-1) {}
  L(int l, int m, int r) : left(l), mid(m), right(r) {}
};

int N, M;
int D[100010], P[100010];

int G;
L E[200010];

int cost(int x) {
  if (E[x].left == -1) return E[x].mid;
  long long a = cost(E[x].left), b = cost(E[x].mid), c = cost(E[x].right);
  return min(a + b + c - max(a, max(b, c)), (long long)INF);
}

bool solve(int x) {
  for (int i=0; i<G; i++) {
    if (E[i].left == -1) E[i].mid = 1;
  }
  for (int i=0; i<M; i++) {
    if (D[i] >= x) E[P[i]-1].mid = 0;
    else           E[P[i]-1].mid = INF;
  }

  int K = 0;
  for (int i=0; i<N-M; i++) K += D[i+M] >= x;
  return cost(G-1) <= K;
}

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) cin >> D[i] >> P[i];
  for (int i=0; i<N-M; i++) cin >> D[i+M];

  queue<int> q;
  for (int i=0; i<N; i++) {
    q.push(i);
    E[i] = L(-1, -1, -1);
  }

  G = N;
  while (q.size() >= 3) {
    int a = q.front(); q.pop();
    int b = q.front(); q.pop();
    int c = q.front(); q.pop();
    E[G] = L(a, b, c);
    q.push(G);
    G += 1;
  }

  int lo = -1, hi = INF;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (solve(mid)) lo = mid;
    else hi = mid;
  }
  cout << lo << "\n";
  return 0;
}

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

using namespace std;

const int mod=1e9+7;

void run();

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

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

void run(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];
    vector<bool> dp(k+1);
    REP(i,1,k){
        rep(j,n){
            if(i>=a[j]&&!dp[i-a[j]])dp[i]=1;
        }
    }
    cout<<(dp[k]?"First":"Second")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ar[100005];
struct op
{
    long long usetime;
    long long value;
}myop[100005];
bool cmp(op a,op b){
	return a.value > b.value;
}
int main()
{
    long long n,m;
    long long ans=0;
    long long i,j=0,k=1;
    cin>>n>>m;
    for(i=0;i<=n-1;i++) scanf("%lld",&ar[i]);
    for(i=0;i<=m-1;i++) scanf("%lld%lld",&myop[i].usetime,&myop[i].value);
    sort(ar,ar+n);
    sort(myop,myop+m,cmp);
    for(i=0;i<=n-1 && j<=m-1;i++){
        if(ar[i]<myop[j].value){
            ar[i]=myop[j].value;
            k++;
            if(k>myop[j].usetime){
                k=1;
                j++;
            }
        }
        else break;
    }
    for(i=0;i<=n-1;i++) ans+=ar[i];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <bitset>
#include <math.h>
#include <vector>
#include <set>

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 long long INF = 1LL<<60;

using namespace std;

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

    if(N == 1){
        cout << "Hello World" << endl;
    }
    else{
        cin >> A >> B;
        cout << A+B << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  int ans=0;
  for(int i=1; i<=N; i+=2){
    int num=0;
    for(int j=1; j<=N; j++){
      if(i%j==0) num++;
    }
    if(num==8) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
f_inf = float("inf")

max_l = 0
min_r = f_inf
for l, r in LR:
    max_l = max(max_l, l)
    min_r = min(min_r, r)

if min_r >= max_l:
    print(min_r - max_l + 1)
else:
    print(0)

Measured memory_bytes: 27244
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    std::string s, t;
    std::cin >> s >> t;
    std::cout << t + s << std::endl;
    return 0;
}

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


int main() {
	int N;
	int a[110];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int A = 0;
	int B = 0;
	for (int k = 1; k <= N; k++) {
		int max = 0;
		int max_ind;
		for (int i = 0; i < N; i++) {
			if (max < a[i]) {
				max = a[i];
				max_ind = i;
			}
		}
		a[max_ind] = -1;
		if (k % 2 == 0) {
			B += max;
		}
		else {
			A += max;
		}
	}
	cout << A - B << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <unordered_map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

vector<int> posMap[26];

int main(int argc, char** argv) {
  string s, t;
  cin >> s;
  cin >> t;

  // For Debug
  // cout << s << endl;
  // cout << t << endl;
  int s_len = s.size();
  rep(i, s_len) {
    int c = s[i] - 'a';
    posMap[c].push_back(i);
  }

  // For Debug
  // rep(i, 26) {
  //   cout << (char)('a' + i) << ": ";
  //   for (auto e : posMap[i]) {
  //     cout << e << " ";
  //   }
  //   cout << endl;
  // }

  bool impossible = false;
  int last_index = -1; // -1 is the sentinel.
  uint64_t cycle_cnt = 0;  // The count of cycle.
  int t_len = t.size();
  rep(i, t_len) {
    int c = t[i] - 'a';
    if (posMap[c].size() == 0) {
      impossible = true;
      break;
    }

    auto it = upper_bound(all(posMap[c]), last_index); // posMap[c] is sorted.

    // If last_index is lower than any element in posMap[c], we use the next value of posMap[c].
    // If last_index is larger than all value of posMap[c], we have to cycle.
    if (it == posMap[c].end()) { // last_index is equal or the largest if incidex
      cycle_cnt += 1;
      last_index = posMap[c][0];
    } else {
      last_index = *it;
    }
  }


  if (impossible) {
    cout << -1 << endl;
  } else {
    uint64_t res = (s_len * cycle_cnt) + last_index + 1;
    cout << res << endl;
  }
}


Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] A = new int[n];
		for( int i = 0; i < n; i++){
			A[i] = scan.nextInt();
		}
		int ans = 200;
		for (int i = 0; i < A.length; i++) {
			int a = A[i];
			int now = 0;
			while (a%2 == 0) {
				a /= 2;
				now++;
			}
			if (ans > now) {
				ans = now;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 20692
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
string s[1000];
int n,m;
int main()
{
    while(~scanf("%d %d",&n,&m))
    {
        for(int i=0;i<n;i++)
        {
            cin>>s[i];
        }
        for(int j=0;j<n;j++)
        {
            cout<<s[j]<<endl;
            cout<<s[j]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3204
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define nmax 100001
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}

ll res = 1;
vector<vector<ll>> adj(nmax, vector<ll>());
vector<ll> facts(nmax,1);
vector<ll> inv_facts(nmax,1);

ll extended_gcd(ll a,ll b, ll &x, ll &y) {
    if(a==0) {
        x = 0;
        y = 1;
        return b;
    }

    ll x1,y1;
    ll r1 = extended_gcd(b%a, a, x1, y1);

    x = y1-(b/a)*x1;
    y = x1;
    return r1;
}

void dfs(ll idx, ll k, ll par) {
    // cout<<idx<<endl;
    if(idx!=0) {
        ll a = adj[idx].size();
        if(a+1>k) {
            res = 0;
            return;
        }
        if(a==1) return;
        res = (res*((facts[k-2]*inv_facts[k-1-a])%N))%N;        
    } 

    for(auto i:adj[idx]) {
        if(i!=par)
            dfs(i, k, idx);
    }
}

int main() {
    
    for(int i=1;i<nmax;i++){
        facts[i] = (i*facts[i-1])%N;
        ll x,y;
        extended_gcd(facts[i],N,x,y);
        inv_facts[i] = x;
    }

    ll n,k;
    cin>>n>>k;
    
    fill_edges(adj,n-1);
    ll a = adj[0].size();

    if(a+1>k) {
        cout<<0<<endl;
        return 0;
    }

    res = (facts[k]*inv_facts[k-a-1])%N;
    dfs(0,k,-1);

    cout<<(res+N)%N<<endl;
    return 0;
}




Measured memory_bytes: 10752
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue
//#define minn 999999999
//#define maxx 0
int longest_palindrome_prefix(const string &s)
{
    string kmprev = s;
        std::reverse(kmprev.begin(), kmprev.end());
        string kmp = s + "#" + kmprev;

        vector<int> lps(kmp.size(), 0);   // lps[i] = longest suffix length for substring kmp[0..i] where the suffix == prefix
        for (int i = 1; i < (int)lps.size(); ++i)
        {
            int prev_idx = lps[i - 1];

            while (prev_idx > 0 && kmp[i] != kmp[prev_idx])
            {
                prev_idx = lps[prev_idx - 1];
            }

            lps[i] = prev_idx + (kmp[i] == kmp[prev_idx] ? 1 : 0);
        }

        // after KMP's LPS preprocessing, the last index of the LPS array will contain the longest palindrome prefix' length!
        return lps[lps.size() - 1];

}
float maxvolume(float s) 
{ 
    // finding length 
    ld length = s / 3.0; 
  
    s -= length; 
  
    // finding breadth 
    ld breadth = s / 2.0; 
  
    // finding height 
    ld height = s - breadth; 
  
    return length * breadth * height; 
} 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ld n;
    cin>>n;
    //ld ans=maxvolume(n);
    ld s1 = n/3.0;
    ld ans = s1*s1*s1;
    cout<<fixed << setprecision(10) << ans<<endl;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



string s;
void solve(){
	cin >> s;
	int a = s[0]-'0';
	int b = s[1]-'0';
	int c = s[2]-'0';
	int d = s[3]-'0';
	
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				int cnt = a;
				if(i) cnt += b;
				else cnt -= b;
				if(j) cnt += c;
				else cnt -= c;
				if(k) cnt += d;
				else cnt -= d;
				
				if(cnt == 7){
					cout << a;
					cout << (i?'+':'-');
					cout << b;
					cout << (j?'+':'-');
					cout << c;
					cout << (k?'+':'-');
					cout << d;
					cout << "=7" << endl;
					return;
				}
			}
		}
	}
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long f[100];
int main()
{
	long long n;
	cin>>n;
	f[0]=2;
	f[1]=1;
	for(int i=2;i<=100;i++)
	f[i]=f[i-1]+f[i-2];
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 500;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> dp(s.length() + 2);
    for(int i = 0; i < s.length() - 1; ++i) {
        if(s[i] == 'A' && s[i+1] == 'C') {
            dp[i+2]++;
        }
    }
    for(int i = 1; i <= s.length(); ++i) {
        dp[i] += dp[i-1];
//        cout << i << " " << dp[i] << "\n";
    }
    while(q--) {
        int l, r;
        cin >> l >> r;
        l = l + 1;
        cout << dp[r] - dp[l - 1] << "\n";
    }
    return 0;
}

Measured memory_bytes: 1488
using System;
using System.Collections.Generic;

namespace ITP1_3_B
{
    class Program
    {
        static void Main(string[] args)
        {
            LinkedList<int> list = new LinkedList<int>();
            while (true) {
                int x = int.Parse(Console.ReadLine());
                if (x == 0) break;
                list.AddLast(x);
            }
            int i = 1;
            foreach(int x in list)
            {
                Console.WriteLine("Case " + i + ": " + x);
                i++;
            }
        }
    }
}

Measured memory_bytes: 10820
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: u32 = read();
    let b: u32 = read();

    let ans = if (a * b) % 2 == 0 { "Even" } else { "Odd" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

long long d[2501];

struct Edge
{
	int from;
	int to;
	long long cost;
};

int main()
{
	int N, M, P;
	cin >> N >> M >> P;
	vector<vector<int>> G(N + 1);
	vector<vector<int>> GB(N + 1);
	vector<Edge> E;
	for (auto i = 0; i < M; ++i)
	{
		int A, B;
		long long C;
		cin >> A >> B >> C;
		G[A].push_back(B);
		GB[B].push_back(A);
		E.push_back(Edge{ A, B, C - P });
	}

	bool used[2501];
	bool fromS[2501];
	bool fromE[2501];
	memset(used, 0, sizeof(used));
	memset(fromS, 0, sizeof(fromS));
	memset(fromE, 0, sizeof(fromE));

	queue<int> q;

	auto search = [&](vector<vector<int>>& g, bool from[])
	{
		while (!q.empty())
		{
			auto v = q.front();
			q.pop();
			if (used[v])
			{
				continue;
			}

			used[v] = true;
			from[v] = true;
			for (auto n : g[v])
			{
				if (used[n])
				{
					continue;
				}
				q.push(n);
			}
		}
	};

	q.push(1);
	search(G, fromS);
	q.push(N);
	memset(used, 0, sizeof(used));
	search(GB, fromE);



	for (auto i = 2; i <= N; ++i)
	{
		d[i] = LLONG_MIN;
	}

	auto count = 0;
	auto valid = true;
	while (true)
	{
		auto update = false;
		for (auto& e : E)
		{
			if (fromS[e.from] == false || fromE[e.from] == false
				|| fromS[e.to] == false || fromE[e.to] == false)
			{
				continue;
			}

			if (d[e.from] != LLONG_MIN && d[e.to] < d[e.from] + e.cost)
			{
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}

		if (!update)
		{
			break;
		}
		++count;
		if (count > N)
		{
			valid = false;
			break;
		}
	}

	if (valid)
	{
		cout << max(0ll, d[N]) << endl;
	}
	else
	{
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int n, x, max;
	int a, b, c;
	int ans;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		ans = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2044
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	int maxv = 0;
	for (int n = 0;n<N;++n) {
		int num;
		cin >> num;
		ans += num;
		maxv = max(maxv,num);
	}
	cout << ans - maxv/2 << endl;
}

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

typedef long long ll;
using namespace std;
int main()
{
  ll n,x,t;
  cin>>n>>x>>t;
  ll ans=(n/x)*t;
  if(n%x!=0)ans+=t;
  cout<<ans<<endl;;
  return 0;
}


Measured memory_bytes: 3584