akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
//10万
#define MAX 100000
//20億
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

//配列LとR、10億+2を用意
struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for( i = 0; i < n1; i++ ) L[i] = A[left + i]; //配列Aの左側の各要素を配列Lに代入
  for( i = 0; i < n2; i++ ) R[i] = A[mid + i]; //配列Aの右側の各要素を配列Rに代入
  L[n1].value = R[n2].value = SENTINEL; //番兵
  i = j = 0;
  for( k = left; k < right; k++ ) {
    //LとRの配列を比較して、昇順になるようにAの配列に統合する
    if( L[i].value <= R[j].value ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
//mergeSort(A, n, 0, n);
//配列全体を対象として mergeSort を行う
void mergeSort(struct Card A[], int n, int left, int right) {
  int mid;
  //要素が2個以上の時、それぞれ n/2 個の要素を含む2つの部分配列に分割する
  if( left+1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, n, left, mid); //配列左側の分割
    mergeSort(A, n, mid, right); //配列右側の分割
    merge(A, n, left, mid, right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r]; //パーティションの基準となるA[r]をxに代入
  i = p - 1;
  for( j = p; j < r; j++) {
    //パーティションの基準となるxとA[j]を比較
    if( A[j].value <= x.value ) {
      //A[j]がx以下の時
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  //A[j]がxより大きい時
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i+1;
}
//quickSort(B, n, 0, n-1)
void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if( p < r ) {
    q = partition(A, n, p, r);
    quickSort(A, n, p, q-1);
    quickSort(A, n, q+1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX]; //AとBの配列を用意する
  char S[10];
  int stable = 1; //安定している時を"1"とする

  scanf("%d", &n); //カードの枚数

//カードの枚数分forを回す
  for( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v); //絵柄と数を入力
    A[i].suit = B[i].suit = S[0]; //それぞれの配列に絵柄を代入
    A[i].value = B[i].value = v; //それぞれの配列に数を代入
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for( i = 0; i < n; i++ ) {
    //マージソートとクイックソートの結果を比べる
    if( A[i].suit != B[i].suit ) stable = 0;
  }

  if( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value); //ソートした結果を示す
  }

  return 0;
}



Measured memory_bytes: 4048
fn main() {
    let c = read::<char>();
    if c.is_ascii_uppercase() {
        println!("A");
    } else {
        println!("a");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2132
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;


char s[105];
ll n;
int main()
{
    while(~scanf("%s%lld",s,&n))
    {
        int i;
        for(i=0;i<strlen(s);i++)
        {
            if(s[i]!='1') break;
        }
        if(i>=n) printf("1\n");
        else printf("%c\n",s[i]);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<ll> as(n);
    cin >> as;
    sort(as.begin(), as.end());
    int last_weak = -1;
    ll sum = 0;
    for (int i : irange(0, n-1)) {
        sum += as[i];
        if (sum * 2 < as[i+1]) last_weak = i;
    }
    cout << (n - last_weak - 1) << nl;
}


Measured memory_bytes: 1024
def main():
  n = int(input())
  bs = list(map(int, input().split(' ')))
  ans = bs[0] + bs[n-2]
  if n > 2:
    for i in range(1, n-1):
      ans += min(bs[i], bs[i-1])
  print(ans)


if __name__ == '__main__':
  main()


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - OddString
            var s = Console.ReadLine();
            string ans = "";

            for(int i = 0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                {
                    ans += s[i];
                }
            }

            Console.WriteLine(ans);
        }
    }
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe\n";
  } else {
    cout << "safe\n";
  }
}


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

long long int cnt[200001];

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

	int n,k;

	cin >> n >> k;

	for(int i=1;i<=n;i++)
	{
		cnt[i%k]++;
	}
	long long int res = 0;
	if(k%2==0)
	{
		res += (cnt[k/2]*cnt[k/2]*cnt[k/2]);
	}
	res += (cnt[0]*cnt[0]*cnt[0]);

	cout << res << '\n';
	
	return 0;
}

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

const int INF=1001001001;
int N;
int dp[100010];

int main(){
    cin>>N;
    fill_n(dp,N+3,INF);
    dp[0]=-1;

    for(int i=0;i<N;i++){
        int A;cin>>A;
        *lower_bound(dp,dp+N+3,A)=A;
    }

    cout<<lower_bound(dp,dp+N+3,INF)-dp-1<<endl;
}

Measured memory_bytes: 1552
#include <iostream>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3652
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }
    static object Solve() {
        var w = Console.ReadLine();
        var b = new bool[26];
        var len = w.Length;
        for (int i = 0; i < len; i++) {
            b[w[i] - 'a'] = !b[w[i] - 'a'];
        }
        return b.Contains(true) ? "No" : "Yes";
    }
}

