akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const int INF=1e9;
int n, m;
vi d(110);

bool ok(int mid) {
	int cnt = 1, now = 0;
	rep(i, 0, n) {
		if (now + d[i] <= mid) {
			now += d[i];
		}
		else if (d[i] <= mid) {
			now = d[i];
			cnt++;
		}
		else {
			return false;
		}
	}
	//cout << mid << " " << (cnt <= m ? "ok" : "ng") << cnt << m << endl;
	return cnt <= m;
}

signed main() {
	while (1) {
		cin >> m >> n;
		if (n + m == 0) break;
		d.clear();
		rep(i, 0, n) {
			cin >> d[i];
		}
		int l = 1, r = 1500000;
		rep(i, 0, 100) {
			int mid = (l + r) / 2;
			if (ok(mid)) r = mid;
			else l = mid;
		}
		cout << r << endl;
	}
}

Measured memory_bytes: 1192
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;

int main() {
  array<int,10> a;
  for(int &i: a) cin >> i;
  sort(a.begin(),a.end(),greater<int>());
  for(int i: {0,1,2}) cout << a[i] << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    
    // 要素
    int a[100][100] = {};
    // 要素の横方向の累積和を取る
    int sum[101][101] = {};
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            sum[i][j+1] += sum[i][j] + a[i][j];
        }
    }
    
    // 横方向の区間[i,j]を固定し、縦方向に動かして部分行列の和の最大値を取る
    int ans = INT_MIN;
    for(int i = 0; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            int tmp = 0;
            // 行kを0~nまで動かして最大値を探す
            // tmpが負になった時点でtmpをリセットしてしまって良い
            // (１つ前のループでtmpをmax関数に通しているので問題ない)
            for(int k = 0; k < n; k++){
                if(tmp < 0){
                    tmp = sum[k][j] - sum[k][i];
                }else{
                    tmp += sum[k][j] - sum[k][i];
                }
                ans = max(ans, tmp);
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

vector <double> points[12];
double dist[15][15];

double dd(int i, int j)
{
    double u = 0;
    for (int k = 0; k<points[i].size(); k++)
    {
        u+=((points[i][k]-points[j][k])*(points[i][k]-points[j][k]));
    }
    return sqrt(u);
}
int main()
{
    int n, d;
    cin >> n >> d;
    for (int i = 0; i<n; i++)
    {
        for (int j = 0; j<d; j++)
        {
            double x;
            cin >>x;
            points[i].push_back(x);
        }
    }
    int ct = 0;
    for (int i = 0; i<n; i++)
    {
        for (int j = 0; j<n; j++)
        {
            dist[i][j] = dd(i, j);
            if (dist[i][j]==(int)(dist[i][j]))
                ct++;
        }
    }
    ct-=n;
    cout << ct/2 << '\n';
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

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

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

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s;
	cin >> s;
	rep(i,SIZE(s)-1){
		if(s[i]==s[i+1]){
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}
		else if(i!=0 && s[i-1]==s[i+1]){
			cout << i << " " << i+2 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
from collections import deque
H, W = map(int,input().split())
maze = [input() for i in range(H)]
visit = [[-1]*W for i in range(H)]
x, y = 0, 0
cnt = 0
for i in range(H):
  for j in range(W):
    if maze[i][j] == ".":
      cnt += 1
def bfs(maze, visit, x, y):
  queue = deque()
  queue.append([0, 0])
  visit[y][x] = 0
  while queue:
    y, x = queue.popleft()
    if y == H-1 and x == W-1:
      return cnt-visit[y][x]-1
    for i, j in [[1,0],[-1,0],[0,1],[0,-1]]:
      nextx, nexty = x+i, y+j
      if nextx<0 or nextx>=W or nexty<0 or nexty>=H:
        continue
      elif maze[nexty][nextx] != "#" and visit[nexty][nextx] == -1:
        visit[nexty][nextx] = visit[y][x] + 1
        queue.append([nexty,nextx])
  return -1
print(bfs(maze,visit,x,y))

Measured memory_bytes: 3316
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int wide, tall, num, no[16][16], memo[128][128][3][3];

//x: 現在のx座標  y:現在のy座標  go:どちらの方向へ進んでいるか  prev:前に曲がったかどうか
//go = 0: east  go = 1: north
int road(int x, int y, int go, int prev)
{
	if(x > wide-1 || y > tall-1)
	{
		return 0;
	}
	else if(memo[x][y][go][prev] >= 0)
	{
		return memo[x][y][go][prev];
	}
	else if(x == wide-1 && y == tall-1)
	{
		return 1;
	}
	else
	{
		int ans;
		if(go == 2)
			ans = road(x+1, y, 0, 0) + road(x, y+1, 1, 0);

		else if(go == 1 && prev == 0)
			ans = road(x+1, y, 0, 1) + road(x, y+1, 1, 0);
		
		else if(go == 0 && prev == 0)
			ans = road(x+1, y, 0, 0) + road(x, y+1, 1, 1);
	
		else if(go == 1 && prev == 1)
			ans = road(x, y+1, 1, 0);
	
		else if(go == 0 && prev == 1)
			ans = road(x+1, y, 0, 0);
		
		return memo[x][y][go][prev] = ans % 100000;
	}
}

int main()
{
	while(cin >> wide >> tall)
	{
		if(!wide && !tall)
			break;

		memset(memo, -1, sizeof(memo));
		
		cout << road(0, 0, 2, 0) << endl;
		//for(int i = 0; i < 6; i++)
		//	for(int j = 0; j < 6; j++)
		//		printf("%2d%s", memo[j][i], (j == 5)?"\n":" ");
	}
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int32> ans;
    int32 cur = n;
    while(cur > 0){
        FOR(nx,max<int32>(0,cur-m),cur+1){
            if(nx == cur){
                ANS(-1);
                return 0;
            }
            if(s[nx] == '1')continue;
            ans.pb(cur-nx);
            cur = nx;
            // cout << cur << endl;
        }
    }
    reverse(ALL(ans));
    REP(i,ans.size()){
        if(i != 0)cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1480
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int x, k, q;
	cin >> x >> k;
	vi r(k + 1); rep(i, k) cin >> r[i + 1];
	
	cin >> q;
	vector<pi> qs;
	rep(i, q){
		int t, a; cin >> t >> a;
		qs.emplace_back(t, a);
	}
	int qi = 0;
	int a = 0, b = 0, c = x, d = x;
	rep(i, k+1){
		while(qi < q && (i==k || qs[qi].first <= r[i + 1])){
			int t = qs[qi].first - r[i];
			int s = qs[qi].second;
			int ans = s <= a ? b : s <= c ? b + s - a : d;
			if(i % 2) ans = min(x, ans + t);
			else ans = max(0, ans - t);
			cout << ans << endl;
			qi++;
		}
		if(i==k) break;
	
		int t = r[i + 1] - r[i];
		if(i % 2){
			if(d + t <= x) b += t, d += t;
			else if(b + t >= x) a = 0, b = x, c = 0, d = x;
			else{
				c -= t - (x - d); d = x; b += t;
			}
		}
		else{
			if(t <= b) b -= t, d -= t;
			else if(t <= d){
				a += t - b; b = 0; d -= t;
			}
			else a = 0, b = 0, c = 0, d = 0;
		}
		assert(a <= c);
	}
	return 0;
}

Measured memory_bytes: 2548
<?php
fscanf(STDIN, '%d %d %d', $n, $a, $b);
define('MOD', 10 ** 9 + 7);

$ans = modSub(modSub(modSub(modPow(2, $n), 1), nCr($n, $a)), nCr($n, $b));
echo $ans . PHP_EOL;

// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return $x * modPow($y, MOD - 2) % MOD;
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = ($res * $n) % MOD;
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return $n * modFac($n - 1) % MOD;
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return nPr($n, $r - 1) * ($n - $r + 1) % MOD;
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    if ($r === 1) return $n;
    return modDiv(nPr($n, $r), modFac($r));
}

Measured memory_bytes: 61944
N = gets.to_i
G = (1..N).map{ Array.new(N, 0) }
N.times do
  u, k, *v = gets.split(' ').map(&:to_i)
  v.each do |vi|
    G[u - 1][vi - 1] = 1
  end
end

Q = [0] #?§????0?????\??£????????\???
D = Array.new(N, -1)
D[0] = 0 #?§???????????????¢???0??????????????¢???-1??¨????????????

while Q.size > 0
  cur = Q.shift
  (0..N-1).each do |dst|
    if G[cur][dst] == 1 && D[dst] == -1
      D[dst] = D[cur] + 1
      Q << dst
    end
  end
end

(0..N-1).each do |id|
  puts "#{id + 1} #{D[id]}"
end



# g.each do |r|
#   puts r.join(" ")
# end

Measured memory_bytes: 8752
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int l = 0; int cur = (s[0] == '0');
    int ans = 0;
    for (int r = 1; r < n; r++) {
        if (s[r] != s[r-1]) {
            if (s[r] == '0') cur++;
            if (cur > k) {
                //cout << l << " " << r << endl;
                ans = max(ans, r - l);
                l++;
                for (l; l < n; l++) {
                    if (s[l] != s[l-1]) {
                        if (s[l] == '1') break;
                    }
                }
                cur--;
            }
        }
    }
    //cout << l << " " << n << endl;
    ans = max(ans, n - l);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
int main()
{
    bool chk=true;
    int ara[109][109];
    int x, y, j, i, cnt=1, n, tm, now=1;
    cin >> x >> y >> n;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&tm);
        while(tm--)
        {
            ara[now][cnt++]=i;
            if(cnt>y) now++, cnt=1;
        }
    }
    for(i=1; i<=x; i++)
    {
        if(i%2)
        {
            for(j=1; j<y; j++) printf("%d ",ara[i][j]);
            printf("%d\n",ara[i][j]);
        }
        else
        {
            for(j=y; j>1; j--) printf("%d ",ara[i][j]);
            printf("%d\n",ara[i][1]);
        }
    }
    return 0;
}


Measured memory_bytes: 764
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        (n, k) = [int(e) for e in lines[0].split(' ')]
        for i in range(2*k):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        (n, k) = [int(e) for e in lines[0].split(' ')]

    d = [] 
    a = []
    for i in range(1, 2*k+1):
        if i % 2 == 1:
           d.append(int(lines[i]))
        else:
           a.append([int(e) for e in lines[i].split(' ')])

    return (n, k, d, a)


def solve(n, k, d, a):


    candy_a = set() 
    for i in range(k):
        for e in a[i]:
            candy_a.add(e)

    result = n - len(candy_a)

    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 67720
S = list(map(int, input().split()))
S1 = S[0]
sum = 0
c = 0
coin = 0
for i in range(1,S[0]+1):
    k = i
    while k < S[1]:
        c = c + 1
        k = k * 2
    sum = sum + 1/S[0] * (0.5 ** c)
    
    c = 0
print(sum)


Measured memory_bytes: 3060
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = [int(input()) for _ in range(N)]

ans = 0
prev = 0
for i in range(N):
    if prev == 1 and A[i] > 0:
        A[i] -= 1
        ans += 1
    q, mod = divmod(A[i], 2)
    ans += q
    prev = mod

print(ans)

Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
int N,ans;
set<int>st;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>N;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        if(st.find(x)!=st.end())st.erase(st.find(x));
        else st.insert(x);
    }
    cout<<st.size();
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
using namespace std;

int n,k;
deque<int> d,e;
signed main(){
    
    cin>>n;
    rep(i,n){
    	int a;
    	cin>>a;
    	d.push_back(a);
    }
    sort(d.begin(),d.end());
    e=d;
    deque<int> da,ea;
    da.push_back(d[n-1]);
    d.pop_back();
    ea.push_back(e[0]);
    e.pop_front();
    for(int i=0;d.size();i++){
    	if(d.size()==1){
    		if(abs(d[0]-da[0])<abs(d[0]-da[da.size()-1])){
    			da.push_back(d[0]);
    		}
    		else{
    			da.push_front(d[0]);
    		}
    		break;
    	}
    	if(i%2==0){
    		da.push_back(d[0]);
    		da.push_front(d[1]);
    		d.pop_front();d.pop_front();
    	}
    	else{
    		da.push_back(d[d.size()-1]);
    		da.push_front(d[d.size()-2]);
    		d.pop_back();d.pop_back();
    	}
    }
    
    for(int i=0;e.size();i++){
    	if(e.size()==1){
    		if(abs(e[0]-ea[0])<abs(e[0]-ea[ea.size()-1])){
    			ea.push_back(e[0]);
    		}
    		else{
    			ea.push_front(e[0]);
    		}
    		break;
    	}
    	if(i%2==1){
    		ea.push_back(e[0]);
    		ea.push_front(e[1]);
    		e.pop_front();e.pop_front();
    	}
    	else{
    		ea.push_back(e[e.size()-1]);
    		ea.push_front(e[e.size()-2]);
    		e.pop_back();e.pop_back();
    	}
    }
    
    int ans=0,ans2=0;
    for(int i=1;i<n;i++){
    	ans+=abs(da[i-1]-da[i]);
    	ans2+=abs(ea[i-1]-ea[i]);
    }
    /*rep(i,n)cout<<da[i]<<" ";
    cout<<endl;
    rep(i,n)cout<<ea[i]<<" ";
    cout<<endl;*/
    cout<<max(ans,ans2)<<endl;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdint>
using namespace std;

int main() {
    uint32_t n; cin >> n;
    vector<int32_t> h(n);
    for (auto &e : h) cin >> e;

    // dp[i] = i番目の足場へ行くのに掛かるコストの最小値
    vector<uint32_t> dp(n + 1);
    // 0番目の足場と1番目の足場へ行くのに掛かるコストは0
    dp[0] = dp[1] = 0;
    // 2番目の足場へ行くには 1 -> 2 という道しかない
    dp[2] = abs(h[0] - h[1]);

    // 足場 j + 1 番目へ飛ぶとき、j の足場から飛んでくるか、 j - 1の足場から飛んでくるか、
    // どちらのほうが小さいコストで飛んでこれるかを min で取る。
    // 最初の計算には dp[0] dp[1] dp[2] のあらかじめ決定された値が使用される
    for (uint32_t j = 2; j < n; ++j) {
        dp[j + 1] = min(dp[j] + abs(h[j - 1] - h[j]), dp[j - 1] + abs(h[j - 2] - h[j]));
    }

    // 最終的にn番目の足場へ行くのに掛かる最小コストを出力
    cout << dp[n] << endl;
}



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

// 素因数分解をして結果を map で返す
// first: 素数, second: 素数 first の数
// 計算量 O(√n)
map<ll, ll> PrimeFactor(ll n) {
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++res[i];
            n /= i;
        }
        if(LLINF / i <= i) { break; }  // オーバーフロー警察
    }
    if(n != 1) { res[n] = 1; }
    return res;
}

ll S;

void Check(ll x1, ll y1, ll x2, ll y2) {
    assert(abs(x1 * y2 - x2 * y1) == S);
}

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

    cin >> S;

    const ll e9 = 1000000000LL;
    const ll e18 = e9 * e9;
    if(S == e18) {
        printf("%lld 0 0 %lld 0 0\n", e9, e9);
        return 0;
    }
    else if(S < e9) {
        // 少ない数なら 1 点を固定可能
        printf("%lld 0 0 1 0 0\n", S);
        return 0;
    }

    // 上 9 桁と下 9 桁に分ける
    ll upper = S / e9 + 1;
    ll lower = e9 - (S % e9);

    ll x1 = e9;
    ll y2 = upper;

    // 下を適当な掛け算に分ける
    auto res = PrimeFactor(lower);

    ll x2 = 1;
    for(auto& p : res) {
        ll tmp = p.first / ((p.second == 1) ? 1 : 2);
        ll next_x2 = x2 * tmp;
        if(tmp > e9) { break; }
        x2 = next_x2;
    }
    ll y1 = lower / x2;

    printf("%lld %lld %lld %lld 0 0\n", x1, y1, x2, y2);
    Check(x1, y1, x2, y2);

    return 0;
}


