akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	ll arc=0,abc=0,m,n,k,cnt=0;
	cin>>n;
	ll a[n];
	REP(i,0,n-1)
		cin>>a[i];
	sort(a,a+n);
	cout<<a[n/2]-a[(n/2)-1];
}

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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            long count = 0;

            Dictionary<string, long> dic = new Dictionary<string, long>();
            for (int i = 0; i < n; i++)
            {
                // 文字列の入力
                string s = Console.ReadLine();

                if (dic.ContainsKey(s))
                {
                    dic[s]++;
                }
                else
                {
                    dic.Add(s, 1);
                }

                if (dic[s] > count)
                {
                    count = dic[s];
                }
            }

            List<string> results = new List<string>();
            foreach (var kv in dic)
            {
                if (kv.Value == count)
                {
                    results.Add(kv.Key);
                }
            }

            results.Sort(StringComparer.Ordinal);

            foreach (var result in results)
            {
                Console.WriteLine(result);
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 39260
#include <stdio.h>                                      
#include <string.h>
int main (void)
{
    int a=0,b=0,c=0;
    char A[11],B[11],C[11];
    scanf("%s%s%s",A,B,C);
    a=strlen(A);
    b=strlen(B);
    c=strlen(C);
    if((A[a-1]==B[0])&&(B[b-1]==C[0]))
        printf("YES\n");
    else
        printf("NO\n");
return 0 ; 
}

Measured memory_bytes: 128
#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 1000000007
#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())
ll dp[3005][3005];

ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}


