akhauriyash/Code-Regression huggingface dataset:
n, *ss = open(0).read().split()
ans = 0
inter_count = sum([s.count('AB') for s in ss])
ans += inter_count

_a = sum(s[-1] == 'A' for s in ss)
b_ = sum(s[0] == 'B' for s in ss)
b_a = sum(s[0] == 'B' and s[-1] == 'A' for s in ss)
_a -= b_a
b_ -= b_a

ans += max(0,b_a-1)

if b_a:
    ans += bool(b_)
    b_ -= bool(b_)
    ans += bool(_a)
    _a -= bool(_a)

ans += min(b_, _a)
print(ans)

Measured memory_bytes: 68440
A,V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if A < B:
  if (T*V+A) >= (T*W+B):
    print("YES")
  else:
    print("NO")
else:
  if  (A-T*V) <= (B-T*W):
    print("YES")
  else:
    print("NO")


Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <queue>

int main()
{
	int N;
	std::cin >> N;
	int count = 0;
	bool exist = false;
	for (int i = 0; i < N; ++i) {
		int D1, D2;
		std::cin >> D1 >> D2;
		if (D1 == D2) {
			++count;
		}
		else {
			count = 0;
		}
		if (count == 3) {
			exist = true;
		}
	}
	if (exist) {
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
int main() {
	int K, N; cin >> K >> N;
	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	int ans = A[N - 1] - A[0];
	vector<int> D(N); int m = 0;
	rep(i, N - 1) {
		D[i] = A[i + 1] - A[i];
		m = max(m, D[i]);
	}
	D[N - 1] = K - A[N - 1] + A[0];
	if (m > D[N - 1]) {
		cout << ans - m + D[N - 1] << endl;
	}
	else {
		cout << ans << endl;
	}

	

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll      	long long int
#define PI      	acos(-1)
#define read    	freopen("in.txt","r",stdin)
#define uu      	first
#define vv      	second
#define write   	freopen("out.txt","w",stdout)
#define pii     	pair<int,int>
#define pll         pair<ll,ll>
#define INF     	2e9
#define EPS     	1e-8
#define MAX     	100005
#define MOD     	1000000007
#define fastRead 	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
int n , ara[MAX][5] , dp[MAX][5];

int solve(int id , int prev) {

    if( id ==n ) return 0;

    int &ret = dp[id][prev];
    if( ret != -1)  return ret;

    ret = 0;
    for(int i =1 ; i <= 3; i++ ) {

        if( prev ==i ) continue;
//        cout<<id<<" "<<i<<endl;

        ret = max( ret , ara[id][i] + solve(id+1 , i) );
    }
    return ret;

}

int main()
{
    fastRead;
    cin>>n;
    for(int i =0 ; i < n ; i++ ) {
        for(int j =1 ; j <= 3; j++ ) {
            cin>>ara[i][j];
        }
    }

    memset(dp , -1   ,sizeof dp);
    int ans = solve(0 , 0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12032
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int a[4];
  for (int i = 0; i < 4; i++) cin >> a[i];
  sort(a, a + 4);
  int ans = 1 << 30;
  do {
    ans = min(ans, abs(a[0] + a[1] - a[2] - a[3]));
  } while (next_permutation(a, a + 4));
  cout << ans << endl;
  return 0;
}


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

int N;
int x[110],y[110],h[110];

int main()
{
    scanf("%d",&N);

    for(int i = 0; i < N; i++)scanf("%d%d%d",x + i,y + i,h + i);

    for(int i = 0; i <= 100; i++)
    {
        for(int j = 0; j <= 100; j++)
        {
            int mem = -1;
            bool flag = false;
            for(int k = 0; k < N; k++)
            {
                if(h[k])
                {
                    int tmp = abs(i - x[k]) + abs(j - y[k]) + h[k];
                    if(mem == -1 || mem == tmp)mem = tmp;
                    else flag = true;
                }
            }
            if(flag)continue;

            for(int k = 0; k < N; k++)
            {
                if(h[k] == 0)
                {
                    if(mem - abs(i - x[k]) - abs(j - y[k]) > h[k])flag = true;
                }
            }

            if(flag)continue;


            printf("%d %d %d\n",i,j,mem);
            return 0;
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = str.length();
        char[] c = str.toCharArray();
        String str2 = sc.next();
        int n2 = str2.length();
        
        if (n < n2) {
            System.out.println("UNRESTORABLE");
            return;
        }
        
        int index = -1;
        for (int i = n - n2; i >= 0; i--) {
            boolean end = true;
            for (int j = 0; j < n2; j++) {
                if (c[i + j] == '?') continue;
                if (c[i + j] != str2.charAt(j)) {
                    end = false;
                    break;
                }
            }
            
            if (end) {
                index = i;
                break;
            } else if (i == 0) {
                System.out.println("UNRESTORABLE");
                return;
            }
        }
        
        for (int i = index; i < index + n2; i++) {
            c[i] = str2.charAt(i - index);
        }
        
        for (char chr : c) {
            if (chr == '?') {
                System.out.print('a');
            } else {
                System.out.print(chr);
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 21972
#include <iostream>

int main(int argc, char const* argv[])
{
    int a;
    std::cin >> a;

    auto left = a / 100;
    auto right = a - left * 100;

    auto yymm = false;
    auto mmyy = false;

    if (1 <= left && left <= 12) {
        if (1 <= right && right <= 12) {
            yymm = true;
            mmyy = true;
        }
        else {
            mmyy = true;
        }
    }
    else {
        if (right <= 12 && 1 <= right) {
            yymm = true;
        }
        else {
        }
    }
    if (yymm) {
        if (mmyy) {
            std::cout << "AMBIGUOUS" << std::endl;
        }
        else {
            std::cout << "YYMM" << std::endl;
        }
    }
    else {
        if (mmyy) {
            std::cout << "MMYY" << std::endl;
        }
        else {
            std::cout << "NA" << std::endl;
        }
    }
}

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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	lli 			long long int
#define 	rep(i, n) 		for(int i = 0 ; i < n ; i++)
#define 	repn(i, n) 		for(int i = n - 1 ; i >= 0 ; i--)
#define 	loop(i, a, b)	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define 	hello 			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	F 				first
#define 	S 				second
#define 	pb 				push_back
#define 	mp				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define 	vs 				vector<string>
#define 	print(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; }

bool compare(const pair<string, int> &a, const pair<string, int> &b){ return a.second < b.second; }

int gcd(int a, int b) 
{ 	
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}

int main()
{
	boost;
	int h, w, n, count = 0, tmp = 0;
	cin>>h>>w>>n;

	if(h > w)
	{
		while(tmp < n && h)
		{
			tmp += h;
			count++;
		}
	}
	else
	{
		while(tmp < n && w)
		{
			tmp += w;
			count++;
		}
	}

	cout<<count<<nl;


}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	string S, T;
	cin >> S >> T;
	map<char, char>ma, ima;
	bool can = true;
	for (int i = 0; i < S.size(); ++i) {
		char s = S[i];
		char t = T[i];
		if (ma.count(s)) {
			if (ma[s] != t) {
				can = false;
			}
		}
		if (ima.count(t)) {
			if (ima[t] != s) {
				can = false;
			}
		}
		ma[s] = t;
		ima[t] = s;
	}
	if (can)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200005];
int main(){
    ll n,k,ans=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(k>0){
            k--;continue;
        }
        else{
            ans+=a[i];
        }
    }
    cout<<ans<<endl;
}                     

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int x,c=0;
  string s;
  cin>>x;
  s=to_string(x);
  for(int i=0;i<(int)s.size();i++) c+=s[i]-'0';
  cout<<(x%c==0?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
 
int calc(int N){
  int i;
  for(i=0;i*(i+1)*(i+2)/6<=N;i++){
  }
  i--;
  return i*(i+1)*(i+2)/6;
}
 
int solve(){
  int res=0;
  for(int i=0;i*i*i<=n;i++){
    res=max(res, i*i*i + calc( n-i*i*i ) );
  }
  return res;
}
 
int main(){
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    printf("%d\n",solve());
  }
  return 0;
}

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	cStart := (a - 1) / c
	cEnd := b / c
	cNum := cEnd - cStart

	dStart := (a - 1) / d
	dEnd := b / d
	dNum := dEnd - dStart

	cdNum := 0
	if cNum > 0 && dNum > 0 {
		minCommonMultiple := c * d / getMinCommonDivisor(c, d)

		cdStart := (a - 1) / minCommonMultiple
		cdEnd := b / minCommonMultiple

		cdNum = cdEnd - cdStart

	}
	// fmt.Println(c * d / getMinCommonDivisor(c, d))
	// fmt.Println(cNum, dNum, cdNum)
	res := b - a + 1 - (cNum + dNum - cdNum)
	fmt.Println(res)
}

func getMinCommonDivisor(m, n int) int {
	for m%n != 0 {
		temp := n
		n = m % n
		m = temp
	}
	return n
}


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

const int MAX = 1000000;

int main() {
  static bool is_prime[MAX + 1];
  fill(is_prime, is_prime + MAX + 1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i = 2; i * i <= MAX; ++i)
    for(int j = i * i; j <= MAX; j += i)
      is_prime[j] = false;
  for(int N, S; cin >> N >> S, N || S; ) {
    static bool can_make[MAX + 1];
    fill(can_make, can_make + MAX + 1, false);
    can_make[0] = true;
    for(int i = 0; i < N; ++i) {
      int x; cin >> x;
      for(int j = 0; j <= S - x; ++j) {
        if(can_make[j]) can_make[j + x] = true;
      }
    }
    int ans = -1;
    for(int i = (int)S; i >= 0; --i) {
      if(can_make[i] && is_prime[i]) {
        ans = i;
        break;
      }
    }
    if(ans == -1) cout << "NA" << endl;
    else cout << ans << endl;
  }
}

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

#define int long long int
#define pb push_back
#define pi pair<int, int>
#define fir first
#define sec second
#define MAXN 19
#define mod 1000000007

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, t;
  cin >> s >> t;
  int ans = INT_MAX, l = 0, r = t.size() - 1;
  while (r < s.size())
  {
    int at = 0;
    for (int i = 0; i < t.size(); i++)
      if (t[i] != s[l + i])
        at++;
    ans = min(ans, at);
    l++, r++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
-module('Main').
-export([main/1]).

main(_) ->
    {ok, [S]} = io:fread("", "~s"),
    case lists:last(S) == $s of
        true ->
            io:format("~s~s~n", [S, "es"]);
        false ->
            io:format("~s~s~n", [S, "s"])
    end,
    halt().

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

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

ll a, b, n, c1, c2, ans = 0;

ll f(ll x) { return floor(a * x / b) - a * floor(x / b); }

int main() {
  cin >> a >> b >> n;
  cout << f(min(b - 1, n)) << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    vector<P> a(n);
    rep(i,n) cin>>a.at(i).F>>a.at(i).S;
    sort(all(a));
    int ans=0;
    rep(i,n){
        ans+=a.at(i).F*min(a.at(i).S,m);
        m-=min(a.at(i).S,m);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
//
// Created by watemus on 05.06.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;

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

template<typename T>
using uset = unordered_set<T>;

template<typename T1, typename T2>
using umap = unordered_map<T1, T2>;

#define int ll

constexpr ld INFL = 1'000'000'000'000'000'001;
constexpr int INFI = 1'000'000'228;
constexpr ld PI = acos(-1);

vector<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

#ifdef LOCAL
#else
#endif

void run() {
    int n;
    cin >> n;
    ld cur = 1;
    int z = 0;
    bool fnd = false;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == z) z++;
        cur *= a;
        if (cur >= INFL) {
            fnd = true;
        }
    }
    if (z > 0) {
        puts("0");
        return;
    } else if (fnd) {
        puts("-1");
        return;
    }
    cout << int(cur) << '\n';
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    cout << fixed << setprecision(20);
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}



Measured memory_bytes: 3580
import java.util.*;

class Main{
    static int num = 1000*2+1;
    static int max = 1000;
    static long[][] dp = new long[num+1][num+1];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Long x = sc.nextLong();
        for(int i=0;i<=max*2;i++){
            long it = i-max;
            long a = pow5(it);
            for(int j=0;j<=max*2;j++){
                long jt = j-max;
                long b = pow5(jt);
                if(x==(a-b)){
                    System.out.println(it + " " + jt);
                    return;
                }
                else if(x==(b-a)){
                    System.out.println(jt + " " + it);
                    return;
                }
            }
        }

    }

    private static Long pow5(Long x) {
        return x*x*x*x*x;        
    }
}


Measured memory_bytes: 78356
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    int N; cin>>N;
    
    vint dp(N+1,N);
    dp[0]=0;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=i;j*=6){
            dp[i]=min(dp[i],dp[i-j]+1);
        }
        for(int j=1;j<=i;j*=9){
            dp[i]=min(dp[i],dp[i-j]+1);
        }
    }
    cout<<dp[N]<<endl;

}


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

#define int long long
#define ld long double

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>b;i--)

#define pb push_back
#define mp make_pair
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define precise(i) fixed << setprecision(i)
#define fi first
#define se second

#define err() cout<<"\n==================================\n";
#define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n";
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n";
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n";

const int logN = 20;
const int M = 1000000007;
const int INF = 1e12;
#define PI 3.14159265;
const int N = 200005;

#define Pii pair<int,int>
#define Vi vector<int>
#define Vpii vector<Pii>

void solve()
{
       int n,m1,m2;
       cin>>n;
       Vi a(n),b(n);
       rep(c,0,n)
       {
              cin>>a[c]>>b[c];
       }
       sort(all(a));
       sort(all(b));
       if(n%2==0)
       {
              m1=((a[n/2-1])+(a[n/2]));
              m2=((b[n/2-1])+(b[n/2]));
       }
       else
       {
              m1=a[(n-1)/2];
              m2=b[(n-1)/2];
       }
       cout<<(m2-m1)+1;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)
    {
           solve();
    }
    return 0;
}

Measured memory_bytes: 6300
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	_ = nextInt()
	s := nextStr()

	ok := true

	for i := 0; i < len(s); i++ {
		if i == a {
			if s[i] != '-' {
				ok = false
				break
			}
		} else {
			//if (s[i] < '0') || (s[i] > '9') {
			if !isDigit(s[i]) {
				ok = false
				break
			}
		}

	}

	if ok == true {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

func isDigit(a byte) bool {
	return ((a >= '0') && (a <= '9'))
}
func isDigit2(a byte) bool {
	return unicode.IsDigit(rune(a))
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
#include <iostream>
#include <cstdint>

using namespace std;

int main() {
  uint64_t n;
  cin >> n;
  --n;
  uint64_t s = 0;
  for (uint64_t i = 1; i <= n; ++i) {
    s += n / i;
  }
  cout << s << endl;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
int a[100005];
signed main(){
  int b;
  while(scanf("%d",&b),b){
      int c,d;
      scanf("%d%d",&c,&d);
      a[0]=0;
      a[1]=b;
      for(int e=2;e<=c;e++){
	  scanf("%d",&a[e]);
	  }
	  sort(a,a+c+1);
	int sum=0;
	for(int f=0;f<d;f++){
	    int g;
	    scanf("%d",&g);
	    auto t=lower_bound(a,a+c+1,g);
	    int k=*t-g;
	    t--;
	    k=min(k,g-*t);
	    sum+=k;
	    }
	    cout<<sum<<endl;
      }
}

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

int main() {
  int n;
  cin >> n;
  int nextnum = 1;
  rep(i, n) {
    int a;
    cin >> a;
    if(a == nextnum) ++nextnum;
  }
  
  if (nextnum == 1) cout << -1 << endl;
  else cout << n-nextnum+1 << endl;
      
  return 0;
}


Measured memory_bytes: 3628
N,K = map(int,input().split())

h = list(map(int,input().split()))

INF = 100100100100100
dp = [INF]*N

dp[0] = 0

for i in range(1,N):
    for k in range(1,K+1):
        if i < k:
            break
        dp[i] = min(dp[i], dp[i-k] + abs(h[i] - h[i-k]))
        
print(dp[N-1])

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	static int sum[101][101];
	rep(i,n) rep(j,n) {
		int a; scanf("%d",&a);
		sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+a;
	}

	int ans=sum[n][n];
	rep(t,n) for(int b=t+1;b<=n;b++) rep(l,n) for(int r=l+1;r<=n;r++) ans=max(ans,sum[b][r]-sum[b][l]-sum[t][r]+sum[t][l]);
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 1068
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int a, b;
	int sum;
	cin >> a >> b;
	if (a >= 3 && b >= 3)
	{
		sum=max(a + a - 1,b+b-1);
		sum = max(sum, a + b);
	}
	cout << sum;
}

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  long long n,a,b;
  cin>>n>>a>>b;
  long long len=a+b;
  long long cnt=n/len;
  cnt*=a;
  cnt+=min(a,n%len);
  cout<<cnt<<endl;
  return 0;
}






Measured memory_bytes: 256
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  string S,T;
  //vector<ll> A();
  cin>>S;
  for(ll i=0;i<3;i++){
    cout<<S.at(i);
  }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    int sum = 0;
    rep(i,n-1) sum += p[i];
    sum += p[n-1]/2;
    cout << sum << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define rf(i,a,b) for(int (i) = (a); (i) <= (b); (i)++)
#define rb(i,b,a) for(int (i) = (b); (i) >= (a); (i)--)
#define watch(x) cout << (#x) << " = " << (x) << endl
#define test(t) int(testCnt) = 0; int(t); cin >> (t); while(t -- && ++testCnt) 

const int INF = 2e9 + 7;
const int MAXA = 1e5 + 10;
const ll MOD = (ll) 1e9 + 7;
const ll INFLL = 9e18 + 7;

typedef pair<int, int> ii;
typedef pair<ii, int> II;
typedef vector<int> vi;
typedef vector<ii> vii;

ll addMod(ll x, ll y) {return (x + y) % MOD;}

ll subMod(ll x, ll y) {return ((x - y) % MOD + MOD) % MOD;}

ll mulMod(ll x, ll y) {return ((x % MOD) * (y % MOD)) % MOD;}

ll powMod(ll x, ll p) {
    if (p == 0) return 1LL; if (p == 1) return x % MOD;
    ll t = powMod(x, (p/2));
    return (((t * t) % MOD) * powMod(x, p % 2)) % MOD;
}

ll revMod(ll x) {return powMod(x, MOD - 2);}

bool v[110][MAXA];
ll f[110][MAXA];
int a[MAXA], n, k;

ll sol(int i, int cr) {
	//cout << i << " " << cr << endl;
	if(v[i][cr]) return f[i][cr];
	v[i][cr] = 1;
	if(i == n) {
		if(cr > a[n]) return f[i][cr] = 0LL;
		else return f[i][cr] = 1LL;
	}
	if(v[i][cr - 1]) {
		ll temp = f[i][cr - 1];
		if(cr - 1 >= a[i])
			temp = subMod(temp, f[i + 1][cr - 1 - a[i]]);
		return f[i][cr] = addMod(temp, sol(i + 1, cr));
	}
	rb(j, a[i], 0) {
		if(cr >= j)
			f[i][cr] = addMod(f[i][cr], sol(i + 1, cr - j));
	}
	return f[i][cr];
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
    #endif
    cin >> n >> k;
    rf(i, 1, n) {
    	cin >> a[i];
    }
    sol(1,k);
    cout << f[1][k];
    return 0;
}

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


int main()
{
  int sum = 0, tmpmin = 10;
  for(int i=0; i<5; i++)
  {
    int tmp;
    cin >> tmp;
    sum += ceil(tmp/10.0)*10;
    int res = tmp%10;
    if(res==0) res=10;
    tmpmin = min(tmpmin,res);
  }
  cout << sum-10+tmpmin << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<string.h>
#include<map>
#include<set>
//#include <boost/multiprecision/cpp_int.hpp>

//namespace mp = boost::multiprecision;

using namespace std;
int main() {
	int n,k;
	cin >> n >> k;
	int flag =0;
	if (n % 2 == 0) {
		if (k <= n / 2) {
			flag++;
		}
	}
	else {
		if (k <= n / 2 + 1)flag++;
	}
	if (flag == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define md 1000000007
#define fi first
#define se second
#define mp make_pair
#define	inf 1000000000
#define li 1000005
#define int long long
#define pb push_back
#define GG {printf("0\n");return 0;}
using namespace std;
int n,m,vis[li],A[1005],B[1005],sat[li],sut[li],say;
int ksutun,ksatir;
int cev=1;
inline int mul(int a,int b){
	return a*b%md;
}
main(){
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&A[i]);
		if(vis[A[i]]==1) GG;
		vis[A[i]]=1;
		sat[A[i]]=1;
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=m;i++){
		scanf("%lld",&B[i]);
		if(vis[B[i]]==1) GG;
		vis[B[i]]=1;
		sut[B[i]]=1;
	}
	for(int i=n*m;i>=1;i--){
		if(sat[i]==1 && sut[i]==1) {say++;ksatir++;ksutun++;continue;}
		if(sat[i]==1 && sut[i]==0){
			//~ printf("?");
			cev=mul(cev,ksutun);
		}
		if(sat[i]==0 && sut[i]==1){
			//~ printf("!");
			cev=mul(cev,ksatir);
		}
		if(sat[i]==0 && sut[i]==0){
			//~ printf("h");
			//~ cout<<"deb :: "<<say<<m*n<<endl;
			cev=mul(cev,ksatir*ksutun-(n*m-i));
		}
		say++;
		if(sat[i]==1) ksatir++;
		if(sut[i]==1) ksutun++;
		//~ cout<<"deb:: "<<i<<"  "<<cev<<endl;
	}
	printf("%lld\n",cev);
	return 0;
}


Measured memory_bytes: 13440
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
	long long x,l;
}a[100005];
bool cmp(node h,node g){
	return h.x<g.x;
}
int main(){
	long long n,ans,x1,x2,l1,l2;
	ans=1;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i].x,&a[i].l);
	}
	sort(a+1,a+1+n,cmp);
	x1=a[1].x;l1=a[1].l;
	for(int i=2;i<=n;i++){
		x2=a[i].x;l2=a[i].l;
		if(x1+l1<=x2-l2){
			x1=x2;l1=l2;
			ans++;
		}
		else{
			if(x1+l1>x2+l2){
				x1=x2;l1=l2;
			}
		}
	} 
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 1792
let () =
  let n = read_int () in
  let rec read l = function
      0 -> List.rev l
    | i -> read (read_int () :: l) (i-1)
  in
  let m,d,lst = match read [] n with
      a::b::l -> (min a b),b-a,l
    | _ -> 0,0,[]in
  let _,md = List.fold_left
      (fun acc v ->
         match acc with
           m,md -> let d = v-m in
           (if v < m then v else m), (if d > md then d else md))
      (m,d)
      lst in
  Printf.printf "%d\n" md

