akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100005
using namespace std;
typedef long long ll;
int n,b[N],m,t[N<<3];
ll K,a[N],s[N],L[N],R[N],v[N<<1],f[N];
void update(int k,int l,int r,int L,int R,int val){
	if(L>R) return;
	if(L<=l&&R>=r){
		t[k]=val;
		return;
	}
	if(t[k]) t[k<<1]=t[k<<1|1]=t[k],t[k]=0;
	int mid=l+r>>1;
	if(L<=mid) update(k<<1,l,mid,L,R,val);
	if(R>mid) update(k<<1|1,mid+1,r,L,R,val);
}
int query(int k,int l,int r,int x){
	if(l==r) return t[k];
	if(t[k]) t[k<<1]=t[k<<1|1]=t[k],t[k]=0;
	int mid=l+r>>1;
	if(x<=mid) return query(k<<1,l,mid,x);
	else return query(k<<1|1,mid+1,r,x);
}
ll calc(int x){
	int y=query(1,1,m,x);
	if(!y) return 0;
	return f[y]+(v[L[y]]-v[x]+K)%K;
}
int main(){
	scanf("%d%lld",&n,&K);
	for(int i=1;i<=n;i++){
		scanf("%lld%d",&a[i],&b[i]);
		s[i]=s[i-1]+a[i];
		if(b[i]==1&&a[i]+a[i]>K){
			puts("-1");
			return 0;
		}
	}
	for(int i=1;i<=n;i++){
		if(b[i]==1){
			L[i]=((-2*s[i-1])%K+K)%K;
			R[i]=((-2*s[i])%K+K)%K;
		}else L[i]=0,R[i]=K-1;
	}
	for(int i=1;i<=n;i++) v[++m]=L[i],v[++m]=R[i];
	sort(v+1,v+m+1);
	m=unique(v+1,v+m+1)-v-1;
	for(int i=n;i;i--){
		L[i]=lower_bound(v+1,v+m+1,L[i])-v;
		R[i]=lower_bound(v+1,v+m+1,R[i])-v;
		f[i]=calc(L[i]);
		if(L[i]>R[i]) update(1,1,m,R[i]+1,L[i]-1,i);
		else update(1,1,m,1,L[i]-1,i),update(1,1,m,R[i]+1,m,i);
	}
	ll ans=1e18;
	for(int i=1;i<=m;i++){
		ans=min(ans,calc(i));
	}
	printf("%lld",ans+s[n]+s[n]);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  int answer = 0;
  for(int j = 0;j < N;j++) {
    answer = answer + vec.at(j) - 1;
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
s=input()

h=""
if s[0]=="0":
    if len(s)%2==0:
        for i in range(int(len(s)/2)):
            h+="0"
            h+='1'
    else:
        for i in range(int(len(s)/2)):
            h+='0'
            h+='1'
        h+='0'
else:
    if len(s)%2==0:
        for i in range(int(len(s)/2)):
            h+="1"
            h+='0'
    else:
        for i in range(int(len(s)/2)):
            h+='1'
            h+='0'
        h+='1'

ans=0
for i in range(len(s)):
    if h[i]!=s[i]:
        ans+=1

print(ans)

Measured memory_bytes: 3316
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    a, b, c, x, y = map(int, input().split())
    lim = max(x, y)
    ans = 10**12
    for i in range(lim+1):
        price = a*max(0, x-i) + b*max(0, y-i) + c*2*i
        ans = min(ans, price)
    print(ans)

if __name__ == '__main__':
    main()
    

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

using namespace std;

int n, k;
int a[200001];
int l = 0, r = 0;
int ans = 0x3f3f3f3f;
int main( ) {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i ++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= k; i ++) {
		if (a[i] >= 0) l = max(l, a[i]);
		if (a[i] <= 0) r = max(r, -a[i]);
	}
	for (int i = 1; i <= n - k + 1; i ++) {
		ans = min(ans, l + r + min(l, r));
		if (a[i + k] >= 0) l = a[i + k];
		else l = 0;
		if (a[i + 1] <= 0) r = -a[i + 1];
		else r = 0;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n; 
    cin>>n;
    ll a[n];
    ll s[n], p[n];
    for(ll i=0;i<n; i++)
    {
        cin>>a[i];
    }
    s[0] = a[0];
    p[0] = a[n-1];
    for(ll i=1; i<(n-1); i++)
    {
        s[i] = a[i]^s[i-1];
        p[i] = p[i-1]^a[n - i -1];
    }
    for(ll i=0; i<n; i++)
    {
       if(i==0)
       {
           cout<<p[n-2]<<" ";
       }
       else if(i==(n-1))
       {
           cout<<s[n-2]<<'\n';
       }
       else
       {
           ll x = s[i]^p[n - i - 1];
           cout<<x<<" ";
       }
       
    }
}

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


int main()
{


    int n;
    cin>>n;

    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin>>A.at(i);
    }

    vector<int> B(n);
    B=A;

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

    for(int i=0;i<n;i++){
        if(B.at(i)!=A.at(n-1))
            cout<<A.at(n-1)<<endl;
        else
            cout<<A.at(n-2)<<endl;
    }

    return 0;
}   

Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#define ll long long 
using namespace std;

int main() {
	ll a;
	cin >> a;
	ll b = 0, c = 1;
	for (;; b++) {
		if (a <= c)break;
		c *= 3;
	}
	cout << b << endl;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 1000000007;

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

constexpr ll flen = 2000;
ll fact[flen+1];
ll ifact[flen+1];

ll comb(ll n, ll k) {
  return fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}

int main() {
  fact[0] = 1;
  REP(i,flen) {
    fact[i+1] = fact[i] * (i+1) % MOD;
  }
  ifact[flen] = inv(fact[flen], MOD);
  REP(ri,flen) {
    int i = flen - ri;
    ifact[i-1] = ifact[i] * i % MOD;
  }
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  vector<vecll> pif(flen, vecll(flen));
  REP(i,flen) {
    pif[i][0] = 1;
    REP(j,flen-1) {
      pif[i][j+1] = pif[i][j] * ifact[i] % MOD;
    }
  }
  vecll dp(n+1, 0);
  dp[0] = 1;
  FOR(i,a,b+1) {
    vecll tmp = dp;
    FOR(j,c,d+1) {
      int num = i*j;
      if (num > n) break;
      FOR(k,num,n+1) {
        ll val = dp[k-num] * comb(n-k+num, num) % MOD * fact[num] % MOD;
        val *= pif[i][j] * ifact[j] % MOD;
        val %= MOD;
        tmp[k] += val;
        tmp[k] %= MOD;
      }
    }
    swap(dp, tmp);
  }
  cout<<dp[n]<<endl;
  return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

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

  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  int s = 0, t = 0;
  ll sum1 = 0, sum2 = 0;
  ll ans = 0;
  while(s < n){
      while(t < n && sum1 + a[t] == (sum2 ^ a[t])) {
          sum1 += a[t];
          sum2 ^= a[t];
          t++;
      }
      ans += 1LL * (t - s);
      sum1 -= a[s];
      sum2 ^= a[s];
      s++;
  }

  pl(ans)

  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] ds = new long[N];
			for(int i = 0; i < N; i++) { ds[i] = sc.nextLong(); }
			
			long answer = 0;
			for(int i = 0; i < N; i++) {
				for(int j = i + 1; j < N; j++) {
					answer += ds[i] * ds[j];
				}
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21716
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC X(100).
       01  a1 PIC S9(08).
       01  a2 PIC S9(08).
       01  r1 PIC S9(08).
       01  r2 PIC S9(08).
       01  r3 PIC S9(08).
       01  r pic S9(08).
       01 disp pic Z(20)9.
       PROCEDURE DIVISION.
        ACCEPT indata.
        
        UNSTRING indata DELIMITED BY SPACE INTO a1 a2.


        IF a1 <= 5 THEN
          DISPLAY "0"
        ELSE IF 6 <= a1 AND a1 <= 12 THEN
          divide a2 by 2 giving r2
          MOVE FUNCTION TRIM(r2) to disp
          DISPLAY disp
        ELSE
          MOVE FUNCTION TRIM(a2) to disp
          DISPLAY disp
        END-IF
        END-IF


       STOP RUN.


Measured memory_bytes: 636
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>

using namespace std;

#define reE(i,a,b) for(auto (i)=(a);(i)<=(b);(i)++)
#define rE(i,b) reE(i,0,b)
#define reT(i,a,b) for(auto (i)=(a);(i)<(b);(i)++)
#define rT(i,b) reT(i,0,b)
#define rep(i,a,b) reE(i,a,b);

#define rev(i,a,b) for(auto (i)=(b)-1;(i)>=(a);(i)--)
#define itr(i,b) for(auto (i)=(b).begin();(i)!=(b).end();++(i))
#define LL long long
#define all(b) (b).begin(),(b).end()

#define input_init stringstream ss; string strtoken, token; istringstream is
#define input_line  getline(cin, strtoken);is.str(strtoken);is.clear(istringstream::goodbit)
#define input_token(num) ss.str(""); ss.clear(stringstream::goodbit); getline(is, token, ','); ss << token; ss >> num

typedef complex<double> P;
typedef vector<P> Poly;

const LL INF = 1 << 30;
const double eps = 1e-8;


inline double dot(const P a, const  P b){//A dot B
	return a.real()*b.real() + a.imag()*b.imag();
}

inline double cross(const P a, const P b){//A cross B
	return a.real()*b.imag() - a.imag()*b.real();
}

bool less_P(const P& l, const P& r){
	if (l.real() == r.real())
		return l.imag() < r.imag();
	else return l.real() < r.real();
}

inline void convex_hull(Poly p, Poly& res){
	int k = 0, t;
	res.resize(2 * p.size());
	sort(all(p),less_P);
	reT(i, 0, (int)p.size()){
		while (k > 1 && (cross(res[k - 1] - res[k - 2], p[i] - res[k - 1])<eps))k--;
		res[k++] = p[i];
	}
	t = k;
	rev(i, 0, (int)p.size() - 1){
		while (k > t && (cross(res[k - 1] - res[k - 2], p[i] - res[k - 1])<eps))k--;
		res[k++] = p[i];
	}
	res.resize(k-1);
}





int main(void){
	int n;
	double x, y;
	Poly p, q;
	input_init;
	while (true){
		input_line;
		input_token(n);
		if (n == 0)break;
		p.resize(n);
		rT(i, n){
			input_line;
			input_token(x);
			input_token(y);
			p[i].real(x);
			p[i].imag(y);
		}
		convex_hull(p, q);
		cout << n - q.size() << endl;
	}

	return(0);
}

Measured memory_bytes: 3280
#include <stdio.h>
#define N 100

int main(){
  int i,n,fib[N];

  scanf("%d",&n);

  fib[0]=1;
  fib[1]=1;
  
  for(i=2;i<=n;i++){
      fib[i]=fib[i-1]+fib[i-2];
  }

  printf("%d\n",fib[n]);
  return 0;
}



Measured memory_bytes: 2088
#include <cstdio>
#define ri register int
typedef long long ll;
const int mod=998244353,N=5e5+5;
int fac[N],ifac[N];
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
inline int C(ri n,ri m){
	return m<0||n<m?0:(ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline int min(ri x,ri y){
	return x<y ? x:y;
}
inline int max(ri x,ri y){
	return x>y ? x:y;
}
int main(){
	ri n,m,i,ans,l;
	scanf("%d%d",&n,&m);
	l=max(n,m);
	fac[0]=1;
	for(i=1;i<=l;++i) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[l]=fpow(fac[l],mod-2);
	for(i=l;i;--i) ifac[i-1]=(ll)ifac[i]*i%mod;
	l=min(n,m);
	ans=0;
	for(i=0;i<=l;++i)
		if(i&1)
			ans=(ans-(ll)C(n,i)*C(m,i)%mod*fac[i]%mod*fpow(m+1,n-i)%mod*fpow(n+1,m-i))%mod;
		else
			ans=(ans+(ll)C(n,i)*C(m,i)%mod*fac[i]%mod*fpow(m+1,n-i)%mod*fpow(n+1,m-i))%mod;
	ans=ans<0?ans+mod:ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096
//#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=998244353;
const int maxn=1e6+100;
const int N=2e5+100;
const int M=2e6+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


int main()
{
#ifdef local
      freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // local
    IOS;cout.tie(0);
    int n;cin>>n;
    cout<<n+n*n+n*n*n<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
const int maxn = 46, mlg = 18, rt = 1<<10, mod = 1e9 + 7;
int dp[50][100003];
void mq(int &a, int b) {
	a = min(a, b);
}
int ok[100003], vis[100003];
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	memset(dp, 0x4f, sizeof dp);
	dp[0][0] = 0;
	int ans = 1<<30;
	for(int i = 0; i < 47; i++) {
		
		memset(ok, 0x4f, sizeof ok);
		memset(vis, 0, sizeof vis);
		for(int z = 0; z < n; z++) {
			if(vis[z]) continue;
			int g = z, mn = dp[i][g];
			vi t;
			while(!vis[g]) {
				vis[g] = 1;
				mq(mn, dp[i][g]);
				t.pb(g);
				g = g*10%n;
			}
			for(auto x : t) dp[i][x] = mn;
		}
		
		for(int r = 0; r < n; r++) {
			for(int d = i==0; d < 10; d++) {
				mq(dp[i+1][(r*10 + d)%n], dp[i][r] + d);
			}
		}
		if(i)
			ans = min(ans, dp[i][0]);
	}
	cout << ans;
} 


Measured memory_bytes: 21436
import java.util.Scanner;

public class Main {

    private static Scanner scanner;
    private static final int HH_TIME = 3600;
    private static final int MM_TIME = 60;

    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        System.out.println(timeChangeHMS(scanner.nextInt()));
    }

    /*
     * 秒数からHH:MM:SSで変換します。
     */
    private static String timeChangeHMS(int input) {
        Integer hh = 0;
        Integer mm = 0;
        Integer ss = 0;
        if (input >= HH_TIME) {
            Integer mm_s = 0;
            hh = input / HH_TIME;
            mm_s = input % HH_TIME;
            if (mm_s >= MM_TIME) {
                mm = mm_s / MM_TIME;
                ss = mm_s % MM_TIME;
            } else {
                ss = mm_s;
            }
        } else {
            mm = input / MM_TIME;
            ss = input % MM_TIME;
        }
        return hh.toString() + ":" + mm.toString() + ":" + ss.toString();
    }
}

Measured memory_bytes: 17176
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
 
int dp[10][60][10];
int co[10][60][10];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	rep(i,10)rep(j,60)rep(k,10)dp[i][j][k]=co[i][j][k]=0;
	
	rep(i,10)rep(j,10){
		int a=i+j;
		if(a<10){
			dp[i][0][j]=a;
			co[i][0][j]=1;
		}else{
			dp[i][0][j]=a/10+a%10;
			co[i][0][j]=2;
		}
		if(i==0)co[i][0][j]--;
	}
	rep(j,59)rep(i,10)rep(k,10){
		int a=dp[i][j][k];
		int c=co[i][j][k]+co[a][j][k];
		a=dp[a][j][k];
		dp[i][j+1][k]=a;
		co[i][j+1][k]=c;
	}
	int n;
	cin>>n;
	int out=0,t=0;
	while(n--){
		int a,b;
		cin>>a>>b;
		rep(i,60)if(1ll<<i&b){
			out+=co[t][i][a];
			t=dp[t][i][a];
		}
	}
	cout<<out<<endl;
}












Measured memory_bytes: 384
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String sum = "";
        for (int i = 0; i < S.length(); i++) {
            sum += "x";
        }
        System.out.println(sum);
    }
}

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

using namespace std;
typedef long long ll;

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

  char pre = '*';
  ll count = 0;

  for(auto i : s){
    if(i == pre) continue;
    pre = i;
    count++;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 512
n = int(input())
mod = 10 ** 9 + 7
dp = [[0] * 4 for _ in range(n)]

# A / C / G / T
dp[0] = [1, 1, 1, 1]
dp[1] = [4, 4, 4, 4]
# AGC, ACG, GAC, A?GC,AG?C -> AGGC, ATGC,AGTC

for i in range(2, n):
    if i == 2:
        dp[i][0] = dp[i - 1][0] * 4
        dp[i][1] = dp[i - 1][1] * 4 - 2
        dp[i][2] = dp[i - 1][2] * 4 - 1
        dp[i][3] = dp[i - 1][3] * 4
    else:
        dp[i][0] = sum(dp[i - 1])
        # -AGC -CAG -A**C
        dp[i][1] = sum(dp[i - 1]) - dp[i - 2][0] - dp[i - 2][2] - dp[i - 3][0] * 3
        # -ACG
        dp[i][2] = sum(dp[i - 1]) - dp[i - 2][0] + dp[i - 3][2]
        dp[i][3] = sum(dp[i - 1])


print(sum(dp[n - 1]) % mod)


Measured memory_bytes: 3064
using System;
using System.Text;
using CompLib.Util;

public class Program
{
    private int N;
    private int[] A;
    private int Q;
    private int[] B, C;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();
        Q = sc.NextInt();
        B = new int[Q];
        C = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            B[i] = sc.NextInt();
            C[i] = sc.NextInt();
        }

        var sb = new StringBuilder();
        long sum = 0;
        int[] cnt = new int[100001];
        foreach (int i in A)
        {
            cnt[i]++;
            sum += i;
        }


        for (int i = 0; i < Q; i++)
        {
            int tmp = cnt[B[i]];
            long t = (long) (C[i] - B[i]) * tmp;
            sum += t;
            cnt[B[i]] = 0;
            cnt[C[i]] += tmp;

            sb.AppendLine(sum.ToString());
        }

        Console.Write(sb);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 47352
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := nextInt()
		if a%2 == 0 {
			if a%3 == 0 {
				continue
			}
			if a%5 == 0 {
				continue
			}
			fmt.Println("DENIED")
			return
		}
	}
	fmt.Println("APPROVED")
}


Measured memory_bytes: 1776
#include <stdio.h>

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  int c, d, e;
  c = a + b;
  d = a - b;
  e = a * b;
  int ans = c > d ? c : d;
  ans = ans > e ? ans : e;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int a, b;
    cin >> a>> b;
    if(a>=10 || b>=10){
        cout << -1 << endl;
    }else{
        cout << a * b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
#define is insert
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
ll fa[MAX];
ll power(ll p,ll q){
    ll res=1;
    p%=mod;
    while(q){
        if (q&1)
            res=(res*p)%mod;
        q>>=1;
        p=(p*p)%mod;
    }
    return res;
}
ll fact(ll n){
    if (n<=1)
        return fa[n]=1;
    if (fa[n])
        return fa[n];
    return fa[n]=(n*fact(n-1))%mod;
}
ll ncr(ll n,ll r){
    if (!r)
        return 1;
    return (((fact(n)*power(fact(n-r),mod-2))%mod)*power(fact(r),mod-2))%mod;
}
void solve(){
    ll x,k,d,l;
    cin>>x>>k>>d;
    if (!x && !(k&1))
        cout<<x<<endl;
    else if (!x)
        cout<<d<<endl;
    else{
        l=min(abs(x)/d,k);
        if (k&1 && !(l&1))
            l++;
        else if (!(k&1) && l&1)
            l++;
        if (x<0)
            cout<<abs(x+l*d)<<endl;
        else
            cout<<abs(x-l*d)<<endl;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
 int n, i;

 char PIC[52];
 int NUM[52];

 int S[13];
 int H[13];
 int C[13];
 int D[13];

for(i = 0; i <= 13; i++)
 S[i] = i;

for(i = 0; i <= 13; i++)
 H[i] = i;

for(i = 0; i <= 13; i++)
 C[i] = i;

for(i = 0; i <= 13; i++)
 D[i] = i;

scanf("%d", &n);

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

 if(PIC[i] == 'S')
  S[NUM[i]] = 0;

 if(PIC[i] == 'H')
  H[NUM[i]] = 0;

 if(PIC[i] == 'C')
  C[NUM[i]] = 0;

 if(PIC[i] == 'D')
  D[NUM[i]] = 0;

}

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

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

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

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

return 0;
}



Measured memory_bytes: 2020
# -*- coding: utf-8 -*-
N, K = map(int, input().split())

kukan = list()
for i in range(K):
  l, r =  map(int, input().split())
  kukan.append((l, r))
dp = [0] * (N+1)
dp[1] = 1
dp_sum = [0] * (N+1)
dp_sum[1] = 1
for i in range(0, N+1):
  for j in range(K):
    from_l = i - kukan[j][1]
    from_r = i - kukan[j][0]
    if from_r < 0:
      continue
    else:
      from_l = max(1, from_l)
      dp[i] += dp_sum[from_r] - dp_sum[from_l - 1]
      dp[i] %= 998244353
  dp_sum[i] = dp[i] + dp_sum[i-1]
print(dp[N] % 998244353)

Measured memory_bytes: 76556
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ll long long
#define INF 999999999

const ll mod = 1e9+7;

int main(){
	ll a, b;
	cin >> a >> b;
	if (a<=8 && b<=8){cout << "Yay!" << endl;}
	else {cout << ":(" << endl;}
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define INF 1<<21
using namespace std;

int main(){
  int dp[5001];
  int items[]={200,300,500,1000,1200,1500};
  int prices[]={380,550,850,1520,1870,2244};
  int mg;
  for(int i=0;i<5001;i++){
    dp[i] = INF;
  }
  dp[0]=0;
  for(int i=0;i<6;i++){
    for(int j=0;j<5001-items[i];j++){
      dp[j+items[i]] = min(dp[j+items[i]],dp[j]+prices[i]);
    }
  }
  while(1){
    cin >> mg;
    if(mg == 0) break;
    cout << dp[mg] << endl;
  }
}

Measured memory_bytes: 1180
A,B,C,X,Y=map(int,input().split())
direct=A*X+B*Y
W=min(X,Y)
Z=max(X,Y)
if Z==X:
    E=A
    D=B
else:
    E=B
    D=A
over=Z*C*2
under=W*C*2+(Z-W)*E

print(min(direct,over,under))
    

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - (i + 1)
A.sort()

b = A[N // 2] if N % 2 else A[((N - 1) // 2 + N // 2) // 2]

sum = 0
for i in range(N):
    sum += abs(A[i] - b)

print(sum)


Measured memory_bytes: 26836
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;


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

	long long X = 0;
	long long preT = 0;
	cin >> preT;
	for (int i = 0; i < N - 1; ++i) {
		int t; cin >> t;
		if (preT + T < t) {
			X += T;
		}
		else {
			X += (t - preT);
		}

		preT = t;
	}

	cout << X + T << endl;

	return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int m,d,ans=0;
	cin>>m>>d;
	fo(i,1,m+1) fo(j,1,d+1) if(j/10>1&&j%10>1&&(j/10)*(j%10)==i)ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[1000000];

int32_t main(){_
   
   cin >> n;

   for (int x = 1; x <= 101; ++x)
   {
      for (int y = 1; y <= 101; ++y)
      {
         for (int z = 1; z <= 101; ++z)
         {
            int sum = x * x + y * y + z * z + x*y + y*z + z*x;
            if (sum <= n){
               a[sum]++;
            }
         }
      }
   }

   for (int i = 1; i <= n; ++i)
   {
      cout<<a[i]<<endl;
   }

   return 0;
}

Measured memory_bytes: 3692
n,m=map(int,input().split())
f=lambda x:int(x)-1
p=list(map(f,input().split()))
par=[j for j in range(n)]
def find(x):
  if x==par[x]:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
 
def union(a,b):
  ra=find(a)
  rb=find(b)
  if ra!=rb:
    par[ra]=par[rb]
 
for i in range(m):
  v,w=map(f,input().split())
  union(v,w)
 
ans=0
for j in range(n):
  if find(j)==find(p[j]):
    ans+=1
print(ans)

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

int main() {
    int n;
    cin >> n;
    map<string, int> mmp;
    while (n--) {
        string s;
        cin >> s;
        mmp[s]++;
    }
    cout << "AC x " << mmp["AC"] << endl; 
    cout << "WA x " << mmp["WA"] << endl; 
    cout << "TLE x " << mmp["TLE"] << endl; 
    cout << "RE x " << mmp["RE"] << endl; 
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b= scan.next();

	//	long a = Long.parseLong(aS);
		//long b = Long.parseLong(bS);
		//if(a>0 &&b>0) {
		String ans ="";
			if(a.length()>b.length()) {
				ans ="GREATER";
			}else if(a.length()<b.length()) {
				ans ="LESS";
			}
			if(a.length()==b.length()) {

				for (int i=0;i<a.length();i++) {
					if(a.charAt(i)>b.charAt(i)) {
						ans ="GREATER";
						break;
					}else if(a.charAt(i)<b.charAt(i)) {
						ans ="LESS";
						break;
					}else {
						ans = "EQUAL";

					}

					}


				}
			System.out.println(ans);}

}


Measured memory_bytes: 23636
import numpy as np
N = int(input())
L = input().split()
npL = np.array([int(l) for l in L])
l_max = npL.max()
arg_max = np.argmax(npL)
l_deleted = np.delete(npL, arg_max)
if l_max < l_deleted.sum():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 12448
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



string N;
long long int K,A[200005],Sum[200005]={},res=0,dp[105][4]={},dp2[105][4]={};

int main() {
	cout << fixed << setprecision(18);
	cin>>N>>K;
	dp[1][1]=1;
	dp2[1][1]=N[0]-'1';
	for(int i=1;i<N.length();i++){
		if(N[i]=='0'){
			//0
			dp[i+1][3]+=dp[i][3];
			dp[i+1][2]+=dp[i][2];
			dp[i+1][1]+=dp[i][1];

			//not0
			dp2[i+1][3]+=9*dp2[i][2];
			dp2[i+1][2]+=9*dp2[i][1];

			//0
			dp2[i+1][3]+=dp2[i][3];
			dp2[i+1][2]+=dp2[i][2];
			dp2[i+1][1]+=dp2[i][1];

			dp2[i+1][1]+=9LL;
			
		}else{
			//not 0
			dp[i+1][3]+=dp[i][2];
			dp[i+1][2]+=dp[i][1];
			//not 0
			dp2[i+1][3]+=(N[i]-'1')*dp[i][2];
			dp2[i+1][2]+=(N[i]-'1')*dp[i][1];
			//not0
			dp2[i+1][3]+=9*dp2[i][2];
			dp2[i+1][2]+=9*dp2[i][1];
			//0
			dp2[i+1][3]+=dp2[i][3]+dp[i][3];
			dp2[i+1][2]+=dp2[i][2]+dp[i][2];
			dp2[i+1][1]+=dp2[i][1]+dp[i][1];

			
			dp2[i+1][1]+=9LL;
		}
	}
	cout<<dp2[N.length()][K]+dp[N.length()][K];
} 

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

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)


class CColoringColorfully {
public:
    void solve(std::istream &in, std::ostream &out) {
      string s;
      in >> s;
      int ans = 0;
      char search = s[0];
      FOR(i, 1, s.length()) {
        if (search == s[i]) {
          ans++;
          search = s[i] == '0' ? '1' : '0';
        } else {
          search = s[i];
        }
      }
      out << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  CColoringColorfully solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	ll s = 0;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &a[i]);
		s += a[i];
	}
	ll c = 0;
	ll ans = LLONG_MAX;
	for (int i = 0; i + 1 < n; ++i) {
		c += a[i];
		ll r = s - c;
		ll need = abs(r - c);
		ans = min(ans, need);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1792
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b+c)>=22)
    cout<<"bust";
    else cout<<"win";

    return 0;
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2014
#include <bits/stdc++.h>
using namespace std;

int ans_b, ans_w;
int w,h;

void solve(int start_h, int start_w, vector<vector<char>> &field){
  queue<pair<int,int>> q;
  q.push(make_pair(start_h,start_w));
  vector<vector<char>> tmp = field;
  int flag = 0; //1 B, 2 W, 3 ???????????£??\

  // bfs
  while(!q.empty()){
    int i,j;
    i = q.front().first;
    j = q.front().second;
    q.pop();

    // ?¨?????????´?????????
    if(tmp[i][j]=='V'){
      continue;
    }

    // ?????????????????§??£??\????????????????????§??????
    // ????????????????????§??£??\?????????????????????????????????
    if((flag==1&&tmp[i][j]=='W')||(flag==2&&tmp[i][j]=='B')){
      flag=3;
      break;
    }else if(flag==0){
      if(tmp[i][j]=='B')
        flag=1;
      else if(tmp[i][j]=='W')
        flag=2;
    }

    // ?¨?????????????????????????
    if(tmp[i][j]=='B'||tmp[i][j]=='W'){
      tmp[i][j]='V';
      continue;
    }
    tmp[i][j] = 'V'; // V is visited state.

    // ??????????????????queue?????????
    if(j-1>=0)
      q.push(make_pair(i,j-1));
    if(j+1<w)
      q.push(make_pair(i,j+1));
    if(i-1>=0)
      q.push(make_pair(i-1,j));
    if(i+1<h)
      q.push(make_pair(i+1,j));
   // cout<<q.size()<<endl;
  }

  // ??????????????£??\???????????????????????????
  if(flag==1)
    ans_b++;
  else if(flag==2)
    ans_w++;
}

int main(){
  while(true){
    scanf("%d %d", &w, &h);
    if(w==0)
      break;
    ans_b = 0;
    ans_w = 0;

    vector<vector<char>> field(h,vector<char>(w));
    // input field info
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
        cin>>field[i][j];

    // check either adjacent to B or adjacent to W
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        if(field[i][j]=='.')
          solve(i,j,field);
      }
    }

    printf("%d %d\n", ans_b, ans_w);
  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1232
using System;

public class AtCoder{
	public static void Main(){
		string n;
		n = Console.ReadLine().Trim();
		string s = "";
		if(n.Length == 2){
			Console.WriteLine(n);
		}else{
			s += n[2];
			s += n[1];
			s += n[0];
			Console.WriteLine(s);
		}
		
	}
}

Measured memory_bytes: 13140
#include <iostream>
 
#include <deque>
 
#include <stdio.h>
 
#include <cstdio>
 
#include <algorithm>
 
#include<bits/stdc++.h>
 
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "
#define nw <<"\n"
#define ca "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define ull unsigned LL
#define check cout<<"* ";
#define show_vector for(int q=0;q<v.size();q++){cout<<v[q]<<" ";}
#define REP(i,n) for (int i=0;i<(n);++i)
#define N_MAX 26
 
 
const int inf=1<<30;
const long long int INF=1e10;
const int MOD=1e9+7;
const int maxn = 1e5+10;
int a[200005],b[1000005];
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
/*
int ck_prime(int n)
{
    int coun;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
           return 1; // n is prime
        }
    return 0;
}
*/
int main()
{
    int n,x;
    vector<int>a;
    vector<int>b;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        a.pub(x);
    }
    for(int i=1;i<=n;i++){
        cin>>x;
        b.pub(x);
    }
    int sumX=0,sumY=0;
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            sumX+=a[i];
            sumY+=b[i];
        }
    }
    cout<<sumX-sumY nw;
}

