akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int n; string s;
    cin >> n >> s;
    char pre = '#';
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        if(s[i] != pre) {
            pre = s[i];
            ans++;
        }
    }    
    cout << ans;
}


int main() {
    //freopen("input", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3720
sx, sy, tx, ty = map(int, input().split())
X, Y = tx - sx, ty - sy
for d, n in zip("RULD", [X, Y, X, Y]):
    print(d * n, end="")
for d, n in zip("DRULULDR", [1, X + 1, Y + 1, 1, 1, X + 1, Y + 1, 1]):
    print(d * n, end="")
print()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  ll A, B;
  double x;
  cin >> A >> x;
  B = x * 100 + 0.5;
 
  ll ans = A * B / 100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3720
#include <stdio.h>

int main(void)
{
    int h1, h2, m1, m2, s1, s2, i;
    int h, m, s;
    for(i=0; i<3; i++) {
        scanf("%d%d%d%d%d%d", &h1, &m1, &s1, &h2, &m2, &s2);
        if(s1<=s2) {
            s = s2-s1;
        } else {
            s = s2+60-s1;
            m2--;
        }
        if(m1<=m2) {
            m = m2-m1;
        } else {
            m = m2+60-m1;
            h2--;
        }
        h = h2-h1;

        printf("%d %d %d\n", h, m, s);
    }

    return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int x,a,b;
	cin >> x >> a >> b;
  	if(a>=b){
      cout<<"delicious";
    }
    else{
      if(x<(b-a)){
        cout<<"dangerous";
      }
      else{
        cout<<"safe";
      }
    }
  
}

Measured memory_bytes: 256
local mmi, mma = math.min, math.max
local n, ma, mb = io.read("*n", "*n", "*n")
local a, b, c = {}, {}, {}
for i = 1, n do
  a[i], b[i], c[i] = io.read("*n", "*n", "*n")
end
local inf = 1000000007
local t = {}
for i = 1, 400 do
  t[i] = {}
  for j = 1, 400 do
    t[i][j] = inf
  end
end
for k = 1, n do
  for i = 400 - a[k], 1, -1 do
    for j = 400 - b[k], 1, -1 do
      t[i + a[k]][j + b[k]] = mmi(t[i + a[k]][j + b[k]], t[i][j] + c[k])
    end
  end
  t[a[k]][b[k]] = mmi(t[a[k]][b[k]], c[k])
end
local ret = -1
for i = 1, 400 do
  for j = 1, 400 do
    if i * mb == j * ma and t[i][j] < inf then
      if ret < 0 or t[i][j] < ret then
        ret = t[i][j]
      end
    end
  end
end
print(ret)


Measured memory_bytes: 3696
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    bool ok = true;
    ll N = S.size();
    rep(i,0,N){
        if(i % 2 == 0){
            if(S[i] == 'L') ok = false;
        }else{
            if(S[i] == 'R') ok = false;
        }
    }
    if(ok){
        print("Yes");
    }else{
        print("No");
    }

    
}


Measured memory_bytes: 256
#include <chrono>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

const int MAX_V = 100;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  cout << fixed << setprecision(10);

  int n;
  cin >> n;

  vector<vector<double>> dp(n + 1, vector<double>(MAX_V + 1, -1));
  dp[0][0] = 0;

  vector<int> t(n);
  for (int i = 0; i < n; ++i)
    cin >> t[i];

  vector<int> v(n);
  for (int i = 0; i < n; ++i)
    cin >> v[i];

  for (int i = 0; i < n; ++i) {
    for (int prev_v = 0; prev_v <= v[i]; ++prev_v) {
      if (dp[i][prev_v] == -1)
        continue;
      for (int next_v = 0; next_v <= v[i]; ++next_v) {
        if (abs(next_v - prev_v) > t[i])
          continue;

        double _max = min(1.0 * v[i], (t[i] + prev_v + next_v) / 2.0);

        double dist = dp[i][prev_v];
        double t1 = _max - prev_v;
        double t2 = _max - next_v;

        dist += t1 * prev_v + t1 * t1 / 2.0 + _max * (t[i] - t1 - t2) + t2 * t2 / 2.0 + t2 * next_v;
        dp[i + 1][next_v] = max(dp[i + 1][next_v], dist);
      }
    }
  }

  cout << dp[n][0] << endl;

  return 0;
}


Measured memory_bytes: 384
import sys
INF = 10**18

if __name__ == "__main__":
    n = int(input())
    h = []
    for i in range(n):
        a,b,c = map(int,input().split())
        h.append([a,b,c])
    dp = [[0]*3 for i in range(n)]
    for i in range(n):
        if i == 0:
            dp[i][0] = h[i][0]
            dp[i][1] = h[i][1]
            dp[i][2] = h[i][2]
        else:
            for j in range(3):
                dp[i][0] = max(dp[i-1][1] + h[i][0],dp[i-1][2] + h[i][0])
                dp[i][1] = max(dp[i-1][0] + h[i][1],dp[i-1][2] + h[i][1])
                dp[i][2] = max(dp[i-1][0] + h[i][2],dp[i-1][1] + h[i][2])
    print(max(dp[-1]))

