akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max()/2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<Edge>>g;
vector<edge>edges;
vector<Pll>v;
map<string, LL>ma;
multiset<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000],d[10000];
string str, ss;
bool f[110000];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
int main() {
	cin >> n >> m >> p;
	rep(i, m) {
		LL x, y, z;
		cin >> x >> y >> z;
		x--, y--;
		edges.push_back(edge{ x,y,-(z - p) });
	}
	rep(i, 10000)d[i] = INF;
	d[0] = 0;
	for (int i = 0; i < 40000; i++) {
		for (int j = 0; j < (int)edges.size(); j++) {
			struct edge e = edges[j];
			if(d[e.from]!=INF)
			if (d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが小さいと、頂点のコストを更新
				d[e.to] = d[e.from] + e.cost;
				if (i > 20000 &&e.to==n-1) {         //頂点の数と同じ回数ループすると、負の閉路があるのでループをぬける
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	cout << max(0LL,-d[n - 1]) << endl;
	return 0;
}


Measured memory_bytes: 576
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;



int main() {
    int d,i,j,k;
    int c[26];
    int s[365][26];
    cin >> d;
    for(i = 0; i < 26; ++i) cin >> c[i];
    for(i = 0; i < d; ++i) for(j = 0; j < 26; ++j) cin >> s[i][j];

    int arr[365] = {};

    int t1,t2,s1,s2, diff, count;
    count = 0;
    int max, loc;
    int a[26] = {};
    int b[26] = {};
    for(i = 0; i < 365; ++i) {
        for(j = 0; j < 26; ++j) {
            b[j] = s[i][j]+a[j]*a[j]*c[j];
            a[j]++;
        }
        max = *max_element(b,b+26);
        loc = find(b,b+26,max)-b;
        arr[i] = loc;
        a[loc] = 0;
    }
    
    
    while(true) {
        label1:
        for(i = 0; i < d; ++i) {
            for(j = 0; j < 26; ++j) {
                if(arr[i]==j) continue;
                if(count>20000000) goto label2;
                ++count;
                for(s1 = i+1; s1 < d; ++s1) {
                    if(arr[s1]==arr[i]) break;
                }
                for(t1 = i-1; t1 >= 0; --t1) {
                    if(arr[t1]==arr[i]) break;
                }
                for(s2 = i+1; s2 < d; ++s2) {
                    if(arr[s2]==j) break;
                }
                for(t2 = i-1; t2 >= 0; --t2) {
                    if(arr[t2]==j) break;
                }
                diff = s[i][j]-s[i][arr[i]]+(((s1-i)*(s1-i-1))/2+((i-t1)*(i-t1-1))/2-((s1-t1)*(s1-t1-1))/2)*c[arr[i]] + (-((s2-i)*(s2-i-1))/2-((i-t2)*(i-t2-1))/2+((s2-t2)*(s2-t2-1))/2)*c[j];
                if(diff>0) {
                    arr[i] = j;
                    goto label1;
                }
            }
        }
    }
    label2:
    for(i = 0; i < d; ++i) {
        cout<<(arr[i]+1)<<"\n";
    }


    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int inf = 205 * 205;
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	string s[n];
	vector<vector<int> > dist(n, vector<int>(n, inf));
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		for (int j = 0; j < n; ++j) {
			if (s[i][j] == '1') {
				dist[i][j] = 1;
			}
		}
	}
	queue<int> q;
	q.push(0);
	vector<int> col(n, -1);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int i = 0; i < n; ++i) {
			if (s[u][i] == '1') {
				if (col[i] == -1) {
					col[i] = !col[u];
					q.push(i);
				} else if (col[i] == col[u]) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i != j) {
				ans = max(ans, dist[i][j]);
			}
		}
	}
	cout << ++ans << endl;
	return 0;
}

Measured memory_bytes: 3952
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {

  val n = readInt()
  val nodes = Array.fill(n){Nil: List[Int]}
  for (_ ← 1 until n){
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt - 1)
    nodes(a) ::= b
    nodes(b) ::= a
  }
  println(
    if (calRadius(nodes) % 3 == 2) "Second" else "First"
  )

  def calRadius(tree: Array[List[Int]]): Int = {
    val distances = Array.fill(tree.length){-1 }
    val queue = mutable.Queue[Int]()
    queue.enqueue(0)
    distances(0) = 0
    while(queue.nonEmpty) {
      val current = queue.dequeue()
      for (next ← tree(current) if distances(next) == -1) {
        distances(next) = distances(current) + 1
        queue.enqueue(next)
      }
    }
    val max = distances.indices.maxBy(distances)
    distances.indices.foreach(i ⇒ distances(i) = -1)
    queue.enqueue(max)
    distances(max) = 1
    while(queue.nonEmpty){
      val current = queue.dequeue()
      for (next ← tree(current) if distances(next) == -1){
        distances(next) = distances(current) + 1
        queue.enqueue(next)
      }
    }
    distances.max
  }
}

