akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

struct problem
{
    int score;
    int num;
    int bonus;
};

vector< problem > probs;

u32 makemax(int x)
{
    u32 ret = 0;
    while (x > 0)
    {
        ret = (ret << 1) | 1;
        --x;
    }
    return ret;
}

int addbonus(u32 x, int& score)
{
    score = 0;
    int cnt = 0;
    int ret = 0;
    while (x > 0)
    {
        if (x & 1)
        {
            score += probs[cnt].bonus + probs[cnt].num * probs[cnt].score;
            ret += probs[cnt].num;
        }
        x >>= 1;
        ++cnt;
    }
    return ret;
}

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

    int D, G;
    cin >> D >> G;
    G /= 100;

    probs.resize(D);
    rep (i, D)
    {
        cin >> probs[i].num >> probs[i].bonus;
        probs[i].score = i + 1;
        probs[i].bonus /= 100;
    }

    u32 m = makemax(D);
    int ans = 1e6;
    int score;
    int num;
    for (u32 i = 0; i <= m; ++i)
    {
        num = addbonus(i, score);
        if (score < G)
        {
            int cnt = D - 1;
            while (score < G && cnt >= 0)
            {
                if (i & (1 << cnt))
                {
                    --cnt;
                }
                else
                {
                    for (int j = 0; j < probs[cnt].num - 1 && score < G; ++j)
                    {
                        score += probs[cnt].score;
                        ++num;
                    }
                    --cnt;
                }
            }
        }
        if (score >= G) ans = MIN(ans, num);
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
inp = input()
n, m = [int(inp.split()[i]) for i in range(0, 2)]

small, large = 0, 0

for _ in range(0, m):
  i = input()
  s = int(i.split()[0])
  l = int(i.split()[1])
  if small == 0:
    small, large = s, l
  else:
    if small < s:
      small = s
    if large > l:
      large = l

if small > large:
  print(0)
elif small > n:
  print(0)
elif small <= n:
  if large <= n:
    print(large - small + 1)
  elif large > n:
    print(n - small + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define deb(x)  cout << #x << ' ' << x << endl;
#define mod 1000000007
#define all(n)      (n).begin(), (n).end()
#define ll long long
#define ull unsigned long long 
void solve() {
    int n; cin >> n;
    while(n--){
        cout <<"ACL";
    }
    cout << '\n';
    
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    //Starts here , 
    // Chaaliya Be! Tamam Dekhun!	
                
    int T = 1; 
    // cin >> T;	
    while(T--){
        solve();
    }
    return 0;
            
}

Measured memory_bytes: 3600
a, b = gets.split.map(&:to_i)

case
when a == 0 || b == 0 || (a < 0 && 0 < b)
  puts 'Zero'
when 0 < a || (a != b && (b - a).odd?)
  puts 'Positive'
else
  puts 'Negative'
end

Measured memory_bytes: 14372
from itertools import accumulate as acc

def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x) - 1, input().split()))


if __name__ == "__main__":
    N, M, Q = LI()
    LR = [[0]*N for _ in range(N)]
    for i in range(M):
        l, r = LI_()
        LR[l][r] += 1

    # 二次元累積和
    S = [tuple(acc(reversed(s))) for s in zip(*(acc(x) for x in LR))]
    for _ in range(Q):
        p, q = LI()
        # 必ず正方形だから、
        print(S[q-1][N-p])


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

