akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

LL lcd(LL a, LL b){
    LL c = a;
    LL d = b;
    while(d){
        c%=d;
        swap(c, d);
    }
    return a / c * b;
}

int N;
int M;
vector<vector<int> > roads;
vector<char> used;

bool check(int i, int j){
    return roads[i][j] || roads[j][i];
}

void setr(int i, int j, bool d){
    roads[i][j]=roads[j][i]=d;
}

int search(int place){
    int res = 1;
    REPA(i, N+1){
        if(!check(place, i))continue;
        if(used[i])continue;
        used[i]=true;
        res += search(i);
    }
    return res;
}

int count(){
    int res = 0;
    REPA(i, N+1){
        REPA(j, i){
            if(!check(i, j))continue;
            setr(i, j, 0);
            used.assign(N+1, false);
            used[1]=true;
            res += search(1)!=N;
            setr(i, j, 1);
        }
    }
    return res;
}

int main(){
    cin >> N;
    cin >> M;
    roads.resize(N+1, vector<int>(N+1, 0));
    REP(i, M){
        int a, b;
        cin >> a >> b;
        setr(a, b, 1);
    }
    cout << count() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;cin >> n >> q;
    string s;cin >> s;
    vector<int> a(n+1);
    for(int i=0;i<n;i++){
        if(i){
            if(s[i-1]=='A'&&s[i]=='C'){
                a[i+1]=a[i]+1;
            }
            else{
                a[i+1]=a[i];
            }
        }
    }
    for(int i=0;i<q;i++){
        int l,r;cin >> l >> r;
        cout << a[r]-a[l] << endl;
    }
}

Measured memory_bytes: 1488
x,n=map(int,input().split())
l=list(map(int,input().split()))
if x not in l:
    print(x)
elif n==0:
    print(x)
else:
    a=101
    p1=0
    for i in range(102):
        if i not in l:
            if abs(x-i)<a:
                a=abs(x-i)
                p1=i

    print(p1)


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
int cnt[50] = {0};
int main(){
	int n, m, k, x;
	scanf("%d%d", &n , &m);
	for(int i = 0 ; i < n ; i++){
		scanf("%d", &k);
		for(int j = 0 ; j < k ; j++){
			scanf("%d", &x);
			cnt[x]++;
		}
	}
	int ans = 0;
	for(int i = 1 ; i <= m ; i++)
		if(cnt[i] == n) ans++;
	printf("%d\n", ans);	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int a, b, c ,z;

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

    if (a > b) {
    	z = a;
    	a = b;
    	b = z;
    }
    if (b > c) {
    	z = b;
    	b = c;
    	c = z;
    }
    if (a > b) {
    	z = a;
    	a = b;
    	b = z;
    }

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

    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<'\n';
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n, d;
    cin >> n >> d;
    int dd = d * 2 + 1;
    int ans = (n + dd - 1) / dd;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n,m,a,b;
	cin >> n >> m;
	vector<int> load(n+1,0);
	REP(i, m) {
		cin >> a >> b;
		load[a]++; load[b]++;
	}
	REPS(i, n)cout << load[i] << endl;
	return 0;
}



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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<int> h(n,0);
    vector<int> dp(n,0);
    for(int i=0;i<n;i++)
    cin>>h[i];
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 3976
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;

constexpr int INF = 1 << 29;

struct state {
    int pos, life, cost;
    state() {}
    state(int a, int b, int c): pos(a), life(b), cost(c) {}
};

int N, M, L, K, A, H;

int fridge[111];
int graph[111][111];

