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

struct Log{
  int t;
  int n;
  int m;
  int s;
};

struct Query{
  int ts;
  int te;
  int m;
};


void displayLog(vector<Log> L, int r){
  for(int i = 0; i < r; i++){
	cout << L[i].t << " " << L[i].n << " " << L[i].m << " " << L[i].s << endl;
  }
  cout << endl;
}

void displayQuery(vector<Query> Q, int q){
  for(int i = 0; i < q; i++){
	cout << Q[i].ts << " " << Q[i].te << " " << Q[i].m << endl;
  }
  cout << endl;
}

template <typename T> void displayTmp(T tmp_time, int M){
  
  for(int i = 0; i < M; i++){
	cout << "tmp_time[" << i << "] = ";
	cout << tmp_time[i].first << " " << tmp_time[i].second << endl; 
  }
  cout << endl;
}

void displayLogin_t(vector<vector<P> > login_t, int M){
  for(int i = 0; i < M; i++){
	cout << "login_t[" << i << "] = ";
	for(int j = 0; j < login_t[i].size(); j++){
	  cout << " ( " << login_t[i][j].first << ", " << login_t[i][j].second << " )";
	}
	cout << endl;
  }
  cout << endl;
}


int main(){
  int N, M, r, q;
  while(1){
    cin >> N >> M;
    if(N == 0 && M == 0) break;

	cin >> r;
    vector<Log> L;

	for(int i = 0; i < r; i++){
	  Log tmp;
	  cin >> tmp.t >> tmp.n >> tmp.m >> tmp.s;
	  L.push_back(tmp);
    }
	
    cin >> q;
    vector<Query> Q;

	for(int i = 0; i < q; i++){
	  Query tmp;
	  cin >> tmp.ts >> tmp.te >> tmp.m;
	  Q.push_back(tmp);
    }

	vector<int> student(M, 0);
	vector<vector<P> > login_t(M);
	vector<P> tmp_time(M, P(0, 0));
	
	for(int i = 0; i < r; i++){
	  if(L[i].s == 1){
		if(student[L[i].m - 1] == 0){
		  student[L[i].m - 1]++;
		  tmp_time[L[i].m - 1].first = L[i].t;
 		}
		else{
		  student[L[i].m - 1]++;
		}
	  }
	  else{
		if(student[L[i].m - 1] == 1){
		  student[L[i].m - 1]--;
		  tmp_time[L[i].m - 1].second = L[i].t;
		  login_t[L[i].m - 1].push_back(tmp_time[L[i].m - 1]);
		}
		else{
		  student[L[i].m - 1]--;
		}
	  }
	}

	for(int i = 0; i < q; i++){
	  int qs = Q[i].ts;
	  int qe = Q[i].te;
	  int id = Q[i].m - 1;
	  int ans = 0;
	  
	  for(int j = 0; j < login_t[id].size(); j++){
		int ls = login_t[id][j].first;
		int le = login_t[id][j].second;
		if(qs < ls && ls <= qe && qe <= le){
		  ans += qe - ls;
		}
		else if(ls < qs && qe < le){
		  ans += qe - qs;
		}
		else if(ls <= qs && qs < le && le < qe){
		  ans += le - qs;
		}
		else if(qs <= ls && le <= qe){
		  ans += le - ls;
		}
	  }
	  cout << ans << endl;
	}
  }
  return 0;
}

Measured memory_bytes: 3276
while True:
    m, f, r = map(int, input().split())
    if m != -1 or f != -1 or r != -1:
        x = max(0, m) + max(0, f)
        if m == -1 or f == -1:
            grade = 'F'
        elif 80 <= x:
            grade = 'A'
        elif 65 <= x and x < 80:
            grade = 'B'
        elif 50 <= x and x < 65:
            grade = 'C'
        elif 30 <= x and x < 50:
            if 50 <= r:
                grade = 'C'
            else:
                grade = 'D'
        else:
            grade = 'F'
        print(grade)
    else:
        break


Measured memory_bytes: 5592
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {

        try (final Scanner sc = new Scanner(System.in)) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int T = sc.nextInt();
            int sumB = 0;
            for (int t = A; t <= 20; t += A) {
                if (t <= T) {
                    sumB += B;
                }
            }
            System.out.println(sumB);
        }
    }
}


Measured memory_bytes: 24148
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s = itr.next().unwrap();
    let n = s.len();
    let s = s[..n - 8].to_string();
    println!("{}", s);
}


