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

using namespace std;
typedef long long int ll;
typedef pair<double, double > pi; 
typedef pair<pair<ll ,ll >,ll > pii; 

int main(){
    
    ll X, Y; cin >> X >> Y;

    ll ans = X + Y / 2;
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<double> P;
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
bool in_triangle(const P& p1,const P& p2,const P& p3,const P& p){
	return cross(p2-p1,p-p1)>0 && cross(p3-p2,p-p2)>0 && cross(p1-p3,p-p3)>0;
}
int main(){
	double x1,y1,x2,y2,x3,y3,x,y;
	for(;~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y);){
		P p1(x1,y1),p2(x2,y2),p3(x3,y3),p(x,y);
		bool in=in_triangle(p1,p2,p3,p)||in_triangle(p2,p1,p3,p);
		puts(in?"YES":"NO");
	}
}

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

int main() {
  int s;
  int s1, s2, s3;
  
  cin >> s;
  
  s1 = s % 10;
  s = (s - s1)/10;
  s2 = s % 10;
  s = (s - s2)/10;
  s3 = s % 10;
  
  cout << s1 + s2 + s3 << endl;

}

Measured memory_bytes: 256
import math

def calc_angle(h, m):
	# validate the input
	if (h < 0 or m < 0 or h > 12 or m > 60):
		print('Wrong input')

	if (h == 12):
		h = 0
	if (m == 60):
		m = 0

	# Calculate the angles moved by
	# hour and minute hands with
	# reference to 12:00
	hour_angle = 0.5 * (h * 60 + m)
	minute_angle = 6 * m

	# Find the difference between two angles
	angle = abs(hour_angle - minute_angle)

	# Return the smaller angle of two
	# possible angles
	angle = min(360 - angle, angle)

	return angle

def resolve():
	a, b, h, m = map(int, input().split())
	ang = calc_angle(h, m)
	radi = math.radians(ang)
	v = (a**2 + b**2 - 2*a*b*math.cos(radi))**0.5
	print(v)
resolve()

Measured memory_bytes: 62716
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(ll X) {
	if (!X) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[20];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
int A[100000];
ll B[100001];
int C[100001];
int MA[100001], MI[100001];
int saidai, k = 1;
ll kotae[100001];

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


	int N = getint();
	int k3 = 0;
	rep(i, N) {
		int a = getint();
		if (a > saidai) {
			MA[k] = a;
			MI[k] = i;
			B[k] += a - saidai;
			C[k++]++;
			saidai = a;
		}
		else A[k3++] = a;
	}
	if (k < 10) {
		rep(i, k3) {
			int k2 = 1;
			while (MA[k2] < A[i]) k2++;
			B[k2] += A[i] - MA[k2 - 1];
			C[k2]++;
		}
	}
	else {
		pakuri_sort(k3, A);
		int k2 = 1;
		rep(i, k3) {
			while (MA[k2] < A[i]) k2++;
			B[k2] += A[i] - MA[k2 - 1];
			C[k2]++;
		}
	}

	ll cnt = 0;
	for (int i = k - 1; i >= 1; i--) {
		kotae[MI[i]] = B[i] + (MA[i] - MA[i - 1]) * cnt;
		cnt += C[i];
	}

	rep(i, N) putint(kotae[i]);

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  bool flag =false;
  if(A == B && A != C){
    flag = true; }
else if(A == C && A != B){
   flag = true; }
 else if(B == C && A != B) {
    flag = true; }
  if(flag == true) {
    cout << "Yes" << endl; }
  else {
    cout << "No" << endl; }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m;
    cin >> n >> m;
    vec a(m);
    rep(i, m) cin >> a[i];

    rep(i, m) n -= a[i];

    if (n < 0) n = -1;
    cout << n << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n, i, j, cont=1, ndiv;

    scanf("%d", &n);

    if(n<105)
        printf("0\n");
    else if(n==105)
        printf("1\n");
    else
    {
        for(i=106;i<=n;i++)
        {
            ndiv=2;
            for(j=2;j<=i/2;j++)
            {
                if(i%j==0)
                    ndiv++;

            }
            if(i%2!=0 && ndiv==8)
                cont++;
        }

        printf("%d\n", cont);
    }

    return 0;
}



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

struct card {
	char s;
	int n;
};

int n;
card A[100000], B[100000];
const card MAX = { 'X', 10000 };

