akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define rrng(obj) (obj).rbegin(), (obj).rend()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,v.size())i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(v.size())o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
bool comp(pair<char,int> a,pair<char,int> b){
  return a.se<b.se;
}
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  string s;
  cin>>s;
  string t = s;
  unordered_map<char,int> m;
  int n=s.length();
  rep(i,n){
    m[s[i]]++;
  }
  int ans=INF;
  for(auto mm:m){
    n = s.length();
    s=t;
    char mc = mm.fi;
    rep(ii,100){
      bool f = true;
      rep(i,n){
        if(s[i]!=mc){f = false;break;}
      }    
      if(f){
        mins(ans,ii);
        break;
      }
      rep(i,n-1){
        if(s[i]==mc or s[i+1]==mc ) s[i]=mc;
      }
      n--;
    }
  }
  cout<<ans<<endl;
  
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 384
n = int(input())
nums = list(map(int, input().split()))

left = 0
right = 0
res = 0
while left < n:
    prev = nums[left]
    right = left
    while right < n and prev >= nums[right]:
        right += 1
        prev = nums[right - 1]
    res = max(res, right - left)
    left = right
print(res - 1)

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

long long n;
vector<vector<int>> edge;
vector<int> dp;
vector<bool> ch;

string solve();
int dfs(int now);
int reroot(int now);

int main() {
  cin >> n;
  edge.resize(n);
  for(int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edge[--a].push_back(--b);
    edge[b].push_back(a);
  }
  cout << solve() << endl;
  return 0;
}

string solve() {
  string res;
  for(int i = 0; i < n; ++i) res += "1";
  dp.assign(n, 0);
  ch.assign(n, 0);
  ch[0] = 1;
  dfs(0);
  ch.assign(n, 0);
  ch[0] = 1;
  int num = reroot(0);
  if(num != -1)
    for(int j = 2; j <= num; ++j) res[j] = '0';
  return res;
}

int dfs(int now) {
  int res = 0;
  for(auto to : edge[now])
    if(!ch[to]) {
      ch[to] = 1;
      res = max(res, 1 + dfs(to));
    }
  return dp[now] = res;
}

int reroot(int now) {
  int res = -1, num = 0, bf = dp[now];
  dp[now] = 0;
  vector<int> child, pre, suf;
  for(auto to : edge[now]) {
    child.push_back(dp[to]);
    pre.push_back(dp[to]);
    suf.push_back(dp[to]);
  }
  num = child.size();
  for(int i = 1; i < num; ++i) {
    pre[i] = max(pre[i - 1], pre[i]);
    suf[num - i - 1] = max(suf[num - i], suf[num - i - 1]);
  }
  for(int i = 0; i < num; ++i)
    if(!ch[edge[now][i]]) {
      dp[now] = 0;
      ch[edge[now][i]] = 1;
      if(i != 0) dp[now] = max(dp[now], pre[i - 1] + 1);
      if(i != num - 1)
        dp[now] = max(dp[now], suf[i + 1] + 1);
      res = max(res, reroot(edge[now][i]));
    }
  if(num >= 3) {
    sort(child.begin(), child.end(), greater<int>());
    if(child[0] == child[2])
      res = max(res, child[0] + child[2]);
    else
      res = max(res, child[0] + child[2] + 1);
  }
  dp[now] = bf;
  return res;
}


Measured memory_bytes: 35216
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

char field[1000][1000];
int n,m;
int sx,sy;
int gx,gy;
int d[1000][1000];

int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