bool solve() {
    cin >> N >> M >> L >> K >> A >> H;
    if (N+M+L+K+A+H==0) { return false; }

    fill(fridge, fridge+N, 0);
    for (int j = 0; j < L; ++j) {
        int l; cin >> l;
        fridge[l] = 1;
    }
    fridge[A] = fridge[H] = 1;
    for (int j = 0; j < N; ++j) {
        fill(graph[j], graph[j]+N, INF); graph[j][j] = 0;
    }
    for (int j = 0; j < K; ++j) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a][b] = min(graph[a][b], c);
        graph[b][a] = min(graph[b][a], c);
    }

    int min_cost[111][111];
    for (int j = 0; j < N; ++j) {
        fill(min_cost[j], min_cost[j]+M+1, INF);
    }
    min_cost[A][M] = 0;

    queue<state> que;
    que.emplace(A, M, 0);

    while (!que.empty()) {
        state st = que.front(); que.pop();
        int pos = st.pos, life = st.life, cost = st.cost;
        if (cost > min_cost[pos][life]) { continue; }

        if (fridge[pos]) {
            for (int j = 1; life+j <= M; ++j) {
                if (cost+j < min_cost[pos][life+j]) {
                    min_cost[pos][life+j] = cost+j;
                    que.emplace(pos, life+j, cost+j);
                }
            }
        }

        for (int j = 0; j < N; ++j) {
            if (j == pos || life < graph[pos][j]) { continue; }

            int next_cost = cost + graph[pos][j];
            if (next_cost < min_cost[j][life-graph[pos][j]]) {
                min_cost[j][life-graph[pos][j]] = next_cost;
                que.emplace(j, life-graph[pos][j], next_cost);
            }
        }
    }
    int ret = INF;
    for (int j = 0; j <= M; ++j) { ret = min(ret, min_cost[H][j]); }
    if (ret == INF) { cout << "Help!" << endl; }
    else { cout << ret << endl; }
    return true;
}

int main() {
    while (solve());
    return 0;
}

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

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

  int ans = 0;
  while (n) {
    n /= k;
    ans++;
  }

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int n, m, l;
    unsigned int **A, **B;
    unsigned long long **C;

    cin >> n >> m >> l;

    A = new unsigned int*[n];
    for (int i=0; i<n; i++)
        A[i] = new unsigned int[m];
    B = new unsigned int*[m];
    for (int i=0; i<m; i++)
        B[i] = new unsigned int[l];
    C = new unsigned long long*[n];
    for (int i=0; i<n; i++)
        C[i] = new unsigned long long[l];
    
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
            cin >> A[i][j];
    for (int i=0; i<m; i++)
        for (int j=0; j<l; j++)
            cin >> B[i][j];

    for (int i=0; i<n; i++) {
        for (int j=0; j<l; j++) {
            for (int k=0; k<m; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
            cout << C[i][j];
            if (j != l-1)
                cout << " ";
        }
        cout << endl;
    }

    delete[] A;
    delete[] B;
    delete[] C;
}


Measured memory_bytes: 3188
#include <cmath>
#include <iostream>
#include <vector>

const double kEpsilon = 1e-10;
inline bool equals (double a, double b){
  return fabs(a-b) < kEpsilon;
}

class Point {
 public:
  double x, y;

  Point() = default;
  Point(double x, double y) : x(x), y(y) {}

  Point operator+(const Point &p) { return Point(x + p.x, y + p.y); }
  Point operator-(const Point &p) { return Point(x - p.x, y - p.y); }
  Point operator*(const double k) { return Point(x * k, y * k); }

  double SquaredNorm() { return x * x + y * y; }
  double abs() { return sqrt(this->SquaredNorm()); }

  bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
  bool operator==(const Point &p) const {
    return fabs(x - p.x) < kEpsilon && fabs(y - p.y) < kEpsilon;
  }

  double dot(const Point &p) const { return x * p.x + y * p.y; }
  double cross(const Point &p) const { return x * p.y - y * p.x; }
};

double dot(const Point &p1, const Point &p2) {
  return p1.x * p2.x + p1.y * p2.y;
}
double cross(const Point &p1, const Point &p2) {
  return p1.x * p2.y - p1.y * p2.x;
}

using Vector = Point;

struct Segment {
  Point p1, p2;

  Segment() = default;
  Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};
using Line = Segment;

class Circle {
 public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
};

using Polygon = std::vector<Point>;
#include <array>
#include <cmath>
#include <cstddef>
#include <iostream>

int main() {
  int q;

  std::array<Point, 4> points;

  std::cin >> q;
  for (size_t i = 0; i < q; ++i) {
    for (size_t j = 0; j < 4; ++j) {
      std::cin >> points[j].x >> points[j].y;
    }
    Vector q1 = points[1] - points[0];
    Vector q2 = points[3] - points[2];

    if (equals(cross(q1, q2), 0)) {
      std::cout << 2 << std::endl;
    } else if (equals(dot(q1, q2), 0)) {
      std::cout << 1 << std::endl;
    } else {
      std::cout << 0 << std::endl;
    }
  }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

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

    vector<int> ans;
    int n;
    cin >> n;
    rep(i, n){
        int x;
        cin >> x;
        if(x > i+1) {
            ppp(-1);
            return 0;
        }
        ans.insert(ans.begin()+x-1, x);
    }

    for(auto x : ans){
        ppp(x);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



long long dp[10][5000];

int n;


int main() {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j <= 4000; ++j) {
            for (int k = 0; k <= 1000; ++k) {
                if (j + k <= 4000) dp[i+1][j+k] += dp[i][j];
            }
        }
    }
    while (cin >> n) {
        cout << dp[4][n] << endl;
    }
    return 0;
}