Measured memory_bytes: 256
import math
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

A=10*(math.ceil(a/10))
B=10*(math.ceil(b/10))
C=10*(math.ceil(c/10))
D=10*(math.ceil(d/10))
E=10*(math.ceil(e/10))

re1=A-a
re2=B-b
re3=C-c
re4=D-d
re5=E-e
result=[[re1,A],[re2,B],[re3,C],[re4,D],[re5,E]]
result.sort()
ans=0
for i in range(5):
    if i==4:
        ans+=result[i][1]-result[i][0]
        break
    ans+=result[i][1]
print(ans)

Measured memory_bytes: 62128
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string>

using namespace std;

void solve() {
    int n, t;
    cin >> n >> t;
    int mincost = 100000;
    for(int i = 0; i < n; i++){
        int tmpc, tmpt;
        cin >> tmpc >> tmpt;
        if(tmpt <= t){
            mincost = min(mincost, tmpc);
        }
    }
    cout << (mincost == 100000 ? "TLE" : to_string(mincost)) << endl;
}

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

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

int main() {
  int N, M, A, X = 0;
  cin >> N;
  vector<string> blue(N);
  //blue代入
  for (int i = 0; i < N; i++){
    cin >> blue.at(i);
  }
  //red代入
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++){
    cin >> red.at(i);
  }
  for (int i = 0; i < N; i++){
    A = 1;
    for (int j = i + 1; j < N; j++){
      if (blue.at(i) == blue.at(j)){
        A += 1;
      }
    }
    for (int k = 0; k < M; k++){
      if (blue.at(i) == red.at(k)){
        if (A == 0)
          continue;
        A -= 1;
      }
    }
    if (X < A)
      X = A;
  }
  cout << X << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int X;
    cin >> X;
    int Ans=0;
    Ans+=(X/500)*1000;
    X%=500;
    Ans+=(X/5)*5;
    
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		100000									// 最大配列数
#define D_BIT_MAX		35										// 最大ビット数

