akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x;
    cin >> x;
    vector<pair<pii, int>> edges;
    int k = 18;
    bool flag = true;
    int nx = 0;
    if ((x>>19)&1){
        flag = false;
        nx = (1 << 19);
    }
    repr(i,k,-1)
    {
        if (flag){
            edges.eb(mp(mp(19 - i, 19 - i + 1), 0));
            if ((x>>i)&1){
                flag = false;
                nx += (1 << i);
            }
            continue;
        }
        edges.eb(mp(mp(19 - i, 19 - i + 1), 0));
        edges.eb(mp(mp(19 - i, 19 - i + 1), (1 << i)));
        if ((x>>i)&1){
            edges.eb(mp(mp(1, 19 - i + 1), nx));
            nx += (1 << i);
        }
    }
    cout << 20 << " " << edges.size() << ENDL;
    rep(i,edges.size()){
        cout << edges[i].F.F << " " << edges[i].F.S << " " << edges[i].S << ENDL;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b, c;

    scanf("%d %d %d ", &a, &b, &c);

    b=a+b;
    a=b-a;
    b=b-a;

    c=c+a;
    a=c-a;
    c=c-a;











    printf("%d %d %d",a,b,c);

    
    return 0;
}

Measured memory_bytes: 128
using System;

namespace Testcode
{
    class Program
    {
        
        static void Main(string[] args)
        {         
            while (true)
            {
                string[] d = Console.ReadLine().Split();
                var a = int.Parse(d[0]);
                string b = (d[1]);
                var c = int.Parse(d[2]);

               
               if (b == "+")
                {
                    Console.WriteLine(a + c);
                }

                if (b == "-")
                {
                    Console.WriteLine(a - c);
                }

                if (b == "*")
                {
                    Console.WriteLine(a * c);
                }

                if (b == "/")
                {
                    Console.WriteLine(a / c);
                }

                if (b == "?") 
                {
                    break;
                }

            }
        
            
        }
       
    }
}


Measured memory_bytes: 17944
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
	int n,d,x,num,i;
	
	while (scanf("%d",&n)==1)
	{
		num=0;
		
		scanf("%d%d",&d,&x);
		
		num=x;
		
		for (i=0;i<n;i++)
		{
			scanf("%d",&x);
			num=num+1+(d-1)/x;
		}
		
		printf("%d\n",num);
	}
		
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
 
// replace ll with pair if multiset needed
typedef tree<pair<int,int>, null_type, greater<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;
 
const ll INF = 1e9 + 9;
const ll MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<int> gen(0,n-1);

const int SIZE = 100;

bool adj[SIZE][SIZE];
long long dp[(int)5e6];
int n;

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

	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> adj[i][j];
		}
	}

	dp[0] = 1;
	for(int i = 1; i < (1 << n); i++){
		int ktory = __builtin_popcount(i) - 1;
		for(int j = 0; j < n; j++){
			if(i & (1 << j)){
				if(adj[ktory][j]){
					dp[i] = (dp[i] + dp[i ^ (1 << j)]) % MOD;
				}
			} 		
		}
	}
	
	cout << dp[(int)(1 << n) -1];

}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

signed main() {
	string a, b, c;
	cin >> a >> b >> c;
	puts(a.back() == b[0] and b.back() == c[0] ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    int max = 0;
    int count = 0;

    for (int i = 0;i<3 ;i++ ) {
      if (s.charAt(i)=='R') {
        count++;        
      }else{
        count = 0;
      }
      max = Math.max(max,count);
    }
    System.out.println(max);

  }
}


Measured memory_bytes: 35528
#include <iostream>
#include <cstdio>

using namespace std;

#define MAX 1000

int dat[MAX];
int ind[MAX];
int dp[21][1000];
int n;

bool solve(int i,int m){
    //cout<<"solve i:"<<i<<" m:"<<m<<" n:"<<n<<endl;
    if(m==0){
        return true;
    }else if(i<n){
        if(solve(i+1,m))
	    return true;
        return solve(i+1,m-dat[i]);
    }
    return false;
}

int main(){
    int m;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
	scanf("%d",&dat[i]);
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++){
	scanf("%d",&ind[i]);
    }
    for(int i=0;i<m;i++){
        if(solve(0,ind[i])){
	    printf("yes\n");
        }else{
	    printf("no\n");
        }
    }
    return 0;
}

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

