akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    vector<pair<ll, int> > sorted(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        sorted[i] = make_pair(a[i], i);
    }
    sort(sorted.rbegin(), sorted.rend());
    ll first = sorted[0].first;
    ll exception = sorted[0].second;
    ll second = sorted[1].first;
    for(int i=0;i<n;i++){
        if(i == exception){
            cout << second << endl;
        }else{
            cout << first << endl;
        }
    }
}

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

using namespace std;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-')
			f = -1;
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
	}
	return x * f;
}

int main() {
	int a, b;
	cin >> a >> b ;
	cout << max(a + b, max(a - b, a * b)) << endl ;
	return 0;
}

Measured memory_bytes: 256
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n - 1));
    rep(i, n) rep(j, n - 1) {
        cin >> a[i][j];
        --a[i][j];
    }
    
    auto f = [&](int x, int y) -> int {
        return min(x, y) * n + max(x, y);
    };
    
    vector<vector<int>> G(n * n);
    vector<int> cnt(n * n, 0);
    rep(i, n) rng(j, 1, n - 1) {
        G[f(i, a[i][j - 1])].pb(f(i, a[i][j]));
        ++cnt[f(i, a[i][j])];
    }
    
    vector<bool> searched(n * n, false);
    queue<int> q;
    rep(i, n * n) {
        if (cnt[i] == 0) q.push(i);
    }
    vector<int> dist(n * n, -1);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        searched[u] = true;
        if (dist[u] == -1) dist[u] = 0;
        for (int v: G[u]) {
            --cnt[v];
            if (!cnt[v]) q.push(v);
            dist[v] = dist[u] + 1;
        }
    }
    
    int ans = 0;
    rep(i, n * n) {
        if (!searched[i]) {
            cout << -1 << "\n";
            return;
        }
        chmax(ans, dist[i]);
    }
    cout << ans + 1 << "\n";
    return;
}



Measured memory_bytes: 56196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> p(51), b(51);

ll f(ll n, ll x) {
	if (n == 0) return (x <= 0) ? 0 : 1;
	if (x <= 1 + b[n-1]) return f(n-1, x-1);
	else return p[n-1] + 1 + f(n-1, x-2-b[n-1]);
}

int main() {
	ll n, x; cin >> n >> x;
	p[0] = b[0] = 1;
	for (int i = 0; i < 50; i++) {
		b[i+1] = b[i] * 2 + 3;
		p[i+1] = p[i] * 2 + 1;
	}
	cout << f(n, x) << '\n';
	return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    string s;cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(i+1<n){
            if(s[i]==s[i+1]){
                cout<<i+1<<' '<<i+2<<'\n';
                return 0;
            }
        }
        if(i+2<n){
            if(s[i]==s[i+2]||s[i+1]==s[i+2]||s[i]==s[i+1]){
                cout<<i+1<<' '<<i+3<<'\n';
                return 0;
            }
        }
    }
    cout<<-1<<' '<<-1<<'\n';
    return 0;
}


Measured memory_bytes: 3712
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                
    # divisors.sort()
    return divisors

s = make_divisors(n)
sum = 0

for i in s:
    if i > 1:
        if n // (i - 1) == n % (i - 1):
            sum += i - 1

print(sum)
        

Measured memory_bytes: 3272
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007
#define mp(a,b) make_pair(a,b)


ll N,M;
ll X[100010];
ll Y[100010];
ll Z[100010];

ll P[100010],W[100010];
void init(ll N){
    for (ll i=0; i<N; ++i) {
        P[i] = i;
        W[i] = 1;
    }
}

ll root(ll a){
    if (P[a] == a) return a;
    return (P[a] = root(P[a]));
}

bool is_same_set(ll a, ll b){
    return root(a) == root(b);
}

ll size(ll a){
    return W[root(a)];
}

void unite(ll a, ll b){
    ll temp = size(a) + size(b);
    if (!is_same_set(a,b)) {
        P[root(a)]= root(b);
        W[root(a)] = temp;
    }
    else P[root(a)] = root(b);
}