void merge(int left, int mid, int right) {
	int n1 = mid - left, n2 = right - mid;
	card L[n1 + 1], R[n1 + 1];
	for (int i = 0; i < n1; i++)
		L[i] = B[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = B[mid + i];
	L[n1] = MAX;
	R[n2] = MAX;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		if (L[i].n <= R[j].n) {
			B[k] = L[i];
			i++;
		} else {
			B[k] = R[j];
			j++;
		}
	}
}

void mergesort(int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergesort(left, mid);
		mergesort(mid, right);
		merge(left, mid, right);
	}
}

int partition(int p, int r) {
	int x = A[r].n;
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j].n <= x) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

void quicksort(int p, int r) {
	if (p < r) {
		int q = partition(p, r);
		quicksort(p, q - 1);
		quicksort(q + 1, r);
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i].s >> A[i].n;
		B[i].s = A[i].s;
		B[i].n = A[i].n;
	}
	quicksort(0, n - 1);
	mergesort(0, n);
	for (int i = 0; i < n; i++) {
		if (A[i].s != B[i].s) {
			cout << "Not stable" << endl;
			break;
		} else if (i == n - 1) {
			cout << "Stable" << endl;
		}
	}
	for (int i = 0; i < n; i++)
		cout << A[i].s << " " << A[i].n << endl;
	return 0;
}



Measured memory_bytes: 5400
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <string.h>
using namespace std;


//void dfs(int ind, vector<int> adj[], vector<bool> visited, vector<int> arr){
void dfs(int ind, vector<int> adj[], bool visited[], int arr[]){
  visited[ind] = true;
  for (int i=0; i < adj[ind].size(); i++){
    if(!visited[adj[ind][i]]){
      dfs(adj[ind][i], adj, visited, arr);
    }
  }
  for (int i=0; i < adj[ind].size(); i++){
    arr[ind] = max(arr[ind], arr[adj[ind][i]] + 1);
  }
}

int main()
{
  int n = 0;
  int m = 0;
  scanf("%d %d", &n, &m);
  vector<int> adj[n]; //array of vectors
  int s, e;
  for(int i = 0; i<m; i++){
    scanf("%d %d", &s, &e);
    adj[s-1].push_back(e-1);
  }
  //vector<bool> visited(n+1, false);
  //vector<int> arr(n+1, 0);
  int arr[n];
  bool visited[n];
  memset(arr, 0, sizeof arr);
  memset(visited, false, sizeof visited);


  for (int i=0; i<n; i++){
    dfs(i, adj, visited, arr);
  }
  int result = 0;
  for (int i=0; i<n; i++){
    //printf("%d ", arr[i]);
    result = max(result, arr[i]);
  }
  //printf("\n");
  printf("%d\n", result);
}


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

set< pair<int, int> > que[1 << 18];
int ans[1 << 18];

