akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int main()
{
	int h, w;
	while (cin >> h >> w)
	{
		if (h*w)
		{
			loop(i, h)
			{
				loop(j, w)
				{
					if((i+j)%2==0)cout << "#";
					else cout << ".";
				}
				cout << endl;
			}
			cout << endl;
		}
		else break;
	}
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<cstring>

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define space ' '
#define kick(t) cout << "Case #" << t << ":" << endl;

typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli a,lli b) {
  lli ans = 1;
  while(b > 0) {
    if(b&1)
      ans = mul(ans, a);
    a = mul(a,a);;
    b >>= 1;
  }
  return ans;
}
bool cmp1(pl a, pl b) {
  return a.first<b.first;
}

bool cmp2(pl a, pl b) {
  return a.second < b.second;
}
void solve() {
  int n;
  cin >> n;
  vector<pl> s;
  for(int i=0; i<n; i++) {
    lli u, v;
    cin >> u >> v;
    s.pb({u+v, u-v});
  }
  sort(all(s), cmp1);
  lli ans=s[n-1].first-s[0].first;
  sort(all(s), cmp2);
  ans=max(ans, s[n-1].second-s[0].second);
  cout << ans << endl;
}

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

  lli testcases=1;
  while(testcases--) {
    solve();
  }
}



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

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    
    if (x < 1 || y < 1){
        cout << "No" << endl;
    } else if ((w < x + r) || (h < y + r)){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define cases int t; cin >> t; while(t--)
#define fast_cin() ios_base::sync_with_stdio(0) 

const int mod = 1e9+7;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main()
{
	int N;
	cin >> N;
	int A[N + 1];
	map <ll, int> mp;
	for(int i=1 ;i <= N; i++)
	{
		cin >> A[i];
		if(mp.find(A[i]) == mp.end())
			mp[A[i]] = 1;
		else
			mp[A[i]] ++;
	}

	
	vector <ll> x;
	vector <ll> y;
	for(auto it = mp.begin(); it != mp.end(); it++)
	{
		if((*it).S >= 2)
			x.pb((*it).F);
		if((*it).S >= 4)
			y.pb((*it).F);
	}
	sort(all(x));
	sort(all(y));

	if(sz(x) < 2 and y.empty())
		cout << 0 << endl;
	else
	{
		if(y.empty())
			cout << x.back() * x[sz(x) - 2] << endl;
		else
			cout << max(y.back() * y.back(), x.back() * x[sz(x) - 2]) << endl;
	}

	return 0;
}

Measured memory_bytes: 6912
n = int(input())
s = list(input())

num_eas = s.count('E')


res = []
res += [num_eas - s[0].count("E")]

for i in range(1,n):
    res += [res[i-1] + s[i-1].count("W") - s[i].count("E")]
    
print(min(res))


Measured memory_bytes: 103912
from collections import deque

def bfs(maze, visited, sy, sx):
  queue = deque([[sy, sx]])
  visited[sy][sx] = 0
  va = 0
  while queue:
    y,x = queue.popleft()
    if visited[y][x] > va :
      va = visited[y][x]
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_y, new_x = y+j, x+k
      if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
        visited[new_y][new_x] = visited[y][x] + 1
        queue.append([new_y, new_x])
  return va

h,w = map(int,input().split())
wall = ''
for i in range(w+2):
  wall += '#'
maze = [wall]
for i in range(h) :
  m1 = input()
  maze.append('#'+m1+'#')
maze .append(wall)

ans = []
for sy in range(1,h+1) :
  for sx in range(1+w+1):
    if maze[sy][sx] == '#' :
      continue
    visited = [[-1]*(w+2) for _ in range(h+2)]
    ans.append(bfs(maze, visited, sy, sx))

print(max(ans))

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

using namespace std;

using ll = long long;


const int inf = 1e6 + 3;


template<class T>
T sqr(T x)
{
	return x * x;
}


ll powmod(ll x, int y)
{
	return y ? (y & 1 ? x * powmod(x, y - 1) : sqr(powmod(x, y / 2))) % inf : 1;
}


ll mult(ll a, ll b)
{
	return (a * b) % inf;
}


int fact (int n)
{
	static vector<int> dp = {1};

	if (n >= (int)dp.size ())
	{
		auto q = fact (n - 1);

		dp.push_back (mult (q, n));
	}

	return dp[n];
}


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	for (int i = 0; i < inf; i++)
		fact (i);

	int q;

	cin >> q;

	for (int i = 0; i < q; i++)
	{
		int x, d, n;

		cin >> x >> d >> n;

		if (d == 0)
			cout << powmod (x, n) << endl;
		else
		{
			auto xd = mult(x, powmod (d, inf - 2));

			if (xd == 0 || xd + n > inf)
				cout << 0 << endl;
			else
				cout << mult (mult (fact (xd + n - 1), powmod (fact (xd - 1), inf - 2)), powmod (d, n)) << endl;
		}
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	cout << fixed;

#ifdef LOCAL
	ifstream fin("../input.txt");

	solve(fin);

	cout << setprecision(4) << "clock: " << clock() / (double) CLOCKS_PER_SEC << endl;
#else
	cout << setprecision(20);

	solve();
#endif

	return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define endl "\n"
    #define sz(x) (int)(x).size()
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
/*.....................................................................................................................*/

    ll mod =(ll)1e9+7;
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
    long long binpow(long long x, long long p) 
    {
        if (p == 0) return 1;
    	if (p == 2 || (p & 1)) return mult(x, binpow(x, p - 1));
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
    // bool check(ll x){}
    ll binsearch(ll l,ll r)
    {
        while(l<r)
        {
            ll mid=(l+r)/2;
            // if(check(mid))r=mid;
            // else l=mid+1;
        }
        return l;
    }
    const ll man=(ll)1005;
    vector<ll>adj[man];
    bool vis[man][man];
    ll d[man],depth[man],par[man];
    void addedge(ll u,ll v){adj[u].pb(v);adj[v].pb(u);}
    ll dx[4]={1,-1,0,0};ll dy[4]={0,0,1,-1};
/*........................................................................................................................*/

signed main()/*Check flow...question galat mat padhna */
{
    fast;  
    ll x,y;
    cin>>x>>y;
    
    
        if(y<=4*x&&y>=2*x&&y%2==0)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        cout<<"No"<<endl;
    
}      


Measured memory_bytes: 3616
#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
#define ALL(x) (x).begin(),(x).end()
// 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<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 == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
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); }

//CODE

void solve(void)
{
  int X,t;
  cin>>X>>t;
  cout<<max(X-t,0LL)<<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
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var list = Enumerable.Range(1, N).Select(s => Console.ReadLine().Split(' ').Select(int.Parse).ToArray()).ToList();
            Func<int[], int[], double> d = (x, y) => Math.Sqrt((x[1] - y[1]) * (x[1] - y[1]) + (x[0] - y[0]) * (x[0] - y[0]));

            var sum = 0.0;
            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    sum += d(list[i], list[j]);
                }
            }

            Console.WriteLine(sum / N * 2);
        }
    }
}

