akhauriyash/Code-Regression huggingface dataset:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    seen = [[False] * W for _ in range(H)]
    black = [0]
    white = [0]

    def dfs(x, y):
        seen[x][y] = True
        if S[x][y] == "#":
            black[-1] += 1
        else:
            white[-1] += 1
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if not (0 <= nx < H and 0 <= ny < W):
                continue
            if S[x][y] == S[nx][ny]:
                continue
            if seen[nx][ny]:
                continue
            dfs(nx, ny)

    answer = 0
    for h in range(H):
        for w in range(W):
            if S[h][w] == ".":
                continue
            if seen[h][w]:
                continue
            black.append(0)
            white.append(0)
            dfs(h, w)

    for i in range(len(black)):
        answer += black[i] * white[i]
    print(answer)


if __name__ == "__main__":
    main()


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



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

    int T=1;
    //cin >> T;
    while(T--){
        int n;
        cin>>n;
        int x, ans=0;
        rep_a(i,1,n+1){
            cin>>x;
            if((i&1) && (x&1)) ans++;
        }
        cout<<ans<<el;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3800
n =input()

#最上位の桁をc,桁数をkとすると、
#c以外が9の場合(ex.49999)はc,9*(k-1)となる
#それ以外の場合、c,9*(k-2),8となる(ex.9995:9989)

c = int(n[0])
k = len(n)
if int(n)<10:
    print(n);exit()
if int(n[1:])==int('9'*(k-1)):
    ans = c+9*(k-1)
else:
    ans = c+9*(k-1)-1

print(ans)


Measured memory_bytes: 61744
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn = 1e6+6;
int main()
{
	ll x;
	scanf("%lld",&x);
	ll sum = 100;
	ll ji = 0;
	while(sum < x)
	{
		ji ++;
		sum += sum/100;
	}
	printf("%lld\n",ji);
	return 0;
}

Measured memory_bytes: 3192
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
using namespace std;
using ll = long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;




ll dp[2005][2005] = {};

int main()
{
    ll n;
    cin>>n;
    pll a[n+1];
    FOR(i,1,n+1) cin >> a[i].F , a[i].S = i;
    sort(a+1,a+n+1,greater<pll>());
    FOR(i,1,n+1){
        FOR(j,0,i){
            ll L = j;
            ll R = i-1-j;
            dp[L+1][R] = max(
                dp[L+1][R],
                dp[L][R] + abs(L+1 - a[i].S)*a[i].F
            );
            R = j;
            L = i-1-j;
            dp[L][R+1] = max(
                dp[L][R+1],
                dp[L][R] + abs(n - R - a[i].S)*a[i].F
            );
        }
    }
    ll ans = 0;
    FOR(i,0,n+1){
        ans = max(ans,dp[i][n-i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 26308
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	s = IS()
	r,g,b=[],[],[]

	def binary_search(lst, K):
		l = 0; r = len(lst);
		while(l+1<r):
			mid = (l+r)//2
	    #下記の操作を書き換えることによって探索条件を変更可能
			if(lst[mid]>K): r=mid
			else: l=mid
		return l

	for i,ss in enumerate(s):
		if ss=='R':
			r.append(i)
		elif ss=='G':
			g.append(i)
		else:
			b.append(i)
	ans=len(r)*len(g)*len(b)
	for rr in r:
		for gg in g:
			a=max(rr,gg)+abs(rr-gg)
			if(a<n):
				if(s[a]=="B"):
					ans-=1
			a=min(rr,gg)-abs(rr-gg)
			if(a<n and a>=0):
				if(s[a]=="B"):
					ans-=1
			if((rr+gg)%2==0):
				a=(rr+gg)//2
				if(a<n):
					if(s[a]=="B"):
						ans-=1
	print(ans)







if __name__ == '__main__':
	main()

Measured memory_bytes: 70176
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>> a(n);
    for(int i=0;i<n;i++) {
        int x,y;
        cin>>x>>y;
        a[i]={x,y};
    }
    sort(a.begin(),a.end());
    int count=0;
    for(int i=0;i<n;i++) {
        count+=a[i].second;
        if(count>=k) {
            cout<<a[i].first<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
object Main extends App {
  import scala.io.StdIn._

  println(
    readLine.trim.toInt.let(f ⇒ (f - 30) / 2)
  )
  implicit class ScopeFunc[T](value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 43888
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<ll> enum_div(ll n) {
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int> D(N);
    cin >> D;
    int M;
    cin >> M;
    vector<int> T(M);
    cin >> T;

    auto solve = [&]() {
        if (N < M) return false;
        map<int, int> m;
        REP(i, N) {
            m[D[i]]++;
        }
        REP(i, M) {
            m[T[i]]--;
            if (m[T[i]] < 0) return false;
        }
        return true;
    };

    YESNO(solve(), "YES", "NO");
    return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int N,sum=1;
	cin>>N;
	vector<int> H(N);
    for(int i=0;i<N;++i)cin>>H[i];
	int op=H[0];
	for(int i=1;i<=N;++i){
		if(op<=H[i]){
			op=H[i];
			++sum;
		}
	}
	cout<<sum;
}

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

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

    vector<int> A(b);
    for (int i = 0; i < b; i++){
        A.at(i) = a;
    }

    vector<int> B(a);
    for (int i = 0; i < a; i++){
        B.at(i) = b;
    }

    if (a < b) for (int i = 0; i < b; i++)cout << a;
    else for(int i = 0; i < a; i++)cout << b;

    cout << endl;
}

Measured memory_bytes: 3580
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string s = readln.chomp;
    writeln(s[0 .. 4], " ", s[4 .. $]);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
#include<iostream> 
#include<stdio.h>
#include<string>
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl; }
void outl(ll x) { cout << x << endl; }
void outs(string x) { cout << x << endl; }
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
//---------------------------------------------------------------

int main() {
	int a, b;

	cin >> a >> b;
	int x = max(a, b);
	if (a == b) {
		outi(2 * a);
	}
	else {
		outi(x + x - 1);
	}
}

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

using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long                           //del this if TLE or MLE
#define ll long long
#define pr pair<int,int>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fow(i,a,b,c) for(int i=a;i<=b;i+=c)
#define bck(i,a,b,c) for(int i=a;i>=b;i-=c)
#define F first
#define S second
#define loop int tests;cin>>tests;while(tests--)

const int N=3005;

int a[N];

int dp[N][N];

signed main()
{
	fastio;
	int n;
	cin>>n;
	fow(i,1,n,1)
	{
		cin>>a[i];
		dp[i][i]=a[i];
	}
	bck(l,n,1,1)
	{
		fow(r,l+1,n,1)
		{
			dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
		}
	}
	cout<<dp[1][n]<<"\n";
}



Measured memory_bytes: 70016
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int cal(int v) {
  int ret = 0;
  while (v > 0) {
    ret += (v%10);
    v /= 10;
  }
  return ret;
}

int main(int argc, char *argv[])
{
  int N, ans = 1000000;
  cin >> N;

  for (int i = 1; i < N; i++) {
    ans = min(ans, cal(i) + cal(N-i));
  }

  printf("%d\n", ans);
}


Measured memory_bytes: 256
mod scanner {
    use std;
    use std::io::Read;
    pub struct Scanner<R: Read> {
        pub input: R,
    }
    impl<R: Read> Scanner<R> {
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let v = self.input.by_ref().bytes()
                .map(|x| x.unwrap())
                .skip_while(|&x| x == b' ' || x == b'\n')
                .take_while(|&x| x != b' ' && x != b'\n')
                .collect::<Vec<_>>();
            unsafe { std::str::from_utf8_unchecked(&v) }
            .parse()
            .ok()
            .expect("Parse error.")
        }
    }
}

fn main() {
    let sc = std::io::stdin();
    let mut sc = scanner::Scanner{input: sc.lock()};
    let n: usize = sc.next();
    let m: usize = sc.next();
    let mut a = vec![(false, false); n];
    for _ in 0..m {
        let x: usize = sc.next();
        let y: usize = sc.next();
        if x == 1 {
            a[y - 1].0 = true;
        }
        if y == n {
            a[x - 1].1 = true;
        }
    }
    for (a, b) in a {
        if a && b {
            println!("POSSIBLE");
            return;
        }
    }
    println!("IMPOSSIBLE");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int div=n%10;
	if(div==2||div==4||div==5||div==7||div==9){
		cout<<"hon"<<endl;
	}else if(div==0||div==1||div==6||div==8){
		cout<<"pon"<<endl;
	}else {
	cout<<"bon"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
using System;

class Program
{
    static void Main(string[] args)
    {
        string input;
        int n, minTall, total = 0;

        input = Console.ReadLine();
        string[] inputValues = input.Split(' ');

        n = Int32.Parse(inputValues[0]);
        minTall = Int32.Parse(inputValues[1]);

        string allTalls = Console.ReadLine();
        string[] tallValues = allTalls.Split(' ');

        for (int i = 0; i < n; i++)
        {
            if (Int32.Parse(tallValues[i]) >= minTall)
                total++;
        }

        Console.WriteLine(total);
    }
}




Measured memory_bytes: 15584
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n, a = 0, w = 0, t = 0, r = 0;
    cin >> n;
    string s;
    for (long long q = 0; q < n; q++)
    {
        cin >> s;
        if (s == "AC")
            a++;
        else if (s == "WA")
            w++;
        else if (s == "TLE")
            t++;
        else if (s == "RE")
            r++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF=0x7fffffff;
const  int MAXN=300+10;

ll ans=0,gra[MAXN][MAXN];
bool gra2[MAXN][MAXN]={0};//gra2[i][j]=0,表示ij之间的路要保留，gra2[i][j]=true表示要删除 
int n;
bool f=1;

bool Floyd(){
	for(int k=1;k<=n&&f;k++){
		for(int i=1;i<=n&&f;i++){
			for(int j=1;j<=n&&f;j++){
				if(gra[i][k]+gra[k][j]<gra[i][j]){//如果这图里面有两点之间的距离不是最短路径
				//那么不能找到一个网使得两点之间的最短距离等于原图之中的距离 ，输出-1； 
					f=false;
					break;
				}
				else if(gra[i][k]+gra[k][j]==gra[i][j]){
					//如果i经过其他点到达j的路径与直接到达j的路径长度相同
					//那么ij可以不要 
					if(i!=k&&k!=j){
						gra2[i][j]=true;//true表示不要这条边 
					}	
				}
			}
		}
	}
	return f; 
}



void print(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(gra2[i][j]){
				cout<<0<<" ";
			}
			else cout<<1<<" ";
		}
		cout<<endl;		
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%lld",&gra[i][j]);
		}		
	}
	Floyd();
	if(!f){
		cout<<-1<<endl;
		return 0;
	}
//	print();
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(!gra2[i][j]){
				ans+=gra[i][j];
			}
		}		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
S = input()
type = sorted(set(S))
count = [0] * len(type)

for i,t in enumerate(type):
  sen = S
  con = 0
  while True:
    tmp = ""
    if len(set(sen)) == 1:
      count[i] = con
      break
    for j in range(len(sen) - 1):
      if (sen[j] == t) or (sen[j + 1] == t):
        tmp += t
      else:
        tmp += sen[j]
    con += 1
    sen = tmp

print(min(count))

Measured memory_bytes: 3064
n = int(input())
b = list(map(int, input().split()))
a = [None] * n

for i in range(n-1):
    if a[i] is None or a[i] > b[i]:
        a[i] = b[i]
    a[i+1] = b[i]

res = sum(a)

print(res)

Measured memory_bytes: 3060
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll LINF = ll(1e18);
const ll MOD = ll(1e9+7);

int main(){
  int n, x;cin>>n>>x;
  vector<ll> a(n), mcost(n);
  rep(i, n){
    cin>>a[i];
    mcost[i]=a[i];
  }
  ll ans = LINF;
  rep(k, n){ // cast a spell k times
    ll cost = 0LL;
    rep(i, n){
      mcost[i] = min(mcost[i], a[(i+n-k)%n]);
      cost += mcost[i];
    }
    ans = min(ans, cost+ll(k)*x);
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 384
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#include<bits/stdc++.h>
#define fr first
#define sc second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define forn(i,n) for(int i =1;i<= (n);++i)
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
const int inf = 1e9+7;
const int nmax = 500005;
const ll linf = LLONG_MAX;
const ll mod = 1000000007;

ll n, a[10005] , lcm , sum;
ll primes[1000005] , pows[1000005];

void ciur(){
    primes[1] = 1;
    for(int i = 2; i <= 1000000 ; i++){
        if(primes[i] == 0){
            primes[i] = i;
            for(int j = 2*i ; j <= 1000000; j+= i){
                if(primes[j] == 0){
                    primes[j] = i;
                }
            }
        }
    }
}

ll p(ll k , ll power){
    ll r = 1;
    for(ll i = 0 ; (1<<i) <= power ; i++){
        if((1<<i)&(power)){
            r *= k;
            r %= mod;
        }
        k *= k;
        k %= mod;
    }
    return r;
}
int main(){
    //fast;
    ciur();
    //cout << "CHECK\n";
    cin >> n;
    forn(i,n){
        cin >> a[i];
        ll ac = a[i];
        while(primes[ac] != 1){
            ll prime = primes[ac] , vp = 0;
            while(primes[ac] == prime){
                vp++;
                ac /= prime;
            }
            pows[prime] = max(pows[prime] , vp);
        }
    }
    //cout << "CHECK\n";
    ll lcm = 1;
    forn(i,1000000){
        if(primes[i] == i && pows[i] > 0){
            lcm *= p(i,pows[i]);
            lcm %= mod;
        }
    }
    //cout << "CHECK\n";
    ll rez = 0;
    forn(i,n){
        ll add = (lcm * p(a[i],mod-2));
        add %= mod;
        rez += add;
        rez %= mod;
    }
    //cout << "CHECK\n";
    cout << rez << '\n';
}


Measured memory_bytes: 15744
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, ans = 0; string s, t; cin >> s >> n;
	for (int h = 0; h < n; h++) {
		cin >> t; int num = 1;
		for (int i = 0; i < 10; i++) {
			int sum = 0;
			if (i < 11 - s.size()) {
				for (int k = i; k < i + s.size(); k++) {
					if (s[k - i] == t[k]) {
						sum++;
					}
				}
				if (sum == s.size()) {
					ans++; i = 10;
				}
			}
			else {
				sum = 0;
				for (int k = i; k < 10; k++) {
					if (s[k - i] == t[k]) {
						sum++;
					}
				}
				for (int k = 0; k < num; k++) {
					if (s[10 - i + k] == t[k]) {
						sum++;
					}
				}
				if (sum == s.size()) {
					ans++; i = 10;
				}
				num++;
			}
		}
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int main()
{
	int N;
	cin >>N;
	map<string, int> mp;
	rep(i, N){
		string s;
		cin >>s;
		mp[s]++;
	}
	int mx = 0;
	for(auto p : mp){
		mx = max(mx, p.second);
	}
	for(auto p: mp){
		if(p.second != mx){
			continue;
		}
		cout <<p.first <<endl;
	}
	return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int N;
    cin >> N;
    cout << (N+1)/2;
}


Measured memory_bytes: 256
while True:
    ins = list(map(int, input().split()))
    ls = range(1,ins[0]+1)
    
    if ins[0] == 0 and ins[1] == 0:
        break
        
    else:
        counter = 0
        for i in range(ins[0]-2):
           for j in range(i+1, ins[0]-1):
            for k in range(j+1, ins[0]):
                if ls[i] + ls[j] + ls[k] == ins[1]:
                    counter += 1
    print(counter)

Measured memory_bytes: 7664
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = LI()

def solve():
  
  lenl = [0 for i in range(N+1)]
  for i in range(N+1):
    if i == 0:
      lenl[i] = 1
    else:
      lenl[i] = 2 * lenl[i-1] + 3
  
  npl = [0 for i in range(N+1)]
  for i in range(N+1):
    if i == 0:
      npl[i] = 1
    else:
      npl[i] = 2 * npl[i-1] + 1

  def np(l, x):
    if x <= 0:
      return 0
    if l == 0:
      return 1
    
    if x < lenl[l] // 2:
      return np(l-1, x-1)
    elif x == lenl[l] // 2:
      return npl[l-1]
    elif x == (lenl[l] // 2) + 1:
      return npl[l-1] + 1
    else:
      return npl[l-1] + 1 + np(l-1, x-(lenl[l]//2)-1)
  
  print(np(N, X))
solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S; cin >> S;
    string T; cin >> T;

    int S_size = S.length();
    int T_size = T.length();
    int kaisuu = S_size - T_size + 1;
    int ans = 0;

    for(int i = 0; i < kaisuu; i++){
        int onaji = 0;
        for(int j = 0; j < T_size; j++){
            char tmp_S = S[i+j];
            char tmp_T = T[j];
            if(tmp_S == tmp_T) onaji ++;
        }
        ans = max(ans, onaji);
        onaji = 0;
    }

    ans = T_size - ans;
    cout << ans << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  bool findN = S.find('N') != string::npos;
  bool findS = S.find('S') != string::npos;
  bool findE = S.find('E') != string::npos;
  bool findW = S.find('W') != string::npos;

  if(findN && findS) {
    cout << (((!findE && findW) || (findE && !findW)) ? NO : YES) << endl;
  }
  else if(findE && findW) {
    cout << (((!findN && findS) || (findN && !findS)) ? NO : YES) << endl;
  }
  else {
    cout << NO << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


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

int main() {

int N , M ;

cin >> N ; 			// 駒の数をNに読み込む
int koma[N + 1] ; 		// 駒の座標を記録するN+1個の配列を用意し、0で初期化。koma[0]は、混乱防止のため使わない（欠番）とする。


	// N個の駒の座標を、配列に読み込む
	int i = 0 ;
	
	for( i = 1 ; i <= N ;){
	cin >> koma[i] ;
	i = i + 1 ;
	}
	

cin >> M ; 			// 操作回数の読み込み


	//駒の操作
	int koma_index_number = 0 ;	// 操作すべき駒の番号に使う変数
	
	while( 0 < M ){
	cin >> koma_index_number ;
	
	    if( koma[koma_index_number] + 1 == koma[koma_index_number + 1 ] ){	// 移動先のマスに別の駒が置かれているかの判定。
	    // 移動先のマスに別の駒が置かれている場合、何もしない。
	    }else{
		    if( 2019 < koma[koma_index_number] + 1 ){
		    // 移動先のマスの座標が2019より大きい場合、何もしない。
		    }else{
		    koma[koma_index_number] = koma[koma_index_number] + 1 ;		// 邪魔がない場合は、駒の座標を1進める。
		    }
		}
	M = M - 1 ;
	}



    // 座標の出力
	for( i = 1 ; i <= N ; ){
	cout << koma[i] <<endl ;
	i = i + 1 ;
	}
	


	

}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vs = vector<string>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

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

  if (S == "SUN") cout << 7 << endl;
  else if (S == "MON") cout << 6 << endl;
  else if (S == "TUE") cout << 5 << endl;
  else if (S == "WED") cout << 4 << endl;
  else if (S == "THU") cout << 3 << endl;
  else if (S == "FRI") cout << 2 << endl;
  else if (S == "SAT") cout << 1 << endl;
  
}

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

int main(){

    int n, k;
    cin >> n >> k; 
    int num = 0;
    for(int i = 0; i < n; i++){
        int height;
        cin >> height;
        if(height >= k)
            num++;
    }

    cout << num << "\n";

    return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(int &a, int b){
  if(a > b)
    a = b;
}
void chmax(int &a, int b){
  if(a < b)
    a = b;
}

void llchmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void llchmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  char s;
  cin >> s;
  
  char al = 'a';
  
  rep(i, 0, 26){
    if(al == s){
      cout << "a" << endl;
      return 0;
    }
    
    al++;
  }
  
  al = 'A';
  
  rep(i, 0, 26){
    if(al == s){
      cout << "A" << endl;
      return 0;
    }
    
    al++;
  }
  
  return 0;
  
}

Measured memory_bytes: 3668
# -*- coding: utf-8 -*-
from decimal import *
n = int(input())

res1 = Decimal(0)
res2 = Decimal(0)
for _ in range(n):
    x,u = input().split()
    if u=="JPY":
        res1 += Decimal(x)
    else:
        res2 += Decimal(x)*Decimal(380000.0)

print(res1+res2)


Measured memory_bytes: 5588
N, x = map(int, input().split())		# 5 7
A = sorted(list( map(int, input().split()) ))	# 1 2 3 4 5 ...(ソート付き)

B = [0]*N

#print(N,x,A,B)

zan=x

for i in range(N):
	a=A[i]
	if zan>=a:
		B[i]=a
		zan-=a
	else:
		B[i]=zan
		zan=0
		break

if zan>0:
	B[-1]+=zan
	zan=0

ans=0
for i in range(N):
	if (A[i]>0)and(A[i]==B[i]):
		ans+=1

#print(B)
print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
      	long ans = INF;
      	for(int i = 1 ; i >= -1 ; i += -2){
			for(int j = 1 ;j >= -1; j += -2){
              	long a=0;
              	if(i == -1){
                  a++;
                }
              	if(j == -1){
                  a++;
                }
              	if(y*j >= x*i){
                  ans=Math.min(ans,(y*j-x*i)+a);
                }
         	}
    	}
      	System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll gcd(ll a, ll b){
    if(a < b)  swap(a,b);
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (ll i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n ;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    cout << nlcm(v) << endl;
    return 0;
    return 0;
}

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

int main(){
    int N;
    double T,A;
    cin >> N >> T >> A;
    vector<double>H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
        H[i] = T-H[i]*0.006;
    }
    int ans = 1;
    double cnt = abs(A-H[0]);
    for(int i = 1; i < N; i++) {
        if(cnt > abs(A-H[i])) {
            ans = i+1;
            cnt = abs(A-H[i]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a-b,b-a);}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

long long n,x[16],y[16],p[16],bs[16];

long long find(long long sta[],long long kp[],long long kpc,long long akp[],long long akpc[]){
  long long res=0,i,j,k,l,md;
  for(l=0;l<akpc;l++){
    i=akp[l];
    md=bs[i];
    for(k=0;k<kpc;k++){
      j=kp[k];
      if(sta[j]==1){md=llmin(llzt(x[i],x[j]),md);}
      else if(sta[j]==2){md=llmin(llzt(y[i],y[j]),md);}
    }
    res+=(md*p[i]);
  }
  return res;
}

int main(void){
  long long i,j,res[16],tg,w,pt;
  long long sta[16],kp[16],akp[16],akpc;
  scanf("%lld",&n);
  for(i=0;i<16;i++){res[i]=llinf;}
  for(i=0;i<n;i++){
    scanf("%lld%lld%lld",&x[i],&y[i],&p[i]);
    bs[i]=llmin(llzt(0,x[i]),llzt(0,y[i]));
  }
  tg=llpow(3,n);
  for(i=0;i<tg;i++){
    w=i;pt=0;akpc=0;
    for(j=0;j<n;j++){
      sta[j]=w%3;w/=3;
      if(sta[j]){kp[pt]=j;pt++;}
      else{akp[akpc]=j;akpc++;}
    }
    res[pt]=llmin(res[pt],find(sta,kp,pt,akp,akpc));
  }
  for(i=0;i<=n;i++){
    printf("%lld\n",res[i]);
  }
  return 0;
}


Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0554
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int time1 = ReadInt();
            int time2 = ReadInt();
            int time3 = ReadInt();
            int time4 = ReadInt();
            int total = time1 + time2 + time3 + time4;
            Console.WriteLine(total/60);
            Console.WriteLine(total%60);
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15900
#include <iostream>

#define inRange(x, y, w, h) (0 <= x && x < w && 0 <= y && y < h)
#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define rep(i, n) rep2(i, 0, n)
#define repd(i, b, n) for(int i=b; i > n; --i)

using namespace std;

const int dx[] = { 0, 0, -1, 1, -1, -1, 1, 1 };
const int dy[] = { -1, 1, 0, 0, -1, 1, -1, 1 };
char fd[8][8];

int counter( int x, int y, int d, char _my, char your )
{
	int count = 0;
	int mx = x + dx[d];
	int my = y + dy[d];
	while(inRange(mx, my, 8, 8)) {
		char c = fd[my][mx];
		if(c == _my) return count;
		else if(c == your) ++count;
		else break;
		mx += dx[d];
		my += dy[d];
	}
	return 0;
}

void filler( int x, int y, int d, char _my )
{
	fd[y][x] = _my;
	int mx = x + dx[d];
	int my = y + dy[d];
	do {
		fd[my][mx] = _my;
		mx += dx[d];
		my += dy[d];
		if(fd[my][mx] == _my) break;
	} while(inRange(mx, my, 8, 8));
}

int main( void )
{
	while(cin >> fd[0][0]) {
		rep2(x, 1, 8) cin >> fd[0][x];
		rep2(y, 1, 8) rep(x, 8) cin >> fd[y][x];
		bool hit1, hit2;
		do {
			int sx, sy, count, Max = 0;
			hit1 = false;
			rep(y, 8)
				rep(x, 8) {
					if(fd[y][x] != '.') continue;
					count = 0;
					rep(d, 8) count += counter(x, y, d, 'o', 'x');
					if(Max < count) { Max = count; sx = x; sy = y; hit1 = true; }
				}
			if(hit1) rep(d, 8) if(counter(sx, sy, d, 'o', 'x')) filler(sx, sy, d, 'o');

			hit2 = false;
			Max = 0;
			repd(y, 7, -1)
				repd(x, 7, -1) {
					if(fd[y][x] != '.') continue;
					count = 0;
					rep(d, 8) count += counter(x, y, d, 'x', 'o');
					if(Max < count) { Max = count; sx = x; sy = y; hit2 = true; }
				}
			if(hit2) rep(d, 8) if(counter(sx, sy, d, 'x', 'o')) filler(sx, sy, d, 'x');
		} while(hit1 || hit2);
		rep(y, 8) {
			rep(x, 8)
				cout << fd[y][x];
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n,x,y = l_in()
d = [0 for _ in range(n)]

# for i in range(1, x+1):
#     for j in range(i+1, x):
#         d[j-i] += 1
#     for j in range(x+1, y+1):
#         d[min(j-i, y-j+x-i)] += 1
#     for j in range(y+1, n+1):
#         d[j-y+x-i] += 1

# for i in range(x+1, y+1):
#     for j in range(i+1, y+1):
#         d[min(j-i, y-j+i-x)] += 1
#     for j in range(y+1, n+1):
#         d[min(j-y+x-i)] += 1

for i in range(1, n+1):
    for j in range(i+1, n+1):
        d[min(abs(j-i), abs(x-i)+abs(j-y)+1, abs(i-y)+abs(x-j)+1)] += 1

# print(d)
for k in range(1,n):
    print(d[k])



Measured memory_bytes: 48732
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


int main(){
    LL n;
    cin >> n;
    if(n == 1){
        cout << "Yes" << endl;
        cout << "2" << endl;
        cout << "1 1" << endl;
        cout << "1 1" << endl;
        return 0;
    }
    LL total = 0;
    for(LL i = 1; i <= n; ++i){
        total += i;
        if(total > n) break;
        if(total == n){
            cout << "Yes" << endl;
            LL c = n * 2 / i;
            cout << c << endl;
            vector<vector<LL> > a(c, vector<LL>(i));
            LL next = 1;
            for(LL j = 0; j < c; ++j){
                cout << i;
                for(LL k = 0; k < j; ++k){
                    a[j][k] = a[k][j-1];
                    cout << " " << a[j][k];
                }
                for(LL k = j; k < i; ++k){
                    a[j][k] = next;
                    cout << " " << a[j][k];
                    next++;
                }
                cout << endl;
            }
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



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

A, B, Q = map(int, input().split())
Shrine = [int(input()) for _ in range(A)]
Temple = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]
Shrine = [-100000000000] + Shrine + [100000000000]
Temple = [-100000000000] + Temple + [100000000000]

for x in X:
    nums = bisect.bisect_left(Shrine, x)
    tems = bisect.bisect_left(Temple, x)
    ans1 = max(abs(Shrine[nums]-x), abs(Temple[tems]-x))
    ans2 = max(abs(x - Shrine[nums-1]), abs(x - Temple[tems-1]))
    ans3 = abs(Shrine[nums]-x) * 2 + abs(x - Temple[tems-1])
    ans4 = abs(Temple[tems]-x) * 2 + abs(x - Shrine[nums-1])
    ans5 = abs(x - Shrine[nums-1]) * 2 + abs(Temple[tems]-x)
    ans6 = abs(x - Temple[tems-1]) * 2 + abs(Shrine[nums]-x)

    print(min(ans1, ans2, ans3, ans4, ans5, ans6))

Measured memory_bytes: 16784
s=input()
cnt_1=0
cnt_2=0
for i in range(1,len(s)):
  if i!=1 and i!=len(s)-1 and s[i]=="C":
    cnt_2+=1
  if s[i].islower():
    cnt_1+=1
if s[0]=="A" and cnt_2==1 and cnt_1==len(s)-2:
  print("AC")
else:
  print("WA")

Measured memory_bytes: 8992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c;
    cin>>n;
    cin.ignore();
    map<char,ll>mp;
    string s;
    for(i=0;i<n;i++)
    {
        cin>>s;
        if(s[0]=='M'||s[0]=='A'||s[0]=='R'||s[0]=='C'||s[0]=='H')
        {
            mp[s[0]]++;
        }
    }
    c=0;
    c+=mp['M']*mp['A']*mp['R']+mp['M']*mp['A']*mp['C']+mp['M']*mp['A']*mp['H'];
    c+=mp['M']*mp['R']*mp['C']+mp['M']*mp['R']*mp['H'];
    c+=mp['M']*mp['C']*mp['H'];
    c+=mp['A']*mp['R']*mp['C']+mp['A']*mp['R']*mp['H']+mp['A']*mp['C']*mp['H'];
    c+=mp['R']*mp['C']*mp['H'];
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a * b == 15)cout << "*" << endl;
  else if(a + b == 15)cout << "+" << endl;	\
  else cout << "x" << endl;

  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)
keta=10 if N==1 else 100 if N==2 else 1000
res=[10]*3
ans=-1
start=0 if(N==1) else keta//10
for i in range(start,keta):
    st=str(i)
    t=1
    for j in range(M):
        if(st[s[j]-1]!=str(c[j])):
            t=0
            break
    if(t==1):
        ans=i
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define sort(v)     sort((v).begin(),(v).end())
#define rall(v)     (v).rbegin(),(v).rend()
#define rsort(v)     sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;


bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}
struct type{
    int k, i, j;
};
signed main() 
{
    fastio;
    string s;
    cin>>s;
    int n=s.length();
    f(i,n)cout<<"x"<<"";
    cout<<endl;
    
    
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pll = pair < ll, ll >;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
 
int main(){   
    ll n; cin >> n;
    if(n%1000 != 0) 
        cout << 1000- n % 1000 << endl;
    else 
        cout << 0 << endl;
}
    

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
typedef long long ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
const double PI=3.14159265358979323846;

using namespace std;

int n;

int main () {

	int a, b;

	cin >> a >> b;

	cout << a * b << endl;
}

Measured memory_bytes: 3636
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	int x; cin >> x;
	int a = __gcd(360, x);
	cout << 360 / a << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
struct O {
	int t, x, y;
} p[100005];
bool cmp(O a, O b) {
	return a.t < b.t;
}
int n, t, x, y;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) {
		scanf("%d %d %d", &p[i].t, &p[i].x, &p[i].y);
	}
	sort(p + 1, p + 1 + n, cmp);
	int nx = 0, ny = 0, nt = 0;
	for (int i = 1; i <= n; i ++) {
		int tx = p[i].x, ty = p[i].y;
		int dis = abs(tx - nx) + abs(ty - ny), time = p[i].t - nt;
		if (time - dis < 0) return printf("No"), 0;
		if ((time - dis) % 2) return printf("No"), 0;
	}
	printf("Yes"), 0;
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3

# input
N = int(input())
blue = {}
for _ in range(N):
    s = input()
    if s not in blue:
        blue[s] = 1
    else:
        blue[s] += 1

M = int(input())
red = {}
for _ in range(M):
    s = input()
    if s not in red:
        red[s] = 1
    else:
        red[s] += 1

# solve
max_point = 0

for s, blue_count in blue.items():
    red_count = red.get(s) or 0
    point = blue_count - red_count

    if point > max_point:
        max_point = point

print(max_point)


Measured memory_bytes: 3064