int bfs(int s)
{
    queue<P> que;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            d[i][j] = INF;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;

    while(que.size()){
        P p = que.front(); que.pop();
        if(field[p.first][p.second] == '0' + (s+1)){
            sx = p.first;
            sy = p.second;
            return d[p.first][p.second];
        }

        for(int i = 0; i < 4; i++){
            int nx = p.first + dx[i] ,ny = p.second + dy[i];
            if(0 <= nx && nx < n && 0 <= ny && ny < m && field[nx][ny] != 'X' && d[nx][ny] == INF){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return 0;
}

int main()
{
    cin >> n >> m;
    ll ans = 0;
    int num; cin >> num;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> field[i][j];
            if(field[i][j] == 'S'){
                sx = i; sy = j;
            }
        }
    }
    for(int i = 0; i < num; i++){
        ans += bfs(i);
    }
    cout << ans << endl;
}


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

int main() {
  int x;
  cin >> x;
  bool flag = false;
  for(int i = 3; i <= 7; i += 2) {
    if(x == i) flag = true;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include<sstream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define  mem memset(a,0,sizeof(a))

const int mo=1000000007;
const int inf=0x3f3f3f3f;

typedef long long ll;
using namespace std;

int dir[4][2]={1,0, 0,1, -1,0, 0,-1};
char ma[55][55];
int vis[55][55];
int n,m;
struct node
{
    int step,x,y;
}t,f;

int bfs()
{
    queue<node>q;
    t.x=0,t.y=0,t.step=1;
    q.push(t);
    while(!q.empty())
    {
        t=q.front();
        q.pop();
        if(vis[t.x][t.y])
            continue;
        vis[t.x][t.y]=t.step;
        if(t.x==n-1&&t.y==m-1)
            return t.step;
        int i,tx,ty;
        for(i=0;i<4;i++)
        {
            tx=t.x+dir[i][0];
            ty=t.y+dir[i][1];
            if(tx>=0&&tx<n&&ty>=0&&ty<m&&ma[tx][ty]=='.')
            {
                f.x=tx;
                f.y=ty;
                f.step=t.step+1;
                q.push(f);
            }
        }
    }
    return -1;
}
int main()
{
    memset(vis,0,sizeof(vis));
    cin>>n>>m;
    int i,j;
    for(i=0;i<n;i++)
    {
        cin>>ma[i];
    }
    int ans=n*m;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(ma[i][j]=='#')
                ans--;
        }
    }
    int x=bfs();
    if(x==-1)
        cout<<-1<<endl;
    else
        cout<<ans-x<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char c;
  string s,t;
  cin >> s;
  string orgS = s;
  int i,j;
  int chk = 1;
  int minn = 99999999;
  int tmp = 0;
  for(j=0;j<26;j++){
    c = 'a'+j;
    chk = 1;
    s = orgS;
    for(i=0;i<s.length();i++){
      if(s[i]!=c)chk=0;
    }
    tmp = 0;
    while(chk ==0 && s.length()>1){
      t = "";
      chk = 1;
      tmp ++;
      for(i=0;i<s.length()-1;i++){
        if(s[i]==c||s[i+1]==c)t = t+c;
        else t = t + s[i];
      }
      for(i=0;i<t.length();i++){
        if(t[i]!=c)chk = 0;
      }
      s=t;
    }
    if(tmp<minn)minn=tmp;
  }
  cout << minn << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll A,B;
  cin>>A>>B;
  if(A>B)
    cout<<"safe"<<endl;
  else
    cout<<"unsafe"<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

int INF = 1'000'000;

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

    vector<int> even(N/2), odd(N/2);
    unordered_map<int, int> evenCnt, oddCnt;
    for(int i=0;i<N;i++){
        if( i % 2 == 0 ){
            cin >> even[i/2];
            evenCnt[even[i/2]]++;
        }
        else{
            cin >> odd[i/2];
            oddCnt[odd[i/2]]++;
        }
    }

    int eMax[2] = {}, eMaxKey[2] = {};
    for(auto itr=evenCnt.begin();itr!=evenCnt.end();itr++){
        if( eMax[0] < itr->second ){
            eMax[1] = eMax[0];
            eMaxKey[1] = eMaxKey[0];
            eMax[0] = itr->second;
            eMaxKey[0] = itr->first;
        } else if( eMax[1] < itr->second ){
            eMax[1] = itr->second;
            eMaxKey[1] = itr->first;
        }
    }

    int oMax[2] = {}, oMaxKey[2] = {};
    for(auto itr=oddCnt.begin();itr!=oddCnt.end();itr++){
        if( oMax[0] < itr->second ){
            oMax[1] = oMax[0];
            oMaxKey[1] = oMaxKey[0];
            oMax[0] = itr->second;
            oMaxKey[0] = itr->first;
        } else if( oMax[1] < itr->second ){
            oMax[1] = itr->second;
            oMaxKey[1] = itr->first;
        }
    }

    int ans = INF;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            if( eMaxKey[i] != oMaxKey[j] ){
                ans = min(ans, int((N/2-eMax[i]) + (N/2-oMax[j])));
            }
        }
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define REP(i,n) for(int i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")

using ll = long long;
using P = pair<int,int>;
using vi = vector<int>; 
using vii = vector<vi>;

const int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int dy[8] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


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

  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  vector<int> y(n);
  rep(i,n) y[i] = x[i];
  sort(all(y));
  int lm = y[n/2-1];
  int rm = y[n/2];
  rep(i,n){
    if(x[i] <= lm) cout << rm << endl;
    else cout << lm << endl;
  }
}

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

#define ll                  long long int
#define llu                 long long unsigned
#define ld                  long double
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);
#define endl                "\n"
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define mp                  make_pair
#define ms(a,b)             memset((a),(b),sizeof(a))
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(min(a,b),min(c,d))
#define max4(a,b,c,d)       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
#define NUM                 1000000
#define PI		    2*acos(0.0)
#define maximum             (-1*INF)
#define READ(f) 	    freopen("f", "r", stdin)
#define WRITE(f) 	    freopen("f", "w", stdout)
const int INF = 1e5 + 10 ;

