akhauriyash/Code-Regression huggingface dataset:
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

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

int main()
{
  int n;
  cin >> n;
  int ar[n];
  
  for(int i = 0 ; i < n ; ++i)
    cin >> ar[i];
  
  int dp[n+1];
  dp[0] = 0;
  dp[1] = abs(ar[1] - ar[0]);
  
  for(int i = 2 ; i < n ; ++i)
  {
    dp[i] = min(dp[i-1] + abs(ar[i-1] - ar[i]), dp[i-2] + abs(ar[i-2] - ar[i]));
  }
  cout << dp[n-1] << endl;
}

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

class BIT {
  int size;
  vector<int> v;
public:
  BIT(int n)
    : size(n), v(n + 1) {
  }
  
  void add(int i, int del) {
    ++i;
    for (; i <= size; i += i & -i) {
      v[i] += del;
    }
  }
  
  int get(int i) {
    int sum = 0;
    for (; i > 0; i -= i & -i) {
      sum += v[i];
    }
    return sum;
  }
};

int n;
long a[200000];
long p[200001];
int main() {
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] -= k;
  }
  partial_sum(a, a + n, p + 1);

  vector<int> ord(n + 1);
  iota(ord.begin(), ord.end(), 0);
  
  stable_sort(ord.begin(), ord.end(), [](int i, int j) {
    return p[i] < p[j];
  });
  
  BIT bit(n + 1);
  long cnt = 0;
  for (int i : ord) {
    cnt += bit.get(i);
    bit.add(i, 1);
  }
  cout << cnt << endl;
}

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

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

    int N;  cin >> N;
    map<string, int> mp{
        {"AC",0},
        {"WA",0},
        {"TLE",0},
        {"RE",0}
    };

    rep(i,N){
        string S;    cin >> S;
        mp[S]++;
    }



    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    

    return 0;
}

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

using namespace std;

const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};

int h, w;
int ans;
char grid[1024][1024];
int dist[1024][1024];

