akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            if(B%A == 0)
            {
                Console.Write(A + B);
            }
            else
            {
                Console.Write(B - A);
            }


        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    int N,W; cin >> N >> W;
    vi v(N),w(N);
    rep(i,N) cin >> v[i] >> w[i];
    int dp[105][10101] = {0};

    rep(i,N){
        rep(j,W+1){
            if(j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}



Measured memory_bytes: 7244
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<int(n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 998244353;

int main(){
	int N, S; cin >> N >> S;
	int A[N];
	rep(i, N) cin >> A[i];
	ll dp[N][S+1], sum[N][S+1];
	ll ans = 0;
	rep(i, N)rep(j, S+1){
		if(i==0){
			if(j == A[i]) dp[i][j] = 1;
			else dp[i][j] = 0;
			sum[i][j] = dp[i][j];
		}else{
			if(j < A[i]) dp[i][j] = 0;
			else if(j == A[i]) dp[i][j] = i+1;
			else dp[i][j] = sum[i-1][j - A[i]];
			sum[i][j] = (sum[i-1][j] + dp[i][j]) % mod;
		}
	}
	rep(i, N){
		ans = (ans + (N-i) * dp[i][S] % mod) % mod;
	}
	cout << ans << endl;
	return 0;
}


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

const int MAXN = 1004;
const int MAXW = 1004;
int W;
int N;
int P[MAXN];
int C[MAXN];
int dp[MAXW];

int main() {
  while(scanf("%d", &W) != EOF && W) {
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) {
      scanf("%d,%d", &P[i], &C[i]);
    }
    fill(dp,dp+MAXW,0);
    for(int i = 0; i < N; ++i) {
      for(int j = W-C[i]; j >= 0; --j) {
	dp[j+C[i]] = max(dp[j+C[i]], dp[j] + P[i]);
      }
    }
    int res = -1;
    int w = 0;
    for(int j = 0; j <= W; ++j) {
      if(dp[j] > res) {
	res = dp[j];
	w = j;
      }
    }
    static int tc = 0;
    cout << "Case " << ++tc << ":" << endl;
    cout << res << endl;
    cout << w << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  string in;
  cin >> in;
  string S=in, newS;

  do{
    for(int i=0;i<S.size()-1;i++){
      if(S[i] == 'S' && S[i+1] == 'T'){
        int j=0;
        while(S[i-j] == 'S' && S[i+j+1] == 'T' && i-j >= 0 && i+j+1 < S.size()){
          S[i-j] = 'N';
          S[i+j+1] = 'N';
          j++;
        }
      }
    }
    newS = "";
    for(int i=0;i<S.size();i++) if(S[i] != 'N') newS += S[i];
    if(newS == S || newS.size() == 0) break;
    S = newS;
  }while(true);
  cout << newS.size() << endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007
#define ll long long

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (k % 2 == 0) ans = a - b;
	else ans = b - a;

	cout << ans << endl;

	return 0;
}


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

int main(){
    int a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a),t(b),x(q);
    rep(i,a) cin>>s[i];
    rep(i,b) cin>>t[i];
    rep(i,q) cin>>x[i];

    sort(all(s));
    sort(all(t));
    rep(i,q){
        if(s[0]>x[i] && t[0]>x[i]) cout<<max(s[0],t[0])-x[i]<<endl;
        else if(s[a-1]<x[i] && t[b-1]<x[i]) cout<<x[i]-min(s[a-1],t[b-1])<<endl;
        else{
            ll ans=1LL<<60;
            int ia=lower_bound(all(s),x[i])-s.begin();
            int ib=lower_bound(all(t),x[i])-t.begin();
            ll sj,tk;
            if(ia!=0 && ib!=b){
                sj=s[ia-1];
                tk=t[ib];
                ans=min(ans,2*min(tk-x[i],x[i]-sj)+max(tk-x[i],x[i]-sj));
                //cout<<sj<<" "<<tk<<endl;
            }
            
            if(ia!=a && ib!=0){
                sj=s[ia];
                tk=t[ib-1];
                ans=min(ans,2*min(x[i]-tk,sj-x[i])+max(x[i]-tk,sj-x[i]));
                //cout<<sj<<" "<<tk<<endl;
            }

            if(ia!=0 && ib!=0){
                sj=s[ia-1];
                tk=t[ib-1];
                ans=min(ans,x[i]-min(tk,sj));
                //cout<<sj<<" "<<tk<<endl;
            }

            if(ia!=a && ib!=b){
                sj=s[ia];
                tk=t[ib];
                ans=min(ans,max(tk,sj)-x[i]);
                //cout<<sj<<" "<<tk<<endl;
            }
            
            cout<<ans<<endl;
        }
    }
}

Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    string S;
    map<string, ll> mp;
    for (int i = 0; i < N; i++) {
        cin >> S;
        sort(S.begin(), S.end());
        mp[S] += 1;
    }
    ll ans = 0;
    for (auto m : mp) { ans += m.second * (m.second - 1) / 2; }
    cout << ans << '\n';
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int A, B, T;

int main() {
    cin >> A >> B >> T;
    cout << (T/A)*B << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN = (1 << 17);
const int MOD = 998244353;
const int INV = (MOD + 1) >> 1;
const int POW = (long long)(1E18) % MOD;

void fwt(int *a, int n, int type) {
    for(int s=2;s<=n;s<<=1) {
        int t = (s>>1);
        for(int i=0;i<n;i+=s) {
            for(int j=0;j<t;j++) {
                int x = a[i+j], y = a[i+j+t];
                a[i+j] = (type == -1) ? 1LL*(x + y)%MOD*INV%MOD : (x + y)%MOD;
                a[i+j+t] = (type == -1) ? 1LL*(x + MOD - y)%MOD*INV%MOD : (x + MOD - y)%MOD;
            }
        }
    }
}

vector<int>G[MAXN + 5];
int mex[MAXN + 5], sg[MAXN + 5];

int ans[MAXN + 5], tmp[MAXN + 5], pw[MAXN + 5];
int main() {
	pw[0] = 1;
	for(int i=1;i<=MAXN;i++)
		pw[i] = 1LL*pw[i-1]*POW%MOD;
		
	int N; scanf("%d", &N);
	int len; for(len = 1; len < N; len <<= 1);
	ans[0] = 1; fwt(ans, len, 1);
	for(int o=0;o<3;o++) {
		int M; scanf("%d", &M);
		for(int i=1;i<=N;i++) G[i].clear();
		for(int i=1;i<=M;i++) {
			int u, v; scanf("%d%d", &u, &v);
			if( u > v ) swap(u, v);
			G[u].push_back(v);
		}
		for(int i=N;i>=1;i--) {
			for(int j=0;j<G[i].size();j++)
				mex[sg[G[i][j]]] = true;
			sg[i] = 0;
			while( mex[sg[i]] ) sg[i]++;
			for(int j=0;j<G[i].size();j++)
				mex[sg[G[i][j]]] = false;
		}
		for(int i=0;i<len;i++) tmp[i] = 0;
		for(int i=1;i<=N;i++) tmp[sg[i]] = (tmp[sg[i]] + pw[i]) % MOD;
		fwt(tmp, len, 1);
		for(int i=0;i<len;i++) ans[i] = 1LL*ans[i]*tmp[i]%MOD;
	}
	fwt(ans, len, -1), printf("%d\n", ans[0]);
}

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

int main() {
  int h,w,ht,wt;
  cin>>h>>w>>ht>>wt;
  h-=ht;
  w-=wt;
  cout<<(h*w)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int MAXN=100100;
int a[10],b[10],c[10];
int main()
{
    ios;
    int a,b;
    cin>>a>>b;
    if(a*500>=b) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long int
#define pi 3.14159265358979323846
#define mod 1000000007
using namespace std;
int main()
{
    ll n,cnt=0;
    cin>>n;
    ll a[n],b[n]={0};
    for(int i=0;i<n;i++)
    {
    cin>>a[i];
    b[i]=a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        cnt++;
    }
    if(cnt==2 || cnt==0)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int32>> dp(n+1,vector<int32>(n+1,0));
  FORR(i,n-1,0)FORR(j,n-1,0){
    if(s[i] == s[j])dp[i][j] = dp[i+1][j+1]+1;
  }
  int32 ans = 0;
  REP(i,n){
    REP(j,n){
      ans = max(ans, min(dp[i][j], abs(i-j)));
      // cout << dp[i][j] << " ";
    }
    // cout << endl;
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 195840
#include<stdio.h>
int main(){
  int n,a[200001],max1=0,max2=0;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
  	scanf("%d",&a[i]);
    if(max1<a[i]){
      max2=max1;
      max1=a[i];
    }else if(max2<a[i]){
      max2=a[i];
    }
  }
  for(int j=1;j<=n;j++){
    if(a[j]==max1)	printf("%d\n",max2);
    else	printf("%d\n",max1);
  }
  return 0;
}


Measured memory_bytes: 2304
# [int(e) for e in input().split()]
def sub():
    MOD = 10**9 + 7
    H, W = [int(e) for e in input().split()]
    mat = [[e for e in input()] for _ in range(H)]
    # print(mat)
    dp_table = [[0 for _ in range(W)] for _ in range(H)]
    dp_table[0][0] = 1
    for i in range(H):
        for j in range(W):
            # print(i,j)
            if mat[i][j] == "#":
                continue
            if i+1 < H:
                if mat[i+1][j] == ".":
                    dp_table[i+1][j] += dp_table[i][j]
                    if dp_table[i+1][j] > MOD:
                        dp_table[i+1][j] = dp_table[i+1][j] % MOD
            if j+1 < W:
                if mat[i][j+1] == ".":
                    dp_table[i][j+1] += dp_table[i][j]
                    if dp_table[i][j+1] > MOD:
                        dp_table[i][j+1] = dp_table[i][j+1] % MOD
    print(dp_table[H-1][W-1])



if __name__ == "__main__":
    sub()
    



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

bool prime[50001];

void seive(int s){
	memset(prime,true,sizeof(prime));
	prime[0]=prime[1]=false;
	for(int i=2;i<=s;i++){
		if(prime[i]==true){
			for(int j=i*2;j<=s;j+=i)prime[j]=false;
		}
	}
}

int main(void){
	seive(50000);
	while(1){
		int n,ans=0;
		scanf("%d",&n);
		if(n==0)break;
		if(n<=3)printf("0\n");
		else{
			for(int i=2;i<=n/2;i++){
				if(prime[i]==true && prime[n-i]==true)ans++;
			}
			printf("%d\n",ans);
		}
	}
    return 0;
}

Measured memory_bytes: 928
#include <bits/stdc++.h>
using namespace std;
const int MM=100013;
const int inf=2000000013;
int dp[MM],T[MM];
int main()
{
    ios_base::sync_with_stdio(0);
    int n,K;
    cin>>n>>K;
    for(int i=1;i<=n;i++)
    {
        cin>>T[K+i];
    }
    for(int i=1;i<=K;i++)   T[i]=T[K+1];
    for(int i=2+K;i<=n+K;i++)
    {
        dp[i]=inf;
        for(int j=1;j<=K;j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(T[i]-T[i-j]));
        }
    }
    cout<<dp[n+K]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
#define keta 50
typedef long long ll;
////////////////////////////////////////////////////////////
int main(){
	int n,K;
	cin >> n >> K;
	vector<ll> a(n);
	rep(i,0,n) cin >> a[i];

	ll s[1010][1010] = {};

	
	vector<ll> num;
	rep(i,0,n){
		s[0][i] = a[i];
		num.push_back(a[i]);
	}


	rep(i,1,n){
		rep(j,0,n-i){
			s[i][j] = s[i-1][j] + a[j+i];
			num.push_back(s[i][j]);
		}
	}

	rvsort(num);

	ll che[keta];
	che[0] = 1;
	rep(i,1,keta) che[i] = che[i-1] * 2; 

	int start = keta;

	while(1){
		//rep(i,0,num.size()) cout << num[i] << " ";
		//cout << endl;
		int cnt[keta] = {};
		rep(i,0,num.size()){
			rep(j,0,start){
				if( (num[i] & che[j]) == che[j] ) cnt[j]++;
			}
		}
		//rep(i,0,start) cout << che[i] << ":" << cnt[i] << endl;
		ll check = -1;
		for(int i = start-1; i >= 0 ; i-- ){
			if(cnt[i] >= K ){
				check = che[i];
				start = i;
				break;
			}
		}

		if( check == -1){
			//cout << "break" << endl;
			break;
		}
		vector<ll> t;
		rep(i,0,num.size()){
			if( (num[i] & check) == check ){
				t.push_back(num[i]);
			}
		}

		if( t.size() == K ){
			num = t;
			break;
		}
		else num = t;
	}


	
	ll ans = num[0];
	rep(i,1,K) ans = ans & num[i];
	cout << ans << endl;

	ret 0;
}

Measured memory_bytes: 14064
x = [int(x) for x in input().split()]
N = x[0]
A = x[1]
B = x[2]
ans = 0
for i in range(N):
  i = i+1
  to_int = [int(i) for i in list(str(i))]
  X = sum(to_int)
  if (X >= A) & (X <= B) :
    ans += i
print(ans)

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

int main()
{
    int n;
    cin >> n;
    int p = 0;
    int l = n;
    while(l % 2 == 0){
        l /= 2;
        p <<= 1;
        p |= 2;
    }
    if(l == 1){
        cout << "No" << endl;
        return 0;
    }
    l = n;
    cout << "Yes" << endl;
    cout << 2 << " " << n + 1 << endl;
    if(p){
        cout << p << " " << n << endl;
        cout << n - 1 << " " << n + p + 1 << endl;
        cout << n - 2 << " " << n << endl;
        cout << n + p << " " << n * 2 - 2 << endl;
        cout << n * 2 - 2 << " " << n * 2 - 1 << endl;
        cout << n * 2 - 2 << " " << n * 2 << endl;
        l -= 3;
    }
    for(int i = 2; i < l; i += 2){
        cout << 1 << " " << i + 1 << endl;
        cout << 1 << " " << i + n << endl;
        cout << i << " " << i + 1 << endl;
        cout << i + n << " " << i + n + 1 << endl;
    }
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <string.h>
 
int main()
{
    char str[21];
    int i, leng;
 
    scanf("%s", str);
    leng=strlen(str);
    for( i=leng-1; i>=0; i-- ){
        printf("%c", str[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 932
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int x = N % 10;
  if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
    cout << "hon" << endl;
  else if (x == 0 || x == 1 || x == 6 || x == 8)
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
}

Measured memory_bytes: 3676
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[11],a[11];
    int i,t=0;
    scanf("%s",s);
    for(i=0;i<strlen(s);i++){
        if(s[i]=='0'){
            a[t]='0';
            t++;
        }
        else if(s[i]=='1'){
            a[t]='1';
            t++;
        }
        else if(t!=0){
            a[t-1]='\0';
            t--;
        }
    }
    a[t]='\0';
    puts(a);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
const int maxn = 100005;
int a[maxn];
int b[maxn];
int c[3*maxn];
signed main()
{
	int  q, w, e, r, t;
	cin >> q >> w >> e >> r >> t;
	rep(i, 0, e-1)
		sc(a[i]);
	rep(i, 0, r - 1)
		sc(b[i]);
	rep(i, 0, t - 1)
		sc(c[i]);
	sort(a, a + e);
	sort(b, b + r);
	t--;
	rep(i, e - q , e - 1)
		c[++t] = a[i];
	rep(i, r - w , r - 1)
		c[++t] = b[i];
	t++;
	sort(c, c + t);
	int ans = 0;
	rep(i, t - q - w , t-1 )
		ans += c[i];
	cout << ans << endl;
}


Measured memory_bytes: 3968
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define set_it set<Node>::iterator
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e5+5;
ll read(){
	ll s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
ll Dist,a[N];
int n,m,b[N],fa[N],sum[N];
bool cmp(int x,int y){return a[x]>a[y];}
struct Node{
	ll val;int x;
	friend bool operator<(Node A,Node B){return A.val!=B.val?A.val<B.val:A.x<B.x;}
};
set<Node>F;
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){a[i]=read();b[i]=i;sum[i]=1;F.insert((Node){a[i],i});}
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<n;i++){
		int x=b[i];
		ll val=a[x]+2*sum[x]-n;
		F.erase((Node){a[x],x});
		set_it p=F.lower_bound((Node){val,0});
		if(p==F.end()||(*p).val!=val){puts("-1");return 0;}
		int y=(*p).x;fa[x]=y;sum[y]+=sum[x];Dist+=sum[x];
	}
	if(Dist!=a[b[n]]){puts("-1");return 0;}
	for(int i=1;i<=n;i++)if(fa[i])printf("%d %d\n",i,fa[i]);
	return 0;
}

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

using namespace std;
 
int main()
{
    int i,n;
    cin>>n;

    int a[n][2];
    for(i=0; i<n; i++)
    {
        cin>>a[i][0]>>a[i][1];
    }

    int c=0,f=0;
    for(i=0; i<=n-3; i++)
    {
        if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1])
        {
            f=1;
            break;
        }
    }

    if(f==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

int main() {
	int a, b, c, d;
	std::cin >> a >> b >> c >> d;
	if (a + b < c + d) {
		std::cout << "Right" << std::endl;
	}
	else if (a + b > c + d) {
		std::cout << "Left" << std::endl;
	}
	else {
		std::cout << "Balanced" << std::endl;
	}
	return 0;
}

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

int main(){
    long long int n;
    cin >> n;
    long long int a,b;
    cin >> a >> b;
    long long int ans;

    if((a-b)%2){
        ans=min(a-1,n-b)+(b-a+1)/2;
    }
    else{
        ans=(b-a)/2;
    }
    cout << ans << endl;
}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n, m;
    while (cin >> n >> m, n|m) {
        vector<pair<int, pii>> packets;
        REP(i, m) {
            int t, s, d;
            cin >> t >> s >> d;
            s--;
            d--;
            packets.push_back({t, {s, d}});
        }
        SORT(packets);
        vb infected(n);
        infected[0] = true;
        for (auto pkt : packets) {
            int s = pkt.second.first, d = pkt.second.second;
            if (infected[s]) infected[d] = true;
        }
        int ans = 0;
        REP(i, n) {
            if (infected[i]) ans++;
        }
        cout << ans << endl;
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, L;
    cin >> N >> L;

    vector<string > v(N);
    for(ll i = 0; i < N; i++){
        cin >> v[i];
    }

    sort(v.begin(), v.end());
    for(ll i = 0; i < N; i++){
        cout << v[i];
    }
    cout << endl;


}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		boolean f1 = false;
		boolean f7 = false;
		boolean f9 = false;
		boolean f4 = false;

		for ( int i = 0; i < 4; i ++) {
			int test = sc.nextInt();
			if ( test == 1) {
				f1 = true;
			}
			if ( test == 7) {
				f7 = true;
			}
			if ( test == 9) {
				f9 = true;
			}
			if ( test == 4) {
				f4 = true;
			}
		}

		if ( f1 && f7 && f9 && f4) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21972
#include <iostream>
using namespace std;
char c[105][105];
bool row[105];
bool col[105];
int main() {
    int h,w;
    cin >> h >> w;
    for (int i=1;i<=h;i++) {
        for (int j=1;j<=w;j++) cin >> c[i][j];
    }
    for (int i=1;i<=h;i++) {
        int cnt=0;
        for (int j=1;j<=w;j++) {
            if (c[i][j]=='.') cnt++;
        }
        if (cnt==w) row[i] = 1;
    }
    for (int i=1;i<=w;i++) {
        int cnt = 0;
        for (int j=1;j<=h;j++) {
            if (c[j][i]=='.') cnt++;
        }
        if (cnt==h) col[i] = 1;
    }
    for (int i=1;i<=h;i++) {
        bool o = false;
        for (int j=1;j<=w;j++) {
            if (row[i]||col[j]) continue;
            else {cout << c[i][j];o = true;}
        }
        if (o) cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int> answer(Q);
  for(int i=0;i<Q;i++){
    cin>>answer.at(i);
  }
  vector<int> point(N,K-Q);
  for(int i=0;i<Q;i++){
    point.at(answer.at(i)-1)++;
  }
   for(int i=0;i<N;i++){
    if(point.at(i)>0){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}
    

Measured memory_bytes: 1408
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  vector<int> v;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    v.push_back(s[i] - '0');
    ans += s[i] - '0';
  }

  int core = 0;
  for (int i = 0; i < v.size(); i++) {
    int sum = core + v[i] - 1;
    sum += 9 * (v.size() - (i + 1));
    ans = max(ans, sum);
    core += v[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    vi a(N,0), b(N-1);

    REP(i,N-1) cin >> b[i];

    REP(i,N-1) {
        if (i == 0 or a[i] > b[i]) a[i] = b[i];
        a[i+1] = b[i];
    }

    cout << accumulate(ALL(a),0) << endl;
    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int D;
  cin>>D;
  vector<int> c(26+1);
  for(int i(1);i<27;i++){
    cin>>c[i];
  }
  vector<vector<int>> s(D+1,vector<int>(26+1));
  for(int i(1);i<=D;i++){
    for(int j(1);j<=26;j++){
      cin>>s[i][j];
    }
  }
  vector<int> t(D+1);
  for(int i(1);i<=D;i++){
    cin>>t[i];
  }
  int M;cin>>M;
  for(int i(0);i<M;i++){
    int d,q;
    cin>>d>>q;
    t[d] = q;
    int p(0);
    vector<int> lp(27,0);
    for(int i(1);i<=D;i++){
      p += s[i][t[i]];
      lp[t[i]] = i;
      for(int j(1);j<=26;j++){
        p -= c[j]*(i-lp[j]);
      } 
    }
    cout << p << endl;
  }
  return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int cnt=0;
    for(int i=0;i<3;++i)
    {
        if(s[i]=='R')
        {
            int ans=1;
            for(int j=i+1;j<3;++j)
            {
                if(s[j]=='R') 
                {
                    ans++;
                    continue;
                }
                break;
            }
            cnt=max(cnt,ans);
        }
    }
    cout<<cnt<<endl;
    return 0;   
}

Measured memory_bytes: 3640
program abc
	implicit none
	integer :: a,b,n,na,nb,x
    double precision :: an,bn

	read(*,*) a,b
	
    x = -1
    
    do n = 1, 1000
    	an = n * 0.08
        na = int(an)
        if(na /= a) goto 100
        bn = n * 0.1
        nb = int(bn)
        if(nb /= b) goto 100
        x = n
        goto 200
100		continue
	enddo

200	continue
 
	write(*,*) x
    
end program abc

Measured memory_bytes: 768
import math
n = int(input())
sq_n = round(math.sqrt(n))
m = 0.0

for i in range(1, sq_n + 1):
    m = n/i
    #print(m)
    if (m.is_integer()):
        maxm = m
        maxi = i

print(int(maxm+maxi-2))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
long long MOD=1e9;

void solve(){
    int n;
    cin>>n;
    vector<long long> a(n,0);
    for(int i=0;i<n;i++) cin>>a[i];
    MOD*=MOD;
    long long ans=1;
    for(int i=0;i<n&&ans!=0;i++){
        if(a[i]!=0ll && ans!=0){
            if(ans!=-1){
                if(MOD/a[i]>=ans){
                    ans*=a[i];
                }
                else{
                    ans=-1;
                }
            }
        }
        else{
            ans=0;
        }
    }
    cout<<ans<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3992
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
M = sum(A)

for n in range(N):
  if A[n]>=B[n]:
    A[n]-=B[n]
  else:
    A[n+1] = max(0,A[n+1]+A[n]-B[n])
    A[n] = 0
    
print(M-sum(A))

Measured memory_bytes: 24260
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

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

    vector<ll> H{};
    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        ll h; cin >> h;
        H.push_back(h);
        ans += h;
    }

    sort(H.begin(), H.end(), greater<int>());

    for (ll j = 0; j < min(N, K); j++)
    {
        ans -= H[j];
    }

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

Measured memory_bytes: 2420
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
#define N 100005

vector<int> adj[N];

int a[N], dp[N];

bool dfs(int node, int p) {
	if (adj[node].size() == 1) {
		dp[node] = a[node];
		return true;
	}
	int maxi = 0;
	long long sum = 0;
	int sz = adj[node].size();
	for (int i = 0; i < sz; ++i) {
		int ch = adj[node][i];
		if (ch == p) {
			continue;
		}
		if (!dfs(ch, node)) {
			return false;
		}
		sum += dp[ch];
		maxi = max(maxi, dp[ch]);
	}
	long long k = sum - a[node];
	if (k<0 || k>a[node] || k > sum || sum - maxi < k) {
		return false;
	}
	dp[node] = a[node] - k;
	return true;
}
void solve() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	if (n == 2) {
		if (a[1] == a[2]) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		return;
	}
	for (int i = 0; i < n - 1; ++i) {
		int x, y; scanf("%d %d", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int root = -1;
	for (int i = 1; i <= n; ++i) {
		if (adj[i].size() > 1) {
			root = i;
			break;
		}
	}
	if (!dfs(root, 0) || dp[root] != 0) {
		printf("NO\n");
	}
	else {
		printf("YES\n");
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}


Measured memory_bytes: 14464
#include<stdio.h>

int s[1000000] = {0};

int main(){
	int a,b,c,d,e;
	int temp;
	int cont = 0;
	
	while(scanf("%d",&a) != EOF){
		/*
		for(int i = 0; i < a; i++){
			s[i] = 1;
		}
		*/
		
		cont = 0;
		
		s[0] = 1;
		s[1] = 1;
		
		for(temp = 2; temp < a+1; temp++){
			if(s[temp] == 0){
				for(b=temp; b <= a; b+= temp){
					if(b == temp){
						s[b] = 0;
					}
					else{
						s[b] = 1;
					}
				}
			}
		}
		
		for(c = 0; c < a+1; c++){
			if(s[c] == 0){
				
	//		printf("%d\n",c);
				cont++;
			}
		}
		
		printf("%d\n",cont);
	}
}
			

Measured memory_bytes: 0
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define MP make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b){
	return b ? gcd(b, a%b) : a;
}

vector<pair<ll,int>> factorize(ll n){
	vector<pair<ll,int>> res;
  	for(ll i = 2; n >= i*i; i++){
    	if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i == 0){
        	n /= i;
          	res.back().second++;
        }
    }
  	if(n!=1){
  		res.emplace_back(n,1);
    }
  	return res;
}

void Main()
{
	ll a, b;
  	cin >> a >> b;
  	
  	// gcd(a,b) の素因数の種類 + 1 を答える
	ll g = gcd(a,b);  	
	auto f = factorize(g);    
  	cout << f.size()+1 << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    int N;
    double den = 0;
    double ans;

    cin >> N;

    int a;

    for(int i; i < N; i++){
        cin >> a;
        den += 1.0 / (double)a;
    }

    ans = 1 / den;

    cout << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*
 Shahadat Hossain
 I.C.T Department
 Comilla University
 Session: 2013-2014
 */

#include<iostream>
#include<vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    
    
    int res = 0;
    for(int i = 1; i <= n; i++){
        int m = i;
        int cnt = 0;
        while(m != 0){
            cnt++;
            m /= 10;
        }
        if(cnt % 2 == 1)
            res++;
    }
    cout << res << endl;
    
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	string s;
	cin >> s;
	bool res = false;
	REP(i, 3)if (s[i] == s[i + 1])res = true;
	cout << (res ? "Bad" : "Good") << endl;
	return 0;
}



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

using namespace std;

int main(){
  int n;
  cin >> n;
  bool flag=false;
  vector<long long> a(n);
  const long long INF=1000000000+5;
  long long m=INF;
  long long cnt=0;
  long long ans=0;
  for(int i=0;i<n;i++){
      cin >> a[i];
      if(a[i]==0){
          flag=true;
      }
      if(a[i]<0){
          cnt++;
      }
      ans+=abs(a[i]);
      m=min(m,abs(a[i]));
  }
  if(cnt%2==0){
      cout << ans << endl;
      return 0;
  }
  if(flag){
      cout << ans << endl;
      return 0;
  }
  cout << ans-m*2 << endl;
  
}


Measured memory_bytes: 1024
use std::cmp::{max, min};
use std::collections::HashSet;

fn gcd(a: usize, b: usize) -> usize {
    let mi = min(a, b);
    let ma = max(a, b);

    let r = ma % mi;
    if r == 0 {
        return mi;
    }

    gcd(mi, r)
}

fn solve_(e: usize, set: &mut HashSet<usize>) {
    if e == 2 || e == 3 {
        set.insert(e);
        return;
    }

    for i in 2..((e as f64).sqrt() as usize + 1) {
        if e % i == 0 {
            set.insert(i);
            return solve_(e / i, set);
        }
        if i == ((e as f64).sqrt() as usize) {
            set.insert(e);
        }
    }
}

fn solve(a: usize, b: usize) -> usize {
    let c = gcd(a, b);

    let mut set = HashSet::new();

    solve_(c, &mut set);

    set.len() + 1
}

#[test]
fn test() {
    assert_eq!(solve(420, 660), 4);
    assert_eq!(solve(1, 2), 1);
    assert_eq!(solve(2, 2), 2);
    assert_eq!(solve(4, 4), 2);
    assert_eq!(solve(5, 5), 2);
    assert_eq!(solve(1, 2019), 1);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (a, b) = parse_line!(usize, usize);
    println!("{}", solve(a, b));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second



int main(){
	ll n,m;
	ll ans=0;
	int res;
	cin>>n>>m;
	res=m%2;
	m/=2;
	if(n>=m){
		ans+=m;
	}else{
		ans+=n;
		ans+=(m-n)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    string s;
    cin >> s;
    vector<int> check(26);
    rep(i,s.size()){
        int c = s[i];
        check[c - 97]++;
    }
    bool ans = true;
    rep(i,26){
        if(1 < check[i]){
            ans = false;
        }
    }
    cout << (ans ? "yes" : "no") << endl;
}

Measured memory_bytes: 3604
ABCDEs = [int(input()) for _ in range(5)]

Qs = []
ans = 0
for A in ABCDEs:
    ans += (A+9)//10*10
    if A%10:
        Qs.append(A%10)

if Qs:
    print(ans-(10-min(Qs)))
else:
    print(ans)


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

using namespace std;

struct sta 
{
	int X,Y;
	sta(){}
	sta(int a,int b){X=a;Y=b;}
	inline bool operator>(const sta& a) const 
	{
		return X!=a.X?X>a.X:Y<a.Y;
	}
};
#define P sta

const int MAXN=1e5+10,INF=1<<27;
int n,m,x,y,z,dist[MAXN];
set<int> s[MAXN];
vector<P> G[MAXN];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		G[x].push_back(P(y,z));G[y].push_back(P(x,z));
	}
	
	int oo,tmp;
	priority_queue<P,vector<P>,greater<P> > q;
	memset(dist,33,sizeof(dist));oo=*dist;
	dist[1]=0;q.push(P(0,1));
	while(!q.empty())
	{
		P t=q.top();q.pop();
		int u=t.Y,cost=t.X;
		if(cost>dist[u]) continue;
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].X,col=G[u][i].Y;
			tmp=dist[u]+(!s[u].count(col));
			if(tmp==dist[v]) s[v].insert(col);
			else if(tmp<dist[v])
			{
				s[v].clear();s[v].insert(col);
				dist[v]=tmp,q.push(P(dist[v],v));
			}
		}
	}
	printf("%d",(dist[n]==oo)?-1:dist[n]);
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec A(N+1), B(N);
    REP(i,0,N+1) cin >> A[i];
    REP(i,0,N) cin >> B[i];

    ll cnt = 0;
    REP(i,0,N) {
        ll d;
        if(A[i] <= B[i]) {
            B[i] -= A[i];
            cnt += A[i];
            A[i] = 0;
            if(A[i+1] <= B[i]) {
                B[i] -= A[i+1];
                cnt += A[i+1];
                A[i+1] = 0;
            }
            else {
                A[i+1] -= B[i];
                cnt += B[i];
                B[i] = 0;
            }
        }
        else {
            A[i] -= B[i];
            cnt += B[i];
            B[i] = 0;
        }
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 4856
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

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

    return false;
}

struct Edge {
    int to,cost;
    Edge(int to,int cost) : 
        to(to),cost(cost) {}
};
vector<Edge> G[502];

int n,m;
map<string,int> ids;

int to_id(string s) {
    if(!ids.count(s)) ids[s]=ids.size();

    return ids[s];
}
int dijk(int s,int t) {
    int d[502];
    rep(i,502) d[i]=INF;
    d[s]=0;
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,s));

    while(que.size()) {
        P p=que.top(); que.pop();
        int v=p.sc;
        int cost=p.fr;

        rep(i,G[v].size()) {
            Edge e=G[v][i];
            if(chmin(d[e.to],d[v]+e.cost)) {
                que.push(P(d[e.to],e.to));
            }
        }
    }

    return d[t];
}
void solve() {
    rep(i,502) G[i].clear();
    ids.clear();
    string s,p,g;
    cin>>s>>p>>g;
    to_id(s);
    to_id(p);
    to_id(g);
    rep(i,m) {
        string a,b;
        int c,d;
        cin>>a>>b>>c>>d;
        G[to_id(a)].pb(Edge(to_id(b),c/40+d));
        G[to_id(b)].pb(Edge(to_id(a),c/40+d));
    }

    int ans=dijk(to_id(s),to_id(p));
    ans+=dijk(to_id(p),to_id(g));
    cout<<ans<<endl;

}

int main() {
    while(cin>>n>>m) {
        if(n+m==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1512
H, W, K = map(int, input().split())
cake = [input() for _ in range(H)]
# 答え
memo = [[0] * W for _ in range(H)]
#print(memo)
# 行にケーキが何個あるか
cake_count_row = [0] * H
for y in range(H):
    count = 0
    for x in range(W):
        if cake[y][x] == "#":
            count += 1
    cake_count_row[y] = count
 
# イチゴがある行について色塗り
count = 1
for y in range(H):
    first = True
    if cake_count_row[y] == 0:
        continue 
    for x in range(W):
        if cake[y][x] == "#":
            if first:
                first = False
            else:
                count += 1
        memo[y][x] = count
    count += 1

# イチゴがない行について色塗り
# 上から下に
for y in range(1, H):
    if cake_count_row[y] == 0:
        for x in range(W):
            memo[y][x] = memo[y-1][x]
# 下から上に
for y in range(H-1)[::-1]:
    if cake_count_row[y] == 0:
        for x in range(W):
            memo[y][x] = memo[y+1][x]
 
# 出力
for i in range(H):
    print(" ".join(list(map(str, memo[i]))))

Measured memory_bytes: 7284