int main()
{
    ll n, m, temp, sum = 0;
    cin>>n>>m;
    while(m--)
    {
        cin>>temp;
        sum += temp;
    }
    if(sum>n)
        cout<<-1;
    else
        cout<<n - sum;
    return 0;
}


Measured memory_bytes: 3636
import sys,collections
input = sys.stdin.readline

N,Q = list(map(int,input().split()))
road = [[] for i in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    road[a].append(b)
    road[b].append(a)
point = [0]*(N+1)

for _ in range(Q):
    p,x = map(int,input().split())
    point[p] += x

q = collections.deque([1])
visit = [0]*(N+1)
visit[1]=1

while q:
    now = q.pop()
    for i in road[now]:
        if visit[i] == 0:
            q.append(i)
            point[i] += point[now]
            visit[i]=1

print(*point[1:])


Measured memory_bytes: 58068
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int r = abs((a+b)-(c+d));
	r = min(r, abs((a+c)-(b+d)));
	r = min(r, abs((a+d)-(c+b)));
	cout << r << endl;
}



Measured memory_bytes: 3104
#include <stdio.h>
#include <string.h>


int main(void)
{
	char s[101];
	char t[1001];
	int soe;
	int i = 1;
	int tmp;
	
	scanf("%s", s);
	scanf("%s", t);
	
	while (i != 0){
		i = 0;
		for (soe = 1; s[soe] != '\0'; soe++){
			if (s[soe - 1] > s[soe]){
				tmp = s[soe];
				s[soe] = s[soe - 1];
				s[soe - 1] = tmp;
				i++;
			}
		}
	}
	
	
	i = 1;
	while (i != 0){
		i = 0;
		for (soe = 1; t[soe] != '\0'; soe++){
			if (t[soe - 1] < t[soe]){
				tmp = t[soe];
				t[soe] = t[soe - 1];
				t[soe - 1] = tmp;
				i++;
			}
		}
	}
	if (strcmp(t, s) > 0){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	
		
	return (0);
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> num(k);

  for(ll i=1;i<=n;i++) num[i%k]++;
  ll res = 0;
  for(ll a=0;a<k;a++) {
    ll b = (k-a)%k;
    ll c = (k-a)%k;
    if((b+c)%k != 0) continue;
    res += num[a] * num[b] * num[c];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
char lower(char x){
    if(x=='A'){
         return 'a';
    }
    else if(x=='B'){
        return 'b';
    }
    else if(x=='C'){
        return 'c';
    }
}
int main(){
    int n,k;
    cin>>n>>k;
    char str[n];
    cin>>str;
    for(int i=0;i<n;i++){
        if(i==k-1){
            cout<<lower(str[i]);
        }
        else{
            cout<<str[i];
        }
    }
}


Measured memory_bytes: 3616
/**
 * Created by hiramekun at 20:51 on 2019-09-01.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl h(n);
    cin >> h;

    ll now = -1;
    ll ans = 0;
    ll tmp = 0;
    for (ll i = 0; i < n; ++i) {
        if (now != -1 && h[i] <= now) tmp++, now = h[i];
        else {
            ans = max(tmp, ans);
            tmp = 0;
            now = h[i];
        }
    }
    ans = max(tmp, ans);
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
const int mod=1e9+7;
const int maxn=1e5+5;
vector<int>v;
int dp[maxn][105];
int main()
{
    scanf("%d%d",&n,&k);
    int l=1,r=1;
    while(r+1<=n)
    {
        v.push_back(r);
        l=r+1;
        r=n/(n/l);
    }
    v.push_back(r);
    dp[0][1]=v[0];
    for(int i=1;i<v.size();i++)
    {
        dp[i][1]=v[i]-v[i-1];
    }
    ll ans=0;
    for(int i=2;i<=k;i++)
    {
        ll now=0;
        int r=v.size()-1;
        for(int j=0;j<v.size();j++)
        {
            now=(now+dp[j][i-1])%mod;
            dp[r][i]=now*(r==0?v[r]:v[r]-v[r-1])%mod;
            r--;
        }
    }
    for(int i=0;i<v.size();i++)
        ans=(ans+dp[i][k])%mod;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 27260
/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
typedef long long Long;
void FastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
}

const int N = 1e6;

int main()
{
  FastIO();
  int tc, ca = 0;
  int n;
  cin >> n;
  vector <int> v(4, 0);
  int el;
  for (int i = 0;i < n;i++){
    cin >> el;
    v[el%4]++;
  }
  int f = v[0] + (v[2]/2);
  if (f >= n/2)cout << "Yes" << '\n';
  else cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 3576
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    static int gcd(int x, int y) {
        int r = Math.max(x, y) % Math.min(x, y);
        if (r == 0) return Math.min(x, y);
        else return gcd(Math.min(x, y), r);
    }
    
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String[] nabc = br.readLine().split(" ");
        int n = Integer.parseInt(br.readLine());
        String[] m = br.readLine().split(" ");
        int[] mon = new int[n];
        
        for (int i = 0; i < n; i++) {
            mon[i] = Integer.parseInt(m[i]);
        }
        
        int cd = gcd(mon[0], mon[1]);
        for (int i = 2; i < n; i++) {
            cd = gcd(cd, mon[i]);
            if (cd == 1) {
                break;
            }
        }
        
        System.out.println(cd);
    }
}





Measured memory_bytes: 37972
import java.util.*;
import java.io.*;
public class Main{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
// end
static long[] f;
// taking inputs
static BufferedReader s;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends
//......................................@uthor_Alx..............................................

public static void main(String[] args) throws  IOException{
       assign();
      long[] nab=long_arr();
      long res=0;
      if(nab[1]!=0){
      	 res=(nab[0]/(nab[1]+nab[2]))*nab[1];
      	 long re=nab[0]-((nab[0]/(nab[1]+nab[2])))*(nab[1]+nab[2]);

      	 if(re>=nab[1]){res+=nab[1];}
      	 else{res+=re;}
      }
     out.write(res+"\n");
             
        out.flush();
  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#define llint long long
#define mod 1000000007

using namespace std;

string s;
llint dp[300005][2][2][2][3];

int main(void)
{
	cin >> s;
	s += "1";
	int n = s.size();
	s = "#" + s;
	
	dp[0][0][0][0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				for(int l = 0; l < 2; l++){
					for(int m = 0; m < 3; m++){
						if(s[i+1] != '1'){
							(dp[i+1][(j+1)%2][1][l][m] += dp[i][j][k][l][m]) %= mod;
						}
						if(s[i+1] != '0'){
							if(j % 2){
								(dp[i+1][0][0][l][m] += dp[i][j][k][l][m]) %= mod;
								continue;
							}
							int nm = m;
							if(k == 0){
								if(m == 0 && l % 2 == 0) nm = 1;
								else if(m == 1 && l % 2) nm = 2;
							}
							(dp[i+1][0][0][(l+1)%2][nm] += dp[i][j][k][l][m]) %= mod;
						}
					}
				}
			}
		}
	}
	llint ans = 0;
	for(int l = 0; l < 2; l++) ans += dp[n][0][0][l][2], ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 56924
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int k = in();
  string s = stin();
  if (s.size() <= k) cout << s << endl;
  else cout << s.substr(0,k) + "..." << endl;
  return 0;
}

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(5);

    ll mi = 1LL<<60;
    rep(i, 5) {
        cin >> A[i], mi = min(mi, A[i]);
    }

    cout << (N + mi - 1) / mi + 4 << endl;

    return 0;
}

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

int main()
{
    int n,ans;
    string str;

    cin>>n>>str;

    ans=0;
    for (int i=0 ; i<n-2; i++)
    {
        if(str[i]=='A'){
            if(str[i+1]=='B'){
                if(str[i+2]=='C')
                    {
                        ans++;
                        i+=2;
                    }
            }
        }
    }
    cout<<ans<<endl;
}


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

int main( )
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
    if (a == b && a != c) {
        cout << "Yes\n";
    }
    else if (b == c && a != c) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
// Author: πα

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

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, i;
    cin >> n;
    vector<long> v(n);
    for(i = 0; i < n; ++i)
        cin >> v[i];
    long x = 0;
    for(i = 0; i < n; ++i)
        x += (i % 2 ? -v[i] : v[i]);
    x /= 2;
    vector<long> ans(n);
    ans[0] = x;
    for(i = 1; i < n; ++i)
        ans[i] = v[i-1] - ans[i-1];
    for(auto it : ans)
        cout << it+it << ' ';
    return 0;
}


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

int main(){
    long long n,a,b;
    cin >> n >> a >> b;
    if(a > b){
        swap(a,b);
    }
    if((b-a) % 2 == 0){
        cout << (b-a)/2;
    }else{
        cout << min((n-b+1)-(a-b+1)/2,a-1 + (b-a+1)/2);
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<String> s = new ArrayList<>();
        Integer[] t = new Integer[n];
        for (int i = 0; i < n; i++) {
            s.add(sc.next());
            t[i] = Integer.parseInt(sc.next());
        }
        String x = sc.next();
        sc.close();

        // 主処理
        int index = s.indexOf(x);
        int result = 0;
        for (int i = index + 1; i < t.length; i++) {
            result += t[i];
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/16/20 21:00:53
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,q; cin>>n>>q;
  string s; cin>>s;
  vector<int> cum(n);
  for (int i = 0; i < n-1; i++) {
    if (s[i] == 'A' and s[i+1] == 'C') {
      cum[i]++;
    }
    if (i > 0)
      cum[i] += cum[i-1];
  }
  while (q--) {
    int l,r; cin>>l>>r;
    int ans;
    if (r < 2)
      ans = 0;
    else {
      ans = cum[r-2];
      if (l > 1)
        ans -= cum[l-2];
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1488
H, W = map(int, input().split())
S = [['.']*(W+2)] + [['.'] + list(input()) + ['.'] for _ in range(H)] + [['.']*(W+2)]
for i in range(1, H+1):
  S[i][0] = S[i][1]
  S[i][-1] = S[i][-2]
for i in range(1, W+1):
  S[0][i] = S[1][i]
  S[-1][i] = S[-2][i]
S[0][0] = S[0][1]
S[-1][0] = S[-2][0]
S[0][-1] = S[0][-2]
S[-1][-1] = S[-2][-1]
V = [[0 for _ in range(W+2)] for i in range(H+2)]
num = 0
for i in range(1, H+1):
  for j in range(1, W+1):
    if S[i][j] == '#' and V[i][j] == 0:
      V[i][j] = 1
      p = [[i, j]]
      cnt = 1
      pnt = 0
      D = {'.': 0, '#': 0}
      D[S[i][j]] = 1
      while pnt < cnt:
        n = cnt
        for k in range(pnt, cnt):
          x = p[k][:]
          y = S[x[0]][x[1]][:]
          if S[x[0]-1][x[1]] != y and V[x[0]-1][x[1]] == 0:
            V[x[0]-1][x[1]] = 1
            p.append([x[0]-1, x[1]])
            D[S[x[0]-1][x[1]]] += 1
            cnt += 1
          if S[x[0]+1][x[1]] != y and V[x[0]+1][x[1]] == 0:
            V[x[0]+1][x[1]] = 1
            p.append([x[0]+1, x[1]])
            D[S[x[0]+1][x[1]]] += 1
            cnt += 1
          if S[x[0]][x[1]-1] != y and V[x[0]][x[1]-1] == 0:
            V[x[0]][x[1]-1] = 1
            p.append([x[0], x[1]-1])
            D[S[x[0]][x[1]-1]] += 1
            cnt += 1
          if S[x[0]][x[1]+1] != y and V[x[0]][x[1]+1] == 0:
            V[x[0]][x[1]+1] = 1
            p.append([x[0], x[1]+1])
            D[S[x[0]][x[1]+1]] += 1
            cnt += 1
        pnt = n
      num += D['.'] * D['#']
print(num)

Measured memory_bytes: 27332
#include <iostream>
#include <algorithm>
using namespace std;
int d, n;
int t[205] = { 0 }, a[205] = { 0 }, b[205] = { 0 }, c[205] = { 0 };
int dp[205][205] = { 0 };
int main() {
	cin >> d >> n;
	for (int i = 1; i <= d; i++) {
		cin >> t[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 2; i <= d; i++) {
		for (int j = 0; j < n; j++) {
			if (a[j] <= t[i] && t[i] <= b[j]) {
				for (int k = 0; k < n; k++) {
					if(a[k]<=t[i-1]&&t[i-1]<=b[k]) dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[k] - c[j]));
				}
			}
			else continue;
		}
	}
	int res = 0;
	for (int j = 0; j < n; j++) {
		res = max(res, dp[d][j]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,s;
  cin>>a>>b;
  s=a+b;
  if(s%2==1){
    cout << (a+b)/2+1 << endl;
  } else {
    cout << (a+b)/2 << endl;
  }
}

Measured memory_bytes: 256
n, q = map(int,input().split())
queries = []
for _ in range(q):
    com, x, y = map(int,input().split())
    queries.append((com, x, y))

joining = [[x] for x in range(n)]

def unite(x, y):
    if joining[x] == joining[y]:
        return
    joining[x] += joining[y]
    for member in joining[y]:
        joining[member] = joining[x]

def is_same(x, y):
    return joining[x] == joining[y]

answers = []
for query in queries:
    if query[0] == 0:
        unite(query[1], query[2])
    else:
        answers.append(is_same(query[1], query[2]))

for answer in answers:
    if answer:
        print(1)
    else:
        print(0)



Measured memory_bytes: 22032
// Program.cpp

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

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

#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n)           for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

void solve(int TEST_CASE){
    int n;
    cin >> n;
    int arr[n];
    int m[n];
    fr(i,n){
    	cin >> arr[i];
    	m[i] = INF;
    }
    for(int i=0;i<n;++i){
    	if(i==0)
    		m[i] = 0;
    	else if(i==1)
    		m[i] = abs(arr[1] - arr[0]);
    	else{
    		int a1 = m[i-2] + abs(arr[i]-arr[i-2]);
			int a2 = m[i-1] + abs(arr[i]-arr[i-1]);
			m[i] = min(a1,a2);
    	}
    }
	cout << m[n-1] << endl;
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 4336
#include <algorithm>  //max
#include <iostream>
#include <queue>
#include <string>
#include <utility>  //pair
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;

template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

int h, w;
vector<pii> dxy = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int bfs(pii s, vvi tbl) {
  if (tbl[s.first][s.second]) {
    return 0;
  }

  vvi tmp = vvi(h, vi(w, 0));
  queue<pair<int, pii>> q;
  q.push(make_pair(0, s));
  tmp[s.first][s.second] = 1;

  int ret = 0;
  while (!q.empty()) {
    int cost = q.front().first;
    ret = max(cost, ret);
    pii xy = q.front().second;
    for (auto&& d : dxy) {
      int nx = xy.first + d.first;
      int ny = xy.second + d.second;
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (tmp[nx][ny] + tbl[nx][ny]) continue;
      tmp[nx][ny] = 1;
      q.push(make_pair(cost+1,make_pair(nx,ny)));
    }
    q.pop();
  }
  return ret;
}
int main() {
  cin >> h >> w;
  string s;
  vvi tbl = vvi(h, vi(w, 0));
  for (int i = 0; i < h; i++) {
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '.')
        tbl[i][j] = 0;
      else
        tbl[i][j] = 10000;
    }
  }
  int ret = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ret = max(ret, bfs(make_pair(i, j), tbl));
    }
  }
  cout << ret << endl;
  return 0;
}


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

int main()
{
	int  a;

 	cin >> a;
	 	vector<int>p(a);
	for (int i = 0; i < a ; i++)
	{
		cin >> p[i];
	}
		int first = -1;
		int second = -1;
		for(int i = 1; i <= a; i++){
			if(first == -1 && p[i-1]!= i)
				first = i-1;
			else if(second == -1 && p[i-1]!= i){
				second = i-1;
			}else if(p[i-1] != i){
				cout << "NO" << endl;
				return 0;
			}

		}
	cout << "YES" << endl;

	return 0;
}


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

int main() {
    int64_t N, M, sum = 0;
    cin >> N >> M;
    for (int64_t i = 0; i < M; i++) {
        int64_t A;
        cin >> A;
        sum += A;
    }
    if (sum > N) {
        cout << "-1" << endl;
    } else {
        cout << N - sum << endl;
    }
    
    return 0;
}


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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}


double ev(int i) {
        return (double)(i * (1 + i) / 2) / i;
}


void _main() {
        int n, k; cin >> n >> k;
        vector<double> pre(n + 1);
        double ans = 0;
        for (int i = 1; i <= n; i++) {
                int x; cin >> x;
                pre[i] = pre[i - 1] + ev(x);
        }

        for (int i = k; i <= n; i++) {
                ans = max(ans, pre[i] - pre[i - k]);
        }
        cout << fixed << setprecision(10) << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool sto(ll a)
{
 for(ll i = 2;i*i<=a;i++)
  if(a%i==0)
   return false;
 return true;
}
int main()
{
  ll x;
  cin>>x;
  while(!sto(x))
   x++;
  cout<<x<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
  int i,j,k,a,count=0,n;


  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a==2) count++;
    if(a%2!=0){
      k=0;
      for(j=3;j<=sqrt(a);j+=2)
	{
	  if(a%j==0)
	    {
	      k=1;
	      break;
	    }
	}

      if(k==0)count++;
    }
  }
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 596
# C - Reconciled?
N, M = map(int, input().split())
ans_N = 1
ans_M = 1
mod = 10**9+7

if abs(N - M) >= 2:
    print(0)
else:
    for i in range(N):
        ans_N = ans_N * ((M - i) * (N - i)) % mod
    for j in range(M):
        ans_M = ans_M * ((M - j) * (N - j)) % mod
    print((ans_N+ans_M)% mod)

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

using namespace std;

struct Result {
    int team;
    int solved;
    int time;
    friend bool operator <(struct Result a, struct Result b) {
        if (a.solved != b.solved) {
            return a.solved < b.solved;
        }
        if (a.time != b.time) {
            return a.time > b.time;
        }
        else {
            return a.team < b.team;
        }
    }
};

int main() {
    int m, t, p, r;
    while (true) {
        cin >> m >> t >> p >> r;
        if (m == 0) {
            break;
        }
        vector<vector<int> > time(t, vector<int>(p, 0));
        vector<vector<bool> > is_solved(t, vector<bool>(p, false));
        vector<struct Result> result(t);
        for (int i=0; i<r; i++) {
            int passed, team, problem, judge;
            cin >> passed >> team >> problem >> judge;
            if (judge == 0) {
                is_solved[team-1][problem-1] = true;
                time[team-1][problem-1] += passed;
            }
            else {
                time[team-1][problem-1] += 20;
            }
        }
        for (int i=0; i<t; i++) {
            result[i].team = i+1;
            result[i].solved = 0;
            result[i].time = 0;
            for (int j=0; j<p; j++) {
                if (is_solved[i][j]) {
                    result[i].solved++;
                    result[i].time += time[i][j];
                }
            }
        }
        sort(result.begin(), result.end());
        for (int i=t-1; i>=0; i--) {
            cout << result[i].team;
            if (i > 0) {
                if (result[i].solved == result[i-1].solved &&
                    result[i].time == result[i-1].time) {
                    cout << '=';
                }
                else {
                    cout << ',';
                }
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main() {
	long long A, B,K=0;
	cin >> A >> B;
	K = ((A * A) - (B * B)) / (2 * (B - A));
	if (K < 0)
		K = K * -1;
	A = A - K;
	B = B - K;
	if (A < 0)
		A = A * -1;
	if (B < 0)
		B = B * -1;
	if (A==B)
		cout << K << endl;
	else
		cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;

public class Main {
    int d,sum;
    void run() throws Exception {
        while(cin.hasNext()){
          d=cin.nextInt();
          sum=0;
          for(int i=d;i<=600;i+=d){
        	  sum+=d*(i-d)*(i-d);
          }
          System.out.println(sum);
        }
    }
    public static void main(String[] args) throws Exception {
        new Main().run();
    } 
    Scanner cin = new Scanner(new BufferedInputStream(System.in));
    
//    BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
}

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

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
struct maxhist{
  vector<int> hist;
  struct rect{int height,idx;};

  void add_hist(int a){
    hist.push_back(a);
  }

  int get_max(){
    int res=0;
    stack<rect> s;
    for(int j=0;j<hist.size();j++){
      if((!s.size())||s.top().height<hist[j])s.push({hist[j],j});
      else if(s.top().height>hist[j]){
        int left;
        while(s.top().height>hist[j]){
          rect tmp=s.top();s.pop();
          left=tmp.idx;
          //chmax(res,tmp.height*(j-left));
          chmax(res,(tmp.height+1)*(j-left+1));
          if(!s.size())break;
        }
        s.push({hist[j],left});
      }
    }
    while(s.size()){
      rect tmp=s.top();s.pop();
      //chmax(res,tmp.height*(hist.size()-tmp.idx));
      chmax(res,(tmp.height+1)*((int)hist.size()-tmp.idx+1));
    }
    return res;
  }
};
struct maxrect{
  vector<vector<bool>> rect;

  void add_line(vector<bool> &v){
    rect.push_back(v);
  }
  void add_dot(int h,bool f){
    if(rect.size()<=h)rect.resize(h+1);
    rect[h].push_back(f);
  }

  int get_max(){
    int res=0;
    int h=rect.size();
    vector<vector<int>> hist(h);
    for(int i=0;i<h;i++)hist[i].resize(rect[i].size());
    for(int i=0;i<h;i++){
      maxhist mh;
      for(int j=0;j<hist[i].size();j++){
        if(i){
          if(hist[i-1].size()<=j)hist[i][j]=rect[i][j];
          else hist[i][j]=(hist[i-1][j]+rect[i][j])*rect[i][j];
        }
        else hist[i][j]=rect[i][j];
        mh.add_hist(hist[i][j]);
      }
      chmax(res,mh.get_max());
    }
    return res;
  }
};

signed main(){
  int h,w;cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++)cin>>s[i];
  maxrect m;
  vector<bool> f(w-1);
  for(int i=1;i<h;i++){
    for(int j=0;j<w-1;j++){
      int a=(s[i-1][j]=='#')+(s[i-1][j+1]=='#')+(s[i][j]=='#')+(s[i][j+1]=='#');
      f[j]=(a&1)^1;
    }
    m.add_line(f);
  }
  cout<<max({h,w,m.get_max()})<<endl;
}

/*
解説AC
広義唐草模様の面積求めたくなって、どこがダメな場所かも分かったけど最大長方形のアルゴリズムを知らず
時間かければ自分で思いつきそうな気もするけどコスパ悪いし見ていいでしょ
面白かった
*/


Measured memory_bytes: 20736
#include<iostream>
#include<algorithm>

int main() {
	int n;
	std::cin >> n;
	std::pair<int, int>*r = new std::pair<int, int>[n];
	std::pair<int, int>*b = new std::pair<int, int>[n];
	bool *use = new bool[n];

	for (int i = 0; i < n; i++) {
		std::cin >> r[i].first;
		std::cin >> r[i].second;
		use[i] = false;
	}
	for (int i = 0; i < n; i++) {
		std::cin >> b[i].first;
		std::cin >> b[i].second;
	}

	std::sort(r, r + n);
	std::sort(b, b + n);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int k = -1;
		for (int j = 0; j < n&&r[j].first < b[i].first; j++) {
			if (!use[j]&&r[j].second < b[i].second) {
				if (k < 0)k = j;
				else if (r[k].second < r[j].second)k = j;
			}
		}
		if (k >= 0) {
			ans++;
			use[k] = true;
		}
	}
	printf("%d", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,a;cin>>n>>a;
  if(n%500<=a)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.Point2D;
import java.awt.geom.Line2D;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new Q2006B();
	}
	
	Point2D intersectionPoint(Line2D l1,Line2D l2){
		return intersectionPoint(l1.getP1(), l1.getP2(), l2.getP1(), l2.getP2());
	}
	Point2D intersectionPoint(Point2D a1,Point2D a2,Point2D b1,Point2D b2){
		Point2D a=diff(a2,a1),
				b=diff(b2,b1);
		return sum(a1, mul(cross(b, diff(b1,a1))/cross(b,a), a));
	}
	Point2D diff(Point2D p1,Point2D p2){
		return new Point2D.Double(p1.getX()-p2.getX(), p1.getY()-p2.getY());
	}
	double cross(Point2D p1,Point2D p2){
		return p1.getX()*p2.getY() - p2.getX()*p1.getY();
	}
	Point2D mul(double n,Point2D p1){
		return new Point2D.Double(p1.getX()*n, p1.getY()*n);
	}
	Point2D sum(Point2D p1,Point2D p2){
		return new Point2D.Double(p1.getX()+p2.getX(), p1.getY()+p2.getY());
	}
	private ArrayList<Point2D> polygonCut(ArrayList<Point2D> plist, Line2D cut) {
		int n = plist.size();
		ArrayList<Point2D> ans = new ArrayList<Point2D>();
		for(int i =0; i<n; i++){
			Point2D from = plist.get(i), to = plist.get((i+1)%n);
			if(cut.relativeCCW(from) <= 0){
				ans.add(from);
			}
			int temp1 = cut.relativeCCW(from);
			int temp2 = cut.relativeCCW(to);
			if(temp1 * temp2 < 0){
				Point2D IntersectP = intersectionPoint(cut, new Line2D.Double(from,to));
				ans.add(IntersectP);
			}
		}
		return ans;
	}
	
	class Q2006B{
		int N;
		Q2006B(){
			while(true){
				N=sc.nextInt();
				if(N==0)	break;
				solve();
			}
		}
		void solve(){
			Point2D[] ps = new Point2D[N];
			for(int i=0; i<N; ++i)	ps[i]=new Point2D.Double(sc.nextInt(), sc.nextInt());
			ArrayList<Point2D> ps2 = new ArrayList<Point2D>(4);
			ps2.add(new Point2D.Double(0,0));
			ps2.add(new Point2D.Double(10000,0));
			ps2.add(new Point2D.Double(10000,10000));
			ps2.add(new Point2D.Double(0,10000));
			for(int i=0; i<N; ++i){
				ps2 = polygonCut(ps2, new Line2D.Double(ps[i], ps[(i+1)%N]));
			}
			System.out.println(ps2.isEmpty()? "0": "1");
		}
	}
}

Measured memory_bytes: 27720
def merge(arr,left,mid,right)
  n1=mid-left
  n2=right-mid
  larr=Array.new()
  rarr=Array.new()
  0.upto(n1-1) do |i|
    larr[i]=arr[left+i]
  end
  0.upto(n2-1) do |i|
    rarr[i]=arr[mid+i]
  end
  larr[n1]=1000000000
  rarr[n2]=1000000000
  i=0
  j=0
  left.upto(right-1) do |k|
    if larr[i] <= rarr[j]
      arr[k]=larr[i]
      i=i+1
      @count+=1
    else
      arr[k]=rarr[j]
      j=j+1
      @count+=1
    end
  end
end

def mergeSort(arr,left,right)
  if left+1 < right
    mid=(left+right)/2
    mergeSort(arr,left,mid)
    mergeSort(arr,mid,right)
    merge(arr,left,mid,right)
  else
    return arr
  end
end

n=gets.to_i
arr=gets.split.map(&:to_i)
@count=0
mergeSort(arr,0,n)
puts arr.join(' ')
puts @count

Measured memory_bytes: 71480
#include <bits/stdc++.h>
using namespace std;
 
 int main() {
    char b;
     cin >> b;
    
    if (b == 'A')
        cout << "T" << endl;
    else if (b== 'T')
        cout << "A" <<endl;
    else if (b== 'C')
        cout << "G" << endl;
    else if (b == 'G')
        cout << "C" << endl;    
}

Measured memory_bytes: 256
S = input()

yymm = False
mmyy = False

#MMYY
if 0 <= int(S[2:]):
    if 1 <= int(S[:2]) and int(S[:2]) <= 12:
        mmyy = True

#YYMM
if 1 <= int(S[2:]) and int(S[2:]) <= 12:
    if 0 <= int(S[:2]):
        yymm = True

if yymm:
    if mmyy:
        print('AMBIGUOUS')
    else:
        print('YYMM')
elif mmyy:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3064