int main() {
	queue<pair<int, int>> q;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	for (int j = 0; j < w; j++)
	{
		cin >> grid[i][j];
		if (grid[i][j] == '#') 
			q.emplace(i, j);
	}
	
	while (q.size()) {
		int r, c;
		tie(r, c) = q.front();
		q.pop();
		for (int i = 0; i < 4; i++) {
			int nr, nc;
			nr = r + dr[i];
			nc = c + dc[i];
			if (nr < 0 || nr >= h || nc < 0 || nc >= w) continue;
			if (grid[nr][nc] == '#') continue;
			grid[nr][nc] = '#';
			dist[nr][nc] = dist[r][c] + 1;
			ans = max(ans, dist[nr][nc]);
			q.emplace(nr, nc);
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 10368
s = int(input())
a=[s]
cnt = 1
for i in range(1000000):
    if a[-1]%2 == 0:
        a2 = int(a[-1] /2)
        cnt += 1
        if a2 in a:
            print(cnt)
            break
        a.append(a2)
            
    else:
        a2 = a[-1]*3 + 1
        cnt += 1
        if a2 in a:
            print(cnt)
            break
        a.append(a2)
    

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

int pow(int x, int n)
{
  int ret = 1;
  while (n > 0)
  {
    if (n & 1)
      ret = ret * x;
    x = x * x;
    n >>= 1;
  }
  return ret;
}

int main()
{
  int m, k;
  cin >> m >> k;
  int m2 = pow(2, m);
  if (m2 <= k)
  {
    printf("-1\n");
    return 0;
  }
  if (m == 1)
  {
    if (k == 0)
      printf("1 0 0 1\n");
    else
      printf("-1\n");
    return 0;
  }
  for (int i=m2-1; i>=0; i--)
    if (i != k)
      printf("%d ", i);
  printf("%d ", k);
  rep(i, m2)
    if (i != k)
      printf("%d ", i);
  printf("%d\n", k);
  return 0;
}

Measured memory_bytes: 1792
fun main(arr:Array<String>) {
    val s = "Z" + readLine()!! + "Z"
    var start = 0
    var ans = 0
    for(i in s.indices) {
        if("ACGT".contains(s[i])) {
            continue
        }
        ans = Math.max(ans, i - start)
        start = i + 1
    }
    println(ans)
}

Measured memory_bytes: 31820
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n, x;
  cin >> x >> n;
  vecint p(102, 0);
  REP(i, n) {
    int k;
    cin >> k;
    p[k] = 1;
  }
  if (p[x] == 0) {
    cout << x << endl;
    return 0;
  }
  REP(i, 102) {
    if (p[x - i] == 0) {
      cout << x - i << endl;
      return 0;
    }
    if (p[x + i] == 0) {
      cout << x + i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;



int main(void){
    ll w, h, x, y; cin >> w >> h >> x >> y;
    double ans = (double)w*h/2.0;
    if(w == x*2 && h == y*2)printf("%lf 1\n", ans);
    else printf("%lf 0\n", ans);
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n), b(n), c(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];
  vsort(a); vsort(b); vsort(c);
  
  ll ans=0;
  rep(i,n){
    auto itr1=lower_bound(all(a), b[i]);
    if(itr1==a.begin()) continue;
    ll x=itr1-a.begin();
    auto itr2=upper_bound(all(c), b[i]);
    if(itr2==c.end()) continue;
    ll y=c.end()-itr2;
    ans+=x*y;
  }
  
  cout<<ans<<endl;
}

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

using namespace std;

int x[100], y[100], a[100];

int main() {

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

	int W, H, N;
	cin >> W >> H >> N;
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i] >> a[i];
	}
	int x1 = 0, x2 = W, y1 = 0, y2 = H;
	for (int i = 0; i < N; ++i) {
		if (a[i] == 1) {
			x1 = max(x1, x[i]);
		}
		else if (a[i] == 2) {
			x2 = min(x2, x[i]);
		}
		else if (a[i] == 3) {
			y1 = max(y1, y[i]);
		}
		else if (a[i] == 4) {
			y2 = min(y2, y[i]);
		}
	}
	if (x2 - x1 < 0 || y2 - y1 < 0) cout << 0;
	else cout << (x2 - x1) * (y2 - y1) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 2e5 + 5;

using namespace std;

int n, head[N], cnte, sz[N], fa[N], dep[N];
struct edge { int to, nxt; } e[N << 1]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

inline void adde(int u, int v) { e[++cnte] = (edge) { v, head[u] }, head[u] = cnte; }

void dfs(int u, int pa)
{
	sz[u] = 1, fa[u] = pa, dep[u] = dep[pa] + 1;
	for(int v, i = head[u]; i; i = e[i].nxt)
		if((v = e[i].to) != pa) dfs(v, u), sz[u] += sz[v]; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	for(int u, v, i = 1; i < n; i++)
		u = read <int> (), v = read <int> (), adde(u, v), adde(v, u);
	dfs(1, 0); int u = n; 
	while(dep[fa[u]] > (dep[n] + 1) / 2) u = fa[u]; 
	int x = sz[u], y = n - sz[u];
	if(x >= y) puts("Snuke");
	else puts("Fennec"); 
	return 0; 
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

string ans = "No";

void rec(int n) {
  if(n == 0) {
    ans = "Yes";
    return;
  }
  if(n - 4 < 0 && n - 7 < 0) return;
  if(n - 4 >= 0) rec(n - 4);
  if(n - 7 >= 0) rec(n - 7);
}

int main() {
  int N; cin >> N;
  rec(N);
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, m);
    Cin(string, s, t);
    
    int cd = gcd(n, m);
    ll cm = (ll) n * m / cd;
    
    For(i, cd){
        if(s[cm/m*i] != t[cm/n*i]){
            Cout(-1); return 0;
        }
    }
    Cout(cm);
}


Measured memory_bytes: 512
n, m = gets.split(" ").map(&:to_i)
minr = 1000000
maxl = -1
m.times do |i|
  l, r = gets.split(" ").map(&:to_i)
  maxl = [maxl, l].max
  minr = [minr, r].min
end
puts [minr - maxl + 1, 0].max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
string str;
int dp[100010][110][2], d;
int f(int pos, int sum, int flag) {
    if(pos == (int)str.size()) return sum == 0;
    int &ans = dp[pos][sum][flag];
    if(ans == -1){
        int lim = str[pos] - '0';
        ans = 0;
        for(int i = 0; i <= 9; i++) {
            if(flag || i < lim) ans += f(pos + 1, (sum + i + d) % d, 1);
            else if(i == lim) ans += f(pos + 1, (sum + i + d) % d, 0);
            ans %= MOD;
        }
    }
    return ans;
}
int main(){
    fast;
    memset(dp, -1, sizeof dp);
    cin >> str >> d;
    cout << (f(0,0,0) - 1 + MOD) % MOD << "\n";
    return 0;
    return 0;
}


Measured memory_bytes: 90288
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int32_t main()
{
	BOOST
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
	cout << "OUTPUT \n";
#endif
	int t; //cin >> t;
	t = 1;
	while (t--)
	{
		int n, x, y;
		cin >> n >> x >> y;
		int z;
		if (n % x == 0)
			z = n / x;
		else
		{
			z = (n / x) + 1;
		}
		int ans = z * y;
		cout << ans << "\n";
	}
	return 0;

}


Measured memory_bytes: 3632
#include <stdio.h>


 
int main(){
    int S, h, m, s;
    scanf("%d", &S);
    h = S / 3600;
    m = S % 3600 / 60;
    s = S % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n,m,x;
    cin >> n >> m >>x;
    vvll satu(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++){
            ll z;
            cin >>z;
            satu.at(i).push_back(z);
        }
    }
    ll ans = 1e18;
    for(int i=0;i<pow(2,n);i++){
        ll now =0;
        vector<ll>che(m,0);
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                now+=satu.at(j).at(0);
                for(int k=0;k<m;k++){
                    che.at(k)+=satu.at(j).at(k+1);
                }
            }
        }
        bool ok = true;
        for(int k=0;k<m;k++){
            if(che.at(k)<x)ok=false;
        }
        if(ok){
            ans = min(ans,now);
        }
    }
    if(ans==1e18){
        cout<<-1<<endl;
    }
    else{
        cout<<ans<<endl;
    }
}
    



Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N, M;
int A[100005], B[100005];
vector<int> G[100005];
int D[100005];
bool loop;

