akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
using namespace std;


int main(){
    bool a=false;
    bool b=false;
    int n;
    cin>>n;
    vector<int>p(n);
    vector<int>q(n);
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++)cin>>q[i];
    vector<int>r(n);
    vector<int>s(n);
    int x=1;
    int y=1;
for(int i=0;i<n;i++)r[i]=p[i];
for(int i=0;i<n;i++)s[i]=q[i];

sort(p.begin(),p.end());
do{
 for(int i=0;i<n;i++){
if(p[i]==r[i])a=true;
else{a=false;break;}
}
if(a)break;
x++;
}while(next_permutation(p.begin(),p.end()));

sort(q.begin(),q.end());
do{
 for(int i=0;i<n;i++){
if(q[i]==s[i])b=true;
else{b=false;break;}
}
if(b)break;
y++;
}while(next_permutation(q.begin(),q.end()));
    
cout<<abs(x-y);
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
      string s,d;
      cin>>s>>d;
      int mn=10000000,c=0,f=0;
      for(int i=0;i<s.length();i++)
      {
          c=0;
          for(int j=0;j<d.length();j++)
          {
              if(i+d.length()<=s.length())
              {
                  if(s[i+j]!=d[j]) c++;
              }
               else {f=1;break;}
          }
            if(f==1) break;
            mn=min(c,mn);
      }
      cout<<mn<<endl;

}

Measured memory_bytes: 3656
n,m=map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
    a[i]+=[sum(a[i])]
    print(*a[i])
a=list(zip(*a[::-1]))
for i in range(m):print(sum(a[i]),end=' ')
print(sum(a[m]))


Measured memory_bytes: 5776
N, K = map(int, input().split())

i = 1
tmp = (N - 1) * (N - 2) // 2
if K > tmp:
    print(-1)
    exit()
ans = []
for j in range(2, N + 1):
    ans.append((i, j))

if tmp != K:
    for i in range(2, N + 1):
        for j in range(i + 1, N+ 1):
            if i == j:
                continue
            else:
                ans.append((i, j))
                tmp -= 1
                if tmp == K:
                    break
        if tmp == K:
            break
if tmp == K:
    print(len(ans))
    for a in ans:
        print(a[0], a[1])
else:
    print(-1)


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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using  vi = vector<int>;
using  vl = vector<ll>;
using  vd = vector<double>;
template<class T,class U>
using umap = unordered_map<T,U>;
template<class T>
using uset = unordered_set<T>;

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

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

template<class T>
inline void putv(const vector<T>&v,char c = '\n'){
  for(auto&&e:v){
    cout << e << c;
  }
}

int main(){
  int n; cin >> n;
  vector<pii> v(n);
  int idx = 1;
  for(auto&&e:v){
    cin >> e.first;
    e.second = idx++;
  }
  sort(v.begin(), v.end());
  for(int i = 1; i <= n; ++i){
    if(v[n-1].second == i)cout << v[n-2].first << endl;
    else cout << v[n-1].first << endl;
  }

  return 0;
}


Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        Point[] list = new Point[N];
        for (int i = 0; i < N; i++) {
            Point p = new Point();
            p.t = scan.nextInt();
            p.x = scan.nextInt();
            p.y = scan.nextInt();
            list[i] = p;
        }
        Point prev = new Point();
        prev.t = 0;
        prev.x = 0;
        prev.y = 0;
        boolean answer = true;
        for (int i = 0; i < N; i++) {
            Point current = list[i];
            int time = current.t - prev.t;
            int distance = prev.distance(current);

            if (time == distance) {
                prev = current;
                continue;
            }
            if (time < distance || ((time - distance) % 2 != 0)) {
                answer = false;
                break;
            }
            prev = current;
        }
        System.out.println(answer ? "Yes" : "No");
    }
    class Point {
        int t;
        int x;
        int y;
        int distance(Point t) {
            return Math.abs(this.x - t.x) + Math.abs(this.y - t.y);
        }
    }
}


Measured memory_bytes: 93952
#include<iostream>
#include<cmath>

using namespace std;

int main() {
	int a, b, c, k;

	cin >>a>>b>>c>>k;
	
	int t = 0;
		t = pow(2, k);
		if (a >= b && a >= c) {
			cout << a * t + b + c << endl;
		}if (b >= c && b > a) {
			cout << a + b * t + c << endl;
		}if (c > b&&c > a) {
			cout << a + b + c * t << endl;
		}

		system("pause");
}
	
	

