akhauriyash/Code-Regression huggingface dataset:
//Created by Aminul on 8/29/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        String a = in.next(), b = in.next();
        int minRes = Integer.MAX_VALUE;
        for (int i = 0; i + b.length() <= a.length(); i++) {
            int tmp = getMismatch(a.substring(i, i + b.length()), b);
            minRes = min(minRes, tmp);
        }
        pw.println(minRes);
        pw.close();
    }

    static int getMismatch(String a, String b) {
        if (a.length() != b.length()) return b.length();
        int cnt = 0;
        for (int i = 0; i < b.length(); i++) {
            if (a.charAt(i) != b.charAt(i)) cnt++;
        }
        return cnt;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 27548
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

int in(){
	int t;
	cin >> t;
	return t;
}

struct sta{
	vi edges;
	vi costs;
	vi times;


};

int main()
{

	while(1){
		int n,m,k;
		cin >> n >> m;
		if(n==0 && m==0)
			break;
		vector<sta>stations(m);

		rep(i,n){
			int a,b,cost,time;
			cin >> a >> b >> cost >> time;
			a--;
			b--;
			stations[a].edges.pb(b);
			stations[a].costs.pb(cost);
			stations[a].times.pb(time);
			stations[b].edges.pb(a);
			stations[b].costs.pb(cost);
			stations[b].times.pb(time);
		}
		cin >> k;
		rep(i,k){
			int s,g,q;
			cin >> s >> g >> q;
			s--;
			g--;
			if(!q){
				queue<int> Q;
				vi cost(m,inf);
				cost[s]=0;
				Q.push(s);
				while(!Q.empty()){
					int f=Q.front();Q.pop();
					sta now=stations[f];
					rp(i,now.edges){
						int to=now.edges[i];
						int cos=now.costs[i];
						if(cost[to] > cost[f]+cos){
							cost[to]=cost[f]+cos;
							Q.push(to);
						}
					}
				}
				cout << cost[g] << endl;
			}else{
				queue<int> Q;
				vi time(m,inf);
				time[s]=0;
				Q.push(s);
				while(!Q.empty()){
					int f=Q.front();Q.pop();
					sta now=stations[f];
					rp(i,now.edges){
						int to=now.edges[i];
						int ti=now.times[i];
						if(time[to] > time[f]+ti){
							time[to]=time[f]+ti;
							Q.push(to);
						}
					}
				}
				cout << time[g] << endl;
			}
		}
	}
}

Measured memory_bytes: 1352
#include<bits/stdc++.h>
using namespace std;
long long int n,m,p,q,arr[200009],i,j,k,l;
int main()
{
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
        scanf("%lld",&arr[i]);
    l=1;
    for(j=1;j<=n;j++){
            if(arr[j]==l)
                l++;
        }
    if(l>1)
    printf("%lld\n",n-l+1);
    else
        printf("-1");
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#define uLL unsigned long long
using namespace std;
uLL x,a[10];
int main()
{
	//freopen("triple.in","r",stdin);
	//freopen("triple.out","w",stdout);
		uLL ans=0;
		cin>>x;
		a[1]=1;a[2]=2;a[3]=3;
		for(int i=1;i<=x;i++)
		{
			ans=a[1]+a[2]+a[3];
			a[2]=ans;a[3]=ans+1;
		}
		cout<<ans<<endl;
	return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  string s, t; cin >> s >> t;
  for (ll i = 0; i < N; i++) {
    if (s.substr(i, N - i) == t.substr(0, N - i)) {
      cout << i + N << endl;
      return 0;
    }
  }
  cout << 2 * N << endl;

  return 0;
}



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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if ( n*a-b > 0 )
    {
        cout << b << endl;
    }
    else
    {
        cout << n*a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, x, d, a, p;
  p = 0;
  d = 0;
  a = 1;
  in2(n, x);
  vector<ll> l(n);
  rep(i, n)
    in(l[i]);
  while(d + l[p] <= x){
    d = d + l[p];
    p++;
    a++;
    if(a == n + 1)
      break;
  }
  out(a);
  memi;
}

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

int main() {
  int n;cin>>n;
  string t="MARCH";
  vector<ll> vec(5);
  rep(i,n){
    string s;cin>>s;
    rep(j,5){
      if(s[0]==t[j])vec[j]++;
    }
  }
  ll ans=0;
  rep(i,3)for(int j=i+1;j<4;j++)for(int k=j+1;k<5;k++){
    ans+=vec[i]*vec[j]*vec[k];
  }
  cout<<ans<<endl;
}

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

int main(){
    long long N, A, B, i, j, s, w;
    cin >> N >> A >> B;

    w = A + B;

    i = N / w;
    j = N % w;

    if(j >= A) j = A;

    s = i * A + j;
    cout << s << endl;

}

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

int main() {
	int	N;
	cin >> N;
	vector<int> vec(N);
	rep(i, N)
		vec.at(i) = i + 1;
	do
	{
		rep(i, N)
		{
			if (i)
				cout << ' ';
			cout << vec.at(i);
		}
		cout << endl;
	}
	while (next_permutation(vec.begin(), vec.end()));
}



Measured memory_bytes: 3088
import collections
x, n= map(int, input().split())
P = list(map(int, input().split()))
 
PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0

for i in range(100):
  if CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Measured memory_bytes: 9352
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        d: u32,
        n: u32,
    }
    let mut time = 0;
    let mut i = 1;
    loop {
        if i % 100 != 0 || i < 100 {
            time+=1;
            if time == n {
                println!("{}", 100_u32.pow(d) * i);
                return;
            }
        }
        i+=1;
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    int n,m;
    cin >>n >>m;


    if(n%2 == 1){
		rep(i,m){
			cout << i+1 << " " << n-i << "\n";
		}
	}
	else{
		rep(h,n/4){
			if(h == m){
				break;
			}
			cout << h+1 << " " << n-h << "\n";
		}
		for(int j = n/4; j < m; ++j){
			cout << j+1 << " " << n-j-1 << "\n";
		}  
	}
   
}

Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <vector>
#include <set>
using namespace std;
const int maxn = 2e6+10;
typedef pair<int,int> pii;
typedef long long ll;

string s;int K;
ll sum = 0;
ll C[1000][1000];
void initC(int N){
    C[1][1] = 1;
    for(int i = 0;i<=N;i++) C[i][0] = 1;
    for(int i = 1;i<=N;i++){
        for(int j = 1;j<=i;j++){
            C[i][j] = C[i-1][j]+C[i-1][j-1];
        }
    }
}
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b&1) res *= a;
        a*=a;
        b>>=1;
    }
    return res;
}

