akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

ll n, m;
vvl to, ot;

ll dfs(ll v) {
    if (ot[v].size() == 0) return v;
    return dfs(ot[v][0]);
}

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

    cin>>n>>m;
    to = vvl(n);
    ot = vvl(n);
    rep(i, n + m - 1) {
        ll v1, v2;
        cin>>v1>>v2; v1--; v2--;

        to[v1].push_back(v2);
        ot[v2].push_back(v1);
    }

    ll r = dfs(0);
    vl ps(n);
    ps[r] = -1;
    vl in(n);
    rep(i, n) in[i] = ot[i].size();
    queue<ll> q;
    q.push(r);
    while(!q.empty()) {
        ll v = q.front(); q.pop();

        for (auto nv : to[v]) {
            in[nv]--;
            if (in[nv] == 0) {
                ps[nv] = v;
                q.push(nv);
            }
        }
    }
    rep(i, n) cout<<ps[i] + 1<<endl;
}

Measured memory_bytes: 13312
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] == k){
            cout << "POSSIBLE\n";
            return 0;
        }
    }
    sort(a.begin(), a.end());
    if(a.back() < k){
        cout << "IMPOSSIBLE\n";
        return 0;
    }
    int g = 0;
    for(int i = 0; i < n; ++i){
        g = __gcd(g, a[i]);
        if(g == 1){
            cout << "POSSIBLE\n";
            return 0;
        }
    }
    if(k % g == 0)  cout << "POSSIBLE\n";
    else    cout << "IMPOSSIBLE\n";
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 1; i <= 9; ++i) {
    if (n % i != 0) continue;

    int div = n / i;

    if (1 <= div && div <= 9) {
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");

  return 0;
}


Measured memory_bytes: 256
ret = []
while True:
   n, x = map(int, raw_input().split())
   num_arr = [i for i in range(1, n+1)]
   if (n, x) == (0, 0):
       break

   cnt = 0
   for i in range(n, 0, -1):
       if x - i <= 2:
           continue
       #print "i : %d" % i
       for j in range(i -1, 0, -1):
          if x-i-j <= 0:
              continue
          #print "j : %d" % j
          for k in range(j - 1, 0 , -1):
              if x-i-j-k < 0:
                  continue
              if x -i-j-k == 0:
                  cnt += 1
                  #print "k : %d" % k
                  break
   ret += [cnt]
for i in ret:
    print i

Measured memory_bytes: 6392
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if X - 500*a - 100*b - 50*c == 0:
                res += 1

print(res)

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

#define pb push_back

vector<int>g[100003];
vector<int>v(100003);
queue<int>q;

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

    while(m--)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[a].pb(b);
        g[b].pb(a);
        //cout<<a<<" "<<b<<" ok"<<endl;
    }

    q.push(0);
    v[0]=1;
    //cout<<"ok"<<endl;

    vector<int>ans(n-1);

    while(!q.empty())
    {
        int u = q.front();
        //cout<<u<<" u" <<endl;
        q.pop();
        for(auto i = g[u].begin(); i !=g[u].end(); i++)
        {
            if(!v[*i])
            {
                q.push(*i);
                v[*i]=1;
                ans[*i-1]=u;
            }
        }
    }
    int f=0;
    for(auto i:v )
    {
        if(!v[i])
        {
            f=1;
        }
    }
    if(f==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
        for(auto i:ans)
            cout<<i+1<<endl;
    }
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << "\n"
         << a << "\n"
         << b << "\n";

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[100];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n-1; i++) cout << a[i] << " ";
    cout << a[n-1] << endl;
    for(int i = 1; i < n; i ++) {
			int key = a[i];
			int j = i - 1;
			while(j >= 0 && a[j] > key) {
				a[j + 1] = a[j];
				j --;
			}
			a[j + 1] = key;
			for(int k = 0; k < n - 1; k ++) {
				cout << a[k] << " ";
			}
			cout << a[n-1] << endl;
		}
    return 0;
}


Measured memory_bytes: 3108
def input_number():
    return int(input())

def input_1line_list(number_of_input):
    return [input() for i in range(number_of_input)]

def input_1line():
    return map(int, input().split())

# def print_unique_length(input_list):
#     print(len(set(input_list)))

def main():
    k = input_number()
    a, b = input_1line()
    for i in range(a, b+1):
        if i % k == 0:
            print('OK')
            exit()
    print('NG')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
n,m=map(int,input().split())
sl=[];cl=[]
for i in range(m):
    s,c=map(int,input().split())
    sl.append(s)
    cl.append(c)

isThere=False
#ans=10**n-1

