akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
  int n;
  cin >> n;
  // n = 3;
  vector<int> a;
  vector<int> b;
  vector<int> c;

  a.assign(n, 0);
  b.assign(n, 0);
  c.assign(n, 0);

  for (size_t i = 0; i < n; i++)
  {
    cin >> a[i];
  }

  for (size_t i = 0; i < n; i++)
  {
    cin >> b[i];
  }

  for (size_t i = 0; i < n - 1; i++)
  {
    cin >> c[i];
  }

  int total = 0;
  int bonus_num = 0;

  for (size_t i = 0; i < n; i++)
  {
    int num = a[i];
    int score = b[num - 1];
    total += score;
    if (bonus_num == num)
    {
      total += c[num - 2];
    }
    bonus_num = num + 1;
  }
  cout << total << endl;
}

Measured memory_bytes: 256
# unionfind
class Uf:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]

def main():
    N, M = map(int, input().split())
    P = list(map(int, input().split()))
    uf = Uf(N+1)
    for _ in range(M):
        x, y = map(int, input().split())
        uf.unite(x, y)
    ans = 0
    for i, p in enumerate(P, 1):
        if uf.same(i, p):
            ans += 1
    print(ans)

main()


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

LL dp[105][100005];

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

    int N, W;
    cin >> N >> W;
    vector< LP > v(N);
    for( int i = 0; i < N; ++i ) {
        cin >> v[i].F >> v[i].S;

    }

    for( int i = 0; i < N; ++i ) {
        for( int j = 1; j <= W; ++j ) {
            if( i != 0 ) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j]);
                if( j > v[i].F ) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i].F] + v[i].S);

                }

            }
            if( j == v[i].F ) {
                dp[i][j] = max(dp[i][j], v[i].S);

            }
            dp[i][j] = max(dp[i][j], dp[i][j - 1]);

        }
    }
    cout << dp[N - 1][W] << endl;
    return 0;
}



Measured memory_bytes: 80128
#include<iostream>
using namespace std;
#define MAX 500000
int H,largest;
int right(int i)
{
    return 2*i+1;
}
int left(int i)
{
    return 2*i;
}
int parent(int i)
{
    return i/2;
}

void maxHeapify(int A[],int i)
{
    int l = left(i);
    int r = right(i);
    //从左节点、自身、右节点中选出值最大的节点
    if( l <= H && A[l] > A[i] )
    {
        largest = l;
    }else{
        largest = i;
    }
    if( r <= H && A[r] > A[largest])
    {
        largest = r;
    }
    if(largest != i)
    {
        int temp = A[i] ;
        A[i] = A[largest];
        A[largest] = temp;
        maxHeapify(A,largest);
    }
}

void buildMaxHeap(int A[])
{
    for(int i=H/2;i>0;i--)
    {
        maxHeapify(A,i);
    }
}

int main()
{
    int A[MAX+1];
    cin>>H;
    for(int i=1;i<=H;i++)
    {
        cin>>A[i];
    }
    buildMaxHeap(A);
    for(int i=1;i<=H;i++)
    {
        cout<<" "<<A[i];
    }
    cout<<endl;
    return 0;
}





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

int main(){
  int n, k, d,sunuke;
  cin >> n >> k ;
  map<int, int> a;
  for(int i = 1; i <= k; i++){
    cin >> d;
    for(int j = 0; j<d; j++){
      cin >> sunuke;
      a[sunuke] = 0;
    }
  }
  cout << n- a.size() << endl;
}
    
  

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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

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

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	REP(i, n) {
		cin >> v[i];
		sum += v[i];
	}
	vector<bool> ans(sum + 1, false);

	for (int j = 0; j < 1 << n; ++j) {
		int s=0;
		int a = j;
		REP(i, n) {
			s += v[i] * (a & 1);
			a >>= 1;
		}
		ans[s] = true;
	}
    cin >> m;

	REP(i, m) {
		int a;
		cin >> a;
		if (a<=sum&&ans[a]) cout << "yes" << endl;
		else cout << "no" << endl;
	}


	return 0;
}

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