void judge(){
    ll cnt = 0,n = 0;
    for(int i = 1;i<=s.length()-1;i++) n = n*10+s[i]-'0';
    for(int i = 1;i<=n;i++){
        int t = i,coun = 0;
        while(t){
            if(t%10 != 0) coun++;
            t/=10;
        }
        if(K == coun) cnt++;

    }
    cout<<"judge "<<cnt<<endl;
}
int main(){
    initC(110);
    cin>>s>>K;
    s.insert(s.begin(),'0');
    int len = s.length()-1;
    if(K>len){
        puts("0"); return 0;
    }
    if(len>K) sum += C[len-1][K]*ksm(9,K);
    if(K == 3){
        sum += (s[1]-'1')*C[len-1][2]*ksm(9,2);
        for(int i = 2;i<=len;i++){
            if(s[i] == '0') continue;
            sum += (s[i] - '1') * C[len-i][1] * ksm(9, 1);
            for (int j = i + 1; j <=len; j++) {
                 if(s[j] == '0') continue;
                 sum += s[j] - '0';
                 sum += C[len-j][1]*9;
                 break;
            }
            if(len-i>=2) sum += C[len-i][2] * ksm(9,2);
            break;
        }
    }
    else if(K == 2){
        sum += (s[1]-'1')*C[len-1][1]*ksm(9,1);
        for(int j = 2;j<=len;j++){
            if(s[j] == '0') continue;
            sum += s[j]-'0';
            if(len-j>=1) sum += C[len-j][1]*9;
            break;
        }
    }else{
        sum += s[1]-'0';
    }
//    judge();
    cout<<sum<<endl;



    return 0;
}

