akhauriyash/Code-Regression huggingface dataset:
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
ll ans = 0;
ll maxVal = 0;
bool is753(string val)
{
	int ptn = 0;
	int iVal = atoi(val.c_str());
	if (maxVal < iVal) return false;

	REP(i, val.size()) {
		if (val[i] == '7') {
			ptn |= 1;
		} else if (val[i] == '5') {
			ptn |= 2;
		} else {
			ptn |= 4;
		}
	}
	return ptn == 7 ? true : false;
}

void dfs(string val, char ch = 0)
{
	if (9 <= val.size()) {
		return;
	}

	if (ch != 0) {
		string apd(1, ch);
		val.append(apd);
		if (is753(val)) ans++;
	}

	dfs(val, '7');
	dfs(val, '5');
	dfs(val, '3');
}

int main()
{
	string val;
	cin >> maxVal;
	dfs(val);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//the number of dice

#include<iostream>
#include<cmath>
#include<string>

using namespace std;

class DICE {
    
public:
    int top;
    int bottom;
    int right;
    int left;
    int front;
    int back;
    void South();
    void North();
    void East();
    void West();
};

void DICE::South(){
    int temp = front;
    front   = top;
    top     = back;
    back    = bottom;
    bottom  = temp;
}

void DICE::North(){
    int temp = front;
    front   = bottom;
    bottom  = back;
    back    = top;
    top     = temp;
}

void DICE::West(){
    int temp = left;
    left    = top;
    top     = right;
    right   = bottom;
    bottom  = temp; 
}

void DICE::East(){
    int temp = right;
    right   = top;
    top     = left;
    left    = bottom;
    bottom  = temp;       
}

int main(void){
    
    DICE d;
    cin >> d.top >> d.front >> d.right >> d.left >> d.back >> d.bottom;
    
    string str;
    
    cin >> str;
    for(int i = 0; i < str.size(); i++){
        if(str[i] == 'S') d.South();
        if(str[i] == 'W') d.West();
        if(str[i] == 'E') d.East();
        if(str[i] == 'N') d.North();
    }
    
    cout << d.top << endl;
    
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdint>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
  int64_t N;
  cin >> N;
  vector<int64_t> A(N, 0);
  vector<int64_t> csA(N+1, 0);
  {
    int64_t tmp;
    for (int i = 0; i < N; i++)
    {
      cin >> tmp;
      A[i] = tmp;
      csA[i+1] = tmp + csA[i];
    }
  }

  int64_t diff;
  diff = 9223372036854775807;

  int64_t p, q, r, s;
  int64_t mid0 = 0;
  int64_t mid2 = 2;

  for (int64_t mid1 = 0; mid1 < N - 2; mid1++)
  {
    int64_t diff0, diff2;
    diff0 = diff2 = 9223372036854775807;
    
    // mid0 search
    for (int64_t i = mid0; i < mid1; i++)
    {
      int64_t tmpp = csA[i+1] - csA[0];
      int64_t tmpq = csA[mid1+1] - csA[i+1];
      int64_t tmpdiff0 = abs(tmpp - tmpq);
      if (diff0 > tmpdiff0)
      {
        mid0 = i;
        diff0 = tmpdiff0;
        p = tmpp;
        q = tmpq;
      }
      else
      {
        break;
      }
    }

    // mid2 search
    int64_t start = (mid1 > mid2)? mid1 : mid2;
    for (int64_t i = start; i < N - 1; i++)
    {
      int64_t tmpr = csA[i+1] - csA[mid1+1];
      int64_t tmps = csA[N] - csA[i+1];
      int64_t tmpdiff2 = abs(tmpr - tmps);
      if (diff2 > tmpdiff2)
      {
        mid2 = i;
        diff2 = tmpdiff2;
        r = tmpr;
        s = tmps;
      }
      else
      {
        break;
      }
    }

    // check finaldiff
    int64_t tmpdiff = max({p, q, r, s}) - min({p, q, r, s});
    if (diff > tmpdiff)
      diff = tmpdiff;
  }

  cout << diff << endl;

  return 0;
}
  


Measured memory_bytes: 3328
program main
  implicit none
  integer :: n
  logical :: i, j
  character(100000) :: s
  read(*, *) s
  n = len(trim(s))
  i = mod(n, 2) == 0
  j = s(1:1) == s(n:n)
  if (i .eqv. j) then
    write(*, "(a)") "First"
  else
    write(*, "(a)") "Second"
  end if
end program main


Measured memory_bytes: 700
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int a=h2-h1;
    int b=m2-m1;
    int c=(a*60+b)-k;
    cout<<c<<endl;
    exit(0);
}


Measured memory_bytes: 3604
import collections
n=int(input())
arr=list(map(int,input().split()))
q=collections.deque()
for i in range(n):
  if i%2==0:
    q.append(arr[i])
  else:
    q.appendleft(arr[i])