int main(){
    int n, p;
    
    while(true){
        int ans = 0;
        cin >> n >> p;
        vector<int> v(n);
        if(n == 0 && p == 0) break;

        int flag = 0, i = 0;
        int cnt = 0;
        while(true){
            if(p == 0){
                p += v[i];
                v[i] = 0;
            }
            else {
                p--;
                v[i]++;
            }
            if(p == 0) for(int j=0; j<n; j++) flag += (v[j] != 0);
            if(flag == 1) break;
            else flag = 0;
            i++;
            i %= n;
        }
        cout << i << endl;
    }
    return 0;
}


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

string s;
int solve(){
    int l = s.size();
    int ans = INF;
    for(int i=0;i<l-1;i++){
        if(s[i]==s[i+1])continue;
        chmin(ans,max(i+1,l-i-1));
    }
    if(ans==INF)return l;
    return ans;
}

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


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)


using namespace std;
typedef long long ll;

int main(){
    string S;
    cin>>S;
    char c = S[0];
    if(c=='A'){
        cout<<'T'<<endl;
    }else if(c=='T'){
        cout<<'A'<<endl;
    }else if(c=='G'){
        cout<<'C'<<endl;
    }else if(c=='C'){
        cout<<'G'<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<map>
#include<queue>
#include<math.h>
using namespace std;


int main(){
  string s ;
  cin >> s;
  s[5]=' ';
  s[13]=' ';
  cout << s <<endl;
}


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

#define za ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod %1000000007
#define moz 1000000007
#define nl "\n"
#define S second
#define F first
#define PB push_back
#define MP make_pair
#define V vector
//#define P pair
#define LEN length()
#define SZ size()
#define loop(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
typedef complex<ll> P;
#define X real()
#define Y imag()


int main()
{
    za ;
    ll x;
    ll n;
    pair <ll,ll> arr[5];
    loop(i,0,3)
    {
        cin >> x;
        if(i==0) arr[i]=MP(x*8,1);
        else if(i==1) arr[i]=MP(x*4,1);
        else if(i==2) arr[i]=MP(x*2,1);
        else arr[i]=MP(x,2);
    }
    cin >> n;
    sort(arr,arr+4);
    loop(i,0,3)
    {
        if(arr[i].S==1)
        {
            arr[i].F=arr[i].F/2;
        }
    }
    int i=0;
    ll co=0;
    while(n!=0)
    {
        ll x=n/arr[i].S;
        co+=(x*arr[i].F);
        n=n-(x*arr[i].S);
        i++;
        //cout << x << ' ' << arr[i].F << nl;
    }
    cout << co << nl;
}


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

ll n,w;
ll bag_weight[110];
ll bag_value[110];
ll sum_value[110][100100] = {0};

int main(){
	cin >> n >> w;
	for (int i =0;i < n;i++) cin >> bag_weight[i] >> bag_value[i];
	
	for (int i = 0;i < n;i++){
		for (int sum_w = 0; sum_w <= w; sum_w++){
			if(sum_w - bag_weight[i] >= 0){
				chmax(sum_value[i+1][sum_w], sum_value[i][sum_w - bag_weight[i]] + bag_value[i]);
			}
			chmax(sum_value[i+1][sum_w], sum_value[i][sum_w]);
		}
	}
	cout << sum_value[n][w] << endl;;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

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

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  if (M1 != M2) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define ll long long

int a[114514], b[114514],m11 = 0,m12 = 0,m21 = 0,m22 = 0,n11,n12;
int main() {
	int n;
	cin >> n;
	REP(i, n) {
		int c;
		cin >> c;
		if (i % 2 == 0) a[c]++;
		else b[c]++;
	}
	REP(i, 114514) {
		if (m11 <= a[i]) {
			m12 = m11;
			n11 = i;
			m11 = a[i];
		}
		else if (m12 < a[i]) m12 = a[i];
	}
	REP(i, 114514) {
		if (m21 <= b[i]) {
			m22 = m21;
			n12 = i;
			m21 = b[i];
		}
		else if (m22 < b[i]) m22 = b[i];
	}
	if (n11 == n12) cout << n - max(m11 + m22, m12 + m21) << endl;
	else cout << n - m11 - m21 << endl;
}


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

typedef long long  ll;
	

int main()
{
	ll n,x,c=0;
	cin>>n;
	map<ll,ll>m1,m2;
	for(ll i=1;i<=n;i++)
	{
		cin>>x;
		m1[i+x]++;
		m2[i-x]++;
	}
	for(auto i:m1)
		c+=i.second*m2[i.first];
	cout<<c<<endl;
}

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

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

int main(void){
    ll a,b;
    cin >> a >> b;
    if(a<b) swap(a,b);
    int c = a;
    while(a%b!=0) a += c;
    cout << a << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int x, y, ans;
  string s;
  cin >> s;

  x = 0;
  y = 0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      x++;
    }else{
      y++;
    }
  }

  if(x<y){
    ans = 2*x;
  }else{
    ans = 2*y;
  }

  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    string s;
    cin >> s;
    ll c=0,ans=0;

    for (ll i=0;i<s.size();i++){
        if (s[i]=='B'){
            c++;
        }else{
            ans+=c;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3756
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := ri(), ri()
	s := make([][]int, m)
	for i := 0; i < m; i++ {
		k := ri()
		s[i] = make([]int, k)
		for j := 0; j < k; j++ {
			s[i][j] = ri() - 1
		}
	}
	p := make([]int, m)
	for i := 0; i < m; i++ {
		p[i] = ri()
	}
	ans := 0
	for i := 0; i < (1 << uint(n)); i++ {
		ok := true
		for j := 0; j < m; j++ {
			tmp := 0
			for k := 0; k < len(s[j]); k++ {
				tmp += i >> uint(s[j][k]) & 1
			}
			if tmp%2 != p[j] {
				ok = false
				break
			}
		}
		if ok {
			ans++
		}
	}
	fmt.Println(ans)
}


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

using namespace std;
int const N=5e5;
int dp[N][15];
int n;
string s;
int rec(int idx,int md){
    int &ret=dp[idx][md];
    if(ret!=-1)return ret;
    if(idx==n)return ret=md==5;
    ret=0;
    if(s[idx]=='?'){
        for(int i=0;i<10;i++){
            ret+=rec(idx+1,(10*md+i)%13);
            ret%=(1000000007);
        }
        return ret;
    }else{
        return ret=rec(idx+1,(10*md+(s[idx]-'0'))%13);
    }
}
int main() {
    cin>>s;
    n=s.size();
    memset(dp,-1,sizeof dp);
    cout<<rec(0,0);
    return 0;
}

Measured memory_bytes: 35968
#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include<cstring>
using namespace std;
int n;

int main(){
	cin>>n;
	string n1,n2;
	cin>>n1>>n2;
	for(int i=0;i<n;i++){
		cout<<n1[i]<<n2[i]; 
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] r = new int[n+1];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            r[a]++;
            r[b]++;
        }

        for (int i = 1; i <= n; i++) {
            System.out.println(r[i]);
        }
    }
}

Measured memory_bytes: 36056
import java.util.*;

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

    int[][] k1 = new int[3][10];
    int[][] k2 = new int[3][10];
    int[][] k3 = new int[3][10];
    int[][] k4 = new int[3][10];

    int n = sc.nextInt();

    for(int i = 0; i < n; i++){
      int b = sc.nextInt();
      int f = sc.nextInt();
      int r = sc.nextInt();
      int v = sc.nextInt();

      if(b == 1){
        k1[f - 1][r - 1] += v;
      } else if(b == 2){
        k2[f - 1][r - 1] += v;
      } else if(b == 3){
        k3[f - 1][r - 1] += v;
      } else {
        k4[f - 1][r - 1] += v;
      }
    }

    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 10; j++){
        System.out.print(" " + k1[i][j]);
      }
      System.out.println();
    }

    for(int i = 0; i < 20; i++){
      System.out.print("#");
    }

    System.out.println();

    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 10; j++){
        System.out.print(" " + k2[i][j]);
      }
      System.out.println();
    }

    for(int i = 0; i < 20; i++){
      System.out.print("#");
    }

    System.out.println();

    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 10; j++){
        System.out.print(" " + k3[i][j]);
      }
      System.out.println();
    }

    for(int i = 0; i < 20; i++){
      System.out.print("#");
    }

    System.out.println();

    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 10; j++){
        System.out.print(" " + k4[i][j]);
      }
      System.out.println();
    }
  }
}



