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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 600001;
const ll MOD = 1e9 + 7;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    auto solve = [](int _) {
        set<ll> s;
        int n;
        cin >> n;
        vector<ll> a(3 * n + 1);
        for (int i = 1; i <= 3 * n; ++i) {
            cin >> a[i];
        }
        priority_queue<ll> pq;
        vector<ll> dp_suf(3 * n + 1);
        vector<ll> dp_pref(3 * n + 1);
        ll sum = 0;
        for (int i = 3 * n; i >= 1; --i) {
            pq.push(a[i]);
            sum += a[i];
            if (pq.size() > n) {
                sum -= pq.top();
                pq.pop();
            }
            if (pq.size() == n) {
                dp_suf[i] = sum;
            }
        }
        priority_queue<ll, vector<ll>, greater<>> pq2;
        sum = 0;
        for (int i = 1; i <= 3 * n; ++i) {
            sum += a[i];
            pq2.push(a[i]);
            if (pq2.size() > n) {
                sum -= pq2.top();
                pq2.pop();
            }
            if (pq2.size() == n) {
                dp_pref[i] = sum;
            }
        }
        ll ans = -1e18;
        for (int i = n; i <= 2 * n; ++i) {
            ans = max(ans, dp_pref[i] - dp_suf[i + 1]);
        }
        cout << ans;
    };


    fast_io();
    cout.precision(9);
    cout << fixed;

    solve(1);


}


Measured memory_bytes: 9588
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define FOR(i, a, b) for (int i = a, i##_len = (b); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS (1e-7)
#define INF (1e9)

using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int H, W;
vector<string> field(51);
int d[51][51];

void bfs(int sy, int sx) {
  queue< pair<int, int> > que;
  que.push(make_pair(sy, sx));
  d[sy][sx] = 0;

  while(!que.empty()) {
    int y = que.front().first, x = que.front().second;
    que.pop();
    if(y == H-1 && x == W-1) break;
    for(int i=0;i<4;i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if(ny >= 0 && ny < H && nx >= 0 && nx < W && d[ny][nx] == -1 && field[ny][nx] != '#') {
        que.push(make_pair(ny, nx));
        d[ny][nx] = d[y][x] + 1;
      }
    }

  }
  return;

}

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

  for(int i=0;i<H;i++) {
    cin >> field[i];
  }
  int white = 0;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      if(field[i][j] == '.')
        white++;

  memset(d, -1, sizeof(d));
  bfs(0, 0);
  if(d[H-1][W-1] < 0)
    cout << -1 << endl;
  else
    cout << white - (d[H-1][W-1]+1) << endl;

}


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

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


Measured memory_bytes: 3084
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

string to_bit(ll n){
    int c[50] {0};
    int i = 0;
    while(n){
        c[i] = n % 2;
        n /= 2;
        i++;
    }
    string s = "";
    for(int i = 0; i < 50; i++){
        s.push_back('0' + c[i]);
    }
    return s;
}
 