Measured memory_bytes: 127432
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main(args: Array<String>) {
    val ints = readInts()
    println("${ints[2]} ${ints[0]} ${ints[1]}")
}


Measured memory_bytes: 37936
if __name__ == '__main__':
	n,m,X,Y = map(int,input().split())
	x = list(map(int,input().split()))
	y = list(map(int,input().split()))
 
	x_max = max(x)
	y_min = min(y)

	flg = False
	for Z in range(X+1,Y+1):
		if x_max < Z <= y_min:
			flg = True
			break

	if flg:
		print("No War")
	else:
		print("War")

Measured memory_bytes: 9184
n = int(input())

for _ in range(n):
    start, end = map(int, input().split())

    anslist = []
    if start <= 5:
        if start > end:
            [anslist.append(i) for i in range(start, end-1, -1)]
        else:
            [anslist.append(i) for i in range(start, end+1)]
    elif start < end:
        [anslist.append(i) for i in range(start, end+1)]
    else:
        [anslist.append(i) for i in range(start, 10)]
        if end <= 5:
            [anslist.append(i) for i in range(5, end-1, -1)]
        else:
            [anslist.append(i) for i in range(5, 0, -1)]
            [anslist.append(i) for i in range(0, end+1)]

    print(' '.join(str(ans) for ans in anslist))


Measured memory_bytes: 5600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();
        string t = sc.Next();

        bool ok = false;

        for (int i = 0; i < s.Length; i++)
        {
            if (s == t)
            {
                ok = true;
                break;
            }
            s = s.Substring(1) + s.Substring(0, 1);
        }

        string answer = ok ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int INF = 1e9 ;
const int maxN = 2e5 + 5;
int n;
int a[maxN];
int main()
{
	scanf("%d",&n);
	int sum = 0;
	int maxv = 0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum += a[i];
		maxv = max(maxv,a[i]);
	}
	int ans = (sum - maxv) + maxv/2;
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int, int> > p(n);
    rep(i,n)cin>>p[i].second>>p[i].first;
    sort(p.begin(), p.end());
    int t=0;
    bool x=true;
    rep(i,n){
        t+=p[i].second;
        if(t>p[i].first){x=false;break;}
    }
if(x)cout<<"Yes";
else cout<<"No";
return 0;
}

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

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

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int n;
mint ans;
vector<int> adj[200200];

int dfs(int cur, int prev = -1) {
    int sz = 1;
    mint score = mint(2).pow(n - 1) - 1;
    vector<int> parts;
    for (int to : adj[cur]) {
        if (to == prev) continue;
        int t = dfs(to, cur);
        sz += t;
        parts.push_back(t);
    }
    if (prev != -1) {
        parts.push_back(n - sz);
    }
    for (int t : parts) {
        score -= mint(2).pow(t) - 1;
    }
    ans += score;
    return sz;
}

int main() {
    cin >> n;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(0);
    ans /= mint(2).pow(n);
    cout << ans.x << endl;
}

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

constexpr int mod = 1e5;

int main() {
    int M, N, K;
    cin >> M >> N >> K;
    vector<string> v(M);
    for(int i=0; i<M; ++i) {
        cin >> v[i];
    }
    vector<vector<int>> J(M+1, vector<int>(N+1)), O(M+1, vector<int>(N+1));
    for(int i=0; i<M; ++i) {
        for(int j=0; j<N; ++j) {
            J[i+1][j+1] = v[i][j] == 'J';
            O[i+1][j+1] = v[i][j] == 'O';
        }
    }
    for(int i=0; i<M+1; ++i) {
        for(int j=0; j<N; ++j) {
            J[i][j+1] += J[i][j];
            O[i][j+1] += O[i][j];
        }
    }
    for(int j=0; j<N+1; ++j) {
        for(int i=0; i<M; ++i) {
            J[i+1][j] += J[i][j];
            O[i+1][j] += O[i][j];
        }
    }
    for(int i=0; i<K; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int res_j = J[c][d] - J[a-1][d] - J[c][b-1] + J[a-1][b-1];
        int res_o = O[c][d] - O[a-1][d] - O[c][b-1] + O[a-1][b-1];
        int res_i = (c - a + 1) * (d - b + 1) - res_j - res_o;
        cout << res_j << ' ' << res_o << ' ' << res_i << endl;
    }
}

