akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	
	static int h;
	static int w;
	static int c;
	static int cnt;
	static int[][] p;
	static int[][] tmp;
	static int[][] move = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
	static int[] order;
	static boolean[][] jud;
	
	static void e() {
		for(int k=0; k<5; k++) {
			if(tmp[0][0] == order[k]) continue;
			f(0, 0, tmp[0][0], order[k]);
		}
		cnt = 0;
		jud = new boolean[h][w];
		v(0, 0);
	}
	
	static void v(int i, int j) {
		if(tmp[i][j] != c) return;
		cnt++;
		jud[i][j] = true;
		for(int k=0; k<4; k++) {
			int newi = i + move[k][0];
			int newj = j + move[k][1];
			if(0 <= newi && newi < h && 0 <= newj && newj < w && !jud[newi][newj]) {
				v(newi, newj);
			}
		}
	}
	
	static void f(int i, int j, int from, int to) {
		if(tmp[i][j] != from) return;
		tmp[i][j] = to;
		for(int k=0; k<4; k++) {
			int newi = i + move[k][0];
			int newj = j + move[k][1];
			if(0 <= newi && newi < h && 0 <= newj && newj < w) {
				f(newi, newj, from, to);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			h = sc.nextInt();
			w = sc.nextInt();
			c = sc.nextInt();
			if(h + w + c == 0) break;
			p = new int[h][w];
			tmp = new int[h][w];
			for(int i=0; i<h; i++) {
				for(int j=0; j<w; j++) {
					p[i][j] = sc.nextInt();
				}
			}
			int max = 0;
			order = new int[5];
			for(int i=1; i<=6; i++) {
				for(int j=1; j<=6; j++) {
					for(int k=1; k<=6; k++) {
						for(int l=1; l<=6; l++) {
							order[0] = i;
							order[1] = j;
							order[2] = k;
							order[3] = l;
							order[4] = c;
							for(int x=0; x<h; x++) {
								for(int y=0; y<w; y++) {
									tmp[x][y] = p[x][y];
								}
							}
							e();
							max = Math.max(max, cnt);
						}
					}
				}
			}
			System.out.println(max);
		}
	}
}


Measured memory_bytes: 65792
n = int(input())

p = list(map(int, input().split()))

cnt = 0
for i in range(1,n-1):
    # インデックス参照で順番に見ていって、現在の数がそのとおりであればcnt += 1する
    num = p[i]
    pre_num = p[i-1]
    next_num = p[i+1]
    numbers = sorted([num, pre_num, next_num])

    if numbers[1] == num:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, k] <- getIntList
  as <- getIntVec n

  forM_ [k..(n-1)] $ \i -> do
    let j = i - k
    if as V.! i > as V.! j
      then putStrLn "Yes"
      else putStrLn "No"


Measured memory_bytes: 11680
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

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>;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
using ll = long long;

const int INF = (int) 1e9 + 9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi b(n-1);
    rep(i, 0, n-1) {
        cin >> b[i];
    }
    ll sum = b[0];
    rep(i, 1, n-1) {
        sum += min(b[i-1], b[i]);
    }
    sum += b[n-2];
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
req = []
for _ in range(m):
    a, b = map(int, input().split())
    req.append((a, b))

req.sort(key=lambda x: x[1])

ans = 0
pre = 0

for i in range(m):
    a, b = req[i]
    if a < pre:
        continue
    pre = b
    ans += 1
    
print(ans)

Measured memory_bytes: 56928
#include <algorithm>

namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
    
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;

    ~edge() = default;

    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}

namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
      }
      catch (int x) {}
      return r;
    }
  }

  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
  int N;
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

Measured memory_bytes: 35360
N = int(input())
S = input()

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "#"
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "#")

