akhauriyash/Code-Regression huggingface dataset:
#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

vector<ll> factmemo, factmemoInv;
ll factmemoMod = -1;

ll factorial(int n, int M){
  if(factmemoMod == M) return factmemo[n];
  if(n <= 1) return 1;

  ll res = 1;
  for(int i=1; i<=n; i++) res = res * i % M;
  return res;
}

ll power(ll k, ll n, int M){
  ll res = 1;
  while(n > 0) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

void initFactorial(int n, int M){
  factmemo.assign(n+1, 0);
  factmemoInv.assign(n+1, 0);
  factmemoMod = M;
  factmemo[0] = 1;
  for(int i=1;i<=n;i++) factmemo[i] = factmemo[i-1] * i % M;
  factmemoInv[n] = power(factmemo[n], M-2, M);
  for(int i=n;i>0;i--) factmemoInv[i-1] = factmemoInv[i] * i % M;
}

//nCm nPm nHm (mod M)

/*Combination*/
ll C(int n, int m, int M){
  if(n < m) return 0;
  if(m == 0 || n == m) return 1;

  if(factmemoMod == M)
    return factmemo[n] * factmemoInv[m] % M * factmemoInv[n-m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(m, M) * factorial(n-m, M) % M;

  denom = power((int)denom, M-2, M);

  return numer * denom % M;
}
/*Permutation*/
ll P(int n, int m, int M){
  if(n < m) return 0;
  if(m == 0) return 1;

  if(factmemoMod == M)
    return factmemo[n] * factmemoInv[n-m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(n-m, M);

  denom = power((int)denom, M-2, M);

  return numer * denom % M;
}
/*Combination with Repetitions*/
ll H(int n, int m, int M){
  if(n == 0 && m == 0) return 1;
  return C(n+m-1, m, M);
}


ll calc(int H, int W, int K) {
  ll res = 0;

  for (int i=1; i<H; i++) {
    ll r = (ll)(H - i) * W % mod * W % mod * i % mod;

    r = r * C(H*W-2, K-2, mod) % mod;

    res += r % mod;
  }

  return res % mod;
}

int main() {
  int H, W, K;

  cin >> H >> W >> K;

  initFactorial(H * W, mod);

  cout << (calc(H, W, K) + calc(W, H, K)) % mod << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
//#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
string s;
int ans;
bool bad[105];
int main(){
    cin >> n >> s;
    {
        for(int i=0;i<n;i++){
            if(s[i] != '.') continue;
            int cnt = 0;
            int side = 0;
            for(int j=i-1;j>=0;j--){
                if(s[j] == 'B'){side++; break;}
                else if(s[j] == '.') cnt++;
            }
            for(int j=i+1;j<n;j++){
                if(s[j] == 'B'){side++; break;}
                else if(s[j] == '.') cnt++;
            }
            if(side == 2 && cnt == 0) continue;
            s[i] = 'W'; 
            vector<int>ers;
            for(int i=0;i<n;i++){
                if(s[i] != 'B') continue;
                bool bad = 0;
                for(int j=i-1;j>=0;j--){
                    if(s[j] == '.'){bad=1;break;}
                    else if(s[j] == 'W') goto nxt;
                }
                bad=1; nxt:;
                for(int j=i+1;j<n;j++){
                    if(s[j] == '.'){bad=1;break;}
                    else if(s[j] == 'W') goto nxt2;
                }
                bad=1; nxt2:;
                if(!bad) ers.pb(i);
            }
            if(ans < ers.size()) ans = ers.size();
            s[i] = '.';
        }
    }
    cout << ans << endl;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,q; cin>>k>>q;
    vll d(k);
    rep(i,k) cin>>d[i];
    while(q--){
        ll n,x,m; cin>>n>>x>>m; x%=m;
        vll dd(k);
        rep(i,k) dd[i] = d[i]%m;
        vll sum(k+1);
        rep(i,k) sum[i+1]=sum[i]+dd[i];
        ll tail = x + (n-1)/k*sum[k] + sum[(n-1)%k];
        vi zsum(k+1);
        rep(i,k)if(dd[i]==0) zsum[i+1]++;
        rep(i,k) zsum[i+1]+=zsum[i];
        ll ans=n-1;
        ans -= tail/m;
        ans -= (n-1)/k*zsum[k] + zsum[(n-1)%k];
        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {
	int N;
	cin>>N;
    vector<int>A(N);
    vector<int>B(N);
    vector<int>C(N);
    for(int i=0;i<N;i++) cin>>A.at(i);
    for(int i=0;i<N;i++) cin>>B.at(i);
    for(int i=0;i<N-1;i++) cin>>C.at(i);
    C.at(N-1)=0;
    int sum=0;
    for(int y:B) sum+=y;
    
    int count=A.at(0);
    for(int i=1;i<N;i++){
    	if(A.at(i)-1==A.at(i-1)) sum+=C.at(A.at(i-1)-1);
    }
    
    cout<<sum<<endl;
    
    
    
    
    
    
    
    
    
    
    
	return 0;
}

Measured memory_bytes: 256
N=int(input())
import copy
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d

  
cost=[list(map(int,input().split())) for i in range(N)]
D=copy.deepcopy(cost)
E=warshall_floyd(cost)
      
if D!=E: 
  print(-1)
  exit()
D=cost
for k in range(N):
  for i in range(N):
    for j in range(N):
      a,b,c=D[i][j],D[j][k],D[i][k]
      if a!=0 and b!=0 and c!=0:
        if D[i][j]==D[i][k]+D[k][j]:
          D[i][j]=0       
ans=0
for i in range(N):
  ans+=sum(D[i]) 
print(ans//2)


Measured memory_bytes: 76884
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

vector<string> split(char d,string s)
{
	stringstream ss(s);
	string t;
	vector<string> words;
	while(getline(ss,t,d))
	{
		words.pb(t);
	}

	return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
	auto start = chrono::high_resolution_clock::now();
#endif
	
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	int m;
	cin>>n>>m;
	vector<ll> arr(m);
	ll sum=0;
	for(auto &x:arr){
		cin>>x;
		sum+=x;
	}
	if(sum>n)cout<<-1;
	else cout<<n-sum;




#ifdef LOCAL
	auto end = chrono::high_resolution_clock::now();
	double time_taken =
		chrono::duration_cast<chrono::nanoseconds>(end - start).count();

	time_taken *= 1e-9;

	cerr << "\nTime taken by program is : " << fixed
		 << time_taken << setprecision(9);
	cerr << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 3728
//each exchange takes two steps
//
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long k,a,b;cin>>k>>a>>b;
  if(b-a<=2){cout<<k+1;return 0;}
  //first reach a;
  long long ret=1;
  long long z = min(k,a-1);
  ret+=z;
  k-=z;
  ret+=(b-a)*(k/2);
  ret+=(k%2);
  cout<<ret;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)

int main() {
    long n, k, q;
    cin >> n >> k >> q;
    long points[100010];
    rep(i, 100010) {
        points[i] = 0;
    }
    rep(i, q) {
        int a;
        cin >> a;
        points[a - 1]++;
    }
    rep(i, n) {
        if (k - (q - points[i]) > 0) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main()
{
  string s;
  cin>>s;
  string ans = s.substr(4);
  cout<<"2018"<<ans;
 
}


Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var n int
  fmt.Scan(&n)
  var p []int = primes(55555)
  var a []int
  for r:=1;r<5;r++ {
    a = []int{}
    for i:=0;i<len(p);i++ {
      if len(a) == n { break }
      if p[i]%5 == r {
        a = append(a,p[i])
      }
    }
    if len(a) == n { break }
  }
  fmt.Print(a[0])
  for i:=1;i<n;i++ {
    fmt.Print(" ")
    fmt.Print(a[i])
  }
  fmt.Println()
}
func primes(n int) []int {
  var m []int = make([]int,n+1)
  for i:=0;i<n+1;i++ {
    m[i] = i+1
  }
  m[0] = -1
  for i:=1;i<n+1;i++ {
    if m[i] < 0 { continue }
    for j:=i+m[i];j<n+1;j+=m[i] {
      m[j] = -1
    }
  }
  var p []int = []int{}
  for i:=1;i<n+1;i++ {
    if m[i] < 0 { continue }
    p = append(p,int(m[i]))
  }
  return p
}

Measured memory_bytes: 1280
from bisect import bisect_left
import sys
input = sys.stdin.readline

INF = 10**18

A, B, Q = map(int, input().split())
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(input())
    si = bisect_left(S,x)
    ti = bisect_left(T,x)
    res = INF
    res = min(res, max(S[si] - x, T[ti] - x))
    res = min(res, max(x - S[si - 1], x - T[ti - 1]))
    res = min(res, x + T[ti] - 2 * S[si - 1])
    res = min(res, -x + 2 * T[ti] - S[si - 1])
    res = min(res, x + S[si] - 2 * T[ti - 1])
    res = min(res, -x + 2 * S[si] - T[ti - 1])
    print(res)

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	int k=0;
	int b, c;
	b = 0;
	c = 0;
	while (k<n) {
		if (k % 2 == 0) {
			b += a.at(n - k - 1);
		}
		else {
			c += a.at(n - k - 1);
		}
		a.at(n - k - 1) = 0;
		k++;
	}
	cout << b - c << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int M = scan.nextInt();
		int[] A = new int [M];
		for (int i = 0; i < M; i++) {
			A[i] = scan.nextInt();
		}

		for (int i = 0; i < M; i++) {
			N -= A[i];
		}

		if (N < 0) {
			System.out.println(-1);
		} else {
			System.out.println(N);
		}
	}

}

Measured memory_bytes: 45988
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fi first
#define se second
#define MK make_pair
#define PB push_back
using namespace std;

typedef long long LL;
typedef pair<int ,int> PII;
const int N=1e6+10, P= 998244353;

void upsum(LL &a, LL b){a=(a+b)%P;}
LL inv[N], sumb[N], cnt[N], b[N], g[N], mu[N], p[N];
int n, m,pn;
bool vis[N];
void Init(int m){
	mu[1]=1;
	for (int i=2; i<=m; ++i){
		if ( !vis[i]) p[pn++] = i, mu[i]= -1;
		for (int j=0; j<pn && i*p[j]<=m; ++j){
			vis[i*p[j]]=true;
			if ( i%p[j]) mu[i*p[j]]=-mu[i];
				else{
					mu[i*p[j]]=0;break;
				}
		}
	}
	
}
int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	scanf("%d", &n); m= 1e6;
	Init(m);
	for (int i=0,x; i<n; ++i){
		scanf("%d", &x); b[x] += x;cnt[x]++;
	}
	inv[0]=inv[1]=1;
	for (int i=2; i<=m; ++i)
		inv[i] = (P-inv[P%i])*(P/i)%P;
	#ifdef che
	for (int i=1; i<=10; ++i) debug("mu[%d]= %lld, inv[]=%lld\n", i, mu[i],inv[i]);
	#endif
	// mu * 1/d
	for (int i=1; i<=m; ++i){
		for (int j=i; j<=m; j+=i) upsum(g[j], inv[i]*(P+mu[j/i]));
		#ifdef che
		if ( i<=15 ) debug("i=%d, g[]=%lld\n", i, g[i]);
		#endif
	}
	
	// (\sigma)^2-
	for (int i=1; i<=m; ++i){
		LL add=0, del=0;
		for (int j=i; j<= m; j+=i){
			upsum(add, b[j]);
			upsum(del, 1ll*j*j%P*cnt[j]%P);
		}
		sumb[i] = (add*add-del+P)%P*inv[2]%P;
		#ifdef che
		if ( i<=15) debug("i=%d ,add=%lld, del=%lld, sumb[]=%lld\n",i, add, del, sumb[i]);
		#endif
	}
	LL ans=0;
	for (int i=1; i<=m; ++i) upsum(ans, sumb[i]*g[i]);
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  string a;
  cin >> a;
  int alen = a.length();
  int cnt = 0;
  for(int i=0; i<alen/2; i++){
    if(a[i]!=a[alen-1-i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

double getMoreHeadsProb(vector<double> inp) {
    int n=inp.size();
    vector<vector<double>> dp(n+1,vector<double>(n+1,0));
    dp[0][0]=1;
    for(int i=1;i<=n;i++) {
        for(int j=0;j<=n;j++) {
            dp[i][j]=j==0?dp[i-1][j]*(1-inp[i-1]):dp[i-1][j]*(1-inp[i-1])+dp[i-1][j-1]*inp[i-1];
        }
    }
    double res=0;
    for(int i=n/2+1;i<=n;i++) {
        res+=dp[n][i];
    }
    return res;
}

int main(void){
    // Your code here!
    int n=0;
    cin>>n;
    vector<double> inp(n,0);
    for(int i=0;i<n;i++)cin>>inp[i];
    cout<<setprecision(15)<<getMoreHeadsProb(inp)<<endl;
}


Measured memory_bytes: 73768
#include<iostream>
using  namespace std;
int main(){
char a[16];
for(int i=0;i<16;i++){cin>>a[i];}
int count=0;
char b[]="CODEFESTIVAL2016";
for(int i=0;i<16;i++){
  if(a[i]==b[i]){count++;}
}
cout<<16-count;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;

int main(){
	int i,j;
	char s[3],temp;
	char ans[3] = {0};
	scanf("%s",s);
	if(strlen(s) == 2)
		cout << s << endl;
	if(strlen(s) == 3){
		for(i = 0;i < 3;i++){
			temp = s[i];
			ans[2-i] = temp;
		}
		for(j = 0;j < 3;j++){
			if(j == 2){
				printf("%c\n",ans[j]);
				break;
			}
			printf("%c",ans[j]);
		}
	}
	return 0;
}

Measured memory_bytes: 256
def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1])


Measured memory_bytes: 28120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, m;

int main(void){
	while(cin >> n >> m, n||m){
		int cost[120][120];
		int timm[120][120];
		fill_n(*cost, 120*120, 10000000);
		fill_n(*timm, 120*120, 10000000);
		for(int i = 0; i < n; i++){
			int a, b,c,t;
			cin >> a >> b >> c >> t;
			a--;b--;
			cost[a][b] = c;
			cost[b][a] = c;
			timm[a][b] = t;
			timm[b][a] = t;
		}
		for(int k=0;k<m;++k)for(int i=0;i<m;++i)for(int j=0;j<m;++j){
			cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			timm[i][j] = min(timm[i][j], timm[i][k] + timm[k][j]);
		}
		int k;
		cin >> k;
		rep(i, k){
			int a, b, c;
			cin >> a >> b >> c;
			a--;b--;
			if(!c)
				cout << cost[a][b] << endl;
			else
				cout << timm[a][b] << endl;
		}
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1272
#include<iostream>
using namespace std;
  
int main(){
int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;
if(x+r<=W&&y+r<=H&&x-r>=0&&y-r>=0 ){
cout<<"Yes\n";
}
else{
cout<<"No\n";
}
  
return 0;
}

Measured memory_bytes: 1128
import fractions
n = int(input())
a = list(map(int, input().split()))
forward = [0]
back =[0]
for i in range(0,n-1):
    forward.append(fractions.gcd(forward[i], a[i]))
    back.append(fractions.gcd(back[i], a[n-i-1]))
ans = 0
for i in range(n):
    ans = max(ans, fractions.gcd(forward[i], back[n-1-i]))
print(ans)


Measured memory_bytes: 16148
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    vector<int> x, y;
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == 'B')
            {
                x.push_back(i + j);
                y.push_back(i - j);
            }
        }
    }
    int sz = x.size();
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    int ret = max(x[sz - 1] - x[0], y[sz - 1] - y[0]);
    cout << ret << endl;
}



Measured memory_bytes: 9364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp21 {
    class Program {
        static void Main(string[] args) {
            //入力シリーズ
            int N = int.Parse(Console.ReadLine());

            int[] A = new int[N];

            int[][] x = new int[N][];
            int[][] y = new int[N][];

            for (int i = 0; i < N; i++) {
                A[i] = int.Parse(Console.ReadLine());

                x[i] = new int[A[i]];
                y[i] = new int[A[i]];

                for (int j = 0; j < A[i]; j++) {
                    var p = Console.ReadLine().Split(' ').Select(q => int.Parse(q)).ToArray();
                    x[i][j] = p[0] - 1;
                    y[i][j] = p[1];
                }
            }

            //1がhonest, 0がdishonestである

            //解答
            int ans = 0;

            //N人のhonest or dishonestについて、ビットで全可能性を探索
            for (int s = 0; s < (1 << N); s++) {
                //全員のパターンのstringを作成する
                string st = "";
                for (int i = 0; i < N; i++) {
                    if ((s & (1 << (N - i - 1))) != 0) {
                        st += "1";
                    } else {
                        st += "0";
                    }
                }

                //カウンタ
                int cnt = 0;

                //Console.WriteLine(st);

                //左からi番目の人のビットが立っている（=honest）ときに、妥当性を調べる
                for (int i = 0; i < N; i++) {
                    if ((s & (1 << (N - i - 1))) != 0) {
                        //if (A[i] == 0) {
                        //    cnt++;
                        //    //Console.WriteLine("a");
                        //}

                        for (int j = 0; j < A[i]; j++) {
                            if (st[x[i][j]].ToString() == y[i][j].ToString()) {
                                //cnt++;
                                //Console.WriteLine("b");
                            } else if (x[i][0] == -1) {
                                //cnt++;
                                //Console.WriteLine("d");
                            } else {
                                //ダメだったときはループを抜ける
                                goto skip;
                            }
                            
                        }
                        cnt++;
                    }
                }

                ans = Math.Max(ans, cnt);

                skip:;
            }


            Console.WriteLine(ans);
        }
    }
}

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

int main(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; i++){
    int s = i % 10, t = i / 10000 % 10;
    int u = i / 10 % 10, v = i / 1000 % 10;
    if(s == t && u == v){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>
#include <cstdlib>

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil;
    nil -> prev = nil;
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x -> key = key;

    x ->next = nil -> next;
    nil -> next -> prev = x;
    nil -> next = x;
    x -> prev = nil;
}

Node* listSearch(int key){
    Node *cur = nil -> next;
    while(cur != nil && cur -> key != key){
        cur = cur -> next;
    }
    return cur;
}

void deleteNode(Node *t){
    if(t == nil)return;
    t -> prev -> next = t -> next;
    t -> next -> prev = t -> prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil -> next);
}

void deleteLast(){
    deleteNode(nil -> prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void printList(){
    Node *cur = nil -> next;
    int isf = 0;
    while(1){
        if (cur == nil)break;
        if (isf++ > 0)printf(" ");
        printf("%d",cur -> key);
        cur = cur -> next;
    }
    printf("\n");
}


int main(){
    int key, n, i;
    char com[20];
    scanf("%d",&n);
    init();
	for(i=0;i<n;i++){
		scanf("%s%d",com, &key);
		if(com[0]=='i'){
			insert(key);
        }
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F')deleteFirst();
				else if(com[6]=='L')deleteLast();
			}else{
				deleteKey(key);
			}
		}       
    }
    printList();
    return 0;
}


Measured memory_bytes: 33984
/*input
10
1 2 4 8 16 32 64 128 256 512
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll inv(ll n){
	if(n==1) return 1;
	return (MOD-MOD/n)*inv(MOD%n)%MOD;
}
ll a[maxn];
ll ans=0;

ll fac=1;
ll I[maxn];

int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];	
	REP(i,n) fac=fac*(n-i)%MOD;
	REP(i,n) I[i+1]=inv(i+1);

	ll cur=0;
	REP(i,n) cur=(cur+I[i+1])%MOD;

	REP(i,n){
		ans+=a[i]*cur%MOD;
		ans%=MOD;
		cur+=I[i+2];
		cur-=I[n-i];
		cur=(cur+MOD)%MOD;
	}
	cout<<ans*fac%MOD<<'\n';

	return 0;
}


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

public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String w = br.readLine();
		StringBuilder sb = new StringBuilder();
		while(sb.indexOf("END_OF_TEXT") == -1)
		{
			sb.append(" " + br.readLine());
		}
		StringBuilder sb2 = new StringBuilder();
		sb2.append(sb.toString().toLowerCase());
		int chk = 0, sum = 0;
		while(true)
		{
			chk = sb2.indexOf(" " + w + " ", chk);
			if(chk==-1)	break;
			sum++;
			chk++;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 24312
#include<stdio.h>
#define N 101
int sum[N][N],num[N],tum[N];
int n,i;

void rum(int xu){
  int a;
  tum[xu]=++i;
  for(a=0;a<n;a++)
    {
      if(sum[xu][a] && tum[a]==0)rum(a);
    }
  num[xu]=++i;
}

      
int main()
{
  int a,b,c,d,e;
  scanf("%d",&n);
  for(a=0;a<n;a++)
    {
      tum[a]=0;
      num[a]=0;
      for(b=0;b<n;b++)sum[a][b]=0;
    }
  for(a=0;a<n;a++)
    {
      scanf("%d",&c);
      scanf("%d",&d);
      for(b=0;b<d;b++)
	{
	  scanf("%d",&e);
	  sum[c-1][e-1]=1;
	}
    }
  i=0;
  for(a=0;a<n;a++)
    {
      if(tum[a]==0)
	rum(a);
    }
  for(a=0;a<n;a++)printf("%d %d %d\n",a+1,tum[a],num[a]);

  return 0;
}

	
  
  
  
			    			    
	
	
  



Measured memory_bytes: 2088
s=list(input().split())
A = []

for x in s:
    A.append(x)
    
    if x == '+':
        A.pop()
        a,b = A[-2],A[-1]
        A.pop()
        A.pop()
        A.append(int(a)+int(b))
    elif x == '-':
        A.pop()
        a,b = A[-2],A[-1]
        A.pop()
        A.pop()
        A.append(int(a)-int(b))
    elif x == '*':
        A.pop()
        a,b = A[-2],A[-1]
        A.pop()
        A.pop()
        A.append(int(a)*int(b))
        
print(A[0])


Measured memory_bytes: 5596
import bisect 


def make_prime_numbers(n):
    """n以下の素数を列挙したリストを出力する
    計算量: O(NloglogN)
    入出力例: 30 -> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    """
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(2 * i, n + 1, i):
            is_prime[j] = False
    prime_numbers = [i for i in range(n + 1) if is_prime[i]]
    return prime_numbers


prime_numbers = make_prime_numbers(10 ** 6)
while True:
    try:
        n = int(input())
    except:
        break
    print(bisect.bisect_right(prime_numbers, n))


Measured memory_bytes: 16408
#include<algorithm>
#include<cmath>
#include<functional> //sortのgreater
#include<iostream>
#include<numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include<string> //文字列
#include<vector>

using namespace std;
typedef long long ll;

int main()
{
    // Input
    int a, b, k;
    cin >> k;
    cin >> a >> b;

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}


Measured memory_bytes: 3040
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int a,b;
    char op;
    cin>>a>>op;
    cin>>b;
    
    if(op=='+') p(a+b);
    else p(a-b);

}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
          printf("a < b\n");
          }
          else if(a>b){
          printf("a > b\n");
          }
          else{
          printf("a == b\n");
          }
 return 0;
}

Measured memory_bytes: 2600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='1'){
            s[i]='9';
        }else{
            s[i]='1';
        }
    }
    cout<<stoi(s)<<endl;
}


Measured memory_bytes: 256
<?php

$stdin = preg_split('/ /', trim(fgets(STDIN)));
$a = intval($stdin[0]);
$b = intval($stdin[1]);

if ($a > $b) {
	print("a > b\n");
} elseif ($a < $b) {
	print("a < b\n");
} else {
	print("a == b\n");
}

Measured memory_bytes: 6612
import math

n=int(input())
x=input().split()
y=input().split()
A=[]
# case p=1
su=0
i=0
while i<n:
    su+=math.sqrt((int(x[i])-int(y[i]))*(int(x[i])-int(y[i])))
    i+=1
A.append(su)

# case p=2
su2=0
l=0
while l<n:
    su2+=(int(x[l])-int(y[l]))*(int(x[l])-int(y[l]))
    l+=1
A.append(math.sqrt(su2))

# case p=3
su3=0
m=0
while m<n:
    su3+=math.pow(math.sqrt(math.pow(int(x[m])-int(y[m]),2)),3)
    m+=1
A.append(math.pow(su3,1/3))

# case p=mugendai
mu=[]
q=0
while q<n:
    mu.append(math.sqrt(math.pow(int(x[q])-int(y[q]),2)))
    q+=1
M=max(mu)
A.append(M)

for Ans in A:
    print(Ans)



Measured memory_bytes: 5728
# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


# 最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

a,b,c,d = input().split(' ')

a = int(a)
b = int(b)
c = int(c)
d = int(d)

hoge = lcm(c,d)

counter = 0

counter = counter + ((b // c) + (b // d) - (b // hoge))
counter = counter - (((a - 1) // c) + ((a - 1) // d) - ((a - 1) // hoge))

print(b - a + 1 - counter)


Measured memory_bytes: 3064
import math
a, b, x = map(int, input().split())
if (a * a * b >= 2 * x):
    print((math.pi / 2 - math.atan(2 * x / (a * b * b))) * 180 / math.pi)
else:
    print(math.atan(2*(b-x/a/a)/a)*180/math.pi)



Measured memory_bytes: 3188
#include<iostream>
int main() {
	int S;
	std::cin >> S;
	int h = S / 3600;
	int a = S % 3600;
	int m = a / 60;
	int s = a % 60;
	std::cout << h << ":" << m << ":" << s << std::endl;
	return 0;
}
    

Measured memory_bytes: 1164
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll a[100][100];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n>>m>>c;
    rep(i,m)cin>>b[i];
    rep(i,n){
        rep(j,m){
            cin>>a[i][j];
        }
    }
    rep(i,n){
        cnt=c;
        rep(j,m){
            cnt+=a[i][j]*b[j];
        }
        if(cnt>0)ans++;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
# N = gets_i

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
# N, M = gets_i_list
# list = gets_i_list

N, C, K = gets_i_list
t_list = []
N.times do
  t_list.push(gets_i)
end
t_list.sort!

t_end = t_list[0] + K
p_count = 0
count = 1
t_list.each_with_index do |t, i|
  if t <= t_end && p_count < C
    # 乗れた
    p_count += 1
  else
    # 乗れない
    t_end   = t + K
    count  += 1
    p_count = 1
  end
end

puts count

Measured memory_bytes: 4272
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

int a[8];
int d[4] = {-1, 1, -4, 4};

map<string, int> mymap;

void bfs() {
  queue<string> q;
  q.push("01234567");
  mymap["01234567"] = 0;
  while (!q.empty()) {
    string cur = q.front();
    string nxt;
    q.pop();
    int p = (int) cur.find("0");
    for (int i = 0; i < 4; ++i) {
      int np = p + d[i];
      if (np >= 0 && np < 8 && (p != 3 || d[i] != 1) && (p != 4 || d[i] != -1)) {
        nxt = cur;
        nxt[np] = '0';
        nxt[p] = cur[np];
        if (mymap.find(nxt) == mymap.end()) {
          mymap[nxt] = mymap[cur] + 1;
          q.push(nxt);
        }
      }

    }
  }
}

int main() {
  bfs();
  while (cin >> a[0]) {
    for (int i = 1; i < 8; ++i) {
      cin >> a[i];
    }
    string s = "";
    for (int i = 0; i < 8; ++i) {
      s += a[i] + '0';
    }
    if (mymap.find(s) == mymap.end())
      cout << -1 << endl;
    else
      cout << mymap[s] << endl;
  }
  return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

void solve() {
  string s; cin >> s;
  long long ans = 0, count = 0;
  for (int i = 0; i < (int)s.size(); ++i) {
    if (s[i] == 'B') continue;
    ans += i-count;
    ++count;
  }
  cout << ans;
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3780
#include<stdio.h>

int main(){
	int way, num, result[30];
	int a, b, c;
	int i;

	scanf("%d",&way);
	scanf("%d",&num);
	for(i=0;i<=way;i++) result[i]=i;
	for(i=0;i<num;i++){
		scanf("%d,%d",&a,&b);
		c=result[a];
		result[a]=result[b];
		result[b]=c;
	}
	for(i=1;i<=way;i++) printf("%d\n",result[i]);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
double x[10],y[10],total=0.00;
int a[10];
double distant(double x1,double x2,double y1,double y2)
{
	double distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)*1.00);
	return distance;
}
double get(int a)
{
	int total=1;
	for (int i=1;i<=a;i++)  total*=i;
	return double(total*1.00);
}
int main()
{
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>x[i]>>y[i];
	for (int i=1;i<=n;i++)  a[i]=i;
	do
	{
		double sumv=0.000;
		for (int i=2;i<=n;i++)
		{
			sumv+=distant(x[a[i-1]],x[a[i]],y[a[i]],y[a[i-1]]);
		}
		total+=sumv;
	}while(next_permutation(a+1,a+n+1));
	cout<<fixed<<setprecision(10)<<total*1.00/(get(n)*1.00)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	private static int counter = 0;
	private static int upperOrder = 0;
	private static int lowerOrder = 0;
	
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		long n = sc.nextLong();
		String res = "";
		
		while (n > 0) {
			long r = n % 26;
			res = (char)(--n % 26 + 'a') + res;
			
			n /= 26;
		}
		
		System.out.println(res);
	}
	
	public static void permuteHelper(int[] nums, int start, int end, List<String> ans) {
        if (start == end) {
            String str = "";
            for (int num: nums) {
                str += ("" + num);
            }
            ans.add(str);
        } else {
            for (int i = start; i < end; i++) {
                swap(nums, i, start);
                permuteHelper(nums, start + 1, end, ans);
                swap(nums, i, start);
            }
        }
    }
	
	static public void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
	
	static boolean isEqual(int[] a, int[] b) {
		for (int i = 0; i < a.length; i++) {
			if (a[i] != b[i]) {
				return false;
			}
		}
		return true;
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 37128
from numpy import cumsum

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

# 黒を1,白を0として　リスト化
ss = S.replace("#", "1").replace(".", "0")
* ls, = map(int, ss)

# 累積和
cum_ls = cumsum(ls)

# 左から何個目に初めてblackが出てくるか
first_black = -1
for i in range(N):
    if S[i] == "#":
        first_black = i
        break

# blackが後ろから何個まで続いているか
last_black = N
for i in reversed(range(N)):
    if S[i] == "#":
        last_black = i
    else:
        break
if first_black == -1:
    print(0)
else:
    # i番目より左をすべて白、それより右をすべて黒にしたとき何回塗り替えるか
    ans_temp = 10 ** 10
    for i in range(N):
        ans_temp = min(ans_temp, cum_ls[i] +
                       (N-(i+1) - (cum_ls[-1] - cum_ls[i])))

    ans = min(S[first_black:].count("."), S[first_black:].count(
        "#"), S[:last_black].count("#"), ans_temp)

    print(ans)


Measured memory_bytes: 18356
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 998244353;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


//最大公約数
ll gcd(ll m, ll n) {
	if (n == 0)return m;
	return gcd(n, m % n);
}//gcd

 //最小公倍数
ll lcm(ll m, ll n) {
	return m / gcd(m, n) * n;
}

//拡張ユークリッドの互除法：ax+by=gcd(a,b)となるx,y
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}

void solve() {
	ll a, b;
	cin >> a >> b;
	ll x=0, y=0;
	extgcd(a, b, x, y);
	cout << x << " " << y << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  int x;
  cin >> x;
  if(x>=30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3480
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }

    val ans = IntArray(n){0}
    repeat(a.size) {
        ans[a[it]-1]++
    }

    repeat(n) {
        println(ans[it])
    }
}


Measured memory_bytes: 69760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String X = sc.next();
		String Y = sc.next();
		sc.close();
		if (X.compareTo(Y) > 0) {
			System.out.println(">");
		} else if (X.compareTo(Y) == 0) {
			System.out.println("=");
		} else {
			System.out.println("<");
		}
	}
}

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

#define INF (1 << 29)

#define MAX_N 16

using namespace std;

int N, T[MAX_N][MAX_N + 1], dp[1 << MAX_N];

int main()
{
	int power2[MAX_N + 1];

	power2[0] = 1;

	for (int i = 1; i <= MAX_N; i++)
	{
		power2[i] = power2[i - 1] * 2;
	}

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < N + 1; j++)
			{
				cin >> T[i][j];
			}
		}

		for (int i = 1; i < power2[MAX_N]; i++)
		{
			dp[i] = INF;
		}

		dp[0] = 0;

		for (int j = 0; j < power2[N]; j++)
		{
			for (int k = 0; k < N; k++)
			{
				if (j & power2[k])
				{
					dp[j] = min(dp[j - (1 << k)] + T[k][0], dp[j]);

					int val1 = j - power2[k];

					for (int l = 0; l < N; l++)
					{
						if (j & power2[l])
						{
							if (k != l)
							{
								dp[j] = min(dp[val1] + T[k][l + 1], dp[j]);
							}
						}
					}
				}
			}
		}

		cout << dp[power2[N] - 1] << endl;
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }


int main(){
  ll N,M; cin>>N>>M;
  ll b[N];
  REP(i,N){
    ll a; cin >> a;
    b[i] = a/2;
  }
  sort(b,b+N,greater<ll>());
  ll check = 1;
  REP(i,N){
    ll t = b[i];
    if(i==0){
      while(t%2==0){
        t/= 2;
        check*=2;
      }
    }else{ 
      if( (t/check)%2==0  ){ check=-1; break;}
    }
  }
  ll ans = 0;
  if(check>0){
    ll t = b[0];
    for(int i=1;i<N;++i){
      if(t%b[i]>0){
        t = lcm(t,b[i]);
      }
    }
    ans = M/t - M/(t*2);
  }
  cout << ans <<"\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 int i;
 int j;
 int k;
 int a[3][3];
 int c[3][3];
 for(i=0;i<3;i++){
     for(j=0;j<3;j++){
         cin >> a[i][j];
        c[i][j]=0;
     }
 }
 cin >> N;
 int b[N];
for(i=0;i<N;i++){
    cin >> b[i];
    for(j=0;j<3;j++){
        for(k=0;k<3;k++){
            if(a[j][k]==b[i])c[j][k]=1;
     }
 }}
 int flag=0;
if(c[0][0]==1 && c[1][1]==1 && c[2][2]==1)flag++;
if(c[2][0]==1 && c[1][1]==1 && c[0][2]==1)flag++;
 for(i=0;i<3;i++){
    if(c[0][i]==1 && c[1][i]==1 && c[2][i]==1){
        flag++;
        break;
    }
    else if(c[i][0]==1 && c[i][1]==1 && c[i][2]==1){
        flag++;
        break;
    }
 }
 if(flag>0)cout << "Yes" << endl;
 else{cout << "No" << endl;}

}

Measured memory_bytes: 256