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

using namespace std;
using ll = long long;
using ld = long double;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

mint choose(int n,int a){
    mint x=1;
    mint y=1;
    for(int i = 0; i < a; i++) {
        x*=n-i;
        y*=i+1;
    }
    return x/y;
}

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    vector<int> cnt(26,1);
    for(int i = 0; i < n; i++) {
        cnt[s[i]-'a']++;
    }
    mint ans = 1;
    for(int i = 0; i < 26; i++) {
        ans=ans*cnt[i];
    }
    cout << ans-1 << "\n";
    return 0;
}


Measured memory_bytes: 3700
#include<stdio.h>
#include<math.h>
int main(){
  long long n,temp;
  int min=0,num,i;
  scanf("%lld",&n);
  temp=n;
  while(temp!=0){
    min++;
    temp/=10;
  }
  int sqrt=sqrtl(n);
  for(i=2;i<=sqrt+1;i++){
    if(n%i==0){
      num=0;
      temp=n/(long long)i;
      while(temp!=0){
        num++;
        temp/=10;
      }
      if(num<min)
        min=num;
    }
  }
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 2152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#include <queue>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf INT_MAX
#define mod 1000000009
using namespace std;

inline int FastI() {
	char c = ' '; int a = 0;
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) {
		a *= 10;
		a += c - '0';
		c = getchar();
	}
	return a;
}

int main() {
	speed;
	int n, m, c;
	cin >> n >> m >> c;
	vector<int>v(m);
	for (int i = 0; i < m; ++i) {
		cin >> v[i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int s = 0, a;
		for (int j = 0; j < m; ++j) {
			cin >> a;
			s += a * v[j];
		}
		s += c;
		ans += bool(s > 0);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int NN=100*1000+10;
int rep[NN];
int stamp[NN];
int weight[NN];
int N,M,K,Q;
vector<int> path[NN];
vector<int> len[NN];
int Find(int p){
	while(p!=rep[p])
		p=rep[p];
	return p;
}
vector<int> events;
void Union(int a, int b, int s){
	a=Find(a);
	b=Find(b);
	if(a==b)return;
	if(weight[a]<weight[b]){
		swap(a,b);
	}
	rep[b]=a;
	stamp[b]=events.size();
	events.push_back(s);
	weight[a]+=weight[b];
}

int dist[NN];
int main() {
	cin >> N >> M >> K >> Q;
	for(int i=0;i<M;i++){
		int a,b,l;
		cin >> a >> b >> l;
		path[a].push_back(b);
		len[a].push_back(l);
		path[b].push_back(a);
		len[b].push_back(l);
	}
	priority_queue<P,vector<P>,greater<P> > q;
	for(int i=1;i<=N;i++){
		dist[i]=1<<30;
	}
	for(int i=0;i<K;i++){
		int a;
		cin >> a;
		q.push(P(0,a));
		dist[a]=0;
	}
	while(q.size()){
		int d=q.top().first;
		int s=q.top().second;
		q.pop();
		if(dist[s]<d)continue;
		for(int i=0;i<path[s].size();i++){
			int t=path[s][i];
			int l=len[s][i];
			if(dist[s]+l<dist[t]){
				dist[t]=dist[s]+l;
				q.push(P(dist[s]+l,t));
			}
		}
	}
	vector<P> ds;
	for(int i=1;i<=N;i++){
		ds.push_back(P(dist[i],i));
		rep[i]=i;
		stamp[i]=1<<30;
		weight[i]=1;
	}
	sort(ds.begin(),ds.end());
	for(int i=ds.size()-1;i>=0;i--){
		int s=ds[i].second;
		for(auto t:path[s]){
			if(P(dist[t],t)>ds[i]){
				Union(s,t,ds[i].first);
			}
		}
	}
	for(int i=0;i<Q;i++){
		int s,t;
		cin >> s >> t;
		int v=0;
		while(s!=t){
			if(stamp[s]>stamp[t]){
				swap(s,t);
			}
			v=stamp[s];
			s=rep[s];
		}
		cout << events[v] << endl;
	}
}

Measured memory_bytes: 17360
n, m = gets.split.map(&:to_i)
sc = Array.new(m){gets.split.map(&:to_i)}
ans = '*' * n
sc.each do |s, c|
  if ans[s-1] == '*'
    ans[s-1] = c.to_s 
  elsif ans[s-1] != c.to_s
    ans[s-1] = 'X'
  end
end
if ans[0] == '*'
  if n == 1
    ans[0] = '0'
  else
    ans[0] = '1'
  end
end
if n > 1
  (1..n-1).each do |i|
    ans[i] = '0' if ans[i] == '*'
  end
end
if ans.include?('X')
  puts '-1'
elsif ans.start_with?('0') && n > 1
  puts '-1'
else
  puts ans
end


Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

// Use g++ compiler for this include to work.
#include <bits/stdc++.h>

using namespace std;

// Constants 
#define INF 1e18
#define EPS 1e-9
#define MOD 1000000007
 
// // for using in pairs
#define F first
#define S second
 
// Macros
#define all(x) begin(x), end(x)
 
// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

// Temporary macro.
#define int long long

// Operator overloads.
/**
 * The type of element in the vector should have overload for << operator with ostream. 
 */
template<typename T>
ostream& operator<<(ostream &stream, vector<T> v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

/**
 * Both types in the pair should have overload for << operator with ostream. 
 */
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, pair<T1, T2> p)
{
	ostream << p.first << " " << p.second;
	return ostream;
}

template<typename T>
void swap(T &a, T &b)
{
	T t = a;
	a = b;
	b = t;
}

// Utility functions.
void swap(int &a, int &b)
{
	int t = a;
	a = b;
	b = t;
}

int GCD(int a, int b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}

int LCM(int a, int b)
{
	return (a * b) / GCD(a, b);
}

int modpow(int x, int n, int m = MOD)
{
	if (n == 0) return 1 % m;
	long long u = modpow(x, n / 2, m);
	u = (u * u) % m;
	if (n % 2 == 1)
		u = (u * x) % m;
	return u;	
}

//////////////////// START CODE HERE ///////////////////////////


void solve(int tc)
{
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];

	int dp[n + 1][3];
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;


	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i - 1];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i - 1];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i - 1];
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << "\n";
}

