akhauriyash/Code-Regression huggingface dataset:
"""
https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_c

B -> 1
W -> 0

BWWWWB
100001

反転操作を３つに分解
左端からl-1まで+1
左端からr-1まで+1
rに+1

こうしておくとつまり、右端として選ぶかどうかを決めるだけでよくなる

"""

from math import factorial

N = int(input())
d = {"W":0, "B":1}
ls = [d[s] for s in input()]
r_ls = reversed(ls)
xs = []
mod = 10**9 + 7
# 全部左右とか関係なく取ったとする
for i,r in enumerate(r_ls):
    xs.append(r + i)
# 右でトルものを選ぶ(↑の操作後、mod2が1のところ)
LR = [x%2 for x in list(reversed(xs))]

# Lの数を持ちながら、Rが来たら消化＆場合の数にLの数をかける
cnt = 0 # Lの数
num = 1 # 場合の数

for lr in LR:
    if lr == 0:
        cnt += 1
    else:
        num *= cnt
        cnt -= 1
        cnt = max(0,cnt)
        num %= mod
# LとRのペアが一致していない
if cnt > 0:
    num = 0
ans = num * factorial(N)
print(ans%mod)


Measured memory_bytes: 15908
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> 
new_data_set;
const LL MOD = 1000003;
int ans[121212];

int main() {
	string S;
	cin >> S;
	vector<int> kiri, kanan;
	int N = S.length();
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L') kiri.push_back(i);
		else kanan.push_back(i);
	}
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L') {
			int l1 = kanan.size();
			int l = 0, r = l1 - 1, idx;
			while (l <= r) {
				int mid = (l + r) >> 1;
				if (kanan[mid] <= i) {
					idx = mid;
					l = mid + 1;
				} else {
					r = mid - 1;
				}
			}
			int dist = i - (kanan[idx] + 1) ;
			if (dist % 2 == 0) {
				ans[kanan[idx] + 1]++;
			} else {
				ans[kanan[idx]]++;
			}
		} else {
			int l1 = kiri.size();
			int l = 0, r = l1 - 1, idx;
			while (l <= r) {
				int mid = (l + r) >> 1;
				if (kiri[mid] >= i) {
					idx = mid;
					r = mid - 1;
				} else {
					l = mid + 1;
				}
			}
			int dist = (kiri[idx] - 1) - i;
			if (dist % 2 == 0) {
				ans[kiri[idx] - 1]++;
			} else {
				ans[kiri[idx]]++;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%d", ans[i]);
	}
	printf("\n");
} 

Measured memory_bytes: 1532
#include <iostream>
#include <map>

using namespace std;

int main() {
	map<string, int> words;
	string word;
	int longest = 0, aliance = 0;
	while (cin >> word) {
		if (words.find(word) == words.end()) {
			int len = word.size();
			words[word] = 1;
			longest = max(longest, len);
		} else {
			int n = words[word];
			words[word] = n + 1;
		}
	}
	map<string, int>::iterator it;
	for (it = words.begin(); it != words.end(); it++)
		aliance = max(aliance, it->second);
	for (it = words.begin(); it != words.end(); it++)
		if (it->second == aliance) {
			cout << it->first;
			break;
		}
	for (it = words.begin(); it != words.end(); it++) {
		string s = it->first;
		if (s.size() == longest) {
			cout << " " << s << endl;
		}
	}

	return 0;
}

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

int main() {
  int a,b; cin>>a>>b;
  if(a <= 0 && b >= 0) cout <<  "Zero" << endl;
  else if(a>0) cout << "Positive" << endl;
  else if((b-a+1)%2==0) cout << "Positive" << endl;
  else cout << "Negative" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  lvector D(n,0);rep(i,n) cin>>D[i];
  ll m;cin>>m;
  lvector T(m,0);rep(i,m) cin>>T[i];
  sort(ALL(D));sort(ALL(T));
  ll dpos=0,tpos=0,val=0;
  bool isok=false;
  while(dpos<n) {
    if(D[dpos]==T[tpos]) {
      val++;dpos++;tpos++;
    }
    else dpos++;
    if(val==m) {
      isok=true;break;
    }
  }
  puts(isok?"YES":"NO");
  return 0;
}

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

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

    int min_num = b*10;

    while((int) (min_num * 0.08) != a) {
        // cout << min_num  << endl;
        min_num++;

        if((int) (min_num * 0.1) != b) break;
    }

    if((int)(min_num * 0.08) == a && (int) (min_num*0.1) == b) {
        cout << min_num << endl;
    } else {
        cout << -1 << endl;
    }


    return 0;
}

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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


int main() {
	int a, b, k;
	cin >> a >> b>>k;
	
	vector<int> as(100);
		for (int i = 1; i <= min(a, b); i++) {
			if (a % i == 0 && b % i == 0) {
				as.push_back(i);
			}
		}
		sort(as.rbegin(), as.rend());
		cout << as[k - 1];
	return 0;
}










Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<25)