int main() {
	int n;
	string s;
	bool f=false;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s=="Y") f=true;
	}
	if(f==true){
		cout<<"Four"<<endl;
	}else{
		cout<<"Three"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
 
int main(){
/*	int n, k;
	string s;
	cin >> n >> k >> s;
	ll cnt=0;
	vector<ll> v;
	bool b=true;
	for(int i=0; i<s.length(); i++){
		if(s[i]=='('){
			cnt++;
		}else{
			if(s[i-1]==')') v.push_back(cnt);
			v.push_back(cnt);
			cnt--;
		}
	}
	sort(v.begin(), v.end(), greater<ll>());
 
	ll ans=0;
	for(int i=0; i<k && i<v.size(); i++){
		ans+=v[i];
	}
	cout << ans << endl;
*/
	//Tenka1 2019 C-stones
	int n;
	string s;
	cin >> n >> s;
	vector<int> u, v;
	int m=0, cnt;
	while(m<n){
		cnt=0;
		while(s[m]=='#'){
			cnt++;
			m++;
		}
		u.push_back(cnt);
		cnt=0;
		while(s[m]=='.'){
			cnt++;
			m++;
		}
		v.push_back(cnt);
	}
	int l=u.size();
	for(int i=1; i<l; i++) u[i]+=u[i-1];
	for(int i=1; i<l; i++) v[i]+=v[i-1];

	int ans=n;
	for(int i=0; i<l; i++) ans=min(ans, u[i]+v[l-1]-v[i]);
	ans=min(ans, v[l-1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, m, p;
    cin >> n >> m >> p;
    WGraph G(n);
    for (int i=0; i<m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        G.at(a-1).push_back({b-1, c-p});
    }

    // bellman-ford
    vector<ll> dis(n, -LINF);
    dis.at(0) = 0;
    for (int i=0; i<2*n; i++) {
        for (int j=0; j<n; j++) {
            for (auto pa : G.at(j)) {
                if (dis.at(pa.first) < dis.at(j) + pa.second && dis.at(j) != -LINF) {
                    if (i < n-1) {
                        dis.at(pa.first) = dis.at(j) + pa.second;
                    } else {
                        dis.at(pa.first) = LINF;
                    }
                }
            }
        }
    }

    if (dis.at(n-1) == LINF) cout << -1 << '\n';
    else cout << max(0LL, dis.at(n-1)) << '\n';
}

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

    solve();

    return 0;
}


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

using namespace std;
vector<int> G[200050];
int a[200105];
int res[200050];

int ans = 0;
void dfs(int v,int fa){
    if(v==1)    ans+=a[1];

    res[v] = ans;
    for(auto to:G[v]){
        if(to==fa)  continue;
        ans += a[to];
        dfs(to,v);
        ans -= a[to];
    }
}
int main()
{
    int n,q;
    cin>>n>>q;

    for(int i=0;i<n-1;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }


    while(q--){
        int id,x;
        scanf("%d%d",&id,&x);
        a[id] += x;
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++)printf("%d ",res[i]);

    return 0;
}


Measured memory_bytes: 24064
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: i32,
        s: String, 
    }
    let mut ans: i32 = 0;
    let mut tmp: i32 = 0;

    for c in s.chars() {
        tmp = match c {
            'I' => tmp + 1,
            'D' => tmp - 1,
            _ => panic!("expect I or D"),
        };
        if tmp > ans {
            ans = tmp;
        }
    }
    println!("{}", ans);
} 


Measured memory_bytes: 4352
# D - Sum of Divisors
N = int(input())
ans = 0

for i in range(1, N + 1):
	j = 1
	
	while True:
		if i * j <= N:
			#print(i * j)
			
			ans += i * j
			j += 1
		else:
			break

print(ans)
	


Measured memory_bytes: 72988
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int count_way(int x, int y){
  int res = INFi;
  int res1 = (y >= x) ? (y - x) : INFi; chmin(res, res1);
  int res2 = (-x <= y) ? (1 + y + x) : INFi; chmin(res, res2);
  int res3 = (y <= -x) ? (1 - x - y) : INFi; chmin(res, res3);
  int res4 = (x >= y) ? (2 + x - y) : INFi; chmin(res, res4);
  return res;
}


int main(void){
  int x, y; cin >> x >> y;
  cout << count_way(x, y) << BR;
  return 0;
}

Measured memory_bytes: 888
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  while(1) {
    int n, p;
    cin >> n >> p;
    if(n == 0) break;
    int num[n];
    FOR(i,0,n) num[i] = 0;
    int wan = p;
    FOR(i,0,1000006) {
      int now = i % n;
      if(wan > 0) {
        wan--;
        num[now]++;
        if(num[now] == p) {
          cout << now << endl;
          break;
        }
      } else {
        wan = num[now];
        num[now] = 0;
      }
    }
  }
  return 0;
}

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

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

  if((b<=a+W && b>=a) || (b+W>=a && b+W<=a+W)) {
    cout << 0 << endl;
  }else {
    //cout << (int)fabs(b-a-W) <<  " " << (int)fabs(b+W-a) << endl;
    cout << min(max(0,(int)fabs(b-a-W)),max(0,(int)fabs(b+W-a))) << endl;
  }
}


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

