akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let h: usize = sc.cin();
    let w: usize = sc.cin();
    let mut wall = vec![vec![true; w + 2]; h + 2];
    for i in 0..h {
        let cs: Vec<char> = sc.cin::<String>().chars().collect();
        for j in 0..w {
            if cs[j] == '.' {
                wall[i+1][j+1] = false;
            }
        }
    }

    let mut yoko = vec![vec![0; w + 2]; h + 2];
    let mut tate = vec![vec![0; w + 2]; h + 2];

    for i in 0..h+2 {
        for j in 0..w+2 {
            if wall[i][j] { continue }
            yoko[i][j] = yoko[i][j-1] + 1;
            tate[i][j] = tate[i-1][j] + 1;
        }
    }
    for i in (0..h+2).rev() {
        for j in (0..w+2).rev() {
            if wall[i][j] { continue }
            yoko[i][j] = max(yoko[i][j], yoko[i][j+1]);
            tate[i][j] = max(tate[i][j], tate[i+1][j]);
        }
    }
    // for i in 0..h+2 { trace!(&yoko[i]);}
    // for i in 0..h+2 { trace!(&tate[i]);}

    let mut ans = 0;
    for i in 0..h+2 {
        for j in 0..w+2 {
            if wall[i][j] { continue }
            ans = max(ans, yoko[i][j] + tate[i][j] - 1);
        }}
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 41212
#include<stdio.h>

int main(){
  char S[26]={};
  char c[26]={};
  int i,j;
  int flag=0;
  scanf("%s",S);
  for(i=0;S[i]!='\0';i++){
    c[i]=S[i];
    for(j=0;j<=i;j++){
      if(j!=i && S[i]==c[j]){
	flag=1;
	break;
      }
    }
  }
  if(flag==1){
    printf("no\n");
  }else{
    printf("yes\n");
  }
  return 0;
} 


Measured memory_bytes: 128
a, b = map(int, input().split())
power = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
 
a = power.index(a)
b = power.index(b)
 
if a > b:
    print('Alice')
elif a < b:
    print('Bob')
elif a == b:
    print('Draw')

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

using namespace std;

int main()
{
    int a[9];

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

    int n;
    cin >> n;

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    bool c[9] = {false};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 9; j++) {
            if (b[i] == a[j]) {
                c[j] = true;
            }
        }
    }

    bool ans = false;

    ans =  (c[0] && c[1] && c[2])
        || (c[3] && c[4] && c[5])
        || (c[6] && c[7] && c[8])
        || (c[0] && c[3] && c[6])
        || (c[1] && c[4] && c[7])
        || (c[2] && c[5] && c[8])
        || (c[0] && c[4] && c[8])
        || (c[2] && c[4] && c[6]);

    if (ans == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define all(s0) s0.begin(),s0.end()
#define ins(s0) inserter(s0,s0.begin())
using namespace std;
ll read()
{
    char ch=getchar();
    ll x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
    ll n,m,a[10005];
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        a[i]=read();
        n-=a[i];
    }
    if(n<0)
        cout<<"-1"<<endl;
    else
        cout<<n<<endl;
    return 0;
}


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

void printa(int w) {
	while(w--) {
		cout<<"#";
	}
	cout<<endl;
}

void printb(int w) {
	w-=2;
	cout<<"#";
	while(w--) {
		cout<<".";
	}
	cout<<"#"<<endl;
}

int main() {
	int h,w;
	while(cin>>h>>w,h) {
		h-=2;
		printa(w);
		while(h--) {
			printb(w);
		}
		printa(w);
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
int main(){
IOS;
lli n,i,j,k;
cin>>n;
lli a[n];
for(i=0;i<n;i++){
    cin>>a[i];
}
for(i=0;i<n;i++){
    if(a[i]!=i+1)
        break;
}
if(i==n){
    cout<<"YES"<<endl;
    return 0;
}
for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
        swap(a[i],a[j]);
        for(k=0;k<n;k++){
            if(a[k]!=k+1)
                break;
        }
        if(k==n){
            cout<<"YES"<<endl;
            return 0;
        }
        swap(a[i],a[j]);
    }
}
cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	double xs[2], ys[2], eqs[2];
	double x, y;

	while (~scanf("%lf %lf %lf %lf %lf %lf", xs, ys, eqs, xs + 1, ys + 1, eqs + 1)){
		x = (eqs[0] * ys[1] - eqs[1] * ys[0]) / (xs[0] * ys[1] - xs[1] * ys[0]);
		y = (eqs[1] * xs[0] - eqs[0] * xs[1]) / (xs[0] * ys[1] - xs[1] * ys[0]);

		if (x == 0.0) x = 0.0;
		if (y == 0.0) y = 0.0; 

		printf("%.3lf %.3lf\n", x, y);
	}

	return (0);
}