int main()
{
	int n,q;
	vector<int>num;
	scanf("%d%d",&n,&q);
//	n = 3000; q = 3000;
	for(int i=0;i<n;i++)
	{
		int x; scanf("%d",&x);
		num.pb(x);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(num[i]>num[j]) dp[i][j]=1;
		}
	}
	ll xx = modpow(2LL,mod-2);
	for(int i=0;i<q;i++)
	{
		int a,b;
	//	a = i; b = (i*i)%n;
		scanf("%d %d",&a,&b);
	    a--; b--;
		for(int j=0;j<n;j++)
		{
		    if(j == a || j == b) continue;
			dp[j][a]=dp[j][b]=(dp[j][a]+dp[j][b])%mod*xx%mod;
			dp[a][j]=dp[b][j]=(dp[a][j]+dp[b][j])%mod*xx%mod;
		}
		dp[a][b]=dp[b][a]=(dp[a][b]+dp[b][a])%mod*xx%mod;;
		dp[a][a]=dp[b][b]=0;
	}
	ll ret = 0;
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) ret+=dp[i][j];
	ret %= mod;
	ret = ret*modpow(2LL,q)%mod;
	cout<<(ret+mod)%mod<<endl;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	sort(d.rbegin(), d.rend());
	int ans = 0;
	rep(i, k) ans += d[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>

using namespace std;

int main(void) {
	int w, h, n;
	cin >> w >> h >> n;
	vector<int>x(n), y(n), a(n);
	for (int i = 0; i < n; i++)cin >> x[i] >> y[i] >> a[i];
	int A[2] = { 0,0 };
	int B[2] = { w,h };
	for (int i = 0; i < n; i++) {
		if (a[i] == 2) {
			if (x[i] <= B[0]) {
				B[0] = x[i];
			}
		}
		if (a[i] == 1) {
			if (x[i] >= A[0]) {
				A[0] = x[i];
			}
		}
		if (a[i] == 3) {
			if (y[i] >= A[1]) {
				A[1] = y[i];
			}
		}
		if (a[i] == 4) {
			if (y[i] <= B[1]) {
				B[1] = y[i];
			}
		}
	}
	int len = max(0, B[0] - A[0]);
	int high = max(0, (B[1] - A[1]));
	cout << len * high;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

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

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

bool comp(P a, P b){
	return (a.first < b.first);
}

int n,a,b,c,l[10],ans=INF;

void dfs(int d, int x, int y, int z, int p, int q, int r){
	if(d==n){
		if(!(p&&q&&r)){
			return;
		}
		ans = min(ans,abs(x-a)+abs(y-b)+abs(z-c)+10*(p+q+r-3));
	}else{
		dfs(d+1,x,y,z,p,q,r);
		dfs(d+1,x+l[d],y,z,p+1,q,r);
		dfs(d+1,x,y+l[d],z,p,q+1,r);
		dfs(d+1,x,y,z+l[d],p,q,r+1);
	}
}

int main(void){
	int i;
	cin >> n;
	cin >> a >> b >> c;
	for(i=0; i<n; ++i){
		cin >> l[i];
	}
	dfs(0,0,0,0,0,0,0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
#define SZ(x) ((ll).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, n) for(ll i = 0; i < n; i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}
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; }

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

  ll x;
  cin >> x;
  for(ll i = -200; i <= 200; i++){
    for(ll j = -200; j <= 200; j++){
      if(pow(i,5) - pow(j,5) == x){
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,M;
  cin>>A>>B>>M;
  vector<long>a(A);
  vector<long>b(B);
  vector<long>x(M);
  vector<long>y(M);
  vector<long>c(M);
  for(int i=0;i<A;i++)cin>>a[i];
  for(int i=0;i<B;i++)cin>>b[i];
  for(int i=0;i<M;i++)cin>>x[i]>>y[i]>>c[i];
  
  vector<long>p(M);
  for(int i=0;i<M;i++) p[i]=a[x[i]-1]+b[y[i]-1]-c[i];
  //for(int i=0;i<m;i++)cout<<p[i]<<endl;
  sort(p.begin(),p.end());
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  cout<<min(p[0],a[0]+b[0])<<endl;
}
  

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define REP(i,m,n) for(ll i = (ll)(m); i < (ll) (n) ;i++)
#define rep(i,n)  REP(i , 0 , n)
using namespace std;

string  s;
ll k;
ll i = 0;

int main(){
	cin >> s >> k;
	while (s[i] == '1'){
		i++;
	}
	if (k < i + 1) cout << s[k - 1] << endl;
	else cout << s[i] << endl;






	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

ll gcd(ll a, ll b) {
  ll greater = max(a, b), less = min(a, b);
  ll remainder = greater % less;

  if(remainder == 0) {
    return less;
  } else {
    return gcd(less, remainder);
  }
}

// 1以上k以下でcでもdでも割りきれいない個数
ll n(ll k, ll c, ll d) {
  ll r = c * d / gcd(c, d);
  return k - ((k / c) + (k / d) - (k / r));
}

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

  ll k = (a % c == 0 || a % d == 0) ? 0 : 1;
  cout << n(b, c, d) - n(a, c, d) + k << endl;

  return 0;
}

Measured memory_bytes: 256
ABCD = input()
A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]

op = ["+", "-"]
for i in op:
  for j in op:
    for k in op:
      if eval(A+i+B+j+C+k+D) == 7:
        print(A+i+B+j+C+k+D+"=7")
        exit()

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
void trace(int A[],int N)
{
    int i;
    for(i=0;i<N;i++)
    {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionsort(int A[],int N)
{
    int i,j,v;
    for(i=1;i<N;i++)
    {
        v=A[i];
        j=i-1;
        while(j>=0&&A[j]>v)
        {
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}
int main()
{
    int N,i;
    int A[100];
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&A[i]);
    }
    trace(A,N);
    insertionsort(A,N);
    return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "agc026_d"
int n;
int h[101];
const ll base=1000000007;
ll power(ll a, ll b){
    if(b==0) return 1;
    ll t=power(a, b/2);
    t=(t*t)%base;
    if(b%2) t=(t*a)%base;
    return t;
}
int minpos[101][101];
bool doneg[101][101][101];
ll g[101][101][101];
ll G(int l, int r, int low){
    if(l>r) return 1;
    ///calculate from l to r, above low
    if(doneg[l][r][low]) return g[l][r][low];
    doneg[l][r][low]=1;
    int x=minpos[l][r];
    return g[l][r][low]=((G(l, x-1, (h[x]>h[low])?x:low)*G(x+1, r, (h[x]>h[low])?x:low))%base*power(2, max(0, h[x]-h[low])))%base;
}
bool done[101][101];
ll f[101][101];
ll F(int l, int low){
    if(done[l][low]) return f[l][low];
    done[l][low]=1;
    int aff[101];
    aff[l]=low;
    FOR(i, l+1, n) aff[i]=(h[i]<h[aff[i-1]])?i:aff[i-1];
    FOR(i, l+1, n){
        int aff2[101];
        ll cnt=1;
        FOR(x, l, i) aff2[x]=aff[x];
        int now=i;
        DFOR(j, i, l){
            if(h[j]<h[now]) now=j;
            if(h[aff2[j]]<h[now]) aff2[j]=now;
        }
        FOR(j, l, i){
            int k=j;
            while((k<i-1)&&(aff2[k+1]==aff2[j])) k++;
            cnt=(cnt*G(j, k, aff2[j]))%base;
            j=k;
        }
        if(h[i]>h[i-1]){
            f[l][low]+=(cnt*F(i, i-1))%base;
        }
        else{
            f[l][low]+=(cnt*F(i, i))%base;
        }
    }
    ll cnt=1;
    FOR(j, l, n){
        int k=j;
        while((k<n)&&(aff[k+1]==aff[j])) k++;
        cnt=(cnt*G(j, k, aff[j]))%base;
        j=k;
    }
    f[l][low]+=cnt;
    f[l][low]%=base;
    return f[l][low];
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    FOR(i, 1, n) read(h[i]);
    FOR(l, 1, n) FOR(r, l, n) minpos[l][r]=min_element(h+l, h+r+1)-h;
    h[0]=1;
    writeln((F(1, 0)*2)%base);
}

Measured memory_bytes: 8960
n, m = map(int, input().split())

MOD = 10 ** 9 + 7

if n == m:
    ans = 1
    for i in range(2, n + 1):
        ans = ans * i % MOD
    print(ans * ans * 2 % MOD)

elif n + 1 == m:
    ans = 1
    for i in range(2, n + 1):
        ans = ans * i % MOD
    print(ans * ans * m % MOD)

elif n == m + 1:
    ans = 1
    for i in range(2, m + 1):
        ans = ans * i % MOD
    print(ans * ans * n % MOD)

else:
    print(0)

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

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
for i in range(n):
  ans += b[a[i]-1]
  if i==n-1: continue
  if a[i]+1 == a[i+1]:
    ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
// finish date: 2018/03/14

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>

vvi connect;

void memo(int t, vi &dist, int temp) {
    if (dist[t] != INF) return;
    dist[t] = temp;
    for (int i:connect[t]) {
        memo(i, dist, temp + 1);
    }

}

int main() {
    int N, K;
    cin >> N >> K;
    connect = vvi(N, vi());
    vi A(N), B(N);
    rep(i, N - 1) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        connect[A[i]].emplace_back(B[i]);
        connect[B[i]].emplace_back(A[i]);
    }
    int mi = INF;
    rep(i, N) {
        if (K % 2 == 1 && i == N - 1) continue;

        vi dist(N, INF);
        int c = 0;
        if (K % 2 == 0) {
            memo(i, dist, 0);

        } else {
            dist[B[i]] = 0;
            memo(A[i], dist, 0);
            dist[B[i]] = INF;
            memo(B[i], dist, 0);
        }
        rep(j, N) if (dist[j] > K / 2) c++;
        mi = min(mi, c);
    }
    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 512
#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)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){  
  int n,m;
  cin >> n >> m;
  set<int> ac;
  vector<int> wa(mx,0);
  
  rep(i,m){
    int p;
    string s;
    cin>>p>>s;
    if(s=="AC"){
      ac.insert(p);
    }else if(ac.find(p)==ac.end()){
      wa[p]++;
    }
  }
  
  int ans=0;
  for(auto to:ac){
    ans += wa[to];
  }
  
  cout << ac.size() << " " << ans << endl;
  return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var abc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = abc[0];
        var b = abc[1];
        var c = abc[2];

        Console.WriteLine(a < b && a < c && c < b || a > b && b < c && c < a ? "Yes" : "No");
    }
}


Measured memory_bytes: 13396
N, M = map(int, input().split())
H = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u - 1].append(H[v - 1])
    graph[v - 1].append(H[u - 1])
seen = [0 for _ in range(N)]

ans = 0
for i in range(N):
    if len(graph[i]) == 0:
        ans += 1
    elif max(graph[i]) < H[i]:
        ans += 1
print(ans)

Measured memory_bytes: 98988
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int div_row[6] = {-1,-1,-1,1,1,1},div_col[6] = {-1,0,1,-1,0,1},H,W;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}


int main(){

	scanf("%d %d",&H,&W);
	char** table = new char*[H];
	for(int i = 0; i < H; i++){
		table[i] = new char[W+1];
		scanf("%s",table[i]);
	}

	int count = 0;
	bool FLG;

	for(int row = 1; row <= H-1; row++){
		for(int col = 0; col <= W-1; col++){
			if(table[row][col] != '-')continue;
			FLG = true;

			if((rangeCheck(row,col-1) == true && table[row][col-1] != '-') ||
			   (rangeCheck(row,col+1) == true && table[row][col+1] != '-'))FLG = false;

			if(FLG){
				for(int i = 0; i < 6; i++){
					if(rangeCheck(row+div_row[i],col+div_col[i]) == true &&
							table[row+div_row[i]][col+div_col[i]] == 'x'){
						FLG = false;
						break;
					}
				}
			}

			if(FLG)count++;
		}
	}

	printf("%d\n",count);

	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int n;
    cin>>n;
    vi a(n+1);
    rep(i,n+1)cin>>a[i];
    if(a[0]!=0 || a[n]==0){
        if(n==0 && a[n]==1)cout<<1<<"\n";
        else cout<<-1<<"\n";
        return 0;
    }

    //子あり頂点の最大値
    //n<=10^5 だからofしてる？
    vl num(n+1);
    num[0]=1;
    repa(i,1,n+1){
        num[i]=num[i-1]*2-a[i];
        if(num[i-1]>INT64_MAX/2+a[i]/2)num[i]=INT64_MAX;
    }

    ll ans=0;
    ll chi=0;

    rrep(i,n){
        //一つ下の子を集約しきれないとき
        if((chi+1)/2>num[i]){
            cout<<-1<<"\n";
            return 0;
        }

        //
        if(num[i]<chi)chi=num[i];
        chi+=a[i];
        ans+=chi;
    }

    cout<<ans<<"\n";

    return 0;

}

Measured memory_bytes: 4472
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class ALphabet {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        string al = "abcdefghijklmnopqrstuvwxyz";

        rep(i,26){
            if(al[i] == s[0]){
                out << "a"<< endl;
                return ;
            }
        }
        out << "A"<< endl;
        return ;
	}
};


int main() {
	ALphabet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] w = new int[n];
    int min = 1000000;
    int total = 0;
    int current = 0;
    
    for(int i=0; i<n; i++) {
      w[i] = Integer.parseInt(str[i]);
      total += w[i];
    }

    for(int i=0; i<n; i++) {
      min = Math.min(min,Math.abs(current-total));
      total -= w[i];
      current += w[i];
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

void pr(bool f){
    cout << (f ? "Yes" : "No") << endl;
    exit(0);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    vll cnt(3, 0);
    rep(i, n){
        ll j = 0;
        while(((a[i] >> j) & 1) == 0){
            j++;
        }
        if(j > 2) j = 2;
        cnt[j]++;
    }
    //dump(cnt);
    ll k = 0;
    while(cnt[k] == 0) k++;
    cnt[k]--;
    repr(i, 1, n){
        ll nxt = 2-k;
        while(cnt[nxt] == 0){
            if(nxt == 2) pr(false);
            nxt++;
        }
        cnt[nxt]--;
        k = nxt;
    }
    pr(true);
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int total =b-a;
        int tall =0;
        
        for(int i = total; i > 0; i--){
            tall += i;
        }
        System.out.println(tall - b);
    }
} 

Measured memory_bytes: 35952
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
        for(int i=0; i<10; i++){
          x = r*x-d;
		  System.out.println(x);
        }
	}
}