Measured memory_bytes: 13524
loop do
  n = gets.to_i
  break if n==0
  hanako = (1..2*n).to_a
  taro = []
  n.times do
    taro << hanako.delete(gets.to_i)
  end
  taro.sort!
  field = 0
  loop do
    field =  (f=taro.find {|x|x>field}) ? taro.delete(f) : 0
      break if taro.empty?
    field =  (f=hanako.find {|x|x>field}) ? hanako.delete(f) : 0
      break if hanako.empty?
  end
  p hanako.size
  p taro.size
end

Measured memory_bytes: 6160
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    long long addition = ans + K; 
    long long multiplication = ans * 2;
    if (addition < multiplication) ans = addition;
    else ans = multiplication;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int h,w;
    cin >> h >> w;

    rep(i,h){
        rep(j,w){
            string s;
            cin >> s;
            if(s=="snuke"){
                int a = 'A';
                cout << (char)(a+j);
                cout << i+1 << endl;
                return 0;
            }
        }
    }

    return 0;
}
 
 


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

struct data{
  int ax,ay,bx,by,id;
};

int N,ans[10],C;

void solve(vector<data> v){
  if(v.size()==0)return;
  int size=v.size();
  int f=0;
  for(int i=1;i<size;i++){
    if(v[f].ax>v[i].ax){
      f=i;
    }else if(v[f].ax==v[i].ax && v[f].ay>v[i].ay){
      f=i;
    }
  }
  ans[ v[f].id ]=C++;
  int lx=500,rx=v[f].ax,ty=v[f].by;
  for(int i=0;i<size;i++){
    data d=v[i];
    if(d.ay<ty && d.by>ty && d.ax>rx){
      lx=min(lx,d.ax);
    }
  }
  vector< data > L,R;
  for(int i=0;i<size;i++){
    if(i==f)continue;
    data d=v[i];
    if( d.ax>=rx && lx>=d.bx && d.by <= ty ){
      L.push_back(d);
    }else{
      R.push_back(d);
    }
  }
  solve(L);
  solve(R);
}