Measured memory_bytes: 29564
/*
  AOJ 2546
  Title:Chocolate
  @kankichi573
  14/04/27 RE 4/43
  14/04/27 WA 34/43
*/
#include <stdio.h>

int M,N;
int choco[100][100];

void invert(int ch[],int x)
{
  ch[x]=(1-ch[x]);
}
void inv_row(int ch[])
{
  int i;
  for(i=0;i<N;i++)
    ch[i]=1-ch[i];
}
int solve(int ch[100])
{
  int i,j,cnt,cntz;
  
  if(N==1)
    return(ch[0]);
  else if(N==2)
    {
    if(ch[1]+ch[0]==1)
      return(2);
    else
      return(1);
    }
  cnt=ch[0]+ch[N-1];
  for(i=1,cntz=0;i<N-1;i++)
    cntz += (1-ch[i]);
  
  if(cnt==0)
    return(1+cntz);
  else if(cnt==1)
    return(2+cntz);
  else if(cntz==N-2)
    return(1+cntz);
  else
    return(3+cntz);
}

main()
{
  int i,j,ret;
  scanf("%d %d",&M,&N);
  for(i=0;i<M;i++)
    for(j=0;j<N;j++)
      scanf("%d",&choco[i][j]);
  ret=0;
  for(i=0;i<M;i++)
    {
      if(i>0)
	inv_row(&choco[i][0]);
      ret+=solve(&choco[i][0]);
    }
  printf("%d\n",ret);
  return(0);
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, A, B;
  cin >> N >> A >> B;
  vector<ll> V(N);
  for (int i = 0; i < N; i++)
    cin >> V[i];
  sort(V.begin(), V.end(), greater<ll>());

  vector<vector<ll>> comb(N + 1, vector<ll>(N + 1, 0));
  comb[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      comb[i][j] += comb[i - 1][j];
      if (j > 0) comb[i][j] += comb[i - 1][j - 1];
    }
  }

  double max_average = 0.0;
  for (int i = 0; i < A; i++)
    max_average += V[i];
  max_average /= A;

  ll res = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (V[i] == V[A - 1]) cnt++;
  }

  if (V[0] == V[A - 1]) {
    for (int i = A; i <= B; i++)
      res += comb[cnt][i];
  } else {
    int a = 0;
    for (int i = 0; i < A; i++) {
      if (V[i] == V[A - 1]) a++;
    }
    res = comb[cnt][a];
  }

  cout << fixed << setprecision(6) << max_average << '\n';
  cout << res << '\n';

  return 0;
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
int m;

