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

#define REP(i, a) for(int64 i = 0; i < (a);i++)
#define FOR(i, a, b) for(int64 i = (a); i < (b); i++)

using int32 = int32_t;
using int64 = int64_t;

const int64 year[3] = {20*10, 20*5+19*5, 20*5+19*5};
const int64 month[3][2] = {{20, 20}, {20, 19}, {20, 19}};

int64 cnt(int64 Y, int64 M, int64 D) {
  int64 res = 0;
  FOR(i, 1, Y) {
    res += year[i%3];
  }
  REP(i, M-1) {
    res += month[Y%3][i%2];
  }
  return res+D;
}

int main(void) {
  int64 n;
  cin >> n;
  int64 mill = cnt(1000, 1, 1);
  REP(i, n) {
    int64 y, m, d;
    cin >> y >> m >> d;
    cout << mill-cnt(y, m, d) << endl;
  }
}



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


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

    vector<int> b(n+1);
    b[0] = 0;
    int m = 0;
    vector<int> out;

    for (int i = n; i > 0; --i) {
        if (i >= n / 2 + 1) {
            // iの倍数はi一つしかないから, a[i]とボールの数が一致する必要がある
            b[i] = a[i];
            if (a[i] == 1) {
                m += 1;
                out.push_back(i);
            }
        } else {
            int j = 2 * i;
            int tmp = 0;
            while (j <= n) {
                tmp += b[j];
                j += i;
            }
            if (a[i] % 2 == tmp % 2) {
                b[i] = 0;
            } else {
                b[i] = 1;
                m += 1;
                out.push_back(i);
            }
        }
    }

    cout << m << endl;
    for (int i = 0; i < out.size(); ++i) {
        cout << out[i];
        if (i + 1 < out.size()) cout << " ";
    }

    if (m > 0) cout << endl;
    return 0;
}

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
	int a,b;
	cin >> a;
	while (a!=0) {
		int ruio = 0;
		for (int i = 0; i < 9; i++) {
			cin >> b;
			ruio += b;
		}
		cout << a - ruio << endl;
		cin >> a;
	}
}

Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
string s,t;
vector<string>ans;
main()
{
	cin>>s>>t;
	if(s.size()<t.size())
	{
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	else
	{
		for(int i=s.size()-t.size();i>=0;i--)
		{
			bool flag=true;
			for(int j=0;j<t.size();j++)
			{
				if(s[i+j]!='?'&&s[i+j]!=t[j])flag=false;
			}
			if(flag)
			{
				string ss="";
				for(int j=0;j<i;j++)ss+=(s[j]=='?'?'a':s[j]);
				ss+=t;
				for(int j=i+t.size();j<s.size();j++)ss+=(s[j]=='?'?'a':s[j]);
				ans.push_back(ss);
			}
		}
	}
	if(ans.size()>0)
	{
		sort(ans.begin(),ans.end());
		cout<<ans[0]<<endl;
	}
	else cout<<"UNRESTORABLE"<<endl;
}

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

using namespace std;

#define show(x) cerr << #x << " = " << x << endl;


int main()
{
 int h, w;
 cin>>h>>w;

 char M[h+2][w+2];

 for (int i = 0; i < h+2; i++)
 {
   for (int j = 0; j < w+2; j++)
   {
     M[i][j] = '#';
   }
 }

 for (int i = 0; i <h; i++)
 {
   for (int j = 0; j < w; j++)
   {
     cin>>M[i+1][j+1];
   }
 }


 for (int i = 0; i <h+2; i++)
 {
   for (int j = 0; j < w+2; j++)
   {
     cout<<M[i][j];
     if(j==w+1)
     {
       cout<<endl;
     }
   }
 }


  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

  	int N; cin >> N;
    cout << N/3 << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7

ans = 0
A = [0 for _ in range(K+1)]
for i in range(1,K+1):
  ans += pow(K//i, N, MOD) * (i - A[i])
  ans %= MOD
  #print(ans, i)
  
  j = 2*i
  while j <= K:
    A[j] += i - A[i]
    j += i
    
print(ans)

Measured memory_bytes: 79340
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var count = 0;
            while (true)
            {
                count++;
                var num = GetNumber();
                if (num == 0)
                {
                    break;
                }

                Console.WriteLine("Case {0}: {1}", count, num);
            }
        }

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbers()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

Measured memory_bytes: 9572
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int A,B;

	cin >> A >> B;

	if (A + B < 10) {
		cout << A + B << endl;
	}
	else {
		cout << "error" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    int a[100];
    
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &a[i]);
    }
    
    for ( int i = n - 1; i >= 0; i-- ) {
        printf("%d", a[i]);
        if ( i != 0 ) {
            printf(" ");
        } else {
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2056
import sys
input=sys.stdin.readline

def solve(n,a,b,c,S):
    Ans=[]
    for i,s in enumerate(S):
        if s=='AB':
            if a==0 and b==0:
                return 'No'
            if a==1 and b==1:
                if i==n-1:
                    Ans.append('A')
                else:
                    if S[i+1]=='AB':
                        a+=1; b-=1
                        Ans.append('A')
                    elif S[i+1]=='BC':
                        a-=1; b+=1
                        Ans.append('B')
                    else:
                        a+=1; b-=1
                        Ans.append('A')
            elif a>b:
                a-=1; b+=1
                Ans.append('B')
            else:
                a+=1; b-=1
                Ans.append('A')
        if s=='BC':
            if b==0 and c==0:
                return 'No'
            if b==1 and c==1:
                if i==n-1:
                    Ans.append('B')
                else:
                    if S[i+1]=='BC':
                        b+=1; c-=1
                        Ans.append('B')
                    elif S[i+1]=='AC':
                        b-=1; c+=1
                        Ans.append('C')
                    else:
                        b+=1; c-=1
                        Ans.append('B')
            elif b>c:
                b-=1; c+=1
                Ans.append('C')
            else:
                b+=1; c-=1
                Ans.append('B')
        if s=='AC':
            if c==0 and a==0:
                return 'No'
            if c==1 and a==1:
                if i==n-1:
                    Ans.append('C')
                else:
                    if S[i+1]=='AC':
                        c+=1; a-=1
                        Ans.append('C')
                    elif S[i+1]=='AB':
                        c-=1; a+=1
                        Ans.append('A')
                    else:
                        c+=1; a-=1
                        Ans.append('C')
            elif c>a:
                c-=1; a+=1
                Ans.append('A')
            else:
                c+=1; a-=1
                Ans.append('C')
    return Ans

def main():
    n,a,b,c=map(int,input().split())
    S=[input().strip() for _ in range(n)]
    Ans=solve(n,a,b,c,S)
    if Ans=='No':
        print(Ans)
    else:
        print('Yes')
        print(*Ans,sep='\n')
    
if __name__=='__main__':
    main()

Measured memory_bytes: 85644
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int num[101];
int main(){
  int N;
  cin >> N;
  for(int i=1;i<=100;i++) num[i]=0;
  //100までの素数を作りたい
  //それらを割ることで、約数の数を配列に格納
  vector<int> sosu;
  for(int i=2;i<=100;i++){
    bool flag=true;
    for(int j=2;j*j<=i;j++){
      if(i%j==0){
        flag=false;
        break;
      }
    }
    if(flag){
      sosu.pb(i);
    }
  }
  for(int i=2;i<=N;i++){
    int tmp = i;
    while(1){
      for(int j=0;sosu[j]<=tmp;j++){
        int s = sosu[j];
        while(1){
          if(tmp%s==0){
            num[s]++;
            tmp /= s;
          }else{
            break;
          }
        }
        if(tmp==1){
          break;
        }
      }
      if(tmp==1){
        break;
      }
    }
  }
  int four=0,two=0,a=0,b=0,c=0,d=0,e=0;
  for(int i=2;i<=100;i++){
    if(num[i]>=14) a++;
    else if(4<=num[i] && num[i]<14) b++;

    if(num[i]>=24) c++;
    else if(2<=num[i] && num[i]<24) d++;

    if(num[i]>=4) four++;
    else if(2<=num[i] && num[i]<4) two++;

    if(num[i]>=74) e++;
  }
  if(four<2){
    cout << 0 << endl;
    return 0;
  }else{
    cout << ((four*(four-1))/2)*(four+two-2) + a*(a-1+b) + c*(c-1+d) + e << endl;
  }
}

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

int main(void){
	ll ans=0,n,k;
	cin>>n>>k;
	if(k==0){
		cout<<n*n<<endl;
		return 0;
	}
	for(ll b=k+1;b<=n;++b){
		ll ovo=n/b;
		ans+=ovo*(b-k);
		if(n%b>=k)
			ans+=n%b-k+1;
	}
	cout<<ans;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
ans = A[0]

t = N
if N % 2 == 1:
    t = N + 1
for i in range((t-2)//2):
    ans += 2*A[i+1]
if N % 2 == 1:
    ans -= A[i+1]

print(ans)

Measured memory_bytes: 31552
#include <iostream>
#include <vector>
 
int main() {
  int N;
  int M;
  int C;
  std::vector<int> s;
 
  std::cin >> N >> M >> C;
 
  int B;
  for (int k = 0; k < M; k++) {
    std::cin >> B;
    s.push_back(B);
  }
 
  int A;
  int count = 0;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < M; j++) {
      std::cin >> A;
      sum += A * s[j];
    }
    if (sum + C > 0) {
      count = count + 1;
    }
  }
  std::cout << count << std::endl;
  return 0;
}

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

typedef pair<int, int> step; // masu, turn

int main() {
  int N;
  cin >> N;
  vector<int> masu = vector<int>(N);
  for (auto i=0; i<N; i++) {
    cin >> masu[i];
  }
  vector<bool> checked = vector<bool>(N, false);
  vector<int> node = vector<int>(N);
  for (auto i=0; i<N; i++) {
    if (!checked[i]) {
      vector<int> V;
      vector<bool> B = vector<bool>(N, false);
      int cur = i;
      while(true) {
	if (B[cur]) { // 無限ループに突入した場合棄却
	  V.push_back(cur);
	  node[cur] = -1;
	  break;
	}
	B[cur] = true;
	V.push_back(cur);
	if (checked[cur]) {  // 過去調べたものと合流
	  break;
	}
	if (masu[cur] == 0) { // ストップの場合
	  node[cur] = cur;
	  break;
	}
	cur += masu[cur];
      }
      for (auto j=0; j<V.size(); j++) {
	checked[V[j]] = true;
	node[V[j]] = node[V[V.size()-1]];
	// cerr << V[j] << " to " << node[V[j]] << endl;
      }
    }
  }
  queue<step> Q;
  Q.push(make_pair(0 ,0));
  vector<bool> visited = vector<bool>(N, false);
  while (!Q.empty()) {
    int m = Q.front().first;
    int t = Q.front().second;
    Q.pop();
    if (m == N-1) {
      cout << t << endl;
      return 0;
    }
    if (!visited[m]) {
      visited[m] = true;
      for (auto i=1; i<=6; i++) {
	int cur_m;
	if ((cur_m = node[m+i]) < N && cur_m >= 0 && !visited[cur_m]) {
	    Q.push(make_pair(cur_m, t+1));
	}
      }
    }
  }
}

Measured memory_bytes: 2484
#include <iostream>
using namespace std;
int main(void){
    string S;
    int N,K;
    cin >> N;
    cin >> S;
    cin >> K;
    for(int i = 0; i < N; i++){
        if(S[i] != S[K-1]){
            S[i] = '*';
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL << 60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  ll D,G;
  cin >> D >> G;
  vector<ll> p(D),c(D);
  for(int i=0; i<D; i++){
    cin >> p[i] >> c[i];
  }
  ll ans = 1e5;
  for(int bit=0; bit<(1<<D); bit++){
    ll point = 0;
    ll cnt = 0;
    for(ll i=0; i<D; i++){
      if(bit & (1<<i)){
        cnt += p[i];
        point += c[i];
        point += (i+1)*100*p[i];
      }
    }
    if(point >= G){
      chmin(ans,cnt);
      continue;
    }
    for(ll i=D-1; i>=0; i--){
      if(!(bit & (1<<i))){
        if((i+1)*100*(p[i]-1)+point < G){
          point += (i+1)*100*(p[i]-1);
          cnt += p[i]-1;
        }else{
          ll num;
          num = (G-point+(i+1)*100-1)/((i+1)*100);
          cnt += num;
          point += (i+1)*100*num;
          break;
        }
      }
    }
    if(point >= G){
      chmin(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def bubbleSort(l, n):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if l[i] < l[i-1]:
                temp = l[i]
                l[i] = l[i-1]
                l[i-1] = temp
                count += 1
                flag = 1
    return count

n = int(input())
l = list(map(int, input().split()))
c = bubbleSort(l, n)
print(" ".join(map(str, l)))
print(c)



Measured memory_bytes: 5600
//21
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

const int maxn = 5001;
const int lbt = 1e9 + 7;

int n;
int xs[maxn];
vector<int> adj[maxn];
int prt[maxn];
int cnt[maxn];
int dp[maxn][maxn];

void dfs(int u);

int main() {
	scanf("%d", &n);
	xs[0] = 1;
	for (int i = 2; i <= n; i++) {
		xs[i] = (long long)(i - 1) * xs[i - 2] % lbt;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1);
	int ans = (lbt - dp[1][0]) % lbt;
	printf("%d", ans);
	return 0;
}

void dfs(int u) {
	static int tmp[maxn];
	dp[u][0] = 1;
	for (int i = 0; i < adj[u].size(); i++) {
		int v = adj[u][i];
		if (v == prt[u]) continue;
		prt[v] = u;
		dfs(v);
		for (int i = 0; i <= cnt[u] + cnt[v]; i++) {
			tmp[i] = 0;
		}
		for (int i = 0; i <= cnt[u]; i++) {
			for (int j = 0; j <= cnt[v]; j++) {
				tmp[i + j] = (tmp[i + j] + (long long)dp[u][i] * dp[v][j]) % lbt;
			}
		}
		for (int i = 0; i <= cnt[u] + cnt[v]; i++) {
			dp[u][i] = tmp[i];
		}
		cnt[u] += cnt[v];
	}
	for (int i = cnt[u]; i >= 0; i--) {
		dp[u][i + 1] = dp[u][i];
	}
	cnt[u]++;
	dp[u][0] = 0;
	for (int i = 1; i <= cnt[u]; i++) {
		if (i % 2 == 0) dp[u][0] = (dp[u][0] + (long long)(lbt - xs[i]) * dp[u][i]) % lbt;
	}
}

Measured memory_bytes: 97408
#include<stdio.h>

int main( void ) 
{
	char str[1001];
	int i;
	int sum;
	
	while( 1 ) {
		scanf( "%s", str );
		if( '0' == str[0] ) { break; }

		sum=0;
		for( i=0; '\0'!=str[i]; i++ ) {//48='0'
			sum+=str[i]-'0';
		}
		printf( "%d\n", sum );	
	}
		
	return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long dp[5005][5005];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	dp[1][0]=1;
	for (int i=1;i<=m;i++)
	dp[1][i]=(2*dp[1][i-1])%mod;
	for (int i=2;i<=n;i++)
	{
		for (int j=2;j<=m;j++)
		dp[i][j]=(2*dp[i][j-1]+dp[i-1][j-1]*(j-1))%mod;
		for (int j=1;j<=m;j++)
		dp[i][j]=(dp[i][j]+(j+1)*dp[i-1][j])%mod;
	}
	printf("%lld",dp[n][m]);
}

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

using namespace std;

int main() {
  long long H, W, N;
  cin >> H >> W >> N;

  map<pair<int, int>, int> rects;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;

    for (int y = a - 2; y <= a; y++) {
      for (int x = b - 2; x <= b; x++) {
        if (x < 0 || x + 2 >= W || y < 0 || y + 2 >= H) {
          continue;
        }

        auto key = pair<int, int>(x, y);
        auto count = rects.find(key);
        if (count != rects.end()) {
          count->second++;
        } else {
          rects.insert(make_pair(key, 1));
        }
      }
    }
  }

  int result[10] = {0};
  for (int i = 1; i < 10; i++) {
    for(auto itr = rects.begin(); itr != rects.end(); ++itr) {
      if (itr->second == i) {
        result[i]++;
      }
    }
  }

  long long sum_rect = 0;
  for (auto n : result) sum_rect += n;

  long long result0 = (W - 2) * (H - 2) - sum_rect;
  cout << result0 << endl;

  for (int i = 1; i < 10; i++) cout << result[i] << endl;

  return 0;
}


Measured memory_bytes: 56448
N, M = gets.split.map(&:to_i)
C = Array.new(N + 1) {Array.new(N + 1)}
R = Hash.new {|h, i| h[i] = []}
M.times do
  a, b, c = gets.split.map(&:to_i)
  C[a][b] = c
  R[a] << b
end
     
T = Array.new(N + 1, -Float::INFINITY)
 
def calc(node, step = 0, cost = 0, n_pass = 0)
  return true if cost <= T[node]
  return false if n_pass >= 2
  return false if node == N && step > N
  return true if step >= 2 * N
  T[node] = cost
  np = (node == N ? n_pass + 1 : n_pass)
  R[node].all? {|x| calc(x, step + 1, cost + C[node][x], np)}
end
     
puts calc(1) ? T[N] : 'inf'

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

int main(){
  int h, w;
  cin >> h >> w;
  
  for (int i = 0; i < w+2; i++) {
    cout << "#";
  }
  cout << endl;
  
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cout << "#";
    cin >> s.at(i);
    cout << s.at(i);
    cout << "#" << endl;
  }
  
  
  for (int i = 0; i < w+2; i++) {
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define I 900000
int x[99],z[99],y[99][20],h[99],a,b,c,d,e,f,i,j,k;string S;
int main(){
while(true){
for(i=0;i<99;i++){x[i]=I;}
memset(y,0,sizeof(y));
memset(h,0,sizeof(h));
cin>>a>>b>>c;
if(!a){break;}
for(i=0;i<c;i++){
cin>>d>>e>>f>>S;
if(S[0]=='W'){
y[d][e]++;
}
else{
x[d]+=I;
x[d]-=f+1200*y[d][e];
}
}
for(i=1;i<=a;i++){z[i]=x[i];}
sort(x+1,x+a+1);
for(i=a;i>=1;i--){
for(j=1;j<=a;j++){
if(z[j]==x[i]&&!h[j]){
printf("%d %d %d\n",j,(x[i]+I-1)/I-1,(99*I-x[i])%I);
h[j]=1;
}
}
}
}
}

Measured memory_bytes: 1224
#include<iostream>
#include<cstdio>
const int N=2005;
typedef long long ll;
const ll mod=1e9+7;
int a[N],n,k;
int main() {
    ll ans=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    ll c=1LL*(k-1)*k/2%mod;
    for(int i=1;i<=n;i++) {
        int l=0,r=0;
        for(int j=1;j<=n;j++) {
            if(a[j]>=a[i]) continue;
            l++;
            if(j>i) r++;
        }
        ans=(ans+1LL*k*r)%mod;
        ans=(ans+c*l)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 888
N = int(input())
a = list(map(int, input().split()))

a.sort()

arrival = 1
ans = 0

while arrival < N:
    score = a.pop()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)

Measured memory_bytes: 105316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=min(b-1,n);
    cout<<(a*x)/b<<endl;
}


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

int main(int argc, char const *argv[])
{
  int N, L;
  cin >> N >> L;
  vector<string> str(N);
  for(int i = 0; i < N; i++)
    cin >> str[i];
  string tmp;
  string ans = "";

  for(int i = 0; i < N - 1; i++)
  {
    for(int j = 0; j < N - i - 1; j++)
    {
      if(str[j+1] < str[j])
      {
        tmp = str[j];
        str[j] = str[j+1];
        str[j+1] = tmp;
      }
    }
  }

  for(int i = 0; i < N; i++)
    ans += str[i];

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


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

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数

int main()
{
	string s;

	cin >> s;
	int len = s.size();
	int p=0,e=0;
	vector<int> cnt;
	REP(i, len) {
		cnt.push_back(0);
		if (s[i] == 'L') {
			if (s[i - 1] == 'L') {
				if ((i - (e - 1)) % 2 == 0) {
					cnt[e-1]++;
				}
				else {
					cnt[e - 2]++;
				}
				p = i + 1;
				continue;
			}
			FOR(j, p, i + 1) {
				if ((i - j) % 2 == 0) {
					cnt[i]++;
				}
				else {
					cnt[i - 1]++;
				}
			}
			p = i + 1;
			e = i + 1;
		}
	}

	REP(i, len) {
		cout << cnt[i] << (i == len - 1 ? "" : " ");
	}
	cout << endl;

}

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

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

  ll N; cin >> N;
  ll P; cin >> P;
  vector<ll> F, C;
  vector<pair<ll, ll>> v;
  for (ll i = 2; i * i <= P; i++) {
    pair<ll, ll> p;
    if (P == 1) break;
    if (P % i) continue;
    p.first = i;
    p.second = 1;
    P /= i;
    while (true) {
      if (P % i) break;
      p.second++;
      P /= i;
    }
    v.emplace_back(p);
  }

  if (P > 1) {
    pair<ll, ll> p;
    p.first = P;
    p.second = 1;
    v.emplace_back(p);
  }

  ll ans = 1;
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v[i].second / N; j++) {
      ans = ans * v[i].first;
    }
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

int main()
{
    int N, wh, ans, temp;
    string S;
    cin >> N >> S;

    wh = 0;
    for (int i = 0; i < N; i++)
        if (S[i] == '.') wh++;

    ans = wh; temp = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '.') temp = wh - 1;
        else temp = wh + 1;

        if (temp < ans) ans = temp;
        wh = temp;
    }

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


Measured memory_bytes: 640
import java.util.Scanner;

// ABC095 at 2018/04/24

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

    private void solveA() {
        Scanner sc = new Scanner(System.in);
        char[] N = sc.nextLine().toCharArray();
        int result = 700;
        for (char c : N) {
            if ("o".equals(String.valueOf(c))) {
                result += 100;
            }
        }
        System.out.println(result);
    }

    private void solveB() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveD() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveE() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveF() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

}

Measured memory_bytes: 23892
x, n = map(int, input().split())
p = set(map(int, input().split()))
if n == 0:
    print(x)
else:
    for i in range(101):
        if x - i not in p:
            print(x - i)
            break
        elif x + i not in p:
            print(x + i)
            break


Measured memory_bytes: 9168
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const mint dv = mint(1) / 9;
struct S { mint a, b; };
using F = int;
S op(S l, S r) { return S{l.a * r.b + r.a, l.b * r.b}; }
S e() { return S{0, 1}; }
F id() { return -1; }
S mapping(F f, S x) { return f == id() ? x : S{(x.b - 1) * dv * f, x.b}; }
F composition(F f, F g) { return f == id() ? g : f; }
main() {
    F n, q;
    cin >> n >> q;
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(vector(n, S{1, 10}));
    while (q--) {
        F l, r, d;
        cin >> l >> r >> d;
        seg.apply(l - 1, r, d);
        cout << seg.all_prod().a.val() << '\n';
    }
}

Measured memory_bytes: 9836
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
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 RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;
 
int main() {
    string s;
    while(getline(cin, s)) {
        REP(i, 26) {
            REP(j, s.length()) {
                if('a' <= s[j] && s[j] <= 'z') {
                    s[j]++;
                    if('z' < s[j]) {
                        s[j] -= 26;
                    }
                }
            }
 
            if(s.find("the") != string::npos) {
                cout << s << endl;
                goto next;
            } else if(s.find("this") != string::npos) {
                cout << s << endl;
                goto next;
            } else if(s.find("that") != string::npos) {
                cout << s << endl;
                goto next;
            }
        }
 
        next:;
    }
 
    return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
//#define MOD 998244353

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

using namespace std;

template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }

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

	ll N, K;
	cin >> N >> K;

	string S;

	cin >> S;

	S[K - 1] += 'a' - 'A';


	cout << S << endl;




	return 0;
}


Measured memory_bytes: 256
#! python3
# grading.py

for i in range(50):
    m, f, r = [int(x) for x in input().split(' ')]
    if m == -1 and f == -1 and r == -1: break

    if m == -1 or f == -1 or m + f < 30:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50 or r >= 50:
        print('C')
    else:
        print('D')


Measured memory_bytes: 5600
def yakusu(x):
    ans=0

    for i in range(1,x+1):
        if i%2==0:
            continue

        cnt=0
        for j in range(1,i+1):
            if i%j==0:
                cnt+=1

            if cnt==8:
                ans+=1
    return(ans)

s=int(input())
print(yakusu(s))


Measured memory_bytes: 2940
#include<stdio.h>
#define N 30

int count;

void paint_map(
    int h,int w,char map[N][N],
    int x,int y){
  if(x==-1 || y==-1 || x==h || y==w)
    return ;
  if(map[x][y]=='#')
    return ;

  map[x][y]='#';
  count++;

  paint_map(h,w,map,x-1,y);
  paint_map(h,w,map,x+1,y);
  paint_map(h,w,map,x,y-1);
  paint_map(h,w,map,x,y+1);
}

int main(void){
  int i,j;
  int w,h,sx,sy;
  char map[N][N],hoge;

  for(;;){
    scanf("%d%d",&w,&h);
    if(w==0 && h==0)
      break;

    for(i=0;i<h;i++){
      scanf("%c",&hoge);
      for(j=0;j<w;j++){
        scanf("%c",&map[i][j]);
        if(map[i][j]=='@'){
          sy=i;
          sx=j;
        }
      }
    }

    count=0;
    paint_map(h,w,map,sy,sx);

    printf("%d\n",count);
  }

  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
 
typedef struct{
  char name[20];
  int num;
    }Name;
 
#define M 100000
#define TRUE 1
#define FALSE 0
 
//void initialize(int,int);
void enqueue(Name);
Name dequeue(void);
int isEmpty(int,int);
int isFULL(int,int);
 
int i,j,N,time=0,sumtime=0,time2,quantum;
int head,tail;
 
Name Q[M],de;
 
int main(){
 
  scanf("%d",&N);
  scanf("%d",&quantum);
 
  for(i=0;i<N;i++){  
    scanf("%s %d",Q[i].name,&Q[i].num);
    enqueue(Q[i]);
  }
   
  while(head!=tail){
    if(quantum>=Q[head].num){
      sumtime+=Q[head].num;
      printf("%s %d\n",Q[head].name,sumtime);
      head++;
    }
    else{
      sumtime += quantum;
      Q[head].num -= quantum;
      de = dequeue();
      enqueue(de);
    }
  } 
  return 0;
}
 
int isEmpty(int x,int y){
  if(x == y){
    return TRUE;
  }
  else {
    return FALSE;
     
  }
}
 
int isFULL(int x,int y){
  if(x == (y+1) % M){
    return TRUE;
  }
  else return FALSE;
}
 
void enqueue(Name x){
  if(isFULL(head,tail)==TRUE){
    printf("Over flow!\n");
  }
  Q[tail] = x;
  if(tail + 1 == M){
    tail = 0;
  }
  else
    tail++;
}
 
 
Name dequeue(){
  if(isEmpty(head,tail)==TRUE){
    printf("Under flow!\n");
  }
  Name x;
  x = Q[head];
  if(head + 1 == M){
    head = 0;
  }
  else {
    head++;
  }
  return x; 
}

Measured memory_bytes: 2944
def main(N,C,A,B):
    import sys
    input = sys.stdin.readline
    #N,C = map(int,input().split())
    #A = list(map(int,input().split()))
    #B = list(map(int,input().split()))
    mod = 10**9+7
    powA = [[0]*(401) for i in range(401)]
    for i in range(401):
        for j in range(401):
            powA[i][j] = pow(i,j,mod)
    
    S = [[0]*401 for i in range(C+1)]
    for i in range(C+1):
        S[i][0] = 0
    for i in range(C+1):
        for j in range(1,401):
            S[i][j] = (S[i][j-1] + powA[j][i])%mod
    
    dp = [[0]*(C+1) for i in range(N)]
    for i in range(C+1):
        dp[0][i] = S[i][B[0]] - S[i][A[0]-1]
    for i in range(1,N):
        for j in range(C+1):
            tmp = 0
            for k in range(j+1):
                tmp = (tmp + (S[k][B[i]] - S[k][A[i]-1])*dp[i-1][j-k])%mod
            dp[i][j] = tmp
    print(dp[N-1][C])
    #print(S[1])
    
def main2(N,C,A,B):
    import sys
    input = sys.stdin.readline
    #N,C = map(int,input().split())
    #A = list(map(int,input().split()))
    #B = list(map(int,input().split()))
    mod = 10**9+7
    powA = [[0]*(401) for i in range(401)]
    for i in range(401):
        for j in range(401):
            powA[i][j] = pow(i,j,mod)
    
    S = [[0]*400 for i in range(C+1)]
    for i in range(C+1):
        S[i][0] = 1
    for i in range(C+1):
        for j in range(1,400):
            S[i][j] = (S[i][j-1] + powA[j+1][i])%mod
    
    dp = [[0]*(C+1) for i in range(N)]
    for i in range(C+1):
        dp[0][i] = pow(A[0],i,mod)
    for i in range(1,N):
        for j in range(C+1):
            tmp = 0
            for k in range(j+1):
                tmp = (tmp + powA[A[i]][k]*dp[i-1][j-k])%mod
            dp[i][j] = tmp
    print(dp[N-1][C])
    
import sys
input = sys.stdin.readline
N,C = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if A==B:
    main2(N,C,A,B)
else:
    main(N,C,A,B)

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

using namespace std;

#define MAX 100

int main(){
  int n, arr[MAX][MAX];
 
  while(cin >> n,n){
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        cin >> arr[i][j];
      }
    }

    int cnt[MAX][MAX];
    memset(cnt,0,sizeof(cnt));
    for(int i = 0 ; i < n ; i++){
      int min = 1e9, max = 0;
      for(int j = 0 ; j < n ; j++){
        min = std::min(min,arr[i][j]);
        max = std::max(max,arr[j][i]);
      }
      for(int j = 0 ; j < n ; j++){
        if(arr[i][j] == min){
          ++cnt[i][j];
        }
        if(arr[j][i] == max){
          ++cnt[j][i];
        }
      }
    }

    int ans = -1;
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        if(cnt[i][j] == 2){
          ans = max(ans, arr[i][j]);
        }
      }
    }
    cout << (ans==-1?0:ans) << endl;
  }

  return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int x;
	cin >> x;
	switch (x)
	{
	case 7:
	case 5:
	case 3:
		cout << "YES\n";
		break;
	default:
		cout << "NO\n";
	}
}

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


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


x = list(map(int, input().split()))
x_sorted = sorted(x)

if n == 2:
  print(x[1])
  print(x[0])

else:
  piv = n//2

  b = x_sorted[piv]
  a = x_sorted[piv-1]
  for i in range(n):

    if x[i] < x_sorted[piv]:
      print(b)
    else:
      print(a)

  


Measured memory_bytes: 26176
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
typedef long long lint;
const int N=1e5+2;
int n,m;
lint st[N],cnt[N],add_p[N];

template <class T> inline T nxi(){
	T x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

int main(){
#ifndef ONLINE_JUDGE
//	freopen("a.in","r",stdin);
#endif
	n=nxi<int>(),m=nxi<int>();
	int pt=1;
	st[1]=n;
	for(int i=1;i<=m;++i){
		const lint x=nxi<lint>();
		while(pt&&st[pt]>=x) --pt;
		st[++pt]=x;
	}
	m=pt;
	cnt[m]=1;
	for(int i=m;i>1;--i){
		lint cur=st[i];
		for(int tp=i-1;cur>=st[1];cur%=st[tp]){
			tp=std::upper_bound(st+1,st+tp+1,cur)-st-1;
			cnt[tp]+=cur/st[tp]*cnt[i];
		}
		add_p[cur]+=cnt[i];
	}
	for(int i=st[1];i;--i){
		add_p[i-1]+=add_p[i];
	}
	for(int i=1;i<=n;++i){
		printf("%lld\n",(st[1]>=i?cnt[1]:0)+add_p[i]);
	}
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k,n;
    cin>>k>>n;
    vector<int>  vec(n),vec1(n);
    for(int i=0;i<n;++i)
    {
        cin>>vec[i];
    }


    for(int i=0;i<n;++i)
    {
        if(i==0)
            vec1[i] = (k-vec[n-1])+(vec[0]);
        else
        vec1[i]=vec[i]-vec[i-1];
    }
    
    sort(vec1.begin(),vec1.end());
    ll ans=0;
    for(int i=0;i<n-1;++i)
    {
        ans+=vec1[i];
    }

    cout<<ans<<"\n";


    
}


Measured memory_bytes: 1792
#!/usr/bin/env python3

K, N = list(map(int, input().split()))
a_list = list(map(int, input().split()))

max_d = -float("inf")
total_d = 0
for i, a in enumerate(a_list):
    if i == 0:
        d = (K - a_list[-1]) + a_list[i]
    else:
        d = a_list[i] - a_list[i - 1]
    total_d += d
    max_d = max(max_d, d)
ans = total_d - max_d

print(ans)


Measured memory_bytes: 25832
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let S = rl().chars().collect::<Vec<_>>();
    let ok = S[2] == S[3] && S[4] == S[5];
    println!("{}", if ok { "Yes" } else { "No" })
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(int a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(int a){
	write(a); puts("");
}
inline int read()//不管是正负数，都可以 
{
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
const int N=100005;
int mod=1000000007,n,m,fac[N];
int main(){
	n=read(); m=read();
	if(n==m){
		fac[0]=1;
		for(int i=1;i<=n;i++)fac[i]=(long long)fac[i-1]*i%mod;
		write((long long)fac[n]*fac[m]%mod*2%mod);
	}else if(abs(n-m)==1){
		fac[0]=1;
		for(int i=1;i<=n+1;i++)fac[i]=(long long)fac[i-1]*i%mod;
		write((long long)fac[n]*fac[m]%mod);
	}else puts("0");
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int n; cin >> n;
    cout << (n%2==0 ? n : 2*n) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]				data = null;
		ArrayList<Integer>	lf   = new ArrayList<Integer>();

		while ((data = parseData()) != null) {
			int		p   = data[0] / data[1];
			int		q   = data[0] % data[1];
			String	out = "";
			String	lp  = "";

			lf.clear();
			while (true) {
				if (q == 0) {
					// 割り切れた
					lp = "";
					break;
				} else if (lf.contains(q)) {
					break;
				}
				lf.add(q);
				p = (q * 10) / data[1];
				q = (q * 10) % data[1];
				out += String.valueOf(p);
				lp  += " ";
			}

			out = (out.isEmpty()) ? "0" : out;
			
			System.out.println(out);
			if (!lp.isEmpty()) {
				char[]	tmp = lp.toCharArray();
				Arrays.fill(tmp, lf.indexOf(q), tmp.length, '^');
				System.out.println(tmp);
			}
		}
	}

	private static int[] parseData() {
		int[]	data = null;
		String	str = null;

		if ((str = parseStdin()) != null) {
			String[]	lines = str.split(" ");
			data    = new int[2]; 
			data[0] = Integer.parseInt(lines[0]);
			data[1] = Integer.parseInt(lines[1]);
		}

		return data;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 22888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.next());
		System.out.println(calc(num));
		sc.close();
	}
	static long calc (int num) {
		if (num == 1) {
			return num;
		} else {
			return num * calc(num - 1);
		}
	}

}



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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 200005

int main(){
sp;
int n;
cin>>n;
ll a[n+1],b[n+1],c[n+1];
for(int i=1; i<=n; ++i)cin>>a[i]>>b[i]>>c[i];
ll dp[4][n+1];
memset(dp,0,sizeof dp);
dp[1][1]=a[1];
dp[2][1]=b[1];
dp[3][1]=c[1];
for(int i=2; i<=n; ++i){
    dp[1][i]=max(dp[2][i-1]+a[i],dp[3][i-1]+a[i]);
    dp[2][i]=max(dp[1][i-1]+b[i],dp[3][i-1]+b[i]);
    dp[3][i]=max(dp[2][i-1]+c[i],dp[1][i-1]+c[i]);
}
cout<<max(dp[1][n],max(dp[2][n],dp[3][n]));
return 0;}


Measured memory_bytes: 5760
#include<cstdio>
#include<algorithm>
#define maxn 105
using namespace std;
int n,cnt[maxn],d;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		cnt[a]++; d=max(d,a);
	}
	if(d%2)
		for(int i=d;i>=(d+1)/2;i--)
		{
			if(cnt[i]<2) { printf("Impossible\n"); return 0; }
			cnt[i]-=2;
		}
	else
	{
		for(int i=d;i>d/2;i--)
		{
			if(cnt[i]<2) { printf("Impossible\n"); return 0; }
			cnt[i]-=2;
		}
		if(!cnt[d/2]) { printf("Impossible\n"); return 0; }
		cnt[d/2]--;
	}
	for(int i=1;i<=(d+1)/2;i++)
		if(cnt[i]) { printf("Impossible\n"); return 0; }
	printf("Possible\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
vector<int> S(3);
  for (int i = 0; i < 3; i++) {
    cin>> S[i];
  }
  sort(S.begin(), S.end());
  cout << 10*S[2]+S[1]+S[0];
}
  



Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n, debt = 100000;
		
		n = sc.nextInt();
		for(int i = 0; i < n; i++){
			 debt *= 1.05;
			 if(debt % 1000 != 0){
				 debt += 1000 - debt % 1000;
			 }
		}
		
		System.out.println(debt);
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;


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

    int a,b;
    vector<P> pr;
    for(int i=0;i<N;++i){
       cin >> a >> b;
       pr.push_back(P(b,a));
    }
    vector<P> pb;
    for(int i =0;i<N;++i){
        cin >>a >> b;
        pb.push_back(P(a,b));
    }
    sort(pr.begin(),pr.end());//yでソート
    sort(pb.begin(),pb.end());//xでソート
    int ans =0;

    for(int i=0;i<N;i++){
        for(int j=N-1;j >= 0;--j){
            if(pb.at(i).second > pr.at(j).first && pb.at(i).first > pr.at(j).second){
                ans++;
                pr.at(j)=P(2*N,2*N);
                break;
            }
        }

    }
    cout << ans <<endl;


}

Measured memory_bytes: 256
N = int(input())
Xmi, Xma, Ymi, Yma, DYmi, DYma, UYmi, UYma, RXmi, RXma, LXmi, LXma = [(10**10), -(10**10)] * 6
for _ in range(N):
    x, y, d = input().split()
    x, y = int(x), int(y)
    
    if d == "R":
        RXmi = min(RXmi, x)
        RXma = max(RXma, x)
    elif d == "L":
        LXmi = min(LXmi, x)
        LXma = max(LXma, x)
    else:
        Xmi = min(Xmi, x)
        Xma = max(Xma, x)
        
    if d == "U":
        UYmi = min(UYmi, y)
        UYma = max(UYma, y)
    elif d == "D":
        DYmi = min(DYmi, y)
        DYma = max(DYma, y)
    else:
        Ymi = min(Ymi, y)
        Yma = max(Yma, y)

def calc(t):
    xmi = min(RXmi+t, LXmi-t, Xmi)
    xma = max(RXma+t, LXma-t, Xma)
    ymi = min(UYmi+t, DYmi-t, Ymi)
    yma = max(UYma+t, DYma-t, Yma)
    return max(yma-ymi, 0)*max(xma-xmi, 0)
    
def di(t):
    a = 1
    return calc(t+a) - calc(t-a)
def dii(t):
    a = 0.0000001
    return calc(t+a) - calc(t-a)

l = 0
r = 10**10
for _ in range(100):
    m = (l+r)//2
    if di(m) > 0:
        r = m
    else:
        l = m
for _ in range(100):
    m = (l+r)/2
    if dii(m) > 0:
        r = m
    else:
        l = m
print(calc(m))


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

int a[10000000]{}, n;

bool binarySearch(int a[], int n, int key) {
    int left = 0, right = n, mid;
    while(left < right) {
        mid = (left + right) / 2;
        if(a[mid] == key)
            return true;
        else if(a[mid] < key)
            left = mid + 1;
        else
            right = mid;
    }
    return false;
}

int main() {
    cin >> n;
    
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    int q, key, sum{};
           
    cin >> q;
    
    for(int i = 0; i < q; i++) {
        cin >> key;
        if(binarySearch(a, n, key))
            sum++;
    }
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3400