void dfs(int u) {
  for (auto v: G[u]) {
    if (D[v] == -1) {
      D[v] = 1 - D[u];
      dfs(v);
    } else if (D[v] == 1 - D[u]) {
      continue;
    } else {
      loop = true;
    }
  }
}

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

  cin >> N >> M;
  rep(i, M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }

  rep(i, N) D[i] = -1;
  D[0] = 0;
  loop = false;
  dfs(0);

  if (loop) {
    cout << (ll)N*(N - 1)/2 - M << endl;
  } else {
    int z = 0;
    rep(i, N) if (D[i] == 0) z++;
    cout << (ll)z*(N - z) - M << endl;
  }
  return 0;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
using lint = long int;
#define pb push_back
#define MOD 1000000007

lint N, K, val;
lint res = 1;
lint plen, nlen;
bool sign;
vector<lint> pA;
vector<lint> nA;

bool is_plus(lint p, lint k){
    if(k & 1){
        if(p > 0) return true; //正の数が皆無
        else return false;
    }
    return true;  //偶数は確実
}


void use_minus_val(lint& n, lint& kk, lint& r){
    while(kk > 0){
        r *= abs(nA[n]); r %= MOD;
        r *= abs(nA[n+1]); r %= MOD;
        n += 2; kk-=2;
    }
}


void use_plus_val(lint& p, lint& kk, lint& r){
    while(kk > 0){
        r *= pA[p]; r %= MOD;
        r *= pA[p+1]; r %= MOD;
        p += 2; kk-=2;
    }
}


