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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;F f;T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz=v.size();
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i+=n;data[i]=x;
    while(i,i>>=1)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  T fold(int l,int r)const{
    l+=n,r+=n;
    T x=identity;
    while(l<r){
      if(l&1)x=f(x,data[l++]);
      if(r&1)x=f(x,data[--r]);
      l>>=1,r>>=1;
    }
    return x;
  }
  T operator[](int i)const{return data[i+n];}
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}
template<class T>
vector<pair<T,int>> indexed(vector<T> const& t){
  size_t n = t.size();
  vector<pair<T,int>> res(n);
  for(int i=0;i<n;++i){
    res[i] = {t[i],i};
  }
  return res;
}
signed main(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  ll kabu = 0;
  ll kane = 1000;

  auto dp = vec<pll>(2,n+1);
  dp[0][0] = pll(kane/a[0],kane%a[0]);
  dp[1][0] = pll(0,kane);

  rep(i,n-1){
    chmax<pll>(dp[0][i+1],dp[0][i]);
    chmax<pll>(dp[0][i+1],pll(dp[1][i].second/a[i+1],dp[1][i].second%a[i+1]));
    chmax<pll>(dp[1][i+1],dp[1][i]);
    chmax<pll>(dp[1][i+1],pll(0,dp[0][i].first*a[i+1]+dp[0][i].second));
  }
  ll ans = 0;
  for(auto [_,v]:dp[1])chmax<ll>(ans,v);
  cout<<(ans)<<endl;

  rep(i,n)dump(dp[0][i]);
  rep(i,n)dump(dp[1][i]);


}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

X = int(input())
if 400 <= X < 600:
    print(8)
elif 600 <= X  < 800:
    print(7)
elif 800 <= X  < 1000:
    print(6)
elif 1000 <= X  < 1200:
    print(5)
elif 1200 <= X  < 1400:
    print(4)
elif 1400 <= X  < 1600:
    print(3)
elif 1600 <= X  < 1800:
    print(2)
elif 1800 <= X:
    print(1)

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

int main() {
    long long int N;
    string ans = "No";
    cin >> N;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (N == i*j) {
                ans = "Yes";
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
import sys
import numpy as np

reatInt = lambda: int(sys.stdin.readline())
reatIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]


ss = sys.stdin.readline()
e = 0
o = 0
for i, s in enumerate(ss):
    if i % 2 == 0:
        e += int(s == '0')
        o += int(s == '1')
    else:
        e += int(s == '1')
        o += int(s == '0')
ret = min(e, o)
print(ret)

Measured memory_bytes: 21592
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    ll M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    sort(all(A));

    ll low = 2 * A[0], high = 2 * A[N - 1] + 1;
    while (high - low > 1) {
        ll mid = (low + high) / 2;

        ll c = 0;
        rep(i, N) {
            ll t = mid - A[i];
            c += A.end() - lower_bound(all(A), t);
        }

        if (c >= M) low = mid;
        else high = mid;
    }

    vector<ll> sumA(N + 1);
    rep(i, N) sumA[i + 1] = sumA[i] + A[i];

    ll ans = 0;
    ll cnt = 0;
    rep(i, N) {
        ll t = low - A[i];
        int c = A.end() - lower_bound(all(A), t);
        ans += A[i] * c;
        ans += sumA[N] - sumA[N - c];
        cnt += c;
    }

    write(ans - low * (cnt - M));
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 100;
const int maxN = 1e16;
const int oo = 1e18;
const int mod  = 1e9 + 7;
const int base = 26;
const double PI = 3.14159265358979323846;

int add(int x, int y) { return (x + y) % mod; }

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("spm.out", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    int ans = 0;
    FOR(i, k, n + 1)    {
        int lef = i * (i - 1) / 2, rig = i * (n + n - i + 1) / 2;
        ans = add(ans, rig - lef + 1);
    }
    cout << ans;
}


Measured memory_bytes: 3688
#include<iostream>


using namespace std;

int main()
{
	string s,t,u;int a,b;cin >> s >> t >> a >> b >> u;
	if(u == t){
		printf("%d %d\n",a,b - 1);
	}else{
		printf("%d %d\n",a - 1,b);
	}
}

 

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
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; }