ll pow(int n){
    ll r = 1;
    for(int i = 0; i < n; i++){
        r *= 2;
    }
    return r;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll dif = b - a + 1;
    string bit = to_bit(a);
    for(int i = 0; i < 50; i++){
//        cout << bit[i] << endl;
    }
    int ans[50] {0};
    if(bit[0] == '1'){
        if(dif % 4 == 0 || dif % 4 == 3){
            ans[0] = 0;
        }
        else{
            ans[0] = 1;
        }
    }
    else{
        if(dif % 4 == 0 || dif % 4 == 1){
            ans[0] = 0;
        }
        else{
            ans[0] = 1;
        }
    }
    for(int i = 1; i < 50; i++){
        ll miman = 0;
        for(int j = 0; j < i; j++){
            miman = miman + (bit[j] - '0') * pow(j);
        }
//        cout << miman << endl;
        ll saisho = pow(i) - miman;
//        cout << saisho << endl;
        if(dif < saisho){
            if(bit[i] == '1' && dif % 2 == 1){
                ans[i] = 1;
            }
            else{
                ans[i] = 0;
            }
        }
        else{
            ll left = (dif - saisho) % pow(i + 1);
            if(bit[i] == '1'){
                ans[i] = saisho % 2;
            }
//            cout << left << endl;
            if(left <= pow(i)){
                if(bit[i] == '0'){
                    ans[i] = left % 2;
                }
            }
            else{
                if(bit[i] == '1'){
                    ans[i] = (saisho + left) % 2;
                }
            }
        }
    }
    ll an = 0;
    for(int i = 0; i < 50; i++){
        an += ans[i] * pow(i);
    }
    cout << an << endl;
    for(int i = 0; i < 49; i++){
//        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<n;i++)
    {
        cout<<s[i]<<t[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>

using namespace std;

int main() {
  int N, M, K, a;
  
  cin >> N >> M;
  
  vector<int> food(M, 0);
  for(int i = 0; i < N; i++) {
  	cin >> K;
    for(int j = 0; j < K; j++) {
      cin >> a;
      food[a-1]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < M; i++) {
    if(food[i] == N) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int num[MAX];
bool red[MAX];

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

  for (int i = 0; i < N; i++) num[i] = 1;
  red[0] = true;
  for (int i = 0; i < M; i++) {
    x[i]--, y[i]--;
    num[x[i]]--;
    num[y[i]]++;
    if (red[x[i]]) red[y[i]] = true;
    if (num[x[i]] == 0) red[x[i]] = false;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) if (red[i]) {
    ans++;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI x(m);
  rep(i, m) cin >> x[i];
  sort(all(x));
  VI l(m-1);
  rep(i, m-1){
    l[i] = x[i+1] - x[i];
  }
  sort(rall(l));
  ll ans;
  if(n >= m) ans = 0;
  else {
    ll sum = 0;
    rep(i, n-1) sum += l[i];
    ans = (x[m-1] - x[0]) - sum;
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;

    string row;
    vector<string> img(H);
    for (int i = 0; i < H; i++) {
        cin >> row;
        img.at(i) = row;
    }

    for (auto row : img) {
        cout << row << endl;
        cout << row << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int d,n;
  cin>>d>>n;
  ll ans=1;
  rep(i,d) ans*=100;
  if(n==100)
    cout<<ans*101<<endl;
  else
    cout<<ans*n<<endl;
}

Measured memory_bytes: 3560
use strict;
use warnings;
use feature 'say';
use Data::Dumper;

chomp(my $str = <STDIN>);

my @rep = qw(P D);
my $max_index_cnt = 0;
my $target_str = '';
for my $rep (@rep) {
  my $target = '';
  ($target = $str) =~ s/\?/$rep/g;

  my $before = length($target);
  my $total_pd_cnt = 0;
  for my $rep ( qw/ D PD / ) {

    my $occurrence_cnt = (() = $target =~ m/$rep/g);
    $total_pd_cnt += $occurrence_cnt;
  }

  if( $total_pd_cnt > $max_index_cnt) {
    $max_index_cnt = $total_pd_cnt;
    $target_str = $target;
  }
}
print $target_str,"\n";


Measured memory_bytes: 23860
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

bool yy(char c, char d){
  return true;
}

bool mm(char c, char d){
  if(c == '0' && d != '0') return true;
  else if(c == '1' && (d == '0' || d == '1' || d == '2')) return true;
  else return false;
}

bool yymm(string s){
  return yy(s[0], s[1]) && mm(s[2], s[3]);
}

bool mmyy(string s){
  return mm(s[0], s[1]) && yy(s[2], s[3]);
}

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

  if(yymm(s) && mmyy(s)) cout << "AMBIGUOUS" << endl;
  if(!yymm(s) && mmyy(s)) cout << "MMYY" << endl;
  if(yymm(s) && !mmyy(s)) cout << "YYMM" << endl;
  if(!yymm(s) && !mmyy(s)) cout << "NA" << endl;

  return 0;
}


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

void solve() {
    int N;
    cin >> N;
    vector<pair<ll,int>> v(N);
    for(int i=0;i<N;i++) {
        cin >> v[i].first;
        v[i].second=i;
    }
    sort(v.begin(),v.end());
    int cnt=0;
    for(int i=0;i<N;i++) {
        if((v[i].second&1) != (i&1)) cnt++;
    }
    cout << (cnt+1)/2 << "\n";
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    //input
    int d = sc.nextInt();
    /*
    int[] c = new int[26]; //array of decrease
    for(int i = 0; i < c.length; i++){
      c[i] = sc.nextInt();
    }
    */

    ArrayList<Integer> c = new ArrayList<Integer>();
    for(int i = 0; i < 26; i++){
      c.add(sc.nextInt());
    }

    int[][] s = new int[d][26]; //two dimensional array of increase
    for(int row = 0; row < s.length; row++){ //day
      for(int col = 0; col < s[row].length; col++){ //contest number
        s[row][col] = sc.nextInt();
      }
    }
    /*
    int[] t = new int[d]; //array of contest numbers of the day
    for(int i = 0; i < t.length; i++){
      t[i] = sc.nextInt();
    }
    */

    //output
    //based on increase
    /*
    for(int m = 0; m < d; m++){
      if( m%2 == 0 ){
        int largestNum = s[0][0];
        int largestNumRow = 0;
        int largestNumCol = 0;
        for(int row = 0; row < s.length; row++){
          for(int col = 0; col < s[row].length; col++){
            if( s[row][col] > largestNum ){
              largestNum = s[row][col];
              largestNumRow = row;
              largestNumCol = col;
            }
          }
        }
        System.out.println(largestNumCol+1);
      }else{
        int largestNum = c.get(0);
        int largestNumPos = 0;
        for(int i = 0; i < d; i++){
          largestNum = c.get(0);
          largestNumPos = 0;
          for(int j = 0; j < c.size(); j++){
            if( c.get(j) > largestNum ){
              largestNum = c.get(j);
              largestNumPos = j;
            }
          }
          c.remove(largestNumPos);
        }
        System.out.println(largestNumPos+1);
      }
    }
    */



    for(int i = 0; i < d; i++){
      System.out.println((int)(Math.random()*26+1));
      //System.out.println(largestNumCol+1);
    }




    /*
    int value = 0;
    for(int i = 0; i < t.length; i++){
      int contestNum = t[i]-1;
      int day = i+1;
      value += s[day-1][contestNum]; //increase
      for(int j = 0; j < c.length; j++){
        if( !(j == contestNum) ){
          int daySinceLast = day;
          for(int m = 0; m < i; m++){
            if( j == t[m]-1 ){
              daySinceLast = day-m-1;
            }
          }
          value -= c[j]*(daySinceLast); //decrease (amount of decrease * days since last one)
        }
      }
      System.out.println(value);
    }
    */

  }
}


Measured memory_bytes: 38116
if __name__ == '__main__':
    N, M = map(int, input().split())
    drinks = [tuple(map(int, input().split())) for _ in range(N)]

    drinks.sort()
    ans = 0
    for drink in drinks:
        cost, num = drink
        buy_num = min(num, M)

        ans += cost * buy_num
        M -= buy_num

        if M == 0:
            break

    print(ans)


Measured memory_bytes: 16972
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s[3];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    cin >> s[0] >> s[1] >> s[2];
    if(s[0][0] == '0')break;

    rep(i, 3){
      rep(j, 3)if(s[i][0] != s[i][j])break;
      if(j == 3 && s[i][0] != '+'){
        cout << s[i][0] << endl;
        break;
      }
      rep(j, 3)if(s[0][i] != s[j][i])break;
      if(j == 3 && s[0][i] != '+'){
        cout << s[0][i] << endl;
        break;
      }
    }
    if(i == 3){
      if(s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] != '+'){
        cout << s[0][0] << endl;
        continue;
      }
      if(s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[2][0] != '+'){
        cout << s[0][2] << endl;
        continue;
      }
      puts("NA");
    }



//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N; cin >> N; string s, t; cin >> s >> t;
    
    ll mx = 0;
    REP(i, N){
        bool ok = true;
        FOR(j, 0, N-i){
            if(s[i+j] != t[j]){
                ok = false; break;
            }
            j++;
        }
        if(ok) mx = max(mx, N-i);
    }
    cout << 2*N - mx << endstr;
    return 0;
}


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

int main()
{
    int A, B;
    std::cin >> A >> B;
    int plus = (A - 1);
    B -= 1;
    if (B == 0) {
        std::cout << 0 << std::endl;
    } else if (B % plus == 0) {
        std::cout << (B / plus) << std::endl;
    } else {
        std::cout << (B / plus) + 1 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001

sys.setrecursionlimit(3**12)

SIZE = 15

POW = [1]*SIZE
for i in range(1,SIZE):
    POW[i] = POW[i-1]*3

W = int(input())

max_digit = None
for i in range(SIZE):
    if (POW[i]-1)//2 >= W:
        max_digit = i
        break

ans =  [None]*(max_digit+1)
work = [None]*(max_digit+1)

def recursive(digit,tmp_sum):
    global ans,work,W,max_digit
    if digit == -1:
        if tmp_sum == W:
            for i in range(max_digit,-1,-1):
                ans[i] = work[i]
        return
    work[digit] = '0'
    recursive(digit-1,tmp_sum)
    work[digit] = '+'
    recursive(digit-1,tmp_sum+POW[digit])
    if tmp_sum > 0:
        work[digit] = '-'
        recursive(digit-1,tmp_sum-POW[digit])

recursive(max_digit,0)

is_First = True
for i in range(max_digit,-1,-1):
    if ans[i] == '0':
        if is_First:
            continue
        else:
            print("0",end="")
    elif ans[i] == '+':
        is_First = False
        print("+",end="")
    else: #ans[i] == '-'
        is_First = False
        print("-",end="")
print()




Measured memory_bytes: 6380
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    vector<lint> a(n + 1);
    rep(i, n + 1){
        cin >> a[i];
    }

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

    vector<lint> maxi(n + 1);

    maxi[0] = 1;
    reps(i, n){
        maxi[i] = min((maxi[i - 1] - a[i - 1]) * 2, LLINF);
    }

    rrep(i, n + 1){
        if(i == n){
            chmin(maxi[i], a[i]);
        }else{
            chmin(maxi[i], maxi[i + 1] + a[i]);
        }
        if(maxi[i] < a[i]){
            cout << -1 << endl;
            return 0;
        }
    }

    lint ans = 0;
    rep(i, n + 1){
        ans += maxi[i];
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << '\n';
}

Measured memory_bytes: 256
N = int(input())
high = [int(x) for x in input().split()]

top = 0
count = 0

for i in range(N):
    challenge = True
    
    if count > 0:
        count -= 1
    else:
        while challenge == True and i < N-1:
            if high[i] >= high[i+1]:
                count += 1
                if i < N-1:
                    i += 1
            else:
                challenge = False
        
        if top < count:
            top = count

print(top)


Measured memory_bytes: 15660
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;
typedef long long lint;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep0(i,n) rep(i,0,n)

int main(void){
	long W, H;
	int i, j, k;
	double x, y, z;
	cin >> W >> H >> x >> y;
	z = (double)(W)*(double)(H)*0.50;
	cout.precision(17);
	if ((double)(x) == (double)(W)*0.50 && (double)(y) == (double)(H)*0.50) {
		cout << fixed << z  << " 1";
	}
	else {
		cout << fixed << z << " 0";
	}
	return 0;
}

//sort Ｎ個の配列a
//sort(a, a + N); //昇順
//sort(a, a + N, greater<int>()); //降順

////最大公約数（ユークリッドの互除法利用）
//int gcd(int a, int b) {
//	if (a == 0) return b;
//	if (b == 0) return a;
//	int m = max(a, b);
//	int n = min(a, b);
//	if (m%n == 0) return n;
//	else return gcd(n, m%n);
//
//}
//
////最小公倍数
//int lca(int a, int b) {
//	if (a == 0) return 0;
//	if (b == 0) return 0;
//	return a * b / gcm(a, b);
//}
//
////n^k(整数)
//int pow_int(int n, int k) {
//	int re = 1;
//	for (int i = 0; i < k; i++) re *= n;
//	return re;
//}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
	char a[11], b[11], c[11];
	scanf("%s%s%s", a, b, c);
	if (a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


class UnionFind{
    vector<int> par;
    int all = 0;
    vector<int> siz;
    int treenum;

    public:UnionFind(int N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par.emplace_back(i);
        for(int i = 0; i < N; i++) siz.emplace_back(1);
        all = N;
        treenum = N;
    }

    public:int root(int x){
        if(par[x]==x) return x;
        else{
            par[x]=root(par[x]);
            return par[x];
        }
    }

    public:bool same(int x, int y){
        return root(x)==root(y);
    }

    public:void unite(int x, int y){
        if(same(x,y)) return;
        else{
            int rx=root(x);
            int ry=root(y);
            par[ry]=rx;
            siz[rx]=siz[rx]+siz[ry];
            siz[ry]=siz[rx];
            treenum--;
            return;
        }
    }

    public:int size(int x){
        siz[x]=siz[root(x)];
        return siz[x];
    }

    public:void sizall(){
        rep(i,all){
            siz[i] = siz[root(i)];
        }
    }

    public:int treenumber(){
        return treenum;
    }

    public:void add(){
        par.emplace_back(all);
        siz.emplace_back(1);
        all++;
        treenum++;
    }

    public:void del(int x){
        //xを木から外して単一ノードの木に分離する
        //子の検索にO(n)かける. UF木の弱点なので使用は推奨されない
        //根であれば繋ぎ直し、素集合としてみなさない.
        bool isroot=false;
        //あるノードの根であるかどうか.
        rep(i,all){
            if(root(i)==x) isroot=true;
        }
        if(!isroot){
            rep(i,all){
                if(par[i]==x){
                    par[i]=par[x];
                }
            }
            par[x]=x;
            return;
        }

        if(isroot){
            sizall();
            if(size(x)==1) return;
            rep(i,all){
                if(par[i]==x){
                    treenum++;
                    par[i]=i;
                }
            }
            return;
        }

    }

};



void solve(){

    int v,e;
    cin >> v >> e;
    vector<tuple<int,int,int>> t;
    rep(i,e){
        int x,y,z;
        cin >> x >> y >> z;
        t.emplace_back(make_tuple(z,x,y));
    }

    sort(t.begin(), t.end());
    UnionFind uf(v);
    int pointer=0;
    int ans = 0;
    while(uf.treenumber()>1){
        int d = get<0>(t[pointer]);
        int x = get<1>(t[pointer]);
        int y = get<2>(t[pointer]);
        if(!uf.same(x,y)){
            ans += d;
            uf.unite(x,y);
        }
        pointer++;
    }
    cout << ans << endl;

}


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



Measured memory_bytes: 4572
// Date: 2020-06-13

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int a[N], b[N];
int main() {
    FIO;
    int n, k;
    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    while(k--) {
        int cnt = 0;
        rep(i, 0, n+1) b[i] = 0;
        rep(i, 1, n) {
            b[max(0, i-a[i])]++;
            b[min(n+1, i+a[i]+1)]--;
        }
        rep(i, 1, n) {
            b[i] += b[i-1];
            a[i] = b[i];
            if(a[i] == n) ++cnt;
        }
        if(cnt == n) break;
    }
    rep(i, 1, n) cout << a[i] << " ";

    return 0;
}

Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int main() {
    DAU
    int x;
    cin >> x;
    for (int i = 1; i <= 9; ++i)
        for (int j = 1; j <= 9; ++j)
            if (i * j == x) {
                cout << "Yes";
                PLEC
            }
    cout << "No";
    PLEC
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    int ans=0;
    rep(i,n){
        int a;
        cin>>a;
        if((i+1)%2==1 && a%2==1) ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <iomanip>

constexpr double Eps = 1e-7;

int main() {
	int N, K, T, U, V, L;
	std::cin >> N >> K >> T >> U >> V >> L;

	std::vector<int> D(N);
	for (auto&& e : D)
		std::cin >> e;

	D.push_back(L + 1);

	double time = 0;
	int boost = 0, carrot = 0, area = 0;
	for (int cur = 1; cur <= L; ++cur) {
		if (boost > 0) {
			--boost;
			time += 1.0 / V;
		}
		else
			time += 1.0 / U;

		if (boost == 0 && carrot > 0) {
			--carrot;
			boost = V * T;
		}

		if (cur == D[area]) {
			if (carrot >= K)
				boost = V * T;
			else if (boost == 0)
				boost = V * T;
			else
				++carrot;

			++area;
		}
	}

	std::cout << std::fixed << std::setprecision(8);
	std::cout << time << std::endl;
}


Measured memory_bytes: 3268
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

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

typedef long long ll;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }

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

int asc(const void* a, const void* b) { return *(int*)a - *(int*)b; }

ll dsc(const void* a, const void* b) { return *(ll*)b - *(ll*)a; }

bool used[100];
ll perm[100];

void permutation(int pos, int n) {
    if (pos == n) return;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            perm[pos] = i;
            used[i] = true;
            permutation(pos + 1, n);
            used[i] = false;
        }
    }
}

int main() {
    ll n,k,d,ans;
    scanf("%lld%lld%lld", &n,&k,&d);
    n = labs(n);
    if (n / d > k) {
        ans = n - d * k;
    }
    else if (n / d % 2 == k % 2) {
        ans = n % d;
    }
    else ans = d - n %d;

    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 2148
#include "bits/stdc++.h"

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

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int r; cin >> r;
	cout << 3 * r * r;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
using namespace std;

int main()
{
  char s[10];
  scanf("%s",s);
  sort(s,s+4);
  printf((s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) ? "Yes" : "No");
}
    

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N,M;
	scanf("%d",&N);
	scanf("%d",&M);
	if(N==0||N==1)N=0;
	if(M==0||M==1)M=0;
	if(N!=0)N=N*(N-1)/2;
	if(M!=0)M=M*(M-1)/2;
	printf("%d",N+M);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

int cnt[256];
int n;
string s;
ll ans = 1;

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

    cin >> s; n =s.size();
    for (int i = 0; i < n; ++i)
        ++cnt[s[i]];
    for (int i = 0; i < n; ++i) {
        for (int j = 'a'; j <= 'z'; ++j)
            if (s[i] != j)
                ans += cnt[j];
        --cnt[s[i]];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int a; cin >> a;
	cout << a + a*a + a*a*a;
	
	
	
}


Measured memory_bytes: 3616
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if (x1 == 0) {
    cout << "1" << endl;
    return 0;
  }
  if (x2 == 0) {
    cout << "2" << endl;
    return 0;
  }
  if (x3 == 0) {
    cout << "3" << endl;
    return 0;
  }
  if (x4 == 0) {
    cout << "4" << endl;
    return 0;
  }
  if (x5 == 0) {
    cout << "5" << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  vector<int> C(N-1),S(N-1),F(N-1),ans(N);
  for(int i=0;i<N-1;i++)
    cin>>C.at(i)>>S.at(i)>>F.at(i);
  
  for(int i=0;i<N-1;i++){
    ans.at(i)=C.at(i)+S.at(i);
    for(int j=i+1;j<N-1;j++){
      if(ans.at(i)-S.at(j)>=0){
        if(ans.at(i)%F.at(j)!=0)
          ans.at(i) += F.at(j) - ans.at(i)%F.at(j);
      }else
        ans.at(i)=S.at(j);
      ans.at(i)+=C.at(j);
    }
  }
  for(int i=0;i<N;i++)
    cout<<ans.at(i)<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		int n = sc.nextInt();
		sc.nextLine();
		for(int i=0; i<n;i++){
			String order = sc.nextLine();
			String message = sc.nextLine();
			calc(order, message);
		}
	}
	public void calc(String order, String message){
		if(order.equals("")) System.out.println(message);
		else{
			String person = order.substring(order.length() - 1);
			if(person.equals("J")){
				String me = message.substring(message.length()-1) + message.substring(0, message.length() - 1);
				message = me;
			}
			else if(person.equals("C")){
				String me = message.substring(1) + message.substring(0, 1);
				message = me;
			}
			else if(person.equals("E")){
				int half = message.length() / 2;
				String me = message.substring(message.length()-half) 
						+ message.substring(half, message.length()-half) 
						+ message.substring(0, half);
				message = me;
			}
			else if(person.equals("A")){
				String me = reverse(message, "");
				message = me;
			}
			else if(person.equals("P")){
				String me = addNum(message, -1);
				message = me;
			}
			else if(person.equals("M")){
				String me = addNum(message, 1);
				message = me;
			}
			calc(order.substring(0, order.length()-1), message);
		}
	}
	public String reverse(String s, String ans){
		if(s.equals("")) return ans;
		else{
			ans = ans + s.substring(s.length()-1);
			return reverse(s.substring(0, s.length()-1), ans);
		}
	}
	public String addNum(String message, int n){
		for(int i = 0; i < message.length(); i++){
			String c = message.substring(i, i+1);
			if(c.equals("0")) message = message.substring(0,i) + addN(0,n) + message.substring(i+1);
			else if(c.equals("1")) message = message.substring(0,i) + addN(1,n) + message.substring(i+1);
			else if(c.equals("2")) message = message.substring(0,i) + addN(2,n) + message.substring(i+1);
			else if(c.equals("3")) message = message.substring(0,i) + addN(3,n) + message.substring(i+1);
			else if(c.equals("4")) message = message.substring(0,i) + addN(4,n) + message.substring(i+1);
			else if(c.equals("5")) message = message.substring(0,i) + addN(5,n) + message.substring(i+1);
			else if(c.equals("6")) message = message.substring(0,i) + addN(6,n) + message.substring(i+1);
			else if(c.equals("7")) message = message.substring(0,i) + addN(7,n) + message.substring(i+1);
			else if(c.equals("8")) message = message.substring(0,i) + addN(8,n) + message.substring(i+1);
			else if(c.equals("9")) message = message.substring(0,i) + addN(9,n) + message.substring(i+1);
		}
		return message;
	}
	public String addN(int m, int n){
		int ans = m + n;
		if(ans == 10) ans = 0;
		if(ans == -1) ans = 9;
		return Integer.toString(ans);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17324
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

#pragma endregion



int main(){
  int n,m;
  cin >> n >> m;
  cout << n*m << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <cstdio>

typedef long long LL;
int n;
LL a, b, ans;

int main() {
    scanf("%d", &n);
    for (int i = 0 ; i < n ; i++) {
        scanf("%lld", &b);
        if (b < a) ans += a - b, b = a;
        a = b;
    }
    printf("%lld", ans);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
using namespace std;

int N, W;
long long res;
int We[103], Ve[103];
map <int, long long> Values;

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i ) {
        cin >> We[i] >> Ve[i];
    }
    /*for (int i = 0; i < N; ++i)
        We[i] = Ve[i] = i + 5;*/
    vector <pair <int, long long>> V;
    for (int i = 0; i < N; ++i) {
        res = max(res, (long long)Ve[i]);
        for (auto x : Values) {
            if (x.first + We[i] <= W) {
                V.push_back({x.first + We[i], x.second + Ve[i]});
            }
        }
        while(!V.empty()) {
            pair <int, long long> x = V.back();
            V.pop_back();
            auto it = Values.find(x.first);
            res = max(res, x.second);
            if (it == Values.end()) {
                Values.insert(x);
            }
            else {
                (*it).second = max((*it).second, x.second);
            }
        }
        auto it = Values.find(We[i]);
        if (it == Values.end()) {
            Values.insert({We[i], Ve[i]});
        }
        else Values[We[i]] = max((*it).second, (long long)Ve[i]);
    }
    cout << res;
    return 0;
}


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

long long n,s[105],r;

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

    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        r+=s[i];
    }
    sort(s,s+n);
    if(r%10==0)
    {
        for(int i=0;i<n;i++)
            if((s[i]%10)!=0)
            {
                cout<<r-s[i]<<endl;
                return 0;
            }
        cout<<0<<endl;
        return 0;
    }
    else
    {
        cout<<r<<endl;
        return 0;
    }

}


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

#define ll long long
#define ar array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

#define E_ACH2(x, a) for (auto& x: a)
#define E_ACH3(x, y, a) for (auto& [x, y]: a)
#define E_ACH4(x, y, z, a) for (auto& [x, y, z]: a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...) E_ACHC(__VA_ARGS__)(__VA_ARGS__)

int h, w, k, ans;
string g[6];

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

	cin >> h >> w >> k;
	FOR(h)
		cin >> g[i];
	FOR(1<<h) {
		FOR(j, 1<<w) {
			int c=0;
			FOR(i2, h)
				FOR(j2, w)
				if(i>>i2&1&&j>>j2&1&&g[i2][j2]=='#')
					++c;
			if(c==k)
				++ans;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
int main()
{
	int x=io::F();
	printf("%d\n",x+io::F()/2); 
	return 0;
}


Measured memory_bytes: 256
//abc127
#include <iostream>
#include <vector>


int main(){
    int n,m;
    std::cin >> n >> m;
    std::vector<int>l(m);
    std::vector<int>r(m);
    for(int i=0;i<m;i++){
        std::cin >> l[i] >> r[i];
    }
    
    int maxL=1;
    int minR=n;
    
    int ans=0;
    
    for(int i=0;i<m;i++){
        maxL=std::max(maxL,l[i]);
        minR=std::min(minR,r[i]);
    }
    ans=minR-maxL+1;
    if(maxL>minR){
        ans=0;
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int count = 0;
	if (N / 1000 == 2)count += 1;
	if (N % 1000 / 100 == 2)count += 1;
	if (N % 100 / 10 == 2)count += 1;
	if (N % 10 == 2)count += 1;
	cout << count << endl;
	return 0;
}

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

using namespace std;

const int maxn = 100005;

int a[maxn],ai,aj,n;

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++) scanf("%d",&a[i]);
    sort(a,a+n);

    aj=a[n-1];
    int i=0;
    while (a[i]<aj/2) i++;
    if (i>0 && (abs(a[i-1]-aj/2)<abs(a[i]-aj/2) || a[i]==aj)) i--;
    ai=a[i];

    printf("%d %d",aj,ai);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

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

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

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

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  ll a,b,c; cin >> a >> b >> c;
  if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){cout << 0 << endl; return 0;}
  if(a == b && b == c){cout << -1 << endl; return 0;}
  ll ans = 0;
  do{
    ll tmpA = (b+c)/2;
    ll tmpB = (a+c)/2;
    ll tmpC = (a+b)/2;
    a = tmpA; b = tmpB; c = tmpC; ans++;
  }while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	char a[5];
	scanf("%s",a);
	if(a[0]=='S'){
					if(a[1]=='U') printf("7");
				  else printf("1");} 
	if(a[0]=='M') printf("6");
	if(a[0]=='T') {
	if(a[1]=='U') printf("5");
				  else printf("3");}
	if(a[0]=='W') printf("4");
	if(a[0]=='F') printf("2");
	return 0;
}

Measured memory_bytes: 128
<?php
  list($s) = explode(" ", trim(fgets(STDIN)));

  $n = strlen($s);

  $gpsa = 0;
  $ans = 0;
  for ($i=0; $i<$n; $i++) {
    if($s[$i] == 'g'){
      if($gpsa > 0){
        $ans++;
        $gpsa--;
      }else{
        $gpsa++;
      }
    }else{
      if($gpsa > 0){
        $gpsa--;        
      }else{
        $ans--;
        $gpsa++;
      }
    }
  }
  echo $ans;

Measured memory_bytes: 16472
def main():
    from itertools import accumulate

    N = int(input())
    S = input()

    R, G, B = [0], [0], [0]
    for s in S:
        if s == 'R':
            R.append(1)
            G.append(0)
            B.append(0)

        elif s == 'G':
            R.append(0)
            G.append(1)
            B.append(0)

        elif s == 'B':
            R.append(0)
            G.append(0)
            B.append(1)

    R = list(accumulate(R))
    G = list(accumulate(G))
    B = list(accumulate(B))

    # print(R)
    # print(G)
    # print(B)
    ans = 0
    for j in range(1, N - 1):
        sj = S[j]
        for i in range(j):
            si = S[i]
            sk = ''
            if j + j - i < N:
                sk = S[j + j - i]

            if si == sj:
                continue

            # if sj == sk:
            #     continue

            # print(sj, j, i)
            if (si == 'G' and sj == 'B') or (si == 'B' and sj == 'G'):
                ans += R[-1] - R[j + 1]
                if sk and si != sk and sj != sk:
                    ans -= 1
                # print('Rx', ans)

            if (si == 'R' and sj == 'B') or (si == 'B' and sj == 'R'):
                ans += G[-1] - G[j + 1]

                if sk and si != sk and sj != sk:
                    ans -= 1
                # print('Gx', ans)

            if (si == 'R' and sj == 'G') or (si == 'G' and sj == 'R'):
                ans += B[-1] - B[j + 1]
                if sk and si != sk and sj != sk:
                    ans -= 1
                # print('Bx', ans)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 69576