int main(){
  cin >>n>>m;
  int a = (n-m)*100+m*1900;
  cout << a * pow(2,m) << endl;
}


Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
main(){
  char fie[4][4];
  string s;
  while(cin >> s){
    for(int i=0;i<3;i++)
      for(int j=0;j<3;j++) fie[j][i]=s[j+i*3];
   
    char res='d';
    for(int i=0;i<3;i++){
      char a = fie[0][i];
      bool f=true;
      for(int j=1;j<3;j++){
	if(a != fie[j][i]) f=false;
      }
      if(f && a!='s')
	res=a;
    }
    
    for(int i=0;i<3;i++){
      char a = fie[i][0];
      bool f=true;
      for(int j=1;j<3;j++){
	if(a != fie[i][j]) f=false;
      }
      if(f && a!='s')
	res=a;
    }
  
    if( fie[0][0]==fie[1][1] && fie[1][1]== fie[2][2] && fie[0][0]!='s')
      res = fie[0][0];
    if( fie[2][0]==fie[1][1] && fie[1][1]== fie[0][2] && fie[2][0]!='s')
      res = fie[2][0];
    
    printf("%c\n",res);
  }
			   
}

Measured memory_bytes: 1176
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ga, sa, ba;
    cin >> ga >> sa >> ba;
    ll gb, sb, bb;
    cin >> gb >> sb >> bb;
    if(sa < sb){ swap(ga, sa); swap(gb, sb); }
    if(ba < bb){ swap(ga, ba); swap(gb, bb); }
    if(ba < bb){ swap(ba, sa); swap(bb, sb); }
    ll ans = 0;
    if((ga < gb && sa < sb && ba < bb) || (ga >= gb && sa >= sb && ba >= bb)){
        if(ga >= gb){
            swap(ga, gb);
            swap(sa, sb);
            swap(ba, bb);
        }
        int ie = n / ga;
        for(ll i = 0; i <= ie; i++){
            int rem = n - i * ga;
            int je = rem / sa;
            for(int j = 0; j <= je; j++){
                int rem2 = rem - j * sa;
                int k = rem2 / ba;
                int rem3 = rem2 - k * ba;
                ll cand = i * gb + j * sb + k * bb + rem3;
                ans = max(ans, cand);
            }
        }
    }else if(ga < gb && sa < sb){
        int ie = n / ga;
        for(int i = 0; i <= ie; i++){
            int rem = n - i * ga;
            int je = rem / sa;
            for(int j = 0; j <= je; j++){
                int rem2 = rem - j * sa;
                int n2 = i * gb + j * sb + rem2;
                int k = n2 / bb;
                int rem3 = n2 - k * bb;
                ll cand = (ll)k * ba + rem3;
                ans = max(ans, cand);
            }
        }
    }else if(ga < gb){
        int ie = n / ga;
        for(int i = ie; i <= ie; i++){
            int rem = n - i * ga;
            int n2 = i * gb + rem;
            int je = n2 / sb;
            for(int j = 0; j <= je; j++){
                int rem2 = n2 - j * sb;
                int k = rem2 / bb;
                int rem3 = rem2 - k * bb;
                ll cand = (ll)j * sa + (ll)k * ba + rem3;
                ans = max(ans, cand);
            }
        }
    }else{
        return 1;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        if (scanner.hasNextLine()) {
            String[] array = scanner.nextLine().split(" ");
            int A = Integer.parseInt(array[0]);
            int B = Integer.parseInt(array[1]);
            int X = Integer.parseInt(array[2]);

            if (A <= X && X <= A + B) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 25300
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ab = [math.fabs(x[i]-y[i]) for i in range(n)]
p_1, p_2, p_3 = 0, 0, 0
for i in range(n):
    p_1 += ab[i]
for i in range(n):
    p_2 += ab[i]**2
p_2 = math.sqrt(p_2)
for i in range(n):
    p_3 += ab[i]**3
p_3 = p_3**(1/3)
p_inf = max(ab)
print(p_1)
print(p_2)
print(p_3)
print(p_inf)


Measured memory_bytes: 5720
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
LL ans[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int h, w;
	scanf("%d%d", &h, &w);
	map<pair<int, int>, int> mc;
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		mc[{x, y}] = 1;
		for (int i = 0; i < 3 && x - i >= 1; i++)
		{
			for (int j = 0; j < 3 && y - j >= 1; j++)
			{
				mc[{x - i, y - j}];
			}
		}
	}
	ans[0] = 1LL * (h - 2) * (w - 2);
	for (auto& p : mc)
	{
		int x, y;
		tie(x, y) = p.first;
		if (x + 1 >= h || y + 1 >= w) continue;
		int tot = 0;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				if (mc.count(make_pair(x + i, y + j)))
					tot += mc[{x + i, y + j}] != 0;
			}
		}
		ans[tot]++;
	}
	for (int i = 1; i <= 9; i++) ans[0] -= ans[i];
	for (int i = 0; i <= 9; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 56448
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define ll long long int

using namespace std;

bool a[10][10000] , b[10][10000];

int main(void) {
    int c,r;
    while (cin>>r>>c && r>0){
        REP(i,r){
            REP(j,c){
                cin >> a[i][j];
            }
        }
        int ans = 0;
        REP(d,1<<r){
            int e=d;
            REP(i,r){
                if (e%2==0){
                    REP(j,c) b[i][j] = a[i][j];
                }else{
                    REP(j,c) b[i][j] = a[i][j]^1;
                }
                e/=2;
            }
            int s=0;
            REP(j,c){
                int omote=0,ura=0;
                REP(i,r){
                    if(b[i][j]) omote++;
                    else ura++;
                }
                s+=max(omote,ura);
            }
            ans=max(ans,s);
        }
        cout << ans << endl;
        
        
    }
    return 0;
}

Measured memory_bytes: 1356
extern crate core;

use std::cmp::{max, min};
use std::collections::HashMap;
use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    let mut r = 10000000;
    for x in divisor(n) {
        r = min(r, max(f(x), f(n / x)));
    }
    r.to_string()
}