Measured memory_bytes: 2068
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(void){
  int N;
  cin >> N;
  int T[N];
  rep(i, N)
    cin >> T[i];
  int M;
  cin >> M;
  int P[M], X[M];
  rep(i, M)
    cin >> P[i] >> X[i];
  //入力終了

  //ドリンクP, Xをなめる
  rep(i, M){
    int ans = 0;
    //時間Tをなめる
    rep(j, N){
      //問題番号と，ドリンクが適用される問題番号が一致
      if(j == P[i]-1)
	ans += X[i];
      else
	ans += T[j];
    }
    //解答
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
class Fixnum
def-@
1-self
end
alias:+:|
def>x
-self|x
end
end
T=1
F=0
until(s=gets.sub(?=,'==').gsub('->',?>))<?(
v=s.scan(/[a-z]/).uniq
puts %w(T F).repeated_permutation(v.size).all?{|a|
eval s.tr(v*'',a*'')
}?'YES':'NO'
end

Measured memory_bytes: 11300
#include <stdio.h>

int main(void) {
  int A;
  int B;
  int C;
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);

  if (A == B || B == C || C == A) {
    if (A != B || B != C || C != A) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1580
use strict;
use warnings;

main();

sub main{
	my $input = <stdin>;
	chomp($input);

	while(1){
		my $len = length($input);
		# printf("%d : %s\n", $len, $input);

		if(rindex($input,'dreamer') == $len-7){
			$input = substr($input, 0, -7);
		}
		elsif(rindex($input,'dream') == $len-5){
			$input = substr($input, 0, -5);
		}
		elsif(rindex($input,'eraser') == $len-6){
			$input = substr($input, 0, -6);
		}
		elsif(rindex($input,'erase') == $len-5){
			$input = substr($input, 0, -5);
		}
		else{
			print "NO\n";
			return;
		}

		if(length($input) == 0){
			print "YES\n";
			return;
		}
	}
}
1;

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

class Main {

	void solve() {

		out.println(Math.max(inint()*inint(), inint()*inint()));

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

	public char[][] incharmap(int h, int w) {
		char[][] a = new char[h][w];
		for (int i=0; i<h; i++) {
			String temp = in.next();
			for (int j=0; j<w; j++) {
				a[i][j] = temp.charAt(j);
			}
		}
		return a;
	}

}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define alll(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define endl '\n'

vector<int> v{0,111,222,333,444,555,666,777,888,999};
int main()
{
    int n;
    cin>>n;
    while(find(all(v),n) == v.end()) ++n;
    cout<<n<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	ll a[3*n+1];
	ll res[3*n+1];
	ll res1[3*n+1];
	for(int i=1;i<=3*n;i++)
	{
		cin>>a[i];
	}
	multiset<ll> s1;
	ll min1=10000000000,sum1=0;
	for(int i=1;i<=n;i++)
	{
		min1=min(min1,a[i]);
		sum1+=a[i];
		s1.insert(a[i]);
	}
	ll sum2=0,max2=0;
	multiset<ll> s2;
	for(int i=3*n;i>2*n;i--)
	{
		sum2+=a[i];
		max2=max(max2,a[i]);
		s2.insert(a[i]);
	}
	res[n]=sum1;
	for(int i=n+1;i<=2*n;i++)
	{
		if(a[i]>=min1)
		{
			sum1+=a[i];
			sum1-=min1;
			s1.erase(s1.find(min1));
			s1.insert(a[i]);
			min1=(*s1.begin());
			res[i]=sum1;
		}
		else
		{
			res[i]=sum1;
		}
	}
	res1[2*n+1]=sum2;
	for(int i=2*n;i>=n+1;i--)
	{
		if(a[i]<=max2)
		{
			sum2-=max2;
			sum2+=a[i];
			s2.erase(s2.find(max2));
			s2.insert(a[i]);
			multiset<ll>::iterator it1=s2.end();
			it1--;
			max2=(*it1);
			res1[i]=sum2;
		}
		else
		{
			res1[i]=sum2;
		}
	}
	ll fans=-10000000000000000;
	for(int i=n;i<=2*n;i++)
	{
		//cout<<res[i]<<" "<<res1[i+1]<<"\n";
		fans=max(fans,res[i]-res1[i+1]);
	}
	cout<<fans<<"\n";
}

Measured memory_bytes: 16640
from operator import mul
from functools import reduce

n, p = map(int, input().split())

a_list = list(map(int, input().split()))

a_0 = []
a_1 = []
for j in a_list:
    if j % 2 == 0:
        a_0.append(j)
    else:
        a_1.append(j)

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


if p == 0:
    ans = 1

    tmp_2 = 0
    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            tmp_2 += combinations_count(len(a_0), i)
    #print(tmp_2)
    ans += tmp_2
    
    tmp_1 = 0
    if len(a_1) > 2:
        for i in range(2,len(a_1)+1, 2):
            #print(i)
            tmp_1 += combinations_count(len(a_1), i)
    elif len(a_1) == 2:
        tmp_1 += 1
    ans += tmp_1
    #print(tmp_1)

    ans += tmp_1*tmp_2


elif p == 1:
    ans = 0

    tmp_2 = 1
    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            tmp_2 += combinations_count(len(a_0), i)
    #print(tmp_2)

    if len(a_1) >= 1:
        for i in range(1,len(a_1)+1, 2):
            #print(i)
            tmp = combinations_count(len(a_1), i)
            ans += tmp*tmp_2

print(ans)


Measured memory_bytes: 3572
#include <iostream>
using namespace std;
const int mod = 1000000007;
//B
template <int mod>
struct ModInt{
  int n;
  ModInt():n(0){}
  ModInt(int n_):n(n_ >= 0 ? n_%mod : mod - ((-n_)%mod) ){}

  ModInt &operator+=(const ModInt &p){
    if((n+=p.n) >= mod)n-=mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p){
    n+=mod-p.n;
    if(n >= mod)n-=mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p){
    n = (int) ((1LL*n*p.n)%mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p){
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const {return ModInt(-n);}
  ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
  ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
  ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
  ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

  bool operator==(const ModInt &p) const {return n==p.n;}
  bool operator!=(const ModInt &p) const {return n!=p.n;}

  ModInt inverse() const {
    int a = n,b = mod,u = 1,v = 0;
    while(b){
      int t = a/b;
      a -= t*b; swap(a,b);
      u -= t*v; swap(u,v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t z) const {
    ModInt ret(1),mul(n);
    while(z > 0){
      if(z & 1) ret *= mul;
      mul *= mul;
      z >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p){
    return os << p.n;
  }
  friend istream &operator>>(istream &is, ModInt &a){
    int64_t t;
    is >> t;
    a = ModInt<mod> (t);
    return (is);

  }
};
using modint = ModInt<mod>;
//E
int main(){
  int n,a,b;cin>>n>>a>>b;
  modint z = 2;
  z = z.pow(n)-1;
  modint tmp = 1;
  for(int i = 1; a >= i; i++){
    tmp *= (n-a+i);
    tmp /= i;
  }
  z -= tmp;
  tmp = 1;
  for(int i = 1; b >= i; i++){
    tmp *= (n-b+i);
    tmp /= i;
  }
  cout << z-tmp << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int m = in.nextInt();
		int d = in.nextInt();

		int ans = 0;
		for ( int month = 1; month <= m; month++ ) {
			for ( int day = 2; day <= d; day++ ) {
				int d10 = day / 10 != 0 ? day / 10 : 1;
				int d1 = day % 10;

				if ( d10 == 1 || d1 == 1 ) continue;
				else if ( month == d10 * d1 ) ans++;
			}
		}
		System.out.println(ans);
		in.close();
	}
}


Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

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

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

    int res[n];
    int tmp = 0;
    for( int i = n - 1; i >= 0; --i ) {
        if( ( i + 1 ) % 2 ) tmp += a[i];
        else tmp -= a[i];

    }

    res[0] = tmp / 2;
    a[0] -= res[0];
    for( int i = 1; i < n; ++i ) {
        res[i] = a[i - 1] * 2;
        a[i - 1] = 0;
        a[i] -= res[i] / 2;

    }

    cout << res[0] * 2;
    for( int i = 1; i < n; ++i ) cout << " " << res[i];
    cout << endl;
    return 0;

}



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

using namespace std;

using ll = long long;

int n;
int cnt[4];
double dp[305][305][305];

double solve(int c1, int c2, int c3) {
	double& res = dp[c1][c2][c3];
	if (res >= 0) return res;

	int sum = c1 + c2 + c3;
	res = 0;
	if (sum == 0) return res;

	res = (double)n / sum;
	if (c1) res += solve(c1 - 1, c2, c3) * c1 / sum;
	if (c2) res += solve(c1 + 1, c2 - 1, c3) * c2 / sum;
	if (c3) res += solve(c1, c2 + 1, c3 - 1) * c3 / sum;
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		cnt[a]++;
	}

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				dp[i][j][k] = -1;
			}
		}
	}

	cout << fixed << setprecision(15) << solve(cnt[1], cnt[2], cnt[3]) << endl;
	return 0;
}

Measured memory_bytes: 219520
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
ll gcd(ll a, ll b) {
	if (b == 0LL) return a;
	return gcd(b, a % b);
}

int main()
{
	int i, j;
	ll x;
	scanf("%lld", &x);
	int tot = 0;
	for (ll d = 2; d * d <= x; ++d) {
		if (x % d == 0) {
			int cnt = 0;
			while (x % d == 0) {
				x /= d;
				++cnt;
			}
			int k = 1;
			int num = 0;
			while (cnt >= k) {
				cnt -= k;
				++k;
				++num;
			}
			tot += num;
		}
	}
	if (x != 1) ++tot;
	printf("%d", tot);
}

Measured memory_bytes: 3824
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);

  int array[n];

  for(int i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }

  for(int i = n - 1; i >= 0; i--) {
    printf("%d", array[i]);
    if(i != 0) printf(" ");
  }
  printf("\n");
}



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

int main(){
  long long int x;
  long long int i=0;
  long long int ans;
  cin>>x;
  ans = x/11*2;
  x=x%11;
  if(x/6!=0)ans+=2;
  if(x/6==0)ans+=1;
  if(x%6==0)ans-=1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;


int main(void){
    double w, h, x, y;
    double min_area=0.0;
    cin >> w >> h >> x >> y;
    min_area = w*h/2;
    if(x*2==w && y*2 == h){
        cout << min_area << " " << 1 << endl;
    }else{
        cout << min_area << " " << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from scipy.sparse import*
e=enumerate
h,*s=open(0)
h,w=map(int,h.split())
r,c=[],[]
for i,t in e(s):
  for j,u in e(t):
    if u>'#'<t[j+1]:r+=i*w+j,;c+=i*w+j+1,
    if(i<h-1)*u>'#'<s[i+1][j]:r+=i*w+j,;c+=j-~i*w,    
a=csgraph.johnson(csr_matrix(([1]*len(r),(r,c)),[h*w]*2),0)
print(int(a[a<999].max()))

Measured memory_bytes: 16312
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    
    int n,c; cin>>n>>c;
    
    vector<int> x(n+1),cx(n+1),v(n+1);
    x.front()=v.front()=cx.front()=0;
    rep(i,n)cin>>x.at(i+1)>>v.at(i+1);
    rep(i,n)cx.at(i+1)=c-x.at(n-i);
    
    vector<int> clo(n+1),cclo(n+1);
    clo.front()=cclo.front()=0;
    
    rep(i,n){
        clo.at(i+1)=clo.at(i)+v.at(i+1)-abs(x.at(i+1)-x.at(i));
    }
    
    rep(i,n){
        cclo.at(i+1)=cclo.at(i)+v.at(n-i)-abs(cx.at(i+1)-cx.at(i));
    }
    
    vector<int> clo_max(n+1),cclo_max(n+1);
    clo_max.front()=cclo_max.front()=0;
    rep(i,n){
        clo_max.at(i+1)=max<int>(clo.at(i+1),clo_max.at(i));
        cclo_max.at(i+1)=max<int>(cclo.at(i+1),cclo_max.at(i));
    }
    
    int ans=0;
    rep(i,n+1){
        //時計回りに最初行って、どこかで折り返す
        chmax(ans, clo.at(i)-x.at(i)+cclo_max.at(n-i));
    }
    rep(i,n+1){
        //反時計回りに最初行って、どこかで折り返す
        chmax(ans, cclo.at(i)-cx.at(i)+clo_max.at(n-i));
    }
    
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;


ll llmin(ll x, ll y){
	if (x < y) return x;
	return y;
}

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

char rev(char c){
	if (c == 'S') return 'W';
	return 'S';
}

int n;
string s;

bool check1(string ans){
	if (ans[n-1] == 'S'){
		if (s[n-1] == 'o'){
			if (ans[0] == ans[n-2]){
				return true;
			}
		}
		if (s[n-1] == 'x'){
			if (ans[0] != ans[n-2]){
				return true;
			}
		}
	}
	if (ans[n-1] == 'W'){
		if (s[n-1] == 'o'){
			if (ans[0] != ans[n-2]){
				return true;
			}
		}
		if (s[n-1] == 'x'){
			if (ans[0] == ans[n-2]){
				return true;
			}
		}			
	}
	return false;
}

bool check2(string ans){
	if (ans[0] == 'S'){
		if (s[0] == 'o'){
			if (ans[1] == ans[n-1]){
				return true;
			}
		}
		if (s[0] == 'x'){
			if (ans[1] != ans[n-1]){
				return true;
			}
		}
	}
	if (ans[0] == 'W'){
		if (s[0] == 'o'){
			if (ans[1] != ans[n-1]){
				return true;
			}
		}
		if (s[0] == 'x'){
			if (ans[1] == ans[n-1]){
				return true;
			}
		}			
	}
	return false;
}

int main(){

	cin >> n >> s;
	string a[4] = {"SS", "SW", "WS", "WW"};

	for (int i = 0; i < 4; i++){
		string ans = a[i];
		for (int j = 2; j < n; j++){
			if (ans[j-1] == 'S'){
				if (s[j-1] == 'o'){
					ans.push_back(ans[j-2]);
				}
				if (s[j-1] == 'x'){
					ans.push_back(rev(ans[j-2]));
				}
			}
			if (ans[j-1] == 'W'){
				if (s[j-1] == 'o'){
					ans.push_back(rev(ans[j-2]));
				}
				if (s[j-1] == 'x'){
					ans.push_back(ans[j-2]);
				}
			}
		}
		if (check1(ans) && check2(ans)){
			cout << ans << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3808
#include<iostream>
#include <vector>
#include <cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<math.h>
#define ll long long int
using namespace std;


int main()
{
 string a,b;
 cin>>a>>b;
 ll aa,bb;
 //cout<<1;
 aa=a.size();
 bb=b.size();
// cout<<2;
 vector <vector <ll>> arr(aa+1,vector <ll> (bb+1,0));
 for(ll i=0;i<=aa;i++)
 {
     for(ll j=0;j<=bb;j++)
     {
         if(i==0 || j==0)
         {
             arr[i][j]=0;
           //  cout<<arr[i][j]<<" ";
             continue;
         }
         
         if(a[i-1]==b[j-1])
         arr[i][j]=max(arr[i-1][j-1]+1,max(arr[i-1][j],arr[i][j-1]));
         else
         arr[i][j]=max(arr[i-1][j-1],max(arr[i-1][j],arr[i][j-1]));
      //   cout<<arr[i][j]<<" ";


     }
    // cout<<endl;
 }
 if(arr[aa][bb]==0)
 return 0;
 vector <char> ans;
 ll j=bb;
 ll i=aa;
 while(1)
 {
     if(i==0)
     break;
     if(j==0)
     break;
     while(arr[i][j]==arr[i-1][j]  && i!=0)
     i--;
     //cout<<i<<endl;
     ans.push_back(a[i-1]);
     i--;
     //cout<<a[i]<<endl;
     if(i==0)
     break;
     if(j==0)
     break;
     while(arr[i][j]==arr[i][j-1]  && j>=1)
     j--;
    // cout<<" hello :"<<j<<endl;
    //cout<<"check i "<<i<<endl;
     if(i==0)
     break;
     if(j==0)
     break;


 }
 for(ll l=ans.size()-1;l>=0;l--)
 cout<<ans[l];
 //cin>>a;
    return 0;

   

}

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

void swap(int *a,int *b){
	int *n=a;
	a=b;
	b=n;
}

int SelectionSort(int a[],int n){
	int sum=0;
	int min;
	for(int i=0;i<n;i++){
		min=i;
		for(int j=i;j<n;j++){
			if(a[j]<a[min]){
				min=j;
			}
		} 
		if(a[i]!=a[min]){
			swap(a[i],a[min]);
			sum++;
		}
	}
	return sum;
}



int main(){
	int n;
	cin>>n;
	int a[100];
	for(int i=0;i<n;i++)cin>>a[i];
	
	int x=SelectionSort(a,n);
	for(int i=0;i<n;i++){
		if(i>0)cout<<" ";
		cout<<a[i]; 
	}
	cout<<endl<<x<<endl;
} 


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);

int dp[500010]={};//0==lose

signed main(){
    int n;cin>>n;
    ll k;cin>>k;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];

    rep(i,k+1){
        rep(j,n){
            dp[i+a[j]]=max(1-dp[i],dp[i+a[j]]);
        }
    }

    if(dp[k]==1){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
}



Measured memory_bytes: 1024
def resolve():
    s = input()
    for i in range(len(s)):
        if i % 2 == 0:
            if s[i] == "L":
                print("No")
                exit()
        elif i % 2 == 1:
            if s[i] == "R":
                print("No")
                exit()
    print("Yes")
resolve()

Measured memory_bytes: 2940
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    String t = next();
    String[] ss = splitString(t);
    for(int i=0;i<ss.length;i++){
      if(ss[i].equals("?")){
        System.out.print("D");
      }
      else{
        System.out.print(ss[i]);
      }
    }



    //System.out.println();

  }

  static int lcm(int a,int b){
    return a*b*gcd(a,b);
  }

  static int gcd(int a,int b){
    if(a%b!=0){
      return gcd(b,a%b);
    }
    else{
      return b;
    }
  }

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
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; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	cout << setprecision(15);
	double l;
	cin >> l;
	double my_max = (l) / 3;
	l -= my_max;
	// 残り2辺をうまいこと最大化する。また切り上げたものが大きい方
	double next_max = (l) / 2;
	l -= next_max;

	double ans = my_max * next_max * l;
	cout << ans << endl;
}


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

int main() {
  string str;
  cin >> str;
  int Ncnt = 0, Wcnt = 0, Scnt = 0, Ecnt = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == 'N') {
      Ncnt++;
    }
    else if (str[i] == 'W') {
      Wcnt++;
    }
    else if (str[i] == 'S') {
      Scnt++;
    }
    else if (str[i] == 'E') {
      Ecnt++;
    }
  }
  if ((Ncnt > 0 && Scnt > 0 && Wcnt > 0 && Ecnt > 0) ||
      (Ncnt == 0 && Scnt == 0 && Wcnt > 0 && Ecnt > 0) ||
      (Ncnt > 0 && Scnt > 0 && Wcnt == 0 && Ecnt == 0) ||
      (Ncnt == 0 && Scnt == 0 && Wcnt == 0 && Ecnt == 0)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int total_competitions;
  int total_committee;
  while(~scanf("%d %d",
               &total_competitions,
               &total_committee)){
    
    int cost[1001];
    memset(cost,0,sizeof(cost));
    for(int competition_idx=1; competition_idx<=total_competitions; competition_idx++){
      scanf("%d",cost + competition_idx);
    }

    int votes[1001];
    memset(votes,0,sizeof(votes));
    
    int res = 0;
    int max_votes = 0;
    for(int committee_idx = 1; committee_idx <= total_committee; committee_idx++){
      int criteria;
      scanf("%d",&criteria);
      for(int competition_idx=1; competition_idx<=total_competitions; competition_idx++){
        if(cost[competition_idx] <= criteria){
          votes[competition_idx]++;

          if(max_votes < votes[competition_idx]){
            res = competition_idx;
            max_votes = votes[competition_idx];
          }
          break;
        }
      }
    }

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

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

int main() {
  int A,B;
  cin >> A >> B;
  
  int s = 0;
  for (int i = A; i <= B; i++) {
    if (i / 1000 == (i - i / 10 * 10) * 10 + (i / 10 - i / 100 * 10))
      s++;
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#!/usr/bin/perl

my ($a,$b,$k) = map {$_ - 0} split(/\s+/o,<STDIN>);

if( $b - $a <= 2 * $k - 1 ){
  for(my $i=$a;$i<=$b;$i++){
    print "$i\n";
  }
} else {
  for(my $i=$a;$i<$a+$k;$i++){
    print "$i\n";
  }
  for(my $i=$b-$k+1;$i<=$b;$i++){
    print "$i\n";
  }
}

exit(0);


Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int h,w,c,cnt;
int Panel[8][8];
int P[8][8];

void dfs(int y, int x, int color, int precolor){
  if (color==precolor)
    return ;
  P[y][x]=color;
  for (int i=0;i<4;i++){
    int mx=x+dx[i];
    int my=y+dy[i];
    if (0<=mx && mx<w && 0<=my && my<h && P[my][mx]==precolor)
      dfs(my,mx,color,precolor);
  }
}


int panelnum(int y, int x, int color){
  if (P[y][x]==color){
    P[y][x]=0;
    cnt+=1;
  }else
    return cnt;
  for (int i=0;i<4;i++){
    int mx=x+dx[i];
    int my=y+dy[i];
    if (0<=mx && mx<w && 0<=my && my<h && P[my][mx]==color)
      panelnum(my,mx,color);
  }
  return cnt;
}



int main(){
  while (1){
    scanf("%d %d %d",&h,&w,&c);
    if (h==0 && w==0 && c==0)
      return 0;
    for (int i=0;i<h;i++)
      for (int j=0;j<w;j++)
        scanf("%d",&Panel[i][j]);
    int maxInt=0;
    for (int i=1;i<7;i++)
      for (int j=1;j<7;j++)
        for (int k=1;k<7;k++)
          for (int l=1;l<7;l++){
            cnt=0;
            for (int t=0;t<h;t++)
              for (int s=0;s<w;s++)
                P[t][s]=Panel[t][s];
            dfs(0,0,i,P[0][0]);
            dfs(0,0,j,P[0][0]);
            dfs(0,0,k,P[0][0]);
            dfs(0,0,l,P[0][0]);
            dfs(0,0,c,P[0][0]);
            int temp=panelnum(0,0,c);
            maxInt=std::max(maxInt,temp);
          }
    printf("%d\n",maxInt);
  }
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vii = vector<ii>;

const int mod = 1e9+7;
const int oo = 1e9+7;


int main() {
    
    int n, w;
    scanf("%d%d",&n,&w);
    
    vector<ll> dp(1e5+5, oo);
    dp[0] = 0;
    
    for(int i = 0; i < n; ++i) {
        ll wi, vi;
        scanf("%lld%lld",&wi,&vi);
        
        for(int v = 1e5+4; v >= 0; --v) {
            if(v + vi < 1e5+5) {
                dp[v+vi] = min(dp[v+vi], dp[v]+wi);
            }
        }
    }
    
    for(int i = 1e5+4; i >= 0; --i) {
        if(dp[i] <= w) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}




Measured memory_bytes: 1152
N=int(input())
link=[[]for _ in range(N)]
node=[-1]*N
for _ in  range(N-1):
  u,v,w=map(int,input().split())
  w%=2
  link[u-1].append([v-1,w])
  link[v-1].append([u-1,w])
node[0]=0
q=[0]
while q:
  x=q.pop(0)
  for i,j in link[x]:
    if node[i]==-1:
      q.append(i)
      if j==1 :
        node[i]=(node[x]+1)%2
      elif j==0:
        node[i]=node[x]
print(*node,sep='\n')

Measured memory_bytes: 43536
#include<cstdio>
#include<algorithm>
using namespace std;
char p[101000];
int n, Res;
int main() {
	int i;
	scanf("%s", p);
	for (i = 0; p[i]; i++);
	n = i;
	Res = n;
	for (i = 0; i < n - 1; i++) {
		if (p[i] != p[i + 1]) {
			Res = min(Res, max(i + 1, n - i - 1));
		}
	}
	printf("%d\n", Res);
}

Measured memory_bytes: 256
import math,sys
try: sys.stdin = open('in.in','r')
except: pass

class Point:
	def __init__(self,x,y):
		self.x = x
		self.y = y
	def __add__(self,p):
		return Point(self.x+p.x,self.y+p.y)
	def __sub__(self,p):
		return Point(self.x-p.x,self.y-p.y)
	def __mul__(self,p):
		return Point(self.x*p,self.y*p)

def Dot(a,b):
	return a.x*b.x + a.y*b.y
def Cross(a,b):
	return a.x*b.y - a.y*b.x
def Dis(a,b):
	return math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) )
def Dis2(a,b):
	return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)

q = int(input())
for i in range(q):

	x0,y0,x1,y1,x2,y2,x3,y3 = map(int,input().split())
	p0 = Point(x0,y0)
	p1 = Point(x1,y1)
	p2 = Point(x2,y2)
	p3 = Point(x3,y3)

	l1 = p0-p1
	l2 = p3-p2

	if Dot(l1,l2) == 0:
		print('1')
	elif Cross(l1,l2) == 0:
		print('2')
	else:
		print('0')



Measured memory_bytes: 5692
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	lint N;
	lint A[100010]={};

	cin >> N;
	lint tmp=0;
	for(int i=0;i<N;i++)
	{
		cin >> A[i];
		if(i%2==0)
			tmp+=2*A[i];
		else
			tmp-=2*A[i];
	}

	lint ans[100010]={};
	ans[0]=tmp/2;
	for(int i=0;i<N-1;i++)
		ans[i+1]=2*A[i]-ans[i];
	for(int i=0;i<N;i++)
	{
		cout << ans[i];
		if(i==N-1)cout << endl;
		else cout << " ";
	}
	return 0;
}



Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
using namespace std;
typedef long long ll;


int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b != c) {
		cout << "Yes" << endl;
	}
	else if (a == c && a != b) {
		cout << "Yes" << endl;
	}
	else if (b == c && a != b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int maxN = 2e5 + 10;
const int inf = 1e9 + 7;

int n;
int h[maxN], a[maxN], f[maxN], st[maxN * 4];

void update(int id, int l, int r, int i, int val){
    if(i < l || i > r)
        return;
    if(l == r){
        st[id] = val;
        return;
    }
    int mid = (l + r) / 2;
    update(id << 1, l, mid, i, val);
    update(id << 1 | 1, mid + 1, r, i, val);
    st[id] = max(st[id << 1], st[id << 1 | 1]);
}

int get(int id, int l, int r, int u, int v){
    if(v < l || u > r)
        return -inf;
    if(u <= l && v >= r)
        return st[id];
    int mid = (l + r) / 2;
    return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> h[i];
    for(int i = 1; i <= n; ++i)
        cin >> a[i];

    for(int i = 1; i <= n; ++i)
        f[h[i]] = a[i];

    for(int i = 1; i <= n; ++i){
        int mx = get(1, 1, n, 1, h[i]);
        f[h[i]] = max(f[h[i]], mx + a[i]);
        update(1, 1, n, h[i], f[h[i]]);
    }

    int res = 0;
    for(int i = 1; i <= n; ++i)
        res = max(res, f[i]);
    cout << res;
}


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int a, b, n;
    cin >> a >> b >> n;
    cout << (a*min(n,b-1))/b - a*(min(n,b-1)/b) << endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    vector<pair<int,int>> CB(M);
    rep(i,N) cin >> A[i];
    rep(i,M){
        int B,C;
        cin >> B >> C;
        CB[i] = make_pair(C,B);
    }
    sort(A.begin(),A.end());
    sort(CB.rbegin(),CB.rend());
    int j=0;
    int num = CB[0].second;
    for(int i=0;i<N;i++){
        if(A[i]<=CB[j].first&&num>0){
            A[i]=CB[j].first;
            num--;
            if(num<=0){
                j++;
                num=CB[j].second;
            }
        }
    }
    ll ans = 0;
    rep(i,N){
        ans+=A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

typedef long long ll;
int main() {
	ll i, o, j, l;
	scanf("%lld %lld %*lld %lld %lld", &i, &o, &j, &l);
	
	ll r = i % 2 + j % 2 + l % 2; // reminder sum
	ll k = i + o + j + l - r;
	
	ll even;
	switch (r)
	{
	case 3:
		k += 3;
		break;
	
	case 2: // odd * 2, even * 1
		if (i % 2 == 0)
		{
			even = i;
		}
		else if (j % 2 == 0)
		{
			even = j;
		}
		else
		{
			even = l;
		}
		if (even > 0)
		{
			k += 1;
		}
		
		break;
	
	default:
		break;
	}
	printf("%lld", k);
	
	return 0;
}


Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
int main(){
	char x[1001],y[1001];
	scanf("%s%s",x,y);
	int leng1=strlen(x),leng2=strlen(y);
	int ans=99999,q=0,tmp=0;
	for(int i=0;i<=leng1-leng2;i++){
		tmp=0;
		for(int j=0;j<=leng2-1;j++){
			q=i+j;
			if(x[q]!=y[j])tmp++;
		}
		if(ans>tmp)ans=tmp;
	}
	printf("%d",ans);
}

Measured memory_bytes: 3812
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

MOD = 10**9+7
N,M = map(int, input().split())

if abs(N-M) == 1:
    ans = (math.factorial(N)*math.factorial(M))%MOD
elif abs(N-M) == 0:
    ans = (2*math.factorial(N)*math.factorial(M))%MOD
else: ans = 0

print(ans)

Measured memory_bytes: 14264
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  int n; cin>>n;
  int p[n];
  int count=0;
  for(int i=0;i<n;i++) cin>>p[i];
  for(int i=1;i<n-1;i++){
    if(p[i-1]<p[i]&&p[i]<p[i+1]) count++;
    else if(p[i-1]>p[i]&&p[i]>p[i+1]) count++;
  }
  cout<<count<<endl;
  return 0;
}

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

using namespace std;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(0); //Don't delete this line!
    string s;
    cin >> s;
    int maxx=0,strk=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R'){
            strk++;
            maxx = max(maxx,strk);
        }
        else strk=0;
    }
    cout << maxx;
}


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

int main()
{
    int n,k;
    cin >> n >> k;
    int sum = 1;
    for(int i = 0;i < n;i++){
        if(i == 0) sum *= k;
        else sum *= k - 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <limits>
using namespace std;
// numeric_limits<double>::epsilon()
 
// #define int int64_t
#define pr(x) cout << x << endl;
#define vi vector<int>
#define vii vector< vector<int> >
#define mp make_pair
#define f(i,n) for(i =0 ; i< n ; i++)
#define ff first
#define ss second
#define pb push_back
#define INF 1e9
#define SIZE 200001
#define mod 1000000007
void solve();


int power(int a, int b)
{
    if(b==0) return 1;
    else if(b&1) return a*power(a*a,b/2);
    else return power(a*a, b/2);
}
 


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}
bool AreSame(double a, double b) {
    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}
 
int  j=1, n, t, m=0, dot=0, i, k, a, x, y, n1, m1, l;

// void extendGcd(int m, int n)
// {
//     if(n==0)
//     {
//         x=1;
//         y=0;
//         dot=m;
//     }
//     else
//     {
//         extendGcd(n,m%n);
//         q = x;
//         x = y;
//         y = q - (m/n)*y;
//     }
    

// }



string s1, s2,s3;
void solve()
{
    // cin >> t;while(t--)
    {
        x=0;
        cin >> n;
        f(i,n)
        {
            cin >> y;
            if(y!=i+1) x++;
        }
        if(x==2 or x==0) pr("YES")
        else pr("NO")
    }

}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)5e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll k,a,b,i;cin>>k>>a>>b;for(i=a;i<=b;i++) if(i%k==0) return cout<<"OK\n",0;
	cout<<"NG\n";
}


Measured memory_bytes: 3592
import java.io.*;
import java.util.PriorityQueue;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int x = Integer.parseInt(line[0]);
        int y = Integer.parseInt(line[1]);
        int a = Integer.parseInt(line[2]);
        int b = Integer.parseInt(line[3]);
        int c = Integer.parseInt(line[4]);
        PriorityQueue<Integer> p = new PriorityQueue<Integer>(a);
        PriorityQueue<Integer> q = new PriorityQueue<Integer>(b);
        PriorityQueue<Integer> r = new PriorityQueue<Integer>(c, Comparator.reverseOrder());
        line = br.readLine().split(" ");
        for(int i = 0; i < a; i++)  p.add(Integer.parseInt(line[i]));
        line = br.readLine().split(" ");
        for(int i = 0; i < b; i++)  q.add(Integer.parseInt(line[i]));
        line = br.readLine().split(" ");
        for(int i = 0; i < c; i++)  r.add(Integer.parseInt(line[i]));
        while(p.size() > x) p.poll();
        while(q.size() > y) q.poll();
        while(!r.isEmpty() && (p.peek() < r.peek() || q.peek() < r.peek())){
            if(p.peek() < q.peek()){
                p.poll();
                p.add(r.poll());
            }else{
                q.poll();
                q.add(r.poll());
            }
        }
        long ans = 0;
        for(int val : p)    ans += val;
        for(int val : q)    ans += val;
        System.out.println(ans);
    }
}


Measured memory_bytes: 69528
N = int(input())
W = list(map(int, input().split()))

ans = 101
tmp1L = [0] * N
tmp2L = [0] * N
tmp1L[0] = W[0]
tmp2L[N - 1] = W[N - 1]
for i in range(N - 1):
    tmp = 0
    for j in range(0, i + 1):
        tmp += W[j]
    tmp1L[i] = tmp

for i in range(1, N):
    tmp = 0
    for j in range(1, i + 1):
        tmp += W[-j]
    tmp2L[-i] = tmp

for i in range(N - 1):
    ans = min(ans, abs(tmp1L[i] - tmp2L[i + 1]))
print(ans)

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

int main() {
  int N; 
  cin >> N;
  vector<vector<int>> vc(2, vector<int>(N));
  
  for (int i = 0; i < N; i++) {
    cin >> vc.at(0).at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> vc.at(1).at(i);
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a = vc.at(0).at(i) - vc.at(1).at(i);
    if (a > 0) {
      ans += a;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const double EPS = 1e-9;


int main(){
	string s, rs;

	int count = 0;
	while(cin >> s){
		rs = s;
		reverse(rs.begin(), rs.end());

		if(rs == s){
			count++;
		}
	}

	cout << count << endl;

    return 0;
}

Measured memory_bytes: 1192
package main

import (
	"bufio"
	"fmt"
	basicIO "io"
	"os"
	"strconv"
)

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(r basicIO.Reader, w basicIO.Writer) {
	io := NewIO(r, w)
	N, _ := io.nextInt()
	M, _ := io.nextInt()

	L := 1
	R := N

	for i := 0; i < M; i++ {
		nl, _ := io.nextInt()
		if nl > L {
			L = nl
		}
		nr, _ := io.nextInt()
		if nr < R {
			R = nr
		}
	}

	sol := R - L + 1
	if sol < 0 {
		sol = 0
	}

	io.PutInt(sol)
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) nextString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) nextInt() (int, error) {
	io.Scanner.Scan()
	i, err := strconv.Atoi(io.Scanner.Text())
	return i, err
}

func (io *IO) PutInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) PutString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 1000010;

string N;
int dp[MAX_N][2];

int dfs(int i, int raising) {
    if(i >= N.length()) { return 0; }

    int& ret = dp[i][raising];
    if(~ret) { return ret; }
    ret = LLINF;

    int n = N[i] - '0' + raising;

    // 繰り上がりをする場合
    ret = dfs(i + 1, 1) + (10 - n);
    // 繰り上がりをしない場合
    chmin(ret, dfs(i + 1, 0) + n);

    return ret;
}

int solve() {
    N = "0" + N;

    reverse(N.begin(), N.end());

    MINUS(dp);
    ll ret = dfs(0, 0);
    return ret;
}

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

    cin >> N;
    printf("%lld\n", solve());

    return 0;
}



Measured memory_bytes: 63816
A, B, K = map(int, input().split())
turn = 1
for k in range(K):
    if turn:
        if A % 2 == 1:
            A -= 1
        A, B = A//2, B + A//2
        turn = 0
    else:
        if B % 2 == 1:
            B -= 1
        A, B = A + B//2, B//2
        turn = 1
print(A, B)

Measured memory_bytes: 3060