void use_norp_val(lint& n, lint& p, lint& kk, lint& r){
    lint pp = pA[p]*pA[p+1];
    lint nn = nA[n]*nA[n+1];
    if(pp > nn){
        r *= pA[p]; r %= MOD;
        r *= pA[p+1]; r %= MOD;
        p += 2; kk -= 2;
    }else{
        r *= abs(nA[n]); r %= MOD;
        r *= abs(nA[n+1]); r %= MOD;
        n += 2; kk -= 2;
    }
}


int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> val;
        if(val < 0) nA.pb(val);
        else pA.pb(val);
    }


    plen = pA.size(); nlen = nA.size();


    if(K==N){
        for(int i = 0; i < plen; i++){ res *= pA[i]; res %= MOD; }
        for(int i = 0; i < nlen/2; i++){
            res *= abs(nA[2*i]); res %= MOD;
            res *= abs(nA[2*i+1]); res %= MOD;
        }
        if(nlen & 1){
            res *= nA[nlen-1];
            res += (abs(res)/MOD+1) * MOD;
        }
    }else{

        lint k = K;
        lint pk = 0, nk = 0;

        if(is_plus(plen, K)){
            /*絶対値が大きい値を先頭に*/
            sort(nA.begin(), nA.end());
            sort(pA.begin(), pA.end());
            reverse(pA.begin(), pA.end());
            sign = true;
        }else{
            /*絶対値が小さい値を先頭に*/
            sort(nA.begin(), nA.end());
            reverse(nA.begin(), nA.end());
            sort(pA.begin(), pA.end());
            sign = false;
        }


        if(K & 1){  //Kが奇数
            if(sign){  //pAサイズ1以上,偶数なら2以上が保障
                res *= pA[pk++];
                --k;  //残り偶数個必要
                while(k > 0){  //kは偶数
                    if(plen-pk < 2) use_minus_val(nk, k, res);
                    else if(nlen-nk < 2) use_plus_val(pk, k, res);
                    else use_norp_val(nk, pk, k, res);
                }
            }else{    //負の値となる
                while(k > 1){
                    res *= abs(nA[nk]); res %= MOD;
                    res *= abs(nA[nk+1]); res %= MOD;
                    nk += 2; k -= 2;
                }
                res *= nA[nk];
                res += (abs(res)/MOD + 1) * MOD;
            }

        }else{    //Kが偶数
            while(k > 0){
                if(plen-pk <= 1) use_minus_val(nk, k, res);
                else if(nlen-nk <= 1) use_plus_val(pk, k, res);
                else use_norp_val(nk, pk, k, res);
            }
        }
    }

    cout << res << endl;
    return 0;

}

Measured memory_bytes: 5480
import java.util.Scanner;

class Main {
	
	public static void main(String args []) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, com, x, y, min;
		
		n = scan.nextInt();
		q = scan.nextInt();
		
		int a[] = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = (int)(Math.pow(2, 31) - 1); 
		}
		
		for(int i = 0; i < q; i++) {
			com = scan.nextInt();
			x = scan.nextInt();
			y = scan.nextInt();
		
			if(com == 0) { //update	
				a[x] = y;
				
			} else if (com == 1) { //find
				min = (int)(Math.pow(2, 31) - 1);
				
				for(int j = x; j <= y; j++) {
					if(a[j] < min) {
						min = a[j];
					}
				}
				
				System.out.println(min);
			}
		}
		
		scan.close();
	}

}

Measured memory_bytes: 100096
#include<iostream>
#include <bits/stdc++.h>
//1000000000000223
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, m, x, y;
ll a[600][600], sum;
int main()
{
    IO
    cin>>n>>m>>x>>y;
    ll z=(1e9-1)/(x*y-1);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            a[i][j]= (i%x==0 && j%y==0) ? -z*(x*y-1)-1 : z ;
            sum+=a[i][j];
        }
    if(sum<=0)
        return cout<<"No",0;
    cout<<"Yes\n";
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            cout<<a[i][j]<<" ";
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;
using namespace chrono;
 
typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

//#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define loop(x,n) for(int x = 0; x < n; ++x)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