// 内部構造体 - 値情報
typedef struct Val {
	char mc1Bit[D_BIT_MAX];										// 値
	int miVal;													// 価値
} Val;

// 内部変数
static FILE *szpFpI;											// 入力
static Val sz1Val[D_ARRAY_MAX];									// 配列
static int siACnt;												// 配列数
static char sc1K[D_BIT_MAX];									// K

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 最大値 - 取得
long long
fGetMaxL(
	long long plVal1			// <I> 値１
	, long long plVal2			// <I> 値２
)
{
	if (plVal1 > plVal2) {
		return plVal1;
	}
	else {
		return plVal2;
	}
}

// ビット化
int
fIntToBit(
	int piVal					// <I> 値
	, char *pcpBit				// <O> ビット
)
{
	int i;

	for (i = 0; i < D_BIT_MAX; i++) {
		pcpBit[i] = piVal % 2;
		piVal /= 2;
	}

	return 0;
}

// 価値合計 - 取得
long long
fGetVSum(
	char *pcpK					// <I> K
)
{
	int i, j;

	long long llVSum = 0;
	for (i = 0; i < siACnt; i++) {
		for (j = 0; j < D_BIT_MAX; j++) {
			if (sz1Val[i].mc1Bit[j] > pcpK[j]) {
				break;
			}
		}
		if (j == D_BIT_MAX) {
			llVSum += sz1Val[i].miVal;
		}
	}

	return llVSum;
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024];

	// 配列数・K - 取得
	int liK;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siACnt, &liK);
	fIntToBit(liK, sc1K);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		int liVal;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &liVal, &sz1Val[i].miVal);
		fIntToBit(liVal, sz1Val[i].mc1Bit);
	}

	// 最大値 - 取得
	long long llMax = fGetVSum(sc1K);
	for (i = D_BIT_MAX - 1; i >= 0; i--) {
		if (sc1K[i] == 0) {
			continue;
		}

		// 下位 ALL ON
		char lc1K[D_BIT_MAX];
		memcpy(lc1K, sc1K, sizeof(lc1K));
		lc1K[i] = 0;
		for (j = 0; j < i; j++) {
			lc1K[j] = 1;
		}

		// 価値合計 - 取得
		long long llVSum = fGetVSum(lc1K);
		llMax = fGetMaxL(llMax, llVSum);
	}

	// 出力
	sprintf(lc1Buf, "%lld\n", llMax);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 4096
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

