akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main(){
    string s;
    cin >> s;
    string t;
    t.push_back(s.at(5));
    t.push_back(s.at(6));
    int a=stoi(t);
    if (a>=5) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
}


Measured memory_bytes: 256
N=int(input())
S=input()

answer=0
for i in range(1000):
  i0=i//100
  i1=(i//10)%10
  i2=i%10

  flag_num=0
  for s in S:
    if flag_num==0 and s==str(i0):
      flag_num+=1
    elif flag_num==1 and s==str(i1):
      flag_num+=1
    elif flag_num==2 and s==str(i2):
      answer+=1
      break
      
print(answer)

Measured memory_bytes: 45660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define in(a) cin >> a;
#define in2(a,b) cin >> a >> b;
#define in3(a,b,c) cin >> a >> b >> c;
#define out(a) cout << a << endl;
#define inV(A) REP(i,A.size()) in(A[i]);
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
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); }
//-----------------------------------
int main(){
    init();
    ll K,S;
    in2(K,S);
    ll cnt=0;
    REP(i,K+1){
        REP(j,K+1){
            if(0<=S-(i+j) && S-(i+j)<=K) cnt++;
        }
    }
    // inV(A);
    out(cnt);
}

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

using namespace std;

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int n,a,odd=0,even=0,temp;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++) {
    	cin>>a;
    	if(a%2==0)
    		even++;
    	else
    		odd++;
	}
	while(odd>1){
		temp=odd/2;
		odd=odd-temp*2;
		even=even+temp;
	}
	while(even>1){
		temp=even/2;
		even=even-temp*2;
		even=even+temp;
	}
	if(odd+even==1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String str = br.readLine();
			if ("0".equals(str)) {
				break;
			}
			int len = str.length();
			int sum = 0;
			for (int i = 0; i < len; i++) {
				int n = Integer.parseInt(String.valueOf(str.charAt(i)));
				sum += n;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,m,ac{},wa{};
    in>>n>>m;
    vector<int> v(n+1);
    fr(i,m){
        int p;
        string s;
        in>>p>>s;
        if(v[p]==-1) continue;
        if(s=="AC"){
            ++ac;
            wa+=v[p];
            v[p]=-1;
        }
        else{
            ++v[p];
        }
    }
    cout<<ac<<" "<<wa<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

int solve(){
    ll X,K,D;
    cin >> X >> K >> D;
    ll res;
    //-5 3 → 1
    //あまりを求めるしかない
    //あまりを求めて、　D - あまり　か あまりが 最小値になる
    //K回が足りなければ、X - K*D

    X = abs(X);
    if(X / D >= K)
    {
        res = X - K*D;
    }
    else
    {
        ll sho,amari;
        sho = X / D;
        amari = X % D;

        if((K-sho) % 2 == 0)
        {
            res = amari;
        } 
        else
        {
            res = D - amari;
        }
    }
    
    cout << res << endl;
    return 0;
}

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


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;cin>>n;
  for (int i=0;i<100/4+1;i++){
    for (int j=0;j<100/7+1;j++){
      if (4*i + 7*j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
// 2019-06-19
// 提出したが，WA.
// Tをまったく使わないのが
// 変だとは思うけど，
// 何か問題を勘違いしている？

#include <bits/stdc++.h>

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

using namespace std;

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

    int N, T;
    cin >> N >> T;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    int cost = 0;
    int profit_max = 0;
    int p = N - 1;
    int A_max = A[p];
    while (p > 0) {
        int max_count = 1;
        A_max = max(A_max, A[p]);
        while (p > 0 && A[p - 1] == A[p]) {
            ++max_count;
            --p;
        }
        while (p > 0 && A[p - 1] < A[p]) {
            --p;
        }
        int min_count = 1;
        int A_min = A[p];
        while (p > 0 && A[p - 1] == A[p]) {
            ++min_count;
            --p;
        }
        int profit = A_max - A_min;
        if (profit_max < profit) {
            profit_max = profit;
            cost = 0;
        }
        if (profit_max == profit) {
            cost += min(max_count, min_count);
        }
        while (p > 0 && A[p - 1] > A[p]) {
            --p;
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 640
use std::io;
use std::cmp::max;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	println!("{}", max(max(a+b, a-b), a*b));
}

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

//void primeFactor(int n);
//void hateFactor(int n, int a, int b)
//{
//    if(a == 0)
//    {
//        n = pow(b, 5);
//        a = pow(a, 5);
//    }
//
//}
int main()
{
    int x;
    cin >> x;
    for(int a = -1000; a <= 1000; a++)
    {
        for(int b = -1000; b <= 1000; b++)
        {
            if(pow(a, 5) - pow(b, 5) == x)
            {
                cout << a << " " << b << "\n";
                return 0;
            }
        }
    }
}


Measured memory_bytes: 4008
#include <iostream>
#include <string>
using namespace std;
string k;
int i, n, r ,s;
int main(){
	cin>>k;
	
	for(i=0; i<=2; i++){
		if(k[i]=='R') r++;
		else s++; 
	}
	if(k[1]=='S'){
		if(r==0) cout<<"0";
		else cout<<"1";
	}
	else cout<<r;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
#define MAX 1000005
bool ham[MAX];
int num_ham[MAX];
using namespace std;
void MakeHammings(){
	const int mul[] = {2,3,5};
	ham[1] = true;
	num_ham[0] = 0;
	for(int i = 1; i < MAX; ++i){
		num_ham[i] = num_ham[i-1];
		if( ham[i] ){
			num_ham[i]++;		
			for(int k = 0; k < sizeof(mul)/sizeof(*mul); ++k){
				for(int j = 1; i * (int)pow((double)mul[k],j) < MAX; ++j){
					ham[i*(int)pow((double)mul[k],j)] = true;
				}
			}
		}
	}
}
int main(){
	MakeHammings();
	while(true){
		int m,n;
		scanf("%d", &m);
		if(m==0)break;
		scanf("%d",&n);
		printf("%d\n", num_ham[n]-num_ham[m]+(ham[m]?1:0));
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
vector<tuple<string,int,int>>a;
for(int i=1;i<=N;i++){
  string s;
  int p;
  cin>>s>>p;
  p=-p;
  a.push_back(tie(s,p,i));
}
sort(a.begin(),a.end());
for(int i=0;i<N;i++){
  cout<<get<2>(a.at(i))<<endl;
  
}
}


Measured memory_bytes: 256
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! print_vec {
    ($vec:expr) => {
        for (i, &v) in $vec.iter().enumerate() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", v);
        }
        println!();
    };
}

fn main() {
    let k = scan!(usize);

    println!("50");
    let mut vs: Vec<usize> = (0..50).map(|i| i + (k / 50)).rev().collect();

    for v in vs.iter_mut().take(k % 50) {
        *v += 1
    }
    print_vec!(vs);
}


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

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N;
    set<int> s;
    cin >> N;
    rep(i, N){
        int a;
        cin >> a;
        s.insert(a);
    }
    int ans = s.size() % 2 ? s.size() : s.size() - 1;
    cout << ans << endl;


}


Measured memory_bytes: 4992
N=int(input())
A=[int(i) for i in input().split()]
C=0
for i in range(N):
    minj=i
    for j in range(i,N):
        if A[j]<A[minj]:
            minj=j
    if i!=minj:
        t=A[i]
        A[i]=A[minj]
        A[minj]=t
        C+=1
 #   print(minj)
for i in range(N):
    A[i]=str(A[i])
print(" ".join(A))
print(C)

Measured memory_bytes: 7744
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

ll mod_pow(ll x, int n){
    if(n == 0)      return 1;

    ll res = 1;
    while(n > 0){
        if(n & 1)   res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

struct Combination{
    int sz;
    vector<ll> fact;
    vector<ll> ifact;

    Combination(int sz = 1e+5) : sz(sz) {
        fact = vector<ll>(sz + 1);
        ifact = vector<ll>(sz + 1);

        fact[0] = 1;
        for(ll i = 1; i <= sz; ++i){
            fact[i] = fact[i - 1] * i % mod;
        }

        ifact[sz] = mod_pow(fact[sz], mod - 2);
        for(ll i = sz; i > 0; --i){
            ifact[i - 1] = ifact[i] * i % mod;
        }
    }

    ll get_combination(int n, int r){
        if(n < 0 || r < 0 || n < r)     return 0;

        return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
    }
};

// product[i][j] := i 人グループを j 個作る場合の数
ll product[1005][1005];

ll dp[1005][1005];

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

    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    Combination comb(2 * 1e+6);
    for(int i = 0; i <= b; ++i) product[i][0] = 1;
    for(int i = 0; i <= b; ++i){
        for(int j = 1; j <= d; ++j){
            product[i][j] = product[i][j - 1] * comb.get_combination(i * j, i) % mod;
        }
        for(int j = 0; j <= d; ++j){
            product[i][j] *= comb.ifact[j];
            product[i][j] %= mod;
        }
    }
    dp[a-1][0] = 1;
    for(int i = a; i <= b; ++i){
        for(int j = 0; j <= n; ++j){
            chadd(dp[i][j], dp[i-1][j]);
            for(int k = c; k <= min(d, j / i); ++k){
                ll hoge = dp[i - 1][j - i * k] * comb.get_combination(n - (j - i * k), i * k) % mod;
                hoge = hoge * product[i][k] % mod;
                chadd(dp[i][j], hoge);
            }
        }
    }
    cout << dp[b][n] << "\n";
}

Measured memory_bytes: 47232
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int dpo[10];
int dpx[10];
ll dp[105][10];
int w;
int d(int x){
    if(x<=0||x>w)return 1;
    else return (dpo[x]+dpx[x]);
}
int main(){
    int h,k;
    cin>>h>>w>>k;
    dpo[1]=1;dpx[1]=0;
    for(int i=1;i<w;i++){
        dpo[i+1]=dpo[i]+dpx[i];
        dpx[i+1]=dpo[i];
    }
    dp[0][1]=1;
    REP(i,h){
        for(int j=1;j<=w;j++){
            dp[i+1][j]+=(ll)dp[i][j]*d(j-1)*d(w-j);
            //cout<<dp[i][j]<<" "<<d(j-1)<<" "<<d(w-j);
            dp[i+1][j]%=MOD;
            dp[i+1][j]+=dp[i][j+1]*d(w-j-1)*d(j-1);
            dp[i+1][j]+=dp[i][j-1]*d(w-j)*d(j-2);
            dp[i+1][j]%=MOD;
            //OUT(dp[i+1][j]);
        }
    }
    OUT(dp[h][k]);
    return 0;
}

Measured memory_bytes: 256
var input=require("fs").readFileSync(0,"utf8");
var a=input.match(/\d+/g).map(Number);
var x=Math.abs(a[0]-a[1]),
	y=Math.abs(a[1]-a[2]),
	z=Math.abs(a[2]-a[0]);
var ans=x+y+z-Math.max(x,y,z);
console.log(ans);


Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};



int main(){
	int a;
	cin>>a;
	print(a*a*3);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int x;
    for(int i(0); i < 5; ++i){
        std::cin >> x;
        if(!x){
            std::cout << i + 1 << std::endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, k;

  cin >> n >> k;

  cout << !!(n % k) << endl;

  return 0;
}


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

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())

d = defaultdict(int)
for i in range(1, n+1):
    s = str(i)
    f = int(s[0])
    b = int(s[-1])
    d[(f, b)] += 1

ans = 0
for a in range(1, 10):
    for b in range(1, 10):
        ans += d[(a, b)] * d[(b, a)]
print(ans)

Measured memory_bytes: 9336
import numpy as np
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N,M,Q=acinput()

A=np.zeros([N+1,N+1])

for i in range(M):
    tmp=acinput()
    A[tmp[0],tmp[1]]+=1
Acs=np.cumsum(A,axis=1 )
Acs=np.cumsum(Acs,axis=0)

for i in range(Q):
    tmp=acinput()
    print(int(Acs[tmp[1], tmp[1]]-Acs[tmp[1],tmp[0]-1]-Acs[tmp[0]-1,tmp[1]]+Acs[tmp[0]-1, tmp[0]-1]))


Measured memory_bytes: 18968
#include<cstdio>

int gcd(int a,int b){ return b?gcd(b,a%b):a; }

int main(){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    long long g = gcd(a,b);
    printf("%lld\n",a*b/g);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<queue>
using namespace std;
const int N=1205;
const int INF=0x3f3f3f3f;
struct Node {
	int x,y,s;
};
char c[N][N];
bool vis[N][N];
int dx[5]= {0,1,-1,2,-2};
int sx[4]= {0,0,-1,1};
int sy[4]= {1,-1,0,0};
int main() {
	int h,w;
	scanf("%d %d",&h,&w);
	int ch,cw,dh,dw;
	scanf("%d %d %d %d",&ch,&cw,&dh,&dw);
	ch--;
	cw--;
	dh--;
	dw--;
	for (int i=0; i<h; i++) scanf("%s",c[i]);
	if (c[ch][cw]=='#' || c[dh][dw]=='#') {
		puts("-1");
		return 0;
	}
	deque<Node> q;
	q.push_front({ch,cw,0});
	int ans=0x3f3f3f3f;
	while(!q.empty()) {
		int x=q.front().x,y=q.front().y,s=q.front().s;
		q.pop_front();
		if (x==dh && y==dw) {
			//cout<<x<<" "<<y<<" "<<s<<endl;
			ans=min(ans,s);
		}
		if (vis[x][y]==1) continue;
		vis[x][y]=1;
		for (int i=0; i<5; i++) {
			int px=0,py=0;
			if (i<4) {
				px=x+sx[i];
				py=y+sy[i];
				if (px>=0 && px<h && py>=0 && py<w && vis[px][py]==0 && c[px][py]!='#') q.push_front({px,py,s});
			}
			for (int j=0; j<5; j++) {
				int tx=x+dx[i],ty=y+dx[j];
				if (abs(dx[i])+abs(dx[j])>1 && tx>=0 && tx<h && ty>=0 && ty<w && vis[tx][ty]==0 && c[tx][ty]!='#') q.push_back({tx,ty,s+1});
			}
		}
	}
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}

Measured memory_bytes: 6340
#include<bits/stdc++.h>
#define endl '\n'
typedef long long int ll;
int flag=0;

using namespace std;
ll arr[300000];

int main()
{
  
  ll n,a,b,c,d;
  string s;
  cin>>n>>a>>b>>c>>d;
  cin>>s;
  for(int i=0;i<s.size();i++){
      if(s[i]=='#') arr[i+1]=1;
  }
//   for(int i=1;i<=n;i++) cout<<arr[i]<<" ";
//   cout<<endl;
    if(c<d){
        for(int i=b;i<d;i++){
            if(arr[i]==1 && arr[i+1]==1){ cout<<"No"<<endl; return 0; }
        }
        for(int i=a;i<c;i++){
            if(arr[i]==1 && arr[i+1]==1){ cout<<"No"<<endl; return 0; }
        }
        cout<<"Yes"<<endl; return 0;
    }
    else{
       for(int i=b;i<d;i++){
            if(arr[i]==1 && arr[i+1]==1){ cout<<"No"<<endl; return 0; }
        }
        int flag=0;
        for(int i=b;i<=d;i++){
            if(arr[i-1]==0 && arr[i]==0 && arr[i+1]==0){
                 flag=1; arr[i]=1; break;
            }
        }
        if(flag==0) arr[d]=1;
        for(int i=a;i<c;i++){
            if(arr[i]==1 && arr[i+1]==1){ cout<<"No"<<endl; return 0; }
        }
        
        cout<<"Yes"<<endl; return 0;
    }
}

Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;int k(int64_t n){int c=0;while(n!=0){n/=10;c++;}return c;}int main(){int64_t n;cin>>n;vector<int> d;for(int64_t i=1;i<=sqrt(n);i++)if(n%i==0)d.push_back(i);cout<<k(n/d.back())<<endl;}

Measured memory_bytes: 3676
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

int su(char c){
    int a=c-'0'-49;
    return a;
}

int main(){
    int N;cin>>N;
    string S;cin>>S;
    set<int> X[30];
    for(int i=0;i<N;i++){
        X[su(S[i])].insert(i);
    }
    for(int k=0;k<26;k++){
        X[k].insert(pow(10,9));
    }
    int Q;cin>>Q;
    for(int q=0;q<Q;q++){
        int t;cin>>t;
        if(t==1){
            int i;cin>>i;i--;
            char c;cin>>c;
            X[su(S[i])].erase(i);
            X[su(c)].insert(i);
            S[i]=c;
        }
        else{
            int l,r,count=0;cin>>l>>r;l--;r--;
            for(int k=0;k<26;k++){
                auto itr=X[k].lower_bound(l);
                if(*itr<=r)count++;
            }
            cout<<count<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
/***********************************
*******AUTHOR SHASHI KANT **********         
****GMAIL Shshiksnt140895@gmail.com*
************************************                                  
***********************************/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
/*class graph
{
	map<int,list<int>>adj;
	public :
	       void addedge(int a, int b)
	       {
	           adj[a].push_back(b);
	           adj[b].push_back(a);
	       }

}*/
int min_cost(vector<int>in, int n, int k)
{
    vector<int>dp(n+1);
    dp[1] = 0;
     int op1;
    for(int i=2; i<=n; i++)
    {
    	int mn = INT_MAX;
    	for(int j=1; j<=k; j++)
    	{
    		if(i-j>0)
    		{
               op1 = abs(in[i] - in[i-j]) + dp[i-j];
               mn = min(mn, op1);
    		}
    	}
    	dp[i] = mn;
    }
    return dp[n];
}
int main(){
       //int t;
      /// cin>>t;
      // while(t--)
      // {
       	int n, k;
       	cin>>n>>k;
      vector<int>in(n+1);
       	for(int i=1; i<=n; i++)
       		cin>>in[i];
       cout<< 	min_cost(in, n, k) << endl;


      // }	
	return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
int main() {
	int N, M;
	cin >> N;

	set<string> name;
	string tmp;
	REP(i, N) {
		cin >> tmp;
		name.insert(tmp);
	}

	int status = 0;
	cin >> M;
	REP(i, M) {
		cin >> tmp;
		if(EXIST(name, tmp)) {
			if(!(status%2)) {
				cout << "Opened by " << tmp << endl;
			} else {
				cout << "Closed by " << tmp << endl;
			}
			status++;
		} else {
			cout << "Unknown " << tmp << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) \
    SORT(a);     \
    reverse(a.begin(), a.end())
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll a, b;

int main()
{
    cin >> a >> b;
    ll ans = 0;
    if (a <= b)
    {
        REP(i, b)
        {
            ans = 10 * ans + a;
        }
    }
    else
    {
        REP(i, a)
        {
            ans = 10 * ans + b;
        }
    }
    OUT(ans);
}


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

using namespace std;

int const dxL[] = {-1,0,1,0};
int const dxR[] = {1,0,-1,0};
int const dy[]  = {0,-1,0,1};
typedef pair<int, int> Pii;
#define X first
#define Y second
int const INF = 1<<28;
int W, H;
char grL[51][51], grR[51][51];
bool used[2500][2500];
inline bool isValid(int x, int y) {
  if(0<=x&&x<W && 0<=y&&y<H) return true;
  return false;
}

inline bool inF(int x, int y, int isL) {
  if(isL) return grL[y][x]!='#';
  return grR[y][x]!='#';
}
inline int toNode(int x, int y) {
  return y*W+x;
}
inline void toPos(int node, int &x, int &y) {
  x = node%W, y = node/W;
}
int main() {
  
  while(cin >> W >> H && (W|H)) {
    int sxL, syL, sxR, syR;
    int gxL, gyL, gxR, gyR;
    for(int i=0; i<H; i++) {
      for(int j=0; j<2*W; j++) {
        if(j<W) {
          cin >> grL[i][j];
          if(grL[i][j] == 'L') {
            sxL = j, syL = i;
          }
          if(grL[i][j] == '%') {
            gxL = j, gyL = i;
          }
        }
        else {
          cin >> grR[i][j-W];
          if(grR[i][j-W] == 'R') {
            sxR = j-W, syR = i;
          }
          if(grR[i][j-W] == '%') {
            gxR = j-W, gyR = i;
          }
        }
      }
    }
    
    queue<Pii> que;
    que.push(make_pair(toNode(sxL, syL), toNode(sxR, syR)));
    bool ok = false;
    memset(used, false, sizeof used);
    while(!que.empty()) {
      const int nowL = que.front().first;
      const int nowR = que.front().second; que.pop();
      int lx, ly; toPos(nowL, lx, ly);
      int rx, ry; toPos(nowR, rx, ry);

      if(lx == gxL && ly == gyL && rx == gxR && ry == gyR) {
        ok = true; break;
      }
      
      if(lx == gxL && ly == gyL) continue;
      if(rx == gxR && ry == gyR) continue;
      
      for(int i=0; i<4; i++) {
        int nxL = lx+dxL[i], nyL = ly+dy[i];
        int nxR = rx+dxR[i], nyR = ry+dy[i];

        if(!isValid(nxL, nyL) || !inF(nxL, nyL, 1)) { nxL = lx, nyL = ly; }
        if(!isValid(nxR, nyR) || !inF(nxR, nyR, 0)) { nxR = rx, nyR = ry; }
        if(used[toNode(nxL, nyL)][toNode(nxR, nyR)]) continue;
        que.push(make_pair(toNode(nxL, nyL), toNode(nxR, nyR)));
        used[toNode(nxL, nyL)][toNode(nxR, nyR)] = true;
      }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 7784
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,a = map(int,readline().split())
lst1 = list(map(int,readline().split()))

import numpy as np

dp = np.zeros((n+1,3000),dtype=np.int64) # 枚数、目標数ごとに場合の数
dp[0,0] = 1

for x in lst1:
  dp[1:,x:] += dp[:-1,:-x].copy()
  
ans = 0
for i in range(1,n+1):
  ans += dp[i,i*a]
  
print(ans)


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

int main(){
int n; cin >> n; int f=0;
string s; cin >> s;
  if(n%2!=0) f++;
if(n%2==0){
rep(i,n/2){
    if(s[i] != s[i+(n/2)]){
      	f=1; break;
    }
}
}
if(f==0) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import bisect


def main():
    N, Q = [int(x) for x in input().split()]
    S = input().strip()

    ac = []
    for i in range(len(S) - 1):
        if S[i] == 'A' and S[i + 1] == 'C':
            ac.append(i)

    for _ in range(Q):
        x, y = [int(x) for x in input().split()]
        l = bisect.bisect_left(ac, x - 1)
        r = bisect.bisect_right(ac, y - 2)
        print(r - l)

    
    




if __name__ == '__main__':
    main()




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

const int MXN=100005;

int N,M,sol[MXN];
int dpdown[MXN][2];
vector<int>adj[MXN];

int add(int x,int y){return(x+=y)<M?x:x-M;}
int sub(int x,int y){return(x-=y)>= 0?x:x+M;}
int mul(int x,int y){return 1LL*x*y%M;}

void dfs1(int x,int p){
  dpdown[x][0]=1;
  dpdown[x][1]=1;
  for(int y:adj[x]){
    if(y==p)continue;
    dfs1(y,x);
    dpdown[x][0]=mul(dpdown[x][0],dpdown[y][0]);
    dpdown[x][1]=mul(dpdown[x][1],add(dpdown[y][0],dpdown[y][1]));
  }
}

void dfs2(int x,int p,int dpup0,int dpup1){
  sol[x]=mul(dpdown[x][1],add(dpup0,dpup1));
  vector<array<int,2>>vals;
  vector<array<int,2>>pref;
  vector<array<int,2>>suff;
  vector<int>vert;
  for(int y:adj[x]){
    if(y==p)continue;
    vert.push_back(y);
    vals.push_back({dpdown[y][0],dpdown[y][1]});
    pref.push_back({1,1});
    suff.push_back({1,1});
  }
  for(int i=1;i<pref.size();++i){
    pref[i][0]=mul(pref[i-1][0],vals[i-1][0]);
    pref[i][1]=mul(pref[i-1][1],add(vals[i-1][0],vals[i-1][1]));
  }
  for(int i=suff.size()-2;i>=0;--i){
    suff[i][0]=mul(suff[i+1][0],vals[i+1][0]);
    suff[i][1]=mul(suff[i+1][1],add(vals[i+1][0],vals[i+1][1]));
  }
  for(int i=0;i<vert.size();++i){
    int dp0=mul(pref[i][0],suff[i][0]);
    int dp1=mul(pref[i][1],suff[i][1]);
    dfs2(vert[i],x,mul(dp0,dpup0),mul(dp1,add(dpup0,dpup1)));
  }
}

int main(){
  scanf("%d%d",&N,&M);
  for(int i=1;i<N;++i){
    int x,y;
    scanf("%d%d",&x,&y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(1,0);
  dfs2(1,0,1,0);
  sol[1]=dpdown[1][1];
  for(int i=1;i<=N;++i){
    printf("%d\n",sol[i]);
  }
}


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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i, s.length()){
    if(s[i]!=t[i])ans++;
  }
  
  cout << ans;
  return 0;
}


Measured memory_bytes: 3920
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 




int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  int a,b;
  cin>>a>>b;
  cout<<a*b;
}




Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
    int n,m;
    cin>>n>>m;
    string s;
    vector<string> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<m;j++){
    //         cout<<arr[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<endl;
    vector<vector<int>> dp(n,vector<int>(m,0));
    bool flag=0;
    for(int i=1;i<m;i++){
        if(arr[0][i]=='.' and flag==0){
            dp[0][i] = 1;
        }
        else{
            flag=1;
            dp[0][i] = 0;
        }
    }
    flag=0;
    for(int i=1;i<n;i++){
        if(arr[i][0]=='.' and flag==0)
            dp[i][0] = 1;
        else{
            flag=1;
            dp[i][0] = 0;
        }
    }
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<m;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<endl;
    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(arr[i][j]=='.')
                dp[i][j] = (dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
            else
                dp[i][j] = 0;
                
        }
    }
    
    cout<<dp[n-1][m-1]<<endl;
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int main(){
    int A,B;
    char x;
    cin >> A >> x >> B;
    
    int ans;
    if (x=='+') ans=A+B;
    else ans=A-B;
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int N = 405;
const int A = 1e9 + 5;

int sl[N];
int64_t dp[N][N];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> sl[i], dp[i][i] = 0;

    auto sum = [&](int L, int R) {
        int64_t s = 0;
        for (int i = L; i <= R; i++) {
            s += sl[i];
        }
        return s;
    };

    for (int len = 2; len <= n; len++) {
        for (int L = 1; L <= n - len + 1; L++) {
            int R = L + len - 1;
            dp[L][R] = INT64_MAX;
            int64_t s = sum(L, R);
            for (int i = L; i < R; i++) {
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
            }
        }
    }

    cout << dp[1][n];

    // for (int i = 1; i <= n; i++) {
    //     for (int j = 1; j <= n; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}



Measured memory_bytes: 4848
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int cal = a - b * 2;
    if(cal < 0) {
      System.out.println(0);
    } else {
      System.out.println(cal);
    }
  }
}


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

using namespace std;

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll ans = a*c;
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    ans = max(ans,b*d);
    cout << ans;

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 924844033 
#define N 100005
#define M 1000003
#define LOG 20
#define KOK 250
#define EPS 0.0000001
using namespace std;

int n,k;
bool vis[305][305][305];
int dp[305][305][305];
char s[305];

int solve(int l,int r,int rem) {

	if(rem<0) return -inf;

	if(l>=r) return (l==r);

	bool& v=vis[l][r][rem];
	int& res=dp[l][r][rem];

	if(v) return res;

	v=1;

	if(s[l]==s[r]) umax(res,solve(l+1,r-1,rem)+2);

	umax(res,max(solve(l+1,r,rem),solve(l,r-1,rem)));

	umax(res,solve(l+1,r-1,rem-1)+2);

	return res;

}

int main() {

	scanf("%s %d",s+1,&k);

	n=strlen(s+1);

	printf("%d",solve(1,n,k));

}

Measured memory_bytes: 137216
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,l;
	cin >> n >> l;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll last=0;
  rep(i,n-1){
    if(a[i]+a[i+1] >= l){
      last = i+1;
      break;
    }
  }
  if(last == 0){
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;
  for(int i=1;i < last;i++){
    cout << i << endl;
  }
  for(int i=n-1;i >= last;i--){
    cout << i << endl;
  }
	return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int x,y;
int main()
{
  scanf("%d%d",&x,&y);
  printf("%d\n",x*y-x-y+1);
  return 0;
}

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

using namespace std;

int main (void) {
    int n;
    string s_tmp;
    cin >> n;
    map<string, int> s;

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

    cout << s.size() << endl;
}


Measured memory_bytes: 19256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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

int n, m;
vector<pair<int, int>> v;

bool check(int x) {
	string s = to_string(x);
	if (s.length() != n) return false;

	for (auto i : v) {
		if ((s[i.ff] - '0') != i.ss) return false;
	}
	return true;
}

int main() {

	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int ss, c; cin >> ss >> c;
		v.push_back({ss - 1, c});
	}

	for (int i = 0; i <= 1000; i++) {
		if (check(i)) {
			cout << i;
			return 0;
		}
	}
	cout << -1;

	return 0;
}

Measured memory_bytes: 3164
/* Author : Harshit Jain a.k.a. iharshit009 */
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define sortrev(x)       sort(all(x), greater<int>())
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
#define ld               long double
#define endl 			 "\n";
#define mp 				 make_pair
#define pii 			 <int, int>
#define lb 				 lower_bound
#define ub				 upper_bound
#define len(a)           int((a).size())
#define prec(n)          fixed<<setprecision(n)
#define cnt(n)           __builtin_popcountll(n)
#define pi               pair<int, int>
const int mod = 1000000007;
using namespace std;
using namespace std::chrono;
// const int N = 1e5 + 5; 
// int n;
// int a[N];
int fact = 1;
// int facts(int n){

// for(int i = 1; i<=n; i++){
// 	fact = (fact*i)%mod;
// }
// return fact%mod;
// }


int powmod(int x,int y){
    int res=1;
    for(int i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}


int32_t main(){
auto start = high_resolution_clock::now(); // starting clock
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >>t;
while(t--){
int n;
cin >> n;


int pap = powmod(10,n) - 2*powmod(9,n) + powmod(8,n);
pap %= mod;
pap = (pap+mod)%mod;
cout << pap;

}
auto stop = high_resolution_clock::now(); // stop clock
auto duration = duration_cast<microseconds>(stop - start);  // printing duration
cerr << "Time taken by function: " << duration.count() << " milliseconds" << endl; 
return 0;
}

Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var a = Reads();
           
            long count4 = 0;
            long count2 = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] % 4 == 0) count4 ++;
                else if (a[i] % 2 == 0) count2++;
            }
            Console.WriteLine(2*count4+1 >=n||2*count4+count2>=n ? "Yes" : "No");
         
            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 20832
n = int(input())
s = input()
ans = 0
for i in range(1000):
    n = "000" + str(i)
    n = n[-3:]
    index = 0
    for j in range(len(s)):
        if s[j] == n[index]:
            index += 1
            if index == 3:
                break
    if index == 3:
        ans += 1
print(ans)

Measured memory_bytes: 41052
#include<bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////////////////////////
void update(vector<int> &tree,int k,int val) {
	++k;
	while(k < tree.size()) {
		tree[k] += val;
		k = (k + (k & (-k)));
	}
}
int prefix(vector<int> &tree,int i) {
	if(i == -1) return 0;
	++i;
	int sum = 0;
	while(i > 0) {
		sum += tree[i];
		i = i ^ (i & (-i));
	}
	return sum;
}

//////////////////////////////////////////////////////////////

int main() {
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i = 0; i < n;i++)
	{
		cin >> v[i];
		v[i]--;
	}

	vector<pair<int,int>> query(k); // query
	vector<vector<int>> bucket(n);
	vector<int> lastindex(n,-1); // right most index
	
	
	for(int i = 0;i<k;i++)
	{
		cin >> query[i].first >> query[i].second;
		query[i].first -= 1;
		query[i].second -= 1;
		bucket[query[i].first].push_back(i);
	}

	vector<int> result(k); // result vector
  	vector<int> tree(n+1); // tree
  	for(int i = n-1;i >=0 ;i--)
  	{
  		int tmp = lastindex[v[i]];
  		lastindex[v[i]] = i;
  		update(tree,i,1);
  		if(tmp != -1) update(tree,tmp,-1);
  		for(int j = 0;j < bucket[i].size();j++)
  		{
  			int index = bucket[i][j];
  			result[index] = prefix(tree,query[index].second) - prefix(tree,query[index].first-1);
  		}
  	}
  	for(int i = 0;i<k;i++) {
  		cout << result[i] << endl;
  	}
	return 0;
}


Measured memory_bytes: 36204