Measured memory_bytes: 11876
n, m = map(int, input().split())
g = [[]for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b) 
    g[b].append(a)

ret = 0
def walk(node, visited):
    global ret
    tmp = visited + [node]
    if len(tmp) == n:
        ret += 1 
    for nd in g[node]:
        if nd not in tmp:
            walk(nd, tmp)
walk(1, [])
print(ret)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <map>
using namespace std;
typedef long long ll;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
const int INF = 1e9;

int N,C;
int table[30][110000];
int main(){
    cin >> N >> C;
    rep(i,N){
        int a,b,c;
        cin >> a >> b >> c;
        a--; c--;
        table[c][a]++;
        table[c][b]--;
    }
    rep(c,C){
        reps(i,1,110000) table[c][i] += table[c][i-1];
    }
    
    rep(c,C){
        rep(i,110000) if(table[c][i]) table[c][i] = 1;
    }

    int ans = 0;
    rep(i,110000){
        int cnt = 0;
        rep(c,C) cnt += table[c][i];
        ans = max(ans,cnt);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13184
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		
		// 計算
		int result = 1;
		result += (n - 2)/(k - 1); 
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 50596
#include <bits/stdc++.h>
#include <cctype>
#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(){
  string s,p ;
  getline(cin, s);
  getline(cin, p);

  string s_2 = s + s;
  bool ans = false;

  for (int i=0;i<s.size();i++){
//    cout << "s_2 ::" << s_2.substr(i, p.size()) << endl;
//    cout << "p   ::" << p << endl;
    if ( s_2.substr(i, p.size()) == p ) {
      ans = true;
      break;
    }
  }

  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}




Measured memory_bytes: 3192
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
a, p = map(int, input().split())
p += 3*a
print(p//2)

Measured memory_bytes: 5300
#include<bits/stdc++.h>
#define endl "\n"
#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cout<<#x<<" : {"<<x<<"}"<<endl; 
#endif
using namespace std;
typedef long long int lli;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int x, y;
	cin>>x>>y;
	//2*n1 + 4*n2 = y
	//n1 + n2 = x
	bool flag = false;
	for(int i=0; i<=x; ++i){
		int res = y - 2 * i;
		if(res%4 == 0 && res/4 == x - i){
			flag = true;
			break;
		}
	}
	cout<<(flag?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 3548
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a,b) << " " << max(0, a + b - n) << endl;
	return 0;
}


Measured memory_bytes: 3584
fun main(args: Array<String>) {
    var (n, l) = readLine()!!.split(" ").map { it.toInt() }
    val a = mutableListOf<Int>()
    for (i in 0 until n) {
        a.add(i + l)
    }
    var j = false
    var m = 10000
    val s = a.sum()
    var su = 0
    for (i in 0 until n) {
        su = 0
        for (j in 0 until n) {
            if (j != i) {
                su += a[j]
            }
        }
        if (m > Math.abs(s - su)) {
            m = Math.abs(s - su)
            if ((s - su) < 0) j = true
        }
    }
    println(
        if (j) s + m
        else s - m
    )
}

Measured memory_bytes: 36112
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  for (int i = 0; i < 5; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3624
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

I, O, T, J, L, S, Z = mapint()

if I==0 or J==0 or L==0:
    three = 0
elif I%2+J%2+L%2>=2:
    three = 1
    I -= 1
    J -= 1
    L -= 1
else:
    three = 0

ans = O+(I//2+J//2+L//2)*2+three*3
print(ans)

Measured memory_bytes: 79680
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int x, y, a, b;
    long i, result = 1;
    cin >> x >> y;
    if((x+y)%3 != 0){
        cout << 0;
    }else{
        a = (2*x - y)/3;
        b = (2*y - x)/3;
        if(a <0 || b<0){
            cout << 0;
            return 0;
        }
        for(i=1; i<=a+b; i++){
            result *= i;
            result %= MOD;
        }
        for(i=1; i<=a; i++){
            result *= modinv(i, MOD);
            result %= MOD;
        }
        for(i=1; i<=b; i++){
            result *= modinv(i, MOD);
            result %= MOD;
        }
        cout << result;
    }
    return 0;
}

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


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

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

int main(){
    string S,T;
    cin>>S>>T;
    map<char,ll> ms,mt;
    ll si=0,ti=0;
    string Sans,Tans;
    rep(i,0,S.size()){
        if(ms[S[i]] == 0){
            si++;
            ms[S[i]]=si;
        }
        if(mt[T[i]] == 0){
            ti++;
            mt[T[i]]=ti;
        }
        Sans.PB(ms[S[i]]);
        Tans.PB(mt[T[i]]);
    }
    YN(Sans == Tans);
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	LL ans = 0;
	for (LL A = 1; A <= N; A++) {
		LL AC = A;
		LL aa = A% 10;
		if (aa == 0)continue;
		LL a;
		while (AC > 0) {
			a = AC % 10;
			AC /= 10;
		}
		if (a == aa) {
			if (a <= N) {
				ans++;
			}
		}
		if (10 * aa + a <= N) {
			ans++;
		}
		for (LL x = 0; x < 10; x++) {
			if (100 * aa + 10*x + a <= N) {
				ans++;
			}
		}
		for (LL x = 0; x < 100; x++) {
			if (1000 * aa + 10*x + a <= N) {
				ans++;
			}
		}
		for (LL x = 0; x < 1000; x++) {
			if (10000 * aa + 10*x + a <= N) {
				ans++;
			}
		}
		for (LL x = 0; x < 10000; x++) {
			if (100000 * aa + 10*x + a <= N) {
				ans++;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            int x;
            cin >> x;

            if(x >= 30)
                cout << "Yes\n";
            else
                cout << "No\n";
            





           return 0;
        }
          

Measured memory_bytes: 3644
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import deque
import bisect
from decimal import *
def main():
    x = I()
    if x == 0:
        print(1)
    else:
        print(0)

if __name__ == "__main__":
    main()



Measured memory_bytes: 77052
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<map>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;
long long a[200005],b[200005],mod=1000000007;
map<pair<long long,long long>,pair<long long,long long>> m;
vector<pair<long long,long long>> vec;
long long power(long long n,long long m){
	if(!m)
		return 1;
	long long v=power(n,m>>1);
	if(m&1)
		return v*v%mod*n%mod;
	return v*v%mod;
}
long long GCD(long long a,long long b){
	return b?GCD(b,a%b):a;
}
int main(){
	long long i,n,ans=1,zero=0,cnt=0,zero2=0,zero3=0;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
		scanf("%lld%lld",&a[i],&b[i]);
	for(i=1;i<=n;i++){
		if(!a[i]&&!b[i])
			zero++;
		else if(!a[i])
			zero2++;
		else if(!b[i])
			zero3++;
		else{
			long long v=abs(GCD(a[i],b[i]));
			a[i]/=v;
			b[i]/=v;
			if(a[i]<0){
				if(b[i]<0)
					m[{-a[i],-b[i]}].first++;
				else
					m[{b[i],-a[i]}].second++;
			}
			else{
				if(b[i]<0)
					m[{-b[i],a[i]}].second++;
				else
					m[{a[i],b[i]}].first++;
			}
		}
	}
	for(auto x:m){
		auto y=x.second;
		if(y.first&&y.second){
			vec.emplace_back(y.first,y.second);
			cnt+=y.first+y.second;
		}
	} 
	ans=power(2,n-cnt-zero-zero2-zero3);
	vec.emplace_back(zero2,zero3);
	for(auto x:vec){
		long long v=((power(2,x.first)+power(2,x.second))%mod-1+mod)%mod;
		ans=ans*v%mod;
	}
	printf("%lld\n",(ans-1+mod+zero)%mod);
}

Measured memory_bytes: 21964
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (true) {
        int n;
        scan(n);

        if (n == 0) return;

        solve(n);
    }
}

void solve(int n) {
    int l=1, r=1;
    int v;
    int cnt;

    while (r <= n) {
        if (v < n) {
            v += r++;
        }
        else {
            if (v == n) cnt++;
            v -= l++;
        }
    }

    writeln(cnt);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2436
#include <bits/stdc++.h>
using namespace std;
int A[100];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++ ) {
        scanf("%d",&A[i]);
    }
    int H = A[1];
    int ans = 1;
    for(int i=2;i<=n;i++) {
        if(A[i] >= H) {
            ans += 1;
            H = A[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
num = list(map(int,input().split()))
numabs = [abs(i) for i in num]
cnt = 0           
for i in num :
    if i < 0 :
        cnt += 1

if cnt % 2 == 0 :
    print(sum(numabs))

if cnt % 2 == 1 :
    print(sum(numabs) - 2*min(numabs))

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

char s[12525];
int x,y;

bool dp[2][25252];
const int C = 12525;

int main(){
  scanf("%s%d%d",s,&x,&y);
  int n = strlen(s);
  vi vx, vy;
  int first = 0;
  int it = 0;
  while(it < n && s[it]=='F'){
    first++;
    it++;
  }
  it++;
  bool xxx = false;
  while(it < n){
    int tmp = 0;
    while(it < n && s[it] == 'F'){
      tmp++;
      it++;
    }
    (xxx ? vx : vy).push_back(tmp);
    it++;
    xxx = xxx ^ 1;
  }
  // x check
  REP(i,25252)dp[0][i] = false;
  dp[0][C+first] = true;
  for(int xx : vx){
    REP(i,25252)dp[1][i] = false;
    REP(i,25252)if(dp[0][i]){
      dp[1][i+xx] = true;
      dp[1][i-xx] = true;
    }
    REP(i,25252)dp[0][i] = dp[1][i];
  }
  if(!dp[0][C+x]){
    puts("No");
    return 0;
  }
  // y check
  REP(i,25252)dp[0][i] = false;
  dp[0][C] = true;
  for(int yy : vy){
    REP(i,25252)dp[1][i] = false;
    REP(i,25252)if(dp[0][i]){
      dp[1][i+yy] = true;
      dp[1][i-yy] = true;
    }
    REP(i,25252)dp[0][i] = dp[1][i];
  }
  if(!dp[0][C+y]){
    puts("No");
    return 0;
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;


int main(){
  int n;cin>>n;
  int G[n][n];
  ll ans=0;
  rep(i,n)rep(j,n){
    cin>>G[i][j];ans+=G[i][j];
  }
  int d[n][n];memset(d,0,sizeof(d));
  rep(k,n) rep(i,n) rep(j,n){
    if(i==j||j==k||k==i)continue;
    if(G[i][j]==G[i][k]+G[k][j]){
      if(!d[i][j]){
        ans-=G[i][j];d[i][j]=1;
      }
    }
    if(G[i][j]>G[i][k]+G[k][j]){
      cout<<-1<<endl;exit(0);
    }
  }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 896
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    graph = [[] for i in range(N)]
    prev = [-1 for i in range(N)]
    colors = {}
    edges = []
    for _ in range(N-1):
        a, b = MI()
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
        edges.append([a-1, b-1])
    max_edge = 0
    max_edge_idx = -1
    for i in range(len(graph)):
        length = len(graph[i])
        if length >= max_edge:
            max_edge = length
            max_edge_idx = i

    deque = cl.deque([max_edge_idx])
    while len(deque) > 0:
        target = deque.popleft()
        pre = prev[target]
        pre_key = (target, pre) if target < pre else (pre, target)
        used_color = 0
        if pre != -1:
            used_color = colors[pre_key]

        connecteds = graph[target]
        color = 1
        for connected in connecteds:
            key = (target, connected) if target < connected else (
                connected, target)
            if key in colors:
                continue
            if color == used_color:
                color += 1
            colors[key] = color
            prev[connected] = target
            deque.append(connected)
            color += 1

    print(max_edge)

    for edge in edges:
        print(colors[(edge[0], edge[1])])


main()


Measured memory_bytes: 118364
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, C, D, L, R;

    cin >> A >> B >> C >> D;
    L = A + B;
    R = C + D;

    if (L > R) {
        cout << "Left" << endl;
    }
    else if (L == R) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}

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

using namespace std;

int main(){


	int n;
	cin>>n;
	string s;
	cin>>s;

	int total = 0;
	if(n == 1){
		cout<<1<<endl;
	}
	else{
		char ini = s[0];
		char anterior = ini;
		for(int i =1;i<n;i++){
			if(s[i] == anterior){

			}
			else{
				total++;
				anterior = s[i];
			}
		}

		cout<<total+1<<endl;
	}

	return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        Set<Integer> set = new HashSet<Integer>();

        for (int i = 0; i < n; i++) {
            set.add(sc.nextInt());
        }

        if (set.size() == n) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}

Measured memory_bytes: 100352
A= int(input())
B= int(input())
C= int(input())
X= int(input())
f = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            s = 500*i + 100*j + 50*k
            if s == X:
                f+=1
print(f)

Measured memory_bytes: 39664
<?php
fscanf(STDIN, "%d", $n);
$h = array_map('intval', explode(' ', trim(fgets(STDIN))));

for ($i = $n - 1; $i >= 1; $i--) {
    if ($h[$i - 1] === $h[$i] + 1) {
        $h[$i - 1]--;
    } elseif ($h[$i - 1] > $h[$i] + 1) {
        exit ('No'.PHP_EOL);
    }
}
echo 'Yes'.PHP_EOL;

Measured memory_bytes: 16884
#include <iomanip>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  double x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed << setprecision(6) << sqrt(pow((x1-x2), 2)+pow((y1-y2), 2)) << endl;
  return 0;
}

Measured memory_bytes: 1284
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<cstring>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define FOREACH(t,p,tit) for(t::iterator tit=p.begin();tit!=p.end();++tit)
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef set<int> pp;
string ss;

pp solve(int f,int l)
{

	pp ans;
	//ans.clear();
	bool ope=false;
/*	for(int i=f;i<l;i++)
	{
		if(
				ss[i]=='+'||
				ss[i]=='-'||
				ss[i]=='*'||
				ss[i]=='/')ope = true;
	}*/

	//int ofs = 0;
	int bo =0;
	for(int i=f;i<l;i++)
	{
	
		if(ss[i]=='(') bo++;
		if(ss[i]==')') bo--;

		if((ss[i]=='+'||ss[i]=='-'||ss[i]=='*'||ss[i]=='/')&&(bo==0))
		{
			ope = true;
		
			pp ansl = solve(f,i-1);
			pp ansr = solve(i+1,l);
			FOREACH(pp,ansl,iit)FOREACH(pp,ansr,jit)
			{
				if(ss[i]=='+') ans.insert((*iit)+(*jit));
				if(ss[i]=='-') ans.insert((*iit)-(*jit));
				if(ss[i]=='*') ans.insert((*iit)*(*jit));
				if(ss[i]=='/')if((*jit)!=0)	ans.insert((*iit)/(*jit));
			}
		}
	}
	if(!ope)
	{
		if(ss[f]=='('&& ss[l]==')'  ){return solve(f+1,l-1);}
		else
		{
			string s = ss.substr(f,(l-f+1));
			//cout << s << endl;
			int t = atoi(s.c_str() );
			ans.insert(t);
			//foreach(pp,ans)cout << *it << endl;
			//cout << atoi( (ss.substr(f,l+1)).c_str()) << endl ;
			//cout <<ss.substr(f,(l-f+1))<<endl;
			return ans;
		}
	}
		return ans;
}

int main()
{
	while(cin >> ss &&(ss!="#"))
	{
		pp anss = solve(0,ss.size()-1);
		//foreach(pp,anss)cout << *it << endl;
		cout << anss.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,A,B;
    cin>>N>>A>>B;
    int sum,ans=0;
    for(int i=1;i<=N;i++){
        sum=i%10+i/10%10+i/100%10+i/1000%10+i/10000;
        if(A<=sum&&sum<=B){ans+=i;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
using ll = long long;

int main(){
  long double w,h,x,y,rx,ry,s;
  cin >> w >> h >> x >> y;
  long can=0;
  s = w*h/2;
  if(x == w/2 && y == h/2){
    can = 1;
  }
  // }else{
  //   can = 0;
  //   if(w-x>x){
  //     rx = x;
  //   }else{
  //     rx=w-x;
  //   }
  //   if(h-y>y){
  //     ry=y;
  //   }else{
  //     ry=h-y;
  //   }
  //   s = (rx*rx+ry*ry) / rx / ry * (rx*rx+ry*ry);
  // }
  cout << s << " " << can;
}


Measured memory_bytes: 256
def mod_rep_pow(a, n, mod=(10 ** 9 + 7)):
    res = 1
    while n > 0:
        if n % 2 == 0:
            a = a ** 2 % mod
            n //= 2
        else:
            res = res * a % mod
            n -= 1
    return (res % mod)


def mod_comb(n, k, mod=(10 ** 9 + 7)):
    res1 = 1
    for i in range(n, (n - k), -1):
        res1 *= i
        res1 %= mod
    res2 = 1
    for i in range(1, (k + 1)):
        res2 *= i
        res2 %= mod
    return ((res1 * mod_rep_pow(res2, (mod - 2), mod)) % mod)


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
ans = mod_rep_pow(2, n, mod) - 1
ans -= mod_comb(n, a, mod)
ans -= mod_comb(n, b, mod)
while ans < 0:
    ans += mod
print(ans)


Measured memory_bytes: 38640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def inv(x):
    return pow(x, mod - 2, mod)

cms = 10**5 + 5
cm = [0] * cms

def comb_init():
    cm[0] = 1
    for i in range(1, cms):
        cm[i] = cm[i-1] * i % mod

def comb(a, b):
    return (cm[a] * inv(cm[a-b]) % mod) * inv(cm[b]) % mod

def main():
    n,k = LI()
    ab = [LI_() for _ in range(n-1)]
    e = collections.defaultdict(list)
    for a,b in ab:
        e[a].append(b)
        e[b].append(a)

    for v in e.values():
        if len(v) >= k:
            return 0

    comb_init()
    def f(i, p):
        el = len(e[i])
        if p == -1:
            r = comb(k-1, el) * cm[el] % mod
        else:
            r = comb(k-2, el-1) * cm[el-1] % mod
        for c in e[i]:
            if c == p:
                continue
            r *= f(c, i)
            r %= mod
        return r

    r = f(0,-1) * k


    return r % mod


print(main())





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

int main()
{
    int n;
    cin >> n;
    
    int l, r, count = 0;
    for(int i = 0; i < n; ++i)
    {
        cin >> l >> r;
        count += (r - l + 1);
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	long long int n,k,ans=0,temp;
	scanf("%lld %lld",&n,&k);
	for(long long int i=k;i<n+2;i++){
		temp=((i*(2*n-i+1)))/2+1;
		temp-=((i*(i-1)))/2;
		ans+=(temp%1000000007);
		ans=ans%1000000007;
	}
	printf("%lld",ans);
}

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

string s;
unordered_map<char, int> cnt;

int main() {
    cin >> s;
    for(auto x : s) {
        cnt[x]++;
    }

    if(cnt.size() != 2) {
        cout << "No" << endl;
        return 0;
    }

    bool ok = true;
    for(auto x : cnt) {
        if(x.second != 2)
            ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

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

int main () {
	int sn, tn, t, c = 0;
	cin >> sn;
	int *s = new int[sn];
	for (int i = 0; i < sn; i++)
		cin >> s[i];
	cin >> tn;
	for (int i = 0; i < tn; i++) {
		cin >> t;
		for (int j = 0; j < sn; j++) {
			if (s[j] == t) {
				c++;
				break;
			}
		}
	}
	cout << c << endl;
	return 0;
}

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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)

/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)

/* debug */
#define pp(v) cerr << #v "=" << (v) << endl;

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using vs = vector<string>;
using Graph = vvi;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* iostream */
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template<class T> T div_ceil(const T &a, const T &b) { return (a + b - 1) / b; }

int fact(int n) {
  int ans = 1;
  repi(i,n) ans = ans * i % MOD;
  return ans;
}

int solve(int n, int m) {
  if (abs(n-m)>1) return 0;
  int ans = fact(n) * fact(m) % MOD;
  if (n==m) ans = ans * 2 % MOD;
  return ans;
}

signed main() {
  int n,m;cin>>n>>m;
  int ans = solve(n,m);
  cout << ans << endl;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_161a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] box = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int tmp = 0;
            tmp = box[0];
            box[0] = box[1];
            box[1] = tmp;
            tmp = box[0];
            box[0] = box[2];
            box[2] = tmp;

            foreach(int item in box)
            {
                Console.Write(item + " ");
            }
            Console.Read();
        }
    }
}


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

int main() {
	char s[100010];
	int n = fgets(s, 100005, stdin);
	char* top = s;
	char* bottom = top + strlen(s) - 1;
	if (*bottom == '\n') bottom--;
	int count = 0;
	while (top < bottom) {
		if (*top == *bottom) {
			top++; bottom--; continue;
		}
		if (*top == 'x') {
			top++; count++; continue;
		}
		if (*bottom == 'x') {
			bottom--; count++; continue;
		}
		printf("-1");
		return 0;
	}
	printf("%d", count);
	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn lms(a: usize, b: usize) -> usize {
    let mut x = cmp::max(a,b);
    let mut y = cmp::min(a,b);
    while x%y > 0 {
        let z = x % y;
        x = y;
        y = z;
    }
    y
}

fn main() {
    let nx: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nx[0];
    let x = nx[1];

    let mut xs: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    xs.push(x);
    xs.sort();

    let mut ans = xs[1] - xs[0];

    for i in 1..xs.len()-1 {
        ans = lms(ans, xs[i+1]-xs[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
import sys
input = sys.stdin.buffer.readline

N = int(input())
issame = True
s = 0
B_min = 10 ** 9 + 7
for _ in range(N):
    A, B = map(int, input().split())
    s += B
    if issame:
        issame = (A == B)
    if A > B and B_min > B:
        B_min = B

print(0 if issame else s - B_min)

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

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

	for (i = 0; i < 2; i++) {
		if (a > b) {
			d = a;
			a = b;
			b = d;
		}
		if (b > c) {
			d = b;
			b = c;
			c = d;
		}
	}

	cout << a << " " << b << " " << c << endl;

	return 0;
}

Measured memory_bytes: 3084
N=int(input())
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
bit = [bin(i)[2:].zfill(k) for i in A]
mod = 10**9+7
c = [0]*k
ans = 0
for i in range(k):
  cnt = sum([1 for j in bit if j[i]=='1'])
  ans += cnt*(N-cnt)*(2**(k-i-1))
  ans %= mod  

print(ans)
  

Measured memory_bytes: 56416
K, T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]


def argmax(l, excep):
    m = -1
    ix = -1

    for i, e in enumerate(l):
        if i == excep:
            continue

        if e > m:
            m = e
            ix = i

    return ix, m


t = sum(a)
b = -1
ans = 0

for i in range(t):
    ix, m = argmax(a, b)

    if m > 0:
        b = ix
        a[ix] -= 1

    else:
        if b == -1:
            break

        if a[b] != 0:
            ans += 1
            a[b] -= 1
        else:
            break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    using namespace std;
    signed main(){
    int k,x;
    cin>>k>>x;
    for(int i=x+1-k;i<x+k;i++){
    cout<<i;
    if(i != x-1+k)
    cout<<' ';
    }
    cout<<endl;
    return(0);
    }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,K,A,D,cou=0;
	cin>>N>>K;
	int H[101]={0};
	for(int i=0;i<K;i++){
		cin>>D;
		for(int t=0;t<D;t++){
			cin>>A;
			H[A]++;
		}
	}
	for(int i=1;i<=N;i++){
		if(H[i]==0)cou++;
	}
	cout<<cou<<endl;
}

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


int main(){
  int n;
  cin>>n;
  long long a[100100][3];
  long long dp[100100][3];
  long long mx;
  
  rep(i,n){rep(j,3)cin>>a[i][j];}
  
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  
  rep(i,n){
  dp[i+1][0]=max(dp[i][1],dp[i][2])+a[i+1][0];
  dp[i+1][1]=max(dp[i][0],dp[i][2])+a[i+1][1];
  dp[i+1][2]=max(dp[i][0],dp[i][1])+a[i+1][2];
  }
  mx=max(dp[n-1][0],dp[n-1][1]);
  mx=max(mx,dp[n-1][2]);
  cout<<mx<<endl;
  }

Measured memory_bytes: 4992
fun main(args: Array<String>) {
    val S = readInputLine().toCharArray()
    val T = readInputLine().toCharArray()
    
    var ans = 0
    
    for (i in 0..2) {
        if (S[i] == T[i]) {
            ans++
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 29816
def F(x):
    # x-1までのxor sum
    # 偶数の時
    if not x&1:
        y = x >> 1
        return y&1
    else:
        return (x-1)^F(x-1)

A, B = map(int, input().split())
print(F(A)^F(B+1))

Measured memory_bytes: 2940