Measured memory_bytes: 13292
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

ll a[10][10];

int main() {
	IOS();
	ll n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> a[i][j];
		}
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ll tmp = 0;
			for (int k = 0; k < d; k++) {
				tmp += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
			}
			for (int k = 0; k < 200; k++) {
				ll unko = k * k;
				if (unko == tmp) {
					ans++;
					break;
				}
			}
		}
	}
	dump(ans);
	return 0;
}


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


int main(void)
{
    int loginCoinA = 0;
    int weeklyCoinB = 0;
    int targetCoinC = 0;

    std::cin >> loginCoinA >> weeklyCoinB >> targetCoinC;

    int nowCoin = 0;
    int days = 0;
    while (targetCoinC > nowCoin) {
        days++;

        nowCoin += loginCoinA;
        if ((days % 7) == 0) {
            nowCoin += weeklyCoinB;
        }
    }

    std::cout << days << "\n";
    return 0;
}



Measured memory_bytes: 3128
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  long long A, B, C;
  cin >> A >> B >> C;

  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }

  long long ret = A * B;
  ret = min(ret, A * C);
  ret = min(ret, B * C);

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define ll long long

int main(void)
{
    int a1,a2,b,cn=0;
    scanf("%d%d%d",&a1,&a2,&b);
    for(;a1<=a2;a1++)
    {
        if(b%a1==0)
            cn++;
    }
    printf("%d\n",cn);
    return 0;
}