Measured memory_bytes: 20560
count = int(input())
test_str = ['AC', 'WA', 'TLE', 'RE']
result_str = []
flag_list = [0,0,0,0]

for num in range(count):
    result_str.append(input())

for num in range(count):
    for n in range(4):
        if result_str[num] == test_str[n]:
            flag_list[n] = flag_list[n] + 1

for n in range(4):
    print("{} x {}".format(test_str[n], flag_list[n]))


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

def main():
    A, B = map(int, input().split())

    if A == B:
        print('Draw')
    elif A == 1 or 0 < A - B < 12:
        print('Alice')
    elif B == 1 or A < B:
        print('Bob')

if __name__ == '__main__':
    main()

Measured memory_bytes: 10304
#include<bits/stdc++.h>
using namespace std;
int q[510][510];
int n,m;
int ans;
struct data{
	int i,j;
	int x,y;
}qwq[1000010];
signed main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    scanf("%d",&q[i][j]);
	for(int i=1;i<n;i++)
	  for(int j=1;j<=m;j++)
	  	if(q[i][j]&1) q[i+1][j]++,qwq[++ans].i=i,qwq[ans].j=j,qwq[ans].x=i+1,qwq[ans].y=j;
	for(int j=1;j<m;j++) if(q[n][j]&1) q[n][j+1]++,qwq[++ans].i=n,qwq[ans].j=j,qwq[ans].x=n,qwq[ans].y=j+1;
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++) printf("%d %d %d %d\n",qwq[i].i,qwq[i].j,qwq[i].x,qwq[i].y); 	
	return 0;
}

