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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    char ex = 'A';
    ll ans = 0;
    REP(i, n){
        if(s[i] == ex) ans++;
        else ex = s[i];
    }
    cout << min(ans+2*k, n-1);
    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define repf(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define rep(i,n) repf((i),0,(n))
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n;
vector<ll> primes;
vector<ll> p_num(101,0);
void find_primes(ll n){
    DEBUG{cout << "find prime" << endl;}
    repf(i,1,n+1){
        if(i==1)continue;
        if(i==2){
            primes.push_back(2);
            continue;
        }
        bool flg=false;
        for(auto x:primes){
            if(i%x==0){
                flg=true;
                break;
            }
        }
        if(!flg)primes.push_back(i);
    }
}

int main(void) {
    cin >> n;
    find_primes(n/2);
    DEBUG{
        cout << "primes" << endl;
        for(auto x:primes)cout << x << endl;
        cout << "primes end" << endl;
    }
    for(auto x:primes){
        ll tmp=n,cnt=0;
        while(tmp!=0){
            cnt += tmp/x;
            tmp /= x;
        }
        p_num[x]=cnt;
    }
    ll res=0;
    int cnt74=0, cnt24=0, cnt14=0, cnt4=0, cnt2=0; 
    for(auto x:p_num){
        if(x>=74)cnt74++;
        if(x>=24)cnt24++;
        if(x>=14)cnt14++;
        if(x>=4)cnt4++;
        if(x>=2)cnt2++;
    }
    res += cnt74;
    if(cnt4>=2)res += cnt14*(cnt4-1);
    if(cnt2>=2)res += cnt24*(cnt2-1);
    if(cnt4>=2&&cnt2>=3)res += cnt4*(cnt4-1)*(cnt2-2)/2;
        // 5 5 3, 15 5, 75 1, 25 3,
    cout << res << endl;
    return 0;
}


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

using namespace std;

int n, C, d[31][31], c[3][31], ans = 0x3f3f3f3f;
bool used[31];

void search(int x, int y)
{
    if (x > 2) { ans = min(ans, y); return; }
    int sum = 0;
    for (int i = 1; i <= C; i++)
    {
        if (used[i]) continue;
        sum = 0;
        for (int j = 1; j <= C; j++) sum += c[x][j] * d[j][i];
        used[i] = true;
        search(x + 1, y + sum);
        used[i] = false;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> C;
    for (int i = 1; i <= C; i++)
        for (int j = 1; j <= C; j++) cin >> d[i][j];
    int t;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) { cin >> t; c[(i + j) % 3][t]++; }
    search(0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = tuple(map(int, input().split()))
m = [0] * n

for i in range(0, n, 2):
  m[0] += a[i]

for i in range(1, n, 2):
  m[0] -= a[i]

for i in range(n-1):
  m[i+1] = 2*a[i]-m[i]

print(*m)

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

int main(){
  int K;
  cin >> K;
  int A, B;
  cin >> A >> B;
  bool j=false;
  for(int i=0; K*i<=B; i++){
    if(K*i >= A){
      j=true;
      break;
    }
  }
  if(j==true){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;

const ll mod = 1000000007;

string s;

int main(){
  cin >> s;
  if(s == "SUN") cout << 7 << endl;
  if(s == "MON") cout << 6 << endl;
  if(s == "TUE") cout << 5 << endl;
  if(s == "WED") cout << 4 << endl;
  if(s == "THU") cout << 3 << endl;
  if(s == "FRI") cout << 2 << endl;
  if(s == "SAT") cout << 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    ll N, K;
    cin >> N >> K;
    ll cnt = 0;
    ll ans = 0;
    while (N > ans)
    {
        // cout << cnt << " " << ans << endl;
        ans += (K - 1) * pow(K, cnt);
        cnt++;
    }
    // cout << cnt << " " << ans << endl;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    if (K != 1) {
        cout << (N - K + 1) - 1 << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "bufio"
    "os"
)
var r = bufio.NewReader(os.Stdin)

func main(){
    var a, b, c int
    fmt.Fscan(r, &a, &b, &c)
    if a <= b && b <= c {
        fmt.Printf("%v %v %v\n",a,b,c)
    } else if a <= c && c <= b {
        fmt.Printf("%v %v %v\n",a,c,b)
    } else if b <= a && a <= c {
        fmt.Printf("%v %v %v\n",b,a,c)
    } else if b <= c && c <= a {
        fmt.Printf("%v %v %v\n",b,c,a)
    } else if c <= a && a <= b {
        fmt.Printf("%v %v %v\n",c,a,b)
    } else {
        fmt.Printf("%v %v %v\n",c,b,a)
    }
}



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

int main(int argc, char const *argv[])
{
	int h,w,n,sh,sw;
	string s,t;
	cin>>h>>w>>n>>sh>>sw>>s>>t;
	--sh;--sw;
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	int l=0,r=w,u=0,d=h;
	for (int i = 0; i < n; ++i)
	{
		if (t.at(i)=='L')
		{
			r=min(w,r+1);
			if (r==l)
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else if (t.at(i)=='R')
		{
			l=max(0,l-1);
			if (r==l)
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else if (t.at(i)=='U')
		{
			d=min(h,d+1);
			if (u==d)
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else if (t.at(i)=='D')
		{
			u=max(0,u-1);
			if (u==d)
			{
				cout<<"NO\n";
				return 0;
			}
		}
		if (s.at(i)=='L')
		{
			++l;
			if (r==l)
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else if (s.at(i)=='R')
		{
			--r;
			if (r==l)
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else if (s.at(i)=='U')
		{
			++u;
			if (u==d)
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else if (s.at(i)=='D')
		{
			--d;
			if (u==d)
			{
				cout<<"NO\n";
				return 0;
			}
		}
	}
	if (l<=sw&&sw<r&&u<=sh&&sh<d)
	{
		cout<<"YES\n";
	}
	else
	{
		cout<<"NO\n";
	}
	return 0;
}


Measured memory_bytes: 776
n=int(input())
l=sorted(list(map(int,input().split())))
if l[0]>=0:
  c=l[0]
  l1=[]
  for i in range(1,n-1):
    l1.append([c,l[i]])
    c-=l[i]
  score=l[-1]-c
  print(score)
  for i in l1:
    print(i[0],i[1])
  print(l[-1],c)
elif l[-1]<0:
  c=l[-1]
  l1=[]
  for i in range(0,n-1):
    l1.append([c,l[i]])
    c-=l[i]
  print(c)
  for i in l1:
    print(i[0],i[1])
else:
  l1=[]
  l2=[]
  l3=[]
  for i in l:
    if i<0:
      l1.append(i)
    else:
      l2.append(i)
  c=l1[0]
  for i in range(len(l2)-1):
    l3.append([c,l2[i]])
    c-=l2[i]
  s1=l2[len(l2)-1]
  for i in range(1,len(l1)):
    l3.append([s1,l1[i]])
    s1-=l1[i]
  score=s1-c
  print(score)
  for i in l3:
    print(i[0],i[1])
  print(s1,c)

Measured memory_bytes: 23272
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        StringBuilder s = new StringBuilder(scanner.next());
        final int q = scanner.nextInt();
        final StringBuilder start = new StringBuilder();
        final StringBuilder end = new StringBuilder();

        boolean flag = true;
        for (int i = 0; i < q; i++) {
            final int t = scanner.nextInt();
            if (t == 1) {
                flag = !flag;
                continue;
            }

            final boolean f = scanner.nextInt() == 1;
            final String c = scanner.next();

            if (flag ^ f) {
                end.append(c);
            } else {
                start.append(c);
            }
        }

        if (flag) {
            System.out.println(start.reverse().toString() + s.toString() + end.toString());
        } else {
            System.out.println(end.reverse().toString() + s.reverse().toString() + start.toString());
        }
    }
}


Measured memory_bytes: 125148
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
b = list(li())
b = [b[0]] + b + [b[-1]]

ans = 0

for i in range(n):
    ans += min(b[i], b[i+1])

print(ans)

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

int main () {
    int n, ans = 0; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b(n);
    rep(i, n) cin >> b[i];
    vector<int> c(n - 1);
    rep(i, n - 1) cin >> c[i];
    rep(i, n) a[i]--;

    rep(i, n) {
        ans += b[a[i]];
    }

    rep(i, n - 1) {
        if (a[i] + 1 == a[i + 1]) {
            ans += c[a[i]];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T>
ostream& operator<<(ostream& stream, const vector<T> v){
    stream << "[";
    for (int i=0; i<(int)v.size(); i++) cout << v[i] << " ";
    stream << "]";
    return stream;
}

int N,M,K;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M >> K;

    bool ok=0;

    int i,j;
    for (i=0; i<=N; i++)
        for (j=0; j<=M; j++){
            if (i*M+j*N-2*i*j==K) ok=1;
        }

    cout << (ok ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	V a(n);
	input(a);
	deque<ll> dis;
	
	dis.push_back(-INFLL);
	auto ter = dis.begin();
	rep(i, n) {
		ter = lower_bound(all(dis), a[i]);
		if (ter == dis.begin()) {
			dis.push_front(a[i]);
		}
		else {
			ter--;
			*ter = a[i];
		}
		
	}
	cout<<dis.size()<<endl;
}
/*
2 1 4 5 3
2
2 1
4 1
5 1
5 3
*/

Measured memory_bytes: 4832
a, b, c, d = map(int, input().split())
x = c-a
y = d-b
ans = []
for i in range(x):
    ans.append('R')
for i in range(y):
    ans.append('U')
for i in range(x):
    ans.append('L')
for i in range(y+1):
    ans.append('D')
for i in range(x+1):
    ans.append('R')
for i in range(y+1):
    ans.append('U')
ans.append('L')
ans.append('U')
for i in range(x+1):
    ans.append('L')
for i in range(y+1):
    ans.append('D')
ans.append('R')
print(''.join(ans))

Measured memory_bytes: 40176
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N)
  cin >> A[i];
  ll ans = 0;
  int left = 0, right = 0;
  ll sum = 0;
  for (; left < N; ++left)
  {
    while (right < N && (sum + A[right]) == (sum ^ A[right]))
    {
      sum += A[right];
      right++;
    }
    ans += right - left;
    if (left == right)
      right++;
    else
      sum -= A[left];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
       char ch,sh;
     scanf("%c %c",&ch,&sh);
       if (ch=='H')
       {
           if (sh=='H')
            printf("H\n");
           else
            printf("D\n");
       }
       else if (ch=='D')
       {
           if (sh=='H')
            printf("D\n");
           else printf("H\n");
       }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main {

    private static boolean isPrime(int n){
        int sqrt = (int) Math.sqrt(n) + 1;
        
        for (int i = 2; i < sqrt; i++)
            if (n % i == 0)
                return false;

        return true;
    }


    public static void main(String[] args) throws Exception{

        Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();

        int ans = 0;

        while (sc.hasNextInt())
            if (isPrime(sc.nextInt()))
                ans++;

        System.out.println(ans);
    }
}



Measured memory_bytes: 42416
#include <iostream>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

int main(){
  string S, tmp;
  int Q, tmp2;
  bool rev = false;
  list<string> buf;
  cin >> S >> Q;
  for (int i=0; i<S.size(); i++){
    buf.push_back(S.substr(i, 1));
  }
  for (int i=0; i<Q; i++){
    cin >> tmp2;
    if (tmp2 == 1){
      rev ^= true;
    }
    else{
      cin >> tmp2 >> tmp;
      bool f = (tmp2 == 1) ^ rev;
      if (f){
        buf.push_front(tmp);
      }
      else {
        buf.push_back(tmp);
      }
    }
  }
  if (rev){
    while (!buf.empty()){
      cout << buf.back();
      buf.pop_back();
    }
  }
  else{
    while (!buf.empty()){
      cout << buf.front();
      buf.pop_front();
    }
  }
  cout << endl;
  return 0;
}

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

#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
const int MOD=1e9+7;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};

void solve(vt<vt<int>>arr){
	int n=sz(arr);
	For(i,0,n-3){
		if(arr[i][0]==arr[i][1]&&arr[i+1][0]==arr[i+1][1]&&arr[i+2][0]==arr[i+2][1]){
			cout<<"Yes";return;
		}
	}
	cout<<"No";
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;cin>>n;
	vt<vt<int>>arr(n,vt<int>(2));
	FOR(n){
		cin>>arr[i][0]>>arr[i][1];
	}
	if(n<3){cout<<"No";return 0;}
	solve(arr);
}


Measured memory_bytes: 3668
#include <iostream>
#include <string>

using namespace std;


int main(){
	string A,B;  	
  	cin >> A >> B;
  	
	if(A.length()>B.length()){
    	cout <<"GREATER"<<endl;
      	return 0;
    }
  	
    if(A.length()<B.length()){
    	cout <<"LESS"<<endl;
      	return 0;
    }
  	
  	for(int i = 0; i <A.length();i++){
    	if(A[i]>B[i]){
            cout <<"GREATER"<<endl;
      		return 0;
        }
      
     	if(A[i]<B[i]){
            cout <<"LESS"<<endl;
      		return 0;
        }
    
    
    }
  	
  	cout << "EQUAL" <<endl;
  
}

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

int main() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);

	int A, B, C; cin >> A >> B >> C;
	if (A != B && B != C && A != C)cout << 3 << endl;
	else if (A == B && B == C && A == C) cout << 1 << endl;
	else cout << 2 << endl;

	return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int a, b;

int main(){
	cin >>a >> b;
	
	cout << b + (b-a) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>

using namespace std;

typedef long long ll;
#define divide 1000000007

int main(){
    ll N, M;
    cin >> N >> M;
    if(N < M) swap(N, M);
    ll ans1, ans2;
    ans1 = 1;
    if(N-M>1){
        cout << 0 << endl;
        return 0;
    }
    for(ll i=1; i<=N; i++){
        ans1 = ans1*i%divide;
        if(i==N-1 && N!=M) ans2 = ans1;
        if(i==N && N==M) ans2 = 2*ans1%divide;
    }
    ans1 = ans1*ans2%divide;
    cout << ans1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;

int n, nn[101], x, dp[100005];

int main()
{
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		scanf("%d", nn + i);
	}
	for (int i = 0; i < n; i++)
		x -= nn[i];
	/*for (int i = 0; i < n; i++)
		for (int j = x; j >= 0; j--) {
			dp[j] = max(dp[j], dp[j - nn[i]] + 1);
		}*/
	sort(nn, nn + n);

	cout << x/nn[0] + n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,c,d,e,h,w;
 
ll asum[500005],csum[500005],qsuml[500005],qsumr[500005];
char s[500005];
int main(){
    cin>>s;
	n=strlen(s);
	for(i=0;i<n;i++){
		if(s[i]=='A'){
			a++;
		}
		asum[i] = a;
		if(s[i]=='?'){
			num++;
			d++;
		}
		qsuml[i] = num;
	}
	num=0;
	for(i=n-1;i>=0;i--){
		if(s[i]=='C')c++;
		csum[i]=c;
		if(s[i]=='?'){
			num++;
			//d++;
		}
		qsumr[i] = num;
	}
	for(i=1;i<n-1;i++){
		if(s[i]=='B' || s[i]=='?'){
			if(s[i]=='?')d--;
			ans += asum[i-1] * csum[i+1] * rui(3,d);
			//p(ans);
			ans %= mod;
			ans += qsuml[i-1] * csum[i+1] * rui(3,d-1);
			//p(ans);
			ans %= mod;
			ans += asum[i-1] * qsumr[i+1] * rui(3,d-1);
			//p(ans);
			ans %= mod;
			ans += qsuml[i-1] * qsumr[i+1] * rui(3,d-2);
			//p(ans);
			ans %= mod;
			if(s[i]=='?')d++;
		}
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 15744
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(void)
{
	lli S; cin >> S;
	lli x = S / 1000000000 + 1;
	lli y = 1000000000 - S % 1000000000;
	if (S % 1000000000 == 0) {
		x--;
		y = 0;
	}

	cout << 0 << " " << 0 << " " << 1 << " " << 1000000000 << " " << x << " " << y << " " << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid (l+r)/2
#define int ll
const int mod=1e9+7,inf=0x3f3f3f3f,maxn=2e5+5;
int n,m,Q,K;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*f;
}
string s[maxn],q[maxn];
map<string,int>p;
bool cmp(string a,string b){
    return a<b;
}
signed main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    n=read();
    for(int i=1;i<=n;++i){
        cin>>s[i];
        p[s[i]]++;
    }//cout<<endl;
    int Max=0,len=0;
    for(int i=1;i<=n;++i)Max=max(Max,p[s[i]]);
    for(int i=1;i<=n;++i){
        if(p[s[i]]==Max){
            p[s[i]]=-1;
            q[++len]=s[i];
        }
    }sort(q+1,q+1+len);
    for(int i=1;i<=len;++i){
        for(int j=0;j<q[i].size();++j){
            cout<<q[i][j];
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 38912
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll dp[1 << 16];
ll cost[1 << 16];

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

    int n;
    cin >> n;

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

    for (int mask = 0; mask < (1 << n); mask++) {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (mask & (1 << i) && mask & (1 << j)) {
                    cost[mask] += a[i][j];
                }
            }
        }
    }

    for (int mask = 0; mask < (1 << n); mask++) {
        for (int mask2 = mask; mask2 > 0; mask2 = (mask2 - 1) & mask) {
            dp[mask] = max(dp[mask], dp[mask ^ mask2] + cost[mask2]);
        }
    }

    cout << dp[(1 << n) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<iomanip>
 
#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

int main(){
	vector<string> word;
	vector<int> count;

	int imax = 0;
	string s;

	while(cin >> s){
		for(int i = 0; i < s.size(); i++){
			s[i] = tolower(s[i]);
		}
		bool b = true;
		int num;
		for(int i = 0; i < word.size(); i++){
			if(word[i] == s){
				b = false;
				num = i;
				break;
			}
		}
		if(b){
			word.push_back(s);
			count.push_back(0);
		}else{
			count[num]++;
			if(count[num] > count[imax]){
				imax = num;
			}
		}
	}

	int l = 0;
	for(int i = 0; i < word.size(); i++){
		if(word[l].size() < word[i].size()){
			l = i;
		}
	}

	cout << word[imax] << ' ' << word[l] << endl;

	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}

int main() {
    ll n;
    cin >> n;
    ll che [n][3];
    for(int i=0;i<n;i++){
        cin >> che[i][0]>>che[i][1]>>che[i][2];
    }
    ll dp[n+1][3];
    for(int i=0;i<=n;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){                
                if(j==k)continue;
                dp[i+1][k]=max(dp[i+1][k],dp[i][j]+che[i][k]);
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<3;i++){
        ans = max(ans,dp[n][i]);
    }
    cout << ans << endl;
}
    



Measured memory_bytes: 8280
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
 
#define FOR1(n) for(int i=0;i<n;i++)
#define FOR2(j, n) for(int j=0;j<n;j++)
#define FOR3(i, m, n) for(int i=m;i<=n;i++)
#define ALL(c) c.begin(), c.end()
#define SCANF(x) scanf("%lld", &x)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};
 
int parents[201000];

void init(int n){
	FOR1(n){
		parents[i] = i;
	}
}

int find(int x){
	if(x == parents[x]){
		return x;
	}else{
		parents[x] = find(parents[x]); //return parents[x] = find(x);
        return parents[x];
	}
}

void unite(int x, int y) {
    parents[find(x)] = find(y);
    find(x);
}

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

signed main(){
	int n, m;
	cin >> n >> m;
    init(n + m);
    
    FOR1(n){
        int k;
        cin >> k;
        FOR2(j, k) {
            int lang;
            cin >> lang;
            lang += n - 1;
            unite(i, lang);
        }
    }
    
    FOR1(n){
        if (!same(0, i)) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = 1000000007;
		int N  = sc.nextInt();
		long ans = 1;
		for(int i = 2; i <= N; i++) {
			ans = ans * i % w;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int dp[50];
int main(){
  int n;
  while(cin>>n,n){
    dp[0]=1;
    dp[1]=1;
    dp[2]=2;
    for(int i=3;i<=n;i++){
      dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
    }
    cout<<(dp[n]+3649)/3650<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void) {

  int n;
  scanf("%d", &n);
  char s[n+1];
  scanf("%s", s);
  int west[n];
  west[0] = 0;
  for (int i = 0; i < n-1; i++) {
    west[i+1] = west[i];
    if (s[i] == 'W') {
      west[i+1]++;
    }
  }
  int east[n];
  east[n-1] = 0;
  for (int i = n-1; i > 0; i--) {
    east[i-1] = east[i];
    if (s[i] == 'E') {
      east[i-1]++;
    }
  }
  int min = west[0]+east[0];
  for (int i = 1; i < n; i++) {
    if (west[i]+east[i] < min) {
      min = west[i]+east[i];
    }
  }
  printf("%d\n", min);

  return 0;
}

Measured memory_bytes: 2816
a,b,c,d=map(int,input().split())
if c%b==0:
    x=c/b
else:
    x=c//b+1
if a%d==0:
    y=a/d
else:
    y=a//d+1
    
x=int(x)
y=int(y)
if x>=y+1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9132
package main

import "fmt"

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	current := a[0]
	a = a[1:]
	for {
		if current == 'a' {
			if a == "" {
				fmt.Println("A")
				break
			}
			current = a[0]
			a = a[1:]
			continue
		}
		if current == 'b' {
			if b == "" {
				fmt.Println("B")
				break
			}
			current = b[0]
			b = b[1:]
			continue
		}
		if current == 'c' {
			if c == "" {
				fmt.Println("C")
				break
			}
			current = c[0]
			c = c[1:]
			continue
		}
	}
}


Measured memory_bytes: 512
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int kin = 0;
		int a,b;
		for(int i=0;i<4;i++){
			a = sc.nextInt();
			b = sc.nextInt();
			switch (a) {
			case 1:
				kin =6000*b;
				break;
			case 2:
				kin =4000*b;
				break;
			case 3:
				kin =3000*b;
				break;
			case 4:
				kin =2000*b;
				break;
			}
			System.out.println(kin);
		}
	}

}

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

int main() {
  int N,T;
  cin >> N >> T;
  int ans = T;
  vector<int> t(N);
  for (int i=0; i<N; i++) {
    cin >> t[i];
  }
  for (int i=0; i<N-1; i++) {
    ans += min(T,t[i+1]-t[i]);
  }
  cout << ans << endl;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/* standard add x to A[L,R) and query A[i] */

const int maxn = 2e5+5;
int tree[4*maxn], pre[maxn], post[maxn]; VI G[maxn];

void add(int i, int j, const int v, const int n)
{
    for (i += n, j += n; i < j; i /= 2, j /= 2) {
        if (i&1) { tree[i++] += v; }
        if (j&1) { tree[--j] += v; }
    }
}

void pushdown(const int n)
{
    for (int i = 1; i < n; i++) {
        tree[i*2] += tree[i]; tree[(i*2)|1] += tree[i]; tree[i] = 0;
    }
}

void dfs(const int u, const int p, int& label)
{
    pre[u] = label++;
    FOR_ALL(v,G[u]) if (*v != p)
        dfs(*v,u,label);
    post[u] = label++;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    while (cin >> n >> q) {
        memset(tree,0,sizeof(tree));
        FOR(i,1,n+1)
            G[i].clear();
        FOR(i,0,n-1) {
            int u,v; cin >> u >> v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        int label = 1;
        dfs(1,0,label);
        FOR(i,0,q) {
            int p,x; cin >> p >> x;
            add(pre[p],post[p]+1,x,label);
        }
        pushdown(label);
        FOR(i,1,n+1)
            cout << tree[pre[i]+label] << ' ';
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 30592
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    rep(i,n-k){
        if(t[i]==t[i+k]) t[i+k]='.';
    }
    ll sum=0;
    rep(i,n){
        if(t[i]=='r') sum+=p;
        if(t[i]=='s') sum+=r;
        if(t[i]=='p') sum+=s;
    }
    cout<<sum<<endl;
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  long long a, b, c; scanf("%lld %lld.%lld", &a, &b, &c);
  printf("%lld", a * (100LL * b + c) / 100LL);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3796
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        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;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

/* -- template -- */
int cnt[200001];
int main() {
    int N; cin >> N;
    int A[N];
    rep(i, N - 1){
        cin >> A[i];
        --A[i];
        cnt[A[i]]++;
    }
    rep(i, N)
        cout << cnt[i] << endl;
}


Measured memory_bytes: 5200
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

// dp[i][j][k]
// i:確定している桁数（最大100桁だが少し多めに）
// j:Kより、0から3まで
// k:N未満(1)か否(0)か
int dp[105][4][2];

int main() {

 string N;
 cin >> N;

 int K;
 cin >> K;

 // 桁数
 int n = N.size();

 // 初期化
 dp[0][0][0] = 1;

 for (int i = 0; i < n; i++) {
   for (int j = 0; j < 4; j++) {
     for (int k = 0; k < 2; k++) {

       // 1桁ずつ見ていく
       int c_ = N[i] - '0';

       for (int c = 0; c < 10; c++) {

         // 値を入れる場所を決める
         int i_ = i + 1;
         int j_ = j;
         int k_ = k;

         // 条件 -----
         // j が 0 じゃない場合は次(j_++)を見るが
         // K を超えていたら条件を満たさないので、このループは終わり
         if (c != 0) {
           j_++;
         }
         if (j_ > K) {
           continue;
         }

         // N未満(1)か否(0)かのチェック -----
         // k が N 未満か確定していないときは
         // 見ている桁の値(c_)が c 未満のときは条件を満たさないので、このループ終わり
         // 見ている桁の値(c_)が c を超えると N 未満が確定する
         if (k_ == 0) {
           if (c_ < c) {
             continue;
           } else if (c < c_) {
             k_ = 1;
           }
         }

         // 決めた場所に値を入れる
         dp[i_][j_][k_] += dp[i][j][k];

       }
     }
   }
 }

 // n 桁の値で 0 じゃない数字が K 個あって、
 // N 未満が確定している場合と確定していない場合の値を足したものが答え
 int answer = dp[n][K][0] + dp[n][K][1];
 cout << answer << endl;

 return 0;

}

Measured memory_bytes: 256
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(-100, 200))
Nums = Nums - P
sorted(Nums)


minNum = 99999
minIndex = 0
for n in Nums:
    if minNum == abs(X-n):
        break
    if abs(X - n)< minNum:
        minNum = abs(X-n)
        minIndex = n

print(minIndex)

Measured memory_bytes: 61756
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	vector<long long> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long long ans = 0;
	for (int i = 1; i < n; i++) {
		long long add = max(0LL, a[i-1] - a[i]);
		a[i] += add;
		ans += add;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4468
import java.util.Scanner;
public class Main {

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

		int n = stdIn.nextInt();
		int m = stdIn.nextInt();

		if(n==1 && m==1) {
			System.out.println(1);
		}else if(n == 1 && m != 1) {
			System.out.println(m-2);
		}else if(m == 1 && n != 1){
			System.out.println(n-2);
		}else {
			System.out.println((long)(m-2)*(n-2));
		}



	}

}


Measured memory_bytes: 35596
use std::io;
use std::collections::HashSet;

fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}
fn read_nums() -> Vec<i64>
{
    let line = read_line();
    let items: Vec<&str> = line.split(' ').collect();

    let mut nums: Vec<i64> = Vec::new();

    for item in items {
        nums.push(to_i(item));
    }
    return nums;
}
fn main() {
    let nt = read_nums();
    let N = nt[0];
    let T = nt[1];

    let mut value = 9999;
    for i in 0..N {
        let nums = read_nums();
        //println!("{}-{} {}", i, nums.len(), value);
        let c = nums[0];
        let t = nums[1];
        //println!(" {} {}", c, t);
        if t<=T {
            //println!("<");
            if c < value {
                //println!("updatemin {}", c);
                value = c;
            }
        }
    }
    //print!("loopend");
    if value == 9999 {
        print!("TLE");
        return;
    } 
    

    print!("{}", value);


}   

Measured memory_bytes: 4352
console.log((args=>{
  const [[N,Y]] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  for ( let i = 0; i <= N; i++ ) {
    for ( let j = 0; i + j <= N; j++ ) {
      const k = N - i - j;
      if ( i*10000 + j*5000 + k*1000 === Y ) return `${i} ${j} ${k}`;
    }
  }
  return '-1 -1 -1';
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 32288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int x;
    cin >> x;
    cout << (x ^ 1) << endl;
}

Measured memory_bytes: 3632
package main

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

var scanner= bufio.NewScanner(os.Stdin)

func main() {
	result := make([][]int, 4)
	for i :=range result {
		result[i] = make([]int, 2)
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		l, _ := strconv.ParseFloat(buf[0], 64)
		r, _ := strconv.ParseFloat(buf[1], 64)
		if 1.1 <= l {
			result[0][0]++
		} else if 0.6 <= l && l < 1.1 {
			result[1][0]++
		} else if 0.2 <= l && l < 0.6 {
			result[2][0]++
		} else {
			result[3][0]++
		}
		if 1.1 <= r {
			result[0][1]++
		} else if 0.6 <= r && r < 1.1 {
			result[1][1]++
		} else if 0.2 <= r && r < 0.6 {
			result[2][1]++
		} else {
			result[3][1]++
		}
	}
	ans := make([][]string, 4)
	for i :=range ans {
		ans[i] = make([]string, 2)
	}
	for i := range result {
		for j := range result[i] {
			ans[i][j] = strconv.Itoa(result[i][j])
		}
	}
	for i := 0; i < 4; i++ {
		fmt.Println(strings.Join(ans[i], " "))
	}
}


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


int N;
string S, T;

void Main() {
  cin >> N;
  cin >> S >> T;

  rep(i, N) {
    cout << S[i] << T[i];
  }

  cout << endl;
}

int main() {
  Main();
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>

using namespace std;
int main()
{
	double N, K;
	cin >> N >> K;
	double ans = 0;
	for(double i = 1; i <= min(N, K - 1); i++)
	{
		ans += pow(0.5, ceil(log(K / i) / log(2)));
	}
	ans *= 1 / N;
	if(N > K - 1)
	{
		ans += (N - K + 1) / N;
	}

	printf("%.10f", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int[] dist = new int[k];
    for(int i = 0; i < k; i++) {
      dist[i] = Integer.MAX_VALUE;
    }
    dist[1] = 0;
    Deque<Integer> deque = new ArrayDeque<>();
    deque.addFirst(1);
    int[] visit = new int[k];
    visit[1] = 1;
    while(deque.size() > 0) {
      int u = deque.pollFirst();
      int v1 = (10 * u) % k;
      int v2 = (u + 1) % k;
      if(visit[v1] == 0)  {
        dist[v1] = Math.min(dist[v1], dist[u]);
        deque.addFirst(v1);
        visit[v1] = 1;
      } else {
        if(dist[v1] > dist[u]) {
          dist[v1] = dist[u];
          deque.remove(v1);
          deque.addFirst(v1);
        }
      }
      if(visit[v2] == 0) {
        dist[v2] = Math.min(dist[v2], dist[u] + 1);
        deque.addLast(v2);
        visit[v2] = 1;
      }
    }
    System.out.println(dist[0] + 1);
  }
}

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

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll i;
    ll ans = 0;
    for(i = 0; i < n;){
        if(i < n - 1 &&
           (s.substr(i, 2) == "OX" || s.substr(i, 2) == "XO")){
            ans++;
            i += 2;
        }else{
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i=0,j,c=0,p,h[1000010],m=0,max=0;
    int n;
    string s;
    cin >> n;
    s=to_string(n);
    for(i=1;i<=n;i++)
    {
        if(to_string(i).size()%2!=0)
        {
            m++;
        }
    }
    cout << m << endl;
    return 0;

}


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

using Int = long long int;
using UInt = unsigned long long int;


int main(void) {
    string s, t;
    cin >> s;
    t = s;
    std::reverse(s.begin(), s.end());
    if (s == t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
int H;
using namespace std;

int parent(int i){
	return i/2;
}

int left(int i){
	return 2*i;
}

int right(int i){
	return 2*i+1;
}

void maxHeapify(int *A, int i){
	int l = left(i);
	int r = right(i);
	int largest;

	if (l <= H && A[l] > A[i]){
		largest = l;
	}else{
		largest = i;
	}

	if(r <= H && A[r] > A[largest])
		largest = r;

	if (largest != i){
		swap(A[i], A[largest]);
		maxHeapify(A, largest);
	}
}


int main(){
	cin >> H;
	int *A = new int[H+1];

	for(int i=1; i<=H; ++i){
		scanf("%d", &A[i]);
	}

	for(int i=H/2; i>=1; --i){
		maxHeapify(A, i);
	}

	for(int i=1; i<=H; ++i)
		cout << " " << A[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 5108