int32_t main()
{	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

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

	int t = 1;
	// cin >> t;		
	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


Measured memory_bytes: 8284
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    string t = "";
    REP(i, s.length()){
        if(i % 2 == 0){
            t = t + s[i];
        }
    }
    cout << t << endl;
    return 0;
}

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


int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  int Co = 60 * H + M;
  double x, y;
  x = Co * M_PI / 360;
  y = M * M_PI / 30;
  double answer = sqrt(A * A + B * B 
                       - 2 * A * B * cos(x - y));
  cout << fixed << setprecision(20);
  cout << answer << endl;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 2019;
int INF = (int)2e18;

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


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

using namespace std;
const ll maxn=2e4+100,inf=1e9,LOG=23,mod=1e9+7;
int block = 300, timer = 0;
const ld EPS = 1e-7;

#define bt(i) (1 << (i))
#define int ll
#define pii pair <int, int>

int n, d, p[maxn][11], dp[maxn][110], al[maxn][110];

main()
{
	string s;
	cin >> s >> d;
	forn(0, i, 9)
	{
		dp[1][i % d]++;
	}
	forn(2, i, 10000)
	{
		forn(0, os, d - 1)
		{
			forn(0, j, 9)
			{
				dp[i][(os + j) % d] += dp[i - 1][os];
				dp[i][(os + j) % d] %= mod;
			}
		}
	}
	n = s.size();
	s = '#' + s;
	int T = 0;
	int ans  = 0;
	forn(1, i, n - 1)
	{
		forn(0, j, s[i] - '0' - 1)
		{
			/*int S = d - j - T;
			while(S < 0)
			{
				S += d;
			}*/
			ans += dp[n - i][(d - j + d - T) % d];
			ans %= mod;
		}
		T += s[i] - '0';
		T %= d;
	}
	forn(0, i, s[n] - '0')
	{
		if((i + T) % d == 0)
		{
			ans++;
			ans%=mod;
		}
	}
	cout << (ans - 1 + mod) % mod;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<char>S(3);
  vector<char>T(3);
  for(int i=0;i<3;i++){
    cin >> S.at(i);
  }
  for(int i=0;i<3;i++){
    cin >> T.at(i);
  }
  int count =0;
  for(int i=0;i<3;i++){
    if (S.at(i)==T.at(i)){
      count++;
    }
  }
  cout << count <<endl;
}  
  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

y, m, d = map(int, input().split("/"))

heisei = True
if y < 2019:
    heisei = True
elif y == 2019:
    if m < 4:
        heisei = True
    elif m == 4:
        if d <= 30:
            heisei = True
        else:
            heisei = False
    else:
        heisei = False
else:
    heisei = False

if heisei is True:
    print("Heisei")
else:
    print("TBD")


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<queue>
using namespace std;

struct edge{
  edge(){};
  edge(int to,int cost){
    p=to;
    c=cost;
  }
  int p,c;
};
bool operator<(edge a,edge b){
  return a.c>b.c;
}
int s,e,money,pay;
vector<vector<edge> > edges;


void init(){
  edges.clear();
}