//Roling Hash
//RollingHash RH(s,base) base:[2,MOD)?????±??°
//RH.set(s,base): vector???????§???????????????????????????§????????????????????????????????????
//RH.get(l,r): [l,r)??????????????\ O(1)
//1000000007, 1000000009, 1000000021
template<long long MOD>
class RollingHash {
public:
	int n;
	long long base;
	vector<long long> pow, hash;
	RollingHash() {}
	RollingHash(const string &s, long long base_ = 10007) { set(s, base_); }
	void set(const string &s, long long base_ = 10007) {
		n = s.size();
		base = base_;
		calc(s.c_str());
	}
	long long get(int x)const { return hash[x]; }
	long long get(int l, int r)const { return (get(r) - get(l)*pow[r - l] % MOD + MOD) % MOD; }
	void calc(const char *s) {
		pow.resize(n + 1);
		pow[0] = 1;
		hash.resize(n + 1);
		hash[0] = 0;
		for (int i = 0; i < n; i++) {
			pow[i + 1] = pow[i] * base % MOD;
			hash[i + 1] = (s[i] + hash[i] * base) % MOD;
		}
	}
};

using RH = RollingHash<1000000007>;

int main() {
	string s;

	while (cin >> s) {
		int n = s.size();
		int a = n % 2 == 0 ? 2 : 1;
		int b = n % 2 == 0 ? n / 2 - 1 : n / 2;
		int c = b + a;
		int d = n - a;
		RH rh(s);
		int ans = n;
		while (a < b) {
			int A = rh.get(0, a);
			if (rh.get(b, c) == A && rh.get(d, n) == A && rh.get(a, b) == rh.get(c, d)) {
				ans = min(ans, b);
			}
			a += 2;
			b -= 1;
			c += 1;
			d -= 2;
		}
		if (ans != n) {
			cout << "Love " << s.substr(0, ans) << '!';
		}
		else {
			cout << "mitomerarenaiWA";
		}
		cout << '\n';
	}
}

Measured memory_bytes: 19976
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int, int> ii;
typedef long double ld;


int main() {
    int K,X;
    cin >>K>>X;

    int kosuu=2*K-1;
    X=X-K;

    for(int i=0;i<kosuu;i++){
        X++;
         cout<<X<<" ";
    }

}

Measured memory_bytes: 256
def main():
  import sys
  n,s,_,*t=sys.stdin.buffer.read().split()
  n=int(n)
  d=[0]*n+[2**(c-97)for c in s]
  for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
  r=[]
  for q,a,b in zip(*[iter(t)]*3):
    i,s=int(a)+n-1,0
    if q<b'2':
      d[i]=2**(b[0]-97)
      while i>1:
        i//=2
        d[i]=d[i+i]|d[i-~i]
      continue
    j=int(b)+n
    while i<j:
      if i&1:
        s|=d[i]
        i+=1
      if j&1:
        j-=1
        s|=d[j]
      i//=2
      j//=2
    r+=bin(s).count('1'),
  print(' '.join(map(str,r)))
main()