string get_str() {
    string temp;
    cin >> temp;
    return temp;
}
ll get_int() {
    ll temp;
    cin >> temp;
    return temp;
}



int n, m; 
ll A[200000], B[200000];
vector<ll> a, b;
ll k;

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

    a.pb(0); b.pb(0);


    loop(i, n) {
        cin >> A[i];
        a.pb(a[i] + A[i]);
    }
    loop(i, m) {
        cin >> B[i];
        b.pb(b[i] + B[i]);
    }

    int num = 0, j = m;

    loop(i, n+1) {
        if(a[i] > k) break;
        while(b[j] > k - a[i]) {
            j--;
        }
        num = max(num, i+j);
    }

    cout << num << endl;





}

Measured memory_bytes: 10456
#include<bits/stdc++.h>
#define reg register
#define mid (l+r>>1)
typedef long long ll;
using namespace std;
#define lowbit(x) (x&-x)
const int MN=1e5+5;
const int lim=2e5+5;
int n,a[MN],b[MN],t[MN],d[MN<<1],tot;
inline void update(int x){while(x<=lim)d[x]++,x+=lowbit(x);}
inline int query(int x){reg int res=0;while(x)res+=d[x],x-=lowbit(x);return res;}
inline bool check(int x){
	memset(t,0,sizeof(t));memset(d,0,sizeof(d));
	for(reg int i=1;i<=n;i++)t[i]=t[i-1]+(a[i]>x?-1:1);
	for(reg int i=0;i<=n;i++)t[i]+=n+1;reg ll ans=0;
	for(reg int i=0;i<=n;i++)ans+=query(t[i]-1),update(t[i]);
	return ans>=1ll*n*(n+1)/4+1;
}
int main(){
	scanf("%d",&n);
	for(reg int i=1;i<=n;i++)scanf("%d",a+i);
	reg int l=1,r=1e9;
	while(l<r)
		if(check(mid))r=mid;
		else l=mid+1;
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int length = scan.nextInt();
		int width = scan.nextInt();
		
		int area = length * width;
		int syuu = 2 * (length + width);
		System.out.println(area + " " + syuu);
		
	}

}

Measured memory_bytes: 26356
num = gets.to_i
ans = 1
if 2<=num && num<4 then
    ans = 2
elsif 4<=num && num<8 then
    ans = 4
elsif 8<=num && num<16 then
    ans = 8
elsif 16<=num && num<32 then
    ans = 16
elsif 32<=num && num<64 then
    ans = 32
elsif 64<=num then
    ans = 64
end
puts ans

Measured memory_bytes: 1788
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll K = 0;
	ll M = 0;
	ll X = 0;
	//double a[100000] = {};
	//double b[100000] = {};
	//ll v[100] = {};
	ll *l, *r, *d;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;

	
	//char p;
	//cin >>N >> M;
	
	//vector<pair<float, float>> is(M);
	//sort(is.begin(), is.end());
	l = (ll *)malloc(N * sizeof(ll));
	r = (ll *)malloc(N * sizeof(ll));

	cin >> N;
	
	rep(i, 0, N) {
		cin >> l[i] >> r[i];

		sum += (r[i] - l[i]) + 1;
	}
	
	
	cout << sum << endl;
	
		

	return 0;

}



Measured memory_bytes: 256
A,B,C = map(int,input().split())

def F(A,B,C):
    if any(x&1 for x in [A,B,C]):
        return 0
    if A == B == C:
        return -1
    return 1 + F((A+B)//2,(B+C)//2,(C+A)//2)

answer = F(A,B,C)
print(answer)


Measured memory_bytes: 2940
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

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;
}
const int maxn = 2e5 + 5;
int a[maxn * 2];
ll s[maxn * 2];
int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int k, n;
    sf(k, n);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i + n] = a[i] + k;
    }
    // for (int i = 1; i <= 2 * n; ++i) {
    //     s[i] = s[i - 1] + 1ll * a[i];
    //     prln(s[i]);
    // }
    ll mn = INF;
    for (int i = 1; i <= n; ++i) {
        pr(a[i + n - 1]);prln(a[i]);
        mn = min(mn, 1ll * a[i + n - 1] - a[i]);
    }
    out(mn);

    return 0;
}

