akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong x,y;
	cin >> x >> y;
	llong ans = inf;
	int h[2] = {1,-1};
	for(int i = 0; i <= 1; i ++){
		llong xx = x*h[i];
		if(xx <= y)
			ans = min(ans, y - xx + i);
		if(xx <= -y)
			ans = min(ans, -y-xx + i + 1);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use itertools::Itertools;
use proconio::input;
use proconio::marker::Chars;
use std::collections::HashSet;
use std::iter::Iterator;

fn main() {
    input! {
    n: usize,
    m: i32,
    q: i32,
    qq: [(i32, i32, i32, i32); q],
    }

    let mut max = 0;
    let it = (1..(m + 1)). combinations_with_replacement(n);
    for combvec in it {
        let sum = cal(&combvec, &qq);
        max = std::cmp::max(max,sum); 
    }

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

fn cal(target: &Vec<i32>, qqq: &Vec<(i32, i32, i32, i32)>) -> i32 {
    let mut sum = 0;
    for (q1, q2, q3, q4) in qqq {
        if target[(q2 - 1) as usize] - target[(q1 - 1) as usize] == *q3 {
            sum += q4;
        }
    }
    return sum;
}


Measured memory_bytes: 2148
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
	int N, q;
	cin >> N >> q;
	vector<vector<int>> V(N);
	Rep(i, q) {
		int n;
		cin >> n;
		if (n == 0) {
			int t, x;
			cin >> t >> x;
			V[t].push_back(x);
		}
		else if (n == 1) {
			int t;
			cin >> t;
			Rep(i, V[t].size()) {
				if (i) cout << " ";
				cout << V[t][i];
			}
			cout << endl;
		}
		else if (n == 2) {
			int t;
			cin >> t;
			V[t].clear();
		}
	}
	return 0;
}


Measured memory_bytes: 5792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    ll n = 0 ; 
    cin >> n ; 
    ll a[n+1] , sum[n+1] , minCost[n+1][n+1] , temp = 0 ;
    sum[0] = 0 ;
    for(ll i = 1 ; i <= n ; i++)
        cin >> a[i] , sum[i] = sum[i-1] + a[i] ;
    for(ll i = 0 ; i <= n ; i++)
        for(ll j = 0 ; j <= n ; j++)
            minCost[i][j] = 0 ;
    for(ll i = 1 ; i <= n-2+1 ; i++)
        minCost[2][i] = a[i] + a[i+1] ;
    for(ll L = 3 ; L <= n ; L++){
        for(ll i = 1 ; i <= n-L+1 ; i++){
            temp = LONG_MAX ;
            for(ll j = 1 ; j <= L-1 ; j++)
                temp = min(temp , minCost[j][i]+minCost[L-j][i+j]) ;
            minCost[L][i] = sum[i+L-1]-sum[i-1] + temp ;
        }
    }
    cout << minCost[n][1] ;
}


Measured memory_bytes: 4880
n, m = map(int, input().split())

if n == 1 and m == 1:   # 1*1
    print(1)
elif n == 1 or m == 1:  # 1*n
    if n > m:
        print(n-2)
    else:
        print(m-2)
else:                   # n*n
    print((n-2)*(m-2))


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-18;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

vint edge[200010];