Measured memory_bytes: 6400
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
b=[int(i) for i in input().split()]
a=[b[0]]
for i in range(1,n-1):
    a.append(min(b[i-1],b[i]))
a.append(b[-1])
print(sum(a))

Measured memory_bytes: 3316
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);
int H, W, K;
vector<vi> a;

int get(int u1, int v1,int u2,int v2){
    return a[u2][v2] - a[u1 - 1][v2] - a[u2][v1 - 1] + a[u1 - 1][v1 - 1];
}


int f(int c1,int c2,const vi& row){
    for (int i = 1; i < row.size(); i++){
        int r1 = row[i - 1] + 1;
        int r2 = row[i];
        int sum = get(r1,c1,r2,c2);
        if (sum > K) return false;
    }
    return true;
}

int calc(int msk){
    vi row;
    row.eb(0);
    int res = 0;
    for (int i = 0; i < H - 1; i++)
        if (getbit(msk,i)){ 
            res++;
            row.eb(i + 1);
        }
    row.eb(H);
   

    int lef = 1;
    int rig = 1;
    while (rig <= W){
        while (rig <= W  && f(lef,rig,row)) rig++;
        if (lef == rig) return INF;
        res++;
        lef = rig;
    }
    return res - 1;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> H >> W >> K;
    
    a.resize(H + 1,vi (W + 1));
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j){
            char x;
            cin >> x;
            a[i][j] = (x - '0') + a[i - 1][j] + a[i][j - 1]  - a[i - 1][j - 1];
        }
    
    int mask = (1 << (H - 1));
    int ans = INF;
    for (int msk = 0; msk < mask; msk++){
        ans = min(ans,calc(msk));
    }
    cout << ans << '\n';

    return 0;
}


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