Measured memory_bytes: 45560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,H1,c=-1,count=0,H=1000000000;
  cin >>N;
  for (int i=0;i<N;i++){
      cin >>H1;
      if(H1<=H){
          c++;
          H=H1;
      }
      else{
          if(c>count)
          count=c;
          c=0;
          H=H1;
      }
    if(c>count)
          count=c;

      
  }
  cout <<count<<endl;
}
 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<climits>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main(){
  int n,i,t=0,l,k=0;
  long long int ans=0;
  cin >> n;
  vector<int>a(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)<=0)t++;
  }
  if(t%2==0){
    for(i=0;i<n;i++)ans+=abs(a.at(i));
  }else{
    l=a.at(0);
    for(i=0;i<n;i++)if(abs(l)>abs(a.at(i)))l=a.at(i);
    for(i=0;i<n;i++){
      if(a.at(i)==l && k==0){
        if(a.at(i)>0)a.at(i)*=-1;
        ans+=a.at(i);
        k++;
      }
      else ans+=abs(a.at(i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

string s;
int cnt[26];

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

	cin>>s;
	REP(i,s.size()) cnt[s[i]-'a']++;
	REP(i,26) {
		if(cnt[i]>1) {
			cout<<"no"<<endl;
			return 0;
		}
	}
	cout<<"yes"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////
 
#define fs first
#define sc second
#define pb push_back
//#define int long long
#define len(x) (int)(x).size()     
#define all(x) (x).begin(), (x).end()
#define test int _; cin >> _; while(_--)
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
 
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9+7;
 
inline ll gcd(ll a, ll b){while(b){ a %= b; swap(a, b); } return a; }
inline ll mod(ll a, ll b){return ((a%b)+b)%b;}
inline ll expo(ll b, ll p, ll m = MOD){
  ll ans = 1; 
  while(p > 0){
    if(p&1LL) ans = mod(ans*b, m); 
    b = mod(b*b, m); 
    p >>= 1LL;
  } 
  return ans;
}
 
////////////////////////// Solution starts below. //////////////////////////////

int32_t main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> quant(n+1, 0);
  for(int i = 1; i <= n; i++){
    cin >> quant[i];
  }
  
  vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
  dp[0][0] = 1;
  for(int kid = 1; kid <= n; kid++){
    vector<int> pref(m+1, 0);
    for(int used = 0; used <= m; used++){

      int value = dp[kid-1][used];
      int l = used;
      int r = used + min(quant[kid], m - used);

      pref[l] = mod(pref[l] + value, MOD);
      if(r < m) pref[r+1] = mod(pref[r+1] - value, MOD);
      /*for(int can = 0; can <= min(quant[kid], m-used); can++){
        dp[kid][used + can] = mod(dp[kid][used + can] + dp[kid-1][used], MOD);
      }*/
    }
    for(int k = 0; k <= m; k++){
      if(k) pref[k] = mod(pref[k] + pref[k-1], MOD);
      dp[kid][k] = mod(dp[kid][k] + pref[k], MOD);
    }
  }
  cout << dp[n][m] << '\n';
  return 0; 
}

Measured memory_bytes: 43264
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

// 0-indexed bottom up Segment Tree
// UNIT is the identity element of operation func
template <typename T = int>
struct SegmentTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> dat;
    F func;
    T UNIT;

    SegmentTree(int n_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        // full binary tree: num of leaves = n = 2^k >= n_
        while (n < n_)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
    }
    SegmentTree(vector<T> v_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n      = 1;
        int nv = v_.size();
        while (n < nv)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
        for (int i = 0; i < nv; ++i) {
            dat[n - 1 + i] = v_[i];
        }
        for (int i = n - 2; i >= 0; --i) {
            dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }
    void update(int k, T a) {
        // leaves are at index n-1 to 2*n-2
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            // k -> parent node
            k = (k - 1) / 2;
            // func(child nodes)
            dat[k] = func(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    // get result of func() in [l, r)
    T query(int l, int r) {
        l += n - 1;
        r += n - 1;
        T retl = UNIT, retr = UNIT;
        while (l < r) {
            if ((l & 1) == 0)
                retl = func(retl, dat[l]);
            if ((r & 1) == 0)
                retr = func(dat[r - 1], retr);
            l = l / 2;
            r = (r - 1) / 2;
        }
        return func(retl, retr);
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        c[i]--;
    }
    vector<pair<pair<int, int>, int>> rl;
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        rl.push_back({{r, l}, i});
    }
    sort(rl.begin(), rl.end());
    vector<int> last(n, -1);
    auto f          = [](lint l, lint r) { return l + r; };
    const lint unit = 0;
    SegmentTree<lint> seg(n + 1, f, unit);
    int cr = -1;
    vector<int> ret(q);
    for (int i = 0; i < q; ++i) {
        while (cr < rl[i].first.first) {
            cr++;
            if (last[c[cr]] != -1)
                seg.update(last[c[cr]], 0);
            last[c[cr]] = cr;
            seg.update(last[c[cr]], 1);
        }
        ret[rl[i].second] = seg.query(rl[i].first.second, rl[i].first.first + 1);
    }
    for (auto &r : ret) {
        cout << r << "\n";
    }
    return 0;
}

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

typedef long long LL;

const int N=1000000;

int n;
char s[N+9];

void into(){
  scanf("%d%s",&n,s+1);
}

int Lucas(int n,int m){
  if (n<m||m<0) return 0;
  return n<2?1:(n&1)>=(m&1)&&Lucas(n>>1,m>>1);
}

int a[N+9],c1;

void Get_a(){
  for (int i=1;i<=n;++i) c1+=(a[i]=s[i]-'1')==1;
}

int ans;

void Get_ans(){
  for (int i=1;i<=n;++i) a[i]=a[i]>>!c1&1;
  for (int i=1;i<=n;++i) ans^=a[i]&Lucas(n-1,i-1);
  ans<<=!c1;
}

void work(){
  Get_a();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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


void tmp(int* n,int* m)
{
	int t = *n;
	*n = *m;
	*m = t;
	return;
}

int gcd(int n,int m)//n>mªð
{
	if(n<m)
		tmp(&n,&m);
	if(m==0)
		return 0;
	if(n%m==0)
		return m;
	else
		gcd(m,n%m);
}

int main()
{
	int n,m;
	while(cin>>n && cin>>m)
		cout << gcd(n,m) << endl;
	return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
int f[102];
int p[101][10];
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	int n,x;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			cin>>x;
			if(x)
			f[i]|=(1<<j);
		}
	}

	for(int i=0;i<n;i++)
		for(int j=0;j<11;j++)cin>>p[i][j];

	int ans=-1e9;
	for(int mask=1;mask<(1<<10);mask++)
	{
		int tmp=0;
		for(int i=0;i<n;i++)
		{
			x=mask&f[i];
			int ct=__builtin_popcount(x);
			tmp+=p[i][ct];
		}
		ans=max(ans,tmp);

	}
	cout<<ans;


}

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

#define all(a) (a).begin(),(a).end()

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;

  sort(all(s));
  sort(all(t), greater<char>());
  if (s < t)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    string S, T;
    cin >> S >> T;

    int L = 0;
    int R = 1;
    int U = 2;
    int D = 3;

    // 左
    int c = sc;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'L') c--;
        if (c <= 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'R' && c < W) c++;
    }
    // 右
    c = sc;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') c++;
        if (c > W) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'L' && c > 1) c--;
    }
    // 上
    int r = sr;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'U') r--;
        if (r <= 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'D' && r < H) r++;
    }
    // 下
    r = sr;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') r++;
        if (r > H) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'U' && r > 1) r--;
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
using namespace std;

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

  vector<int> L( N );
  rep( i, 0, N ) cin >> L.at(i);

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

  bool flag = false;
  int x = 0;
  rep( i, 0, N-1 ) {
    x += L.at(i);
  }
  if ( L.back() < x ) {
    flag = true;
  }

  cout << ( flag ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

ll x, k, d;

int main() {
    fastio();

    cin >> x >> k >> d;

    x = abs(x);

    if (x / d >= k) {
        cout << x - d * k << endl;
    } else {
        ll c = x / d;
        ll a = x - c * d;
        ll b = d - a;
        if (c % 2 == k % 2) {
            cout << a << endl;
        } else {
            cout << b << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define Sort(ss) sort(ss.begin(), ss.end())
#define Rsort(ss) sort(ss.rbegin(), ss.rend())
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return acos(-1.0);
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int n;
	cin>>n;
	vi ss(2*n,0);
	for(int i=0;i<2*n;i++){
		cin>>ss[i];
	}
	int ans=0;
	Sort(ss);
	for(int i=0;i<2*n;i++){
		if(i%2==0){
			ans+=ss[i];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
  	l1=input[0].split(" ");
    l2=input[1].split(" ");
	var n = parseInt(l1[0], 10);
  	var x=parseInt(l1[1],10);
  	var a= new Array(n);
  	for (var i=0; i<n; i++){
     	a[i]= parseInt(l2[i].split(" "), 10);
    }
  	var sum=0;
  	
  	if (a[0]>x){
      	sum+=a[0]-x;
     	a[0]=x;     	
    }
  	
  	for (var j=1; j<n; j++){
      if (a[j-1]+a[j]>x){
       	sum+=a[j]-(x-a[j-1]);
        a[j]=x-a[j-1];
      }
    }
  	console.log('%d',sum);
  }
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29932
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int t = int.Parse(input[0]);
        int a = int.Parse(input[1]);
        int[] h = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int ans = 0;
        double min = Math.Abs(a - (t - h[ans] * 0.006));
        double tmp;
        for (int i = 0; i < n; i++)
        {
            tmp = Math.Abs(a - (t - h[i] * 0.006));
            if (min > tmp)
            {
                ans = i;
                min = tmp;
            }
        }
        Console.WriteLine(ans + 1);
    }
}

Measured memory_bytes: 13204
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int s,w;
	cin >> s >> w;
	if(w>=s) cout << "unsafe";
	else cout << "safe";
	return 0;
}



Measured memory_bytes: 3584
#include <cstdio>
const long long MOD = 1000000007;
int a[200001],b[200001];
long long fac[8001],ni[8001],f[4001][4001],ans;
int n,x,y,p;
void read(int &k) {
    char c=getchar();
    while (c<48||c>57) c=getchar();
    k=0;
    while (c>=48&&c<=57) {
        k=k*10+c-48;
        c=getchar();
    }
}
long long C(int n,int m) {
    return fac[n]*ni[m]%MOD*ni[n-m]%MOD;
}
long long fun(long long a,int k) {
    long long s=1;
    while (k) {
        if (k&1) s=s*a%MOD;
        a=a*a%MOD;
        k>>=1;
    }
    return s;
}

int main() {
    fac[0]=1;
    for (int i=1; i<=8000; ++i) fac[i]=fac[i-1]*i%MOD;

    ni[8000]=fun(fac[8000],MOD-2);
    for (int i=7999; i>0; --i) ni[i]=ni[i+1]*(i+1)%MOD;

    read(n);
    for (int i=1; i<=n; ++i) {
        read(a[i]);
        read(b[i]);
        if (a[i]>x) x=a[i];
        if (b[i]>y) y=b[i];
        f[2000-a[i]][2000-b[i]]++;
    }

    for (int i=2000-x; i<=2000+x; ++i)
        for (int j=2000-y; j<=2000+y; ++j) {
            if (i>0) {
                p=f[i][j]+f[i-1][j];
                f[i][j]= p>=MOD ? p-MOD : p;
            }
            if (j>0) {
                p=f[i][j]+f[i][j-1];
                f[i][j]= p>=MOD ? p-MOD : p;
            }
        }

    for (int i=1; i<=n; ++i) {
        p=ans+f[2000+a[i]][2000+b[i]];
        ans = p>=MOD ? p-MOD : p;
        p=ans+MOD - C(a[i]+b[i]+a[i]+b[i],a[i]+a[i]);
        ans = p>=MOD ? p-MOD : p;
    }

    ans=ans*ni[2]%MOD;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 126976
/******

AUTHOR : RUDRANSH TRIPATHI, IIIT NAGPUR, CCID(rt24) & CFID(rsgt24)

MOTTO : Use criticism as fuel and you will never run out of energy.
        AIM : TO BECOME A BETTER CODER
        INTROSPECT + COURSE CORRECTIONS = CATALYST FOR SUCCESS
        Every moment is an opportunity to better yourself

*******/

#include<bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MAX = 1e5 + 5;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define pb push_back
#define d(x) cout<<x<<"\n"
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

//basic mathematics
int gcd(int a, int b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

//modular arithmetic
int powermod(int x, int y, int p)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;

	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

//Prime numbers till n precomputation - range query
int prefix[MAX + 1];

void buildPrefix()
{
	bool prime[MAX + 1];
	memset(prime, true, sizeof(prime));

	for (int p = 2; p * p <= MAX; p++) {
		if (prime[p] == true) {
			for (int i = p * 2; i <= MAX; i += p)
				prime[i] = false;
		}
	}
	prefix[0] = prefix[1] = 0;
	for (int p = 2; p <= MAX; p++) {
		prefix[p] = prefix[p - 1];
		if (prime[p])
			prefix[p]++;
	}
}

int query(int L, int R)
{
	return prefix[R] - prefix[L - 1];
}


//Find all paths from a to b in an undirected graph
vector<int> g[MAX];
int visited[MAX];
//count of all the paths from 1 to n;

void dfs(int visited[MAX], int u, int v, vector<int> path)
{
	visited[u] = 1;
	if (u == v)
	{
		for (int i = 0; i < path.size(); i++)
		{
			cout << path[i] << " ";
		}
		cout << "\n";
	}
	else
	{
		for (int i = 0; i < g[u].size(); i++)
		{
			int y = g[u][i];

			if (visited[y] == 0)
			{
				visited[y] = 1;
				path.pb(y);
				dfs(visited, y, v, path);
				path.pop_back();
			}

		}
	}

	visited[u] = 0;

}

vector<int> graph[MAX];
int vis[MAX];

void dfs(int v)
{
	vis[v] = 1;
	
	for(auto x: graph[v]){
	    
		if(vis[x] == 0)
		{
		    dfs(x);
		}
		
	}
}

void solve()
{
	string x;
	cin>>x;
	
	if(x[x.size()-1]!='s')
	x+='s';
	else
	x+="es";
	
	cout<<x<<"\n";
}

int32_t main(void)
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	cerr << "\n" << "Time elapsed : " << time_passed << "\n";
	return 0;
}

Measured memory_bytes: 8480
R=range(8)
A=[4,1,4,1,2,1,2,1]
A+=A
B="41412121"
B=map(int,[B[i:]+B[:i] for i in R])

import sys
for s in sys.stdin:
  x=map(int,s[:-1].split())
  m=sum(x)
  for i in R:
    s=sum([max(0,x[j]-A[i+j]) for j in R])
    if s<m: m,p=s,B[i]
    elif m==s and B[i]<p: p=B[i]
  print " ".join(list(str(p)))

Measured memory_bytes: 4244
#include <iostream>
#include <vector>

using namespace std;

struct edge {
    int to;
    int index;
};

vector<vector<edge>> graph;
vector<int> ret;

void dfs(int v, int prevColor) {
    int color = 1;
    for (auto nextEdge:graph[v]) {
        if (ret[nextEdge.index] == 0) {
            if (color == prevColor)color++;
            ret[nextEdge.index] = color;
            dfs(nextEdge.to, color);
            color++;
        }
    }
}

int main() {
    int n;
    cin >> n;
    graph = vector<vector<edge>>(n);
    vector<int> count(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge x, y;
        x.to = b, x.index = i;
        y.to = a, y.index = i;
        graph[a].push_back(x);
        graph[b].push_back(y);
        count[a]++, count[b]++;
    }

    int maxCount = 0;
    int maxIndex = -1;
    for (int i = 0; i < n; i++) {
        if (maxCount < count[i]) {
            maxCount = count[i];
            maxIndex = i;
        }
    }

    cout << maxCount << endl;
    ret = vector<int>(n - 1);
    dfs(maxIndex, 0);
    for (auto x:ret)cout << x << endl;
    return 0;
}

Measured memory_bytes: 7296
[sx, sy, tx, ty]=list(map(int,input().split()))
a1=["R"]*(tx-sx)+["U"]*(ty-sy)+["L"]*(tx-sx)+["D"]*(ty-sy)
a2=["D"]+["R"]*(tx-sx+1)+["U"]*(ty-sy+1)+["L"]+["U"]+["L"]*(tx-sx+1)+["D"]*(ty-sy+1)+["R"]
ans=a1+a2
for i in range(len(ans)):
	print(ans[i],end="")




Measured memory_bytes: 4852
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			int n=int.Parse(Console.ReadLine());
			if(n==0)break;;
			new Sol(n).Solve();
		}
	}
}

