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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] S = new int[n];
        for (int i = 0; i < n; i++) {
            S[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int C = 0;
        for (int i = 0; i < q; i++) {
            int T = sc.nextInt();
            boolean answer = binarySearch(S, n, T);
            if (answer) C++;
        }
        System.out.println(C);
        sc.close();
    }
    public static boolean binarySearch(int[] S, int n, int T) {
        int left = 0;
        int right = n;
        while (left < right) {
            int mid = (left + right) / 2;
            if (S[mid] == T) return true;
            else if (T < S[mid]) right = mid;
            else left = mid + 1;
        }
        return false;
    }
}


Measured memory_bytes: 67396
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

vector<int> D(100);
int N;

bool isOK(int nax){
	set<int> used;
	rep(i,N){
		int pivot;
		if(D[i] == 0 && used.count(0) == 1)return false;
		if(used.count(D[i]) == 0)pivot = D[i];
		else if(used.count(24-D[i]) == 0)pivot = 24 - D[i];
		else return false;
		rep(k, nax){
			int up = (pivot + k) % 24;
			int dw = pivot - k; if(dw < 0)dw += 24;
			used.insert(up);
			used.insert(dw);
		}
	}
	return true;
}

int binary_search(){
	int ng = 27;
	int ok = 0;
	while(abs(ok-ng) > 1){
		int mid = (ok + ng)/2;
		if(isOK(mid))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
	cin >> N;
	D.resize(N+1);
	rep(i,N)cin >> D[i];
	D[N] = 0;
	sort(all(D));
	++N;
	cout << binary_search() << endl;
	return 0;
}


Measured memory_bytes: 3600
import collections

def answer(list,n):
    Even = collections.Counter(list[::2]).most_common(2)
    Odd = collections.Counter(list[1::2]).most_common(2)

    if Even[0][0] != Odd[0][0]:
        return n - Even[0][1] - Odd[0][1]
    else:
        if len(Even) == 1 or len(Odd) == 1:
            return n // 2
        else:
            return n - max(Even[0][1]+Odd[1][1],Even[1][1]+Odd[0][1])

N = int(input())
list = input().split(" ")
print(answer(list,N))


Measured memory_bytes: 16352
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

vector<int> X;
void input(){
    fast_io();
    X.assign(5,0);
    for (int i = 0; i < 5; i++)
    {
        cin >> X[i];
        if(X[i]==0) cout << (i+1) << endl;
    }
    
}

int solve(){
    return 0;
}   

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

Measured memory_bytes: 3560
N = int(input())

#26の倍数の辞書を保持する

a = 1
baisu = []
ruiseki = [26]

for i in range(11):
    a *= 26
    baisu.append(a)
    if i != 0:
        ruiseki.append(ruiseki[i-1]+a)

#何桁か  
length = 0
new_N = 0
f = True
for i,rui in enumerate(ruiseki):
    if N <= rui:
        length = i+1
        if i!=0:
            new_N = N-ruiseki[i-1]
        else:
            new_N = N
        f = False
        break
if f:
    new_N = N-ruiseki[-1]

# print(length)



# print(new_N)
# print(length)
# print(baisu)

ans = []
for i in range(length):
    u = 0
    cnt = 0
    while(1):
        if new_N <= 26 and i==length-1:
            ans.append(new_N-1)

            break
        pre_u = u
        u += baisu[length - i -2 ]
        if new_N <= u:
            ans.append(cnt)
            new_N -= pre_u
            break
        cnt += 1

alp = [chr(ord('a') + i) for i in range(26)]
ans_c = ""

# print(ans)
for an in ans:
    ans_c+=alp[an]
print(ans_c)




# while(1):
#     for bai in baisu:


# print(baisu)
# print(ruiseki)


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  bool rev = false;
  string fronts = "";
  string backs = "";
  REP(i,q) {
    int com;
    cin >> com;
    if(com == 1) {
      if(rev) rev = false;
      else rev = true;
    } else {
      int fb;
      char c;
      cin >> fb;
      cin >> c;
      if(fb == 1) {
        if(rev) {
          backs += c;
        } else {
          fronts = c + fronts;
        }
      } else {
        if(rev) {
          fronts = c + fronts;
        } else {
          backs += c;
        }
      }
    }
  }
  if(rev) {
    s = fronts + s + backs;
    reverse(ALL(s));
  } else {
    s = fronts + s + backs;
  }
  cout << s;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1360
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int MAP[100][100]={};
int a,b;
int ans=0;
void dfs(int x,int y){
  if(x==a&&y==b){
    ans++;
    return;
  }
  if(x+1>0&&x+1<=a&&!MAP[x+1][y])
    dfs(x+1,y);
  if(y+1>0&&y+1<=b&&!MAP[x][y+1])
    dfs(x,y+1);
}
int main(){
  while(cin>>a>>b,a+b){
    int n;
    for(int i=0;i<100;i++)
      for(int j=0;j<100;j++)
	MAP[i][j]=0;
    ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      MAP[x][y]=1;
    }
    dfs(1,1);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3052
open System
let N = int(Console.ReadLine())
let SP = [|for i in 1.. N do
  let tmp = (Console.ReadLine().Split(' '))
  yield (tmp.[0], - int (tmp.[1]), i)
|]

let sorted = Array.sort SP
let f (p : string * int * int) =
    let _, _, i = p
    Console.WriteLine i
Array.iter f sorted

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
// const ll MOD = 1e9+7;
const ll MOD = 998244353;
const ll LINF = 1e18;

// https://betrue12.hateblo.jp/entry/2019/04/21/150214

const ll maxj=300*300+5;
ll dp1[305][maxj];
ll dp2[305][maxj];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll  a(n);
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  
  dp1[0][0]=dp2[0][0]=1;
  rep(i,n){
    rep(j,maxj){
      (dp1[i+1][j+a[i]]+=dp1[i][j])%=MOD;
      (dp1[i+1][j]+=(dp1[i][j]*2)%MOD)%=MOD;
      (dp2[i+1][j+a[i]]+=dp2[i][j])%=MOD;
      (dp2[i+1][j]+=dp2[i][j])%=MOD;
    }
  }
  
  ll ng=0;
  irep(j,(sum+1)/2,maxj){
    (ng+=dp1[n][j])%=MOD;
  }
  if(sum%2==0){
    (ng+=MOD-dp2[n][sum/2])%=MOD;
  }
  (ng*=3)%=MOD;
  
  ll ans=1;
  rep(i,n) (ans*=3)%=MOD;
  (ans+=MOD-ng)%=MOD;
  cout<<ans<<endl;
}

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

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


	String[] a, b;
	String from, go;
	int MAX = 99999999;
	void solve(){

		Scanner cin = new Scanner(System.in);

		while(true)
		{
			int n = cin.nextInt();
			if(n==0) return;
			a = new String[n];
			b = new String[n];
			for(int i=0;i<n;i++){
				a[i] = cin.next();
				b[i] = cin.next();
			}
			from = cin.next();
			go = cin.next();
			hm = new HashMap<String, Integer>();
			int ret = dfs(from);
			if(ret < MAX) System.out.println(dfs(from));
			else System.out.println(-1);
		}
	}

	HashMap<String, Integer> hm;

	int dfs(String now){
		int ret = MAX;
		if(hm.containsKey(now)) return hm.get(now);
		if(now.length()>=go.length()){
			if(now.equals(go)) return 0;
			else return MAX;
		}
		for(int i = 0; i < a.length;i++){
			String next = sed(now, a[i], b[i]);
			if(now.equals(next)) continue;
			ret = Math.min(dfs(next) + 1 , ret);
		}

		hm.put(now, ret);
		return ret;
	}

	String sed(String now, String from, String to){
		String ret = "";
		for(int i=0;i<now.length();i++){
			if(i<now.length()-from.length()+1 && now.subSequence(i, i + from.length()).equals(from)){
				ret += to;
				i += from.length()-1;
			}
			else ret += now.charAt(i);
		}
		return ret;
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
using namespace std;
int s[55];
int main()
{
   int a,b;
   while(scanf("%d%d",&a,&b)==2)
   {
      for(int i=0;i<a;i++)
         scanf("%d",&s[i]);
      sort(s,s+a);
      int sum=0;
      for(int i=a-1;i>=a-1-b+1;i--)
         sum+=s[i];
         cout<<sum<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
// Mujin Programming Challenge 2017
#include <bits/stdc++.h>
//#include "testlib.h"
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define se second
#define fi first
#define prout(x) cout.precision(x)
using namespace std;
ll a[100010];
vector<ll>v;
int main(){
    int n;
    cin>>n;
    ll c=1;
    ll ans=1;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]<c){
            c=a[i]+1;
            if(v.size()==0)ans=i;
            else ans*=(i-v.size());
            v.pb(i);
            ans=ans%mod;
            continue;
        }
        if(a[i]==a[i-1]+1)a[i]=max(a[i], c);
        else a[i]=c;
        c=a[i]+2;
    }
    if(v.size()==0){
        for(ll i=1;i<=n;i++){
            ans=ans*i;
            ans=ans%mod;
        }
        cout<<ans<<endl;
        return 0;
    }
    for(ll i=n-v.size();i>=1;i--){
        ans=ans*i;
        ans=ans%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1528
#include <iostream>
#include <cassert>

class UnionFind {
#define MAX_V 10001

private:

  int parent[MAX_V];
  int rank[MAX_V];
  int V;
  
public:  
  
  UnionFind(int V): V(V) {
    if (V >= MAX_V) {
      assert(false);
    }
    for (int i = 0; i < V; i++) {
      parent[i] = i;
      rank[i]   = 0;
    }
  }

  int find(int x) {
    if (parent[x] == x) {
      return x;
    }
    return parent[x] = find(parent[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) {
      return;
    }

    if (rank[x] < rank[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      if (rank[x] == rank[y]) {
        rank[x]++;
      }
    }
  }
};

using namespace std;

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

  UnionFind uf(n);

  for (int i = 0; i < q; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0) {
      uf.unite(b, c);
    } else {
      if (uf.find(b) == uf.find(c)) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3176
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
if len(c) > 3:
    print('No')
else:
    if len(c) == 1 and c.get(0):
        print('Yes')
    elif len(c) == 2 and c.get(0) == n / 3:
        print('Yes')
    elif len(c) == 3:
        x, y, z = c.keys()
        if x^y^z == 0 and c.get(x) == c.get(y) == c.get(z) == n / 3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')


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

void swap(long long int *a, long long int *b){
	if(*a != *b){
		*a ^= *b;
		*b ^= *a;
		*a ^= *b;
	}
}

int main() {
	long long int n, xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3, d1, d2, d3, d4;
	
	cin >> n;
	for(int i=0;i<n;++i){
		cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;
		d1 = (yp2 - yp0)*(xp1 - xp0) - (xp2 - xp0)*(yp1 - yp0);
		d2 = (yp3 - yp0)*(xp1 - xp0) - (xp3 - xp0)*(yp1 - yp0);
		d3 = (yp0 - yp2)*(xp3 - xp2) - (xp0 - xp2)*(yp3 - yp2);
		d4 = (yp1 - yp2)*(xp3 - xp2) - (xp1 - xp2)*(yp3 - yp2);
		
		if( d1 == 0 && d2 == 0){
			if(xp0 != xp1){//not parallel with y axis
				if(xp0 > xp1)swap(&xp0, &xp1);
				if(xp2 > xp3)swap(&xp2, &xp3);
				
				if(xp0 <= xp3 && xp1 >= xp2){
					cout << 1 << endl;
				}else{
					cout << 0 << endl;
				}
			}else{//parallel with y axis
				if(yp0 > yp1)swap(&yp0, &yp1);
				if(yp2 > yp3)swap(&yp2, &yp3);
				
				if(yp0 <= yp3 && yp1 >= yp2){
					cout << 1 << endl;
				}else{
					cout << 0 << endl;
				}
			}
		}else if( d1 * d2 <= 0 && d3 * d4 <= 0){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input


class Edge:
    def __init__(self, dst, weight):
        self.dst, self.weight = dst, weight

    def __lt__(self, e):
        return self.weight > e.weight


class Graph:
    def __init__(self, V):
        self.V = V
        self.E = [[] for _ in range(V)]

    def add_edge(self, src, dst, weight):
        self.E[src].append(Edge(dst, weight))


class HeavyLightDecomposition:
    def __init__(self, g, root=0):
        self.g = g
        self.vid, self.head, self.heavy, self.parent = [0] * g.V, [-1] * g.V, [-1] * g.V, [-1] * g.V
        self.dfs(root)
        self.bfs(root)

    def dfs(self, root):
        stack = [(root, -1, False)]
        sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V
        while stack:
            v, par, flag = stack.pop()
            if not flag:
                self.parent[v] = par
                stack.append((v, par, True))
                stack.extend((e.dst, v, False) for e in self.g.E[v] if e.dst != par)
            else:
                if par != -1:
                    sub[par] += sub[v]
                    max_sub[par] = max(max_sub[par], (sub[v], v))
                self.heavy[v] = max_sub[v][1]

    def bfs(self, root=0):
        from collections import deque
        k, que = 0, deque([root])
        while que:
            r = v = que.popleft()
            while v != -1:
                self.vid[v], self.head[v] = k, r
                for e in self.g.E[v]:
                    if e.dst != self.parent[v] and e.dst != self.heavy[v]:
                        que.append(e.dst)
                k += 1
                v = self.heavy[v]

    def lca(self, u, v):
        while self.head[u] != self.head[v]:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
            v = self.parent[self.head[v]]
        else:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
        return u

N = int(input())
g = Graph(N)
for i in range(N):
    for c in map(int, input().split()[1:]):
        g.add_edge(i, c, 1)
        g.add_edge(c, i, 1)
hld = HeavyLightDecomposition(g)
Q = int(input())
for _ in range(Q):
    u, v = map(int, input().split())
    print(hld.lca(u, v))

Measured memory_bytes: 73588
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    ll L[110];
    rep(i,0,N) cin >> L[i];
    sort(L, L+N);
    ll ans = 0;
    rep(i,0,N){
        rep(j,i+1,N){
            rep(k,j+1,N){
                if(L[i] == L[j] || L[j] == L[k] || L[i] == L[k]) continue;
                if(L[k] < L[i] + L[j]) ans++;

            }
        }
    }
    print(ans);

}

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

Measured memory_bytes: 3652
#include<stdio.h>

int main(void){
  char str[3][10];
  int i,j,k;
  for(i=0;i<3;i++) scanf("%s%*c",str[i]);
  for(i=0;i<3;i++) putchar(str[i][i]);
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
         if (n & 1) res = res * a % MOD;
         a= a * a % MOD;//次の準備
         n >>= 1;
      }
 return res;
}
ll waru(ll a,ll b){
    return a*modpow(b,MOD-2)%MOD;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n,m;cin>>n>>m;
    ll ans=0;
    ans+=min(n,m/2);
    m-=2*ans;
    
    ans+=m/4;
    
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 256
N, M = map(int, input().split())
lamps = []
for i in range(0, M):
	inpt = list(map(int, input().split()))
	lamps.append(list(map(lambda v: v-1, inpt[1:])))
onoff = list(map(int, input().split()))
cnt = 0
for i in range(0, 2**N):
	m = i
	drived = []
	for j in range(0, M):
		drived.append(0)
	for j in range(0, N):
		if m % 2 == 1:
			for k in range(0, M):
				if j in lamps[k]:
					drived[k] += 1
		m //= 2
	flag = True
	for j in range(0, M):
		if onoff[j] != drived[j]%2:
			flag = False
			break
	if flag:
		cnt += 1
print(cnt)

Measured memory_bytes: 43120
#include <stdio.h>

int main()
{
	int i, N, W, w[101], v[101];
	scanf("%d %d", &N, &W);
	for (i = 1; i <= N; i++) scanf("%d %d", &(w[i]), &(v[i]));

	int j;
	long long dp[100001] = {}, max = 0;
	for (i = 1; i <= N; i++) {
		for (j = W; j >= w[i]; j--) if (dp[j-w[i]] + v[i] > dp[j]) dp[j] = dp[j-w[i]] + v[i];
	}
	for (j = 0; j <= W; j++) if (dp[j] > max) max = dp[j];
	printf("%lld\n", max);
	fflush(stdout);
	return 0;
}

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

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

  for(int i = 1; i <=b; i++) {
    if(i*a % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


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

bitdp = [[0 for j in range(w)] for i in range(h)]
al = []
bl = []
for _ in range(h):
   a = list(map(int,input().split()))
   al.append(a)
for _ in range(h):
   b = list(map(int,input().split()))
   bl.append(b)
abl = [[] for i in range(h)]
for i in range(h):
   for j in range(w):
      abl[i].append(abs(al[i][j] - bl[i][j]))

bitdp[0][0] = 1 << h*w+abl[0][0]
for i in range(h):
   for j in range(w):
      if j != w-1:
         bitdp[i][j+1] |= bitdp[i][j] << abl[i][j+1] | bitdp[i][j] >> abl[i][j+1]
      if i != h-1:
         bitdp[i+1][j] |= bitdp[i][j] << abl[i+1][j] | bitdp[i][j] >> abl[i+1][j]

ans = []
for i in range(h*w*2+1):
   if (bitdp[-1][-1] >> i & 1):
      ans.append(abs(h*w-i))

print(min(ans))

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

const int DIM = 3005;
const int MOD = 1000000007;

int dp[2][DIM][2];

inline void f(int &a, int b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
}

int main(void)
{
    int n, m;
    cin >> n >> m;
    
    for (int i = 0; i <= n; ++i)
        dp[0][i][i == 0] = 1;
    
    for (int j = 0, l = 0; j < m; ++j, l ^= 1) {
        memset(dp[l ^ 1], 0, sizeof dp[l ^ 1]);
        
        for (int i = 0; i <= n; ++i) {
            if (i != 0) {
                f(dp[l ^ 1][i][(i - 1) == 0], dp[l][i][0]);
                f(dp[l ^ 1][i][1], dp[l][i][1]);
                
                f(dp[l ^ 1][i - 1][(i - 1) == 0], dp[l][i][0]);
                f(dp[l ^ 1][i - 1][1], dp[l][i][1]);
            }
            
            if (i != n) {
                f(dp[l ^ 1][i][0], dp[l][i][0]);
                f(dp[l ^ 1][i][1], dp[l][i][1]);
                
                f(dp[l ^ 1][i + 1][0], dp[l][i][0]);
                f(dp[l ^ 1][i + 1][1], dp[l][i][1]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i <= n; ++i)
        f(ans, dp[m & 1][i][1]);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define MAX 100
int main(void){
  int i, j, k, n, temp, d[MAX];
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &d[i]);
  }

  for(i = 0; i < n; i++){
    if(i > 0){
      printf(" ");
    }
    printf("%d", d[i]);
  }
  printf("\n");

  for(i = 1; i <= n - 1; i++){
    temp = d[i];
    j = i - 1;
    while(j >= 0 && d[j] > temp){
      d[j + 1] = d[j];
      j--;
    }
    d[j + 1] = temp;

    for(k = 0; k < n; k++){
      if(k > 0){
        printf(" ");
      }
      printf("%d", d[k]);
    }
    printf("\n");
  }


  return 0;
}

Measured memory_bytes: 604
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */


template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 1000100010010010;
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


/* main */
template<typename T>
auto cut(T &a, int l, int r){
    //get a[l:r]
    return T(a.begin()+l, a.begin()+r);   
}

int n;
vec<double> arr(3100);
double dp[3100][3100];

double dfs(int i, int cnt){

	if(i == n){
		if(cnt > n - cnt){
			return 1;
		}else{
			return 0;
		}
	}

	if(dp[i][cnt] > -1) return dp[i][cnt];

	double ans = 0.0;
	ans += arr[i] * dfs(i + 1, cnt + 1);
	ans += ((1 - arr[i]) * dfs(i + 1, cnt));

	return dp[i][cnt] = ans;

}


signed main(){


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

	cin >> n;
	rep(i,0,n) cin >> arr[i];

	memset(dp, -1, sizeof(dp));

	printf("%0.9f\n", dfs(0, 0));


	
	

	



	
	


	




	




    



	








    



    





    


    

}



Measured memory_bytes: 75520
#include <stdio.h>

int main(){
    int a, b, w, answer;
    scanf("%d %d %d", &w, &a, &b);
    if((a < b && b < a + w) || (a < b + w && b < a) || (a == b)){
        printf("0\n");
    }else if(a < b){
        answer = b - a - w;
        printf("%d\n", answer);
    }else{
        answer = a - b - w;
        printf("%d\n", answer);
    }
    return 0;
}

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

int main(){
	int S;
	int h, m, s;
	cin >> S;
	
	h = S / 3600;
	S = S % 3600;
	m = S / 60;
	s = S % 60;
	
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    long sum = 0;
    for(long bits = 0; bits < (1 <<(S.size() - 1)); ++bits){
        long sum1 = 0;
        string tmp = S;
        long size = tmp.size();
        for(long i = 0; i < S.size() - 1; ++i){
            if(bits & (1<<i)){
                tmp.insert(size - 1 - i, "+");
            }
        }
      
        long sum2 = 0;
        for(long i = 0; i < tmp.size(); i++){
            if(!(tmp[i] == '+')){
                sum2 = sum2 * 10 + (tmp[i] - '0');
            }else{
                sum1 += sum2;
                sum2 = 0;
            }
        }
     
        sum += sum2;
        sum += sum1;
    }
    cout << sum << endl;
} 
//オーバーロードされた関数 "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert [代入_CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" のインスタンスが引数リストと一致しません -- 引数の型: (long, char) -- オブジェクト型は std::string です

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

const int INF=1001001001001001001ll;

int H,W;
int N;

vpint G[222222];
int val[222222];

signed main(){
    cin>>H>>W;
    cin>>N;
    rep(i,N){
        int h,w,a;cin>>h>>w>>a;
        h--;w--;
        G[h].pb({w+H,a});
        G[w+H].pb({h,a});
    }
    fill_n(val,222222,INF);

    rep(i,H+W){
        if(val[i]!=INF)continue;
        val[i]=0;
        queue<int>que;
        que.push(i);


        int mih=INF,miw=INF;

        while(que.size()){
            int v=que.front();
            que.pop();
            if(v<H)chmin(mih,val[v]);
            else chmin(miw,val[v]);
            for(auto &e:G[v]){
                int tmp=e.se-val[v];
                if(val[e.fi]==INF){
                    val[e.fi]=tmp;
                    que.push(e.fi);
                }
                else if(val[e.fi]!=tmp){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        if(mih+miw<0){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 13440
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    vector<int> road(n, 0);
    REP(i, m){
        int a, b; cin >> a >> b;
        ++road[a-1]; ++road[b-1];
    }
    REP(i, n) cout << road[i] << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
typedef long long ll;
int main(){
  int N; cin>>N;
  multiset<int> A;
  int mx = 0;
  rep(i,N) {
    int v; cin>>v;
    A.insert(v);
    mx = max(mx,v);
  }
  vector<ll> B;
  ll a = 1;
  B.push_back(a);
  while(a<=2*mx)
    B.push_back(a*=2);
  int ans = 0;
  while(!A.empty()){
    auto itr = A.end(); itr--;
    ll t = *upper_bound(B.begin(),B.end(),*itr);
    ll dif = t - *itr;
    auto itrr = A.find(dif);
    if(itrr!=itr && itrr!=A.end()) {
      ans++;
      A.erase(itrr);
    }
    A.erase(itr);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
  ll N,a[101];
  cin>>N;
  rep(i,N) cin>>a[i];
  sort(a,a+N);
  p(a[N-1]-a[0]);

}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
using P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int n,c;
int x[101010],v[101010];
int A[101010],B[101010];
int C[101010],D[101010];
int antime[101010];

int calc(){
  A[0] = v[0];
  rep(i,1,n) A[i] = A[i-1] + v[i];  
  
  B[n-1] = v[n-1];
  rrep(i,n-2,0) B[i] = B[i+1] + v[i];

  rep(i,0,n) C[i] = c - x[i];

  D[n-1] = B[n-1] - C[n-1];
  rrep(i,n-2,0){
    D[i] = B[i] - C[i];
    chmax(D[i],D[i+1]);
  }

  int ans = 0;
  rep(i,0,n){
    int sm = 0;
    
    sm -= x[i];
    sm += A[i];
    chmax(ans,sm);

    sm -= x[i];
    
    if(i < n-1) sm += D[i+1];

    chmax(ans,sm);
  }
  return ans;
}

signed main(){
  cin >> n >> c;
  rep(i,0,n){
    cin >> x[i] >> v[i];
  }
  int ans = 0;

  chmax(ans,calc());

  reverse(v,v+n);
  rep(i,0,n) x[i] = c - x[i];
  reverse(x,x+n);

  chmax(ans,calc());

  cout << ans << endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=998244353;
ll modpow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll N;
ll A,B,C,D;
ll dp[3010][3010]={};
int main(){
    cin>>A>>B>>C>>D;
    dp[A][B]=1;
    for(ll i=A;i<=C;i++){
        for(ll j=B;j<=D;j++){
            if(i>A && j>B){
                ll minus = dp[i-1][j-1]*(i-1)%MOD*(j-1)%MOD;
                dp[i][j]=(dp[i][j] - minus +MOD)%MOD;
            }
            dp[i+1][j]=(dp[i+1][j] +dp[i][j]*j%MOD )%MOD;
            dp[i][j+1]=(dp[i][j+1] +dp[i][j]*i%MOD )%MOD;
        }
    }
    cout<<dp[C][D]<<endl;
    return 0;
}

Measured memory_bytes: 73956
#include<bits/stdc++.h>
#include<string>
#include<math.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<c-(d-b)<<' '<<d+(c-a)<<' '<<a-(d-b)<<' '<<b+(c-a)<<endl;
}



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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define int ll
int N;
string X;

ll qexp(ll x, ll y,int MOD) { 
ll res = 1; 
while (y > 0){
if (y & 1){
res = res*x; 
			res %= MOD;
        		}
        		y = y>>1;
        		x = x*x; 
        		x %= MOD;
} 
    return res; 
}

int32_t main(){
	fast;
	
	cin>>N>>X;
	
	int popc = 0;
	aFOR(i,X) if (i == '1') popc++;
	
		
	int numm = 0, nump = 0;
	FOR(i,0,N-1){
		if (X[i] == '1' && popc > 1){
			numm += qexp(2,N - i - 1,popc-1);
			numm %= popc-1;
		}
	}
	
	FOR(i,0,N-1){
		if (X[i] == '1'){
			nump += qexp(2,N - i - 1,popc+1);
			nump %= popc+1;
		}
	}
	
	
	FOR(i,0,N-1){
		int curnum;
		if (X[i] == '1'){
			if (popc == 1){
				cout<<0<<'\n';
				continue;
			}
			curnum = numm + popc - 1 - qexp(2,N - i - 1,popc-1);
			curnum %= popc - 1;
			while (curnum < 0) curnum += popc - 1;
		}else{
			curnum = nump + qexp(2,N - i - 1,popc+1);
			curnum %= popc + 1;
		}
		
		int ans = 1;
		while (curnum > 0){
			int curpopc = __builtin_popcountll(curnum);
			//FOR(j,0,50) if ((1LL << j) & curnum) curpopc++;
			curnum %= curpopc;
			ans++;
		}
		cout<<ans<<'\n';
	}
		
}



Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=2019;
int main(void){
    // Your code here!
    ll l,r;
    cin>>l>>r;
    if(r-l>2019){
        cout<<0<<endl;
        return 0;
    }
    ll ans=3000;
    rep(l,i,r+1){
        rep(i+1,j,r+1)ans=min(i*j%mod,ans);
    }
    cout<<ans;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    string s; cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String result = "WA";
		if("A".equals(S.substring(0,1)) &&
				(S.substring(1,2).toLowerCase()).equals(S.substring(1,2)) &&
				(S.substring(S.length()-1)).toLowerCase().equals(S.substring(S.length()-1))) {
			for(int i = 2; i < S.length()-1; i++) {
				if("C".equals(S.substring(i,i+1))) {
					if("WA".equals(result)) {
						result = "AC";
					}else {
						result = "WA";
						break;
					}
				}else if(!(S.substring(i,i+1).toLowerCase()).equals(S.substring(i,i+1))) {
					result = "WA";
					break;
				}
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 27008
n=int(input())
b = list(map(int,input().split()))
a = [0] * n
ans = 0
for i in range(n):
  if i == 0:
    ans += b[i]
  elif i == n -1:
    ans += b[i - 1]
  else:
    ans += min(b[i - 1],b[i])
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
std::vector<int> dparttobinary(double n){
	std::vector<int> vec;
	while(n != 0){
		n *= 2;
		int ipart = (int)n;
		vec.push_back(ipart);
		n = n - (double)ipart;
	}
	return vec;
}

std::vector<int> iparttobinary(int n){
	std::vector<int> vec;
	while(n != 0){
		vec.push_back(n % 2);
		n /= 2;
	}
	std::reverse(vec.begin(), vec.end());
	return vec;
}

int main(){
	double n;
	while(std::cin >> n, n > 0){
		int ipart = (int)n;
		double dpart = n - (double)ipart;
		std::vector<int> dvec = dparttobinary(dpart),
			ivec = iparttobinary(ipart);
	
		if(dvec.size() <= 4 && ivec.size() <= 8){
			for(int i=8-ivec.size();i;i--)
				std::cout << "0";
			for(int i=0;i<ivec.size();i++)
				std::cout << ivec[i];
			std::cout << ".";
			for(int i=0;i<dvec.size();i++)
				std::cout << dvec[i];
			for(int i=4-dvec.size();i;i--)
				std::cout << "0";
			std::cout << "\n";
		}else{
			std::cout << "NA\n";
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int w, h;
	string s;
	int i, j;
	while (cin >> w >> h) {
		if (w == 0)break;
		char tile[22][22]; int used[22][22];
		for (i = 0; i < 22; i++) {
			for (j = 0; j < 22; j++) {
				used[i][j] = 0; tile[i][j] = '#';
			}
		}
		vector<int> q1,q2;
		for (j = 1; j <= h; j++) {
			cin >> s;
			for (i = 1; i <= w; i++) {
				tile[i][j] = s[i - 1];
				if (s[i - 1] == '@') {
					q1.push_back(i); q2.push_back(j); used[i][j] = 1;
				}
			}
		}
		while (!q1.empty()) {
			int x = q1[0]; int y = q2[0];
			q1.erase(q1.begin() + 0); q2.erase(q2.begin() + 0);
			if (used[x - 1][y] == 0 && tile[x - 1][y]=='.') {
				q1.push_back(x - 1); q2.push_back(y); used[x - 1][y] = 1;
			}
			if (used[x + 1][y] == 0 && tile[x + 1][y] == '.') {
				q1.push_back(x + 1); q2.push_back(y); used[x + 1][y] = 1;
			}
			if (used[x][y-1] == 0 && tile[x][y-1] == '.') {
				q1.push_back(x); q2.push_back(y - 1); used[x][y - 1] = 1;
			}
			if (used[x][y+1] == 0 && tile[x][y+1] == '.') {
				q1.push_back(x); q2.push_back(y + 1); used[x][y + 1] = 1;
			}
		}
		int count = 0;
		for (i = 0; i < 22; i++) {
			for (j = 0; j < 22; j++) {
				if (used[i][j] == 1)count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int N;
	int digit = 0;

	if(scanf("%d", &N) == 1);

	if(N < 1 || N > 100000) exit(0);

	int tmpN = N;

	/* 桁数を計算 */
  	while(tmpN != 0) {
    	tmpN = tmpN / 10;
    	++digit;
  	}

  	if(digit == 1) {
  		printf("%d\n", N);
  		exit(0);
  	}

  	int start;
  	if(digit % 2 == 0) {
  		start = digit - 1;
  	} else {
  		start = digit;
  	}

  	int count = 0;
  	while(1) {
  		if(start == 1) {
  			count += 9;
  		} else if(start == digit) {
  			count += N - pow(10, start - 1) + 1;
  		} else {
  			count += 9 * pow(10, start - 1);
  		}

  		start -= 2;

  		if(start < 0) break;
  	}
 
  	/* 数値の桁数を表示 */
  	printf("%d\n", count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    vl v(5);
    FOR(i,0,5)cin >> v[i];
    ll k;
    cin >> k;
    cout << (v[4]-v[0] > k ? ":(" : "Yay!") << endl;
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

for a in As:
    d[a] += 1
cnt = 0
for k in d.keys():
    cnt += d[k] - 1

if cnt % 2 == 0:
    print(N-cnt)
else:
    print(N-cnt-1)

Measured memory_bytes: 21924
n=int(input())
d={}
for _ in range(n):
    chara=input()
    if chara in d:
        d[chara]+=1
    else:
        d[chara]=1

m=int(input())
for _ in range(m):
    chara=input()
    if chara in d:
        d[chara]-=1
    else:
        d[chara]=-1

out=sorted(d.items(), key=lambda x: x[1])[-1][1]
if out<0:
    print(0)
else:
    print(out)


Measured memory_bytes: 3064
use std::io;
use std::str::FromStr;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut iter = input.split_whitespace().map(|n| i32::from_str(n).unwrap());
    let (A, B) = (iter.next().unwrap(), iter.next().unwrap());
    let add = A + B;
    let sub = A - B;
    let mul = A * B;
    let mut ans = add;
    ans = std::cmp::max(ans, sub);
    ans = std::cmp::max(ans, mul);
    println!("{}", ans);
}


Measured memory_bytes: 4352
N=int(input())
T = [0]*(N+1)
X = [0]*(N+1)
Y = [0]*(N+1)

for i in range(1, N+1):
  T[i], X[i], Y[i] = list(map(int, input().split()))

for i in range(0, N):
  dist = (abs(X[i] - X[i+1]) + abs(Y[i] - Y[i+1]))
  if T[i+1] - T[i] >= dist and (T[i+1] - T[i] - dist)%2==0:
    continue
  else:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 11764