akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>//memset()
#include<algorithm>
#include<sstream>
#include<stack>
#include<bitset>
#include<queue>
#include<cmath>
#include<set>
#define ll long long
#define PI 3.14159265358979323846
#define IO ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,start,end) for(int i=start;i<end;i++)
#define per(i,start,end) for (int i=end-1;i>=start;i--)
using namespace std;

const ll mod=1000000007;
const ll inf=1e9;

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}
ll leastbit(ll a) { return a&(-a);}
ll C(int a,int b) { ll res=1;rep(i,0,b)res=res*(a-i)/(i+1);return res;}
ll powmod(ll a,ll  b) { if(b==0)return 1;ll cnt=powmod(a,b/2);(cnt*=cnt) %=mod;if(b&1){(cnt*=a) %= mod;}return cnt;}

int n,m,k,a[200005],b[200005],idx=-1,ans=0;
ll sum=0;

int main()
{IO
#ifndef ONLINE_JUDGE
    freopen("output.txt","w",stdout);
#else
#endif
    
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
    for(int i=0;i<n;i++){
        if(sum+a[i]<=k){
            idx=i;
            sum+=a[i];
        }
        else break;
    }
    ans=idx+1;int cnt=ans;
    for(int i=0;i<m;i++){
        while(sum+b[i]>k && idx>=0){
            sum-=a[idx];
            idx--;
            cnt--;
        }
        if(sum+b[i]<=k){
            cnt++;
            sum+=b[i];
        }
        else break;
        ans=max(cnt,ans);
    }
    cout<<ans<<endl;
    return 0;
}

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

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

  vector<ll> vi(100001, 0);

  ll sum = 0;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    vi.at(a)++;
    sum += a;
  }

  int Q;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    ll from, to;
    cin >> from >> to;

    ll dif = vi.at(from) * (to - from);
    sum = sum + dif;

    vi.at(to) += vi.at(from);
    vi.at(from) -= vi.at(from);

    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 4036
N, A, B = map(int, input().split())
S = list(input())
yosen = 0
yosen_kaigai = 0
for i in range(N):
    if S[i] == 'a':
        if yosen < A + B:
            yosen += 1
            print('Yes')
        else:
            print('No')
    elif S[i] == 'b':
        if yosen < A + B and yosen_kaigai < B:
            yosen += 1
            yosen_kaigai += 1
            print('Yes')
        else:
            print('No')
    else:
        print('No')


