akhauriyash/Code-Regression huggingface dataset:
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-5-5 20:57:41
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

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

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

int main(int argc, char const *argv[]) {
  int n, cnt = 0;
  cin >> n;
  vector<int> p(n);
  for (size_t i = 0; i < n; i++) cin >> p[i];
  vector<int> tmp(p);

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

  for (size_t i = 0; i < n; i++)
    if (tmp[i] != p[i]) cnt++;

  if (cnt == 0 || cnt == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  char c[N];
  for (int i = 0; i < N; i++) {
    cin >> c[i];
  }
  
  int flip = 0;
  

  for (int i = 0; i < N - 1; i++) {
    if (c[i] != c[i + 1]) flip++;
  }
  
  int unhappy = flip + 1;
  int op = 0;
  
  while (unhappy > 2 && op < K) {
    unhappy = unhappy - 2;
    op++;
  }
  
  if (op == K) {
    cout << N - unhappy << endl;
  } else {
    cout << N - 1 << endl;
  }
}
    
  


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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        long a = sc.NextLong();
        long b = sc.NextLong();
        
        long d = 1;
        long ans = 0;
        for (int i = 0; i < 40; i++)
        {
            ans |= ((Count(b, d) - Count(a - 1, d)) % 2) << i;
            d <<= 1;
        }
        Console.WriteLine(ans);
    }

    static long Count(long n, long d)
    {
        return Math.Max((n + 1) / (2 * d) * d, 0) + Math.Max((n + 1 - ((n + 1) / (2 * d) * (2 * d) + d)) % d, 0);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int N;
  ll a[100010],x,cnt=0;
  std::cin >> N >> x;
  for(int i=0; i<N; i++) std::cin >> a[i];

  if(a[0]>x){
    cnt+=a[0]-x;
    a[0]=x;
  }

  for(int i=0; i<N-1; i++){
    ll sum=a[i]+a[i+1];
    while(sum>x){
      a[i+1]--; cnt++;
      sum--;
    }
  }
  std::cout << cnt << '\n';
  return 0;

}


Measured memory_bytes: 1024
# A
import copy
N = int(input())
b = list(map(int,input().split()))
flag = True
ans = copy.copy(b)
for i in range(N):
    check = i + 1 - b[i]
    if check < 0:
        flag = False
        break
    elif check > 0:
        ans.insert(b[i]-1,ans.pop(i))

if flag:
    for i in ans:
        print(i)
else:
    print('-1')

Measured memory_bytes: 3444
import heapq

N,M = map(int,input().split())

AB = []

for i in range(N):

    A,B = map(int,input().split())

    AB.append([A,B])

AB.sort()


day = 1
i = 0
lis = []
ans = 0

while day <= M:

    if i < N and AB[i][0] == day:

        heapq.heappush(lis,-1 * AB[i][1])
        i += 1

    else:

        day += 1

        if len(lis) > 0:
            ans -= heapq.heappop(lis)

print (ans)