int main() {
    cin >> N >> M;
    init(N);
    rep(i,M){
        cin >> X[i] >> Y[i] >> Z[i];
        unite(X[i]-1,Y[i]-1);
        
    }
    ll res = 0;
    rep(i,N){
        if (root(i) == i)
            res ++;
    }
    cout << res << endl;
   
    
   
    
    return 0;
}


Measured memory_bytes: 4608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i,p,q,ans=0,c,k,a[100100];
	cin >> n >> c >> k;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	sort(a,a+n);
	p = 0;
	while(p < n){
		q = (int)(upper_bound(a,a+n,a[p]+k)-a);
		q = min(q,p+c);
		q = min(q,n);
		++ans;
		p = q;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a;
  while (cin >> a) {
    cout << "3C" << setfill('0') << setw(2) << (a % 39 == 0 ? 39 : a % 39) << endl;
  }

  return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<stack>
#include<string>
#include<cstdlib>
#include<sstream>
using namespace std;
void opt(stack<int> &st,string s){
	int b=st.top();st.pop();
	int a=st.top();st.pop();
	int c;
	switch(s[0]){
		case '+':c=a+b;break;
		case '-':c=a-b;break;
		case '*':c=a*b;break;
		case '/':c=a/b;break;
		default:break;
	}
	st.push(c);
}
int main(){
	string input,s;
	getline(cin,input);
	istringstream S(input);
	stack<int> st;
	while(S>>s){
		if(s=="+"||s=="-"||s=="*"||s=="/"){
			opt(st,s);
		}else {
			st.push(atoi(s.c_str()));
		}
	}
	cout<<st.top()<<endl;
	return 0;
}


Measured memory_bytes: 3208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc158/tasks/abc158_e>
 問題文============================================================
 E - Divisible Substring
 =================================================================
 解説=============================================================
 ================================================================
 */

ll MOD = -1;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

template<class Type>
Type solve(Type res = Type()){
    int N,P; cin >> N >> P;
    MOD = P;
    string S; cin >> S;
    for(auto& c:S) c -= '0';
    
    if(P==2 || P == 5){
        for(int i = 0; i < N;i++){
            if(S[i]%P==0){
                res += i+1;
            }
        }
    }else{
        for(auto& c:S) c%=P;
        map<ll,ll> mp;
        
        ll num = 0;
        for(int i = N-1; i >= 0; i--){
            num += powmod(10,N-1-i)*S[i]%P;
            num %= P;
            mp[num]++;
        }
        mp[0]++;
        for(int i = 0; i < P;i++){
            res += mp[i]*(mp[i]-1)/2;
        }
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1044
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N;
    int a[100];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a + N);

    int Alice = 0;
    int Bob = 0;

    int counter = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (counter % 2 == 0) {
            Alice += a[i];
        }
        else {
            Bob += a[i];
        }
        counter++;
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int H, W; cin >> H >> W;
    vector<string> G(H);
    int cnt = 0;
    rep(i, H) {
        cin >> G.at(i);
        rep(j, G[i].size()) if (G[i][j] == '#') cnt++;
    }
    if (cnt == H + W - 1) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

int main() {
  string S;
  getline(cin, S);

  for (int i = 0; i < S.size(); i++) {
    if (S[i] - 'a' < 26 && S[i] - 'a' >= 0) {
      S[i] = 'A' + (S[i] - 'a');
    } else if (S[i] - 'A' < 26 && S[i] - 'A' >= 0) {
      S[i] = 'a' + (S[i] - 'A');
    }
  }
  cout << S << BR;

  return 0;
}


Measured memory_bytes: 3200
n = int(input())
k = int(input())
ans = 0
if k == 1:
    if n < 10:
        ans = n
    else:
        l = len(str(n))
        ans += 9 * (l - 1)
        ans += int(str(n)[0])
elif k == 2:
    if n < 11:
        ans = 0
    else:
        l = len(str(n))
        for i in range(2, l):
            ans += 9 * 9 * (i - 1)
        f = int(str(n)[0])
        ans += (f - 1) * 9 * (l - 1)
        for i in range(1, l):
            if int(str(n)[i]) != 0:
                f = int(str(n)[i])
                num = i
                break
        else:
            num = l - 1
            f = 0
        ans += f
        ans += 9 * (l - num - 1)
else:
    if n < 111:
        ans = 0
    else:
        l = len(str(n))
        # 54321
        # 1桁下まで 10000未満
        ans += 9 * 9 * 9 * (l - 1) * (l - 2) * (l - 3) // 6

        # 最高位の桁1小さいとこまで 50000未満
        f = int(str(n)[0])
        ans += (f - 1) * 9 * 9 * (l - 1) * (l - 2) // 2

        # 最高位の桁一致 54000未満
        for i in range(1, l):
            if int(str(n)[i]) != 0:
                f = int(str(n)[i])
                num = i
                break
        else:
            num = l - 1
        ans += (f - 1) * (l - num - 1) * 9  # その桁が0でない
        ans += 9 * 9 * (l - num - 1) * (l - num - 2) // 2  # その桁が0である

        # 54000台
        for i in range(num + 1, l):
            if int(str(n)[i]) != 0:
                f = int(str(n)[i])
                num = i
                break
        else:
            num = l - 1
            f = 0
        ans += (l - num - 1) * 9
        ans += f
print(ans)

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

int main(){

    string s;
    cin >> s;

    map<char, int> dict;
    for (int i=0; i<s.size(); i++){
        dict[s.at(i)]++;
    }

    bool flg = true;
    if (dict.count('N') != dict.count('S')) flg = false;
    if (dict.count('E') != dict.count('W')) flg = false;

    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int x, i;
    char S[10], T[10];
    scanf("%s", S);
    scanf("%s", T);
    x=0;
    for (i=0; i<3; i++) {
        if (S[i]==T[i]) x++;
    }
    printf("%d", x);
    return 0;
}


Measured memory_bytes: 128
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    multiples = [1] * (10 ** 6 + 1)

    bucket = Counter(A)
    res = 0

    for num in A:
        if bucket[num] == 1 and multiples[num] == 1:
            res += 1
        if multiples[num] == 1:
            for i in range(num, 10**6+1, num):
                multiples[i] = 0
    
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 44432
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  vi rgb = {R,G,B};
  sort(all(rgb), greater<int>());
  dump (rgb,N);
  int cnt=0;
  for(int r=0; r<=N/rgb[0]; ++r){
    if(r*rgb[0]==N) {cnt++; continue; }
    for(int g=0; g<=(N-r*rgb[0])/rgb[1]; ++g){
      int remain = (N-r*rgb[0]-g*rgb[1]);
      if(remain%rgb[2]==0) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	long long int n,m;
	long long int mod=1000000007;
	cin>>n>>m;
	int x=n;
	int y=m;
	if(-2<x-y&&x-y<2){
		for(int i=1;i<x;i++){
			n*=i;
			n%=mod;
		}
		for(int i=1;i<y;i++){
			m*=i;
			m%=mod;
		}		
		if(x-y!=0){	
			long long int ans=(n*m)%mod;
			cout<<ans<<endl;
		}
		else{
			long long int ans=(n*m*2)%mod;
			cout<<ans<<endl;
		}
	}
	else{
		cout<<0<<endl;
	}
}

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

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

  p = (a > b) ? a : b;
  if ( a > b ) {
    a--;
  } else {
    b--;
  }
  p += (a > b) ? a : b;

  cout << p << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int w = scanner.nextInt();
        int n = scanner.nextInt();
        int[] numbers = new int[w];
        
        for (int i = 0; i < w; i++) {
            numbers[i] = i+1;
        }
        
        for (int i = 0; i < n; i++) {
            String op[] = scanner.next().split(",");
            int a = Integer.parseInt(op[0]);
            int b = Integer.parseInt(op[1]);
            int temp = numbers[a-1];
            numbers[a-1] = numbers[b-1];
            numbers[b-1] = temp;
        }
        for (int i = 0; i < w; i++) {
            System.out.println(numbers[i]);
        }
    }
}

Measured memory_bytes: 17196
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double p[n];
    for(int i=0;i<n;i++)
        cin>>p[i];
    double dp[n+1][n+1];
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1-p[i-1]);
    }
    for(int j=1;j<=n;j++)
    {
        dp[0][j]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
               double x=(1-p[i-1])*dp[i-1][j];
                dp[i][j]=(p[i-1]*dp[i-1][j-1])+x;
        }
    }
    int temp=n/2;
    double ans=0.0;
    for(int i=temp+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }

	cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 70528