for i in range(10**n):
    st=list(str(i))
    flag=True
    if len(st)==n:
        for j in range(m):
            if st[sl[j]-1]!=str(cl[j]):
                flag=False
                break
        if flag:
            isThere=True
            ans=i
    if isThere:
        break
if isThere:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
using namespace std;
long long n, S[405], F[405][405], a[405];
int main()
{
    //freopen("SLIMES.INP", "r", stdin);
    cin >> n;

    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++) F[i][j] = 1e18;

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        S[i] = S[i - 1] + a[i];
        F[i][i] = 0;
    }

    for (int cnt = 1; cnt <= n - 1 ; cnt++)
        for (int i = 1; i <= n - cnt; i++)
        {
            int j = i + cnt;
            for (int mid = i; mid < j; mid++)
                F[i][j] = min(F[i][j], F[i][mid] + F[mid + 1][j]);
            F[i][j] += S[j] - S[i - 1];

        }

    cout <<F[1][n];
    return 0;
}


Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    long ans = x;
    REP(i,n) {
        int a;
        cin >> a;
        int j = 1;
        while (j <= d) {
            ans++;
            j += a;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SilverFoxVsMonster | diff SilverFoxVsMonster.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SilverFoxVsMonster.cpp && ./a.out

/*
 
 5/2/2020
 
 17:11-
 
 */

const int MAX_N=1e6+1;
pair<LL,LL> X[MAX_N];
int N;
LL D,A;

void solve() {
  map<LL,LL> ms;
  set<LL> xset;
  FORR(p,X) ms[p.first]=p.second,xset.emplace(p.first),xset.emplace(p.first+2LL*D+1);
  vector<LL> xs(ALL(xset));
    
  LL cur=0,res=0;
  map<LL,LL> imos;
  REP(i,SZ(xs)) {
    LL x=xs[i];
    if(imos.count(x)) cur+=imos[x];
    assert(cur>=0);
    if(ms.count(x)) {
      LL h=ms[x];
      LL rem=max(0LL,h-cur);
      LL cnt=(rem+A-1)/A;
      LL damage=A*cnt;
      cur+=damage,imos[x+2LL*D+1]-=damage;
      res+=cnt;
//      dump(i,x,h,rem,cnt);
    }
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>D>>A;
  REP(i,N) {
    cin>>X[i].first>>X[i].second;
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 51260
/*
 *  Author : Jun_SH
 *  12/11/2019
 */
#include<bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
main(){
    ios::sync_with_stdio(false);
    double a,b,n;
    cin>>a>>b>>n;
    double s=n/a;
    double ts=a*b-s;
    if(2*ts<=a*b){
        cout<<fixed<<setprecision(10)<<atan(2*ts/a/a)*180/acos(-1)<<endl;
    }
    else cout<<fixed<<setprecision(10)<<90.0-atan(2*s/b/b)*180/acos(-1)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

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

    vector<int> cards;
    for (int i=0; i<N; i++) {
        int a; cin >> a;
        cards.push_back(a);
    }
    sort(cards.begin(), cards.end());

    vector<pair<int, int> > v;
    for (int i=0; i<M; i++) {
        int b,c; cin >> b >> c;
        v.push_back(make_pair(c,b));
    }
    sort(v.rbegin(), v.rend());

    int i = 0;
    for (int m=0; m<M; m++) {
        int c = v[m].first;
        int b = v[m].second;
        while (i < N && b > 0 && cards[i] < c) {
            cards[i] = c;
            i++;
            b--;
        }
    }

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int ans = 0;

		for (int a = 0; a <= A; a++) {
			for (int b = 0; b <= B; b++) {
				int c = (X - (500 * a) - (100 * b)) / 50;
				if (c >= 0 && c <= C) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}

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

int main(){
    
    int S;
    
    cin >> S;
    int h,m,s;
    h = S / 60 / 60;
    m = S / 60 % 60;
    s = S % 60;
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}

Measured memory_bytes: 1164
N, K = map(int, input().split())

if (K > (N - 1) * (N - 2) // 2):
  print(-1)
  exit(0)
bstar = (N - 1) * (N - 2) // 2 - K
print(N - 1 + bstar)
for i in range(2, N + 1):
  print(1, i)

for i in range(2, N + 1):
  for j in range(i + 1, N + 1):
    if bstar > 0:
      print(i, j)
      bstar -= 1
    else:
      exit(0)

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p.at(i);
  int count = 0;
  for (int i = 1; i < N-1; i++) {
    if ((p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1)) || (p.at(i+1) < p.at(i) && p.at(i) < p.at(i-1))) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	int a, b;
	std::cin >> a >> b;
	if(a>=13){
	    std::cout << b << std::endl;
	}else if(a>=6 and a<=12){
	    std::cout << (b / 2) << std::endl;
	}else{
	    std::cout << 0 << std::endl;
	}
	return 0;
}

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

using namespace std;

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

    long long ans = 0, cnt = 0;
    for (int i = 0; i < S.length(); ++i) {
        if (S[i] == 'B')
            ++cnt;
        else
            ans += cnt;
    }
    cout << ans << endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli X,Y,A,B,C;
	cin>>X>>Y>>A>>B>>C;

	priority_queue<lli,vector<lli>,greater<lli>> aq,bq;

	vector<lli> a(A),b(B),c(C);
	REP(i,0,A)cin>>a[i];
	REP(i,0,B)cin>>b[i];
	REP(i,0,C)cin>>c[i];

	sort(a.rbegin(),a.rend());
	sort(b.rbegin(),b.rend());
	sort(c.rbegin(),c.rend());

	lli sumA=0,sumB=0;
	REP(i,0,X){
		aq.push(a[i]);
		sumA+=a[i];
	}
	REP(i,0,Y){
		bq.push(b[i]);
		sumB+=b[i];
	}

	lli ans = sumA+sumB;
	if(DEBUG)cout<<ans<<endl;

	REP(i,0,C){
		if(DEBUG)cout<<"sumA="<<sumA<<" sumB="<<sumB<<endl;
		if(DEBUG)cout<<"aqT="<<aq.top()<<"bqT="<<bq.top()<<endl;
		if(aq.top()>bq.top()){
			sumB -= bq.top();
			bq.pop();
			bq.push(c[i]);
			sumB+=c[i];
		}
		else{
			sumA -= aq.top();
			aq.pop();
			aq.push(c[i]);
			sumA += c[i];
		}
		ans = max(ans,sumA+sumB);
	}
	cout<<ans<<endl;




	return 0;
}

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

#define int long long
#define REP(i, l, r) REPEAT(i,l,r,true) // [l, r)
#define rep(i, n) REP(i,0,n)           // [0, n)
#define REPEAT(i, l, r, condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n, l, r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...) true
#define showlr(n,l,r) true
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int, int>;

struct io {
    io() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.tie(0);
        cout << fixed << setprecision(20);
    }
} io;

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &e:v)is >> e;
    return is;
}

template<class T>
ostream &operator<<(ostream &os, vector<T> v) {
    os << "{";
    for (T &e:v)os << e << (v.size() - (int) (&e - &v[0]) > 1 ? ", " : "");
    os << "}";
    return os;
}

void _DEBUG() {}

template<typename H, typename... T>
void _DEBUG(H a, T...b) {
    cerr << a << (sizeof...(b) ? "," : "\n");
    _DEBUG(b...);
}

inline void in() {}

template<typename H, typename... T>
void in(H &a, T &... b) {
    cin >> a;
    in(b...);
}

inline void out() {}

template<typename H, typename... T>
void out(H a, T... b) {
    cout << a << (sizeof...(b) ? " " : "\n");
    out(b...);
}

template<class T>
void resz(int n, T &v) { v.resize(n); }

template<class H, class... T>
void resz(int n, H &a, T &... b) {
    a.resize(n);
    resz(n, b...);
}

template<typename V, typename H>
void resize(vector<V> &v, const H a) { v.resize(a); }

template<typename V, typename H, typename... T>
void resize(vector<V> &v, const H &a, const T... b) {
    v.resize(a);
    for (auto &v:v) resize(v, b...);
}

const int INF = 1LL << 55;
const int MOD = 1000000007;
const double EPS = 1e-8;

/*------------end of definitions------------*/

int H, W;

void solve() {
    map<char, pint> M;
    rep(i, H) {
        rep(j, W) {
            char c;
            in(c);
            M[c] = {i, j};
        }
    }
    vector<pint> V;
    V.pb({0, 0});
    string S;
    in(S);
    int ans = S.size();
    for_each(all(S), [&V, &M](char c) { V.pb(M[c]); });

    REP(i, 1, V.size()) {
        ans += abs(V[i - 1].first - V[i].first) + abs(V[i - 1].second - V[i].second);
    }
    out(ans);
}

signed main() {

    while (in(H, W), H) {
        solve();
    }

    return 0;
}



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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e10;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
typedef tuple<int, int, int> Q;


int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n << endl;
    } else {
        cout << n * 2 << endl;
    }
}



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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string S;
    cin >> S;

    if(S == "Sunny") cout << "Cloudy" << endl;
    else if (S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = min(n * a, b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }.sortedDescending()
    val alice = a.filterIndexed { index, i -> index and 1 == 0 }.sum()
    val bob = a.filterIndexed { index, i -> index and 1 == 1 }.sum()
    println(alice - bob)
}


Measured memory_bytes: 38360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<bool> AC(N, false);
	int ok = 0, penalty = 0;
	vector<int> debt(N, 0);
	for (int i = 0; i < M; i++) {
		int p;
		string S;
		cin >> p >> S;
		p--;
		if (!AC[p]) {
			if (S == "AC") {
				AC[p] = true;
				ok++;
				penalty += debt[p];
				debt[p] = 0;
			}
			if (S == "WA") debt[p]++;
		}
	}
	cout << ok << " " << penalty << endl;
	
	return 0;
}

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

