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

struct StronglyConnectedComponents{
    vector<vector<int>> G,rG,C,T;
    vector<int> vs,cmp,used;
    StronglyConnectedComponents(int n):G(n),rG(n),cmp(n),used(n){}
    void add_edge(int u,int v){
        G[u].emplace_back(v);
        rG[v].emplace_back(u);
    }
    void dfs(int v){
        used[v]=1;
        for (int u:G[v]) if(!used[u]) dfs(u);
        vs.emplace_back(v);
    }
    void rdfs(int v,int k){
        used[v]=1;
        cmp[v]=k;
        C[k].emplace_back(v);
        for (int u:rG[v]) if (!used[u]) rdfs(u,k);
    }
    int build(){
        int n=G.size();
        for (int i=0;i<n;++i) if (!used[i]) dfs(i);
        fill(used.begin(),used.end(),0);
        int k=0;
        for (int i=n-1;i>=0;--i){
            if (!used[vs[i]]){
                C.emplace_back(),T.emplace_back();
                rdfs(vs[i],k++);
            }
        }
        for (int v=0;v<n;++v) for (int u:G[v]){
            if (cmp[v]!=cmp[u]) T[cmp[v]].emplace_back(cmp[u]);
        }
        for (int i=0;i<k;++i){
            sort(T[i].begin(),T[i].end());
            T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
        }
        return k;
    }
    int operator[](int i) const{
        return cmp[i];
    }
};

