akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc052.contest.atcoder.jp/tasks/arc067_a?lang=en>
問題文============================================================
整数 N が与えられます。 N! の正の約数の個数を 10^9+7 で割った余りを求めてください。
=================================================================

解説=============================================================
 
================================================================
*/
const ll MAX_PRIME = 1000;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}
const ll MOD = 1e9+7;
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    
    init_primes();
    
    vector<ll> primes_cnt(primes.size(),0);
    for(int i = 2; i <=N;i++){
        ll T = i;
        for(int j = 0; j < (int)primes.size();j++){
            while(T%primes[j] == 0){
                primes_cnt[j]++;
                T/=primes[j];
            }
        }
    }
    ll ans = 1;
    for(int i = 0; i <= (int)primes.size();i++){
  //      cout << primes[i] << " " << primes_cnt[i] << endl;
        ans *= primes_cnt[i]+1;
        ans %=MOD;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

const int H_MAX = 50;
const int W_MAX = 50;
const int D[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

int H, W;
char s[H_MAX][W_MAX + 1];

void solve() {
  bool ng = false;
  REP(i, H) REP(j, W) {
    if (s[i][j] == '.') continue;
    bool ok = false;
    REP(k, 4) {
      int i2 = i + D[k][0];
      int j2 = j + D[k][1];
      if (i2 < 0 || i2 >= H || j2 < 0 || j2 >= W) continue;
      if (s[i2][j2] == '#') {
        ok = true;
        break;
      }
    }
    if (!ok) {
      ng = true;
      break;
    }
  }
  printf("%s\n", ng ? "No" : "Yes");
}

void input() {
  scanf("%d%d", &H, &W);
  REP(i, H) scanf("%s", s[i]);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a + b >= 24) {
		cout << a + b - 24 << endl;
	}
	else {
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long a, b, c;
int main() {
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)cout << "0" << endl;
	else {
		cout << min(a*b, min(b*c, a*c)) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

x = inn()
for i in range(1,361):
    #if ((180-x)*i)%360==0:
    if ((x)*i)%360==0:
        print(i)
        exit()


Measured memory_bytes: 61824
import java.util.*;

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

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        while (C > 0 && A > 0) {
            C -= B;
            if (C <= 0) {break;}
            A -= D;
        }

        String ans;
        if (C <= 0) {ans = "Yes";}
        else {ans = "No";}

        System.out.println(ans);

        scanner.close();
    }
}

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

██╗    ██╗██████╗ ██╗████████╗████████╗███████╗███╗   ██╗    ██████╗ ██╗   ██╗
██║    ██║██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗  ██║    ██╔══██╗╚██╗ ██╔╝
██║ █╗ ██║██████╔╝██║   ██║      ██║   █████╗  ██╔██╗ ██║    ██████╔╝ ╚████╔╝
██║███╗██║██╔══██╗██║   ██║      ██║   ██╔══╝  ██║╚██╗██║    ██╔══██╗  ╚██╔╝
╚███╔███╔╝██║  ██║██║   ██║      ██║   ███████╗██║ ╚████║    ██████╔╝   ██║
 ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝   ╚═╝      ╚═╝   ╚══════╝╚═╝  ╚═══╝    ╚═════╝    ╚═╝

     ███╗   ███╗   ██╗██████╗ ██████╗  █████╗ ██╗  ██╗██╗███╗   ███╗
     ████╗ ████║   ██║██╔══██╗██╔══██╗██╔══██╗██║  ██║██║████╗ ████║
     ██╔████╔██║   ██║██████╔╝██████╔╝███████║███████║██║██╔████╔██║
     ██║╚██╔╝██║   ██║██╔══██╗██╔══██╗██╔══██║██╔══██║██║██║╚██╔╝██║
     ██║ ╚═╝ ██║██╗██║██████╔╝██║  ██║██║  ██║██║  ██║██║██║ ╚═╝ ██║
     ╚═╝     ╚═╝╚═╝╚═╝╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝     ╚═╝
*/
#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
const int N=1e6+1;
ll dp[N],n,k,arr[N];

ll solve(int i)
{
    if(dp[i]!=-1)return dp[i];
    if(i == n-1) return 0;

    ll ret = 1e18;

    for(int j=1;i+j<n&&j<=k;j++)
        ret = min(ret,solve(i+j)+ abs(arr[i]-arr[i+j]));

    return dp[i]=ret;

}

int main(){ speed;
memset(dp,-1,sizeof dp);
cin>> n >> k;
FOR(n)cin>>arr[i];

cout<<solve(0);
return 0;}


Measured memory_bytes: 15232
#include<iostream>
#include <bits/stdc++.h>
#include<vector>

using namespace std;

int main(){
  int k,n;
  int d[10]={};

  cin>>n>>k;
  int temp;
  for(int i=0;i<k;i++){
    cin>>temp;
    d[temp]=1;
  }

int ans,num=n;
  ans=num;
  while(1){
    num=ans;
      while(num>0){
        if(d[num%10])break;
        num/=10;
      }
      if(num==0)break;
      ans++;
  }

  cout<<ans<<endl;


}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  string s;
  cin >> s;
  if (s.back() == 's') {
    cout << s << "es" << endl;
  } else {
    cout << s << "s" << endl;
  }
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		int count = 0;
		for(int a = 1; a < 10; a++) {
			for(int b  = 0; b < 10; b++) {
				for(int c = 0; c < 10; c++) {
					int temp = (10001*a)+(1010*b)+(100*c);
					if(temp >= l &&temp <= r) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21972
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		int count = 0;
		long sum = 0;

		Map<Long, Long> map = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			if (map.containsKey((a[i]))) {
				map.put((a[i]), map.get((a[i])) + b[i]);
			} else {
				map.put((a[i]), b[i]);
			}
		}

		for (Map.Entry<Long, Long> me : map.entrySet()) {
			if (me.getValue() < m - count) {
				sum += me.getKey() * me.getValue();
				count += me.getValue();
			} else {
				sum += me.getKey() * (m - count);
				System.out.println(sum);
				break;
			}






		}

	}
}


Measured memory_bytes: 100416
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
    int n, ans;
    ans = 0;
    cin >> n;
    vector<int> v;
    long long num;
    int l = (to_string(n)).length();
    for(int i=3; i<=l; ++i){
        // a + b + c = l
        for(int a=1; a<=i-2; ++a){
            for(int b=1; b<=i-2; ++b){
                for(int c=i-a-b; c<=i-2; ++c){
                    if(a <= 0 || b <= 0 || c <= 0 || (a+b+c != i)){
                        continue;
                    }
                    for(int j=0; j<a; ++j){
                        v.push_back(3);
                    }
                    for(int j=0; j<b; ++j){
                        v.push_back(5);
                    }
                    for(int j=0; j<c; ++j){
                        v.push_back(7);
                    }
                    num = 0;
                    /*
                    for(auto itr=v.begin(); itr != v.end(); ++itr){
                        cout << *itr << " ";
                    }
                    cout << endl;
                    */
                    do {
                        num = 0;
                        for(int j=0; j<i; ++j){
                            num += v[j] * (long long)(pow(10, j));
                        }
                        if(num <= n){
                            ans++;
                            //cout << num << endl;
                        }
                    } while(next_permutation(v.begin(), v.end()));
                    v.clear();
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A , B , C;
  cin >> A >> B >> C;
  
  if(A == B && B == C){
    cout << "No" << endl;
  }
  
  else if(!(A == B) && !(B == C) && !(A == C)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

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

int INF = 1e9;
int n, c;

vector<vector<int> > color;
void dfs(int idx, vector<int> tmp, int now){
    if(idx == 2) color.push_back(tmp);
    else {
        for(int i = now+1;i<=c-1;i++){
            tmp.push_back(i);
            dfs(idx+1, tmp, i);
            tmp.pop_back();
        }
    }
}
 
int main(void){
    cin>>n>>c;
    vector<vector<int> > d(c, vector<int>(c));
    rep(i, c)rep(j, c) cin>>d[i][j];
    vector<vector<int> > v(n, vector<int>(n));
    rep(i, n)rep(j, n) {
        int a;
        cin>>a;
        --a;
        v[i][j] =a;
    }
    vector<unordered_map<int, int> > vmap(3);
    rep(i, n)rep(j, n){
        vmap[(i+j)%3][v[i][j]]++;
    }
    vector<int>tmp;
    dfs(-1, tmp, -1);
    int ans = INF;
    rep(i, color.size()){
        do{
            int tmp = 0;
            rep(j, 3) {
                for(auto p : vmap[j]){
                    tmp += p.second*d[p.first][color[i][j]];
                }
            }
            ans = min(ans, tmp);
        }while(next_permutation(color[i].begin(), color[i].end()));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
int main(void) {
  int n, sum, a, i;
  scanf("%d",&n);

  while(n != 0) {
    sum = 0;
    for( i=0; i < (n/4); i++) {
      scanf("%d",&a);
      sum += a;
    }
    printf("%d\n",sum);
    scanf("%d",&n);
  }
  return(0);
}    

Measured memory_bytes: 600
#include<stdio.h>

int main(void)
{

	int i, j;
	
	scanf("%d%d", &i, &j);

	if (i - 2 >= j) {
		printf("%d", i + i - 1);

	}
	else if (i + 2 > j) {
		printf("%d", i + j);

	}
	else{

		printf("%d", j + j - 1);

	}
	return 0;


}

Measured memory_bytes: 128
from collections import deque
S = input()

def calculate(s):
    q = deque()
    for i in range(len(s)):

        if s[i] == "0":
            q.append("0")
            continue

        if s[i] == "1":
            q.append("1")
            continue

        if s[i] == "B":
            if len(q) > 0:
                q.pop()


    if len(q) == 0:
        print("(empty)")
    else:
        print("".join(list(q)))


calculate(S)


Measured memory_bytes: 9348
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cassert>
#include<utility>
#include<algorithm>
#include<complex>
using namespace std;
int n,m,now,ans;
vector<int> a(100002);
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.begin()+n);
  for(int i=0;i<n;i++){
    if(now!=a[i]){
      if(now>m)ans+=m;
      if(now<m)ans+=(m-now);
      now=a[i];m=1;
    }else{
      m++;
    }
  }
  if(now>m)ans+=m;
  if(now<m)ans+=(m-now);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
S = list(str(input()))

count = 0
count_bef = 0
count_list=[]
count_list2=[]
minus = []
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    count += 1
  elif not S[i] ==S[i+1]:
    count_list.append(int((count+1)*(count+2)/2))
    count_list2.append(count+1)
    count = 0
count_list.append(int((count+1)*(count+2)/2))
count_list2.append(count+1)
if S[0] == "<":
  for i in range(len(count_list2)//2):
    minus.append(min(count_list2[2*i], count_list2[2*i+1]))
elif S[0] == ">":
  try:
    for i in range(len(count_list2)//2):
      minus.append(min(count_list2[2*i+1], count_list2[2*i+2]))
  except IndexError:
    pass
#print(count_list)
#print(count_list2)
#print(minus)
print(sum(count_list)-sum(minus))

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long X){
    REP2(i, -300, 300) {
        REP2(j, -300, 300) {
            LL ii = (LL)i * (LL)i * (LL)i * (LL)i * (LL)i;
            LL jj = (LL)j * (LL)j * (LL)j * (LL)j * (LL)j;

            if(ii - jj == X) {
                cout << i << " " << j << endl;
                return;
            }
        }
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, m;
vector<pi> s;
int dp[1024];
using namespace std;

int main() {
    int m, n;
    bool a[1000010];
    int b[1000010];

    for(int i = 0; i < 1000010; i++)
        a[i] = false;

    for(int i = 1; i < 1000010; i *= 5) {
        for(int j = 1; i * j< 1000010; j *= 3) {
            for(int k = 1; i * j * k < 1000010; k *= 2) {
                a[i * j * k] = true;
            }
        }
    }

    b[0] = 0;
    for(int i = 1; i < 1000010; i++) {
        b[i] = b[i - 1] + (a[i] ? 1 : 0);
    }

    while(cin >> m, m) { cin >> n;
        cout << b[n] - b[m - 1] << endl;
    }

    return 0;
}

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

void main_()
{
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> scs;

    for (ll i = 0; i < M; ++i) {
        int s, c;
        cin >> s >> c;
        scs.emplace_back(s, c);
    }

    vector<int> keta_vals(N, -1);

    for (auto&& sc : scs) {
        int keta = sc.first - 1;
        int val = sc.second;

        if (keta_vals[keta] == -1 || keta_vals[keta] == val) {
            keta_vals[keta] = val;
        } else {
            // 同じ桁に複数の値
            cout << -1 << endl;
            return;
        }
    }

    for (ll i = 0; i < N; ++i) {
        if (i == 0) {
            if (keta_vals[i] == -1) {
                keta_vals[i] = (N > 1) ? 1 : 0;
            } else if (keta_vals[i] == 0 && N > 1) {
                cout << -1 << endl;
                return;
            }
        } else {
            if (keta_vals[i] == -1) {
                keta_vals[i] = 0;
            }
        }
    }

    for (auto&& v : keta_vals) {
        cout << v;
    }
    cout << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(void){
    
    int Min = 10000,n,total = 0,a;
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> a;
        total += a;
        if(a%10){
            Min = min(Min,a);
        }
    }
    
    if(Min == 10000){
        cout << 0 << endl;
    }else{
        if(total % 10)
        cout << total << endl;
        else
        cout << total - Min << endl;
    }
    
}

Measured memory_bytes: 256
N = int(input())
A1, A2 = [[int(a) for a in input().split()] for _ in range(2)]
tmp = A1[0] + sum(A2)
ans = tmp
for i in range(1, N):
    tmp += A1[i]-A2[i-1]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

unsigned long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0, startp = 0, endp = 0, checker = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
int iremono[100001];
std::vector<unsigned long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{

	cin >> a>>b>>c;
	for (int i = 1; i <= std::min(a, b);i++) {
		if (a%i == 0 && b%i == 0) {
			kaku.push_back(i);
		}
    }
	cout << kaku[kaku.size() - c] << endl;
}


Measured memory_bytes: 256
N, C = map(int, input().split())
x = []
v = []
for _ in range(N):
    xi, vi = map(int, input().split())
    x.append(xi)
    v.append(vi)
vsp = [0] * (N + 1)
vsn = [0] * (N + 1)
dprp = [0] * (N + 1)
dprn = [0] * (N + 1)
dpsp = [0] * (N + 1)
dpsn = [0] * (N + 1)
for i in range(N):
    vsp[i + 1] = vsp[i] + v[i]
    vsn[i + 1] = vsn[i] + v[N - 1 - i]
    dprp[i + 1] = max(dprp[i], vsp[i + 1] - 2 * x[i])
    dpsp[i + 1] = max(dpsp[i], vsp[i + 1] - x[i])
    dprn[i + 1] = max(dprn[i], vsn[i + 1] - 2 * (C - x[N - 1 - i]))
    dpsn[i + 1] = max(dpsn[i], vsn[i + 1] - (C - x[N - 1 - i]))
ans = max(dpsp[N], dpsn[N])
for i in range(N + 1):
    ans = max(ans, dprp[i] + dpsn[N - i], dprn[i] + dpsp[N - i])
print(ans)


Measured memory_bytes: 33124
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <iostream>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
    int n,k;
    cin >> n >> k;
    bool higaisya[n + 1];
    for (int i = 1; i<= n; i++){
        higaisya[i] = true;
    }
    for (int i = 1; i <= k; i++){
        int d;
        cin >> d;
        for (int j = 1; j <= d; j++){
            int x;
            cin >> x;
            higaisya[x] = false;
        }
    }
    int ret = 0;
    for (int i = 1; i<=n; i++){
        if(higaisya[i]){
            ret++;
        }
    }
    cout << ret;
    return 0;
}

Measured memory_bytes: 3636
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
// constexpr auto mod = 1000000007;
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> D(K);
  for (auto &&Di : D) {
    cin >> Di;
  }
  vector<int> S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  set<int> T;
  set_difference(ALL(S), ALL(D), inserter(T, T.end()));
  const int UN = 10 * N;
  FOR(i, N, UN) {
    set<int> U;
    auto t = i;
    while (t) {
      U.emplace(t % 10);
      t = t / 10;
    }
    if (all_of(ALL(U), [&T](const int u) { return T.count(u) > 0; })) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
A,B,C=map(int,input().split())
ans=10**19
whole=A*B*C
for a in range(A//2,A//2+2):
  ans=min(ans,abs(whole-a*B*C*2))
for b in range(B//2,B//2+2):
  ans=min(ans,abs(whole-A*b*C*2))
for c in range(C//2,C//2+2):
  ans=min(ans,abs(whole-A*B*c*2))
print(ans)

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

int main() {
  long int A,B,V,W,T;
  cin >> A >> V >> B >> W >> T;
  string ans="YES";
  if (V <= W){
    ans = "NO";
  }
  else if (abs(A-B)>T*(V-W)){
    ans = "NO";
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3636
n = int(input())
monster = list(map(int,input().split()))
brave = list(map(int,input().split()))
ans = 0
for i in range(n):
  kill = min(monster[i],brave[i])
  ans += kill
  brave[i] -= kill
  kill = min(monster[i+1],brave[i])
  ans += kill
  monster[i+1] -= kill
print(ans)
    

Measured memory_bytes: 19116
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define fe(vec,lambda) std::for_each(vec.begin(), vec.end(), lambda );
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){vector<pair<T,T>> out(input.size()-1);rep(i,input.size()-1){out[i].first =input[i  ];out[i].second=input[i+1];}return(out);}
vector<char> String_to_vector_char(const string& input){vector<char> out(input.size());rep(i,input.size()){out[i]=input[i];}return out;}
void YesNo(bool flag){ cout<<(flag? "A":"B");}

ll a,b,c,d,n,x;
vector<ll>v[3];
map<ll,ll>m;
string s,s2;
void input(){
    cin>>x>>a;
}
void src(){
    cout<< max(0ll,x-a);
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;


int main(){

    int n;
    cin >> n;

    vector<ll> a;

    rep(i,n){
        ll tmp;
        cin >> tmp;
        a.pback(tmp);
    }

    sort(ALL(a));

    ll tmp = a[n - 1];
    ll half = tmp / 2;

    auto itr = upper_bound(a.begin(), a.end(), half);
    int index1 = distance(a.begin(), itr);

    ll ans1 = tmp;
    ll ans2 = a[index1];

    cerr << ans1 << " " << ans2 << endl;

    int index2;

    if(index1 != 0){
        index2 = index1 - 1;

        if(a[index2] > tmp - a[index1] || tmp == a[index1]){
            ans2 = a[index2];
        }
    }

    cout << ans1 << " " << ans2 << endl;


    /*

    for(int i = n - 2; i >= 0; i--){
        ll tmp = a[i];
        ll half = a[i] / 2;

        auto itr = lower_bound(a.begin(), a.end(), half);
    }
    */
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
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(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  for(int i=0; i<=999; i++){
    string pass = toString(i);
    if(pass.size() == 1){
      pass = "00" + pass;
    }else if(pass.size() == 2){
      pass = "0" + pass;
    }
    vector<bool> can(3,false);
    int k = 0;
    for(int j=0; j<N; j++){
      if(pass[k] == S[j]){
        can[k] = true;
        k++;
        if(k == 3) break;
      }
    }
    if(can[2]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let inc_seq len m =
  let rec aux rest n =
    if rest = 0 then [[]]
    else if n = succ m then []
    else
      (ListL.map ~f:(fun l -> n::l) @@ aux (pred rest) n)
      @ aux rest (succ n)
  in
  aux len 1

let (n,m,q) = scan "%d %d %d"  Tuple3.make
let qs = scan_lines q "%d %d %d %d" Tuple4.make

let () =
  inc_seq n m
  |> ListL.map ~f:Array.of_list
  (* |> (fun l -> List.print ~sep:"\n" (Array.print Int.print) stderr l; l) *)
  |> ListL.map ~f:(fun l ->
      ListL.map ~f:(fun (a,b,c,d) ->
          if l.(pred b) - l.(pred a) = c then d else 0)
        qs |> List.sum)
  |> List.max
  |> Printf.printf "%d\n"


Measured memory_bytes: 49288
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
b_arr = list(map(lambda b: int(b), input().split()))
a_arr = list(range(N))

for n in range(N-1, -1, -1):
    if (n == N-1) or (n == N-2):
        a_arr[N-1] = b_arr[N-2]
        a_arr[N-2] = b_arr[N-2]
    elif b_arr[n+1] >= b_arr[n]:
        a_arr[n+1] = b_arr[n]
        a_arr[n] = b_arr[n]
    else:
        a_arr[n] = b_arr[n]

print(sum(a_arr))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        sc.nextLine();
        
        List<String> list = Arrays.asList(sc.nextLine().split(" "));
        Set<String> set = new HashSet<>(list);
        if(list.size() == set.size()){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 68752
package main

import (
	"fmt"
)

func trace(arr []int) {
	for i, e := range arr {
		if i == len(arr)-1 {
			fmt.Printf("%d\n", e)
		} else {
			fmt.Printf("%d ", e)
		}
	}
}

func insertionSort(arr []int) {
	for i, e := range arr {
		j := i - 1
		for ; j >= 0 && arr[j] > e; j-- {
			arr[j+1] = arr[j]
		}
		arr[j+1] = e
		trace(arr)
	}
}

func main() {
	var n int
	fmt.Scan(&n)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}

	insertionSort(arr)
}



Measured memory_bytes: 1172
#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, m;
bool x[21][21];

int main(){
	while(scanf("%d", &n), n){
		rep(i, 21){
			fill_n(x[i], 21, false);
		}
		rep(i, n){
			int a, b;
			scanf("%d%d", &a, &b);
			x[a][b] = true;
		}
		scanf("%d", &m);
		int p = 10, q = 10;
		int ans = 0;
		if(x[p][q]){
			++ans;
			x[p][q] = false;
		}
		rep(i, m){
			char c;
			int d;
			scanf(" %c %d", &c, &d);
			int dx = 0, dy = 0;
			switch(c){
			case 'N':
				dy = 1;
				break;

			case 'E':
				dx = 1;
				break;

			case 'S':
				dy = -1;
				break;

			case 'W':
				dx = -1;
				break;
			}

			rep(j, d){
				p += dx;
				q += dy;
				if(x[p][q]){
					++ans;
					x[p][q] = false;
				}
			}
		}
		printf("%s\n", n == ans ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }
  else if(A+B<C+D){
  cout<<"Right"<<endl;
  }
  else{
    cout<<"Balanced"<<endl;
  }

}

Measured memory_bytes: 256
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def sieve_of_eratosthenes(n):
	if n == 1:
		return []
	if n == 2:
		return [2]
	candidate = [i for i in range(2, n+1)]
	prime = []
	limit = math.sqrt(n) + 1

	while True:
		p = min(candidate)
		if limit <= p:
			prime.extend(candidate)
			break
		prime.append(p)
		candidate = [i for i in candidate if i % p != 0]
	return prime

#sosu = sieve_of_eratosthenes(1)
#sosu.append(1)
ans = 0
l = [[[0 for _ in range(201)]for _ in range(201)]for _ in range(201)]
for i in range(1,K+1):
	for j in range(1,K+1):
		for k in range(1,K+1):
			a = sorted([i,j,k])
			if l[a[0]][a[1]][a[2]] == 0:
				tmp = gcd(i,j,k)
				ans += tmp
				l[a[0]][a[1]][a[2]] = tmp
			else:
				ans += l[a[0]][a[1]][a[2]]
print(ans)

Measured memory_bytes: 137336
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;

int main(){
 int n; cin>>n;
 int rate[9];
  REP(i,9)rate[i]=0;
 int sum=0,add=0; 
 REP(i,n){
   int a; cin>>a;
   if(a>=3200){
     rate[0]++; add++;
   }else if(a>=2800)rate[1]++;
   else if(a>=2400)rate[2]++;
   else if(a>=2000)rate[3]++;
   else if(a>=1600)rate[4]++;
   else if(a>=1200)rate[5]++;
   else if(a>=800)rate[6]++;
   else if(a>=400)rate[7]++;
   else rate[8]++;
 }
 
 REP(i,9)
   if(i!=0&&rate[i]>0)sum++;
  if(sum==0&&add>0){
    sum++; add--;
  }
  cout<<sum<<" "<<sum+add<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int A,B,C;
	scanf("%d %d %d", &A, &B, &C);
	if(A==B){
		printf("%d\n",C);
	}
	else if (B == C)
	{
		printf("%d\n", A);
	}
	else if(C == A)
	{
		printf("%d\n", B);
	}
	else

		return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
int c[110000];
set<int>S;
int n;
int gcd(int a,int b){
	while(b){
		a%=b;swap(a,b);
	}
	return a;
}
int L[32][110000];
int R[32][110000];
int solve(int a,int b){
	int cur=0;
	long long cnt=0;
	for(int i=0;i<n;i++){
		cnt+=c[i]/a-1;
		cur=gcd(cur,c[i]/a);
		L[b][i+1]=cur;
	}
	cur=0;
	for(int i=n-1;i>=0;i--){
		cur=gcd(cur,c[i]/a);
		R[b][i]=cur;
	}
	for(int i=0;i<n;i++){
		if(c[i]/a==1)continue;
		int t=gcd(gcd(L[b][i],R[b][i+1]),c[i]/a-1);
		if(t==1&&cnt%2)return 1;
		if(t!=1&&solve(a*t,b+1)==0)return 1;
	}
	return 0;
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",c+i);
		n=a;
	int ret=solve(1,0);
	if(ret)printf("First\n");
	else printf("Second\n");
}


Measured memory_bytes: 19584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    string S,T; cin >> S >> T;
    bool found = false;
    int endpoint;
    for(int i = S.length() - 1; i >= T.length() - 1; i--)
    {
        bool ok = 1;
        int end = i;
        REP(j,T.length())
        {
            if(S[end-j] == T[T.length()-1-j] || S[end-j] == '?') continue;
            else
            {
                ok = 0;
                break;
            }
        }
        if(ok)
        {
            found = true;
            endpoint = i;
            break;
        }
    }
    if(found)
    {
        REP(i,T.length())
        {
            S[endpoint-i] = T[T.length()-1-i];
        }
        REP(i,S.length())
        {
            if(S[i] == '?') cout << 'a';
            else cout << S[i];
        }
        cout << endl;
    }
    else
    {
        cout << "UNRESTORABLE" << endl;
    }

}


Measured memory_bytes: 256
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

from pprint import pprint
import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random

def main():
    n = int(input().strip())
    l_xy=[]
    for i in range(n):
        x,y = map(int, input().strip().split())
        l_xy.append([x,y])
    #epint("l_xy ",end=":\n")
    #epint(l_xy,width=20)

    sum_distance= 0 #for _ in range(math.factorial(n))]
    i_cnt=0
    for l_route in itertools.permutations(l_xy):
        #epint("l_route ",end=": ")
        #epint(l_route)
        distance=0
        for i in range(1,len(l_route)):
            distance+=math.sqrt((l_route[i][1] - l_route[i-1][1])**2 + (l_route[i][0] - l_route[i-1][0])**2)
        sum_distance+=distance
        i_cnt+=1
        # hoge
    ans=sum_distance/math.factorial(n)
    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N], B[MAX_N];
bool D[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];
	ll res = 1;
	if(B[0] < A[0] || B[N - 1] > A[N - 1]) res = 0;
	rep(i, 1, N - 1) {
		if(A[i] != A[i - 1]) {
			D[i] = true;
			if(A[i] > B[i]) res = 0;
		}
	}
	rer(i, N - 1, 1) {
		if(B[i] != B[i + 1]) {
			if(D[i]) {
				if(A[i] != B[i]) res = 0;
			}
			else {
				if(A[i] < B[i]) res = 0;
			}
			D[i] = true;
		}
	}
	rep(i, 1, N - 1) {
		MUL(res, D[i] ? 1 : min(A[i], B[i]));
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1920
var K = readLine()!
let D = Int(readLine()!)!

var dp = Array(repeating: [true: 0, false: 0], count: D)
dp[0][false] = 1

for _ in stride(from: 0, to: K.count, by: 1) {
    let number = Int(String(K.removeFirst()))!
    var newDP = Array(repeating: [true: 0, false: 0], count: D)

    for i in stride(from: 0, to: D, by: 1) {
        [false, true].forEach { isLessThanK in
            let limit = isLessThanK ? 9 : number
            for j in stride(from: 0, through: limit, by: 1) {
                let newI = (i + j) % D
                let newIsLessThanK = isLessThanK || j < number
                newDP[newI][newIsLessThanK] = (newDP[newI][newIsLessThanK]! + dp[i][isLessThanK]!) % 1_000_000_007
            }
        }
    }

    dp = newDP
}

print((dp[0][true]! + dp[0][false]! + 1_000_000_007 - 1) % 1_000_000_007)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define Max(x, y)(max(decltype(x)(0), max((x), (y))))
#define Min(x, y)(max(decltype(x)(0), min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool _max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool _min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    string s;

    cin >> n;

    V<string> v[5];
    ll ans = 0;

    int i, j, k;

    rep(i, n) {
        cin >> s;

        if (s[0] == 'M') v[0].pb(s);
        else if (s[0] == 'A') v[1].pb(s);
        else if (s[0] == 'R') v[2].pb(s);
        else if (s[0] == 'C') v[3].pb(s);
        else if (s[0] == 'H') v[4].pb(s);
    }

    rep(i, 5) {
        repi(j, 5, i + 1) {
            repi(k, 5, j + 1) {
                ans += v[i].size() * v[j].size() * v[k].size();
            }
        }
    }

    Out(ans);

    return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
	ll x, k, d;
	cin >> x >> k >> d;
	ll X;
	X = abs(x);
	ll req = X / d;
	if (k <= req) {
		cout << X - k * d << endl;
	}
	else {
		ll first = X % d;
		ll second = abs(X % d - d);
		if ((X / d) % 2 == k % 2)
			cout << first << endl;
		else
			cout << second << endl;
	}
}

Measured memory_bytes: 3608
import java.util.Scanner;

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

		Scanner stdIn = new Scanner (System.in);

		int a = stdIn.nextInt();
		int b = stdIn.nextInt();

		if(a>b) System.out.println("a > b");
		else if(a<b) System.out.println("a < b");
		else System.out.println("a == b");

	}

}

Measured memory_bytes: 26384
from itertools import*
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:
 b[3:5]=b[4],b[3]
def g():
 for d,e in combinations(a,2):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[i]for i in p]
   if f[0::5]==e[0::5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(g())


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll x;
ll num[55][2];
ll ret(int n,ll x){
	assert(num[n][0]+num[n][1] >= x);
	if(num[n][0]+num[n][1] == x) return num[n][1];
	ll rett = 0;
	ll zan = x-1;
	zan = min(zan,num[n-1][0]+num[n-1][1]);
	if(zan > 0) rett += ret(n-1,zan);
	zan = x-1-num[n-1][0]-num[n-1][1];
	if(zan > 0) rett++;
	zan--;
	zan = min(zan,num[n-1][0]+num[n-1][1]);
	if(zan > 0) rett += ret(n-1,zan);
	return rett;
}
int main(){
	num[0][0] = 0; num[0][1] = 1;
	for(int i=1;i<55;i++){
		num[i][0] = 2LL+2LL*num[i-1][0];
		num[i][1] = 1LL+2LL*num[i-1][1];
	}
	cin>>n>>x;
	cout<<ret(n,x)<<endl;
}

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;


const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::string s1, s2;
	std::cin >> s1 >> s2;
	
	if (s1.size() != s2.size())
	{
		pnl("NO"); return 0;
	}

	for (int i(0); i < s1.size(); ++i)
	{
		if (s1[i] != s2[s1.size() - 1 - i])
		{
			pnl("NO");
			return 0;
		}
	}
	pnl("YES");
}



Measured memory_bytes: 256