using namespace std;

int main(){

string s,bk,fr,ans;
cin >> s;
ans = s;
long long q; cin >> q;
long long t1[q],t2[q],f[q];
char c[q];

for (long long i = 0; i < q; ++i)
{
    int t; cin >> t;
    if (t == 1)
    {   
        if (i==0)
        {
            t1[0] = 1;
        }
       else 
        {
        t1[i] = t1[i-1]+1;
        t2[i] =0;
        }
    }
    else if(t==2)
    {
        if (i==0)
        {
            t2[0] = 1;t1[0] = 0;
        }
        else 
        {
             t2[i] = 1;
             t1[i] = t1[i-1];
         }

        int fin;cin >> fin;
        cin >> c[i];
        if (fin==1)
        {
           f[i] = 0;
        }
        else if(fin == 2)
        {
            f[i] = 1;
        }
    }    
}
if (t1[q-1]%2==1)
{
    reverse(ans.begin(),ans.end());
}
for (int i = 0; i < q; ++i)
{
   if (t2[i] && (t1[q-1]-t1[i]+f[i])%2 == 0)
   {
       fr = fr+c[i];
   }
   else if(t2[i] && (t1[q-1]-t1[i]+f[i])%2 == 1)
   {
    bk = bk + c[i];
   }
}
ans = ans + bk;
reverse(ans.begin(),ans.end());
ans = ans + fr;
reverse(ans.begin(),ans.end());

cout << ans;
    return 0;
}

