akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
const int inf = 1e9;
const int mod = 1e9 + 7;

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

bool inside(int x, int y, int H, int W) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

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

    int H, W, m;
    cin >> H >> W >> m;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    vvi power(H, vi(W));
    rep(i, H) rep(j, W) cin >> power[i][j];
    vvi on(H, vi(W));
    rep(i, H) rep(j, W) cin >> on[i][j];
    vvi off(H, vi(W));
    rep(i, H) rep(j, W) cin >> off[i][j];
    vector<Pii> task(m);
    rep(i, m) cin >> task[i].first >> task[i].second;

    vvvi time(H, vvi(W));
    time[task[0].first][task[0].second].emplace_back(0);
    std::function<int(int,int,int,int,int,int,int)> dfs = [&](int x, int y, int px, int py, int gx, int gy, int t) {
        if (x == gx && y == gy) {
            return t;
        }

        rep(k, 4) {
            int nx = x + dx[k], ny = y + dy[k];
            if (!inside(nx, ny, H, W)) continue;
            if (s[nx][ny] == '#') continue;
            if (nx == px && ny == py) continue;
            time[nx][ny].emplace_back(t);
            int ret = dfs(nx, ny, x, y, gx, gy, t + 1);
            if (ret < inf) return ret;
            time[nx][ny].pop_back();
        }

        return inf;
    };

    int t = 1;
    rep(i, m - 1) {
        t = dfs(task[i].first, task[i].second, -1, -1, task[i + 1].first, task[i + 1].second, t);
    }

    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            if (time[i][j].empty()) {
                continue;
            }
            ans += on[i][j];
            rep(k, (int)time[i][j].size() - 1) {
                ans += min(power[i][j] * (time[i][j][k + 1] - time[i][j][k]), off[i][j] + on[i][j]);
            }
            ans += off[i][j];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 13476
/**
 *   Praveen Fulera    
**/


// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

#define endl '\n'
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define point pair <double, double>
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl

void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "\n[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int N = 1000005;
const int mod = 1e9 + 7;
//const int mod = 998244353;
int dp[N][3], n;
string s;

int go(int ind, int carry){
    if(ind < 0){
        return carry;
    }
    int &x = dp[ind][carry];
    if(x != -1) return x;
    int temp1, temp2;
    if(carry){
        temp1 = (9-(s[ind]-'0'))+go(ind-1,1);
        temp2 = (s[ind]-'0'+1) + go(ind-1,0);
    }
    else{
        temp1 = (10-(s[ind]-'0'))+go(ind-1,1);
        temp2 = (s[ind]-'0') + go(ind-1,0);   
    }
    return(x = min(temp1, temp2));
}

void solve(){
    cin >> s;
    n = s.size();
    memset(dp,-1,sizeof(dp));
    cout << go(n-1,0) << '\n';
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
        clock_t t1 = clock();
  int t = 1; //cin >> t;
  while(t--){      
     solve();
  }
        clock_t t2 = clock();
  //cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;      
}


Measured memory_bytes: 71708
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define f(i,a,b) for(ll i=a; i<b; i++)
#define F first
#define S second
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n], b[n], ans = 0;
    map <ll, ll> mp;
    f(i, 0, n)
    {
    	cin>>a[i];
    	mp[a[i]]++;
    }
    map <ll, ll>::iterator it;
    for(it = mp.begin(); it != mp.end(); it++)
    {
    	ll y = it->S;
    	ans += (y*(y-1))/2;
    }
    f(i, 0, n)
    {
    	ll y = mp[a[i]];
    	cout<<ans - (y*(y-1))/2 + ((y-1)*(y-2))/2<<endl;
    }
    return 0;
}

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