struct info{
	ll len, val, up_min, down_min;
	info(): len(1), val((ll)1e6 * (ll)1e6), up_min(val), down_min(val){}
	info(const ll x): len(1), val(x), up_min(x), down_min(x){}
	info(const info& a, const info& b):
		len(a.len + b.len),
		val(-1),
		up_min(min({a.up_min, a.len + b.up_min, (ll)1e6 * (ll)(1e6)})),
		down_min(min({a.down_min + b.len, b.down_min, (ll)1e6 * (ll)(1e6)})){} };

struct arbint{
	ll n, big_delta = 0;
	vector<info> buf;
public:
	arbint(const ll N): n(1 << (ll)ceil(log2(N))), buf(2*n){
		for(ll i = n-1; i; --i) buf[i] = info { buf[2*i], buf[2*i+1] }; }
	void update_delta(const ll x){ big_delta += x; }
	void update(ll poz, const ll new_val){
		buf[poz+=n] = info { new_val - big_delta };
		for(poz /= 2; poz; poz /= 2)
			buf[poz] = info { buf[2*poz], buf[2*poz+1] }; }
	info query(ll st, ll dr){
		info rez_st, rez_dr;
		rez_st.len = rez_dr.len = 0;
		for(st += n, dr += n+1; st < dr; st /= 2, dr /= 2){
			if(st%2) rez_st = info { rez_st, buf[st++] };
			if(dr%2) rez_dr = info { buf[--dr], rez_dr }; }
		auto rez = info { rez_st, rez_dr };
		rez.up_min += big_delta;
		rez.down_min += big_delta;
		return rez; }
	ll stupid_small_cost(){
		ll rez = (ll)1e6 * (ll)1e6;
		for(ll i = n; i < 2*n; ++i) rez = min(rez, buf[i].val + big_delta);
		return rez; } };

int main(){
	ll n, q, a, b;
	cin >> n >> q >> a >> b;
	arbint aa(n + 100);
	ll p0 = a;
	aa.update(b, 0);

	for(ll i = 0, x; i < q; ++i){
		cin >> x;
		const ll other_cost = min<ll>(
			aa.query(1, x).down_min,
			aa.query(x, n).up_min);
		const ll prev_cost = max(p0 - x, x - p0);
		
		aa.update_delta(prev_cost);
		aa.update(p0, other_cost);
		p0 = x; }
	cout << aa.stupid_small_cost() << endl;
	return 0; }


Measured memory_bytes: 16640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    long long n,a,b,c,d;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        cin>>c;
        if(c<a || c>=b)d++;
    }
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( " " ).map( Number );
  var x1 = data[0];
  var y1 = data[1];
  var x2 = data[2];
  var y2 = data[3];
  
  var d = Math.sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) );
  console.log( d );
});

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

int main() {
  int n,rieki = 0;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for(int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  for(int j = 0; j < n; j++){
    cin >> c.at(j);
    if(c.at(j) < v.at(j)){
      rieki += v.at(j) - c.at(j);
    }
  }
  cout << rieki << endl;
}


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

#define ll long long

int main() {
  int k, n;
  cin >> k >> n;
  int a[n];
  int ans=0;
  for(int i=0; i<n; ++i) {
    cin >> a[i];
  }
  ans = abs(a[n-1]-a[0]);
  a[0]+=k;
  for(int i=1; i<n; ++i) {
    if(ans > abs(a[i-1]-a[i])) {
      ans = abs(a[i-1]-a[i]);
    }
    a[i]+=k;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4276
/*
I believe on myself and I will achieve
this->author = Fuad Ashraful Mehmet, CSE ,University of Asia Pacific
Todo:
https://codeforces.com/problemset/problem/1365/E
*/
#include<bits/stdc++.h>
#define forn(i,n) for(int i=0;i<(int)n;++i)
#define all(o) (o).begin(),(o).end()
#define sz(o) (o).size() 
#define dbg(o)  cerr<<"at "<<__LINE__<<" response = "<<o<<endl;
#define pb push_back
using namespace std;

template<class T> void print(T & x){ cout << x; }
template<class T> void print(vector<T> & v) {
	cout << "{";
	if (sz(v)) print(v[0]);
	for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]);
	cout << "}\n";
}

typedef long long ll;
const int N=2e5+5;
int q,k,m,n,cs=1;
const ll mod=998244353;
ll tree[N*4],lazy[N*4],pwr[N],base[N*4];

void build(int l,int r,int nd=1)
{
	if(l==r)
	{
		base[nd]=tree[nd]=pwr[n-r];
		return;
	}

	int mid=(l+r)>>1;
	build(l,mid,nd<<1);
	build(mid+1,r,nd<<1|1);
	tree[nd]=tree[nd<<1]+tree[nd<<1|1];
	base[nd]=base[nd<<1]+base[nd<<1|1];
	tree[nd]%=mod;
	base[nd]%=mod;
	return;
}// end func

void push_down(int nd,int l,int r)
{

	if(lazy[nd])
	{
		tree[nd]=1LL*lazy[nd]*base[nd]%mod;

		if(l!=r)
		{
			lazy[nd<<1]=lazy[nd<<1|1]=lazy[nd];
		}

		lazy[nd]=0;
	}
	return;
}
void update(int l,int r,int x,int y,int d,int nd=1)
{
	push_down(nd,l,r);
	
	if(l>y or r<x)return;

	if(l>=x and r<=y)
	{
		lazy[nd]=d;
		push_down(nd,l,r);
		return;
	}

	int mid=(l+r)>>1;
	update(l,mid,x,y,d,nd<<1);
	update(mid+1,r,x,y,d,nd<<1|1);

	tree[nd]=tree[nd<<1]+tree[nd<<1|1];
	tree[nd]%=mod;
	return;
}
void HalfDead(){
	
	pwr[0]=1;
	for(int i=1;i<N;++i)
	{
		pwr[i]=1LL*pwr[i-1]*10%mod;
	}
	cin>>n>>q;
	build(1,n);


	int x,y,d;
	while(q--)
	{
		cin>>x>>y>>d;
		update(1,n,x,y,d);
		cout<<tree[1]<<endl;
	}
}// end func
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(nullptr);  cout.tie(0);
	// cout<<setprecision(10)<<fixed;
	int tc=1;
	//cin>>tc;
	while(tc--){
		HalfDead();
	}
	  return 0;
}