Measured memory_bytes: 6700
X=int(input())
flg=0
ans=[]
for i in range(-500,500):
	if flg!=0:break
	for j in range(-500,500):
		if i**5-j**5==X:
			ans=[i,j]
			flg=1
		if flg!=0:break
print(str(ans[0])+" "+str(ans[1]))

Measured memory_bytes: 64612
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 500005
#define M 10005
#define INF 1000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-7
using namespace std;

vector<int>e[N];
int dep[N];
int dfs(int u,int fa)
{
    for(auto v:e[u])
    {
        if(v == fa)continue;
        dfs(v,u);
    }
    sort(e[u].begin(),e[u].end(),[](const int a,const int b){return dep[a]>dep[b];});
    int max_dep = 1;
    int now = 1;
    for(auto v:e[u])max_dep = max(max_dep,(now++)+dep[v]);
    //cout<<u<<" "<<max_dep<<endl;
    return dep[u] = max_dep;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        FOR(i,1,n)e[i].clear();
        FOR(i,2,n)
        {
            int x;
            cin>>x;
            e[x].PB(i);
        }
        cout<<dfs(1,-1)-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 23296
#include<stdio.h>

int main(void){
  int a=0,b=0;
  scanf("%d %d",&a,&b);
  if(a>=1){
    if(a<=9){
      if(b>=1){
        if(b<=9){
          printf("%d",a*b);
		}
		else{
    printf("-1");
  }
	  }
	  else{
    printf("-1");
  }
	}
	else{
    printf("-1");
  }
  }
  else{
    printf("-1");
  }
  return 0;
}

Measured memory_bytes: 128
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<u64>();
    let b = read_vec::<u64>();
    if a.iter().sum::<u64>() < b.iter().sum::<u64>() {
        println!("-1");
        return;
    }

    let mut yojou = std::collections::BinaryHeap::new();
    for i in 0..n {
        if a[i] > b[i] {
            yojou.push(a[i] - b[i]);
        }
    }
    let mut ans = 0;
    let mut buffer = 0;
    for i in 0..n {
        if a[i] >= b[i] {
            continue;
        }
        ans += 1;
        while buffer < b[i] - a[i] {
            buffer += yojou.pop().unwrap();
            ans += 1;
        }
        buffer -= b[i] - a[i];
    }
    println!("{:?}", ans);
}


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