Measured memory_bytes: 1552
import sys

h,w,m = map(int, input().split( ))
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0]*h
Y = [0]*w
for a,b in bomb:
  X[a] += 1
  Y[b] += 1
maxX, maxY = max(X), max(Y)

R = [h for h, x in enumerate(X) if x == maxX]  # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY]  # C:爆破対象の数が最大となる列の番号

bomb = set(bomb)
for r in R:
  for c in C:
    if (r,c) not in bomb:
      print(maxX + maxY)
      exit()
print(maxX + maxY -1)    

Measured memory_bytes: 92780
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  long long A, B, N;
  std::cin >> A >> B >> N;
  if (N >= B - 1) {
    std::cout << (A * (B - 1)) / B - A * ((B - 1) / B) << '\n';
    return 0;
  }
  else {
    std::cout << (A * (N)) / B - A * ((N) / B) << '\n';
    return 0;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int length = S.size();
    if(S.at(length - 1) == 's'){
        cout << S << "es" << endl;
    }
    else{
        cout << S << 's' << endl;
    }
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	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();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

int n;
LL s[N], t[N];

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(t[i]);
	sort(t + 1, t + n + 1);
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + t[i];
	int ans = 0;
	for (int i = n; i; i--) {
		if (2 * s[i] < t[i + 1]) break;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(void)
{
    int N, Q;
    cin >> N >> Q;

    string s;
    cin >> s;

    vector<int> v(N,0);
    for(int i=1; i<s.size(); ++i){
        if(s[i-1]=='A' and s[i]=='C')
            v[i] = v[i-1] + 1;
        else
            v[i] = v[i-1];
    }

    int start, end;

    for(int q=0; q<Q; ++q){
        cin >> start >> end;
        cout << v[end-1] - v[start-1] << endl;
    }

}

Measured memory_bytes: 1408
n,k=map(int,input().split())
X=[]
for i in range(n):
    t,d=map(int,input().split())
    X.append([t,d])
    
X.sort(key=lambda x:x[1],reverse=True)

V=set()
point=0
S=[]

for t,d in X[:k]:
    point+=d
    if t in V:
        S.append(d)
    else:
        V.add(t)
point+=len(V)**2

ans=point

for t,d in X[k:]:
    if not S:
        break
    if not t in V:
        point+=d-S.pop()+1+len(V)*2
        V.add(t)
        ans=max(ans,point)

print(ans)

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

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; ++i) { cin >> a[i]; }

	bool can = true;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (a[i][j] == '.') { continue; }

			int cnt1 = 0;
			if ((i > 0) && (a[i - 1][j] == '#')) { ++cnt1; }
			if ((j > 0) && (a[i][j - 1] == '#')) { ++cnt1; }

			int cnt2 = 0;
			if ((i < H - 1) && (a[i + 1][j] == '#')) { ++cnt2; }
			if ((j < W - 1) && (a[i][j + 1] == '#')) { ++cnt2; }

			if ((i == 0) && (j == 0)) {
				if (cnt2 > 1) { can = false; }
			} else if ((i == H - 1) && (j == W - 1)) {
				if (cnt1 > 1) { can = false; }
			} else {
				if ((cnt1 != 1) || (cnt2 != 1)) { can = false; }
			}
		}
	}

	if (can) { cout << "Possible" << endl; }
	else { cout << "Impossible" << endl; }

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