bool input(){
  char t;
  int n;
  if(!(cin>>n))return false;
  edges.resize(n);
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int a,b,c,d;
    cin>>a>>t>>b>>t>>c>>t>>d;
    a--;b--;
    edges[a].push_back(edge(b,c));
    edges[b].push_back(edge(a,d));
  }
  cin>>s>>t>>e>>t>>money>>t>>pay;
  s--,e--;
  return true;
}

int path_cost(int start,int end){
  priority_queue<edge> q;
  vector<int> dp(edges.size());
  for(int i=0;i<dp.size();i++){
    dp[i]=-1;
  }
  q.push(edge(start,0));
  while(!q.empty()){
    edge now = q.top();q.pop();
    
    if(dp[now.p]!=-1)continue;
    dp[now.p]=now.c;
    
    if(now.p==end)return now.c;
    
    for(int i=0;i<edges[now.p].size();i++){
      edge to = edges[now.p][i];
      q.push(edge(to.p,now.c+to.c));
    }

  }
  return dp[end];
}


int solve(){
  int tmp=0;
  tmp += path_cost(s,e);
  tmp += path_cost(e,s);
  return money - tmp - pay;
}


int main(){
  while(init(),input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define ull unsigned long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define meme(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define mod 1'000'000'007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
} 

int dp[100000][3];

int zzsum(int arr[][3],int n,int i,int j){
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(i==n-1){
        return (dp[i][j] = arr[i][j]);
    }
    int res=0;
    for(int q=0;q<3;q++){
        if(q!=j){
            res=max(res,arr[i][j]+zzsum(arr,n,i+1,q));
        }
    }
    return (dp[i][j]=res);
}

int zs(int arr[][3],int n){
    int i;
    memset(dp,-1,sizeof(dp));
    int sum=0;
    fo(i,3){
        sum = max(sum,zzsum(arr,n,0,i));
    }
    return sum;
}

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int n,i;
    cin>>n;
    int arr[n][3];
    fo(i,n){
        cin>>arr[i][0];
        cin>>arr[i][1];
        cin>>arr[i][2];
    }
    cout<<zs(arr,n)<<"\n";
}


Measured memory_bytes: 15288
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    s=input()
    if s[0]==s[1] and s[2]==s[3] and len(set(s))==2:
        print("Yes")
    elif s[0]==s[2] and s[1]==s[3] and len(set(s))==2:
        print("Yes")
    elif s[0]==s[3] and s[1]==s[2] and len(set(s))==2:
        print("Yes")
    
    else:
        print("No")
if __name__ == '__main__':
    main()

Measured memory_bytes: 5076
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    if((s.size()%2==0)^(s[0]==s[s.size()-1])){
        cout1("Second");
    }else{
        cout1("First");
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 2 != b % 2) {
        cout << "IMPOSSIBLE";
    }
    else {
        cout << ((a + b) / 2);
    }
}


Measured memory_bytes: 256
N = int(input())
d = [-1] * N
a = []
x = [[0, 0] for _ in range(N)]
cnt = 0
def dfs(v):
    global cnt
    if v == N:
        cntF = True
        for i in range(N):
            if d[i] != 1:
                continue
            for j in range(len(a[i])):
                if a[i][j][1] != d[a[i][j][0] - 1]:
                    cntF = False
                    break
            if cntF == False:
                break

        if cntF:
            cnt = max(cnt, sum(d))
        return

    d[v] = 0
    dfs(v + 1)
    d[v] = 1
    dfs(v + 1)
    return

for i in range(N):
    tmp = int(input())
    tmplst = [[0, 0] for _ in range(tmp)]
    for j in range(tmp):
        x1, y1 = map(int, input().split())
        tmplst[j][0] = x1
        tmplst[j][1] = y1
    a.append(tmplst)
dfs(0)
print(cnt)

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

#define F first
#define S second
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl

using namespace std;

typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;



int main() {
#define TASK "A"
#ifdef HOME 
    assert(freopen(TASK".in", "r", stdin));
#endif
    int a, b, c;
    cin >> a >> b >> c;
    int mx = max(a, max(b, c));
    int sum = a + b + c;
    int res = 0;
    if ((mx * 3 - sum) % 2 == 1) {
        mx++;
    }

    res = (mx * 3 - sum) / 2;
    cout << res << endl;


    return 0;
}



Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val s = cin.next()
    var l = Array<Char>(2, { s[0] })
    var count = Array<Int>(2, { 1 })
    var ok = true
    for (i in 1..3) {
        if (l[0] == s[i]) {
            count[0] += 1
        } else {
            if (l[1] == s[0]) {
                l[1] = s[i]
            } else if (l[1] == s[i]) {
                count[1] += 1
            } else {
                ok = false
            }
        }
    }
    if (count[0] != 2 || count[1] != 2) {
        ok = false
    }
    if (ok) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 31400
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,Q;
  cin>>N>>Q;
  string S;
  cin>>S;
  int l[N],r[N];
  REP(i,Q)cin>>l[i]>>r[i];
  int m[N];
  m[0]=0;
  FOR(i,1,N){
    if(S[i-1]=='A' and S[i]=='C')m[i]=m[i-1]+1;
    else m[i]=m[i-1];
  }
  REP(i,Q)cout<<m[r[i]-1]-m[l[i]-1]<<endl;
  return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;

