akhauriyash/Code-Regression huggingface dataset:
/**
 *   created: 07 September 2019  17:28:19
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
    optimizeIO();
    int tt=1;
    //cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vi a(n,-1),b(n-1),c(n-1);
        rep(i,0,n-1){
            cin>>b[i];
            c[i] = b[i];
        }
        sort(all(c));
        a[0] = b[0];
        a[1] = b[0];
        rep(i,1,n-1){
            if(a[i]>b[i])
                a[i]= b[i];
            a[i+1] = b[i];
        }
        int sum = 0;
        rep(i,0,n)
            sum+=a[i];
        cout<<sum;
    }
    return 0;
}


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

struct E{
    int to,co;
    E(int to = 0,int co = 0):to(to),co(co){}
};
using graph = vector<vector<E>>;

int main(){
    int n;cin >> n;
    graph G(n+1);
    rep(i,n-1){
        int u,v,w;cin >> u >> v >> w;
        G[u].emplace_back(v,w);
        G[v].emplace_back(u,w);
    }

    queue<int> q;
    q.push(1);
    vector<int> label(n+1,-1);
    label[1] = 1;
    while(!q.empty()){
        int v = q.front();q.pop();
        for(E nv:G[v]){
            if(label[nv.to]!=-1) continue;
            if(nv.co%2 == 1) label[nv.to] = 1-label[v];
            else label[nv.to] = label[v];
            q.push(nv.to);
        }
    }

    rep(i,n) cout << label[i+1] << endl;



    
}

Measured memory_bytes: 9508
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;




int main(){
	ll A,B,K;
	std::cin >> A >> B >> K;
	
	if( K <= A ){
		printf("%lld %lld\n", A-K, B );
	}else if( K <= A+B ){
		printf("0 %lld\n", B-(K-A) );
	}else{
		printf("0 0\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(std::vector<T>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}


//CODE
void solve(void)
{
 double a,b;
 cin>>a>>b;
 cout<<(int)ceil((a+b)/2)<<endl;
  
  return;
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
def solve(A, i, m, n):
    """Return if it is possible to make value m with some elements in A.
 
    n is length of A.
    i is index.
    R is the record of answer i, m.
    Using Divide-and-Conquer method.
    """
 
    if R[i][m] != None:
        return R[i][m]
    if m == 0:
        R[i][m] = True
        return True
    elif i >= n:
        R[i][m] = False
        return False
    else:
        ans = solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n)
        R[i][m] = ans
        return ans
 
 
import sys
 
n = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
q = int(sys.stdin.readline())
M = tuple(map(int, sys.stdin.readline().split()))
 
s_A = sum(A)
R = [[None] * 2000 for i in range(n + 1)]
 
ans = ''
 
for m in M:
    if s_A < m:
        ans += 'no\n'
    elif solve(A, 0, m, n):
        ans += 'yes\n'
    else:
        ans += 'no\n'
 
print(ans, end = '')

Measured memory_bytes: 8120
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,xr=0,ans=0,i;set<int>avl;cin>>n;int a[n];
    for(i=0;i<n;i++)cin>>a[i],xr^=a[i],avl.insert(a[i]^(a[i]-1));
    for(i=29;i>=0;i--)
        if((xr>>i)&1){
            if(avl.count((1<<i+1)-1))xr^=(1<<i+1)-1,ans++;
            else return puts("-1")*0;
        }
    cout<<ans<<endl;
}

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

int main() {

  while( true ) {

    long long int n, m;
    cin >> n >> m;
    if ( n == 0 ) break;

    vector< pair< long long int, long long int > > c;
    for ( long long int i = 0; i < m; i++ ) {
      c.push_back( make_pair( 0, i+1 ) );
    }

    for ( long long int i = 0; i < n; i++ ) {
      for ( long long int j = 0; j < m; j++ ) {
	long long int in;
	cin >> in;
	if ( in == 1 ) c[j].first--;
      }
    }

    sort( c.begin(), c.end() );

    for ( long long int i = 0; i < m; i++ ) {
      if ( i > 0 ) cout << " ";
      cout << c[i].second;
    }

    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1204
//Gaurav Singh (saintpopo)
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(),x.end()
#define pb push_back

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int main(){
    //io_set();
    ll i,n=5,k,f=0,j;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    cin>>k;
    sort(a,a+n);
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(a[j] - a[i] > k){
                f=1;
            }
        }
    }
    if(f){
        cout<<":(";
    }
    else{
        cout<<"Yay!\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;

int dfs(int max, const vector<int>& l, int n, int a, int b, int c, int A, int B, int C) {

    if (n == max) 
        return (min(a, min(b, c))) ?  abs(a-A) + abs(b-B) + abs(c-C) - 30 : 1000000;

    int sa = dfs(max, l, n + 1, a+l[n], b, c, A, B, C) + 10;
    int sb = dfs(max, l, n + 1, a, b+l[n], c, A, B, C) + 10;
    int sc = dfs(max, l, n + 1, a, b, c+l[n], A, B, C) + 10;
    int sx = dfs(max, l, n + 1, a, b, c, A, B, C);

    return min(sa, min(sb, min(sc, sx)));
}

int main(int argc, const char * argv[]) {
    
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l;
    l.resize(n);
    for (int i=0; i<n; i++) {
        cin >> l[i];
    }

    int ret = dfs(n, l, 0, 0, 0, 0, a, b, c);

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,e,t){"use strict";function n(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=Number(r[0]),t=new Array(e),o=0;o<e;o++)t[o]=[];for(var u=n(r[e].split(" ").map(function(r){return Number(r)}),2),i=u[0],f=u[1],a=0;a<e-1;a++){var l=r[a+1].split(" ").map(function(r){return Number(r)});l[1]!=f&&t[l[0]-1].push([l[1]-1,l[2]]),l[0]!=f&&t[l[1]-1].push([l[0]-1,l[2]])}for(var c=new Array(e).fill(-1),p=[[f-1,0]];p.length>0;)for(var s=p.pop(),d=t[s[0]].length,v=0;v<d;v++){var y=t[s[0]][v];if(-1==c[y[0]]){var b=s[1]+y[1];c[y[0]]=b,p.push([y[0],b])}}for(var m=0;m<i;m++){var h=r[m+e+1].split(" ").map(function(r){return Number(r)-1}),g=c[h[0]]+c[h[1]];console.log(g)}}},function(r,e){r.exports=require("fs")}]);

Measured memory_bytes: 95504
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n;
  int a[55][3];
  cin >> n;
  REP(i, n) { cin >> a[i][0] >> a[i][1]; }
  int sum = 0;
  REP(i, n) {
    REP(j, n) {
      if (j == i) continue;
      int p = a[i][0] - a[j][0];
      int q = a[i][1] - a[j][1];
      int tmp_sum = 0;
      REP(ni, n) {
        REP(nj, n) {
          if (nj == ni) continue;
          if (a[ni][0] == a[nj][0] - p && a[ni][1] == a[nj][1] - q) {
            tmp_sum++;
          }
        }
      }
      sum = max(sum, tmp_sum);
    }
  }
  cout << n - sum << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	if (v[0] != 0) {
		cout << -1 << endl;
		return 0;
	}

	ll ans = 0;
	for (int i = 1; i < n; i++) {
		if (v[i] - v[i-1] > 1) {
			cout << -1 << endl;
			return 0;
		}
		if (v[i] - v[i-1] == 1) ans++;
		else ans += v[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	std::string s;

	std::cin >> s;

	if (s[2] == s[3] && s[4] == s[5]) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main ()
{
    int N,a=0,b=0,c=0,d=0;
    scanf ("%d",&N);
    if (N<=999&&N>=100)
    {
        a=N%10;
        b=N/10;
        c=b%10;
        d=b/10;
        if (a==7||c==7||d==7)
        {
            printf ("Yes\n");
        }
        else
        {
            printf ("No\n");
        }
    }
   return 0;
}


Measured memory_bytes: 2056
#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,M;
  cin>>N>>M;
  
  vector<int> A(N);
  rep(i,N)cin>>A[i];
  sort(A.rbegin(),A.rend());
  
  string ans="Yes";
  int sum=0;
  
  for(int i=0;i<N;i++){
    sum+=A[i];
  }
  
  double limit=(double)sum/(double)4/(double)M;
  int count=0;
  
  for(int i=0;i<N;i++){
    if(A[i]<limit)break;
    count++;
  }
  
  if(count<M){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }



}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)

int a[100100];
bool b[100100];

int main() {
    int N;
    cin >> N;
    int cN =N;
    int sum = 0;
    rep(i, 9) {
        sum += cN % 10;
        cN /= 10;
    }
    if (N%sum == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define continue continue
#define break break
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	ll n; cin >> n;
	ll ans = n;
	rep2(i, 1, sqrt(n)+1){
		if(n%i == 0){
			ans = min(ans, (i+(n/i))-2);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
c = [input() for j in range(h)]
ans = 0

for rows in range(1 << h):
  for cols in range(1 << w):
    black = 0
    for i in range(h):
      if (rows >> i) & 1:
        continue
      for j in range(w):
        if (cols >> j) & 1:
          continue
        black += c[i][j] == "#"
    if black == k:
      ans += 1
      
print(ans)

Measured memory_bytes: 9036
#include <stdio.h>
#define N 100000

typedef struct{
  int id;
  int parent;
  int child;
  int right_sibling;
} Node;

main(){
  int n, i, j;
  int id, degree, depth, parent;
  int c[N];
  Node node[N];

  scanf("%d", &n);

  for( i = 0; i < n; i++){
    node[i].parent = -1;
    node[i].child = -1;
    node[i].right_sibling = -1;
  }

  for( i = 0; i < n; i++){
    c[0] = -1;
    scanf("%d%d", &id, &degree);

    for( j = 0; j < degree; j++){
      scanf("%d", &c[j]);
    }

    node[id].id = id;
    node[id].child = c[0];

    for( j = 0; j < degree; j++){
      node[c[j]].parent = id;
    }
    for( j = 1; j < degree; j++){
      node[c[j-1]]. right_sibling = c[j];
    }
  }

  for( i = 0; i < n; i++){
    printf("node %d: parent = %d, ", node[i].id, node[i].parent);

    depth = 0;
    parent = node[i].parent;
    while(1){
      if( parent == -1 ) break;
      else {
        parent = node[parent].parent;
        depth++;
      }
    }

    printf("depth = %d, ", depth);

    if( node[i].parent == -1 ){
      printf("root, [");
    }
    else if( node[i].child == -1 ){
      printf("leaf, [");
    }
    else printf("internal node, [");

    if( node[i].child != -1 ){
      printf("%d", node[i].child);
      degree = node[i].child;
      while(1){
        if( node[degree].right_sibling == -1 ) break;
        else {
          printf(", %d", node[degree].right_sibling);
          degree = node[degree].right_sibling;
        }
      }
    }
    printf("]\n");
  }

  return 0;

}

Measured memory_bytes: 2564
use std::io::stdin;

fn main() {
    let mut s = String::new();

    stdin().read_line(&mut s).ok();
    let nums: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    let x = nums[0];
    let y = nums[1];

    stdin().read_line(&mut s).ok();
    let mut ps: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    ps.sort();
    ps.reverse();
    ps = ps[..(x as usize)].to_vec();

    stdin().read_line(&mut s).ok();
    let mut qs: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    qs.sort();
    qs.reverse();
    qs = qs[..(y as usize)].to_vec();

    stdin().read_line(&mut s).ok();
    let mut rs: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    rs.sort();

    ps.append(&mut qs);
    // ps.append(&mut rs);
    ps.sort();
    // ps.reverse();

    rs.reverse();
    let mut res_i: Option<usize> = None;
    for i in 0..rs.len() {
        if rs[i] > ps[i] {
            res_i = Some(i);
        } else {
            break;
        }
    }

    let res: i64;
    if let None = res_i {
        res = ps.iter().sum::<i64>();
    } else {
        res = (ps[res_i.unwrap() + 1..].iter().sum::<i64>()
            + rs[..res_i.unwrap() + 1].iter().sum::<i64>()) as i64;
    }

    // $B8e$O!"MW$O(B bottom rs.len() $B8D$N(B ps $B$K$D$$$F(B
    // allignment $B$NLdBj(B
    // let mut switch_cnt = 0;
    // let mut rs_i = 0;
    // for ps_item in ps.iter_mut() {
    //     while rs_i < rs.len() {
    //         if ps_item < &mut rs[rs_i] {
    //             // *ps_item = rs[rs_i];
    //             switch_cnt += 1;
    //             rs_i += 1;
    //             break;
    //         }
    //         rs_i += 1;
    //     }
    // }
    // rs.reverse();
    // 
    // let res = ps[switch_cnt..].iter().sum::<i64>() + rs[..switch_cnt].iter().sum::<i64>();

    //     for res_elem in ps.iter_mut() {
    //         for rs_i in 0..rs.len() {
    //             if rs[i] {
    //                 rs = rs[rs_i..].to_vec();
    //                 break;
    //             }
    //         }
    //     }
    //
    //
    //
    //         if rs.len() > 0 {
    //             if *res_item < *rs.peek().unwrap() {
    //                 *res_item = rs.pop().unwrap();
    //             } else {
    //                 break;
    //             }
    //         } else {
    //             break;
    //         }
    //     }

    // let res: i64 = ps[..(x + y) as usize].to_vec().iter().sum();

    println!("{}", res);
}


Measured memory_bytes: 11512
program c_stop
    implicit none
    integer(8) n
    integer(8),allocatable :: a(:)
    integer(8) i, ans, sa

    read *,n
    allocate(a(n))
    read *,a

    ans=0
    sa=0
    do i=1,n
        if(i/=n)then
            if(a(i)>a(i+1)) then
            sa=a(i)-a(i+1)
            a(i+1)=a(i+1)+sa
            ans=ans+sa
            end if
        else 
            exit
        end if
    end do
    print *,ans
end program c_stop

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

template <typename T>
T pow(T a, int n){
	T r = 1;
	while(n){
		if(n & 1) r *= a;
		a *= a;
		n >>= 1;
	}
	return r;
}

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	int ans = 1e9;
	for(int i = -100; i <= 100; i++){
		int diff = 0;
		for(int j = 0; j < n; j++) diff += pow(i - a[j], 2);
		ans = min(ans, diff);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring> 
#include<iostream>
#include<set>
using namespace std;
#define N 100005
#define INF 1000000000
#define M 1000000007
int hd[N],nx[2*N],to[2*N],v[N];
long long int fa[N],son[N];
int ls=0;
long long int ans=1;
int n;
long long int k;
void add(int x,int y){
nx[++ls]=hd[x];
hd[x]=ls;
to[ls]=y;

nx[++ls]=hd[y];
hd[y]=ls;
to[ls]=x;
}
void dfs1(int s,int f){
	v[s]=1;
	fa[s]=f;
	for(int i=hd[s];i;i=nx[i])if(!v[to[i]]){
	dfs1(to[i],s);
	}
}
void dfs2(int s){
	long long int ks=k;
	v[s]=0;
	if(fa[s]){
	ks-=son[fa[s]]+1;
	son[fa[s]]++;
	}
	if(fa[fa[s]])ks--;
	ans*=ks;
	ans%=M;
	for(int i=hd[s];i;i=nx[i])if(v[to[i]]){
	dfs2(to[i]);
	}
}
int main(){
memset(son,0,sizeof(son));
memset(v,0,sizeof(v));
memset(hd,0,sizeof(hd));
scanf("%d%lld",&n,&k);
for(int i=1;i<=n-1;i++){
	int x,y;
	scanf("%d%d",&x,&y);
	add(x,y);
}
dfs1(1,0);
dfs2(1);
printf("%lld",ans);
}

Measured memory_bytes: 11128
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()
using namespace std;

const long long MOD = 1000000007;

void solve(long long N, long long M, std::vector<long long> S, std::vector<long long> T){
    vector<vector<LL>> dp(N+1, vector<LL>(M+1, 0));
    rep(i, N+1)dp[i][0]=1;
    rep(i, M+1)dp[0][i]=1;
    rep(i, N){
        rep(j, M){
            dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%MOD;
            if(S[i] != T[j]) {
                if(dp[i + 1][j + 1] <= dp[i][j])dp[i + 1][j + 1]+=MOD;
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] - dp[i][j]) % MOD;
            }
        }
    }
    cout << dp[N][M] << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> S(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&S[i]);
    }
    std::vector<long long> T(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&T[i]);
    }
    solve(N, M, std::move(S), std::move(T));
    return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    char s[100000]={};
    scanf("%s",s);
    int k=strlen(s);
    if(k<=n)
        cout<<s<<endl;
    else if(k>n){
      for(int i=0;i<n;i++){
        printf("%c",s[i]);}
        cout<<"..."<<endl;
    }}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << (X - Z) / (Y + Z) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$N = $key->A[0];
$c1=0;
$c2=0;
$c4=0;
foreach($key->X[0] as $v) {
  $c = $v % 4;
  switch($c) {
  case 1:
  case 3:
    $c1++;
    break;
  case 0:
    $c4++;
    break;
  case 2:
   $c2++;
   break;
  }
}
$flg = false;
if ($c2 == 0) {
  if ($c1 <= $c4+1) {
    $flg = true;
  }
  else {
    $flg = false;
  }
}
else {
  if ($c1 <= $c4) {
    $flg = true;
  }
  else {
    $flg = false;
  }
}
printf("%s\n",$flg?"Yes":"No");


Measured memory_bytes: 33012
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

const int MAXN = 100000;
struct edge {int to, cost;};
int n;
vector<edge> G[MAXN];
int dist[MAXN];

int best_to[MAXN];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(dist, dist + n, INF);
    fill(best_to, best_to + n, -1);
    dist[s] = 0;
    que.push(P(dist[s], s));

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                best_to[e.to] = v;
                que.push(P(dist[e.to], e.to));
            };
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << best_to[i] + 1 << endl;
    }
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        edge e;
        e.to = b, e.cost = 1;
        G[a].push_back(e);
        e.to = a, e.cost = 1;
        G[b].push_back(e);
    }

    dijkstra(0);

    return 0;
}

Measured memory_bytes: 13592
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
constexpr int Inf = 2100000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

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

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

vector<ll> one(200020);
vector<ll> ten(200020);

struct S {
    int len;
    ll val;
};

S op(S a,S b) {
    return S{a.len + b.len,(a.val * ten.at(b.len) + b.val) % MOD};
}

S e() {
    return S{0,0};
}

S mapping(int a,S x) {
    if(a == 0) {
        return x;
    }
    else {
        return S{x.len,one.at(x.len) * a % MOD};
    }
}

int composition(int f,int g) {
    if(f == 0) {
        return g;
    }
    else {
        return f;
    }
}

int id() {
    return 0;
}

int main() {
    int N,Q;
    cin >> N >> Q;
    ten.at(0) = 1;
    for(int i = 1;i < N;i++) {
        one.at(i) = (one.at(i - 1) * 10 + 1) % MOD;
        ten.at(i) = ten.at(i - 1) * 10 % MOD;
    }
    lazy_segtree<S,op,e,int,mapping,composition,id> seg(N);
    for(int i = 0;i < N;i++) {
        seg.set(i,S{1,1});
    }
    for(int i = 0;i < Q;i++) {
        int L,R,D;
        cin >> L >> R >> D;
        L--;
        R--;
        seg.apply(L,R + 1,D);
        S ret = seg.all_prod();
        cout << ret.val << endl;
    }
}

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

using namespace std;

int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if (a+b>c+d) printf("Left");
	else if (a+b==c+d) printf("Balanced");
	else printf("Right");
	return 0; 
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int flag = 0;
    for(int i = 0; i < N; i++){
        if(a[i] % 2 == 1) flag = 1;
    }
    if(flag == 1) cout << "first" <<  endl;
    else cout << "second" << endl;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
s = [-1]
c = [-1]
OK = True
x = 0
for i in range(M):
    s_, c_ = map(int, input().split())
    if N != 1 and s_ == 1 and c_ == 0:
        OK = False
    ok = True
    for i in range(len(s)):
        if s[i] == s_:
            ok = False
            if c[i] != c_:
                OK = False
                break
            break
    if ok:
        s.append(s_)
        c.append(c_)
        x += (10 ** (N - s_)) * c_

if N != 1 and x < 10 ** (N - 1):
    x += 10 ** (N - 1)

if OK:
    print(x)
else:
    print(-1)


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

long long N; vector<long long>vec;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		long long a[3]; cin >> a[0] >> a[1] >> a[2];
		sort(a, a + 3);
		long long E = a[0];
		E += 1000000LL * a[1];
		E += 1000000000000LL * a[2];
		vec.push_back(E);
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	cout << N - (int)vec.size() << endl;
	return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dp[10000][10000];
ll combination(ll n, ll r) {
         if (n == r){dp[n][n] = 1;}
	else if (r == 0) {return dp[n][0] = 1;}
	else if (r == 1) {return dp[n][1]=n;}
	else {dp[n][r]=dp[n - 1][r - 1] % 1000000007 + dp[n - 1][r] % 1000000007;
	return dp[n][r]=combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;}
}
int main() {
	int a;
	double count,ans;
	cin >> a;
	count = 0;
	for (int i = 0;i < a;i++)
	{
		if ((i + 1) % 2 == 1) { count++; }
	}
	ans = count / a;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int number;
  cin >> number;
  int count =0;
  for (int i =0;i<4;i++){
    if(number%10==2){
      count++;
    }
    number =number/10;
  }
  cout << count <<endl;


}

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

using namespace std;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w, n, x, y, ans = 0;
    cin >> h >> w >> n;
    ans = h;
    vector < pair < int, int > > Q;
    for (int i = 1; i <= n; ++i) {
        cin >> x >> y;
        Q.push_back({x, y});
    }
    sort(Q.begin(), Q.end());
    int d = 0;
    for (int i = 0; i < (int)Q.size(); ++i) {
        if (Q[i].first - d == Q[i].second) d++;
        if (Q[i].second < Q[i].first - d) {
            ans = Q[i].first - 1;
            break;
        }
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 2420
#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>

using namespace std;

#define OUT cout <<
#define IN cin >>
#define E << endl;
#define FOR(i,a,b) for(int i = a;i < b;i++)

vector<int> array;

void input(){
	int temp = 0;
	FOR(i, 0, 5){
		IN temp;
		array.push_back(temp);
	}; 
}

int main(){
	input();
	sort(array.begin(), array.end(),greater<int>());
	
	OUT array[0];

	FOR(i, 1, 5){
		OUT " " << array[i];
	}
	OUT endl;
}

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

using namespace std;

string decode(string src, int a, int b) {
    string dst(src);
    int table[26];
    for (int i = 0; i < 26; i++) {
        int c = (a * i + b) % 26;
        table[c] = i;
    }
    for (int i = 0; i < src.size(); i++) {
        if (src[i] != ' ') {
            dst[i] = (char)('a' + table[(int)(src[i] - 'a')]);
        }
    }
    return dst;
}

int gcd(int n, int m) {
    if (n > m) return gcd(m, n);
    if (n == 0) return m;
    return gcd(m % n, n);
}

int main(void) {
    int n;
    cin >> n;
    cin.ignore();
    for (; n--; ) {
        string src;
        getline(cin, src);
        for (int a = 1; ; a++) {
            bool break_flag = false;
            if (gcd(a, 26) != 1) continue;
            for (int b = 0; b < 26; b++) {
                string dst = decode(src, a, b);
                if ((int)dst.find("that") != -1 || (int)dst.find("this") != -1) {
                    cout << dst << endl;
                    break_flag = true;
                    break;
                }
            }
            if (break_flag) break;
        }
    }
    return 0;
}

Measured memory_bytes: 1216
N, M, C = map(int, input().split())

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

A = []
for i in range(N):
    A .append(list(map(int, input().split())))

result= 0

for i in range(N):
    sum = C
    for j in range(M):
        sum  += A[i][j] * B[j]
    if sum > 0:
        result += 1

print(result)


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

int main() {
  int n;
  cin>>n;
  int a=0;
  string s;
  for(int i=0;i<n;i++){cin>>s;if(s=="Y")a++;}
  if(a)cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


int main(){
    int M, N, A, B, C;
    string s1, s2;
    cin >> s1 >> s2;
    int ans = 0;
    rep(i, s1.length()){
        if(s1[i] != s2[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3832
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<stdio.h>
#include<vector>
#define rep(i,n)for(int i=0;i<n;i++)
//printf("%.yf\n",x); xを小数点以下y桁で
using namespace std;
int main() {
    vector <int> data;
    int a, b, c;
    cin >> a >> b >> c;
    data.push_back(a);
    data.push_back(b);
    data.push_back(c);
    sort(data.begin(), data.end());
    cout << data[0] <<" "<< data[1] <<" "<< data[2] << endl;
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  string s;
  cin >> s;
  string ans;
  rep(i,s.size()){
    if(i%2 == 0){
      ans.push_back(s[i]);
    }
  }
  
  cout << ans << endl;
 }

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  map<char, int> M;
  char X[5] = {'M', 'A', 'R', 'C', 'H'};
  REP(i, N) {
    string S;
    cin >> S;
    if(!M.count(S[0])) {
      M[S[0]] = 1;
    } else {
      M[S[0]]++;
    }
  }
  int ans = 0;
  FOR(i, 0, 3) {
    int tmp = 1;
    if(!M.count(X[i])) continue;
    FOR(j, i + 1, 4) {
      if(!M.count(X[j])) continue;
      FOR(k, j + 1, 5) {
        if(!M.count(X[k])) continue;
        tmp = M[X[i]] * M[X[j]] * M[X[k]];
        ans += tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005
ll k;
ll dp[10004][10][102];
ll solve(ll z,ll d,ll m)
{
    m=m%k;
    if(dp[z][d][m]!=-1)
        return dp[z][d][m];
    if(z==0&&d==0)
    {
        return 0;
    }
    if(z==0)
    {
        ll ans=solve(z,d-1,m);
        if(d%k==m)
            ans++;
        ans%=hell;
        dp[z][d][m]=ans;
        return dp[z][d][m];
    }
    if(d==0)
    {
        ll ans=solve(z-1,9,(m%k+k)%k);
        ans=(ans+solve(z-1,0,(m-(9)%k+k)%k))%hell;
        dp[z][d][m]=ans;
        return ans;
    }
    ll ans=0;
    if(d!=1)
        ans=solve(z,d-1,m);
    ans=(ans+solve(z,0,(m-(d-1)%k+k)%k))%hell;
    if(d%k==m)
        ans=(ans+1)%hell;
    dp[z][d][m]=ans;
    return ans;
}
int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,l,m,n;
        string s;
        cin>>s>>k;
        clr(dp,-1);
        dp[0][0][0]=0;
        n=s.size();
        ll ans=0;
        ll x=0;
        for(i=0;i<n;i++)
        {
            if(s[i]=='0')
                continue;
            solve(n-1-i,s[i]-48,(k-x)%k);
            ans=(ans+dp[n-1-i][s[i]-48][(k-x)%k])%hell;
            x=(x+s[i]-48)%k;
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 84736
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
B = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

count = B.sum() - A.sum()

ac = 0
bc = 0
for a, b in zip(A, B):
    if b < a:
        bc += a - b
    if a < b:
        if (b - a) % 2 == 0:
            ac += (b - a) // 2
        else:
            ac += (b - a) // 2 + 1
            bc += 1
if ac > bc:
    x = ac - bc
    ac += x
    bc += 2 * x

ok = bc == ac and bc == count
if ok:
    print('Yes')
else:
    print('No')


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

using namespace std;
using nagai = long long;
#define sz(x) int((x).size())
const int N=100100;
const int Q=200200;
int n,m,q;
string s,t;
int sgn(int x){
	 return (x>0)-(x<0);
}
int dir1[N],dir2[N];

vector<int>occ1[2],occ2[2];
vector<int>inter1,inter2;
const int SZ=8;
bool used[SZ][SZ];
nagai d[SZ][SZ];
const nagai oo=0x3f3f3f3f3f3f3f3f;

struct cmp{
	bool operator()(pair<int,int>a,pair<int,int>b)const{
		if(d[a.first][a.second]!=d[b.first][b.second])
			return d[a.first][a.second]>d[b.first][b.second];
		return a<b;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>q;
	cin>>s>>t;
	for(int i=0;i<n;++i)
		dir1[i]=s[i]=='E'?1:-1;
	for(int i=0;i<m;++i)
		dir2[i]=t[i]=='S'?1:-1;
	for(int i=0;i<n;++i)
		occ1[dir1[i]>0].push_back(i);
	for(int i=0;i<m;++i)
		occ2[dir2[i]>0].push_back(i);
	for(int i=0;i<q;++i){
		 int a,b,c,D;
		 cin>>a>>b>>c>>D;
		 --a,--b,--c,--D;
		 inter1.clear();
		 inter2.clear();
		 for(int d=0;d<2;++d){
			 for(int pt:{a,c}){
				 int kek=lower_bound(occ1[d].begin(),occ1[d].end(),pt)-occ1[d].begin();
				 if(kek!=occ1[d].size())inter1.push_back(occ1[d][kek]);
				 if(kek!=0)inter1.push_back(occ1[d][kek-1]);
			 }
			 for(int pt:{b,D}){
				 int kek=lower_bound(occ2[d].begin(),occ2[d].end(),pt)-occ2[d].begin();
				 if(kek!=occ2[d].size())inter2.push_back(occ2[d][kek]);
				 if(kek!=0)inter2.push_back(occ2[d][kek-1]);
			 }
		 }
		 sort(inter1.begin(),inter1.end());
		 inter1.erase(unique(inter1.begin(),inter1.end()),inter1.end());
		 sort(inter2.begin(),inter2.end());
		 inter2.erase(unique(inter2.begin(),inter2.end()),inter2.end());
		 memset(d,0x3f,sizeof d);
		 auto find=[&](vector<int>&vec,int x){
			 return lower_bound(vec.begin(),vec.end(),x)-vec.begin();
		 };
		 int sx=find(inter1,a);
		 int sy=find(inter2,b);
		 d[sx][sy]=0;
		 memset(used,0,sizeof used);
		 int sz1=inter1.size();
		 int sz2=inter2.size();
		 int tx=find(inter1,c);
		 int ty=find(inter2,D);
		 while(true){
			 nagai mn=oo;
			 int x=-1,y=-1;
			 for(int i=0;i<sz1;++i)
				 for(int j=0;j<sz2;++j)
					 if(!used[i][j]&&d[i][j]<mn)
						 mn=d[i][j],x=i,y=j;
			 if(x==-1)break;
			 if(x==tx&&y==ty){
				 break;
			 }
			 used[x][y]=true;
			 for(int x1=0;x1<sz1;++x1)
				 if(sgn(x1-x)==dir2[inter2[y]])
					 d[x1][y]=min(d[x1][y],d[x][y]+abs(inter1[x]-inter1[x1]));
			 for(int y1=0;y1<sz2;++y1)
				 if(sgn(y1-y)==dir1[inter1[x]]){
					 d[x][y1]=min(d[x][y1],d[x][y]+abs(inter2[y1]-inter2[y]));
				 }
		 }
		 if(d[tx][ty]==oo)
			 cout<<-1<<'\n';
		 else
			 cout<<d[tx][ty]<<'\n';
	}
	return 0;
}



Measured memory_bytes: 3596
until (n, r = gets.split.map(&:to_i)) == [0, 0]
  d = (1..n).to_a.reverse
  r.times do
    p, c = gets.split.map(&:to_i)
    t = d.slice!(p - 1, c)
    d = t.concat(d)
  end
  puts d[0]
end

Measured memory_bytes: 9532
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int i = 0; i < n; i++) {
            int m = sc.nextInt();
            min = Math.min(min, m);
            max = Math.max(max, m);
        }
        System.out.println(max - min);
    }    
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

ll fact[200010];
ll invfact[200010];

ll powMod(ll n, ll p, const int mod = MOD) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    ll t = powMod(n, p / 2);
    return t * t % mod;
  } else {
    return n * powMod(n, p - 1) % mod;
  }
}

ll combMod(int n, int p) { 
  ll ret = fact[n] * invfact[p] % MOD;
  ret = ret * invfact[n - p] % MOD;
  return ret;
}

int main() {

  ll N, K;
  cin >> N >> K;
  K = min(N, K);
  fact[0] = 1;
  invfact[0] = 1;
  repi(i, 1, N + 1) {
    fact[i] = fact[i - 1] * i % MOD;
    invfact[i] = invfact[i - 1] * powMod(i, MOD - 2) % MOD;
  }

  ll ans = 0;
  // ゼロが入る位置の組み合わせを数え上げる
  // nCm * (n-m)Hm = nCm * (n - m + m - 1)Cm = nCm * (n-1)Cm
  // via xHy = (x + y - 1)Cy
  rep(i, K + 1) {
    ll tmp = combMod(N, i) * combMod(N - 1, i) % MOD;
    ans = (ans + tmp) % MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int a=0,b=0;
  char c= '1';
  for(int i=0; i<s.size() ;i++){
    if(s[i] != c)
      a++;
    else
      b++;
    if(c =='1' )
      c ='0';
    else
      c='1';
  }
  if(a<b)
    cout << a << endl;
  else
    cout << b << endl;
  return 0;
}

Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        n: usize,
        a: [usize;n],
        q: usize,
        ope: [[usize;2];q],
    }

    let mut a_num: Vec<usize> = vec![0;100000+1];

    let mut sum = 0;
    for &i in &a {
        a_num[i] += 1;
        sum += i;
    }

    for i in ope {
        //let line: Vec<usize> = i;
        if a_num[i[0]]!=0 {
            sum += i[1]*a_num[i[0]];
            sum -= i[0]*a_num[i[0]];
            a_num[i[1]] += a_num[i[0]];
            a_num[i[0]] = 0;
        }
        
        println!("{}",sum);
    }
}

Measured memory_bytes: 9128