Measured memory_bytes: 4708
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,K;
	cin >> N >> K;
	vector<ll> x(N),y(N);
	rep(i,N)cin >> x[i] >> y[i];
	ll ans = INF;
	rep(a,N)rep(b,N){
		if(a==b)continue;
		ll xl = min(x[a],x[b]);
		ll xr = max(x[a],x[b]);
		ll xlength = xr - xl;
		//[xl,xr]にある点の中からyを決める
		rep(c,N)rep(d,N){
			bool ok = 0;
			if(xl<=x[c]&&x[c]<=xr&&xl<=x[d]&&x[d]<=xr)ok = 1;
			if(!ok)continue;
			ll yt = max(y[c],y[d]);
			ll yb = min(y[c],y[d]);
			ll ylength = yt-yb;
			int cnt = 0;
			rep(e,N){
				//中に含まれるかどうか調べる
				if(xl<=x[e]&&x[e]<=xr&&yb<=y[e]&&y[e]<=yt)cnt++;
			}
			if(cnt>=K){
				ans = min(ans,xlength*ylength);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {


    static boolean isDiamond( ArrayList<Integer> t) {
        if (t.get(0) == t.get(1))   return true;
        else    return false;
    }

    static boolean isRectangle ( ArrayList<Integer> t ) {
        if (t.get(0) * t.get(0) + t.get(1) * t.get(1) == t.get(2) * t.get(2))
            return true;
        else
            return false;
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        int rectangle = 0;
        int diamond = 0;

        while(sc.hasNext()) {
            String [] line = sc.nextLine().split(",");
            ArrayList<Integer> triangle = new ArrayList<Integer>(3);
            for(int i = 0; i < 3; i++)  triangle.add(Integer.parseInt(line[i]));
            if (isRectangle(triangle))  rectangle += 1;
            else if (isDiamond(triangle))   diamond += 1;
        }

        System.out.println(rectangle);
        System.out.println(diamond);

    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
using namespace std;
#define int long long 
#define w(t) int t; cin>>t; while(t--)
#define mk(arr,n,type) type *arr = new type [n];
#define rep(i,n) for(i=0;i<n;++i)
#define REP(i,k,n) for(i=k;i<=n;++i)
#define REPR(i,k,n) for(i=k;i>=n;--i)
#define inpc(x)   scanf("%d",&x)
#define printc(x) printf("%d",x)
void input(){
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    #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);
#endif
}
void solve(){
input();
string s1,s2;
cin>>s1>>s2;
int len = s2.length();
 if(s2.substr(0,len-1)==s1){
  cout<<"Yes\n";

 }
 else
  cout<<"No\n";


}
int32_t main(){

  solve();

  return 0;
      }



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

using namespace std;

//#define FILE_IO

int N;
char s[100005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%s", &s);
    N = strlen(s);

    int ans = 0;
    for(int i = 0; i < N - 1; i++)
        if(s[i] != s[i + 1])
            ans++;
    printf("%d\n", ans);

    return 0;
}


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

int main(){
  string s_tmp;
  cin >> s_tmp;
  deque<char> s;
  for(int i = 0; i < s_tmp.size(); ++i)s.push_back(s_tmp[i]);

  int q;
  cin >> q;

  bool flg = true;
  for(int _ = 0; _ < q; ++_){
    int t;
    cin >> t;
    if(t == 1)flg = !flg;
    else if(t == 2){
      int f;
      char c;
      cin >> f >> c;
      if(f == 1){
        if(flg)s.push_front(c);
        else s.push_back(c);
      }
      else if(f == 2){
        if(flg)s.push_back(c);
        else s.push_front(c);
      }
    }
  }

  if(!flg)reverse(s.begin(), s.end());
  for(auto c : s)cout << c;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x+mo_num)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e6+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
map<string ,int>t;
int32_t main()
{
    IOS
    cin>>n;
    fun(i) {
        string k;
        cin >> k;
        sort(k.begin(),k.end());
        t[k]++;
    }
    fa(i,t)
    {
        ans+=(i.se*(i.se-1)/2);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 11264
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
    
#define endl '\n'
#define int long long

using namespace std;

const int INF = 100000000;

vector<int> g, loop, used;

int dfs(int v) {
    loop.push_back(v);
    used[v] = 1;
    int u = g[v];
    if (used[u]) return u;
    else {
        return dfs(u);
    }
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    g = vector<int> (n);
    loop = vector<int>();
    used = vector<int>(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> g[i];
        g[i]--;
    }
    int val = dfs(0);
    int ind = 0;
    for (int i = 0; i < loop.size(); i++) {
        if (loop[i] == val) {ind = i; break;}
    }
    int x = loop.size() - ind;
    if (k <= ind) cout << loop[k] + 1;
    else cout << loop[ind + (k - ind) % x] + 1;
}


Measured memory_bytes: 14024
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    Vi a(n);
    rp(i,n) cin >> a.at(i);
    ll cash=1000,stock=0;
    rp(i,n-1){
        if(a[i]<a[i+1]){
            ll s=cash/a[i];
            cash%=a[i];
            stock+=s;
        }else if(a[i]>a[i+1]){
            cash+=stock*a[i];
            stock=0;
        }
    }
    cash+=stock*a[n-1];
    print(cash);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <stdlib.h> 

using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;




int main(void) {
	int fX,N,num;
	fX = 0;
	string X;
	cin >> N;
	X = to_string(N);
	num = X.length();

	for (int i = 0; i < num; i++) fX += X[i]-'0';
	
	if (N%fX == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]) {
    int h, w, n;
    
    scanf("%d", &h);
    scanf("%d", &w);
    scanf("%d", &n);
    
    int max, min;
    if (h >  w) max = h;
    if (h <= w) max = w;
    
    int i = 0;
    while (1) {
        n -= max;
        i++;
        if (n <= 0) break;
    }
    
    printf("%d\n", i);
    
    return 0;
}

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

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

    int n, x;
    vector<int> v;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }

    for(int i = n - 1; i >= 0; i--){
        if(i != 0){
            cout << v[i] << " " << flush;
        }else cout << v[i] << endl;
    }
    return 0;
}

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

int main(){
  string sta;
  cin >> sta;
  bool a=0;
  bool b=0;
  for (char c:sta){
    if(c=='A') a=1;
    if(c=='B') b=1;
    if(a&&b) break;
  }
  cout << (a and b ? "Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#define eps (1e-12)
typedef long long ll;
inline int rd(){
    int x=0,p=1;
    char a=getchar();
    while((a<48||a>57)&&a!='-')a=getchar();
    if(a=='-')p=-p,a=getchar();
    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
    return x*p;
}
const int N=1000002;
int n;
struct node{
	double x,y;
}a[N],O;
double R;
inline double dist(node a,node b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
inline void circle(node a,node b,node c){
	double A,B,C,D,E,F;
	A=b.y-a.y,B=c.y-a.y,C=b.x-a.x,D=c.x-a.x;
	E=b.x*b.x+b.y*b.y-a.x*a.x-a.y*a.y;
	F=c.x*c.x+c.y*c.y-a.x*a.x-a.y*a.y;
	O.x=(A*F-B*E)/(2*A*D-2*B*C);
	O.y=(D*E-C*F)/(2*A*D-2*B*C);
	R=dist(O,a);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lf %lf",&a[i].x,&a[i].y);
	std::random_shuffle(a+1,a+n+1);
	O=a[1];
	for(int i=2;i<=n;i++)
		if(dist(a[i],O)>R+eps){
			O=a[i],R=0;
			for(int j=1;j<i;j++)
				if(dist(O,a[j])>R+eps){
					O.x=(a[i].x+a[j].x)/2;
					O.y=(a[i].y+a[j].y)/2;
					R=dist(O,a[j]);
					for(int k=1;k<j;k++)
						if(dist(O,a[k])>R+eps)
							circle(a[i],a[j],a[k]);
				}
		}
//	printf("%.2lf %.2lf ",O.x,O.y);
	printf("%.12lf\n",R);
    return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


int N;
int L[2000];

signed main(){
    cin >> N;
    REP(i, N) cin >> L[i];
    sort(L, L + N);
    int ans = 0;
    REP(a, N - 1){
        FOR(b, a + 1, N){
            auto itr = lower_bound(L, L + N, L[a] + L[b]);
            ans += (itr - L) - 1 - b; 
        }
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> E(N,0);
  int res = 1000;
  for (int i = 0; i < N; i++){
    while (A[i] % 2 == 0){
      E[i]++;
      A[i]/=2;
    }
    res = min(res,E[i]);
  }
  cout << res;
}

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

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
vector<T> PrimeFactorization(T x){
    vector<T> res;
    T v = 2;
    while( v * v <= x){
        if(x%v != 0){
            v++;
        }else{
            res.push_back(v);
            x /= v;
        }
    }
    if(x!=1) res.push_back(x);
    sort(res.begin(), res.end());
    return res;
}

template <typename T>
class ModCalc{
public:
    ModCalc(T MOD){
        mod = MOD;
    }

    T add(T a, T b){
        return (a + b) % mod;
    }

    T sub(T a, T b){
        return (a - b) % mod;
    }

    T multi(T a, T b){
        return ((a % mod) * (b % mod)) % mod;
    }

    T power(T a, T n){
        T res = 1;
        while(n){
            if(n&1) res = multi(res, a);
            a = multi(a, a);
            n >>= 1;
        }
        return res;
    }

    T div(T a, T b){
        return multi(a, power(b, mod-2));
    }

    T comb(T n, T k){
        T res = 1;
        for(int i=0; i<k; i++){
            res = multi(res, n-i);
            res = div  (res, i+1);
        }
        return res;
    }

    T multicomb(T n, T k){
        return comb(n+k-1, k);
    }
private:
    T mod;
};

int main()
{
    ll N, M;
    cin >> N >> M;
    auto pf = PrimeFactorization(M);
    map<ll, ll> pf_map;
    for(auto v : pf){
        if(pf_map.count(v)==0) pf_map[v] = 0;
        pf_map[v]++;
    }
    ModCalc<ll> mc(1000000007);
    ll res = 1;
    for(auto m : pf_map){
        res = mc.multi(res, mc.multicomb(N, m.second));
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define mod             1000000007
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}void _p() {cout << "]\n";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=========================================================




const int N=1e6+6;
int n,m,k,x,y,z,b,c,d,i,j,l,r;

int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};






void sol()
{   
    cin>>n;
    
    
    
    
    cout<< a[n-1] <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 256
/*
 * 16-8-21_AGC003_A.cpp
 *
 *  Created on: 2016/08/21
 *      Author: ryoma
 */

#include<iostream>
#include<string>

using namespace std;


string S;
bool dir[4];
int main(){
	cin >> S;
	for(int i=0;i<S.length();i++){
		switch(S[i]){
		case 'E':
			dir[0] = true;
			break;
		case 'W':
			dir[1] = true;
			break;
		case 'N':
			dir[2] = true;
			break;
		case 'S':
			dir[3] = true;
			break;
		}
	}
	cout <<(!(dir[0]^dir[1])&&!(dir[2]^dir[3])? "Yes":"No")<<endl;
	return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
#define N 2005
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}

const int mo=1000000007;
int n,k,dp[N][N][2];

LL qp(LL x,LL y) {
    LL res=1;
    for(;y;y>>=1,x=x*x%mo)
	if(y&1) res=res*x%mo;
    return res;
}
int main()
{
    n=gi(),k=gi();
    dp[n+1][0][0]=1;
    for(int i=n;i;--i) {
	for(int j=n-i;j>=0;--j) dp[i+1][j][0]+=dp[i+1][j+1][0],dp[i+1][j][0]>=mo?dp[i+1][j][0]-=mo:0;
	for(int j=0;j<=n-i+1;++j)
	    for(int k=0;k<2;++k) {
		dp[i][j+1][1]+=dp[i+1][j][k],dp[i][j+1][1]>=mo?dp[i][j+1][1]-=mo:0;
		dp[i][j][0]+=dp[i+1][j][k],dp[i][j][0]>=mo?dp[i][j][0]-=mo:0;
	    }
    }
    printf("%lld\n",dp[1][n-k][0]*qp(2,max(n-k-1,0))%mo);
    return 0;
}


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

long long mod = 1e9 + 7;

long long modpow(long long x, long long n) {
    x = x%mod;
    if(n == 0){
        return 1;
    }
    else if(n%2 == 1){
        return(x*modpow(x, n-1))%mod;
    }
    else{
        return modpow((x*x)%mod, n/2)%mod;
    }
}

/*コンビネーションの高速化
フェルマーの小定理と逆元の利用*/
long long comb(long long n, long long k){
    long long x = 1;

    for(long long i = n-k+1; i <= n; i++){
        x = x*i;
        x = x%mod;
    }
    long long y = 1;
    for(long long i = 1; i <= k; i++){
        y = y*i;
        y = y%mod;
    }

    y = modpow(y, mod-2);//フェルマーの小定理と逆元を使うことで、計算できない割り算を掛け算にして計算可能にする
    //yで割りたい時はy^(mod-2)を掛ければ良い
    return x*y%mod;//計算可能
}

int main(){
    long long x, y;
    cin >> x >> y;

    if((-x + 2 * y) % 3 != 0 || (2*x - y) % 3 != 0){
        printf("0\n");
        return 0;
    }

    long long a = (-x + 2 * y)/3;
    long long b = (2 * x - y)/3;

    if(a < 0 || b < 0){
        printf("0\n");
        return 0;
    }

    long long ans = comb(a+b, a);

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

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main
{
	static final int MAX = 100005;
	static int arr[] = new int[MAX];
	public static void main(String []args)
	{
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		for(int i = 0; i < n; i++)
		{
			arr[i] = cin.nextInt();
		}
		int q = cin.nextInt();
		for(int i = 0; i < q; i++)
		{
			int a = cin.nextInt();
			binarySearch(0,n,a);
		}
	}
	static void binarySearch(int L,int R,int num)
	{
		while(L < R)
		{
			int mid = L+(R-L)/2;
			if(arr[mid] == num)
			{
				System.out.println("1");
				return;
			}
			else if(arr[mid] > num)
			{
				R = mid;
			}
			else
			{
				L = mid+1;
			}
		}
		System.out.println("0");
	}
}


Measured memory_bytes: 121052
#include <iostream>  
#include <string>  
#include <cstdio>  
#include <cmath>  
#include<cstring>  
#define max(x,y) x>y?x:y  
using namespace std;  
const int maxn=1011111;  
int f[maxn];  
int d[maxn];  
int find(int x)  
{  
    if(f[x]==x)  
        return x;  
  
    int r=find(f[x]);  
    d[x]=d[f[x]]+d[x];//当前x到她老祖宗的距离等于他现在的距离加上她爸爸到老祖宗的距离  
  
    return f[x]=r; //把每个子节点合并到他的祖先  
}  
  
  
int fix(int x,int y,int z)  
{  
    int fx=find(x);  
    int fy=find(y);  
    if(fx==fy)  
        return z==d[y]-d[x];  
    f[fy]=fx;//把x当作y的爸爸；  
    d[fy]=d[x]+z-d[y];  
    return 1;  
}  
  
  
  
  
  
int main()  
{  
    int n,m;  
    int lose=1;  
    cin>>n>>m;  
    for(int i=1;i<=n;i++)//初始化：先把所有点的爸爸都设为自己；  
        f[i]=i;  
    for(int i=1;i<=m;i++)  
    {  
        int x,y,z;  
        cin>>x>>y>>z;  
  
        if(lose)  
            lose=fix(x,y,z);  
  
    }  
  
    if(lose)  
        cout<<"Yes"<<endl;  
    else  
        cout<<"No"<<endl;  
    return 0;  
}  

Measured memory_bytes: 4736
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, c, d = MAP()

if abs(c-a) <= d:
	print("Yes")
elif abs(b-a) <= d and abs(c-b) <= d:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 5588
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)2e6 + 123;

ld a[N];
ld pref[N];
int n;
int k;
ld ans;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif	
	Fast_Read_Out();
	Random();   
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++)
	{
		a[i] = (a[i] + 1) * a[i] / 2 / a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	for(int l = 1; l <= n - k + 1; l++) ans = max(ans, pref[l + k - 1] - pref[l - 1]);
	cout << fixed << setprecision(6) << ans << endl;
}                                

Measured memory_bytes: 8448
object Main extends App {
	val n = scala.io.StdIn.readInt
	val s = scala.io.StdIn.readLine
	val k = scala.io.StdIn.readInt - 1

	val ans = new Array[Char](n)

	for(i<-0 until n){
		ans(i) = if(s(i) == s(k)) s(k)
			else '*'
	}

	println(ans.mkString)


}

Measured memory_bytes: 25552
#include<stdio.h>
 #include<string.h>
 int main(void)
 {
     char S[11],T[12];
     int s,i,J=0,t,U;

     scanf("%s",S);
     scanf("%s",T);

     s=strlen(S);
     t=strlen(T);
     U=t-s;

     for(i=0;i<s;i++)
       if(S[i]==T[i]) J++;

     if((J==s)&&(U==1)) printf("Yes\n");
     else printf("No\n");

     return 0;
 }


Measured memory_bytes: 1612
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned;
int const MOD = 1000000007;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;

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

    Int n,q; cin>>n>>q;
    if(n==1){
    for (int i = 0; i < q; i++){
        Int v,w; cin>>v>>w; cout<<v<<'\n';
    }
    }else{
    for (int i = 0; i < q; i++){
        Int v,w; cin>>v>>w;
        while(v!=w){
            if(v>w)v=(v+n-2)/n;
            else w=(w+n-2)/n;
        }
        cout<<v<<'\n';
    }
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <iomanip>
#include <set>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,n) for(int i=1,i##_len=(n);i<=i##_len;++i)
#define rrep(i,n) for(int i=((int)((n)-1));i>=0;--i)
#define rreps(i,n) for(int i=((int)(n));i>0;--i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end());

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#define DUMPOUT cout
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef LOCAL_
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif

typedef long long int lli;
typedef pair<int, int> ii;
typedef priority_queue<int, vector<int>, greater<int> > heapq;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

// #define int long long int
signed main() {
    int K, X; cin >> K >> X;
    for (int i = X - (K - 1) ; i <= X + (K - 1); i++) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 888
#include<stdio.h>

int main(){
  char S[111111];
  scanf("%s",S);
  int one = 0;
  int two = 0;
  int length = 0;
  int i;
  for(i=0;i<=111111;i++)
    if(S[i] == '\0'){
      length = i;
      break;
    };
  for(i=0;i<=length/2;i++){
    if(S[2*i] == '0') one++;
    if(S[2*i+1]== '1') one++;
  };
  for(i=0;i<=length/2;i++){
   if(S[2*i] == '1') two++;
   if(S[2*i+1]== '0') two++;
  };
  if(one>=two) printf("%d\n",two);
  if(one<two) printf("%d\n",one);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
    int h, w = 1;
    int i, j;

    cin >> h >> w;
    while (h != 0 && w != 0) {
        for (i = 1; i <= h; i++) {
            for (j = 1; j <= w; j++)
                if ((i + j) % 2 == 0)
                    cout << "#";
                else 
                    cout << ".";
            cout << "\n";
        }
        cout << "\n";
        cin >> h >> w;
    }
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s,t;
	bool f=true;
	cin>>s>>t;
	s=s+s;
	REP(i,s.size()-t.size()+1){
		if(s.substr(i,(int)t.size())==t){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
const int N = 2e5 + 10;
int a[N] , n;
unordered_map <int,int> mp;
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 1; i <= n; i++){
        if (mp.count(i - a[i]) > 0) ans = ans + mp[i - a[i]]; // get result at [i]
        mp[a[i] + i]++; // update result at [i]
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 12172
#include <queue>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 805;

char s[MAX][MAX];
int bio[MAX][MAX];
int pr[4] = {1, 0, -1, 0};
int ps[4] = {0, 1, 0, -1};
int brred, brstup;

int vani(int r, int c) {
  return r < 0 || c < 0 || r >= brred || c >= brstup;
}

void bfs(int r, int c) {
  REP(i, MAX) REP(j, MAX) bio[i][j] = 1e9;

  queue <P> Q;
  Q.push(P(r, c));
  bio[r][c] = 0;
  
  for (; !Q.empty(); ) {
    P tmp = Q.front(); Q.pop();
    REP(i, 4) {
      int nr = tmp.X + pr[i];
      int nc = tmp.Y + ps[i];
      if (!vani(nr, nc) && s[nr][nc] != '#' && bio[nr][nc] > bio[tmp.X][tmp.Y] + 1) {
	bio[nr][nc] = bio[tmp.X][tmp.Y] + 1;
	Q.push(P(nr, nc));
      }
    }
  }
}

int main()
{
  int K;
  scanf("%d%d%d", &brred, &brstup, &K);

  P poc = P(-1, -1);
  REP(i, brred) {
    scanf(" %s", s[i]);
    REP(j, brstup)
      if (s[i][j] == 'S')
	poc = P(i, j);
  }

  assert(poc.X != -1);
  bfs(poc.X, poc.Y);

  int rje = 1e9;
  REP(i, brred) {
    REP(j, brstup) {
      if (bio[i][j] <= K) {
	int mn = min(min(i, j), min(brred-i-1, brstup-j-1));
	int jos = (mn + K - 1) / K;
	rje = min(rje, 1 + jos);
      }
    }
  }

  printf("%d\n", rje);
  
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<stack>
#include<queue>
#include <map>
#include<cmath>
#include<vector>
#define MAX_N 1000000
#define INF 1000000
using namespace std;


char a[100][100];
int sum;
int n, m;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void dfs(int x, int y, char c)
{
    a[x][y] = '.';
    for (int i = 0; i < 4; i++)
    {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (xx >= 0 && xx < n && yy >= 0 && yy < m && a[xx][yy] == c)
            dfs(xx, yy, c);
    }
}
int main()
{
    while (~scanf("%d%d%*c", &n, &m) && n && m)
    {
        sum = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%s", a[i]);
            getchar();
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (a[i][j] != '.')
                {
                    dfs(i, j, a[i][j]);
                    sum++;
                }
            }
        }
        printf("%d\n", sum);
    }
}

Measured memory_bytes: 1668
#include <iostream>

using namespace std;

int main(void) {
        int l, r, d;
        cin >> l >> r >> d;

        int count = 0;
        for (int i = l; i <= r; i++) {
                if (i % d == 0)
                        count++;
        }

        cout << count << endl;

        return 0;
}

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

using namespace std;

//int minCostFrom(int curr, const vector<int>& h, vector<int>& memo) {
//    int N = h.size();
//    if (memo[curr] >= 0) {
//        return memo[curr];
//    }
//    if (curr == N - 1) {
//        return 0;
//    }
//    else if (curr == N - 2) {
//        memo[curr] = abs(h[N - 1] - h[N - 2]);
//        return memo[curr];
//    }
//    int ip1 = minCostFrom(curr + 1, h, memo) + abs(h[curr] - h[curr + 1]);
//    int ip2 = minCostFrom(curr + 2, h, memo) + abs(h[curr] - h[curr + 2]);
//    memo[curr] = min(ip1, ip2);
//    return memo[curr];
//}

int Main() {
    int N;
    cin >> N;
    vector<int> h(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }

    //vector<int> memo(N, -1);
    //memo[N - 1] = 0;
    //int ans = minCostFrom(0, h, memo);
    //cout << ans << endl;
    //return 0;

    vector<int> minCost(N, -1);
    minCost[N - 1] = 0;
    minCost[N - 2] = abs(h[N - 1] - h[N - 2]);
    for (int i = N - 3; i >= 0; --i) {
        int one = minCost[i + 1] + abs(h[i] - h[i + 1]);
        int two = minCost[i + 2] + abs(h[i] - h[i + 2]);
        minCost[i] = min(one, two);
    }
    cout << minCost[0] << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
vector<int> v[20056],v1[20020];
int a,b,c,n,m,i,k,o[110000][4][11],d,e,dy[15]={0,0,-1,1,-1,1,-1,1},dx[15]={-1,1,0,0,1,1,-1,-1};
int l[1701000];
long long x,y,z;
P u[600][55];
int j[6000100];
//queue<int> q,q1;
stack<int> s;
queue<int> q;
//long long x=0,y=0,z[99];

//deque<int> d;
//'1'==49;
//'A'==65;
//'a'==97;
map<int, int > p;
string r,r1;
//char r[5000][1111];

bool as(P a,P b)
{
     return a.x<b.x;

}

long long f(int t,int w,int i)
{
    if(i>d) return 0;
    if(v[t].size()==1) return 1;
    if(o[t][w][i]>=0) return o[t][w][i];


}

int main()
{
    long long a,b;
    scanf("%lld",&a);
    for(long long h=1;h<=3500;h++)
        for(long long n=1;n<=3500;n++)
    {
        if(4*h*n-a*n-a*h<=0)
            goto as;
        b=(a*h*n)/(4*h*n-a*n-a*h);

        if(b>0&&4*h*n*b==a*n*b+a*h*b+a*h*n)
        {
            printf("%lld %lld %lld",h,n,b);
            return 0;
        }
        as:;
    }
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){

    int a;
    char buf[30];

    fgets(buf, sizeof(buf), stdin);

    a = atoi(buf);
    
    if(1 <= a <= 10){
        printf("%d\n",a+a*a+a*a*a);  
    }
      

    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  ll tmp[100000] = {};
  REP(i, q) {
    int a;
    cin >> a;
    a--;
    tmp[a]++;
  }
  REP(i, n) {
    if (tmp[i] - q + k > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n, m, ans = 1;
	cin >> n >> m;
	if (max(n, m) > min(n, m) + 1) {
		cout << "0" << endl;
		return 0;
	}
	for (long long i = n; i > 0; i--) {
		ans = ans * i % 1000000007;
	}
	for (long long j = m; j > 0; j--) {
		ans = ans * j % 1000000007;
	}
	if ((n + m) % 2 == 0) {
		ans = ans * 2 % 1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect



q = int(input())

M = {}
list_key_sorted = []

for _ in range(q):
    
    command, *list_num = input().split()

    if   command == "0":
        # insert(key, x)
        key = list_num[0]
        x = int(list_num[1])

        if key not in M:
            bisect.insort_left(list_key_sorted, key)

            M[key] = []

        M[key].append(x)
    elif command == "1":
        # get(key)
        key = list_num[0]
        if key in M:
            if M[key]:
                for value in M[key]:
                    print(value)
    elif command == "2":
        # delete(key)
        key = list_num[0]
        if key in M:
            M[key] = []
    elif command == "3":
        # dump(L, R)
        L = list_num[0]
        R = list_num[1]

        index_left = bisect.bisect_left(list_key_sorted, L)
        index_right = bisect.bisect_right(list_key_sorted, R)

        for index in range(index_left, index_right):
            key_ans = list_key_sorted[index]
            if M[key_ans]:
                for value_ans in M[key_ans]:
                    print(key_ans, value_ans)
    else:
        raise



Measured memory_bytes: 39208
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps (1e-8)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int n,m,l;cin>>n>>m>>l;
    int v[301][301]={0};
    for(int i=1;i<=300;i++)for(int j=1;j<=300;j++)if(i!=j)v[i][j]=1e18;
    
    while(m--){
        int a,b,c;cin>>a>>b>>c;
        v[a][b]=v[b][a]=c;
    }
    
    for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    
    
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
        if(v[i][j]<=l)v[i][j]=1;
        else v[i][j]=1e18;
    }
    
    for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    
    int q;cin>>q;
    while(q--){
        int a,b;cin>>a>>b;
        cout<<((v[a][b])<1e18?v[a][b]-1:-1)<<"\n";
    }
}



Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cmath>

using namespace std;

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

int main() {

    
    int n, k;
    cin >> n >> k;
    
    if (k > ((n - 2) * (n - 1)) / 2)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<P> ret;
    
    for (int i = 2; i <= n; ++i)
    {
        ret.push_back(make_pair(1, i));
    }
    int c = 0;
    bool f = 0;
    for (int i = 2; i < n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            if (2 * c == (n - 2) * (n - 1) - 2 * k)
            {
                f = 1;
                break;
            }
            ret.push_back(make_pair(i, j));
            c++;
        }
        if (f)
        {
            break;
        }
    }
    
    cout << ret.size() << endl;
    
    for (int i = 0; i < ret.size(); ++i)
    {
        cout << ret[i].first << " " << ret[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 512
N, K = list(map(int, input().split()))

x = 0
t = 1
while x < K:
    x = N * (2 ** t)
    t += 1
t -= 1
per = 0
if N >= K:
    per += (1.0 / N)
else:
    per += (1.0 / N) * (0.5 ** t)

for i in range(1, N):
    v = N - i
    x = v * (2 ** t)
    while x < K:
        t += 1
        x = v * (2 ** t)
    if v >= K:
        per += (1.0 / N)
    else:
        per += (1.0 / N) * (0.5 ** t)
print(per)

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

int main () {
  int N;
  string S;
  cin >> N >> S;
  int w[300010] = {0};
  int e[300010] = {0};
  if(S[0] == 'W'){
    w[0] = 1;
  }
  else {
    e[0] = 1;
  }
  for (int i = 1; i < N; ++i) {
    if (S[i] == 'W'){
      w[i] = w[i-1] + 1;
      e[i] = e[i-1];
    }
    else {
      w[i] = w[i-1];
      e[i] = e[i-1] + 1;
    }
  }
  int ans = e[N-1] - e[0];
  for (int i = 1; i < N; ++i) {
    int count = w[i-1] + e[N-1] - e[i];
    if (count < ans) ans = min(ans, count);
  }
  cout << ans << endl;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    cout << 180 * (N - 2) << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] X = new int[N];
		int[] remainder = new int[M];
		int[] db = new int[M];
		HashSet<Integer> set = new HashSet<Integer>();
		for (int i=0;i<N;i++) {
			X[i] = sc.nextInt();
			remainder[X[i]%M]++;
			if (set.contains(X[i])) {
				db[X[i]%M]++;
				set.remove(X[i]);
			} else { // set.!contains(X[i])
				set.add(X[i]);
			}
		}
		int ans = 0;
		for (int i=0;i<M/2+1;i++) {
			if (i==(M-i)%M) {
				ans += remainder[i]/2;
				remainder[i]-=remainder[i];
			} else {
				int tmp = Math.min(remainder[i], remainder[(M-i)%M]);
				ans += tmp;
				remainder[i] -= tmp;
				remainder[(M-i)%M] -= tmp;
			}
		}
		for (int i=0;i<M;i++) {
			int tmp = Math.min(remainder[i]/2, db[i]);
			ans += tmp;
			remainder[i] -= tmp*2;
		}
		System.out.println(ans);
		// System.out.println(Arrays.toString(remainder));
		// System.out.println(Arrays.toString(db));
	}
}

Measured memory_bytes: 65896
import sys
input = sys.stdin.read().split()

N = int(input[0])
words = input[1:]

hantei = 0

for i in range(N-1):
    for j in range(i+1,N):
        if words[i] == words[j]:    # 同じ文字がないか
            hantei += 1
            break
    if list(words[i])[-1] != list(words[i+1])[0]:   #しりとりになっているか
        hantei += 1
        break

if hantei == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064