akhauriyash/Code-Regression huggingface dataset:
//回答見てやり直し
//http://drken1215.hatenablog.com/entry/2019/04/23/120400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
ll N;

//多次元vector
template<typename T>
vector<T> make_table(int n, T v) {
    return vector<T>(n, v);
}

template<typename... Args>
auto make_table(int n, Args... args) {
    auto val = make_table(forward<Args>(args)...);
    return vector<decltype(val)>(n,move(val));
}

int main() {
    cin >> N;
    auto dp = make_table(110, 5, 5, 5, 0ll);
    dp[0][0][0][0] = 1;
    for (int n = 0; n < N; n++) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                for (int k = 0; k < 5; k++) {
                    for (int l = 1; l < 5; l++) {
                        if (i == 1 && j == 2 && l == 3) continue;
                        if (i == 1 && k == 2 && l == 3) continue;
                        if (j == 1 && k == 2 && l == 3) continue;
                        if (j == 2 && k == 1 && l == 3) continue;
                        if (j == 1 && k == 3 && l == 2) continue;
                        dp[n+1][j][k][l] += dp[n][i][j][k];
                        dp[n+1][j][k][l] %= MOD;
                    }
                }
            }
        }
    }
    ll res = 0;
    for (int i = 1; i < 5; i++) {
        for (int j = 1; j < 5; j++) {
            for (int k = 1; k < 5; k++) {
                res += dp[N][i][j][k];
                res %= MOD;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  std::vector<int> l(N); rep(i,N) std::cin >> l[i];
  std::sort(all(l), std::greater<int>());

  int ans = 0;
  rep(i,K) ans += l[i];
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()

#define MAX 500

int main() {

	//clock_t start, end;
	//start = clock();

	lint N;
	cin >> N;

	lint C[MAX + 1] = {};
	lint S[MAX + 1] = {};
	lint F[MAX + 1] = {};

	for (lint i = 1; i <= N - 1; i++) cin >> C[i] >> S[i] >> F[i];
	
	for (int i = 1; i <= N; i++) {
		// 開始式開始時 x = 0 に駅 i にいる
		lint x = 0;

		// 駅 j から駅 j + 1 に移動するのに要する時間を加算していく
		for (int j = i; j <= N - 1; j++) {
			if (x <= S[j]) {
				x = S[j];
			}
			else if (x > S[j]) {
				if (x % F[j] != 0) x = (x / F[j] + 1) * F[j];
			}
			x += C[j];
		}
		cout << x << endl;
	}

	//end = clock();
	//printf("%f sec.\n", double(end - start) / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans_a = 0
ans_b = 0
sum = 0

n.times do |i|
    sum += a[i]
    if i % 2 == 0 then
        if sum <= 0
            ans_a += sum.abs + 1
            sum += sum.abs + 1
        end
    else
        if sum >= 0 then
            ans_a += sum.abs + 1
            sum -= sum.abs + 1
        end
    end
end

sum = 0

n.times do |i|
    sum += a[i]
    if i % 2 == 1 then
        if sum <= 0
            ans_b += sum.abs + 1
            sum += sum.abs + 1
        end
    else
        if sum >= 0 then
            ans_b += sum.abs + 1
            sum -= sum.abs + 1
        end
    end
end

puts [ans_a, ans_b].min

Measured memory_bytes: 9612
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
    if not a[i] in dic:
        dic[a[i]]=0
    dic[a[i]]+=1

keys=list(dic.keys())
count=0

for i in range(len(keys)):
    if keys[i]<dic[keys[i]]:
        count+=dic[keys[i]]-keys[i]
    elif dic[keys[i]]<keys[i]:
        count+=dic[keys[i]]
    else:
        pass

print(count)

Measured memory_bytes: 69032
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    int64_t k = 1;
    for (auto i : irange(0L, n)) {
        int64_t a;
        cin >> a;

        if (a == k) {
            ++k;
        }
    }

    if (k == 1) {
        cout << -1 << endl;
    } else {
        cout << n - (k - 1) << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<t.first<<" "<<t.second;}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

vi eratosthenes_sieve(int n){
	vi res(n+1);
	if(n<2) return res;
	res[2]=1;
	for(int i=3;i<=n;i+=2){
		if(i*i<=n && !res[i]) for(int j=i+i+i;j<=n;j+=i+i) res[j]=1;
		res[i]=!res[i];
	}
	return res;
}

int n, m;
int pmap[2000][2000];
int sx = 1000, sy = 1000;
map<int, pii> i2p;

int d[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
pii dp[2001][2001];

pii dfs(int y, int x, int upper){
	if(dp[y][x].first != -1) return dp[y][x];
	if(abs(pmap[y][x]) > upper) return dp[y][x] = pii(0, 0);
	pii res(0, 0);
	res = max(res, dfs(y+1, x-1, upper));
	res = max(res, dfs(y+1, x  , upper));
	res = max(res, dfs(y+1, x+1, upper));
	if(pmap[y][x] > 0){
		res.first ++;
		if(res.second == 0) res.second = pmap[y][x];
	}
	return dp[y][x] = res;
}

main(){
	vi isPrime = eratosthenes_sieve(1000001);
	int di = 0, px=sx, py=sy;
	for(int i=1;i<=1000000;i++){
		pmap[py][px] = isPrime[i] ? i : -i;
		i2p[i] = pii(py, px);
		px+=d[di][0];
		py+=d[di][1];
		if(!pmap[py+d[(di+1)%4][1]][px+d[(di+1)%4][0]]) di=(di+1)%4;
	}

	while(cin >> m >> n, m){
		REP(i, 2000)REP(j, 2000) dp[i][j] = pii(-1, -1);
		cout << dfs(i2p[n].first, i2p[n].second, m) << endl;
	}
	return 0;
}

Measured memory_bytes: 110800
def solve():
    n = int(input())
    A = tuple(map(int, input().split()))

    def check(B):
        for i in range(n - 1):
            if B[i] > B[i + 1]:
                return False
        return True

    def out(ans):
        print(len(ans))
        for a in ans:
            print(a[1] + 1, a[0] + 1)
        import sys
        sys.exit(0)

    mai = -1
    mii = -1
    ma = -10 ** 30
    mi = 10 ** 30

    for i in range(n):
        if A[i] > ma:
            ma = A[i]
            mai = i
        if A[i] < mi:
            mi = A[i]
            mii = i

    #print(ma, mai, mi, mii)

    B = list(A)
    ans = []
    for i in range(n):
        if i != mai:
            B[i] += B[mai]
            B[i] += B[mai]
            ans.append((i, mai))
            ans.append((i, mai))
            mai = i

    if check(B):
        out(ans)
        return


    B = list(A)
    ans = []
    for i in range(n - 1, -1, -1):
        if i != mii:
            B[i] += B[mii]
            B[i] += B[mii]
            ans.append((i, mii))
            ans.append((i, mii))
            mii = i

    if check(B):
        out(ans)
        return


solve()


Measured memory_bytes: 3192
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
namespace IO
{
	char buf[1 << 20 | 1] , *f1 = buf , *f2 = buf , pbuf[1 << 24 | 1] , *f3 = pbuf , sta[100];
	#define gc() ((f1 == f2) && (f2 = (f1 = buf) + fread(buf,1,sizeof buf,stdin),f1 == f2) ? EOF : *f1 ++)
	#define gt() getchar()
	inline int read()
	{
		int x = 0 , f = 1; char ch = gt();
		while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = gt();}
		while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = gt();}
		return x * f;
	}
	template <class T> inline void write(T x)
	{
		if(!x) return (void)(*f3 ++ = 48 , *f3 ++ = ' ');
		if(x < 0) *f3 ++ = '-' , x = ~x + 1;
		char *top = sta;
		while(x) *top ++ = x % 10 + 48 , x /= 10;
		while(top != sta) *f3 ++ = *-- top;
		*f3 ++ = ' ';
	}
	inline void put(std::string s)
	{
		int len = s.length();
		for(int i = 0;i < len;i ++) *f3 ++ = s[i];
		*f3 ++ = ' ';
	}
	inline void endline() { *f3 ++ = '\n';}
	#define flush() fwrite(pbuf,1,f3 - pbuf,stdout)
	template <class T> inline T abs(T a) { return a < 0 ? -a : a;}
	template <class T> inline T max(T a,T b) { return a > b ? a : b;}
	template <class T> inline T min(T a,T b) { return a < b ? a : b;}
	template <class T> inline void swap(T &a,T &b) { T t = a; a = b; b = t;}
}
using namespace IO;
const int N = 3e3 + 5 , mod = 1e9 + 7 , inv = (mod + 1) / 2;
int n , m;
int a[N];
ll f[N][N] , g[N][N];
int main()
{
	n = read(); m = read(); ll ans = 0 , tmp = 1;
	for(int i = 1;i <= n;i ++) a[i] = read();
	for(int i = 1;i <= n;i ++) for(int j = 1;j <= n;j ++) f[i][j] = a[i] > a[j];
	while(m --> 0)
	{
		int u = read() , v = read();
		if(u > v) swap(u,v); tmp = tmp * 2 % mod;
		for(int i = 1;i <= n;i ++) if(i != u && i != v) g[i][u] = (f[i][u] + f[i][v]) * inv % mod , g[u][i] = (f[u][i] + f[v][i]) * inv % mod , g[i][v] = (f[i][v] + f[i][u]) * inv % mod , g[v][i] = (f[v][i] + f[u][i]) * inv % mod;
		for(int i = 1;i <= n;i ++) if(i != u && i != v) f[i][u] = g[i][u] , f[u][i] = g[u][i] , f[i][v] = g[i][v] , f[v][i] = g[v][i];
		f[u][v] = f[v][u] = (f[u][v] + f[v][u]) * inv % mod;
	}
	for(int i = 1;i <= n;i ++) for(int j = i + 1;j <= n;j ++) ans = (ans + f[i][j]) % mod;
	printf("%lld\n",ans * tmp % mod);
	return 0;
}

Measured memory_bytes: 141568
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	unordered_map<string,int> s;

	int n;
	cin >> n;
	for(int i=0 ; i<n ; i++)
	{
		string temp;
		cin >> temp;
		s[temp]++;
	}

	int m;
	cin >> m;
	for(int j=0 ; j<m ; j++)
	{
		string temp;
		cin >> temp;
		s[temp]--;
	}

	int ans = 0;
	for(auto p : s)
	{
		ans = max(ans , p.second);
	}
	cout << ans;
	return 0;
}

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

typedef long long Long;

Long mabs(Long x) {
   if(x < 0) return -x;
   return +x;
}

void mmin(Long& a, Long b) {
   // cerr << a << " " << b << "\n";
   if(b < 0) return;
   a = min(a, b);
}

int main() {
   Long x, y; cin >> x >> y;
   Long rs = mabs(x) + mabs(y) + 10;
   // -(x+k) = y
   // -x-k = y
   // -k = y+x
   // k = -y-x
   if(-y-x >= 0) mmin(rs, -y-x+1);
   // x+k = y
   if(y-x >= 0) mmin(rs, y-x);
   // -x+k == y
   // k = y+x
   if(y+x >= 0) mmin(rs, y+x+1);
   // -(-x+k) == y
   // -x+k = -y
   // k = -y+x
   if(-y+x >= 0) mmin(rs, -y+x+2);
   cout << rs << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	while(1){
		int n,m,taro[100],hanako[100];
		scanf("%d %d",&n,&m);
		if(!n) break;
		int st=0,sh=0;
		for(int i=0;i<n;i++){
			scanf("%d",&taro[i]);
			st+=taro[i];
		}
		for(int i=0;i<m;i++){
			scanf("%d",&hanako[i]);
			sh+=hanako[i];
		}
		bool f=false;
		int anst,ansh;
		int ct,ch;
		int cs=114514;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				ct=st-taro[i]+hanako[j];
				ch=sh-hanako[j]+taro[i];
				if(ct==ch&&cs>taro[i]+hanako[j]){
					f=true;
					anst=taro[i];
					ansh=hanako[j];
					cs=taro[i]+hanako[j];
				}
			}
		}
		if(f)
			printf("%d %d\n",anst,ansh);
		else
			puts("-1");
	}
	return 0;
}