Measured memory_bytes: 2944
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
} 


int n1, n2;
ll arr1[100005], arr2[100005];


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

    cin>>n1>>n2;
    for(int i=1;i<=n1;i++)  cin>>arr1[i];
    for(int i=1;i<=n2;i++)  cin>>arr2[i];

    ll xsum = 0, temp = arr1[n1];
    for(int i=n1-1;i>=1;i--){
        xsum += temp - (n1-i)*arr1[i];
        xsum %= MOD;
        temp += arr1[i];
    }

    ll ysum = 0;    temp = arr2[n2];
    for(int i=n2-1;i>=1;i--){
        ysum += temp - (n2-i)*arr2[i];
        ysum %= MOD;
        temp += arr2[i];
    }

// cout<<xsum<<" "<<ysum<<endl;

    xsum *= ysum;
    xsum %= MOD;
    xsum += MOD;
    xsum %= MOD;
    cout<<xsum;
    return 0;
}
 









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

int main(){
  string S;
  cin>>S;
  for(int i=0;i<S.size();i++){
    if(i+1<S.size()){
      if(S.at(i)=='B' && S.at(i+1)=='C'){
        S.replace(i,2,"D");
      }
    }
  }
  
  long long cnt=0;
  long long atemp=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='A') atemp++;
    if(S.at(i)=='D'){
      cnt+=atemp;
    }
    if(S.at(i)=='B'||S.at(i)=='C'){
      atemp=0;
    }
  }
  
  cout<<setprecision(18)<<cnt<<endl;
  return 0;
}

    

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

int main()
{
  int n;
  cin >> n;
  int a;
  for(int i = 0;i <= n;i++){
    if(i*i <= n) a = i * i;
    else break;
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <sstream>

#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	while(n > 1000){
		n-=1000;
	}
	
	cout << 1000 - n << endl;


	return 0;
}


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

typedef long long ll;
const int MOD = 1e9 + 7;

ll add(ll x, ll y){
	return (x + y) % MOD;
}