int main(){

    int N, ans=0; cin >> N;
    for (int n=1; n<=N; n++){
        int cnt=0;
        if (n%2!=0){
            for (int i=1; i<=n; i++){
                if (n%i==0) cnt++;
            }
        }
        if (cnt==8) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3620
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int dp[2000];
int n, k, c, g;
vector<int> b[11], v[11];
int main() {
	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> c >> g;
		b[g].emplace_back(c);
	}

	for (int i = 1; i <= 10; i++) {
		sort(ALL(b[i]), greater<int>());
		v[i].emplace_back(0);
	}

	for (int i = 1; i <= 10; i++) {
		for (int j = 0; j < b[i].size(); j++) {
			v[i].emplace_back(v[i][j] + b[i][j] + j * 2);
		}
	}

	for (int i = 1; i <= 10; i++) {
		for (int j = k; j >= 0; j--) {
			for (int h = max(0, j - (int)v[i].size() + 1); h < j; h++) {
				dp[j] = max(dp[j], dp[h] + v[i][j - h]);
			}
		}
	}

	cout << dp[k] << endl;
}

Measured memory_bytes: 3184
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int a,b,c;

int main(){
  ll ans=0;
  cin >> a >> b>>c;
  if ((a+b+c)>=22){
  cout<<"bust"<<endl;
  }else{
  cout<<"win"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	cnt := 0
	for i := 1; i < n-1; i++ {
		if (xs[i-1] < xs[i] && xs[i] < xs[i+1]) || (xs[i+1] < xs[i] && xs[i] < xs[i-1]) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
左から順番に、上から順番に上に乗れるか調べる
*/

int h,w,n,ans,top=1;
vector<int> v[200010];
map<pair<int,int>,int> m;

int main(void){
	cin>>h>>w>>n;
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		v[y].push_back(x);
		m[{x,y}]=1;
	}
	reg(y,1,w)sort(v[y].begin(),v[y].end());
	ans=h;
	reg(y,1,w){//左から順番に探索
		reg(i,top,h){
			if(!m.count({i,y})){
				top=i;
				break;
			}
		}
		// cout<<"top="<<top<<endl;
		rep(i,v[y].size()){
			if(top<v[y][i]){
				ans=min(ans,v[y][i]-1);
				break;
			}
		}
		top++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 21248
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();

        int N = sc.nextInt();
        int i = 0;
        int j = 0;
        while( i < N) {
        	map.put(sc.nextInt(),i + 1);
        	i++;
        }
        while ( j < N) {
        	System.out.print(map.get(j+1) + " ");
        	j++;
        }

    }
}


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

using namespace std;

int main(){

  	int input;
  	vector<int> data;
  	while(cin >> input){
    	data.push_back(input);
    }
  
  	for(int i=0; i<data.size(); i++){
      	if(data.at(i) != 0){
    		cout << "Case " << i+1 <<": " << data.at(i) <<endl; 
        }
    }
  
    return 0;
}


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

//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4"

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)(1<<16);
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n,a[16][16];
int dp[maxn],dp1[maxn];
main () {
  cin>>n;
  forn(i,0,n-1)
    forn(j,0,n-1)
      cin>>a[i][j];
  forn(i,0,maxn-1)
    dp[i]=-inf*inf;
  dp[0]=0;
  forn(msk,0,(1<<n)-1){
    int cost=0;
    forn(i,0,n-1){
      if(!((msk>>i)&1))continue;
      forn(j,i,n-1)
        if((msk>>j)&1)
          cost+=a[i][j];
    }
    for(int sub=msk;;sub=(sub-1)&msk){
      dp[msk]=max(dp[msk],dp[sub]+dp[sub^msk]);
      if(!sub) break;
    }
    dp[msk]=max(dp[msk],cost);
  }
  cout<<dp[(1<<n)-1];
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main(){
  int x=0;
  int ans=0;
  int n; cin>>n;
  string s; cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      x+=1;
    }
    if(s[i]=='D'){
      x-=1;
    }
    if(x>ans)ans=x;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
S_list = [input() for i in range(2)]
N, M, X= map(int,S_list[0].split())    
A_list = list(map(int,S_list[1].split()))

A_goal_N = [i for i in A_list if X < i and i < N]
A_goal_0 = [i for i in A_list if 0 < i and i < X]
result = min(len(A_goal_N),len(A_goal_0))
print(result)

Measured memory_bytes: 9080
#include <iostream>
#include <cstring>
#include <string>
int main()
{
    std::string s;
    std::cin>>s;
    int x=0,y=0,z=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='a')x=1;
        if(s[i]=='b')y=1;
        if(s[i]=='c')z=1;
    }
    if(x&&y&&z)std::cout<<"Yes\n";
    else std::cout<<"No\n";
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

a,b,c,d = map(int,readline().split())


dp1 = [[0]*(d+1) for _ in range(c+1)] #下OK
dp2 = [[0]*(d+1) for _ in range(c+1)] #下NG

dp1[a][b] = 1

#print(dp1)
#print(dp2)
MOD = 998244353
for i in range(a,c+1):
    for j in range(b,d+1):
        if i != c:
            dp1[i+1][j] += j*dp1[i][j]
            dp1[i+1][j] += dp2[i][j]
            dp1[i+1][j] %= MOD
        if j != d:
            dp2[i][j+1] += i*dp2[i][j]
            dp2[i][j+1] += i*dp1[i][j]
            dp2[i][j+1] %= MOD
            
#print(dp1)
#print(dp2)

print((dp1[c][d]+dp2[c][d])%MOD)


Measured memory_bytes: 210020
#include <bits/stdc++.h>
using namespace std;
int dp[10][10];
void init(){
    for (int i=0;i<10;++i) dp[0][i]=1;
    for (int i=1;i<10;++i){
        for (int j=0;j<10;++j){
            for (int k=j-1;k<=j+1;++k){
                if (k<0 || k>9) continue;
                dp[i][j]+=dp[i-1][k];
            }
        }
    }
}
long long solve(int k){
    int i,j;
    for (i=0;i<10;++i){
        for (j=1;j<10;++j)
            if (k>dp[i][j]) k-=dp[i][j];
            else break;
        if (j<10) break;
    }
    long long ans=j;
    int last=j;
    for (i=i-1;i>=0;--i){
        for (j=last-1;j<=last+1;++j){
            if (j<0 || j>9) continue;
            if (k>dp[i][j]) k-=dp[i][j];
            else break;
        }
        ans=ans*10+j;
        last=j;
    }
    return ans;
}
int main(){
    init();
    int n;
    cin>>n;
    cout<<solve(n)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a<=k){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmp( const void *p, const void *q ) {
  return *(int*)p - *(int*)q;
}
int main(void){
  int n,med, x[200005],t[200005];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&x[i]);
    t[i]=x[i];
  }
  qsort(x, n, sizeof(int),cmp);
  /*  for(int i=0;i<n;i++){
    printf("%d",x[i]);
    printf("%d",t[i]);
    }*/
  med=x[n/2-1];
  for(int i=0;i<n;i++){
    if(t[i]<=med) printf("%d\n",x[n/2]);
    if(t[i]>med) printf("%d\n",med);
  }

  return 0;
}




Measured memory_bytes: 3848
n = int(input(), 2)  + 1
MOD = 10**9 + 7
B = [[3, 0], [1, 2]]
A = [[1, 2], [0, 3]]
ans = [[1, 0], [0, 1]]

while True:
    if n == 1:
        break
    if n % 2 == 1:
        ans = [[(ans[0][0]*A[0][0] + ans[0][1]*A[1][0]) % MOD, (ans[0][0]*A[0][1] + ans[0][1]*A[1][1]) % MOD], \
               [(ans[1][0]*A[0][0] + ans[1][1]*A[1][0]) % MOD, (ans[1][0]*A[0][1] + ans[1][1]*A[1][1]) % MOD]]
        n = (n-1)//2 + 1
    else:
        ans = [[(ans[0][0]*B[0][0] + ans[0][1]*B[1][0]) % MOD, (ans[0][0]*B[0][1] + ans[0][1]*B[1][1]) % MOD], \
               [(ans[1][0]*B[0][0] + ans[1][1]*B[1][0]) % MOD, (ans[1][0]*B[0][1] + ans[1][1]*B[1][1]) % MOD]]
        n = n//2
print(ans[0][0] % MOD)

Measured memory_bytes: 42972
#include <stdio.h>
#include <math.h>
#define sqr(x) ((x) * (x))

int main(void){
double x1, y1, x2, y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
printf("%f\n",sqrt(sqr(x2 - x1) + sqr(y2 - y1)));
return 0;
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define nl '\n'

using namespace std;

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

void solve()
{
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<nl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	//cin>>t;
	t = 1;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int H, W, N;

int main() {
	cin >> H >> W >> N;
	int now = 0;
	int ans = 0;
	while (now < N) {
		ans++;
		now += max(H, W);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
w, h, n = map(int, input().split())


d = []
for _ in range(n):
  a = [int(i) for i in input().split()]
  d.append(a)
  
#print(w, h)
  
x1 = [0]
x2 = [w]
y1 = [0]
y2 = [h]

for i in range(n):
  if d[i][2] == 1:
    x1.append(d[i][0])
  if d[i][2] == 2:
    x2.append(d[i][0])
  if d[i][2] == 3:
    y1.append(d[i][1])
  if d[i][2] == 4:
    y2.append(d[i][1])
#print(x1, x2, y1, y2)
x1 = sorted(x1, reverse = True)[0]
x2 = sorted(x2)[0]
y1 = sorted(y1, reverse = True)[0]
y2 = sorted(y2)[0]

sum = (x2 - x1)*(y2 - y1)
if x2 - x1 >= 0 and y2 - y1 >= 0:
  print(sum)
else:
  print(0)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int n;
vector<int> v(N);
int dp[N];
int dfs(int pos){
    if(pos == n){
        return INF;
    }
    if(pos == n - 1){
        return 0;
    }
    int &res = dp[pos];
    if(res != -1){
        return res;
    }
    return res = min(dfs(pos + 1) + abs(v[pos] - v[pos + 1]), dfs(pos + 2) + abs(v[pos] - v[pos + 2]));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        memset(dp, -1, sizeof(dp));
        cout << dfs(0) << '\n';
    }
}

Measured memory_bytes: 48640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int h, w;
string s[55];
int d[55][55];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> h >> w;
	int cnt = 0;
	FOR(i, h) {
		cin >> s[i];
		FOR(j, w) {
			d[i][j] = 1e9;
			if (s[i][j]=='#') cnt++;
		}
	}
	queue<P> que;
	que.push({0, 0});
	d[0][0] = 0;
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		if (p.first == h-1 && p.second == w-1) break;
		FOR(i, 4) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx >= 0 && nx < h && ny >= 0 && ny < w && s[nx][ny] != '#' && d[nx][ny] == 1e9) {
				que.push({nx, ny});
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	// cout << d[h-1][w-1] << endl;
	// cout << cnt << endl;
	if (d[h-1][w-1] == 1e9) cout << -1 << endl;
	else {
		cout << h*w-d[h-1][w-1]-cnt-1 << endl;
	}
	return 0;
}

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

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

	int ans = 0;
	int sums = 0;
	int sumt = 0;
	for (int i = 0;i < x.size();i++) {
		if (x[i] == 'S') {
			sums++;
		}
		else {
			sumt++;
			if (sumt - ans > sums) {
				ans ++;
			}
		}
	}
	cout << ans * 2 << endl;

	return 0;
}

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

using namespace std;
typedef long long int ll;
int main() {
    
    ll n, i, j, a[200], dap=1000, stock=0;
    cin>>n;
    for(i=1;i<=n;i++)
    cin>>a[i];
    
    for(i=1;i<=n;i++)
    {
        if((i==1)&&(a[i]<a[i+1]))
        {
            stock+=(dap/a[i]);
            dap=dap%a[i];
            
        }
        else if(i==1)
        {
            
        }
        else if((i==n))
        {
            dap+=a[i]*stock;
            stock=0;
            
        }
        else if((a[i]>=a[i-1])&&(a[i]>a[i+1]))
        {
            dap+=a[i]*stock;
            stock=0;
        }
        else if((a[i]<=a[i-1])&&(a[i]<a[i+1]))
        {
            stock+=(dap/a[i]);
            dap=dap%a[i];
        }
        
    }
    
    
    cout<<dap;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i,m,n) for(int i = (int)(m) ; i < (int) (n);i++)
#define rep(i,n) REP(i,0,n)

int n;
int a[25], b[25], c[25];
int ans;


int main(){
	cin >> n;
	REP(i,1,n + 1) {
		cin >> a[i];
	}
	REP(i,1, n + 1) {
		cin >> b[i];
	}
	REP(i, 1 , n ) {
		cin >> c[i];
	}
	REP(i, 1 , n + 1 ){
		ans += b[a[i]];
		if (i < n){
			if (a[i] == a[i + 1] - 1){
				ans += c[a[i]];
			}
		}
	}
	cout << ans << endl;



}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
const int N=200005,M=55;

int n;
ll ans;
pii a[N];
int st[M][M][M][M];

ll read()
{
    ll x=0,d=0;
    char ch;bool f=false;
    do ch=getchar();while(~ch&&(ch<48||ch>57));
    for(;ch>47&&ch<58||ch=='.';ch=getchar())
        if(ch!='.')x=(x<<1)+(x<<3)+(ch^48),d+=f;
        else f=true;
    for(int i=10-d;i;i--)x*=10;
    return x;
}

ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}

int get(ll x,int p)
{
    int k=0;
    while(!(x%p))x/=p,k++;
    return k;
}

void add(int a,int b,int c,int d)
{
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int u=c;u<M;u++)
                for(int v=d;v<M;v++)
                    st[i][j][u][v]++;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        a[i].first=read();
        a[i].second=1e10;
    }
    for(int i=0;i<n;i++)
    {
        ll d=gcd(a[i].first,a[i].second);
        a[i].first/=d,a[i].second/=d;
    }
    for(int i=0;i<n;i++)
    {
        int u=get(a[i].first,2),v=get(a[i].first,5);
        int x=get(a[i].second,2),y=get(a[i].second,5);
        ans+=st[x][y][u][v];
        add(u,v,x,y);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7120
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){

	  int n;
	  cin>>n;
	  unordered_map<string,int> m;
	  string s;
	  FOR(i,n){
	  cin>>s;
	  m[s]++;}
	  out1("AC x ");
	  out(m["AC"]);
	  out1("WA x ");
	  out(m["WA"]);
	  out1("TLE x ");
	  out(m["TLE"]);
	  out1("RE x ");
	  out(m["RE"]);

}


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