int main() {
	int a, b, m;

	cin >> a >> b;

	m = a + b;

	if (m < a - b) {
		m = a - b;
	}
	if (m < a * b) {
		m = a * b;
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
/*
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define p_q priority_queue
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    fast_io;

    bool x;
    cin>>x;

    cout<<!x<<endl;

return 0;
}
*/

#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define p_q priority_queue
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;


int main()
{
    fast_io;

    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<<max({a*c, a*d,b*c,b*d})<<endl;

return 0;
}

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

using namespace std;

typedef pair<int,int> P;

int main(){
    int N,M,a,b,count,l,r,i;
    const int Mmax = 100000;
    P requirements[Mmax];

    cin >> N >> M;
    for(int i = 0;i < M;i++){
        cin >> a >> b;
        requirements[i] = P(a,b);
    }
    sort(requirements,requirements + M);

    l = requirements[0].first;
    r = requirements[0].second;
    i = 1;
    count = 0;
    while(i < M){
        if(r <= requirements[i].first){
            l = requirements[i].first;
            r = requirements[i].second;
            count++;
        }else if(requirements[i].second < r){
            l = requirements[i].first;
            r = requirements[i].second;
        }
        i++;
    }

    cout << ++count << endl;
}

Measured memory_bytes: 1024
import math
from functools import reduce

n = int(input())
ans = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            ans += gcd(a,b,c)
print(ans)

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

using namespace std;

int h,w;
int n;
vector<int> m[101];

int main () {
  cin >> h >> w >> n;

  int k = 0;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    while(a--) {
      if(m[k].size() == w) k++;
      m[k].push_back(i + 1);
    }
  }

  for(int i = 1; i < h; i+=2) reverse(m[i].begin(),m[i].end());

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cout << m[i][j] <<" ";
    }
    cout << endl;
  }

}
    
  


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>h(n),H(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  H.at(0)=h.at(0);
  if(n==1)cout<<"Yes"<<endl;
  else{
    for(int i=1;i<n;i++){
      if(h.at(i)<h.at(i-1))h.at(i)++;
      H.at(i)=h.at(i);
    }
    sort(H.begin(),H.end());
    int a=0;
    for(int i=0;i<n;i++){
      if(h.at(i)!=H.at(i)){
        a++;
        break;
      }
    }
    if(a>0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}
    
  

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>

#define MAX 100
#define NIL -1

struct Node {
    int parent;
    int left;
    int right;
};

Node T[MAX];
int n;

// preorder
void preorder(int id) {
    if (id == NIL) return;
    
    printf(" %d", id);
    preorder(T[id].left);
    preorder(T[id].right);
}

// inorder
void inorder(int id) {
    if (id == NIL) return;
    
    inorder(T[id].left);
    printf(" %d", id);
    inorder(T[id].right);
}

// postorder
void postorder(int id) {
    if (id == NIL) return;
    
    postorder(T[id].left);
    postorder(T[id].right);
    printf(" %d", id);
}

int main() {
    int id;
    int root = 0;
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }
    
    
    for (int i = 0; i < n; i++) {
        scanf("%d", &id);
        scanf("%d %d", &T[id].left, &T[id].right);
        if (i == 0) T[id].parent = NIL;
        if (T[id].left != NIL) T[T[id].left].parent = id;
        if (T[id].right != NIL) T[T[id].right].parent = id;
    }
    
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) root = i;
    }
    
    printf("Preorder\n");
    preorder(root);
    printf("\n");
    printf("Inorder\n");
    inorder(root);
    printf("\n");
    printf("Postorder\n");
    postorder(root);
    printf("\n");
    
    return 0;
}

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

int main() {
	string s,cut,ans = "keyence";
	bool ok = false;

	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (ok)break;
		for (int j = 0; j <= s.size(); j++) {
			cut = s;
			cut.erase(i, j);
			if (cut == ans)ok = true;
		}
	}
	if (ok)cout << "YES"<< endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e3 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[1005][1005];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> x >> y >> k >> n;
    if(x + y == k + n)
    {
        cout << "Balanced";
    }
    if(x + y > k + n)
    {
        cout << "Left";
    }
    if(x + y < k + n)
    {
        cout << "Right";
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x;
    VI m(3);
    string s,s1,s2;
    cin >> a;   
    if(a < 1200) cout << "ABC" << endl;
    else if (a < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
} 

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

using namespace std;

bool withinRegion(int i, int j, int h, int w, char **matrix)
{
    if (i >= 0 && i < h && j >= 0 && j < w && matrix[i][j] == '.') {
        return true;
    }
    return false;
}

void init_searched(int h, int w, int **searched)
{
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            searched[i][j] = -1;
        }
    }
}