int main() {
    int N; cin >> N;
    for(int i=0; i<(1<<N); i++) {
        int val; cin >> val;
        que[i].insert(make_pair(val, i));
        for(int k=0; k<N; k++) {
            if(i >> k & 1) {
                int bit = i ^ (1 << k);
                auto tmp = que[bit];
                // fprintf(stderr, "i = %d, bit = %d\n", i, bit);
                while(tmp.size()) {
                    auto it = tmp.begin();
                    que[i].insert(*it); tmp.erase(*it);
                }
            }
        }
        while(que[i].size() > 2) que[i].erase(*que[i].begin());

        for(auto x : que[i]) {
            ans[i] += x.first;
        }
    }

    int ma = -1;
    for(int bit=0; bit<(1<<N); bit++) {
        ma = max(ma, ans[bit]);
        if(bit >= 1) cout << ma << endl;
    }
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s, t;
    cin >> s >> t;
    map<char, vector<ll>> idx;
    rep(i, len(s)) idx[s[i]].push_back(i);
    ll ans = 0, cur = 0;
    rep(i, len(t)) {
        if (sz(idx[t[i]]) == 0) {
            cout << -1 << endl;
            return 0;
        }
        char c = t[i];
        auto it = lower_bound(all(idx[c]), cur);
        if (it == idx[c].end()) {
            ll st = *(idx[c].begin());
            ans += (len(s) - cur + 1) + st;
            cur = st + 1;
        }
        else {
            ans += *it - cur + 1;
            cur = *it + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> L(N),R(N),A(N);
    rep(i,N) cin >> A[i];
    L[0]=A[0];
    R[N-1]=A[N-1];

    rep2(i,1,N){
        L[i]=__gcd(L[i-1],A[i]);
        R[N-i-1]=__gcd(R[N-i],A[N-i-1]);
    }

    int ans=0;
    rep(i,N){
        if(i==0){
            ans = max(ans,R[1]);
        }else if(i==N-1){
            ans = max(ans,L[N-2]);
        }else{
            ans = max(ans,__gcd(L[i-1],R[i+1]));
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 1408
N = int(input())
T = []
try:
	while True:
		t = input()
		t=int(t)
		T_temp=[]
		for t_ in range(t) :
			temp = list(map(int,input().split()))
			T_temp.append(temp)
		T.append(T_temp)
except EOFError:
	pass
    
def check_Contradiction(true_list):
    S = {}
    for n in range(N):
        if n in true_list:
            S[n]=set([1])
        else:
            S[n]=set([0])

    for t in true_list:
        for T_ in T[t]:
            S[T_[0]-1].add(T_[1])
    ok=True
    for s in S.keys():
        if len(S[s])!=1:
            ok='False'
            break

    return ok

ok_max = -1
for i in range(2**N):
#     print('=====',i)
    true_list=[]
    for j in range(N):
        if i>>j&1 ==True:
            true_list.append(j)
#     print(true_list)
#     print(check_Contradiction(true_list))
            
    if check_Contradiction(true_list)==True:
        if ok_max < len(true_list):
            ok_max=len(true_list)
            
print(ok_max)

Measured memory_bytes: 74496
#include<bits/stdc++.h>
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int MX=5000;
const ll inf=(1ll<<60);
const ll mod=1e9+7;
ll n,k,sum,m,a[MX],b[MX],ans;
int main(){
    scanf("%lld%lld",&n,&k);ans=n;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(a[i]>=k){ans--;continue;}
        b[m]=a[i];m++;
    }
    sort(b,b+m);
    while(m>=2){
        sum+=b[m-1];
        if(b[0]+sum>=k){ans=0;break;}
        if(b[m-2]+sum<k){m--;continue;}
        ll l=0,r=m-2;
        while(l+1<r){
            ll mid=(l+r)/2;
            if(b[mid]+sum>=k)r=mid;
            else l=mid;
        }
        ans-=(m-r);
        m=r;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next(), t = sc.next();
		int a = sc.nextInt(), b = sc.nextInt();
		String u = sc.next();
		if(u.equals(s)) {
			a--;
		}else {
			b--;
		}
		System.out.println(a+" "+b);
	}
}

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		final int r = sc.nextInt();
		final int c = sc.nextInt();
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int v = sc.nextInt();
				table[i][j] = v;
				table[i][c] += v;
				table[r][j] += v;
				table[r][c] += v;
			}
		}
		sc.close();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				sb.append(table[i][j]);
				if (j == c) {
					sb.append("\n");
				} else {
					sb.append(" ");
				}
			}
		}
		System.out.print(sb);
	}
}

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