Measured memory_bytes: 26508
from collections import defaultdict

class LCM_mod:
    """
    最小公倍数の計算を行う
    オーバーフローが発生しないように素因数分解し,
    因数の積を逐次余りに置き換えて最小公倍数を導出する.
    """
    def __init__(self, max_num, p=10**9+7):
        self.max_num = max_num + 1
        self.p = p
        self.prime = [0 for _ in range(self.max_num)]
        self.max_map = defaultdict(int)
        self.sieve()

    def rep_sqr(self, base, k):
        # 繰り返し二乗法
        if k == 0:
            return 1
        elif k % 2 == 0:
            return (self.rep_sqr(base, k / 2) ** 2) % self.p
        else:
            return (self.rep_sqr(base, k - 1) * base) % self.p

    def sieve(self):
        """
        エラトステネスの篩　O(n)
        nまでに含まれる素数を導出
        """
        self.prime[0], self.prime[1] = 1, 1
        for i in range(2, self.max_num):
            if self.prime[i] == 0:
                for j in range(i * 2, self.max_num, i):
                    if self.prime[j] == 0:
                        self.prime[j] = i
                self.prime[i] = i

    def lcm_list_mod(self, arr):
        """
        listのそれぞれの要素について、素因数分解する
        それぞれの因数について最大であれば更新する
        """
        for i in range(len(arr)):
            num = arr[i]
            d = defaultdict(int)

            while num > 1:
                fact = self.prime[num]
                d[fact] += 1
                num //= fact

            for i in d.keys():
                self.max_map[i] = max(self.max_map[i], d[i])

        ans = 1
        for i in self.max_map.keys():
            ans = (ans * self.rep_sqr(i, self.max_map[i])) % self.p
        return ans


def rep_sqr(base, k, mod):
    if k == 0:
        return 1
    elif k % 2 == 0:
        return (rep_sqr(base, k / 2, mod) ** 2) % mod
    else:
        return (rep_sqr(base, k - 1, mod) * base) % mod

# a^(-1) == a^(m-2)

def flt(a, mod):
    return rep_sqr(a, mod-2, mod)

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7

lcm_mod = LCM_mod(max(a), MOD)
lcm_all = lcm_mod.lcm_list_mod(a)

