akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin>>x;
	int ans=1;
	for(int j=2;j<=x;j++){
		int ret=j;
		while(ret<=x){
			ret*=j;
			if(ret<=x){
				ans=max(ans,ret);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (a == b && a == c) {
        printf("No\n");
    }
    else if (a != b && b != c && a != c) {
        printf("No\n");
    }
    else {
        printf("Yes\n");
    }
}

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;

const int INF = 1001001001;

int main(){
  int h,n;
  cin >>h >>n;
  vector<int> dp(h+1,INF);
  dp[0] = 0;
  rep(i,n){
   int a,b;
   cin >> a >> b;
   rep(j,h){
     int nj = min(j+a,h);
     dp[nj] = min(dp[nj], dp[j]+b);
   }
  }
  cout << dp[h] << endl;
}

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

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

int main()
{
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<int> ty(q);
  vector<int> f(q);
  vector<char> c(q);
  deque<char> deq;
  for (auto c : s)
  {
    deq.emplace_back(c);
  }
  int cur = 0;
  rep(i, q)
  {
    cin >> ty[i];
    ty[i]--;
    if (ty[i])
    {
      cin >> f[i] >> c[i];
      f[i]--;
      f[i] ^= cur;
      if (f[i])
      {
        deq.emplace_back(c[i]);
      }
      else
      {
        deq.emplace_front(c[i]);
      }
    }
    else
    {
      cur ^= 1;
    }
  }
  if (cur)
  {
    reverse(deq.begin(), deq.end());
  }
  for (auto s : deq)
  {
    cout << s;
  }
  cout << endl;
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 2688
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define rep(i,j,k) for(int i=j; i<k; ++i)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io 
	int n,m; cin>>n>>m;
	if(m==n) cout<<"Yes";
	else cout<<"No";
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    string s;
    cin >> n >> s;
    vector< vector<int> > rgb(3, vector<int>(n+1, 0));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++) rgb[j][i+1] = rgb[j][i];
        if(s[i] == 'R') rgb[0][i+1]++;
        if(s[i] == 'G') rgb[1][i+1]++;
        if(s[i] == 'B') rgb[2][i+1]++;
    }
    long long ans = 0;
    for(int j=2;j<n;j++){
        int a, b;
        
        if(s[j-1] == 'R'){ a = 1; b = 2; }
        if(s[j-1] == 'G'){ a = 0; b = 2; }
        if(s[j-1] == 'B'){ a = 0; b = 1; }
        
        
        ans += rgb[a][j] * (rgb[b][n]-rgb[b][j]) + rgb[b][j] * (rgb[a][n] - rgb[a][j]);

        for(int i=1;;i++){
            if(j-1-i < 0) break;
            if(j-1+i >= n) break;
            char x = s[j-1-i];
            char y = s[j-1+i];
            if(x != y && x != s[j-1] && y != s[j-1]) ans--;
        }
    }
    cout << ans << endl;
}


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

int main()
{
    int h, w;
    char sij;
    cin >> h >> w;

    bool p[52][52] = { 0 };
    string ans = "Yes";
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> sij;
            p[i+1][j+1] = (sij == '#');
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(!p[i][j]) continue;
            if(!p[i-1][j] && !p[i+1][j] && !p[i][j-1] && !p[i][j+1]){
                ans = "No";
                break;
            }
        }
    }

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


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

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int A, B, C, X, Y;