int N, K;
const int MAX_N = 1.0e5 + 100; 
int h[MAX_N];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> h[i];

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (h[i] >= K) ans++;
    }
    
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int N,C,p1,p2,H;
    cin>>N>>C;
    p2=0; H=0;
    H=N+1;
    for(int i=0;i<C;i++){
        cin>>p1;
     p2=p2+p1;
    }
    if(p2%H==0){
        cout<<p2/H<<endl;
    }
    else if(p2%H>0){
        cout<<(p2/H)+1<<endl;
    }
}


Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int counter1,counter2;
int w, h;
int x, y;
char map[50][50];

void serch_w(int x, int y);
void serch_b(int x, int y);

int main(){

	while (cin >> w >> h, w&&h){
		counter1 = 0;
		counter2 = 0;
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				cin >> map[i][j];
			}
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (map[i][j] == 'W'){
					x = i;
					y = j;
					serch_w(x, y);
				}
			}
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (map[i][j] == 'B'){
					x = i;
					y = j;
					serch_b(x, y);
				}
			}
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (map[i][j] == '2') counter1++;
				if (map[i][j] == '1') counter2++;
			}
		}

		cout << counter2 << " " <<counter1 << endl;
	}
	return 0;
}

void serch_w(int x, int y){

	//if(?????????????????§??????&&??£??\???????????????'.'????????§??????)
	if (x + 1 < h && map[x + 1][y] == '.' && map[x + 1][y] != '2'){
		map[x + 1][y] = '2';
		serch_w(x + 1, y);
	}
	if (y + 1 < w && map[x][y + 1] == '.' && map[x][y + 1] != '2'){
		map[x][y + 1] = '2';
		serch_w(x, y + 1);
	}
	if (x - 1 >= 0 && map[x - 1][y] == '.' && map[x - 1][y] != '2'){
		map[x - 1][y] = '2';
		serch_w(x - 1, y);
	}
	if (y - 1 >= 0 && map[x][y - 1] == '.' && map[x][y - 1] != '2'){
		map[x][y - 1] = '2';
		serch_w(x, y - 1);
	}
}