Measured memory_bytes: 2096
#include <iostream>

using namespace std;

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

    bool alice_moved = true, borys_moved = true;
    int i = 0;
    while(1) {

        if (i % 2 == 0) {
            if (a + 1 == b) {
                if (a == 1) {
                    alice_moved = false;
                    break;
                }
                a--;

            } else {
                a++;
            }

        } else {
            if (b - 1 == a) {
                if (b == n) {
                    borys_moved = false;
                    break;
                }
                b++;

            } else {
                b--;
            }
        }

        i++;
    }

    cout << ((alice_moved)? "Alice" : "Borys") << endl;

    return 0;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

#from fractions import gcd

def gcd(a, b): 
    if a == 0: return b 
    if b == 0: return a 
    k = 0
    while ((a | b) & 1) == 0: 
        a >>= 1
        b >>= 1
        k += 1
    while (a & 1) == 0: 
        a >>= 1
    while b:  
        while (b & 1) == 0: 
            b >>= 1
        if a > b : 
            a,b = b,a
        b = b - a 
    return a << k 

from math import sqrt
def pfact(num):
    global dt
    if num&1 == 0:
        num >>= 1
        if dt[2]:
            dt[2] = 0
        else:
            return 'setwise coprime'
    while num&1 == 0:
        num >>= 1
    for i in range(3,int(sqrt(num))+1,2):
        if num%i == 0:
            num //= i
            if dt[i]:
                dt[i] = 0
            else:
                return 'setwise coprime'
        while num%i == 0:
            num //= i
    if num>2:
        if dt[num]:
            dt[num] = 0
        else:
            return 'setwise coprime'
    return 'pairwise coprime'