class Sol{
	public void Solve(){
		
		Pg.Sort((x,y)=>x.Date>y.Date?1:x.Date<y.Date?-1:0);
		List<Prog> FavL=new List<Prog>();
		for(int i=0;i<P;i++){
			for(int j=0;j<N;j++){
				if(Pg[j].Name==Fav[i]){
					FavL.Add(Pg[j].Clone());
				}
			}
		}
		FavL.Sort((x,y)=>x.Date>y.Date?1:x.Date<y.Date?-1:0);
		for(int i=0;i<P-1;i++){
			if(FavL[i].Date+30>FavL[i+1].Date){
				Console.WriteLine(-1);
				return;
			}
		}
		
		int cnt=0;
		int fcnt=0;
		int time=0;
		
		for(int i=0;i<N;i++){
			if(Pg[i].Date<time)continue;
			if(fcnt<P){
				if(Pg[i].Date+30<=FavL[fcnt].Date){
					cnt++;
					time=Pg[i].Date+30;
					continue;
				}
				if(Pg[i].Date+30>FavL[fcnt].Date){
					if(Pg[i].Date!=FavL[fcnt].Date){
						continue;
					}
					
					if(Pg[i].Name!=FavL[fcnt].Name){
						continue;
					}
					if(Pg[i].Name==FavL[fcnt].Name){
						cnt++;
						fcnt++;
						time=Pg[i].Date+30;
					}
					continue;
				}
			}else{
				cnt++;
				time=Pg[i].Date+30;
			}
		}
		
		Console.WriteLine(cnt);
		
		
		
		
	}
	int N;
	List<Prog> Pg;
	int P;
	List<String> Fav;
	public Sol(int n_){
		N=n_;
		Pg=new List<Prog>();
		for(int i=0;i<N;i++)Pg.Add(new Prog(rsa()));
		P=ri();
		Fav=new List<String>();
		for(int i=0;i<P;i++)Fav.Add(rs());
	}