T = [w + b - 1 for w, b in zip(W, B)]
T = min(T)
print(min(T, W[0], B[-1]))


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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int main() {
    ll n=in();
    map<int,int> v;
    ll a;
    REP(i,n){
        cin>>a;
        v[a]++;
    }
    ll ans=0;
    for (auto&& item : v) {
        if(item.second>item.first)ans+=item.second-item.first;
        if(item.second<item.first)ans+=item.second;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 4736
N, M = map(int, input().split())
X = list(map(int, input().split()))

if M <= N:
    print(0)
else:
    X.sort()
    L = []
    for i in range(M-1):
        L.append(X[i+1] - X[i])
    L.sort(reverse=True)
    print(X[-1]-X[0]-sum(L[:N-1]))

Measured memory_bytes: 13968
N = int(input())
A = list(map(int,input().split()))

right = 1
xor = A[0]
sum = A[0]
ans = 0
for left in range(N):
  while right < N and xor ^ A[right] == sum + A[right]:
    xor ^= A[right]
    sum += A[right]
    right += 1
  ans += right - left
  if left == right:
    right += 1
  xor ^=A[left]
  sum -=A[left]
print(ans)

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

vector<int> ve,ie;
int main(){
	int D,N,M,hog,res;
	vector<int>::iterator it,it2;
	while(true){
		ve.clear();
		ie.clear();
		cin>>D;
		if(D==0) break;
		cin>>N>>M;
		for(int i=0;i<N-1;i++){
			cin>>hog;
			ve.push_back(hog);
		}
		for(int i=0;i<M;i++){
			cin>>hog;
			if(hog==0) hog=D;
			ie.push_back(hog);
		}
		ve.push_back(0);
		ve.push_back(D);
		sort(ve.begin(),ve.end());
		res=0;
		for(int i=0;i<M;i++){
			it=lower_bound(ve.begin(),ve.end(),ie[i]);
			it2=it-1;
			res+=min((*it)-ie[i],ie[i]-(*it2));
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1832
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

inline int ex(int a, int b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	int tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
inline int inv(int k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
const int maxi=1e7;
vector<int> fact(maxi);
int c(int a,int b)
{
	int num=fact[a];
	int den=fact[b]*fact[a-b];
	den%=N;
	return (num*inv(den))%N;
}
signed main()
{
	speed
	fact[0]=1;
	for(int i=1;i<maxi;++i)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=N;
	}
	int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
	int ans=0;
	for(int i=r1;i<=r2;++i)
	{
		ans+=c(i+c2+1,i+1)-c(i+c1,i+1);
		ans%=N;
	}
	ans+=N;ans%=N;
	cout<<ans<<"\n";

}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	ll x;
	cin>>N>>x;
	vector<ll> a(N);
	rep(i,N){
		cin>>a[i];
	}
	ll ans = 0;
	if(a[0]>x){
		ans+=a[0]-x;
		a[0] = x;
	}
	for (int i = 0; i+1 <= N-1; ++i){
		if(a[i]+a[i+1]>x){
			ans+=a[i]+a[i+1]-x;
			a[i+1]-=a[i]+a[i+1]-x;
		}
	}
	//rep(i,N)cout<<a[i]<<endl;
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
          double a,b=0;
          cin>>a;
          for(int i=1;i<=a;i++)
          {
                    if(i%2==0)
                              b++;
          }
          cout<<fixed<<setprecision(10)<<1-(b/a)<<endl;
return 0;
}


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

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int x,y,b,p;
    int ans;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x>>y>>b>>p;
        if( b >= 5 && p >= 2){
            ans = (x*b + y*p)*8/10;
        }else{
            ans = x*b + y*p;
        }
        if(b >= 5 && p < 2){
            ans = min(ans,(x*b+y*2)*8/10);
        }
        if(b < 5 && p >= 2){
            ans = min(ans,(x*5+y*p)*8/10);
        }
        if(b < 5 && p < 2){
            ans = min(ans,(x*5+y*2)*8/10);
        }
        cout<<ans<<"\n";
    }
    return 0;
}




Measured memory_bytes: 3220
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int n;
int m;
int c;

vector<vector<int>> a;
vector<int> b;

void input() {
  cin >> n >> m >> c;

  b.resize(m);
  for (auto&& i : b) {
    cin >> i;
  }

  a.resize(n);
  for (int i = 0; i < n; ++i) {
    a[i].resize(m);

    for (auto&& j : a[i]) {
      cin >> j;
    }
  }
}

void solve() {
  int ans = 0;

  for (auto&& i : a) {
    int sum = 0;

    for (int j = 0; j < m; ++j) {
      sum += i[j] * b[j];
    }

    if (sum + c > 0)
      ++ans;
  }

  cout << ans;
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



// Tはintのほうがdoubleより早い
// ！！！注意！！！！　　　　　得られるのは最近点対の距離の二乗！！！！！！！！！！！！！！
#define INF inf
using T = double;
struct ClosestPair{
    vector<pair<T,T>> a, b, c;

    void add(T x, T y) { a.push_back({ x, y }); }
    inline T sqr(T x) { return x * x; }
    T dis(pair<T,T>& a, pair<T,T>& b) { return sqr(a.first - b.first) + sqr(a.second - b.second); }

    T calc(int l, int r)
    {
        if (l == r) return INF;
        int mid = (l + r) >> 1;
        T d = min(calc(l, mid), calc(mid + 1, r));
        double d0 = sqrt(double(d));
        int cnt1 = 0, cnt2 = 0;
        T ma = a[l].first, mi = a[r].first;
        for (int i = l; i <= mid; i++) ma = max(a[i].first, ma);
        for (int i = mid + 1; i <= r; i++) mi = min(a[i].first, mi);
        for (int i = l; i <= mid; i++) if (a[i].first>mi - d0) b[++cnt1] = a[i];
        for (int i = mid + 1; i <= r; i++) if (a[i].first<ma + d0) c[++cnt2] = a[i];
        int k = 1;
        for (int i = 1; i <= cnt1; i++)
        {
            while (k <= cnt2 && c[k].second<b[i].second - d0) k++;
            for (int j = k; j <= cnt2 && c[j].second<b[i].second + d0; j++) d = min(d, dis(b[i], c[j]));
        }
        int k1 = l, k2 = mid + 1;
        for (int i = l; i <= r; i++)
            if (k1 <= mid && (k2>r || a[k1].second<a[k2].second)) b[i] = a[k1++]; else b[i] = a[k2++];
        for (int i = l; i <= r; i++) a[i] = b[i];
        return d;
    }

    T solve() {
        int n = a.size();
        assert(2 <= n);
        sort(all(a));
        b.resize(n);
        c.resize(n);
        return calc(0, n - 1);
    }
};
//---------------------------------------------------------------------------------------------------





int N;
ClosestPair cp;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) {
        double x, y; cin >> x >> y;
        cp.add(x, y);
    }
    double ans = sqrt(cp.solve());
    printf("%.10f\n", ans);

}


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

int main() {
  int a,b;
  cin >>a>>b;
  if(a>0&&b>0){
    cout<<"Positive"<<endl;
    return 0;
  }else if(a<=0&&b>=0){
    cout<<"Zero"<<endl;
  }else if(abs(a-b)%2==1){
    cout<<"Positive"<<endl;
  }else{
    cout<<"Negative"<<endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import deque
 
H, W = map(int, input().split())
S = [input() for _ in range(H)]
INF = 10**15

answer = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      continue
    else:
      dist = [[INF for _ in range(W)] for _ in range(H)] # 始点からの距離
      dist[i][j] = 0 # 始点を定義
      queue = deque([(i, j)]) # 始点を"先入れ先出し"の配列に入れる
      
      while queue:
      # BFS
      # * 計算量 O(4HW:辺の数)
        si, sj = queue.popleft() 
        # "先入れ先出し"
        # * ⇔後入れ先出し。DFS
        #   si, sj = stack.pop()
        
        for ni, nj in [(si + 1, sj), (si - 1, sj), (si, sj + 1), (si, sj - 1)]:
        # 経路に重みがない場合、BFSでは先に入れた方がそのマスに対する最短経路になる...☆
        # * DFSを使用すると更新の必要があり、
        #   計算量が(4HW*HW:辺の数×グリッドの数) -> TLE
        # ** 木だと経路は1つしかないため、BFSもDFSも計算量は同じ
        #    グラフでは基本的にBFS推奨[要出典]
        # * 経路に重みがある場合も更新の必要があり、計算量はO(4HW*HW)
        # ** Dijkstra法を使えば、計算量はO(4HW+HWlogHW)
        #    O(E + VlogV): E -> Edge, V -> Vertex
          if 0 <= ni <= H - 1 and 0 <= nj <= W - 1 and S[ni][nj] != "#":
            if dist[ni][nj] > dist[si][sj] + 1:
              dist[ni][nj] = dist[si][sj] + 1
              queue.append((ni, nj))
          # ☆より、最短経路をとるマスからの隣接が次の最短経路の候補となる
          # すでに最短経路を取っているものは排除
              
      max_dist = 0
      for ii in range(H):
        for jj in range(W):
          if dist[ii][jj] != INF:
            max_dist = max(max_dist, dist[ii][jj])
      answer = max(max_dist, answer)
      # 添え字被りに注意
      
print(answer)




Measured memory_bytes: 48492
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

vi vecint(1);
int main() {
	int count = 0;
	int temp;
	while (1) {
		cin >> temp;
		if (temp == 0)break;
		count++;
		vecint.push_back(temp);
	}

	rep(i, 1, count+1) cout << "Case " << i << ": " << vecint[i] << endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 3272
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353

n, s = map(int, input().split())
A = list(map(int, input().split()))
dp = [0] * (s + 1)
ans = 0
for i in range(n):
    dp[0] += 1
    for j in range(s, A[i] - 1, -1):
        dp[j] += dp[j - A[i]]
        dp[j] %= mod
    ans += dp[s]
    ans %= mod
print(ans)


Measured memory_bytes: 42092
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
#define gg(u) for(int &i=cur[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=5e5+5,M=1e6+5,inf=0x3f3f3f3f;
inline int min(R int x,R int y){return x<y?x:y;}
struct eg{int v,nx,w;}e[M];int head[N],tot=1;
inline void add(R int u,R int v,R int w){
	e[++tot]={v,head[u],w},head[u]=tot;
	e[++tot]={u,head[v],0},head[v]=tot;
}
int dep[N],cur[N],S,T,n;
bool bfs(){
	memset(dep,-1,(T+1)<<2);
	memcpy(cur,head,(T+1)<<2);
	static int q[N];
	int h=1,t=0,u;q[++t]=S,dep[S]=0;
	while(h<=t){
		u=q[h++];
		go(u)if(e[i].w&&dep[v]<0)q[++t]=v,dep[v]=dep[u]+1;
	}
	return ~dep[T];
}
int dfs(int u,int lim){
	if(u==T||!lim)return lim;
	int fl=0,f;
	gg(u)if(dep[v]==dep[u]+1&&(f=dfs(v,min(lim,e[i].w)))){
		fl+=f,lim-=f,e[i].w-=f,e[i^1].w+=f;
		if(!lim)break;
	}
	if(!fl)dep[u]=-1;
	return fl;
}
inline int dinic(){R int res=0;while(bfs())res+=dfs(S,inf);return res;}
int p[N],q[N],blp[N],blq[N],s0[N],s1[N],sum,cnt;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&p[i]),++p[i];
	fp(i,1,n)scanf("%d",&q[i]),++q[i];
	fp(i,1,n)if(!blp[i]){
		++cnt;
		for(R int j=i;!blp[j];j=p[j])blp[j]=cnt;
	}
	fp(i,1,n)if(!blq[i]){
		++cnt;
		for(R int j=i;!blq[j];j=q[j])blq[j]=cnt;
	}
	S=0,T=cnt+1;
	fp(i,1,n)sum+=p[i]!=q[i];
	fp(i,1,n){
		if(p[i]==q[i]){
			if(p[i]==i)continue;sum+=2;
			add(S,blp[i],1),add(blq[i],T,1),add(blp[i],blq[i],2);
		}else{
			if(p[i]==i)add(S,blq[i],1);
			else if(q[i]==i)add(blp[i],T,1);
			else add(blp[i],blq[i],1);
		}
	}
	printf("%d\n",sum-dinic());
	return 0;
}

Measured memory_bytes: 24832
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll n;
    cin >>n;
    ll ans[n+1];
    vector< pair<int,int> > v[n+1];
    for(int i=0;i<n;i++){
        ll a,b,c;
        cin >>a>>b>>c;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
        ans[i+1]=-1;
    }
    
    queue<int> list;
    list.push(1);
    ans[1]=0;//始点を黒にする
    while(!list.empty()){
        int num=list.front();
        list.pop();
        vector< pair<int,int> >::iterator a=v[num].begin();
        for(; a!=v[num].end();a++){
            int dist=a->second;
            int next=a->first;
            if(ans[next]>=0)continue;
            ans[next]=(abs(ans[num]-ans[1])==0)?(dist%2):((dist%2==0)?ans[num]:ans[1]);
            list.push(next);
        }

    }

    for(int i=1;i<=n;i++){
        cout <<ans[i]<<endl;
    }


    return 0;

}

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

int main() {
    // 入力
    int d, g;
    cin >> d >> g;

    vector<int> p(d), c(d);
    for (int i=0; i<d; i++){
        cin >> p.at(i) >> c.at(i);
    }

    //難易度の数dでbit 全探索
    int res = INT_MAX;
    for(int bit=0; bit<(1<<d); bit++){
        int sum = 0;
        int num = 0;
        for(int i=d-1; i>=0; i--){
            if(((bit >> i) & 1) == 1){
                for(int j=0; j<p.at(i); j++){
                    sum += 100*(i+1);
                    num ++;
                    if(j==p.at(i)-1) sum += c.at(i); //すべてp(i)が選択されるときc(i)
                    if(sum >= g) break;
                }
            }
        }
        if(sum >= g){
            res = min(res, num);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
    int nb_lignes,nb_colonnes;
    while(cin>>nb_colonnes>>nb_lignes)
    {
        if(nb_lignes == 0)
            break;
        int res = 1;
        vector<string> lab(nb_lignes);
        vector<vector<bool> > visites(nb_lignes,vector<bool>(nb_colonnes,false));
        for(int c=0;c<nb_lignes;c++) cin>>lab[c];
        int xdep,ydep=0;
        for(xdep=0;xdep<nb_lignes&&lab[xdep][ydep]!='@';xdep++){ for(ydep=0;ydep<nb_colonnes&&lab[xdep][ydep]!='@';ydep++);if(lab[xdep][ydep]=='@')break;}
        vector<pair<int,int> > parcours;
        visites[xdep][ydep]=true;
        parcours.push_back(make_pair(xdep,ydep));
        while(parcours.size())
        {
            int xact = parcours.back().first;
            int yact = parcours.back().second;
            parcours.pop_back();
            int dx[4]={1,-1,0,0};
            int dy[4]={0,0,1,-1};
            for(int c=0;c<4;c++)
            {
                int x2 = xact + dx[c];
                int y2 = yact + dy[c];
                if(x2>=0&&x2<nb_lignes&&y2>=0&&y2<nb_colonnes&&lab[x2][y2]!='#'&&!visites[x2][y2])
                {
                    visites[x2][y2]=true;
                    res++;
                    parcours.push_back(make_pair(x2,y2));
                }
            }
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 1220
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*16
#define REP(i,n) for(long long i = 0;i < n;++i)
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
int main() {
	int n;
	cin >> n;
	long long ans = 0;
	cin >> ans;
	REP(i, n - 1) {
		long long geko;
		cin >> geko;
		ans = gcd(ans, geko);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def iin(): return int(input())
def nl(): return list(map(int, input().split()))
def ary(r, c, v): return [[v for _ in range(c)] for _ in range(r)]

N, C = nl()
d = [nl() for _ in range(C)]
c = [nl() for _ in range(N)]

color_count_by_r = []
for i in range(3):
    color_count_by_r.append(dict())
for i in range(N):
    for j in range(N):
        color_count_by_r[(i + j) % 3][c[i][j]] = color_count_by_r[(i + j) % 3].get(c[i][j], 0) + 1

ans = float('inf')
for c0 in range(1, C + 1):
    for c1 in range(1, C + 1):
        if c0 == c1:
            continue
        for c2 in range(1, C + 1):
            if c0 == c2 or c1 == c2:
                continue
            cost = 0
            for i in range(3):
                for j in range(1, C + 1):
                    next_color = [c0, c1, c2][i]
                    cost += color_count_by_r[i].get(j, 0) * d[j - 1][next_color - 1]
            ans = min(ans, cost)
print(ans)

Measured memory_bytes: 7668
#include<bits/stdc++.h>
using namespace std;
const int N=10;
int n,a[N],b[N],c[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&c[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
        a[i]=i;
    int ans=1,l,r;
    while(true)
    {
        bool f1=true,f2=true;
        for(int i=1;i<=n;i++)
        {
            if(c[i]!=a[i]) f1=false;
            if(b[i]!=a[i]) f2=false;
        }
        if(f1) l=ans;
        if(f2) r=ans;
        ans++;
        if(!next_permutation(a+1,a+1+n)) break;
    }
    printf("%d\n",abs(r-l));
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

namespace solver {
string s;
typedef string::const_iterator Iter;
Iter it, end;
int priority[3];

#define my_assert(condition)  \
  if(!(condition)) {  \
    cout << string(it, end) << endl;  \
    assert(0 && #condition); \
  } \

void consume(char e) {
  my_assert(*it == e);
  it ++;
}

bool isconsume(char e) {
  if(*it == e) {
    consume(e);
    return true;
  }
  return false;
}

ll number() {
  ll ret = 0;
  my_assert(isdigit(*it));
  while(isdigit(*it)) {
    ret *= 10;
    ret += *it - '0';
    it ++;
  }
  return ret;
}

// 1. solve operator priority recursion
ll expr(int p) {
  if(p == 3) {
    if(isconsume('(')) {
      ll ret = expr(0);
      consume(')');
      return ret;
    }
    return number();
  }

  // 2. solve operator association
  ll ret = expr(p + 1);

  auto priority_condition = [&]() {
    auto k = string("+-*").find(*it);
    if(k == string::npos) return false;
    return priority[k] == p;
  };

  while(priority_condition())
    if(isconsume('+')) ret += expr(p + 1);
    else if(isconsume('-')) ret -= expr(p + 1);
    else if(isconsume('*')) ret *= expr(p + 1);

  return ret;
}

ll calc() {
  it = s.begin(), end = s.end();
  ll ret = expr(0);
  my_assert(it == end);
  return ret;
}

bool next_priority() {
  static int turn = 0;
  int t = turn++;
  priority[0] = t % 3;
  t /= 3;
  priority[1] = t % 3;
  t /= 3;
  if(t >= 3) return false;
  priority[2] = t;
  return true;
}

ll solve() {
  ll ret = numeric_limits<ll>::min();
  do {
    ret = max(ret, calc());
  } while(next_priority());
  return ret;
}

}

int main() {
  cin >> solver::s;
  cout << solver::solve() << endl;
  return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
int main()
{
	long long a, b,nowA,nowB,ans;
	cin >> a >> b;

        ans=a*b;
 
	nowA = a, nowB = b;
	
	for (long long i = 0; i < a*b; i++)
	{
		if (nowA == nowB)
		{
			ans = max(nowA,nowB);
			break;
		}
		else if (nowA < nowB)
			nowA += a;
		else
			nowB += b;
	}
	
	cout << ans << std::endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws IOException {
	Main m = new Main();
	m.solve();
    }

    private void solve() throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int[] nm = Arrays.stream(br.readLine().split("[\\s]+"))
	    .mapToInt(Integer::parseInt).toArray();
	int n = nm[0];
    	int m = nm[1];
	String S = br.readLine();
	String T = br.readLine();
	br.close();
	int gcd = n > m ? gcd(n,m) : gcd(m,n);
	long lcm = (long)n*(long)m/(long)gcd;
	for (int i=0;i<n;i++) {
	    if (((long)i*(long)m)%(long)n != 0) continue;
	    long j = ((long)i*(long)m)/(long)n;
	    if ((int)j == m) continue;
	    char s = S.charAt(i);
	    char t = T.charAt((int)j);
	    if (s != t) {
		System.out.println(-1);
		System.exit(0);
	    }
	}
	System.out.println(lcm);
    }

    private int gcd(int n,int m) {
	if (n%m == 0) return m;
	return gcd(m,n-m*(n/m));
    }
}

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

int main(){
	string s;
	cin>>s;
	
	string ans;
	REP(i,s.size()){
		if(s[i]=='B'){
			if(ans.size()!=0) ans.pop_back();
		}else ans+=s[i];
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, a, b, p;
int n, m, r;

signed main()
{
    cin >> N >> a >> b;
    for(int i = 0; i < N; i++){
        cin >> p;
        if(p <= a){
            n++;
        }
        else if(p <= b){
            m++;
        }
        else{
            r++;
        }
    }
    cout << min(n, min(m, r)) << endl;

    return 0;
}

/*


*/


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x, y, i, judge=0;
  scanf("%d %d", &x, &y);

  for(i=0; i<=x; i++){
    if(y==(i*2+(x-i)*4)){
      printf("Yes\n");
      judge=1;
      break;
    }
  }

  if(judge==0)
    printf("No\n");

  return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d,e; cin >> a >> b >> c >> d >> e;
    a = 60*a;
    c = 60*c;
    cout << (c+d) - (a+b) - e << endl;
    return 0;
}

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

int main()
{
	int N, K, sum = 1;

	cin >> N >> K;

	for (int i = 0; i < N; i++)
	{
		sum = min(sum*2, sum + K);
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 764
#include <iostream>

typedef long long ll;

int main(){
   const int n = 26;
   ll N;
   std::cin >> N;
   
   int m = 1;
   ll x = n;
   ll sum = x;
   while(sum<N){
      x *= n;
      sum += x;
      ++m;
   }

   std::string ans;
   char ch;
   ll y = N - (sum - x) - 1;
   for(int i=0; i<m; ++i){
      ch = 'a' + y%n;
      ans = ch + ans;
      y = y / n;
   }

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


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)

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

   cout << a + a * a + a * a * a << endl;


}


Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <algorithm>

using namespace std;

int main()
{
	int e;
	while(1){
		cin >> e;
		if(e == 0) break;
		int x, y, z, p, m, min_m=1000000;
		for(z = 0; z <= 100; z++){
			if((z * z * z) > e) break;
			for(y = 0; y <= 1000; y++){
				if((y * y) + (z * z * z) > e) break;
				x = e - (y * y) - (z * z * z);
				min_m = min(min_m, x+y+z);
				}
			}
		cout << min_m << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
s = input().strip()
odd = list('RUD')
even = list('LUD')

ok = True
for i, c in enumerate(s):
    i += 1
    if (i % 2 == 0 and c not in even) or (i % 2 == 1 and c not in odd):
        ok = False
        break
if ok:
    print('Yes')
else:
    print('No')

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll D,X,Y;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>D;
	int num=0;
	FOR(i,N) {
		cin>>X>>Y;
		if(X*X+Y*Y<=D*D) num++;
	}
	cout<<num<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    ll N;
    cin >> N;

    vector<ll> H(N);
    rep (i, N) {
        cin >> H[i];
    }

    ll ans = 0;
    ll cnt = 0;
    rep (i, N-1) {
        if (H[i] >= H[i+1]) {
            cnt++;
            ans = max(ans, cnt);
        } else {
            cnt = 0;
        }
    }
    ans = max(ans, cnt);

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

Measured memory_bytes: 1024
use std::collections::BinaryHeap;

fn main() {
    // input
    let one = read_vec::<u32>();
    // N
    let _ = one[0];
    // m
    let m = one[1];
    // A
    let a = read_vec::<u64>();

    let mut bh = BinaryHeap::<u64>::new();

    for &now in a.iter() {
        bh.push(now);
    }

    for _ in 0..m {
        let max = bh.pop().unwrap();
        bh.push(max / 2);
    }

    let ans: u64 = bh.into_iter().sum();
    println!("{}", ans);
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 9464
#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

typedef long long ll;


int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    
    ll x = c - a - b;
    
//     if(c <= a || c <= b) {
//         cout << "No";
//     } 
    
    if(x <= 0) {
        cout << "No";
        return 0;
    }
    if(a * b * 4LL < x * x) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    
    return 0;
}

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

int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;
  if(U==S)
    cout<<A-1<<' '<<B<<endl;
  else
    cout<<A<<' '<<B-1<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void reverse(long a[], int b, int e){
        long A[] = new long[e-b];
        for(int i = 0 ; i < e-b ; i++)
            A[i] = a[e-1-i];
        for(int i = 0 ; i < e-b ; i++)
            a[b+i] = A[i];
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        for(int i = 0 ; i < n ; i++)
            a[i] = sc.nextLong();
        int q = sc.nextInt();
        for(int i = 0 ; i < q ; i++){
            int b = sc.nextInt();
            int e = sc.nextInt();
            reverse(a,b,e);
        }
        for(int i = 0 ; i < n-1 ; i++)
            System.out.print(a[i] + " ");
        System.out.println(a[n-1]);
    }
}


Measured memory_bytes: 35072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  h2-=(k/60);
  m2-=(k%60);
  if(m2<0){
    h2--;
    m2+=60;
  }
  h2-=h1;
  m2-=m1;
  if(m2<0){
    h2--;
    m2+=60;
  }
  cout << h2*60+m2 << endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



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

  ll c=a%2;
  ll d=b%2;

  if(c==d){
     cout<<(b-a)/2;
  }
  else{
     cout<<min(a-1,n-b)+1+(b-a-1)/2;
  }

return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int n, w;
	cin >> n >> w;
	vector<long> weights(n), values(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> weights[i] >> values[i];
	}
	vector<vector<long>> dp(n + 1, vector<long>(w + 1));
	for (int i = 0; i <= w; ++i)	dp[0][i] = 0;
	for (int i = 1; i <= n; ++i)
	{
		dp[i][0] = 0;
		for (int j = 1; j <= w; ++j)
		{
			if (j >= weights[i - 1]
				&& dp[i][j] < dp[i - 1][j - weights[i - 1]] + values[i - 1])
			{
				dp[i][j] = dp[i - 1][j - weights[i - 1]] + values[i - 1];
			}
			if (dp[i][j] < dp[i - 1][j])
			{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}


Measured memory_bytes: 80256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var AB = Sarray();
            var A = AB[0];
            var B = AB[1];
            for (var i = 0L; i <= 1250; ++i)
            {
                if ((long)(i * 0.08) == A && (long)(i * 0.10) == B)
                {
                    WriteLine(i);
                    return;
                }
            }
            WriteLine(-1);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
string s,t;
int main(){
  cin>>s;
  t="";
  for(int i=0;i<s.length();i++){
    t+=s[s.length()-1-i];
  }
  if(s==t){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    if (n == 1) {
        if (a[0] == 0)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    int target = (n % 2) ^ 1;
    for (int i = 0; i < n - 1;) {
        if (target == 0) {
            if (a[i] == 0 && a[i + 1] != 0) {
                i++;
                target += 2;
                continue;
            }
            else {
                cout << 0 << endl;
                return 0;
            }
        }
        else {
            if (a[i] == target && a[i + 1] == target) {
                i += 2;
                target += 2;
            }
            else {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    int ans = 1;
    rep(i, n / 2) {
        ans *= 2;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3696
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 5;

typedef pair<int, int> pii;

char g[N][N];
int vis[N][N], d[N][N];
int h,w;

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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>h>>w;
    queue<pii> q;
    
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin>>g[i][j];
            if(g[i][j]=='#'){
                vis[i][j] = 1;
                d[i][j] = 0;
                q.push({i,j});
            }
        }
    }
    
    int mxd = 0;
    while (!q.empty()) {
        pii u = q.front();
        q.pop();
        
        for (int i = 0; i < 4; i++){
            int nx = u.first + dx[i];
            int ny = u.second + dy[i];
            if(nx<0||nx>=h)continue;
            if(ny<0||ny>=w)continue;
            if(!vis[nx][ny]){
                d[nx][ny] = d[u.first][u.second] + 1;
                vis[nx][ny] = 1;
                q.push({nx,ny});
                mxd = max(mxd, d[nx][ny]);
            }
        }
        
    }
    
    
    cout<<mxd<<endl;
    
    return 0;
}



Measured memory_bytes: 17296
X = int(input())

A = 0
B = 0
flag = False
for i in range(1, 1000):
    if flag == True:
        break
    for j in range(-1000, i):
        if flag == True:
            break
        if i**5 - j**5 == X:
            A = i
            B = j
            flag = True
print(A,B)


Measured memory_bytes: 9176