n = inp()
x = ip()
t = x[0]
for i in range(1,n):
    t = gcd(t,x[i])
    if t == 1:
        break
if t != 1:
    ans = 'not coprime'
else:
    ans = 'pairwise coprime'
    dt = {i+1:1 for i in range(10**6)}
    for i in x:
        if pfact(i) == 'setwise coprime':
            ans = 'setwise coprime'
            break
print(ans)


Measured memory_bytes: 246324
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>

using namespace std;


int w,h,x,y;
double s;

int main() {

  int ans = 0;
  cin >> w >> h >> x >> y;

  s = (double)((double)w*(double)h/(double)2.0);


  if ((w%2) == 0) {
    if ((h%2) == 0) {
      if (x == (w/2)) {
        if (y == (h/2)) {
          ans = 1;
        }
      }
    }
  }

  cout << s << " " << ans << endl;

  return 0;
}


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

namespace Sample1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int T = int.Parse(str[1]);
            int[,] route = new int[N,2];
            for(int i=0; i<N; i++)
            {
                str = Console.ReadLine().Split(' ');
                for(int j=0; j<2; j++)
                {
                    route[i, j] = int.Parse(str[j]);
                }
            }
            var cost = 1001;
            for(int i=0; i<N; i++)
            {
                if(route[i,1] <= T)
                {
                    if(route[i,0] < cost)
                    {
                        cost = route[i, 0];
                    }
                }
            }
            if(cost==1001)
            {
                Console.WriteLine("TLE");
            }
            else
            {
                Console.WriteLine($"{cost}");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;

int main () {
  int N, K;
  cin >> N >> K;
  
  long double ans = 0;
  for (int i = 1; i <= N; i++) {
    int j = 0;
    while ((i * 1<<j) < K) j++;
    ans += pow(0.5, j);
  }
  cout << setprecision(15) << ans / N;
}


Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
import sys
import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
if w%3==0:
    s1=0
else:
    s1=h
if h%3==0:
    s2=0
else:
    s2=w
fw=floor(w/3)
fh=floor(h/2)
cw=ceil(w/3)
SMAX1=(w-fw)*(h-fh)
SMIN1=min(fw*h,(w-fw)*fh)
SMAX2=max(cw*h,(w-cw)*(h-fh))
SMIN2=(w-cw)*fh
#print(SMAX1,SMIN1,SMAX2,SMIN2)
s3=min(SMAX1-SMIN1,SMAX2-SMIN2)
h,w=w,h
fw=floor(w/3)
fh=floor(h/2)
cw=ceil(w/3)
SMAX1=(w-fw)*(h-fh)
SMIN1=min(fw*h,(w-fw)*fh)
SMAX2=max(cw*h,(w-cw)*(h-fh))
SMIN2=(w-cw)*fh
s4=min(SMAX1-SMIN1,SMAX2-SMIN2)
#print(s1,s2,s3,s4)
ans=min(s1,s2,s3,s4)
print(ans)

Measured memory_bytes: 12432
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 10e-8;

ll nCr(int n,int r){
	return (r==0|| n==r) ? 1 : nCr(n-1,r) + nCr(n-1,r-1);
}

int main(){
	string str;
	while(cin>>str){
		map<char,int> freq;
		for(int i=0;i<str.size();i++){
			freq[str[i]]++;
		}

		bool isok = true;
		ll sum=1;
		if(str.size() % 2 == 0){	
			int size = str.size() / 2;
			for(map<char,int>::iterator it = freq.begin(); it != freq.end(); it++){
				if(it->second % 2 != 0){
					isok = false;
					break;
				}
				else{
					sum *= nCr(size,it->second / 2);
					size -= it->second / 2;
				}
			}
		}
		else{
			int size = str.size() / 2;
			int c = 0;
			for(map<char,int>::iterator it = freq.begin(); it != freq.end(); it++){
				if(it->second % 2 != 0){
					c++;
					if(c>=2) isok = false;
					if(it->second > 2){
						sum *= nCr(size,(it->second - 1) / 2);
						size -= (it->second - 1) / 2;
					}
				}
				else{
					sum *= nCr(size,it->second / 2);
					size -= it->second / 2;
				}
			}
		}

		printf("%lld\n",isok ? sum : 0);
	}	
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
int n,tim=0;
vector<vector<int> >  lis(100000+5);
vint d(100000+5); vint f(100000+5); vector<bool> flag(100000+5);
void dfs(int now){
    if(flag[now]){
        return;
    }
    flag[now]=true;
    d[now]=++tim;
    rep(i,lis[now].size()){
        dfs(lis[now][i]);
    }
    f[now]=++tim;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    int u,k,v;
    rep(i,n){
        cin>>u>>k;
        rep(j,k){
            cin>>v;
            lis[u].push_back(v);
        }
    }
    REP(i,1,n+1){
        if(!flag[i]){
            dfs(i);
        }
    }    
    REP(i,1,n+1){
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return(0);
}


Measured memory_bytes: 5840
#include <stdio.h>

int lowerBound(int [], int, int);

int main(void)
{
    int i, n, q, k, A[100000];

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", A + i);
    
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &k);
        printf("%d\n", lowerBound(A, n, k));
    }

    return 0;
}

int lowerBound(int A[], int N, int k)
{
    int low, mid, high;
    low = 0;
    high = N;
    while (low < high) {
        mid = (low + high) / 2;
        if (A[mid] == k) {
            while (mid > 0 && A[mid - 1] == k)
                mid--;
            return mid;
        } else if (A[mid] < k) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    if (A[mid] < k)
        return mid + 1;
    else
        return mid;
}


Measured memory_bytes: 2252
#pragma GCC optimize("O3", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC optimize("tree-vectorize")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")

#include <iostream>
#include <bitset>
using namespace std;

int h, w, n;
int sr, sc;

string s, t;

bitset<200003> b;

template <char c1, char c2>
bool solve(int m, int pos)
{
    b.reset();
    b[0] = true;
    b[m + 1] = true;

    for (int i = n - 1; i >= 0; i--)
    {
        if (t[i] == c1)
            b &= (b << 1);
        else if (t[i] == c2)
            b &= (b >> 1);

        b[0] = true;
        b[m + 1] = true;

        if (s[i] == c1)
            b |= (b << 1);
        else if (s[i] == c2)
            b |= (b >> 1);

        b[0] = true;
        b[m + 1] = true;
    }

    return b[pos + 1];
}

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

    cin >> h >> w >> n;
    cin >> sr >> sc;
    sr--;
    sc--;
    cin >> s >> t;

    bool ans = false;
    if (solve<'L', 'R'>(w, sc) || solve<'U', 'D'>(h, sr))
    {
        ans = true;
    }

    cout << (ans ? "NO" : "YES") << endl;

    return 0;
}

Measured memory_bytes: 920
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
if K % 7 == 0:
    K //= 7

A = [1]  # A[i] = 10**i mod K
for i in range(K):
    A.append((A[-1]*10) % K)

s = 1
for i in range(1,K+1):
    if s % K == 0:
        print(i)
        exit()
    else:
        s += A[i]
        s %= K


Measured memory_bytes: 141320
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int series_sum(long long int);

int main(){
    ll n,m,ans;
    cin>>n>>m;
    if(n==1||m==1){
        if(n==1&&m==1)ans=1;
        else if(n==1)ans=m-2;
        else if(m==1)ans=n-2;
    }else if(n==2||m==2){
        ans=0;
    }else{
        ans=(m-2)*(n-2);
    }
    cout<<ans<<endl;
}

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

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

ll modpower(ll x, ll y) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else if (y % 2 == 0) {
        ll p = modpower(x, y / 2);
        return p * p % mod;
    } else {
        ll p = modpower (x, y / 2);
        return (p * p) % mod * (x % mod) % mod;
    }
}

