akhauriyash/Code-Regression huggingface dataset:
// Aizu 1131: Unit Fraction Partition
// 2017.10.24 bal4u@uu

#include <stdio.h>
#include <math.h>

#define M 2000000000
#define EPS 1e-9
#define HASHSIZ 34981
typedef struct { int b; double v; } HASH;
HASH hash[HASHSIZ + 2], *hashend = hash + HASHSIZ;

int lookup(double v)
{
	int k = (int)(v * M);
	HASH *hp = hash + k % HASHSIZ;
	while (hp->b) {
		if (fabs(hp->v - v) <= EPS) return hp->b;
		if (++hp == hashend) hp = hash;
	}
	return -1;
}

void insert(double v, int b)
{
	int k = (int)(v * M);
	HASH *hp = hash + k % HASHSIZ;
	while (hp->b) {
		if (fabs(hp->v - v) <= EPS) return;
		if (++hp == hashend) hp = hash;
	}
	hp->v = v, hp->b = b;
}

double tbl[12005];

int bsch(double v)
{
	int m, l = 0, r = 12001;

	while (l < r) {
		m = (l + r) >> 1;
		if (fabs(tbl[m] - v) <= EPS) return m;
		if (tbl[m] > v) l = m + 1; else r = m;
	}
	if (l <= 0) l = 1;
	return l;
}

int ans, a;

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

void rec(double v, int k, int n, int aa)
{
	int i, l, r;

	if (n < 0 || aa > a) return;
	if (fabs(v) <= EPS) { ans++; return; }
	if (n == 0) return;

	l = bsch(v), r = bsch(v / n);
	if (k > l) l = k;
	if ((double)n/l + EPS < v) return;
	k = a / aa+1;
	if (r > k) r = k;
	for (i = l; i <= r; i++) rec(v - 1.0 / i, i, n - 1, aa*i);
}

int main()
{
	int p, q, n, i, l, r;
	double v;

	for (i = 1; i <= 12002; i++) {
		v = 1.0 / i;
		insert(v, i), tbl[i] = v;
	}

	while (scanf("%d%d%d%d", &p, &q, &a, &n) && n > 0) {
		i = gcd(p, q); p /= i, q /= i;
		v = (double)p / q;
//		if (fabs(v-n) <= EPS) { puts("1"); continue; }
		if (v > n) { puts("0"); continue; }
		l = bsch(v), r = bsch(v / n);
		for (ans = 0, i = l; i <= r; i++) {
			rec(v - 1.0 / i, i, n - 1, i);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2372
#include <bits/stdc++.h>
#define ll long long int
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main()
{
  IO;  
 string s; 
 cin >> s; 
 cout << s[0] << s[1] << s[2] << endl;
  
return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
    string s,JOI="JOI",IOI="IOI";
    while(cin>>s){
        int a=0,b=0;
        for(int i=0;i<s.size()-2;++i){
            if(s[i]==JOI[0]){
                if(s[i+1]==JOI[1]){
                    if(s[i+2]==JOI[2]){
                        ++a;
                    }
                }
            }
            if(s[i]==IOI[0]){
                if(s[i+1]==IOI[1]){
                    if(s[i+2]==IOI[2]){
                        ++b;
                    }
                }
            }
        }
        cout<<a<<endl;
        cout<<b<<endl;
    }
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){

    const int h = 19, w = 15;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)
        cin >> s[i];
    vector<vector<char>> v(h, vector<char>(w, -1));
    int st = 0, en = 0;
    int cnt = 0;
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j){
            if(s[i][j] == 'O')
                st = i, en = j;
            if(s[i][j] == 'X'){
                v[i][j] = cnt++;
            }
        }

    vector<int> dx{-1, 0, 1, 1, 1, 0, -1, -1};
    vector<int> dy{1, 1, 1, 0, -1, -1, -1, 0};

    vector<map<pair<int,int>, int>> dp(1 << cnt);
    char ans = 100;
    dp[0][make_pair(st, en)] = 0;
    for(int mask = 0; mask < (1 << cnt); ++mask){
        for(auto& p : dp[mask]){
            int i, j;
            tie(i, j) = p.first;
            int val = p.second;
            for(int d = 0; d < 8; ++d){
                int ma = 0;
                bool fl = true;
                int dist = 1;
                int nx, ny;
                for(;; ++dist){
                    nx = i + dist * dx[d];
                    ny = j + dist * dy[d];
                    if(nx >= h)
                        break;
                    if(nx < 0 || ny < 0 || ny >= w){
                        fl = false;
                        break;
                    }
                    if(v[nx][ny] == -1 || mask & (1 << v[nx][ny]))
                        break;
                    ma |= (1 << v[nx][ny]);
                }
                if(!fl || dist == 1)
                    continue;
                if(nx >= h - 1){
                    chmin(ans, char(val + 1));
                    continue;
                }
                if(dp[mask | ma].find(make_pair(nx, ny)) == dp[mask | ma].end() || dp[mask | ma][make_pair(nx, ny)] > char(val + 1)){
                    dp[mask | ma][make_pair(nx, ny)] = char(val + 1);
                }
            }
        }
    }
    cout << (ans == 100 ? -1 : ans) << endl;

    return false;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 57232
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	BufferSize = 100
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	k := scanInt(sc)
	s := scanStr(sc)
	slice := strings.Split(s, "")

	for i := 0; i < n; i++ {
		if i != k-1 {
			fmt.Printf("%v", slice[i])
		} else {
			fmt.Printf("%v", strings.ToLower(slice[i]))
		}
	}
}


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

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

    string s1, s2; cin >> s1 >> s2;

    for (int i = 0; i < n; i++)
        if (s1[i] == s2[0]) {
            bool g = 1;
            for (int j = i + 1, k = 1; j < n; j++, k++)
                if(s1[j] != s2[k])
                    g = 0;
            if (g){
                cout << i + n;
                return (0);
            }
        }

    cout << 2 * n;
}

