akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while ( 1 ) {
    if ( cur == nil ) break;
    if ( isf++ > 0 ) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

Node* listSearch(int key) {
  Node *cur = nil->next;
  while ( cur != nil && cur->key != key )
    cur = cur->next;
  return cur;
}

void deleteNode(Node *t) {
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ) {
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) insert(key);
    else if ( strlen(com) == 6 ) deleteKey(key);
    else if ( com[6] == 'F' ) deleteFirst();
    else deleteLast();
  }

  printList();

  return 0;
}


Measured memory_bytes: 33988
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll             long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
const ll mx = 1e5;
void solve(int test)
{
    int n;
    string s;
    cin>>s;
    n = s.size();
    int count = 0,mxc = 0;
    forn(i,0,n)
    {
        if(s[i]=='R')   count++;
        else
        {
            mxc = max(mxc ,count);
            count = 0;
        }
    }
    mxc = max(count,mxc);
    cout<<mxc<<endl;
}
int32_t main()
{
    ioS    
    int t;
    // cin>>t;
    // forn(i,1,t+1)
        solve(0);
}



Measured memory_bytes: 3648
#include<cstdio>
int digit0b(int x){
    int ans=0;
    while(x>0){
        ans++;
        x/=2;
    }
    return ans;
}
int numofbits(int x){
    int ans=0;
    while(x>0){
        if(x%2==1)ans++;
        x/=2;
    }
    return ans;
}
int lowestbit(int x){
    return x&-x;
}
int main(){
    int l;
    scanf("%d",&l);
    int n=digit0b(l),m=2*(n-1)+numofbits(l)-1;
    printf("%d %d\n",n,m);
    for(int i=0;i<=n-2;i++){
        printf("%d %d %d\n",i+1,i+2,1<<i);
        printf("%d %d %d\n",i+1,i+2,0);
    }
    for(int i=l;i>(1<<(n-1));i-=lowestbit(i)){
        printf("%d %d %d\n",digit0b(lowestbit(i)),n,i-lowestbit(i));
    }
    return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  vector<vector<int>> m(h, vector<int>(w));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> m[i][j];
    }
  }

  vector<array<int, 4>> ans;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w - 1; ++j) {
      if (m[i][j] % 2 == 0) {
        continue;
      }

      m[i][j]--;
      m[i][j + 1]++;
      ans.push_back({i + 1, j + 1, i + 1, j + 2});
    }
  }

  for (int i = 0; i < h - 1; ++i) {
    if (m[i][w - 1] % 2 == 0) {
      continue;
    }

    m[i][w - 1]--;
    m[i + 1][w - 1]++;
    ans.push_back({i + 1, w, i + 2, w});
  }

  cout << ans.size() << '\n';
  for (auto &a : ans) {
    cout << a[0] << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] << '\n';
  }
  return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	int buf = n % 10;
	if (buf == 3)cout << "bon" << endl;
	else if (buf == 0 || buf == 1 || buf == 6 || buf == 8)cout << "pon" << endl;
	else cout << "hon" << endl;
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi v(N);
    rep(i,N) {
        v.at(i)=i+1;
    }
    vi P(N),Q(N);
    rep(i,N) cin>>P.at(i);
    rep(i,N) cin>>Q.at(i);
    int a=1, b=1;
    do {
        if(v==P) break;
        a++;
    } while(next_permutation(all(v)));
    sort(all(v));
    do {
        if(v==Q) break;
        b++;
    } while(next_permutation(all(v)));
    cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
    int S, h,m,s;
    scanf("%d", &S);
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int,int> P;
const int MOD = 998244353;
const ll mod = 1e9 + 7;
const int mxN = 1e6 + 9;


int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int cnt_w = 0;
    for(int i=0; i < n; i++){
        if( s[i] == 'W' ) ++cnt_w;
    }
    if( cnt_w == 0 || cnt_w == n ) cout << 0;
    else{
        int ans = 0;
        int ptr = n-1;
        while( cnt_w-- ){
            if( s[ptr] == 'R' ) ++ans;
            --ptr;
        }
        cout << ans;
    }

}




Measured memory_bytes: 3772
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line;
        
        while(true) {
            int count = 0;
            try {
                line = sc.nextLine();
            }catch(Exception e) {
                break;
            }
            int n = Integer.parseInt(line);
            if(n > 36) {
                System.out.println(0);
                continue;
            }
            for(int i = 0; i < 10; i++) {
                for(int j = 0; j < 10; j++) {
                    for(int k = 0; k < 10; k++) {
                        for(int l = 0; l < 10; l++) {
                            if(i + j + k + l == n) {
                                count++;
                            }
                            if(i + j + k > n) {
                                break;
                            }
                        }                        
                    }
                }
            }
            System.out.println(count);
        }
        
    }
 } 


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