fn f(n: i64) -> i64 {
    n.to_string().len() as i64
}

fn divisor(n: i64) -> Vec<i64> {
    let mut res = Vec::new();
    for i in (1..).take_while(|x| x * x <= n) {
        if n % i == 0 {
            res.push(i);
            if i != n / i {
                res.push(n / i);
            }
        }
    }
    res
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "10000" => "3",
    test2: "1000003" => "7",
    test3: "9876543210" => "6",
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
    int i, j, k;
    int n, x;
    int count;

    while(1){
        scanf("%d %d ", &n, &x);
        if(n==0&&x==0)break;
        count=0;
        for(i=1;3*i+3<=x;i++){
            for(j=i+1;i+2*j+1<=x;j++){
                for(k=n;k>j;k--){
                    if(x==i+j+k){
                        count++;
                        break;
                    }else if(x>=i+j+k){
                        break;
                    }
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}


Measured memory_bytes: 2144
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */


#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BGoToJail {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<bool> v(n);
      rep(i, n) {
        int a, b; cin >> a >> b;
        v[i] = (a == b);
      }
      for(int i=0; i+2<n; i++) {
        if (v[i] && v[i+1] && v[i+2]) {
          cout << "Yes" << endl;
          return;
        }
      }
      cout << "No" << endl;
      return;

    }
};

signed main() {
  BGoToJail solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
typedef long long ll;
ll N,M,u,v,s,A[100010],B[100010],inf = INT_MAX,x = inf;
bool judge = true;
vector<vector<pair<int,int>>> e(100010);

void dfs(int n){
	for(int i=0;i<e[n].size();i++){
		int m = e[n][i].first,t = e[n][i].second;
		if(A[m]==inf){
			A[m] = -A[n];
			B[m] = t-B[n];
			dfs(m);
		}else{
			if(x==inf){
				ll delb = t-B[n]-B[m],dela = A[n]+A[m];
				if(dela==0 && delb!=0) judge = false;
				if(dela!=0 && delb%dela!=0) judge = false;
				else if(dela!=0) x = delb/dela;
			}else{
				if(A[n]*x+B[n]+A[m]*x+B[m]!=t) judge = false;
			}
		}
	}
}

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> u >> v >> s;
		e[u].push_back({v,s});
		e[v].push_back({u,s});
	}
	for(int i=1;i<=N;i++){
		A[i] = inf;
		B[i] = inf;
	}
	A[1] = 1; B[1] = 0;
	dfs(1);
	if(!judge){
		cout << 0 << endl;
		return 0;
	}else if(x!=inf){
		for(int i=1;i<=N;i++){
			if(A[i]*x+B[i]<=0){
				cout << 0 << endl;
				return 0;
			}
		}
		cout << 1 << endl;
		return 0;
	}
	ll l = -inf,r = inf;
	for(int i=1;i<=N;i++){
		if(A[i]>0) l = max(l,-B[i]+1);
		else if(A[i]<0) r = min(r,B[i]-1); 
	}
	if(l<=0) l = 1;
	cout << max((ll) 0,r-l+1) << endl;
	return 0;
}

Measured memory_bytes: 10368
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int  n, s=1, p=pow(10,18) ; 
    bool flag=false;
    cin >> n ; 
    int a[n];
    for (int i=0;i<n;i++) cin >> a[i] ; 
    sort(a,a+n) ; 
    int i=0;
    while (i<n){
        if ( a[i]>0 and s>0 and (p/a[i] < s) ) {
            cout << -1 << endl;
            return ; 
        }
        s *= a[i];
        i++;
    }
    cout << s <<endl;
    
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4384
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(b+c,a))
    return