Measured memory_bytes: 17476
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 10000007;

int n;
int q[N];

void solv()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = i; j <= n; j += i)
        {
            ++q[j];
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i)
        ans += i * 1LL * q[i];
    printf("%lld\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 42888
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
using namespace std;
ll a,b;
int32_t main(){
cin>>a;
cin>>b;
if(b%a==0) cout<<a+b;
else cout<<b-a;
return 0;}


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	ll n, X, Y;
	cin >> n >> X >> Y;
	ll a[n] = {0};
	fo(i, 1, n-1){
		fo(j, i+1, n){
			ll x = min(j-i, min(abs(X-i) + abs(Y-j) + 1, abs(Y-i) + abs(X-j) + 1));
			a[x]++;
		}
	}
	fo(i, 1, n-1){
		cout << a[i] << endl;
	}
}

int main() {
	IOS;
	//io_set();
	ll tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main (){
 int N;
 cin >> N;
 string H;
 int check = 0;
 for (int i; i < N; i++){
  cin >> H; 
  if (H == "Y"){
   check = 1 ;
   break;
  } 
  }
if (check == 0){
  cout << "Three" << endl;
}else{
  cout << "Four"  << endl;
}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int mn = 999;
  for(int i = 0;i < 26;i++){
    int mx = 0;
    for(int j = 0;j < str.size();j++){
      if(str[j] != 'a'+i){
	int k;
	for(k = j+1;k < str.size();k++){
	  if(str[k] == 'a'+i) break;
	}
	mx = max(mx, k-j);
      }
    }
    mn = min(mn, mx);
  }

  cout << mn << endl;

  return 0;
}


Measured memory_bytes: 256
fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun main(args: Array<String>) {
    val (a, b, c) = readInts().sorted()
    val d = c - a + c - b
    println(if (d == 0) 0 else if (d % 2 == 0) d / 2 else d / 2 + 2)
}


Measured memory_bytes: 37908
#include <iostream>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  int p = 0;
  int q = 0;
  
  for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    if(a > p){
      p = a;
      q = b;
    }
  }
  
  cout << p + q << endl;
  
  return 0;
}

    

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define MN 40002
#define MM 5000001
#define ll long long
#define ld long double
#define inf 0x7fffffff
#define clz 1000000007
#define ers(arr,val) memset(arr,val,sizeof(arr));
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,b,a) for(int i=(b);i>=(a);i--)
#define repe(i,u) for(int i=h[u];i;i=e[i].nx)
using namespace std;
char s[200001];
int a[200001];
int n;
ll Ans=0;
int main(){
	scanf("%s",s);
	n=strlen(s);
	rep(i,0,n-1){
		if(s[i]=='B') a[i]++;
		a[i]+=a[i-1];
		if(s[i]=='W') Ans+=1ll*a[i];
	}
	printf("%lld\n",Ans);
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cmath>
#include<cctype>
#include<string>
#include<iomanip>

#define rep(i,start,n) for(int i=start ; i<n ; i++)
#define REP(k,start,n) for(int k=start ; k<n ; k++)
#define Rep(j,start,n) for(int j=start ; j<=n ; j++)


using namespace std;

  int surface[100][6];

  void turn_n(int n){                                 //n??????????????¢???????????¨???

    int temp = surface[n][0];
    surface[n][0] = surface[n][1];
    surface[n][1] = surface[n][5];
    surface[n][5] = surface[n][4];
    surface[n][4] = temp;
  }
  void turn_e(int n){                                 //e??????????????¢???????????¨???
    int temp = surface[n][0];
    surface[n][0] = surface[n][3];
    surface[n][3] = surface[n][5];
    surface[n][5] = surface[n][2];
    surface[n][2] = temp;
  }
  void turn_s(int n){                                 //s??????????????¢???????????¨???
    rep(i,0,3) turn_n(n);
  }
  void turn_w(int n){                                 //w??????????????¢???????????¨???
    rep(i,0,3) turn_e(n);
  }

  void top_print(){                                 //????????????????????£???????????¨???
    cout << surface[0] << endl;
  }

void turn(char c , int n){
   if(c=='E') turn_e(n);
   else  if(c=='W') turn_w(n);
   else  if(c=='S') turn_s(n);
   else  if(c=='N') turn_n(n);
}


int main(){

  int x;
  int ans = 0;                                   //????????¨??????????????°?????????
  cin >> x;

  REP(k,0,x){
    rep(i,0,6){
      cin >> surface[k][i];                         //???????????????????????\???
    }
  }


  rep(i,0,x) {
        Rep (j,i+1,x) {

            char SWS[10]={"SSSSWSSSS"};
            REP(k,0,10){
                if(surface[i][1] == surface[j][1]) break;
                turn(SWS[k],j);
            }

            REP(k,0,4){
                if(surface[i][0] == surface[j][0]){
                    if(surface[i][1] == surface[j][1] && surface[i][2]== surface[j][2] && surface[i][3]==surface[j][3] && surface[i][4] == surface[j][4] && surface[i][5] == surface[j][5])
                        ans++;
                }
                turn('W',j);
            }
        }
    }
/////////////////////////////////////
//Yes or No?????¨???
////////////////////////////////////
  if (ans == 0){
      cout << "Yes" <<endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  }

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

#define rev(v) (v).begin(),(v).end()
#define quick ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


bool is(string s1)
{
    string st = s1;
    reverse(rev(s1));
    return (st==s1);
}
int main()
{
    quick;
    string s1;
    cin >> s1;
    int l = s1.length();
    bool x=is(s1);
    string y=s1.substr(0,(l-1)/2);
    string z=s1.substr((l+3)/2-1,l-1);
    bool x2=is(y);
    bool x3=is(z);
    if(x&&x3&&x2)
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
return 0;
}

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

int main(){
  string S;
  cin >> S;
  char a=S.at(0),b=S.at(1),c=S.at(2),d=S.at(3);
  bool ok=false;
  if(a==b){
    if(c==d) ok=true;
  }
  if(a==c){
    if(b==d) ok=true;
  }
  if(a==d){
    if(b==c) ok=true;
  }
  if(a==b&&b==c&&c==d) ok=false;
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
/*int main(void){
    rep(i,5){
        int a;
        cin>>a;
    if(a==0) cout<<i+1<<endl;
    }
    return 0;
}*/
//////////////////
//  B
/*int main(void){
    int x,y;
    cin>>x>>y;
    string ret="No";

    for(int i=0;i<=x;i++){
        if(i*4+(x-i)*2==y){
            ret="Yes";
            break;
        }

    }
    cout<<ret<<endl;

    return 0;
}*/
//////////////////
//  C
int main(void){
    int x,n;cin>>x>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    int abs=0;
    while(1){
        int check=x-abs;
        int ret=1;
        for(int i=0;i<n;i++){
            if(check==a[i]){
                ret=0;
                break;
            }
        }
        if(ret==1){cout<<check<<endl;return 0;}

        check=x+abs;
        for(int j=0; j<n;j++){
            if(check==a[j]){
                ret=1;
                break;
            }
        }
        if(ret==0){cout<<check<<endl;return 0;}
        else abs++;
    }
}
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


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

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<long long> dp(n,1000000000000000),v;
    for( int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        v.push_back(b);
    }
    dp[0]=0;
    dp[1]=abs(v[0]-v[1]);
    for( int i = 2; i < n; i++)
    {
        for( int j = 1; j <= k; j++)
        {
            if(i<j)
            {
                break;
            }
            dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
        }
    }
    cout << dp[n-1];
}



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

int main(){
  int x, y;
  char X, Y;
  cin >> X >> Y;
  x = X;
  y = Y;
  if(x == y){
    cout << "=";
  }
  else if(x > y){
    cout << ">";
  }
  else{
    cout << "<";
  }
}

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

using namespace std;

int main()
{
    int n {0}, w {0};
    cin >> n >> w;
    vector < pair <int, int> > p (n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    long long int dp[w + 1][n + 1];
    for (int i = 0; i <= w; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            dp[i][j] = 0;
        }
    }
    for (int i = 0; i <= w; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (i + p[j].first <= w)
            {
                for (int k = j + 1; k <= n; k++)
                {
                    dp[i + p[j].first][k] = max(dp[i + p[j].first][k], dp[i][j] + p[j].second);
                }
            }
        }
    }
    long long int maximum {0};
    for (int i = 0; i <= w; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            maximum = max(maximum, dp[i][j]);
        }
    }
    cout << maximum << endl;
}

