akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x) cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x) cerr << "  (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl;
template<typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";}

int main() {
  string s;
  while (getline(cin, s)) {
    string orig;
    for (int i = 0; i <= 'z'-'a'; i++) {
      orig = s;
      for (int j = 0; j < orig.size(); j++) {
        if (orig[j] >= 'a' && orig[j] <= 'z') {
          orig[j] = 'a' + ((orig[j]-'a') + i) % ('z'-'a'+1);
        }
      }
      if (orig.find("the") != string::npos ||
          orig.find("this") != string::npos ||
          orig.find("that") != string::npos) {
        break;
      }
    }
    cout << orig << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int k, t; cin >> k >> t;
	int m = 0;
	for (int i = 0; i < k; i++){
		int a; cin >> a;
		m = max(m, a);
	}
	if (m * 2 <= k + 1)cout << 0;
	else cout << 2 * m - 1 - k;
	cout << endl;
}

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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("a_in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int A, B, C;

    cin >> A >> B;

    int max = INT_MIN;

    int add = A + B;
    int diff = A- B;
    int mul = A * B;

    if (max < add)
    {
        max = add;
    }
    if (max < diff)
    {
        max = diff;
    }
    if (max < mul)
    {
        max = mul;
    }

    cout << max;
    
    return 0;
}


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

typedef long long int ll;

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif

int main()
{
	GO
	//fioe();
	ll n,a,b;
	cin>>n>>a>>b;
	if(a==0 && b==0){
		cout<<0<<endl;
	}
	ll ans=n/(a+b);
	ll val=ans*(a+b);
	val=n-val;
	ans=ans*a;
	if(val<=a){
		ans+=val;
	}	
	else{
		ans+=a;
	}
	cout<<ans<<endl;
	return 0;
}

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

table = [0] * m
column = []

for i in range(m):
	table[i] = list(map(int, input().split()))

for j in range(n):
	column.append(int(input()))

for k in range(m):
	result = 0
	for l in range(n):
		result += table[k][l] * column[l]
	print(result)


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

int main() {
    int K;
    string S;
    cin >> K >> S;
    if(K >= S.size()){
        cout << S << endl;
    }
    else{
        for(int i = 0; i < K; i++){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3628
#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 emplace_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;
    cin >> n;
    vector<vector<pair<ll, ll>>> t(n+1);
    REP(i, n-1){
        ll u, v, w;
        cin >> u >> v >> w;
        t[u].PB(MP(v, w));
        t[v].PB(MP(u, w));
    }
    queue<ll> q;
    vector<ll> depth(n+1, -1), ans(n+1);
    ll start = 1;
    q.push(start);
    depth[start] = 0;
    while(q.empty() != true){
        ll v = q.front();
        q.pop();
        for(auto x : t[v]){
            if(depth[x.F] == -1){
                depth[x.F] = depth[v] + x.S;
                ans[x.F] = (ans[v] + x.S) % 2;
                q.push(x.F);
            }
        }
    }
    REP(i, n){
        cout << ans[i+1] << endl;
    }
    return 0;
}

Measured memory_bytes: 12216
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#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 INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    map<char, int> m;
    set<char> st;
    rep(i, s.length()) m[s[i]]++, st.insert(s[i]);
    if (st.size() != 2)
        cout << "No" << endl;
    else
    {
        for (auto i : m)
        {
            if (i.second != 2)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3636
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
	auto ab = readNums!int;
	foreach(i; 0 .. max(ab[0], ab[1])){
		write(min(ab[0], ab[1]));
	}
	writeln();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, s[1 << 18], tree[1 << 19], Q;
pair<int, int>lr[200000];
bool b[1 << 18];

void update(int x, int t) {
	int l, r;
	l = r = x;
	x += 1 << 18;
	tree[x] = min(tree[x], t);
	while (x != 1) {
		if (x & 1) {
			l -= r - l + 1;
		}
		else {
			r += r - l + 1;
		}
		x /= 2;
		tree[x] = min(tree[x * 2] + r - (l + r) / 2 - (s[r] - s[(l + r) / 2]), tree[x * 2 + 1]);
	}
}

int calc(int l, int r, int p, int q, int k) {
	if (r < p || q < l)return 0xE869120;
	if (p <= l&&r <= q)return tree[k] + q - r - (s[q] - s[r]);
	return min(calc(l, (l + r) / 2, p, q, k * 2), calc((l + r) / 2 + 1, r, p, q, k * 2 + 1));
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> b[i];
		s[i] = s[i - 1] + b[i];
	}
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		cin >> lr[i].first >> lr[i].second;
	}
	sort(lr, lr + Q);
	int t = 0;
	for (int i = 0; i < 1 << 19; ++i) {
		tree[i] = 0xE869120;
	}
	update(0, 0);
	for (int i = 1; i <= N; ++i) {
		while (t != Q&&lr[t].first == i) {
			update(lr[t].second, calc(0, (1 << 18) - 1, lr[t].first - 1, lr[t].second, 1));
			++t;
		}
		update(i, tree[(1 << 18) + i - 1] + b[i]);
	}
	cout << tree[(1 << 18) + N] << endl;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define MAX_N 50

using namespace std;


long int L[MAX_N];
long int P[MAX_N];

long int rec(long int N, long int X) {
    if (N == 0) return X == 1 ? 1 : 0;
    if (X == 1) return 0;
    if (X <= 1 + L[N - 1]) return rec(N - 1, X - 1);
    if (X == 2 + L[N - 1]) return P[N - 1] + 1;
    if (X <= 2 + 2 * L[N - 1]) return P[N - 1] + 1 + rec(N - 1, X - L[N - 1] - 2);
    if (X == L[N]) return 2 * P[N - 1] + 1;
    else {
        return -1;
    }
}

int main() {

    long int N, X;

    scanf("%ld %ld", &N, &X);
    L[0] = 1;
    P[0] = 1;
    for (int i = 1; i <= N; i++) {
        L[i] = 2 * L[i-1] + 3;
        P[i] = 2 * P[i-1] + 1;
    }

    printf("%ld\n", rec(N, X));

    return 0;
}

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

int main()
{
    int64_t X;
    cin >> X;
    int64_t yokin = 100;
    int64_t ans = 0;

    while (yokin < X)
    {
        yokin *= 1.01;
        ans ++;
    }

    cout << ans;
    
}

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

int main() {
  int n,a,b,reg;
  cin >> n >> a >> b;
  reg=0;

  for(int i=1; i<n+1; i++){
    int sum = (i/10000)%10+(i/1000)%10+(i/100)%10+(i/10)%10+i%10;
    if(sum>=a && sum<=b) reg=reg+i;
  }

  cout << reg << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,t;
  cin>>n>>t;
  vector<pair<long long int,long long int>> hoge(n);
  for(long long int i=0; i<n; i++){
    cin>>hoge.at(i).first>>hoge.at(i).second;
  }
  long long int ans=9999999999;
  bool ok=false;
  for(long long int i=0; i<n; i++){
    if(hoge.at(i).second<=t){
      ok=true;
      ans=min(ans,hoge.at(i).first);
    }
  }
  if(ok){
    cout<<ans<<endl;
  }else{
    cout<<"TLE"<<endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

class Flow{
public:
    int t,s,d;
    bool operator<(const Flow &f)const{
        return f.t>this->t;
    }
};

int main(){
    int n,m;
    while(cin>>n>>m&&!(n==0&&m==0)){
        //vector<Flow> v;
        set<Flow> s;
        for(int i = 0; i < m; i++){
            Flow f;
            cin>>f.t>>f.s>>f.d;
            //v.push_back(f);
            s.insert(f);
        }
        //sort(v.begin(),v.end());
        bool isInfected[20001];
        fill(isInfected,isInfected+20001,false);
        isInfected[1]=true;
        int cnt=1;
        for(set<Flow>::iterator it = s.begin(); it != s.end(); it++){
            if(isInfected[it->s]&&!isInfected[it->d]){
                isInfected[it->d]=true;
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  int n;
  n=2*N;
  int a=0;
  bool flag=false;
  for (int i=0;i<=N+1;i++){
    if (i*(i-1)==n){
      a=i;
      flag=true;
      break;
    }
  }
  if (flag==true){
    cout<<"Yes"<<endl;
    cout<<a<<endl;
    int A[a][a-1];
    int num[a];
    int counter=1;
    for (int i=0;i<a;i++){
      num[i]=0;
    }
    for (int j=0;j<a-1;j++){
      for (int k=j+1;k<a;k++){
        A[j][num[j]]=counter;
        A[k][num[k]]=counter;
        ++counter;
        num[j]+=1;
        num[k]+=1;
      }
    }
    for (int j=0;j<a;j++){
      cout<<a-1<<' ';
      for (int k=0;k<a-1;k++){
        cout<<A[j][k]<<' ';
      }
      cout<<endl;
    }
  }
  else{
    cout<<"No";
  }
  return 0;
}

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

char S[200];
int main()
{
	string S1,S2,S3;
	cin>>S1>>S2>>S3;
	string ans;
	ans.push_back(S1[0]);
	ans.push_back(S2[0]);
	ans.push_back(S3[0]);
	cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int i,j,k,n,m,l,a[100][100],b[100][100];
  long int s;
  scanf("%d%d%d",&n,&m,&l);
 
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);
 
  for(i=0;i<m;i++)
    for(j=0;j<l;j++)
      scanf("%d",&b[i][j]);
 
  for(i=0;i<n;i++)
    for(j=0;j<l;j++){
      s = 0;
      for(k=0;k<m;k++)
        s += a[i][k] * b[k][j] ;
      printf("%ld", s);
      if(j+1 == l)
        printf("\n");
      else
        printf(" ");
    }
 
  return 0;
}


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

int N,W;
int a[256],b[256];
const int mod=1e9+7;
int main(){
    cin>>N>>W;
    for(int i=0;i<N;i++)cin>>a[i];
    sort(a,a+N);
    reverse(a,a+N);
    for(int i=N-1;i>=0;i--){
        b[i]=b[i+1]+a[i];
    }

    int dp[10001]={0};
    dp[0]=1;

    for(int i=0;i<N;i++){
        int latte=W-b[i];
        for(int j=W;j>0;j--){
            if(j-a[i]<0||j-a[i]<=latte)continue;
            dp[j]=(dp[j-a[i]]+dp[j])%mod;
        }
        //for(int j=0;j<=W;j++)cout<<dp[j]<<" ";cout<<endl;
    }

    int ans=0;
    for(int i=0;i<=W;i++)ans=(ans+dp[i])%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, m, c;
	cin >>n >> m >> c;
	int b[20];
	int a[20][20];
	int count = 0, sum = 0;
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	for (int i = 0; i < n; i++)
	{
		sum = 0;
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
			sum += a[i][j] * b[j];
		}
		if (sum + c > 0)count++;
	}
	cout << count;
}

Measured memory_bytes: 256
import java.io.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public int[][] move = new int[][]{
		{0, -1}, {1, 0}, {0, 1}, {-1, 0}
	};
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = in.readLine();
		int size = Integer.parseInt(line);
		for(int i=0; i<size; i++){
			line = in.readLine();
			int n = Integer.parseInt(line);
			int data[][] = new int[n][n];
			int flag = 1;
			
			drawCorner(data, flag, 0, 0, n, n);
			
			
			for(int y=0; y<n; y++){
				for(int x=0; x<n; x++){
					if(data[y][x]==1){
						System.out.print("#");
					}else{
						System.out.print(" ");
					}
				}
				System.out.println();
			}
			if(i!=size-1){
				System.out.println();
			}
		}
	}
	
	public void drawCorner(int[][] data, int flag, int x, int y, int xm, int ym){
		int first = 1;
		if(x==0 && y==0){
			first = 0;
		}
		
		if(x>=xm || y>=ym){
			return;
		}
		
		if(flag==1){
			for(int i=x; i<xm; i++){
				data[y][i] = 1;
			}
			
			for(int j=y; j<ym; j++){
				data[j][x] = 1;
			}
			
			drawCorner(data, -flag, x+2, y+1, xm, ym-first);
		}
		
		if(flag==-1){
			for(int i=x; i<xm; i++){
				data[ym-1][i] = 1;
			}
			
			for(int j=y; j<ym; j++){
				data[j][xm-1] = 1;
			}
			
			drawCorner(data, -flag, x, y+1, xm-2, ym-1);
		}
	}
}

Measured memory_bytes: 10000
#include <bits/stdc++.h>
#define rep(i,s,t) for (int i=s;i<=t;++i)
#define fi first
#define se second
const int maxn=4e6+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
ll quick_mod(ll x,ll y){
    ll ans=1;
    for (;y;y>>=1){
        if (y&1) ans=ans*x%mod;
        x=x*x%mod;
    }
    return ans;
}
ll fac[maxn],inv[maxn],ans;
ll dp[2010][2010];
void init(){
    fac[0]=1;
    rep(i,1,maxn-10) fac[i]=fac[i-1]*i%mod;
    inv[maxn-10]=quick_mod(fac[maxn-10],mod-2);
    for (int i=maxn-11;i>=0;--i){
        inv[i]=inv[i+1]*(i+1)%mod;
    }
}
ll c(int n,int m){
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
    init();
    int n,k; scanf("%d%d",&n,&k);
    if (k==1) return 0*puts("1");
    dp[0][0]=1;
    rep(i,0,n){
        rep(j,0,n){
            if (i) (dp[i][j]+=dp[i-1][j])%=mod;
            if (j>i) (dp[i][j]+=dp[i][j-1]*c(i+j*(k-1)-1,k-2)%mod)%=mod;
        }
    }
    printf("%lld\n",fac[n]*dp[n][n]%mod);
    return 0;
}


Measured memory_bytes: 94336
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, i, f=0;
  cin>>n;
  int a[n], b[n];
  for(i=0; i<n; i++)
  {
    cin>>a[i]>>b[i];
  }
  for(i=0; i<n-2; i++)
  {
    if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2])
    {
 		cout<<"Yes\n";
      f=1;
      break;
    }
  }
  if(f==0)
    cout<<"No\n";
  return 0;
}


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


int main(){
  string s;
  cin >>s;
  int n = s.size();
  int count =0 ;
  for (int i = 0;i<n/2;i++){
  //  cout<<s.at(i)<<" : "<<s.at(n-i-1)<<endl;
    if (s.at(i)!=s.at(n-i-1)){
      count++;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

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

int main() {
  int x, y;
  cin >> x >> y;
  int win[4] = {300000, 200000, 100000, 400000};
  int money = 0;
  if (x <= 3) money += win[x-1];
  if (y <= 3) money += win[y-1];
  if (x * y == 1) money += win[3];
  cout << money << endl;
  return 0;
}

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

int main () {
    long long n; cin >> n;
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
        if (i%3 != 0 && i%5 != 0) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(n), r(n);
    rep(i, k)cin >> l[i] >> r[i];
    vector<ll> dp(n + 1);
    vector<ll> dpsum(n + 1);
    dp[1] = 1;
    dpsum[1] = 1;//dpの累積和
    for (int i = 2; i <= n; i++) {
        rep(j, k) {
            int li = i - r[j];
            int ri = i - l[j];
            if (ri < 0)continue;
            li = max(li, 1);
            dp[i] += dpsum[ri] - dpsum[li - 1];//現在位置iからの差分のdpsumが更新に必要となる
            dp[i] %= 998244353; 
            if (dp[i] < 0)dp[i] += 998244353;
        }
        dpsum[i] = dpsum[i - 1] + dp[i];
        dpsum[i] %= 998244353;
        if (dpsum[i] < 0)dpsum[i] += 998244353;
    }
    cout << dp[n] << endl;

    return 0;
}

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

using namespace std;

#define ll  long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

ll n;
vector< pair<ll,ll> > v;
priority_queue< pair<ll,ll> > q , q2 , q3 , q4;

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

    cin >> n;
    for(int i=1; i<=n; i++)
    {
        ll x,y;
        cin >> x >> y;
        v.push_back({x , y});
        q.push({x+y , i-1});
        q2.push({-x+y , i-1});
        q3.push({x-y , i-1});
        q4.push({-x-y , i-1});
    }

    ll ans=0;
    for(int i=0; i<v.size(); i++)
    {
        ll x = v[i].f , y = v[i].s;
        pair<ll,ll> tmp;

        if (q.top().s==i)
        {
            tmp = q.top();
            q.pop();
        }
        ll tmp2 = q.top().f;
        if (q.size() != n) q.push(tmp);
        ans = max(ans , tmp2-x-y);

        if (q2.top().s==i)
        {
            tmp = q2.top();
            q2.pop();
        }
        tmp2 = q2.top().f;
        if (q2.size() != n) q2.push(tmp);
        ans = max(ans , tmp2+x-y);

        if (q3.top().s==i)
        {
            tmp = q3.top();
            q3.pop();
        }
        tmp2 = q3.top().f;
        if (q3.size() != n) q3.push(tmp);
        ans = max(ans , tmp2-x+y);

        if (q4.top().s==i)
        {
            tmp=q4.top();
            q4.pop();
        }
        tmp2 = q4.top().f;
        if (q4.size() != n) q4.push(tmp);
        ans = max(ans , tmp2+x+y);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 19036
import java.util.*;
import java.io.*;

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");
        int[] numbers = new int[n];
        int ans = 0;
        
        for(int i = 0; i < n; i++){
            numbers[i] = Integer.parseInt(input[i]);
            if(i % 2 == 0 && numbers[i] % 2 != 0){
                ans++;
            }
        }
        
        out.println(ans);
        out.close();
        
    }
}

Measured memory_bytes: 32704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,m,ans=0;
    scanf("%d%d",&n,&m);
    int x,y,a[n];
    bool red[n];
    for (int i=0; i<n; i++){
        a[i]=1;
        red[i]=false;
    }
    red[0]=true;
    for (int i=0; i<m; i++){
        scanf("%d%d",&x,&y);
        a[x-1]--;
        a[y-1]++;
        if (red[x-1]==true){
            red[y-1]=true;
        }
        if (a[x-1]==0){
            red[x-1]=false;
        }
    }
    for (int i=0; i<n; i++){
        if (a[i]>0 && red[i]==true){
            ans++;
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 640
N,M = map(int, input().split())

#data = [[N+1]*3 for i in range(M)]
data = []
for i in range(1, M+1):
    p,S = map(str, input().split())
    s = 0
    if S == 'AC':
        s = 1
    data.append([int(i),int(p),int(s)])


sorted_data = sorted(data, key=lambda x:(x[1], x[0]))

before = 0
is_ac = False
ac_num = 0
wa_num = 0
tmp = 0
for val in sorted_data:
    if before == val[1]:
        if is_ac:
            continue
        else:
            if val[2] == 1:
                ac_num += 1
                wa_num += tmp
                is_ac = True
            else:
                tmp += 1
    else:
        is_ac = False
        before = val[1]
        tmp = 0
        if val[2] == 1:
            ac_num += 1
            is_ac = True
        else:
            tmp += 1

print(str(ac_num)+' '+str(wa_num))

Measured memory_bytes: 70232
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		A(sc);
	}
	
	public static void A(Scanner sc) {
		int m = sc.nextInt();
		out.println(24-m+24);
	}
}

Measured memory_bytes: 21716
#include <stdio.h>

#define MAX 100005
#define NIL -1

typedef struct {int p, l, r;} Node;

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if( T[u].p == NIL ) printf("root, ");
  else if( T[u].l == NIL ) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0, c=T[u].l; c != NIL; i++, c=T[c].r) {
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++) {
      scanf("%d",&c);
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6392
#include<iostream>
using namespace std;
int main()
{
	int N;
	while (cin >> N && N != 0)
	{
		int member[100][100] = {};
		int M[100] = {};
		int K;
		int L[100] = {};
		for (int i = 0; i < N; i++)
		{
			cin >> M[i];
			for (int j = 0; j < M[i]; j++)
			{
				int p;
				cin >> p;
				member[i][j] = p;
			}
		}

		cin >> K;
		for (int i = 0; i < K; i++)
		{
			int l;
			cin >> l;
			L[i] = l;
		}

		int ansCount = 0;
		int ansNumber = -1;
		for (int i = 0; i < N; i++)
		{
			int cnt = 0;
			for (int j = 0; j < M[i]; j++)
			{
				for (int k = 0; k < K; k++)
				{
					if (L[k] == member[i][j])cnt++;
				}
			}
			if (cnt == K)
			{
				ansNumber = i + 1;
				ansCount++;
			}
		}

		if (ansCount > 1 || ansNumber == -1)
		{
			cout << -1 << endl;
		}
		else
		{
			cout << ansNumber << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
using namespace std;
int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int i;
  for(i=0;i<tx-sx;i++)cout << 'R';
  for(i=0;i<ty-sy;i++)cout << 'U';
  for(i=0;i<tx-sx;i++)cout << 'L';
  for(i=0;i<ty-sy;i++)cout << 'D';
  cout << 'D';
  for(i=0;i<tx-sx+1;i++)cout << 'R';
  for(i=0;i<ty-sy+1;i++)cout << 'U';
  cout << "LU";
  for(i=0;i<tx-sx+1;i++)cout << 'L';
  for(i=0;i<ty-sy+1;i++)cout << 'D';
  cout << 'R' << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int a, b, k;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll x = A.size();
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());

    ll y = A.size();

    if (x == y) { cout << "YES" << endl; }
    else { cout << "NO" << endl; }

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <vector>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n, a;
    cin >> n >> a;

    ll rem = n % 500;

    if (rem <= a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
def g(A,l,m,r):
 global c
 L=A[l:m]+[1e10]
 R=A[m:r]+[1e10]
 i=j=0
 for k in range(l,r):
  if L[i]<R[j]:A[k]=L[i];i+=1
  else:A[k]=R[j];j+=1
  c+=1
def s(A,l,r):
 if l+1<r:
  m=(l+r)//2
  s(A,l,m)
  s(A,m,r)
  g(A,l,m,r)
c=0
n=int(input())
A=list(map(int,input().split()))
s(A,0,n)
print(*A)
print(c)


Measured memory_bytes: 63176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll n;
set<string> ans;

void dfs(vector<ll> &vs) {
    if (sz(vs) == n) {
        string tmp = "";
        rep(i, n) tmp += (char)(vs[i] + 'a');
        ans.insert(tmp);
        return;
    }
    ll mv = *max_element(all(vs));
    rep(i, mv + 2) {
        vs.push_back(i);
        dfs(vs);
        vs.pop_back();
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n;
    vector<ll> vs(1, 0);
    dfs(vs);
    for(auto x : ans) printf("%s\n", x.c_str());
    return 0;
}


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

int main(){
  int A,B,C,K;
  cin >>A>>B>>C>>K;
  
  int M = max({A,B,C});
  int sum = A+B+C - M;
  rep(i,0,K) M *= 2;
  
  int ans = sum + M;
  cout <<ans<< endl;
}

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

bool visited[200000];
int n, m;
int mark[200000];
vector<vector<int>> adj;

int main()
{
	scanf("%d %d", &n, &m);
	adj = vector<vector<int>> (n+5);
	for(int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	queue<int> q;
	q.push(1);
	memset(visited, 0, sizeof(visited));
	memset(mark, 0, sizeof(mark));
	mark[1] = 1;
	while(!q.empty()) {
		int v = q.front();
		q.pop();
		for(int to : adj[v]) {
			if(!mark[to]){
				mark[to] = v;
				q.push(to);
			}
		}
	}

	int c = count(mark+1, mark+n+1, 0);
	if(c) printf("No\n");
	else {
		printf("Yes\n");
		for(int i = 2; i <= n; i++) {
			printf("%d\n", mark[i]);
		}
	}
}

Measured memory_bytes: 10792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int maxn=222222;
int main()
{
    ll a,b;
    cin>>a>>b;
    if((a+b)%3==0 || a%3==0 || b%3==0)puts("Possible");
    else puts("Impossible");
    return 0;
}

Measured memory_bytes: 256
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False]*102
for i in p:
    flag[i] = True
for j in range(0, 102):
    l = max(0, x-j)
    r = min(101, x+j)
    if not flag[l]:
        print(l)
        sys.exit()
    if not flag[r]:
        print(r)
        sys.exit()


Measured memory_bytes: 9192
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

i = 0
j = 0
count = 0
a = [0]*N
b = [0]*M
ans = 0

sum = 0
for i in range(N):
    sum += A[i]
    a[i] = sum
sum = 0
for j in range(M):
    sum += B[j]
    b[j] = sum

ind = bisect.bisect_right(b, K)
ans = ind

for i in range(N):
    if a[i] <= K:
        ind = bisect.bisect_right(b, K-a[i])
        ans = max(ans, ind+i+1)
    else:
        break

print(ans)


Measured memory_bytes: 47376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll h,w;cin>>h>>w;
    string s[h];
    rep(i,0,h-1){
        cin>>s[i];
    }
    ll dp[h][w];
    dp[0][0]=1;
    rep(i,0,h-1){
        rep(j,0,w-1){
            if(s[i][j]=='.'){
                if(i==0 && j==0)continue;
                if(i==0){
                    dp[i][j]=dp[i][j-1];
                    continue;
                }
                if(j==0){
                    dp[i][j]=dp[i-1][j];
                    continue;
                }
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%i_7;
            }else{
                dp[i][j]=0;
            }
        }
    }
    
    cout<<dp[h-1][w-1]%i_7<<endl;
    return 0;
}


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

ll N;

int main() {
    cin >> N;

    vector<ll> v(N);
    rep(i, N) cin >> v[i];

    vector<ll> sum_l(N + 1);
    sum_l[0] = v[0];
    rep(i, N) {
        sum_l[i + 1] += __gcd(sum_l[i], v[i]);
    }

    // for (int i = 0; i < sum_l.size(); i++) {
    //     cout << sum_l[i] << endl;
    // }

    vector<ll> sum_r(N + 1);
    // 最後の要素
    sum_r[N] = v[N - 1];
    rep(i, N) {
        sum_r[N - i - 1] += __gcd(sum_r[N - i], v[N - i - 1]);
        // printf("i: %d, sum_r[i]: %d v: %d\n", i, sum_r[i], v[N - i - 1]);
    }

    // for (int i = 0; i < sum_r.size(); i++) {
    //     // printf("i: %d, sum_r[i]: %d\n", i, sum_r[i]);
    //     cout << sum_r[i] << endl;
    // }

    ll ans = 0;
    rep (i, N) {
        ll tmp = 0;
        if (i == 0) {
            // 左端の時
            tmp = sum_r[i + 1];
        } else if (i == N - 1) {
            // 右端の時
            tmp = sum_l[i];
        } else {
            ll left_gcd = sum_l[i];
            ll right_gcd = sum_r[i + 1];
            tmp = __gcd(left_gcd, right_gcd);
        }

        ans = max(ans, tmp);
    }

    cout << ans << endl;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

bool check(string s){
	int chr[28] = {};
	if(s.size() < 2){
		return false;
	}

	for(int i=0; i<s.size(); i++){
		chr[s[i]-'a']++;
		if(chr[s[i]-'a'] > s.size()/2){
			return true;
		}
	}

	return false;
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string s;
	cin >> s;

	char b = ' ';
	char b2 = ' ';
	for(int i=0; i<s.size(); i++){
		if(b == s[i]){
			printf("%d %d\n", i, i+1);
			return 0;
		}
		if(i > 1 && s[i-2] == s[i]){
			printf("%d %d\n", i-1, i+1);
			return 0;
		}
		b = s[i];
	}
	puts("-1 -1");

	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,k,n,m;
    double x,y,s,z,d;
    scanf("%d%lf%lf",&n,&x,&y);
    s=1000000000;
    for(i=1;i<=n;i++)
    {
        scanf("%lf",&z);
        d=x-z*0.006;
        if(fabs(d-y)<s)
        {
            s=fabs(d-y);
            k=i;
        }
    }
    printf("%d\n",k);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string s1, s2, s3; std::cin >> s1 >> s2 >> s3;
  std::cout << (char)std::toupper(s1[0]) << (char)std::toupper(s2[0]) << (char)std::toupper(s3[0]) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    REP(i,n){
        int k;
        cin >> k;
        a.push_back(k);
    }
    int alice= 0, bob = 0;
    sort(a.begin(), a.end(), greater<int>());
    REP(i,n){
        if(i % 2)  bob += a[i];
        else alice += a[i];
    }
    cout << alice - bob << endl;
}


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

using namespace std;

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

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int mod = 1e9 + 7;

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

	int n, m;
	cin >> n >> m;

	if (abs(n - m) > 1)
		return cout << 0, 0;

	if (n == m)
	{
		int a = n + m;
		ll res = 1;
		rep(i, 0, a)
		{
			if (i & 1)
			{
				res = (res * m) % mod;
				m--;
			}
			else
			{
				res = (res * n) % mod;
				n--;
			}
		}
		cout << (res * 2ll) % mod << endl;
	}
	else
	{
		if (n < m)
			swap(n, m);
		int a = n + m;
		ll res = 1;
		rep(i, 0, a)
		{
			if (i & 1)
			{
				res = (res * m) % mod;
				m--;
			}
			else
			{
				res = (res * n) % mod;
				n--;
			}
		}
		cout << res << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


signed main() {
  fio();
  int n, m;
  cin >> n >> m;
  vi a(n), b(m);
  rep (i, n) cin >> a[i];
  rep (i, m) cin >> b[i];

  vll dp(n + 1, vl(m + 1));
  dp[0][0] = 1;
  rep (i, n) {
    ll add = 0;
    rep (j, m + 1) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j > 0 and a[i] == b[j - 1]) {
        (dp[i + 1][j] += add) %= MOD;
      }
      (add += dp[i][j]) %= MOD;
    }
  }
  ll ans = 0;
  rep (j, m + 1) {
    (ans += dp[n][j]) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

    vector<int> num(n+1, -1);
    for (int i=0; i<m; i++) {
        int s, c;
        cin >> s >> c;
        if (s == 1 && c == 0 && n != 1) {
            cout << -1 << endl;
            return 0;
        }
        if (num[s] != -1 && num[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        num[s] = c;
    }

    if (n == 1 && num[1] == -1) {
        cout << 0 << endl;
        return 0;
    }

    for (int i=1; i<=n; i++)
        if (num[i] != -1)
            cout << num[i];
        else if (i != 1)
            cout << 0;
        else
            cout << 1;
    cout << endl;
}


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

using namespace std;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;

vector <int> a;

bool cmp(int x, int y) {
	return abs(x) > abs(y);
}

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		a.push_back(x);
	}
	
	sort(a.begin(), a.end(), cmp);

	int cnt = 0;
	for (int i = 0; i < k; i++) {
		cnt += (a[i] < 0);
	}
	
	if (cnt % 2 == 0) {
		long long res = 1LL;
		for (int i = 0; i < k; i++) res = res * a[i] % MOD;
		printf("%lld\n", res);
	}
	else {
		// add neg or remove neg
		int firstNeg = INF;
		int firstPos = INF;
		for (int i = k; i < n; i++) {
			if (a[i] < 0) {
				if (firstNeg == INF) firstNeg = i;
			}
			else {
				if (firstPos == INF) firstPos = i;
			}
		}
		
		int leastNeg = INF;
		int leastPos = INF;
		for (int i = k - 1; i >= 0; i--) {
			if (a[i] < 0) {
				if (leastNeg == INF) leastNeg = i;
			}
			else {
				if (leastPos == INF) leastPos = i;
			}
		}
		
		long long res = 1LL;
		
		if ((firstNeg == INF || leastPos == INF) && (firstPos == INF || leastNeg == INF)) {
			for (int i = 0; i < k; i++) res = res * a[n - i - 1] % MOD;
		}
		else if (firstNeg == INF || leastPos == INF) {
			for (int i = 0; i < k; i++) {
				if (i == leastNeg) continue;
				res = res * a[i] % MOD;
			}
			res = res * a[firstPos] % MOD;
		}
		else if (firstPos == INF || leastNeg == INF) {
			for (int i = 0; i < k; i++) {
				if (i == leastPos) continue;
				res = res * a[i] % MOD;
			}
			res = res * a[firstNeg] % MOD;
		}
		else {
			if (1LL * a[firstNeg] * a[leastNeg] < 1LL * a[firstPos] * a[leastPos]) {
				for (int i = 0; i < k; i++) {
					if (i == leastNeg) continue;
					res = res * a[i] % MOD;
				}
				res = res * a[firstPos] % MOD;
			}
			else {
				for (int i = 0; i < k; i++) {
					if (i == leastPos) continue;
					res = res * a[i] % MOD;
				}
				res = res * a[firstNeg] % MOD;
			}
		}
		
		printf("%lld\n", (res + MOD) % MOD);
	}
}


Measured memory_bytes: 4380
#include<iostream>
#include <cmath>

using namespace std;

int main (void) {

    int N, T, A;
    int H[1010];

    cin >> N;
    cin >> T >> A;
    for (int i = 0; i < N; i++) cin >> H[i];


    double temp = 100000;
    double diff = 100000;
    int max = 0;

    for (int i = 0; i < N; i++) {
        temp = T - (double)(H[i]*0.006);

        //cout << fabs(diff - A) << endl;
        //cout << fabs(temp - A) << endl;
        if (fabs(diff-A) > fabs(temp-A)) {
            diff = temp;
            max = i + 1;
        }
    }

    cout << max << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int num2 = scan.nextInt();
        int num3 = scan.nextInt();
        int i;
        int j=0;
      
        for(i=num2; i<=num3;i++){
            if(i%num1==0){
                System.out.println("OK");
                j=1;
                break;
                }
            }
        if(j==0)
              System.out.println("NG");
        scan.close();
    }
}



Measured memory_bytes: 35724
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    if(N == 0) {cout << 0 << endl; return 0;}
    int cnt = 0;
    string A;
    while(N != 0) {
        if(cnt % 2 == 0) {
            if(abs(N) % 2 == 1) {
                N -= 1;
                A = "1" + A;
            } else {
                A = "0" + A;
            }
        } else {
            if(abs(N) % 2 == 1) {
                N += 1;
                A = "1" + A;
            } else {
                A = "0" + A;
            }
        }
        N /= 2;
        //N *= -1;
        cnt++;
    }
    cout << A << endl;

    return 0;
}



Measured memory_bytes: 256