int main()
{
    int n, k, sum{};
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        sum += 2 * std::min(x, k - x);
    }
    printf("%d\n", sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<LL> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    //! Binary search. (l, r]
    LL l = -1;
    LL r = N-1;

    while (1 < r-l) {
        LL m = (r+l) / 2;

        if (N-m <= P) {
            //! m is already in top P before adding points
            r = m;
            // cout << "N-m <= P, setting m to r" << endl;
        } else {
            // cout << "P < N-m" << endl;
            LL maxM = A[m]+M; //! the max points that m can take
            //! the best case for m is to distribute all points to low score problems in greedy way
            LL remaining = max(0LL, V-m-1) * M;

            //! distribute points to top (P-1) problems
            remaining -= (P-1) * M;
            remaining = max(0LL, remaining);

            // cout << "maxM, remaining = " << maxM << ' ' << remaining << endl;

            bool ok = true;
            for (LL i = N-P; ok && m < i; --i) {
                if (maxM < A[i]) {
                    ok = false;
                } else {
                    remaining -= min(M, maxM-A[i]);
                    remaining = max(0LL, remaining);
                }
            }
            if (0 < remaining) {
                // cout << "ok = false, because 0 < remaining" << endl; 
                ok = false;
            }
            
            if (ok) {
                r = m;
            } else {
                l = m;
            }
        }
        // cout << "BOTTOM l , r = " << l << ' ' << r << endl;
    }

    cout << (N-r) << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate など
#include <stdexcept>
#include <cassert> // assert
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// constexpr inline ll MOD = 1'000'000'007;
constexpr int max_n = 200000 + 9;
int n, m, k;
vector<int> as(max_n), bs(max_n);
vector<int> suma(max_n), sumb(max_n);

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m >> k;
    REP(i, n)
    {
        cin >> as[i];
    }
    REP(i, n)
    {
        suma[i + 1] = suma[i] + as[i];
        if (suma[i + 1] > k)
        {
            n = i;
            break;
        }
    }
    REP(i, m)
    {
        cin >> bs[i];
    }
    REP(i, m)
    {
        sumb[i + 1] = sumb[i] + bs[i];
        if (sumb[i + 1] > k)
        {
            m = i;
            break;
        }
    }

    int res = 0;
    for (int i = 0, j = m; i <= n && suma[i] <= k; i++)
    {
        while (j > 0 && sumb[j] > k - suma[i])
        {
            j--;
        }
        res = max(res, i + j);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 6288
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cassert>

using ll=long long;
using namespace std;

int main() {
    ll N, A, B, C, D;

    cin >> N >> A  >> B >> C >> D;
    vector<char> S(N+1);
    for (auto i=1; i <=N; i++) cin >> S[i];
    // cout << "....:::" << S[1] << endl;

    for (auto i=A+1; i<=C-1; i++) {
        if (S[i]=='#' && S[i+1]=='#') { cout << "No" << endl; return 0;}
    }

    for (auto i=B+1; i<=D-1; i++) {
        if (S[i]=='#' && S[i+1]=='#') { cout << "No" << endl; return 0;}
    }

    if (C > D) { // A pass B
    // check 3 empty from B-1
        bool flag = false;
        for (auto i=B-1; i<=D-1; i++) {
            if (S[i] == '.' && S[i+1] == '.' && S[i+2] == '.')
            flag = true;
        }

        if (!flag) { cout << "No" << endl; return 0;}
    }


    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 888
import collections


def main():
    n = int(input())
    a = input_list()
    sum_a = sum(a)
    wa = []
    for i, v in enumerate(a):
        if i == 0:
            wa.append(v)
        else:
            wa.append(v+wa[i-1])
    ans = float('inf')
    for i in range(n-1):
        ans = min(ans, abs(sum_a-(wa[i]*2)))
    print(ans)


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


if __name__ == '__main__':
    main()


Measured memory_bytes: 86864
def ans():
  n = int(input())
  ans = 0
  for i in range(1,n+1):
    count = 0
    for j in range(1,i+1):
      if i % j == 0:
        count += 1
      if count == 8 and i % 2 != 0:
        ans += 1
  print(ans)
  return

ans()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int h, n;
    cin >> h >> n;
    vector<P> spell(n);
    rep(i, n) cin >> spell[i].first >> spell[i].second;
    vector<vector<int>> dp(n + 1, vector<int>(h + 1, INT32_MAX));
    dp[0][0] = 0;

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j <= h; ++j)
        {
            int d = j - spell[i].first;
            chmax(d, 0);

            chmin(dp[i][j], dp[i][d] + spell[i].second);
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][j], dp[i][d] + spell[i].second);
        }
    }
    cout << dp[n][h] << endl;

    return 0;
}