Measured memory_bytes: 68824
/**********************************************

1.score.cpp
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@11:54

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;

int main (void){

        while(1){
                
                int a=0,total1=0;
                int b=0,total2=0;
                
                for(int i=0; i<4; i++){
                        
                        cin >> a;                
                        total1 = total1 + a;
                }
                if(a == NULL)break;
                
                for(int i=0; i<4; i++){
                        
                        cin >> b;
                        total2 = total2 +b;                
                }
                
                if(total1 > total2){
                        cout << total1 <<endl;
                }else{
                        cout << total2 << endl;
                }
                
        }



}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);

        var AC = new bool[N + 1];
        var WA = new int[N + 1];

        for (int i = 0; i < M; i++)
        {
            var pS = ReadLine().Split(' ').ToArray();
            var (p, S) = (int.Parse(pS[0]), pS[1]);

            if(!AC[p])
            {
                if(S == "AC")
                {
                    AC[p] = true;
                }
                else
                {
                    WA[p]++;
                }
            }
        }

        WriteLine($"{AC.Count(x => x)} {WA.Where((x, i) => AC[i]).Sum()}");
    }
}


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

int main(){
    string s;
    int k;
    cin >> s >> k;
    k--;
    int idx = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != '1'){
            idx = i; break;
        }
    }
    if(k < idx) cout << "1" << endl;
    else cout << s[idx] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	char[] ch=sc.next().toCharArray();
    if(ch[0]==ch[2]){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);
const int MAXN = 2e5+5;
int fa[MAXN], fa1[MAXN];
void init()
{
    for(int i = 0; i <MAXN; i++)
    {
        fa[i] = i;
        fa1[i] = i;
    }
}
int find_root(int x)
{
    return x == fa[x] ? x : fa[x] = find_root(fa[x]);
}
int find_root1(int x)
{
    return x == fa1[x] ? x : fa1[x] = find_root1(fa1[x]);
}
void merge(int x, int y)
{
    int fx = find_root(x);
    int fy = find_root(y);
    if(fx != fy)
    {
        fa[fy] = fx;
    }
}
void merge1(int x, int y)
{
    int fx = find_root1(x);
    int fy = find_root1(y);
    if(fx != fy)
    {
        fa1[fy] = fx;
    }
}
int main()
{
    //FIN;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    init();
    int n, k, l;
    cin >> n >> k >> l;
    for(int i = 0; i < k ; i++)
    {
        int a, b;
        cin >> a >> b;
        merge1(a, b);
    }
    for(int i = 0; i < l; i++)
    {
        int a, b;
        cin >> a >> b;
        merge(a, b);
    }
    for(int i = 1; i <= n; i++)
    {
        find_root(i);
        find_root1(i);
    }
    map<P, int> m;
    for(int i = 1; i <= n; i++)
    {
        m[P(fa[i], fa1[i])]++;
    }
    for(int i = 1; i <= n; i++)
    {
        cout << m[P(fa[i], fa1[i])] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 13696
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int r = 0;
int gcd(int a,int b) {
	if (b == 0)return a;
	else r++;
	return (gcd(b, a%b));
}
int main()
{
	string s;
	cin>>s;
	rep(i, s.length())
	{
		cout<<"x";
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N,M;
  cin>>N>>M;
  vector<int> data(N+1,0);
  for (int i = 0; i < M; i++)
  {
    int L,R;
    cin>>L>>R;
    data[L]++;
    data[R+1]--;
  }
  for (int i = 0; i < N; i++)
  {
    data[i+1] += data[i];
  }
  int ANS = 0;
  // DEBUG(data);
  for (int i = 0; i < N+1; i++)
  {
    if(data[i] == M) ANS++;
  }
  cout<<ANS<<endl;
  
  
  
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 1024
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
typedef pair<int, int> P;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}

vector<ll> fact;
vector<ll> inv_fact;

void comb_init(int n) {
	fact.resize(n + 1);
	inv_fact.resize(n + 1);
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
}

ll comb(int n, int k) {
	if (n < k) return 0;
	ll ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}
int main() {
	ll N, M, K;
	cin >> N >> M >> K;
	ll ans = 0;
	comb_init(N*M);
	for (int i = 1; i < N; i++) {
		ll t = (N - i)*M*M%MOD;
		(t *= comb(N*M - 2, K - 2)) %= MOD;
		(t *= i) %= MOD;
		(ans += t) %= MOD;
	}
	for (int i = 1; i < M; i++) {
		ll t = (M - i)*N*N%MOD;
		(t *= comb(N*M - 2, K - 2)) %= MOD;
		(t *= i) %= MOD;
		(ans += t) %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int nxt[maxn][26], tmp[26];
int main(){
	long double sum = 0;
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		sum += 1.0 / x;
	}
	cout << fixed << setprecision(12) << 1.0 / sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int h1, m1, h2, m2, k;

int main() {
    scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
    int diff = (h2 - h1) * 60 + (m2 - m1);
    printf("%d\n", diff - k);
    return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
    string s; cin >> s;
    if(s[0] != s[1] || s[0] != s[2] || s[1] != s[2]){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 1000000007
ll t,n,m,i,j,k,l,arr[sz],brr[sz],crr[sz];
vector<ll>v;
int main()
{
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                l=(i*i)+(j*j)+(i*j)+(i*k)+(j*k)+(k*k);
                if(l<=10000)
                    arr[l]++;
            }
        }
    }
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        printf("%lld\n",arr[i]);
    }
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

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

  ll ans = 0;
  if ((m - n*2) < 0) {
    ans = m/2;
  } else {
    m = m - n*2;
    ans = n + m/4;
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void solve(int n,int m){
	string s,a;
	int pos,temp,now;
	bool f,ok;
	for(int i=0;i<n;i++)s.push_back('#');
	for(int x=0;x<m;x++){
		cin>>a;
		if(a[0]=='A'){
			for(int i=0;i<n;i++)if(s[i]=='#'){
				s[i]='A';
				break;
			}
		}
		else if(a[0]=='B'){
			ok=false;
			for(int i=n-1;i>=0;i--)if(s[i]=='#'){
				f=true;
				if(i<n-1){
					if(s[i+1]=='A')f=false;
				}
				if(i>0){
					if(s[i-1]=='A')f=false;
				}
				if(f){
					s[i]='B';
					ok=true;
					break;
				}
			}
			if(!ok)for(int i=0;i<n;i++)if(s[i]=='#'){
				s[i]='B';
				break;
			}
		}
		else if(a[0]=='C'){
			if(x==0)s[n/2]='C';
			else{
				for(int i=0;i<n;i++)if(s[i]!='#'){
					if(i<n-1&&s[i+1]=='#'){
						s[i+1]='C';
						break;
					}
					else if(i>0&&s[i-1]=='#'){
						s[i-1]='C';
						break;
					}
				}
			}
		}
		else{
			if(x==0)s[0]='D';
			else{
				pos=temp=now=0;
				for(int i=0;i<n;i++){
					if(s[i]=='#'){
						temp=n;
						for(int j=i-1;j>=0;j--){
							if(s[j]!='#'){
								temp=i-j;
								break;
							}
						}
						for(int j=i+1;j<n;j++){
							if(s[j]!='#'){
								if(j-i<temp)temp=j-i;
								break;
							}
							
						}
						if(temp>now){
							now=temp;
							pos=i;
						}
					}
				}
				s[pos]='D';
			}
		}
	}
	cout<<s<<endl;
}
int main(){
	int n,m;
	while(true){
		cin>>n>>m;
		if(n==0&&m==0)break;
		solve(n,m);
	}
}



Measured memory_bytes: 3064
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::*;
use proconio::{input, fastout, marker::*};

#[fastout]
fn main() {
  input!{
    a:isize,
    b:isize,
    c:isize,
    d:isize
  }
    
  println!("{}",cmp::max(cmp::max(a*c,a*d),cmp::max(b*c,b*d)));
}


Measured memory_bytes: 2200
n=int(input())
a=list(map(int,input().split()))
q=int(input())
x=[0 for i in range(10**5+1)]
su=0
y=[0 for i in range(q)]
import copy
for i in range(n):
    su+=a[i]
    x[a[i]]+=1

for i in range(q):
    b,c=map(int,input().split())
    su+=(c-b)*x[b]
    y[i]=copy.deepcopy(su)
    
    x[c]+=x[b]
    x[b]=0
    
for i  in range(q):
    print(y[i])

Measured memory_bytes: 87284
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
  char x,y;
  cin>>x;
  if('a'<=x && x<='z') p('a');
  else  p('A');
   
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int H,W;
char field[24][24];
int dis[24][24];
bool have[24][24];
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

int DFS(int x,int y) {
  int res = -1;
  queue<pair<int,int>> Q;
  for (int i = 0; i < 24; i++) {
    for (int j = 0; j < 24; j++) {
      dis[i][j] = -1;
      have[i][j] = false; 
    }
  }
  dis[x][y] = 0;
  have[x][y] = true;
  Q.push(make_pair(x,y));
  while (!Q.empty()) {
    pair<int,int> T = Q.front();
    int ax = T.first;
    int ay = T.second;
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int fx = dx[i] + ax;
      int fy = dy[i] + ay;
      if (0 <= fx && fx < H && 0 <= fy && fy < W) {
        if (!have[fx][fy] && field[fx][fy] == '.') {
          have[fx][fy] = true;
          dis[fx][fy] = dis[ax][ay] + 1;
          res = max(res,dis[fx][fy]);
          Q.push(make_pair(fx,fy));
        }
      }
    }
  }
  return res;
}



int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
    }
  }
  int ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '.') {
        ans = max(ans,DFS(i,j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

namespace ABC114_753
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            x = int.Parse(Console.ReadLine());
            if ((x == 3) || (x == 5) || (x == 7))
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

            Console.ReadKey();
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

ll bitcount(ll a) {
  ll cnt = 0;
  ll mask = 1;
  for (; mask != 0; mask <<= 1) {
    if (a & mask) cnt++;
  }
  return cnt;
}

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

  vector<ll> si(m);
  for (ll i = 0; i < m; ++i) {
    ll k;
    cin >> k;

    for (ll j = 0; j < k; ++j) {
      ll s;
      cin >> s;
      s--;
      si[i] |= 1 << s;
    }
  }

  ll p = 0;
  for (ll i = 0; i < m; ++i) {
    ll tmp;
    cin >> tmp;
    p |= tmp << i;
  }

  // on, offの2通りのN乗パターンをすべて試す
  ll ans = 0;
  for (ll i = 0; i < (1<<n); ++i) {
    bool t = true;
    for (ll j = 0; j < m; ++j) {
      ll count = bitcount(si[j] & i);
      if (count % 2 != ((p >> j) & 1)) {
        t = false;
        break;
      }
    }
    if (t) ans++;
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())

Ls = list(map(int,input().split()))
c = collections.Counter(Ls)

Ls = list(set(Ls))
Ls.sort()
N = len(Ls)

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if Ls[k]<Ls[i]+Ls[j]:
                cnt += 1 * c[Ls[i]]*c[Ls[j]]*c[Ls[k]]


print(cnt)

Measured memory_bytes: 68508
#include <stdio.h>
  
int prime(int a){
  int i;
  if(a<=1)return 1;
  if(a==2)return 0;
  if(a%2==0)return 1;
  
  for(i=3;i*i<=a;i+=2){
    if(a%i==0)return 1;
  }
  
  return 0;
}
  
int main(void){
  int i,n,a,count=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(prime(a)==0)count++;
  }
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);


int main(){

	IOS
	ll n;
	cin>>n;
	ll a[n+1];
	FOR(i,1,n) cin>>a[i];
	map<ll,ll> mp;
    ll tmp;
    ll ans=0;
	for(ll i=1;i<=n;i++){
		tmp=(i-a[i]);
		if(tmp>=0&&mp.count(tmp)){
			ans+=mp[tmp];
		}
		//dbg(i);
		mp[i+a[i]]++;



	}
	cout<<ans<<endl;


}

Measured memory_bytes: 17628
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();
        System.out.println(String.valueOf(s1.toUpperCase().charAt(0)) + String.valueOf(s2.toUpperCase().charAt(0)) + String.valueOf(s3.toUpperCase().charAt(0)));
    }
}


Measured memory_bytes: 23764
#include<iostream>

using namespace std;

int k,n;
long long  w[100000];
int f(int p){
	int j=0;
	for(int i=0;i<k;i++){
		long long s=0;
		while((s+w[j])<=p){
			s+=w[j];
			j++;
			if(j==n)return n;
		}
	}
	return j;
}
int s(){
	long long left=0;
	long long right=100000*100000;
	long long mid;
	while(right>left){
		mid=(left+right)/2;
		int v=f(mid);
		if(v>=n)right=mid;
		else left=mid+1;
	}
	return right;
}
int main(){
	
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>w[i];
	}
	long long ans=s();
	cout<<ans<<endl;
	return 0;
}


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

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

  if(N<4){
    cout << "No" << endl;
    return 0;
  }
  else{
    for(int i=0; i<=N/4; i++){
      for(int j=0; j<=N/7; j++){
        if(N==i*4+j*7){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  sort(a.begin(),a.end());
  int a_max = a[a.size()-1];
  vector<int> dp(a_max+1, 1);
  rep(i,n) {
    int ni = a[i];
    if (dp[ni] == 0) continue;
    if (dp[ni] == 2) {
      dp[ni] = 0;
      continue;
    }
    dp[ni] = 2;
    int nj = 2*ni;
    while (nj <= a_max) {
      dp[nj] = 0;
      nj += ni;
    }
  }

  int ans = 0;
  rep(i,n) {
    if (dp[a[i]] == 2) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7912
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int A, B, C, X; cin >> A >> B >> C >> X;
  int result = 0;
  rep(i, A+1) rep(j, B+1) rep(k, C+1) if (500*i+100*j+50*k==X) result++;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;

int main() {
  int r,g,b;
  cin>>r>>g>>b;
  int rgb=r*100+g*10+b;
  cout<<(rgb%4==0 ? "YES":"NO")<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#define LL long long 

using namespace std;

const LL mm = 1000000007;
int main() {
	int n;
	LL *a;
	scanf("%d", &n);
	a = new LL[n];
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &a[i]);
	}
	LL res = 0;
	for (int i = 0; i < 61; ++i) {
		LL tot = 0;
		for (int j = 0; j < n; ++j) {
			tot += ((a[j] >> i) & (LL)(1));
		}
		//printf("i = %d, tot = %lld\n", i, tot);
		LL mds = ((LL)(1) << i) % mm;
		mds *= tot;
		mds %= mm;
		mds *= ((LL)(n) - tot);
		mds %= mm;
		res += mds;
		res %= mm;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2560
import numpy as np
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max_1_idx = np.argmax(a)
max_1_val = a[max_1_idx]
a[max_1_idx] = -1
max_2_val = np.max(a)
for i in range(n):
    if i == max_1_idx:
        print(max_2_val)
    else:
        print(max_1_val)

Measured memory_bytes: 22876
#include <bits/stdc++.h>
#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, m, n) for(int i = m+1;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  int N;cin>>N;
  int A;cin>>A;
  int B;cin>>B;
  cout << min(A*N,B)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
bool isPrime(int x)
{
    if(x < 2) return false;
    for(int i = 2; i * i <= x; i++) if(x % i == 0) return false;
    return true;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        if(isPrime(x)) ans++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3172
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/********** Main()  function **********/
int main()
{
	int a,b;
	cin >> a;
	cin >> b;
	if(a>b){
		cout << "safe";
	}
	else{
		cout << "unsafe";
	}
	return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 3560
#include <stdio.h>

int main(void){

  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b) {
    if (a == c) {
      printf("1\n");
    } else {
      printf("2\n");
    }
  } else {
    if (a == c) {
      printf("2\n");
    } else if (b == c) {
      printf("2\n");
    } else {
      printf("3\n");
    }
  }

  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
  int n;
  cin >> n;
  int a[2][n];
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  int sum[2][n];
  sum[0][0] = a[0][0];
  sum[1][0] = a[1][0];
  for(int i=0;i<2;i++){
    for(int j=1;j<n;j++){
      sum[i][j] = sum[i][j-1]+a[i][j];
    }
  }
  int maxc = sum[0][0]+sum[1][n-1];
  for(int p=1;p<n;p++){
    int c = sum[0][p]+sum[1][n-1]-sum[1][p-1];
    maxc = max(maxc, c);
  }
  cout << maxc << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
//int[1e7] ll[5*1e6]

using std::cin;using std::cout;using std::endl;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    #ifdef LOCAL
    freopen("in.in", "r", stdin);
    #endif
    std::string str;bool flag = false;
    cin >> str;
    for(int i = 0;i < str.length();i++){
        if(str[i] == 'C' && flag == false) flag = true;
        if(flag == true && str[i] == 'F'){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> d(n);
  for(int i=0;i<n;i++)
    cin>>d.at(i);
  if(n>12){
    vector<int> b(13,0);
    for(int i=0;i<n;i++)
      b.at(d.at(i))++;
    bool f=(b.at(0)>0||b.at(12)>1?0:1);
    for(int i=1;i<12;i++)
      f=(b.at(i)>2?0:f);
    cout<<(f?1:0)<<endl;
    return 0;
  }
  int ma=0;
  for(int x=0;x<(1<<n);x++){
    int b=x;
    vector<int> t(n+1,0);
    for(int i=0;i<n;i++){
      t.at(i)=(b%2==1?d.at(i):24-d.at(i));
      b/=2;
    }
    int mi=12;
    for(int i=0;i<=n;i++)
      for(int j=i+1;j<=n;j++)
        mi=min(mi,min(abs(t.at(i)-t.at(j)),24-abs(t.at(i)-t.at(j))));
    ma=max(ma,mi);
  }
  cout<<ma<<endl;
}

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

#define ran 202202

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int sub(int x,int y){return (x-=y)>=0?x:x+mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int base, int p) {
		int res = 1, mu = base%mod;
		for(;p>0;p/=2) {
			if (p&1) res = mul(res, mu);
			mu = mul(mu, mu);
		}
		return res;
	}
	int rev(int x) {return pw(x, mod-2);}
};
modular_arithmetic ma;

int n, k;
int n_0;
int pos[ran], neg[ran];
int n_pos, n_neg;

int cmp(int a, int b) { return a>b; }

int main() {
	scanf("%d%d", &n, &k);
	for(int i=0;i<n;i++) {
		int x;
		scanf("%d", &x);
		if(x==0) n_0 ++;
		else 
		if(x>0) pos[n_pos++] = x;
		else neg[n_neg++] = -x;
	}
	sort(pos, pos+n_pos, cmp);
	sort(neg, neg+n_neg, cmp);
	
	int ans = -1;
	if (n==k) {
		if (n_0>0) ans = 0;
		else {
			ans = 1;
			for(int i=0;i<n_pos;i++)
				ans = ma.mul(ans, pos[i]);
			for(int i=0;i<n_neg;i++)
				ans = ma.mul(ans, neg[i]);
			if(n_neg%2) ans = ma.mod - ans;
		}
	}
	else
	if (n_neg/2*2 + n_pos < k)
		ans = 0;
	else
	if (k%2==1 && n_pos==0) {
		if (n_0 > 0) ans = 0;
		else {
			ans = 1;
			for(int i=0;i<k;i++)
				ans = ma.mul(ans, neg[n_neg-i-1]);
			ans = ma.mod - ans;
		}
	} else {
		ans = 1;
		int it_pos = 0, it_neg = 0;
		if (k%2==1) {
			ans = pos[it_pos++];
			k--;
		}
		while(k>0) {
			if (it_pos + 2 > n_pos) {
				ans = ma.mul(ans, neg[it_neg++]);
				ans = ma.mul(ans, neg[it_neg++]);
			} else 
			if (it_neg + 2 > n_neg) {
				ans = ma.mul(ans, pos[it_pos++]);
				ans = ma.mul(ans, pos[it_pos++]);
			} else 
			if (1LL*neg[it_neg]*neg[it_neg+1] < 1LL*pos[it_pos]*pos[it_pos+1]) {
				ans = ma.mul(ans, pos[it_pos++]);
				ans = ma.mul(ans, pos[it_pos++]);
			} else {
				ans = ma.mul(ans, neg[it_neg++]);
				ans = ma.mul(ans, neg[it_neg++]);
			}
			k-=2;
		}
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 4524
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<double>;

	class InputData {
	public:
		void getInput(void);
		void skipInput(void);
		Str getStr(void);
		Num getNum(void);
		BigNum getBigNum(void);
	private:
		Str str;
		Num num;
		BigNum bNum;
	};
	Str AtCoder::InputData::getStr(void) {
		return this->str;
	}
	Num AtCoder::InputData::getNum(void) {
		return this->num;
	}
	BigNum AtCoder::InputData::getBigNum(void) {
		return this->bNum;
	}
	void AtCoder::InputData::skipInput(void) {
		std::string buf = "";
		std::getline(std::cin, buf);
	}
	void AtCoder::InputData::getInput(void) {
		this->str.clear();
		this->num.clear();
		this->bNum.clear();

		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				this->str.push_back(row);
				this->num.push_back(std::atoi(row.c_str()));
				this->bNum.push_back(std::atof(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		this->str.push_back(row);
		this->num.push_back(std::atoi(row.c_str()));
		this->bNum.push_back(std::atof(row.c_str()));
	}

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::InputData* data = new AtCoder::InputData();
	data->getInput();

	AtCoder::Num num = data->getNum();
	
	const int a = num[0], b = num[1], c = num[2];

	if (a == b && a == c && b == c) {
		printf("No\n");
		return 0;
	}
	if (a != b && a != c && b != c) {
		printf("No\n");
		return 0;
	}
	printf("Yes\n");

	delete(data);

	return 0;
}

Measured memory_bytes: 888
import numpy as np
N,W=map(int,input().split())
dp=np.full(10**5+1,W+1)
dp[0]=0
for i in range(N):
    w,v=map(int,input().split())
    dp[v:]=np.minimum(dp[:-v]+w,dp[v:])
print(np.max(np.where(dp<=W)))

Measured memory_bytes: 14928
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
int main() {
	cin >> N >> K;
	vl A(N);
	for (i = 0; i < K; i++) {
		ll d;
		cin >> d;
		for (j = 0; j < d; j++) {
			ll a;
			cin >> a;
			A[a - 1] = 1;
		}
	}
	for (i = 0; i < N; i++) {
		if (!A[i]) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    for(ll i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    ll cnt = 0;
    for(ll i = 0; i < N; i++) {
        if(A[i] >= 0) break;
        cnt++;
    }

    for(ll i = 0; i < N; i++) A[i] = abs(A[i]);
    sort(A.begin(), A.end());
    ll ans = 0;
    for(ll i = 0; i < N; i++) ans += A[i];
    if(cnt % 2 != 0) ans -= (A[0]*2);

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,s=1;
  cin >> n >> k;
  for (int i=0; i<n; i++) {
    if (s*2<s+k) {
      s*=2;
    } else {
      s+=k;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
"""
Created on Thu Mar  7 01:40:39 2019

@author: yuta
"""

A,B,C = list(map(int,input().split()))

def main(a,b,c):
    rest = []
    rest.append(a % b) #rest[0]を埋めた
    if rest[0] == c:
        print("YES")
    num = 2
    count = 0
    while ((a*num) % b) != rest[0]:
        rest.append((a*num) % b)
        if (a*num) % b == c:
            count += 1
            break
        else:
            num += 1
    if count == 1:
        print("YES")
    else:
        print("NO")
main(A,B,C)
    

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
using ll = long long;
const int MOD = (int)1e9 + 7;

int main() {
    int N, M; cin >> N >> M;
    if (abs(N - M) > 1) {
        cout << 0 << endl;
        return 0;
    }
    ll fn = N, fm = M;
    for (int i = N - 1; i > 0; i--) {
        (fn *= i) %= MOD;
    }
    for (int i = M - 1; i > 0; i--) {
        (fm *= i) %= MOD;
    }
    if (N == M) {
        cout << (fn * fm * 2) % MOD << endl;
    } else {
        cout << (fn * fm) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAXN 2*1000000
#define QQQ 1000000007

typedef unsigned long long ll;

ll S[(MAXN+1)*2];
int V[MAXN+1], H[MAXN+1];
int N;

int init(int n )
{
  int i,j;
  i = 1;
  while ( i < n+1 ) i *= 2;

  for ( j = 0; j < 2*i-1; j++ ) S[j] = 0;

  return i;
}

void update ( int no, ll data, int N )
{
  S[no+N-1] = data;

  int p,t,l,r,maxno;

  p = (no+N-1-1)/2;
  t = 1;

  while ( t > 0 ) {
    t = p;
    l = p*2+1; r = p*2+2;
    maxno = (S[l] > S[r] ) ? l:r;
    if ( S[maxno] == S[p] ) break;
    S[p] = S[maxno];
    p = (p-1)/2;
  }
}

ll find(int x, int y, int no, int l, int r )
{
  if ( r <= x ) return 0;
  if ( l >= y ) return 0;
  if ( l >= x && r <= y ) return S[no];

  int mid = (l+r)/2;
  ll tmp1,tmp2;

  tmp1 = find(x,y,no*2+1,l,mid);
  tmp2 = find(x,y,no*2+2,mid,r);

  return ( tmp1 > tmp2 ) ? tmp1:tmp2;
}

ll flower(int n, int N )
{
  int i,j;
  ll tmp,tmp2,max,pos;

  for ( i = 0; i < n; i++ ) {
    pos = find(0,H[i],0,0,N+1);
    tmp = pos+V[i];
    tmp2 = S[H[i]+N-1];
    if ( tmp > tmp2 ) update(H[i],tmp,N);
  }

  max = S[0+N-1];
  for ( i = 1; i <= n; i++ ) {
    if ( max < S[i+N-1] ) max = S[i+N-1];
  }

  return max;
}

int main(void)
{
  int n,i,tmp;

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

  N = init(n);

  printf("%ld\n",flower(n,N));

  return 0;
}


Measured memory_bytes: 11136
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

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

	cin >> N >> M >> L >> R;
	L--;
	R--;
	vector<vector<int>>edge(N);
	for (int i = 0; i < M; i++) {
		cin >> H >> W;
		H--;
		W--;
		edge[H].push_back(W);
		edge[W].push_back(H);
	}
	vector<int>depthL(N, MOD);
	vector<int>depthR(N, MOD);
	Calculate_Depth(edge, depthL, L);
	Calculate_Depth(edge, depthR, R);
	//cout << depthL[R] << endl;
	if (depthL[R] == 1) {
		cout << 0 << endl;
		return 0;
	}
	long long int ans = 0;
	vector<int>Lnum(N);
	vector<int>Rnum(N);
	for (auto i : depthL)if (i != MOD)Lnum[i]++;
	for (auto i : depthR)if (i != MOD)Rnum[i]++;
	for (int i = 0; i < depthL[R] - 1; i++) {
		ans += 1LL * Lnum[i] * Rnum[depthL[R] - i - 2];
		//cout << Lnum[i] << " " << Rnum[depthL[R] - i - 2] << endl;
		//cout << ans << endl;
	}
	cout << ans << endl;
}



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

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

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

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());

    while (v.size() != 1) {
        double n_g = (v[0] + v[1]) / 2;
        v.erase(v.begin());
        v.erase(v.begin());
        v.emplace_back(n_g);
        sort(v.begin(), v.end());
    }

    printf("%f", v[0]);
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    a[i] = a[i]%2

l = a.count(1)
b = len(set(a))

if b == 1:
    print('YES')
elif a.count(1)%2 == 0:
    print('YES')
else:
    print('NO')

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

int main(){
  cout << fixed << setprecision(12);
  int N;
  cin >> N;
  vector<double> X(N,0);
  vector<double> Y(N,0);
  for(int i=0;i<N;i++){
    cin >> X[i] >> Y[i];
  }
  double sum = 0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      sum += sqrt((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]));
    }
  }
  double M = N;
  cout << sum*2/M << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    double ctr = 0;
    vector<int> a(n);
    rep (i, n) {
        int p;
        cin >> p;
        p -= i + 1;
        a[i] = p;
        ctr += p;
    }
    sort(all(a));
    int q = a[a.size()/2];
    ll ans = 0;
    rep (i, n) {
        ans += abs(a[i] - q);
    }
    cout << ans << endl;
}

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

typedef long long ll;

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0);

ll arr[200005] ;

int main()
{
  ll n, minVal, cnt = 1 ;
  cin >> n ;

  for(int i = 0; i < n; i++) {
    cin >> arr[i] ;
  }
  minVal = arr[0] ;
  for(int i = 1; i < n; i++) {
    if(arr[i] < minVal) {
      minVal = arr[i] ;
      cnt++ ;
    }
  }
  cout << cnt << endl ;

}


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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = c - a - b;
  cout << (d > 0 && 4 * a * b < d * d ? "Yes" : "No") << endl;
  return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >>d;
  if(a+b>c+d) {
    cout << "Left" << endl;
  } else {
    if(a+b==c+d) {
      cout << "Balanced" << endl;
    } else {
      cout << "Right" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(){
    int Q;
    long long max=101010;
    vector<long long> is_prime(max,1);
    is_prime[0]=0;is_prime[1]=0;

    for(long long i =2;i<max;i++){
        if(!is_prime[i]) continue;
        for(int j=i*2;j<max;j+=i)is_prime[j]=0;
    }
   
    vector<long long> like(max,0);
    for(long long i=0;i<max;i++){
        if(i%2==0) continue;
        if(is_prime[i] && is_prime[(i+1)/2])like[i]=1;
    }

    vector<long long> sum(max+1,0);
    for(long long i=0;i<max;i++){
        sum[i+1]=sum[i]+like[i];
    }

    cin>>Q;
    for(long long i =0;i<Q;i++){
        long long l,r;
        cin>>l>>r;
        ++r;
        cout<<sum[r]-sum[l]<<endl;
    }
}

Measured memory_bytes: 5432
N, K = list(map(int, input().split()))
sunuke_set = set([i for i in range(1, N + 1)])

for i in range(K):
    d = int(input())
    d_set = set(list(map(int, input().split())))
    sunuke_set = sunuke_set - d_set

ans = len(sunuke_set)
print(ans)

Measured memory_bytes: 9216