ll mul(ll x, ll y){
	return (x * y) % MOD;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<ll> v(n);
	for(int i = 0;i < n; ++i)cin >> v[i];
	ll ans = 0;
	for(int b = 0; b < 60; ++b){
		vector<ll> rsum(n+1, 0);
		for(int i = n - 1; i >= 0; --i){
			int cnt = ((v[i] >> b) & 1 ? n - 1 - i - rsum[i+1] : rsum[i+1]);
			ans = add(ans, mul(cnt, (1LL << b) % MOD)); 
			rsum[i] = rsum[i + 1] + ((v[i] >> b) & 1);	
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  string S;
  cin >> S;
  
  int K;
  cin >> K;
  
  rep(i, S.size()) {
    if(S[i] != '1') {
      fin(S[i]);
      return 0;
    }
    if(K == i+1) {
      fin(1);
      return 0;
    }
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
	int a[5], mini, ans = 0,count = 1;
	for (int i = 0; i < 5; i++) { cin >> a[i]; }
	sort(a, a + 5);
	mini = a[0];
	for (int i = 1; i < 5; i++)
	{
		if (mini == a[i]) { count++; }
		else if (mini % 10 == 0) { mini = a[i]; }
		else if (a[i] % 10 == 0) { continue; }
		else if (mini % 10 > a[i] % 10) { mini = a[i]; }
	}
	for(int i = 0;i < 5;i++)
	{
		if (mini == a[i]) { continue; }
		else if(a[i] % 10 != 0){ ans += a[i] - a[i] % 10 + 10; }
		else { ans += a[i]; }
	}
	if (count == 1) { cout << ans + mini << endl; }
	else
	{
		for(int i = 1;i < count;i++)
		{
			if (mini % 10 != 0) { ans += mini - mini % 10 + 10; }
			else { ans += mini; }
		}
		cout << ans + mini;
	}
	return 0;
}

Measured memory_bytes: 256
k = str(input())


n = 0
w = 0
s = 0
e = 0
for i in range(len(k)):
    if k[i] == "N":
        n += 1
    elif k[i] == "W":
        w += 1
    elif k[i] == "S":
        s += 1
    else:
        e += 1
if (n == 0 and s > 0) or (s == 0 and n > 0) or (e == 0 and w > 0) or (w == 0 and e > 0):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int x = sc.nextInt();
    int y = sc.nextInt();
    ArrayList<Integer> listx = new ArrayList<Integer>();
    ArrayList<Integer> listy = new ArrayList<Integer>();
    int p = 0;
    int t = 0;
    for(int i = 0; i < s.length(); i++) {
      if(s.charAt(i) == 'F') {
        t++;
      } else {
        if(p == 0) listx.add(t);
        if(p == 1) listy.add(t);
        t = 0; 
        p = 1 - p;
      }
    }
    if(t > 0) {
       if(p == 0) listx.add(t);
       if(p == 1) listy.add(t);      
    }
    int sx = listx.size();
    int sy = listy.size();
    int len = s.length();
    boolean[][] dpx = new boolean[sx + 1][2 * len + 1];
    boolean[][] dpy = new boolean[sy + 1][2 * len + 1];
    dpx[0][len] = true;
    dpy[0][len] = true;
    dpx[1][listx.get(0) + len] = true;
    for(int i = 2; i <= sx; i++) {
      for(int j = 0; j <= 2 * len; j++) {
        boolean f = false;
        if(j - listx.get(i - 1) >= 0) f = f || dpx[i - 1][j - listx.get(i - 1)];
        if(j + listx.get(i - 1) <= 2 * len) f = f || dpx[i - 1][j + listx.get(i - 1)];
        dpx[i][j] = f;
      }
    }
    for(int i = 1; i <= sy; i++) {
      for(int j = 0; j <= 2 * len; j++) {
        boolean f = false;
        if(j - listy.get(i - 1) >= 0) f = f || dpy[i - 1][j - listy.get(i - 1)];
        if(j + listy.get(i - 1) <= 2 * len) f = f || dpy[i - 1][j + listy.get(i - 1)];
        dpy[i][j] = f;        
      }
    }
    String ans = "No";
    if(dpx[sx][len + x] && dpy[sy][len + y]) ans = "Yes";
    System.out.println(ans);
  }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b)) cout << "A" << endl;
    else cout << "B" << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
abc=[list(map(int,input().split())) for i in range(n)]
dp=[[0 for i in range(3)] for i in range(n+1)]
for i,l in enumerate(abc,1):
  a,b,c=l
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[n]))

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

