akhauriyash/Code-Regression huggingface dataset:
input = input().split()
inputList = list(input[0])
# a = int(input[0])
# b = int(input[1])
# c = int(input[2])

# inputList.sort()

flg = 1
for i in range(0, len(inputList)-1):
    if inputList[i] == inputList[i + 1]:
        flg = 0
        break

if flg == 0:
    print("Bad")
else:
    print("Good")


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int ans = 0;

int main(){
  int M, D;
  cin >> M >> D;
 for(int i = 2; i <= M; i++){
   for(int j = 2; j <= D; j++){
     int a = j / 10;
     int b = j % 10;
     if(a >= 2 && b >= 2 && a * b == i){
       ans++;
     }
   }
 }
     
     cout << ans << endl;
}

Measured memory_bytes: 256
function main(input) {
  const args = input.split('\n');
  const [N, X] = args[0].split(' ');
  const L = args[1].split(' ');
  const n = Number(N);
  let count = 0;
  const array = [0];
  for (let i = 0; i < n; i++) {
    array.push(count += Number(L[i]));
   }
  for (let i = 0; i < array.length; i++) {
    if (array[i] > X) {
      console.log(i)
      return
    }
  }
  console.log(array.length)
  return; 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define PI acos(-1)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("maxflow.in", "r", stdin),freopen ("maxflow.out", "w", stdout);
#define all(v) ((v).begin()), ((v).end())

using namespace std;

typedef pair<int, int> pii;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> pli;

const int N = 305;

int a[N][N];
int n, m;

int cnt[N], ptr[N];

bool can(int th) {
  //cout << "th " << th << endl;
  memset(ptr, 0, sizeof ptr);
  memset(cnt, 0, sizeof cnt);
  for(int i = 0; i < n; i++) {
    cnt[a[i][0]]++;
  }
  set<pii> st;
  for(int i = 0; i < m; i++) {
    st.insert(mp(cnt[i], i));
  }
  while(true) {
    //cout << "it "  << endl;
    if(st.empty()) {
      return false;
    }
    if(st.rbegin()->fi <= th){
//      for(int i = 0; i < n; i++) {
//        cout << "ptr[i] " << ptr[i] << endl;
//      }
//      for(int i = 0; i < m; i++) {
//        cout << "cnt[i] " << cnt[i] << endl;
//      }
      return true;
    }
    int game = st.rbegin()->se;
    cnt[game] = -1;
    st.erase(--st.end());
    for(int i = 0; i < n; i++) {
      if(a[i][ptr[i]] == game) {
        while(ptr[i] < m && cnt[a[i][ptr[i]]] == -1 ) {
          ptr[i]++;
        }
        if(ptr[i] == m) {
          return 0;
        }
        st.erase(make_pair(cnt[a[i][ptr[i]]], a[i][ptr[i]]));
        cnt[a[i][ptr[i]]]++;
        st.insert(make_pair(cnt[a[i][ptr[i]]], a[i][ptr[i]]));
      }
    }
  }
  assert(0);
  return true;
}

int main() {
//#ifndef ONLINE_JUDGE
//freopen ("in.txt", "r", stdin);
//#endif
  cin >> n >> m;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  int ans = n;
  int L = 1, R = n;
  while(L <= R) {
    int mid = (L + R) / 2;
    if(can(mid)) {
      ans = mid;
      R = mid - 1;
    }else {
      L = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  long long x;
  cin >> x;
  long long ans=(x/11)*2;
  if (0<x%11&&x%11<7){
    ans++;
  }
  else if (x%11>6){
    ans+=2;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
int main()
{
	ll A,B;
	scanf("%lld %lld",&A,&B);
	printf("%lld\n",A*B);
}

Measured memory_bytes: 3760
def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    odd_num = 0
    #print(A)
    while odd_num == 0:
        for Ai in A:
            if Ai%2 != 0:
                odd_num+=1
        if odd_num == 0:
            cnt +=1
            #print(list(A))
            A = list(map(lambda x: x/2,A))
    print(cnt)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define vi vector<ll>
#define pii pair<ll, ll>
#define pb push_back
const ll m=1e9+7;
const ll N=1e5+7;
bool prime[N];
vector<int> p;
void sieve(int n)
{
	fill(prime, prime+n, true);
	for(int i=2;i<n;i++)
	{
		if(prime[i])p.pb(i);
		for(int j=0;j<p.size() and i*p[j]<n;j++)
		{
			prime[i*p[j]]=false;
			if(i%p[j]==0)break;
		}
	}
}
ll modp(ll a, ll b)
{
	if(b==0)return 1;
	ll u=modp(a, b>>1);
	u=(u*u)%m;
	if(b&1)
	return (u*a)%m;
	return u;
}
ll fac[N];
ll invfac[N];
void init_fact(int n)
{
	fac[0]=fac[1]=1;
	for(int i=2;i<=n;i++)
	{
		fac[i]=i*fac[i-1];	
	}
	for(int i=0;i<=n;i++)
	{
		invfac[i]=modp(fac[i],m-2);
	}
	
	
}
long double dis(pii a, pii b)
{
	long double X=(double)(a.x-b.x);
	long double Y=(double)(a.y-b.y);
	
	X=X*X;Y=Y*Y;
	return sqrt(X+Y);
}
int main()
{
	int n;cin>>n;
	pii p[n];
	for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y;
	
	string s="";
	for(int i=0;i<n;i++)
	s+=(i+48);
	long double path=0;
	do
	{
		long double curr=0;
		for(int i=0;i<n-1;i++)
		{
			int u=s[i]-48;
			int v=s[i+1]-48;
			long double cur=dis(p[u],p[v]);
			curr+=cur;
			
			
			
		}
		
		path+=curr;
		
		
	}while(next_permutation(s.begin(),s.end()));
	
	ll factn=1;
	for(int i=2;i<=n;i++)factn=factn*i;
	long double ans=path/factn;
	
	cout<<fixed<<setprecision(10)<<ans;
	
	
	
	
	
	
	
	
	
}

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int w, a, b;
    
    read(w, a, b);
    if (a > b) {
        swap(a, b);
    }
    
    print(max(b - a - w, 0LL));
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
//    read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



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

int main(void)
{
    string str;
    cin >> str;
    bool flag = 0;
    int repair1 = 0, repair2 = 0, N = str.size();

    for (int i = 0; i < N; i++)
    {
        if (flag == 1)
        {
            if (str.at(i) != '1')
            {
                repair1++;
            }
        }
        else
        {
            if (str.at(i) != '0')
            {
                repair1++;
            }
        }
        if (flag)
        {
            flag = 0;
        }
        else
        {
            flag = 1;
        }
    }

    flag = 1;
    for (int i = 0; i < N; i++)
    {
        if (flag == 1)
        {
            if (str.at(i) != '1')
            {
                repair2++;
            }
        }
        else
        {
            if (str.at(i) != '0')
            {
                repair2++;
            }
        }
        if (flag)
        {
            flag = 0;
        }
        else
        {
            flag = 1;
        }
    }

    if (repair1 < repair2)
    {
        cout << repair1 << endl;
    }
    else
    {
        cout << repair2 << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

const int V = 1000;
const int E = 2000;
LL n, m, a[E], b[E], c[E], d[2][V], INF = -1e13;
bool loop[2][V];

int main() {
	cin >> n >> m;
	inc(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}
	
	inc(k, 2) {
	inc(i, n) {
		d[k][i] = INF;
	}
	}
	d[0][0] = 0;
	d[1][n - 1] = 0;
	inc(k, 2) {
		inc(q, 2 * n) {
			inc(i, m) {
				if(d[k][a[i]] == INF) { continue; }
				loop[k][b[i]] |= setmax(d[k][b[i]], d[k][a[i]] + c[i]) && (q >= n);
			}
		}
		inc(i, m) { swap(a[i], b[i]); }
	}
	
	bool inf = false;
	inc(i, n) { inf |= (loop[0][i] && loop[1][i]); }
	
	cout << (inf ? "inf" : to_string(d[0][n - 1])) << endl;
	
	return 0;
}


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

int main() {
  
  int N;
  cin >> N;
  
  int count = 0;
  
  for (int i=0;i<N;i++) {
    int l,r;
    cin >> l >> r;
    count += r-l+1;
  }
  
  cout << count << endl;
    
}

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

raw = input().split()
li = list(map(int, raw))
s = sum(li)
a = round(s / N)
all_tairyoku = 0
for i in li:
    tairyoku = (i - a) ** 2
    all_tairyoku += tairyoku
print(all_tairyoku)

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

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

const int INF = 1e9 + 7;

using namespace std;

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

	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	rep (i, 0, n)
		cin >> a[i];

	int res = INT_MAX;
	auto it = min_element(a.begin(), a.end());
	int id = distance(a.begin(), it);
	for (int i = 0; i < k; i++) {
		int l_id = id - i;
		int r_id = id + (k - i);

		int l_num = l_id;
		int r_num = n - r_id;
		if (l_num < 0 || r_num < 0)
			continue;

		int tmp = ceil((float)l_num / (k - 1)) + ceil((float)r_num / (k - 1)) + 1;
		res = min(res, tmp);
	}

	cout << res << endl;
	return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    int n; cin >> n;vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    if(count(a.begin(), a.end(), 1) == 0) {
        cout << -1 << endl;
        return 0;
    }
    int cur = 1;
    for(int i = 0; i < n; i++) {
        if(a[i] == cur) {
            cur++;
        }
    }
    cout << n - cur + 1 << endl;
}

Measured memory_bytes: 1024
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
dp = [float('inf') for i in range(H+1)]
dp[0] = 0
for i in range(N):
    a,b = AB[i]
    for j in range(H+1):
        if j+a > H:
            dp[H] = min(dp[H],dp[j]+b)
        else:
            dp[j+a] = min(dp[j+a],dp[j]+b)
print(dp[-1])

Measured memory_bytes: 51164
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	int N;
	cin >> N;
	ll sum = 0;
	vector<ll> vec;
	for (int i = 0; i < N; i++) {
		ll A, B;
		cin >> A >> B;
		sum += A;
		vec.push_back(A + B);
	}
	sort(vec.begin(), vec.end());
	for (int i = N - 2; i >= 0; i -= 2) {
		sum -= vec[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 1400
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        String line = readLine();
        StringTokenizer st = new StringTokenizer(line, " ");
        Integer x = Integer.parseInt(st.nextToken());
        Integer a = Integer.parseInt(st.nextToken());
        Integer b = Integer.parseInt(st.nextToken());

        if ( a >= b) {
        	System.out.println("delicious");
        }else if ( (a + x) >= b) {
        	System.out.println("safe");
        }else {
        	System.out.println("dangerous");
        }

    }

    private static String readLine() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        return br.readLine();
    }
}


Measured memory_bytes: 21076
H,W=map(int,input().split())
M=[[0 for i in range(W)] for i in range(H)]
for _ in range(H):
    s=input()
    for i in range(W):
        if s[i]=='#':
            M[_][i]=1
dp=[[10**6 for i in range(W)] for i in range(H)]
if M[0][0]==1:
    dp[0][0]=1
else:
    dp[0][0]=0
for j in range(W-1):
    if M[0][j+1]==0:
        dp[0][j+1]=dp[0][j]
    else:
        if M[0][j]==1:
            dp[0][j+1]=dp[0][j]
        else:
            dp[0][j+1]=dp[0][j]+1
for i in range(H-1):
    if M[i+1][0]==0:
        dp[i+1][0]=dp[i][0]
    else:
        if M[i][0]==1:
            dp[i+1][0]=dp[i][0]
        else:
            dp[i+1][0]=dp[i][0]+1
for i in range(1,H):
    for j in range(0,W-1):
        if M[i][j+1]==0:
            dp[i][j+1]=min(dp[i-1][j+1],dp[i][j])
        elif M[i][j+1]==1:
            if M[i-1][j+1]==1:
                if M[i][j]==1:
                    dp[i][j+1]=min(dp[i-1][j+1],dp[i][j])
                else:
                    dp[i][j+1]=min(dp[i-1][j+1],dp[i][j]+1)
            else:
                if M[i][j]==1:
                    dp[i][j+1]=min(dp[i-1][j+1]+1, dp[i][j])
                else:
                    dp[i][j+1]=min(dp[i-1][j+1]+1,dp[i][j]+1)
print(dp[H-1][W-1])

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

int main() {
    int N; cin >> N;
    if (N == 1) {
        cout << N << endl;
    } else {
        int ans = 2;
        while (N >= ans * 2) ans *= 2;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
bool isPali(int i , int j){
    j--;
    for(;i<=j;i++,j--){
        if(s[i] != s[j]){
            return false;
        }
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    cin >> s;
    int n = s.length();
    if (isPali(0,n) && isPali(0,(n-1)/2) && isPali((n+3)/2-1,n)){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:f64,
    b:f64,
    }
    println!("{}",a/b)
}

Measured memory_bytes: 2208
#include <cstdio>

int main() {
    int n, t1, ans;
    ans = 1001;
    scanf("%d%d", &n, &t1);
    int tmp_min = 1001;
    for (int i = 0; i < n; i++) {
        int c, t;
        scanf("%d%d", &c, &t);
        if (t <= t1) {
            if (c <= tmp_min) {
                ans = c;
                tmp_min = ans;
            };
        }
    }
    if (ans == 1001) {
        printf("TLE\n");
        return 0;
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<int> alp(3);
    rep (i, s.size()) alp[s[i] - 'a']++;
    if (max(alp[0], max(alp[1], alp[2])) - min(alp[0], min(alp[1], alp[2])) <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int A[][] = new int[n][m];
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < m ; j++){
				A[i][j] = scan.nextInt();
			}
		}
		int b[] = new int[m];
		for(int i = 0 ; i < m ; i++){
			b[i] = scan.nextInt();
		}
		int output[] = new int[n];

		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < m ; j++){
				output[i] += A[i][j] * b[j];
			}
		}

		for(int i = 0 ; i < n ; i++){
			System.out.println(output[i]);
		}
	}
}

Measured memory_bytes: 40808
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');

_a(input);

function _a(input: string) {
  const X = parseInt(input);

  if (400 <= X && X <= 599) {
    console.log(8);
  }
  if (600 <= X && X <= 799) {
    console.log(7);
  }
  if (800 <= X && X <= 999) {
    console.log(6);
  }
  if (1000 <= X && X <= 1199) {
    console.log(5);
  }
  if (1200 <= X && X <= 1399) {
    console.log(4);
  }
  if (1400 <= X && X <= 1599) {
    console.log(3);
  }
  if (1600 <= X && X <= 1799) {
    console.log(2);
  }
  if (1800 <= X && X <= 1999) {
    console.log(1);
  }
}


Measured memory_bytes: 29692
#D問題
N,C = map(int,input().split())
D = [list(map(int,input().split())) for i in range(C)]
c = [list(map(int,input().split())) for i in range(N)]
for i in range(N):
    for j in range(N):
        c[i][j]-=1
    

mod3 = [[0 for i in range(C)] for j in range(3)]
for i in range(N):
    for j in range(N):
        mod3[(i+j)%3][c[i][j]]+=1
        
c3 = [[0 for i in range(C)] for j in range(3)]
for i in range(3):
    for j in range(C):
        kari = 0
        for k in range(C):#kからjへ
            kari+=mod3[i][k]*D[k][j]
        c3[i][j] = kari
        
inf = float("inf")
MIN = inf

for i in range(C):
    C1 = c3[0][i]
    for j in range(C):
        if j != i:
            C2 = c3[1][j]
            for k in range(C):
                if k != i and k != j:
                    C3 = c3[2][k]
                    MIN = min(MIN,C1+C2+C3)
                    #print(C1,C2,C3)
                
if MIN != inf:
    print(MIN)
else:
    print(0)   


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

signed main()
{
    int N; cin>>N;
    vint x(N),y(N),h(N);
    REP(i,N) cin>>x[i]>>y[i]>>h[i];

    REP(cx,101) REP(cy,101){
        int H;
        REP(i,N) if(h[i]>0) H=h[i]+abs(x[i]-cx)+abs(y[i]-cy);
        bool ok=true;
        REP(i,N){
            if(h[i]!=max(0LL,H-abs(x[i]-cx)-abs(y[i]-cy))) ok=false;
        }
        if(ok){
            cout<<cx<<' '<<cy<<' '<<H<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import math

inp = list(map(int,input().split()))
N,M = inp
r1 = math.factorial(2)
if N > 1:
    N1 = math.factorial(N)
    Nr1 = math.factorial(N-2)
    a = N1/r1/Nr1
else:
    a = 0

if M > 1:
    M1 = math.factorial(M)
    Mr1 = math.factorial(M-2)
    b =M1/r1/Mr1
else:
    b = 0

kai = a + b
print(int(kai))


Measured memory_bytes: 3064
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

class SegTree
    attr_accessor:node,:n
    def initialize(n,a)
        @n=1
        @n*=2 while @n<n
        @node=array(2*@n,0)
        n.times do|i|
          @node[i+@n]=a[i]
        end
        (@n-1).downto(1) do|i|
            @node[i]=@node[i*2].gcd(@node[i*2+1])
        end
    end
    def get_gcd(l,r)
      l+=@n
      r+=@n
      ret=0
      while l<r
        if l.odd?
            ret=ret.gcd(@node[l])
            l+=1
        end
        if r.odd?
            r-=1
            ret=ret.gcd(@node[r])
        end
        l/=2
        r/=2
      end
      return ret
    end
end
N=gets.to_i
A=get_i
st=SegTree.new(N,A)
ans=0
N.times do|i|
  l_val=0
  r_val=0
  if i==0
    l_val=0
    r_val=st.get_gcd(1,N) 
  elsif i==N-1
    l_val=st.get_gcd(0,N-1)
    r_val=0
  else
    l_val=st.get_gcd(0,i)
    r_val=st.get_gcd(i+1,N)
  end 
  val=l_val.gcd(r_val)
  ans=val if ans<val
end
puts ans


Measured memory_bytes: 11804
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=998244353;//1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
  string s;
  cin>>s;
  vector<vector<ll>> dp(s.size()+2,vector<ll>(2,-E));
  dp[0][0]=1;
  dp[1][1]=1;
  for(int i=0;i<s.size();i++){
    dp[i+2][1]=max(dp[i+2][1],dp[i][0]+1);
    dp[i+1][0]=max(dp[i+1][0],dp[i][1]+1);
    if(i+1<s.size() && s[i]!=s[i+1]){
      dp[i+1][0]=max(dp[i+1][0],dp[i][0]+1);
    }
    if(i+2<s.size() && i-1>=0 && (s[i]!=s[i+2] || s[i-1]!=s[i+1])){
      dp[i+2][1]=max(dp[i+2][1],dp[i][1]+1);
    }
  }
  cout<<max(dp[s.size()-1][0],dp[s.size()-1][1])<<endl;

  return 0;
}


Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
using pii = pair<int, int>;

signed main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0) break;
    
    int rsum = 0, wsum = 0;
    vector<pii> rw(n);
    REP(i, n) {
      int r, w;
      cin >> r >> w;
      rw[i] = {r, w};
      rsum += r;
      wsum += w;
    }
    sort(RALL(rw));
    
    int rmax = rw.front().first;
    if (rmax <= rsum - rmax) {
      int ans = rsum;
      REP(i, n) {
        ans += rw[i].second;
      }
      cout << ans << endl;
    } else {
      int W = rmax - (rsum - rmax);
      vector<vector<bool>> dp(n + 1, vector<bool>(W + 1));
      dp[0][0] = true;
      REP(i, n) {
        REP(j, W + 1) {
          if (dp[i][j]) {
            int nj = j + rw[i].second;
            if (i != 0 && nj <= W) dp[i + 1][nj] = true;
            dp[i + 1][j] = true;
          }
        }
      }
      int tmp = 0;
      for (int i = W; i >= 0; i--) {
        if (dp[n][i]) {
          tmp = i;
          break;
        }
      }
      int add = wsum - tmp;
      cout << rmax * 2 + add << endl;
    }
  }
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N;
    string S;
    cin >> N;
    vector<ll> vec(N);
    REP(i, N)
        cin >> vec.at(i);

        ll ans = 0;
        REP(i, N)
        ans += (vec.at(i)-1);
        cout << ans << endl;
}


Measured memory_bytes: 764
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        int[][] ab = new int[n - 1][2];
        int[][] px = new int[q][2];
        int[] nValue = new int[n];
        Arrays.fill(nValue, 0);
        Map<Integer, List<Integer>> parents = new TreeMap<Integer, List<Integer>>();

        for (int i = 0; i < n - 1; i++) {
            ab[i][0] = scanner.nextInt();
            ab[i][1] = scanner.nextInt();
            if(!parents.containsKey(ab[i][1]-1)) {
                parents.put(ab[i][1]-1, new ArrayList<Integer>());
            }
            parents.get(ab[i][1]-1).add(ab[i][0]-1);
        }
        for (int i = 0; i < q; i++) {
            px[i][0] = scanner.nextInt();
            px[i][1] = scanner.nextInt();
            nValue[px[i][0] - 1] += px[i][1];
        }

        for (int i = 0; i < n; i++) {
            if(parents.containsKey(i)){
                for(int j : parents.get(i))
                    nValue[i] += nValue[j];
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.print(nValue[i] + " ");
        }
    }

}


Measured memory_bytes: 247860
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    int ans = 0;
    int n;
    cin >> n;
    int flg = 0;
    for(int i = 1; i <= n; i++){
        int p;
        cin >> p;
        if(i != p)flg = 0;
        else if(i == p && flg == 1)flg = 0;
        else{
            ans++;
            flg = 1;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int W ,H ,x ,y ,r;
	scanf("%d %d %d %d %d",&W ,&H ,&x ,&y ,&r);
	if(0<=x-r && x+r<=W && 0<=y-r && y+r<=H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	

	return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N, M, C;
int B[21];
int A[21][21];

void _main() {
    cin >> N >> M >> C;
    REP(i, M) cin >> B[i];
    REP(i, N) REP(j, M) {
        cin >> A[i][j];
    }
    int ans = 0;
    REP(i, N) {
        int sum = C;
        REP(j, M) {
            sum += A[i][j] * B[j];
        }
        ans += (sum > 0);
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
def main():
    X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
         1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = int(input())
    print(X[K-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 38512
import sys


def input():
    return sys.stdin.readline()[:-1]


# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))

n, k = map(int, input().split())
ans = 0
for i in range(n):
    temp = i + 1
    pro = 1 / n
    while temp < k:
        pro = pro * 0.5
        temp = temp * 2
    ans += pro
print(ans)

Measured memory_bytes: 3060
N=int(input())
nums=list(map(int,input().split()))
count=0
for n in range(N-2):
    if max(nums[n],nums[n+1],nums[n+2])!=nums[n+1] and min(nums[n],nums[n+1],nums[n+2])!=nums[n+1]:
        count+=1
print(count)


Measured memory_bytes: 3060
// D - DivRem Number

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	ll ans = 0;

	for (ll q=1; q*q<N; q++) {
		ll r = q;
		if ((N - r) % q == 0) {
			ll m = (N - r) / q;
			if (N % m == r) {
				ans += (N - q) / q;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
int main(void)
{
  int N,i,j,tmp,count=0;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  for(i=0;i<N;i++)
  {
    for(j=N-1;j>i;j--)
    {
      if(A[j]<A[j-1])
      {
        tmp=A[j];
        A[j]=A[j-1];
        A[j-1]=tmp;
        count++;
      }
    }
  }
  for(i=0;i<N-1;i++) printf("%d ",A[i]);
  printf("%d",A[N-1]);
  printf("\n%d\n",count);
  return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <utility>

using namespace std;
typedef pair<int, int> P;
int INF = 1 << 20;
int main(){
  int h, w;
  while(1){
    cin >> h >> w;
    P ans = P(INF, INF);
    if(h == 0 && w == 0) break;
    int taikaku = h * h + w * w;
    //cout << "taiakaku = " << taikaku << endl;
    int min = INF;
    for(int i = 1; i <= 150; i++){
      bool flag = false;
      for(int j = i + 1; j <= 151; j++){
        int tmp = i * i + j * j;
        if(tmp == taikaku && i > h){
          //cout << "tmp = " << tmp  << endl;
          ans.first = i;
          ans.second = j;
          flag = true;
          break;
        }
        else if(taikaku < tmp && tmp < min){
          //cout << "min = " << min << endl;
          //cout << "tmp = " << tmp << endl;
          min = tmp;
          ans.first = i;
          ans.second = j;
        }
      }
      if(flag) break;
    }
    cout << ans.first << " " << ans.second << endl;
                         
  }
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
long long a[200000];
int main()
{
	long long n;
	cin>>n;	

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

	long long k = 1,ans=0,mx=0;

	for (long long i = 0; i < n; ++i)
	{

		if(a[i]<=k)
		{
			if(a[i]>mx)
			{
				mx = a[i];
			}
			k = mx + 1;
			continue;
		}

		// printf("Customer #%d --> %d %d\n",i+1,a[i],k );
		if(a[i]%k==0)
		{
			ans += a[i]/k - 1;
			a[i] = 1;
		}
		else
		{
			ans += a[i]/k;
			a[i] = a[i]%k;
		}

		if(a[i]>mx)
		{
			mx = a[i];
		}
		k = mx + 1;
		// printf("Ans : %d\n",ans );
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1152
n, k = map(int, input().split())
num = [0] * k
for i in range(1, n+1):
    num[i % k] += 1
ans = 0
for a in range(k):
    b = (k-a) % k
    c = (k-a) % k
    if ((b+c) % k != 0):
        continue
    ans += num[a] * num[b] * num[c]
print(ans)


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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

const int N = 1e5 + 5;

int A[N];
vector<int> G[N];

bool DFS(int v, int p = 0) {
	if (sz(G[v]) == 1) return true;
	int mx = 0, sum = 0;
	bool flag = true;
	for (int u : G[v]) if (u != p) {
		flag &= DFS(u, v);
		sum += A[u];
		mx = max(mx, A[u]);
	}
	A[v] += A[v] - sum, sum += A[v];
	mx = max(mx, A[v]);
	flag &= (mx + mx <= sum) && (p || !A[v]) && A[v] >= 0;
	return flag;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i + 1];
	for (int i = 1; i < n; i++) {
		int v, u; cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	if (n == 2) die((A[1] == A[2] ? "YES" : "NO"));
	int r = 0;
	for (int i = 0; i < n; i++) if (sz(G[i + 1]) > 1) r = i + 1;
	cout << (DFS(r) ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 13312
#13:19
n = int(input())
s = input()
t = []
for i in range(n):
  t.append(ord(s[i])-97)
q = int(input())
scale = 19
seg = [[0 for _ in range(2**(scale+1))] for _ in range(26)]
for i in range(n):
  tmp = int(i) + 2 ** scale
  x = t[i]
  while tmp != 0:
    seg[x][tmp] += 1
    tmp //= 2
#print(seg)
raw = []
for _ in range(q):
  d,a,b = input().split()
  d = int(d)
  if d == 1:
    a = int(a) - 1
    b = ord(b) - 97
  else:
    a = int(a) - 2
    b = int(b) - 1
  raw.append([d,a,b])
for p in range(q):
  d,a,b = raw[p]
  if d == 1:
    tmp = int(a)
    c = t[tmp]
    tmp += 2**scale
    while tmp:
      seg[c][tmp] -= 1
      tmp >>= 1
    tmp = int(a)
    t[tmp] = b
    tmp += 2**scale
    while tmp:
      seg[b][tmp] += 1
      tmp >>= 1
  else:
    ans = 0
    for d in range(26):
      l = 0
      r = 0
      if a == -1:
        l = 0
      else:
        tmp = a + 2**scale
        l += seg[d][tmp]
        while tmp-1:
          if tmp & 1:
            l += seg[d][tmp-1]
          tmp >>= 1
      tmp = b + 2**scale
      r += seg[d][tmp]
      while tmp-1:
        if tmp & 1:
          r += seg[d][tmp-1]
        tmp >>= 1
      if r > l:
        ans += 1
      #print(d,r,l)
    print(ans)
#print(t)

Measured memory_bytes: 413412
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include <limits.h>
#include <iomanip>
#include <stack>

using namespace std;
using namespace boost::multiprecision;

void solve() {
	long long a, b;
	cin >> a >> b;
	long long c = 1;
	long long ans = 0;
	a--;
	while (c <= b) {
		long long bb = floor((b) / (2 * c))*c + (b%(2*c)>=c? (b% (2 * c)) - c+1:0);
		long long aa = 0;
		if(a >= 0)aa = floor((a) / (2 * c))*c + (a % (2 * c) >= c ? (a % (2 * c)) - c +1: 0);
		ans += ((bb - aa) % 2)*c;
		c *= 2;
	}
	cout << ans << endl;
	return;
}

Measured memory_bytes: 256
N, D = map( int, input().split() )
d = list( map( int, input().split() ) )
Q = int( input() )
q = list( map( lambda x: int( x ) - 1, input().split() ) )

dis = [ 0 for i in range( N + 1 ) ]
dis[ 0 ] = D
for i in range( N ):
  dis[ i + 1 ] = min( dis[ i ], abs( dis[ i ] - d[ i ] ) )

dp = [ 0 for i in range( N + 1 ) ]
dp[ N ] = 1
for i in range( N - 1, -1, -1 ):
  if dp[ i + 1 ] <= d[ i ] // 2:
    dp[ i ] = dp[ i + 1 ]
  else:
    dp[ i ] = dp[ i + 1 ] + d[ i ]

for qi in range( Q ):
  print( [ "NO", "YES" ][ dis[ q[ qi ] ] >= dp[ q[ qi ] + 1 ] ] )


Measured memory_bytes: 80556
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.equals("SUN")){
            System.out.println(7);
        }else if(s.equals("MON")){
            System.out.println(6);
        }else if(s.equals("TUE")){
            System.out.println(5);
        }else if(s.equals("WED")){
            System.out.println(4);
        }else if(s.equals("THU")){
            System.out.println(3);
        }else if(s.equals("FRI")){
            System.out.println(2);
        }else if(s.equals("SAT")){
            System.out.println(1);
        }
        sc.close();
    }
}

Measured memory_bytes: 35744
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<functional>
#include<queue>
#include<math.h>
#define INF 999999

using namespace std;

int main()
{
	int n,m;
	cin >> n >> m;
	
	long long int a[100050];
	a[1] = 1;
	for (int i = 2; i <= max(n, m); i++) {
		a[i] = a[i-1] * i % 1000000007;
	}

	if (abs(n - m) >= 2)cout << 0 << endl;
	else if (n == m) {
		cout << a[n] * a[m] * 2 %1000000007<< endl;
	}
	else cout << a[n] * a[m]% 1000000007 << endl;

	return 0;
}



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




int main() {
  
  int A, B;
  cin>>A>>B;
  
  if (A==B){
    cout<<"Draw"<<endl;
  }
  
  else if (A==1 or (B!=1 and A>B)){
    cout<<"Alice"<<endl;
  }
  
  else {
    cout<<"Bob"<<endl;
  }
  
  
 
}










Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace std;

int a,b;
class ABC148A {
public:
	void solve(std::istream& in, std::ostream& out) {
        in >> a >> b;
        set<int> vals;
        vals.insert(1);
        vals.insert(2);
        vals.insert(3);
        vals.erase(a);
        vals.erase(b);
        out << *vals.begin() << "\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ABC148A solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
a,b,c = 0,0,0
n = int(input())
p,q = map(int,input().split())
for i in list(map(int,input().split())):
    if i <= p:
        a += 1
    elif i >= q + 1:
        c += 1
    else:
        b += 1
print(min(a,b,c))


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

int main() {
    int n; cin >> n;
    int a[n];
    map<int, int> h;
    rep(i, n){
        cin >> a[i];
        h[i-a[i]]++;
    } 
    ll ans = 0;
    rep(i, n){
        ans += h[i+a[i]];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 21312
#include<bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i=0;i<n;++i)
int n,a,b,y[]={1000,100,10,1};
map<char,int> x;
string s,t="mcxi";
main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  x['m']=1000,x['c']=100,x['x']=10,x['i']=1;
  cin>>n;
  R(i,n){
    a=0;
    R(j,2){
      cin>>s;
      R(k,s.size())
        t.find(s[k])!=string::npos?a+=x[s[k]]:a+=(s[k]-'0')*x[s[++k]];
    }
    R(j,4){
      b=1;
      while(a/y[j])a-=y[j],++b;
      --b>1&&cout<<b<<t[j];
      --b||cout<<t[j];
    }cout<<endl;
  }
}

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

int main(){
  int N; cin >> N;
  string S; cin >> S;
  int tmp=0;
  int rightclose=0;
  for(int i=0; i<N; i++){
    if(S[i]=='('){
      tmp++;
    }else{
      if(tmp==0){
        rightclose++;
      }else{
        tmp--;
      }
    }
  }
  tmp=0;
  int leftopen=0;
  for(int i=N-1; i>=0; i--){
    if(S[i]==')'){
      tmp++;
    }else{
      if(tmp==0){
        leftopen++;
      }else{
        tmp--;
      }
    }
  }
  while(rightclose>0){
    cout << '(';
    rightclose--;
  }
  cout << S;
  while(leftopen>0){
    cout << ')';
    leftopen--;
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
char a[10][10];
int h,w,k;
bool check(int s1,int s2)
{
	bool f[10][10]={};
	int i,j,tot=0;
	for(i=0;i<h;i++)
		if((s1>>i)&1)
			for(j=1;j<=w;j++)
				f[i+1][j]=true;
	for(i=0;i<w;i++)
		if((s2>>i)&1)
			for(j=1;j<=h;j++)
				f[j][i+1]=true;
	for(i=1;i<=h;i++)
		for(j=1;j<=w;j++)
			if(!f[i][j]&&a[i][j]=='#')
				tot++;
	return tot==k;
}
signed main()
{
	int i,j,s1,s2,ans=0;
	cin>>h>>w>>k;
	for(i=1;i<=h;i++)
		for(j=1;j<=w;j++)
			cin>>a[i][j];
	for(s1=0;s1<(1<<h);s1++)
		for(s2=0;s2<(1<<w);s2++)
			if(check(s1,s2))
				ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, B, *H = map(int, read().split())
    C = A - B

    ok = 10 ** 9
    ng = 0
    while ok - ng > 1:
        mid = (ok + ng) // 2
        res = 0
        for h in H:
            res += max((h - mid * B + C - 1) // C, 0)
        if res <= mid:
            ok = mid
        else:
            ng = mid

    print(ok)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 83896
#include <bits/stdc++.h>
#include <fstream>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


typedef  long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=3e5+5;
ll mod=998244353;
ll mul (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)ans=mul(ans,b);
    return ans;
}

int ans[N];
int main()
{
    FIO
    memset(ans,-1,sizeof ans);
    int n,q;
     cin>>n>>q;
    vector<pair<int,pair<int,int>>>v;
     set<pair<int,int>>st;
    for(int i=0;i<n;i++)
    {

        int s,e,x;
        cin>>s>>e>>x;
        v.push_back({x,{s,e}});
    }
    sort(v.begin(),v.end());
    for(int i=0;i<q;i++)
    {
        int x;
        cin>>x;
        st.insert({x,i});
    }
    set<pair<int,int>>::iterator it;
    for(int i=0;i<v.size()&&st.size();i++)
    {
        int x=v[i].first;
        int s=v[i].second.first-x;
        int e=v[i].second.second-x;
        while(true)
        {
            it=st.lower_bound({s,0});
            if(it==st.end()||(it->first)>=e)
                break;
            ans[it->second]=x;
            st.erase(it);
        }
    }
    for(int i=0;i<q;i++)
        cout<<ans[i]<<endl;



    return 0;
}


Measured memory_bytes: 16188
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int weight_count;
    vector<int> weights;

    cin >> weight_count;

    for(int i = 0; i < weight_count; i++){
        int w;
        cin >> w;
        weights.push_back(w);
    }

    int least_diff = 10000;

    for(int border = 0; border < weight_count; border++){
        int left_sum = 0;
        for(int i = 0; i < border; i++){
            left_sum += weights[i];
        }
        int right_sum = 0;
        for(int j = border; j < weight_count; j++){
            right_sum += weights[j];
        }

        int diff = abs(left_sum - right_sum);
        if(least_diff > diff){
            least_diff = diff;
        }
    }

    cout << least_diff << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{ 
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;cin>>s;
    int i,count=0;
    int n=s.length();
    for(i=0;i<n/2;i++)
if(s[i]!=s[n-1-i])count++;

cout<<count<<endl;
return 0;
}
     


    

    

Measured memory_bytes: 256
from functools import reduce

n, x = [int(i) for i in input().split(" ")]
xs = [int(i) for i in input().split(" ")]

xs = list(map(lambda k: abs(k - x), xs))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

print(reduce(gcd, xs))

Measured memory_bytes: 14596