#B
def B():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2:
            ans += 1
    print(ans)
    return

#C
def C():
    n = II()
    h = LI()
    h = h[::-1]
    for i in range(1, n):
        if h[i] <= h[i-1]:
            continue
        if h[i] == h[i - 1] + 1:
            h[i] -= 1
            continue
        print("No")
        return
    print("Yes")
    return

#D
def D():
    s = S()
    lens = len(s)
    ans = [0] * len(s)
    i = 0
    while i != len(s):
        for j in range(i, lens):
            if s[j] == "R":
                continue
            break
        R = j - i
        for i in range(j, lens):
            if s[i] == "L":
                continue
            break
        else:
            i += 1
        L = i - j
        ans[j] = R // 2 + (L+1) // 2
        ans[j - 1] = L // 2 + (R+1) // 2

    print(*ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 60016
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
struct node{
	int qz;
	int hz;
}n[300005];
char s[300005];
int main(){
	int a;
	int e, w;
	cin >> a;
		e = 0;
		w = 0;
		n[0].qz = 0;
		n[0].hz = 0;
		n[a - 1].qz = 0;
		n[a - 1].hz = 0;
		cin >> s;
		for(int i = 0; i < a; i++){
			if(s[i] == 'W'){
				n[i].qz = w;
				w++;
			}
			else{
				n[i].qz = w;
				e++;				
			}
		}
		w = 0;
		e = 0;
		for(int i = a - 1; i >= 0; i--){
			if(s[i] == 'W'){
				n[i].hz = e;
				w++;
			}
			else{
				n[i].hz = e;
				e++;
			}
		}
		int	min = 300005;
		for(int i = 0; i < a; i++){
			if((n[i].qz + n[i].hz) < min)
				min = (n[i].qz + n[i].hz);
		}
		cout << min << endl;
	//int x;
	//cin >> x;
return 0;
}

Measured memory_bytes: 2944
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let x: usize = read();
    let mut arr = vec![x];
    for _ in 0..n {
        arr.push(read());
    }
    arr.sort();
    let mut ans = arr[1] - arr[0];
    for i in 1..=n {
        ans = gcd(ans, arr[i] - arr[i - 1]);
    }
    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        return a;
    }
    return gcd(b, a % b);
}