using namespace std;

typedef long long ll;

const int MAXN = 100;
// t -> t*2
const int MAXTT = 200*100*2;
const double INF = 1e9;

double sumtt[MAXN + 1];
vector<double> points[MAXTT + 1];

double minpoint(int ti){
  double minp = INF;
  for(auto p: points[ti]){
    minp = min(minp, p);
  }
  return minp;
}

void plot_points(double s, double t, double v){
  for(int i=s;i<=t;i++) points[i].push_back(v);
  for(int i=s-1;i>=0;i--) points[i].push_back(v + ((double)(s-i))*0.5);
  for(int i=t+1;i<=MAXTT;i++) points[i].push_back(v + ((double)(i-t))*0.5);
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  double t[N], v[N];
  sumtt[0] = 0;
  for(int i=0;i<N;i++){
    cin >> t[i];
    sumtt[i+1] = sumtt[i] + t[i]*2;
  }
  for(int i=0;i<N;i++) cin >> v[i];
  plot_points(sumtt[0], sumtt[0], 0);
  for(int i=0;i<=N-1;i++){
    plot_points(sumtt[i], sumtt[i+1], v[i]);
  }
  plot_points(sumtt[N], sumtt[N], 0);
  double sum = 0;
  // calculate areasize ti to ti+1
  for(int ti=0;ti<=sumtt[N]-1;ti++){
    /*
    for(int i=0;i<points[ti].size();i++) cout << points[ti][i] << " ";
    cout << minpoint(ti) << endl;
    */
    sum += 0.25*(minpoint(ti) + minpoint(ti+1));
  }
  cout << setprecision(10) << sum << endl;
}

Measured memory_bytes: 42240
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int x;
   cin >> x;
   if(x>=30) {
      cout << "Yes" << endl;
      return 0;
   }
   cout << "No" << endl;
}

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

using ll = long long;

#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 pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N, X; cin >> N >> X;
	ll n2 = 2*N-1;
	if (N == 1) {
		cout << "Yes" << endl;
		cout << 1 << endl;
	} else if (N == 2 and X == 2) {
		cout << "Yes" << endl;
		cout << 1 << endl << 2 << endl << 3 << endl;
	} else if (X == 1 or X == n2) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
		set<ll> cs;
		REP(i, n2) cs.insert(i + 1);
		vector<ll> out(n2);
		out[N-1] = X; cs.erase(X);
		if (X == 2) {
			out[N-2] = X+1; cs.erase(X+1);
			out[N] = X-1; cs.erase(X-1);
			out[N+1] = X+2; cs.erase(X+2);
		} else {
			out[N-2] = X-1; cs.erase(X-1);
			out[N] = X+1; cs.erase(X+1);
			out[N+1] = X-2; cs.erase(X-2);
		}
		int idx = 0;
		for (auto c : cs) {
			if (idx >= n2) continue;
			out[idx] = c;
			idx++;
			if (idx == N-2) {
				idx = N + 2;
			}
		}
		REP(i, n2) {
			cout << out[i] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 13312
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = unsigned long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in(), m = in();

    vector<ll>a(n);
    REP(i, n)scanf("%lld", &a[i]);
    sort(ALL(a));

    vector<pair<ll, ll>>bc(m);
    REP(i, m) {
        ll b = in(), c = in();
        bc[i] = make_pair(c, b);
    }
    sort(ALL(bc), greater<pair<ll, ll>>());

    ll inow = 0;
    ll ans = 0;
    REP(i, m) {
        ll b = bc[i].second, c = bc[i].first;
        for (ll j = inow; j < min(inow + b, n); ++j) {
            ans += max(a[j], c);
        }
        inow += b;
    }
    for (ll j = inow; j < n; ++j)ans += a[j];

    cout << ans << endl;
}