int main() {
  ll n;
  cin >> n;
  vector<ll> x, y;
  ll mod;

  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    if (i == 0) {
      mod = abs((a + b) % 2);
    } else {
      if (mod != abs((a + b) % 2)) {
        return !printf("-1\n");
      }
    }
    if (mod == 0) {
      a++;
    }
    x.pb(a);
    y.pb(b);
  }

  if (mod == 0) {
    cout << 40 << endl;
    cout << 1 << " ";
  } else {
    cout << 39 << endl;
  }
  for (ll i = 38; i >= 0; i--) {
    printf("%lld", ((ll)1 << i));
    if (i)
      cout << " ";
  }
  cout << endl;
  char ansList[] = {'R', 'U', 'L', 'D'};
  REP(k, n) {
    if (mod == 0)
      cout << "L";
    ll X = 0, Y = 0;

    for (int i = 38; i >= 0; i--) {
      ll dis = INF, d = (ll(1) << i), xkari, ykari;
      ll lis[][4] = {{d, 0, -d, 0}, {0, d, 0, -d}};
      char ans;
      REP(j, 4) {
        if (dis > abs(X + lis[0][j] - x[k]) + abs(Y + lis[1][j] - y[k])) {
          dis = abs(X + lis[0][j] - x[k]) + abs(Y + lis[1][j] - y[k]);
          ans = ansList[j];
          xkari = X + lis[0][j];
          ykari = Y + lis[1][j];
        }
      }
      X = xkari;
      Y = ykari;
      cout << ans;
    }
    cout << endl;
    // cout << "Debug  " << X << " " << Y << " " << x[k] << " " << y[k] << endl;
  }
}

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

 ll MOD = 1000000007;
 ll pow_mod(ll x, ll n) {
   x %= MOD;
   if (n == 0) return 1;
   else if (n % 2 == 1) return (x * pow_mod(x, n - 1)) % MOD;
   else return pow_mod((x * x) % MOD, n / 2) % MOD;
 }

 ll comb(ll l, ll m) {
   ll t1 = 1, t2 = 1;
   for (ll i = l; i >= l - m + 1; i--) t1 = t1 * i % MOD;
   for (ll i = 1; i <= m; i++) t2 = t2 * i % MOD;
   t2 = pow_mod(t2, MOD - 2);
   return t1 * t2 % MOD;
 }

 int main() {
   ll N, a, b, ans;
   cin >> N >> a >> b;

   ans = (pow_mod(2, N) - 1 - comb(N, a) - comb(N, b)) % MOD;

   while (ans < 0) ans += MOD;

   cout << ans << endl;
 }


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

int main()
{
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> ps(n);
    for (auto& p : ps) {
        cin >> p;
        p--;
    }

    int ans = 0;
    int len = 0;
    for (int i = 0; i < n; i++) {
        if (ps[i] == i) {
            len++;
        } else {
            ans += (len + 1) / 2;
            len = 0;
        }
    }
    ans += (len + 1) / 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
a,b,k=gets.chomp.split(" ").map { |e| e.to_i }

if (b-a+1) <= 2*k
  a.upto(b) do |i|
    puts i
  end
else
  a.upto(a+k-1) do |i|
    puts i
  end

  (b-k+1).upto(b) do |i|
    puts i
  end

end


Measured memory_bytes: 1788
# n= int(input())
# import math
# s =input()
n,k = map(int, input().split())
# a = list(map(int, input().split()))
# a,b = map(str, input().split())
# ab = [list(map(int,input().split())) for _ in range(n)]

ans = 0
for i in range(k,n+2):
    mn = i*(i-1)//2
    mx = (2*(n-i+1)+(i-1))*i//2
    ans += (mx-mn +1)
    ans = ans%(10**9+7)
print(ans)



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

int main() {
  string s;
  cin>>s;
  int a=0,b=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      a++;
    }
    else{
      b++;
    }
  }
  cout<<min(a,b)*2<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < (int)N; ++i) cin >> A[i] >> B[i];

  vector<ll> dp(H + 1, 1e18);
  dp[0] = 0;

  for (int i = 0; i < (int)N; ++i) for (int j = 0; j < (int)H + 1; ++j) chmin(dp[min(j + A[i], H)], dp[j] + B[i]);

  cout << dp[H] << endl;
  return 0;
}


Measured memory_bytes: 384
import numpy as np

N = int(input())
h_list = np.array(list(map(int, input().split())))
count = 0

def count_mountain(h_list):
    pre = -1000
    count = 0
    for h in h_list:
        if pre <= 0 and h > 0:
            count += 1
        pre = h
    return count


for i in range(np.max(h_list)):
    count += count_mountain(h_list)
    h_list -= 1

print(count)

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

int main() {
  int s;
  cin >> s;
  int x, y;
  x = 800 * s;
  y = s / 15 * 200;
  cout << x - y << endl;
}


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