void serch_b(int x, int y){


	if (x + 1 < h && map[x + 1][y] == '.'){
		map[x + 1][y] = '1';
		serch_b(x + 1, y);
	}
	else if (x + 1 < h &&  map[x + 1][y] == '2'){
		map[x + 1][y] = '3';
		serch_b(x + 1,y);
	}


	if (y + 1 < w && map[x][y + 1] == '.' ){
		map[x][y + 1] = '1';
		serch_b(x, y + 1);
	}
	else if (y + 1 < w &&  map[x][y + 1] == '2'){
		map[x][y + 1] = '3';
		serch_b(x, y+1);
	}

	if (x - 1 >= 0 && map[x - 1][y] == '.'){
		map[x - 1][y] = '1';
		serch_b(x - 1, y);
	}
	else if (x - 1 >= 0 &&  map[x - 1][y] == '2'){
		map[x - 1][y] ='3';
		serch_b(x - 1, y);
	}

	if (y - 1 >= 0 && map[x][y - 1] == '.'){
		map[x][y - 1] = '1';
		serch_b(x, y - 1);
	}
	else if (y - 1 >= 0 &&  map[x][y - 1] == '2'){
		map[x][y - 1] = '3';
		serch_b(x, y - 1);
	}

}

Measured memory_bytes: 1216