Measured memory_bytes: 39424
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

int a[3];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	for (int i = 0; i < 3; i++)
		cin >> a[i];
	for (int i = 0; i < 3; i++)
		for (int t = 0; t < 3; t++)
			if (a[i] != a[t])
				return cout << "No\n", 0;
	cout << "Yes\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main() {
    string s;
    cin >> s;
    if("2019/04/30" >= s) cout << "Heisei" << endl;
    else cout << "TBD" << endl;

    return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
xyh=n.times.map{gsmi}

0.upto(100) do |i|
  0.upto(100) do |j|
    hh=nil
    can=false
    xyh.each do |x,y,h|
      next if h==0
      h_ex=h+(x-i).abs+(y-j).abs
      #puts h_ex
      if hh
        if hh!=h_ex
          can=false
          break
        else
          can=true
        end
      else
        hh=h_ex
        can=true
      end
    end
    if can
      # 0だけ調査
      xyh.each do |x,y,h|
        next unless h==0
        h_ex=hh-(x-i).abs-(y-j).abs
        if h_ex>0
          can=false
          break
        end
      end
      if can
        putsend "#{i} #{j} #{hh}"
      end
    end
  end
end

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

int32_t main()
{
	string s;
	cin>>s;
	if(s == "ABC")
	{
		cout<<"ARC"<<endl;

	}
	else 
	{
		cout<<"ABC"<<endl;
	}
	

	


}


Measured memory_bytes: 3572
#include <iostream>

using namespace std;
int main (){
    int a[9];
    for (int i = 0; i < 9; i++){
        cin >> a[i];
    }
    bool state[9]={};
    int n;
    cin >> n;
    int b[n];
    for (int i = 0; i < n; i++){
        cin >> b[i];
        for (int j = 0; j < 9; j++)
        {
            if(a[j]==b[i]) state[j]=true;
        }
    }

    if(state[0]*state[1]*state[2]==true ||
       state[3]*state[4]*state[5]==true ||
       state[6]*state[7]*state[8]==true ||
       state[0]*state[3]*state[6]==true ||
       state[1]*state[4]*state[7]==true ||
       state[2]*state[8]*state[8]==true ||
       state[0]*state[4]*state[8]==true ||
       state[2]*state[4]*state[6]==true) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
let rec max_heapify h (a:int array) j =
  let largest = ref j
  in
  if j*2 <= h then
    begin
      if a.(j*2-1) > a.(j-1) then largest := j*2;
      if j*2+1 <= h && a.(j*2) > a.(!largest-1) then largest := j*2+1;
      if !largest != j then
        begin
          let temp = a.(!largest-1) in
          a.(!largest-1) <- a.(j-1);
          a.(j-1) <- temp;
          max_heapify h a !largest
        end
    end
;;

let build_max_heap h (a:int array) =
  let rec loop = function
      0 -> ()
    | i -> max_heapify h a i;loop (i-1)
  in loop (h/2)
;;

let () =
  let h = read_int () in
  let a = Array.init h (fun _ -> Scanf.scanf " %d" (fun x -> x))
  in
  build_max_heap h a;
  Array.iter (fun x -> print_string " ";print_int x) a;
  print_newline ();;

Measured memory_bytes: 8584
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX_V 510

struct edge{ int to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];

int V, E;

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to,cap,(int)G[to].size()});
	G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		memset(used, 0,sizeof(used));
		int f = dfs(s,t,INF);
		if(f == 0) return flow;
		flow += f;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int a, M, s, t, b;
	string U;
	
	cin>>V>>M;
	
	E = V+1;
	
	cin>>U;
	
	for(int i = 0; i < V; i++){
		cin>>a;
		if(U[i] == 'R'){
			add_edge(0,i+1,a);
			add_edge(i+1,E,0);
		} else {
			add_edge(0,i+1,0);
			add_edge(i+1,E,a);
		}
	}
	
	for(int i = 0; i < M; i++){
		cin>>s>>t>>b;
		if(s < t) add_edge(s,t,b);
		else add_edge(t,s,b);
	}
	
	
	cout<<max_flow(0,E)<<endl;
	
	return 0;
}