Measured memory_bytes: 504
#include <stdio.h>

int main(void) {
    int a1, a2, a3, a4, b1, b2, b3, b4, S, T;

    scanf ("%d %d %d %d\n", &a1, &a2, &a3, &a4);    
    scanf ("%d %d %d %d\n", &b1, &b2, &b3, &b4);

    S = a1 + a2 + a3 + a4;
    T = b1 + b2 + b3 + b4;

    if (S > T) {
        printf ("%d\n", S);
    }
    else {
        printf ("%d\n", T);
    }

    return 0;
}

Measured memory_bytes: 596
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(int i=0;i<(n);i++)
#define f1(i,n) for(int i=1;i<=(n);i++)
#define f2(i,a,n) for(int i=(a);i<=(n);i++)
#define fr(i,n,a) for(int i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;

ll a[201];
char s[202];
int main(){
	ll t; cin >> t;
	while(t--){
		int n;
		cin >> n;
		f1(i, n)
			cin >> a[i];
		scanf("%s",s+1);
		for(int i=n;i;i--){
			if(a[i]==0)continue;
			int u=60;
			while(!(a[i]>>u&1))u--;
			for(int j=i-1;j;j--)
				if(a[j]>>u&1)a[j]^=a[i];
		}
		int ans=0;
		for(int i=1;i<=n;i++)
			if(s[i]=='1'&&a[i])
				ans=1;
		cout << ans << nl;
	}
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    if (s =="Sunny"){
        cout << "Cloudy" << endl;
    }else if (s == "Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
f x y = x * y `mod` (10^9+7)
g x = foldl1 f [1..x]
main = do
  [n,m] <- map read . words <$> getLine
  let d = abs (n-m)
  print $ if d<=1 
    then (g n) `f` (g m) `f` (2-d)
    else 0

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


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

    int a[n];

    rep(i,n) {
        a[i] = 0;
    }

    rep(i,n-1) {
        int temp;
        cin >> temp;
        a[temp-1]++;
    }

    rep(i,n) {
        cout << a[i] << endl;
    }





    return 0;
}



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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;

int main() {
    cin >> n;

    printf("%.8lf\n", pow(n/3.0, 3));

    return 0;
}


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

using namespace std;

int N;
string s;

int main(void)
{
	cin >> s;
	N = s.size();
	
	int ans = (N+1)/2 * -1;
	for(int i = 0; i < N; i++){
		if(s[i] == 'g') ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner br = new Scanner(System.in);
        int A = br.nextInt();
        int B = br.nextInt();
        int C = br.nextInt();
        int D = br.nextInt();
        System.out.println(Math.min(A,B)+Math.min(C,D));
    }
}


Measured memory_bytes: 23764
import heapq
A =[]
n,m= map(int,input().split())
a = list(map(int,input().split( )))
for i in range(n):
    a [i]*= -1
    heapq.heappush(A,a[i])
#print(*A)
cnt = 0
while cnt < m:
    i = heapq.heappop(A)
    i *= -1
    i //=2
    i *=-1
    heapq.heappush(A,i)
    cnt+=1
sm = 0
for i in A:
    sm += i
sm *=-1
#print(*A)
print(sm)


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

#define mod 1000000007
#define inf 1000000000000000001;

using namespace std;

void solve(){
	int a;cin>>a;
	cout<<a+a*a + a*a*a<<endl;
}


int main()
{
	std::ios::sync_with_stdio(false);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif


		solve();

	return 0;
}


Measured memory_bytes: 3636
import sys
import bisect
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = list(map(int, input().split()))
    X_s = sorted(X)

    for i in range(n):
        idx = bisect.bisect_left(X_s, X[i])
        if idx <= n // 2 - 1:
            print(X_s[n // 2])
        else:
            print(X_s[n // 2 - 1])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 95828
def find(x):
    if tree[x] < 0:
        return x
    tree[x] = find(tree[x])
    return tree[x]


def unite(x, y):
    x_position = find(x)
    y_position = find(y)
    if x_position == y_position:
        return True
    if y_position < x_position:
        x_position, y_position = y_position, x_position
    tree[x_position] += tree[y_position]
    tree[y_position] = x_position
    return False


def same(x, y):
    if find(x) == find(y):
        print(1)
    else:
        print(0)


n, q = map(int, input().split())
tree = [-1] * n
for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        unite(x, y)
    if com == 1:
        same(x, y)

Measured memory_bytes: 7880
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;


int32_t main(){
	ios::sync_with_stdio(false);
    int n;int x;
    cin>>n>>x;
    vi a(n);
    REP(i,0,n)cin>>a[i];
    int ans=0;
    for(int i=0;i<(n-1);i++){
        if(a[i]+a[i+1]>x){
            ans+=a[i]+a[i+1]-x;
            if(a[i+1] >= a[i]+a[i+1]-x){
                a[i+1]-=a[i]+a[i+1]-x;
            }
            else{
                a[i+1]=0;
                a[i]=x;
            }
        }
    }
    cout<<ans<<"\n";



	return 0;
}

Measured memory_bytes: 1024
X, Y = map(int, input().split())

result = 'No'
li = []
for i in range(X):
    li.append(4)
if sum(li) == Y:
    result = 'Yes'
else:
    for i in range(X):
        li[i] = 2
        if sum(li) == Y:
            result = 'Yes'
            break

print(result)


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



int solution(int* arr , int n){
    
    int* dp = new int[n];
    for(int i=0 ; i<n ; i++){
        dp[i] = INT_MAX;
    }
    
    dp[0] = 0;
    if(n>=1){
        dp[1] = abs(arr[0]-arr[1]);
    }

    for(int i=2 ; i<n ; i++){
        dp[i] = min(dp[i] , min(dp[i-2]+abs(arr[i]-arr[i-2]) , dp[i-1]+abs(arr[i]-arr[i-1])));
    }
    
    return dp[n-1];

}


int main(){
    int n;
    cin>>n;
    int* arr = new int[n];
    for(int i=0 ; i<n ; i++){
        cin>>arr[i];
    }
    cout<<solution(arr , n)<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n,ma=INT_MAX,cnt=0,b;
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>b;
			if(b<ma){
				cnt++;
				ma=b;
			}
		}
		cout<<cnt;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    string S;cin>>S;
    int ans=700;
    REP(i,3){
        if(S[i]=='o')ans+=100;
    }
    cout<<ans<<endl;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, M;
	cin >> N >> M;
	
	vector< int > A(M);
	for_(i,0,M) cin >> A[i];
	
	vector< int > point(N);
	
	for_(i,0,M) {
		int add = 0;
		
		for_(j,0,N) {
			int B;
			cin >> B;
			
			if (B == A[i]) ++point[j];
			else ++add;
		}
		
		point[A[i] - 1] += add;
	}
	
	for_(i,0,N) cout << point[i] << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); }
 size_t operator()(uint64_t x) const {
  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

int n;
V<ld> p;
V<V<ld>> dp;
V<V<bool>> computed;

ld f(int i, int k)
{
    if (k < 0) return 0;
    if (i == n) {
        if (k == 0) return 1;
        return 0;
    }
    if (computed[i][k]) return dp[i][k];
    ld a = f(i+1, k-1) * p[i];
    ld b = f(i+1, k) * (1 - p[i]);
    computed[i][k] = true;
    return dp[i][k] = a + b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    p.resize(n);
    rep(i,0,n) cin >> p[i];
    computed.assign(n+1,  V<bool>(n+1, false));
    dp.resize(n+1, V<ld>(n+1));
    ld ans = 0;
    rep(i,n/2+1,n+1) ans += f(0, i);
    cout << fixed << setprecision(14) << ans << endl;
}


Measured memory_bytes: 144640
def comb(k, n, m, s, r):
    if k == n:
        r.append(s[1:])
        return
    for ai in range(s[-1], m + 1):
        comb(k + 1, n, m, s + [ai], r)
    return r

def main():
    n, m, q = map(int, input().split())
    abcd = [[int(i) for i in input().split()] for _ in range(q)]
    s = 0
    for p in comb(0, n, m, [1], []):
        t = 0
        for a, b, c, d in abcd:
            t += d * (p[b - 1] - p[a - 1] == c)
        s = max(s, t)
    print(s)

if __name__ == '__main__':
    main()

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

typedef struct _leaf
{
	int father;
	int value;
}leaf;

map<int, leaf> Map;
int main()
{
	int a,b;
	int n,i,q;
	int value;
	cin >> n;
	cin >> q;
	for (i = 0; i < n - 1; i++)
	{
		cin >> a;
		cin >> b;
		if (Map.count(a) == 0)
		{
			Map[a].value = 0;
			Map[a].father = 0;
		}

		Map[b].value = 0;
		Map[b].father = a;
	}
	for (i = 0; i < q; i++)
	{
		cin >> a;
		cin >> value;
		if (Map.count(a) == 1)
		{
			Map[a].value += value;
		}
		else
		{

		}
	}
	map<int, leaf> ::iterator iter;
	for (iter = Map.begin(); iter != Map.end(); iter++)
	{
	//	if(iter!= Map.begin())
			if(Map.count((*iter).second.father)!=0)
		(*iter).second.value += Map[(*iter).second.father].value;
	}
	for (iter = Map.begin(); iter != Map.end(); iter++)
	{
		cout<<(*iter).second.value <<" ";
	}
	return 0;
}

Measured memory_bytes: 14848
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define iceil(n, x) ((n + x - 1) / x)
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 100005
#define M 105
using namespace std;

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
			 tree_order_statistics_node_update> ordered_set;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.
#define int ll
int a[N];

inline int add(int a, int b, int p = mod){ ll c = a + b; if(c >= p) c -= p; return c;}
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c;}
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p;}

main()
{	
	#ifdef CP
		freopen("/home/tarun/Desktop/input.txt", "r", stdin);
		//freopen("/home/tarun/Desktop/output.txt", "w", stdout);
	#endif
	sync;
	clock_t clk = clock();
	cerr << "I will return...\n";
	
	int n, m; cin >> n >> m;
	map<ll, ll> mp;
	ll ans, pre;
	ans = pre = 0;
	mp[0]++;
	rep(i, 1, n + 1) {
		cin >> a[i];
		a[i] %= m;
		pre = add(pre, a[i], m);
		ans += mp[pre];
		mp[pre]++;
	}
	cout << ans << '\n';

	cerr << "...don't you ever hang your head.\n";
	cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment






Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int,int> P;
int INF = 100000;

int main() {
    int H,W;cin >> H >> W;
    char s[H][W] = {};
    int d[H][W] = {};
    int count = 0;
    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            cin >> s[i][j];
            if (s[i][j] == '.') count++;
            d[i][j] = INF;
        }
    }
    int sx = 0;int sy = 0;int gx = W - 1;int gy = H - 1;
    int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
    queue<P> que;
    que.push(P(sx,sy));
    d[sy][sx] = 0;
    while(que.size()){
        P p = que.front();que.pop();
        if (p.first == gx && p.second == gy) break;
        for (int i = 0;i < 4;i++){
            int nx = p.first + dx[i];int ny = p.second + dy[i];
            if (nx >= 0 && nx < W && ny >= 0 && ny < H && s[ny][nx] != '#' && d[ny][nx] == INF){
                d[ny][nx] = d[p.second][p.first] + 1;
                que.push(P(nx,ny));
            }
        }
    }
    if (d[gy][gx] == INF) {
        cout << -1 << endl;
        return 0;
    }
    else{
        cout << count - d[gy][gx] - 1 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
def main():
    MAX = 10 ** 5 + 1

    data = [-1] * (2 * MAX)

    def find(x):
        if data[x] < 0:
            return x
        else:
            data[x] = find(data[x])
            return data[x]

    def union(x, y):
        x, y = find(x), find(y)
        if x != y:
            if data[y] < data[x]:
                x, y = y, x
            data[x] += data[y]
            data[y] = x
        return (x != y)


    N, *XY = map(int, open(0).read().split())

    for x, y in zip(*[iter(XY)] * 2):
        union(x, y + MAX)

    X = [0] * (MAX * 2)
    Y = [0] * (MAX * 2)

    for i in range(MAX):
        X[find(i)] += 1
    for i in range(MAX, MAX * 2):
        Y[find(i)] += 1

    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print(res - N)


if __name__ == '__main__':
    main()


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

ll f(ll n){
  if(n%4 == 0) return n;
  if(n%4 == 1) return 1;
  if(n%4 == 2) return (1^n);
  if(n%4 == 3) return 0;
}

int main(){
  ll A,B;
  cin >>A>>B;
  ll ans = (A == 0) ? f(B) : f(A-1)^f(B);
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    if(n%2==0) n--;
    if(n<105){
        cout << 0 << endl;
    }
    else if(n==105){
        cout << 1 << endl;
    }
    else{
        int ans=1;
        for(int i=107; i<=n; i+=2){
            int cnt=0;
            for(int j=1; j<=i; j++){
                if(i%j==0) cnt++;
            }
            if(cnt==8) ans++;
        }
        cout << ans << endl;
    }
}

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

#define pb push_back
#define MAX 100005
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

int k;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>k;
    int even = k/2;
    int odd  = k-even;
    cout<<even*odd<<"\n";
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS= 1e-10;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    int n;
    cin>> n;
    string S;
    cin>> S;
    if(n%2==1){
        cout<< "No"<<el;
        return 0;
    }
    forn(i,n/2){
        if(S[i]!=S[i+n/2]){
            cout<< "No"<<el;
            return 0;
        }
    }
    cout<< "Yes"<<el;
}


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

using namespace std;

int n, m;
string s[410];
char used[410][410];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

bool in(int i, int j){
    return i >= 0 && i < n && j >= 0 && j < m;
}

int wh, bl;

void dfs(int i, int j){
    used[i][j] = true;
    if(s[i][j] == '#') bl++;
    else wh++;
    for(int k = 0; k < 4; k++){
        int ii = i + dx[k];
        int jj = j + dy[k];
        if(in(ii, jj) && !used[ii][jj] && s[i][j] != s[ii][jj]){
            dfs(ii, jj);
        }
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    long long an = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(!used[i][j]){
                bl = 0;
                wh = 0;
                dfs(i, j);
                an += 1ll * bl * wh;
            }
        }
    }
    cout << an;
    return 0;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    if(max(a,max(b,c))==a){
        cout << a*pow(2,k)+b+c << endl;
    }else if(max(a,max(b,c))==b){
        cout << b*pow(2,k)+a+c << endl;
    }else{
        cout << c*pow(2,k)+b+a << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
const int a[8] = { 0, 1, 2, 3, 5, 7, 8, 9 };
int n, s[15];
int main() {
	while(true) {
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < 15; i++) {
			s[i] = a[n % 8];
			n /= 8;
		}
		reverse(s, s + 15); bool flag = false;
		for(int i = 0; i < 15; i++) {
			flag = flag || s[i];
			if(flag) {
				printf("%d", s[i]);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2588
s=input()
l=len(s)
s2=''
for i in range(l):
  if s[i]!='x':
    s2+=s[i]
l2=len(s2)
for i in range(l2):
  if s2[i]!=s2[-(i+1)]:
    print(-1)
    break
else:
  lpos=0
  rpos=l-1
  cnt=0
  while rpos-lpos>=1:
    if s[lpos]==s[rpos]:
      lpos+=1
      rpos-=1
      continue
    else:
      if s[lpos]=='x':
        lpos+=1
        cnt+=1
      else:
        rpos-=1
        cnt+=1
  print(cnt)

Measured memory_bytes: 3316
until (n, k, m, r = gets.split.map(&:to_i)).all?(&:zero?)
  ans = 10**(r+5) / n
  ans += (1...n).inject(0){|sum, i| sum + 10**(r+5)/i} / n unless m.zero?
  s = ans.to_s
  s = "0" + s until (r+5) < s.size
  print s[0]
  print "."
  puts s[1..r]
end

Measured memory_bytes: 34860
#include <iostream>
#include <map>
#include <string>

using namespace std;

void solve()
{
	map<int, int> Map1;
	map<int, int> Map2;
	string str;
	bool next = false;
	while(getline(cin, str))
	{
		if(str == "")
		{
			next = true;
			continue;
		}
		int num = 0;
		int size = str.size();
		string snum;
		for(int i = 0; i < size; ++i)
		{
			if(str[i] == ',')
			{
				break;
			}
			snum += str[i];
		}
		size = snum.size();
		int temp = 1;
		for(int i = size - 1; i >= 0; --i)
		{
			num += (snum[i] - '0') * temp;
			temp *= 10;
		}
		if(next == false)
		{
			Map1[num]++;
		}
		else
		{
			Map2[num]++;
		}
	}
	for(map<int, int>::iterator Ite1 = Map1.begin(); Ite1 != Map1.end(); ++Ite1)
	{
		for(map<int, int>::iterator Ite2 = Map2.begin(); Ite2 != Map2.end(); ++Ite2)
		{
			if(Ite1->first == Ite2->first)
			{
				cout << Ite1->first << " " << Ite1->second + Ite2->second << endl;
			}
		}
	}
}

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

Measured memory_bytes: 0
#include<iostream>
using namespace std;
long long int cara(long long int x);
int main() {

	long long int n;
	cin >> n;
	cout << cara(n) << endl;
	return 0;

}
long long int cara(long long int x) {

	int i = 0;
	if (x == 1) {
		return 1;
	}
	else {
		return 1  + 2 * cara((long long int)(x / 2));
	}

}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define si set<int>
#define mp map<ll,ll>
#define mpi map<ii,ll>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#include <unordered_map> 
#define ump unordered_map<ll,ll>
int main()
{ 
	fast 
	ll a,b;
	cin>>a>>b;
	cout<<max(0,a-2*b)<<endl;
}

Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const a = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

a.sort((a, b) => b - a)

let cost = 0

cost = Math.abs(a[0] - a[1])

cost += Math.abs(a[1] - a[2])

console.log(cost)


Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   string s;
   cin>>s;
   map<char,int> mp;
   rep(i,s.size()){
       mp[s[i]]++;
   }
   for(auto x:mp){
       if(x.second%2){cout<<"No"<<endl;return 0;}
   }
   cout<<"Yes"<<endl;
   return 0;
}


Measured memory_bytes: 256
<?php
  function to_f($e) {
    return (float)$e;
  }

  while($line = fgets(STDIN)) {
    $a = explode(" ", $line);
    $a = array_map("to_f", $a);
    $x = ($a[2]*$a[4]-$a[1]*$a[5])/($a[0]*$a[4]-$a[3]*$a[1]);
    $y = ($a[2]*$a[3]-$a[0]*$a[5])/($a[1]*$a[3]-$a[0]*$a[4]);
    printf("%.3f %.3f\n", $x, $y);
  }

Measured memory_bytes: 15164
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> P(N);
  int64_t count = 0;
  vector<int64_t> sequences;
  for (int64_t i = 0; i < N; ++i) {
    cin >> P[i];
    if (P[i] == i + 1) {
      ++count;
    } else {
      if (count > 0) {
        sequences.push_back(count);
      }
      count = 0;
    }
  }
  if (count > 0) {
    sequences.push_back(count);
  }
  // cerr << sequences.size() << endl;
  int64_t result = 0;
  for (const int64_t a : sequences) {
    result += (a + 1) / 2;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1660
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

vector<string> v;

int main()
{
	fast;
	ll a,b,c;
	cin>>a>>b>>c;
	if(c-a-b>=0 and (c-a-b)*(c-a-b)>4*a*b)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

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

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int N = 18;
const int P = 998244353;
const llong INV2 = 499122177ll;
llong p[(1<<N)+3];
llong a[(1<<N)+3],b[(1<<N)+3];
int n,sum;

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}
llong mulinv(llong x) {return quickpow(x,P-2);}

void fwt(int dgr,int coe,llong poly[],llong ret[])
{
	memcpy(ret,poly,sizeof(llong)*(1<<dgr));
	for(int i=0; i<dgr; i++)
	{
		for(int j=0; j<(1<<dgr); j+=(1<<i+1))
		{
			for(int k=0; k<(1<<i); k++)
			{
				llong x = poly[k+j],y = poly[k+(1<<i)+j];
				poly[k+j] = x+y>=P?x+y-P:x+y; poly[k+(1<<i)+j] = x-y<0?x-y+P:x-y;
			}
		}
	}
	if(coe==-1) {llong tmp = mulinv(1<<dgr); for(int i=0; i<(1<<dgr); i++) ret[i] = ret[i]*tmp%P;}
}

int main()
{
	scanf("%d",&n); for(int i=0; i<(1<<n); i++) {scanf("%lld",&p[i]); sum += p[i];} sum = mulinv(sum);
	for(int i=0; i<(1<<n); i++) p[i] = p[i]*sum%P; p[0] = (p[0]-1+P)%P;
	a[0] = (1<<n)-1; for(int i=1; i<(1<<n); i++) a[i] = P-1;
	fwt(n,1,a,a); fwt(n,1,p,p);
	b[0] = 0ll; for(int i=1; i<(1<<n); i++) b[i] = a[i]*mulinv(p[i])%P;
	fwt(n,-1,b,b);
	llong tmp = b[0]; for(int i=0; i<(1<<n); i++) b[i] = (b[i]-tmp+P)%P;
	for(int i=0; i<(1<<n); i++) printf("%lld\n",b[i]);
	return 0;
}

Measured memory_bytes: 8960
K=int(input())
s=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[K-1])

Measured memory_bytes: 3060
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array: [String] = []
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map({String($0)})
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map({Int($0)!})
}

let x = readString()
let pattern = "[A-Z]"
let regex = try! NSRegularExpression(pattern: pattern, options: [])

if regex.firstMatch(in: x, options: [], range: NSRange(location: 0, length: x.count)) != nil {
    print("A")
} else {
    print("a")
}



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

int main (){
	int a,b,c,d;
	cin>>a>>b>>c;
	d=0;
	for(a=a;a<=b;a++){
		if(c%a==0){
			d=d+1;
		}
		
	}
	cout<<d<<endl;
	return 0;
}


Measured memory_bytes: 3120
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second

//CHECK FOR N = 1 OR OTHER DUMB TESTS 

using namespace std;

int n, m;
string s, t;
ll ans;
vector<int> pos[12345];

int main() {
	//ifstream cin("tst.in");
	//ofstream out("tst.out");
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cin >> s >> t;
	n = s.size();
	m = t.size();
	s = '+' + s;
	t = '+' + t;
	for (int i = 1; i <= n; i++)
		pos[s[i]].push_back(i);
	
	for (int i = 1; i <= m; i++)
		if (pos[t[i]].size() == 0) 
			return cout << "-1", 0;
			
	int lst = 0;
	for (int i = 1; i <= m; i++) {
		char c = t[i];
		auto p = upper_bound(pos[c].begin(), pos[c].end(), lst);
		
		
		if (p != pos[c].end()) {
//			cout << i << ' ' << "Asd\n";
			int pp = p - pos[c].begin();
//			cout << pp << endl;
			ans += pos[c][pp] - lst;
			lst = pos[c][pp];  
		} else {
			ans += n - lst;
			ans += pos[c][0];
			lst = pos[c][0];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1516
#include <iostream>
#include <cstring>
#include <map>

using namespace std;
map <string,bool> ds;
int ans=0;
string s;
int n;
int main(){
    cin>>n;
    while(n--){
        cin>>s;
        if(!ds[s]){ans++;ds[s]=1;}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 19256
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 100005;
const int mod = 1e9 + 7;

int main() {
    int n,a[maxn];
    LL ans = 0;
    cin>>n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    for (int i=0; i<n; i++) {
        ans += a[i]>>1;
        a[i] %= 2;
        if (i<n-1 && a[i] && a[i+1]) {
            ans++;
            a[i]--, a[i+1]--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
// atcoder/abc177/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);


  int d, t, s;
  while (cin >> d >> t >> s) {
    cout << (d <= t * s ? "Yes" : "No") << endl;
  }


  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)

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

	int N, M;
	ll X;
	cin >> N >> M;
	cin >> X;

	vector<ll> C(N,0); // cost
	vector<vector<ll> > A(N,vector<ll>(M,0));
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}

	ll minC = 12000000LL;
	for (int b = 0; b < (1 << N); ++b) {
//		cout << b << endl;
		ll curC = 0LL;
		vector <ll> S(M, 0LL);
		for (int i = 0; i < N; ++i) {
			if (b & (1 << i)) {
//				cout << "  " << i << endl;
				// i がb に入る
				curC += C[i];
				for (int j = 0; j < M; j++) {
					S[j] += A[i][j];
//					cout << "    " << j << " " << A[i][j] << endl;
				}
			}
		}
//		cout << "   curC = " << curC << endl;
		bool f = true;
		for (int j = 0; j < M; j++) {
//				cout << "  S[" << j << "] = " << S[j] << endl;
			if (S[j] < X) {
				f = false;
				break;
			}
		}
		if (f) {
			if (curC < minC) {
				minC = curC;
			}
		}
	}

	if (minC == 12000000LL) {
		cout << -1 << endl;
	}
	else {
		cout << minC << endl;

	}
	return(0);
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

//#define pt(s)      cerr << s << endl
//#define pt(a, b)      cerr << a << " "  << b << endl
#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int maxn = 1;
const double EPS = 1e-8;

int g[600][600];
int n, m;
vector< tuple<int, int, int, int>> v;

class DMakeThemEven {
public:
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
		memset(g, 0, sizeof(g));
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				in >> g[i][j];
			}
		}

		v.clear();
		int tmp = 0;
		for (int i = 0; i < n; ++i) {
			if(i % 2 == 0){
				for (int j = 0; j < m; ++j) {
					if(g[i][j] % 2 == 1){
						if(j == m - 1){
							if(i < n - 1)
								v.emplace_back(i, j, i+1, j), g[i+1][j]++;
						}
						else {v.emplace_back(i, j, i, j+1); g[i][j+1]++;}
					}
				}
			} else {
				for (int j = m - 1; j >= 0; --j) {
					if(g[i][j] % 2 == 1){
						if(j == 0){
							if(i < n - 1)
								v.emplace_back(i, j, i+1, j), g[i+1][j]++;
						}
						else v.emplace_back(i, j, i, j-1), g[i][j-1]++;
					}
				}
			}

		}
		out << v.size() << "\n";
		int a, b, c, d;
		for (int i = 0; i < v.size(); ++i) {
			tie(a, b, c, d) = v[i];
			a++, b++, c++, d++;
			out << a << " " << b << " " << c << " " << d << "\n";
		}
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	DMakeThemEven solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5616
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;



int main(){
    int n;
    cin >> n;
    VEC(string, s, n);
    int head = 0, back = 0, same = 0;
    int res = 0;
    rep(i, n){
        if(s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A')same++;
        rep(j, s[i].size()){
            if(j == 0){
                if(s[i][j] == 'B')head++;
            }
            if(j == s[i].size() - 1){
                if(s[i][j] == 'A')back++;
                break;
            }
            
            if(s[i][j] == 'A' && s[i][j + 1] == 'B')res++;
        }
    }
    res += min(head, back);
    if(head == back && back == same && same != 0)res--;
    cout << res << endl;
}

Measured memory_bytes: 512
H,W = map(int,input().split())
s=[]
for i in range(H):
    s.append(input().strip())
dist=[[float("inf")]*W for i in range(H)]
Q=[]
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            Q.append((i,j))
dist[0][0]=0
while len(Q) > 0:
    Q=sorted(Q,key=lambda x: dist[x[0]][x[1]])
    pt=Q.pop(0)
    if pt==(H-1,W-1):
        break
    dpt = dist[pt[0]][pt[1]]
    for nbr in [(pt[0]-1,pt[1]),(pt[0],pt[1]-1),(pt[0]+1,pt[1]),(pt[0],pt[1]+1)]:
        if nbr in Q:
            dist[nbr[0]][nbr[1]] = min(dist[nbr[0]][nbr[1]],dpt+1)
    
#全体-黒マスー最短路
print(max(H*W-sum(i.count("#") for i in s)-dist[-1][-1]-1,-1))

Measured memory_bytes: 3188
#include <stdio.h>

#define MAX_STRING 100000

int main()
{
	int i, count_odd, count_even;
	char s[MAX_STRING + 1];

	scanf("%s", s);

	for (i = 0, count_odd = 0; s[i] != '\0'; i++) {
		if (i % 2 == 0 && s[i] == '0' || i % 2 == 1 && s[i] == '1')
			count_odd++;
	}

	for (i = 0, count_even = 0; s[i] != '\0'; i++) {
		if (i % 2 == 0 && s[i] == '1' || i % 2 == 1 && s[i] == '0')
			count_even++;
	}

	printf("%d\n", count_odd > count_even ? count_even : count_odd);

	return 0;
}


Measured memory_bytes: 256