typedef long long ll;

const int SMAX = 8000;

int main(){
  string s; cin >> s;
  int fx, fy; cin >> fx >> fy;
  vector<int> cx(SMAX+1), cy(SMAX+1);
  for(int i=0;i<=SMAX;i++){
    cx[i]=0; cy[i]=0;
  }
  int turn=1;
  for(int i=0;i<s.size();i++){
    if(s[i] == 'T') turn++;
    else if(turn %2 == 0){
      cy[turn/2]++;
    }else{
      cx[(turn+1)/2]++;
    }
  }
  int xt = (turn+1)/2, yt = turn/2;
  bool dpx[xt+1][2*SMAX+1], dpy[yt+1][2*SMAX+1];
  for(int i=0;i<=xt;i++){
    for(int j=0;j<=2*SMAX;j++){
      dpx[i][j] = false;
    }
  }
  for(int i=0;i<=yt;i++){
    for(int j=0;j<=2*SMAX;j++){
      dpy[i][j] = false;
    }
  }
  dpx[0][SMAX] = true;
  dpx[1][SMAX+cx[1]] = true;
  for(int i=2;i<=xt;i++){
    for(int j=0;j<=SMAX*2;j++){
      if(j-cx[i] < 0){
        dpx[i][j] = dpx[i-1][j+cx[i]];
      }else if(j+cx[i] > SMAX*2){
        dpx[i][j] = dpx[i-1][j-cx[i]];
      }else{
        dpx[i][j] = (dpx[i-1][j-cx[i]] || dpx[i-1][j+cx[i]]);
      }
    }
  }
  dpy[0][SMAX] = true;
  for(int i=1;i<=yt;i++){
    for(int j=0;j<=SMAX*2;j++){
      if(j-cy[i] < 0) dpy[i][j] = dpy[i-1][j+cy[i]];
      else if(j+cy[i] > SMAX*2) dpy[i][j] = dpy[i-1][j-cy[i]];
      else dpy[i][j] = (dpy[i-1][j-cy[i]] || dpy[i-1][j+cy[i]]);
    }
  }
  if(dpx[xt][fx+SMAX] && dpy[yt][fy+SMAX]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 124288
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str1, str2;

    cin >> str1 >> str2;

    if(str1.length() > str2.length())
    {
        cout << "GREATER" <<endl;
    }
    else if(str1.length() < str2.length())
    {
        cout << "LESS" << endl;
    }
    else
    {
        int i = 0, len = str1.length();

        while(i < len)
        {
            if(str1[i] > str2[i])
            {
                cout << "GREATER" <<endl;
                break;
            }
            else if( str1[i] < str2[i])
            {
                cout << "LESS" <<endl;
                break;
            }
            else
            {
                i++;
            }
        }
        ///cout << i <<endl;
        if(i == len)
        {
            cout << "EQUAL" <<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N;
  cin>>N;
  vector<string>S(N);
  for(int i=0;i<N;i++){
  string s;
    cin>>s;
    sort(s.begin(),s.end());
    S.at(i)=s;
  }map<string,int64_t>M;
  for(int64_t i=0;i<N;i++){
  if(!M.count(S.at(i)))
     M[S.at(i)]=1;
     else
     M.at(S.at(i))++;
  }int64_t ans=0;
     for(auto p:M){
     auto k=p.first;
       auto v=p.second;
       ans+=(M[k]*(M[k]-1))/2;
     } cout<<ans<<endl;
     return 0;
}

Measured memory_bytes: 11904
#define z(m,n)for(;m;m--)scanf("%d",&s),x[s+n]++
x[41];main(m,n,s){for(;scanf("%d%d",&m,&n),m;printf("%d\n",s)){memset(x,0,164);z(m,0);z(n,20);for(m=21,s=0;m--;s+=m*(x[m]>x[m+20]?x[m]:x[m+20]));}}

Measured memory_bytes: 0
#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,m, ac = 0;
    ll wa = 0;
    cin >> n >> m;
    vector<int> v(n+1), ans(n+1);
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        if (s == "WA" && ans.at(p) != 1){
            wa += 1;
            v.at(p) += 1;
        }
        else if (s == "AC" && ans.at(p) != 1){
            ac += 1;
            ans.at(p) = 1;
        }
        else continue;
    }
    rep (i,n){
        if (ans.at(i+1)!=1 and v.at(i+1) >= 1) wa -= v.at(i+1);
    }
    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


struct edge{
    ll to,cost;
};
ll n,m,l,q;
vector<edge>  G[100010];
ll d[100010];
ll D[400][400];
ll cost[310][310];

void  dijkstra(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d,d+n+1,LLINF);
    d[s]=0;
    que.push(pii(0,s));

    while(!que.empty()){
        pii p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    } 
    rep(i,n){
        cost[s][i]=d[i];
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin>>n>>m>>l;
    rep(i,310)rep(j,310){
        cost[i][j]=LLINF;
        D[i][j]=LLINF;
    }
    rep(i,m){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    cin>>q;
    rep(i,n){
        dijkstra(i);
    }
    rep(i,310){
        G[i].clear();
    }
    rep(i,n)rep(j,n){
        if(cost[i][j]<=l){
            G[i].push_back({j,1});
            G[j].push_back({i,1});
        }
    }
    rep(i,n){
        dijkstra(i);
    }
    rep(i,q){
        ll s,t,L=l,ans=0;
        cin>>s>>t;
        s--;t--;
        if(cost[s][t]>=LLINF){
            ans=-1;
        }
        else{
            ans=cost[s][t]-1;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 9856
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1005;
const long double epsilon = 1e-9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	ll n, m, k;
	cin >> n >> m >> k;
	vector<vector<char>> a(n, vector<char>(m));
	loop(i, n)	loop(j, m)	cin >> a[i][j];
	ll ans = 0;
	loop(mask1, (1 << n))
	{
		set<ll> rows;
		loop(i, n)
		{
			if ((1 << i) & mask1)
				rows.insert(i);
		}
		loop(mask2, (1 << m))
		{
			set<ll> cols;
			loop(j, m)
			{
				if ((1 << j) & mask2)
					cols.insert(j);
			}
			ll black = 0;
			loop(i, n)
			{
				loop(j, m)
				{
					if (rows.find(i) == rows.end() && cols.find(j) == cols.end() && a[i][j] == '#')
						++black;
				}
			}
			if (black == k)
				++ans;
		}
	}
	cout << ans << END;


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
int XOR(int a,int b){
	int ni=1;
	rep(0,i,41){
		n2[i]=ni;
		ni*=2;
	}
	rep(0,i,41)nis[i]=0;
	for(int i=40;i>=0;i-=1){
		if(a>=n2[i]){
			nis[i]++;
			a-=n2[i];
		}
		if(b>=n2[i]){
			nis[i]++;
			b-=n2[i];
		}	
	}
	int sum=0;
	rep(0,i,41)sum+=(nis[i]%2*n2[i]);
	return sum;
}
signed main(){
	ic(a) ic(b) ic(c) ic(d) ic(e) ic(f) ic(g)
	int ans=0;
	ans+=b;
	if(a%2+d%2+e%2==0)ans+=(a+d+e);
	else if(a%2+d%2+e%2==1)ans+=(a+d+e-1);
	else if(a%2+d%2+e%2==2){
		if(a==0||d==0||e==0)ans-=1;
		ans+=(a+d+e-1);
	}	
	else ans+=(a+d+e);
	c(ans)
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

#正/負いずれかから始める
cost1=0
cost2=0
sum1=0
sum2=0
for i in range(n):
  sum1=sum1+a[i]
  sum2=sum2+a[i]
  if i%2==0:
    if sum1<1:
      cost1+=1-sum1
      sum1=1
    
    if sum2>-1:
      cost2+=1+sum2
      sum2=-1
  else:
    if sum1>-1:
      cost1+=1+sum1
      sum1=-1
    
    if sum2<1:
      cost2+=1-sum2
      sum2=1
print(min(cost1,cost2))

Measured memory_bytes: 19964
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

ll LCM(ll x , ll y){
	return (x*y) / __gcd(x,y) ;
}

ll NumOfDiv(ll a , ll b , ll k){
	return b/k - a/k + (a%k == 0) ;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ----------------------
    ll a , b , x , y ; 
    cin >> a >> b >> x >> y ; 
    ll resX = NumOfDiv(a,b,x);    
    ll resY = NumOfDiv(a,b,y);    
    ll resLCM = NumOfDiv(a,b,LCM(x,y));
    ll result = b - a + 1 - resX - resY + resLCM ;
    cout << result << endl ;    
    return 0 ;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if ((a+b) % 2 == 0){
        cout << (a+b) / 2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long long  dp[1010][1010] = {};
int main() {
	int H, W;
	long long int mod = 1000000007;
	cin >> H >> W;
	vector<vector<char>> G(H,vector<char> (W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> G.at(i).at(j);
		}
	}
	for (int i = 0; i < H; i++) {
		if (G[i][0] == '.') {
			dp[i][0] = 1;
		}
		else {
			break;
		}
	}
	for (int i = 0; i < W; i++) {
		if (G[0][i] == '.') {
			dp[0][i] = 1;
		}
		else {
			break;
		}
	}
	for (int i = 1; i < H; i++) {
		for (int j = 1; j < W; j++) {
			if (G[i][j] == '.') {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
			}
			else {
				dp[i][j] = 0;
			}
		}
	}
	cout << dp[H - 1][W - 1] << endl;
	return 0;
}

Measured memory_bytes: 9088
#include <cstdio>
#include <cstring>

using namespace std;

int s[10][400];
int t[10][400];
int H, W;

int main()
{
	//freopen("in.txt", "r", stdin);

	while (scanf("%d%d", &H, &W)==2) {
		if (H==0 || W==0) break;
		int i, j;

		memset(s, 0, sizeof(s));

		for (i=0; i<H; i++) {
			for (j=0; j<W; j++) {
				int c;
				scanf("%d", &c);
				s[i][j/32] |= c<<(j%32);
			}
		}
		
		
		int mask;
		int limit = 1<<H;
		int max = 0;
		for (mask=0; mask<limit; mask++) {
			
			for (i=0; i<H; i++) {
				if (mask & (1<<i)) {
					for (j=0; j<400; j++)
						t[i][j] = s[i][j]^0xffffffff;

				}
				else {
					for (j=0; j<400; j++)
						t[i][j] = s[i][j];
				}
			}

			int sum = 0;
			for (j=0; j<W; j++) {
				int col_num = 0;
				int col, bit;
				col = j/32; bit = 1<<(j%32);
				for (i=0; i<H; i++) {
					if (t[i][col]&bit)
						col_num++;
				}
				if (col_num<H-col_num)
					col_num = H-col_num;
				sum += col_num;
			}
			if (max<sum)
				max = sum;

		}
		printf("%d\n", max);

	}

	return 0;
}

Measured memory_bytes: 1064
//
// Created by munaiyi on 2020/3/19.
//

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 5;
int h[maxn], mem;
struct {
    int v, next, id;
} e[maxn << 2];

void add(int u, int v, int id) {
    e[mem].v = v;
    e[mem].id = id;
    e[mem].next = h[u];
    h[u] = mem++;
}

int vis[maxn], d[maxn];
pair<int, int> dd[maxn];
int ans[maxn << 1];

int main() {
    memset(h, -1, sizeof(h));
    memset(vis, -1, sizeof(vis));
    memset(ans, -1, sizeof(ans));
    mem = 0;
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &d[i]);
        dd[i].first = d[i];
        dd[i].second = i;
    }
    sort(dd + 1, dd + 1 + n);
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        add(u, v, i);
        add(v, u, i);
    }
    for (int i = 1; i <= n; i++) {
        if (vis[dd[i].second] + 1) continue;
        int uv = -1, id = 0;
        for (int j = h[dd[i].second]; j + 1; j = e[j].next) {
            int v = e[j].v;
            if (vis[v] + 1 && d[v] < d[dd[i].second]) {
                uv = v;
                id = e[j].id;
                break;
            } else if (d[v] == d[dd[i].second]) {
                uv = v;
                id = e[j].id;
            }
        }
        if (uv == -1) {
            printf("-1\n");
            return 0;
        }
        if (d[uv] < d[dd[i].second]) {
            vis[dd[i].second] = vis[uv];
            ans[id] = d[dd[i].second] - d[uv];
        } else {
            if (vis[uv] == -1) {
                vis[uv] = 0;
            }
            vis[dd[i].second] = vis[uv] ^ 1;
            ans[id] = d[dd[i].second];
        }
    }
    for (int i = 1; i <= n; i++) {
        putchar(vis[i] ? 'B' : 'W');
    }
    putchar('\n');
    for (int i = 0; i < m; i++) {
        printf("%d\n", ans[i] == -1 ? 1000000000 : ans[i]);
    }
    return 0;
}

Measured memory_bytes: 9856
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)( 998244353))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    ll n;
    cin >> n;
    map<ll,ll> d;
    ll max_d= 0;
    
    rep(i,0,n){
	ll a;
	cin >> a;
	d[a]++;
	if(i == 0){
	    if(a != 0){
		P(0);
		ret 0;
	    }
	}
	max_d = max(max_d,a);
    }

    ll ans = 0;
    if(d[0] == 1){
	ans = 1;
	ll num = 1; 

	while(num <= max_d){
	 
	    ans *= modpow( d[num-1] , d[num]);
	    ans = mod(ans);
	    
	    num++;
	}

    }
    
    P(ans);
    
    return  0;
}


Measured memory_bytes: 6528