Measured memory_bytes: 3632
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

h,w = gets.split.map(&:to_i)
s = h.times.map do 
  gets.chomp.gsub!(/\.|#/, "." => "0", "#" => "9").split("").map(&:to_i).unshift(-INF).push(-INF)
end

s.unshift([-INF] * (w+2))
s.push([-INF] * (w+2))



0.upto(h+1) do |i|
  0.upto(w+1) do |j|
    if s[i][j] >= 9
      s[i-1][j-1] += 1 
      s[i-1][j] += 1
      s[i-1][j+1] += 1
      s[i][j-1] += 1
      s[i][j+1] += 1
      s[i+1][j-1] += 1 
      s[i+1][j] += 1 
      s[i+1][j+1] += 1 
    end
  end
end

0.upto(h+1) do |i|
  0.upto(w+1) do |j|
    if i != 0 && i != (h+1) && j != 0 && j != (w+1)
      s[i][j] = "#" if s[i][j] >= 9
      print s[i][j]
    end    
  end
  print "\n" if i != 0 && i!= (h+1) 
end




Measured memory_bytes: 2044
def main():
    n = int(input())
    t = list(map(int, input().strip().split()))

    r = 1
    if 0 in t:
        print(0)
        return

    for tt in t:
        r *= tt
        if r > 10**18:
            print(-1)
            return

    print(r)

main()

Measured memory_bytes: 21636
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;

    vector<pair<int, int>> E(M);
    for (int i = 0; i < M; ++i) cin >> E[i].first >> E[i].second;
    sort(E.begin(), E.end());

    int ans = 1;
    int right = E[0].second;
    for (int i = 1; i < M; ++i) {
        int left = E[i].first;
        if (right <= left) {
            ++ans;
            right = E[i].second;
        } else {
            right = min(right, E[i].second);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
    int a,b,x[3],max,i;
    scanf("%d %d",&a,&b);
    x[0]=a+b;
    x[1]=a-b;
    x[2]=a*b;
    max = x[0];
for(i=0;i<=2;i++){
    if(max<x[i]){
max =  x[i];    
    }
}
printf("%d",max);
return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		long[] a = new long[N];
		
		int x1 = 0;
		int x2 = 0;
		int x4 = 0;
		
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
			if(a[i] % 2 != 0) {
				x1++;
			} else if(a[i] % 2 == 0 && a[i] % 4 != 0) {
				x2++;
			} else if(a[i] % 4 == 0) {
				x4++;
			}
		}
		
		if(x4 >= x1) {
			System.out.println("Yes");
		} else if(x4 + 1 == x1 && x4 + x1 == N) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}
}


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

int main(){
  vector<int> x(3,0);
  int k,ans;
  REP(i,3) cin>>x.at(i);
  cin>>k;
  sort(x.begin(),x.end());
  ans+=x.at(0)+x.at(1);
  for(int i=0;i<k;i++) x.at(2)*=2;
  ans+=x.at(2);
  cout<<ans;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  int n = s.size();
  vi ans(n);
  rep(i, n) {
    int j = i;
    while (j+1 < n && s[j+1] == s[i]) j++;
    int cnt = j - i + 1;
    if (s[i] == 'R') {
      if (j == n-1)
        ans[j] += cnt;
      else
        ans[j] += (cnt + 1) / 2, ans[j+1] += cnt / 2;
    } else {
      if (i == 0)
        ans[i] += cnt;
      else
        ans[i] += (cnt + 1) / 2, ans[i-1] += cnt / 2;
    }
    i = j;
  }
  rep(i, n) std::cout << ans[i] << (i+1 < n ? " " : "\n");
}