Measured memory_bytes: 648
#include<iostream>
main()
{
	int c=0,k,s,i,j;
	std::cin>>k>>s;
	for(i=0;i<=k;i++)
		for(j=0;j<=k;j++)
			if(s-i-j>=0&&s-i-j<=k)c++;
	std::cout<<c;
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
ab = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
cd = [set([]) for i in range(n)]
for i in range(k):
    c,d = map(int,input().split())
    cd[c-1].add(d-1)
    cd[d-1].add(c-1)
    
ans = [0 for i in range(n)]
data = [0 for i in range(n)] #見たら1
for i in range(n): #自分がi
    if(data[i] != 0): #もう見てたら必要なし
        continue
    data[i] = 1 #iの人を見る
    data2 = ab[i] + [i]
    data2 = set(data2)
    for j in ab[i]:
        data[j] = 1
    new_friends = [ab[i]]
    for fris in new_friends:
        new = [] #次の深さのリスト
        for fri in fris: #この層の友人を１人選ぶ
            for frfr in ab[fri]: #その友人の友人
                if(data[frfr] == 0): #見てなかったら加える
                    data[frfr] = 1 
                    new.append(frfr) #次の深さのリストに足す
                    data2.add(frfr) #グラフに足す
        if(len(new)==0):
            break
        else:
            new_friends.append(new)

    sam = len(data2)
    for j in data2:
        count = sam
        ans[j] = count - len(ab[j]) - len(cd[j] & data2) - 1 #自分と友達を除く


print(*ans)

Measured memory_bytes: 72400
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

const M: usize = 1_000_000_007;

fn main() {
    input! {
        k: chars,
        d: usize,
    }
    let mut dp = vec![vec![vec![0; 2]; 100]; k.len() + 1];
    dp[0][0][0] = 1;

    for pos in 0..k.len() {
        for m in 0..d {
            for is_less in 0..2 {
                for nd in 0..10 {
                    let nm = (m + nd) % d;
                    let digit = k[pos] as usize - '0' as usize;
                    if nd > digit && is_less == 0 {
                        continue;
                    }
                    if nd < digit {
                        dp[pos + 1][nm][1] += dp[pos][m][is_less];
                        dp[pos + 1][nm][1] %= M;
                    } else {
                        dp[pos + 1][nm][is_less] += dp[pos][m][is_less];
                        dp[pos + 1][nm][is_less] %= M;
                    }
                }
            }
        }
    }
    let mut ans = dp[k.len()][0].iter().sum::<usize>() % M;
    ans = (ans + M - 1) % M;
    println!("{}", ans);
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll X, Y;
    cin >> X >> Y;
    ll x = X;
    ll ans = 0;
    while (x <= Y) {
        x *= 2LL;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm> // sort
#include <map>       // pair
#include <vector>
using namespace std;

#define REP(a,b) for(int i =(a);i < (b);i++)
#define FOR(n) for(int i = 0; i<(n); i++)
#define COUT(c)  cout<<(c)<<endl


const int INF = 100100100;
const int MOD = (int)1e9 +7;
const double EPS = 1e-9; 

typedef long long int ll;

//char in[120];
//ex. pair
//pair<pair<string,int>,int> p[110];

int main(){
    ll n;cin>>n;
    if(n <2){
        cout<<0<<endl;
    }
    else{
        cout << (n-1)*(n)/2 << endl;
    }
    return 0;    
}

Measured memory_bytes: 256
<?php
 
fscanf(STDIN, "%d", $N);

$sum= 0;
for ($i = 1; $i <= $N; $i++) {
  if ($i % 3 === 0 || $i % 5 === 0 || $i % 15 === 0) {
    continue;
  }
  $sum += $i;
}
echo $sum;

Measured memory_bytes: 16164
#include<stdio.h>

int main(void)
{
	int n, p;
	int i, t, k;
	int num[1000][50];
	int wan[1000];
	int ans[1000];
	int lose;
	int change;
	for (i = 0; i < 1000; i++)
	{
		lose = 0;
		scanf("%d %d", &n, &p);
		if (n == 0 && p == 0)
		{
			break;
		}
		for (t = 0; t < n; t++)
		{
			num[i][t] = 0;
		}
		wan[i] = p;
		while (1)
		{
			if (lose == n - 1)
			{
				break;
			}
			
			for (t = 0; t < n; t++)
			{
				lose = 0;
				if (wan[i] == 0)
				{
				
					if (num[i][t] == 0)
					{
						continue;
					}
					else if (num[i][t] != 0)
					{
					
						change = num[i][t];
						wan[i] = change;
						num[i][t] = 0;
						continue;
					}
				}

				wan[i]--;
				num[i][t]++;
				if (wan[i] == 0)
				{
					for (k = 0; k < n; k++)
					{
						if (num[i][k] == 0)
						{
							lose++;
						}
					
					}
				}
				if (lose == n - 1)
				{
					break;
				}
			}
		}
		for (t = 0; t < n; t++)
		{
			if (num[i][t] != 0)
			{
				ans[i] = t;
				if (ans[i] == -1)
				{
					ans[i] = n - 1;
				}
			}
		}
	}
	for (k = 0; k < i; k++)
	{
		printf("%d\n", ans[k]);
	}
	return 0;
}


Measured memory_bytes: 2624
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define F first
#define S second

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
//#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;
/*
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;cin>>n>>k;
    if(n>=10){
        cout<<k<<"\n";
    }
    else{
        cout<<k+(100*(10-n))<<"\n";
    }
    return 0;
}
*/
/*
void findNumberOfDigits(long n, int base)
{

	int dig = (int)(floor( log(n) /
						log(base)) + 1);

	// printing output
	cout<< dig;
}

// Driver method
int main()
{

	long n ;
	int base ;
	cin>>n>>base;

	findNumberOfDigits(n, base);
	return 0;
}
*/


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    std::vector<int> v(n);
    ll int sum = 0 ;
    for (size_t i = 0; i < n; i++) {
        cin>>v[i];
        sum += v[i];
    }
    ll int p1 = ceil((double)sum/n) , p2 = floor((double)sum/n),ans1 = 0,ans2 = 0;
    for (size_t i = 0; i < n; i++) {
        ans1 += abs((ll)(v[i] - p1)*(ll)(v[i] - p1));
        ans2 += abs((ll)(v[i] - p2)*(ll)(v[i] - p2));

    }
    cout<<min((ll)ans1 , (ll)ans2)<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using P = pair<int,int>;
int absi(int x){
  return int(abs(x));
}
int main(){
  int D,n,m,p1,p2;
  cin >> n >> m;
  vector<P> DaN(n);
  vector<P> sts(n);
  for(int i=0;i<n;i++){
    cin >> sts[i].first >> sts[i].second;
    DaN[i].first = 1e9;
    DaN[i].second = 0;
  }
  for(int i = 0;i<m;i++){
    cin >> p1 >> p2;
    for(int j=0;j<n;j++){
      D = absi(p1-sts[j].first)+absi(p2-sts[j].second);
      if(D<DaN[j].first){
        DaN[j].first = D;
        DaN[j].second = i;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << DaN[i].second+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  const Int MOD = 1e9+7;
  Int n;
  cin>>n;
  vector<Int> cnt(n+1);
  for(Int i=1;i<=n;i++){
    Int b=i;
    for(Int j=2;j<=n;j++)
      while(b%j==0) b/=j,cnt[j]++;
  }
  Int ans=1;
  for(Int i=2;i<=n;i++) ans=ans*(cnt[i]+1)%MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

int main()
{
    int n, k;
    std::cin >> n >> k;

    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (ans < k) {
            ans *= 2;
        } else {
            ans += k;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 100
#define MAX_V 200
#define INF 1e9
 
int V,match[MAX_V];
vector<int> G[MAX_V];
bool used[MAX_V];
 
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}
 
bool dfs(int v){
  used[v] = true;
  for(int i = 0 ; i < (int)G[v].size() ; i++){
    int u = G[v][i],w = match[u];
    if(w < 0 || (!used[w] && dfs(w))){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(){
  int res = 0;
  memset(match,-1,sizeof(match));
  for(int v = 0 ; v < V ; v++){
    if(match[v] < 0){
      memset(used,false,sizeof(used));
      if(dfs(v)){ res++; }
    }
  }
  return res;
}
 
int main(){
    int N,a,b;
    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> a >> b; a--; b--;
        for(int j = a ; j <= b ; j++){
            add_edge(j,i+31);
        }
    }
    V = N + 31;
    int K = bipartite_matching();
    cout << 50*(31-K)+100*K << endl;
    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#include<iostream>
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BP(n) __builtin_popcount(n)
#define bs(v,x) binary_search(all(v),x)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(j,n) for (j=i+1;j<n;j++)
#define Unique(v) vector<int>::iterator it; sort(all(v)); it= unique(all(v)); v.resize(distance(v.begin(),it))
#define mod 1000000007
#define PI acos(-1.0)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) 
using namespace std;
void input(vector<ll>& v,ll n){ ll i,io; rep(i,n) { cin>>io; v.pb(io);} }
void output(vector<ll> v) { ll i; rep(i,v.size()) cout<<v.at(i)<<" "; }
map<ll,ll>  frequency(vector<ll> v){ ll i; map<ll,ll> m; rep (i,v.size()) {  if (m.find(v[i])==m.end()) m.insert({v.at(i),1}); else m[v.at(i)]++; } return m; }
/*bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(int n) { if (n&(n-1)==0) return true; else return false; }
bool binary_pred(int a,int b){ return a==b; }*/
int main() {
	fastio;
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	ll i,j,k,n,ans = 0;
	cin>>n;
	vector<ll> v,test;
	input(v,n);
	sort(all(v));
	if (v.size() <= 2) 
		cout<<0<<endl;
	else {
		rep(i,n) {
			rep1(j,n) {
				for (k=j+1;k<n;k++) {
					if (v[i] != v[j] and v[j] != v[k] and v[i] != v[k] and v[i] + v[j] > v[k]) {
						ans++;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}




Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[50][3][2], b[3][2][2];
vector<int> vs[3];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n){
		rep(j,3)rep(k,2)rep(l,2)scanf("%lld", &b[j][k][l]);
		rep(j,3)rep(k,2)a[i][j][k] = 60*b[j][k][0]+b[j][k][1];
		rep(j,3)vs[j].pb(a[i][j][1]);
	}
	rep(i,3)ZIP(vs[i]);
	
	int ans = 0;
	rep(i,vs[0].size())rep(j,vs[1].size())rep(k,vs[2].size()){
		int t[3] = {vs[0][i], vs[1][j], vs[2][k]}, res = 0;
		rep(i,n){
			int f = 1;
			rep(j,3)if(a[i][j][0] > t[j] or t[j] > a[i][j][1])f = 0;
			res += f;
		}
		chmax(ans, res);
	}
	printf("%lld\n", ans);
	return 0;
}







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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

void solve(){

	ll n,ans=0;
	cin>>n;
	vll A(n);for(int i=0;i<n;i++) cin>>A[i];
	for(int i=0;i<n;) {
		int j=i;
		while(j+1<n && A[j]>=A[j+1]){
			j++;
		}
		ans=max(ans,j-i*1LL);
		i=j+1;
	}
	cout<<ans<<"\n";

}


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

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    string s,t;
    cin>>s>>t;
    int ans=0;
    if(s[0]==t[0])ans++;
    if(s[1]==t[1])ans++;
    if(s[2]==t[2])ans++;
    fin(ans);

//////////////////////////////////////////////////////
return 0;}

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

int main(void){
    long a, b, c, d;
    std::cin >> a >> b >> c >> d;
    std::cout << (long)std::max(a * c, std::max(a * d, std::max(b * c, b * d))) << std::endl;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e6 + 20;
int dp[maxn];
void work() {
    int n, t;
    scanf("%d%d", &n, &t);
    if (n == 1) while(1);
    int mi = (1LL << 31) - 1;
    int mx = -((1LL << 31) - 1);
    for (int i = 1; i <= n; ++i) {
        int x;
        scanf("%d", &x);
        dp[i] = max(0, x - mi);
        mi = min(mi, x);
        mx = max(mx, dp[i]);
    }
    int tim = 0;
    for (int i = 1; i <= n; ++i) {
        tim += dp[i] == mx;
    }
    int ans = tim;
    cout << ans << endl;
}

int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    work();
    return 0;
}

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

int N, Q;
vector<vector<int>> tree;  //関係を保存する
vector<long long> px;
vector<bool> used;

void dsf(int n, long long ncn){
  if(!used[n]){
    used[n] = true;
    px[n] += ncn;
    for(int i = 0; i < tree[n].size(); i++){ 
      if(!used[tree[n][i]])
        dsf(tree[n][i], px[n]); 
    }
  }
  return;
}


int main(){
  cin >> N >> Q;
  tree.resize(N+1);   //頂点木
  px.resize(N+1, 0);  //カウンター
  used.resize(N+1, false);  //利用したか否か

  int a, b;
  for(int i = 0; i < N-1; i++){
    cin >> a >> b; tree[a].push_back(b); tree[b].push_back(a);
  }

  int p, x;
  for(int i = 0; i < Q; i++){
    cin >> p >> x; px[p] += x;  //カウンター計算
  }

  dsf(1, 0);
  for(int i = 1; i < px.size(); i++) cout << px[i] << " ";
  cout << endl; return 0;

}



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

if N%4==0:
  print('Yes')
elif N%4==1:
  if N>=21:
    print('Yes')
  else:
    print('No')
elif N%4==2:
  if N>=14:
    print('Yes')
  else:
    print('No')
elif N%4==3:
  if N>=7:
    print('Yes')
  else:
    print('No')

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

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    ll n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007
unsigned long long dp[100001][13];
int main() {
    char s[100001];
    int i;
    dp[0][0] = 1;
    scanf("%s", s);
    for (i = 0; s[i] != '\0'; ++i) {
        if (s[i] == '?') {
            for (int j = 0; j < 13; ++j)
                for (int k = 0; k < 10; ++k)
                    dp[i+1][(j*10+k)%13] += dp[i][j];
        } else {
            for (int j = 0; j < 13; ++j)
                dp[i+1][(j*10+s[i]-'0')%13] += dp[i][j];
        }
        for (int j = 0; j < 13; ++j)
            dp[i+1][j] %= MOD;
    }
    printf("%llu", dp[i][5]);
    return 0;
}

Measured memory_bytes: 10368
#include <cstdio>
#include <vector>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;

int op(int a, int b) { return max(a, b); }
int e() { return -1e+9; }

int target;
bool f(int v) { return v < target; }

int main() {
	int n, q;
	scanf("%d%d", &n, &q);

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	segtree<int, op, e> seg(a);

	for (int i = 0; i < q; i++) {
		int t;
		scanf("%d", &t);
		if (t == 1) {
			int x, v;
			scanf("%d%d", &x, &v);
			x--;
			seg.set(x, v);
		}
		else if (t == 2) {
			int l, r;
			scanf("%d%d", &l, &r);
			l--;
			printf("%d\n", seg.prod(l, r));
		}
		else if (t == 3) {
			int x;
			scanf("%d%d", &x, &target);
			x--;
			//A[i] >= vなる最小のi (ただしi >= x)
			printf("%d\n", seg.max_right(x, f) + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 5660
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 55;

int n, m;
vector <ii> neigh[Maxn];
bool tk[Maxn];

void Traverse(int v, int forb)
{
	if (tk[v]) return;
	tk[v] = true;
	for (int i = 0; i < neigh[v].size(); i++) {
		ii u = neigh[v][i];
		if (u.second == forb) continue;
		Traverse(u.first, forb);
	}
}

bool Con(int forb)
{
	fill(tk, tk + Maxn, false);
	Traverse(1, forb);
	for (int i = 1; i <= n; i++)
		if (!tk[i]) return false;
	return true;
}

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(ii(b, i));
		neigh[b].push_back(ii(a, i));
	}
	int res = 0;
	for (int i = 0; i < m; i++)
		if (!Con(i)) res++;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  bool ans = false;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      if(n == (i*j)){
        ans = true;
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
r,c = map(int,input().split())

a = [0 for i in range(r)] 

for i in range(r):
    a[i] = list(map(int,input().split()))
    
    a[i] += [sum(a[i])]
    
    print(*a[i])

b = []

for i in range(0,c+1):
    x=[]
    for j in range(0,r):
        x.append(a[j][i])
    
    b.append(sum(x))

print(*b)   


Measured memory_bytes: 5716
-- fo "http://abc060.contest.atcoder.jp/tasks/abc060_a"

import Data.List
import Control.Applicative

main = do
  input <- getLine
  let inputWords = words input
      a = inputWords !! 0
      b = inputWords !! 1
      c = inputWords !! 2
  case (  (last a) == (head b) ) && ( (last b) == (head c)) of
    True -> putStr "YES"
    False -> putStr "NO"
        


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

int n,p,t;
deque<int> q;

int main()
{
	scanf("%d",&n);
	p = 1;
	if(n&1)	p ^= 1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&t);
		if(p&1)	q.push_back(t);
		else q.push_front(t);
		p ^= 1;
	}
	while(!q.empty())
	{
		printf("%d ",q.front());
		q.pop_front();
	}
	return 0;
}


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

using namespace std;

#define mod 1000000007
#define int int64_t
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)


void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t<<endl;
}

int32_t main()
{
    fio;
    int t;
    // cin>>t;
    t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 3628
#include <stdio.h>

int main() {

  int n,i,age;
  int a[7];
  
  while(1){
    for(i = 0; i < 7; i++){
      a[i] = 0;
    }
 scanf ("%d",&n);
  if( n == 0)
    return 0;
  
  
   for(i = 0; i < n; i++){
    scanf("%d",&age);
    if(0 <= age && age < 10)
      a[0]++;
    if(10 <= age && age < 20)
     a[1]++;
   if(20 <= age && age < 30)
     a[2]++;
   if(30 <= age && age < 40)
     a[3]++;
   if(40<= age && age < 50)
     a[4]++;
   if(50 <= age && age < 60)
     a[5]++;
   if(60 <= age)
     a[6]++;
  }
   for(i = 0; i < 7; i++){
     printf("%d\n",a[i]);
   }
  }

  return 0;
}

Measured memory_bytes: 404
def main():
    s = input()[::-1]

    sum_of_digits = 0

    cnts = [0] * 2019

    cnts[0] = 1

    d = 1

    for i in range(len(s)):
        sum_of_digits += int(s[i]) * d
        d *= 10
        d %= 2019
        sum_of_digits %= 2019
        cnts[sum_of_digits] += 1


    ans = 0

    for cnt in cnts:
        ans += cnt * (cnt - 1) // 2

    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
    int n, x;
    cin >> n >> x;
    int a = 1000000;
    int ans = n;
    rep(i, n){
        int m;
        cin >> m;
        a = min(a, m);
        x -= m;
    }
    cout << ans + x / a << endl;
}


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

int main() {
  int a,b,x = 0;
  cin >> a >> b ;
  x = (a+b)/2;
  if((a+b)%2 == 0){
    cout << x << endl;
  }else{
    cout << x+1 << endl;
  }
}

Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
    ($line:expr,$name:ident,$t:tt) => {
        let $name=value!($line,$t);
    };
    }

    macro_rules! values_def {
    ($lines:expr,$n:expr,$name:ident,$t:tt) => {
        let $name={
        let mut vec=Vec::new();
        for i in 0..$n{
            let mut next=$lines.next().unwrap().split_whitespace();
            vec.push(value!(next,$t));
        }
        vec
        };
    };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(a:i64 b:i64 c:i64)(k:u32));
    let max = std::cmp::max(std::cmp::max(a, b), c);
    (a + b + c - max + max * (2 as i64).pow(k)).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "5 3 11\n1" => "30",
    test2: "3 3 4\n2" => "22",
}


Measured memory_bytes: 4352
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, w: usize, wv: [[i64; 2];n]};

    let wv: Vec<Vec<i64>> = wv;
    // 上、左に一列余分に空白をとってあげる
    let mut dp: Vec<Vec<i64>> = vec![vec![0; n + 1]; w + 1];

    for i in 1..w + 1 {
        for j in 1..n + 1 {
            if wv[j - 1][0] as usize <= i {
                dp[i][j] = std::cmp::max(
                    dp[i][j - 1],
                    dp[i - wv[j - 1][0] as usize][j - 1] + wv[j - 1][1],
                );
            } else {
                dp[i][j] = dp[i][j - 1];
            }
        }
    }

    println!("{}", dp[w][n]);
}


Measured memory_bytes: 83996
#include<cstdio>
#define MAXIMUM 10001

int C[MAXIMUM] = {0};

int main() {
  int n;
  scanf("%d", &n);

  int A[n] = {0};
  int B[n] = {0};
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);

  for (int i = 0; i < n; i++) C[A[i]]++;
  for (int i = 1; i < MAXIMUM; i++) C[i] += C[i - 1];
  for (int i = n - 1; 0 <= i; i--) {
    B[C[A[i]] - 1] = A[i];
    C[A[i]]--;
  }

  for (int i = 0; i < n; i++) {
    if (i != 0) printf(" ");
    printf("%d", B[i]);
  }

  printf("\n");

  return 0;
}



Measured memory_bytes: 18276
use std::io::stdin;

fn main(){
    let x = getvec()[0];
    println!("{}", solve(x, 0, 100000))
}

fn solve(x: i64, a: i64, b: i64) -> i64{
    if a+1==b {
        b
    } else if sum_((a+b)/2)<x {
        solve(x, (a+b)/2, b)
    } else{
        solve(x, a, (a+b)/2)
    }
}

fn sum_(x: i64) -> i64{
    x * (x+1) / 2
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec() -> Vec<i64>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn getpair() -> (i64, i64){
    let nm = getvec();
    (nm[0], nm[1])
}

Measured memory_bytes: 4352
from decimal import Decimal, ROUND_UP

# input
cook_time = []
append = cook_time.append

for i in range(5):
    append(int(input()))

# check
cook_time.sort(key=lambda x: int(Decimal(x).quantize(Decimal("1E1"), rounding=ROUND_UP)) - x)
res = 0
for c in cook_time:

    if res % 10 != 0:
        res = int(Decimal(res).quantize(Decimal("1E1"), rounding=ROUND_UP))

    res += c

print(res)


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N+1);
    for (int i = 0; i <= N; i++) cin >> A[i];
    if (N == 0) {
        if (A[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if (A[0] > 0) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> dsum(N+2, 0);
    for (int i = N; i >= 0; i--) {
        dsum[i] = dsum[i+1]+A[i];
    }
    
    ll ans = 1;
    ll vnow = 1;
    for (int i = 1; i <= N; i++) {
        if (A[i] > vnow*2) {
            cout << -1 << endl;
            return 0;
        }
        ll now = min(vnow*2, dsum[i]);
        ans += now;
        vnow = now - A[i];
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  int cnt = 0;
  rep(i, N) {
    int a; cin >> a;
    if (a % 2) cnt++;
  }
  cout << (cnt % 2 ? "NO" : "YES") << "\n";
}


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

#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    int n, sum = 0, sum1 = 0; cin >> n;
    for (int i = 1;i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0){
            //cout << i << ' ';
            sum += i;
        }
        sum1 += i;
    }
    cout << sum1 - sum << endl;
    return 0;
}

Measured memory_bytes: 3652
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t=input()
score=0
cnt=0
dame=""
for i in range(n):
    if k>i or dame[i-k]!=t[i]:
        if t[i]=='r':
            score+=p
            dame+='r'
        elif t[i]=='s':
            score+=r
            dame+='s'
        elif t[i]=='p':
            score+=s
            dame+='p'
    else:
        dame+='n'
print(score)

Measured memory_bytes: 3444
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times {|i|yield(i)}                    end
def repl(st,en,n=1);       n*= -1 if st>en;st.step(en,n){|i|yield(i)} end

h,w = gi
ans = []
rep h do
	str = gsf
	ans << str
	ans << str
end

puts ans

Measured memory_bytes: 2044
import scala.io.Source.stdin
import scala.collection.mutable.Queue
import scala.collection.mutable.{ Set => mSet }

object Main {
  val rgb = "rgb".toCharArray

  def main(argv: Array[String]): Unit = {
    stdin.getLines.foreach { l =>
      if (l == "0") sys.exit()

      val q = new Queue[(String, Int)]()
      q.enqueue((l, 0))
      val rgbSet = mSet(Array.fill(l.length)("r").mkString,
        Array.fill(l.length)("g").mkString,
        Array.fill(l.length)("b").mkString)

      val done = mSet[String]()

      var continue = true

      if (rgbSet.contains(l)) {
        println(0)
        continue = false
      }
      while (continue && q.length > 0) {
        val (buf, time) = q.dequeue
        val pairs = (buf.drop(1) zip buf.take(buf.length-1)).map{ case (a, b) => Array(a, b) }.zipWithIndex

        pairs.foreach { case (arr, i) =>
          if (arr(0) != arr(1)) {
            val res = buf.take(i) + convert(arr).mkString + buf.drop(i + 2)
            // 終了判定
            if (rgbSet.contains(res) && continue) {
              println(time+1)
              continue = false
            }
            if (!done.contains(res)) {
              q.enqueue(res -> (time+1))
              done += res
            }
          }
        }

        if (continue && q.length == 0) {
          println("NA")
        }
      }
    }
  }

  def convert(st: Array[Char]): Array[Char] = {
    val c = rgb.filterNot(c => st.contains(c))(0)
    Array(c, c)
  }
}



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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int g[8][8];
int n;

int dfs(int v, vector<int> visited)
{
    if (accumulate(ALL(visited), 0) == n)
        return 1;

    int sum = 0;

    rep(i, n)
    {
        if (!g[v][i] || visited[i])
            continue;

        visited[i] = 1;
        sum += dfs(i, visited);
        visited[i] = 0;
    }

    return sum;
}

int main()
{

    int m;
    cin >> n >> m;
    rep(i, n) rep(j, n) g[i][j] = 0;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        g[a - 1][b - 1] = g[b - 1][a - 1] = 1;
    }

    vector<int> visited(8);
    rep(i, n) visited[i] = 0;

    visited[0] = 1;

    OP(dfs(0, visited));

    return 0;
}

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

const int N = 187;
#define down _down
#define right _right
int down[2][N][N][N] , right[2][N][N][N];

char s[N][N];
int n , m , sum[N][N] , now = 0 , pre = 1;

bool ask(int a , int b , int c , int d) {
    int res = sum[c][d] - sum[a-1][d] - sum[c][b-1] + sum[a-1][b-1];
    return res == 0 || res == (c-a+1)*(d-b+1);
}

bool check(int a , int b , int c , int d) {
    if(down[pre][a][b][d] != -1) {
        int nxt_a = down[pre][a][b][d] + 1;
        if(nxt_a > c) return true;
        if(down[pre][nxt_a][b][d] >= c) return true;
    }
    if(right[pre][b][a][c] != -1) {
        int nxt_b = right[pre][b][a][c] + 1;
        if(nxt_b > d) return true;
        if(right[pre][nxt_b][a][c] >= d) return true;
    }
    return false;
};

template<typename Func>
void trans(Func chk) {
    for(int x = 1 ; x <= n ; x++)
    for(int l = 1 ; l <= m ; l++)
    for(int r = l ; r <= m ; r++) {
        if(!chk(x , l , x , r)) {down[now][x][l][r] = -1; continue;}
        int L = x , R = n , mid;
        while(L < R) {
            mid = (L + R + 1) >> 1;
            if(chk(x , l , mid , r)) L = mid;
            else R = mid - 1;
        }
        down[now][x][l][r] = L;
    }
    for(int y = 1 ; y <= m ; y++)
    for(int l = 1 ; l <= n ; l++)
    for(int r = l ; r <= n ; r++) {
        if(!chk(l , y , r , y)) {right[now][y][l][r] = -1; continue;}
        int L = y , R = m , mid;
        while(L < R) {
            mid = (L + R + 1) >> 1;
            if(chk(l , y , r , mid)) L = mid;
            else R = mid - 1;
        }
        right[now][y][l][r] = L;
    }    
}
int main() {
    scanf("%d %d" , &n , &m);
    for(int i = 1 ; i <= n ; ++i) scanf("%s" , s[i] + 1);
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= m ; ++j)
            sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(s[i][j]=='#');
    if(ask(1 , 1 , n , m)) {puts("0") ; exit(0);}
    trans(ask);
    for(int ans = 1 ;; ans++) {
        swap(now , pre);
        trans(check);
        if(right[now][1][1][n] == m) return printf("%d\n" , ans) & 0;
    }
}

Measured memory_bytes: 102272
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#define rep(i,k,n)for(ll i=k;i<(n);i++)
using namespace std;
using ll =long long;
//const int mod = 1000000007;
//class mint {
//	long long x;
//public:
//	mint(long long x = 0) : x((x% mod + mod) % mod) {}
//	mint operator-() const {
//		return mint(-x);
//	}
//	mint& operator+=(const mint & a) {
//		if ((x += a.x) >= mod) x -= mod;
//		return *this;
//	}
//	mint & operator-=(const mint & a) {
//		if ((x += mod - a.x) >= mod) x -= mod;
//		return *this;
//	}
//	mint & operator*=(const  mint & a) {
//		(x *= a.x) %= mod;
//		return *this;
//	}
//	mint operator+(const mint & a) const {
//		mint res(*this);
//		return res += a;
//	}
//	mint operator-(const mint & a) const {
//		mint res(*this);
//		return res -= a;
//	}
//	mint operator*(const mint & a) const {
//		mint res(*this);
//		return res *= a;
//	}
//	mint pow(ll t) const {
//		if (!t) return 1;
//		mint a = pow(t >> 1);
//		a *= a;
//		if (t & 1) a *= *this;
//		return a;
//	}
//	// for prime mod
//	mint inv() const {
//		return pow(mod - 2);
//	}
//	mint& operator/=(const mint & a) {
//		return (*this) *= a.inv();
//	}
//	mint operator/(const mint & a) const {
//		mint res(*this);
//		return res /= a;
//	}
//
//	friend ostream& operator<<(ostream & os, const mint & m) {
//		os << m.x;
//		return os;
//	}
//};

int main() {
	ll A, B, N;
	cin >>N>> A >> B;
	cout << min(A * N, B);


}

Measured memory_bytes: 256
// AOJ 1616: Taro's Shopping
// 2017.10.6 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

int a[1002], n;

int cmp(int *a, int *b) { return *a - *b; }

int bsch(int x)
{
	int m, l = 0, r = n;

    while (l < r) {
        m = (l + r) >> 1;
		if (a[m] == x) return m;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int m, i, j, ans;

	while (scanf("%d%d", &n, &m) && n > 0) {
		for (i = 0; i < n; i++) scanf("%d", a+i);
		qsort(a, n, sizeof(int), cmp);

		ans = 0;
		if (a[0] + a[1] > m) goto Done;

		if (a[n-1] + a[n-2] <= m) { ans = a[n-1]+a[n-2]; goto Done; }
		for (i = 0; i < n && a[i] < m; i++) {
			j = bsch(m - a[i]);
			if (j < 0) continue;
			if (j != i || (j > 0 && a[j-1] == a[j]) || (j < n-1 && a[j+1] == a[j])) {
				if (a[i] + a[j] > ans) {
					ans = a[i] + a[j];
					if (ans == m) break;
				}
			}
		}
Done:	if (ans == 0) puts("NONE");
		else printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1728
from collections import namedtuple

Report = namedtuple('Report', ['a', 'b'])

def main():
    n = int(input())
    reports = []
    for _ in range(n):
        a, b = map(int, input().split())
        reports.append(Report(a, b))
    
    print(solve(reports))

def solve(reports):
    x, y = reports[0].a, reports[0].b

    for a, b in reports[1:]:
        c = ceil(x, a)
        d = ceil(y, b)
        if d // b * a > c:
            x = d // b * a
            y = d
        else:
            x = c
            y = c // a * b
    
    return x + y

def ceil(x, y):
    r = x % y
    if r == 0:
        return x
    else:
        return x + y - r

main()


Measured memory_bytes: 3436