Measured memory_bytes: 82440
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a,b;
  cin >> a ;
  cin >> b ;
  if (a == 'H' ){
    if (b == 'H') cout << "H" << endl;
    else if (b == 'D') cout << "D" << endl;
  }
  else if (a == 'D'){
    if (b == 'H') cout << "D" << endl;
    else if (b == 'D') cout << "H" << endl;
  }
  return 0;
}



Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a;
	vector<string> s;
	for(int i=0;i<n;i++){
		cin>>a;
		sort(a.begin(),a.end());
		s.push_back(a);
	}
	sort(s.begin(),s.end());
	int long long b=0,c=0;
	for(int i=1;i<n;i++){
		if(s[i]==s[i-1]){
			b++;
		}
		else{
			c+=(b*b+b)/2;
			b=0;
		}
	}
	c+=(b*b+b)/2;
	b=0;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

struct Edge {
  int to;
  i64 cost;

  Edge(int _to, i64 _cost) : to(_to), cost(_cost) {}
};

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

  int h, w;
  cin >> h >> w;
  vvt<bool> grid(h, vt<bool>(w, false));
  rep(i, 0, h) {
    string s;
    cin >> s;
    rep(j, 0, w) {
      if(s[j] == '.') grid[i][j] = true;
    }
  }

  vvt<int> dp(h + 1, vt<int>(w + 1, 0));
  dp[1][1] = 1;
  rep(i, 0, h) {
    rep(j, 0, w) {
      if(grid[i][j]) {
        dp[i + 1][j + 1] += dp[i][j + 1] + dp[i + 1][j];
        dp[i + 1][j + 1] %= mod;
      }
    }
  }
  cout << dp[h][w] << endl;
}