Measured memory_bytes: 2572
N, Y = [int(_) for _ in input().split()]

for x in range(0, Y//10000 + 1, 1):
    for y in range(0, Y//5000 + 1, 1):
        
        z = N - x - y
        
        if z < 0:
            break
        
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()
    
print("-1 -1 -1")


Measured memory_bytes: 66148
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using v2=vector<vector<int>>;
const int INF=1e+7;
v2 fall(v2 masu){

v2 ans(5,vector<int>(10));
for(int i=0;i<5;i++){
    int fin=0;
    for(int j=0;j<10;j++){
        if(masu[i][j]!=INF) {
            ans[i][fin] = masu[i][j];
            fin++;
        }
    }
    for(int j=fin;j<10;j++){
        ans[i][j]=i+10;
    }
}
return ans;
}
int main() {
    int n;

    while(true){
        cin>>n;
        if(n==0)break;
        int ans=0;

        v2 masu(5,vector<int>(10));
        for(int i=n-1;i>=0;i--){
            rep(j,5){
                int aaa;cin>>aaa;
                masu[j][i]=aaa;
            }
        }
        for(int i=n;i<10;i++){
            rep(j,5){
                masu[j][i]=j+10;
            }
        }
        while(true) {
            bool up=false;
            int st[10];
            for (int i = 0; i < 10; i++) {
                int h = 0, t = 0;
                while (t < 4) {
                    t++;
                    if (masu[t][i] != masu[h][i] && t - h <= 2) { h = t; }
                }
                if (h <= 2)st[i] = h;
                else st[i] = 5;
            }
            for (int i = 0; i < 10; i++) {
                if (st[i] != 5) {
                    up=true;
                    int suc=masu[st[i]][i];
                    int count=0;
                    for(int j=st[i];j<5;j++){
                        if(masu[j][i]==suc){count++;masu[j][i]=INF;}
                        else break;
                    }
                    ans+=count*suc;
                }
            }


            if(up==false){break;}
            else{
                masu=fall(masu);
            }
        }
        cout<<ans<<endl;

    }




    return 0;
}



Measured memory_bytes: 3148
import sys
sys.setrecursionlimit(10**9)


N, M = map(int, input().split())
to = [[] for _ in range(N)]
count = 0

for _ in range(M):
    A, B = map(lambda x:int(x) - 1, input().split())
    to[A].append(B)
    to[B].append(A)


def dfs(v, to, seen):
    global count
    seen[v] = True
    count += 1
    for nv in to[v]:
        if seen[nv]:
            continue
        dfs(nv, to, seen)


def main():
    global count
    seen = [False] * N
    cnts = []
    for i in range(N):
        if not seen[i]:
            dfs(i, to, seen)
            cnts.append(count)
            count = 0
    
    print(max(cnts))


if __name__ == "__main__":
    main()



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


string g[55];
int main() {
  int n, m;
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>g[i];
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      if (g[i][j]=='#') {
        cout<<"#"; continue;
      }
      int res=0;
      for (int dx=-1; dx<=1; dx++) {
        for (int dy=-1; dy<=1; dy++) {
          if (dx==0 && dy==0) continue;
          int x=dx+i; int y=dy+j;
          if (x>=0 && x<n && y>=0 && y<m) {
            res += (g[x][y]=='#');
          }
        }
      }
      cout<<res;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;
using ordered_set=tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
int main(int args, const char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    char a;
    cin >> a;
    cout << static_cast<char>(a + 1) << endl;

    return 0;
}

Measured memory_bytes: 256
# solution

import fractions
import math
import io

data=int(input())

array=list(map(int,input().split()))

ki=[0]*100001
gu=[0]*100001

for i in range(data):
    if i%2==0:
        ki[array[i]]+=1
    else:
        gu[array[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(data-km1[0]-gm1[0])
else:
    if km1[0]-km2[0]>=gm1[0]-gm2[0]:
        print(data-km1[0]-gm2[0])
    else:
        print(data-gm1[0]-km2[0])


Measured memory_bytes: 16008
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  ll total = 0;
  vi d(n);
  rep(i,n){
    cin >> d[i];
  }
  rep(i,n-1){
    for (ll j = i + 1; j < n;j++){
      total += d[i] * d[j];
    }
  }
  print(total);
}

Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x & 1 for x in arr)
    res = (res + one * (n - one) * (1 << d)) % mod
    arr = [x >> 1 for x in arr]

print(res)


Measured memory_bytes: 137272
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 30;

int dp[51];

int w[6]={2,3,5,10,12,15};
int v[6]={380,550,850,1520,1870,2244};

int main(void){
	rep(i,51) dp[i]=inf;
	dp[0]=0;
	rep(i,6){
		rep(j,51)if(j+w[i]<=50)
			dp[j+w[i]]=min(dp[j+w[i]],dp[j]+v[i]);
	}
	int n;
	while(cin >> n,n){
		int ans=dp[n/100];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problem168a(n))
}

fun problem168a(n: Int): String {
    return when(n.toString().last().toString()) {
        "2", "4", "5", "7", "9" -> "hon"
        "0", "1", "6", "8" -> "pon"
        "3" -> "bon"
        else -> ""
    }
}

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

using namespace std;

const long long MOD = 1000000007;

string k;
int d;

long long dp[105][10005];

long long solve(int dig, int sum, int top)
{
    if (sum < 0)
        sum = (sum%d)+d;
    sum %= d;
    if (dig == k.size())
        return (sum == 0);
    if (top)
    {
        long long ans = 0;
        for (int x = 0; x < k[dig]-'0'; x++)
            ans += solve(dig+1, sum-x, 0);
        ans += solve(dig+1, sum-(k[dig]-'0'), 1);
        return ans%MOD;
    }
    if (~dp[sum][dig])
        return dp[sum][dig];
    dp[sum][dig] = 0;
    for (int x = 0; x < 10; x++)
        dp[sum][dig] += solve(dig+1, sum-x, 0);
    return dp[sum][dig] %= MOD;
}


int main()
{
    memset(dp, -1, sizeof dp);
    cin>>k>>d;
    printf("%lli\n", (solve(0, 0, 1)-1+MOD)%MOD);
}


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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,x;
    cin>>n>>x;
    int l[n];
    for(int i=0;i<n;i++)
    cin>>l[i];

    int ans=1;
    int z=0;
    for (int i = 0; i < n; ++i) {
        z=z+l[i];
        if(z<=x)
            ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    int n,d;
    cin >> n >> d;
    int p[n][d];
    for(int i = 0; i < n;i++){
        for(int j = 0; j < d; j++){
            cin >> p[i][j];
        }
    }
    int count = 0;
    for(int i = 0; i < n;i++){
        for(int j = i+1; j < n; j++){
            double dans = 0;
            int ians = 0;
            for(int x = 0 ; x < d; x++){
                dans += (p[i][x] - p[j][x]) * (p[i][x] - p[j][x]);
            }
            dans = sqrt(dans);
            ians = dans;
            if(ians == dans) count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
  int sec, h, m, s;
  scanf("%d", &sec);
  h = sec / 3600;
  m = (sec - h * 3600) / 60;
  s = sec % 60;
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int ans=1000000;
    rep(i,(s.size()-t.size()+1)){
        int now=0;
        for(int j=0;j<(int)t.size();j++){
            if(s[i+j]!=t[j]) now++;
        }
        ans=min(ans,now);
    }
    cout<<ans;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////


int main() {
	int N, K; cin >> N >> K;
	vector<int>v(N);
	REP(i, N)cin >> v[i];
	int ans = 0;
	for (int a = 0; a <= min(N,K); ++a) {
		for (int b = 0; a + b <= min(N, K); ++b) {
			int x = K - a - b;
			int sum = 0;
			vector<int>V;
			for (int i = 0; i < a; ++i) {
				sum += v[i];
				V.push_back(v[i]);
			}
			for (int i = N - 1; i >= N - b; --i) {
				sum += v[i];
				V.push_back(v[i]);
			}
			sort(V.begin(), V.end());
			for (int i = 0; i < min(int(V.size()),x); ++i) {
				if (V[i] < 0) {
					sum -= V[i];
				}
				else {
					break;
				}
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define e "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

#define N 5010

int re(int a, int b, int c)
{
    return abs(((a/2)*c*b)-((a-a/2)*c*b));
}

void solve()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(re(a,b,c),min(re(b,a,c),re(c,a,b)));
}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}




Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        a[i]+=a[i-1];
    }
    int ans=0;
    for(int i=n;i>=1;--i){
        ans+=(a[i]-a[i-1])*a[i-1];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <deque>
#include <list>
#include <cassert>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define pb push_back
#define mp make_pair
#ifdef GRAPH
typedef pair <int, int> Edge;
#define v first
#define w second
#endif
#if __cplusplus >= 201103L
using LL = long long;
using ULL = unsigned long long;
#else
#define LL long long
#define ULL unsigned long long
#endif
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-12;

int main() {
	ios::sync_with_stdio(false);
	long double ans = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		ans += 1 / (long double)x;
//		cerr << ans << endl;
	}
//	ans += EPS;
	cout << fixed << setprecision(6) << 1 / ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int k;
  cin >> k;
  vector<ll> v;
  for (int i = 1; i < 10; i++)
    v.push_back(i);
  while (1)
  {
    if (k <= v.size())
    {
      cout << v[k - 1] << endl;
      return 0;
    }
    k -= v.size();
    vector<ll> prev = v;
    v.clear();
    for (auto x : prev)
    {
      for (int i = -1; i < 2; i++)
      {
        int d = x % 10 + i;
        if (d < 0 || d > 9)
          continue;
        ll n = x * 10 + d;
        v.push_back(n);
      }
    }
  }
}


Measured memory_bytes: 4756
N,Y = map(int,input().split())
result = [-1]*3
for i in range(N+1):
    for j in range(N-i+1):
        money = i * 10000 + j * 5000 + (N-i-j)*1000
        if money == Y :
            result = [i,j,(N-i-j)]
            break

print(*result)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
int read() {
    char ch = getchar();
    int x = 0, flag = 1;
    for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
    for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x * flag;
}
void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int Maxn = 109, Maxk = 200009;
int a[Maxn], n, k, dp[Maxk];

void init() {
	n = read(), k = read();
	rep (i, 1, n) a[i] = read();
}

void solve() {
	sort(a + 1, a + n + 1);
	rep (i, 1, k)
		rep (j, 1, n) 
			if (i - a[j] >= 0) 
				dp[i] |= (1 - dp[i - a[j]]);
	cout << (dp[k] ? "First" : "Second") << endl;
}

int main() {
//	freopen("K.in", "r", stdin);
//	freopen("K.out", "w", stdout);

	init();
	solve();

#ifdef Qrsikno
    debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
#define PI 3.14159265359
 
int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll ret = 0;
  if (A < K) {
    ret += A;
    K -= A;
  } else {
    ret += K;
    cout << ret << endl;
    return 0;
  }
  if (B >= K) {
    cout << ret << endl;
    return 0;
  }
  K -= B;
  if (C < K) {
    ret -= C;
  } else {
    ret -= K;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> d(N); for (int i = 0; i < N; i++) cin >> d[i];

    vector<int> num(101);
    for (int i = 0; i < N; i++) num[d[i]]++;

    int ans = 0;
    for (int i = 1; i <= 100; i++) {
        if (num[i] > 0) ans++;
    }

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


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 1;
  for (int i = 0; i + 1 < S.size(); i++) {
    if (S[i] != S[i+1]) ans++;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 512
import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const [a, b, n] = inputs[0].split(' ').map(Number);

  let x = b - 1 < n ? b - 1 : n;

  console.log(Math.floor((a * x) / b) - a * Math.floor(x / b));
}


Measured memory_bytes: 29916
//Plural Form 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;cin>>s;
    if(s[s.size()-1]=='s')cout<<s+"es"<<nnn;
    else cout<<s+"s"<<nnn;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
//4008802802
//4008160009
//1175114440
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define forn(i, a) for(register int i=0; i<a; i++)
#define Forn(i, a) for(register int i=1; i<=a; i++)
#define memINF 127
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;
typedef vector<vector<ll> > matrix;

inline int in() 
{
    int x=0, c;
    while((uint)((c=getchar())-48)>=10) 
        if(c=='-') 
            return -in();
    do 
    { x=(x<<3)+(x<<1)+(c^48); }
    while((uint)((c=getchar())^48)<10);
    return x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=1e5+5;

int N, K, a, b, val[MAX], L[MAX], R[MAX];
vi e[MAX];

inline void Dfs(int x, int p)
{
    L[x]=-1e9-1, R[x]=1e9+1;
    if(val[x]!=-1)
        L[x]=R[x]=val[x];
    foreach(it, e[x])
        if(*it!=p)
        {
            Dfs(*it, x);
            if(L[*it]<-1e9/2)
                continue;
            if(L[x]<-1e9/2)
            {
                L[x]=L[*it]-1;
                R[x]=R[*it]+1;
                continue;
            }
            if(abs(L[x])%2==abs(L[*it])%2)
            {
                puts("No");
                exit(0);
            }
            L[x]=max(L[x], L[*it]-1);
            R[x]=min(R[x], R[*it]+1);
        }
    if(L[x]>R[x])
    {
        puts("No");
        exit(0);
    }
}

inline void Make(int x, int p)
{
    foreach(it, e[x])
        if(*it!=p)
        {
            if(val[*it]==-1)
            {
                if(L[*it]<=val[x]-1&&val[x]-1<=R[*it])
                    val[*it]=val[x]-1;
                else
                    val[*it]=val[x]+1;
            }
            Make(*it, x);
        }
    
}

int main()
{
    memset(val, -1, sizeof(val));
    N=in();
    Forn(i, N-1)
    {
        a=in(), b=in();
        e[a].eb(b);
        e[b].eb(a);
    }
    
    K=in();
    while(K--)
        a=in(), val[a]=in();
    
    Dfs(1, 0);
    
    puts("Yes");
    if(val[1]==-1)
        val[1]=R[1];
        
    Make(1, 0);
    Forn(i, N)
        printf("%d\n", val[i]);
    return 0;
}

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

int main()
{
	int x,n,answerp=101,answerm=-101;
    cin>>x>>n;
    int a[n],p[101];
    for(int i=0;i<101;i++)
        p[i]=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        p[a[i]]=1;
    }
    if(n==0)
    {
        cout<<x;
        return 0;
    }
    if(n==1 && x!=a[0])
    {
        cout<<x;
        return 0;
    }
    for(int i=x;i<101;i++)
    {
        if(p[i]!=1)
        {
            answerp=i;
            break;
        }
    }
    for(int i=x-1;i>-101;i--)
    {
        if(p[i]!=1)
        {
            answerm=i;
            break;
        }
    }
    if((x-answerm)>(answerp-x))
    {
        cout<<answerp;
        return 0;
    }
    cout<<answerm;

}

Measured memory_bytes: 3624
n_5 = 0
n_7 = 0

a = map(int, input().split())
for i in a:
    if i == 5:
        n_5 += 1
    elif i == 7:
        n_7 += 1

if n_5 == 2 and n_7 == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 8848
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%3d", arr[i][j]); } cout << endl; }

using namespace std;

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

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
string s[2000];
int c[2000][2000];
int r[2000][2000];
int H, W;

int main() {
    cin >> H >> W;
    rep(i, H) cin >> s[i];
    int cur = 0;
    int pre = -1;
    rep(i, H) {
        rep(j, W) {
            if (s[i][j] == '#' || j == W - 1) {
                if(j == W - 1 && s[i][j] == '.') {
                    cur++;
                    j++;
                }
                for (int k = pre + 1; k < j; ++k) {
                    c[i][k] = cur;
                }
                pre =  j;
                cur = 0;
            } else {
                cur++;
            }
        }
        pre = -1;
        cur = 0;
    }
    rep(j, W) {
        rep(i, H) {
            if (s[i][j] == '#' || i == H - 1) {
                if(i == H - 1 && s[i][j] == '.') {
                    cur++;
                    i++;
                }
                for (int k = pre + 1; k < i; ++k) {
                    r[k][j] = cur;
                }
                pre =  i;
                cur = 0;
            } else {
                cur++;
            }
        }
        pre = -1;
        cur = 0;
    }
    int ans = -1;
    rep(i, H) {
        rep(j, W) {
            chmax(ans, c[i][j] + r[i][j] - (s[i][j] == '.' ? 1 : 0));
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {
    int n; cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i+=2) {
        if (a[i] % 2 == 1) ans++;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  string t;
  cin >> t;
  int n=0,s=0,e=0,w=0;
  rep(i,t.size()){
    if(t[i]=='N')n++;
    if(t[i]=='S')s++;
    if(t[i]=='E')e++;
    if(t[i]=='W')w++;
  }
  if((n>0 && s==0)||(s>0 && n==0)||(e>0 && w==0)||(w>0 && e==0)){
    cout << "No" << endl;
  }
  else cout << "Yes" << endl;
    
}


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

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;
constexpr long long aPN = 1e9 + 7;

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

int main() {
  ll s;
  cin >> s;

  vector<ll> v(s + 1);
  v.at(0) = 1;

  for (ll i = 2; i <= s; i++) {
    for (ll k = i - 3; k >= 0; k--) {
      v.at(i) += v.at(k);
      v.at(i) %= aPN;
    }
  }
  cout << v.at(s) << endl;

  return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>

typedef struct node{
  int id,parent,left,right;
}point;

point array[10000000];

int main(){
  int H,i,p;
  
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&array[i].id);
    array[i].left = NULL;
    array[i].right = NULL;
    if(i%2==0){
      array[i].parent = array[i/2].id;
      array[i/2].left = array[i].id;
    }
    if(i%2==1){
      array[i].parent = array[i/2].id;
      array[i/2].right = array[i].id;
    }
  }

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,array[i].id);
    if(i>=2)printf("parent key = %d, ",array[i].parent);
    if(array[i].left!=NULL)printf("left key = %d, ",array[i].left);
    if(array[i].right!=NULL)printf("right key = %d, ",array[i].right);
    printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2052
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int solve(string S) {
	int N = S.size();
	map<int, int> dp;
	dp[0] = 0;
	int bit = 0;
	for (int i = 0; i < N; ++i) {
		bit ^= 1 << (S[i] - 'a');
		int opt = (dp.find(bit) != dp.end() ? dp[bit] : inf);
		for (int j = 0; j < 26; ++j) {
			map<int, int>::iterator it = dp.find(bit ^ (1 << j));
			if (it != dp.end()) {
				opt = min(opt, it->second + 1);
			}
		}
		if (opt != inf) dp[bit] = opt;
	}
	return (bit == 0 ? 1 : dp[bit]);
}
int main() {
	string S;
	cin >> S;
	cout << solve(S) << endl;
	return 0;
}

Measured memory_bytes: 9988
#include<iostream>
#include<string>
#include<vector>
using namespace std;
bool judge(int x, string y){
    if ( x % 3 == 0 && x % 5 == 0 ) return y == "FizzBuzz";
    if ( x % 3 == 0 ) return y == "Fizz";
    if ( x % 5 == 0 ) return y == "Buzz";
    if ( !isdigit(y[0]) ) return false;
    return x == stoi(y);
}
int main(){
    int m, n;
    string num;
    while( cin >> m >> n && m ){
        vector<int> P;
        int cur = 0, w = -1;
        for ( int i = 1; i <= m; i++ ) P.push_back(i);
        for ( int i = 1; i <= n; i++ ){
            cin >> num;
            if ( w != -1 ) continue;
            if ( judge(i, num) ) cur++;
            else P.erase(P.begin() + cur);
            cur = cur%P.size();
            if ( P.size() == 1 ) w = P[0];
        }
        if ( w != -1 ){
            cout << w << endl;
        }else {
            for ( int i = 0; i < P.size()-1; i++ ){
                cout<<P[i]<<" ";
            }
            cout<<P[P.size()-1]<<endl;
        }
    }
    return 0;
}

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

#define mod 1000000007
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323
#define debug(x) cout<<"Case "<<x<<": "
#define For(i,n) for(long long i=0;i<n;i++)
#define Frabs(i,a,b) for(long long i = a; i < b; i++)
#define Frabr(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	string s,t;
	cin>>s>>t;
	ll n=s.size(),m=t.size();
	ll dp[n+5][m+5]={0};
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=m;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(s[i-1]==t[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	vector<char> output;
	ll i=n,j=m;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
			output.pb(s[i-1]),i--,j--;
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	}
	reverse(output.begin(),output.end());
	for(ll i=0;i<output.size();i++)
		cout<<output[i];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
const int inf = 1 << 30;
int n, m, x, y = 0;ll z, w, h, sum = 0, ans = 0;
int main(void) {
	cin >> n; vector<int> a(n);
	map<int, int> mp;
	vector<int> p(1000100, 0);
	set<int> st;
	rep(i, n) {
		cin >> a[i];
		st.insert(a[i]);
		p[a[i]]++;
	}sort(ALL(a));
	if (a[0] == 1 && a[1] == 1) {
		cout << 0 << endl;
		return 0;
	}
	else if (a[0] == 1) {
		cout << 1 << endl;
		return 0;
	}
	for(int i : st) {
		int point = i * 2;
		while (point <= 1000010) {
			p[point]++;
			point += i;
		}
	}
	rep(i, n) {
		if (p[a[i]] == 1) ans++;
	}cout << ans << endl;
}

Measured memory_bytes: 17248