Measured memory_bytes: 3596
N = int(input())
C, S, F = [], [], []
for _ in range(N-1):
    c,s,f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

# 到着時刻と駅のインデックスを渡すと、次の駅への到着時刻を返す関数
def time_arrive_next_sta(arrival_time, idx):
    if S[idx] <= arrival_time and arrival_time%F[idx] == 0:
        return arrival_time + C[idx]
    elif S[idx] > arrival_time:
        return S[idx] + C[idx]
    else:
        return arrival_time + C[idx] + (F[idx] - arrival_time%F[idx])

ans = []
for i in range(N-1):
    tmp = 0
    for j in range(i, N-1):
        tmp = time_arrive_next_sta(tmp, j)
    ans.append(tmp)

ans.append(0)

for x in ans:
    print(x)

Measured memory_bytes: 3188
n = int(input())
a = []
a_sort = []

for i in range(n):
  a.append(int(input()))

m1 = max(a)
m2 = sorted(a)[-2]
  
for j in range(n):
  if a[j] == m1:
    print(m2)
  else:
    print(m1)
    

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

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n; cin >> n;
    string ans = "APPROVED";
    rep(i,n){
        int a; cin>> a;
        if(a%2 == 0){
            if(a%3 == 0 || a%5 == 0);
            else {ans = "DENIED"; break;}
        }
    }
    cout << ans << endl; return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,a,b;
	cin>>n>>a>>b;
	long long res=0;
	if (a+b>n){
		if (a>=n){
			cout<<n<<endl;
			return 0;
		}
		else{
			cout<<a<<endl;
			return 0;
		}
	}
	else{
		res+=n/(a+b)*a;
		if (n%(a+b)>a) res+=a;
		else res+=n%(a+b);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
b = []
b = gets.split.map(&:to_i)
M = gets.chomp.to_i
c = []
while s = gets
  c.push(s.split.map(&:to_i))
end
cnt = 0
for i in 0..M-1
  cnt = 0
  for j in 0..N-1
    if j == c[i][0]-1
      cnt = cnt + c[i][1]
    else
      cnt = cnt + b[j]
    end
  end
  puts cnt
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool visited[100005];
vector <int> G[100005];
vector <int> path, path2;
void make(int u){
   for(int i=0;i<G[u].size();i++){
      int v = G[u][i];
      if (visited[v]) continue;
      visited[v] = 1;
      path.push_back(v);
      make(v);
      break;
   }
}
void make2(int u){
   for(int i=0;i<G[u].size();i++){
      int v = G[u][i];
      if (visited[v]) continue;
      path2.push_back(v);
      visited[v] = 1;
      make2(v);
      break;
   }
}
int main(){
   scanf("%d %d",&n,&m);
   for(int i=1;i<=m;i++){
      int x,y;
      scanf("%d %d",&x,&y);
      G[x].push_back(y);
      G[y].push_back(x);
   }
   path.push_back(1);
   visited[1] = 1;
   make(1);
   make2(1);
   printf("%d\n",path.size() + path2.size());
   for(int i=path2.size()-1;i>=0;i--) printf("%d ",path2[i]);
   for(int i=0;i<path.size();i++) printf("%d ",path[i]);
}


Measured memory_bytes: 9720
#include<iostream>
#include<cstdlib>
#include<stack>

using namespace std;

int main() {
	stack<int> S;
	char n;
	string s;
	int a, b;
	while (cin >> s) {
		if (s[0] == '+' || s[0]=='-'||s[0]=='*') {
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			if (s[0] == '+') {
				S.push(a + b);
			}
			else if (s[0] == '-') {
				S.push(b - a);
			}
			else if (s[0] == '*') {
				S.push(a * b);
			}
		}
		else {
			S.push(atoi(s.c_str()));
		}
	}
	cout << S.top() << endl;
}


Measured memory_bytes: 3176
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//221
	int n;
	cin>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	sort(arr.rbegin(),arr.rend());
	ll a=0,b=0;
	for(int i=1;i<n;i+=2) {
		a+=arr[i-1];b+=arr[i];
	}
	if(n&1)a+=arr[n-1];
	cout<<a-b;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3636
N=int(input())
A=[0]*(N)
B=[0]*(N)
for i in range(N):
    x,y=map(int, input().split())
    A[i]=x+y
    B[i]=x-y

A=sorted(A)
B=sorted(B)

print(max(A[-1]-A[0],B[-1]-A[0],A[-1]-A[0],B[-1]-B[0]))

Measured memory_bytes: 26932
import sys
sys.setrecursionlimit(2000000)
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = [int(a) for a in an]
if len(ani) == 1:
  print("0")
else:
  print(str(f(0,0,ani,0)))

Measured memory_bytes: 221856
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,a,b;
    char op;
    cin>>a>>op>>b;

    ans=(op=='+')?(a+b):(a-b);
    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256