int main()
{
	int K, T;
	cin >> K >> T;
	vector<int> a( T );
	for( int i = 0; i < T; i++ ) {
		cin >> a[i];
	}

	sort( a.begin(), a.end() );
	int ma = a[T - 1];
	int r = K - ma;
	int ans = 0;
	if( r >= ma ) {
	}
	else {
		ans = ma - r - 1;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	long[] a = new long[n+1];
	int cnt = 0;
	for(int i = 1; i<n+1; i++) {
	    int tmp = sc.nextInt();
	    if(tmp > n) {
		cnt++;
		continue;
	    }
	    a[tmp]++;
	}
	for(int i = 1; i<n+1; i++) {
	    if(a[i] > i) cnt+= a[i]-i;
	    else if(a[i] < i) cnt += a[i];
	}
	System.out.println(cnt);

    }
}

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

int main(){
  int n;
  double a[1010],mx=0.0,invsum=0.0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%lf",&a[i]);
    if(mx<a[i])mx=a[i];
  }
  for(int i=0;i<n;i++){
    invsum+=mx/a[i];
  }
  printf("%lf",mx/invsum);
}


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

struct Card { char suit, value; };

void bubble(struct Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        for (int j = N - 1; j >= i ; j--)
        {
            if ( A[j].value < A[j - 1].value )
            {
                Card t = A[j];
                A[j] = A[j - 1];
                A[j - 1] = t;
            }
        }
    }
}

void selection(struct Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        int minj = i;
        for (int j = i; j < N; j++)
        {
            if ( A[j].value < A[minj].value )
            {
                minj = j;
            }
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

void print(struct Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        if ( i > 0 )
        {
            cout << " ";
        }
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N)
{
    for (int i = 0; i < N; i++)
    {
        if ( C1[i].suit != C2[i].suit )
        {
            return false;
        }
    }
    return true;
}

int main()
{
    Card C1[100], C2[100];
    int N;
    char ch;

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> C1[i].suit >> C1[i].value;
    }

    for (int i = 0; i< N; i++)
    {
        C2[i] = C1[i];
    }

    bubble(C1, N);
    selection(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    
    print(C2, N);
    if ( isStable(C1, C2, N) )
    {
        cout << "Stable" << endl;
    }
    else
    {
        cout << "Not stable" << endl;
    }

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.14151026535810;
/* global variables */
/* function */
/* main */
int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int> > g(10, vector<int>(10, 0));
    for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cin >> g[i][j];
    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                if (i == j) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    int x;
    int ans = 0;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        cin >> x;
        if (x == -1) continue;
        ans += g[x][1];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int X = scan.nextInt();
			
			if(X>=30)System.out.println("Yes");
			else System.out.println("No");
			
		}
		
		
	}
		

}


Measured memory_bytes: 35712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    
    int imos[1005][1005]={};
    int x,y,X,Y;
    rep(i,n){
	cin>>x>>y>>X>>Y;
	imos[x][y]++;
	imos[x][Y]--;
	imos[X][y]--;
	imos[X][Y]++;
    }

    rep(i,1001){
	reps(j,1000){
	    imos[i][j]+=imos[i][j-1];
	}
    }
    rep(i,1001){
	reps(j,1000){
	    imos[j][i]+=imos[j-1][i];
	}
    }

    int maxv=0;
    rep(i,1001){
	rep(j,1001){
	    maxv=max(maxv,imos[i][j]);
	}
    }

    cout<<maxv<<'\n';

    return 0;
}



Measured memory_bytes: 7164
use proconio::input;

fn main() {
    input! {
        n: usize,
        csf: [(i64, i64, i64); n - 1],
    };
    for i in 0..n - 1 {
        let mut t = csf[i].1 + csf[i].0;
        for &(c_j, s_j, f_j) in csf.iter().skip(i + 1) {
            if t < s_j {
                t = s_j;
            } else if t >= s_j {
                if (t - s_j) % f_j == 0 {
                    // do nothing
                } else {
                    t += f_j - (t - s_j) % f_j;
                }
            } else {
                unreachable!();
            }
            t += c_j;
        }
        println!("{}", t);
    }
    println!("{}", 0);
}


Measured memory_bytes: 2220
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
  string S;
  cin >> S;
  int cnt[3] = {};
  REP(i,S.length()){
    cnt[(int)(S[i] - 'a')]++;
  }
  int M = max(cnt[0],max(cnt[1],cnt[2]));
  int m = min(cnt[0],min(cnt[1],cnt[2]));
  if(M - m <= 1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1359",problemID = "C",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    a,b,c,d,k = invr()
    print(c * 60 + d - a * 60 - b - k)
        
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
    sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))

#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

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

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define inf (ll)1e15
#define mod 1000000007
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;


const int S=100100;

