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

int main()
{
    ll n, m, x;
    cin >> n >> m >> x;
    vector<ll> c(n, 0);
    vector<vector<ll>> a(n, vector<ll>(m, 0));
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    bool impossible = false;
    for (int i = 0; i < m; i++)
    {
        ll gain = 0LL;
        for (int j = 0; j < n; j++)
        {
            gain += a[j][i];
        }

        if (gain < x)
        {
            impossible = true;
            break;
        }
    }
    if (impossible)
    {
        cout << -1 << endl;
        return 0;
    }

    ll cmin = 1001001001;
    for (long long bit = 0; bit < (1 << n); bit++)
    {
        ll tmpsum = 0;
        vector<ll> learned(m, 0LL);
        for (int i = 0; i < n; i++)
        {
            if (bit & (1 << i))
            {
                tmpsum += c[i];
                for (int j = 0; j < m; j++)
                {
                    learned[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for (int i = 0; i < m; i++)
        {
            if (learned[i] < x)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
            continue;
        cmin = min(cmin, tmpsum);
    }
    cout << cmin << endl;
    return 0;
}

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

void swap(int &a, int &b)
{
	a ^= b;
	b ^= a;
	a ^= b;
}

int main(int argc, char **argv)
{
	int tmp;
	int a, b, c;
	cin >> a >> b >> c;

	swap(a, b);
	swap(a, c);

	std::cout << a << " " << b << " " << c << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 5e4+10;
int a[maxn];
string str;
bool cmp(int a,int b)
{
    return a > b;
}
int main()
{
    ll cur = 0;
    cin>>str;
    for (int i = 0;i < str.length();i++)
    {
        cur = (cur + str[i] - '0');
    }
    if(cur%9 == 0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    //cout<<cur<<endl;

}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

vector<int> v(pow(2,18)+1,0),w(pow(2,18)+1,0);
vector<vector<int>> dp(1024,vector<int>(1e5+1,0));

int dfs(int V,int W,int C){
  if(W<0){
    return 0;
  }
  if(V<1024){
    return dp[V][W]+C;
  }
  int s=dfs(V/2,W-w[V],C+v[V]),t=dfs(V/2,W,C);
  return max(s,t);
}

int main() {
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> v[i+1] >> w[i+1];
  }
  for(int i=1;i<1024;i++){
    if(i>N){
      break;
    }
    for(int j=1;j<1e5+1;j++){
      if(j>=w[i]){
        dp[i][j]=max(dp[i/2][j],dp[i/2][j-w[i]]+v[i]);
      }
      else{
        dp[i][j]=dp[i/2][j];
      }
    }
  }
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int V,W;
    cin >> V >> W;
    cout << dfs(V,W,0) << endl;
  }
}

Measured memory_bytes: 406988
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOREACH(i, v) for(auto i = v.begin(); i != v.end(); i++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

int gcd(int a, int b) {
    int x = max(a, b);
    int y = min(a, b);
    int z = x % y;
    if(z == 0){
        return y;
    }else{
        return gcd(y, z);
    }
}

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

void solve() {
    int n;
    cin >> n;
    int t[n], x[n], y[n];
    REP(i, n) cin >> t[i] >> x[i] >> y[i];

    int temp = 0, p = 0;
    REP(i, n){
        temp = t[i] - temp;
        if(abs(x[i]+y[i]-p) <= temp && temp%2 == abs(x[i]+y[i]-p)%2){
            temp = t[i];
            p = x[i]+y[i];
        }else{
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

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

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// dijkstra
template<typename Edge>
struct dijkstra {
  using Graph = std::vector<std::vector<Edge>>;
  using T = typename Edge::cost_type;
  using GP = std::pair<T, int>;
  using Q = std::priority_queue<GP, std::vector<GP>, std::greater<GP>>;

  Graph& G;
  int N;
  std::vector<T> d;
  T INF;
  dijkstra(Graph& Graph, T inf): G(Graph), N(Graph.size()), INF(inf) {}

  void search(int s) {
    Q q;
    d.assign(N, INF);
    d[s] = 0;
    q.push(GP(0, s));
    while(!q.empty()) {
      GP p = q.top(); q.pop();
      int v = p.second;
      if(d[v] < p.first) continue;
      for(auto e: G[v]) {
        T newd = d[v]+e.cost;
        if(newd >= d[e.to]) continue;
        if(newd >= INF) continue;
        d[e.to] = newd;
        q.push(GP(d[e.to], e.to));
      }
    }
  }
};

int64_t const INF = 1e18;

struct edge {
  typedef int64_t cost_type;
  cost_type cost;
  int to;
  edge(cost_type c, int t): cost(c), to(t) {}
};

int main() {
  int N, M, S; std::cin >> N >> M >> S;
  std::vector<int>  U(M), V(M), A(M);
  std::vector<int64_t> B(M);
  int maxa = 0;
  for(int i = 0; i < M; ++i) {
    std::cin >> U[i] >> V[i] >> A[i] >> B[i]; --U[i]; --V[i];
    maxa = std::max(maxa, A[i]);
  }
  int maxs = maxa*(N-1);
  std::vector<std::vector<edge>> G(N*(maxs+1));
  for(int i = 0; i < M; ++i) {
    // add train edge; (U,S)->(V,S-A) and (V,S)->(U,S-A) cost B
    for(int s = A[i]; s <= maxs; ++s) {
      G[s*N+U[i]].emplace_back(B[i], (s-A[i])*N+V[i]);
      G[s*N+V[i]].emplace_back(B[i], (s-A[i])*N+U[i]);
    }
  }
  for(int i = 0; i < N; ++i) {
    // add exchange edge; (i,S)->(i,min(S+C, maxs)) cost D
    int C, D; std::cin >> C >> D;
    for(int s = 0; s < maxs; ++s) {
      G[s*N+i].emplace_back((int64_t)D, std::min(maxs, s+C)*N+i);
    }
  }

  dijkstra dj(G, INF);
  dj.search(std::min(maxs, S)*N);
  for(int i = 1; i < N; ++i) {
    int64_t ans = INF;
    for(int s = 0; s <= maxs; ++s) ans = std::min(ans, dj.d[i+N*s]);
    std::cout << ans << "\n";
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

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

int main(){
	ll n,m,l;cin>>n>>m;
	l=m;
	m-=2*n;
	if(m<0){
		ll cnt=0;
		while(l>1){
			l-=2;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	else{
		cout<<n+m/4<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
int main()
{
	int a,b,c;
	int n = 3;
	std::cin >> a >> b >> c;
	if(a==b) n--;
	if(a==c) n--;
	if(b==c) n--;
	if(a==b && a==c && b==c) n++;
	std::cout << n << std::endl;
	return 0;
}

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

typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    ll p,q,r,qwq[3];
    cin >> p >> q >> r;
    qwq[0]=p+q;
    qwq[1]=p+r;
    qwq[2]=q+r;
    sort(qwq+0,qwq+3);
    cout << qwq[0] << endl;
    //system("PAUSE");
    return 0;
}

Measured memory_bytes: 256
/*
問題D：異なる素数の和

・案
１、素数リストを作成し
２、動的計画法
n_max = 1120, k　<=　14
素数リストをはだいたい p=188
全探索するなら　p C k = 188 C 14 > 10^20

k = 1   | k = 2
--------|-------
n=4 p=2 | n = 6
n=3 p=3 | n = 6
n=1 p=5 | n = 6

異なる素数を扱うので扱った素数を記憶しておく
*/

#include <iostream>
#include <cstring> 
using namespace std;

int p[1130]; // primes
int prime_num;
int c[1121][15][188]; // メモ化

void calc_primes() {
  p[0] = 2;
  prime_num = 1;
  for (int i=3; i<=1120; i+=2) {
    bool add = true;
    for (int j=0; j<prime_num; j++) {
      if (p[j]*p[j] > i) { break; }
      if (i % p[j] == 0) {
        add = false;
        break;
      }
    }
    if (add) { p[prime_num++] = i; }
  }
}

int solve(int n, int k, int idx) {
  if (n == 0 && k == 0) {
    return 1;
  } else if (n == 0 || k == 0) {
    return 0;
  }
  if (c[n][k][idx] >= 0) { return c[n][k][idx]; }

  int cnt = 0;
  for (int i=idx; i<prime_num; i++) {
    if (p[i] > n) {
      break;
    } else {
      cnt += solve(n - p[i], k - 1, i+1);
    }
  }
  c[n][k][idx] = cnt;
  
  return cnt;
}

int main() {
  calc_primes();
//cout << pnum << endl;
//for (int i=0; i<pnum; i++) { cout << p[i] << ", "; }
  memset(c, -1, sizeof(c));
  
  int n, k;
  while (cin >> n >> k, (n || k)) {
    cout << solve(n, k, 0) << endl;
  }
  
  return 0;
}


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		cout << setprecision(12)<< ((n+1)/2)*1.0/n << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

int main(){
    int N;
    vector<int> A;
    cin >> N;
    A.resize(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    sort(A.begin(), A.end());
    long long ans = 0;
    
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            int a = A[i], b = A[j];
            int L = abs(a - b), R = a + b;
            
            int idxL = upper_bound(A.begin(), A.end(), L) - A.begin();
            int idxR = lower_bound(A.begin(), A.end(), R) - A.begin();
            if(idxR < idxL)continue;
            int res = idxR - idxL;
            if(idxL <= i && i <= idxR)res--;
            if(idxL <= j && j <= idxR)res--;
            ans += res;
        }
    }
    cout << ans / 3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
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; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int n,m;
    cin >> n >> m;
    if(n==m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
chomp(my $X = <>);

while (1) {
    if (is_prime($X)) {
        print "$X\n";
        last;
    }
    $X++;
}


sub is_prime {
    my $n = shift or die;
    for (2..$n/2) {
        return unless $n % $_;
    }
    return 1;
}


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

int main() {
  int h,w;
  cin >> h >> w;
  
  for(int i=0;i<w+2;i++){//1st line
    cout << "#" ;
  }
  cout << endl;
  
  for(int i=0;i<h;i++){
    vector<char> s(w);
    for(int j=0;j<w;j++){
      cin >> s.at(j);
    }
    cout << "#";
    for(int j=0;j<w;j++){
      cout <<s.at(j);
    }
    cout << "#" << endl;
  }
  
  for(int i=0;i<w+2;i++){//end line
    cout << "#" ;
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main() {
	char s[300], s1[150], t[150];
	cin >> s1 >> t;
	sprintf(s, "%s%s", s1, s1);
	int hantei = 0;
	for (int i = 0; i < strlen(s); i++) {
		for (int j = 0; j < strlen(t); j++) {
			if (s[i + j] != t[j]) {
				break;
			}
			if (j == strlen(t) - 1) {
				hantei = 1;
			}
		}
		if (hantei == 1) {
			break;
		}
	}
	if (hantei == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>

int main(void){
  int N, i, j;
  std::string W[100];
  scanf("%d", &N);
  std::cin >> W[0];
  for(i=1; i<N; ++i)
  {
  	std::cin >> W[i];
    if(W[i-1].back()!=W[i].front()){puts("No");return(0);}
    for(j=0; j<i; ++j){
    	if(W[j]==W[i]){puts("No");return(0);}
    }
  }
  puts("Yes");
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
typedef long long ll;

int main() {
  ll a;
  double b;
  cin >> a >> b;
  ll bb = round(b * 100);
  cout << (a * bb)/100 << "\n";
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
#define BOOST        ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define AZ(x)        x.begin(),x.end()
#define fi           first
#define se           second
#define pb           push_back
#define emp          emplace_back
#define mp           make_pair
#define mt           make_tuple
#define debug(x)     cerr << #x << " : " << x << endl;


template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;

typedef long long ll;
typedef long double ld;


template<typename T>
// for super_map add a parameter Y above and replace "null_type" with "Y"

// set with two additional super powers
    // find_by_order(int k) - returns k'th smallest element (0-indexed)
    // order_of_key(int k) - returns number of elements strictly smaller than k.
using super_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


const int mod=1e9+7,N=1e5+5;
const ll INF = 1e18;



ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}

ll super_rand(ll n) // Random number from set [0,n-1]
{
    uniform_int_distribution<ll> uid(0, n - 1);
    return uid(rng);
}



/*

1. Make sure you're taking all the inputs.
2. In case of nested loops, remember to use different variables.
3. If in doubt, do int -> ll
4. Don't fight the question, try solving the next one.
5. ffs (positon of first set bit), clz (leading 0s, max->32), ctz (trailing 0s), popcount (set bits). Don't use any of these on 0;
*/



//  Don't code anything above this //

    
int main() 
{ 
    BOOST

    int a,b;

    cin>>a>>b;

    cout<<max({a+b,a-b,a*b})<<"\n";
    
    return 0;    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    double a;
    cin >> a ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    //Sunny, Cloudy, Rainy
    /*
    if( a < 10 && b < 10 ){
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
    //*/
    
    cout << 2 * M_PI * a << endl;
    
    //printf("%lf\n", ((a / 2 + a % 2) / a));

    return 0; 
}


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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;

int dp[3005][3005];
string s1, s2;

int kil(int idx1, int idx2)
{
  if(idx1 == s1.length() || idx2 == s2.length())
    return 0;

  if(dp[idx1][idx2] != -1)
    return dp[idx1][idx2];

  if(s1[idx1] == s2[idx2])
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1+1, idx2+1) + 1);
  else
  {
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1, idx2+1));
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1+1, idx2));
  }
  return dp[idx1][idx2];
}


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

  string res="";

  memset(dp, -1, sizeof dp);
  cin>>s1>>s2;

  // recursive
  // kil(0, 0);

  // iterative
  memset(dp, 0, sizeof dp);

  for(int idx1 = s1.length()-1; idx1>=0; idx1--)
    for(int idx2 = s2.length()-1; idx2>=0; idx2--)
    {
      if(s1[idx1] == s2[idx2])
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1+1][idx2+1] + 1);
      else
      {
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1][idx2+1]);
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1+1][idx2]);
      }
    }



  int idx1=0, idx2=0;

  while(idx1 != s1.length() && idx2 != s2.length())
  {
    if(s1[idx1] == s2[idx2])
    {
      res += s1[idx1];
      idx1 += 1;
      idx2 += 1;
    }
    else
    {
      if(dp[idx1][idx2] == dp[idx1+1][idx2])
        idx1 += 1;
      else
        idx2 += 1;
    }
  }

  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 35584
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
int main() {
  int n,m;
  cin >> n>>m;
  vector<vector<int>> vec(m);//2次元配列を宣言
  for(int i=0;i<m;i++){
    int k; cin >> k;
    vec[i].resize(k);  //kに応じて配列の大きさを確保
    for(int j=0;j<k;j++){
      cin >> vec[i][j];  //素直に入力
      vec[i][j]--;  //スイッチは0から始まるので引いておくとあとでやりやすい
    }
  }
  vector<int> p(m);
  for(int i=0;i<m;i++){
    cin >> p[i];  //スイッチの条件の配列を取得１
  }
  int ans=0;
  int snum;
  for (int bit = 0; bit < (1<<n); ++bit){  //bit全探索ですね!!
    bool ok=true;  //すべての電灯が光っているとき条件を満たす
    for(int i=0;i<m;i++){
      snum=0;  //スイッチのカウント
      for(int id:vec[i]){
        if ((bit >> id) & 1) { //本質的にはif (i & (1<<id))と同じ
		  ++snum;
	    }
      }
      snum%=2;
      if(snum!=p[i]){
        ok=false;
      }
    }
    if(ok){
      ans++;
    }
  }
  cout << ans << endl; //素直に出力
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r;
	cin >> r;
	if(r < 1200) cout << "ABC" << endl;
	else if(r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}


Measured memory_bytes: 3628
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll n ; 
    cin >> n ; 
    ll cnt = 0 ; 
    ll sum = 0 ; 
    ll nax = 1e9 + 10 ; 
    for(ll i=0;i<n;i++){
    	ll x ; 
    	cin >> x ; 
    	if ( x < 0 ) cnt++ ; 
    	sum += abs(x) ;
    	nax = min(nax,abs(x));
    }
    if ( cnt & 1 ) sum -= 2*nax ; 
    cout << sum << endl;
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

void fillvec(vector<int> &a, int s, int k){
    int n = a.size();
    REP(i, k){
        a[i] = i + s;
    }
    REP(i, n - k){
        a[i + k] = n - 1 - i + s;
    }
}

signed main(){

    int N, A, B;
    cin >> N >> A >> B;

    if(A * B < N || A + B > N + 1){
        cout << -1;
        return 0;
    }

    vector< vector<int> > a(N / B + min((int)1, N % B));
    REP(i, N / B){
        a[i] = vector<int>(B);
    }
    if(N % B > 0) a[N / B] = vector<int>(N % B);

    A -= a.size();

    fillvec(a[0], 0, 0);
    FOR(i, 1, a.size()){
        fillvec(a[i], i * B, min(A, B - 1));
        A -= min(A, B - 1);
    }

    REP(i, a.size()){
        REP(j, a[i].size()){
            cout << a[i][j] + 1 << " ";
        }
    }

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define int long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------ILB----------------------------------------------------------------  //

//3 4 3,  4 3 3, 3 3 4, 5 5, 4 6, 6 4, 3 7, 7 3




void solve(){
	int n;
    cin >> n;
    vector<int> v(2001);
    v[0] = 1;
    int x = 0;
    for(int i = 1;i < 2001;i++){
         if(i - 3 >= 0){
               x += v[i - 3];
               x %= 1000000007;
         }
         v[i] = x;
    }
    cout << v[n] << endl;
}




int32_t main() {
	fast_io;
    int t = 1;
    //cin >> t;
    //int xx = 0
    while(t--) {
		//xx++;
		//cout << "Case ";
      solve();
    }
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        p[i]={b[i],a[i]};
    }
    sort(a,a+n);
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(int i=0;i<n-1;i++){
        if(b[i]>=a[i+1]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    sort(p,p+n);
    pair<int,int> aa[n];
    for(int i=0;i<n;i++){
        aa[i]={p[i].second,i};
    }
    sort(aa,aa+n);
    int to[n];
    for(int i=0;i<n;i++){
        to[aa[i].second]=i;
    }
    int now=0;
    bool seen[n]={};
    while(true){
        seen[now]=true;
        if(seen[to[now]])break;
        now=to[now];
    }
    for(int i=0;i<n;i++){
        if(!seen[i]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll sides[3];
  while (cin >> sides[0] >> sides[1] >> sides[2]) {
    ll res = 1ll << 62;
    for (int i = 0; i < 3; i++) {
      ll a = sides[i] / 2;
      ll b = sides[i] - a;
      ll p = 1;
      for (int j = 0; j < 3; j++) {
        if (j != i) p *= sides[j];
      }
      res = min(res, p * abs(a - b));
    }
    cout << res << endl;
  }
  return 0;
}


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

int main() {
	int N = 10010;
	vector<int> vec(N);
	int n;
	cin >> n;
	for(int i=1; i*i<N; i++){
		for(int j=1; j*j<N; j++){
			for(int k=1; k*k<N; k++){
				int a = i*i + j*j + k*k;
				int b = i*j + j*k + k*i;
				if(a+b >= N) break;

				vec.at(a+b)++;
			}
		}
	}

	for(int i=1; i<n+1; i++){
		cout << vec.at(i) << endl;
	}
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define MAX_N 200005

ll factorial[MAX_N];
void make_factorial_tableMOD(){
    factorial[0] = 1;
    for(int i = 1; i < MAX_N; i++){
        factorial[i] = factorial[i-1]*i%MOD;
    }
}

ll bisection_powerMOD(ll x,ll y){
    if(y==0)        { return 1; }
    ll t = bisection_powerMOD(x*x%MOD,y/2);
    if(y%2==1)      { t = t*x%MOD; }
    return t;
}

ll nCrMOD(int n, int r){
    ll a = factorial[n];
    ll b = a*bisection_powerMOD(factorial[r],(MOD-2))%MOD;
    ll c = b*bisection_powerMOD(factorial[n-r],MOD-2)%MOD;
    return c % MOD;
}

int main(){
    ll n, m;
    cin >> n >> m;
    map<int,int> mp;
    for(int i = 2; i <= m; i++){
        while(m%i==0){
            m /= i;
            mp[i]++;
        }
    }

    make_factorial_tableMOD();
    ll ans = 1;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        ans *= nCrMOD((itr->second)+n-1,(itr->second));
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int A, B;
    cin >> A >> B;
    if (8>= A && 8 >= B){
        cout << "Yay!" << endl;
    }
    else cout << ":(" << endl;
}

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

int main() {
  string T;
  cin >> T;
  for (int i = 0; i < T.size(); i++) {
    if (T.at(i) == '?') cout << 'D';
    else cout << T.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 3748
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  int x[N],y[M];
  for(int i=0;i<N;i++) cin >> x[i];
  for(int i=0;i<M;i++) cin >> y[i];

  sort(x,x+N);
  sort(y,y+M);

  if(x[N-1]<y[0]){
    if(y[0]<=X || x[N-1]>=Y){
      cout << "War" << endl;
    }else{
      cout << "No War" << endl;
    }
  }else{
    cout << "War" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def examA():
    N, A, B = LI()
    ansmin = max(0,A+B-N)
    ansmax = min(A,B)
    print(ansmax,ansmin)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()


Measured memory_bytes: 38384
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

template<typename T>
class BIT{
private:
	int n;
	T* dat;
	T init;
public:
	BIT(int x){
		n = x;
		init = 0; //書き換えする
		dat = new T[n+1];
		for(int i = 0; i < n+1; i++){
			dat[i] = init;
		}
		return;
	}

	~BIT(){
		delete[] dat;
	}

	inline T func(T x, T y){
		return x+y; //書き換えする
	}

	T query(int i){ //[0,i)へのクエリ
		T s = 0;
		while(i > 0){
			s = func(s, dat[i]);
			i -= i&-i;
		}
		return s;
	}

	void add(int i, int x){
		i++;
		while(i <= n){
			dat[i] = func(dat[i],x);
			i += i & -i;
		}
	}
};

int main()
{
	ios_init();
	int n;
	LL k;
	while(cin >> n >> k) {
		vector<LL> a(n);
		REP(i,n) cin >> a[i];
		vector<LL> imos(n+1);
		REP(i,n){
			imos[i+1] = imos[i]+a[i]-k;
		}

		auto za = imos;
		sort(ALL(za));
		za.erase(unique(ALL(za)),za.end());
		LL ans = 0;
		BIT<int> bit(SZ(imos)+1);
		{
			int p = lower_bound(ALL(za),imos[0])-za.begin();
			bit.add(p,1);
		}
		REP(i,n){
			int p = lower_bound(ALL(za),imos[i+1])-za.begin();
			ans += bit.query(p+1);
			bit.add(p,1);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 5760
D = gets.to_i
C = gets.chomp.split.map(&:to_i)
s = D.times.map{gets.split.map(&:to_i)}
c = Array.new(26, 0)
t = []

(0..D-1).each do |i|

  (0..25).each do |l|
    c[l] += C[l]
  end
ans = 0
boder = s[i][0]+9*c[0]

  (1..25).each do |e|
    if s[i][e]+9*c[e] >= boder
      ans = e
      boder = s[i][e]+9*c[e]
    end
  end
c[ans] = 0
puts ans+1
end


  



Measured memory_bytes: 14280
import java.util.*;
import java.io.*;

public class Main
{
  	int p, q, r;
  
    Main(Scanner in, PrintWriter out)
    {
    	p = in.nextInt();
      	q = in.nextInt();
      	r = in.nextInt();
      	out.println(Math.min(p+q, Math.min(q+r, r+p)));
    }
	
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		new	Main(in, out);
		out.close();
	} 
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n-1);
	vl ans(n);
	REP(i, n){
		ans[i] = 0;
	}
	for(ll i = 2; i <= n; i++){
		cin >> a[i-2];//a[n-2]まで
		ans[a[i-2]-1]++;
	}
	REP(i, n){
		cout << ans[i] << endl;
	}

	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    ll A,B; cin >> A >> B;
    if(A%2==0 && B%2!=0){
        if((B-A+1)%4 == 0){
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
    }else if(A%2==0 && B%2==0){
        if((B-A)%4 == 0){
            cout << B << endl;
        }else{
            cout << (B^1) << endl;
        }
    }else if(A%2!=0 && B%2!=0){
        if((B-A)%4 == 0){
            cout << A << endl;
        }else{
            cout << (A^1) << endl;
        }
    }else if(A%2!=0 && B%2==0){
        if((B-A-1)%4 == 0){
            cout << (A^B) << endl;
        }else{
            cout << ((A^B)^1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
using namespace std;
int main(){
	int A[6] = {1, 10, 9, 12, 3, 4}; 
	string S; cin >> S; int N = S.size(); 
	reverse(S.begin(), S.end()); 
	long long int dp[100010][14] = {}; 
	long long int P = 1e9 + 7; 
	dp[0][0] = 1; 
	for(int i = 0; i < N; i++){
		if(S.at(i) == '?'){
			for(int j = 0; j < 13; j++){
				for(int k = 0; k < 10; k++){
					dp[i+1][(j + k * A[i % 6]) % 13] += dp[i][j]; 
					dp[i+1][(j + k * A[i % 6]) % 13] %= P; 
				}
			}
		}
		else{
			int D = S.at(i) - '0'; 
			for(int j = 0; j < 13; j++){
				dp[i+1][(j + D * A[i % 6]) % 13] += dp[i][j]; 
				dp[i+1][(j + D * A[i % 6]) % 13] %= P; 
			}
		}
	}
	cout << dp[N][5] << endl; 
}

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

int main(){
  string s;
  cin >>s;
  
  if(s[2]==s[3] && s[4]==s[5]){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
using pl = pair<ll,ll>;
#define ci(n,a)   ll a[n]; rep(i,(n)) cin>>a[i];
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define mp(a,b)   make_pair(a,b)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(int argc,char* argv[]) 
{
    ll n,sum=0;
    cin>>n;
    ll a[n+2];
    a[0]=a[n+1]=0;
    rep(i,n){
        cin>>a[i+1];
        sum+=abs(a[i+1]-a[i]);
    }
    sum+=abs(a[n+1]-a[n]);
    rep(i,n)cout<<sum-abs(a[i]-a[i+1])-abs(a[i+2]-a[i+1])+abs(a[i]-a[i+2])<<endl;
    
    return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
main()
{
  int data[100],count[100]={0},i=0,c,top=0;

  while(scanf("%d",&data[i])!=EOF){
    i++;
  }


  for(c=0;c<i;c++){
    count[data[c]]++;
  }
 
  for(c=0;c<i;c++){
    if(top<count[c]){
      top=count[c];
    }
  }
 
  for(c=0;c<i;c++){
    if(top==count[c]){
      printf("%d\n",c);
    }
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;

int main() {
 string s;
 cin>>s;
 int count0=0,count1=0;
 for(int i=0;i<s.size();i++){
   if(s[i]=='0'){count0++;}
   else{count1++;}
 }
 cout<<min(count0,count1)*2<<endl;
return 0;
} 

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
from collections import deque

nn = 200200
mod = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
inv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % mod
for i in range(1, nn)[::-1]:
    inv[i] = fainv[i] * fa[i-1]

C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a-b] % mod if 0 <= b <= a else 0

N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

BU = [1] * N
TD = [1] * N
SI = [1] * N
for i in R[::-1]:
    a = 1
    s = 1
    for j in X[i]:
        a = a * BU[j] % mod
        s += SI[j]
    SI[i] = s
    BU[i] = inv[s] * a % mod

for i in R:
    c = len(X[i])
    AL = [1] * (c + 1)
    AR = [1] * (c + 1)
    for k, j in enumerate(X[i]):
        AL[k+1] = AL[k] * BU[j] % mod
    for k in range(c-1, 0, -1):
        j = X[i][k]
        AR[k] = AR[k+1] * BU[j] % mod
    for k, j in enumerate(X[i]):
        TD[j] = TD[i] * AL[k] % mod * AR[k+1] % mod * inv[N - SI[j]] % mod

print(*[BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N-1, SI[i] - 1) % mod for i in range(N)], sep = "\n")

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
int main(){
    ll n;
    cin >> n;
    ll ans=0;
    sqrep(i, 1, n){
        if(n%i==0){
            ll a = i;
            ll m = n/i -1;
            if(m>a)ans += m;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b == c || a + c == b || b + c == a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;


int board[2010][2010];
signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K; cin >> N >> K;
    int sum = 0, white = 0;
    for(int i = 0; i < N; i++){
        int x,y; char c; cin >> x >> y >> c;
        x %= 2 * K;
        y %= 2 * K;
        if(c == 'B') {
            board[x+1][y+1]++;
            sum++;
        }
        else{
            board[x+1][y+1]--;
            sum--;
            white++;
        }
    }

    for(int i = 1; i <= 2*K; i++){
        for(int j = 1; j <= 2*K; j++){
            board[i][j] += board[i][j-1];
        }
    }
    for(int j = 1; j <= 2*K; j++){
        for(int i = 1; i <= 2*K;i++){
            board[i][j] += board[i-1][j];
        }
    }
    int ma = -INF;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            int a = board[i][j];
            int b = board[i+K][j+K] - board[i+K][j] - board[i][j+K] + board[i][j];
            int c = board[2*K][j] - board[i+K][j];
            int d = board[i][2*K] - board[i][j+K];
            int e = board[2*K][2*K] - board[2*K][j+K] - board[i+K][2*K] + board[i+K][j+K];
            int tmp = a+b+c+d+e;
            ma = max(ma,max(tmp,sum-tmp));
        }
    }
    ma += white;
    cout << ma << endl;

}

Measured memory_bytes: 16000
#include <stdio.h>

int main() {
    int dia, n;
    scanf("%d %d", &dia, &n);
    
    int vec[n], total = 0;
    
    for (int i = 0; i < n; ++i){
        scanf("%d", &vec[i]);
        total += vec[i];
    }
    if (dia - total >= 0)
        printf("%d\n", dia - total);
    else
        printf("-1\n");
    return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <stdlib.h>
#include<algorithm> 
#include<functional>

using namespace std;

int main() {
	int n;
	int a[200010];
	long bi[200010];
	int bc;
	long sad;
	int i;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		bi[i] = a[i] - (i + 1);
	}

	sort(bi, bi + n, greater<>());

	/*if (n % 2 == 0) {
		bc = (bi[n / 2] + bi[n/2-1])/2;
	}
	else {
		bc = bi[n / 2];
	}*/
	bc = bi[n/2];
	sad = 0;
	for (i = 0; i < n; i++) {
		sad += abs(bi[i] - bc);
	}


	cout << sad << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e6+3;

ll d1[1001000],d2[1001000];

ll mult(ll n,ll m){//n^m%modを求める
    if(m==1){
        return n%mod;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%mod;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%mod;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin>>q;
    d1[0]=1;
    d2[0]=1;
    FOR(i,1,1000011){
      d1[i]=d1[i-1]*i;
      d1[i]%=mod;
      d2[i]=mult(d1[i],mod-2);
    }
    rep(i,q){
      ll x,d,n;
      cin>>x>>d>>n;
      if(d==0){
        cout<<mult(x,n)<<endl;
        continue;
      }
      ll ans=mult(d,n);
      ll a=x*mult(d,mod-2);
      a%=mod;
      ll b=a-1;
      a+=n-1;
      if(a/mod>=1) ans=0;
      else{
        a%=mod;
        (ans*=d1[a])%=mod;
        (ans*=d2[b])%=mod;
      }
      cout<<ans<<endl;
    }
}

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

int main(){
  vector<int> a(3); cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(), a.end());
  
  cout << a.at(2)*10+a.at(1)+a.at(0) << endl;
}


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

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

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    } else if (s == "Rainy") {
        cout << "Sunny" << endl;
    }

    return 0;
}


Measured memory_bytes: 256