if n%2==1:
  q=list(q)[::-1]
print(' '.join(map(str,q)))

Measured memory_bytes: 30660
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		ll x;
		cin >> x;
		if(x & 1)
			return cout << "first", 0;
	}
	cout << "second";





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  ll x,a,sum;
  cin >> x;

  sum=(x/11)*2;
  a=x%11;
  if(a==0){
    cout << sum << endl;
  }
  else if(a<=6){
    cout << sum+1 << endl;
  }
  else{
    cout << sum+2 << endl;
  }



  }


Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	int mid = 0;
	while(mid<10000)
	{
		mid += A;
		if(mid%B == C)
		{
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	return 0;
}

Measured memory_bytes: 128
/* WORK HARD MAN ! IT DEFINETELY AIN'T EASY FOR THE PRIZE IT HOLDS .... */
/* GET YOUR ASS TO WORK ALREADY */
/* FALTU HI LIKH ... BUT KHALI NI BAITHNA */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long
#define pb emplace_back
#define range(v) v.begin(),v.end()
#define mod 1000000007
#define inf 1e15
#define pii pair<int,int>
#define ff first
#define ss second
// #define N --

using namespace std;

/* if not able to handle the ques.. see up */
int32_t main() {
	fast
	int t_c = 1;
//	cin >> t_c;
	while (t_c--) {
		int n, k, maxSum = 0;
		cin >> n >> k;
		vector<int> v(n), w(n);
		for (int i = 0; i < n; i++) {
			cin >> w[i] >> v[i];
			maxSum += v[i];
		}
		vector<vector<int>> dp(n + 1, vector<int>(maxSum + 5));
		for (int i =  n; i >= 0; i--) {
			for (int cv = 0; cv <= maxSum; cv++) {
				if (cv == 0)
					dp[i][cv] = 0;
				else if (i == n)
					dp[i][cv] = inf;
				else {
					dp[i][cv] = dp[i + 1][cv];
					if (v[i] <= cv)
						dp[i][cv] = min(dp[i][cv], dp[i + 1][cv - v[i]] + w[i]);
				}
			}
		}

		int ans = 0;
		for (int i = 0; i <= maxSum; i++) {
			if (dp[0][i] <= k)
				ans = max(ans, i);
		}

		cout << ans;
	}
}

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

int main() {
  long long int Q,H,S,D;
  long long int N;
  cin >> Q >> H >> S >> D;
  cin >> N;
  Q = 4 * Q;
  H = 2 * H;
  long long int min1,min2,min3;
  min1 = min(Q,H);
  min2 = min(H,S);
  min3 = min(min1,min2);
  if(min3 <= D / 2) {
    cout << N * min3;
  }else if(min3 > D / 2) {
    long long int sum = N / 2;
    cout << sum * D + (N % 2) * min3;
  }
}

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

struct Node;
typedef Node* Node_ptr;
struct Node
{
  int key;
  Node_ptr prev, next;
  
  Node(int key_=-1, Node_ptr prev_=NULL, Node_ptr next_=NULL)
    : key(key_), prev(prev_), next(next_) {}
};


class LinkedList
{
private:
  
  Node_ptr head, tail;
  
public:
  
  LinkedList()
  {
    head = new Node();
    tail = new Node();
    head->next = tail; tail->prev = head;
  }
  
  ~LinkedList()
  {
    Node_ptr d = head->next;
    for(Node_ptr iter = head->next->next; iter!=tail; iter=iter->next) {
      delete d;
      d = iter;
    }
    delete d;
    delete head; delete tail;
  }
  
  bool empty()
  {
    return head->next == tail;
  }
  
  void insert(int x)
  {
    Node_ptr nd = new Node(x, head, head->next);
    nd->next->prev = nd;
    head->next = nd;
  }
  
  void erase(int x)
  {
    Node_ptr tprev, tnext;
    bool deleted = false;
    for(Node_ptr iter = head->next; iter!=tail; iter=iter->next) {
      if(iter->key == x) {
	tprev = iter->prev, tnext = iter->next;
	delete iter;
	deleted = true;
	break;
      }
    }
    if(!deleted) return;
    tprev->next = tnext;
    tnext->prev = tprev;
  }
  
  void erase_first()
  {
    if(empty()) return;
    Node_ptr tnext = head->next->next;
    delete head->next;
    head->next = tnext;
    tnext->prev = head;
  }
  
  void erase_last()
  {
    if(empty()) return;
    Node_ptr tprev = tail->prev->prev;
    delete tail->prev;
    tprev->next = tail;
    tail->prev = tprev;
  }
  
  void print()
  {
    for(Node_ptr iter = head->next; iter != tail; iter=iter->next) {
      if(iter!=head->next) cout << " ";
      cout << iter->key;
    }
    cout << endl;
  }

  
};

int main() {
  
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int Q_num; cin >> Q_num;
  LinkedList list;
  for(int q=0; q<Q_num; q++) {
    string s; cin >> s;
    if(s == "deleteFirst") list.erase_first();
    else if(s == "deleteLast") list.erase_last();
    else {
      int x; cin >> x;
      if(s == "insert") list.insert(x);
      if(s == "delete") list.erase(x);
    }
  }
  
  list.print();
  
  return 0;
}

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

int main()
{
    int n;
    int d1, d2;
    cin >> n;
    int ans = 0;
    int max_ans = 0;
    rep(i,n){
        cin >> d1 >> d2;
        if(d1 == d2) ans++;
        else{
            max_ans = max(max_ans, ans);
            ans = 0;
        }
    }
    max_ans = max(max_ans, ans);
    if(max_ans>=3) cout << "Yes" << endl;
    else cout << "No" << endl;

    
    return 0;
}

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

using namespace std;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(NULL);
    
    int n,k,i,j;
    cin >> n >> k;
    int arr[n];bool dp[k+1] = {false};
    for(i=0;i<n;i++){
    cin >> arr[i];
    dp[arr[i]]=true;
    }
    sort(arr,arr+n);
    //dp[0]=true;
    
    for(i=arr[0]+1;i<=k;i++){
        bool dev = false;
        if(binary_search(arr,arr+n,i))
        continue;
        for(j=0;j<n;j++){
            if(i-arr[j] <= 0)
             break;
             else{
                 if(! dp[i-arr[j]])
                 dev = true;
             }
        }
        dp[i] = dev;
    }
    /*for(i=0;i<=k;i++)
    cout << i << " :: " << dp[i] << "\n";*/
    if(dp[k])
    cout << "First";
    else
    cout << "Second";
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    
    n = s.length();
    
    for (int common = n; common >= 0; common--)
    {
        bool fail = false;
        for (int i = 0; i < common; i++)
            if (s[n - common + i] != t[i])
            {
                fail = true;
                break;
            }
            
        if (fail) continue;
        
        printf("%d\n", 2 * n - common);
        return 0;
    }
    assert(!"fail");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N = 3e3+10;
const int M =1e8;
//#define int long long int
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define MAX 1e15+1
#define pi  pair<int,int>

double dp[N][N];
bool visit[N][N];
double a[N];
int n;
double solve(int i,int cnt){
    if(i==n){
        if(cnt>(n-cnt))return 0;
        return 1;
    }
    
    if(visit[i][cnt])return dp[i][cnt];
    visit[i][cnt] = 1;
    double x=0;

    double val = solve(i+1,cnt+1)*(1-a[i]);

    double val2 = solve(i+1,cnt)*(a[i]);

    return dp[i][cnt]=(val+val2);


}
 
signed main(){
    fast;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    double ans = solve(0,0);
    printf("%.15f",ans);
 
    
 
    
 
 
}

Measured memory_bytes: 79872
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[10000];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    int ans=1;
    int memo = a[0];
    for(int i=0; i<n; i++){
        if(a[i]!=memo){
            memo = a[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
p = input()
bl = True
if p in s:
    print("Yes")
    bl = False
if bl:
    for i in range(1,len(s)+1):
        if p[0:i] == s[-i:]:
            if p[i:] == s[0:len(p)-i]:
                print("Yes")
                bl = False
                break
if bl:
    print("No")

Measured memory_bytes: 7448
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(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); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

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

    int N;
    cin >> N;
    vector<int> b(N), ans;
    cin >> b;
    while (!b.empty()) {
        int i;
        for (i = b.size() - 1; i >= 0; i--) {
            if (b[i] == i+1) break;
        }
        if (i < 0) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(b[i]);
        b.erase(b.begin() + i);
    }
    REV(ans);
    REP(i,N) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine();
		WriteLine($"{n[0]}{n.Length - 2}{n[n.Length - 1]}");
	}
}


Measured memory_bytes: 17568
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <iterator>
#define r(i, n) for (int i = 0; i < n; i++)
#define R(i, c, n) for (int i = c; i < n; i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a)            \
  REP(d, a.size())         \
  {                        \
    cout << a[d];          \
    if (d != a.size() - 1) \
      cout << " ";         \
    else                   \
      cout << endl;        \
  }
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) \
  sort(ALL(v));   \
  v.erase(unique(ALL(v)), v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

  int a[5];
  r(i,5) cin >> a[i];

  int ans = 0;
  int hoge = 0;
  int minhoge = 10;
  r(i,5){
    if(a[i]%10!=0){
      if(a[i]%10<minhoge){
        hoge = i;
        minhoge = a[i]%10;
      }
    }
  }
  r(i,5){
    if(i==hoge) continue;
    if(a[i]%10!=0){
      ans += 10 * (a[i]/10+1);
    }else{
      ans += a[i];
    }
  }
  ans += a[hoge];
  cout << ans << endl;

  return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    vector<int> U;
    for (int i = 0; i < N; ++i) {
        if (i == 0 || A[i] != U.back()) {
            U.push_back(A[i]);
        }
    }
    vector<int> M; // local min & max
    if (U[0] < U[1]) {
        M.push_back(U[0]);
    }
    for (int i = 1; i < (U.size() - 1); ++i) {
        if ((U[i] > U[i - 1] && U[i] > U[i + 1]) || (U[i] < U[i - 1] && U[i] < U[i + 1])) {
            M.push_back(U[i]);
        }
    }
    M.push_back(U.back());
    long long money = 1000;
    for (int i = 0; i + 1 < M.size(); i += 2) {
        int buy = M[i], sell = M[i + 1];
        money += (sell - buy) * (money / buy);
    }
    cout << money << '\n';
    return 0;
}

Measured memory_bytes: 3656
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	cnt = 0
	fst = True

	ansans = []
	pgt = queue.Queue()
	for i,val in enumerate(A):
		if i == 0:
			pgt.put(val)
		else:
			tmp = pgt.get()
			ansans.append(tmp)

			pgt.put(val)
			pgt.put(val)
	print(sum(ansans))


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 117584
#include <stdio.h>

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		if(i % 3 == 0)
		{
			printf(" %d", i);
		}
		else
		{
			for(int x = i; x; x /= 10)
			{
				if(x % 10 == 3)
				{
					printf(" %d", i);
					break;
				}
			}

		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2104
m,d=map(int,input().split())
ans=0
for a in range(1,m+1):
    for i in range(1,d+1):
        c=i
        y=c%10
        c//=10
        x=c%10
        if x>=2 and y>=2 and x*y==a:
            ans+=1
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
const ll MAX_N = 100000 + 2;
ll A[MAX_N];
ll B[MAX_N];

struct UnionFind {
  vector<ll> par;
  vector<ll> rank;
  vector<ll> size;
    
  UnionFind(ll N) : par(N), rank(N), size(N) {
    for (ll i = 0; i < N; i++) {
      par[i]  = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }
  
  ll root(ll x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  bool unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx == ry) return false;
    
    if (rank[rx] < rank[ry]) {
      par[rx] = ry;
      size[ry] = size[ry] + size[rx];
    }
    else if (rank[rx] > rank[ry]) {
      par[ry] = rx;
      size[rx] = size[rx] + size[ry];
    }
    else {
      par[ry] = rx;
      size[rx] = size[rx] + size[ry];
      rank[rx]++;
    }
    return true;
  }
  
  bool same(ll x, ll y) {
    return root(x) == root(y);
  }
  
  ll get_size(ll x) {
    ll rx = root(x);
    return size[rx];
  }
  
};


int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;

  for(ll i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  UnionFind uf = UnionFind(N);
  ll ans[M];
  ans[M-1] = N*(N-1)/2;
  
  for(ll i = 0; i < M-1; i++) {
    ll a = uf.get_size(A[M-1-i]);
    ll b = uf.get_size(B[M-1-i]);

    if(uf.same(A[M-1-i], B[M-1-i])) ans[M-1-i-1] = ans[M-i-1];
    else {
      ans[M-1-i-1] = max((ll)0, ans[M-i-1] - a*b);
      uf.unite(A[M-1-i], B[M-1-i]);
    }
  }

  for(ll i = 0; i < M; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 7624
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	int n,i,j=0;
	string s;
	cin>>s;
	n=s.size();
	if(s[0]!='A'){
		cout<<"WA"<<endl;
		return 0;
	}
	for(i=2;i<n-1;i++)
			if(s[i]=='C')j++;
	if(j!=1){
		cout<<"WA"<<endl;
		return 0;
	}
	for(i=1;i<n;i++)
	if(s[i]>='A'&&s[i]<='Z')j++;
	if(j>2)cout<<"WA"<<endl;
	else cout<<"AC"<<endl;
	return 0;
}



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

int main(){
  int s;
  cin>>s;
  int ans;
  if (s==1||s==2||s==4)ans=4;
  else {
    int cnt=0;
    int tmp=s;
    while(tmp!=4){
      if (tmp&1){
        tmp=tmp*3+1;
        cnt++;
      } else{
        tmp/=2;
        cnt++;
      }
    }
    ans=cnt+4;
  } 
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
 
d=deque()
n=int(input())
for _ in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        d.appendleft(cmd[1])
    elif cmd[0] == "delete":
        try:
            d.remove(cmd[1])
        except ValueError:
            pass
    elif cmd[0] == "deleteFirst":
        d.popleft()
    else:
        d.pop()
print(*d)



Measured memory_bytes: 69736
#include <stdio.h>

int main(void){
  int N,M,a;
  scanf("%d%d",&N,&M);

  int cnt[N];
  for(int i = 0;i < N;i++) cnt[i] = 0;

  for(int i = 0;i < 2*M;i++){
    scanf("%d",&a);
    cnt[a-1]++;
  }

  for(int i = 0;i < N;i++) printf("%d\n",cnt[i]);


  return 0;
}

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

int main()
{
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0)
			break;

		vector<int> t(n);
		for (int i = 0; i < n; ++i)
			cin >> t[i];

		vector<int> h(m);
		for (int i = 0; i < m; ++i)
			cin >> h[i];

		int diff = accumulate(t.begin(), t.end(), 0) - accumulate(h.begin(), h.end(), 0);

		int ans1 = -1, ans2 = -1;
		for (unsigned int i = 0; i < t.size(); ++i) {
			for (unsigned int j = 0; j < h.size(); ++j) {
				if (2*(t[i]-h[j]) == diff) {
					if (ans1 == -1 && ans2 == -1) {
						ans1 = t[i];
						ans2 = h[j];
					} else {
						if (ans1+ans2 > t[i]+h[j]) {
							ans1 = t[i];
							ans2 = h[j];
						}
					}
				}
			}
		}

		if (ans1 == -1 && ans2 == -1)
			cout << "-1" << endl;
		else
			cout << ans1 << " " << ans2 << endl;

	}

	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [0] + [int(_) for _ in input().split()]
ans = sum(B)
for i in range(N - 1):
    if A[i] + 1 == A[i + 1]:
        ans += C[A[i]]
print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 2005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

int i,j,m,n,p,k,a[N][N],ans;

char c[N][N]; 

pair<int,int> Q[N];

set<int>st;

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;++i) scanf("%s",c[i]+1);
	for (i=1;i<=n;++i)
	{
				for (j=1;j<=m;++j) c[i][j]-=48;
			for (j=1;j<=m;)
			{
				for (k=j+1;k<=m&&(c[i][k]^c[i-1][k])==(c[i-1][j]^c[i][j]);++k);
				for (p=j;p<k;++p) a[i][p]=k-1;
				j=k;
			}
	}
	for (i=1;i<=m;++i) a[1][i]=m;
	ans=m;
	for (i=1;i<=m;++i)
	{
			st.clear();
			for (j=2;j<=n;++j) Q[j-1]=mk(a[j][i],j);
			sort(Q+1,Q+n);
			for (j=1;j<n;)
			{
				for (k=j+1;k<n&&Q[k].fi==Q[j].fi;++k);
				int now=j,L,R;
				for (;j<k;++j)
				{
					 set<int>::iterator it;
					 it=st.lower_bound(Q[j].se);
					 if (it==st.end()) R=n;
					 else R=(*it)-1;
					 if (it==st.begin()) L=2;
					 else --it,L=(*it)+1;
					 ans=max(ans,(R-L+2)*(Q[j].fi-i+1));
				}
				j=now;
				for (;j<k;++j) st.insert(Q[j].se);
			}
	}
	printf("%d\n",ans); 
}
	


Measured memory_bytes: 20096
S = input()

ans = "WA"
if S[0] == "A":
    ans = "AC"
    S = S.replace("A", "a", 1)

count = 0
for i in range(2, len(S) - 1):
    if S[i] == "C":
        count += 1
        S = S.replace("C", "c", 1)
if count != 1:
    ans = "WA"

if not S.islower():
    ans = "WA"

print(ans)


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1000 + 5;
const int MAX_N = 1e5 + 5;

int a[20];
int x[20][20];
int y[20][20];

int count(int k) {
    if (k == 0) return 0;
    return count(k >> 1) + (k & 1);
}

int main() {
    int n;
    int ans = 0;

    cin >> n;
    repeat(i, 1, n + 1) {
        cin >> a[i];
        repeat(j, 1, a[i] + 1) {
            cin >> x[i][j] >> y[i][j];
        }
    }

    for (int bit = 1; bit < (1 << n); bit++) {
        bool ok = true;
        repeat(i, 1, n + 1) {
            if (!(bit & (1 << (i - 1)))) continue;
            repeat(j, 1, a[i] + 1) {
                if (((bit >> (x[i][j] - 1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if (ok) ans = max(ans, count(bit));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
a,b,c,k=map(int,input().split())
ans=0
if(k>0 and a!=0):
    k1=k-min(k,a) 
    ans+=min(k,a) 
    k=k1
if(k>0 and b!=0):
    k=k-min(k,b) 
if(k>0 and c!=0):
    ans=ans-min(k,c)
print(ans)
    

Measured memory_bytes: 9184
function Main(input) {
  if (Number(input) === 0) {
    console.log('pon')
    return
  }
  const tail =  Number(input) % 10
  switch(tail) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      console.log('hon')
      break
    case 0:
    case 1:
    case 6:
    case 8:
      console.log('pon')
      break
    case 3:
      console.log('bon')
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29528
#include <stdio.h>
#include <stdlib.h>

int main(){
	long N;
	scanf("%ld",&N);
	if(N==22)puts("Christmas Eve Eve Eve");
	else if(N==23)puts("Christmas Eve Eve");
	else if(N==24)puts("Christmas Eve");
	else if(N==25)puts("Christmas");
	return 0;	
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
vector<vector<int>> edge(1010,vector<int>(1010,0));
vector<int> vis(1010,0);
int ec = 0;
int vc = 1;

int bfs(int s){
	queue<int> que;
	que.emplace(s);
	ec = 0;
	vc = 1;
	vis[s] = 1;
	while(!que.empty()){
		int v = que.front();
		que.pop();

		for(int i = 0;i < n;i++){
			if(edge[v][i]){
				ec++;
				edge[v][i] = 0;
				edge[i][v] = 0;
				if(!vis[i]){
					vis[i] = 1;
					vc++;
					que.push(i);
				}
			}
		}
	}
	return vc * (vc - 1) / 2 - ec;
}

int main(){
	cin >> n;
	int check = 0;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		for(int j = 0;j < n;j++){
			if(s[j] == 'Y'){
				 edge[i][j] = 1;
				 check++;
			}
		}
	}
	int turn = 0;
	int cou = 0;
	int uc = 0;
	for(int i = 0;i < n;i++){
		if(!vis[i]){
			uc++;
			int t = bfs(i) % 2;
			turn = (turn + t) % 2;
			cou += vc % 2;
			//cout << ec << " " << vc << " " << vc * (vc - 1) / 2 - ec << endl;
		}
	}
	//cout << turn << endl;
	//cout << check << endl;
	if(uc > 3){
		(turn += (cou / 2) % 2) %= 2;
	}
	if(uc == 3){
		if(turn == 0 && cou >= 2){
			turn = 1;
		}
		else if(turn == 0 && cou <= 1){
			turn = 0;
		}
		else if(turn == 1 && cou == 3){
			turn = 0;
		}
		else if(turn == 1 && cou <= 2){
			turn = 1;
		}

	}
	if(turn == 0){
		cout << "Hanako" << endl;
	}
	else{
		cout << "Taro" << endl;
	}
}



Measured memory_bytes: 6684
<?php

$n = intval(trim(fgets(STDIN)));
$listA = [];
$listB = [];
for ($i = 0; $i < $n; $i++) {
    $var = explode(' ', trim(fgets(STDIN)));
    $listA[$i] = intval($var[0]);
    $listB[$i] = intval($var[1]);
}

$sum = 0;
$min = null;
foreach ($listA as $i => $a) {
    if ($a > $listB[$i]) {
        if (is_null($min)) {
            $min = $listB[$i];
        } else {
            $min = min($min, $listB[$i]);
        }
    }
    $sum += $listB[$i];
}
if (is_null($min)) {
    echo 0;
} else {
    echo $sum - $min;
}


Measured memory_bytes: 9460
N = int(input())

def func(x, y, z):
    f = x**2 + y**2 + z**2 + x*y + y*z + z*x
    return f

def hantei(x, y, z):
    if x==y and x==z:
        return 1
    elif x==y or x==z or z==y:
        return 3
    else:
        return 6
    
    
for n in range(N):
    x = 1
    cnt = 0
    while func(x, 1, 1) <= n+1:
        y = x
        while func(x, y, 1) <= n+1:
            z = y
            while func(x, y, z) <= n+1:
                if func(x, y, z) == n+1:
                    cnt += hantei(x, y, z)
                z += 1
            y += 1
        x += 1
    print(cnt)
                    

Measured memory_bytes: 69624
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
const long long mx =1e15;

int main()

{
    ios::sync_with_stdio(0);
    cin.tie(0);
    double t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>s1>>s2;
    cin>>n>>m>>s3;
    if(s3==s1)
    {
        n=n-1;
    }
    if(s3==s2)
    {
        m=m-1;
    }
    cout<<n<<" "<<m<<endl;

}


Measured memory_bytes: 3748
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI    = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, M, X;
    cin >> N >> M >> X;
    //
    struct Book
    {
    public:
        // price
        ll C;
        // skill
        std::vector<ll> A;
    };
    //
    vector<Book> books;
    rep(i, N)
    {
        Book book;
        cin >> book.C;
        rep(j, M)
        {
            ll a;
            cin >> a;
            book.A.push_back(a);
        }
        books.push_back(book);
    }
    //
    std::vector<ll> skills(N,0);
    uint16_t total = 1 << N;
    ll minCost = std::numeric_limits<ll>::max();
    for (uint16_t bits = 0; bits < total; ++bits)
    {
        // 
        std::fill(skills.begin(), skills.end(), 0);
        uint16_t b = bits;
        ll cost = 0;
        rep(i,N)
        {
            if (b & 1)
            {
                auto& book = books[i];
                cost += book.C;
                rep(j, M)
                {
                    skills[j] += book.A[j];
                }
            }
            b >>= 1;
        }
        //
        bool valid = true;
        rep(i, M)
        {
            valid &= (skills[i] >= X);
        }
        if (valid && (cost < minCost))
        {
            minCost = cost;
        }
    }
    if (minCost == std::numeric_limits<ll>::max())
    {
        cout << -1;
    }
    else
    {
        cout << minCost;
    }

    return 0;
}

Measured memory_bytes: 3164
#include<iostream>
using namespace std;
typedef long long ll;
ll h[30],n;
const ll inf=1e18;
ll solve(int l,int r,ll a,ll b) {
    if(r-l<=1)return 0;
    ll ans=inf;
    for(int i=l+1;i<=r-1;i++) {
        ans=min(ans,solve(l,i,a,a+b)+solve(i,r,a+b,b)+h[i]*(a+b));
    }
    return ans;
    
}
int main() {
    cin>>n;for(int i=1;i<=n;i++)cin>>h[i];
    cout<<solve(1,n,1,1)+h[1]+h[n];
    return 0;
}//

Measured memory_bytes: 3636
#include<stdio.h>
 
int main(){
  int A,B,C,D;
  
  scanf("%d",&A);
  
  B=A/1.08;
  C=B*1.08;
  D=(B+1)*1.08;
  
  if(C == A){
    printf("%d",B);
  }else if(D == A){
    printf("%d",B+1);
  }else{
    printf(":(");
  }
  
  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;

void solve(){
    int a,b,c;
    int x;
    cin >> a >> b >> c >> x;
    int count = 0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(x==i*500+j*100+k*50) count++;
            }
        }
    }
    cout << count << endl;
}

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


Measured memory_bytes: 256
// abc109_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int H, W;
    cin >> H >> W;
    vector<vector<int>> S(H, vector<int>(W, 0));

    int res = 0;
    REP(i, H) REP(j, W) {
        cin >> S[i][j];
        S[i][j] %= 2;
        res += S[i][j];
    }


    vector<tuple<int, int, int, int>> ans;

    REP(i, H){
        REP(j, W-1){
            if (S[i][j]){
                ans.emplace_back(i+1, j+1, i+1, j+2);
                S[i][j+1] += 1; S[i][j+1] %= 2;
            }
        }
    }

    REP(i, H-1){
        if (S[i][W-1]){
            ans.emplace_back(i+1, W, i+2, W);
            S[i+1][W-1] += 1; S[i+1][W-1] %= 2;
        }
    }

    print(ans.size());
    for (auto x: ans){
        print(get<0>(x), get<1>(x), get<2>(x), get<3>(x));
    }

    return 0;
}


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

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

    int h, w, k;
    cin >> h >> w >> k;

    vector<string> a(h);
    rep(i, h) cin >> a[i];

    vector<vector<int>> res(h, vector<int>(w, 0));
    int cnt = 1;
    rep(i, h){
        int s_cnt = 0;
        rep(j, w) if(a[i][j] == '#') ++s_cnt;

        if(s_cnt == 1){
            rep(j, w) res[i][j] = cnt;
            ++cnt;
        }
        int l_cnt = 1;
        if(s_cnt > 1){
            rep(j, w){
                res[i][j] = cnt;

                if(a[i][j] == '#') {
                    if(cnt<k && l_cnt<s_cnt) {
                        ++cnt;
                        ++l_cnt;
                    }

                }
            }
            ++cnt;
        }
    }

    rep(i, h) rep(j, w){
        if(res[i][j] == 0){
            if(i==0) res[i][j] = res[i+1][j];
            else res[i][j] = res[i-1][j];
        }
    }

    for(int i = h-2; i >= 0; --i) rep(j, w){
        if(res[i][j] == 0){
            res[i][j] = res[i+1][j];
        }
    }

    rep(i, h){
        rep(j, w) cout << res[i][j] << " ";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
//package atcoder.beginner_178;

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main (String[] args) throws Exception {

        String s = "-1000000000 0 -1000000000 0";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); long a = nlo(), b=nlo(), c=nlo(), d=nlo();
        if (a<=0 && b<=0 && c>=0 && d>=0) {
            bw.write( (b*c) + "\n");
        } else if (a>=0 && b>=0 && c<=0 && d<=0) {
            bw.write( (a*d) + "\n");
        } else {
            bw.write( Math.max(a*c, b*d) + "\n");
        }
        bw.flush();
    }

    static BufferedReader br; static BufferedWriter bw; static StringTokenizer st;
    static void rl() throws Exception{ st = new StringTokenizer(br.readLine()); }
    static long nlo(){ return Long.parseLong(st.nextToken()); }
    static int nin(){ return Integer.parseInt(st.nextToken()); }
    /*private static void te(){}*/
    static double ndo(){ return Double.parseDouble(st.nextToken()); }
    static char[] nca(){ return st.nextToken().toCharArray(); }
}


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

using namespace std;

long long dp[3005][3005];
long long a[3005];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

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

    for (int i=n;i>=0;i--)
        for(int j=i;j<n;j++)
        dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);

    cout << dp[0][n-1];
}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;


int main() {
    ll A,B,C,D;
    bool flag=false;
    cin>>A>>B>>C>>D;
    while(A>0||C>0){
        C-=B;
        if(C<=0){flag=true; break;}
        A-=D;
        if(A<=0){break;}
    }
    if(flag){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;

#define EPS 1e-8

int main(){

	vector<int> a(4);
	vector<int> b(4);
	
	while(cin >> a[0]){
		vector<bool> used(10, false);
		int hit = 0, blow = 0;
		used[a[0]] = true;
		REP(i, 1, 4){
			cin >> a[i];
			used[a[i]] = true;
		}
		rep(i, 4){
			cin >> b[i];
			if(a[i] == b[i]) hit++;
			else if(used[b[i]]) blow++;
		}
		
		cout << hit << " " << blow << endl;
		
	}

	
	return 0;
}

Measured memory_bytes: 3020
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<u32>().ok().unwrap());
    let mut i = 0;
    while i < 5 {
        let x = it.next().unwrap();
        if x == 0 {
            println!("{}", i + 1);
        }
        i += 1;
    }
}


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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define debug(x) cout << x << endl;
#define sz(x) (int)x.size()
#define all(x) (x.begin(), x.end())
#define rall(x) (x.rbegin(), x.rend())
#define MAXN 10005
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define int long long
#define endl '\n'

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <vi> matriz;

string k;
int d;
int dp[MAXN][105][2];

int calc(int pos, int res, bool ok){
    // cout << pos << " " << res << " " << ok << endl;
    if(dp[pos][res][ok] != -1) return dp[pos][res][ok];

    dp[pos][res][ok] = 0;

    if(pos == 0){
        for(int i = 1; i <= (ok ? (k[0] - '0') : (k[0] - '0' - 1)); i++){
            // cout << pos << " " << res << " " << ok << "ss" << endl;
            if((res + i) % d == 0){
                dp[pos][res][ok]++;
                dp[pos][res][ok] = dp[pos][res][ok] % MOD;
            }
        }
    } else {
        for(int i = 0; i <= 9; i++){
            bool st = (i < (k[pos] - '0') ? 1 : i > (k[pos] - '0') ? 0 : ok);
            if((res + i) % d == 0 && i != 0){
                // cout << pos << " " << res << " " << ok << endl;
                dp[pos][res][ok] = (dp[pos][res][ok] + calc(pos - 1, 0, st) + 1) % MOD;
            } else dp[pos][res][ok] = (dp[pos][res][ok] + calc(pos - 1, (res + i) % d, st)) % MOD;
        }
    }
    return dp[pos][res][ok];
}

int32_t main(){
    fastio
    cin >> k >> d;
    memset(dp, -1, sizeof(dp));
    cout << calc(sz(k) - 1, 0, 1) << endl;

    return 0;
}

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

int main(){
int n,c=0;
cin>>n;

for(int i=1;i<10;i++)
  for(int j=1;j<10;j++){

    if(i*j==n){
        c=1;
        break;
    }
}

if(c)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;


return 0;
}


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

int main(int argc, char *argv[]) {
  int n, m, c;
  std::cin >> n >> m >> c;
  std::vector<int> b(m);
  for (int i = 0; i < m; ++i)
    std::cin >> b.at(i);

  int count = 0;
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int i = 0; i < m; ++i) {
      int a;
      std::cin >> a;
      sum += a * b.at(i);
    }
    if (sum + c > 0)
      ++count;
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

module String =
    /// Converts a string into a list of characters.
    let explode (s:string) =
        [for c in s -> c]

    /// Converts a list of characters into a string.
    let implode (xs:char list) =
        let sb = System.Text.StringBuilder(xs.Length)
        xs |> List.iter (sb.Append >> ignore)
        sb.ToString()

let rec doit acc s =
    match s with
    | 'B'::t when acc = [] -> doit acc t
    | 'B'::t -> doit (List.tail acc) t
    | h::t -> doit (h::acc) t
    | [] -> List.rev acc

Console.ReadLine()
|> String.explode
|> doit []
|> String.implode
|> Console.WriteLine


Measured memory_bytes: 14048