int main()
{
    int h, w;
    cin >> h >> w;
    queue<pair<int, int> > q;
    int max = -1;

    char **matrix = new char*[h];
    int **searched = new int*[h];
    for (int i = 0; i < h; i++) {
        matrix[i] = new char[w];
        searched[i] = new int[w];
    }

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

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (matrix[i][j] == '.') {
                init_searched(h, w, searched);
                searched[i][j] = 0;
                q.push(make_pair(i, j));
                while (!q.empty()) {
                    int r = q.front().first;
                    int c = q.front().second;
                    q.pop();
                    if (withinRegion(r + 1, c, h, w, matrix) && searched[r + 1][c] == -1) {
                        searched[r + 1][c] = searched[r][c] + 1;
                        q.push(make_pair(r + 1, c));
                    }
                    if (withinRegion(r, c + 1, h, w, matrix) && searched[r][c + 1] == -1) {
                        searched[r][c + 1] = searched[r][c] + 1;
                        q.push(make_pair(r, c + 1));
                    }
                    if (withinRegion(r - 1, c, h, w, matrix) && searched[r - 1][c] == -1) {
                        searched[r - 1][c] = searched[r][c] + 1;
                        q.push(make_pair(r - 1, c));
                    }
                    if (withinRegion(r, c - 1, h, w, matrix) && searched[r][c - 1] == -1) {
                        searched[r][c - 1] = searched[r][c] + 1;
                        q.push(make_pair(r, c - 1));
                    }
                }
                for (int r = 0; r < h; r++) {
                    for (int c = 0; c < w; c++) {
                        if (withinRegion(r, c, h, w, matrix) && max < searched[r][c]) {
                            max = searched[r][c];
                        }
                    }
                }
            }
        }
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
S = input()
u = int(S[0]) * 10 + int(S[1])
d = int(S[2]) * 10 + int(S[3])

if d >= 1 and d <= 12:
  if u >= 1 and u <=12:
    print("AMBIGUOUS")
  else:
    print("YYMM")
elif u >= 1 and u <= 12:
  print("MMYY")
else:
  print("NA")


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; 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>
struct WeightedGraph {
  struct Edge {
    int to;
    T cost;
  };
  vector<vector<Edge>> edges;
  int n;
  WeightedGraph(int n) : n(n) {
    edges = vector<vector<Edge>>(n);
  }
  void add_edge(int from, int to, T cost = 0) {
    edges[from].push_back((Edge) { to, cost });
  }
  vector<Edge>& operator[](int x) {
    return edges[x];
  }
};

template <typename T>
T min_spanning_tree(WeightedGraph<T> &g) {
  T ret = 0;
  vector<bool> used(g.n);
  pqasc<pair<T, int>> q;
  q.emplace(0, 0);
  while (!q.empty()) {
    auto p = q.top(); q.pop();
    int c, v;
    tie(c, v) = p;
    if (used[v]) continue;
    used[v] = true;
    ret += c;
    each(e, g[v]) {
      q.emplace(e.cost, e.to);
    }
  }
  return ret;
}

void solve() {
  int V, E; cin >> V >> E;
  auto g = WeightedGraph<i64>(V);
  rep(i, E) {
    int s, t, w; cin >> s >> t >> w;
    g.add_edge(s, t, w);
    g.add_edge(t, s, w);
  }
  cout << min_spanning_tree(g) << '\n';
}



Measured memory_bytes: 12504
#include<iostream>
#include<string>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::string;

int main(){
    string n;
    char p;
    cin >> n;
    p = n[n.length()-1];
    if(p=='2' || p=='4' || p=='5' || p=='7' || p=='9') cout << "hon";
    else if(p=='3') cout << "bon";
    else cout << "pon"; 
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
ll n,m,j,k,t,l,r;
ll a,b,c,d;
char A,B,C,X,Y,Z;
float ans,MAX,MIN=40,sum;
ll ax[8005];
char str[200050],bx[200050];

int main()
{
    ll i,s,x;
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
		ll flag=0;
		cin>>a>>b>>c>>k;
		if(a>=k) cout<<k<<endl;
		else if(a+b>=k) cout<<a<<endl;
		else cout<<a-(k-a-b)<<endl; 
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include<string.h>
int main(void){
    // Your code here!
    int n,dice[3][1000];
    scanf("%d",&n);
    int sum=0,flag=0;
    for(int i=1;i<=n;i++){
    scanf("%d%d",&dice[0][i],&dice[1][i]);
    if(dice[0][i]==dice[1][i]) sum++;
    else sum=0;
    if(sum==3) {flag =1;
    break;
    }
    }
    if(flag==1) printf("Yes\n");
    else printf("No\n");
    return 0;
    
}


Measured memory_bytes: 2100
s = int(input())
a = [s]
for i in range(1,100000):
    if a[i-1]%2==0:
        for j in range(len(a)):
            if (a[j]==a[i-1]//2):
                print(i+1)
                exit()
        a.append(a[i-1]//2)
    else:
        for j in range(len(a)):
            if (a[j]==a[i-1]*3+1):
                print(i+1)
                exit()
        a.append(a[i-1]*3+1)
print(a)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    ll n;
    cin >> n;
    ll fin=1;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0) {
            fin= i;
        }
    }
    cout << (fin-1)+(n/fin-1) << endl;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let it = stdin.lock().bytes().map(|c| c.unwrap() as char);
    let (fs, ft) = (|c: &char| c.is_whitespace(), |c: &char| !c.is_whitespace());
    let token = it.skip_while(fs).take_while(ft).collect::<String>();
    token.parse().ok().unwrap()
}
#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    f(std::io::BufWriter::new(out.lock()));
}
#[allow(unused_macros)]
macro_rules! debug {
    ($($var:expr),*) => { #[cfg(debug_assertions)] {
        $({ match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } })*
        eprintln!();
    }};
}