Measured memory_bytes: 3360
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

struct union_find{
    vector<int> par, rank, s;
    union_find(int n){
        par = vector<int>(n);
        rank = vector<int>(n);
        s = vector<int>(n,1);
        init(n);
    }
    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
    int find(int x){
        if(par[x]==x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
    int size(int x){
        return s[find(x)];
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        int sx=size(x),sy=size(y);
        if(x==y) return;
        if(rank[x]<rank[y]){
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
        s[find(x)]=sx+sy;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

using P=pair<int,int>;
int main(){
    int64_t N,M;
    cin>>N>>M;
    union_find UF(N);
    vector<P> B;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        B.emplace_back(a-1,b-1);
    }
    vector<int64_t> ans(M);
    ans[M-1]=N*(N-1)/2;
    for(int i=M-1;i>0;i--){
        int a,b;
        tie(a,b)=B[i];
        if(!UF.same(a,b)){
            ans[i-1]=ans[i]-int64_t(UF.size(a))*UF.size(b);
            UF.unite(a,b);
        }else{
            ans[i-1]=ans[i];
        }
    }
    for(auto a:ans) cout<<a<<endl;
    return 0;
}

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

int main()
{
    int X;

    cin >> X;

    for (int i = X; true; i++)
    {
        bool flg = false;

        for (int j = 2; j < sqrt(i); j++)
        {
            if (i % j == 0)
            {
                flg = true;
            }
        }

        if (flg == false)
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
from itertools import accumulate


N = int(input())
S = input()

black = [0]*N
white = [0]*N

for i, s in enumerate(S):
    if s == '#':
        black[i] = 1
    else:
        white[i] = 1

# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]

ans = []
for i in range(N+1):
    ans.append(black[i] + white[i])

print(min(ans))

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

using namespace std;

//#define FILE_IO

int N;
int a[20005], b[20005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
    {
        a[i] = (N + 1) * i;
        b[i] = (N + 1) * (N - i + 1);
    }

    for(int i = 1; i <= N; i++)
    {
        int p;
        scanf("%d", &p);
        b[p] += i;
    }

    for(int i = 1; i <= N; i++)
        printf("%d ", a[i]);
    printf("\n");
    for(int i = 1; i <= N; i++)
        printf("%d ", b[i]);
    printf("\n");

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N,T,A;
    cin >> N >> T >> A;

    vector<int> H(N);
    vector<int> tmpr(N);
    int i;
    for(i = 0; i < N; i++)
    {
        cin >> H.at(i);
        tmpr.at(i) = 1000 * (T - 0.006 * H.at(i));
    }

    int def_min = 600*1000;
    int idx = i;

    for(i = 0; i < N; i++)
    {
        if( abs(tmpr.at(i)-1000 * A) < def_min )
        {
            def_min = abs(tmpr.at(i)-1000 * A);
            idx = i+1;
        }
    }

    cout << idx;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

class unionfind {
    std::vector<int> parents;
    std::vector<int> sizes;
    public:
        unionfind(int n) : parents(n), sizes(n, 1) {
            iota(begin(parents), end(parents), 0);
        }
        int root(int x) {
            if (parents[x] == x)
                return x;
            else
                return parents[x] = root(parents[x]);
        }
        bool is_same(int x, int y) {
            return root(x) == root(y);
        }
        void unite(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx == ry)
                return;
            parents[rx] = ry;
            sizes[ry] += sizes[rx];
            sizes[rx] = 0;
        }
        // root size
        int size(int x) {
            return sizes[x];
        }
};

int main() {
    fastio;
    ll ans=0;
    ll N,M;
    cin >> N >> M;
    unionfind uf(N);
    rep(i,M) {
        int x,y,z;
        cin >> x >> y >> z;
        --x; --y;
        uf.unite(x,y);
    }
    rep(i,N) {
        if (uf.root(i) == i) {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
    	if(s[i]!=s[n-1-i]){
    		cout<<"No";
    		return 0;
    	}
    }
    for(int i=0;i<(n-1)/2;i++){
    	if(s[i]!=s[(n-1)/2-1-i]){
    		cout<<"No";
    		return 0;
    	}
    }
    for(int i=(n+1)/2;i<n;i++){
    	if(s[i]!=s[n-1-i]){
    		cout<<"No";
    		return 0;
    	}
    }
    cout<<"Yes";
 
	return 0;
}

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

using namespace std;

int main() {
    // 入力値
    string s;
    cin >> s;

    int count = 0;
    if (s.at(0) == '1') count++;
    if (s.at(1) == '1') count++;
    if (s.at(2) == '1') count++;

    // 出力値
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

const int mx=200010;
const ll mod=1e9+7;

int n;
int x[10],y[10];
ld lengxy[10][10];
string s;
ld ans = 0;


int main(){
  cin >> n;
  rep(i,n){cin >> x[i] >> y[i];}
  rep(i,n){ rep(j,n){
    lengxy[i][j] = sqrtl(pow(abs(x[i]-x[j]),2)+pow(abs(y[i]-y[j]),2));
    ans += lengxy[i][j];
  }}
 
  cout << fixed << setprecision(10) << ans/n << endl;
  return 0;  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main()
{
  int n;
  scanf("%d",&n);
  
  double x;
  
  x=sqrt(n);
  
  x=(int)x;
  
  x=pow(x,2);
  
  printf("%d\n",(int)x);
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int i, j;
        String level[] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};
        double levelData500[] = {35.5d, 37.5d, 40.0d, 43.0d, 50.0d, 55.0d, 70.0d};
        double levelData1000[] = {71d, 77d, 83d, 89d, 105d, 116d, 148d};
        double inputDataSet1, inputDataSet2;
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            i = j = 0;
            inputDataSet1 = sc.nextDouble();
            inputDataSet2 = sc.nextDouble();
            while (i < 7) {
                if (inputDataSet1 < levelData500[i])
                    break;
                i++;
            }

            while (j < 7) {
                if (inputDataSet2 < levelData1000[j])
                    break;
                j++;
            }

            if (i <= j)
                System.out.println(level[j]);
            else
                System.out.println(level[i]);
            
        }
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> in(n);
    int i;
    rep(i, n) cin >> in[i];
    sort(in.begin(), in.end());
    reverse(in.begin(), in.end());
    ll ans = in[0];
    n-=2;
    for (int i = 1; n; i++) {
        ans += in[i] * min(2, n);
        n -= min(2, n);
    }
    cout << ans << endl;
}


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

#define pb  push_back
#define mp  make_pair
#define int long long
#define itr ::iterator 

typedef pair<int,int>  pii;

const int MAX=1e5;

vector<int> vec[MAX];

int N,M,X,Y,arr[MAX],dp[MAX];

void dfs(int node,int par)
{
	for(auto A:vec[node])
	{
		if(A==par)
			continue;
		dfs(A,node);
	}
	for(auto A:vec[node])
	{
		if(A==par)
			continue;
		if(arr[A]<arr[node] and dp[A]==0)
			dp[node]=1;
	}
	return ;
}

signed main()
{
	ios_base::sync_with_stdio(false);

	cin>>N;
	for(int A=1;A<=N;A++)
		cin>>arr[A];
	for(int A=1;A<N;A++)
	{
		cin>>X>>Y;
		vec[X].pb(Y);
		vec[Y].pb(X);
	}
	for(int A=1;A<=N;A++)
	{
		for(int B=1;B<=N;B++)
			dp[B]=0;
		dfs(A,0);
		if(dp[A])
			cout<<A<<" ";
	}
	return 0;
}

Measured memory_bytes: 2944
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
per = (1..N).to_a.permutation.to_a

a = per.index(lines[1])
b = per.index(lines[2])

if a < b then
  print b - a
else
  print a - b
end

Measured memory_bytes: 6780
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

import numpy as np

def main():
    n = ni()
    a = np.array(list(li()))
    b = np.array(list(li()))

    idx = b.argsort().tolist()

    b = b[idx]
    a = a[idx]

    # N-1回以内なら達成可能か判定
    a_sorted = np.msort(a)
    if any(a_sorted > b):
        print('No')
        return

    # N-2回以内で達成可能か判定
    # 置換サイクルが複数あるなら可能
    if any(a_sorted[1:] <= b[:-1]):
        print('Yes')
        return

    perm = a.argsort().tolist()
    x = 0
    period = 0
    for i in range(n):
        period += 1
        x = perm[x]
        if x == 0:
            break

    print('Yes' if period < n else 'No')
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 24200
#include<stdio.h>

int main(){
  int array[15];
  int max,tmp;
  int i,j;
   
  for(i=1; i<=10; i++){
    scanf("%d",&array[i]);
  }
   
  for(i=1; i<=10; i++){
    max = i;
    for(j=i; j<=10; j++){
      if(array[j]>array[max]){
    max=j;
      }
    }
    if(i!=max){
      tmp=array[i];
      array[i]=array[max];
      array[max]=tmp;
    }
  }
   
  for(i=1; i<=3; i++){
    printf("%d",array[i]);
    if(i <= 3){
      printf("\n");
    }
  }
   
  return 0;
}

Measured memory_bytes: 604
//
// Created on 2020/09/24.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



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

    vector<vector<bool>>grid_1(h,vector<bool>(w,false));
    vector<vector<bool>>grid_2(w,vector<bool>(h,false));
    set<int>skip_h;
    set<int>skip_w;

    for (int i = 0; i < h; ++i) {
        string s;
        cin>>s;
        int skip = 0;
        for (int j = 0; j < w; ++j) {
            if(s[j] == '#'){
                grid_1[i][j] = true;
                grid_2[j][i] = true;
                skip++;
            }
        }
        if(skip == 0){
            skip_h.insert(i);
        }
    }

    for (int i = 0; i < w; ++i) {
        auto sum = accumulate(all(grid_2[i]),0);
        if(sum == 0){
            skip_w.insert(i);
        }
    }

    for (int i = 0; i < h; ++i) {
        if(skip_h.count(i) >= 1) continue;
        for (int j = 0; j < w; ++j) {
            if(skip_w.count(j) >= 1) continue;
            if(grid_1[i][j] == 1){
                cout<<'#';
            }else{
                cout<<'.';
            }

        }
        cout<<endl;
    }

    return 0;
}


Measured memory_bytes: 3604
//============================================================================
// Name        : template.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y); swap(x,z); 
    cout << x << " " << y << " " << z;
return 0;
}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static char S[100001], T[100001];

int main(void) {
	uint64_t A, B, K;

	scanf("%"PRIu64" %"PRIu64" %"PRIu64, &A, &B, &K);

	for (uint64_t cnt = 0; cnt < K; cnt++) {
		if (cnt % 2 == 0) {
			if (A % 2 != 0) {
				A--;
			}
			B += A / 2;
			A /= 2;
		}
		else {
			if (B % 2 != 0) {
				B--;
			}
			A += B / 2;
			B /= 2;
		}
	}

	printf("%"PRIu64" %"PRIu64, A, B);

	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python
# -*- coding: utf-8 -*-

POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def issame(self, dice1):
        if set(self.faces.values()) != set(dice1.faces.values()):
            return False
        if (dice1.faces["south"] == self.faces["west"] or dice1.faces["south"] == self.faces["east"]):
            self.roll("E")
        while dice1.faces["south"] != self.faces["south"]:
            self.roll("N")
        for n in range(4):
            if (dice1.faces == self.faces):
                # print("Me: " + str(self.faces))
                # print("You: " + str(dice1.faces))
                return True
                break
            else:
                self.roll("W")
        else:
            return False


def isalldifferent(dices):
    n = len(dices)
    for i in range(n):
        for j in range(i + 1, n):
            # print("Dice #{} vs Dice #{}". format(i, j))
            if dices[i].issame(dices[j]):
                return False
                break
    else:
        return True


def main():
    n = int(input())
    dices = [Dice(input().split()) for i in range(n)]
    print("Yes" if isalldifferent(dices) else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 7900
#include <iostream>

//#include <algorithm>
//#include <vector>
//#include <cmath>
#include <cstring>
//include <queue>
//#include <map>
//cout<<*itr<<endl;
//#define ll long long //data types used often, but you don't want to type them time by time
//#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
//#define FOREACH(itr,cont) for (auto itr=cont.begin(); itr!=cont.end(); itr++) // traverse an STL data structure
#define F(i,R) for (int i = 0; i < R; i++) //next four are for "for loops"

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
    char current[100];
    cin>>current;
    if(strcmp(current,"Sunny")==0)
    cout<<"Cloudy"<<endl;
    if(strcmp(current,"Cloudy")==0)
    cout<<"Rainy"<<endl;
    if(strcmp(current,"Rainy")==0)
    cout<<"Sunny"<<endl;
        
}

Measured memory_bytes: 256
def main():
    h, w = [int(e) for e in input().split()]
    s = [input() for i in range(h)]

    for hi in range(h):
        for wi in range(w):
            if s[hi][wi] == '.':
                continue

            flag = False
            for d in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                hp = hi + d[0]
                wp = wi + d[1]
                if hp < 0 or hp >= len(s) or wp < 0 or wp >= len(s[0]):
                    continue

                if s[hp][wp] == '#':
                    flag = True

            if not flag:
                print('No')
                exit()

    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 39536
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N, A[SIZE], B[SIZE];
  int A2[SIZE], B2[SIZE];
  map<int,int> mm, dicB;

  cin >> N;

  for (int i=0; i<N; i++) {
    cin >> A[i];
    A2[i] = A[i];
  }

  for (int i=0; i<N; i++) {
    cin >> B[i];
    B2[i] = B[i];
    dicB[B[i]] = i;
  }

  sort(A2, A2+N);
  sort(B2, B2+N);


  for (int i=0; i<N; i++) {
    if (A2[i] > B2[i]) {
      puts("No");
      return 0;
    }

    if (i > 0 && A2[i] < B2[i-1]) {
      puts("Yes");
      return 0;
    }

    mm[A2[i]] = dicB[B2[i]];
  }

  //全て異なる
  int now = 0;
  bool visited[SIZE] = {};

  for (int i=0; i<N; i++) {
    if (visited[now]) {
      puts("Yes");
      return 0;
    }

    visited[now] = true;

    now = mm[A[now]];
  }

  puts("No");

  return 0;
}


Measured memory_bytes: 12416
N, W = map(int, input().split())

weights = [0]*(N+5)
values = [0]*(N+5)

dp = [[0]*(W+5) for i in range(N+5)]

for i in range(N):
    weights[i], values[i] = map(int, input().split())
    for sum_w in range(W+1):
        if sum_w >= weights[i]:
            if dp[i+1][sum_w] < dp[i][sum_w-weights[i]]+values[i]:
                dp[i+1][sum_w] = dp[i][sum_w-weights[i]]+values[i]
        if dp[i+1][sum_w] < dp[i][sum_w]:
            dp[i+1][sum_w] = dp[i][sum_w]


print(max([max(row) for row in dp]))

Measured memory_bytes: 117872
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
a = 0
for i in range(N):
    a = a+B[i]

b = 0
for k in range(N-1):
    if A[k]+1 == A[k+1]:
        b = b+C[(A[k]-1)]

print(a+b)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace test01
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var monsters = Console.ReadLine().Split()
                           .Select(e => int.Parse(e));
            var max = monsters.Max();
            var m = monsters.Where(e => e < max);

            List<int> ans = new List<int>();
            if (!m.Any())
            {
                ans.Add(max);
            }
            else
            {
                foreach (var x in m)
                {
                    var gcd = Gcd(max, x);
                    if (gcd == 1)
                    {
                        ans.Add(gcd);
                        break;
                    }
                    else
                    {
                        ans.Add(gcd);
                    }

                }
            }
            Console.WriteLine(ans.Min());
            
        }

        // ユークリッドの互除法 
        public static int Gcd(int a, int b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}


Measured memory_bytes: 23008
#include <iostream>
using namespace std;
int main ()
{

    string s,t,u;
    int a,b;
    //cout<<"enter two strings \n";
    cin>>s>>t;
    //cout<<"enter two integers \n";
    cin>>a>>b;
    cin>>u;
    if(u==s)
     cout<<--a<<" "<<b;
    if (u==t)
     cout<<a<<" "<<--b;










}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size() - 1; ++i) {
    os << v[i] << " ";
  }
  if (v.size() > 0) {
    os << v[v.size() - 1] << endl;
  }
  return os;
}

struct TreeNode {
  vector<TreeNode *> children;
  TreeNode *par;
  int val;
  string color;
};

void dfs(TreeNode* prev, TreeNode* now, string color){
  if (!now) return;
  for (auto elem : now->children){
    if (elem == prev || elem->color.size() != 0) continue;
    elem->color = color;
    dfs(now, elem, color);
  }
}

int main() {
  int n;
  cin >> n;
  vector<vint> G(n);
  REP(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<TreeNode*> nodes;
  REP(i,n){
    TreeNode* tmp = new TreeNode();
    tmp->val = i;
    nodes.push_back(tmp);
  }
  vector<bool> memo(n,false);
  queue<int> que;
  que.push(0);
  memo[0] = true;
  while (que.size()) {
    int now = que.front();que.pop();
    for (int elem : G[now]){
      if (!memo[elem]){
        nodes[now]->children.push_back(nodes[elem]);
        nodes[elem]->par = nodes[now];
        que.push(elem);
        memo[elem] = true;
      }
    }
  }
  int cnt = 0;
  TreeNode* ch = nodes[n-1];
  while (ch->par != nodes[0]){
    ch = ch->par;
    ++cnt;
  }
  cnt /= 2;
  ch = nodes[n-1];
  REP(i,cnt){
    ch = ch->par;
  }
  ch->color = "w";
  dfs(ch->par, ch, "w");
  nodes[0]->color = "b";
  dfs(NULL, nodes[0], "b");
  int cnt_b = 0, cnt_w = 0;
  REP(i,n){
    if (nodes[i]->color == "w") ++cnt_w;
    else
      ++cnt_b;
  }
  if (cnt_w >= cnt_b) {
    cout << "Snuke" << endl;
  } else {
    cout << "Fennec" << endl;
  }
}

Measured memory_bytes: 20596
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1;
    ll r = x;
    while(n){
        if(n % 2) res = res * r % MOD;
        r = r * r % MOD;
        n /= 2;
    }
    return res;
}

ll r[100002];

int main()
{
    int n;
    cin >> n;
    ll a[100002];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) r[i] = (r[i - 1] + modpow(i, MOD - 2)) % MOD;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans = (ans + a[i] * ((r[i + 1] + r[n - i] + MOD - 1) % MOD) % MOD) % MOD;
    }
    for(int i = 1; i <= n; i++) ans = ans * i % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;



int main(void){

    ll N; cin>>N;

    if(N%2!=0){
        cout<<0<<endl;
        return 0;
    }
    N /= 2;
    ll ans = 0;
    while(N){
        ans += N/5;
        N/=5;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int k,t,maxn,i,a;cin >> k >> t;maxn = 0;
  for(i=0;i<k;i++){
    cin >> a;
    maxn = max(maxn,a);
  }
  cout << max(maxn-1-(k-maxn),0) << endl;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  string s;cin >> s;
  sort(s.begin(), s.end());
  if (s[0]==s[1] and s[2]==s[3] and s[1]!=s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3564