Measured memory_bytes: 2560
//confilm 0LL and 1LL
//confilm cornercase such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, a;
	cin >> n;
	ll mini = LINF;
	rep(i, 5){
		cin >> a;
		chmin(mini, a);
	}
	ll ans = n/mini+5;
	if(n%mini == 0) ans--;
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int h, w;
    cin >> h >> w;
    pair<int, int> s;
    int ch, cw;
    cin >> ch >> cw;
    --ch, --cw;
    s = make_pair(ch, cw);
    pair<int, int> g;
    int dh, dw;
    cin >> dh >> dw;
    --dh, --dw;
    g = make_pair(dh, dw);
    vector<vector<char>> hw(h, vector<char>(w));
    rep(i, h) rep(j, w) {
        cin >> hw[i][j];
    }
    //queue<pair<int, int>> que;
    deque<pair<int, int>> que;
    //que.push(s);
    que.push_back(s);
    vector<vector<int>> cnt(h, vector<int>(w, 1e8));
    cnt[s.first][s.second] = 0;
    int dy[4] = {0, 0, 1, -1};
    int dx[4] = {1, -1, 0, 0};
    while(!que.empty()) {
        //pair<int, int> now = que.front(); que.pop();
        pair<int, int> now = que.front(); que.pop_front();
        //cout << now.first << " " << now.second << endl;
        rep(ri, 4) {
            int y = now.first + dy[ri];
            int x = now.second + dx[ri];
            if (y < 0 || y >= h || x < 0 || x >= w) continue;
            if (hw[y][x] == '#') continue;
            if (cnt[y][x] > cnt[now.first][now.second]) {
                cnt[y][x] = cnt[now.first][now.second];
                que.push_front(make_pair(y, x));
            }
        }
        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                if (i == 0 && j == 0) continue;
                int y = now.first + i;
                int x = now.second + j;
                if (y < 0 || y >= h || x < 0 || x >= w) continue;
                if (hw[y][x] == '#') continue;
                //cout << "pretest" << endl;
                //if ((i == 1 && j == 0) || (i == -1 && j == 0) || (i == 0 && j == 1) || (i == 0 && j == -1)) {
                //    //cout << "pretest1" << endl;
                //    if (cnt[y][x] > cnt[now.first][now.second]) {
                //        //cout << "test1" << endl;
                //        cnt[y][x] = cnt[now.first][now.second];
                //        if (y == g.first && x == g.second) {
                //            break;
                //        }
                //        que.push(make_pair(y, x));
                //    }
                //}
                //else {
                    //cout << "pretest2" << endl;
                if (cnt[y][x] <= cnt[now.first][now.second]+1) continue;
                //cout << "test2" << endl;
                cnt[y][x] = cnt[now.first][now.second] + 1;
                //que.push(make_pair(y, x));
                que.push_back(make_pair(y, x));
                //}
            }
        }
    }
    //rep(i, h) {
    //    rep(j, w) cout << cnt[i][j] << " ";
    //    cout << endl;
    //}
    if (cnt[g.first][g.second] == 1e8) cout << -1 << endl;
    else                               cout << cnt[g.first][g.second] << endl;
    return 0;
}


Measured memory_bytes: 8688
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;
typedef pair<int, P> S;
int main(){
  int N;
  while(cin>>N && N){
    string ss, gs; cin>>ss>>gs;
    int St = 0, G = 0;
    REP(i, N){
      St |= (int)(ss[i] == 'B') << i;
      G |= (int)(gs[i] == 'B') << i;
    }
    priority_queue<S> que;
    int dist[1<<16][16];
    REP(i, 1<<N)REP(j, N) dist[i][j] = INF;
    REP(i, N){
      dist[St][i] = 0;
      que.push(S(0, P(St, i)));
    }
    while(!que.empty()){
      S s = que.top(); que.pop();
      int d = s.first * -1;
      int state = s.second.first;
      int u = s.second.second;
      if(state == G){
        cout<<d<<endl;
        break;
      }
      if(dist[state][u] < d) continue;
      REP(i, N){
        if(!((state ^ G) >> i & 1)) continue;
        REP(j, N)if((state >> i & 1) != (state >> j & 1)){
          int nst = state ^ (1 << i) ^ (1 << j);
          if(((nst ^ G) >> i & 1) && (nst ^ G) >> j & 1) continue;
          int nd = d + abs(i - u) + abs(j - i);
          int nu = j;
          if(dist[nst][nu] > nd){
            dist[nst][nu] = nd;
            que.push(S(nd * -1, P(nst, nu)));
          }
        }
      }
    }
  }
  return 0;
}

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