int main(){
    int n,l;cin>>n>>l;
    priority_queue<string,vector<string>,greater<string> > S;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        S.push(s);
    }
    string ans;
    for(int i=0;i<n;i++){
        ans+=S.top();S.pop();
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=2000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll nPk(ll n,ll k){
	return nCk(n,k)*F[k]%mod;
}

ll n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	int t=0;
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) for(int k=j+1;k<n;k++){
		if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]&&a[i]<a[j]+a[k]&&a[i]>abs(a[j]-a[k])) t++;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 3648
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[200005]={},t,ans=0;
  cin >> n >> t;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n-1; i++) {
    if(a[i+1]-a[i]>t) {
      ans+=t;
    }
    else {
      ans+=a[i+1]-a[i];
    }
  }
  ans+=t;
  cout << ans << endl;
}

Measured memory_bytes: 1792
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;

int N = 100;

int main(){
    int m[N+1][N+1];
    int n;
    cin >> n;
    for (int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            m[i][j] = 0;
        }
    }
    for (int i=1;i<=n;i++){
        int p,r; cin >> r >> p;
        for (int j=1;j<=p;j++){
            int q;
            cin >> q;
            m[r][q] = 1;
        }
    }

    for (int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j-1) cout << " ";
            cout << m[i][j];
        }
        cout << endl;
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, long long Q, std::vector<long long> A,
           vector<long long> B)
{
    rep(i, N)
    {
        long long ans = K - Q + B[i];
        if (ans <= 0)
            cout << NO << endl;
        else
            cout << YES << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> A(Q);
    vector<long long> B(N);
    for (int i = 0; i < Q; i++)
    {
        scanf("%lld", &A[i]);
        B[A[i] - 1]++;
    }
    solve(N, K, Q, std::move(A), move(B));
    return 0;
}


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

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

  int sum = 0;
  if (a <= k) {
    sum += a * 1;
    k -= a;
  } else {
    sum += k * 1;
    k -= k;
  }

  if (b <= k) {
    k -= b;
  } else {
    k -= k;
  }

  if (k > 0) {
    sum = sum - k;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3636
import sys
from statistics import *
from collections import *
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
a1 = na()
a2 = na()
s1 = a1[0]
s2 = sum(a2)
ans = s1 + s2
for i in range(1, n):
    s1 += a1[i]
    s2 -= a2[i-1]
    ans = max(ans, s1 + s2)
print(ans)

Measured memory_bytes: 5276
// 1
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

class Tenki {
 private:
  std::string prediction;
  std::string real;
  int count = 0;

 public:
  Tenki() {
    std::getline(std::cin, prediction);
    std::getline(std::cin, real);
    for (int i = 0; i < 3; i++) {
      if (prediction.at(i) == real.at(i))
        count++;
    }
    std::printf("%d\n", count);
  }
};

int main() {
  Tenki t;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<iostream>
#include<math.h>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>


using namespace std;

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

int main()
{
#ifdef overlord
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;
	cout << 180 * (n - 2);

	return 0;
}

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

void dfs(int n, string s, vector<map<string, ll>>& r, string a, string b) {
  int i = a.size() + b.size();
  if (i == n) {
    reverse(begin(b), end(b));
    r[a.size()][a + b]++;
    return;
  }
  a.push_back(s[i]);
  dfs(n, s, r, a, b);
  a.pop_back();
  b.push_back(s[i]);
  dfs(n, s, r, a, b);
}

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

  vector<map<string, ll>> u(n + 1), v(n + 1);
  dfs(n, s, u, "", "");
  reverse(begin(s), end(s));
  dfs(n, s, v, "", "");

  ll m = 0;
  for (int i = 0; i < n + 1; i++) {
    for (auto e : u[i]) {
      m += e.second * v[i][e.first];
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 82688
#include <bits/stdc++.h>
using namespace std;
/*
  l:テ・ツキツヲテァツォツッ
  r:テ・ツ渉ウテァツォツッ
  h:テァツ渉セテ・ツ慊ィテ」ツ?ョテヲツーツエテ、ツスツ?
  w:1テァツァツ津」ツ?づ」ツ?淌」ツつ甘」ツ?ョテヲツーツエテ」ツ?ョテゥツ??
  lkabe:テ・ツキツヲテ」ツ?ョテ・ツ」ツ?」ツ?ョテゥツォツ佚」ツ??
  rkabe:テ・ツキツヲテ」ツ?ョテ・ツ」ツ?」ツ?ョテゥツォツ佚」ツ??
*/
const double EPS = 1e-8; 
struct dat{double l,r,h,w,lkabe,rkabe;};
typedef pair<double,double> P;
typedef pair<P,int> PP;
vector<dat> A;

double getMinTime(){
  double res = 1e9;
  for(dat a:A){
    if(a.w==0)continue;
    double t = ((min(a.lkabe,a.rkabe) - a.h)*(a.r-a.l)*30)/a.w;
    res = min(res,t);
  }
  return res;
}

dat Merge(dat l,dat r){
  dat res;
  res.l = l.l;
  res.r = r.r;
  res.h = min(r.h,l.h);
  res.w = l.w + r.w;
  res.lkabe = l.lkabe;
  res.rkabe = r.rkabe;
  return res;
}

bool replace(int idx,int flg){
  A[idx+flg].w += A[idx].w;
  A[idx].w = 0;
  if(abs(A[idx+flg].h-A[idx].h)>EPS) return 0 ;
  if(flg == 1) A[idx] = Merge(A[idx],A[idx+1]);
  if(flg == -1)A[idx] = Merge(A[idx-1],A[idx]);
  A.erase(A.begin()+idx+flg);
  return 1;
}

void adTime(double sec){
  for(int i=0;i<(int)A.size();i++){
    if(A[i].w==0)continue;
    A[i].h += (sec*A[i].w)/(30*(A[i].r-A[i].l));
  }

  int update = 1;
  while(update){
    update = 0;
    for(int i=0;i<(int)A.size();i++){
      if(A[i].w==0)continue;
      
      if(A[i].lkabe<=A[i].h+EPS){ update=1,replace(i,-1);break;}
      else if(A[i].rkabe<=A[i].h+EPS) { update=1,replace(i,1);break;}
    } 
  }
}

void sim(double t){
  while(t){
    double sec = min(t,getMinTime());
    assert(sec>=0);
    adTime(sec);
    t -=sec;
  }
}


double getH(int x){
  for(int i=0;i<(int)A.size();i++) if(A[i].l<x && x<A[i].r) return A[i].h;
  return -1;
}

int main(){
  int q;
  cin>>q;
  while(q--){
    int n;
    cin>>n;
    A.resize(n+1);
    double l=0,r,lkabe=1e15,rkabe;
    for(int i=0;i<n; i++,l=r,lkabe = rkabe){
      cin>>r>>rkabe;
      A[i] = (dat){l,r,0,0,lkabe,rkabe};
      if(i==n-1) A[n] = (dat){r,100,0,0,rkabe,1e15};
    }
    
    int m;
    cin>>m;
    for(int i=0,x,w;i<m;i++){
      cin>>x>>w;
      for(dat &a:A) if(a.l<x&&x<a.r)a.w+=w;
    }
    int L;
    cin>>L;
    vector<PP> que(L);
    for(int i=0;i<L;i++)cin>>que[i].first.second>>que[i].first.first,que[i].second = i;
    sort(que.begin(),que.end());
    
    vector<double>ans(L);
    int sec=0;
    for(int i=0;i<L;i++){
      double x =que[i].first.second,t = que[i].first.first;
      int idx = que[i].second;
      sim(t-sec);
      ans[idx] = min(50.0,getH(x));
      sec = t;
    }

    for(int i=0;i<L;i++)printf("%.8f\n",ans[i]);
  }
  return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

class largeInt{
public:
	largeInt() : digit( 0 ){
		initNum();
	}
	~largeInt(){}

	void set( const string& s ){
		numStr = s;
		initNum();
		digit = numStr.size();
		if ( digit > 80 ) return;
		StoI();
	}
	const char* getFigure(){ return numStr.c_str(); }
	const int getDigit(){ return digit; }

	void operator+=( const largeInt& a ){
		numStr = "";
		for ( int i = 0; i < 10; ++i ){
			num[ i ] += a.num[ i ];
			if ( num[ i ] / 100000000 && i != 9 ){
				num[ i ] -= 100000000;
				num[ i + 1 ] += 1;
			}
			int t = num[ i ];
			string s;
			for ( int j = ( i == 9 ? 8 : 7 ); j >= 0; --j ){
				int power = static_cast< int >( pow( 10.0, static_cast< double >( j ) ) );
				int c = t / power;
				t %= power;
				s += static_cast< char >( c + '0' );
			}
			numStr = s + numStr;
			if ( i == 9 ){
				string::iterator it = numStr.begin();
				while ( ( *it == '0' ) && ( it != numStr.end() - 1 ) ){
					it = numStr.erase( it );
				}
			}
		}
		digit = numStr.size();
	}

private:
	void initNum(){
		for ( int i = 0; i < 10; ++i ){
			num[ i ] = 0;
		}
	}
	void StoI(){
		bool f = false;
		for ( int i = 0; i < digit / 8; ++i ){
			for ( int j = 0; j < 8; ++j ){
				if ( i*8 + j >= digit ){
					f = true;
					break;
				}else{
					conv( i, j );
				}
			}
			if ( f ) break;
		}
		for ( int i = 0; i < digit % 8; ++i ){
			conv( digit / 8, i );
		}
	}
	void conv( int i, int j ){
		int figure = static_cast< int >( numStr[ ( digit - 1 ) - ( i*8 + j ) ] - '0' );
		int power = static_cast< int >( pow( 10.0, static_cast< double >( j ) ) );
		num[ i ] += figure * power;
	}

	unsigned num[10];
	int digit;
	string numStr;
};

int main(){
	int n;
	string s;

	cin >> n;

	largeInt* a = new largeInt[ n ];
	largeInt* b = new largeInt[ n ];

	for ( int i = 0; i < n; ++i ){
		cin >> s;
		a[ i ].set( s );
		cin >> s;
		b[ i ].set( s );
	}

	for ( int i = 0; i < n; ++i ){
		if ( a[ i ].getDigit() > 80 || b[ i ].getDigit() > 80 ){
			cout << "overflow" << endl;
			continue;
		}
		a[ i ] += b[ i ];
		cout << ( a[ i ].getDigit() > 80 ? "overflow" : a[ i ].getFigure() ) << endl;
	}

	delete[] a;
	delete[] b;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int a;
    cin >> a;
    if (a == 1)
        cout << "Hello World";
    else
    {
        int x, y;
        cin >> x >> y;
        cout << x + y;
    }
    return 0;
}


Measured memory_bytes: 256
l = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
ans = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

for bb in b:
    for i in range(3):
        for j in range(3):
            if l[i][j] == bb:
                ans[i][j] = 1

if ans[0][0] == ans[1][1] == ans[2][2] == 1:
    print('Yes')
elif ans[0][2] == ans[1][1] == ans[2][0] == 1:
    print('Yes')
elif ans[0][0] == ans[1][0] == ans[2][0] == 1:
    print('Yes')
elif ans[0][1] == ans[1][1] == ans[2][1] == 1:
    print('Yes')
elif ans[0][2] == ans[1][2] == ans[2][2] == 1:
    print('Yes')

elif ans[0][0] == ans[0][1] == ans[0][2] == 1:
    print('Yes')
elif ans[1][0] == ans[1][1] == ans[1][2] == 1:
    print('Yes')
elif ans[2][0] == ans[2][1] == ans[2][2] == 1:
    print('Yes')

else:
    print('No')


Measured memory_bytes: 9112
import sys
input = sys.stdin.readline
def readlines(n):
    for _ in range(n):
        yield list(map(int, input().split()))

def main():
    h, w = map(int, input().split())

    C = list(readlines(10))

    for k in range(10):
        for i in range(10):
            for j in range(10):
                C[i][j] = min(C[i][j], C[i][k] + C[k][j])

    for line in readlines(h):
        yield sum(C[c][1] for c in line if c != -1) 


print(sum(main()))


main()

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int ab, bc, ca;
  cin >> ab >> bc >> ca;
  cout << ab * bc / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int mod = 1e9+7;
long frac(int n){
    if(n==0) return 0;
    long m=1;
    for(int i=1;i<=n;i++){
        m *= i;
        m%=mod;
    }
    return m;
}
int main(){
    int n,m;
    cin >> n >> m;
    if(abs(n-m)>1) cout << 0 << endl;
    else{
        long ans = 0;
        ans = frac(n)*frac(m)%mod;
        if(n==m) ans *= 2;
        cout << ans%mod << endl;
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int result = 1;
  for (int i = 0; i < N; i++) {
    int plus_k, times_2;
    plus_k = result + K;
    times_2 = result * 2;
    
    if (plus_k < times_2) {
      result = plus_k;
    }
    else {
      result = times_2;
    }
  }
  
  cout << result << endl;
}


Measured memory_bytes: 256
G[10000],v[10000];i,a,b;main(N){for(;scanf("%d",&N)*N;printf("%d\n",b)){for(i=0;b=i<N*N;G[i++]=a+b*N)v[i]=scanf("%d%d",&a,&b)-3;for(;i--;b+=v[a]==i)for(a=i;!~v[a];a=G[a])v[a]=i;}}

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

int n;
int st[4],a;
double  dp[300+10][300+10][300+10];


double solve(int a,int b,int c)
{
	if(a+b+c==0)
	{
		return 0.00;
	}
	if(dp[a][b][c]>-0.5)return dp[a][b][c];
	
	double ks=(double)n/(a+b+c);
	double ret=0;
	if(a)
	{
		ret+=(solve(a-1,b,c)+ks)*(a)/(a+b+c);
	}
	if(b)
	{
		ret+=(solve(a+1,b-1,c)+ks)*(b)/(a+b+c);
	}
	if(c)
	{
		ret+=(solve(a,b+1,c-1)+ks)*(c)/(a+b+c);
	}
	return dp[a][b][c]=ret;
}


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>a;
    	st[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;
		
	}
	double ret=solve(st[1],st[2],st[3]);
	
	cout<<fixed<<setprecision(12)<<ret<<endl;
	return 0;
}

Measured memory_bytes: 227584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll a,b,c,d,e,f,x,y;
int main(void){
    cin>>a>>b>>c>>d>>e>>f;
    x=(c-e)*a;
    y=(d-f)*b;
    if(x<0)x*=-1LL,y*=-1LL;
    if(x+y==0){
		cout<<"infinity"<<endl;
		return 0;
	}
	if(x+y>0){
		cout<<0<<endl;
		return 0;
	}
	ll p=-x-y;
	if(x%p==0){
		cout<<x/p*2LL<<endl;
	}else{
		cout<<x/p*2LL+1LL<<endl;
	}
}


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

int linearSearch(int x, vector<int> s) {
  for (int i = 0; i < s.size(); i++) {
    if (x == s[i]) return 1;
  }
  return 0;
}

int main() {
  int n, q, tmp;
  vector<int> S;
  vector<int> T;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    S.push_back(tmp);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &tmp);
    T.push_back(tmp);
  }

  int count = 0;
  for (int i = 0; i < T.size(); i++) {
    count += linearSearch(T[i], S);
  }

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


Measured memory_bytes: 2776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<int,int>> p(n);
    for(auto& i:p) cin>>i.sd>>i.ft;
    sort(p.begin(),p.end());
    int nw=0;
    fr(i,n){
        nw+=p[i].sd;
        if(nw>p[i].ft){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
	int x,ans,y;

	while(scanf("%d",&x)!=EOF){
		if(x==0)break;
		ans=0;	y=5;
		while(1){
			if(x/y==0)break;
			ans+=x/y;
			y*=5;
		}
		printf("%d\n",ans);
		
	}
	
	return 0;
}


Measured memory_bytes: 2140
// sandeep_007  
#include <bits/stdc++.h>
 
using namespace std; 
 
#define PI acos(-1)
#define mod 1000000007
#define ll long long
#define nitro std::ios_base::sync_with_stdio (false); cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define vi vector < int >
#define md 998244353
#define rep(i,a,b) for(int i=a;i<b;i++)
#define FF first
#define SS second
#define all(a) (a).begin(),(a).end()

int main () {
    nitro;
 
    #ifdef DBG
        freopen("in","r",stdin);
    #endif
   
   	int n,m1; cin >> n >> m1;
   	map<int,int> m;
   	rep(i,0,n){
   		int k; cin >> k;
   		rep(j,0,k){
   			int a; cin >> a;
   			if(m.find(a) == m.end()) m[a] = 1;
   			else m[a] += 1;
   		}
   	}
   	
   	int ans = 0;
   	for(auto x : m){
   		if(x.SS == n) ans++;
   	}
   	cout << ans << endl;
    return 0;
}   

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int N,i,count=0;
    char A[101],B[101],C[101];
    scanf("%d",&N);
    scanf("%s",A);
    scanf("%s",B);
    scanf("%s",C);
    for(i=0;i<N;i++){
        if(A[i]!=B[i] && B[i]!=C[i] && C[i]!=A[i]){
            count+=2;
        }else if(A[i]==B[i] && B[i]==C[i]){
            continue;
        }else{
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
//43
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int a[100];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int ans=0;
    int f=0,l=n-1;
    int g;
    cin>>g;
    for(;;){
      int m=f+(l-f)/2;
      if(l-f<0){
	break;
      }else{
	ans++;
	if(a[m]==g){
	  break;
	}else if(a[m]>g){
	  l=m-1;
	}else{
	  f=m+1;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int K, T;
	cin >> K >> T;
	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (T == 1) {
		cout << K - 1 << endl;
		return 0;
	}
	vector<int>a(T);

	for (int i = 0; i < T; i++) {
		cin >> a[i];
	}

	int fIndex = 0;
	int sIndex = 1;
	if (a[0] < a[1]) {
		fIndex = 1;
		sIndex = 0;
	}

	for (int i = 0; i < K / 2; i++) {

		for (int j = 0; j < a.size(); j++) {
			if (a[j] > a[fIndex]) {
				sIndex = fIndex;
				fIndex = j;
			}
			else if (a[j] > a[sIndex] && j != fIndex) {
				sIndex = j;
			}
		}

		if (a[sIndex] == 0) {
			cout<<a[fIndex] - 1;
			return 0;
		}

		a[fIndex]--;
		a[sIndex]--;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct{
  vector<int> vec;//左上から時計回り
  int cnt;
  int exist;//0=存在しない調べてない 1=存在してる 2=存在しない調べた
}Bill;
void dfs(int y,int x);
int ans=0;
Bill bill[103][103];
int kdx[6]={0,1,1,1,0,-1};
int gdy[6]={-1,-1,0,1,1,0};
int gdx[6]={-1,0,1,0,-1,-1};
int taimen[6]={3,4,5,0,1,2};
int h,w;
int cntbill[103][103]={0};
main(){
  cin>>w>>h;
  for(int i=0;i<=102;i++){
    for(int j=0;j<=102;j++){
      for(int k=0;k<6;k++){
	bill[i][j].vec.push_back(0);
      }
      bill[i][j].cnt=0;
      bill[i][j].exist=0;
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>bill[i][j].exist;
    }
  }
  //深さで穴を調べて、そこをビルがあることにする。
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(i==1||i==h||j==1||j==w){
	if(bill[i][j].exist==0){
	  dfs(i,j);
	}
	else if(bill[i][j].exist==1){
	  for(int k=0;k<6;k++){
	    int nnx;
	    if(i%2==0){
	      nnx=j+gdx[k];
	    }
	    else{
	      nnx=j+kdx[k];
	    }
	    int nny=i+gdy[k];
	    if(nnx<=0||nnx>w||nny<=0||nny>h){
	      //cout<<nnx<<" "<<nny<<endl;
	      ans++;
	      cntbill[i][j]++;
	    }
	  }
	}
      }
      /*
      cout<<j<<" "<<i<<endl;
      for(int i=1;i<=h;i++){
	for(int j=1;j<=w;j++){
	  cout<<cntbill[i][j]<<" ";
	}
	cout<<endl;
      }
      cout<<endl;
      */
    }
  }
  /*
  cout<<endl;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cout<<cntbill[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
  */
  cout<<ans<<endl;
}
void dfs(int y,int x){
  if(bill[y][x].exist==1){
    return;
  }
  //cout<<x<<'-'<<y<<endl;
  bill[y][x].exist=2;
  for(int k=0;k<6;k++){
    int nx;
    if(y%2==0){
      nx=x+gdx[k];
    }
    else{
      nx=x+kdx[k];
    }
    int ny=y+gdy[k];
    //cout<<nx<<" "<<ny<<endl;
    if(nx>0&&nx<=w&&ny>0&&ny<=h){
      if(bill[ny][nx].exist==0){
	dfs(ny,nx);
      }
      else if(bill[ny][nx].exist==1&&bill[ny][nx].vec[taimen[k]]==0){
	ans++;
	cntbill[ny][nx]++;
	bill[ny][nx].vec[taimen[k]]=1;
      }
    }
  }
  return;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;

    if(s == u){
        a--;
    }else if(t == u){
        b--;
    }

    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d1,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,t;
bool fl;
struct edge{int to,cost;};
ll r1,l1,u1;
ll r2,l2,u2,d2;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>h>>w>>n>>y>>x>>s>>t;
    ll nowx=x,nowy=y;
    rep(i,n){
        if(s[i]=='R')nowx++;
        if(nowx==0||nowx==w+1){
            Cout("NO");
            return 0;
        }
        if(t[i]=='L'&&nowx!=1)nowx--;
    }

    nowx=x,nowy=y;
    rep(i,n){
        if(s[i]=='L')nowx--;
        if(nowx==0||nowx==w+1){
            Cout("NO");
            return 0;
        }
        if(t[i]=='R'&&nowx!=w)nowx++;
    }

    nowx=x,nowy=y;
    rep(i,n){
        if(s[i]=='U')nowy--;
        if(nowy==0||nowy==h+1){
            Cout("NO");
            return 0;
        }
        if(t[i]=='D'&&nowy!=h)nowy++;
    }

    nowx=x,nowy=y;
    rep(i,n){
        if(s[i]=='D')nowy++;
        if(nowy==0||nowy==h+1){
            Cout("NO");
            return 0;
        }
        if(t[i]=='U'&&nowy!=1)nowy--;
    }
    Cout("YES");
    return 0;
}


Measured memory_bytes: 920