ll dp[100010][3];

int main() {
    string S;
    cin >> S;
    ll len = S.size();
    fill(dp[0], dp[0] + 3, 0);
    ll tmp = 1;
    REP(i, 0, len) {
        if (S[i] == 'A') {
            dp[i + 1][0] = dp[i][0] + tmp;
            dp[i + 1][1] = dp[i][1];
            dp[i + 1][2] = dp[i][2];
        } else if (S[i] == 'B') {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1] + dp[i][0];
            dp[i + 1][2] = dp[i][2];
        } else if (S[i] == 'C') {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1];
            dp[i + 1][2] = dp[i][2] + dp[i][1];
        } else {
            dp[i + 1][0] = multiply(dp[i][0], 3) + tmp;
            dp[i + 1][1] = multiply(dp[i][1], 3) + dp[i][0];
            dp[i + 1][2] = multiply(dp[i][2], 3) + dp[i][1];
            tmp = multiply(tmp, 3);
        }
        REP(j, 0, 3) {
            dp[i + 1][j] = dp[i + 1][j] % mod;
        }
    }
    // REP(i, 0, len + 1) {
    //     REP(j, 0, 3) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = dp[len][2];
    cout << ans << endl;
}


Measured memory_bytes: 2816
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++) 
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int N = 1e6 + 50, oo = 1e18 + 100, mod = 1e9 + 9;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[N];
vi visit(N, 0);
int n, m, k;
int cnt = 0;