int main(void) {
  int N, L;
  cin >> N >> L;
  int ans;
  if (L > 0) {
    ans = (2 * L + N) * (N - 1) / 2;
  } else if (L + N - 1 < 0) {
    ans = (2 * L + N - 2) * (N - 1) / 2;
  } else {
    ans = (2 * L + N - 1) * N / 2;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iY = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "";
            int iM = iN + 1;
            int iG = 0;
            int iS = 0;
            Boolean bOk = false;
            for (int i = 0; i <= iN; i++)
            {
                iM -= 1;                                            // 万券
                iG = -1;
                for (int j = 0; j <= i; j++)
                {
                    iG += 1;                                        // 伍券
                    iS = iN - iM - iG;                              // 千券
                    if (iY == 10000 * iM + 5000 * iG + 1000 * iS) { bOk = true; break; }
                }
                if (bOk)
                {
                    break;
                }
            }
            if (bOk) { sOut = iM.ToString() + " " + iG.ToString() + " " + iS.ToString(); }
            else { sOut = "-1 -1 -1"; }

            // 出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
/* 
chirag11032000
Chirag Thakur
*/

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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

void testCase();

int main() {
	fastIo();
	testCase();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void testCase() {
	int n, a, b;
	cin >> n >> a >> b;
	int x = 0, y = 0, z = 0;
	for (int i = 0; i < n; ++i) {
		int temp;
		cin >> temp;
		x += (temp <= a);
		y += (temp > a && temp <= b);
		z += (temp > b);
	}
	cout << min({x, y, z}) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD 1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/
int solve(vector<int> v,vector<int>& P){  //v is passed by reference here;
    int ret = 0;
    while(v != P){
        next_permutation(ALL(v));
        ++ret;
    }
    return ret;
}

void solve(){  
   int N;
   cin>>N;
   vector<int> a(N);
   vector<int> b(N);
   cin>>a>>b;
   vector<int> v(N);
   REP(i,N){
       v[i]=i+1;
   }
   cout<< abs(solve(v,a) - solve(v,b))<<endl;  
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++){
			A[i] = sc.nextInt();
		}
		sort(A);
		long answer = 0;
		int l = N/2;
		for(int i=N-1; i>=l; i--){
			answer += A[i]*2;
		}
		for(int i=0; i<l; i++){
			answer -= A[i]*2;
		}
		if(N%2==0){
			answer += A[l-1];
			answer -= A[l];
		}else{
			if(A[l-1]+A[l+1] > A[l]*2){
				answer += A[l-1];
				answer -= A[l]*3;
			}else{
				answer -= A[l]+A[l+1];
			}
		}
		System.out.println(answer);
		System.out.flush();
		return;
	}

	public static void sort(int[] a){
		quickSort(a, 0, a.length-1);
	}

	private static void quickSort(int[] a, int left, int right){
		if(left >= right){return;}
		int pivot = med3(a[left], a[left+(right-left)/2], a[right]);
		int l=left, r=right;
		while(true){
			while (a[l] < pivot){l++;}
			while (pivot < a[r]){r--;}
			if(l>=r){break;}
			int t=a[l]; a[l]=a[r]; a[r]=t;
			l++; r--;
		}
		quickSort(a, left, l-1);
		quickSort(a, r+1, right);
	}

	private static int med3(int x, int y, int z){
	    if(x < y){
	        if (y < z){return y;}else if(z < x){return x;}else{return z;}
	    } else {
	        if (z < y){return y;}else if(x < z){return x;}else{return z;}
	    }
	}
}

Measured memory_bytes: 51940
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
vector<string> b;
ll h,w;
vector<vector<ll>> dist;

bool isvm(ll r,ll c){
    //移動先を(r,c)とする
    if(r<0||r>=h||c<0||c>=w){
        return false;
    }
    if(b.at(r).at(c) == '#'){
        return false;
    }
    return true;
}


int main(){
    cin >> h >> w;
    b.resize(h);
    rep(i,h) cin >> b.at(i);

    dist.resize(h,vector<ll>(w,-1));

    queue<pair<ll,ll>> q;

    rep(i,h) rep(j,w){
        if(b.at(i).at(j)=='#'){
            q.push(make_pair(i,j));
            dist.at(i).at(j) = 0;
        }
    }

    ll ans = 0;

    while(q.size()){
        ll x = q.front().first;
        ll y = q.front().second;
        q.pop();
        ll now = dist.at(x).at(y);

        if(isvm(x+1,y)){
            dist.at(x+1).at(y) = now + 1;
            b.at(x+1).at(y) = '#';
            q.push(make_pair(x+1,y));
        }
        if(isvm(x,y+1)){
            dist.at(x).at(y+1) = now + 1;
            b.at(x).at(y+1) = '#';
            q.push(make_pair(x,y+1));
        }
        if(isvm(x-1,y)){
            dist.at(x-1).at(y) = now + 1;
            b.at(x-1).at(y) = '#';
            q.push(make_pair(x-1,y));
        }
        if(isvm(x,y-1)){
            dist.at(x).at(y-1) = now + 1;
            b.at(x).at(y-1) = '#';
            q.push(make_pair(x,y-1));
        }
        ans = max(ans,now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 25524
N=int(input())
A=[[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9]

for n in range(N+1):
    temp=str(n)
    r=int(temp[-1])
    l=int(temp[0])
    A[r-1][l-1]+=1

ans=0
for i in range(9):
    for j in range(9):
        ans+=A[i][j]*A[j][i]
if N<=9:
    print(N)
else:
    print(ans)


Measured memory_bytes: 3064
S = input()[::-1]
T = input()[::-1]

flag = False
for i in range(len(S) - len(T) + 1):
    matched = True

    for j in range(len(T)):
        # うーん...
        if i == len(S) - len(T) + 1:
            break

        if S[i + j] != "?" and S[i + j] != T[j]:
            matched = False
    
    if matched:
        S = S[:i] + T + S[i + len(T):]
        flag = True
        break

if flag:
    print(S.replace("?", "a")[::-1])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 9004
n, h = gets.chomp.split(" ").map(&:to_i)
a = []
b = []
n.times do |i|
  a[i], b[i] = gets.chomp.split(" ").map(&:to_i)
end

c = 0

a_max = a.max
b_sorted = b.sort.reverse
b_sorted.each do |x|
  break if x <= a_max
  h -= x
  c += 1
  break if h <= 0
end

if h > 0
  c += (h + a_max - 1)/ a_max
end

puts c


Measured memory_bytes: 5100
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n,m;
  cin >> n >> m;
  vector<LL> a(m);
  for(auto &x:a) cin >> x;
  vector<LL> good(n+2, 1);
  for(auto x:a) good[x]=0;
  vector<LL> dp(n+2, 0);
  dp[0] = 1;
  REP(i,n) {
    if(good[i]) {
      dp[i+1] += dp[i];
      dp[i+1] %= p;
      dp[i+2] += dp[i];
      dp[i+2] %= p;
    }
  }
  cout << dp[n] << endl;
  return 0;
}


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

int construct(int a){
	int temp = a/100 * 100;
	temp += temp/10;
	temp += temp/100;
	return temp;
}

int main(){
	int n;
	cin >> n;
	if(construct(n) < n)
		cout << construct(n+111);
	else
		cout << construct(n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define For(i,x,y)	for(ll i=x;i<=y;++i)
using namespace std;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct szb{	szb(){	freopen("shenzhebei.in","r",stdin);	}	}shenzhebei;
#endif
#define NEG 1
	const int L=2333333;
	char SZB[L],*S=SZB,*T=SZB;
	inline char gc(){	if (S==T){	T=(S=SZB)+fread(SZB,1,L,stdin);	if (S==T) return '\n';	}	return *S++;	}
#if NEG
	inline ll readint(){	ll x=0,f=1;	char ch=gc();	for (;!isdigit(ch);ch=gc())	if (ch=='-') f=-1;	for (;isdigit(ch);ch=gc())	x=x*10-48+ch;	return x*f;	}
	inline void write(ll x){	if (x<0)	putchar('-'),x=-x;	if (x>=10)	write(x/10);	putchar(x%10+'0');	}
#else
	inline ll readint(){	ll x=0;	char ch=gc();	for (;!isdigit(ch);ch=gc());	for (;isdigit(ch);ch=gc())	x=x*10-48+ch;	return x;	}
	inline void write(ll x){	if (x>=10)	write(x/10);	putchar(x%10+'0');	}
#endif
	inline char readchar(){	char ch=gc();	for(;isspace(ch);ch=gc());	return ch;	}
	inline ll readstr(char *s){	char ch=gc();	int cur=0;	for(;isspace(ch);ch=gc());		for(;!isspace(ch);ch=gc())	s[cur++]=ch;	s[cur]='\0';	return cur;	}
	inline void writeln(ll x){	write(x);	puts("");	}
}using namespace SHENZHEBEI;
const ll N=310;
ll a[N][N],vis[N],sum[N],cho[N],n,m,ans,del[N];
int main(){
	n=readint();	m=readint();
	For(i,1,n)	For(j,1,m)	a[i][j]=readint();
	For(i,1,n)	cho[i]=1,ans=max(ans,++sum[a[i][1]]);
	while(1){
		ll c=0;
		For(i,1,m)	if (sum[i]>sum[c])	c=i;
		ans=min(ans,sum[c]);	del[c]=1;
		For(i,1,n){
			while(del[a[i][cho[i]]]){
				sum[a[i][cho[i]]]--;
				cho[i]++;
				sum[a[i][cho[i]]]++;
			}
			if (cho[i]>m)	return writeln(ans),0;
		}
	}
	writeln(ans);
}

Measured memory_bytes: 1280
N = int(input())
s = input()
hist = [(0, 0)]
max_dist = 0
for v in s:
    x, y = hist[-1]
    if v == "(": x += 1
    elif v == ")": y += 1
    hist.append((x,y))
    max_dist = max(y - x, max_dist)
lastx , lasty = hist[-1]
print ("(" * max_dist + s + ")" *(lastx - lasty + max_dist))



Measured memory_bytes: 3060
N, M = map(int, input().split())
AB = [None] * N
for _ in range(N):
    AB[_] = list(map(int, input().split()))

AB.sort()

cart = 0
price = 0
j = 0
for i in range(N):
    if cart + AB[i][1] > M:
        j = i
        break
    cart += AB[i][1]
    price += AB[i][0] * AB[i][1]

price += (M - cart) * AB[j][0]
print(price)


Measured memory_bytes: 55384
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}
struct node{
  int parent;
  int right;
  int left;
  int sibling;
};

int countDegree(node* n){
  int cnt=0;

  if(n->right != -1){cnt++;}
  if(n->left  != -1){cnt++;}
  
  return cnt;

}

int getDepth(int id,vector<node>* nodes){
  int depth = 0;
  id = nodes->at(id).parent;  
  while(id != -1){
    id = nodes->at(id).parent;
    depth++;
  }
  return depth;
}

int getHeight(int id,vector<node>* nodes){
  int h1 = 0,h2 = 0;
  h1 = 0;
  h2 = 0;

  if(nodes->at(id).left != -1){
    h1 = getHeight(nodes->at(id).left,nodes) + 1;
  }
  if(nodes->at(id).right != -1){
    h2 = getHeight(nodes->at(id).right,nodes) + 1;
  }
  
  return max(h1,h2);
}

int main(){
  long ii,jj,kk;
  vector<int> a;
  vector<node> nodes;
  int n;
  cin >> n;
  nodes.resize(n);
  int id,left,right;

  for(ii=0;ii<n;ii++){
    nodes[ii].parent = -1;
    nodes[ii].sibling = -1;
  }
  
  for(ii=0;ii<n;ii++){
    cin >> id >> left >> right;

    nodes[id].left = left;
    nodes[id].right = right;

    if(left != -1){
      nodes[left].parent = id;
      nodes[left].sibling = right;
    }

    if(right != -1){
      nodes[right].sibling = left;
      nodes[right].parent = id;
    }
  }

  for(ii=0;ii<n;ii++){
    cout << "node " << ii << ":";
    cout << " parent = " << nodes[ii].parent;
    cout << ", sibling = " << nodes[ii].sibling;

    cout << ", degree = " << countDegree(&nodes[ii]);
    cout << ", depth = " << getDepth(ii,&nodes);
    cout << ", height = " << getHeight(ii,&nodes);
    
    cout << ", " ;
    if(nodes[ii].parent == -1){
      cout << "root";
    }
    else if(countDegree(&nodes[ii]) == 0){
      cout << "leaf";
    }
    else{
      cout << "internal node";
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
vector<int>v;
int q;
ll dp[200001];
int prv[200001];
int col[200001];
int main(){
	ios::sync_with_stdio(false);
	v.push_back(0);
	cin >> q;
	while(q--){
		int x;cin >> x;
		if(x==v.back()) continue;
		prv[v.size()]=col[x];
		col[x]=v.size();
		v.push_back(x);
	}
	dp[0]=1;
	for(int i=1; i<v.size() ;i++){
		dp[i]=dp[i-1];
		if(prv[i]!=0) dp[i]=(dp[i]+dp[prv[i]])%mod;
	}
	cout << dp[v.size()-1] << endl;
}

Measured memory_bytes: 4340
/*
 * FileName:     D_fix
 * CreatedDate:  2020-07-04 01:20:42 +0900
 * LastModified: 2020-07-04 02:02:44 +0900
 */

#include <stdio.h>
#include <stdlib.h>
int main(void){
    long int n, k;scanf("%ld%ld", &n, &k);
    long int *a = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)scanf("%ld", a+i);
    long int *order = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)order[i]=0;
    long int s = 1, cnt = 0;
    while(order[s]==0){
        order[s]=cnt++;
        s = a[s];
    }
    long int cycle = cnt-order[s];
    long int ini = cnt-cycle;
//    printf("%d,%d\n",ini,cycle);
    if(ini>k){
        for(long int i=0;i<n;i++){
            if(order[i]==k){
                printf("%ld\n",i);
                free(a);
                return 0;
            }
        }
    }
    long int cycle_gun = (k-ini)%cycle+ini;
    for(long int i=0;i<n+1;i++){
        if(order[i]==cycle_gun){
            printf("%ld\n",i);
        }
    }
    free(a);
    return 0;
}


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

int main()
{
    ll n,m;
    cin>>n>>m;
    ll ans;
    if(n < m)
    ans = ((n*2)+m)/4;
    else
    ans = m/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)



int main(){
    char S[100], T[100], C[200];
    int N;

    cin >> N;
    rep(i, N) cin >> S[i];
    rep(j, N) cin >> T[j];

    rep(k, N) {
        C[k*2] = S[k];
        C[k*2+1] = T[k];
    }

    rep(l, N*2) {
        cout << C[l];
    }
    cout << endl;

    return 0;

}

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

#define PP std::pair<int,int>

int N, M;
std::vector<int> D, T;
std::vector<PP> DD, TT;

int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		D.push_back(tmp);
	}
	std::cin >> M;
	for (int i = 0; i < M; i++) {
		int tmp;
		std::cin >> tmp;
		T.push_back(tmp);
	}

	std::sort(D.begin(), D.end());
	std::sort(T.begin(), T.end());
	PP DF = { D[0],1 };

	for (int i = 1; i < N; i++) {
		if (DF.first == D[i])DF.second++;
		else {
			DD.push_back(DF);
			DF = { D[i],1 };
		}
	}
	DD.push_back(DF);
	PP TF = { T[0],1 };
	for (int i = 1; i < M; i++) {
		if (TF.first == T[i])TF.second++;
		else {
			TT.push_back(TF);
			TF = { T[i],1 };
		}
	}
	TT.push_back(TF);
	for (int i = 0; i < (int)TT.size(); i++) {
		PP want = TT[i];
		int ub = DD.size() - 1;
		int lb = 0;
		while (ub - lb > 1) {
			int mid = (ub + lb)/2;
			if (DD[mid].first >= want.first) {
				ub = mid;
			}
			else {
				lb = mid;
			}
		}
		if (DD[lb].first == want.first&&DD[lb].second >= want.second) {
			continue;
		}
		else if (DD[ub].first == want.first&&DD[ub].second >= want.second) {
			continue;
		}
		else {
			std::cout << "NO" << std::endl;
			return 0;
		}
	}
	std::cout << "YES" << std::endl;
	return 0;
}

Measured memory_bytes: 6384
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine(string.Join("", Console.ReadLine().Select(x => (char)('A' + ((x - 'A') + n) % 26))));
    }
}

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

int main(){
  string S;
  int A,K;
  cin >> K >> S; 
  A=S.size();
  if(A<=K){
    cout << S << endl;
  }
  else{
    for(int i=0;i<K;i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
}

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

int main(){
	int n,q;	cin>>n>>q;
	char s[n];	for(int i=0;i<n;i++)cin>>s[i];

	int AC[n];	for(int i=0;i<n;i++)AC[i]=0;

	for(int l=1;l<n;l++){
		if(s[l-1]=='A' && s[l]=='C'){
			++AC[l];
		}
		AC[l+1]=AC[l];
	}

	//for(int i=0;i<n;i++)cout<<AC[i]<<endl;





	int l,r;
	int ans;
	for(int i=0;i<q;i++){
		cin>>l>>r;
		ans=0;

		cout<<AC[r-1]-AC[l-1]<<endl;

	}

	return 0;
}


Measured memory_bytes: 1280
import Control.Monad
import Data.Ord
import Data.List

main = do
  (n:w:_) <- getLine >>= return . map read . words :: IO [Int]
  dat <- getContents >>= return . map ((\(w:v:_) -> (w,v)) . map read . words) . lines :: IO [(Int,Int)]

  let
    w' = fst $ head dat
    f i = zip (iterate (+(w'+i)) 0) . scanl (+) 0 . reverse . sort . map snd . filter ((==w'+i) . fst)
    wv0 = f 0 dat
    wv1 = f 1 dat
    wv2 = f 2 dat
    wv3 = f 3 dat

  print $ maximum [v0+v1+v2+v3 | (w0,v0)<-wv0, (w1,v1)<-wv1, (w2,v2)<-wv2, (w3,v3)<-wv3, w0+w1+w2+w3<=w]


Measured memory_bytes: 2300
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  string s;
  cin >> s;
  if (s[1] == 'B') {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }

  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define pb			push_back
#define vi  		vector<int>
#define all(a)		(a).begin(),(a).end()
#define F 			first
#define S 			second
#define endl		"\n"
#define fast 		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int 		long long int
#define mod			1000000007
#define test		int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define PI 3.14159265

int n,m;
vi adj[100001];

void bfs(vi &dist,vector<bool> &vis,int src,vi &ans){
	vis[src]=true;
	queue<int>q;
	q.push(src);
	dist[src]=0;
	while(!q.empty()){
		int p=q.front();
		q.pop();
		for(auto node:adj[p]){
			if(!vis[node]){
				vis[node]=true;
				dist[node]=dist[p]+1;
				q.push(node);
				ans[node]=p;
			}
		}
	}
}
int32_t main(){

	cin>>n>>m;
	int u,v;
	for(int i=0;i<m;i++){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi dist(n+1);
	vi ans(n+1,0);
	vector<bool> vis(n+1,false);
	int flag=0;
	bfs(dist,vis,1,ans);
	for(int i=2;i<=n;i++){
		if(dist[i]==0){
			cout<<"No"<<endl;
			flag=1;
			break;
		}
	}
	if(flag==0)
	{
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++)
		{
			cout<<ans[i]<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 13604
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
e=[(int(input().split()[0]),list(map(int,input().split())))for _ in range(m)]
INF=10**18
dp=[INF]*2**n
dp[0]=0
for i in range(2**n):
    if dp[i]>=INF:continue
    for a,c in e:
        bit=i
        for j in c:
            bit|=2**(n-j)
        dp[bit]=min(dp[bit],dp[i]+a)
a=dp[-1]
if a>=INF:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 43884
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    if (n == 1) {
        cout << a[0];
        return 0;
    }


    int pre[n], post[n];
    pre[0] = a[0], post[n - 1] = a[n - 1];
    for (int i = 1; i < n; i++) {
        pre[i] = __gcd(pre[i - 1], a[i]);
    }

    for (int i = n - 2; i >= 0; i--) {
        post[i] = __gcd(a[i], post[i + 1]);
    }

    int ans = max(pre[n - 2], post[1]);
    for (int i = 1; i < n - 1; i++) {
        ans = max(ans, __gcd(pre[i - 1], post[i + 1]));
    }

    cout << ans;




}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = (a); i <= (b); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 105;
int n, m, mem[MX][MX][2 * MX];
char a[MX][MX];

int dp (int i, int j, int k) {
	if (i == n || j == m || k < 0) return 1e9;

	if (i == n - 1 && j == m - 1) {
		if ((a[i][j] == '.') ^ (k % 2 == 1)) return 0;
		if (k) return 0;
		return 1;
	}

	int &res = mem[i][j][k];
	if (res != -1) return res;

	if ((a[i][j] == '.') ^ (k % 2 == 0)) {
		res = min({
			dp(i + 1, j, k - 1),
			dp(i, j + 1, k - 1),
			dp(i + 1, j, k + 1) + 1,
			dp(i, j + 1, k + 1) + 1,
		});
	} else {
		res = min(
			dp(i + 1, j, k),
			dp(i, j + 1, k)
		);
	}

	return res;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> m;
	forn (i, n) forn(j, m) cin >> a[i][j];

	memset(mem, -1, sizeof(mem));
	cout << dp(0, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010];

int main() {
  cin >> n >> W;
  for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; ++w) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}


Measured memory_bytes: 7032
S = input()
A= S[:4]
B =S[5:7]
C =S[8:]

ans = "TBD"

if int(A) == 2019:
    if B[0] == "0":
        if int(B[1]) <= 4:
            if C[0] == "0":
                ans = "Heisei"
            elif int(C) <= 30:
                ans = "Heisei"
elif int(A) < 2019:
    ans = "Heisei"

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define M 100000008

ll n;
vector <pair <ll, ll> > ad[100004];
ll vis[100004];
ll c[100004];

void dfs(ll v, ll co)
{
	ll i;
	vis[v] = 1;
	fr(i,0,ad[v].size())
	{
		if(vis[ad[v][i].ff] == 1)
			continue;
		else
		{
			if(ad[v][i].ss % 2 == 0)
			{
				c[ad[v][i].ff] = co;
				dfs(ad[v][i].ff, co);
			}
			else
			{
				c[ad[v][i].ff] = co^1;
				dfs(ad[v][i].ff, co^1);
			}
		}	
	}
}

int main()
{
	FAST;
	ll i;
	cin >> n;
	fr(i,0,n-1)
	{
		ll t1, t2, t3;
		cin >> t1 >> t2 >> t3;
		ad[t1].pb(mp(t2, t3));
		ad[t2].pb(mp(t1, t3));		
	}
	c[1] = 0;	
	dfs(1, 0);
	fr(i,1,n+1)
		cout << c[i] << endl;
}


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

}


Measured memory_bytes: 3624