int main() {
	int n, m;	cin >> n >> m;
	rep(i, m) {
		int a, b;	cin >> a >> b;	a--;	b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	rep(i, n) {
		sort(all(edge[i]));
		reverse(all(edge[i]));
	}
	rep(i, edge[0].size()) {
		int mid = edge[0][i];
		if (edge[mid][0] == n - 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 12016
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int n ;
  cin >> n ;
  vector<ll> a(n) ;
  vector<ll> b(n) ;
  REP(i,n){
    cin >> a.at(i) >> b.at(i) ;
  }
  sort(ALL(a)) ;
  sort(ALL(b)) ;
  cout << a.at(n-1)+b.at(0) <<endl ;
   


  return 0 ;
}




Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int digits( int n ) {
    int ans = 0;
    while ( n > 0 ) {
        n /= 10;
        ans += 1;
    }
    return ans;
}

int po10( int n ) {
    int ans = 1;
    rep (i, n) {
        ans *= 10;
    }
    return ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    vi d(k);
    rep (i, k) { cin >> d[i]; }
    sort(all(d));
    vi able;
    rep (i, 10) {
        if ( lower_bound(all(d), i) == upper_bound(all(d), i) ) {
            able.eb(i);
        }
    }
    int ds = digits(n);
    int samed = 0;
    rep (i, ds) {
        samed += *(end(able)-1) * po10(i);
    }
    if ( samed < n ) {
        int bigd = 0;
        rep (i, ds+1) {
            bigd += *begin(able) * po10(i);
        }
        if ( *begin(able) == 0 ) {
            bigd = *(begin(able)+1) * po10(ds);
        }
        printf("%d\n", bigd);
        return 0;
    }

//    vi nd;
//    int n_ = n;
//    rep (i, ds) {
//        nd.eb(n_ % 10);
//        n_ /= 10;
//    }
//    reverse(all(nd));
//    int ans = 0;

    FOR (i, n, 10000) {
        int i_ = i;
        int dsi = digits(i_);
        bool flag = true;
        rep (j, dsi) {
            int m = (i_ % 10);
            if ( lower_bound(all(able), m) == upper_bound(all(able), m) ) {
                flag = false;
                break;
            }
            i_ /= 10;
        }
        if ( flag ) {
            printf("%d\n", i);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 888
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	int a, b;
	cin >> a >> b;
	cout << a*b << endl;
}

Measured memory_bytes: 3088
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, std::vector<ll> a) {
  sort(a.rbegin(), a.rend());

  ll asum = 0;
  ll bsum = 0;
  rep(i, N) {
    if (i % 2 == 0) {
      asum += a.at(i);
    } else {
      bsum += a.at(i);
    }
  }

  cout << asum - bsum << endl;
}

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


Measured memory_bytes: 256
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        //r(a, 0, "");
        Scanner in = new Scanner(System.in);
            int N = in.nextInt();
            int W = in.nextInt();
            if(W >= N) {
                System.out.println("unsafe");
            } else {
                System.out.println("safe");
            }

    }

}


Measured memory_bytes: 27000
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define eps 1e-9
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int n,m,X[110],Y[110],C[110];
inline double pf(double x){return x*x;}
inline bool pd(double x,double y,double limit)
{
	int ans=n;
	for(int i=1;i<=n;i++)if(sqrt(pf(X[i]-x)+pf(Y[i]-y))*C[i]-limit>eps)ans--;
	if(ans>=m)return true;
	else return false;
}
inline bool check(double limit)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			double r1=limit/C[i],r2=limit/C[j],dis=sqrt(pf(X[i]-X[j])+pf(Y[i]-Y[j]));
			int p1=i,p2=j;
			if(r1<r2)swap(r1,r2),swap(p1,p2);
			if(r1-dis-r2>eps)
			{
				if(pd(X[p2],Y[p2],limit)==true)return true;
			}
			else if(r1+r2-dis>eps)
			{
				double uf=(pf(r1)-pf(r2)+pf(dis))/(2.0*dis),x0=X[p1]+uf/dis*(X[p2]-X[p1]),y0=Y[p1]+uf/dis*(Y[p2]-Y[p1]);
				double ul=sqrt(pf(r1)-pf(uf));
				if(pd(x0-ul/dis*(Y[p2]-Y[p1]),y0+ul/dis*(X[p2]-X[p1]),limit)==true)return true;
				if(pd(x0+ul/dis*(Y[p2]-Y[p1]),y0-ul/dis*(X[p2]-X[p1]),limit)==true)return true;
			}
		}
	}return false;
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    n=read(),m=read();
    for(int i=1;i<=n;i++)X[i]=read(),Y[i]=read(),C[i]=read();
    if(m==1){puts("0");return 0;}
    double l=0,r=300000,ans;
	while(r-l>eps)
	{
		double mid=(l+r)/2.0;
		if(check(mid)==true)ans=mid,r=mid;
		else l=mid;
	}printf("%.7lf\n",ans);
    return 0;
}