Measured memory_bytes: 1016
N = int(input())
X = list(map(int, (input().split())))

distance = lambda Xi, P: (Xi - P) ** 2

X_min = min(X)
X_max = max(X)

answer = None
for P in range(X_min, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer) if answer is not None else total

print(answer)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

N, D = map(int, input().split())
cover_region = 2 * D + 1
ans = N // cover_region
if N % cover_region > 0:
    ans += 1
print(ans)





# def main():

# if __name__ == '__main__':
#     main()


Measured memory_bytes: 3572
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
//素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2;i * i <= n;i++){
        if(n % i == 0) return false;
    }
    return n != 1; //1の場合は除外
}
int main(void){
    int x;cin >> x;
    while(true){
        if(is_prime(x)){
            cout << x << endl;return 0;
        }else{
            x++;
        }
    }
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: i32 = read();
    if n >= 1000 {
        println!("ABD");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	set<char> cset;
	cset.insert('A');
	cset.insert('C');
	cset.insert('G');
	cset.insert('T');

	string S;

	cin >> S;
	int ans = 0;
	int res = 0;
	rep(i, 0, SZ(S))
	{
		if (cset.count(S[i]) > 0)
		{
			res++;
		}
		if (cset.count(S[i]) == 0 || i == SZ(S) - 1)
		{
			chmax(ans, res);
			res = 0;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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

int dp[105][2][5] = {};
signed main(void) {
    string s;
    cin >> s;
    int n = s.size();
    int k;
    cin >> k;
    dp[0][0][0] = 1;
    //k: 0でない数の個数
    rep(i,n)rep(j,2)rep(k,5){
        int lim = 9;
        if(j == 0)lim = s[i] - '0';
        rep(d,lim+1){
            if(j == 1 || d < lim){
                if(k < 4 && d){//k++
                    dp[i+1][1][k+1] += dp[i][j][k];
                }else{
                    dp[i+1][1][k] += dp[i][j][k];
                }
            }else{
                if(k < 4 && d){//k++
                    dp[i+1][0][k+1] += dp[i][j][k];
                }else{
                    dp[i+1][0][k] += dp[i][j][k];
                }
            }
        }
    }
    int ans = 0;
    ans += dp[n][0][k] + dp[n][1][k];
    cout << ans << endl;
}


Measured memory_bytes: 256
M, D   = map(int, input().split())
ans=0
for i in range(M):
    m=i+1
    for j in range(D):
        d=j+1
        d1=d%10
        d10=d//10
        if d1>=2 and d10>=2 and m==d10*d1:
            ans+=1
#             print(m,d)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int judge(vector<int> v, string P, string Q, int N){
    int count = 1;
    int a, b;
    do{
        string num;
        for (int i = 0; i < N; i++){
            num += to_string(v[i]);
        }
        if(num == P){
            a = count;
        }
        if(num == Q){
            b = count;
        }
        count++;
    } while (next_permutation(v.begin(), v.end()));
    return abs(a - b);
}

int main(){
    int N;
    cin >> N;
    string P, Q, s;
    vector<int> v(N);
    iota(v.begin(), v.end(), 1);
    for (int i = 0; i < N; i++){
        cin >> s;
        P += s;
    }
    for (int i = 0; i < N; i++) {
        cin >> s;
        Q += s;
    }
    cout << judge(v, P, Q, N) << endl;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


int main() {
    string s;
    cin >> s;

    int ans = 0;
    rep(i, s.size()) {
        ans -= (s[i] - ',');
    }
    cout << ans << endl;

}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int cur=1;
    for(int n=1; n<=N; n++) {
        if(cur<K) {
            cur += cur;
        } else {
            cur += K;
        }
    }
    cout << cur << endl;


    return 0;
    
}

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

int main(void){

    int i;
    char S[4];
    scanf("%s",S);

    if(S[1] != S[0]){
        if(S[2]!=S[0] && S[2]!=S[1]){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }


}

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

const int INF = 1001001001;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int x = 0, max_x = 0;
  rep(i, n) {
    if (s[i] == 'I')
      x++;
    else
      x--;
    max_x = max(max_x, x);
  }
  cout << max_x << endl;
  return 0;
}


Measured memory_bytes: 3564
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	L := readInt()
	R := readInt()
	res := 2019

	if R-L >= 2019 {
		res = 0
	} else {
		for i := L; i < R; i++ {
			for j := i + 1; j < R+1; j++ {
				calc := (i * j) % 2019
				res = min(res, calc)
			}
		}
	}
	fmt.Println(res)
}

/*-----------------------------------------*/

func checkError(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func read() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	res, err := strconv.Atoi(read())
	checkError(err)
	return res
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a int, b int) int {
	return -min(-a, -b)
}

func pow(a int, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func sqrt(a int) float64 {
	return math.Sqrt(float64(a))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
int main()
{
	SPEED
	int n, k, q, temp;
	cin >> n >> k >> q;
	int arr[n+1];
	int brr[n+2];
	for (int i = 1; i <= n; ++i)
	{
		arr[i] = k;
	}
	for (int i = 0; i <= n+1; ++i)
	{
		brr[i] = 0;
	}
	while(q--)
	{
		cin >> temp;
		brr[temp] += 1;
		brr[1] -= 1;
		brr[temp+1] -= 1;

	}
	for (int i = 2; i <= n; ++i)
	{
		brr[i] += brr[i-1];
	}
	for (int i = 1; i <= n; ++i)
	{
		arr[i] = arr[i]+brr[i];
	}
	/*for (int i = 1; i <= n; ++i)
	{
		cout << arr[i] << " ";
	}
	cout << '\n';*/
	for (int i = 1; i <= n; ++i)
	{
		if (arr[i]<=0)
		{
			cout << "No\n";
		}
		else
		{
			cout << "Yes\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1408
//! Framework <https://github.com/vain0x/procon>

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

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn main() {
    let mut scan = Scan::new();

    let X = scan.word::<usize>();
    let Y = scan.word::<usize>();
    let ok = (0..=X).any(|x| x * 2 + (X - x) * 4 == Y);

    println!("{}", if ok  {"Yes"}else{"No"});
}


Measured memory_bytes: 2140
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    h,w=MI()
    ss=[[c=="#" for c in SI()] for _ in range(h)]
    dist=[[-1]*w for _ in range(h)]
    q=deque()
    q.append((0,0))
    dist[0][0]=1
    while q:
        i,j=q.popleft()
        d=dist[i][j]
        for di,dj in dij:
            ni,nj=i+di,j+dj
            if (ni,nj)==(h-1,w-1):
                ans = h * w - (d + 1) - sum(sum(row) for row in ss)
                print(ans)
                exit()
            if ni<0 or nj<0 or ni>=h or nj>=w:continue
            if dist[ni][nj]!=-1:continue
            if ss[ni][nj]:continue
            dist[ni][nj]=d+1
            q.append((ni,nj))
    print(-1)

main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 ll n,W;
 cin>>n>>W;
 vector<ll> w(n),v(n);
 for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
 vector<vector<ll>> dp(n,vector<ll>(W+1));
 for(ll i=w[n-1];i<=W;i++) dp[n-1][i]=v[n-1];
 for(ll i=n-2;i>=0;i--){
  for(ll j=w[i];j<=W;j++){
   dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
  }
  for(ll j=0;j<w[i];j++) dp[i][j]=dp[i+1][j];
 }
 cout<<dp[0][W]<<endl;
 return 0;
}

Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
const int N=101010;
int n, q, l, x[N];
int f[N][20];
void init(){
	for(int i=0, j=0; i<n; i++){
		while(j+1<n&&x[j+1]<=x[i]+l)j++;
		f[i][0]=j;
	}
	rep(i, 1, 20)rep(j, 0, n)
		f[j][i]=f[f[j][i-1]][i-1];
}
int qry(int l, int r){
	if(l>r)swap(l, r);
	int res=1;
	for(int i=19; ~i; i--){
	//	dd(l), dd(i), de(f[l][i]);
		if(f[l][i]<r){
			l=f[l][i];
			res+=1<<i;
	//		de(res);
		}
	}
	return res;
}
int main(){
	scanf("%d", &n);
	rep(i, 0, n)scanf("%d", x+i);
	scanf("%d%d", &l, &q);
	init();
	rep(qq, 0, q){
		int l, r;
		scanf("%d%d", &l, &r);
		l--, r--;
		printf("%d\n", qry(l, r));
	}
	return 0;
}
/*
9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5
*/

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	REP(i, M) cin >> A[i];
	ll sum = accumulate(ALL(A), 0ll);
	if (N < sum) puts("-1");
	else {
		cout << N - sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

int main() {
	int n,x;
	cin >> n >> x;
	if (x == n) {
		cout << "Yes" << endl;
		REP(i,1,2*n) cout << i << endl;
	} else if (x > 1 && x < 2 * n - 1) {
		cout << "Yes" << endl;
		if (x < n) {
			REP(i,1,n+1) {
				if (i != n && i != x - 1 && i != x) cout << i << endl;
			}
			cout << n << endl;
			cout << x-1 << endl;
			cout << x << endl;
			REP(i,n+1,2*n) cout << i << endl;
		} else {
			REP(i,1,n) cout << i << endl;
			cout << x << endl;
			cout << x+1 << endl;
			cout << n << endl;
			REP(i,n+1,2*n) if (i != n && i != x + 1 && i != x) cout << i << endl;
		}
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;

import static java.lang.System.*;

class Main {
	public static Random rand=new Random();

	public void run() {
		Case:while(true){
			int n=sc.nextInt();
			if(n==0)return;

			boolean[][] link=new boolean[n][n];
			for(int i=0;i<n;i++)
				link[i][i]=true;

			HashSet<?>[] days=new HashSet<?>[n];
			for(int i=0;i<n;i++){
				int k=sc.nextInt();
				HashSet<Integer> hash=new HashSet<Integer>();
				for(int j=0;j<k;j++)
					hash.add(sc.nextInt());
				days[i]=hash;
			}
			for(int d=1;d<=30;d++){
				List<Integer> frees=new ArrayList<Integer>();
				for(int i=0;i<n;i++)if(days[i].contains(d))frees.add(i);

				for(int i:frees)for(int j:frees)for(int k=0;k<n;k++)
					if(link[j][k])link[i][k]=true;

				for(int i=0;i<n;i++){
					boolean nolink=false;
					for(int j=0;j<n;j++)if(!link[i][j])nolink=true;

					if(!nolink){
						ln(d);continue Case;
					}
				}
			}
			ln(-1);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
	// from this
//		static BufferedReader in;
//		static PrintWriter out;
//		static {
//	    	try {
//				in =new BufferedReader(new FileReader("file.in")); Project/file.in
//				out=new PrintWriter(new BufferedWriter(new FileWriter("file.out")));
//	    	} catch (IOException e) {
//				e.printStackTrace();
//			}
	//  }
	// end

	static Scanner sc=new Scanner(in);


	//output lib
	static final String br=System.getProperty("line.separator");
	static final String[] asep=new String[]{""," ",br,br+br};
	static String str(boolean o){
		return o?"YES":"NO";
	}
	static <K,V> String str(Map<K, V> map){
		StringBuilder sb=new StringBuilder();
		boolean isFirst=true;
		for(Entry<K,V> set:map.entrySet()){
			if(!isFirst)sb.append(br);
			sb.append(str(set.getKey())).append(":").append(str(set.getValue()));
			isFirst=false;
		}
		return sb.toString();
	}
	static <E> String str(Collection<E> list){
		StringBuilder sb=new StringBuilder();
		boolean isFirst=true;
		for(E e:list){
			if(!isFirst)sb.append(" ");
			sb.append(str(e));
			isFirst=false;
		}
		return sb.toString();
	}
	static String str(Object o){
		int depth=_getArrayDepth(o);
		if(depth>0)return _strArray(o,depth);
		return o.toString();
	}
	static int _getArrayDepth(Object o){
		if(!o.getClass().isArray() || Array.getLength(o)==0) return 0;
		return 	1+_getArrayDepth(Array.get(o,0));
	}
	//depth ex A[10]…1 A[10][10]…2 exception A[0]…0 A[10][0]…1 A[0][0]…0
	static String _strArray(Object o,int depth){
		if(depth==0) return str(o);
		StringBuilder sb=new StringBuilder();
		for(int i=0,len=Array.getLength(o);i<len;i++){
			if(i!=0)sb.append(asep[depth]);
			sb.append(_strArray(Array.get(o,i),depth-1));
		}
		return sb.toString();
	}
	static void pr(Object... os){
		boolean isFirst=true;
		for(Object o:os){
			if(!isFirst)out.print(" ");
			out.print(o);
			isFirst=false;
		}
	}
	static void ln(){
		out.println();
	}
	static void ln(Object... os){
		for(Object o:os){
			pr(o);ln();
		}
	}
}

Measured memory_bytes: 74212
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <cfenv>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define A_TAX 0.08
#define B_TAX 0.10

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  int a, b;
  cin >> a >> b;
  
  for (int n = 1; n <= 10000; n++)
  {
      /* code */
      int t_inc_a = n * 8 / 100;
      int t_inc_b = n * 10 / 100;
      if (t_inc_a == a && t_inc_b == b) 
      {
          cout << n << endl;
          return 0;
      }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
import math
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
sc = [SL() for i in range(M)]

if N == 1:
  s = 0
  g = 9
elif N ==2:
  s = 10
  g = 99
else:
  s = 100
  g = 999

for i in range(s,g+1):
  n = str(i)
  for s,c in sc:
    s = int(s)
    if n[s-1] == c:
      continue
    else:
      break
  else:
    print(n)
    exit()
print(-1)

Measured memory_bytes: 38484
#include <stdio.h>

int T[255];

int main()
{
    int i, j, N;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%d", &T[i]);
    }
 
    for (i = 0; i < N; i++) {
        printf("node %d: key = %d, ", i+1, T[i]);
        if ((i-1)/2 >= 0.0 && i != 0) {
            printf("parent key = %d, ", T[(i-1)/2]);
        }
        if ((i+1)*2-1 < N) {
            printf("left key = %d, ", T[(i+1)*2-1]);
        }
        if ((i+1)*2 < N) {
            printf("right key = %d, ", T[(i+1)*2]);
        }
        puts("");
    }
    
    return 0;
}

Measured memory_bytes: 608
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a, Comparator.reverseOrder());

		int Alice = 0;
		int Bob = 0;
		int turn = 1;
		for (int i = 0; i < a.length; i++) {
			if (turn > 0) {
				Alice += a[i];
			} else {
				Bob += a[i];
			}
			turn *= -1;
		}

		System.out.println(Alice - Bob);

		sc.close();
	}
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MOD 1e9+7

int main(){
  ll i, j;
  ll n, q;
  cin >> n >> q;
  string str;
  cin >> str;
  vector<ll> l(n), r(n);
  for(i = 0; i < q; i++)
    cin >> l[i] >> r[i];
  ll result = 0;
  vector<ll> count(n);
  ll buf = 0;
  for(i = 0; i < n - 1; i++){
    if(str[i] == 'A' && str[i + 1] == 'C'){
      count[i] = buf;
      buf += 1;
    }
    else
      count[i] = buf;
  }
  count[n - 1] = buf;
  //for(i = 0; i < n; i++)
    //cout << count[i] << " ";
  for(i = 0; i < q; i++) {
    cout << count[r[i] - 1] - count[l[i] - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 3456
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

s = input()

print("ABC"+s)




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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



const int MOD = 1E9 + 7;
void _main() {
        string s; cin >> s;
        int d; cin >> d;
        int n = s.size();
        vector<vector<int>> dp(d, vector<int>(2));
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
                vector<vector<int>> new_dp(d, vector<int>(2));
                for (int rem = 0; rem < d; rem++) {
                        for (int dig = 0; dig < 10; dig++) {
                                for (bool was: {0, 1}) {
                                        if (!was && dig > s[i] - '0') continue;
                                        (new_dp[(rem + dig) % d][!(!was && dig == s[i] - '0')] += dp[rem][was]) %= MOD;
                                }
                        }
                }
                dp = new_dp;
        }

        dp[0][0] += dp[0][1];
        dp[0][0] -= 1 - MOD;
        dp[0][0] %= MOD;
        cout << dp[0][0];
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;

  int ans = t.size();
  for (int i = 0; i <= s.size() - t.size(); i++) {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[j + i] != t[j]) {
        cnt++;
      }
    }
    ans = min(cnt, ans);
  }

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


Measured memory_bytes: 3608
#include <stdio.h>

int main(void) {
	int count[4][3][10] = {0};
	int N, i, j, k;

	fscanf(stdin, "%d", &N);
	for (i = 0; i < N; i++) {
		int b, f, r, v;
		fscanf(stdin, "%d %d %d %d", &b, &f, &r, &v);
		count[b - 1][f - 1][r - 1] += v;
	}
	for (i = 0; i < 4; i++) {
		if (i > 0) printf("####################\n");
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				printf(" %d", count[i][j][k]);
			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2060
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
from collections import defaultdict

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

n,ww = inm()
w = []
v = []
for i in range(n):
    www,vvv = inm()
    w.append(www)
    v.append(vvv)
h = [ defaultdict(int) for i in range(n+1) ]
for i in range(n):
    h[i][0] = 0
for i in range(n):
    for u in h[i]:
        h[i+1][u] = max(h[i+1][u], h[i][u])
        if u+w[i] <= ww:
            h[i+1][u+w[i]] = max(h[i+1][u+w[i]], h[i][u]+v[i])
print(max(list(h[n].values())))


Measured memory_bytes: 53744
#include <stdio.h>

int main(void) {
  int i, j, N;
  long long A[100010], B[100010], C[100010]={0}, D;
  scanf("%d", &N);
  for (i=0;i<N;i++) scanf("%lld%lld", &A[i], &B[i]);
  for (i=N-1;i>=0;i--) {
    if (A[i]%B[i]) C[i] = B[i] - (A[i]%B[i]);
    else C[i] = C[i+1];
    if (C[i] < C[i+1]) {
        if ((C[i]%B[i]) - (C[i+1]%B[i]) >= 0) 
        C[i] = C[i+1] + (C[i]%B[i]) - (C[i+1]%B[i]);
        else C[i] = C[i+1] + (C[i]%B[i]) - (C[i+1]%B[i]) + B[i];
    }
  }
  printf("%lld\n", C[0]);
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

int n;
vl pre;
vl dp;

void f(int i, const vi& p, ll s, int mask, int g){
    if (i == (int)p.size()){
        dp[mask] = max(dp[mask], s + pre[g]);
        return;
    }

    f(i + 1, p, s, mask, g);
    f(i + 1, p, s, (mask ^ (1 << p[i])), g ^ (1 << p[i]));
}

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    cin >> n;

    int z = (1 << n);
    vector<vi> a(n, vi(n, 0));
    for (auto& i : a)
        for (auto& j : i)
            cin >> j;

    pre.resize(z, 0);
    ll nn = INT64_MIN + 1000000;
    dp.resize(z, nn);
    for (int i = 0; i < (1 << n); ++i){
        for (int j = 0; j < n ; ++j){
            if (!(i & (1 << j))) continue;

            for (int k = j + 1; k < n; ++k){
                if (!(i & (1 << k))) continue;

                pre[i] += a[k][j];
            }
        }
    }

    dp[0] = 0;
    for (int i = 0; i < z; ++i){
        vi p;

        for (int j = 0; j < n; ++j){
            if (!(i & (1 << j)))
                p.push_back(j);
        }

        f(0, p, dp[i], i, 0);
    }

    cout << dp[z - 1] << '\n';
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;

int A, P;
int main(int argc, char **argv) {
    cin >> A >> P;

    P += 3 * A;
    cout << (P / 2) << endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

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

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

	string S, T;
	cin >> S >> T;

	int ans = 0;
	rep (i, 3) {
		if (S[i] == T[i]) {
			++ans;
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100001], sec[100001];
long long int iremono2[100001], check[100001],xpo[10000001],ypo[10000001],hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
vector<pair<long long int, long long int>>pairs;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char re;
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

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

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
bool qw = false, er = false, ty = false,ui=false;
int main() {
	cin >> a;
	b = a / 100;
	c = a % 100;

	if (0 < b&&b<= 12) {
		if (0 < c&&c <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
    }
	else if (0 < c&&c <= 12) {
			cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}
}


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

using namespace std;
using ll=long long;

#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U> void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U> void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V> void Printarray3(T f,U a,V b){ rep(i,a){ rep(j,b){ cout<<f[i][j]; } cout<<endl; } }
template<typename T,typename U> void Printarray4(T f,U n){ rep(i,n){ rep(j,n){ cout<<f[i][j]; } cout<<endl; } }
void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  //cout<<hoge(n)<<" "<<hoge(m)<<endl;
  //cout<<hoge(n)/(2*hoge(n-2))<<" "<<hoge(m)/2*hoge(m-2)<<endl;
  //cout<<hoge(n)/(2*hoge(n-2))<<" "<<hoge(m)/(2*hoge(m-2))<<endl;
  cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}


Measured memory_bytes: 256
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(D)]
# 大問D問中のn問といてG点以上をとる最低の問題数n

ans = int(1e10)
for i in range(2 ** D):
    zen = []
    atemp = 0
    ktemp = 0
    for j in range(D):
        if (i >> j) & 1:
            zen.append(True)
        else:
            zen.append(False)
    for n, tf in enumerate(zen):
        if tf:
            atemp += pc[n][0] * (n+1) * 100 + pc[n][1]
            ktemp += pc[n][0]
        else:
            hanpa = n
    if atemp >= G:
        ans = min(ans, ktemp)
    else:
        if atemp + pc[hanpa][0]*(hanpa+1)*100 < G:
            continue
        else:
            if (G - atemp) % ((hanpa+1)*100) == 0:
                ans = min(ans, ktemp + ((G - atemp) // ((hanpa+1)*100)))
            else:
                ans = min(ans, ktemp + ((G - atemp) // ((hanpa+1)*100)) + 1)

print(ans)

Measured memory_bytes: 3064
from operator import add


class SegTree():
    def __init__(self, N, e, operator_func=add):
        self.e = e # 単位元
        self.size = N
        self.node = [self.e] * (2*N)
        self.operator_func = operator_func # 処理(add or xor max minなど)

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size-1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size
        r += self.size

        while l<r:
            if l%2:
                x = self.operator_func(x, self.node[l-1])
                l += 1
            if r%2:
                r -= 1
                x = self.operator_func(x, self.node[r-1])
            l //= 2
            r //= 2
        return x

if __name__ == "__main__":
    n, q = map(int, input().split())
    inf = 2**31-1
    tree = SegTree(n, inf, min)

    for _ in range(q):
        com, x, y = map(int, input().split())
        if com:
            print(tree.get(x, y+1))
        else:
            tree.update(x, y)


Measured memory_bytes: 8480
import numpy as np
import itertools
from sys import stdin
lines = stdin.readlines()
 
N = int(lines[0])
P = list(map(str, lines[1].split()))
Q = list(map(str, lines[2].split()))

permu = []
for a in range(N):
  permu.append(str(a + 1))

#print(permu)

cnt_a = 1
for p in itertools.permutations(permu):
  cnt_a += 1
  p_act = np.array(p)
  p_test = np.array(P)
  if (p_test == p_act).all() == True:
    a = cnt_a

cnt_b = 1
for q in itertools.permutations(permu):
  cnt_b += 1
  q_act = np.array(q)
  q_test = np.array(Q)
  if (q_test == q_act).all() == True:
    b = cnt_b

print(abs(a - b))

Measured memory_bytes: 14412