ll vs(ll x){
  if(x==1)return 1;
  x /=2;
  return (1+2*vs(x));
}

int main(){
  ll H;
  cin >> H;
  ll ans = vs(H);
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
import bisect
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, K, A, B):
    from itertools import accumulate
    sa = [0] + list(accumulate(A))
    sb = [0] + list(accumulate(B))

    ans = 0
    for n, a in enumerate(sa):
        if a > K:
            break
        m = bisect.bisect_right(sb, K-a) - 1
        ans = max(ans, n+m)
    return ans


def main():
    N, M, K = read_int_n()
    A = read_int_n()
    B = read_int_n()
    print(slv(N, M, K, A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 131092
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int W, H, N;
	cin >> W >> H >> N;

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

	auto count = 0;
	for (auto i = 0.5; i < H; ++i)
	{
		for (auto j = 0.5; j < W; ++j)
		{
			auto isWhite = true;
			for (auto k = 0; k < N; ++k)
			{
				switch (a[k])
				{
					case 1:
						if (j < x[k])
						{
							isWhite = false;
						}
						break;
					case 2:
						if (j > x[k])
						{
							isWhite = false;
						}
						break;
					case 3:
						if (i < y[k])
						{
							isWhite = false;
						}
						break;
					case 4:
						if (i > y[k])
						{
							isWhite = false;
						}
						break;
				}
			}

			if (isWhite)
			{
				++count;
			}
		}
	}

	cout << count << endl;

	return 0;
}

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

int main()
{
    const long N = -1000000, M = 1000000;
    int K, X;
    long l, m;
    cin >> K >> X;
    if(X - K + 1 >= N){
        l = X - K + 1;
    }else{
        l = N;
    }

    if(X + K - 1 <= M){
        m = X + K - 1;
    }else{
        m = M;
    }

    for(long i = l; i <= m; i++){
        cout << i << " ";
    }
    cout << endl;

    return 0;
    
}

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

int main(void) {
  int **mas, **candy;
  int N, tmp;
  
  scanf("%d", &N);
  candy = new int*[2];
  candy[0] = new int[N];
  candy[1] = new int[N];
  
  scanf("%d", &candy[0][0]);
  for (int i = 0; i < 2; i++) {
   	 for (int j = (i == 0 ? 1 : 0) ; j < N; j++) {
      	scanf("%d", &candy[i][j]);
       	if (i == 0) {
          candy[i][j] += candy[i][j-1];
        } else {
          tmp = candy[i-1][j] > candy[i][j-1] ? candy[i-1][j] : candy[i][j-1];
          candy[i][j] += tmp;
        }
    }
  }
  
  printf("%d\n", candy[1][N-1]);
    
  
  return 0;
}
  

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a,b,c;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        int z;
        if(a>b){
            z=a;
            a=b;
            b=z;
        }
        if(b>c){
            z=b;
            b=c;
            c=z;
        }
        if(a>b){
            z=a;
            a=b;
            b=z;
        }
        System.out.println(a+" "+b+" "+c);
    }
}


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

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n, ans=INF;
char S[110];

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

	cin>>S;
	n = strlen(S);
	for(char c='a'; c<='z'; c++){
		int now=0, mx=0;
		for(int i=0; i<n; i++){
			if(S[i]==c) now=0;
			else now++;
			mx = max(now, mx);
		}
		ans = min(ans, mx);
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 256
N = int(input())
data = list(map(int, input().split()))
    
for i in range(N):
    tmp = data[i]
    j = i - 1
    while j >= 0 and data[j] > tmp:
        data[j+1] = data[j]
        j -= 1
    data[j+1] = tmp
    
    for j in range(N):
        print("%d" %(data[j]), end="")
        if j != N-1:
            print(" ", end="")
    print()



Measured memory_bytes: 6308
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
while(true){
 int x=ir.nextInt();
 int y=ir.nextInt();
 if((x|y)==0) break;
 if(x>y){
  int temp=x; x=y; y=temp;
 }
 out.println(x+" "+y);
}
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 24868
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, A, B = map(int, input().split())

    if N == 1:
        if A != B:
            print(0)
        else:
            print(1)
    elif N == 2:
        print(1)
    else:
        if A <= B:
            print(B * (N-1) + A - (A * (N-1) + B) + 1)
        else:
            print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
package main

import "fmt"

func main() {
	var A, B, N int
	fmt.Scanf("%d %d %d", &A, &B, &N)

	var beta int
	if N/B == 0 {
		beta = N % B
	} else {
		beta = B - 1
	}
	fmt.Println(A * beta / B)
}


Measured memory_bytes: 1836
use std::collections::HashMap;
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let mut letters = (b'a'..b'z' + 1)
        .map(|c| c as char)
        .map(|c| (c, 0))
        .collect::<HashMap<_, _>>();

    for line in stdin.lock().lines() {
        let line = line.unwrap();
        for c in line.to_lowercase().chars() {
            if !letters.contains_key(&c) { continue; }
            let count = letters.entry(c).or_insert(0);
            *count += 1;
        }
    }

    for c in (b'a'..b'z' + 1).map(|ch| ch as char) {
        println!("{} : {}", c, letters.get(&c).unwrap());
    }
}