bool Solve(int x,int y)
{
	if(x<2 && y<2)return 0;

	for(int i=2;i<=x;i+=2)
	{
		if(!Solve(x-i,y+(i/2)))return 1;
	}
	for(int i=2;i<=y;i+=2)
	{
		if(!Solve(x+(i/2),y-i))return 1;
	}
	return 0;
}

int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //#endif
    
    /*for(int i=0;i<=10;i++)
	{
		for(int j=0;j<=10;j++)
		{
			if(Solve(i,j));//pf("%d %d Alice\n",i,j);
			else pf("%d %d Brown\n",i,j);
		}
	}*/

	ll x,y;
	while(~sf("%lld %lld",&x,&y))
	{
		if(abs(x-y)<=1)puts("Brown");
		else puts("Alice");
	}

    return 0;
}
 






































Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1

const int MAX = 110;
int L[MAX];

int main() {
	int N; scanf("%d", &N);
	REP(i, N) scanf("%d", L + i);
	sort(L, L + N);

	int ans = 0;
	REP(i, N) {
		for(int j = i + 1; j < N; j++) if(L[i] != L[j]) {
			for(int k = j + 1; k < N; k++) if(L[k] != L[i] && L[k] != L[j]) {
				if(L[i] + L[j] > L[k]) ans++;
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3828
import java.util.*;
import java.math.*;
public class Main{

	static int INF = 2 << 27;
	static int m;
	static int n;
	static int k;
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			Data[] data = new Data[n];
			for(int i = 0; i < n; i++) {
				data[i] = new Data(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
			}
			for(int i = 0; i < n; i++) {
				for(int j = i + 1; j < n; j++) {
					boolean check = check(data,i,j);
					if(check) data[j].up |= (1 << i);
				}
			}
			boolean[] dp = new boolean[1 << n];
			dp[0] = true;
			for(int i = 0; i < dp.length; i++) {
				if(!dp[i]) continue;
				ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
				for(int j = 0; j < 5; j++) {
					list.add(new ArrayList<Integer>());
				}
				for(int j = 0; j < n; j++) {
					if((i & (1 << j)) != 0) continue;
					if((i & data[j].up) != data[j].up) continue;
					list.get(data[j].c).add(j);
				}
				IN:for(int j = 1; j < 5; j++) {
					if(list.get(j).size() < 2) continue;
					for(int k = 0; k < list.get(j).size(); k++) {
						for(int l = k + 1; l < list.get(j).size(); l++) {
							int next = i;
							next |= (1 << list.get(j).get(k));
							next |= (1 << list.get(j).get(l));
							dp[next] = true;
						}
					}
				}
			}
			int max = 0;
			for(int i = 0; i < dp.length; i++) {
				if(dp[i]) max = Math.max(max, Integer.bitCount(i));
			}
			System.out.println(max);
			
		}
	}
	static boolean check(Data[] data, int a, int b) {
		int dis = (int)(Math.pow(data[a].x - data[b].x, 2) + Math.pow(data[a].y - data[b].y, 2));
		return dis < Math.pow(data[a].r + data[b].r,2);
	}
	static class Data {
		int up = 0;
		int x;
		int y;
		int r;
		int c;
		Data(int a, int b, int c, int d) {
			this.x = a;
			this.y = b;
			this.r = c;
			this.c = d;
		}
	}
}

Measured memory_bytes: 242088
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll m;
	cin>>m;
	stack<ll> s;
	ll k=1;
	if(m==0)
	{
		cout<<"0\n";
		return 0;
	}
	while(m!=0)
	{
		if(m%(k*-2)!=0)
		{
			s.push(1);
			m-=k;
		}
		else
		{
			s.push(0);
		}
		k*=-2;
	}
	while(!s.empty())
	{
		printf("%lld",s.top());
		s.pop();
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
dice_list = [list(map(int,input().split())) for i in range(n)]

pattern_list =[[0,1,2,3,4,5],[0,2,4,1,3,5],[0,4,3,2,1,5],[0,3,1,4,2,5],[1,2,0,5,3,4],[1,5,2,3,0,4],[1,3,5,0,2,4],[1,0,3,2,5,4],[2,0,1,4,5,3],[2,4,0,5,1,3],[2,5,4,1,0,3],[2,1,5,0,4,3],[3,0,4,1,5,2],[3,1,0,5,4,2],[3,5,1,4,0,2],[3,4,5,0,1,2],[4,2,5,0,3,1],[4,0,2,3,5,1],[4,3,0,5,2,1],[4,5,3,2,0,1],[5,1,3,2,4,0],[5,2,1,4,3,0],[5,4,2,3,1,0],[5,3,4,1,2,0]]

dice_c_list =[0,0,0,0,0,0]
cnt = 0

for g in range(n-1):
	h = g+1
	while h < n:
		for i in range(24):
			for j in range(6):
				dice_c_list[j]=  dice_list[g][pattern_list[i][j]]
			if dice_c_list == dice_list[h]:
				cnt =1
				break
		h +=1
if cnt==0:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5616
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb;
		String[] strs;
		int H, W;
		
		do {
			sb = new StringBuilder();
			
			strs = br.readLine().split("\\s+");
			
			H = Integer.parseInt(strs[0]);
			W = Integer.parseInt(strs[1]);
			
			if (H == 0 && W == 0) break;
			
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) sb.append("#");
				sb.append("\n");
			}
			
			System.out.println(sb);
		} while (true);
	}
}