typedef int ftype;
typedef complex<ftype> point;
#define x real
#define y imag

ftype dot(point a, point b) 
{
	return (conj(a) * b).x();
}

ftype f(point a, ftype x) {
	return dot(a, { x, 1 });
}

vector<point> t(4*N, { 0, oo });

void add_line(point nw, int v = 1, int l = 0, int r = N)
{
	int md = (r + l) >> 1;

	bool left = f(nw, l) < f(t[v], l);
	bool mid = f(nw, md) < f(t[v], md);

	if (mid)
	{
		swap(t[v], nw);
	}

	if (l == r-1)
		return;

	if (left != mid)
	{
		add_line(nw, v << 1, l, md);
	}
	else
	{
		add_line(nw, v << 1 | 1, md, r);
	}

	return;
}

int get(int x, int v = 1, int l = 0, int r = N)
{
	int ret = f(t[v], x);

	if (l == r - 1)
		return ret;

	int md = (r + l) >> 1;

	if (x < md)
	{
		return min(ret, get(x, v << 1, l, md));
	}
	else
	{
		return min(ret, get(x, v << 1 | 1, md, r));
	}
}

int dp[N];

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("stars.in", "r", stdin);
	freopen("stars.out", "w", stdout);*/
	
	cin >> n >> m;

	vi h(n);

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

	dp[0] = 0;
	add_line({ -2 * h[0], h[0] * h[0] + dp[0] });

	for (int i = 1; i < n; i++)
	{
		dp[i] = get(h[i]) + h[i]*h[i] + m;
		add_line({ -2 * h[i], h[i] * h[i] + dp[i] });
	}

	cout << dp[n - 1];
}

Measured memory_bytes: 98816
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

struct prime{
    int p,q;
};

int main(){
    int N;
    cin >> N;
    map<int,int> m;
    int n = N;
    for(int i=2;i*i<=N;i++){
        while(n%i==0){
            n /= i;
            m[i]++;
        }
    }
    if(n!=1) m[n]++;
    vec<prime> P;
    for(auto x:m) P.push_back({x.first,x.second});
    int ans = 0;
    n = P.size();
    for(int S=1;S<(1<<n);S++){
        int val = 1;
        for(int j=0;j<n;j++){
            if(S&(1<<j)) val *= P[j].p;
        }
        int s = __builtin_popcount(S);
        ans += (N/val)*(s%2? 1:-1);
    }
    cout << N-ans << endl;
}


Measured memory_bytes: 3160