int main(){
  bool flg=false;
  while(1){
    cin>>N;
    if(N==0)break;
    if(flg)cout<<endl;
    flg=true;
    vector<data> v;
    for(int i=0;i<N;i++){
      data d;
      cin>>d.ax>>d.ay>>d.bx>>d.by;
      if(d.ax>d.bx)swap(d.ax,d.bx);
      if(d.ay>d.by)swap(d.ay,d.by);
      d.id=i;
      v.push_back(d);
    }
    C=1;
    solve(v);
    for(int i=0;i<N;i++){
      cout<<ans[i]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int64 n, m;
  scanf("%lld%lld", &n, &m);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  int low = a[0] * 2, high = a[n - 1] * 2;
  while (low != high) {
    int mid = (low + high + 1) / 2;
    int64 cnt = 0;
    for (int i = 0; i < n; ++i) {
      int j = lower_bound(a.begin(), a.end(), mid - a[i]) - a.begin();
      cnt += n - j;
    }
    if (cnt < m) {
      high = mid - 1;
    } else {
      low = mid;
    }
  }
  // trace(high);
  vector<int64> S(n + 1);
  for (int i = 0; i < n; ++i) S[i + 1] = S[i] + a[i];
  int64 ret = 0, cnt = 0;
  for (int i = 0; i < n; ++i) {
    int j = lower_bound(a.begin(), a.end(), high - a[i]) - a.begin();
    ret += S[n] - S[j];
    ret += (int64)a[i] * (n - j);
    cnt += n - j;
  }
  ret -= (cnt - m) * high;
  printf("%lld\n", ret);
  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int w, h;
	cin >> w >> h;
	vector<pair<ll, ll>> v;
	for(int i=0; i<w; i++){
		ll p;
		cin >> p;
		v.push_back(make_pair(p, 0));
	}
	for(int i=0; i<h; i++){
		ll q;
		cin >> q;
		v.push_back(make_pair(q, 1));
	}
	sort(v.begin(), v.end());

	ll ans=0;
	for(int i=0; i<v.size(); i++){
		if(v[i].second==0){
			ans+=(h+1)*v[i].first;
			w--;
		}else{
			ans+=(w+1)*v[i].first;
			h--;
		}
		if(h==0 && w==0) break;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6384
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    string s;
    scan(s);
    writeln(s.count('+').to!int - s.count('-').to!int);
}









































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <vector>

using namespace std;

int main() {
	int n;
	int a[5];
	int b = 0, c = 0, d = 0, e = 0;
	int count = 0;

	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	for (int i = 0; i < 5; i++) {
		if (a[i] == 0) {
			n = i + 1;
		}
	}

	cout << n;
}

Measured memory_bytes: 3180
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include <map>

using namespace std;
 
int main() {
	long long n,ans;
	cin >> n;
	ans = n*(n - 1)/2;

	cout << ans << endl;

	return 0;
}

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

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

# トポロジカルソート(頂点数、辺集合(DAG, 0-indexed))
def topological_sort(N: int, edges: list) -> list:
    # ここからトポロジカルソート準備
    incnts = [0] * N
    outnodes = [[] for i in range(N)]
    for i in range(len(edges)):
        # 流入するノード数
        incnts[edges[i][1]] += 1
        # 流出先ノードのリスト
        outnodes[edges[i][0]].append(edges[i][1])
    # 流入ノード数が0であるノードのセットS
    S = set()
    for i in range(N):
        if incnts[i] == 0:
            S.add(i)

    # ここからトポロジカルソート
    L = []
    # 暫定セットが空になるまでループ
    while S:
        # 暫定セットから結果リストへ1つ入れる
        L.append(S.pop())
        # 確定させたノードから流出するノードでループ
        for node in outnodes[L[-1]]:
            # 流入ノード数を1減らす
            incnts[node] -= 1
            # 流入ノードが0なら暫定セットへ
            if incnts[node] == 0:
                S.add(node)
    # ソートされた頂点のリストを返却
    return L

N,M=MAP()
edges=[None]*M
for i in range(M):
    s,t=MAP()
    edges[i]=(s, t)

ans=topological_sort(N, edges)
for i in range(N):
    print(ans[i])



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

const int MAX = 305;
int mat[MAX][MAX];
vector<int> x[MAX];
vector<int> y;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  rep(i, h) {
    rep(j, w) {
      char c;
      cin >> c;
      if (c == '#') {
        x[i].push_back(j);
        y.push_back(i);
      }
    }
    x[i].push_back(w);
  }
  y.push_back(h);
  y.erase(unique(y.begin(), y.end()), y.end());
  
  for (int i = 0; i < y.size() - 1; ++i) {
    for (int j = 0; j < x[y[i]].size() - 1; ++j) {
      for (int s = y[i]; s < y[i+1]; ++s) {
        for (int t = (j == 0 ? 0 : x[y[i]][j]); t < x[y[i]][j+1]; ++t) {
          mat[s][t] = k;
        }
      }
      --k;
    }
  }
  for (int i = y[0]-1; i >= 0; --i) {
    for (int j = 0; j < w; ++j) {
      mat[i][j] = mat[i+1][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      cout << mat[i][j];
      if (j < w-1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 2040
#include <iostream>

static void printQq();
static const int Start = 1;
static const int End = 9;

int main(int /* argc */, char **/* argv */)
{
    printQq();

    return 0;
}

static void printQq()
{
    for (int i = Start; i <= End; ++i) {
       for (int j = Start; j <= End; ++j ) {
           std::cout << i << "x" << j << "=" << i * j << std::endl;
       }
    }
}

Measured memory_bytes: 2976
#include <iostream>

int main (void) {
  int K, S;
  std::cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      const int z = S - x - y;
      if (z >= 0 && z <= K)
        ans++;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
    int i,j;
    int h,w;
    
    while(1) {
        scanf("%d %d", &h, &w);

        if(h == 0 && w == 0) {
            break;
        }
        
        for(i = 0; i < h; i++) {
            for(j = 0; j < w; j++) {
                if(i == 0 || i == h-1 || j == 0 || j == w-1) {
                    printf("#");                    
                } else {
                    printf(".");                                        
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>  // ver2.1.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lW,0,a.size()){Vout(a[lW]);}
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n<0)return 0;
  if(n==0)return 1;
  if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(16);
  string s;
  cin >> s;
  int n=s.size();
  Vi a(n),c(n),aq(n),cq(n);
  int qw=0,Q=0;
  
  rep(i,0,n){
    if(s[i]=='A') qw++;
    if(s[i]=='?') Q++;
    a[i]=qw;
    aq[i]=Q;
  }
  
  qw = 0,Q=0;
  repreq(i,n-1,0){
    if(s[i]=='C') qw++;
    if(s[i]=='?') Q++;
    c[i]=qw;
    cq[i]=Q;
  }
  /*Vout(a);
  Vout(aq);
  Vout(c);
  Vout(cq);*/
  int ans = 0,memo=1;
  
  rep(i,1,n-1){
    memo = 1;
    if(s[i]=='B'||s[i]=='?'){
      memo *= ((c[i+1])*mypow(3,cq[i+1],MOD)%MOD+(cq[i+1])*mypow(3,cq[i+1]-1,MOD)%MOD);
      memo *= ((a[i-1])*mypow(3,aq[i-1],MOD)%MOD+(aq[i-1])*mypow(3,aq[i-1]-1,MOD)%MOD);
      ans += memo;
      ans %= MOD;
    }
  }
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define INF (1e9)
#define M 10005
#define N 105
#define L 55
#define C 20
using namespace std;
typedef pair<int,int> P;
int n,m,c,s,g,x,y,id,ic,p[C],q[L],r[L];
int cost1[C][N][N];
int cost2[C][M];
int d[N];
 
int tocost(int a,int b){
  if(b<M)return cost2[a][b];
  return cost2[a][M-1]+(b-M+1)*(cost2[a][M-1]-cost2[a][M-2]);
}
 
int dijkstra(){
  priority_queue<P,vector<P>,greater<P> > Q;
  for(int i=0;i<n;i++)d[i]=INF;
  d[s]=0;
  Q.push(P(0,s));
  while(!Q.empty()){
    P t=Q.top(); Q.pop();
    int cost=t.first,u=t.second;
    if(u==g)return cost;
    if(d[u]<cost)continue;
    for(int k=0;k<c;k++){
      for(int i=0;i<n;i++){
    if(cost1[k][u][i]==INF)continue;
    int ncost=cost+tocost(k,cost1[k][u][i]);
    if(d[i]>ncost){
      d[i]=ncost;
      Q.push(P(ncost,i));
    }
      }
    }
  }
  return -1;
}
 
int main(){
  while(1){
    cin>>n>>m>>c>>s>>g;
    if(!n&&!m&&!c&&!s&&!g)break;
    s--,g--;
    for(int i=0;i<C;i++)
      for(int j=0;j<N;j++)
    for(int k=0;k<N;k++)
      cost1[i][j][k]=INF;
    for(int i=0;i<m;i++){
      cin>>x>>y>>id>>ic;
      x--,y--,ic--;
      cost1[ic][x][y]=cost1[ic][y][x]=min(cost1[ic][x][y],id);
    }
    for(int l=0;l<c;l++)
      for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        cost1[l][i][j]=min(cost1[l][i][j],cost1[l][i][k]+cost1[l][k][j]);
    for(int i=0;i<c;i++)cin>>p[i];
    for(int i=0;i<c;i++){
      for(int j=0;j<p[i]-1;j++)cin>>q[j];
      for(int j=0;j<p[i];j++)cin>>r[j];
      int idx=0;
      for(int j=1;j<M;j++){
    cost2[i][j]=cost2[i][j-1]+r[idx];
    if(idx<p[i]-1&&j==q[idx])idx++;
      }
    }
    cout<<dijkstra()<<endl;
    memset(cost2,0,sizeof(cost2));
  }
  return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  ll flag = 0;
  ll i = 0;
  while(i<n){
    if(k==0){
      for(int j=i;j<n;j++){
        if(flag ^ s[j]=='A') cout << 'A';
        else cout << 'B';
      }
      rep(j,i){
        if(flag ^ (j&1)) cout << 'A';
        else cout << 'B';
      }
      cout << endl;
      return 0;
    }

    if(flag ^ s[i]=='A'){
      if(s[i] == 'A') s[i] = 'B';
      else s[i] = 'A';
    }else{
      flag = 1 - flag; i++;
    }
    k--;
  }

  if(1-flag){
    if(n&1){
      s = "";
      rep(j,n){
        if(j&1) s[j] = 'A';
        else s[j] = 'B';
      }

      i = 0;
      while(i<n){
        if(k==0){
          for(int j=i;j<n;j++){
            if(flag ^ s[j]=='A') cout << 'A';
            else cout << 'B';
          }
          rep(j,i){
            if(flag ^ (j&1)) cout << 'A';
            else cout << 'B';
          }
          cout << endl;
          return 0;
        }

        if(flag ^ s[i]=='A'){
          if(s[i] == 'A') s[i] = 'B';
          else s[i] = 'A';
        }else{
          flag = 1 - flag; i++;
        }
        k--;
      }
    }else{
      rep(j,n){
        if(j&1) cout << 'A';
        else cout << 'B';
      }
      cout << endl;
      return 0;
    }
  }
  rep(j,n){
    if(j == 0 && (k&1)) cout << 'B';
    else if(j&1) cout << 'B';
    else cout << 'A';
  }
  cout << endl;
}


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

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

const long long INF = 1LL << 60;

vector<int> vec(100000);
vector<long long> memo(100000);

int solve(int i){
  if(memo[i] < INF) return memo[i];
  if(i == 0) return 0;
  int res;
  res = solve(i-1) + abs(vec.at(i) - vec.at(i-1));
  if(i > 1) chmin(res, solve(i-2) + abs(vec.at(i) - vec.at(i-2)));
  return memo[i] = res;
}

int main(){
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++) {
      memo.at(i) = INF;
  }
  
  cout << solve(N-1) << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int S = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        S ^= A[i];
    }
    for(int i=0; i<N; i++) cout << (S^A[i]) << " \n"[i==N-1];
    return 0;
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}


int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    int n,m;
    scn2(n,m);

    vector<int>v[m];

    for(int i=0; i<m; i++){

        int x;
        scn(x);

        while(x--){
            int y;
            scn(y);
            v[i].pb(y);
        }
    }

    int p[m+1];

    for(int i=0; i<m; i++)scn(p[i]);

    int mx = 1<<n;
    int ans=  0;
    for(int mask = 0; mask<mx; mask++){
        int al = m;
        for(int i=0; i<m; i++){
            int cnt = 0;
            for(int j : v[i]){
                cnt += check(mask,j-1);
            }
            if(cnt%2 == p[i])al--;
        }
        if(al == 0)ans++;
    }
    cout<<ans;

    return 0;
    ///return main();
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///priority_queue< int, vector< int >, greater< int > > minHeap;
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 256
<?php
  declare(strict_types=1);

  $s = trim(fgets(STDIN));
  
  $n = strlen($s);
  while ($n -= 2)
  {
      $init = substr($s, 0, $n / 2);
      $tail = substr($s, $n / 2, $n / 2);
      if ($init === $tail)
      {
          echo strlen($init) * 2, PHP_EOL;
          exit;
      }
  }

  throw new Exception("solution not found");


Measured memory_bytes: 4728
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll ans = 0;
  if (2 * C > A + B) {
    ans += A * X + B * Y;
  } else {
    ll minVal = min(X, Y);
    ans += minVal * 2 * C;
    X -= minVal;
    Y -= minVal;
    if (X == 0) {
      if (B > 2 * C)
        ans += 2 * C * Y;
      else
        ans += B * Y;
    } else {
      if (A > 2 * C)
        ans += 2 * C * X;
      else
        ans += A * X;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val r = sc.nextInt
    val D = sc.nextInt
    val x2000 = sc.nextInt
    calc(1, x2000, r, D)
  }

  def calc(count: Int, x: Int, r: Int, D: Int): Int = count match {
    case count if count > 10 => x
    case _ => {
      val result = r * x - D
      println(result)
      calc(count + 1, result, r, D)
    }
  }
}

Measured memory_bytes: 25908
a,b,k = map(int,input().split())

yakusuu_array = []

for ab in [a,b]:
    yakusuu_array_ab = []
    for i in range(1,ab+1):
        if ab % i == 0:
            yakusuu_array_ab.append(i)
    yakusuu_array.append(yakusuu_array_ab)

kouyakusuu = list(set(yakusuu_array[0]) & set(yakusuu_array[1]))
kouyakusuu.sort()

if len(kouyakusuu) == 0:
    print(1)
else:
    print(kouyakusuu[-k])


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

int gcd(int n, int s)
{
	while (n != s)
	{
		if (n > s)
			n -= s;
		else
			s -= n;
	}
	return n;
}

int main()
{
	int W, H, C;
	cin >> W >> H >> C;
	
	int x = gcd(W, H);

	cout << W / x*H / x*C << endl;
	return 0;
}

Measured memory_bytes: 3100
//package april2020;

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main {
//	static long[] dp;
	static int n,k, h[],a[];
	static long MOD = (long)1e9+7;
//	static ArrayList<Integer>[] graph;
//	static HashSet<Integer> visited;
//	static long[][] dp;
//	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		FastReader scn = new FastReader();
		OutputStream out = new BufferedOutputStream ( System.out );
		n = scn.nextInt();
		h = new int[n];
		a= new int[n];
		for(int i =0;i<n;i++) {
			h[i] = scn.nextInt();
		}
		for(int i =0;i<n;i++) {
			a[i] = scn.nextInt();
		}
		int base = 1;
		while(base<=n) {
			base*=2;
		}
		long[] tree = new long[2*base];
		long[] dp = new long[n+1];
//		for(int i =0;i<n;i++) {
//			dp[i] = a[i];
//		}
		for(int flower=0;flower<n;++flower) {
			
			int x = h[flower]+base;
			
			long best = 0;
			while(x>1) {
				if(x%2==1) {
					best = Math.max(best, tree[x-1]);
				}
				x/=2;
			}
			dp[h[flower]] = a[flower]+best;
			for(int i=base+h[flower];i>=1;i/=2) {
				tree[i] = Math.max(tree[i], dp[h[flower]]);
			}
//			for(int i=0;i<flower;i++) {
//				if(h[flower]>h[i]&&dp[i]+a[flower]>dp[flower]) {
//					dp[flower]=dp[i]+a[flower];
//				}
//			}
		}
		long ans= Long.MIN_VALUE;
		for(int i =0;i<=n;i++) {
			ans =Math.max(ans, dp[i]);
		}
		out.write((ans+"\n").getBytes());
		out.close();
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 68772
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using ll = long long;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n+1), b(n);
	REP(i, n+1) {
		cin >> a[i];
	}
	REP(i, n) {
		cin >> b[i];
	}
	ll ans = 0;
	if (b[0] > a[0]) {
		b[0] -= a[0];
		ans += a[0];
		a[0] = 0;
	}
	else {
		a[0] -= b[0];
		ans += b[0];
		b[0] = 0;
	}
	REP(i, n+1) {//i番目の敵のとき
		if (i != 0) {
			if (b[i - 1] > 0) {//i-1番目の勇者
				if (a[i] > b[i - 1]) {//敵の数が多いとき
					a[i] -= b[i - 1];
					ans += b[i - 1];
					b[i - 1] = 0;
				}
				else {
					b[i - 1] -= a[i];
					ans += a[i];
					a[i] = 0;
				}
			}
		}
		if (i != n+1) {
			if (b[i] > a[i]) {
				b[i] -= a[i];
				ans += a[i];
				a[i] = 0;
			}
			else {
				a[i] -= b[i];
				ans += b[i];
				b[i] = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
A = tuple(map(int, input().split()))
direction = 0  # 0=slide, 1=up, 2=down
temp = A[0]
count = 1

for i in A:
    if direction == 0:
        if i > temp:
            temp = i
            direction = 1
        elif i < temp:
            temp = i
            direction = 2
        else:
            temp = i

    elif direction == 1:
        if i >= temp:
            temp = i
        else:
            temp = i
            count += 1
            direction = 0

    elif direction == 2:
        if i <= temp:
            temp = i
        else:
            temp = i
            count += 1
            direction = 0

print(count)

Measured memory_bytes: 14352
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

int main(){
	ll N, K;
	cin >> N >> K;

	vector<ll> V(N);
	rep(i, N) cin >> V[i];


	ll ans = 0;
	for(ll l = 0; l <= min(K, N); l++) {
		for(ll r = 0; r <= min(K - l, N - l); r++) {
			ll rest = K - l - r;

			vector<ll> vec;	
			for(ll i = 0; i < l; i++) vec.push_back(V[i]);
			for(ll i = 0; i < r; i++) vec.push_back(V[N-1-i]);

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

			ll sum = 0;
			for(ll i = 0; i < vec.size(); i++) {
				if(i < rest && vec[i] < 0) continue;
				sum += vec[i];
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 3600
#include <iostream>
#include <list>
using namespace std;
int main(){

  int q;
  list <int> a;
  cin>>q;

  auto it=a.end();

  for(int i=0;i<q;i++){
    int n,x;
    cin>>n;
    if(!n){
      cin>>x;
      a.insert(it,x);
      it--;
    }
    else if(n==1){
      cin>>x;
      advance(it,x);
    }
    else it=a.erase(it);
  }

  for(int e:a) cout<<e<<endl;

  return 0;

}



Measured memory_bytes: 18612
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int main(void) {
	string s;

	int total = 0;

	while (cin >> s) {
		replace_if(s.begin(), s.end(), [](char c){ return !isdigit(c); }, ' ');
		
		istringstream iss(s);
		int num;
		while (iss >> num) {
			total += num;
		}
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 1220
from collections import Counter
n = int(input())
a = list(map(int,input().split()))

c = Counter(a)
key = c.keys()
f = []
ans = 0

for i in key:
    if i < c[i]:
        ans += c[i] - i
    elif i > c[i]:
        ans += c[i]

print(ans)

Measured memory_bytes: 18676
#include <iostream>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;
const int INF = 1001001001;

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

    int cnt_w = 0;
    int cnt_e = 0;

    rep(i, n) {
        if (s[i] == 'W') cnt_w++;
        else cnt_e++;
    }

    int ans = INF;
    int change_w = 0;
    int change_e = cnt_e;

    rep(i, n) {
        if (s[i] == 'E') {
            change_e--;
        }
        if (change_e + change_w <= ans) {
            ans = change_e + change_w;
        }
        if (s[i] == 'W') {
            change_w++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, sz[N];
vector <pair <int, int> > v[N];
ll ans;

void dfs(int node, int pnode){
    sz[node] = 1;
    for(auto &i : v[node]){
        int to = i.first;
        int cost = i.second;
        if(to == pnode) continue;
        dfs(to, node);
        sz[node] += sz[to];
        ans += 2LL * min(sz[to], n - sz[to]) * cost;
    }
}
int find(int node, int pnode){
    for(auto &i : v[node]){
        if(i.first == pnode || sz[i.first] <= n / 2) continue;
        return find(i.first, node);
    }
    return node;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0 ; i < n - 1 ; i++){
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back(make_pair(y, z));
        v[y].push_back(make_pair(x, z));
    }
    dfs(1, 0);
    int cen = find(1, 0);
    int ans2 = 1e9;
    for(auto &i : v[cen]){
        if(2 * sz[i.first] == n) finish(ans - i.second);
        ans2 = min(ans2, i.second);
    }
    cout << ans - ans2 << endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define int LL
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

const int MXN = 3e5+5;
int in[MXN];

int32_t main()
  {
  ios_base::sync_with_stdio(0); 
  int n;
  cin >> n;
  int x = 0;
  REP(i, n)
    {
    cin >> in[i];
    x ^= in[i];
    }
  REP(i, n)cout << (x ^ in[i]) << " ";
  }

/*

4

1101
1110
1011
0111

*/

Measured memory_bytes: 5144
#include<stdio.h> 
int main()
{
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF){
		int x=a*100+b*10+c;
		if(x%4==0)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128