import sys
# from collections import deque, defaultdict, Counter
# from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
# from itertools import permutations, combinations, product
# from operator import itemgetter, mul
# from copy import deepcopy
# from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [input() for _ in range(H)]

L = [[0]*W for _ in range(H)]
R = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]

for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		if S[i][j] == '#':
			R[i][j] = 0
		elif j == W-1:
			R[i][j] = 1
		else:
			R[i][j] = R[i][j+1] + 1

for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			U[i][j] = 0
		elif i == 0:
			U[i][j] = 1
		else:
			U[i][j] = U[i-1][j] + 1

for i in range(H-1, -1, -1):
	for j in range(W):
		if S[i][j] == '#':
			D[i][j] = 0
		elif i == H-1:
			D[i][j] = 1
		else:
			D[i][j] = D[i+1][j] + 1

ans = 0
for i in range(H):
	for j in range(W):
		ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)


Measured memory_bytes: 189292
n=int(input())
ran = int(n**0.5) + 1
ans = 999999999999
for i in range(1, ran):
    j = n // i
    if j != int(n / i):
        continue
    if i * j != n:
        continue
    tmp = i + j - 2
    if tmp < ans:
        ans = tmp
print(ans)


Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys


def solve(S: str, T: str, A: int, B: int, U: str):
    #print(A-1,B if S==U else A,B-1)
    if S==U:
        print(A-1,B)
    else:
        print(A,B-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    U = next(tokens)  # type: str
    solve(S, T, A, B, U)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
void main() {
	auto ip = readAs!(real[]), A = ip[0], B = ip[1];
	writefln("%d", floor(A*B).to!ulong);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

long rl() {
	return readAs!long;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 2916
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x, y = map(int, readline().split())

    if x % y == 0:
        print(-1)
    else:
        print(x * (y - 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61892
#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x,y,z;
  cin >> x >> y >> z;
  cout << 1+(x-y-2*z)/(y+z) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define mod 1000000007
#define inf 1<<30
#define mp(a,b) make_pair(a,b)
#define len(u,N) u.begin(),u.begin()+N

ll N;
vector<ll> A;

ll max(ll a, ll b){
    if (a > b) return a;
    else return b;
}

int main() {
    cin >> N;
    rep(i,5) {
        ll temp;
        cin >>  temp;
        A.push_back(temp);
    }
    ll m = -1;
    ll idx = 0;
    rep(i,5){
        if (m < 0){
            m = A[i];
            idx = i;
        }
        else if (m >= A[i]){
            m = A[i];
            idx = i;
        }
    }
    ll a;
    if (N <= m) {
        cout << 5 << endl;
        return 0;
    }
    if (N%m == 0) a = N/m;
    else a = N/m + 1;
    cout << idx+a+(4-idx)  << endl;
    return 0;
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
int main()
{
	int x=read();
	cout<<3*x*x<<endl;
	return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;





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

	if (a == 1 || b == 1) {
		cout << 1 << endl;
	}
	else cout << (a*b + 1) / 2 << endl;


}




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

typedef unsigned long long ull;

int n;
string s;
int arr[4000];

void solve() {
	ull sum = 0;
	
	ull countF[3][4000];
	int zeros = 0, ones = 0, twos = 0;
	
	
	for (int i = n - 1; i >= 0; --i) {
		if (arr[i] == 0) {
			++zeros;
		} else if (arr[i] == 1) {
			++ones;
		} else {
			++twos;
		}
		countF[0][i] = zeros;
		countF[1][i] = ones;
		countF[2][i] = twos;
	}
	
	for (int i = 0; i < n - 2; ++i) {
		for (int j = i + 1; j < n - 1; ++j) {
			if (arr[i] == arr[j]) continue;
			
			int diff = j - i;
			int e;
			
			if (arr[i] != 0 && arr[j] != 0) {
				e = 0;
			} else if (arr[i] != 1 && arr[j] != 1) {
				e = 1;
			} else {
				e = 2;
			}
			
			sum += countF[e][j + 1];
			
			if (j + diff < n && arr[j + diff] == e) {
				--sum;
			}
		}
	}
	
	cout << sum << endl;
	
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		char c = s[i];
		if (c == 'R') {
			arr[i] = 0;
		} else if (c == 'B') {
			arr[i] = 1;
		} else {
			arr[i] = 2;
		}
	}
	
	solve();
	
	return 0;
}


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

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

	bool f;
	int n, x;
	vector<int> d;
	cin >> n;
	for (int i = 0; i < n; ++i){
		f = false;
		cin >> x;
		for (int j = 0; j < d.size(); ++j){
			if (x == d[j]){
				f = true;
			}
		}
		if (!f){
			d.push_back(x);
		}
	}
	cout << d.size() << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<int> v[100005];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
    }
    multiset<int> val;
    LL ans = 0;
    for(int i=1;i<=m;i++){
        for(int j=0;j<v[i].size();j++){
            int b = v[i][j];
            val.insert(b);
        }
        if(!val.empty()){
            ans += *val.rbegin();
            val.erase(--val.end());
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 7808
#include <iostream>

using namespace std;
int flag;
int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==0){
            if(a[i] %3 == 0 || a[i] % 5==0)
                continue;
            else
                flag=1;
        }
        
    }
    cout<< ((flag == 0) ? "APPROVED" : "DENIED");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  boost::for_each(vc, [&os, &vc](T value) {
    os << value;
    if (value != vc.back())
      os << ' ';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream&
operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  string S{}; std::cin >> S;
  
  std::map<char, ui> m;
  boost::for_each(S, [&m](char c) {
    if (m.find(c) != m.end())
      ++m[c];
    else
      m[c] = 1;
    });

  auto ans = boost::accumulate(m, 1U, [](ui res, auto p) {
    return res & (p.second == 2);
    });

  ans &= m.size() == 2;

  std::cout << (ans ? "Yes" : "No" ) << '\n';

  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main() {
	int N, v, ctr = 0;

	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> v;
		if (i + 1 != v) ctr++;
	}
	if (ctr > 2) std::cout << "NO\n";
	else std::cout << "YES\n";
	return 0;
}

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

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;




int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    printf((b - a) % 2 == 0 ? "Alice" : "Borys");



	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<string, int> P;
typedef vector<vector<int>> Graph;

const double PI = 3.14159265358979323846;

const int mod = 1000000007;

int main(int argc, char *args[]) {
	string S; cin >> S;
	int Q; cin >> Q;
	int rev = 0;
	rep(i, Q) {
		int t; cin >> t;
		if (t == 1) {
			rev++;
			continue;
		}
		int f; cin >> f;
		char c; cin >> c;
		//cout << rev << endl;
		if (rev % 2 == 0) {
			if (f == 1) S.insert(S.begin(), c);
			else S.push_back(c);
		}
		else {
			if (f == 1) S.push_back(c);
			else S.insert(S.begin(), c);
		}
		
		//cout << S << endl;
	}
	
	if (rev % 2 == 1) {
		reverse(S.begin(), S.end());
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 900
//ほぼstandard answer
#include<iostream>
using namespace std;

class Cube{
public:
  int f[6];
  Cube(){} 
  void roll_z(){ roll(1, 2, 4, 3);} //横向き
  void roll_y(){ roll(0, 2, 5, 3);} //サイコロの番号は+1
  void roll_x(){ roll(0, 1, 5, 4);}
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }
};

bool eq( Cube c1, Cube c2 ); //equalの中で使う
bool equal( Cube c1, Cube c2 );

int main(){
  Cube c1,c2; 
  
  for ( int i = 0; i < 6; i++ ) cin >> c1.f[i];
  for ( int i = 0; i < 6; i++ ) cin >> c2.f[i];
  
  if ( equal(c1,c2) ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

bool equal( Cube c1, Cube c2 ){ //ほとんどDiceIIと同じ流れ
  for ( int i = 0; i < 6; i++ ){
    for ( int j = 0; j < 4; j++ ){
      if ( eq(c1, c2) ) return true;
      c1.roll_z();
    }
    if ( i % 2 == 0 ) c1.roll_x();
    else c1.roll_y();
  }
  return false;
}

bool eq( Cube c1, Cube c2 ){
  for ( int i = 0; i < 6; i++ ) {
    if ( c1.f[i] != c2.f[i] ) return false;
  }
  return true;
}




Measured memory_bytes: 3136
x, y = map(int, input().split())
diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1
ie = 1

if (x + y)%3 != 0 or ref < 0:
    print(0)
    exit()


for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = ie*(i + 1)%mod

ie = pow(ie, mod - 2, mod)
ans = ans*ie%mod
print(ans)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define vpii vector<pair<int,int>> 
#define pb push_back

void solve() {
	ll n,d;
	cin>>n>>d;
	int cnt=0;
	for(int i=0;i<n;i++) {
		ll x,y;
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=d) cnt++;
	}
	cout<<cnt<<"\n";
}
 
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("ou.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc=1;
    //cin>>tc;
    for(int t=1;t<=tc;t++) {
        //cout<<"Case #"<<t<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    ll Ans = 0;

    cin >> N;
    rep(A, N - 1)
    {

        int temp = (N - 1) / (A + 1);
        Ans += temp;

        // cout << A << endl;
        // cout << temp << endl;
    }

    cout << Ans << endl;
}

// 余り
ll mod(ll val, ll m = 1e9 + 7)
{
    ll res = val % m;
    if (res < 0)
        res += m;
     return res;
}

// 累乗
ll pow_kai(ll a, ll n, ll m = 1e9 + 7)
{ //aのn乗を計算します。
    ll x = 1;
    rep(i, n)
    {
        x *= a;
        x %= m;
    }
    return x;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
  int n;
  cin >> n;
  cin.ignore();
  int a[n];
  int b[n];
  int nneg=0;
  long long ans=0;
  for(int i=0; i<n; i++){
  cin >> a[i];
  }
  for(int i=0; i<n; i++){
  b[i] = abs(a[i]);
  }
  sort(b, b+n, greater<int>());
  for(int i=0; i<n; i++){
  if(a[i]<0) nneg=nneg+1;
  }
  if((nneg%2)==0){
    for(int i=0; i<n; i++){
    ans=ans+b[i];
    }
  }else{
    for(int i=0; i<n-1; i++){
    ans=ans+b[i];
    }
    ans=ans-b[n-1];
  }
  cout <<ans; 
  return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE ViewPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List
import Data.Array.IArray
import Data.Graph (buildG)
import qualified Data.Sequence as S

bfs :: Int -> Array Int [Int] -> [[Int]]
bfs n g = walk queue
  where
    queue = S.fromList [[1]]
    walk (S.viewl -> S.EmptyL) = []
    walk (S.viewl -> xs S.:< s')
        | length xs == n = xs : walk s'
        | otherwise      = walk $ s' S.>< s''
      where
        as  = filter (`notElem` xs) (g ! head xs)
        s'' = S.fromList $ zipWith (:) as (repeat xs)

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine
    as <- fmap concat . replicateM m $ do
        [a, b] <- fmap read . words <$> getLine
        return [(a, b), (b, a)]
    let g = buildG (1, n) as
    print $ length $ bfs n g

Measured memory_bytes: 1660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] age)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();
		StringBuffer sb2 = new StringBuffer();

		while(true){
			String mountain = br.readLine();

			if( mountain.equals("-")) break;

			int m = Integer.parseInt(br.readLine());
			int i = 0;

			for( i=0 ; i<m ; i++ ){
				int h = Integer.parseInt(br.readLine());
				sb2.append(mountain.substring(h, mountain.length())).append(mountain.substring(0, h));
				mountain = sb2.toString();
				sb2.setLength(0);
			}

			sb.append(mountain).append("\n");
		}

		System.out.print(sb);
	}
}

Measured memory_bytes: 24448
#include <stdio.h>

int main(void)
{
  char S[4];
  scanf ("%s",S);
  char char1=0,char2=0,charn1=0,charn2=0,char2_able=0,error=0;
  
  char1=S[0];
  charn1++;
  if (S[1]!=char1)
  {
    char2=S[1];
    char2_able=1;
    charn2++;
  }
  else if (S[1]==char1)
  {
    charn1++;
  }
  if (S[2]==char1)
  {
    charn1++;
  }
  else if (S[2]==char2)
  {
    charn2++;
  }
  else if (S[2]!=char1&&S[2]!=char2&&char2_able==0)
  {
    char2=S[2];
    char2_able=1;
    charn2++;
  }
  else error=1;
  
  if (S[3]==char1)
  {
    charn1++;
  }
  else if (S[3]==char2)
  {
    charn2++;
  }
  else if (S[3]!=char1&&S[3]!=char2&&char2_able==0)
  {
    char2=S[3];
    char2_able=1;
    charn2++;
  }
  else error=1;
  
  if (error==1) printf("No");
  else if (charn1==2&&charn2==2) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int current=0;
    vector<int> v(s.length()+1);
    long long int i=0;
    long long int count=0;
    i=0;
    while(i!=s.length())
    {
        if(s[i]=='<')
        {
            v[i]=count;
            count++;
            i++;
            if(i==s.length())
            {
                v[i]=count;
            }
        }
        else
        {
            long long int temp=i;
            long long int tempcount=0;
            while(temp<s.length()&&s[temp]=='>')
            {
                tempcount++;
                temp++;
            }
            if(tempcount<=count)
            {
                v[i]=count;
                for(long long int j=i+1;j<temp;j++)
                {
                    tempcount--;
                    v[j]=tempcount;
                }
                v[temp]=0;
                count=0;
            }
            else
            {
                for(long long int j=i;j<temp;j++)
                {
                    v[j]=tempcount;
                    tempcount--;
                }
                v[temp]=0;
                count=0;
            }
            i=temp;
        }
    }
    /*for(long long int i=0;i<s.length();i++)
    {
        cout<<v[i]<<s[i]<<" "; 
    }
    cout<<v[s.length()]<<endl;*/
    long long int sum=0;
    for(long long int i:v)
    {
        sum+=i;
    }
    cout<<sum;
}

Measured memory_bytes: 2820
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    long long N,x; cin >> N >> x;
    long long a[2020];
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    long long dp[2020][2020] = {0};
    long long ans = 1e18;
    for (int i = 0; i < N; i++){
        dp[0][i] = a[i];
    }
    for (int i = 1; i < N; i++){
        for (int j = 0; j < N; j++){
            dp[i][j] = min(a[(j - i + N) % N], dp[(i-1+N) % N][j]);
        }
    }
    for (int i = 0; i < N; i++){
        long long tmp = 0;
        for (int j = 0; j < N; j++){
            tmp += dp[i][j];
        }
        ans = min(ans,i*x + tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 32128
# -*- coding: utf-8 -*-
def check(values):
  for i, value in enumerate(values):
    if (value == 0) or ((value % 2) == 1):
      return False, values
    else:
      values[i] = value / 2
  return True, values


num = int(input())
values = list(map(int, input().split()))

cnt = 0
while True:
  flg, values = check(values)
  if not flg:
    break
  cnt += 1

print(cnt)

Measured memory_bytes: 3060
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int ma=INT_MIN,mi=INT_MAX;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		ma=max(ma,a);
	}
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		mi=min(mi,a);
	}
	int l,r;
	l=max(ma,x);
	r=min(mi,y);
	if(r-l>0){
		cout<<"No War"<<endl;
	}
	else{
		cout<<"War"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int x, y;
int gr[13] = {-1, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

string solve() {
  if (gr[x] == gr[y]) return "Yes";
  else return "No";
}

int main() {
  while (cin >> x >> y) {
	cout << solve() << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,m;
LL l,g,t,ans;
char S[500010],T[500010];
void ck(LL i){
	LL A=m/g*i;
	LL B=n/g*i;
	LL lcm=A*B/__gcd(A,B);
	LL AA=lcm/A;
	LL BB=lcm/B;
	for (int i=1,j=1;i<=n;i+=AA,j+=BB){
		if (S[i]!=T[j]) return;
	}
	ans=min(ans,l*i);
}
int main(){
	cin>>n>>m;
	scanf("%s",S+1);
	scanf("%s",T+1);
	l=1ll*n*m/__gcd(n,m);
	g=t=__gcd(n,m);
	ans=1e18;
	for (LL i=1;i*i<=t;++i){
		ck(i);
		ck(t/i);
	}
	if (ans<1e18)
	cout<<ans<<endl;
	else puts("-1");
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int n,m,i,j,t;
	int a[100],p[100],x[100],w[100];
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	scanf("%d",&m);
	for(i=1;i<=m;i++) scanf("%d %d",&p[i],&x[i]);
	for(i=1;i<=m;i++) w[i]=0;
	t=0;
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			if(j==p[i]){
				t=a[j]; a[p[i]]=x[i]; 
			}	
			w[i]+=a[j];
			if(j==p[i]) a[p[i]]=t;
		}
	}
	for(i=1;i<=m;i++) printf("%d\n",w[i]);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int n,a,b,t,c=0,i;
	scanf("%d%d%d",&n,&a,&b);
	for(i=1;i<=n;i++){
		scanf("%d",&t);
		if(!(a<=t&&t<b)){c++;}
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
	int i,b=0;
	char a[5];
	scanf("%s",a);
	for(i=1;i<=3;i++){
	if(a[i]==a[i-1]) b = 1;
	}
	if(b==0) printf("Good\n");
	else printf("Bad\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int a,b,c;
	cin >> a >> b>>c;
	if (a >= b&& b>= c)cout << c << " " << b << " " << a << endl;
	else {
		if (b >= c && c >= a)cout << a << " " << c << " " << b << endl;
		else if (c >= a && a >= b)cout << b << " " << a << " " << c << endl;
		if (a < b && b < c)cout << a << " " << b << " " << c << endl;
		if (b < c && c < a)cout << b << " " << c << " " << a << endl;
		if (c < a && a < b)cout << c << " " << a << " " << b << endl;
	}
	return 0;

}



Measured memory_bytes: 3072
S, T = input(), input()
conv_table = {}
inv_table = {}

able = True
for i in range(len(S)):
    if S[i] in conv_table:
        if conv_table[S[i]] != T[i]:
            able = False
            break
    else:
        conv_table[S[i]] = T[i]
    if T[i] in inv_table:
        if inv_table[T[i]] != S[i]:
            able = False
            break
    else:
        inv_table[T[i]] = S[i]
print('Yes' if able else 'No')


Measured memory_bytes: 42164
#define sp ' '
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
	int a,b,max,i,ans;
  	max=0;
  	ans=0;
 	cin >> a;
 	for(i=1;i<=a;i++){
      cin >> b;
      if(b>max){
        ans=ans+max;
        max=b;
      }
      else{
        ans=ans+b;
      }
    }

	if(max>=ans){
      cout << "No";
    }
  else{
    cout << "Yes";
  }
	return 0;
}

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

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

	int n, k; cin >> n >> k;
	vector<int> candles(n);
	for(int i = 0; i < n ;i++) cin >> candles[i];
	int dist = (int)1e9;
	int i = 0;
	while(i + k - 1 < n){
		int mindist = min(abs(candles[i]), abs(candles[i + k - 1]));
		dist = min(dist, mindist + abs(candles[i] - candles[i + k -1]));
		i++;
	}
	cout << dist << endl;
	return 0;	
}





  

Measured memory_bytes: 640