Measured memory_bytes: 4352
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;

using namespace std;


int main(){ 
    long long N, M;
    cin >> N;

    M = sqrt(N);
    int ret = log10(N) + 1;

    long long sub;

    for(int i = M; i >= 1; --i){
        if(N % i == 0){
            sub = N / i;
            ret = min<long long>(ret, log10(max(M, sub)) + 1);
        }
    }

    cout << ret;
}



Measured memory_bytes: 384
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 300007;
int a[maxN], dp[maxN];

int main() {
    int n = read(), i, s[2] = {0, 0};
    
    for (i = 1; i <= n; ++i)
        a[i] = read(), s[i & 1] += a[i];
    
    if (n & 1) {
        int l = 0, r = s[0] + s[1], mid;
        dp[0] = a[1];
        while (l < r) {
            mid = (l + r + 1) >> 1;
            for (i = 2; i < n; i += 2) {
                dp[i] = dp[i - 2] - a[i];
                if (dp[i - 2] >= mid)
                    dp[i] = max(dp[i], 0);
                dp[i] += a[i + 1];
            }
            dp[n - 1] >= mid ? l = mid : r = mid - 1;
        }
        l += s[0];
        if (l > s[1])
            printf("%d %d\n", l, s[0] + s[1] - l);
        else
            printf("%d %d\n", s[1], s[0]);
    }
    else
        printf("%d %d\n", max(s[0], s[1]), min(s[0], s[1]));
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int main(){

  string s;
  while(cin>>s&&s!="0000"){
    set<char> st;
    for(int i=0;i<4;i++)
      st.insert(s[i]);
    if(st.size()==1)cout<<"NA"<<endl;
    else{
      for(int i=0;;i++){
        if(s=="6174"){
          cout<<i<<endl;
          break;
        }
        string ls,ss;
        sort(s.begin(),s.end());
        ss=s;
        sort(s.begin(),s.end(),greater<char>());
        ls=s;
        int diff=StringToInt<int>(ls)-StringToInt<int>(ss);
        string ns=IntToString(diff);
        while(ns.size()<4)ns='0'+ns;
        s=ns;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char s[100001];
int l;

int dp[100001];
bool rec(int i)
{
    if (i == l)
        return true;
    if (i + 5 > l)
        return false;
    if (dp[i] != -1)
        return dp[i];

    bool ans = false;
    if (s[i] == 'd' && s[i + 1] == 'r' && s[i + 2] == 'e' && s[i + 3] == 'a' && s[i + 4] == 'm') {
        if (i + 7 <= l && s[i + 5] == 'e' && s[i + 6] == 'r')
            ans = ans || rec(i + 7);
        ans = ans || rec(i + 5);
    } else if (s[i] == 'e' && s[i + 1] == 'r' && s[i + 2] == 'a' && s[i + 3] == 's' && s[i + 4] == 'e') {
        if (i + 6 <= l && s[i + 5] == 'r')
            ans = ans || rec(i + 6);
        ans = ans || rec(i + 5);
    }
    return dp[i] = ans;
}

int main()
{
    scanf("%s", s);
    l = strlen(s);

    fill(dp, dp + 100001, -1);

    if (rec(0))
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
	int n, f = 0;
	cin >> n;
	for (int i = 1; i < 1e7; i++)
	{
		f = (f * 10 + 7) % n;
		if (!f)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 3608
package main

import "fmt"

func main() {
	var K, S, cnt int
	fmt.Scanf("%d %d", &K, &S)

	for X := 0; X <= S && X <= K; X++ {
		for Y := 0; Y <= (S-X) && Y <= K; Y++ {
			r := S - X - Y
			if r >= 0 && r <= K {
				cnt++
			}
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main { //B

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();

		String TT = T + T;

		if(TT.contains(S)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21844
#include<iostream>

int main()
{
    int N,X,T = 0;
    int i = 1;
    int hasu,josan =0;

    std::cin >> N >> X >> T;
    
    josan = N / X;

    if( 0 < N % X )
    {
        josan++;       
    }    

    std::cout << T*josan;

    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <algorithm>
using namespace std;
int W, N, v[1000], w[1000], dp[1001][1001], c, r;
int main() {
	while (~scanf("%d", &W)) {
		if (!W) break;
		scanf("%d", &N);
		for (int i = 0; i < N; i++) scanf("%d,%d", &v[i], &w[i]);
		for (int i = 1; i <= N; i++) {
			for (int j = 0; j <= W; j++) {
				dp[i][j] = dp[i - 1][j];
				if (j >= w[i - 1]) {
					dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
				}
			}
		}
		printf("Case %d:\n", ++c);
		printf("%d\n", dp[N][W]);
		printf("%d\n", lower_bound(dp[N], dp[N] + W + 1, dp[N][W]) - dp[N]);
	}
	return 0;
}

Measured memory_bytes: 6628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;cin>>A>>B;
  //n本目とn+1本目の差はn+1
  int n=B-A-1;
  int ans=0;
  for(int i=1;i<n+1;i++)ans+=i;
  cout<<ans-A;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,m,dp[100005][3],s,t;
vector<int>g[100005];
int main(void){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		g[--a].PB(--b);
	}
	cin>>s>>t;
	s--,t--;
	for(int i=0;i<n;i++){
		dp[i][0]=-1;
		dp[i][1]=-1;
		dp[i][2]=-1;
	}
	dp[s][0]=0;
	queue<P>bfs;
	bfs.push(P(s,0));
	while(!bfs.empty()){
		int v=bfs.front().F,k=bfs.front().S,c=dp[v][k];
		bfs.pop();
		for(int i=0;i<g[v].size();i++){
			int u=g[v][i];
			if(dp[u][(k+1)%3]==-1){
				dp[u][(k+1)%3]=c+1;
				bfs.push(P(u,(k+1)%3));
			}
		}
	}
	if(dp[t][0]!=-1)dp[t][0]/=3;
	cout<<dp[t][0]<<endl;
}

Measured memory_bytes: 7040
n = int(input())
arr = list(map(int, input().split()))

for i in range(0, len(arr)-1):
    for j in range(i+1, len(arr)):
        if arr[i]<arr[j]:
            buf = arr[i]
            arr[i] = arr[j]
            arr[j] = buf

sa = 0
sb = 0
for i in range(0, len(arr)):
    if i % 2 == 0:
        sa += arr[i]
    else:
        sb += arr[i]
print(sa - sb)


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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e10+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ 
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

void solve() {
    int n, m;
    cin >> n >> m;
    int h[n+1];
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    vi g[n+1];
    for(int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        bool f = 1;
        for(auto u : g[i]){
            if(h[u] >= h[i])f = 0;
        }
        if(f)ans++;
    }
    cout << ans << endl;
}


signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    //cin >> t;

    
    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}


Measured memory_bytes: 10220
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define MAX_N (100010)

int main()
{
	ll N, M;
	scanf("%lld%lld", &N, &M);

	ll res = 1;
	for (ll i = 1; i * i <= M; i++) {
		if (M % i != 0)
			continue;

		ll rest = M - (i * (N - 1));
		if (rest > 0 && (rest % i == 0)) {
			res = max(res, i);
		}

		rest = M - ((M / i) * (N - 1));
		if (rest > 0 && (rest % (M / i) == 0)) {
			res = max(res, M / i);
		}
	}

	printf("%lld\n", res);

	return 0;
}


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

using namespace std;

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

    vector<bool> sunuke(N, false);
    for (int k = 0; k < K; ++k)
    {
        int D;
        cin >> D;

        for (int d = 0; d < D; ++d)
        {
            int A;
            cin >> A;
            --A;
            sunuke[A] = true;
        }
    }

    int count = 0;
    for (int n = 0; n < N;++n)
    if(!sunuke[n])
        ++count;

    cout << count;
}

Measured memory_bytes: 3560
n = int(input())
arr = list(map(int,input().split()))
d = {}

for a in arr:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1

ans = 0
for key in d.keys():
    if d[key] < key:
        ans += d[key]
    elif d[key] == key:
        continue
    else:
        ans += (d[key]-key)
print(ans)


Measured memory_bytes: 17780
#include<stdio.h>
#include<iostream>
#include<stack>
#include<algorithm>
#define MAX 1400

using namespace std;

struct Rectangle { int height; int pos; };

int getLargestRectangle(int size, int buffer[]) {
  stack<Rectangle> S;
  int maxv = 0;
  buffer[size] = 0;

  for ( int i = 0; i <= size; i++ ) {
    Rectangle rect;
    rect.height = buffer[i];
    rect.pos = i;
    if ( S.empty() ) {
      S.push(rect);
    } else {
      if ( S.top().height < rect.height ) {
        S.push(rect);
      } else if ( S.top().height > rect.height ) {
        int target = i;
        while ( !S.empty() && S.top().height >= rect.height ) {
          Rectangle pre = S.top(); S.pop();
          int area = pre.height * (i - pre.pos);
          maxv = max(maxv, area);
          target = pre.pos;
        }
        rect.pos = target;
        S.push(rect);
      }
    }
  }
  return maxv;
}

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int getLargestRectangle() {
  for ( int j = 0; j < W; j++ )
    for ( int i = 0; i < H; i++ ) {
      if ( buffer[i][j] )
        T[i][j] = 0;
      else
        T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
    }

  int maxv = 0;
  for ( int i = 0; i < H; i++ )
    maxv = max(maxv, getLargestRectangle(W, T[i]));

  return maxv;
}

int main() {
  scanf("%d %d", &H, &W);
  for ( int i = 0; i < H; i++ )
    for ( int j = 0; j < W; j++ )
      scanf("%d", &buffer[i][j]);
  cout << getLargestRectangle() << endl;

  return 0;
}


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

int main()
{
	long long N, T;
	cin >> N >> T;

	auto sum = 0ll;
	auto end = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		long long t;
		cin >> t;

		if (t <= end)
		{
			sum += (t + T) - end;
		}
		else
		{
			sum += T;
		}
		end = t + T;
	}

	cout << sum << endl;

	return 0;
}

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

int main() {
    int h, w, i, j;
    cin >> h >> w;
    vector<vector<char>> arr(h+2, vector<char>(w+2));
    for(i = 0; i < h+2; i++){
        for(j = 0; j < w+2; j++){
            arr.at(i).at(j) = '#';
        }
    }
    for(i = 1; i < h+1; i++){
        for(j = 1; j < w+1; j++){
            cin >> arr.at(i).at(j);
        }
    }
    for(i = 0; i < h+2; i++){
        for(j = 0; j < w+2; j++){
            cout << arr.at(i).at(j);
        }
        cout << endl;
    }
}
    


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


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


vector<int> c(26);
vector<vector<int>> v(365,vector<int>(26));
vector<int> contest(365,0);
vector<int> satisfy(26,0);
int d;
int res = 0;

void change_data(int day,int pos){
  vector<int> new_contest = contest;
  int res_ = res;
  int pre = new_contest[day];
  res_ += satisfy[pos];
  res_ += satisfy[pre];
  res_ -= v[day][pre];
  res_ += v[day][pos];
  int pos_satisfy = 0,pre_satisfy = 0;
  int pos_last = 0,pre_last = 0;
  new_contest[day] = pos;
  for(int i = 1;i <= d;i++)pos_last = (new_contest[i-1] == pos ? pos_last = i : pos_last),pos_satisfy += c[pos]*(i-pos_last);
  for(int i = 1;i <= d;i++)pre_last = (new_contest[i-1] == pre ? pre_last = i : pre_last),pre_satisfy += c[pre]*(i-pre_last);
  res_ -= (pos_satisfy+pre_satisfy);
  if(res < res_){
    res = res_;
    contest[day] = pos;
    satisfy[pre] = pre_satisfy;
    satisfy[pos] = pos_satisfy;
  }
}
void swap_data(int d1,int d2){
  change_data(d1,contest[d1]);
  change_data(d2,contest[d2]);
}


int main(){
  
  srand((unsigned)time(NULL));
  cin >> d;
  rep(i,26)cin >> c[i];
  rep(i,d)rep(j,26){
    int x;cin >> x;
    v[i][j] = x;
  }
  /*{
    int j = d;
    for(int i = 0;j;i++){
      contest[d-j] = (i%26);
      j--;
    }
  }*/
  {
    vector<int> last(26,0);
    for(int i = 1;i <= d;i++){
      rep(j,26)if(v[i-1][contest[i-1]] < v[i-1][j])contest[i-1] = j;
      last[contest[i-1]] = i;
      res += v[i-1][contest[i-1]];
      rep(j,26)res -= c[j]*(i-last[j]),satisfy[j] += c[j]*(i-last[j]);
    }
  }
  while(1.0*clock()/CLOCKS_PER_SEC <= 0.5){
    //int now_time = clock();
    //if(1.0*now_time/CLOCKS_PER_SEC > 1.7)break;
    int day = rand()%d,pos = rand()%26;
    change_data(day,pos);
  }
  while(1.0*clock()/CLOCKS_PER_SEC <= 1.4){
    swap_data(rand()%d,rand()%d);
  }
  rep(i,d)cout << contest[i]+1 << endl;
  //cout << res << endl;///////////


  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll h,w;
    cin>>h>>w;
    while(h--){
        string s;
        cin>>s;
        cout<<s<<endl;
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Array.Unboxed
import Data.Array.ST
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as B

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

main=do
  (n:m:q:_) <- map read.words<$>getLine::IO[Int]
  (lrs,pqs) <- splitAt m.take (m+q).unfoldr (runStateT parseInt2) <$> B.getContents
  let !ar = f n lrs
  putStr.unlines $ map (\(p,q)->show $ ar ! (p,q)) pqs
--
f n lrs = runSTUArray $ do
  ar <- newArray ((1,1),(n+1,n)) 0 :: ST s (STUArray s (Int,Int) Int)
  forM_ lrs $ \(l,r) -> do
    writeArray ar (1,r) =<< succ <$> readArray ar (1,r)
    writeArray ar (l+1,r) =<< pred <$> readArray ar (l+1,r)
  forM_ [(l,r)|l<-[2..n],r<-[1..n]] $ \(l,r) -> do
    writeArray ar (l,r) =<< (+) <$> readArray ar (l,r) <*> readArray ar (l-1,r)
  forM_ [(l,r)|l<-[1..n],r<-[2..n]] $ \(l,r) -> do
    writeArray ar (l,r) =<< (+) <$> readArray ar (l,r) <*> readArray ar (l,r-1)
  pure ar


Measured memory_bytes: 8828
#include <iostream>
#include <set>
#include <vector>

int iterate(int N)
{
    const std::vector<int> nines { 9, 81, 729, 6561, 59049 };
    const std::vector<int> sixes { 6, 36, 216, 1296, 7776, 46656 };

    int count = 0;
    std::set<int> remains;
    remains.insert(N);
    while (true) {
        std::set<int> prev;
        prev.swap(remains);
        ++count;
        for (int remain : prev) {
            for (int pay : nines) {
                if (pay == remain)
                    return count;
                else if (pay < remain)
                    remains.insert(remain - pay);
                else
                    break;
            }
            for (int pay : sixes) {
                if (pay == remain)
                    return count;
                else if (pay < remain)
                    remains.insert(remain - pay);
                else
                    break;
            }
            if (remain == 1)
                return count;
            else
                remains.insert(remain - 1);
        }
    }
    return count;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int N;
    std::cin >> N;
    std::cout << iterate(N) << std::endl;
    return 0;
}

Measured memory_bytes: 9472
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	cout<<in[n-1]-in[0]<<endl;
}










Measured memory_bytes: 256