int main(){
    int n ,y;
    cin >> n>>y;
    int a = -1, b= -1, c = -1;
    for(int a=0;a<=n;a++){
        for(int b=0; b<=n;b++){
            if(a*10000+b*5000+(n-a-b)*1000==y && n-a-b>=0){
                cout << a << " " << b << " " << n-a-b << endl;
                return 0;
            }
        }
    }
    
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vi pr;
int v[10100];
unordered_set<int> fac;
void gp() {
	pr.push_back(2);
	pr.push_back(3);
	pr.push_back(5);
	for(int i=5;i<50000;i+=2) {
		int bs = 2;
		while(bs--) {
			bool p = true;
			for(int j=2;pr[j]*pr[j]<=i;j++) {
				if(!(i%pr[j])) {p = false;break;}
			}
			if(p && (i != 5)) {pr.push_back(i);}
			i += 2;
		}
	}
}
int gcd(int a, int b) {
	if(b == 0) return a;
	if(a == 0) return b;
	return gcd(b,a%b);
}
int main() {
	gp();
	int n;
	scanf("%d ",&n);
	n++;
	int g = 0;
	for(int i=0;i<n;i++) {
		int t;
		scanf("%d ",&t);
		v[n-i-1] = t;
		g = gcd(g,abs(t));
	}
	for(int i=0;pr[i]*pr[i]<=g;i++) {
		if(!(g%pr[i])) {
			fac.insert(pr[i]);
			while(!(g%pr[i])) {
				g /= pr[i];
			}
		}
	}
	if(g > 1) {fac.insert(g);}
	for(int i=0;pr[i] <= n;i++) {
	//for(int i=0;pr[i] <= 10000;i++) {
		if(fac.find(pr[i]) != fac.end()) continue;
		if(v[0]%pr[i]) continue;
		vi md(pr[i]-1,0);
		for(int j=0;j<n;j++) {
			md[j%(pr[i]-1)] += v[j]%(pr[i]);
			md[j%(pr[i]-1)] %= pr[i];
		}
		bool po = true;
		for(int j=0;j<pr[i]-1;j++) {
			if(md[j] != 0) {po = false;break;}
		}
		if(po) fac.insert(pr[i]);
	}
	vi res;
	for(auto& it: fac) {
		res.push_back(it);
	}
	sort(res.begin(),res.end());
	for(int i=0;i<res.size();i++) {
		printf("%d\n",res[i]);
	}
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
llong A, B, C;
int main() {
	cin >> A >> B >> C;
	if (4 * A * B < (C - A - B) * (C - A - B) && C - A - B >= 0) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%s', $input);
$nums = str_split($input);
$len = count($nums);
$ans = $input;
$memo = [];
if ($len <= 1) {
    echo $ans."\n";
    exit;
} else {
    for ($idx=0; $idx < (1 << ($len-1)); $idx++) {
        $nums = str_split($input);
        for ($plus=0; $plus < $len; $plus++) { 
            if($idx >> $plus & 1){
                $nums[$plus] .= '+';
                $str = implode($nums);
                if (!in_array($str, $memo)) {
                    $memo[] = $str;
                }
            }
        }
    }
}
foreach ($memo as $eval) {
    $ans += eval("return $eval;");
}
echo $ans."\n";

Measured memory_bytes: 4856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n; cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a, a+n,greater<int>());

  int ans=0;
  for(int i=0; i<n; i++){
    if(i%2==0) ans+=a[i];
    else ans-=a[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;
 
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}


int main(){
        int a;
cin>>a;
	cout<<a*a*a<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod = 1000000007;
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */

int main(void){
    string s,t;
    cin >> s >> t;
    int s_len = s.length();
    int t_len = t.length();

    int ok = 0;
    for(int i=(s_len - t_len); i>=0; i--){
        int flag = 0;
        int tmp_i = i;
        for(int j=0; j<t_len; j++){
            if(s[tmp_i]!=t[j] && s[tmp_i]!='?'){
                flag = 1;
            }
            tmp_i++;
        }

        if(flag == 0){
            tmp_i = i;
            for(int j=0; j<t_len; j++){
                s[tmp_i] = t[j];
                tmp_i++;
            }
            ok = 1;
            break;
        }
    }

    // ok??
    if(ok==0) cout << "UNRESTORABLE" << "\n";
    else{
        for(int i=0; i<s_len; i++){
            if(s[i]=='?'){
                s[i] = 'a';
            }
        }
        cout << s;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

bool primes[101000];
void make_prime(){
	primes[0]=primes[1]=true;
	for(int i=2; i*i<=101000; i++)if( !primes[i] )
		for(int j=2*i; j<101000; j+=i)primes[j]=true;
}
int main(){
	int n,p;
	make_prime();
	while(scanf("%d%d",&n,&p),!(n==-1&&p==-1)){
		vector<int> tmp,e;
		for(int i=n+1,c=0; c<p; i++)if( !primes[i] ){
			c++;
			tmp.push_back(i);
		}
		for(int i=0; i<tmp.size(); i++){
			for(int j=i; j<tmp.size(); j++){
				e.push_back(tmp[i]+tmp[j]);
			}
		}
		/*
		rep(i,e.size()){
			printf("%d,",e[i]);
		}
		*/
		sort(e.begin(), e.end());
		printf("%d\n",e[p-1]);
	}
	return 0;
}

Measured memory_bytes: 1068