Measured memory_bytes: 75240
import sys
N, Y = map(int,input().split())
for i in range(N + 1):
	if i * 10000 == Y and i == N:
		print('{0} 0 0'.format(i))
		sys.exit()
	for j in range(N - i + 1):
		if i * 10000 + j * 5000 == Y and i + j == N:
			print('{0} {1} 0'.format(i, j))
			sys.exit()
		if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y:
			print('{0} {1} {2}'.format(i, j, N-i-j))
			sys.exit()
print('-1 -1 -1')



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

void solve(long long N, std::vector<long double> x, std::vector<std::string> u)
{
    long double answer = 0.0f;
    for (int i = 0; i < N; i++)
    {
        if (u[i] == "BTC")
        {
            answer += x[i] * 380000.0;
        }
        else {
            answer += x[i];
        }
    }

    printf("%Lf\n", answer);
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long double> x(N);
    std::vector<std::string> u(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&x[i]);
        std::cin >> u[i];
    }
    solve(N, std::move(x), std::move(u));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000000;
const int MAX=100001;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int a,b,c,n;
    cin>>n;
    while(n){
        cin>>a>>b>>c;
        int a2=a*a;int b2=b*b;int c2=c*c;
        if(a2==b2+c2||b2==a2+c2||c2==a2+b2){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        n--;
    }
    return 0;
}

                           



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const ll MOD = 1e9 + 7;