Measured memory_bytes: 5056
x=int(input())
words=[]
found=0
word_1=''
word_2=''
for i in range(x):
    words.append(input())

for j in range(x-1):
    for k in range(j+1,x):
        if words[j]==words[k]:
            found=-1
for c in range(x-1):
    word_1=words[c]
    word_2=words[c+1]
    if word_1[-1]!=word_2[0]:
        found=-1
if found==-1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

const int mod = 1000000007;
int add(int a, int b) { return (a += b) < mod? a : a - mod; }
int sub(int a, int b) { return (a -= b) >=  0? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int& a, int b) { a = add(a, b); }
void subs(int& a, int b) { a = sub(a, b); }
void muls(int& a, int b) { a = mul(a, b); }
void maxs(int& a, int b) { a = max(a, b); }
void mins(int& a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(a, pwr(a, p - 1));
    return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int sol = 1;
    for (int i = 2; i <= n; ++i)
        muls(sol, i);
    for (int i = 2; i <= m; ++i)
        muls(sol, i);
    if (abs(n - m) == 0)
        muls(sol, 2);
    if (abs(n - m) > 1)
        sol = 0;
    cout << sol;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

int N,K;
long H[200000];

long ans = 0;
 
void solve(){
	if(N<=K){
		ans = 0;
		return;
	}
	sort(H,H+N,greater<long>());
	for(int i=K;i<N;i++) ans+=H[i];
}
 
int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++) cin>>H[i];

	solve();

	cout << ans;
	return 0;
}

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