Measured memory_bytes: 1104
#include <iostream>

using namespace std;

int main()
{
	int dataNum;
	
	cin >> dataNum;
	
	int *inArray = new int[dataNum];
	
	for(int i = 0; i < dataNum; i++)
	{
		cin >> inArray[i];
	}
	
	for(int i = dataNum - 1; i > 0; i--)
	{
		cout << inArray[i] << " ";
	}
	
	cout << inArray[0] << endl;
	
	delete [] inArray;
	
	return 0;
}


Measured memory_bytes: 3108
S = input()
if S == "SUN":
  print(7)
elif S == "MON":
  print(6)
elif S == "TUE":
  print(5)
elif S == "WED":
  print(4)
elif S == "THU":
  print(3)
elif S == "FRI":
  print(2)
else:
  print(1)
  

Measured memory_bytes: 38256
#include <iostream>
#include<math.h>

using namespace std;

int main(int argc, char *argv[])
{
     int H = 0;
     cin >> H;
     int *arr = new int[H + 1];
     for (int i = 1; i < H + 1; i++) {
         cin >> arr[i];
     }
     for (int i = 1; i < H + 1; i++) {
         if (i == 1) {
             cout << "node " << i << ": "<<"key = "<< arr[i] << ", ";
         } else {
             cout << "node " << i << ": "<<"key = "<< arr[i] << ", " << "parent key = " << arr[int(floor(i / 2))] << ", ";
         }
         if (2*i <= H) {
             cout << "left key = "<< arr[2*i] << ", ";
         }
         if (2*i + 1 <= H) {
             cout << "right key = "<< arr[2*i + 1] << ", ";
         }
         cout << endl;

     }

    return 0;
}



Measured memory_bytes: 3112
#include <iostream>

int eucgcd(int m, int n)
{
	int p = m%n;
	
	while( p > 0 )
	{
		m = n;
		n = p;
		p = m%n;
	}
	
	return n;
}