	class Prog{
		public String Name;
		public int Date;
		public Prog(String[] s_){
			Name=s_[0];
			int d=int.Parse(s_[1]);
			int hm=int.Parse(s_[2]);
			Date=d*24*60+(hm/100)*60+hm%100;
		}
		public Prog(){
		}
		public Prog Clone(){
			Prog P=new Prog();
			P.Name=this.Name;
			P.Date=this.Date;
			return P;
		}
	}


	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 6048
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())+[""]

ans = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        ans += 1
        S[i+2] = "-1"
print(len(S)-ans-1)


Measured memory_bytes: 8724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int A,B;
cin>>A>>B;
for(int i=0;i<20000;++i){
if((A==(i*8)/100)&&(B==i/10)){
  cout<<i<<"\n";
  break;
}
if(i==19999){
  cout<<-1<<"\n";
}
  
}

return 0;
}

Measured memory_bytes: 256
#!python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    if len(str(N)) >= 2 and int(str(N)[1:]) == 0 and str(N)[0] == '1':
        print(10)
    else:
        print(sum(map(int, str(N))))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

#cat
a = int(arr_data[0][0])
b = int(arr_data[0][1])
x = int(arr_data[0][2])


print("YES" if a<=x and x-a<=b else "NO")





Measured memory_bytes: 3064
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])