char c[2000][2000];
int rw[2000][2000],rh[2000][2000];

void calcrw(int h,int w){
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            if(c[i][j]=='.') rw[i][j] = (j>0?rw[i][j-1]+1:1);
        }
        for(int j = w-2;j >= 0;j --){
            if(rw[i][j]&&rw[i][j+1]) rw[i][j] = rw[i][j+1];
        }
    }
}
void calcrh(int h,int w){
    for(int j = 0;j < w;j ++){
        for(int i = 0;i < h;i ++){
            if(c[i][j]=='.') rh[i][j] = (i>0?rh[i-1][j]+1:1);
        }
        for(int i = h-2;i >= 0;i --){
            if(rh[i][j]&&rh[i+1][j]) rh[i][j] = rh[i+1][j];
        }
    }
}

int main(){
    int h,w,ans = 0;
    cin >> h >> w;
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            cin >> c[i][j];
        }
    }
    calcrw(h,w);
    calcrh(h,w);
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            ans = max(ans,rh[i][j]+rw[i][j]-1);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 2000010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int modpow(int x, int n, const int mo) {
	int res = 1;
	while (n > 0) {
		if (n & 1) (res *= x) %= mo;
		(x *= x) %= mo;
		n >>= 1;
	}
	return res;
}

int inverse(int x, const int mo) {
	return modpow(x, mo - 2, mo);
}

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

	COMinit();
	int K;
	cin >> K;
	string S;
	cin >> S;

	int ans = 0;
	rep(i, 0, K + 1)
	{
		int l = modpow(25LL, i, MOD);
		int r = modpow(26LL, K - i, MOD);
		int con = COM(SZ(S) + i - 1, i);
		l *= r;
		l %= MOD;
		l *= con;
		l %= MOD;
		ans += l;
		ans %= MOD;
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 51116
#include<iostream>
using namespace std;
int n;
main(){
  cin>>n;
  int ans=0;
  int d[9]={16,2,2,56,2,2,16,2,2};
  if(n<357){
    cout<<0<<endl;
    return 0;
  }
  int a,q,w,e;
  for(int i=-1,j=357;j<=n;j+=d[++i%9])
  {
    a=j;
    q=0,w=0,e=0;
    while(a>0)
    {
      
      if(a%10==7) q++;
      else if(a%10==5) w++;
      else if(a%10==3) e++;
      else{
        q=0;
        break;
      }
      a/=10;
    }
    if(q*w*e>0)ans++;
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++)
    {
        if(a[i] % 2 == 0)
        {
            if(a[i] % 3 != 0 && a[i] % 5 != 0)
            {
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int n,m;
	cin >> n >> m;
	map<ll,ll> mm;
	REP(i,n){
		ll a;
		cin >> a;
		map<ll,ll>::iterator itr = mm.find(a);
		if(itr == mm.end()){
			mm.insert(mp(a,1));
		}else{
			itr->second = itr->second+1;
		}
	}
	REP(i,m){
		ll b;
		ll c;
		cin >> b >> c;
		map<ll,ll>::iterator itr = mm.find(c);
		if(itr == mm.end()){
			mm.insert(mp(c,b));
		}else{
			itr->second = itr->second+b;
		}
	}

	ll sum = 0;
	ll cnt = 0;
	for(map<ll,ll>::reverse_iterator itr = mm.rbegin();itr!= mm.rend();itr++){
//		printf("---- %lld -> %lld\n",itr->first,itr->second);
		ll tba = min(n-cnt,itr->second);
		sum += itr->first * tba;
		cnt += tba;
//		printf(" + %lld * %lld = %lld (cnt:%lld)\n",itr->first,tba,sum,cnt);
		if(cnt==n) break;
	}
	println(sum);

	return 0;
}


Measured memory_bytes: 12800
def main():
    n = int(input())
    a = [[i, int(input())] for i in range(n)]
    b = sorted(a, key=lambda x: x[1], reverse=True)
    b0 = b[0]
    b1 = b[1]

    for aa in a:
        if aa[0] == b0[0]:
            print(b1[1])
        else:
            print(b0[1])


main()


Measured memory_bytes: 41236
#include <iostream>
#include <cmath>

int gcd(int x,int y);
int lcm(int x,int y);

int main(){
  int a,b;
using namespace std;

  while(1){
  cin >> a >> b;
  if(cin.eof())break;
  cout << gcd(a,b)<<" "<<lcm(a,b)<<endl;
  }
  return 0;
}

int gcd(int x,int y){
  int z;
  while(y!=0){
  z = x%y;
  x = y; 
  y = z;
  }
  return x;
}

int lcm(int x,int y){
  int g = gcd(x,y);
  return x/g*y;
}

Measured memory_bytes: 1160
N = int(input())
mod = 10**9 + 7


def powmod(val, n, mod):
    ret = 1
    for i in range(n):
        ret = ret * val % mod

    return ret


all = powmod(10, N, mod)
b = powmod(9, N, mod)
c = powmod(8, N, mod)

ans = (all - (2*b - c))%mod

print(ans)

Measured memory_bytes: 9192
import sys
sys.setrecursionlimit(100002)


N = int(input())
act = [list(map(int, input().split())) for _ in range(N)]
dp = [[-float('inf') for _ in range(3)] for _ in range(N)]


def dp_rec(day, choice):

    if dp[day][choice] > -float('inf'):
        return dp[day][choice]

    v = -float('inf')
    for c in range(3):
        if c != choice:
            v = max(v, dp_rec(day - 1, c) + act[day][choice])

    dp[day][choice] = v
    return v


dp[0] = act[0]
dp_rec(N-1, 0)
dp_rec(N-1, 1)
dp_rec(N-1, 2)
print(max(dp[N-1]))


Measured memory_bytes: 139832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e9;
const int maxN = 59;

int n;
ll a[maxN];

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

void solv(){
  ll mn = *min_element(a, a + n);
  ll mx = *max_element(a, a + n);

  cout << n - 1 + n - 1 << '\n';

  if(abs(mn) > abs(mx)){
    ll mnIdx = -1;
    for(int i = 0; i < n; i++){
      if(a[i] == mn){
        mnIdx = i;
        break;
      }
    }

    for(int i = 0; i < n; i++){
      if(mnIdx == i)  continue;
      cout << mnIdx + 1 << " " << i + 1 << '\n';
    }

    for(int i = n - 2; i >= 0; i--)
      cout << i + 1 + 1 << " " << i + 1 << '\n';
  } else {
    ll mxIdx = -1;
    for(int i = 0; i < n; i++){
      if(a[i] == mx){
        mxIdx = i;
        break;
      }
    }

    for(int i = 0; i < n; i++){
      if(mxIdx == i)  continue;
      cout << mxIdx + 1 << " " << i + 1 << '\n';
    }

    for(int i = 1; i < n; i++){
      cout << i - 1 + 1 << " " << i + 1 << '\n';
    }
  }

}

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

  read();
  solv();

  return 0;
}


Measured memory_bytes: 256