int main(void)
{
  cin >> A >> B >> C >> X >> Y;

  int ans = 0;
  int x = X, y = Y;
  // 安ければ買う
  while ((x > 0 && y > 0 && (A + B > 2 * C)) ||
         ((x > 0 && A > 2 * C) || (y > 0 && B > 2 * C))) {
    ans += 2 * C;
    x--, y--;
  }

  while (x > 0) {
    ans += A;
    x--;
  }

  while (y > 0) {
    ans += B;
    y--;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]

SIZE = 20000
dp = [[0 for _ in range(W)] for _ in range(H)]
dp[0][0] = 1 << (SIZE + C[0][0]) | 1 << (SIZE - C[0][0])

for i in range(H):
    for j in range(W):
        if i == j == 0:
            continue
        else:
            dp[i][j] |= dp[i - 1][j] << C[i][j] | dp[i - 1][j] >> C[i][j]
            dp[i][j] |= dp[i][j - 1] << C[i][j] | dp[i][j - 1] >> C[i][j]

for i in range(SIZE):
    if (dp[-1][-1] >> (i + SIZE)) & 1:
        print(i)
        exit()

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

int main(){
  int n,sum=0,it;
  cin >> n;
  bool flag=true;
  vector<int> v(n,0);
  r(i,n){
    cin >> v.at(i);
    sum+=v.at(i);
  }
  if(sum%10!=0)cout << sum << endl;
  else{
    sort(v.begin(),v.end());
    r(i,n){
      if(v.at(i)%10!=0){
        it=i;break;
      }
      if(i==n-1)flag=false;
    }
    if(flag){
      cout << sum-v.at(it)<<endl;
    }
    else cout << 0 << endl;
  }
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000

void initialize();
int isEmpty();
int isFull();
void push(int);
int pop();
int top;
int S[100];

int main(){
  int x,n,m;
  char s[100];
  initialize();
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      n = pop();
      m = pop();
      push(n + m);
    } else if ( s[0] == '-' ){
      n = pop();
      m = pop();
      push(m - n);
    } else if ( s[0] == '*' ){
      n = pop();
      m = pop();
      push(n * m);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",S[top]);
  return 0;
}

void initialize() {
  top = 0;
    }
int isEmpty() {
  if(top == 0) return 0;
  else return 1;
     }
int isFull() {
   if(top >= MAX - 1)  return 1;
   else return 0;
     }
void push(int x) {
  if(isFull() ==  1) {
   printf("??¨?????????????????????????????????\n");
  }
  top++;
     S[top] = x;
	      }
int pop() {
  if(isEmpty() == 0) {
    printf("??¨???????????¢?????????????????????\n");
  }
  top--;
     return S[top+1];
   }

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef map<ll,ll> mll;
typedef set<ll> sll;

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

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

  ll n,m;
  cin>>n>>m;
  if(m==n)
    cout<<"Yes";
  else
    cout<<"No";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 10000009;
const int MOD = 1e9 + 7;
int cnt[maxn];
bool vis[maxn];
int main(){
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n;cin>>n;
  for(int i=1;i<=n;++i)cnt[i]=1;
  for(int i=2;i<=n;++i)if(vis[i]==0){
    for(int j=i;j<=n;j+=i){
      vis[j]=1;
      int N=j,c=0;
      while(N%i==0)c++,N/=i;
      cnt[j]*=(c+1);
    }
  }
  int64_t res=0;
  for(int i=1;i<=n;++i){
    res+=1ll*i*cnt[i];
  }
  cout<<res<<'\n';
  
  return 0;
}
//2020.06.27 20:12:17


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

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

int main(){
    int A,B; cin >> A >> B;
    
    if(B % A == 0) cout << A + B << endl;
    else cout << B -  A << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

int w, h;
char c[71][71];
string result[71][71];

bool compare(string s1, string s2)
{
    int l1 = s1.length(), l2 = s2.length();
    if(l1 > l2) return true;
    else if(l1 < l2) return false;
    else {
        for(int i = 0; i < l1; i++){
            if(s1[i] > s2[i]) return true;
            else if(s1[i] < s2[i]) return false;
        }
    }
    return true;
}

bool ismax(string s1, string s2)
{
    while(s1 != "" && s1[0] == '0'){
        s1 = s1.substr(1);
    }
    while(s2 != "" && s2[0] == '0'){
        s2 = s2.substr(1);
    }
    if(s1 == "") s1 = "0";
    if(s2 == "") s2 = "0";
    int l1 = s1.length(), l2 = s2.length();
    if(l1 > l2) return true;
    else if(l1 < l2) return false;
    else {
        for(int i = 0; i < l1; i++){
            if(s1[i] > s2[i]) return true;
            else if(s1[i] < s2[i]) return false;
        }
    }
    return true; 
}
 
string solve(int x, int y)
{
    if(result[x][y] != "") return result[x][y];
    // cout << now << endl;
    string now = "", now2 = "";
    now += c[x][y];
    now2 += c[x][y];
    if(x + 1 < h && isdigit(c[x + 1][y])){
        now += solve(x + 1, y);
    }
    if(y + 1 < w && isdigit(c[x][y + 1])){
        now2 += solve(x, y + 1);
    }
    if(compare(now, now2)) result[x][y] = now;
    else result[x][y] = now2;
    return result[x][y];
}

int main()
{
    while(1){
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> c[i][j];
                result[i][j] = "";
            }
        }
        string ans = "0";
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(isdigit(c[i][j])){
                    string nows = solve(i, j);
                    if(ismax(nows, ans)) ans = nows;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1388
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N;
    cin >> N;
    int W[N];
    int sum=0;
    REP(i,N) cin >> W[i],sum+=W[i];
    int ans=10000;
    int res=0;
    REP(i,N) res+=W[i],sum-=W[i],ans=min(ans,abs(sum-res));
    cout << ans;
    }

Measured memory_bytes: 256
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll c=0,d=0,k=0,n,m,h,w,l,r,ans=100000;
    string s,s1,s2;
    cin >> l >> r;
    if(r-l+1 >= 2019) 
        cout << 0 << endl;
    else{
        for(ll i=l; i<r;i++){
            for(ll j=l+1; j<=r;j++){
                ans = min(ans, (i*j)%2019); 
            }
        }
        cout << ans <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll a, b;
ll ans;

int main() {
	cin >> a >> b;
	if(!(a & 1)) {
		if(b & 1) {
			ll ln = b - a + 1;
			if((ln / 2) & 1) ans = 1;
			else ans = 0;
		}
		else {
			ll ln = (b - 1) - a + 1;
			if((ln / 2) & 1) ans = b ^ 1;
			else ans = b ^ 0;
		}
	}
	else {
		if(b & 1) {
			ll ln = b - (a + 1) + 1;
			if((ln / 2) & 1) ans = a ^ 1;
			else ans = a ^ 0;
		}
		else {
			ll ln = (b - 1) - (a + 1) + 1;
			if((ln / 2) & 1) ans = a ^ 1 ^ b;
			else ans = a ^ 0 ^ b;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
chocolate = ['0' + input() for _ in range(h)]

white_count = [[0] * (w+1)]
for line in chocolate:
    prev = white_count[-1]
    cumsum = []
    total = 0
    for color, count in zip(line, prev):
        if color == '1':
            total += 1
        cumsum.append(total + count)
    white_count.append(cumsum)

ans = []
for pattern in range(2**(h-1)):
    dived = []
    for y in range(h-1):
        if (pattern >> y) & 1:
            dived.append(y + 1)

    dived.append(h)
    slash_count = len(dived) - 1

    prev_x = 0
    for nx in range(1, w + 1):
        prev_y = 0
        possible = True
        for ny in dived:
            white = white_count[ny][nx] - white_count[prev_y][nx] - (white_count[ny][prev_x] - white_count[prev_y][prev_x])
            prev_y = ny
            if white <= k:
                continue
            else:
                slash_count += 1
                slash = nx - 1
                if prev_x == slash:
                    possible = False
                prev_x = slash
                break

        if not possible:
            break

    else:
        ans.append(slash_count)

print(min(ans))


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

using namespace std;

using ll = long long;

const int MX = 200 * 1000 + 7;

int pos[MX];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        pos[x] = i;
    }
    int ptr = 1;
    int ans = 0;
    while (ptr <= n) {
        int go = ptr;
        while (go + 1 <= n && pos[go + 1] > pos[go]) {
            go++;
        }
        ans = max(ans, go - ptr + 1);
        ptr = go + 1;
    }
    cout << n - ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
long long N, M, a[100009][3], maxn = -(1LL << 40);
 
int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { 
                if ((i / (1 << k)) % 2 == 0) 
                    S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3672
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int g = sc.nextInt();
        int min = g;
        int count = 0;
        int sum = 0;
        for(int i = 0; i < n; i++){
        	int x = sc.nextInt();
            sum += x;
            if(min > x){
            	min = x;
            }
        }
        sum = g - sum;
        while(sum - min >= 0){
        	sum -= min;
            count++;
        }
        System.out.println(n + count);
    }
}

Measured memory_bytes: 36012
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Measured memory_bytes: 16152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */
int main()
{
	int		i,j,k,N;
	long long ans=0;
	int		h[10000],w[10000];

	N = 0;
	while(1) {
		scanf("%d %d", &h[N], &w[N]);
		if ((h[N]==0)&&(w[N]==0)) break;
		N++;
	}
	for(k=0;k<N;k++) {
		for(i=0;i<h[k];i++) {
			for(j=0;j<w[k];j++) {
				if ((i+j)%2==0) printf("#");
				else printf(".");
			}
			ENTER;
		}
		ENTER;
	}


	return 0;
}



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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    if(a >= k){
        ans = k;
        cout << ans << endl;
        return 0;
    }
    
    ans = a;
    k -= a;
    a = 0;

    if(b >= k){
        cout << ans << endl;
        return 0;
    }

    k -= b;
    b = 0;

    if(c >= k){
        ans -= k;
        cout << ans << endl;
        return 0;
    }

    k -= c;
    ans -= k;

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

Measured memory_bytes: 3636
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        int [] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = sc.nextInt();

        int idx = 0;
        int cnt = 0;
        while (idx < n) {
            int inc = idx;
            while (inc + 1 < n) {
                if (arr[inc] > arr[inc + 1])
                    break;
                inc++;
            }

            int dec = idx;
            while (dec + 1 < n) {
                if (arr[dec] < arr[dec + 1])
                    break;
                dec++;
            }
            cnt++;
            idx = Math.max(inc + 1, dec + 1);
        }

        out.println(cnt);
        out.flush();
        out.close();
    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner (FileReader f) {br = new BufferedReader(f);}

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

Measured memory_bytes: 39612
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int solve(vector<int>& a)
{
    int n = a.size();
    set<int> si;
    si.insert(0);

    for(int i=0; i<n; ++i){
        set<int> si1;
        while(!si.empty()){
            int tmp = *(si.begin());
            si.erase(si.begin());
            si1.insert(tmp + a[i]);
            si1.insert(abs(tmp - a[i]));
        }
        si = si1;
    }
    return *(si.begin());
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> a(n);
        for(int i=0; i<n; ++i)
            cin >> a[i];
        cout << solve(a) << endl;
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N,K;
	string S;
	cin>>N>>S>>K;

	char c=S[K-1];
	rep(i,N)if(S[i]!=c)S[i]='*';
	cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 256
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *NOIP 2019 RP++                                           *
 ***********************************************************/
//#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
    char *pp = (char*)malloc(size) + size;  \
    __asm__("movl %0, %%esp\n" :: "r"(pp))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) ((x>y)?x:y)
#define Min(x,y) ((x<y)?x:y)
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register int a=b;a<=c;++a)
#define FORD(a,b,c) for (register int a=b;a>=c;--a)
using namespace std;
//char buf[1<<20],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline ll read(){
    ll x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}
template<typename T>
inline void write(T a){
    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//

signed main(){
	#ifdef _WIN32
        freopen("0.in","r",stdin);
//        freopen("0.out","w",stdout);
//        ADD_STACK;
        long double be=clock();
    #endif
	int x=read(),a=read();
	if(x<a)puts("0");else puts("10");
	#ifdef _WIN32
        long double en=clock();
        printf("Time: %.0Lfms\n",en-be);
        fclose(stdin);fclose(stdout);
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b))) 
#define endl '\n'
typedef long long lli;        typedef long double ld;
typedef pair<lli,lli> ii;     typedef vector<lli> vi;
typedef vector<ii> vii;       typedef vector<vi> graph;
long long MOD=1000000007;     long double EPS=1e-9;
#define debarr(a,n) cerr<<#a<<" : ";for(lli i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cerr<<#mat<<" :\n";for(lli i=0;i<row;i++) {for(lli j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {lli idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
lli binpow(lli b,lli p,lli mod){lli ans=1;for(;p;p>>=1){if(p&1)ans=ans*b%mod;b=b*b%mod;}return ans;}

void pre(){

}

void solve(){
	string s;
	cin>>s;
	lli ans=0;
	lli n=s.length();
	lli cur=0;
	fr(i,n){
		if(s[i]=='W'){
			ans+=i-cur;
			cur++;
		}
	}
	cout<<ans<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	pre();lli t=1;//cin>>t;
	for(lli i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Measured memory_bytes: 720
#include<cstdio>

int main(){
  int n;
  
  while(scanf("%d",&n)!=EOF){
    int cnt=0;
    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
        for(int l=0;l<10;l++)
          for(int m=0;m<10;m++)
            if(i+j+l+m==n) cnt++;
    printf("%d\n",cnt);
  }

  return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl;

#define iosbase ios_base::sync_with_stdio(false)
#define tie cin.tie();cout.tie();

#define endl '\n'

typedef pair<int, int> ii;
typedef long long ll;

int n, m;
int main(){
  iosbase;
  tie;

  string s; cin >> s;

  if(s == "Sunny") cout << "Cloudy";
  if(s == "Cloudy") cout << "Rainy";
  if(s == "Rainy") cout << "Sunny";

  cout << endl;
}


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

#define ll long long int
#define hell 998244353
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve()
{
    ll k,x;
    cin>>k>>x;
    rep(i,x-k+1,x+1)
        cout<<i<<" ";
    rep(i,x+1,x+k)
        cout<<i<<" ";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

const int N = 2010;
bitset<N * N> dp[2];
int n, sum;

int main () {
	dp[0][0] = 1;
	n = read();
	int v = 1;
	For (i, 1, n) {
		int val = read();
		sum += val;
		dp[v] = dp[v ^ 1] | (dp[v ^ 1] << val) ;
		v ^= 1;
	}

	v ^= 1;
	For(i, (sum + 1) / 2, sum)
		if (dp[v][i])
			return printf("%d\n", i), 0;
		
    return 0;
}


Measured memory_bytes: 2816
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
import itertools

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        if serial >= sqrt:
            return input_list
        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

primeTable = sieve_of_erastosthenes(10**6)

while True:
    N,P = map(int,input().split(" "))
    if N == -1 and P == -1:
        break
    start = N+1
    while primeTable[start] is False:
        start += 1
    prime_list = []
    count = 0
    i = 0
    while count != P:
        if primeTable[start + i]:
            prime_list.append(start+i)
            count += 1
        i += 1
    print(sorted([sum(t) for t in itertools.combinations_with_replacement(prime_list,2)])[P-1])

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

mat = [[] for _ in range(h)]

for i in range(h):
    mat[i] = input()

dp = [[float("inf")] * w for _ in range(h)]

if mat[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(h):
    for j in range(w):

        if mat[i][j - 1] != mat[i][j]:
            left = dp[i][j - 1] + 1
        else:
            left = dp[i][j - 1]

        if mat[i - 1][j] != mat[i][j]:
            top = dp[i - 1][j] + 1
        else:
            top = dp[i - 1][j]

        dp[i][j] = min(dp[i][j], left, top)

print((dp[h - 1][w - 1] + 1) // 2)


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemC solver = new ProblemC();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
			}
			out.println(solve(a.clone()));

			boolean stress = false;
			if (stress) {
				Random random = new Random(0);
				for (int it = 0; it < 100; it++) {
					n = random.nextInt(15) + 1;
					a = new int[n];
					for (int i = 0; i < n; i++) {
						a[i] = random.nextInt(2000) + 1;
					}
					int u = solve(a.clone());
					int v = slow(a.clone());
					if (u != v) {
						throw new AssertionError(Arrays.toString(a));
					}
				}
			}
		}

		private int solve(int[] a) {
			int sum = 0;
			for (int x : a) {
				sum += x;
			}
			BigInteger b = BigInteger.ONE;
			for (int x : a) {
				b = b.or(b.shiftLeft(x));
			}
			for (int i = (sum + 1) / 2; ; i++) {
				if (b.testBit(i)) {
					return i;
				}
			}
		}

		private int slow(int[] a) {
			int n = a.length;
			int[] s = new int[1 << n];
			for (int i = 1; i < s.length; i++) {
				int j = Integer.numberOfTrailingZeros(i);
				s[i] = s[i ^ (1 << j)] + a[j];
			}
			Arrays.sort(s);
			return s[1 << (n - 1)];
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 224328
from collections import deque

N, M = map(int, input().split())
arr = [[] for n in range(N)]
que = deque([1])

for m in range(M):
    a, b = map(int, input().split())
    arr[a - 1].append(b)
    arr[b - 1].append(a)

dist = [-1] * N
dist[0] = 0
arr2 = [0] * (N - 1)

print("Yes")
while que:
    c = que.popleft()
    for i in arr[c - 1]:
        if dist[i - 1] != -1:
            continue

        dist[i - 1] = 0
        arr2[i - 2] = c
        que.append(i)

for i in arr2:
    print(i)




Measured memory_bytes: 34928
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include <limits>
using namespace std;
int main()
{
	string S;
	cin >> S;
	int count=0;
	int max = 0;
	for (int i = 0; i < 3; i++)
	{
		if (S[i] == 'R')
		{
			count++;
		}
		else
		{
			count = 0;
		}
		if (max < count)
		{
			max = count;
		}
	}
	cout <<max<< endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VL a(n);
    REP(i, n) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(ALL(a));
    ll b;
    if(n % 2 == 0) b = (int)((a[n / 2 - 1] + a[n / 2]) / 2);
    else b = a[n / 2];

    ll ans = 0;
    REP(i, n) ans += abs(a[i] - b);
    cout << ans << endl;

    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define N 1000000007;

using namespace std;

int main()
{
 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 int a;
 cin>>a;
 cout<<a+a*a+a*a*a;
 return(0);
}


Measured memory_bytes: 3584
import sys
sys.setrecursionlimit(10 ** 9)

convert = {
    1:'a',
    2:'b',
    3:'c',
    4:'d',
    5:'e',
    6:'f',
    7:'g',
    8:'h',
    9:'i',
    10:'j',
    11:'k',
    12:'l',
    13:'m',
    14:'n',
    15:'o',
    16:'p',
    17:'q',
    18:'r',
    19:'s',
    20:'t',
    21:'u',
    22:'v',
    23:'w',
    24:'x',
    25:'y',
    26:'z',
}
def Base_n_to_10(X, n):
    if (int(X/n)):
        return Base_n_to_10(int(X/n), n)+str(X%n)
    return str(X%n)

def main():
    r = []
    n = int(input())
    while True:
        n -= 1
        r.append(n % 26)
        n = n // 26
        if n == 0: break
    for i in r[::-1]:
        print(convert[i+1], end='')
    print()
if __name__ == "__main__":
    main()

Measured memory_bytes: 9200
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)

	ans := 2019

	if b-a >= 2019 {
		ans = 0
	} else {
		for l := a; l < b; l++ {
			for r := a + 1; r <= b; r++ {
				if (l*r)%2019 < ans {
					ans = (l * r) % 2019
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    A, P = [int(x) for x in input().split()]
    P += A*3
    print(P//2)

if __name__ == '__main__':
    main()

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define pb push_back
#define fst first
#define snd second

typedef long long ll;

const int N = 3e5;

#define oper max
#define NEUT 0
struct STree { // segment tree for min over integers
	vector<ll> st;int n;
	STree(int n): st(4*n+5,NEUT), n(n) {}
	void init(int k, int s, int e, int *a){
		if(s+1==e){st[k]=a[s];return;}
		int m=(s+e)/2;
		init(2*k,s,m,a);init(2*k+1,m,e,a);
		st[k]=oper(st[2*k],st[2*k+1]);
	}
	void upd(int k, int s, int e, int p, ll v){
		if(s+1==e){st[k]=v;return;}
		int m=(s+e)/2;
		if(p<m)upd(2*k,s,m,p,v);
		else upd(2*k+1,m,e,p,v);
		st[k]=oper(st[2*k],st[2*k+1]);
	}
	ll query(int k, int s, int e, int a, int b){
		if(s>=b||e<=a)return NEUT;
		if(s>=a&&e<=b)return st[k];
		int m=(s+e)/2;
		return oper(query(2*k,s,m,a,b),query(2*k+1,m,e,a,b));
	}
	void init(int *a){init(1,0,n,a);}
	void upd(int p, ll v){upd(1,0,n,p,v);}
	ll query(int a, int b){return query(1,0,n,a,b);}
}; // usage: STree rmq(n);rmq.init(x);rmq.upd(i,v);rmq.query(s,e);

int main() {
    int n;
    cin >> n;
    ll h[n], a[n];
    fore(i, 0, n) cin >> h[i];
    fore(i, 0, n) cin >> a[i];
    STree rmq(n);
    fore(i, 0, n) {
        ll q = rmq.query(1, h[i]);
        rmq.upd(h[i], q + a[i]);
    }

    cout << rmq.query(0, n) << endl;
}

Measured memory_bytes: 9600
#include<stdio.h>
int car(char a){
  if(a == 'a'){
    return 0;
  }else if(a == 'b'){
    return 1;
  }else{
    return 2;
  }
}

int main(){
  char S[3][1000];
  int cnt[3] = {0,0,0},k = 0;
  for(int i = 0;i < 3;i++){
    scanf("%s",&S[i]);
  }
  while(1){
    if(cnt[k] == strlen(S[k])){
      if(k == 0){
        printf("A");
        return 0;
      }else if(k == 1){
        printf("B");
        return 0;
      }else{
        printf("C");
        return 0;
      }
    }
    cnt[k]++;
    k = car(S[k][cnt[k] - 1]);
  }
}

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

using namespace std;

int main() {
  int H, W, N, A, i{}, j{}, c{};
  cin >> H >> W >> N;
  vector<vector<int>> G(H, vector<int>(W));
  while (cin >> A) {
    ++c;
    while (A--) {
      G[i][j] = c;
      i % 2 ? (!j ? ++i : --j) : (j == W - 1 ? ++i : ++j);
    }
  }

  for (auto r : G) {
    for (int i = 0; i != W; ++i) cout << (i ? " " : "") << r[i];
    cout << endl;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int a[101][101];
int cnt[11111];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int h,w;
	cin>>h>>w;
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>cnt[i];
	int x = 0; int y = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < cnt[i]; j++)
		{
			a[x][y]=i+1;
			if(x&1)
			{
				if(y>0) y--;
				else x++;
			}
			else
			{
				if(y+1<w) y++;
				else x++;
			}
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cout<<a[i][j];
			if(j+1<w) cout<<' ';
		}
		cout<<'\n';
	}
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
	int R[MAX],n;
	
	cin >> n;
	for(int i=0;i<n;i++)cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for(int i=1;i<n;i++){
		maxv = max(maxv,R[i]-minv);
		minv =min(minv,R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 3876
#include<cstdio>
int main(){
  int a,b,n,s,f,ans=0;
  scanf("%d %d %d",&a,&b,&n);
  for(int i=0;i<n;i++){
    scanf("%d %d",&s,&f);
    if(a < f && s < b) ans = 1;
  }
  printf("%d\n",ans);
  return(0);
}



Measured memory_bytes: 2748
a = int(input())
l = list(map(int,input().split()))
d = [0]*a
for i in l:
    d[i]+=1
r =1
if  l[0]!=0:
    print(0)
    exit()
for i in l[1:]:
    r=r*d[i-1]%998244353
print(r)

Measured memory_bytes: 13908