fn main() {
    let n: usize = input();
    let a: Vec<Vec<usize>> = (0..n)
        .map(|_| (0..n - 1).map(|_| input::<usize>() - 1).collect())
        .collect();

    let mut cur = vec![0; n];
    let mut q = vec![];

    for i in 0..n {
        enq(i, n, &mut q, &a, &cur);
    }

    let mut cnt = 0;
    let mut ans = 0;
    while q.len() > 0 {
        let mut nextq = vec![];
        q.sort();
        q.dedup();
        for &(i, j) in &q {
            cur[i] += 1;
            cur[j] += 1;
            enq(i, n, &mut nextq, &a, &cur);
            enq(j, n, &mut nextq, &a, &cur);
            cnt += 1;
        }
        ans += 1;
        q = nextq;
    }

    if cnt != n * (n - 1) / 2 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

fn enq(i: usize, n: usize, q: &mut Vec<(usize, usize)>, a: &Vec<Vec<usize>>, cur: &Vec<usize>) {
    if cur[i] == n - 1 {
        return;
    }
    let j = a[i][cur[i]];
    if a[j][cur[j]] == i {
        let (mut i, mut j) = (i, j);
        if i > j {
            std::mem::swap(&mut i, &mut j);
        }
        q.push((i, j));
    }
}


Measured memory_bytes: 12540
#include <stdio.h>
#include <stdlib.h>
int LCM (int a ,int b);
double GCD (int a, int b);

int main(int argc, char *argv[]) {
	int a, b,lcm;
	double gcd;
	while ((scanf("%d %d",&a,&b))!=EOF)	{
		lcm=LCM(a,b);
		printf("%d ",lcm);
		gcd=GCD(a,b);
	}
	return 0;
}
int LCM (int a ,int b)	{
	int k;
		while (a%b!=0)	{
			k=a%b;
			a=b;
			b=k;
		}
		return b;
	} 
double GCD (int a, int b)	{
	int l=LCM(a,b);
	double c,d;
	double answer;
	c=a/l;
	d=b/l;
	answer=c*d*l;
	printf("%.lf\n",answer);
}
	 


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

using namespace std;
int main()
{
    int x;
    cin>>x;
    int p=0;
    int i=0;
    for(int j=1;j<=x;j++){
        if(j%2==0){
            p++;
        }else{
            i++;
        }
    }
    cout<<p*i<<endl;
    return 0;
}


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


int main() {
  int A,B,C,D;
  cin >> A >> B>>C>>D;
  int sizeA = A*B;
  int sizeB = C*D;
  int ans = max(sizeA,sizeB);
  cout << ans << endl; 

  return 0;
}



Measured memory_bytes: 3544
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;

int main(void){
  string S;
  cin >> S;
  
  int size = S.size();
  string out;
  for(int i=0;i<size;i++){
    out += "x";
  }
  
  cout << out << endl;;
  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 rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int dist[100005][3];
int main() {
	int N,M;
	cin>>N>>M;
	vector<vector<int>> to(N);
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--;b--;
		to[a].push_back(b);
	}
	int sv,tv;
	cin>>sv>>tv;
	sv--;tv--;
	rep(i,N)rep(j,3) dist[i][j] = INF;
	queue<P> q;
	q.push({sv,0});
	dist[sv][0] = 0;
	while(!q.empty()){
		int v = q.front().first;
		int l = q.front().second;
		q.pop();
		for(int u: to[v]){
			int nl = (l+1)%3;
			if(dist[u][nl]!=INF)continue;
			dist[u][nl] = dist[v][l] + 1;
			q.push({u,nl});
		}
	}
	int ans = dist[tv][0];
	if(ans == INF)ans = -1;
	else ans /= 3;
	cout<<ans<<endl;
}

Measured memory_bytes: 6912
#include <stdio.h>
#include <string.h>
 
int main(){
	
	char S[255];
	int k;
	scanf("%d", &k);
	scanf("%s", &S);
	for(int i = 0; i < strlen(S); i++){
	}
	if( k > 255 ||  k < 1){
		return 0;
	}
	if (k >= strlen(S)){
		printf("%s", S);
	}else if (k < strlen(S)){
		for( int i =0; i < k; i++){
			printf("%c", S[i]);
		}
		printf("...");
	}
	return 0;
}

Measured memory_bytes: 1716
N = int(input())
As = [0]+list(map(int, input().split()))+[0]

rlt = 0
lst = []

for i in range(N+1):
  rlt += abs(As[i+1]-As[i])
  
for i in range(1,N+1):
  print(rlt-abs(As[i]-As[i-1])-abs(As[i+1]-As[i])+abs(As[i+1]-As[i-1]))


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

int main() {
  int N,M,R;
  cin >> N >> M;
  R = 2*M;
  
  vector<int> a(R);
  for(int i=0; i<R; i++)
    cin >> a.at(i);
  
  for(int i=0; i<N; i++){
    int sum=0;
    for(int j=0; j<R; j++){
    	if (a.at(j)==i+1)
      		sum++;
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int32_t main(){
	string s;
	cin>>s;
	if(s=="hi" || s=="hihi" || s=="hihihi" || s=="hihihihi" || s=="hihihihihi"){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
}


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    handle.read_line(&mut buf).unwrap();
    let info: Vec<usize> = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
    let (n, h, w) = (info[0], info[1], info[2]);
    buf.clear();
    let mut count = 0;

    for i in 0..n {
        handle.read_line(&mut buf).unwrap();
        let board: Vec<usize> = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
        if board[0] >= h && board[1] >= w {
            count += 1;
        }
        buf.clear();
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> x(n),y(n);
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>x.at(i)>>y.at(i);
auto dist=[&](int i,int j){
  int dx=x.at(i)-x.at(j);
  int dy=y.at(i)-y.at(j);
  double res=dx*dx+dy*dy;
  return pow(res,0.5);
};
  for(int i=0;i<n;i++)v.at(i)=i;
  double sum=0;
  int cnt=0;
  do{
    cnt++;
    for(int i=0;i<n-1;i++)sum+=dist(v.at(i),v.at(i+1));
  }while(next_permutation(v.begin(),v.end()));
  cout<<fixed<<setprecision(10)<<sum/cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = []
b_list = list(map(int, input().split()))

for i, bi in enumerate(b_list):
    if i == 0:
        a_list.append(bi)
    elif b_list[i] > b_list[i-1]:
        a_list.append(b_list[i-1])
    else:
        a_list.append(b_list[i])

a_list.append(b_list[-1])

print(sum(a_list))

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

int main(int argc, const char * argv[]) {
    // insert code here...
    string a, b, c;
    cin >> a >> b >> c;
    
    int abc = 0;
    string winner;
    while (true) {
        
        if (abc == 0) {
            if (a.size() == 0) {
                winner = "A";
                break;
            }
            else if (a.at(0) == 'a') {
                a.erase(a.begin());
                abc = 0;
            }
            else if (a.at(0) == 'b') {
                a.erase(a.begin());
                abc = 1;
            }
            else if (a.at(0) == 'c') {
                a.erase(a.begin());
                abc = 2;
            }
        }
        
        else if (abc == 1) {
            if (b.size() == 0) {
                winner = "B";
                break;
            }
            else if (b.at(0) == 'a') {
                b.erase(b.begin());
                abc = 0;
            }
            else if (b.at(0) == 'b') {
                b.erase(b.begin());
                abc = 1;
            }
            else if (b.at(0) == 'c') {
                b.erase(b.begin());
                abc = 2;
            }
            
        }
        
        else if (abc == 2) {
            if (c.size() == 0) {
                winner = "C";
                break;
            }
            else if (c.at(0) == 'a') {
                c.erase(c.begin());
                abc = 0;
            }
            else if (c.at(0) == 'b') {
                c.erase(c.begin());
                abc = 1;
            }
            else if (c.at(0) == 'c') {
                c.erase(c.begin());
                abc = 2;
            }
            
        }
        
    }
    
    cout << winner << endl;
    
    /*a = "";
    cout << a.size() << endl;*/
    
    /*b = "ABC";
    b.erase(b.begin());
    cout << b << endl;*/
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n<1200){cout<<"ABC"<<endl;}
  else cout<<"ARC"<<endl;
}

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

int main() {
  int N, T;
  cin >> N >> T;
  auto c = vector<int>(N);
  auto t = vector<int>(N);
  for (int i = 0; i < N; ++i) cin >> c[i] >> t[i];

  int ans = 1e9;
  for (int i = 0; i < N; ++i) {
    if (t[i] > T) continue;
    ans = min(ans, c[i]);
  }
  cout << ( (ans == 1e9) ? "TLE" : to_string(ans) ) << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.19 01:45:50
**/

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

int main() {
    int n,m;cin >> n >> m;
    int now_l = 1, now_r = n;
    vector<bool> used(n,false);
    while(m > 0) {
        int d = now_r - now_l;
        if (used[d] || used[n-d]) {
            now_r--;
            continue;
        }
        if (2 * d == n) {
            now_r--;
            continue;
        }
        used[d] = true;
        cout << now_l << " " << now_r << endl;
        m--;
        now_r--;
        now_l++;
    }
    
    return 0;
}

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

int main(){
    int n, i, p, j, k;
    cin >> n;
    
    int list[101] = {};
    
    for(i = 0; i < n; i++){
        cin >> p;
        list[i] = p;
    }
    
    for(i = 0; i < n; i++){
        p = list[i];
        j = i - 1;
        while(j >= 0 && list[j] > p){
            list[j+1] = list[j];
            j--;
        }
        list[j+1] = p;
        for(k = 0; k < n; k ++){
            cout << list[k];
            if(k == n-1) cout << endl;
            else cout << " " ;
        }
    }
    
}



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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,b,t;
	double f;
	cin>>n;
	b=100, f=100.00; t=0;
	while(1) {
		t++;
		f=f*(1.01);
		b=f;
		f=b;
		if(b>=n) {
			cout<<t;
			break;
		}
	}
}

Measured memory_bytes: 3652
N,A,B,C,D = list(map(int,input().split()))
s = list(input())

if C < D:
	judge = 0
	for i in range(B,D-1):
		if s[i] == "#" and s[i+1] ==  "#":
			judge = 1
	for i in range(A,C-1):
		if s[i] == "#" and s[i+1] == "#":
			judge = 1
	if judge == 1:
		print("No")
	else:
		print("Yes")
		exit()
		
if C > D:
	judge = 0
	judge1 = 0
	for i in range(B,D-1):
		if s[i] == "#" and s[i+1] == "#":
			judge = 1
	for i in range(B-2,D-1):
		if s[i] == "." and s[i+1] == "." and s[i+2] == ".":
			judge1 = 1
	if judge1 == 0:
		judge = 1
	for i in range(A,C-1):
		if s[i] == "#" and s[i+1] == "#":
			judge = 1
	if judge == 1:
		print("No")
	else:
		print("Yes")
		exit()


Measured memory_bytes: 4916
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c,x;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    x = a + b + c;
    if(x>21){
        printf("bust");
    }
    else printf("win");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main (void)
{
   int x, a, h, m, s;
   scanf("%d", &x);
   h = x/3600;
   a = x % 3600;
   m = a/60;
   s = a % 60;
   printf("%d:%d:%d\n", h, m, s);
   return 0;
}

Measured memory_bytes: 592
N = int(input())
A = list(map(int,input().split()))

f = 0
for a in range(len(A)):
  if A[a] % 2 != 0:
    continue
  else:
    if A[a] % 3 != 0 and A[a] % 5 != 0:
      f = 1
      break
      
if f == 1:
  print('DENIED')
else:
  print('APPROVED')

Measured memory_bytes: 3064
n,m=map(int,input().split())
a=list(map(int,input().split()))
l=[]
for i in range(n):
    l.append((a[i],1))
for i in range(m):
    b,c=map(int,input().split())
    l.append((c,b))
l=sorted(l,reverse=True) #
ans,cnt=0,n
for x,y in l:
    dy=min(y,cnt) #
    dx=dy*x
    ans+=dx
    cnt-=dy #
print(ans)
#ABC127D

Measured memory_bytes: 30456
a = []
for rep in range(3):
	a.append(list(map(int,input().split())))
n = int(input())
b = []
for rep in range(n):
    b.append(int(input()))
row = [0,0,0]
col = [0,0,0]
mid = 0
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            row[i] += 1
            col[j] += 1
            if i==1 and j==1:
                mid = 1
f = 1
for rep in range(3):
    if row[rep]==0 or col[rep]==0:
        f = 0
        break
if 3 in row or 3 in col:
    print("Yes")
elif f == 1 and mid == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main() {
	int H, W;

	cin >> H >> W;

	for (int i = 0 ; i < W + 2 ; i++ ) {
		cout << '#';
	}

	cout << endl;

	for (int i = 0 ; i < H ; i++ ) {
		vector<char> line(W);

		for (int j = 0 ; j < W ; j++ ) {
			cin >> line.at(j);
		}

		cout << '#';

		for (int j = 0 ; j < W ; j++ ) {
			cout << line.at(j);
		}

		cout << '#' << endl;
	}

	for (int i = 0 ; i < W + 2 ; i++ ) {
		cout << '#';
	}

	cout << endl;
}

Measured memory_bytes: 256
def yaku(N):
    n=N[0]
    li=[]
    for i in range(5):
        li.append(n)
        n +=1
    if N==li or N==[1,10,11,12,13]:
        print("straight")
        return
    mp={}
    count_2=0
    count_3=0
    for i in N:
        if i in mp:
            mp[i] +=1
        else:
            mp[i]=1
    co=0
    for k,v in mp.items():
        if v!=1:
            if v==2:
                count_2 +=1
            elif v==3:
                count_3 +=1
            else:
                print("four card")
                return
        else:
            co +=1
            if co==5:
                print("null")
                return
    if count_2==1 and count_3==1:
        print("full house")
    elif count_3==1:
        print("three card")
    elif count_2==2:
        print("two pair")
    elif count_2==1:
        print("one pair")
        
while True:
    try:
        N=sorted(list(map(int,input().split(","))))
        yaku(N)
    except:break



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
//using namespace std::chrono;
#define int long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<ld,ld>
#define M 1000000007
#define rep(a,b,c) for(int a=b;a<c;a++)
#define frev(a,b,c) for(a=b;a>=c;a--)
#define msb(x) __builtin_clz(x)
#define lsb(x) __builtin_ctz(x)
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define endl '\n'

void solve(){

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

}
int32_t main(){
   //

  //  cout<<fixed<<setprecision(10);
    //auto start = high_resolution_clock::now();
    int t=1;
    //cin>>t;
    while(t--) solve();
  //  auto stop = high_resolution_clock::now();
    //auto duration = duration_cast<microseconds>(stop - start);
    //cout << duration.count() << endl;
}


Measured memory_bytes: 3916
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int MIN = 10000000;
static const int WH = 0;
static const int GR = 1;
static const int BL = 2;

int n;
vector<pair<int,int> > ad[MAX];

void dijkstra(void){
  priority_queue<pair<int,int> > PQ;
  int color[MAX],d[MAX],i,j,v;
  for(i=0;i<n;i++){
    d[i]=MIN;
    color[i]=WH;
  }
  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0]=GR;

  while(!PQ.empty()){
    pair<int,int> f=PQ.top(); PQ.pop();
    int u=f.second;
    color[u]=BL;
    if(d[u]<f.first*(-1))continue;
    for(j=0;j<ad[u].size();j++){
      v=ad[u][j].first;
      if(color[v]==BL) continue;
      if(d[v]>d[u]+ad[u][j].second){
	d[v]=d[u]+ad[u][j].second;
	PQ.push(make_pair(d[v]*(-1),v));
	color[v]=GR;
      }
    }
  }
  for(i=0;i<n;i++) cout<< i << " " << (d[i]==MIN ? -1:d[i]) << endl;
}

int main(void){
  int i,j,m,l,k,c;

  cin>>n;
  for(i=0;i<n;i++){
    cin>> m >> l;
    for(j=0;j<l;j++){
      cin >> k >> c;
      ad[m].push_back(make_pair(k,c));
    }
  }
  dijkstra();
  return 0;
}



Measured memory_bytes: 8092
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template <size_t I, class H, class... T> struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template <class H, class... T> struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template <class... T> istream& operator>>(istream&i,tuple<T...>& t) { t = TupleReaderWriter<sizeof...(T), T...>::r(i); return i; }
template <class... T> ostream& operator<<(ostream& o, tuple<T...>& t) { string delim = " "; TupleReaderWriter<sizeof...(T) - 1, T...>::w(o, t, delim); return o; }
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

// 二分探索（改）
// judge を満たすような下限を求める
// left:[X] 定義域の下限
// right:[X] 定義域の上限
// judge:[X -> bool] X を評価する関数
// lower:[bool] falseにすると代わりに上限を求める
// eps:[X] 終了距離

template <typename X>
X BinSearch(X left, X right, function<bool(X)> judge, bool lower = true, X eps = 1) {
    while (right - left > eps) {
        X mid = (right + left) / 2;
        if (judge(mid) == lower) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return lower ? right : left;
}

int64_t divceil(int64_t a, int64_t b) {
    return a / b + (a > 0 && a % b ? 1 : 0);
}

int main() {
    i64 N, K;
    cin >> N >> K;
    vector<i64> A(N), F(N);
    for(auto &x : A) cin >> x;
    for(auto &x : F) cin >> x;
    sort(WHOLE(A));
    sort(REV_WHOLE(F));

    i64 ans = BinSearch<i64>(-1, 1e16, [&](i64 T) -> bool {
        i64 k = 0;
        for(int i = 0; i < N; i++) {
            k += max<i64>(0, A[i] - T / F[i]);
        }
        return k <= K;
    }, true);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328