def main():
    h,w=inpm()
    s=[input() for _ in range(h)]
    que=deque()
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    went = [[False for _ in range(w)] for _ in range(h)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if s[i][j]=="#":
                if not went[i][j]:
                    went[i][j] = True
                    que = deque()
                    que.append((i,j))
                    a,b = 1,0
                    while len(que)>0:
                        x,y=que.pop()
                        for k in range(4):
                            nx,ny=x+dx[k],y+dy[k]
                            if nx<0 or h<=nx or ny<0 or w<=ny or went[nx][ny]:
                                continue
                            if s[x][y] != s[nx][ny]:
                                if s[nx][ny] == '#':
                                    a+=1
                                else:
                                    b+=1
                                went[nx][ny]=True
                                que.append((nx,ny))
                    ans += a*b
    print(ans)
    
if __name__ == "__main__":
    main()

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

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a+b+c)&1)cout<<"No";
	else{
		int x=(a+b+c)/2;
		if(x==a || x==b || c==x){
			cout<<"Yes";
		}
		else cout<<"No";
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static char Solve(string S, long K)
        {
            int i = 0;
            while (i + 1 < K)
            {
                if (S[i] != '1') { return S[i]; }
                ++i;
            }
            return S[i];
        }
        static void Main(string[] args)
        {
            string S = Read();
            long K = ReadLong();
            Console.WriteLine(Solve(S, K));
        }
    }
}