int main(){
    int h, w, a, b; cin >> h >> w >> a >> b;
    vector<vector<bool>> m(h, vector<bool>(w, false));
    for (auto i = 0; i < b; i++) for (auto j = 0; j < a; j++) m[i][j] = true;
    for (auto i = b; i < h; i++) for (auto j = a; j < w; j++) m[i][j] = true;
    for (auto i = 0; i < h; i++) {
        for (auto j = 0; j < w; j++) cout << m[i][j];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
using namespace std;
typedef pair<int,int>pii;
int deg[100010];
vector<int>G[100010];
int n,m;
int fa[100010];
bool vis[100010];
void dfs(int x,int pr){
	vis[x]=1;
	fa[x]=pr;
	for(auto to:G[x])deg[to]--;
	for(auto to:G[x])if(!vis[to]&&deg[to]==0)dfs(to,x);
}
int root;
int main(){
	cin>>n>>m;
	for(int i=1,x,y;i<=m-1+n;i++){
		cin>>x>>y;
		G[x].pb(y);
		deg[y]++;
	}
	for(int i=1;i<=n;i++)if(!deg[i]){
		root=i;
		break;
	}
	dfs(root,0);
	for(int i=1;i<=n;i++)cout<<fa[i]<<endl;
	return 0;
}


Measured memory_bytes: 10240
import scala.math

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i

  var s = sc.next()
  var t = sc.next()
  var ans = 0
  for (i <- 0 until 3){
    if(s(i) == t(i))ans += 1
  }
  println(ans)
}


Measured memory_bytes: 55432
def replace(str, st, ed, repl)
	str[st..ed] = repl
	return str
end

def reverse(str, st, ed)
	t = str.split(//)
	while st < ed do
	  t[st], t[ed] = t[ed], t[st]
	  st += 1
	  ed -= 1
	end
	return t.join("")
end

def print(str, st, ed)
	puts str[st..ed]
end


base = gets.chomp
  
n = gets.to_i
  
n.times do
  t = gets.split(" ")
  if t[0]=="replace"
    base = replace(base, t[1].to_i, t[2].to_i, t[3])
  elsif t[0]=="reverse"
    base = reverse(base, t[1].to_i, t[2].to_i)
  else
    print(base, t[1].to_i, t[2].to_i)
  end
  
end

Measured memory_bytes: 6172
"""
??§?°???¢???


???????????´??° a, b ?????????????????§???a ??¨ b ?????§?°???¢??????????????????????????°????????????????????????????????? 

Input

??\??????????????§??????????????????????????´??° a, b ???????§????????????????????????? 

Output

a ?????? b ???????????§???????????° 
a < b


a ?????? b ??????????°????????????°??? 
a > b


a ??¨ b ?????????????????°??? 
a == b


??¨???????????????????????? 

Constraints
??¢ -1,000 ??? a, b ??? 1,000

"""
a,b = map(int, input().split())
if a < b:
 print("a < b")
elif a > b:
 print("a > b")
else:
 print("a == b")

Measured memory_bytes: 7632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	int n;
	cin >> n;
	cout << (n+1)*n / 2;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 1e9 + 7;



string S;

ll N, D, ans = 1;


int main() {

	cin >> N>>D;
	
	cout << (N+2*D) /(2*D+1) << endl;





	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,N) for(int i=0;i < (N);i++)
using namespace std;

int main(){
	int mod = 1000000007;
	long long N;
	long long sum=0;
	cin>>N;
	vector<long long> A(N);
	rep(i,N){
		cin>>A[i];
		sum+=A[i];
		sum%=mod;
	}
	long long ans=0;
	rep(i,N){
		sum-=A[i];
		if(sum<0)sum+=mod;
		ans+=sum*A[i];
		ans%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4836
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
stack<double>X;
int s2i(string s){
	stringstream ss(s);
	int d;
	ss>>d;
	return d;
}
double f(string s){
	double a,b;
	b=X.top();X.pop();
	a=X.top();X.pop();
	if(s=="+")a+=b;
	else if(s=="-")a-=b;
	else if(s=="*")a*=b;
	else if(s=="/")a/=b;
	return a;
}
int main(){
	string s;
	while(getline(cin,s)){
		stringstream ss(s);
		while(ss>>s)X.push((s=="+"||s=="-"||s=="*"||s=="/")?f(s):s2i(s));
		printf("%.6f\n", X.top());
		X.pop();
	}
}

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

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

    int ans = min(n*a, b);

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


Measured memory_bytes: 256
N = int(input())
S = input()

count = {"R": 0, "G": 0, "B": 0}
char2num = {"R": 1, "G": 10, "B": 100}
count_list = []

for char in S[::-1]:
    count[char] += 1
    count_list.append((count["R"], count["G"], count["B"]))
count_list = count_list[::-1]
        

ans = 0
for i in range(N-2):
    one = char2num[S[i]]
    for j in range(i+1, N-1):
        two = char2num[S[j]]
        if one != two:
            tmp = j+(j-i) < N
            if one+two == 11:
                if tmp and S[j+(j-i)] == "B":
                    ans += count_list[j][2] - 1
                else:
                    ans += count_list[j][2]
                    
            if one+two == 101:
                if tmp and S[j+(j-i)] == "G":
                    ans += count_list[j][1] - 1
                else:
                    ans += count_list[j][1]
                    
            if one+two == 110:
                if tmp and S[j+(j-i)] == "R":
                    ans += count_list[j][0] - 1
                else:
                    ans += count_list[j][0]
print(ans)


        

Measured memory_bytes: 69320
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
#define ld long double
#define rep(i,a,n) for (ll i= (a) ; i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(),(v).end()
#define M_PI 3.14159265358979323846
const ll MOD = 1e9 + 7;

void solve() {
	ll n; cin >> n;
	vi dp(3), points(3);

	for ( int day = 0; day < n; day++) {
		for ( int i = 0; i < 3; i++) cin >> points[i];
		vi new_dp(3);
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if ( i != j) {
					new_dp[i] = max(new_dp[i], dp[j] + points[i]);
				}
			}
		}
		dp = new_dp;
	}

	cout << max( { dp[0], dp[1], dp[2]});
}


int main() {

	int t = 1;

	//cin >> t;
	ll k = 1;
	while (t--) {
		//cout << "Case #" << k++ << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 3592
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
int N,Q;
string S;
vector<set<int>>pls;

void solve(){
	pls.assign(26,set<int>({INF}));
	for(int i=0;i<N;i++){
		pls[S[i]-'a'].insert(i);
	}
	while(Q--){
		int type;cin>>type;
		if(type==1){
			int ind;char nc;cin>>ind>>nc;ind--;
			auto pc=S[ind];
			S[ind]=nc;
			pls[pc-'a'].erase(ind);
			pls[nc-'a'].insert(ind);
		}
		else{
			int l,r;cin>>l>>r;l--;
			int res=0;
			for(int c=0;c<26;c++){
				if(pls[c].empty())continue;
				int lid=*pls[c].lower_bound(l);
				int rid=*pls[c].lower_bound(r);
				if(rid>lid)res++;
			}
			cout<<res<<endl;
		}
	}
}
//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin >> N >> S >> Q;
    solve();
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 24220
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll N,i;
    cin>>N>>i;
    cout<<(N-i+1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define st first
#define nd second

const int N = 1e5+5;

int n, m, a, b;

vector <int> v[N];
bool vis[N];
int p[N];

int dp(int wai){
    if(p[wai] != -1) return p[wai];
    vis[wai] = 1;
    int maks = 0;
    if(v[wai].size() == 0) return 0;
    for (int i = 0; i < v[wai].size(); i++){
        maks = max(maks, dp(v[wai][i]));
    }
    p[wai] = maks+1;
    return p[wai];
}

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin >> n >> m;
    memset(p, -1, sizeof(p));
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        v[a].pb(b);
    }
    for (int i = 1; i <= n; i++){
        if(vis[i] == 0)
            dp(i);
    }
    int maks = 0;
    for (int i = 1; i <= n; i++){
        maks = max(maks, p[i]);
    }
    cout << maks << endl;
}

Measured memory_bytes: 11868
import copy
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j][1] <= x[1]:
            i = i + 1
            a[i], a[j] = a[j], a[i]
    a[i + 1], a[r] = a[r], a[i + 1]
    return(i + 1)

def quick_sort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        quick_sort(a, p, q - 1)
        quick_sort(a, q + 1, r)



n = int(input())
a = []
for i in range(n):
    a.append(list(input().split()))
    a[i][1] = int(a[i][1])
b = copy.deepcopy(a)

quick_sort(a, 0, n - 1)

for i in range(n - 1):
    if a[i][1] == a[i + 1][1]:
        if b.index(a[i]) > b.index(a[i + 1]):
            print("Not stable")
            break
else:
    print("Stable")

for i in a:
    print(" ".join(map(str, i)))


Measured memory_bytes: 41796
s = int(input())
l = len(str(s))

ans = 0

for i in range(2**(l-1)):
    su = str(s)[0]
    for j in range(l-1):
        if i & (1<<j) > 0:
            ans += int(su)
            su = str(s)[j+1]
        else:
            su += str(s)[j+1]
    ans += int(su)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 069d
int main(){
    int h, w, n;
    cin >> h >> w >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    // 一筆書き
    vector<vector<int>> s(h, vector<int>(w));
    int hh = 0, ww = 0;
    rep(i, n)rep(j, a[i]){
        s[hh][ww] = i+1;
        ww++;
        if(ww == w){
            ww = 0;
            hh++;
        }
    }

    rep(i, h){
        if (i%2==0){
            rep(j, w) cout << s[i][j] << ' ';
        }else{
            for(int j=w-1; j>=0; j--) cout << s[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>

using namespace std;

int main(){
  string S;
  cin >> S;
  sort(S.begin(),S.end());
  if(S=="abc")  cout << "Yes" << endl;
  else  cout << "No" << endl;
  
  return 0;
}


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

const int N = 1e5+10;
int a[N];

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int cnt=0;
	a[n] = a[0]-1;
	for(int i=0;i<n;i++)
		if(a[i] != a[i+1])
			cnt++;
		else
			i++;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    int b[20];
    rep(i, m){
        cin >> b[i];
    }
    int a[20][20];
    rep(i, n){
        rep(j, m){
            cin >> a[i][j];
        }
    }

    int res;
    int ans = 0;
    rep(i, n){
        res = 0;
        rep(j, m){
            res += b[j] * a[i][j];
        }
        if(c + res > 0){
            ans++;
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter, deque

INF = float('inf')


def abs_score(a, b):
    return abs(a - b)


def main():
    N, K = map(int, input().split())

    if N < K:
        sa = abs(N - K)
        print(min(N, sa))
        exit()

    if N % K == 0:
        a = N // K
    else:
        a = N // K + 1

    print(abs(N - a * K))


if __name__ == '__main__':
    main()


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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

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

    cout << N*N*N << endl;
}


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

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

    int K, A, B;
    cin >> K >> A >> B;

    for(int i = 0; i <= 1000; i++) {
        if(A <= K * i && K * i <= B) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n;
	cin>>n;
	int sum;
	sum=n-(n/500)*500;
	cout<<n/500*1000+sum/5*5;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 20000000
using namespace std;
typedef long long ll;
bool used[N];

ll SumD(ll a,ll d,ll n){return (n*(2*a+(n-1)*d))/2;}

bool mark(ll n){
  bool res=1;
  for(ll i=1;i*i<=n;i++){
    if(n%i)continue;
    if(i<N)res&=!used[i],used[i]=1;
    if(i!=n/i&&n/i<N)res&=!used[n/i],used[n/i]=1;
  }
  return res;
}

int main(){
  while(1){
    ll n,m,p[21];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<m;i++)cin>>p[i];
    sort(p,p+m);
  
    ll sum=0,cnt=0;
    for(int i=0;i<m;i++){
      sum+=SumD(p[i],p[i],n/p[i]);
      cnt+=n/p[i];
      memset(used,0,sizeof(used));
      for(int j=0;j<i;j++){
	ll gcd=__gcd(p[i],p[j]);
	ll lcm=(p[i]/gcd)*p[j];
	if(!mark(lcm))continue;
	sum-=SumD(lcm,lcm,n/lcm);
	cnt-=n/lcm;
      }
    }
    double ans=1.0*(SumD(1,1,n)-sum)/max(1LL,(n-cnt));
    if(p[0]==1)ans=0;
    printf("%.8f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 22748
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(D)]

last=[0]*26


for d in range(1,D+1):
    ans=[]
    for choice in range(1,27):
        ans_tmp=0
        ans_tmp+=s[d-1][choice-1]
        for i in range(26):
            if i+1==choice:
                continue
            ans_tmp-=c[i]*(d-last[i])
        ans.append((ans_tmp,choice))
    _,case=max(ans)
    last[case-1]=d
    print(case)



Measured memory_bytes: 9288
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   string s,t;
   cin>>s>>t;
   if(s[0]==t[2] && s[1]==t[1] && s[2]==t[0])cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
}

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

int f1(string s1) {
    int m = s1.size();
    if(m<1) return 0;
    int h = stoi(s1.substr(0,1));
    return 9*(m-1) + h;
}

int f2(string s2) {
    int m = s2.size();
    if(m<2) return 0;
    int ret = 0;
    if(m>=3) ret += (m-1)*(m-2)/2*9*9;
    int h = stoi(s2.substr(0,1));
    ret += (h-1)*9*(m-1);
    rep2(i,1,m) {
        if(s2[i] != '0') {
            ret += f1(s2.substr(i));
            break;
        }
    }
    return ret;
}

int f3(string s3) {
    int m = s3.size();
    if(m<3) return 0;
    int ret = 0;
    if(m>=4) ret += (m-1)*(m-2)*(m-3)/3/2*9*9*9;
    int h = stoi(s3.substr(0,1));
    ret += (h-1)*(m-1)*(m-2)/2*9*9;
    rep2(i,1,m) {
        if(s3[i] != '0') {
            ret += f2(s3.substr(i));
            break;
        }
    }
    return ret;
}

int main()
{
    string s;
    int k;
    cin >> s >> k;

    int ans = 0;
    if(k==1) ans = f1(s);
    else if(k==2) ans = f2(s);
    else ans = f3(s);

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

Measured memory_bytes: 256
n = int(input())
s = input()

to_int = {"R":0, "G":1, "B":2}
cnt = [0] * 3
for char in s:
    cnt[to_int[char]] += 1

ans = 1
for num in cnt:
    ans *= num

for i in range(n):
    for length in range(1, n):
        if i - length < 0 or i + length >= n:
            break
        if len(set([to_int[s[i - j * length]] for j in (-1, 0, 1)])) == 3:
            ans -= 1

print(ans)



Measured memory_bytes: 73972
// Problem : E - This Message Will Self-Destruct in 5s
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		int arr[n+1];
		for(int i=1;i<=n;++i)
		cin>>arr[i];
		map<int,int> mpadd,mpsub;
		for(int i=1;i<=n;++i)
		{
			mpsub[i-arr[i]]++;
			mpadd[i+arr[i]]++;
		}
		int ans = 0;
		for(auto x:mpsub)
		{
			ans+= (mpsub[x.first]*mpadd[x.first]);
		}
		cout<<ans;    	
    }
    return 0;
}



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

using namespace std;

const int N = 1e4 + 5, mod = 1e9 + 7;
string s;
int d, dp[N][101][2];

int solve (int pos, int rem, bool smaller) {
    if (pos == s.size() ) return (!rem);
    int &ret = dp[pos][rem][smaller];
    if (ret != -1) return ret;
    ret = 0;
    int lim = 9;
    if (!smaller) lim = s[pos] - '0';
    for (int i = 0; i <= lim; ++i) ret = (ret + solve(pos + 1, (rem + i) % d, max(smaller, (i < lim) ) ) ) % mod;
    return ret;
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> d;

    memset(dp, -1, sizeof dp);
    cout << (solve(0, 0, 0) + mod - 1) % mod;

    return 0;
}


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

int h,n;
int main(){
    cin >> h >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++) cin >> vec[i];
    int sum = 0;
    for(int i=0;i<n;i++) sum += vec[i];

    if(sum>=h) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	string s;
	cin >> s;
	string beg = "";
	string end = "";
	int q;
	cin >> q;
	bool reversed = 0;
	while(q--){
		int t;
		cin >> t;
		if(t == 1) reversed ^= 1;
		else{
			int f;
			char c;
			cin >> f >> c;
			if(f == 1){
				if(!reversed) beg += c;
				else end += c;
			}
			else{
				if(reversed) beg += c;
				else end += c;
			}
		}
	}
	reverse(all(beg));
	s = beg + s + end;
	if(reversed) reverse(all(s));
	cout << s;
	

}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 1200
import sys
import collections

while True:
    pc, student = map(int, sys.stdin.readline().split())
    if pc == student == 0:
        break
    
    record = collections.defaultdict(list)
    r = int(raw_input())
    for i in xrange(r):
        t, n, m, s = map(int, sys.stdin.readline().split())
        record[m].append((t, n, s))
    q = int(raw_input())
    for i in xrange(q):
        start, end, q_student = map(int, sys.stdin.readline().split())
        temp_start = start
        time = 0
        f_open = set()
        for i_t, i_n, i_s in record[q_student]:
            if start <= i_t <= end:
                if i_s == 1:
                    if len(f_open) == 0:
                        temp_start = i_t
                    f_open.add(i_n)
                else:
                    f_open.remove(i_n)
                    if len(f_open) == 0:
                        time += i_t - temp_start
                        temp_start = -1
            elif i_t < start:
                if i_s == 1:
                    f_open.add(i_n)
                else:
                    f_open.remove(i_n)
        if len(f_open) > 0:
            time += end - temp_start
        print time

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

ll comb(ll x) {
  ll y = x*(x-1)/2;
  return y;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  map<int, P> mp;
  REP(i, n) mp[a[i]].first++;
  ll sum = 0;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
    itr->second.second = comb(itr->second.first);
    sum += itr->second.second;
  }
  REP(i, n) {
    ll ans = sum - mp[a[i]].second + comb(mp[a[i]].first-1);
    printf("%lld\n", ans);
  }

  return 0;
}

Measured memory_bytes: 10240
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,m=n1()

if n==m:
    ans=math.factorial(n)*math.factorial(m)*2
elif abs(n-m)==1:
    ans=math.factorial(n)*math.factorial(m)
else:
    ans=0
print(ans%(10**9+7))

Measured memory_bytes: 5224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] ints = new int[n];
    boolean bl = true;
    for(int i = 0; i < n; i++){
      ints[i] = sc.nextInt();
      bl &= ((ints[i] % 2 == 1) || (ints[i] % 3 == 0 || ints[i] % 5 == 0));
    }
    if(bl){
      System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");
    }
    
  }
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false; //閉路検出
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >>n >>m >>k;
	
	vector<VI> r2(n);
	UF ufa(n);
	VI ct(n);
	rep(i, m){
		int a,b;
		cin >>a >>b;
		a--; b--;
		ufa.unite(a, b);
		ct[a]++; ct[b]++;
	}
	rep(i, k){
		int a,b;
		cin >>a >>b;
		a--; b--;
		r2[a].push_back(b);
		r2[b].push_back(a);
	}

	rep(i, n){
		int ans = ufa.size(i) - ct[i] -1;
		for(auto z: r2[i]) if(ufa.same(i, z) ) ans--;
		cout << ans <<" ";
	}
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>

int main()
{
  
  while(1){
    int now[21][21] = {0};
    int x, y, n, jewelry, i, j, cnt = 0, nowx = 10, nowy = 10;
    char derection, dummy;

    scanf("%d", &jewelry);
    if(jewelry == 0) break;

    for(i = 0; i < jewelry; i++){
      scanf("%d%d", &x, &y);
      now[x][y] = 1;
  
    }

    scanf("%d", &n);
    for(i = 0; i < n; i++){
      scanf("%c", &dummy);
      scanf("%c %d", &derection, &x);

      for(j = 0; j < x; j++){
    	switch(derection){
      
    	case 'N':
    	  nowy++;
    	  break;

    	case 'S':
    	  nowy--;
    	  break;

    	case 'W':
    	  nowx--;
    	  break;

    	case 'E':
    	  nowx++;
    	  break;
      
    	}

	if(now[nowx][nowy]){
	  cnt++;
	  now[nowx][nowy] = 0;
	}	
      }
    }
    
    if(cnt == jewelry) printf("Yes\n");
    else printf("No\n");

  }
  
  return 0;
  
  
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
vector<int>vb;
bool prime[10000001]={true};
void Seive(int n)
{
    memset(prime, true, sizeof(prime)); 
    for(int i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
        for(int j=i*i;j<=n;j+=i)
        prime[j]=false;
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(prime[i]==true)
        vb.push_back(i);
    }
}
int bs(int e)
{
    int lo = 0, hi = vb.size() - 1;
        while (hi > lo) {
            int mid = (lo + hi) / 2;
            if (vb[mid] >= e) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        return hi;
}

int main()
{
    Imposter
    
    Seive(1e7);
    //for(int i=0;i<vb.size();i++)
    //cout<<vb[i]<<" ";
    
    int x;
    cin>>x;
    cout<<vb[bs(x)]<<endl;
    
}


Measured memory_bytes: 17156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n,m;
ll memo[22222],a[22222],k;
bool done[22222];

ll solve(int i = 0){
	int j;
	ll mx,mn;
	if(done[i]){
		return memo[i];
	}
	done[i] = true;
	if(i == n){
		memo[i] = 0ll;
		return 0ll;
	}
	memo[i] = solve(i+1)+k;
	mx = a[i];
	mn = a[i];
	for(j=2; j<=m; ++j){
		if(i+j>n){
			break;
		}
		mx = max(mx,a[i+j-1]);
		mn = min(mn,a[i+j-1]);
		memo[i] = min(memo[i],solve(i+j)+k+(mx-mn)*j);
	}
	return memo[i];
}

int main(void){
	int i;
	fill(done,done+22222,false);
	cin >> n >> m >> k;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	cout << solve() << endl;
	return 0;
}



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

#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N, M;
int a[100001];
int lav[100001];
vector<int> graph[100001];
unordered_map<int, int> used[100001];

void dfs(int n, int c) {
    if ( lav[n] ) return;
    lav[n] = c;

    Rep(i, graph[n].size()) {
        dfs(graph[n][i], c);
    }
}

signed main() {
    cin >> N >> M;

    Rep(i, N) cin >> a[i];

    Rep(i, M) {
        int x, y;
        cin >> x >> y;
        graph[x].pb(y);
        graph[y].pb(x);
    }

    int now = 1;
    Rep(i, N) {
        if ( lav[i] ) continue;
        else {
            dfs(i, now);
            now++;
        }
    }
    now-=1;
    //Rep(i, N) cout << lav[i] << " ";
    //cout << endl;
    if ( now == 1 ) {
        cout << 0 << endl;
        return 0;
    }

    if ( (now-1)*2 > N ) {
        cout << "Impossible" << endl;
        return 0;
    }

    Pii mi[100001];
    Rep(i, 100001) mi[i] = Pii(INF, INF);
    Rep(i, N) {
        mi[lav[i]] = min(mi[lav[i]], Pii(a[i], i));
    }

    int ans = 0;
    for ( int i = 1; i <= now; i++ ) {
        ans += mi[i].fr;
        a[mi[i].sc] = -1;
    }

    vector<int> v;
    Rep(i, N) if ( a[i] != -1 ) v.pb(a[i]);

    sort(All(v));

    for ( int i = 0; i < (now-1)*2-now; i++ ) {
        ans += v[i];
    }

    cout << ans << endl;

}


Measured memory_bytes: 15996