struct TwoSatisfiability{
    int n;
    StronglyConnectedComponents SCC;
    TwoSatisfiability(int n):n(n),SCC(n*2){}
    int neg(int v){return (n+v)%(n*2);}
    void add_if(int u,int v){
        SCC.add_edge(u,v);
        SCC.add_edge(neg(v),neg(u));
    }
    void add_or(int u,int v){
        add_if(neg(u),v);
    }
    void add_nand(int u,int v){
        add_if(u,neg(v));
    }
    void set_true(int v){
        SCC.add_edge(neg(v),v);
    }
    void set_false(int v){
        SCC.add_edge(v,neg(v));
    }
    vector<int> build(){
        SCC.build();
        vector<int> res(n);
        for (int i=0;i<n;++i){
            if (SCC[i]==SCC[n+i]) return {};
            res[i]=SCC[i]>SCC[n+i];
        }
        return res;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,D; cin >> N >> D;
    vector<int> X(N),Y(N);
    for (int i=0;i<N;++i) cin >> X[i] >> Y[i];
    TwoSatisfiability TS(2*N);
    for (int i=0;i<2*N;i+=2){
        TS.add_or(i,i+1);
        TS.add_nand(i,i+1);
    }
    for (int i=0;i<N;++i){
        for (int j=i+1;j<N;++j){
            if (abs(X[i]-X[j])<D) TS.add_nand(i<<1|0,j<<1|0);
            if (abs(X[i]-Y[j])<D) TS.add_nand(i<<1|0,j<<1|1);
            if (abs(Y[i]-X[j])<D) TS.add_nand(i<<1|1,j<<1|0);
            if (abs(Y[i]-Y[j])<D) TS.add_nand(i<<1|1,j<<1|1);
        }
    }

    vector<int> ans=TS.build();
    if (ans.empty()){cout << "No" << '\n'; return 0;}
    cout << "Yes" << '\n';
    for (int i=0;i<N;++i){
        cout << (ans[i<<1|0]?X[i]:Y[i]) << '\n';
    }
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
	int a[3];
	r(i,3)cin>>a[i];
	sort(a,a+3);
	cout<<a[1]-a[0]+(a[2]-a[1])<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    string s;
    cin >> s;
    int n=s.size();
    rep(i,n-8){
        cout << s.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;




int main()
{
	int size,cou,ans;
	cou = 0;
	string S;
	cin >> S;
	size = S.length();
	ans=size;
	for (int i = 0; i < size; i++){
		if (S[i] == 'S')cou++;
		else if (S[i] == 'T'&&cou>0){
			cou--;
			ans -= 2;

	}
	}
		cout << ans << endl;
	
}

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

using namespace std;

int main() {
  int k,s; cin >> k >> s;
  int ans = 0;

  for (int i = 0; i < k+1; i++) {
    for (int j = 0; j < k+1; j++) {
      if(i + j <= s && s - i - j <= k) {
        ans++;
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL MOD = 1000000007LL;
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if (A % 2 == B % 2) cout << "Alice" << endl;
	else cout << "Borys" << endl;
}

Measured memory_bytes: 256
program abc112_d
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m
    integer(int32):: i

    read*, n,m
    do i=m/n,1,-1
        if (mod(m,i) == 0) then
            print'(i0)', i
            stop
        end if
    end do
end program abc112_d

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    int t[n+1]={}; rep(i,n){cin>>t[i+1],t[i+1]*=2;}
    rep(i,n) t[i+1]+=t[i];
    int v[n]; rep(i,n){cin>>v[i],v[i]*=2;}
    int vv[n+1]={}; rep(i,n-1) vv[i+1]=min(v[i],v[i+1]);
    int sp[40010]; rep(i,40010) sp[i]=INF;
    rep(i,n){
        for(int j=t[i];j<=t[i+1];j++){
            sp[j]=min(sp[j],v[i]);
        }
    }
    rep(i,40010){
        rep(j,n+1){
            sp[i]=min(sp[i],vv[j]+abs(i-t[j]));
        }
    }
    double ans=0;
    rep(i,t[n]){
        ans+=min(sp[i],sp[i+1])+1.0*abs(sp[i]-sp[i+1])/2;
    }
    printf("%.10f\n",ans/4);
    return 0;
}


Measured memory_bytes: 384
N, K = map(int, input().split())
MOD = 998244353
ans = [0, 1, -1] + [0]*(N-2)
L, R = [], []
for _ in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r+1)

temp = 0
for i in range(1, N):
    temp = (temp + (ans[i] % MOD)) % MOD
    for l in L:
        if i + l <= N:
            ans[i+l] = (ans[i+l] + temp) % MOD
    for r in R:
        if i + r <= N:
            ans[i + r] = (ans[i+r] - temp) % MOD
print((temp + ans[N]) % MOD)

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string A, B; cin >> A >> B;
cout << B << A;
}

Measured memory_bytes: 3636
//https://atcoder.jp/contests/abc145/submissions/8631213
//参考にさせて頂いたもの

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

//フェルマーの小定理を用いて逆元を求める関数?
ll power(ll a,ll b,ll c){
    ll res=1;
    a=a%c;
    while(b>0){
        if(b%2==1)res=(res*a)%c;
        b/=2;
        a=(a*a)%c;
    }
    return res;
}


int main(){
    ll X,Y;
    cin>>X>>Y;
    if((X+Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }

    ll m=(2*X-Y)/3;
    ll n=(2*Y-X)/3;
    if(m<0||n<0){
        cout<<0<<endl;
        return 0;
    }

    vector<ll>fact(m+n+1);
    fact[0]=1;
    for(int i=1;i<=n+m;i++){
        fact[i]=(i*fact[i-1])%INF;
    }
    ll num=fact[n+m];
    ll den=(fact[n]*fact[m])%INF;
    den=power(den,INF-2,INF);

    
    //cout<<"m:"<<m<<"n:"<<n<<endl;
    //debugに使ったコードは消そう……

    cout<<(num*den)%INF<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 5504
using System;
using System.IO;

namespace DSL2_B
{
    class BIT
    {
        internal int n;
        internal int[] bit;

        public BIT(int N)
        {
            n = N;
            bit = new int[n + 1];
        }

        public int Sum(int i)
        {
            int s = 0;
            while (i > 0)
            {
                s += bit[i];
                i -= i & -i;
            }
            return s;
        }

        public void Add(int i, int x)
        {
            while (i <= n)
            {
                bit[i] += x;
                i += i & -i;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var t = scan;
            int n = t[0]; int q = t[1];
            var B = new BIT(n);
            for (int i = 0; i < q; i++)
            {
                t = scan;
                if (t[0] == 0)
                {
                    B.Add(t[1], t[2]);
                }
                else
                {
                    Console.WriteLine(B.Sum(t[2]) - B.Sum(t[1] - 1));
                }
            }
            Console.Out.Flush();
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

Measured memory_bytes: 10180
#include <vector>
#include <queue>
#include <cstdio>
#include <utility>
#include <climits>

int main(){
	std::priority_queue<std::pair<int, int>> queue;
	int n;
	std::scanf("%d", &n);
	std::vector<std::vector<std::pair<int, int>>> edges;
	std::vector<int> result(n, INT_MAX);
	for (auto i = 0; i < n; ++i){
		std::vector<std::pair<int, int>> edge;
		int u, k;
		std::scanf("%d %d", &u, &k);
		for (auto j = 0; j < k; ++j){
			int c, v;
			std::scanf("%d %d", &v, &c);
			edge.push_back(std::make_pair(v, c));
		}
		edges.push_back(edge);
	}
	queue.push(std::make_pair(0, 0));
	for (auto i = 0; i < n; ++i){
		while (result.at(queue.top().second) < -queue.top().first){
			//std::cout << queue.top().second << "qqqq" << queue.top().first << std::endl;
			queue.pop();
		}
		int dist = -queue.top().first; int vert = queue.top().second;
		queue.pop();
		result.at(vert) = dist;
		//std::cout << vert << "v-d" << dist << std::endl;
		for (auto j : edges.at(vert)){
			//std::cout << j.first << "(" << result.at(j.first) << ")" << "||" << j.second << "\n";
			if (result.at(j.first) > dist+ j.second){
				queue.push(std::make_pair(-dist - j.second, j.first));
				result.at(j.first) = dist + j.second;
			}
		}
	}
	for (auto i = 0; i < n; ++i){
		std::printf("%d %d\n", i, result.at(i));
	}
}

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

using namespace std;
const int maxn = 200000 + 20;

int n;
char strin[maxn];

char Xor(char a, char b)
{
    return a == b ? '0' : '1';
}

int main(int argc, char *argv[])
{
    cin >> n;
    for (int i = 1; i <= n / 2; ++i)
    {
        cin >> strin[i];
    }
    for (int i = n / 2 + 1; i <= n; ++i)
    {
        cin >> strin[i];
    }
    
    for (int i = n / 2; i >= 1; --i)
    {
        char cur = strin[i];
        for (int j = i + i; j <= n; j += i)
        {
            cur = Xor(cur, strin[j]);
        }
        strin[i] = cur;
    }
    
    vector<int> vec;
    for (int i = 1; i <= n; ++i)
    {
        if (strin[i] == '1')
        {
            vec.emplace_back(i);
        }
    }
    cout << vec.size() << endl;
    for (int num : vec)
    {
        cout << num << ' ';
    }
}

Measured memory_bytes: 1912
#!/bin/env python

def count_nums(v):
    counter = {}
    for x in v:
        if x not in counter:
            counter[x] = 0
        counter[x] += 1
    retval = counter.items()
    retval.sort(lambda a,b:b[1] - a[1])
    # i : index
    # retval[i][0] : number
    # retval[i][1] : count
    # retval is sorted by count
    return retval

def main():
    n = int(raw_input().strip())
    v = raw_input().strip().split(" ")
    v1 = [int(v[x]) for x in xrange(0, n, 2)]
    v2 = [int(v[x]) for x in xrange(1, n, 2)]

    cv1 = count_nums(v1)
    cv2 = count_nums(v2)

    if cv1[0][0] != cv2[0][0]:
        print n - (cv1[0][1] + cv2[0][1])
    elif len(cv1) == 1 and len(cv2) == 1:
        print len(v2)
    elif len(cv1) == 1:
        print len(v2) - cv2[1][1]
    elif len(cv2) == 1:
        print len(v1) - cv1[1][1]
    else:
        print n - max(cv1[0][1]+cv2[1][1], cv1[1][1]+cv2[0][1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 22972
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define T first
#define A second

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, Q;
	vector<pair<int,int>> in;
	
	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].T>>in[i].A;
	}
	
	cin>>Q;
	
	for(int j = 0; j < Q; j++){
		int L, R;
		long double P = 1000000000;
		pair<int,int> key;
		
		cin>>L>>R;
		
		key = {L, -1};
		
		int num = lower_bound(in.begin(), in.end(), key) - in.begin();
		
		// cout<<num<<endl;
		for(int i = 0, k = num; i < 500 && k < N; i++, k++){
			if(in[k].T > R) break;
			
			P *= (10.0 - in[k].A)/10;
		}
		
		cout<<P<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 4428
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	long long n,p;
	cin >> n >> p;
	
	long long ans=0;
	
	for(long long i=(long long)(pow(p,1.0/n))+3;i>=1;i--)
	{
		if(p%(long long)(pow(i,n))==0)
		{
			ans=i;
			break;
		}
	}


	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
//#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int N;
    cin>>N;
    long long A[N],ans=0;
    for (int i=0;i<N;i++) cin>>A[i];
    for (int i=1;i<N;i++){
        if (A[i]<A[i-1]){
            ans+=A[i-1]-A[i];
            A[i]=A[i-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5148
module Main where

import Control.Applicative

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine 

main :: IO ()
main = do
  { [a, b] <- getInts
  ; if a < b then putStrLn "a < b"
    else if a == b then putStrLn "a == b"
         else putStrLn "a > b"
  }



Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	public static void printTuple(Tuple[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	public static class Tuple implements Comparable<Tuple> {
		public final int b, c;

		public Tuple(int b, int c) {
			this.b = b;
			this.c = c;
		}

		@Override
		public int compareTo(Tuple that) {
			return this.c - that.c;
		}

		@Override
		public String toString() {
			return "(" + this.b + ", " + this.c + ")";
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		Tuple[] BC = new Tuple[M];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < M; i++) {
			int b = sc.nextInt();
			int c = sc.nextInt();
			BC[i] = new Tuple(b, c);
		}
		Arrays.sort(A);
		Arrays.sort(BC);
		// printArray(A);
		// printTuple(BC);

		int ixA = N - 1;
		int ixB = M - 1;
		int rest = N;
		long sum = 0;
		while (rest > 0) {
			// System.out.print("sum = " + sum + ", rest = " + rest + "\t");
			if (ixB >= 0 && A[ixA] < BC[ixB].c) {
				// System.out.println("select B " + BC[ixB]);
				if (rest > BC[ixB].b) {
					rest -= BC[ixB].b;
					sum += (long)BC[ixB].b * (long)BC[ixB].c;
					ixB--;
				} else {
					sum += (long)rest * (long)BC[ixB].c;
					rest = 0;
				}
			} else {
				// System.out.println("select A " + A[ixA]);
				rest -= 1;
				sum += A[ixA];
				ixA--;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 93572
from collections import deque
from heapq import heappush, heappop
from copy import deepcopy

n, k = map(int, input().split())
v = list(map(int, input().split()))

dq = deque(v)

ans = 0
for ab in range(k + 1):
    cd = k - ab
    for a in range(ab + 1):
        hp = []
        cp = deepcopy(dq)

        b = ab - a
        for _ in range(a):
            if cp:
                val = cp.popleft()
                heappush(hp, val)
        for _ in range(b):
            if cp:
                val = cp.pop()
                heappush(hp, val)

        for _ in range(cd):
            if not hp or hp[0] >= 0:
                break
            heappop(hp)

        ans = max(ans, sum(hp))

print(ans)


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

using namespace std;

int main() {
	char a, b;
	cin >> a >> b;
	if (a == 'H')
		cout << b << endl;
	else {
		if (b == 'D')
			puts("H");
		else puts("D");
	} 
	return 0;
}

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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define MOD 1000000007

int main()
{
    speed;
    ll a,b,c;
    cin>>a>>b>>c;
    ll x = a-b;
    cout<<max((ll)0,c-x);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll red[100001];
ll gre[100001];
ll whi[100001];

int main() {
	vector<ll>vec;
	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	ll i;
	for (i = 0;i <a;i++) scanf("%lld", &red[i]);	
	sort(red, red + a, greater<ll>());
	for (i = 0;i < b;i++) scanf("%lld", &gre[i]);
	sort(gre, gre + b, greater<ll>());
	for (i = 0;i < c;i++)scanf("%lld", &whi[i]);
	sort(whi, whi + c, greater<ll>());
	for (i = 0;i < x;i++) vec.push_back(red[i]);
	for (i = 0;i < y;i++) vec.push_back(gre[i]);
	for (i = 0;i < c;i++) vec.push_back(whi[i]);
	sort(vec.begin(), vec.end(), greater<ll>());
	ll ans=0;
	for (i = 0;i < x + y;i++) ans += vec[i];
	cout << ans;
	return 0;
}


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

int main()
{
    long long int n, power = 1;
    long long int answer = 1;
    cin >> n;
    for (long long int i = 1; i <= n; i++) {
        answer = ((answer % 1000000007) * (i % 1000000007)) % 1000000007;
    }
    cout << answer << endl;

    return 0;
}


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

ll facctoria(ll k){
    ll mol=1;
    for (ll i=1;i<=k;++i)
    {
        mol*=i;
        mol%=mod;
    }
    return mol;
}
int main(){
	ll n,m;cin>>n>>m;
	ll N=facctoria(n)%mod;
	ll M=facctoria(m)%mod;
	if(abs(n-m)==0){
		cout<<(2*N*M)%mod<<endl;
	}else if(abs(n-m)==1){
		cout<<(N*M)%mod<<endl;
	}else{
		cout<<0<<endl;
	}
}


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

#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll   long long 
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
#define fmd          1000000007
#define md         998244353 
#define M           3011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll dp[M][M];

int solve(){
    ll n,i,j,k,m,x,y,z;
    cin>>n>>m;
    vector<ll> a(n+1);
    for(i=1;i<=n;++i)cin>>a[i];
    for(i=1;i<=n;++i){
        dp[i][a[i]]=i;
        for(j=1;j<=m;++j){
            if(j-a[i]<=0)continue;
            ll sum=dp[i-1][j-a[i]];
            dp[i][j]+=sum;
            dp[i][j]%=md;
        }
        for(j=1;j<=m;++j){
            dp[i][j]+=dp[i-1][j];dp[i][j]%=md;
        }
        


    }
    ll ans=0;
    for(i=1;i<=n;++i){
        ans=ans+(n+1-i)*(dp[i][m]-dp[i-1][m]+md)%md;ans%=md;
    }
    cout<<ans<<"\n";


	die();
}
 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif

     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int t;
    t=1;;
    // prec();
    // cin>>t;
 
    while(t--){

        solve();
    }
 
 
 
 


#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

Measured memory_bytes: 70912
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
// t.me/smok1ng_fat_d1ck
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define len(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
const int maxn = 1e5 + 1;
const int mod = 1e9 + 7;
vector<int>g[maxn];
map<pair<int, int>, int>ans;
void dfs(int v, int p) {
    int cc = 1;
    for (auto to : g[v]) {
        if (to == p) continue;
        if (p != -1 && cc == ans[{p, v}]) cc++;
        ans[{to, v}] = ans[{v, to}] = cc;
        dfs(to, v);
        cc++;
    }
}
signed main() {
    int gg = clock();
    fast;
    srand(time(0));
    int n;
    cin >> n;
    vector<pair<int, int> >ed;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u - 1].pb(v - 1);
        g[v - 1].pb(u - 1);
        ed.pb({u - 1, v - 1});
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (g[i].size() > g[mx].size()) mx = i;
    }
    dfs(0, -1);
    cout << g[mx].size() << '\n';
    for (int i = 0; i < n - 1; i++) {
        cout << ans[ed[i]] << '\n';
    }
    return 0;
}


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

int a[101];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	long long int sum=0,y=0;
	while(y+1<=n&&sum+a[y+1]<=x)	sum+=a[++y];
	if(y==n){
		if(sum==x)	cout<<y<<endl;
		else	cout<<y-1<<endl;
	}
	else	cout<<y<<endl;
}


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



int main()
{
    long long n;
    std::cin>>n;
    long long a,b;
    std::cin>>a>>b;
    long long ans;
    ans=n/(a+b)*a;
    if(n%(a+b)>=a) ans+=a;
    else ans+=n%(a+b);
    std::cout<<ans<<"\n";
    return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s, t;
ll prime[2000000];

// < ----------- func eh ---------------- ? //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	n = s.length();
	for(ll i=0;i<n;i++) if(s[i]=='?') s[i] = 'D';
	cout<<s;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
 
bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


int n,k;
int a[364];
bool b[114514];
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	rep(i,k+1){
		rep(j,n){
			if(i-a[j]>=0&&!b[i-a[j]])b[i]=1;
		}
	}
	cout<<(b[k]?"First":"Second")<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d) << endl;
}

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

int main(){
  string s;
  int K;
  cin>>K>>s;
  if(s.size()<=K)
    cout<<s<<endl;
  else{
    for(int i=0;i<K;i++)
      cout<<s.at(i);
    cout<<"..."<<endl;
  }

}

Measured memory_bytes: 3628
#include <iostream>
#include <queue>

const int INF = 100000;
int H, W;

int main(){
   std::cin >> H >> W;
   std::vector<std::string> S(H);
   for(int i=0; i<H; ++i){
      std::cin >> S[i];
   }

   int ans = 0;
   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j){
	 if(S[i][j]=='#') continue;

	 int count[H][W];
	 std::queue<std::pair<int, int> > que;
	 std::queue<int> n_que;
	 std::fill(count[0], count[H], INF);
	 count[i][j] = 0;
	 que.push(std::make_pair(i, j));
	 n_que.push(0);
	 while(!que.empty()) {
	    int x = que.front().first;
	    int y = que.front().second;
	    int n = n_que.front() + 1;
	    que.pop();
	    n_que.pop();

	    if(0<x && S[x-1][y]=='.' && n<count[x-1][y]) {
	       count[x-1][y] = n;
	       que.push(std::make_pair(x-1, y));
	       n_que.push(n);
	    }
	    if(x+1<H && S[x+1][y]=='.' && n<count[x+1][y]) {
	       count[x+1][y] = n;
	       que.push(std::make_pair(x+1, y));
	       n_que.push(n);
	    }
	    if(0<y && S[x][y-1]=='.' && n<count[x][y-1]) {
	       count[x][y-1] = n;
	       que.push(std::make_pair(x, y-1));
	       n_que.push(n);
	    }
	    if(y+1<W && S[x][y+1]=='.' && n<count[x][y+1]) {
	       count[x][y+1] = n;
	       que.push(std::make_pair(x, y+1));
	       n_que.push(n);
	    }
	 }
	 int max = 0;
	 for(int k=0; k<H; ++k){
	    for(int l=0; l<W; ++l){
	       if(count[k][l]<INF) max = std::max(max, count[k][l]);
	    }
	 }
	 ans = std::max(ans, max);
      }
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  using ld = long double;
  cout << fixed << setprecision(15);

  ll N;
  cin >> N;
  vector<ll> t(N), v(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> t.at(i);
  }
  for (ll i = 0; i < N; i++)
  {
    cin >> v.at(i);
  }
  ll T = accumulate(t.begin(), t.end(), 0LL);

  vector<ld> V(2 * T + 1, INF);
  V.at(0) = 0, V.at(2 * T) = 0;

  {
    ll tt = 0;
    for (ll i = 0; i < N; i++)
    {
      for (ll j = 0; j <= 2 * t.at(i); j++)
      {
        chmin(V.at(tt), (ld)v.at(i));
        tt++;
      }
      tt--;
    }
  }

  /*
  for (ll tt = 0; tt <= 2 * T; tt++)
  {
    cerr << (ld)tt / 2 << " " << V.at(tt) << endl;
  }
  */

  for (ll tt = 0; tt <= 2 * T - 1; tt++)
  {
    chmin(V.at(tt + 1), V.at(tt) + 0.5);
  }
  for (ll tt = 2 * T; tt >= 1; tt--)
  {
    chmin(V.at(tt - 1), V.at(tt) + 0.5);
  }

  /*
  for (ll tt = 0; tt <= 2 * T; tt++)
  {
    cerr << (ld)tt / 2 << " " << V.at(tt) << endl;
  }
  */

  ld ans = 0;
  for (ll tt = 0; tt <= 2 * T - 1; tt++)
  {
    ans += (V.at(tt) + V.at(tt + 1)) * 0.25;
  }
  cout << ans << endl;
}

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

typedef long long ll;

typedef pair<ll, pair<int, int> > p;

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

    int N;
    cin >> N;

    vector<int> a(N);

    for(int i = 0; i < N; i++) cin >> a[i];

    int f = *min_element(a.begin(), a.end());
    int b = *max_element(a.begin(), a.end());

    cout << b - f << endl;
}

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

int main() {

	
	int X, Y, tr;
	double km;
	cin >> X >> Y;
	//vector<long long> a(n);
	if (Y > 4 * X) {
		cout << "No" << endl;
		return 0;
	}

	tr = (Y - 2 * X) / 2;
	km = (Y - 2 * X) % 2;
	if (tr >= 0 && km == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

}


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

using namespace std;

int main()
{
    int n;
    cin >>n;
    int a;
    bool flg=true;
    for(int i=0;i<n;i++){
        cin >>a;
        if(a%2==0){
           if(a%5!=0&&a%3!=0)flg=false;
        }
    }
    if(flg)puts("APPROVED");
    else puts("DENIED");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 
 
ll dp[8005],po[3005];

int main() 
{
    FAST;
    po[0]=1;
    for(int i=1;i<3005;i++)
        po[i]=(po[i-1]*2ll)%B;
    ll n,s;
    cin>>n>>s;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        for(int j=3005;j>=0;j--)
            dp[j+a[i]]=(dp[j+a[i]]+(dp[j]*499122177ll)%B)%B;
        dp[a[i]]=(dp[a[i]]+po[n-1])%B;
    }
    cout<<dp[s];
    subt;
    return 0;
}

Measured memory_bytes: 3880
n, a , b,c = gets.chomp.split(" ").map(&:to_i)
ss = []
saisyou = []
(0..n-1).each do |i|
    s = gets.chomp.to_i
    ss << s    
end
ans = 10000
["0","1","2","3"].repeated_permutation(n) do |arr|
    abc = [0,0,0]
    mp = 0
    (0..n-1).each do |e|
        if arr[e] == "3"
            next
        else
            if abc[arr[e].to_i] != 0 
                mp += 10
            end
            abc[arr[e].to_i] += ss[e].to_i
        end
    end
        if abc.include?(0)
            next
        end
        mp += (abc[0]-a).abs + (abc[1]-b).abs + (abc[2]-c).abs
    ans = [ans,mp].min
end
p  ans

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;

char str[maxn];
int dp[1 << 26];
int num[maxn];
int pre[maxn];

int main(){
	int n;	
	scanf("%s", str + 1);
	n = strlen(str + 1);
	for(int i = 0; i < (1 << 26); i++)
		dp[i] = 1e9;

	dp[0] = 0;
	pre[0] = 0;
	for(int i = 1; i <= n; i++)
		pre[i] = pre[i - 1] ^ (1 << (str[i] - 'a'));

	num[0] = 0;
	for(int i = 1; i <= n; i++){
		num[i] = 1e9;					
		num[i] = min(num[i], dp[pre[i]] + 1); // all characters even number of times
		for(int j = 0; j < 26; j++){		  // one character odd number od times
			int x = pre[i] ^ (1 << j);
			num[i] = min(num[i], dp[x] + 1);
		}
		dp[pre[i]] = min(dp[pre[i]], num[i]);
	}
	printf("%d\n", num[n]);
	return 0;
}

Measured memory_bytes: 264192
Acards, Bcards, Ccards = [input() for i in range(3)]

A_discard = B_discard = C_discard = 0

turn = 'a'
for i in range(len(Acards)+len(Bcards)+len(Ccards)):
    if A_discard == len(Acards) and turn == 'a':
        print('A')
        break

    if B_discard == len(Bcards) and turn == 'b':
        print('B')
        break

    if C_discard == len(Ccards) and turn == 'c':
        print('C')
        break

    if turn == 'a':
        turn = Acards[A_discard]
        A_discard += 1
    elif turn == 'b':
        turn = Bcards[B_discard]
        B_discard += 1
    else:
        turn = Ccards[C_discard]
        C_discard += 1


Measured memory_bytes: 3064
#include <stdio.h>
 
long long int gcd(long long int a, long long int b);
 
int main(){
    long long int a, b, c, d;
    long long int cntb=0,cnta=0;
 
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
 
    cntb = b;
 
    cntb -= b / c;
    cntb -= b / d;
 
    cntb += b / (c / gcd(c, d)*d);
  
  	cnta = a-1;
  	cnta -= (a-1)/c;
  	cnta -= (a-1)/d;
  
 	cnta += (a-1)/(c/gcd(c,d)*d);
 
    printf("%lld\n", cntb-cnta);
 
    return 0;
 
}
 
long long int gcd(long long int a, long long int b){
  long long int work;
  	if(a>b){
  	  work = a;
  	  a = b;
  	  b = work;
	}
    long long int r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
 
    return b;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  int count = 0;
  for(int i=2;i<n;i++){
    if(p.at(i) > p.at(i-1) && p.at(i-1) >= p.at(i-2)){
      count++;
    }
    else if(p.at(i) <= p.at(i-1) && p.at(i-1) < p.at(i-2)){
      count++;
    }
  }
  cout << count << endl;
}

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

using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);
const i64 MOD = 1000000007;

bool check(i64 x, i64 k, const vector<i64> &a) {
  i64 cnt = 0;
  i64 n = a.size();

  rep(i, n) {
    i64 ci = 0;
    long double t = 0;
    if (a[i] == 0) {
      if (x < 0) {
      } else {
        ci = n - 1 - i;
      }
    } else {
      t = x / (long double)a[i];
      if (a[i] > 0) {
        ci = upper_bound(a.begin() + i + 1, a.end(), t) - (a.begin() + i + 1);
      } else {
        ci = a.end() - lower_bound(a.begin() + i + 1, a.end(), t);
      }
    }
    cnt += ci;
  }

  return cnt >= k;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  i64 n, k;
  cin >> n >> k;
  vector<i64> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(all(a));
  const i64 MAX = 1e18 * 2;
  i64 ok = MAX;
  i64 ng = -MAX;
  while (abs(ok - ng) > 1) {
    i64 mid = (ok + ng) / 2;
    if (check(mid, k, a)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <climits>

static const int MAX_W = 100001;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  uint32_t N;
  uint32_t W;

  std::cin >> N >> W;

  uint64_t v[100];
  uint64_t w[100];

  uint64_t dp[101][MAX_W];

  for (uint32_t i = 0; i < N; i++) {
    std::cin >> w[i] >> v[i];
  }

  for (uint32_t i = 0; i < N; i++) {
    for (uint32_t w_sum = 0; w_sum <= W; w_sum++) {
      dp[i + 1][w_sum] = dp[i][w_sum];
      if (w_sum >= w[i]) {
        dp[i + 1][w_sum] = std::max(dp[i][w_sum - w[i]] + v[i], dp[i + 1][w_sum]);
      }
    }
  }

  std::cout << dp[N][W] << std::endl;;

  return 0;
}


Measured memory_bytes: 79232
#include<stdio.h>
#include<stdlib.h>

int main(){
    int n=0, i, j;
    char *s, *t;

    scanf("%d", &n);
    if(n>100 || n<0){
        printf("nが正しくないです\n");
        return 1;
    }

    s = (char *)malloc(sizeof(char)*n);
    t = (char *)malloc(sizeof(char)*n);
    if(s==NULL || t==NULL){
         printf("文字列を確保できませんでした\n");
         return 1;
    }

    scanf("%s", s);
    scanf("%s", t);

    for(i=0;i<n;i++){
        for(j=0;j<n-i;j++){
            if(s[i+j]!=t[j]){
                break;
            }
        }
        if(j==n-i)
            break;
    }

    printf("%d\n", i+n);

    free( s );
    free( t );

    return 0;
}

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

#define int long long int
#define MOD 1000000007
#define N 100001
#define pii pair<int,int>
#define MAX 1e18
#define _mp make_pair
#define pb push_back
#define _sort(v) sort(v.begin(),v.end())
#define _rsort(v) sort(v.rbegin(),v.rend())
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

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

int32_t main(){
SPEED
int n,k,sum=0;
cin>>n>>k;
vector<int> v(n);
for(int i=0;i<n;i++)
cin>>v[i];
_sort(v);
for(int i=0;i<k;i++)
sum+=v[i];
cout<<sum;
    
    // end_timer = std::chrono::high_resolution_clock::now();
    // ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer - start_timer).count();

return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N+1);

    REP(i, N+1){
        cin >> A[i];
        if(A[i] > pow(2,i)){
            cout << -1 << endl;
            return 0;
        }
    }

    if(N == 0){
        if(A[0] == 1){
            cout << 1 << endl;
            return 0;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }

    if(N>=1){
        if(A[0] != 0){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<ll> B(N+1);

    for(ll i=N; i>=0; i--){
        if(i == N){
            B[i] = A[i];
            continue;
        }
        B[i] = B[i+1] + A[i];
    }

    vector<ll> X(N+1);

    REP(i, N+1){
        if(i == 0){
            X[0] = pow(2, 0) - A[0];
            continue;
        }
        if(i == N){
            if(A[N] == 0 || A[N] > pow(2, N)){
                cout << -1 << endl;
                return 0;
            }
            if(X[i-1]*2 < A[i]){
                cout << -1 << endl;
                return 0;
            }
            X[N] = 0;
            // cout << X[i] << endl;
            continue;
        }
        X[i] = min(B[i+1], 2*X[i-1] - A[i]);
        if(X[i] < 0 || X[i] > pow(2, i)){
            cout << -1 << endl;
            return 0;
        }
        // cout << X[i] << endl;
    }

    ll ans = 0;

    REP(i, N+1){
        ans += A[i] + X[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6084
S = input()
s_list = ["dream", "dreamer", "erase", "eraser"]
S_r = S[::-1]
i_n=0
for i, j in enumerate(s_list):
    s_list[i] = j[::-1]
while i_n < len(S):
    f_can = False
    for j in s_list:
        if S_r[i_n:i_n+len(j)] == j:
            f_can = True
            i_n+=len(j)
        else:
            False
    if f_can == False:
        break
        
if f_can == False:
    print("NO")
else:
    print("YES")

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

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            long a = cin.nextLong();
            long b = cin.nextLong();
            long c = cin.nextLong();
            long d = cin.nextLong();

            if (Math.Abs(a - c) <= d || (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main() {
  char c;
  cin >> c;
  
  if(c=='a'||c== 'i'||c== 'u'||c== 'e'||c== 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N;
  string S;
  cin>>N>>S;
  ll cnt=0,A=0,B=0;
  REP(i,N){
    if(S[i]=='(') cnt++;
    else{
      if(cnt==0) A++;
      else cnt--;
    }
  }
  
  cnt=0;
  for(int i=N-1; i>=0; --i){
    if(S[i]==')') cnt++;
    else{
      if(cnt==0) B++;
      else cnt--;
    }
  }
  
  REP(i,A) cout<<"(";
  cout<<S;
  REP(i,B) cout<<")";
  return 0;
}

Measured memory_bytes: 3616