b = list(map(lambda x: lcm_all * flt(x, MOD), a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)


Measured memory_bytes: 114928
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  double W, H, x, y; cin >> W >> H >> x >> y;

  int ans;
  if (x == W/2 && y == H/2) {
    ans = 1;
  } else {
    ans = 0;
  }

  printf("%.10f %d\n", W*H/2., ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

bool mycompare( const tuple<std::string, int, int> &lhs, const tuple<std::string, int, int> &rhs )
{
  if (std::get<0>(lhs) != std::get<0>(rhs)) return std::get<0>(lhs) < std::get<0>(rhs);
  if (std::get<1>(lhs) != std::get<1>(rhs)) return std::get<1>(lhs) > std::get<1>(rhs);
  return std::get<2>(lhs) < std::get<2>(rhs);
}


int main() {
  int n;
  cin >> n;

  vector< tuple <std::string, int, int> > r;
  for (int i = 0; i < n; i++) {
    std::string s;
    int p;
    cin >> s >> p;
    r.push_back(make_tuple(s, p, i+1));
  }

  sort(r.begin(), r.end(), mycompare);

  for (int i = 0; i < n; i++) {
    cout << get<2>(r[i]) << "\n";
  }
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N,K;
    cin>>N>>K;
    if(N>K){
        N=N-(N-K)/K*K;
    }
    if(N==K){
        cout<<"0\n";
        return 0;
    }
    if(N>K)
    N-=K;
    if(K-N>N){
        cout<<N<<"\n";
    }else cout<<K-N<<"\n";
}

Measured memory_bytes: 256
import numpy as np

N=int(input())
A=np.asarray(list(map(int,input().split(" "))))
c=0 # カウンタ

while (A%2==0).all(): # 全て2の倍数の場合
    A=A//2 # 2で割る
    c+=1 # カウンタをインクリメント

print(c)

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

int main() {

 
  // 配列
  string vec; // int型の配列変数vecを宣言
    
    cin >> vec;
 
  
  if(vec[2]==vec[3]&&vec[4]==vec[5]){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
 
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
    long long a,b;
    int k;
    cin >> a >> b >> k;
    for(int i=0; i<k; ++i){
        if(i%2==0){
            if(a%2==1) a--;
            b+=(a/2);
            a=a/2;
        }
        else{
            if(b%2==1) b--;
            a+=(b/2);
            b=b/2;
        }
    }
    cout << a << " "  << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
signed main(){
  string s;
  cin>>s;
  char bef='A';
  int cnt=0;
  lp(i,s.size()){
    if(s[i]==bef) continue;
    else{
      cnt++;
      bef=s[i];
    }
  }
  cout<<cnt-1<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define int LL
#define fi first
#define se second
const LL N=2e6+10;
const LL mod=1e9+7;
const LL inf=0x3f3f3f;
const double eps=1e-9;
using namespace std;
template<typename tp> inline void read(tp &x)
{
    x=0;char c=getchar();
    bool f=0; for(; c<'0'||c>'9'; f|=(c=='-'),c = getchar());
    for(; c>='0'&&c<='9'; x=(x<<3)+(x<<1)+c-'0',c = getchar());
    if(f) x=-x;
}
int fac[N],inv[N],ans;
int KSM(int a,int b,int ret=1)
{
	while(b)
	{
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
int C(int x,int y) { return fac[x]*inv[y]%mod*inv[x-y]%mod;}
int Count(int x,int y) { return C(x+y+2,y+1) - 1;}
void init()
{
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
	inv[N-1]=KSM(fac[N-1],mod-2);
	for(int i=N-2;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
int x[10],y[10];
int solve(int a,int b,int c,int d)
{
	int ret=0;
	ret=(ret+Count(c,d))%mod;
	ret=(ret+Count(a-1,b-1))%mod;
	ret=(ret-Count(a-1,d))%mod;
	ret=(ret-Count(c,b-1))%mod;
	return (ret+mod)%mod;
}
signed main()
{
	init();
	for(int i=1;i<=6;i++) read(x[i]);
	for(int i=1;i<=6;i++) read(y[i]);
	for(int i=x[3];i<=x[4];i++)
	{
		int tag1=solve(i-x[2],y[3]-y[2]-1,i-x[1],y[3]-y[1]-1);
		int tag2=solve(x[5]-i,y[5]-y[3],x[6]-i,y[6]-y[3]);
		int tot=tag1*tag2%mod*(mod-i-y[3])%mod;
		ans=((ans+tot)%mod+mod)%mod;
	}
	for(int i=y[3];i<=y[4];i++)
	{
		int tag1=solve(x[3]-x[2]-1,i-y[2],x[3]-x[1]-1,i-y[1]);
		int tag2=solve(x[5]-x[3],y[5]-i,x[6]-x[3],y[6]-i);
		int tot=tag1*tag2%mod*(mod-i-x[3])%mod;
		ans=((ans+tot)%mod+mod)%mod;
	}
	for(int i=x[3];i<=x[4];i++)
	{
		int tag1=solve(i-x[2],y[4]-y[2],i-x[1],y[4]-y[1]);
		int tag2=solve(x[5]-i,y[5]-y[4]-1,x[6]-i,y[6]-y[4]-1);
		int tot=tag1*tag2%mod*(i+y[4]+1)%mod;
		ans=((ans+tot)%mod+mod)%mod;
	}
	for(int i=y[3];i<=y[4];i++)
	{
		int tag1=solve(x[4]-x[2],i-y[2],x[4]-x[1],i-y[1]);
		int tag2=solve(x[5]-x[4]-1,y[5]-i,x[6]-x[4]-1,y[6]-i);
		int tot=tag1*tag2%mod*(i+x[4]+1)%mod;
		ans=((ans+tot)%mod+mod)%mod;
	}	
	printf("%lld\n",ans);
//	cout<<2*14*46+23*23*2<<endl;
	return 0;
}

Measured memory_bytes: 31488
N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] 
count_AC = 0
count_WA = 0
count_TLE = 0
count_RE = 0

for i in range(len(s)):
    if s[i] == 'AC':
        count_AC += 1
    elif s[i] == "WA":
        count_WA += 1
    elif s[i] == "TLE":
        count_TLE += 1
    else:
        count_RE += 1
print("AC x "+str(count_AC))
print("WA x "+str(count_WA))
print("TLE x "+str(count_TLE))
print("RE x "+str(count_RE))


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

using namespace std;

typedef long long ll;
typedef long double dbl;
typedef vector <int> vi;
typedef pair <int, int> pii;

int const N = 100002;
int const MD = 1000000007;

#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); ++(i))
#define RFOR(i, a, b) for (int (i) = (a); (i) >= (b); --(i))
#define REP(i, n) FOR(i, 0, n - 1)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define sz(v) int(v.size())

int main() {
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	vi v(2 * n);
	for (auto &it : v) cin >> it;
	sort(v.begin(), v.end());
	int ans = 0;
	REP(i, n) ans += min(v[2 * i], v[2 * i + 1]);
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

int N =0;
const int MAXN = 1e5+10;
int A[MAXN];
int B[MAXN];
int C[MAXN];

int main(){
	scanf("%d",&N);
	for(int n=0;n<N;n++){
		scanf("%d",&A[n]);
	}
	for(int n=0;n<N;n++){
		scanf("%d",&B[n]);
	}
	for(int n=0;n<N;n++){
		scanf("%d",&C[n]);
	}
	sort(A,A+N);sort(B,B+N);sort(C,C+N);
	long long int ans=0;
	long long int p = 0;
	long long int q = 0;
	
	for(int i=0;i<N;i++){
		while(A[p]<B[i]&&p<N)	p++;
		while(C[q]<=B[i]&&q<N)	q++;
		ans+=p*(N-q);
	}
	
	printf("%lld",ans);
	
	return 0;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
  
  ll N, T;
  cin >> N >> T;
  
  ll m = 1e15;
  ll flag = 0;
  for(ll i=0; i<N; i++)
  {
    ll c, t;
    cin >> c >> t;
    
    if(t<=T)
    {
      m = min(m, c);
    	flag=1;
    }
    
    else if(i==N-1 && flag==0)
    {
      cout << "TLE" << endl;
      return 0;
    }
    
    
  }
    
  cout << m << endl;

    return 0;
}

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

using namespace std;

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  string a, b, c;
  a = s1[0];
  b = s2[1];
  c = s3[2];
  cout << a + b + c << endl;
  return 0;
}

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

int N, ai, stamina; 
int max_range = - 1;
int min_range = INF;
int min_stamina = INF;
vector<int> X;

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

	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> ai;
		X.pb(ai);
		max_range = max(max_range, ai);
		min_range = min(min_range, ai);
	}

	//cout << max_range <<"\n\n";

	for(int i = min_range; i <= max_range; i++){
		stamina = 0;
		for(int j = 0; j < N; j++){
			stamina += (X[j]-i)*(X[j]-i);
		}
		min_stamina = min(stamina, min_stamina);
	}

	cout << min_stamina << "\n";

	return 0;		
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc074.contest.atcoder.jp/tasks/arc074_a>
問題文============================================================
 縦 H ブロック、横 W ブロックの板チョコがあります。
 すぬけ君は、この板チョコをちょうど 3 つのピースに分割しようとしています。
 ただし、各ピースはブロックの境目に沿った長方形でなければなりません。
 
 すぬけ君は、3 つのピースの面積 (ブロック数) をできるだけ均等にしようとしています。
 具体的には、3 つのピースの面積の最大値を Smax、最小値を Smin としたとき、
 Smax−Smin を最小化しようとしています。 Smax−Smin の最小値を求めてください。

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll H,W; cin >> H >> W;
    ll ans = LINF;
    /*
     パターン１
         サンプル１のようなパターン
     */
    for(int i = 1; i <= H - 2;i++){
        ll S1 = i*W;
        ll S2 = ((H - i)/2) * W;
        ll S3 = ((H - i) - (H - i)/2)*W;
        ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
    }
    /*
     パターン２
         パターン１を90度回転させたパターン
     */
    for(int i = 1; i <= W - 2;i++){
        ll S1 = i*H;
        ll S2 = ((W - i)/2) * H;
        ll S3 = ((W - i) - (W - i)/2)*H;
        ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
    }
    /*
     パターン3
         サンプル2のようなパターン
     */
    for(int i = 1; i <= W;i++){
        ll S1 = H*i;
        ll S2 = (H/2)*(W-i);
        ll S3 = (H - H/2)*(W-i);
        ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
    }
    /*
     パターン４
         パターン３を90度回転させたパターン（サンプル３のようなパターン）
     */
    for(int i = 1; i <= H; i++){
        ll S1 = W*i;
        ll S2 = (W/2)*(H-i);
        ll S3 = (W - W/2)*(H-i);
        ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
vector<ll> v(3010);
ll memo[3010][3010];
ll dfs(ll l,ll r,ll h=0){
    if(l>r)return 0;
    if(memo[l][r])return memo[l][r];
    ll ret=dfs(l+1,r,h^1);
    ll ret2=dfs(l,r-1,h^1);
    ll ans;
    if(h==0){
        ans=max(ret+v[l],ret2+v[r]);
    }
    else{
        ans=min(ret-v[l],ret2-v[r]);
    }
    memo[l][r]=ans;return ans;
}
int main(){
    ll n;cin >> n;rep(i,n)cin >>v[i];
    cout << dfs(0,n-1) <<endl;
}

Measured memory_bytes: 49956
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	int opt[800][800];

	void Solve() {
		UL H, W; cin >> H >> W;
		UL K; cin >> K;
		UL sx, sy;
		rep(y, H) rep(x, W) {
			char c; cin >> c;
			if (c == '#') opt[x][y] = -1;
			if (c == '.') opt[x][y] = 0;
			if (c == 'S') { opt[x][y] = 0; sx = x; sy = y; }
		}
		queue<pair<pair<UL, UL>, UL>> q;
		q.push({ {sx, sy}, K });
		UL ans = 10000;
		while (q.size()) {
			auto p = q.front(); q.pop();
			UL x = p.first.first, y = p.first.second;
			UL k = p.second;
			if (opt[x][y] != 0) continue;
			opt[x][y] = k;
			UL ansbuf = min(min(x, y), min(W - 1 - x, H - 1 - y));
			ans = min(ans, (ansbuf + K - 1) / K);
			if (k == 0) continue;
			if (x != 0) q.push({ {x - 1, y}, k - 1 });
			if (y != 0) q.push({ {x, y - 1}, k - 1 });
			if (x != W - 1) q.push({ {x + 1, y}, k - 1 });
			if (y != H - 1) q.push({ {x, y + 1}, k - 1 });
		}
		cout << (ans + 1) << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

int main(){
	int a,b,c;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int a, b;
  cin >> a >> b;

  int temp = 1, ans = 0;
  while(temp < b){
    temp--;
    temp +=a;
    ans++;
  }
  

  cout << ans << endl;
}

Measured memory_bytes: 256
'''
Check Semi Eulerian graph
'''

l = [0, 0, 0, 0]

# count each city in paths
for i in range(3):
    a, b = map(int, input().split())
    l[a-1] += 1
    l[b-1] += 1

# 
odd_count = 0
for x in l:
    if x % 2 == 1:
        odd_count += 1

if odd_count == 2:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  const int MOD = 1e9 + 7;
  int N, K;
  cin >> N >> K;
  vector<long long> pos, neg;
  for (int i = 0; i < N; i++) {
    long long A;
    cin >> A;
    if (A > 0)
      pos.push_back(A);
    else if (A < 0)
      neg.push_back(-A);
  }
  sort(pos.begin(), pos.end());
  sort(neg.begin(), neg.end());
  long long ans = 1;
  if (pos.size() + neg.size() < K) {
    ans = 0;
  } else if (pos.size() + neg.size() == K) {
    for (int i = 0; i < pos.size(); i++) {
      ans = ans * pos[i] % MOD;
    }
    for (int i = 0; i < neg.size(); i++) {
      ans = ans * (MOD - neg[i]) % MOD;
    }
    if ((neg.size() & 1) && K < N) {
      ans = 0;
    }
  } else if (pos.size() == 0) {
    if (K & 1) {
      if (neg.size() < N) {
        ans = 0;
      } else {
        for (int i = 0; i < K; i++) {
          ans = ans * neg[i] % MOD;
        }
        ans = (MOD - ans) % MOD;
      }
    } else {
      for (int i = 0; i < K; i++) {
        ans = ans * neg[neg.size() - 1 - i] % MOD;
      }
    }
  } else if (pos.size() == 1) {
    if (K & 1) {
      ans = pos[0];
      for (int i = 0; i < K - 1; i++) {
        ans = ans * neg[neg.size() - 1 - i] % MOD;
      }
    } else {
      if (K <= neg.size()) {
        for (int i = 0; i < K; i++) {
          ans = ans * neg[neg.size() - 1 - i] % MOD;
        }
      } else {
        if (pos.size() + neg.size() < N) {
          ans = 0;
        } else {
          ans = pos[0];
          for (int i = 0; i < K - 1; i++) {
            ans = ans * neg[i] % MOD;
          }
          ans = (MOD - ans) % MOD;
        }
      }
    }
  } else {
    reverse(neg.begin(), neg.end());
    reverse(pos.begin(), pos.end());
    int n, p;
    n = min(K / 2 * 2, (int)neg.size() / 2 * 2);
    p = K - n;
    while (n > 0 && p + 1 < pos.size()
           && neg[n - 1] * neg[n - 2] < pos[p] * pos[p + 1]) {
      n -= 2;
      p += 2;
    }
    for (int i = 0; i < n; i++) {
      ans = ans * neg[i] % MOD;
    }
    for (int i = 0; i < p; i++) {
      ans = ans * pos[i] % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5512
use std::collections::{HashMap, HashSet};
use std::error::Error;
use std::io;

fn main() {
    if let Err(e) = run() {
        panic!("failed");
    }
}

const MOD: i64 = 1_000_000_007;

fn run() -> Result<(), Box< Error>> {
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let n: i32 = line.trim().parse().unwrap();
    line.clear();
    // keep x_y as link exists.
    let mut edges: HashMap<usize, Vec<usize>> = HashMap::new();
    for _ in 0..n - 1 {
        io::stdin().read_line(&mut line);
        let mut edge: Vec<usize> = line
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<usize>().unwrap())
            .collect();
        edges.entry(edge[0]).or_insert(vec![]).push(edge[1]);
        edges.entry(edge[1]).or_insert(vec![]).push(edge[0]);
        line.clear();
    }
    // dp[n][2], 0 is white and 1 is black
    let mut dp: Vec<Vec<i64>> = vec![vec![-1; 2]; 1 + n as usize];
    // previous is white
    let result = explore(&edges, &mut dp, 1, true, 0) + explore(&edges, &mut dp, 1, false, 0);
    println!("{}", result % MOD);
    Ok(())
}

fn explore(
    edges: &HashMap<usize, Vec<usize>>,
    dp: &mut Vec<Vec<i64>>,
    node: usize,
    become_white: bool,
    from: usize,
) -> i64 {
    if node != 1 && edges.get(&node).unwrap().len() == 1 {
        // last node
        return 1;
    }
    if dp[node][if become_white { 0 } else { 1 }] != -1 {
        return dp[node][if become_white { 0 } else { 1 }];
    }

    let mut result = 1;
    for &x in edges.get(&node).unwrap_or(&vec![]) {
        if x == from {
            continue;
        }
        if become_white {
            let mut sum = explore(edges, dp, x, true, node) + explore(edges, dp, x, false, node);
            sum %= MOD;
            result *= sum;
        } else {
            result *= explore(edges, dp, x, true, node)
        }
        result %= MOD;
    }
    dp[node][if become_white { 0 } else { 1 }] = result;
    result
}


Measured memory_bytes: 31112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

int N;
int xs[110], ys[110], hs[110];

int get_ch(int cx, int cy, int h, int x, int y) {
    return h + abs(cx - x) + abs(cy - y);
}

int calc(int cx, int cy) {
    int ch = -1;
    rep(i, N) {
        if (hs[i] == 0) continue;
        if (ch == -1) ch = get_ch(cx, cy, hs[i], xs[i], ys[i]);
        int exp = get_ch(cx, cy, hs[i], xs[i], ys[i]);
        if (exp != ch) return -1;
    }
    if (ch == -1) return ch;
    rep(i, N) {
        int h = max(0, ch - abs(xs[i] - cx) - abs(ys[i] - cy));
        if (h == 0) continue;
        if (h != hs[i]) return -1;
    }
    return ch;
}

int main() {
    while (cin >> N) {
        rep(i, N) cin >> xs[i] >> ys[i] >> hs[i];

        if (*max_element(hs, hs + N) == 0) {
            abort();
        } else {
            rep(cx, 101) rep(cy, 101) {
                int h = calc(cx, cy);
                if (h != -1) {
                    cout << cx << ' ' << cy << ' ' << h << endl;
                }
            }
        }
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int dp[2][55][2500+100];

signed main(){
    dp[0][0][0]=1;
    int N;
    cin>>N;
    int latte;cin>>latte;
    vint A(N);rep(i,N)cin>>A[i];
    rep(i,N){
        rep(j,N){
            rep(k,2500){
                dp[(i+1)&1][j][k]+=dp[i&1][j][k];
                dp[(i+1)&1][j+1][k+A[i]]+=dp[i&1][j][k];
                dp[i&1][j][k]=0;
            }
        }
    }

    int ans=0;
    for(int i=1;i<=N;i++)ans+=dp[N&1][i][latte*i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	int n, m;
	cin >> n >> m;


	int ofs = 0;
	REP(i, m)
	{
		int a = i + 1;
		int b = n - i;

		cout << a << " ";

		if (b - a == (a + n) - b)
		{
			ofs = 1;
		}
		cout << b - ofs;
		cout << endl;
		if (b - a - 2 == (a + n) - b)
		{
			ofs = 1;
		}
	}

	return 0;
}
/*
0 2 4
9 7 5


*/

Measured memory_bytes: 3672
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 1100000
ll MOD=1e9+7;
main(){
    int n=in(),m=in();
    pq p;
    rep(i,n){
        p.push(in());
    }
    rep(i,m){
        ll a=p.top();
        p.pop();
        p.push(a/2);
    }
    ll sum=0;
    rep(i,n){
        sum+=p.top();
        p.pop();
    }
    cout<<sum<<endl;
}

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

int main(void) {
    int N,K;cin>>N>>K;
    int dist_min = 0;
    for (int i = 0; i < N; i++) {
        int x;cin>>x;
        dist_min += 2 * min(x, K - x);
    }
    cout << dist_min << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f == r == -1:
        break

    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')

    elif total < 50 and r < 50:
        print('D')

    elif total < 65:
        print('C')
        
    elif total < 80:
        print('B')

    else:
        print('A')
        

Measured memory_bytes: 7720
fun main(args: Array<String>) {
    abc131d()
}

private data class Task(val takeTime: Long, val deadLine: Long)

fun abc131d() {
    val n = readLine()!!.toInt()
    val taskList = (1..n).map { readLine()!!.split(' ').map { it.toLong() } }
        .map { Task(it[0], it[1]) }
        .sortedBy { it.deadLine }

    taskList.fold(0L) { acc, task ->
        if (acc + task.takeTime <= task.deadLine) acc + task.takeTime else return println("No")
    }

    println("Yes")
}


Measured memory_bytes: 149676
N = int(input())
A = [int(i) for i in input().split()] 
mod = 10**9 + 7

b = [0]*N
b[0] = A[0]
for n in range(1,N):
    b[n] = A[n] ^ b[n-1]

dp = [[not j for i in range(1<<20)] for j in range(2)]
cnt = [0 for i in range(1<<20)]
z = 0

for i in range(N):
    if b[i] == 0:
        z +=1
    dp[0][b[i]] += dp[1][b[i]]*(z-cnt[b[i]])
    dp[0][b[i]] %= mod
    dp[1][b[i]] += dp[0][b[i]]
    dp[1][b[i]] %= mod
    cnt[b[i]] = z

if b[N-1]:
    print(dp[0][b[N-1]])
else:
    ans = pow(2, z-1, mod)
    for i in range(1, 1<<20):
        ans += dp[1][i]
        ans %= mod
    print(ans)

Measured memory_bytes: 151768
x, n = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i).sort_by{|x| x}

ans = nil
i = 0
while ans == nil do
  if !p.include?(x-i)
    ans = x-i
  elsif !p.include?(x+i)
    ans = x+i
  end
  i += 1
end

print ans

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

int main() {
    int n, m;
    cin >> n >> m;

    map<int, int> data;
    for (int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        data[a] += b;
    }
  
    int count = 0;
    int64_t sum = 0;
    auto itr = data.begin();
    while(count < m){
        if(itr->second > 0){
            count++;
            itr->second--;
            sum += itr->first;
        }
        else{
            itr++;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 4992
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

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

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

fn solve(a: Vec<char>, b: Vec<char>, c: Vec<char>) -> &'static str {
    let al = a.last().unwrap();
    let bf = b.first().unwrap();
    let bl = b.last().unwrap();
    let cf = c.first().unwrap();
    if al == bf && bl == cf {
         "YES"
    } else {
        "NO"
    }
}



fn main() {
    input!{
        a: chars,
        b: chars,
        c: chars,
    }
    println!("{}", solve(a, b, c));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int c[5];

signed main(){
  int a[3],b[3];
  r(i,3){
    cin>>a[i]>>b[i];
    c[a[i]-1]++;
    c[b[i]-1]++;
  }
  map<int,int>M;
  r(i,4){
    M[c[i]]++;
  }
  if(M[1]==2&&M[2]==2)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  static int H, W;
  static char[][] field;
  static int[][] var, hor;
  static boolean[][] reached_v, reached_h;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    H = Integer.parseInt(S[0]);
    W = Integer.parseInt(S[1]);
    
    field = new char[H][W];
    for(int i = 0; i < H; i++){
      String T = sc.nextLine();
      for(int j = 0; j < W; j++){
        field[i][j] = T.charAt(j);
      }
    }
    
    var = new int[H][W];
    hor = new int[H][W];
    reached_v = new boolean[H][W];
    reached_h = new boolean[H][W];
    
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(!reached_v[i][j]){
          var[i][j] = func1(i,j,0);
        }
      }
    }
    
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(!reached_h[i][j]){
          hor[i][j] = func2(i,j,0);
        }
      }
    }
    
    int ans = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        int n = var[i][j] + hor[i][j];
        ans = ans < n ? n : ans; 
      }
    }
    System.out.println(ans-1);
  }
  
  public static int func1(int h, int w, int count){
    if(h >= H || w >= W || h < 0 || w < 0){
      return count;
    }
    reached_v[h][w] = true;
    if(field[h][w] == '#'){
      return count;
    }
    
    return var[h][w] = func1(h+1, w, count+1);
  }
  
  public static int func2(int h, int w, int count){
    if(h >= H || w >= W || h < 0 || w < 0){
      return count;
    }
    reached_h[h][w] = true;
    if(field[h][w] == '#'){
      return count;
    }
    
    return hor[h][w] = func2(h, w+1, count+1);
  }
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll n,ans=0;
    cin >> n;
    char c[n],color[4]={'P','W','G','Y'};
    vll count(4,0);
    rep(i,n){
        cin >> c[i];
        rep(j,4){
            if(c[i] == color[j]){
                count[j]++;
                break;
            }
        }
    }
    rep(i,4){
        if(count[i] > 0)ans++;
    }
    cout << ((ans == 3)?"Three":"Four") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(const pair<long long,int> &a,const pair<long long,int> &b){
    return a.first<b.first;
}
int main(){
    int n,m;cin>>n>>m;
    vector<pair<long long,int>>d;
    for(int i=0;i<n;++i){
        long long a;int b;cin>>a>>b;
        d.push_back({a,b});
    }
    
    sort(d.begin(),d.end(),cmp);
    
    long long ans=0;
    for(auto p:d){
        ans+=p.first*min(m,p.second);
        if(m<=p.second)break;
        else m-=p.second;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

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

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

/**
 * http://code-festival-2017-quala.contest.atcoder.jp/tasks/code_festival_2017_quala_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		final int K = sc.nextInt();
		sc.close();
		
		boolean[] dp = new boolean[N*M+1];
		
		for(int i=0; i<=N; i++){
			for(int j=0; j<=M; j++){
				dp[i*M+j*N-i*j*2]=true;
			}
		}		
		System.out.println(dp[K] ? "Yes" : "No");
	}

}


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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  double ans = double(n/2+n%2)/double(n);
  cout << setprecision(15) <<  ans << endl;
  return 0;
}


Measured memory_bytes: 3784
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define DEBUG 1
#define ll         long long
#define REP(i, n) for (long long i = 0; i < (n); i++) 
static const ll INF = 1000000000000000000LL;
static const int MOD = 1000000007;


int main(){
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll res = INF;
    //たかだか3パターンしかないので全部やってみる
    
    //Aピザ,Bピザを買う
    res = min(res, a * x + b * y);

    //ABピザをmin(a,b)枚買って、残りを買う
    ll abmin = min(x,y);
    ll tmp;
    tmp = c * 2 * abmin;
    ll zan;
    if(x > y)zan = (x-y)*a;
    else zan = (y-x)*b;

    res = min(res, tmp + zan);

    //ABピザをmax(a,b)枚買う
    res = min(res, c * 2 * max(x,y));

    cout << res << endl;
    return 0;

}

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

public class Main {
  // AtCoder Beginner Contest 070
  // https://atcoder.jp/contests/abc070/tasks
  public static void main(String[] args) {
	FastReader sc = new FastReader();
	int k = sc.nextInt();
	int oddCnt = 0;
	int evenCnt = 0;
	
	for (int i = 1; i <= k; i++) {
		if (i % 2 == 0) {
			oddCnt++;
		} else {
			evenCnt++;
		}
	}
	System.out.println(oddCnt*evenCnt);
  }
  
  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: 21076
#include<bits/stdc++.h>
        #define vll vector<ll>
        #define vi vector<int>
        #define vpll vector<pair<ll,ll>>
        #define pii pair<int,int>
        #define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
        #define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
        #define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
        #define MOD 1000000007
        #define ALL(v) v.begin(), v.end()
        #define m0(x) memset(x,0,sizeof(x))
        typedef long long ll;
         
        using namespace std;
         
        int gcd(int a,int b){return b?gcd(b,a%b):a;}
        int dx[4]={1,0,-1,0};
        int dy[4]={0,1,0,-1};
        ll mod = 998244353;
        ll mod_pow(ll x, ll n) {
    	ll res = 1;
    	  while (n > 0) {
    		if (n % 2)res = res * x%mod;
    		x = x * x%mod; n >>= 1;
    	  }
    	  return res;
        }
         
        int main(){
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);

          ll N, ans = 1;
          cin >> N;
          ll D[N];
          ll count[N] = {};
          REP(i,N){
            cin >> D[i];
            count[D[i]]++; //頂点1からの距離がiとなる頂点数がcount[i]個
          }
          REP(i,N) count[i] %= mod;
          
          ll height = N-1;
          REP(i,N){
            if(count[i]==0){
              height=i;
              break;
            }
          }
          
          bool flg = false;
          if(count[0] != 1) flg = true;
          REP2(i,height+1,N){
            if(count[i] != 0) flg = true;
          }
         
          if(D[0]!=0 || flg){
            cout << "0";
            return 0;
          }
          // 1を根としてもよい
          REP2(i,2,height){
            ans = ans * (mod_pow(count[i-1], count[i]) % mod);
            ans %= mod;
          }
          cout << ans;
         
          return 0;
        }

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
 {
	int n; cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];

	int ans=0;
    int help[n];
    help[n-1]=0;
	for(int i=n-2;i>=0;i--){
	    help[i]=help[i+1]+arr[i+1];
	    help[i]%=1000000007;
	}
	for(int i=0;i<n-1;i++){
        int x=(arr[i]*help[i])%1000000007;
        ans+=x;
        ans%=1000000007;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6424