Measured memory_bytes: 25692
#include <bits/stdc++.h>
 
using namespace std;
 
#define debug(a) cerr << #a << ": " << a << endl
 
typedef long long ll;
typedef pair<int, int> ii;
 
#define x first
#define y second
 
const int N = 20;

int n;
char s[2 * N];

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
 
	cin >> n;
	scanf("%s", s);

	vector< pair<string, string> > v1, v2;
	int mask_end = 1 << n;

	for (int mask = 0; mask < mask_end; mask++) {
		string tmp1, tmp2;
		for (int i = 0; i < n; i++) {
			if (mask & 1 << i) tmp1 += s[i];
			else tmp2 += s[i];
		}
		reverse(tmp2.begin(), tmp2.end());
		v1.push_back({tmp1, tmp2});
	}

	for (int mask = 0; mask < mask_end; mask++) {
		string tmp1, tmp2;
		for (int i = 0; i < n; i++) {
			if (mask & 1 << i) tmp1 += s[n + i];
			else tmp2 += s[n + i];
		}
		reverse(tmp2.begin(), tmp2.end());
		v2.push_back({tmp1, tmp2});
	}

	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());

	ll ans = 0LL;
	for (auto i : v1) {
		swap(i.x, i.y);
		auto res = equal_range(v2.begin(), v2.end(), i);
		ans += res.y - res.x;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 64492
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int A = scan.nextInt();
	int B = scan.nextInt();

	int count = 0;
	for(int i = A; i <= B; i++){
	    String s = String.valueOf(i);
	    if(s.charAt(0) == s.charAt(4) &&
	       s.charAt(1) == s.charAt(3))
		count++;
	}

	System.out.println(count);
    }
}


Measured memory_bytes: 26452
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int i;
    int flag=0;
    ll cnt=0;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        if(a[i] && flag) {
            cnt++; a[i]--;
        }
        flag=a[i]%2;
        cnt+=a[i]/2;
    }
    printf("%lld\n", cnt);

    return 0;
}


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

typedef long long ll;
#define rep(i, n) for (int i = 0; (i) < int(n); ++(i))

bool comp(const vector<int> &x, const vector<int> &y){
    return x[2] > y[2];
}