int main()
{
	int m,n;
	
	while( std::cin >> m >> n && m && n )
	{
		if( m >= n )
			std::cout << eucgcd(m, n) << std::endl;
		else
			std::cout << eucgcd(n, m) << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
s = input()
max_plus = len(s)-1
plus = [reversed(bin(i)[2:]) for i in range(2**max_plus)]
value_sum = 0
for i in plus:
    value = 0
    prov_s = s
    end_plus = 0
    for index, j in enumerate(i):
        if j == "1":
            cut_index = (1+index)*(-1)+end_plus
            value += int(prov_s[cut_index:])
            prov_s = prov_s[0:cut_index]
            end_plus += -1 * cut_index
    value_sum += value + int(prov_s)
print(value_sum)

Measured memory_bytes: 3064
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool operator< (const P &a,const P &b){
  return a.second < b.second;
}


int main()
{
  ll n,s,A[100001],N,T,cnt,sale;
  priority_queue<P,vector<P> , greater<P> > que;
  bool k[100001];
  fill(k,k+100001,false);
  vector<P> sets;
  cin >> N >> T;
  REP(i,N){
    cin >> A[i];
  }
  que.push(P(A[0],0));
  sale = 0;
  cnt = 0;
  for(ll i=1;i<N;i++){
    if(A[i] - (que.top()).first >= sale){
      if(A[i] - (que.top()).first == sale){
        sets.push_back(P(que.top().second,i));
      }else{
        sale = A[i] - que.top().first;
        sets.clear();
        sets.push_back(P(que.top().second,i));
      }
    }
    que.push(P(A[i],i));
  }
  
  REP(i,sets.size()){
    if((k[sets[i].second] == false && k[sets[i].first] == false)){
      k[sets[i].second] = true;
      cnt++;
    }
  }
  cout << cnt << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 4464
#include<iostream>
#include<utility>
using namespace std;
int main(){
	int n;
	cin >> n;
	int x[100],y[100];
	long long h[100];
	int X,Y;
	long long H;
	for(int i=0;i<n;i++) cin >> x[i] >> y[i] >> h[i];
	for(int i=0;i<=100;i++){
		bool flagi=false;
		for(int j=0;j<=100;j++){
			bool flagj=true;
			int point;
			for(int k=1;k<n;k++){
				if(h[k]>0){
					H=h[k]+abs(i-x[k])+abs(j-y[k]);
					point=k;
					break;
				}
			}
			for(int k=0;k<n;k++){
				if(k==point) continue;
				int dis=abs(i-x[k])+abs(j-y[k]);
				if(H-h[k]==dis){}
				else if(h[k]==0 && H-dis<0){}
				else{
					flagj=false;
					break;
				}
			}
			if(flagj){
				X=i;
				Y=j;
				flagi=true;
				break;
			}
		}
		if(flagi) break;
	}
	cout << X << ' ' << Y  << ' ' << H;
}


Measured memory_bytes: 256
// ABC 007 C

#include<bits/stdc++.h>
using namespace std;
#define ll long long
using Graph = vector<vector<int>>;

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

int ret = 0;
void dfs(const Graph &G, int v, vector<bool> visited) {
    if (adjacent_find(visited.begin(), visited.end(), not_equal_to<>()) == visited.end()) {
        ret++;
    }

    for (auto next_v : G[v]) { 
        if (visited[next_v] == false) {
            visited[next_v] = true;
            dfs(G, next_v, visited);
            visited[next_v] = false;
        }
    }
}

int main() {
    int n, m;
    cin >> n >> m;

    Graph G(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<bool> visited;
    visited.assign(n, false);
    visited[0] = true;
    dfs(G, 0, visited);

    cout << ret << endl;
    return 0;
}

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

namespace AtCoder.Abc
{
    class Question6
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var list = a.OrderByDescending(x => x);
            var sum = a.Sum(x => x);
            int[] Array = list.ToArray();

            long A = 0;


            int j;

            for (j = 0; 2 * j < n; j++)
            {
                A += Array[2 * j];
            }

            var result =2 * A -sum ;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

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

    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void xin(){
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}
int f[100005] = {0};
int main()
{
  	xin();
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);

    int a;
    cin>>a;
    int ans = a*(1 + a*(1+a));
    cout<<ans<<endl;
    
 }

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
	string s;
	cin >> s;
	string ans;
	int len = s.size();
	if(s[len-1] == 's') ans = s+"es";
	else ans += s+"s";
	cout << ans << endl;
	return 0;
}

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

using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;
using pii = pair<int, int>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int MOD = 1e9 + 7;


ll modrec(int n){
  ll ans = 1;
  for(int i = 2; i <= n; i++){
    ans = i * ans % MOD;
  }
  return ans;
}


int main(){
  int n, m; cin >> n >> m;
  ll ans = 0;
  if(n == m){
    ll k = modrec(n);
    ans += k * k % MOD;
    ans = 2 * ans % MOD;
  }
  else if(abs(n - m) == 1){
    ans = modrec(n) * modrec(m) % MOD;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,X=get_i
$ans=0
def dfs(now,x,burger,paty)
  if x>=1
      x-=1
  else
      return
  end
  if x>=burger[now-1]
      x-=burger[now-1]
      $ans+=paty[now-1]
  else
      dfs(now-1,x,burger,paty)
      return
  end
  if x>=1
      x-=1
      $ans+=1
  else
      return
  end
  if x>=burger[now-1]
      x-=burger[now-1]
      $ans+=paty[now-1]
  else
      dfs(now-1,x,burger,paty)
      return
  end
  if x>=1
      x-=1
  else
      return
  end
end
burger=array(N+1)
burger[0]=1
paty=array(N+1)
paty[0]=1
N.times do|i|
    burger[i+1]=3+burger[i]*2
    paty[i+1]=1+paty[i]*2
end
dfs(N,X,burger,paty)
puts $ans

Measured memory_bytes: 14388
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
bool sosu[1000010]={1,1,0};
int main(){
  int a,b,n;

  for(int i=4;i<=1000010;i+=2)sosu[i]=true;
  for(int i=3;i<=1000010;i+=2)
    for(int j=i*3;j<=1000010;j+=i*2)sosu[j]=true;

  while(cin>>a>>b>>n,a+b+n){
    int co=0;
    while(co!=n){
      if(!sosu[a])co++;
      a+=b;
    }
    cout<<a-b<<endl;
  }
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#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(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int A,B,cn=0;
	cin>>A>>B;
	FOR(i,A,B+1){
		string S =to_string(i);
		string S2=S;
		reverse(S.begin(),S.end());
		if(S==S2) cn++;
	}

	print(cn);
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int n,q;
const int max_n = 1e5;

int main(){
  cin >> n >> q >> s;
  int a[n];
  for(int i=0 ; i+1<n ; i++){
    if(s[i]=='A'&&s[i+1]=='C'){
      a[i+1] = a[i] + 1;
    }else{
      a[i+1] = a[i];
    }
  }
  for(int i=0 ; i<q ; i++){
    int ll,rr;
    cin >> ll >> rr;
    --ll; --rr;
    cout << a[rr] - a[ll] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long N;
long c00,c01,c10;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
main()
{
	cin>>N;
	vector<pair<long,long> >X;
	for(int i=0;i<N;i++)
	{
		long a,b;cin>>a>>b;
		if(a==0&&b==0)c00++;
		else if(a==0)c01++;
		else if(b==0)c10++;
		else X.push_back(make_pair(a,b));
	}
	map<pair<long,long>,long>mp;
	for(pair<long,long>&p:X)
	{
		long a=p.first,b=p.second;
		long d=gcd(abs(a),abs(b));
		a/=d;b/=d;
		if(a<0)
		{
			a=-a;
			b=-b;
		}
		mp[make_pair(a,b)]++;
		if(b<0)
		{
			long ta=-b,tb=a;
			a=ta;
			b=tb;
		}
		p=make_pair(a,b);
	}
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	long ans=(power(2,c01)+power(2,c10)-1+mod)%mod;
	for(pair<long,long>p:X)
	{
		long a=p.first,b=p.second;
		long A=-b,B=a;
		if(A<0)
		{
			A=-A;
			B=-B;
		}
		long c0=mp[p],c1=mp[make_pair(A,B)];
		ans=ans*(power(2,c0)+power(2,c1)-1+mod)%mod;
	}
	cout<<(ans-1+c00+mod)%mod<<endl;
}


Measured memory_bytes: 31288
from collections import  defaultdict


N = int(input())

d = defaultdict(int)
for i in range(1, N+1):
    s = str(i)
    d[(s[0], s[-1])] += 1


ans = 0
for i in range(1,N+1):
    s = str(i)
    ans += d[(s[-1], s[0])]


print(ans)

Measured memory_bytes: 40428
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MOD 998244353
#define SIZE 100005

enum Type{
	USE,
	NOT,
};

ll N,K;
ll dp[SIZE][305][2],work[305][2];
ll num_nodes[SIZE];
vector<int> G[SIZE];


void dfs(int node_id,int parent){

	//dp[頂点番号(=k)][kの部分木の分割数][kを使用しているかどうか] = 場合の数
	dp[node_id][1][USE] = 1;
	dp[node_id][0][NOT] = 1;
	num_nodes[node_id] = 1;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == parent)continue;

		dfs(child,node_id);

		for(int a = 0; a <= K; a++){
			work[a][USE] = 0;
			work[a][NOT] = 0;
		}

		for(int a = 0; a <= min(num_nodes[node_id],K+1); a++){
			for(int b = 0; b <= min(num_nodes[child],K+1-a); b++){

				work[a+b][USE] += dp[node_id][a][USE]*dp[child][b][USE];
				work[a+b][USE] %= MOD;
				work[a+b][USE] += dp[node_id][a][USE]*dp[child][b][NOT];
				work[a+b][USE] %= MOD;

				work[a+b][NOT] += dp[node_id][a][NOT]*dp[child][b][USE];
				work[a+b][NOT] %= MOD;
				work[a+b][NOT] += dp[node_id][a][NOT]*dp[child][b][NOT];
				work[a+b][NOT] %= MOD;

				if(a+b > 0){
					//node_idとchildを同時に含むグループを作る
					work[a+b-1][USE] += dp[node_id][a][USE]*dp[child][b][USE];
					work[a+b-1][USE] %= MOD;
				}
			}
		}

		num_nodes[node_id] += num_nodes[child];

		for(int a = 0; a <= min(num_nodes[node_id],K+1); a++){

			dp[node_id][a][USE] = work[a][USE];
			dp[node_id][a][NOT] = work[a][NOT];
		}
	}
}


int main(){

	scanf("%lld %lld",&N,&K);

	int from,to;
	for(int loop = 0; loop < N-1; loop++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(to);
		G[to].push_back(from);
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k <= K; k++){
			for(int p = 0; p < 2; p++){
				dp[i][k][p] = 0;
			}
		}
	}

	dfs(0,-1);

	printf("%lld\n",(dp[0][K][USE]+dp[0][K][NOT])%MOD);

	return 0;
}



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

using namespace std;

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

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

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

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, k;
  cin>>n>>k;
  int ans=0;
  while(n>0){
    n/=k;
    ++ans;
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1e18
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t, i, j;
    ll a,b; 
    cin>>a>>b; 
    cout<<a*b<<"\n";

    return (0);
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int maxn=2E5+5;
int n,a[maxn];
struct line
{
	int l,r,w;
	line(int a=0,int b=0,int c=0):l(a),r(b),w(c){}
	inline line operator&(const line&x){return line(max(l,x.l),min(r,x.r));}
	inline line operator^(const line&x){return l==x.l?line(r+1,x.r):line(l,x.l-1);}
	inline bool empty(){return l>r;}
	bool operator<(const line&A)const
	{
		return w<A.w;
	}
};
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	vector<line>now;
	now.push_back(line(0,0,0));
	for(int i=1;i<=n+1;++i)
	{
		int del=a[i]-a[i-1];
		line base(0,a[i]);
		vector<line>cur;
		for(auto p:now)
		{
			line x=line(0,min(p.r-1,del+p.r-1))&base;
			x.w=p.w+2;
			if(!x.empty())
				cur.push_back(x);
			
			x=line(del+p.l,p.r-1)&base;
			x.w=p.w+1;
			if(!x.empty())
				cur.push_back(x);
			
			x=line(p.l,del+p.r-1)&base;
			x.w=p.w+1;
			if(!x.empty())
				cur.push_back(x);
			
			x=line(max(p.l,del+p.l),a[i])&base;
			x.w=p.w;
			if(!x.empty())
				cur.push_back(x);
		}
		sort(cur.begin(),cur.end());
		now.clear();
		for(auto x:cur)
		{
			line g=x;
			for(auto y:now)
			{
				line tmp=g&y;
				if(!tmp.empty())
					g=g^tmp;
				if(g.empty())
					break;
			}
			g.w=x.w;
			if(!g.empty())
				now.push_back(g);
		}
	}
	cout<<now[0].w<<endl;
	return 0;
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

unordered_set<int> a;

int main()
{
	FAST;
	int n;
	cin >> n;

	while(1)
	{	
		if(a.count(n) == 1)
		{
			cout << a.size()+1;
			return 0;
		}
		a.insert(n);
		if(n&1)
		{
			n = 3*n + 1;
		}
		else
		{
			n = n / 2;
		}
	}
	return 0;
}

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

int main() {
  int a, b, min=-1;
  cin >> a >> b;
  for(int i=1; i<= 1010; i++) {
    int c=i*0.08, d=i*0.1;
    if(c==a && d==b){
      min=i;
      break;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define pp pair<ll,ll>
#define mp make_pair
#define PI acos(-1.0)
#define all(v) v.begin(),v.end()
#define pb push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FREV(i,a,b) for(i=a;i>=b;i--)
#define FORI(a) for(auto it=a.begin();it!=a.end();it++)
#define READ(a,i,n) FOR(i,0,n) { sll(a[i]);}
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
#define sll(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define INF 1e18
#define MOD 1000000007

using namespace std;
int32_t main()
{

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

        ll n,x,t;
        cin>>n>>x>>t;
        ll mod=n%x;
        ll timet=(n/x)*t+(mod==0?0:t);
        cout<<timet<<"\n";
    return 0;
}


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

int main() {
  
  int bingo[3][3];
  int hantei[3][3];
  
  rep(i,3)rep(j,3) cin >> bingo[i][j];
  
  int n; cin >> n;
  
  rep(i,n) {
    int x; cin >> x;
    rep(i,3)rep(j,3) if (bingo[i][j] == x) hantei[i][j] = 1;
  }
  
  bool ans = false;
  
  rep(i,3) {
    int cnt = 0;
    rep(j,3) cnt += hantei[i][j];
    if (cnt == 3) ans = true;
  }
  
  rep(i,3) {
    int cnt = 0;
    rep(j,3) cnt += hantei[j][i];
    if (cnt == 3) ans = true;
  }
  
  {
    int cnt = 0;
    rep(j,3) cnt += hantei[j][j];
    if (cnt == 3) ans = true;
  }
  
  {
    int cnt = 0;
    rep(j,3) cnt += hantei[j][2-j];
    if (cnt == 3) ans = true;
  }
  
  cout << (ans ? "Yes" : "No") << endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if(n>=400&&n<600){
        cout << 8;

    }else if(n>=600&&n<800){
        cout << 7;
    }else if(n>=800&&n<1000){
        cout << 6;
    }else if(n>=1000&&n<1200){
        cout << 5;
    }else if(n>=1200&&n<1400){
        cout << 4;
    }else if(n>=1400&&n<1600){
        cout << 3;
    }else if(n>=1600&&n<1800){
        cout << 2;
    }else if(n>=1800&&n<2000){
        cout << 1;
    }

    return 0;
}

Measured memory_bytes: 3648
use std::io::Read;
use std::cmp::min;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut a: Vec<u32> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    a.sort();
    if n <= 2 {
        println!("{}", if n == 1 {a[0]} else {a[1]});
        return;
    }
    let x = a[0];
    let y = a[1];
    let inf = 2_000_000_000 + 1;
    let mut dp = vec![inf; n];
    dp[0] = 0;
    dp[1] = y + x;
    for i in 2..n {
        dp[i] = min(dp[i], dp[i - 1] + a[i] + x);
        dp[i] = min(dp[i], dp[i - 2] + a[i] + x + y + y);
    }
    println!("{}", dp[n - 1] - x);
}

fn main() {
    run();
}



Measured memory_bytes: 5052
n=int(input())
c=[0 for _ in range(n-1)]
s=c[:]
f=c[:]
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
for i in range(n-1):
  t=0
  for j in range(i,n-1):
    cc,ss,ff=c[j],s[j],f[j]
    if t>=ss:
      if t%ff==0:
        t+=t%ff+cc
      else:
        t+=(ff-t%ff)+cc
    else:
      t=ss+cc
      
  print(t)






print(0)

Measured memory_bytes: 3064
// 2020-08-15 18:03:28
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct FenwickTree {
  int N;
  vll bit;
  void init(int n) {
    N = n;
    bit.assign(n+2, 0);
  }
  void add(int i, ll a) {
    while(i <= N) {
      bit[i] += a;
      // chmax(bit[i], a);
      i += (i & -i);
    }
  }
  ll sum(int i) {
    ll res = 0;
    while(i > 0) {
      res += bit[i];
      // chmax(res, bit[i]);
      i -= (i & -i);
    }
    return res;
  }
  int lower_bound(ll w) {
    int k = 1;
    while(k <= N) k *= 2;
    k /= 2;
    int x = 0;
    while(k > 0) {
      if(x+k <= N && bit[x+k] < w) {
        w -= bit[x+k];
        x += k;
      }
      k /= 2;
    }
    return x+1;
  }
};

using T = tuple<int, int, int>;

void answer() {
  int n, q_sz;
  cin >> n >> q_sz;
  vector<int> c(n+1);
  rep(i, n) cin >> c[i+1];
  vector<T> qs(q_sz); // l, r, qi
  rep(qi, q_sz) {
    int l, r;
    cin >> l >> r;
    qs[qi] = T(l, r, qi);
  }
  sort(RALL(qs));
  FenwickTree bit;
  bit.init(n);
  vector<int> ca(n+1, -1), ans(q_sz, -1);
  int li = n;
  for(const auto& q : qs) {
    int l, r, qi;
    tie(l, r, qi) = q;
    for(; l <= li; li--) {
      if(ca[c[li]] >= 0) {
        bit.add(ca[c[li]], -1);
      }
      ca[c[li]] = li;
      bit.add(ca[c[li]], 1);
    }
    ans[qi] = bit.sum(r);
  }
  for(auto a : ans) cout << a << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 19324
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    int n;
    cin>>n;
    int a[100];
    int ma=0,mi=1000;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ma=max(a[i],ma);
        mi=min(a[i],mi);
    }
    cout<<ma-mi<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll a, b, c, x, ans = 0;
    cin >> a >> b >> c >> x;
    rep(i, a+1)
    {
        rep(j, b+1)
        {
            rep(k, c+1)
            {
                if( (i)*500 + (j)*100 + (k)*50 == x ) ans++;
            }
        }
    }
    cout << ans;
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


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

int main()
{
	string s, t;
	int ans = 0;

	cin >> s >> t;

	sort( s.begin(), s.end() );
	sort( t.begin(), t.end() );
	if( s[0] < t[t.size() - 1] ) {
		ans = 1;
	}
	else if( s[0] == t[t.size() - 1] ) {
		int sz = s.size();
		int f = 0;
		for( int i = 0; i < sz; i++ ) {
			auto it = find( t.begin(), t.end(), s[i] );
			if( it == t.end() ) {
				f = 1;
				break;
			}
		}
		if( f == 0 && t.size() > s.size() ) {
			ans = 1;
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 52, M = 50*50;
const ll INF = 1e18;

ll dist[N][M + 1], D[N];
int C[N];

struct edge {
	int from, to, money;
	ll time;
	bool operator < (const edge& e) const {
		if(time == e.time)
			return money > e.money;
		return time > e.time;
	}
};

vector<edge> adj[N];

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int n, m, s, u, v, a, b;
	cin >> n >> m >> s;
	for (int i = 0; i < m; ++i) {
		cin >> u >> v >> a >> b;
		adj[u].push_back({u, v, a, b});
		adj[v].push_back({v, u, a, b});
	}
	for (int i = 1; i <= n; ++i) {
		cin >> C[i] >> D[i];
		for (int j = 0; j < M; ++j)
			dist[i][j] = INF;
	}
	priority_queue<edge> pq;
	s = min(s, 2500);
	pq.push({0, 1, s, 0});
//	pq.push({0, 1, s * s, 50});
//	while(!pq.empty()) {
//		cout << pq.top().time << '\n';
//		pq.pop();
//	}
//	return 0;
	dist[1][s] = 0;
	while(!pq.empty()) {
		edge e = pq.top();
		pq.pop();
		if(e.time > dist[e.to][e.money]) continue;
		if(dist[e.to][min(M, e.money + C[e.to])] > dist[e.to][e.money] + D[e.to]) {
			dist[e.to][min(M, e.money + C[e.to])] = dist[e.to][e.money] + D[e.to];
			pq.push({e.from, e.to, min(M, e.money + C[e.to]), e.time + D[e.to]});
		}
		for(auto it: adj[e.to]) {
			if(e.money >= it.money && dist[it.to][e.money - it.money] > e.time + it.time) {
				dist[it.to][e.money - it.money] = e.time + it.time;
				pq.push({e.to, it.to, e.money - it.money, e.time + it.time});
			}
		}
	}
	for (int i = 2; i <= n; ++i) {
		ll ans = INF;
		for (int j = 0; j < M; ++j)
			ans = min(ans, dist[i][j]);
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 7276
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

/*
 貪欲
 ①決定問題 必ず解に含まれる(含むように変換できる)ものから決めていく みんプロ本選B
 ②最適化問題 任意の解から評価を落とさず解に含められるようなものから決めていく 区間スケジューリングとか
 ③
 */

/*
 DP
 ①DPはある程度決め打ちをするべき
 */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> c(100001,0);
	REP(i,n) {
		ll a;
		cin>>a;
		c[a]++;
	}
	ll buf=0;
	REP(i,100001) {
		if(c[i]>1) buf+=c[i]-1;
	}
	if(buf%2==0) {
		cout<<n-buf<<endl;
	} else {
		cout<<n-buf-1<<endl;
	}
}


Measured memory_bytes: 1024
/*
Hanit Banga
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 3e5 + 5;

ll a[N];

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

	sort(a, a + 3*n);
	int ctr = 0;
	ll ans = 0;
	for (int i = 3*n - 2; ctr < n; i -= 2, ++ctr)
		ans += a[i];

	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vs = V<string>;
using vd = V<double>; using vvi = V< V<int> >; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////////////

void solve(){
  inl(K , N);
  vl a(N); in(a);
  ll s = accumulate(all(a) , 0LL);
  out(s >= K ? "Yes" : "No");
}

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

using namespace std;

int main() {
	int N, T, A;

	cin >> N;
	cin >> T >> A;


	float minDif = INFINITY;
	int minPos = 0;
	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		float x = T - h * 0.006;
		float dif = fabs(A - x);
		if (dif < minDif) {
			minDif = dif;
			minPos = i + 1;
		}
	}

	cout << minPos << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,k;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	if(k>=a+b+c)
	{
		printf("%d\n",a+c*(-1) );
	}
	else if(k>a+b)
	{
		printf("%d\n",a+(k-a-b)*(-1) );
	}
	else if(k>a)
	{
		printf("%d\n",a);
	}
	else
	{
		printf("%d\n",k );
	}
}

Measured memory_bytes: 1736
#include<iostream>
using namespace std;
const int MAX = 100;
const int INFTY = (1<<21);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],color[MAX];

    for (int i = 0; i < n ; ++i) {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;
    while(1){
        minv = INFTY;
        int u = -1;
        for (int i = 0; i < n ; ++i) {
            if( minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1) break;
        color [u] = BLACK;
        for (int v = 0; v < n ; ++v) {
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > d[u] + M[u][v]){
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for (int i = 0; i < n ; ++i) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main (){
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        for (int j = 0; j < n ; ++j) {
            M[i][j] = INFTY ;
        }
    }
    
    int k,c,u,v;
    for (int i = 0; i < n ; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k ; ++j) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    
    dijkstra();
    
    return 0;
}

Measured memory_bytes: 1200
package main

import (
	"fmt"
	"io"
	"os"
)

func solve(w io.Writer, r io.Reader) {
	var S string
	fmt.Scan(&S)

	c := 0
	for _, s := range S {
		if s == 'x' {
			c++
		}
	}
	ans := "YES"
	if c >= 8 {
		ans = "NO"
	}
	fmt.Fprintln(w, ans)
}

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


Measured memory_bytes: 512