Measured memory_bytes: 3160
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int N; cin>>N;
    string res = "";
    if (N==0) {
        cout<<0<<endl;
        return 0;
    }
    while (N!=0) {
        int next_N;
        if (N<0) {
            next_N = (1-N)/2;
        } else {
            next_N = -N/2;
        }
        res += '0'+N+2*next_N;
        N = next_N;
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

int D2[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	ll N = 0, K = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	while ((c = getchar_unlocked()) >= '0') K = K * 10 + c - '0';

	int A[200001];
	rep1(i, N) A[i] = getint();

	int d = 0;
	int p = 1;
	while (A[p] > 0) {
		D2[d] = p;
		int tugi = A[p];
		A[p] = -d++;
		p = tugi;
	}
	if (K > -A[p]) {
		ll k = K + A[p];
		k %= d + A[p];
		K = -A[p] + k;
	}
	printf("%d", D2[K]);

	Would you please return 0;
}

Measured memory_bytes: 3284
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        
        if (input < 0 || input > 86400) {
            System.err.println("Err!"); //標準エラー出力
            return;
        }
        int hour = input / 3600;
        int minutes = (input % 3600) / 60;
        int seconds = (input % 3600) % 60;
        
        System.out.printf("%d:%d:%d%n", hour, minutes, seconds);
    }

}