int P [10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
int Q [10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
int R [10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};

int main(void){

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(c-a) > d){
        if(abs(b-a) > d || abs(c-b) > d) {
            cout << "No" << endl;
            return 0;
        }
    }
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 888
import sys

"""
H1時M1分起床
H2時M2分就寝
K分勉強
"""
 
H1, M1, H2, M2, K = map(int, sys.stdin.read().split())
 
awake_time = H1 *60 + M1
sleep_time = H2 *60 + M2
start_limit_time = sleep_time - K
can_study_time = start_limit_time - awake_time
 
print(can_study_time)


Measured memory_bytes: 9156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int a = scanner.nextInt();
		final int b = scanner.nextInt();
		final int c = scanner.nextInt();

		int i = 0;
		int result = Math.max(a, b);
		while (true) {
			if (a % result == 0 && b % result == 0) {
				if (++i == c) {
					break;
				}
			}
			result--;
		}
		System.out.println(result);
	}

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
ll n,a,b;
ll ans;
int main(){
    scanf("%lld %lld %lld",&n,&a,&b);
    ans=min(b-1,n-a);
    if((b-a)%2==0)
        ans=min(ans,(b-a)/2);
    ans=min(ans,(a-1+b-1+1)/2);
    ans=min((n-a+n-b+1)/2,ans);
    ans=min(ans,(a-1+n-b+n+1)/2);
    ans=min(ans,(n-a+b-1+1)/2);
    printf("%lld\n",ans);
    return 0;
}


/*
..##...
.##....
##.....
.#.....
*/


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

long long N, K, fact[5000009], inv[5000009], INV[5000009], dp[2009][2009], mod = 1000000007;

long long ncr(long long n, long long r, long long m) {
	return (((fact[n] * inv[r]) % m)*inv[n - r]) % m;
}

int main() {
	cin >> N >> K; if (N == 1 || K == 1) { cout << "1" << endl; return 0; }
	fact[0] = 1; inv[0] = 1; INV[0] = 1; INV[1] = 1;
	for (int i = 2; i <= 5000000; i++) INV[i] = (mod - (mod / i)*INV[mod%i] + mod*mod) % mod;
	for (int i = 1; i <= 5000000; i++) fact[i] = (fact[i - 1] * i) % mod;
	for (int i = 1; i <= 5000000; i++) inv[i] = (inv[i - 1] * INV[i]) % mod;
	dp[0][0] = 1;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < N; j++) {
			if (dp[i][j] == 0) continue;
			if (i < N) {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= mod;
			}
			if (i > j) {
				long long A = K - 2;
				long long B = (N - i) + (N - j - 1)*(K - 1);
				dp[i][j + 1] += dp[i][j] * ncr(A + B, A, mod);
				dp[i][j + 1] %= mod;
			}
		}
	}
	cout << (dp[N][N] * fact[N]) % mod << endl;
	return 0;
}

Measured memory_bytes: 147456
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    A = [LI() for _ in range(N)]

    ctr = [0] * N

    sp = [0] * (M+1)
    for i in range(N):
        sp[A[i][ctr[i]]] += 1
    ans = max(sp)

    for _ in range(M-1):
        m = 0
        mi = -1
        for i in range(1,M+1):
            if sp[i] > m:
                m = sp[i]
                mi = i
        sp[mi] = -1
        for i in range(N):
            if A[i][ctr[i]] == mi:
                while sp[A[i][ctr[i]]] < 0:
                    ctr[i] += 1
                sp[A[i][ctr[i]]] += 1
        ans = min(ans,max(sp))

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 76344
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}



signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

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

}       


Measured memory_bytes: 5204
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define X first
#define Y second
#define fw(i, start, end) for (ll i = start; i < end; ++i)
#define fe(i, start, end) for (ll i = start; i <= end; ++i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define endl '\n'

ll b[1006][1006];
int main()
{
    FASTIO
    ll h, w;
    char a[1006][1006];
    memset(b, 0, sizeof b);

    memset(a, 0, sizeof a);
    b[1][1] = 1;
    cin >> h >> w;
    fe(i, 1, h)
    {
        fe(j, 1, w)
        {
            cin >> a[i][j];
        }
    }

    fe(i, 1, h)
    {
        fe(j, 1, w)
        {
            if (a[i][j] == '#')
            {
            }
            if (a[i][j] == '.' && (i != 1 || j != 1))
            {
                b[i][j] = b[i - 1][j] % 1000000007 + b[i][j - 1] % 1000000007;
                b[i][j] = b[i][j] % 1000000007;
            }
        }
    }
    // fe(i, 1, h)
    // {
    //     fe(j, 1, w)
    //     {
    //         cout << b[i][j];
    //     }
    //     cout << endl;
    // }
    cout
        << b[h][w] % 1000000007 << endl;

    return 0;
}

Measured memory_bytes: 9216
def b_search(array, n)
  low = 0
  high = array.size
  while low <= high
    mid = (low + high) / 2
    if n == array[mid]
      return true
    elsif n > array[mid]
      low = mid + 1
    else
      high = mid - 1
    end
  end
  false
end

gets
s = gets.split.map(&:to_i)
gets
t = gets.split.map(&:to_i)
puts t.count { |n| b_search(s, n) }

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

int main(void){
    static char A[1000000010];
    int  N;
    int num;
    int ans;

    scanf("%d",&N);

    for(int i=0;i<1000000010;i++){
        A[i]=0;
    }

    for(int i=0;i<N;i++){
        scanf("%d",&num);
        A[num]++;
        if(A[num]>1){
            printf("NO");
            return 0;
        }
    }

    printf("YES");

    return 0;
}

Measured memory_bytes: 976768