struct P{
	int x,y;
	P(int a,int b){x = a , y = b;}
	P(){}
};
struct NODE{
	int x,y,cost,cur,id;
	NODE(P a,int c,int d,int b){
		x = a.x , y = a.y , cost = c , cur = d , id = b;
	}
};
bool operator<(const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
#define next(n) ((n+1)%5)

int getCost(P a,P b){
	return abs(a.x-b.x)+abs(a.y-b.y);
}
int main(){
	int W,H;
	while(cin >> W >> H,W){
		vector<P> pos[5];
		P goal,start;
		rep(i,H)rep(j,W){
			char c;
			cin >> c;
			if(c == 'S')start = P(j,i);
			else if(c == 'G')goal = P(j,i);
			else if(c != '.')pos[c-'1'].push_back(P(j,i));
		}
		int ans = INF , choice = -1;
		rep(X,5){
			queue<NODE> Q;
			Q.push(NODE(start,0,X,1023));
			int memo[5][1024];
			rep(i,5)rep(j,1024) memo[i][j] = INF;
			while(Q.size()){
				NODE q = Q.front(); Q.pop();
				
				if(q.cost > memo[q.cur][q.id] )continue;
				
				if(next(q.cur) == X){
					int lastCost = q.cost+getCost(P(q.x,q.y),goal);
					if( lastCost < ans ){
						ans = lastCost;
						choice = X;
					}
					continue;
				}
				
				rep(i,pos[next(q.cur)].size()){
					NODE t = NODE(pos[next(q.cur)][i] , q.cost+getCost(P(q.x,q.y),pos[next(q.cur)][i]) , next(q.cur) , i);
					if( t.cost < memo[t.cur][t.id]){
						memo[t.cur][t.id] = t.cost;
						Q.push(t);
					}
				}
			}
		}
		if(~choice)cout << choice+1 << " " << ans << endl;
		else cout << "NA" << endl; 
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF pow(10,10)
#define M 1000000007

vector<ll>memo(100005,-1);
ll n,k;
vector<ll>a(105);

ll beatable(ll k){
    if(memo[k]!=-1) return memo[k];
    bool win = false;
    for(int i=0;i<n;i++){
        if(k < a[i]){
            break;
        }
        if(beatable(k-a[i])==0){
            win = true;
            break;
        }
    }
    if(win == true){
        memo[k]=1;
    }else{
        memo[k]=0;
    }
    return memo[k];
}

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

    for(int i=0;i<n;i++)memo[a[i]] = 1;
    
    if(beatable(k)==1) cout << "First" << endl;
    else cout << "Second" << endl;

    // for(int i=0;i<=k;i++){
    //     cout << memo[i] << ' ';
    // }cout << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    char op;
    int a,b;
    
    while (1) {
        
        scanf("%d %c %d",&a,&op,&b);
        
        if (op == '?') {
            break;
        }
        
        if (op == '+') {
            printf("%d\n",a+b);
        }
        
        if (op == '-') {
            printf("%d\n",a-b);
        }
        
        if (op == '/') {
            printf("%d\n",a/b);
        }
        
        if (op == '*') {
            printf("%d\n",a*b);
        }
    }
    return 0;
}

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

int main() {
  int n,ans,naka = 0,oshiri = 0,atama = 0,shiriatama = 0;
  cin >> n;
  for(int i = 0;i < n;i++){
    string s;
    cin >> s;
    for(int j = 0;j < s.size()-2;j++){
      if(s.at(j) == 'A' && s.at(j+1) == 'B'){
        naka++;
      }
    }
    if(s.at(0) == 'B' && s.at(s.size()-1) == 'A'){
      shiriatama++;
    }
    else if(s.at(0) == 'B'){
      atama++;
    }
    else if(s.at(s.size()-1) == 'A'){
      oshiri++;
    }
  }
  if(atama < oshiri){
    ans = atama + shiriatama + naka;
  }
  else if(atama > oshiri){
    ans = oshiri + shiriatama + naka;
  }
  else if(shiriatama != 0){
    if(oshiri == 0 && atama == 0){
      ans = naka + shiriatama -1;
    }
    else{
      ans = oshiri + naka + shiriatama;
    }
  }
  else{
    ans = oshiri + naka;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >>  A.at(i);
  }
 vector<int> count(N);
  rep(i,N) {
    while(A.at(i) % 2 == 0) {
      count.at(i)++;
      A.at(i) /= 2;
    }
 }
  int  mini = 1e10;
  rep(i,N) {
    mini = min(mini,count.at(i));
  }
cout << mini << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<complex>
#include <algorithm>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
#define point complex<double> 
#define pi 3.14159265359
double dot(point a, point b)
{
	return (conj(a) * b).real();
}
double cross(point a, point b)
{
	return (conj(a) * b).imag();
}
#define mod 1000000007
    typedef long long ll;
        ll dp[2005][2005];
    int main()
    {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n, k;
        cin >> n >> k;
        dp[0][0] = 1; dp[1][1] = 1; dp[1][0] = 1;
        for (int i = 2; i <= n; i++)
        {
            dp[i][0] = 1; dp[i][i] = 1;
            for (int j = 1; j <= i; j++)
            {
                dp[i][j] = dp[i - 1][j]%mod + dp[i - 1][j - 1]%mod;
            }
        }
        int r = n - k;
        for (int i = 1; i <= k; i++)
        {
            cout << ((dp[k - 1][i - 1] % mod) * (dp[r + 1][i] % mod))%mod << '\n'; 
        }
        return 0;
    }


Measured memory_bytes: 30208
n=int(input())
L=[int(i) for i in input().split()]
L.sort(reverse=True)

def binary(a,b,mid):
  if  L[mid]+L[j]>L[i]:
    return True
  else:
    return False

ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    l=j
    r=n
    while r-l>1:
      mid=(r+l)//2
      if binary(i,j,mid):
        l=mid
      else:
        r=mid
    ans+=l-j
print(ans)
        


Measured memory_bytes: 43500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i <= (n); ++i)
#define repD(i, a, n) for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
const long long mod = 1000000007;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll pow(ll a,ll b,ll mod){
    ll ans = 1;
    while(b){
        if(b&1)
            ans*= a;
        ans%= mod;
        a*= a;
        a%= mod;
        b/=2;
    }
    return ans;
}
int main(){
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    ll n,k;
    cin>>n>>k;
    ll mod = 1000000007;
    vector<ll> v(k+1,0);
    ll ans = 0;
    for(ll i = k;i>=1;i--){
        v[i] = pow(k/i,n,mod);
        for(int j = 2*i;j<=k;j+=i){
            v[i]-= v[j];
            v[i] = (v[i]+mod)%mod;
        }
        ans+= ((i*v[i])%mod);
        ans%= mod;
        //cout<<ans<<endl;
    }
       cout<<ans;
    return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int INF = 1e+8;
int t[20][20] = {0};
int n;
int main(){
	while( scanf("%d", &n ) , n ){
		
		for(int y=0 ; y < n ; y++ ){
			for(int x=0 ; x < n+1 ; x++ ){
				scanf("%d", &t[y][x]);
			}
		}
		// dp[bits] := i ツづーツクツδ環アツつキツづゥツづ個づ可つゥツつゥツづゥツ篠楪甘?
		int dp[1<<16];
		for(int i=0 ; i < (1<<n) ; i++ ){
			dp[i] = INF;
		}
		dp[0] = 0;
		for(int y=0 ; y < n ; y++ ){
			dp[1<<y] = t[y][0];
		}
		for(int bits = 1 ; bits < (1<<n) ; bits++ ){
			for(int i=0 ; i < n ; i++ ){
				// i ツづ個スツテツーツジツづ可陳ァツ静ュ
				int c = 1 << i;
				// ツスツテツーツジ i ツづーツつキツづ?づ可クツδ環アツつオツづ?つ「ツつスツづァ continue
				if( (bits & c) ) continue;
				
				int next = bits | c;
				// ツスツテツーツジ i ツづ可つゥツつゥツづゥツ篠楪甘板づーツ仰?づ淞づゥ
				int time = t[i][0];
				for(int x=1 ; x <= n ; x++ ){
					// ツスツテツーツジ x ツづーツクツδ環アツつオツづ?つ「ツづゥ
					if( bits & (1 << (x-1)) ){
						time = min( time , t[i][x] );
					}
				}
				dp[next] = min( dp[next] , dp[bits] + time );
				for(int j=0 ; j < n ; j++ ){
					// i ツづ個スツテツーツジツづ可陳ァツ静ュ
					int c_2 = 1 << j;
					// ツスツテツーツジ i ツづーツつキツづ?づ可クツδ環アツつオツづ?つ「ツつスツづァ continue
					if( (next & c_2) ) continue;
					
					int next_2 = next | c_2;
					// ツスツテツーツジ j ツづ可つゥツつゥツづゥツ篠楪甘板づーツ仰?づ淞づゥ
					int time_2 = t[j][0];
					for(int x=1 ; x < n ; x++ ){
						// ツスツテツーツジ x ツづーツクツδ環アツつオツづ?つ「ツづゥ
						if( next & (1 << (x-1)) ){
							time_2 = min( time_2 , t[j][x] );
						}
					}
					dp[next_2] = min( dp[next_2] , dp[next] + time_2 );
				}
			}
		}
		
		printf( "%d\n", dp[(1<<n)-1] );
	}
}

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

int main()
{
	string S;
	cin >> S;

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

	for (int i = 0; i < S.length() - 1; i++) {
		if (S[i] == S[i + 1]) {
			cout << "no" << endl;
			return 0;
		}
	}

	cout << "yes" << endl;
}





Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>

int main(void) {
	char str[201], tmp[101];
	char p[101];
	int slen, plen;
	int i, j, flag;
	
	scanf("%s %s", str, p);
	
	strcpy(tmp, str);
	strcat(str, tmp);
	
	slen = strlen(str);
	plen = strlen(p);
	
	flag = 0;
	for (i = 0; i < slen - plen; i++) {
		if (strncmp(&str[i], p, plen) == 0) flag = 1;
	}
	
	if (flag) puts("Yes");
	else puts("No");
	
	return 0;
}



Measured memory_bytes: 2112
import sys
N,M,K=map(int, sys.stdin.readline().split())
mod=998244353

fact, inv_fact=[1], [1]
fact_tmp=1
for i in range(1, N+1):
    fact_tmp*=i
    fact_tmp%=mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))

def ncr(n,r):
	if n<0 or r<0 or n<r:	return 0
	else:   return (fact[n]*inv_fact[r]*inv_fact[n-r])%mod

ans=0
for k in range(K+1):
    ans+=ncr(N-1,k)*M*pow(M-1,N-1-k,mod)
    ans%=mod
print ans

Measured memory_bytes: 108224
//完全二分木
//2019-01-15
//Ebitani Akira

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

#define N 250

int Right(int);
int Left(int);

int array[N];
int n;

int main(){
  int i;

  scanf("%d", &n);
  if(n < 1 || n > 250){
    printf("サイズが適当ではありません。\n");
    exit(1);
  }

  for(i = 1 ; i <= n ; i++){
    scanf("%d", &array[i]);
  }
  
  for(i = 1 ; i <= n ; i++){
    printf("node %d: key = %d,", i, array[i]);

    if(i > 1){
      printf(" parent key = %d,", array[i/2]);
    }

    if(Left(i) <= n){
      printf(" left key = %d,", array[Left(i)]);
    }
    if(Right(i) <= n){
      printf(" right key = %d,", array[Right(i)]);
    }
    
    printf(" \n");
  }

  return 0;
}

int Right(int x){
  int re;
  re = 2 * x + 1;
  return re;
}
int Left(int x){
  int re;
  re = 2 * x;
  return re;
}



Measured memory_bytes: 2108
n=int(input())
a=list(map(int,input().split()))
c=1
ans=0
for i in range(1,n):
    #print(c)
    if a[i]==a[i-1]:
        c+=1
        if i==n-1:
            ans+=c//2
    else:
        ans+=c//2
        c=1
print(ans)

Measured memory_bytes: 3060
#pragma gcc optimize("Ofast")

#include <iostream>
using namespace std;
typedef int64_t lld;
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

// code starts here
const int mod = 1000000007;
int invs[100001]={0, 1};
signed main(){jizz
    int n;
    lld f = 1, ans = 0, cnt = 0;
    cin >> n;
    for(int i = 2; i <= n; i++)
        invs[i] = (mod-(lld)(mod/i)*invs[mod%i]%mod);
    for(int i = 1; i <= n; i++)
        (invs[i] += invs[i-1])%=mod, f = f*i%mod;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        ans = (ans + (lld)(invs[i]+invs[n+1-i]-1)*x)%mod;
    }
    cout << ans*f%mod << endl;
}