// 1時間 = 60分 = 3600秒

// 秒数を3600で割る→時間を算出

// 余った数字を60で割る→分を算出




Measured memory_bytes: 26292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;



int main(){
	/*****input*****/
	int A,B,M;
	cin >> A >> B >> M;
	int a[A],b[B];
	int x[M];
	int y[M];
	int c[M];

	int mina=INT_MAX;
	for(int i = 0; i<A; i++){
		cin >> a[i];
		mina = min(mina,a[i]);
	}
	int minb=INT_MAX;
	for(int i = 0; i<B; i++){
		cin >> b[i];
		minb = min(minb,b[i]);
	}
	for(int i = 0; i<M; i++){
		cin >> x[i] >> y[i] >> c[i];
	}

	/*****calc*****/
	int ans=mina+minb;
	for(int i = 0; i < M; i++){
		ans = min(ans,a[x[i]-1] + b[y[i]-1] - c[i]);
	}
	/*****ans*****/
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2176
D, G = gets.split.map(&:to_i)
pc_list = D.times.map { gets.split.map(&:to_i) }
MAX = 1 << 60
ans = MAX
(0...(2 ** D)).each do |bs|
  ret = (0...D).reduce([0, 0]) do |acc, d|
    if bs[d] == 0
      acc
    else
      # ボーナスを獲得する
      count = pc_list[d][0]
      bonus = pc_list[d][1]
      total_count = acc[0] + count
      total_point = acc[1] + ((d + 1) * 100 * count) + bonus
      [total_count, total_point]
    end
  end
  count = ret[0]
  point = ret[1]
  if point >= G
    ans = [ans, count].min
  else
    # 必要な点数に満たない
    rest_point = (G - point)
    d = (D - 1).downto(0).find do |d|
      bs[d] == 0
    end
    next unless d
    max_d_count = [pc_list[d][0] - 1, 0].max
    d_unit = ((d + 1) * 100)
    d_count = rest_point % d_unit == 0 ? rest_point / d_unit : rest_point / d_unit + 1
    if max_d_count >= d_count
      ans = [ans, count + d_count].min
    end
  end
end
puts ans


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int x, y;
    cin >> x >> y;
    cout << x + (y / 2) << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)
	d := a * b
	if d%2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
	// fmt.Println(d)
}


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    ll H, N;
    cin >> H >> N;
    vector<int> A(N);
    REP(i, N) { cin >> A[i]; }
    ll damage = accumulate(A.begin(), A.end(), 0);
    if (damage >= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int X = scanner.nextInt();
        int[] list = new int[N+1];
        for (int i = 0; i < M ; i++) {
            int l = scanner.nextInt();
            list[l] = 1;
        }

        int a = 0;
        for (int i = X; 0 <= i; i--) {
            a+= list[i];
        }
        int b = 0;
        for (int i = X; i < N; i++) {
            b+= list[i];
        }
        System.out.println(Math.min(a, b));
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () {
            s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21204