int main(int argc, char const *argv[])
{

    int w, a, b;
    cin >> w >> a >> b;
    if (a < b)
    {
        cout << max(0, b - (a + w)) << endl;
    }
    else
    {
        cout << max(0, a - (b + w)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#define _PI (3.141592653589793)
int main()
{
	int N, M, X;
	std::cin >> N >> M >> X;
	std::vector<int> C;
	std::vector<std::vector<int>> A;
	for (int i = 0; i < N; ++i) {
		int c;
		std::cin >> c;
		C.push_back(c);
		std::vector<int> row;
		for (int j = 0; j < M; ++j) {
			int a;
			std::cin >> a;
			row.push_back(a);
		}
		A.push_back(row);
	}
	int minsum = -1;
	for (int pattern = 0; pattern < (2 << N); ++pattern) {
		std::vector<int> AA;
		for (int i = 0; i < M; ++i) {
			AA.push_back(0);
		}
		int sum = 0;
		for (int i = 0; i < N; ++i) {
			if ((pattern >> i) & 1) {
				sum += C[i];
				for (int j=0; j < M; ++j) {
					AA[j] += A[i][j];
				}
			}
		}
		int count = 0;
		for (int i = 0; i < M; ++i) {
			if (AA[i] >= X) {
				++count;
			}
		}
		if (count == M) {
			if ((minsum == -1) || (sum < minsum)) {
				minsum = sum;
			}
		}
	}
	std::cout << minsum << std::endl;
	return 0;
}

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

struct Point {
	double x;
	double y;
};

void koch(int n, Point a, Point b);

int main() {
	Point a, b;
	int n;
	cin >> n;
	a.x = 0; 
	a.y = 0;
	b.x = 100;
	b.y = 0;

	cout << setprecision(10) <<  a.x << " " << a.y << endl;
	koch(n, a, b);
	cout << b.x << " " << b.y << endl;
	return 0;
}

void koch(int n, Point a, Point b) {
	if (n == 0)return;
	Point s, t, u;
	s.x = (2.0 * a.x + b.x) / 3.0;
	s.y = (2.0 * a.y + b.y) / 3.0;
	t.x = (a.x + 2.0 * b.x) / 3.0;
	t.y = (a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) / 2.0 - (t.y - s.y) * sqrt(3) / 2.0 + s.x;
	u.y = (t.x - s.x) * sqrt(3) / 2.0 + (t.y - s.y) / 2.0 + s.y;

	koch(n - 1, a, s);
	cout << s.x << " " << s.y << endl;
	koch(n - 1, s, u);
	cout << u.x << " " << u.y << endl;
	koch(n - 1, u, t);
	cout << t.x << " " << t.y << endl;
	koch(n - 1, t, b);
}

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

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

typedef long long ll;

using namespace std;

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  if (n%2!=0) {
    cout << "No" << endl;
    return 0;
  }
  
  string cmp(s.substr(0, n/2));
  if (cmp == s.substr(n/2, n/2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

vi dx = {0, 0, -1, 1};
vi dy = {-1, 1, 0, 0};

int solve(string S) {
    string ans = (S.substr(0, 4) == "YAKI") ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}


int main() {
    string S;
    cin >> S;

    solve(S);

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int aaaaaaaaaaaaa;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int n,u,v;
int dist1[100100],dist2[100100];
vector<int> ga[100100];
void dfs1(int u,int p){
	dist1[u]=dist1[p]+1;
	for(int i=0;i<ga[u].size();i++){
		int v=ga[u][i];
		if(v!=p)
			dfs1(v,u);
	}
}
void dfs2(int u,int p){
	dist2[u]=dist2[p]+1;
	for(int i=0;i<ga[u].size();i++){
		int v=ga[u][i];
		if(v!=p)
			dfs2(v,u);
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		ga[u].push_back(v);
		ga[v].push_back(u);
	}
	dfs1(1,0);
	dfs2(n,0);
	int snuke=0,fennec=0;
	for(int i=1;i<=n;i++){
		if(dist1[i]<=dist2[i])
			fennec++;
		else
			snuke++;
	}
	if(snuke>=fennec)
		cout<<"Snuke"<<endl;
	else
		cout<<"Fennec"<<endl;
	return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
ll n,a[200000];
ll mn,sum;
bool neg;
int main(){
    cin>>n;
    mn = 1000000000;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]<0)neg=not neg;
        sum += abs(a[i]);
        mn = min(mn,abs(a[i]));
    }
    if(neg)sum-=2*mn;
    cout<<sum<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5000*5000 + 233;
long long  f[maxn];
void add(int w,int c){
	if(c<=0)return ;
	for(int i=0;i<=5000*5000-w;i++)
		f[i+w] = max(f[i+w],f[i]+c);
}
int main()
{
	int n,ga,gb,sa,sb,ba,bb;
	cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;
	memset(f,0,sizeof(f));
	add(ga,gb-ga);add(sa,sb-sa);add(ba,bb-ba);
	n = n + f[n];
	memset(f,0,sizeof(f));
	add(gb,ga-gb);add(sb,sa-sb);add(bb,ba-bb);
	cout << n + f[n] << endl;
	return 0;
} 

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

using namespace std;
using ll = long long;

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

		ll x;
		cin >> x;

		ll ans = 100;
		int i = 1;

		while (1) {

			ans += ans * 0.01;

			if (ans >= x)break;
			i++;
		}

		cout << i << "\n";

	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	char ch;
    cin >> ch;
    cout << char(ch+1)<<endl;
  
  	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<math.h>
#include<string>
#include<bits/stdc++.h>
#include<cstdio>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define bll __builtin_popcountll
#define bufclr while((getchar())!='\n')
#define bufcl int ws=cin.get()
#define bl "\n"
#define mp make_pair
#define pb push_back
#define ll long long int
#define UI unsigned int
#define mod  1000000007 /*998244353*/ 
//#define fs first
//#define sc second
#define fora(i,a,x) for(int i=a; i<x; ++i)
#define fors(i,x,a) for(int i=x; i>a; --i)
using namespace std;
void op(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
	#endif
}
int C(pair<int,int> &a ,pair<int,int> &b){
	return a.first<b.first;
}
int dfs(vector<vector<int>> &vec, int i, vector<bool> &vis){

	if(!vis[i]){
		int a=1;
		vis[i]=1;
		for(auto itr: vec[i]){
			if(!vis[itr]){
		 a+=dfs(vec,itr,vis);
	
	}
}	
return a;
	}
	return 0;
}
int main() { 
    	op();
			int f,q;
			cin>>f>>q;
			vector<vector<int>> vec(f+1);
			for(int i=0; i<q; ++i){
				int a,b;
				cin>>a>>b;
				vec[a].push_back(b);
				vec[b].push_back(a);
			}
			vector<bool> vis(f+1,0);

			int ans=0;
			for(int i=1; i<f+1; ++i){
					int r=0;
				if(!vis[i])
					r=dfs(vec,i,vis);
			//	cout<<r;
				ans = max(ans,r);
			}
			cout<<ans;
		}
		//cout<<ans;





            

Measured memory_bytes: 26736
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<string> day{ "SUN","MON","TUE","WED","THU","FRI","SAT" };

	string s;
	cin >> s;

	for (int i = 0; i < day.size(); i++) {
		if (day[i] == s) cout << 7 - i << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <map>
using namespace std;

const int mxN = 1e2 + 5;
int a[mxN];

int main() {
	int n, m;
	cin >> n >> m;
	int tot = 0;
	for(int i = 1; i <= n; ++i)
		cin >> a[i], tot += a[i];
	int cnt = 0;
	for(int i = 1; i <= n; ++i)
		cnt += (a[i] * 4 * m >= tot);
	cout << (cnt >= m ? "Yes" : "No");
}


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

int grid() {//dfsとは違い、一度通ったマスを封鎖したりはしない。その代わりに最短距離を表した配列を使う。
    int64_t H,W;
    cin >> H >> W;
    vector<vector<char>> s(H,vector<char>(W));//マスの文字(HxW)
    vector<vector<int64_t>> d(H,vector<int64_t>(W,-1));//マスの最短距離(-1は到達していない)
    for (int64_t i = 0; i < H; i++){
        for(int64_t j = 0; j < W; j++){
            cin >> s.at(i).at(j);
        }
    }
    //#のマスのカウント
    int64_t cnt_sharp = 0;
    for (int64_t i = 0; i < H; i++){
        for(int64_t j = 0; j < W; j++){
            if(s.at(i).at(j) == '#'){
                cnt_sharp++;
            }
        }
    }
    int64_t cnt_space = H*W-cnt_sharp;

    queue<pair<int64_t,int64_t>> q;
    vector<int> dx = {1,0,-1,0};
    vector<int> dy = {0,-1,0,1};//移動の四方向
    int64_t x,y,nx,ny;
    int64_t sx,sy,gx,gy;
    sx = 0;
    sy = 0;
    gx = H-1;
    gy = W-1;

    q.push(make_pair(sx,sy));
    d.at(sx).at(sy) = 1;//縦向きをx

    while(!q.empty()){
        x = q.front().first;
        y = q.front().second;
        q.pop();
        if(x == gx && y == gy){//goalに到着
            break;
        }else{
            for (int i = 0; i < 4; i++){//四方向の探索
                nx = x+dx[i];
                ny = y+dy[i];
                if(nx >= 0 && nx< H && ny >= 0 && ny < W && s.at(nx).at(ny) == '.' && d.at(nx).at(ny) == -1){//範囲内かつ進めるかつ未到達
                    q.push(make_pair(nx,ny));
                    d.at(nx).at(ny) = d.at(x).at(y) + 1;
                }
            }
        }
    }
    if(d.at(gx).at(gy) == -1){
        return -1;
    }else{
        return cnt_space-d.at(gx).at(gy);
    }
}

int main(){
    int64_t ans = grid();
    cout << ans << endl;
}


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

int main() {

  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S.at(i);
    }

  for (int i = 0; i < H; i++) {
    cout << S.at(i) << endl;
    cout << S.at(i) << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long l = (long)(Math.ceil(Math.sqrt(a)));

        long min = Long.MAX_VALUE;
        long x;
        for(long i = 1; i <= l; i++){
            if(a % i == 0){
                x = a / i;
                min = Math.min(min, (x + i - 2));
            }
        }

        System.out.println(min);

    }

}


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

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

    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            sum += d.at(i) * d.at(j);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define N 300
using namespace std;

int main(){
  int dp[N+1][3], s[N][3], c[N];
  while(1){
    int n, m;
    string temp;
    if(scanf("%d %d", &n, &m)==EOF) break;

    for(int i=0;i<n;i++){
      getchar();
      getline(cin,temp);
      cin >> c[i] >> s[i][0] >> s[i][1] >> s[i][2];
    }

    for(int i=0;i<=m;i++){
      dp[i][0]=dp[i][1]=dp[i][2]=0;
    }


    int maxi=-1;

    for(int i=0;i<=m;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<3;k++){
	  if(i+c[j]>m) continue;
	  dp[i+c[j]][k]=max(dp[i+c[j]][k],dp[i][k]+s[j][k]);
	  maxi=max(dp[i+c[j]][k],maxi);
	}
      }
    }
    if(maxi<1) cout << 0 << endl;
    else cout << maxi << endl;
  }
  return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node
{
    int x;
    int y;
};
Node node[505];
int m; //女生人数
int n; //男生人数
int match[502]; //用于记录男的被哪个女生选择了，没选择的话为-1
bool visited[502]; //表示i号男生被选择过了
bool map[502][502]; //表示i号女生对j号男生有意思
bool find(const int &k)
{
    for(int j=1; j <= n; j++)
    {
        if( map[k][j] && !visited[j] )//女的对男的有意思，并且这个男的未被选择
        {
            visited[j] = true;
            if(-1==match[j] || find(match[j]))
//如果被选择了，前面女生可以重新看有没有另外的男生可选
            {
                match[j]=k;//用于记录男生被选择的情况
                return true;
            }
        }
    }
    return false;
}
int main()
{
    int k,i,j,cnt;
        cnt=0;
        memset(map,0,sizeof(map));
        memset(match,-1,sizeof(match));
        cin>>n;
        m=n;
        for(i=1; i<=2*n; i++)
            scanf("%d%d",&node[i].x,&node[i].y);
        for(i=1; i<=n; i++)
            for(j=n+1; j<=2*n; j++)
            {
                if(node[i].x<node[j].x&&node[i].y<node[j].y)
                    map[i][j-n]=true;
            }
        for(i=1; i<=m; i++)
        {
            memset(visited,0,sizeof(visited));
            if(find(i))
            {
                cnt++;
            }
        }
        cout<<cnt<<endl;
        return 0;
}


Measured memory_bytes: 512
#include <iostream>

int main() {
    char buf[5]{};
    std::cin >> buf;
    char a{}, b{};
    int i = 1;
    int j = 0;
    a = buf[0];
    for(int k = 1; k < 4; ++k){
        if(a == buf[k])
            ++i;
        else if (j == 0 || b == buf[k]){
            ++j;
            b = buf[k];
        }
    }
    if(i == 2 && j == 2)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
program prob4
    implicit none
    character(len=100005) :: S
    integer :: a,b,c
    integer :: i, N
    read(*,*) S
    N = len_trim(S)
    a = 0
    b = 0
    c = 0
    do i = 1, N
        if(S(i:i) == 'a') then
            a = a + 1
        else if(S(i:i) == 'b') then
            b = b + 1
        else
            c = c + 1
        end if
    end do

    if(abs(a-b) <= 1 .and. abs(b-c) <= 1 .and. abs(c-a) <= 1) then
        write(*,*) 'YES'
    else
        write(*,*) 'NO'
    end if


    stop
contains
end program prob4

Measured memory_bytes: 3112
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt();
		int[] A = new int[1<<N];
		
		for(int i=0; i<1<<N; i++)
			A[i] = sc.nextInt();
		
		int[][] max = new int[2][1<<N];
		Arrays.fill(max[0], -1);
		Arrays.fill(max[1], -1);
		for(int i=0; i<N; i++) {
			if(A[1<<i] > A[0]) {
				max[0][1<<i] = 1<<i;
				max[1][1<<i] = 0;
			} else {
				max[0][1<<i] = 0;
				max[1][1<<i] = 1<<i;
			}
		}
		
		for(int L=2; L<=N; L++) {
			int comb = (1<<L)-1;
			HashSet<Integer> set = new HashSet<>();
			while(comb<(1<<N)) {
				set.clear();
				
				for(int i=0; i<N; i++) {
					if((comb & (1<<i))!=0) {
						set.add(max[0][comb^(1<<i)]);
						set.add(max[1][comb^(1<<i)]);
					}
				}
				set.add(comb);
				Iterator<Integer> it = set.iterator();
				while(it.hasNext()) {
					Integer idx = it.next();
					if(max[0][comb]<0 || A[max[0][comb]] < A[idx]) {
						max[1][comb] = max[0][comb];
						max[0][comb] = idx;
					} else if(max[1][comb]<0 || A[max[1][comb]] < A[idx]) {
						max[1][comb] = idx;
					}
				}
				
				int x = comb & -comb;
				int y = comb+x;
				comb = ((comb & ~y)/ x>>1) | y;
			}
		}
		long ans = 0;
		for(int i=1; i<1<<N; i++) {
			ans = Math.max(ans, A[max[0][i]] + A[max[1][i]]);
			pw.println(ans);
		}
		sc.close();
		pw.close();
	}
}


Measured memory_bytes: 162996
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 4009
ll n,m,i,j,k,l,t,arr[sz],brr[sz],crr[sz];
char c[sz];
int main()
{
    scanf("%lld %s",&n,&c);
    if(c[0]=='R')
        arr[0]=1;
     if(c[0]=='G')
        brr[0]=1;
     if(c[0]=='B')
        crr[0]=1;
    for(i=1;i<n;i++)
    {
        arr[i]=arr[i-1];
        brr[i]=brr[i-1];
        crr[i]=crr[i-1];
        if(c[i]=='R')
        arr[i]+=1;
     if(c[i]=='G')
        brr[i]+=1;
     if(c[i]=='B')
        crr[i]+=1;
    }
    for(i=2;i<n;i++)
    {
        for(j=i-1;j>0;j--)
        {
            if(c[i]!=c[j])
            {
                k=i-j;
                if(c[i]!='R' && c[j]!='R')
                {
                    l=arr[j];
                    k=j-k;
                    if(k>=0 && c[k]=='R')
                        l--;
                    m+=l;
                }
                else if(c[i]!='G' && c[j]!='G')
                {
                    l=brr[j];
                    k=j-k;
                    if(k>=0 && c[k]=='G')
                        l--;
                        m+=l;
                }
              else  if(c[i]!='B' && c[j]!='B')
                {
                    l=crr[j];
                    k=j-k;
                    if(k>=0 && c[k]=='B')
                        l--;
                        m+=l;
                }
              //  printf("%lld\n",m);
            }
        }
    }
    printf("%lld\n",m);
    return 0;
}


Measured memory_bytes: 3864
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a, b, c = map(int, input().split())
    print("Yes") if a < c < b or b < c < a else print("No")

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

int N;
int A[200010];

int main() {
    cin >> N;
    REP(i, N - 1) {
        int tmp;
        cin >> tmp;
        A[tmp - 1]++;
    }
    REP(i, N) cout << A[i] << endl;
}

Measured memory_bytes: 4356
#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);
	}

	int br = 0, rem = 0;
	for (int i = 0; i < N; i++) {
		if (a.at(i) != rem + 1) {
			br++;
		}
		else {
			rem++;
		}
	}
	if (br == N) br = -1;
	cout << br << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vl a(101010);
vvl b(101010);

ll dfs(ll u){
	ll res = 0;
	vl tmp;
	for(auto v : b[u]){
		tmp.push_back(dfs(v));
	}
	if(tmp.empty()) return 0;
	else{
		sort(rall(tmp));
		rep(i,tmp.size()){
			chmax(res,tmp[i]+i+1);
		}
		return res;
	}
}


int main(){
	ll n; cin >> n;
	REP(i,1,n) cin >> a[i], a[i]--;
	REP(i,1,n) b[a[i]].push_back(i);
	vl one;
	REP(i,1,n) if(a[i]==0) one.push_back(i);
	vl cnt(one.size());
	rep(i,one.size()){
		cnt[i] = dfs(one[i]);
	}
	sort(rall(cnt));
	ll ans = 0;
	rep(i,cnt.size()){
		chmax(ans,cnt[i]+i+1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 15872
h,w,k=map(int, input().split())
S=[]
y=0
for i in range(h):
  S.append(input())
  
for i in range(2**h):
  S2=[]
  for j in range(h):
    if (i>>j)&1:
      S2.append(S[j])
  
  for l in range(2**w):
    x=0
    for m in range(w):
      if (l>>m)&1:
        for n in range(len(S2)):
          if S2[n][m]=='#':
            x+=1
    if x==k:
      y+=1
print(y)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, M; cin >> N >> M;
    vector<string> A, B;
    rep (i, 0, N) {
        string a; cin >> a;
        A.push_back(a);
    }
    rep (i, 0, M) {
        string b; cin >> b;
        B.push_back(b);
    }

    bool exists = false;
    rep (i, 0, N) {
        rep (j, 0, A[i].size()) {
            if (i+M-1 >= N or j+M-1 >= N) continue;

            bool match = true;
            rep (k, 0, M) {
                rep (l, 0, M) {
                    if (A[i+k][j+l] != B[k][l]) match = false;
                }
            }
            if (match) exists = true;
        }
    }

    if (exists) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

string s;
int x,y;
int vx[8010],vy[8010],posvx=0,posvy=0;
int dp[8010][8010][2];

int solvex(int num,int pos,int f){
    if(dp[num][pos][f]!=-1)return dp[num][pos][f];
    int p=pos;
    if(f==1)p*=-1;
    if(num==posvx){
        if(p==x)return 1;
        else return 0;
    }
    int p1=p+vx[num],p2=p-vx[num];
    int f1=0,f2=0;
    if(p1<0){
        f1=1;
        p1*=-1;
    }
    if(p2<0){
        f2=1;
        p2*=-1;
    }
    if(num==0)dp[num][pos][f]=solvex(num+1,p1,f1);
    else dp[num][pos][f]=max(solvex(num+1,p1,f1),solvex(num+1,p2,f2));
    return dp[num][pos][f];
}
int solvey(int num,int pos,int f){
    if(dp[num][pos][f]!=-1)return dp[num][pos][f];
    int p=pos;
    if(f==1)p*=-1;
    if(num==posvy){
        if(p==y)return 1;
        else return 0;
    }
    int p1=p+vy[num],p2=p-vy[num];
    int f1=0,f2=0;
    if(p1<0){
        f1=1;
        p1*=-1;
    }
    if(p2<0){
        f2=1;
        p2*=-1;
    }
    dp[num][pos][f]=max(solvey(num+1,p1,f1),solvey(num+1,p2,f2));
    return dp[num][pos][f];
}

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

    cin>>s>>x>>y;
    int cnt=0;
    bool f=true;
    for(int i=0;i<s.size();i++){
        if(s[i]=='F')cnt++;
        else{
            if(f){
                vx[posvx++]=cnt;
                f=false;
            }
            else{
                vy[posvy++]=cnt;
                f=true;
            }
            cnt=0;
        }
        if(i==s.size()-1 && s[i]=='F'){
            if(f)vx[posvx++]=cnt;
            else vy[posvy++]=cnt;
        }
    }

    bool ans=true;

    for(int i=0;i<8010;i++){
        for(int j=0;j<8010;j++){
            dp[i][j][0]=-1;
            dp[i][j][1]=-1;
        }
    }
    if(solvex(0,0,0)==0)ans=false;

    for(int i=0;i<8010;i++){
        for(int j=0;j<8010;j++){
            dp[i][j][0]=-1;
            dp[i][j][1]=-1;
        }
    }
    if(solvey(0,0,0)==0)ans=false;
    
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

Measured memory_bytes: 501888
N,Q=map(int,input().split())
G=[[] for _ in range(N+1)]
#このような木に関する問題では、木の代わりに 1−2−3−...−N という直線的なグラフを考えると助け になることがある
cnt=[0]*(N+1)
from collections import deque
for _ in range(N-1):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)

for _ in range(Q):
    p,x=map(int,input().split())
    cnt[p]+=x

queue=deque([1])
visited={1}
while queue:
    tmp=queue.popleft()
    visited.add(tmp)
    for t in G[tmp]:
        if t in visited:
            pass
        else:
            queue.append(t)
            cnt[t]+=cnt[tmp]

print(*cnt[1:])

Measured memory_bytes: 64504
def main():

    r,c = map(int, input().split())
    chart = [list(map(int, input().split())) for i in range(r)]
    total = [0 for i in range(c)]

    for row in chart:
        print((' '.join(map(str, row))) + ' ' + str(sum(row)))
        total = [x + y for (x, y) in zip(total, row)]

    print((' '.join(map(str, total))) + ' ' + str(sum(total)))


main()

Measured memory_bytes: 7664
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = list(s())
xx = Counter(S)
print(min(xx["0"],xx["1"])*2)


Measured memory_bytes: 10660
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[16]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'},b[16];
	int sum=0;
	for(int i=0;i<16;i++)
	{
		cin>>b[i];
		if(b[i]!=a[i]) sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int l[200000] = {0};

int main() {
    int N;
    map<int, int> d;

    scanf("%d", &N);
    for(int i=0;i<N;i++) {
        scanf("%d", &l[i]);
    }

    for(int i=0;i<N;i++) {
        auto itr = d.find(l[i]);
        if(itr != d.end()) {
            d[l[i]]++;
        }
        else {
            d[l[i]] = 1;
        }
    }

    int ans = 0;
    for(auto i=d.rbegin();i!=d.rend();i++) {
        while(i->second > 0) {
            int bitLength = 0;
            int b = i->first;
            while (b) {
                b /= 2;
                bitLength++;
            }
            int v = pow(2, bitLength) - i->first ;
            if (d.find(v)!=d.end() && ((v!=i->first && d[v]>=1) || (v==i->first && d[v]>=2))) {
                i->second--;
                d[v]--;
                ans++;
            }
            else {
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define Min(a,b) (a>b?b:a)
#define Max(a,b) (a>b?a:b)
using namespace std;
int n;
string str[2*(int)1e5+10];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        cin>>str[i];
    sort(str+1,str+n+1);
    int cnt=1;
    for(int i=2;i<=n;i++)
        if(str[i]!=str[i-1])
            cnt++;
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 10048
// author - saiku_ni_naro
// TO THE TOP

#include<bits/stdc++.h>
using namespace std;
#define F_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl '\n'
#define For(i,a,n) for(int i=(a);i<=(n);i++)
#define RFor(i,a,n) for(int i=(n);i>=(a);i--)
#define SET(a,val) memset((a),(val),sizeof((a)))
#define X first
#define Y second
#define pb push_back
#define over(v) v.begin(),v.end()
#define sz(x) (int)x.size()
#define inp(x) cin>>x;
#define oup(x) cout<<x<<endl;

void solving_problem(){
    int N; cin>>N;
    cout<<(1000 - (N%1000))%1000<<endl;
}

signed main(){
    F_IO;


    int testcases = 1; 

    For(i,1,testcases){
        // cout<<"Cases #"<<i<<": ";
        solving_problem();
    }
}

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

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

int bar[3] = { 2, 1, 0 };

int mul[3][3] = {
	{ 0, 0, 0 },
	{ 0, 1, 1 },
	{ 0, 1, 2 }
};

int add[3][3] = {
	{ 0, 1, 2 },
	{ 1, 1, 2 },
	{ 2, 2, 2 }
};

string str;
int var[3];

int expr(int&);
int fomula(int&);

int expr(int& i) {
	int val = fomula(i);
	
	while (str[i] == '*' || str[i] == '+') {
		char op = str[i];
		++i;
		int f = fomula(i);
		if (op == '*') val = mul[val][f];
		else val = add[val][f];
	}
	
	return val;
}

int fomula(int& i) {
	if (str[i] == '-') {
		++i;
		return bar[fomula(i)];
	}
	
	if (isdigit(str[i])) { return str[i++] - '0'; }
	if (str[i] == 'P') { ++i; return var[0]; }
	if (str[i] == 'Q') { ++i; return var[1]; }
	if (str[i] == 'R') { ++i; return var[2]; }
	
	++i;
	int res = expr(i);
	++i;
	
	return res;
}

int main() {
	while (cin >> str) {
		if (str == ".") break;
		
		int ans = 0;
		
		for_(p,0,3) for_(q,0,3) for_(r,0,3) {
			var[0] = p; var[1] = q; var[2] = r;
			int i = 0;
			if (expr(i) == 2) ++ans;
		}
		
		cout << ans << endl;
	}
}

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

int main() {
    int a,b;
    cin >>a>>b;
    vector<int> A(b,a);
    vector<int> B(a,b);
    int minimum = min(a,b);
    bool judge = false;

    for(int i=0; i<minimum;i++){
    if(A.at(i) < B.at(i)){
        judge = true;
        break;
    }
    }
    if(judge){
        for(int i=0; i<b;i++){
            cout << A.at(i);
        }
    }
    else {
        for(int i=0; i<a; i++){
            cout << B.at(i);
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] s = scanner.next().toCharArray();
        int[] children = new int[s.length];

        for (int i = 0; i < s.length; i++) {
            children[i] = 0;
        }

        int j = 0;
        while (s[++j] != 'L');

        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'R') {
                if (0 < i && s[i - 1] != 'R') {
                    for (j = i + 1; j < s.length; j++) {
                        if (s[j] == 'L')
                            break;
                    }
                }
                if ((j - i) % 2 == 1) {
                    children[j - 1]++;
                } else {
                    children[j]++;
                }
            } else {
                if (s[i - 1] != 'L') {
                    for (j = i - 1; j >= 0; j--) {
                        if (s[j] == 'R')
                            break;
                    }
                }
                if ((i - j) % 2 == 1) {
                    children[j + 1]++;
                } else {
                    children[j]++;
                }
            }
        }

        for (int i = 0; i < s.length; i++) {
            System.out.print(children[i] + " ");
        }
    }
}



Measured memory_bytes: 44780
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){

  ll n,x,m;
  cin>>n>>x>>m;
  ll z=x,last=x;
  map<ll,ll> m1;
  vector<ll> v1;
  v1.push_back(last);
  m1[last]=0;
  int idx=-1,idx2=-1;
  rep(i,1,n){
    last=(last*last)%m;
    z=z+last;
    if(last==0) break;
    if(m1.find(last)!=m1.end()){
      idx=m1[last];
      idx2=i;
      break;
    }
    else{
      m1[last]=i;
      v1.push_back(last);
    }
  }
  if(idx2!=-1 ){
    ll cycle_sum=accumulate(v1.begin()+idx,v1.end(),0LL);
    ll ans=accumulate(v1.begin(),v1.end(),0LL);
    ll len=v1.size()-idx;
    ll l=n-idx2;
    ll num=l/len,num2=l%len;
    ans=ans+cycle_sum*num+accumulate(v1.begin()+idx,v1.begin()+idx+num2,0LL);
    cout<<ans<<endl;
  }
  else cout<<z<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    // pre();
    {solve();}
}


Measured memory_bytes: 10584
a, b, c = map(int, input().split())

list = [a, b, c]
list.sort()

max = list[2]
mid = list[1]
min = list[0]

ans = 0

ans += max - mid

if (mid - min) % 2 ==0:
    ans += (mid - min) / 2
else:
    ans += (mid- min + 1) / 2 +1

print(int(ans))


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

signed main(){
    int N;cin>>N;
    int MI=INF;
    int MA=0;
    REP(i,N){
        int a;cin>>a;
        MI=min(a,MI);
        MA=max(a,MA);
    }
    cout<<MA-MI<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int sum = 0;
        for (int i =0; i < a; i++) {
            sum += sc.nextInt();
        }
        if (sum >= n) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  map<ll, ll> mp;
  ll sum = 0;
  rep(i, n){
    cin >> a[i];
    mp[a[i]]++;
    sum += (ll)a[i];
  }
  int q;
  cin >> q;
  rep(i, q){
    ll b, c;
    cin >> b >> c;
    if(mp[b] == 0){
      cout << sum << endl;
    }else{
      ll tmp = mp[b];
      mp[b] = 0;
      sum -= b * tmp;
      mp[c] += tmp;
      sum += c * tmp;
      cout << sum << endl;
    }
  }
}

Measured memory_bytes: 9728
/*
ID: c4ts0up
LANG: C++
TASK: E - Crested Ibis vs Monster
URL: 
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const ll INF = (ll)(1e18);
ll h, n;
vector <ll> A, B;

ll dp[(ll)(1e4+5)][(ll)(1e4+5)];

ll Calc(int idx, ll currh) {
	//cout << idx << ", " << currh << endl;
	// Caso base
	if (currh <= 0) return 0LL;
	// Caso errado
	else if (idx == n && currh > 0) return INF;
	// Caso DP
	else if (dp[idx][currh] != -1) return dp[idx][currh];
	// Caso recursivo
	else {
		// Lo tomo y lo puedo volver a tomar
		ll res1 = Calc(idx, currh-A[idx]) + B[idx];
		// Lo tomo y no lo vuelvo a tomar
		ll res2 = Calc(idx+1, currh-A[idx]) + B[idx];
		// No lo tomo
		ll res3 = Calc(idx+1, currh);
		
		return dp[idx][currh] = min(res1, min(res2, res3));
	}
}

int main() {
	cin >> h >> n;
	A.resize(n);
	B.resize(n);
	for (int i=0; i<n; i++) cin >> A[i] >> B[i];
	for (int i=0; i<=n; i++) for (int j=0; j<=h; j++) dp[i][j] = -1;
	cout << Calc(0, h) << endl;
	return 0;
}


Measured memory_bytes: 80128
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... 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 U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

long long extgcd(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1; y = 0;
        return a;
    }
    long long res = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return res;
}

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

    int a, b;
    cin >> a >> b;
    long long x, y;
    extgcd(a, b, x, y);
    cout << x << " " << y << endl;
}



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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/
ll GCD(ll a, ll b){
    return (b ? GCD(b, a%b) : a);
}

/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, k; cin >> n >> k;
    vi h(n); rep(i,n) cin >> h[i];
    int cnt = 0;
    rep(i,n){
        if(h[i] >= k) cnt++; 
    }
    cout <<cnt << '\n';


}


Measured memory_bytes: 640