Measured memory_bytes: 128
program test
implicit none
integer :: n,i,j,k,l,t,combo,max_combo
integer :: retsu(2*10**5) = 0, jyunjyo(2*10**5) = 0

read(*,*) n

do i=1,n
	read(*,*) retsu(i)
enddo

do i=1,n
	jyunjyo(retsu(i)) = i
enddo

max_combo = 1
combo = 1

do i = 1,n-1
	if(jyunjyo(i+1) > jyunjyo(i)) then
		combo = combo + 1
		max_combo = max(combo,max_combo)
	else
		combo = 1
	endif
enddo

write(*,*) n-max_combo

end program

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  sort(ALL(s));
  if(s=="abc"){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int c;
string a;
int main()
{
	int i;
	cin >> a;
	for (i = 0; i < a.size(); i++) if (a[i] == 'x') c++;
	if (c >= 8) cout << "NO";
	else cout << "YES";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(all(h));
  int ans = 1e9;
  for (int i = 0; i <= n - k; i++) {
    ans = min(ans, abs(h[i] - h[i + k - 1]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int f(int x)
{
    if (x < 0)
        x *= -1;
    return x;
}

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

    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int ans = INF, num[10] = {};
    while (1)
    {
        num[0]++;
        rep(i, n) if (num[i] == 4)
        {
            num[i] = 0;
            num[i + 1]++;
        }
        if (num[n] == 1)
            break;
        int cost[4] = {};
        rep(i, n) cost[num[i]] += l[i];
        int tmp = -30;
        rep(i, n) if (num[i] != 3) tmp += 10;
        if (cost[0] * cost[1] * cost[2] == 0)
            continue;
        tmp += f(a - cost[0]) + f(b - cost[1]) + f(c - cost[2]);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using p = pair<int, int>;

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

    long long x, y;
    x = n / (a + b);
    y = n % (a + b);
    //cout << x << y << endl;

    if (y <= a)
        cout << a * x + y;
    else
        cout << a * x + a;

    return 0;
}

Measured memory_bytes: 256
string = input()
n = int(input())
print_s=[]
for i in range(n):
    order = [i for i in input().split()]
    if order[0] == "replace":
        string = list(string)
        for i in range(len(order[3])):
            string[int(order[1])+i]=order[3][i]
        string= "".join(string)
    elif order[0] == "reverse":
        string = string.replace(string[int(order[1]):int(order[2])+1],
                                string[int(order[2])-len(string):
                                       int(order[1])-len(string)-1:-1])
    else:
        print_s.append(string[int(order[1]):int(order[2])+1])
for i in range(len(print_s)):
    print(print_s[i])


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

using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define loop(i, n) for(int i = 0 ; i < n ; ++i)
#define LOOP(i, a, b) for(int i = a ; i < b ; ++i)
#define max3(a, b, c) max(a, max(b,c))
#define max4(a, b, c, d) max3(a, b, max(c, d))
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c-'0')
#define ltr(c) (int)(c-'a')
#define INF 1e18
#define inf 1e9
#define MOD 1000000007 //check
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

ll n, v[405], ps[405];
ll dp[405][405];

ll combine(int l, int r)
{
	if(l == r) return 0;
	if(l+1 == r) return v[l]+v[r];
	ll &ans = dp[l][r];
	if(ans != -1LL) return ans;
	ans = INF;
	LOOP(i, l, r) ans = min(ans, combine(l, i) + combine(i+1, r) + ps[r+1]-ps[l]);
	return ans;
}
int main() {
	_69e27;
	memset(dp, -1LL, sizeof(dp));
	cin >> n;
	ps[0] = 0;
	loop(i, n)
	{
		 cin >> v[i];
		 ps[i+1] = ps[i] + v[i];
	}
	cout << combine(0, n-1);
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    if (n % 10 == n / 100){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import queue

def solve(K: int):
    q = queue.Queue()
    # initialize
    for i in range(1, 10):
        q.put(i)
    
    for i in range(K):
        res = q.get()
        first = res % 10
        if first == 0:
            q.put(res * 10 + first)
            q.put(res * 10 + first + 1)
        elif first == 9:
            q.put(res * 10 + first - 1)
            q.put(res * 10 + first)
        else:
            q.put(res * 10 + first - 1)
            q.put(res * 10 + first)
            q.put(res * 10 + first + 1)

    print(res)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12456
import java.util.*;
import java.io.*;

class Main {
  int N, len;
  int[] C;
  int[] S;
  int[] F;
  int[] ans;
  public static void main(String[] args) {
    Main m = new Main();
    m.input();
    m.solve();
    m.out();
  }

  public void input() {
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    C = new int[N-1];
    S = new int[N-1];
    F = new int[N-1];
    ans = new int[N];
    len = C.length;
    for(int i = 0; i < len; i++) {
      C[i] = sc.nextInt();
      S[i] = sc.nextInt();
      F[i] = sc.nextInt();
    }
  }

  public void solve() {
    int t;
    for(int i = 0; i <= len; i++) {
      ans[i] = 0;
    }
    for(int i = 0; i < len; i++) {
      ans[i] += (S[i] + C[i]);
      for(int j = i + 1; j < len; j++) {
        if(ans[i] <= S[j]) {
          ans[i] = S[j];
          ans[i] += C[j];
        } else {
          t = S[j];
          while(true) {
            if(t < ans[i]) {
              t += F[j];
            } else {
              ans[i] = t;
              break;
            }
          }
          ans[i] += C[j];
        }
      }
    }
  }

  public void out() {
    for(int i = 0; i <= len; i++) {
      System.out.println(ans[i]);
    }
  }
}


Measured memory_bytes: 26116
n = int(input())
V = [int(v) for v in input().split()]

V1 = [V[n] for n in range(0, n, 2)] #v1, v3, v5, ...
V2 = [V[n] for n in range(1, n, 2)] #v2, v4, v6, ...

mx_V1 = max(V1)
V1_cnt = [[0, 0]] # V1に一種類しか数字が存在しなかったときのために
for i in range(1, mx_V1+1):
  V1_cnt.append([i, 0])
for v in V1:
  V1_cnt[v][1] += 1  
V1_cnt.sort(key=lambda x: x[1], reverse=True)

mx_V2 = max(V2)
V2_cnt = [[0, 0]] # V2に一種類しか数字が存在しなかったときのために
for j in range(1, mx_V2+1):
  V2_cnt.append([j, 0])
for v in V2:
  V2_cnt[v][1] += 1  
V2_cnt.sort(key=lambda x: x[1], reverse=True)

mxnum_V1_cnt = V1_cnt[0][0] #V1の中で一番出現回数多い数字
mxnum_V2_cnt = V2_cnt[0][0] #V2の中で一番出現回数多い数字
if mxnum_V1_cnt != mxnum_V2_cnt:
  ans = n - (V1_cnt[0][1] + V2_cnt[0][1])
else:
  ans = n - max(V1_cnt[0][1] + V2_cnt[1][1], V1_cnt[1][1] + V2_cnt[0][1])

print(ans)

Measured memory_bytes: 35896
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 3e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int W, H, C, n, ans;

struct pt {
	int x, y;
	inline bool operator < (const pt &v) const { return x < v.x; }
}d[maxN];

inline bool in(const pt &x, const pt &y) {
	return y.x <= x.x && x.y <= y.y;
}

inline int calc(const pt &x, const pt &y, const pt &l, const pt &r) {
	return abs(y.x - x.x) + min(l.y, r.y) - max(l.x, r.x);
}

void solve(int l, int r) {
	if (l >= r) return;	
	static pt a[maxN];
	static deque<pt> q;
	int mid = (l + r) >> 1;
	solve(l, mid);
	solve(mid+1, r);

	for (int up = H, dw = 0, i = mid; i >= l; -- i) {
		a[i] = (pt){dw, up};
		if (d[i].y >= C) up = min(up, d[i].y);
		if (d[i].y <= C) dw = max(dw, d[i].y); 
	}

	for (int up = H, dw = 0, i = mid+1; i <= r; ++ i) {
		a[i] = (pt){dw, up};
		if (d[i].y >= C) up = min(up, d[i].y);
		if (d[i].y <= C) dw = max(dw, d[i].y);
	}

	for (int i = l, j = r; i <= mid; ++ i) {
		for (; j > mid && !in(a[i], a[j]); -- j);
		if (j > mid && in(a[i], a[j])) ans = max(ans, calc(d[i], d[j], a[i], a[j])); 
	}

	for (int i = r, j = l; i > mid; -- i) {
		for (; j <= mid && !in(a[i], a[j]); ++ j);
		if (j <= mid && in(a[i], a[j])) ans = max(ans, calc(d[i], d[j], a[i], a[j]));
	}

#define eval(v) ((v).x + (v).y)
	while (!q.empty()) q.pop_back();
	for (int i = mid, j = mid+1; i >= l; -- i) {
		for (; j <= r && a[j].x <= a[i].x; ++ j) {
			pt nw = (pt){d[j].x, a[j].y};
			while (!q.empty() && eval(q.back()) <= eval(nw)) q.pop_back();
			q.push_back(nw);
		}
		while (!q.empty() && q.front().y > a[i].y) q.pop_front();
		if (!q.empty()) ans = max(ans, eval(q.front()) - d[i].x - a[i].x);
	}
#undef eval
#define eval(v) ((v).y - (v).x)
	while (!q.empty()) q.pop_back();
	for (int i = mid + 1, j = mid; i <= r; ++ i) {
		for (; j >= l && a[j].x <= a[i].x; -- j) {
			pt nw = (pt){d[j].x, a[j].y};
			while (!q.empty() && eval(q.back()) <= eval(nw)) q.pop_back();
			q.push_back(nw);
		}
		while (!q.empty() && q.front().y > a[i].y) q.pop_front();
		if (!q.empty()) ans = max(ans, eval(q.front()) + d[i].x - a[i].x);
	}
#undef eval
}

int main() {

	W = ri(), H = ri(), n = ri();
	rep (i, 1, n) d[i].x = ri(), d[i].y = ri();
	ans = max(W, H) + 1;

	sort(d+1, d+n+1); C = H / 2;
	d[0] = (pt){0, C}, d[n+1] = (pt){W, C};
	solve(0, n+1);

	rep (i, 1, n) swap(d[i].x, d[i].y); swap(H, W);
	sort(d+1, d+n+1); C = H / 2;
	d[0] = (pt){0, C}, d[n+1] = (pt){W, C};
	solve(0, n+1);

	printf("%d\n", ans << 1);

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



int dist[100005][3];

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

	int N, M;
	cin >> N >> M;
	vector<VI> to(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
	}
	int sv, tv;
	cin >> sv >> tv;
	sv--; tv--;
	REP(i, N) {
		REP(j, 3) {
			dist[i][j] = LLINF;
		}
	}
	queue<pii> q;
	q.push(pii(sv, 0));
	dist[sv][0] = 0;
	while (!q.empty()) {
		int v = q.front().first;
		int l = q.front().second;
		q.pop();

		for (int u : to[v]) {
			int nl = (l + 1) % 3;
			if (dist[u][nl] != LLINF)continue;
			dist[u][nl] = dist[v][l] + 1;
			q.push(pii(u, nl));
		}
	}
	int ans = dist[tv][0];
	if (ans == LLINF) ans = -1;
	else ans /= 3;
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 8064
#pragma GCC optimize("Ofast,fast-math,unroll-loops,inline,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,abm,mmx,popcnt")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;
#define pb push_back
#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int s1 = 60 * h1 + m1;
    int s2 = 60 * h2 + m2;
    int t = abs(s1 - s2);
    cout << max(t - k, 0LL);

}

Measured memory_bytes: 3608
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())


inputDataList = []
data = []
for i in range(n):
    inputData = input().split()
    inputDataList = [int(n) for n in inputData]
    data.append(inputDataList)

mat = [[-1 for i in range(n)] for j in range(n)] #二次元の静的確保


def calc_dis(x1, y1, x2, y2):
    dis = pow(x1 - x2, 2) + pow(y1 - y2, 2)
    dis = math.sqrt(dis)
    return dis


def path_dis(path):
    dis = 0
    for i in range(len(path)-1):
        dis += mat[path[i]][path[i+1]]
    return dis

for i in range(n):
    for j in range(n):
        mat[i][j] = calc_dis(data[i][0], data[i][1], data[j][0], data[j][1])

perm = list(itertools.permutations(range(n)))

ans = 0
for p in perm:
    tmp_ans = path_dis(p)
    ans += tmp_ans

ans = ans/len(perm)
print(ans)





Measured memory_bytes: 10512
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	char a,b,c;
	cin>>a>>b>>c;
	int d=0;
	if(a=='o')
		d++;
	if(b=='o')
		d++;
	if(c=='o')
		d++;
	cout<<700+100*d<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    vector<int> y = x;
    sort(all(y));
    int mid1 = y[n/2-1], mid2 = y[n/2];
    rep(i,n){
        int xx = x[i];
        if (xx <= mid1) cout << mid2 << endl;
        else cout << mid1 << endl;
    }
}

Measured memory_bytes: 4720
import java.util.Scanner;

public class Main {
	private Scanner sc;

	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);

		while (sc.hasNextLine()) {
			int lines = Integer.parseInt(sc.nextLine());
			if (lines == 0) break;

			double[] x = new double[lines];
			double[] y = new double[lines];
			for (int i = 0; i < lines; i++) {
				String[] nico = sc.nextLine().split(",");
				x[i] = Double.parseDouble(nico[0]);
				y[i] = Double.parseDouble(nico[1]);
			}
			
			int max = 1;
			for (int i = 0; i < lines; i++) {
				for (int j = (i + 1); j < lines; j++) {
					double d = calc(x[i], x[j], y[i], y[j]);
					if (d > 4.0) continue;
					
					double[] px = new double[1];
					double[] py = new double[1];
					
					if ((x[i] == x[j]) && (y[i] == y[j])) {
						px[0] = x[i];
						py[0] = y[i];
					} else {
						double cr = Math.atan2(-(y[j] - y[i]), (x[j] - x[i]));
						double dr = Math.atan2(Math.sqrt(1.0 - (d / (2.0 * 2.0))), (Math.sqrt(d) / 2.0));
						
						px = new double[2];
						py = new double[2];

						px[0] = x[i] + Math.cos(cr - dr);
						py[0] = y[i] - Math.sin(cr - dr);
						
						px[1] = x[i] + Math.cos(cr + dr);
						py[1] = y[i] - Math.sin(cr + dr);
					}
					
					for (int p = 0; p < px.length; p++) {
						int tmp = 0;
						for (int k = 0; k < lines; k++) {
							if (calc(px[p], x[k], py[p], y[k]) < (1.0 + 1E-6)) tmp++;
						}
						
						if (max < tmp) max = tmp;
					}
				}
			}
			System.out.println(max);
		}
	}
	
	public double calc(double x0, double x1, double y0, double y1) {
		return ((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
	}
}

Measured memory_bytes: 29348
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

int main() {
  kyun;
  int a;
  cin >> a;
  cout << 3 * a * a;
  hinata;
}

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

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("maxflow.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,y;
    cin>>n>>y;
    int a=0,b=0,c=0;
    while(y){
        if(y>=10000){
            a++;
            y-=10000;
        }
        else if(y>=5000){
            b++;
            y-=5000;
        }
        else{
            c++;
            y-=1000;
        }
    }
    while(a+b+c<n){
        if(n>=a+b+c+4){
            if(b>0){
                b--;
                c+=5;
            }
            else if(a>0){
                a--;
                b+=2;
            }
            else{
                break;
            }
        }
        else if(n>=a+b+c+1){
            if(a>0){
                a--;
                b+=2;
            }
            else{
                break;
            }
        }
    }
    if(a+b+c!=n){
        cout<<"-1 -1 -1"<<endl;
    }
    else{
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

ll f(ll a, ll b, ll x) {
    return a * x / b - a * (x / b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans = 0;
    if (b > n) {
        cout << f(a, b, n) << endl;
    }
    else {
        cout << f(a, b, b - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    solve2
  }

  def solve2(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, m = sc.nextInt
    val firstCon = scala.collection.mutable.Set[Int]()
    val lastCon = scala.collection.mutable.Set[Int]()
    val con = Array.fill[ArrayBuffer[Int]](n)(new ArrayBuffer[Int]())
    for (i <- 0 until m) {
      val a = sc.nextInt
      val b = sc.nextInt

      if (a == 1) firstCon += b
      if (b == n) lastCon += a
    }

    println(if ((firstCon & lastCon).nonEmpty) "POSSIBLE" else "IMPOSSIBLE")

  }


  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, m = sc.nextInt
    val con = Array.fill[ArrayBuffer[Int]](n)(new ArrayBuffer[Int]())
    for (i <- 0 until m) {
      val a = sc.nextInt - 1
      val b = sc.nextInt - 1
      con(a).append(b)
      con(b).append(a)
    }

    val destNum = n - 1
    var ans = false
    for (num <- con(0)) {
      if (con(num).contains(destNum)) {
        ans = true
      }
    }

    println(if (ans) "POSSIBLE" else "IMPOSSIBLE")

  }
}


Measured memory_bytes: 133508
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $enable = [];
  $enable[1] = true;
  $r1 = 6;
  while($n >= $r1){
    $enable[$r1] = true;
    $r1 *= 6;
  }
  $r2 = 9;
  while($n >= $r2){
    $enable[$r2] = true;
    $r2 *= 9;
  }
  
  $b = array_keys($enable);
  sort($b);

  $dp = range(0,$n);

  for($i=1;$i<=$n;$i++){
    for($j=0;$j<count($b);$j++){
      if($i >= $b[$j]){
        $dp[$i] = min($dp[$i], $dp[$i-$b[$j]]+1);
      }                                   
    }
  }

  echo $dp[$n];

Measured memory_bytes: 19020
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;
const long long MOD = 1000000007;

int H, W, N;
int sr, sc;
std::string S, T;

std::pair<int, int> calc_range(int length, const char dec, const char inc) {
    int lb = 1;
    int ub = length;

    for (int i = N - 1; 0 <= i; i--) {
        if (T[i] == dec) {
            ub = std::min(ub + 1, length);
        } else if (T[i] == inc) {
            lb = std::max(lb - 1, 1);
        }

        if (S[i] == dec) {
            lb++;
        } if (S[i] == inc) {
            ub--;
        }
        if (lb > ub) {
            return std::pair<int, int>({-1, -1});
        }
    }
    return std::pair<int, int>({lb, ub});
}

int main(int argc, char **argv) {
    std::cin >> H >> W >> N;
    std::cin >> sr >> sc;
    std::cin >> S;
    std::cin >> T;

    std::pair<int, int> range_w, range_h;
    range_w = calc_range(W, 'L', 'R');
    range_h = calc_range(H, 'U', 'D');

    if (range_h.first <= sr && sr <= range_h.second && range_w.first <= sc && sc <= range_w.second) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 776
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;
  ll a, k;

  scanf("%d%lld", &n, &k);

  int counter[70] = {};

  for(int i=0;i<n;i++){
    scanf("%lld", &a);
    for(int j=0;a;j++){
      counter[j] += a%2;
      a/=2;
    }
  }

  int m = 0;
  for(ll i=1;i<=k;i*=2) m++;

  debug(k); debug(m);

  for(int i=0;i<=m;i++) debug(counter[i]);

  ll dp[61][2] = {};

  for(int i=0;i<=60;i++)
    dp[i][0] = dp[i][1] = -LLINF;

  dp[60][1] = 0;

  for(int i=59;i>=0;i--){
    if (i >= m) {
      dp[i][1] = max(dp[i][1], dp[i+1][1] + counter[i] * (1LL << i));
    }else if(k & (1LL << i)){
      dp[i][1] = max(dp[i][1], dp[i+1][1] + (n-counter[i]) * (1LL << i));
      dp[i][0] = max(dp[i][0], dp[i+1][1] + counter[i] * (1LL << i));
      dp[i][0] = max(dp[i][0], dp[i+1][0] + (n-counter[i]) * (1LL << i));
      dp[i][0] = max(dp[i][0], dp[i+1][0] + counter[i] * (1LL << i));
    }else{
      dp[i][1] = max(dp[i][1], dp[i+1][1] + counter[i] * (1LL << i));
      dp[i][0] = max(dp[i][0], dp[i+1][0] + counter[i] * (1LL << i));
      dp[i][0] = max(dp[i][0], dp[i+1][0] + (n-counter[i]) * (1LL << i));
    }
  }

  cout << max(dp[0][0], dp[0][1]) << endl;


  return 0;
}


Measured memory_bytes: 256
// Code for A - Study Scheduling
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int h = h2 - h1;
  int m = m2 - m1;
  if (!(m >= 0)) {
    h--;
    m = m + 60;
  }

  int total = h * 60 + m;

	cout << total - k << endl;
	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
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 S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll A,B, C;
    cin >> A >> B >> C;
    cout << max(C-(A-B), 0ll) << endl;

    return 0;
}

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

int main(){
	int a,b; cin>>a>>b;
	if(a>0&&b>0) cout<<"Positive"<<endl;
	else if(a<0&&b>0) cout<<"Zero"<<endl;
	else {
		int r=-a-b;
		if(r%2==1) cout<<"Positive"<<endl;
		else cout<<"Negative"<<endl;
	}
}

Measured memory_bytes: 3564
#include<stdio.h>

#define LENGTH 10

int main(){
	int i,j,temp;
	int data[LENGTH];
	for(i=0;i<LENGTH;i++){
        scanf("%d",&data[i]);
	}
	for(i=0; i < LENGTH-1;i++){
		for(j=0;j<LENGTH-i-1;j++){
			if(data[j]>data[j+1]){
				temp=data[j+1];
				data[j+1]=data[j];
				data[j]=temp;
			}
		}
	}
	printf("%d\n%d\n%d\n",data[LENGTH-1],data[LENGTH-2],data[LENGTH-3]);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(){

	int x,y,s;
	while(cin>>x>>y>>s){
		if(x==0 && y==0 && s==0)break;

		x+=100;
		y+=100;

		int max=0;

		for(int i=1;i<s;i++){
			for(int j=1;j<s;j++){
				if( (i*x/100 + j*x/100) == s){
					if(max<= (i*y/100 +j*y/100)){
						max = i*y/100 +j*y/100;
					}
				}
			}
		}

		cout<<max<<endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define N 1000010
inline int read() {
	int x=0;
	char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int x[N];
char s[N],t[N];
int main() {
	int n=read(),p=0;
	scanf("%s%s",&s,&t);
	for (int i=n-1,j=n,k=0,l=0;i>=0;i--) {
	   	if (j>i && t[i]!=s[i]) j=i;
	   	if (j<=i && t[i]!=s[j]) {
			for (;j>=0 && t[i]!=s[j];j--);
			if (j<0) return puts("-1"),0;
			k++,l++,x[j+l]++,p=max(p,k);
		}
	   	k-=x[i+l],x[i+l]=0;
    }
    printf("%d\n",p);
	return 0;
}

Measured memory_bytes: 6144
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
ll f(ll x)//f(0,x)的异或和
{
   if(x%4==0)
   {
       return x;
   }
   if(x%4==1)
   {
       return 1;
   }
   if(x%4==2)
   {
       return x+1;
   }
   if(x%4==3)
   {
       return 0;
   }
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll ans=f(a-1)^f(b);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
 
int main()
{
int w, h, x, y, r;
scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
if (x < r || y < r || w < x + r || h < y + r)
printf("No\n");
else
printf("Yes\n");
 
return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

vector<int> tree[100005];

int main(){
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    tree[a].pb(b);
    tree[b].pb(a);
  }

  vector<int> df(n, INF), ds(n,INF);

  auto djk = [&](vector<int> &d, int from){
    d[from] = 0;
    queue<int> q;
    q.push(from);
    while(!q.empty()){
      int x = q.front(); q.pop();
      for(auto to : tree[x]) if(d[to]==INF){
        d[to] = d[x] +1;
        q.push(to);
      }
    }
  };

  int fe=0, su=0;
  djk(df,0);
  djk(ds,n-1);

  rep(i,n){
    if(df[i]<=ds[i]) fe++;
    else su++;
  }

  assert(fe + su == n);

  if(fe > su) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  return 0;
}


Measured memory_bytes: 6656