Measured memory_bytes: 640
a,b,c,d=map(int,input().split())
if a<=c<=b and a<=d<=b:
    print(d-c)
elif c<=a<=d and c<=b<=d:
    print(b-a)
elif a<=c<=b:
    print(b-c)
elif a<=d<=b:
    print(d-a)
else:
    print(0)


Measured memory_bytes: 2940
import math
import fractions
import collections
import itertools
import pprint
N=int(input())
l=[list(map(int,input().split())) for _ in range(N)]
l1=[]
l2=[]
for i in range(N):
    l1.append(l[i][0])
    l2.append(l[i][1])
l1.sort()
l2.sort()
if N%2==0:
    minmed=(l1[N//2]+l1[N//2-1])/2
    maxmed=(l2[N//2]+l2[N//2-1])/2
    print(int(2*(maxmed-minmed)+1))
else:
    minmed=l1[N//2]
    maxmed=l2[N//2]
    print(maxmed-minmed+1)

Measured memory_bytes: 134508
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  std::vector<std::string> c(3);
  REP(i, 3) {
    std::cin >> c.at(i);
  }
  
  REP(i, 3) {
    std::cout << c.at(i).at(i);
  }
  cout('\n');
}

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

int main(){

  int n;

  while(cin>>n, n){
    int m[100], p[100][100], k, l[100], c=0, x;
    for(int i=0;i<n;i++){
      cin>>m[i];
      for(int j=0;j<m[i];j++) cin>>p[i][j];
    }
    cin>>k;
    for(int j=0;j<k;j++) cin>>l[j];
    for(int i=0;i<n;i++){
      if(m[i]<k) continue;
      int j;
      for(j=0;j<k;j++){
        int h;
        for(h=0;h<m[i];h++){
          if(l[j]==p[i][h]){
            //cout<<l[j]<<endl;
            break;
          }
        }
        if(h==m[i]) break;
      }
      if(j==k){
        c++;
        x=i;
      }
    }
    if(c==1) cout<<x+1<<endl;
    else cout<<-1<<endl;
  }

  return 0;
}

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

const  int N = 2e5;
vector<vector<int>> b(30, vector<int> (N));

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    for(int j = 0; j < 22; j++) {
      if(a[i] & (1 << j)) b[j][i] = 1;
    }
  }
  for(int j = 0; j < 22; j++) {
    for(int i = 1; i < n; i++) {
      b[j][i] += b[j][i - 1];
    }
  }
  ll r = 0;
  for(int i = 0; i < n; i++) {
    int ans = n;
    for(int j = 0; j < 22; j++) {
      int ok = i, ng = n;
      while(ng - ok > 1) {
        int mid = (ok + ng) >> 1;
        if(b[j][mid] - (i ? b[j][i - 1] : 0) <= 1) ok = mid;
        else ng = mid;
      }
      ans = min(ok, ans);
    }
    r += (ans + 1 - i);
  }
  cout << r << endl;
}


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

int main() {
    int n, d; cin >> n >> d;
    vector<vector<double>> x(n, vector<double>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }
    
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            double powSum = 0.;
            for (int k = 0; k < d; k++)
            {
                double summand = pow(x[i][k] - x[j][k], 2);
                powSum += summand;
            }
            double powSumSqu = pow(powSum, 0.5);
            int intPowSumSqu = powSumSqu;
            if (intPowSumSqu == powSumSqu) cnt++;            
        }
        
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

int main() {
  ll x,y;
  cin >> x >> y;
  ll cnt=0;
  while(y>=x) {
    cnt++;
    y/=2;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
tmp = list(map(int, input().split()))
n = tmp[0]
q = tmp[1]
s = input()

acc = [0] * n
for i in range(1, n):
  if s[i-1] == 'A' and s[i] == 'C':
    acc[i] = acc[i-1] + 1
  else:
    acc[i] = acc[i-1]

ans = []
for i in range(q):
  tmp = list(map(int, input().split()))
  l = tmp[0]
  r = tmp[1]
  ans.append(acc[r-1] - acc[l-1])

for i in range(q):
  print(ans[i])

Measured memory_bytes: 59224
n, y = gets.split(" ").map(&:to_i)

if y > n * 10000 || y < n * 1000
  puts "-1 -1 -1"
  exit
end

x = 0

(n + 1).times do |i|
  (n + 1).times do |j|
    x = i * 10000 + j * 5000 + (n - (i + j)) * 1000
    if x == y && n - (i + j) >= 0
      puts "#{i} #{j} #{n - (i + j)}"
      exit
    end
  end
end

puts "-1 -1 -1"

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;


int main(){
	string S;
	cin>>S;
	string ans="CODEFESTIVAL2016";
	int count=0;
	for(int i=0;i<S.size();i++){
		if (S[i]!=ans[i])
			count++;
	}
	cout<<count<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9
#define common cout << "Case #" << w+1 << ": "




int main()
{
    lli n;
    cin >> n;
    vector<lli>v(n);
    for(lli i=0;i<n;i++)
        cin >> v[i];
    lli amount=1000,st=0;
    vector<lli>imp(n);
    imp[n-1]=n-1;
    for(lli i=n-2;i>-1;i--)
    {
        if(v[i]<v[i+1])
            imp[i]=imp[i+1];
        else
            imp[i]=i;
    }
    for(lli i=0;i<n;i++)
    {
        if(imp[i]!=i)
        {
            st+=(amount)/v[i];
            amount%=v[i];
            amount+=(st)*v[imp[i]];
            st=0;
            i=imp[i];
        }
    }
    cout << amount << endl;
}

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

int n;

void f(string s) {
    if (s.size() == n) {
        cout << s << '\n';
        return;
    }
    s.push_back('a');
    f(s);
    s.pop_back();
    for (char a = 'b'; a <= 'z'; a++) {
        bool ok = false;
        for (auto& b : s) {
            if (a == b + 1) ok = true;
        }

        if (ok) {
            s.push_back(a);
            f(s);
            s.pop_back();
        }
    }
}


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    f("");
}


Measured memory_bytes: 1536
def main():
    mod = 10**9+7
    fact = [1, 1]
    for i in range(2, 10**3):
        fact.append(fact[-1]*i % mod)

    def inv_n(n):
        return pow(n, mod-2, mod)

    def nCr(n, r, mod=10**9+7):
        return inv_n(fact[n-r]*fact[r] % mod)*fact[n] % mod

    n = input()
    k = int(input())

    m = len(n)
    ans2 = 0
    if len(n)-n.count("0") == k:
        ans2 = 1
    for i in range(m):
        s = n[i]
        if s != "0":
            if k >= 0 and m-i-1 >= k:
                ans2 += nCr(m-i-1, k)*pow(9, k)
            k -= 1
            if k >= 0 and m-i-1 >= k:
                ans2 += (int(n[i])-1)*nCr(m-i-1, k)*pow(9, k)
    print(ans2)


main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt

int n,s,t,a[N],b[N],d[N],x[N],y[N],z[N],next[N],p[N],f[N],h[N];

void travel(int x){
	z[x]=z[f[x]]+1;
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x])
		f[y[t]]=x,travel(y[t]);
}

void solve(int x){
	for (int t=p[x];t;t=next[t])
		if (!d[b[t]]&&d[x]+1<z[b[t]])
		d[b[t]]=d[x]+1,solve(b[t]);
}

void build(int x[],int y[]){
	fill(p+1,p+n+1,0);
	for (int i=1;i<=n-1;i++){
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();s=read();t=read();
	for (int i=1;i<=n-1;i++)
		a[2*i-1]=b[2*i]=read(),
		b[2*i-1]=a[2*i]=read();
	for (int i=1;i<=n-1;i++)
		x[2*i-1]=y[2*i]=read(),
		y[2*i-1]=x[2*i]=read();
	build(x,y);travel(t);
	for (int i=1;i<=2*n-2;i++)
		if (f[a[i]]!=b[i]&&f[f[a[i]]]!=b[i]&&
			f[b[i]]!=a[i]&&f[f[b[i]]]!=a[i]&&f[a[i]]!=f[b[i]])
		h[a[i]]=1,h[b[i]]=1;
	build(a,b);d[s]=1;solve(s);
	int ans=0;
	for (int i=1;i<=n;i++){
		if (d[i]&&h[i]) {printf("-1\n");return 0;};
		if (d[i]) ans=max(ans,2*(z[i]-1));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35328
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    vi a;
    int ans,x;
    rep(i,3){
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    ans=a[2]-a[0];
    cout<<ans;
}






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

int main(){
    int n; cin >> n;
    long ans = 0;
    vector<int> a(n+1);
    for(int i = 0;i < n+1;i++){
        cin >> a[i];
    } 
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    rep(i,n){
        int left = min(a[i], b[i]);
        ans += left;
        a[i] -= left;
        b[i] -= left;

        int right = min(a[i + 1], b[i]);
        ans += right;
        a[i + 1] -= right;
        b[i] -= right;
    }
    cout << ans << endl;
}

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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

int32_t main() {
	FAST_IO;
	
//	freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);

	int k;
	cin >> k;
	int a, b;
	cin >> a >> b;
	
	for (int i = a; i <= b; i++)
		if (i%k == 0) {
			cout << "OK" << endl;
			return 0;
		}
		
	cout << "NG" << endl;
	
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


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

int main()
{
  int N, K, X, Y, total;
  cin >> N >> K >> X >> Y;

  for (int i=0; i<N && i<K; i++) {
    total += X;
  }
  for (int i=0; i<N-K; i++) {
    total += Y;
  }
  cout << total << endl;
}


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

struct Edge{
  int src,dst,weight;
  Edge(int src,int dst,int weight) : src(src), dst(dst), weight(weight) { }
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight>f.weight;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void dij(Graph &g,int s,vector<int> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, 1<<30);
  dist[s] = 0;
  prev.assign(n, -1);

  priority_queue<Edge> qu;
  for( qu.push( Edge(-2,s,0) ); !qu.empty(); ) {
    Edge e = qu.top(); qu.pop();
    if(prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(vector<Edge>::iterator it = g[e.dst].begin(); it != g[e.dst].end(); ++it) {
      if(dist[it->dst] > e.weight+it->weight) {
	dist[it->dst] = e.weight + it->weight;
	qu.push( Edge(it->src, it->dst, e.weight + it->weight) );
      }
    }
  }
}

int main() {
  int n,k;
  while(cin>>n>>k, n|k) {
    Graph g(n);
    vector<int> dist(n);
    vector<int> prev(n);
    int c,a,b,cost;
    for(int i=0; i<k; ++i) {
      cin>>c;
      if(c == 0) {
	cin>>a>>b;
	a--,b--;
	dij(g, a, dist, prev);
	if(dist[b] == 1<<30) dist[b] = -1;
	cout<<dist[b]<<endl;
      }else if(c == 1) {
	cin>>a>>b>>cost;
	a--,b--;
	g[a].push_back( Edge(a, b, cost) );
	g[b].push_back( Edge(b, a, cost) );
      }
    }
  }
}

Measured memory_bytes: 952
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int[] price = new int[5];
		for(int i = 0; i < 5; i++) {
			price[i] = sc.nextInt();
		}
		int p_min = price[0], j_min = price[3];
		for(int i = 1; i < 3; i++) {
			if(p_min > price[i]) {
				p_min = price[i];
			}
		}
		if(j_min > price[4]) {
			j_min = price[4];
		}
		int min;
		min = p_min + j_min - 50;
		System.out.println(min);
	}

}

Measured memory_bytes: 25960
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head

bool co1(tuple<int, int, int> a, tuple<int, int, int> b) {
  return get<1>(a) < get<1>(b);
}
bool co2(tuple<int, int, int> a, tuple<int, int, int> b) {
  return get<2>(a) < get<2>(b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vi c(n);
  rep(i, n) cin >> c[i];
  vector<tuple<int, int, int> > lr(q);
  rep(i, q) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    lr[i] = make_tuple(a, b, i);
  }
  sort(all(lr), co1);

  vi la(n+1, -1);
  vi bit(n+1);
  auto add = [&](int i, int x) {
    while(i <= n) {
      bit[i] += x;
      i += i&-i;
    }
  };
  auto sum = [&](int i) {
    int res = 0;
    while(i) {
      res += bit[i];
      i &= i-1;
    }
    return res;
  };

  int j = 0;
  rep(i, q) {
    while(j <= get<1>(lr[i])) {
      if(la[c[j]] == -1) {
        la[c[j]] = j;
        add(j+1, 1);
      } else {
        add(la[c[j]]+1, -1);
        add(j+1, 1);
        la[c[j]] = j;
      }
      j++;
    }
    int &l = get<0>(lr[i]);
    l = sum(j) - sum(l);
  }

  sort(all(lr), co2);
  rep(i, q) {
    cout << get<0>(lr[i]) << '\n';
  }
}

Measured memory_bytes: 15472
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=2010;
const int mod=1000000007;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n,k,f[Maxn][Maxn];
int fac[Maxn*Maxn],inv[Maxn*Maxn],fin[Maxn*Maxn];
void pre()
{
	fac[0]=1;
	for(int i=1;i<=n*k;i++)fac[i]=(LL)fac[i-1]*i%mod;
	inv[0]=inv[1]=1;
	for(int i=2;i<=n*k;i++)inv[i]=(LL)(mod-mod/i)*inv[mod%i]%mod;
	fin[0]=1;
	for(int i=1;i<=n*k;i++)fin[i]=(LL)fin[i-1]*inv[i]%mod;
}
int C(int n,int m)
{
	if(n<m)return 0;
	return (LL)fac[n]*fin[m]%mod*fin[n-m]%mod;
}
int main()
{
	n=read(),k=read();
	if(k==1)return puts("1"),0;
	pre();
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	for(int j=0;j<=i;j++)
	{
		f[i][j]=f[i-1][j];
		if(j)f[i][j]=(f[i][j]+(LL)(n-(j-1))*f[i][j-1]%mod*C(n-i+(n-(j-1))*(k-1)-1,k-2)%mod)%mod;
	}
	printf("%d",f[n][n]);
}

Measured memory_bytes: 63360
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); i++)

using ll = long long;

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N+1);
  rep(i,N){cin >> A[i];}
  
  int atksum = accumulate(A.begin(), A.end(), 0);

  cout << (atksum>=H ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

int main() {
	long long int N, a[100000] = {}, ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		ans += a[i];
	}
	cout << ans - N;
}


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

using namespace std;

long long MOD = 1e9+7;

long long time(long long n)
{
	long long ans=1;
	for(long long i=1;i<=n;i++)
	{
		ans *= i;
		ans %= MOD;
	}
	return ans;
}

int main()
{
	long long n,m;
	long long ans;
	cin>>n>>m;
	if(abs(n-m)>1)
	{
		cout<<0<<endl;
	}else{
		ans = time(n) * time(m);
		ans %= MOD;
		if(abs(n-m)==0)
		{
			ans *= 2;
			ans %= MOD;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int 
using namespace std;
int main() 
{
    ll a,b,c;
    cin>>a>>b>>c;

   if(c <= a)
    {
        a -= c;
        c = 0;
    }
    else 
    {
        c -= a;
        a = 0;
    }

    if(c <= b)
    {
        b -= c;
        c = 0;
    }
    else 
    {
        c -= b;
        b = 0;
    }
   
   cout<<a<<" "<<b;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

struct Node {
  int64_t parent{-1};
  // vector<int64_t> children;
  vector<int64_t> neighbours;
  int64_t offset{0};
  int64_t value{-1};
};

void SetParent(const int64_t cnode, vector<Node> &nodes) {
  for (const int64_t neighbour : nodes[cnode].neighbours) {
    if (nodes[neighbour].parent < 1) {
      nodes[neighbour].parent = cnode;
      SetParent(neighbour, nodes);
    }
  }
}

void UpdateValues(const int64_t cnode, const int64_t carried, vector<Node> &nodes) {
  nodes[cnode].value = nodes[cnode].offset + carried;
  for (const int64_t neighbour : nodes[cnode].neighbours) {
    if (nodes[neighbour].value < 0) {
      UpdateValues(neighbour, nodes[cnode].value, nodes);
    }
  }
}

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

  constexpr int64_t kRoot = 1;
  int64_t N, Q;
  cin >> N >> Q;
  vector<Node> nodes(N + 1);
  nodes[kRoot].parent = kRoot;
  for (int64_t i = 0; i < N - 1; ++i) {
    int64_t a, b;
    cin >> a >> b;
    nodes[a].neighbours.push_back(b);
    nodes[b].neighbours.push_back(a);
  }

  SetParent(kRoot, nodes);

  for (int64_t i = 0; i < Q; ++i) {
    int64_t p, x;
    cin >> p >> x;
    nodes[p].offset += x;
  }

  UpdateValues(kRoot, 0, nodes);
  for (int64_t i = 1; i <= N; ++i) {
    if (i != 1) {
      cout << " ";
    }
    const int64_t result = nodes[i].value;
    cout << result;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 27392
//intのオーバーフローに気をつけろ,AGCはだいたいlongにしておけ
//毎回余りを求めることでオーバーフローしなくなる
//nextLineよりnextだ
//charは''で囲うんだぞ
//読み込みは先に全部やっておけ
//for文を回す回数に気をつけろ

import java.util.Scanner;

public class Main {

	public static void main(String args[]) throws InterruptedException {
		    Scanner sc = new Scanner(System.in);
		    
		    int n = sc.nextInt();
		    int m = sc.nextInt();
		    int ans = m;
		    
		    for(int i = 0; i < n-1;i++) {
		    	ans *= (m-1);
		    }
		    System.out.println(ans);
		    sc.close(); }

	public static void saiki(int a, String b) {
		//再帰コーディングのお手本

		if(a == 0) {
			System.out.println(b);
		}else {
			for(char ch = 'a'; ch <= 'c'; ch++) {
				saiki(a-1,b + ch);
			}
		}
	}

	public static  int gcd(int a, int b) {
	    if (a < b) {
	        int tmp = a;
	        a = b;
	        b = tmp;
	    }

	    int r = -1;
	    while (r != 0) {
	        r = a % b;
	        a = b;
	        b = r;
	    }

	    return a;
	}
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <math.h>

#define N 1024
#define SQ(X) \
  ( (X) * (X) )

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    double avg = 0., alpha = 0.;
    int d[ N ];
    int n;

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

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

    for ( i = 0; i < n; ++i )
    {
      avg += d[ i ];
    }
    avg /= n;

    for ( i = 0; i < n; ++i )
    {
      alpha += SQ( d[ i ] - avg );
    }
    alpha /= n;

    printf ( "%.4f\n", sqrt ( alpha ) );
  }

  return ( 0 );
}



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

int main(){
	int a, b, r; 
	char op;
	while(1){
		cin >> a >> op >> b;
		if(op == '?') break;
		switch(op){
			case '+':
				r = a + b;
				break;
			case '-':
				r = a - b;
				break;
			case '*':
				r = a * b;
				break;
			case '/':
				r = a / b;
		}
		cout << r << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
 	int a,b;
  cin >> a >> b;
  if(b%a==0){
	cout << a+b << endl;
  }else{
	cout << b-a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}




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

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) {
				COUT("Yes");
				return 0;
			}
		}
	}

	COUT("No");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[100010], b[100010];
int main() {
	int sum[100010] = { 0 };
	int h, w, d;
	cin >> h >> w >> d;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int c;
			cin >> c;
			a[c] = i;
			b[c] = j;
		}
	}
	for (int i = 0; i < d; i++) {
		for (int j = d + i + 1; j <= h * w; j += d) {
			sum[j] = abs(a[j] - a[j - d]) + abs(b[j] - b[j - d]);
			sum[j] += sum[j - d];
		}
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		cout << sum[y] - sum[x] << endl;
	}
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

bool divsub(long N, long k){
    while(N % k == 0) N /= k;
    return (1 == N % k);
}

void factorize(long N, map<long, long> *m){
    long lim = sqrt(N);
    long div = 2;
    while(N != 1 && div <= lim){
        long cnt = 0;
        while(N % div == 0){
            cnt ++;
            N /= div;
        }
        if(cnt != 0) (*m).insert({div, cnt});
        div ++;
    }
    if(N != 1) (*m).insert({N, 1});
}

int main(){
    long N;
    cin >> N;
    if (N == 2) {
        cout << 1 << endl;
        return 0;
    }    

    long ans = 1;
    map<long, long> m;
    factorize(N - 1, &m);
    for(auto itr = m.begin(); itr != m.end(); ++itr){
        ans *= (itr -> second + 1);
    }
    for(int i=2; i<=sqrt(N); i++){
        if(N % i == 0 && divsub(N, i)) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int dp[N][N];
char s[N][N];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf(" %s",s[i]+1);
        for(int j=1;j<=m;j++)
        {
            dp[i][j] = 1e9;
            if(i==1&&j==1)  dp[i][j] = s[i][j]=='#';
            if(i>1)
            {
                if(s[i][j]=='#'&&s[i-1][j]=='#')    dp[i][j] = min(dp[i][j],dp[i-1][j]);
                else if(s[i][j]=='#')               dp[i][j] = min(dp[i][j],dp[i-1][j]+1);
                else                                dp[i][j] = min(dp[i][j],dp[i-1][j]);
            }
            if(j>1)
            {
                if(s[i][j]=='#'&&s[i][j-1]=='#')    dp[i][j] = min(dp[i][j],dp[i][j-1]);
                else if(s[i][j]=='#')               dp[i][j] = min(dp[i][j],dp[i][j-1]+1);
                else                                dp[i][j] = min(dp[i][j],dp[i][j-1]);
            }
        }
    }
    printf("%d\n",dp[n][m]);
    return 0;
}


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

int main()
{
  int n;
  char c;

  while (1){
    int sum = 0, ace = 0;
    bool fin = false;
    do {
      scanf("%d", &n);
      if (n == 0){
        fin = true;
        break;
      }
      if (n == 1){
        ace++;
      }
      else {
        sum += min(n, 10);
      }
    } while (scanf("%c", &c), c != '\n');

    if (fin){
      break;
    }
    int rs = 0;
    for (int i = 0; i < ace + 1; i++){
      int tmp = sum + i + (ace - i) * 11;
      if (tmp > 21){
        tmp = 0;
      }
      rs = max(tmp, rs);
    }
    printf("%d\n", rs);
  }

  return (0);
}

Measured memory_bytes: 1188
S = input()
Q = int(input())

rev = False
l, r = "", ""

for _ in range(Q):
    query = input()
    if query[0] == "1":
        rev = not rev
    else:
        T, F, C = query.split()
        if F == "1":
            if rev:
                r += C
            else:
                l = C + l
        else:
            if rev:
                l = C + l
            else:
                r += C

res = l + S + r
if rev:
    res = res[::-1]

print(res)

Measured memory_bytes: 10148
#include <bits/stdc++.h>
#define maxn 200005
#define mod 1000000007
using namespace std;

/// DP Digit Template

vector <int> digit;
long long dp[10005][105][3], k;

void getdigit(string x){
    digit.clear();
    for(int i = x.size() - 1; i >= 0; i--)
        digit.push_back(x[i] - 48);
}

long long getsum(int id, int sum, int tight){
    if(id == -1)
        return (sum == 0) ? 1 : 0;
    if(dp[id][sum][tight] > -1 && tight == 0)
        return (dp[id][sum][tight]) % mod;
    long long res = 0, k1 = (tight == 0) ? 9 : digit[id];
    for(int i = 0; i <= k1; i++){
        int newt = (i == digit[id]) ? tight : 0;
        res = (res + getsum(id - 1, (sum + i) % k, newt)) % mod;
    }
    if(tight == 0)
        dp[id][sum][tight] = res % mod;
    return res % mod;
}

long long query(string l, string r){
    memset(dp, -1, sizeof(dp));
    getdigit(l);
    long long a = getsum(digit.size() - 1, 0, 1);
    getdigit(r);
    long long b = getsum(digit.size() - 1, 0, 1);
    return (b - a + mod) % mod;
}

/// End of template

string r;
main(){
    cin >> r >> k;
    cout << query("0", r);
}


Measured memory_bytes: 25728