Measured memory_bytes: 11092
//#include "bits\stdc++.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long LL;

int main()
{
    int n, k, temp, L = 0;
    vector<int> l;

    cin >> n >> k;
    for (int i = 0; i < n; ++i)
    {
        cin >> temp;
        l.emplace_back(temp);
    }

    sort(l.rbegin(), l.rend());

    for (int i = 0; i < k; ++i)
    {
        L += l[i];
    }

    cout << L << endl;

    return 0;
}

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

int d,n;

int main(){
    scanf("%d%d",&d,&n);
    int ans=1;
    while(d--)ans*=100;
    if(n==100)ans*=101;
    else ans*=n;
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 int main() {
	 int A, B, C, D;
	 cin >> A >> B >> C >> D;
	 int L = A + B, R = C + D;
	 if (L < R) cout << "Right" << endl;
	 else if (L == R) cout << "Balanced" << endl;
	 else cout << "Left" << endl;
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    int mod = 1e9+7;
    cin >>n;
    ll ans = 1;
    
    for(int i = 1; i <= n; i++)
    {
        ans*=i;
        ans%=mod;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def main():
    N, K = map( int, input().split())
    A = list( map( int, input().split()))
    A.sort()
    if A[-1] < K:
        print('IMPOSSIBLE')
        return
    g = A[0]
    if A[0] == K:
        print('POSSIBLE')
        return
    for i in range(N-1):
        if A[i+1] == K:
            print('POSSIBLE')
            return
        g = gcd(g, A[i+1]-A[i])
    if K < g:
        print('IMPOSSIBLE')
        return
    if K%g == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
if __name__ == '__main__':
    main()


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/
int n, w;
vector<vector<int> > a;
vector<vector<ll> > dp;
ll recur(int i, int j){
    //cout<<i<<" "<<j<<endl;
    if(i==n)
        return 0;
    if(j<=0)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll x = 0;
    if(a[i][0]<=j)
        x = a[i][1] + recur(i+1, j-a[i][0]);
    ll y = recur(i+1, j);
    dp[i][j] = max(x, y);
    return dp[i][j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    cin>>n>>w;
    a.resize(n);
    for(int i=0;i<n;i++){
        a[i].resize(2);
        cin>>a[i][0]>>a[i][1];
    }
    dp.resize(n);
    for(int i=0;i<n;i++){
        dp[i].resize(w+1);
        for(int j=0;j<=w;j++)
            dp[i][j]=-1;
    }
    ll an = recur(0, w);
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 81448
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>

typedef long long int ll;


using namespace std;

string s;

bool is_agari_s(vector<int> h,int len);
bool is_agari_k(vector<int> h,int len);

bool is_agari_k(vector<int> h,int len){//koutu
	if(len==0)return true;
	for(int i=0; i<len-2; i++){
		if(h[i]==h[i+1]&&h[i+1]==h[i+2]){
			vector<int> h2;
			for(int j=0; j<len; j++){
				h2.push_back(h[j]);
				if(j==i||j==i+1||j==i+2){
					h2.pop_back();
				}
			}
			return (is_agari_k(h2,len-3)||is_agari_s(h2,len-3));
		}
	}
	return false;
}

bool is_agari_s(vector<int> h,int len){//shuntu
	if(len==0)return true;
	for(int i=0; i<len-2; i++){
		for(int j=i; j<len-1; j++){
			if(h[j]==h[i]+1){
				for(int k=j; k<len; k++){
					if(h[k]==h[j]+1){
						vector<int> h2;
						for(int l=0; l<len; l++){
							h2.push_back(h[l]);
							if(l==i||l==j||l==k){
								h2.pop_back();
							}
						}
						return (is_agari_k(h2,len-3)||is_agari_s(h2,len-3));
					}
				}
			}
		}
	}
	return false;
}


int main(){
	while(cin>>s){
		vector<char> t(14,0);
		vector<int> cnt(10,0);
		for(int j=0; j<13; j++){
			t[j]=s[j]-'0';
			cnt[t[j]]+=1;
		}
		bool zeflag=true;
		bool spflag=false;
		for(int i=1; i<=9; i++){//agarihai=i;
			if(cnt[i]>=4)continue;
			for(int k=1; k<=9; k++){
				vector<int> u(14,0);
				vector<int> cnt2=cnt;
				for(int j=0; j<13; j++){
					u[j]=t[j];
				}
				u[13]=i;
				cnt2[i]+=1;
				sort(u.begin(),u.end());
				if(cnt2[k]>=2){//toitu=k;
					cnt2[k]-=2;
					for(int l=0; l<14; l++){
						if(u[l]==k){
							u[l]=100;
							u[l+1]=100;
							break;
						}
					}
					sort(u.begin(),u.end());
					if(is_agari_k(u,12)||is_agari_s(u,12)){
						zeflag=false;
						if(spflag)printf(" ");
						cout<<i;
						spflag=true;
						break;
					}
				}
			}
		}
		if(zeflag)cout<<"0";
		cout<<endl;
	}
}

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

public class Main{

	public static void main(String[] args) throws IOException {
		int N = readInt(); int arr[] = new int[N+2]; for(int i = 1; i<=N; i++) arr[i] = readInt(); arr[N+1] = 0;
		long dis = 0, crnt = 0; for(int i = 1; i<=N+1; i++) {dis += Math.abs(crnt-arr[i]); crnt = arr[i];}
		for(int i = 1; i<=N; i++) println(dis-Math.abs(arr[i]-arr[i-1])-Math.abs(arr[i]-arr[i+1])+Math.abs(arr[i+1]-arr[i-1]));
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	public void close() throws IOException {
		if (din == null)
			return;
		din.close();
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 33832