akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) puts("pon");
  else if(n % 10 == 3) puts("bon");
  else puts("hon");
  return 0;
}


Measured memory_bytes: 1640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//最大公約数
ll gcd(ll a,ll b)
{
    if(a%b == 0)
        return b;
    else
        return gcd(b, a % b);
}

int main(){
    int n;
    cin>>n;
    vector<pair<double, string>>  p;

    double ans=0;
    for (int i = 0; i < n;i++)

    {
        double l;
        string s;
        cin >> l >> s;
        
        if(s == "BTC")
            ans += l * 380000;
        else
        {
            ans += l;
        }
        
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int dp[101][10001];
	int N,W;
	cin>>N>>W;
	for(int i=0;i<=W;i++){
		dp[0][i] = 0;
	}
	int v,w;
	for(int i=1;i<=N;i++){
		cin>>v>>w;
		for(int j=0;j<=W;j++){
			if(j>=w){
				dp[i][j] = max(dp[i-1][j-w]+v,dp[i-1][j]);
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}

Measured memory_bytes: 5104
while True:
    a, op, b = input().split()
    a, b = int(a), int(b)
    if op == '+':
        print(a+b)
    if op == '-':
        print(a-b)
    if op == '*':
        print(a*b)
    if op == '/':
        print(a//b)
    if op == '?':
        break
    
    


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, L, a[N];
int main() {
	scanf("%d%d", &n, &L);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i < n; i++) {
		if (a[i] + a[i + 1] >= L) {
			puts("Possible");
			for (int j = 1; j < i; j++) printf("%d\n", j);
			for (int j = n - 1; j > i; j--) printf("%d\n", j);
			printf("%d\n", i);
			return 0;
		}
	}
	puts("Impossible");
	return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    ll k;
    cin>>k;
    if(k%2==0)
    cout<<-1<<endl;
    else 
    {
        ll x=7;
        ll cnt=1;
        ll flag=0;
        for(int i=1;i<=k;i++)
        {
            if(x%k==0)
            {
                flag=1;
                cout<<cnt<<endl;
                break;
            }
            else
            {
                x=((x*10+7)%k);
                cnt++;
            }
        }
        if(flag==0)
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 3644
def dfs(n):
    if int(n)>N:
        return
    L.append(int(n))
    dfs(n+"3")
    dfs(n+"5")
    dfs(n+"7")
    
N=int(input())
L=[]
dfs("3")
dfs("5")
dfs("7")

M=[]
for l in L:
    S=str(l)
    if "3" in S and "5" in S and "7" in S and l<=N:
        M.append(l)
print(len(M))

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

Measured memory_bytes: 1752
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include <cstring>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
#define FIND(v, k) find((v).begin(), (v).end(), k)
#define MAX 101
#define MAX_V 15
#define mset(a,x) memset(a,x,sizeof(a))

int main() {
	long long x, res;
	cin >> x;
	res = x / 11 * 2;
	x = x % 11;
	if (x > 6) {
		res += 2;
	}
	else if (0 < x) {
		res += 1;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n ,score ,total=0 ,highest=0 ,lowest;
  while( true ){
    cin >> n;
    if( n == 0 ){
      break;
    }
    
    for( int i=0 ; i<5 ; i++ ){ // 一人目の得点
      cin >> score;
      total += score;
    }
    
    highest = total;
    lowest = total;
    total = 0;
    
    for( int i=0 ; i<n-1 ; i++ ){
      
      for( int j=0 ; j<5 ; j++ ){ // n-1回目の得点
	cin >> score;
	total += score;
      }
      
      if( total > highest ){ // 最大なら
	highest = total;
      }
      
      else if( total < lowest ){ // 最小なら
	lowest = total;
      }
      total = 0;
    }
    
    cout << highest << " " << lowest << endl;
  }
}

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

#define ll long long

int main() {
	ll n, y, a, b, c, num;
	cin >> n >> y;
	ll sum;
	for (a = 0; a <= n; a++) {
		for (b = 0; b <= n; b++) {
			c = n - a - b;
			if (a < 0 || b < 0 || c < 0)continue;
			sum = a * 10000 + b * 5000 + c * 1000;
			if (sum == y) {
				cout << a << " " << b << " " << c << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    long long N, K; cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    for (int i = K; i < N; i++) {
        if (A[i-K] < A[i]) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 4780
#include <cstdio>
#include <vector>

using namespace std;

int all_ones(int n) //Return a number consisting of n 1s in binary
{
    return (1LL << n) - 1;
}

int is_bit_set(int n, int position)
{
    return ( (n&(1LL << position)) != 0);
}

int main()
{
    int no_of_elements, k;
    scanf("%d %d", &no_of_elements, &k);

    vector <int> cost(no_of_elements + 1);
    vector <int> utility(no_of_elements + 1);
    for(int i = 1; i <= no_of_elements; i++)
        scanf("%d %d", &cost[i], &utility[i]);

    int limit = k + 1;
    const int MAX_BITS = 31;

    long long mask = 0, best_utility = 0;

    for(int bit = MAX_BITS; bit >= 0; bit--)
    {
        if(is_bit_set(limit, bit)) //bit is set
        {
            mask = (limit - (1LL << bit)); //Make that bit 0

            mask |= all_ones(bit); //Set all bits after that position

            long long current_utility = 0;

            for(int i = 1; i <= no_of_elements; i++)
            {
                if( (mask&cost[i]) == cost[i] ) //Cost[i] is a submask of mask
                {
                    current_utility += utility[i];
                }
            }

            best_utility = max(best_utility, current_utility);
        }
    }

    printf("%lld\n", best_utility);
    return 0;
}


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


int main(){
	int n,d,x,a[100],ans=0;

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

	for(int i=0;i<n;i++)
		ans+=(d-1)/a[i]+1;
	ans+=x;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	rep(i, (s.length()))cout << 'x';
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <bitset>
using namespace std;

int point(tuple<int, int, int> t) {
    if        (t == make_tuple(0,1,2)) {
        return 0;
    } else if (t == make_tuple(0,2,1)) {
        return 1;
    } else if (t == make_tuple(1,0,2)) {
        return 2;
    } else if (t == make_tuple(1,2,0)) {
        return 3;
    } else if (t == make_tuple(2,0,1)) {
        return 4;
    } else if (t == make_tuple(2,1,0)) {
        return 5;
    }
}

bool dfs(const vector<vector<vector<int>>> &graph, bitset<50> used, int pos) {
    // 0に戻れるか
    for (int amida_id: graph[pos][0]) {
        if (used[amida_id] != 1) return true;
    }
    
    // 移動
    bool f = false;
    for (int i=0; i<6; i++) {
        for (int amida_id: graph[pos][i]) {
            if (used[amida_id] != 1) {
                bitset<50> new_used = used;
                new_used[amida_id] = 1;
                f |= dfs(graph, new_used, i);
            }
        }
    }
    return f; 
}

void solve(const vector<tuple<int, int, int>> &amida) {
    // 置換に変換
    /*
    for (tuple<int, int, int> t: amida) 
        cout << "{" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << "}" << endl;
    */

    vector<vector<vector<int>>> graph(6);
    for (auto &x: graph) x.resize(6);

    int c = 0;
    for (tuple<int,int,int> t: amida) {
        for (int i=0; i<3; i++)
            for (int j=0; j<3; j++)
                for (int k=0; k<3; k++)
                    if (i!=j && i!=k && j!=k) {
                        vector<int> l = {i,j,k};
                        graph[point(make_tuple(i,j,k))]
                             [point(make_tuple(l[get<0>(t)-1], l[get<1>(t)-1], l[get<2>(t)-1]))]
                            .push_back(c);
                    }
        c++;
    }

    /*
    cout << "0" << endl;
    for (int i=0; i<6; i++) {
        cout << i << ": ";
        for (auto x: graph[0][i]) {
            cout << x << " ";
        }
        cout << endl;
    }
    */

    if (dfs(graph, bitset<50>(0), 0)) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
}

int main() {
    int n; cin >> n;
    vector<vector<int>> in(n);

    for (auto &x: in) {
        int w; cin >> w; x.resize(w);
        for (auto &y: x) cin >> y;
    }

    vector<tuple<int, int, int>> amida(n);
    for (int i=0; i<n; i++) {
        tuple<int, int, int> state = make_tuple(1, 2, 3);
        reverse(in[i].begin(), in[i].end());
        for (auto x: in[i]) {
            if (x == 0) {
                state = make_tuple(get<1>(state), get<0>(state), get<2>(state));
            } else {
                state = make_tuple(get<0>(state), get<2>(state), get<1>(state));
            }
        }
        amida[i] = state;
    }

    solve(amida);
}


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

const int mod = 1000000007;
int n, a[100004], cnt[100004], comb[100004], lcomb[100004];

int mul(int a, int b){
	long long ret = (long long) a*b;
	return ret % mod;
}
int power(int a, int p){
	if(p==0)	return 1;
	int ret = power(a,p/2);
	ret = mul(ret,ret);
	if(p % 2 == 1)	ret = mul(ret,a);
	return ret;
}
int inv(int a){
	if(a==1)	return 1;
	return power(a,mod-2);
}
int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n;
	int chk;
	memset(cnt,0,sizeof(cnt));
	comb[0]=1;
	for(int i = 1;i <= n+1;i++)
		comb[i] = mul(inv(i),mul(comb[i-1],(n-i+2)));
	for(int i = 1;i<=n+1;i++){	
		cin>>a[i];
		if(cnt[a[i]])	chk = n-i+cnt[a[i]];
		cnt[a[i]] = i;
	}
	lcomb[0] = 1;
	for(int i = 1;i <= chk;i++)
		lcomb[i] = mul(inv(i),mul(lcomb[i-1],(chk-i+1)));
	for(int i = 1;i<=n+1;i++)
			cout<<(comb[i]-lcomb[i-1]+mod)%mod<<'\n';
	return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	ll a[114514] = {}; int n; cin >> n;
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	sort(a, a + n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == a[i + 1])i += 1;
		else cnt++;
	}
	cout << cnt << endl;
	char c; cin >> c;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

ll MOD = ll(1e9 + 7);

ll add(ll x, ll y){
    x += y;
    if(x >= MOD) x -= MOD;
    return x;
}

ll sub(ll x, ll y){
    x -= y;
    x += MOD;
    if(x >= MOD) x -= MOD;
    return x;
}

ll mul(ll x, ll y){
    return (x % MOD * y % MOD) % MOD;
}

ll pwr(ll x, ll p){
    if(p == 0) return 1;
    if(p == 1) return x;
    if(p&1) return mul(x, pwr(x, p-1));
    ll t = pwr(x, p/2);
    return mul(t, t);
}

ll inv(ll x){
    return pwr(x, MOD-2);
}

const int N = 1e6 + 6;
ll fat[N], ifat[N], iv[N];

void pre(){
    fat[0] = ifat[0] = 1;
        iv[1] = 1;
    for(int i = 2; i < N; i++){
            iv[i] = MOD - MOD / i * iv[MOD % i] % MOD;
    }
    
    for(int i = 1; i < N; i++){
        fat[i] = mul(fat[i-1], i);
            ifat[i] = mul(ifat[i-1], iv[i]);
    }
}

ll nck(int n, int k){
    if(n < 0 or k < 0) return 0;
    if(k > n) return 0;
    if(k == 0) return 1;

    ll a = fat[n];
    ll b = ifat[n-k];
    ll c = ifat[k];
    a = mul(a, b);
    a = mul(a, c);
    return a;
}

int main(){
    fcin;
    int x, y;
    cin >> x >> y;

    pre();

    if((2*y - x) % 3) return cout << 0 << endl, 0;
    int a = 2*y - x;
    a /= 3;
    ll ans = nck((x + a) / 2, a);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 23680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

ll d,n,x = 1;

cin >> d >> n;

if (d == 0 && n != 100)
{
   cout << n << endl;
}else
{  for (ll  i = 0; i < d; i++)
{
   x *= 100;
}
   if (n == 100)
   {
      cout << 101*x << endl;
   }else
   {
      cout << x*n << endl;
   }
   
 }






//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline

N, M = map(int, input().split())
arr = [[i] for i in range(1,M+1)]
for i in range(M):
    temp1, temp2 = map(int, input().split())
    arr[i].append(temp1)
    arr[i].append(temp2)
arr.sort(key=lambda x:x[2])
arr.sort(key=lambda x:x[1])
city = 0
for i, value in enumerate(arr):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]
arr.sort(key=lambda x:x[0])
for value in arr:
    left = str(value[1]).zfill(6)
    right = str(value[3]).zfill(6)
    print(left + right)


Measured memory_bytes: 29064
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

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

    int n;
    cin >> n;
    vector<double> p(n + 1);
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
    for (int i = 1; i <= n; ++i)
        cin >> p[i];

    dp[0][0] = 1.0;

    for (int i = 1; i <= n; ++i)
    {
        dp[i][0] = (1.0 - p[i]) * dp[i - 1][0] * 1.0;
        for (int j = 1; j <= i; ++j)
            dp[i][j] = p[i] * dp[i - 1][j - 1] * 1.0 + (1.0 - p[i]) * dp[i - 1][j] * 1.0;
    }
    /*
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
            cout << dp[i][j] << " \n"[j == n];
    */
    double sol = 0;
    for (int i = ceil(n / 2.0); i <= n; ++i)
        sol += 1.0 * dp[n][i];
    cout << setprecision(10) << sol << endl;
    return 0;
}

Measured memory_bytes: 73696
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
const int MAXN=200000+10;
char s[MAXN], h[MAXN];
int n, m;
int l, k,cnt,num;
int main(){
	cin >> n >> k;
	rep(i, 1, n) cin >> s[i]; 
    rep(i, 1, n) {
		if (s[i] == 'A') s[i] = '1'; 
		else s[i] = '0';
    }
	int i = 1;
    for (l = 1; l <= n + n + 10; ++l) {
        int t = s[i]-'0';
        if (t ^ cnt) s[i] = (1 - t) + '0';
        else{
            cnt ^= 1;
            num ^= 1;
            ++i;
        }
        if (l == k) {
            rep(j, i, n){
                t = s[j] - '0';
                if (t ^ cnt) cout<<"A";
				else cout<<"B";
            }
            rep(j, 1, i - 1) {
                if (num) cout<<"A";
				else cout<<"B";
                num ^= 1;
            }
        }
        if (i > n) break;
    }
    if (l < k) {
        if (!num) {
            rep(i, 1, n) {
                if (i % 2 == 1) cout<<"B";
				else cout<<"A";
			}
			cout<<"\n";
            return 0;
        }
        rep(i, 1, n) {
            if (num) h[i] = 'A';
			else h[i] = 'B';
            num ^= 1;
        }
        if (l % 2 != k % 2) {
            if (h[1] =='A') h[1] = 'B';
			else h[1] = 'A';
        }
        rep(i, 1, n) cout<<h[i];
        cout<<"\n";
        return 0;
    }
}


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

ll N, A, B, C;
vector<ll> L;

template <class T>
void chmin(T &a, T b) {if (a > b) a = b;}

ll rec(ll i, ll a, ll b, ll c)
{
	if (i == N)
	{
		// process
		if (a == 0 || b == 0 || c == 0) return 1ll << 60;
		return abs(A - a) + abs(B - b) + abs(C - c);
	}

	ll res{1ll<<60};
	chmin(res, rec(i+1, a, b, c)); // no use
	chmin(res, rec(i+1, a+L[i], b, c) + (a == 0 ? 0 : 10)); // use L[i] to A
	chmin(res, rec(i+1, a, b+L[i], c) + (b == 0 ? 0 : 10)); // use L[i] to B
	chmin(res, rec(i+1, a, b, c+L[i]) + (c == 0 ? 0 : 10)); // use L[i] to C

	return res;
	
}
int main(int argc, char **argv)
{
	cin >> N >> A >> B >> C;
	L.resize(N); for (int i = 0; i < N; ++i) cin >> L[i];

	std::cout << rec(0ll, 0ll, 0ll, 0ll) << std::endl;
}


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

#define pb push_back
#define mp make_pair

#define fi first
#define se second

typedef long long ll;

using namespace std;

char sign[100005];

int arr[100005];

ll sum, ans;

int n;

void solve() {
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        if (i > 1) {
            scanf(" %c", &sign[i]);
        }
        else {
            sign[i] = '+';
        }

        scanf("%d", &arr[i]);
    }

    for (int i = 1; i <= n; ++i) {
        sum += arr[i];
    }

    int ptr = 1;

    while (ptr <= n && sign[ptr] == '+') {
        ++ptr;
    }

    ll cur1 = 0, cur2 = 0;

    if (ptr > n) {
        ans = 0;
    }
    else {
        ans = 1e15;
    }

    for (; ptr <= n; ++ptr) {
        if (sign[ptr] == '-') {
            cur1 += arr[ptr];
            cur2 = 0;
        }
        else {
            cur2 += arr[ptr];
        }

        if (ptr == n || sign[ptr + 1] == '-') {
            ans = min(ans, cur1 + cur2);
        }
    }

    printf("%lld\n", sum - 2 * ans);
}

int main() {
    #ifdef BThero
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // BThero

    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：Breadth First Search
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_C
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----
static const ll N_MAX = 110;

// グローバル変数（入力）
ll n, A[N_MAX][N_MAX];

// 入力
void input() { cin >> n; }

// 幅優先探索
void bfs() {
  queue<ll> q;

  // 距離を-1で初期化
  vll d(n + 1, -1);

  // 始点の処理
  d[1] = 0;
  q.push(1);

  // 探索
  while (!q.empty()) {
    ll v = q.front();
    q.pop();
    rep(i, n) {
      if (A[v][i + 1] == 1 && d[i + 1] == -1) {
        q.push(i + 1);
        d[i + 1] = d[v] + 1;
      }
    }
  }
  rep(i, n) { cout << i + 1 << " " << d[i + 1] << endl; }
}

void solve() {
  // 隣接リストを隣接行列に変換して二次元配列Aに格納
  rep(i, n) {
    ll v, k;
    cin >> v >> k;
    rep(j, k) {
      ll v2;
      cin >> v2;
      A[v][v2] = 1;
    }
  }

  bfs();
}

int main() {
  input();
  solve();
  return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int i,k,x,a;
    cin >> k >> x;
    a = x-k+1;
    for(i=0;i<2*k-1;i++){
        cout<<a<<" ";
        a++;
    }
    return 0;

}

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

int main(){
int s;
  cin>>s;
  
  int count=1;
  while(s>4 || s==3){
   count++; 
   if(s%2==0){s=s/2;}
   else{s=3*s+1;}
  }
  
  cout<<count+3;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main () 
{
    string s;cin>>s;
    long long int l=s.length();
    for (long long int i=0;i<l;i++) cout<<"x";
    cout<<endl;
    
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
A = list(map(int, input().split()))
d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
for i in range(M):
    Bi, Ci = map(int, input().split())
    d[Ci] += Bi

res = N
ans = 0
for k, v in sorted(d.items(), reverse=True):
    ans += k * min(v, res)
    res -= v
    if res <= 0:
        break
print(ans)


Measured memory_bytes: 40992
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
string query (int pos) {
  cout << pos << endl;
  string get;
  cin >> get;
  if (get == "Vacant") {
    exit(0);
  }
  return get;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int l = 0;
  int r = n - 1;
  string sl = query(l);
  string sr = query(r);
  while (true) {
    int mid = (l + r) / 2;
    string ms = query(mid);
    if (((mid - l) % 2 == 0 && sl != ms) || ((mid - l) % 2 == 1 && sl == ms)) {
      r = mid;
      sr = ms;
    }
    if (((r - mid) % 2 == 0 && ms != sr) || ((r - mid) % 2 == 1 && sr == ms)) {
      l = mid;
      sl = ms;
    }
  }
  return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }

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

    string S;
    std::cin >> S;

    string ans = "Yes";
    REP(i, S.size()) {
        if((i % 2 == 1 && S[i] == 'R') || (i % 2 == 0 && S[i] == 'L')) {
            ans = "No";
            break;
        }
    }
    std::cout << ans << std::endl;

    return 0;
}


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

int main() {
  int h,w;
  cin>>h>>w;
  int c[15][15];
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      cin>>c[i][j];
    }
  }
  int a[205][205];
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin>>a[i][j];
    }
  }

  for (int k=0; k<10; k++) {
    for (int i=0; i<10; i++) {
      for (int j=0; j<10; j++) {
	c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  int ans=0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (a[i][j]==-1) continue;
      ans+=c[a[i][j]][1];
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 384
n, d = map(int, input().split())
l = []
for i in range(n):
    l.append(list(map(int, input().split())))

ans = 0

for i in range(n):
    for j in range(i+1, n):
        left = l[i]
        right = l[j]
        sm = sum(list(map(lambda x,y: pow(x-y, 2), left, right)))

        result = pow(sm, 1/2)
        if result.is_integer():
            ans += 1

print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String line2 = br.readLine();
        String[] ary = line2.split(" ");
        List<Integer> list = new ArrayList<Integer>();
        for(int i=0;i<ary.length;i++) {
          list.add(new Integer(ary[i]));
        }
        Collections.reverse(list);
        for(int i=0;i<list.size();i++) {
           System.out.print(list.get(i));
           if(i==list.size()-1) {
             System.out.println();
           }else {
             System.out.print(" ");
           }
        }
    }
}

Measured memory_bytes: 17092
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define N 100010
#define pb push_back
#define ll long long
#define pii pair <int, int>

using namespace std;

struct st {
	int ff, ss, in;
};

st p[N];
int n, m;
string A[N];

bool cmp(st a, st b)
{
	if(a.ff == b.ff)
		return a.ss < b.ss;
	
	return a.ff < b.ff;
}

int main()
{
	cin >> n >> m;
	
	for(int i = 1; i <= m; i++)
		cin >> p[i].ff >> p[i].ss, p[i].in = i;
	
	sort(p+1, p+m+1, cmp);
	
	int now = 0;
	for(int i = 1; i <= m; i++) {
		int now = 1;
		
		while(p[i].ff == p[i+1].ff) {
			string s;
			int a = p[i].ff;
			
			while(a) s += (char)(a%10+'0'), a /= 10;
			
			reverse(s.begin(), s.end());
			
			for(int h = 1; h <= 6-s.length(); h++) A[p[i].in] += '0';
			
			A[p[i].in] += s;
			
			a = now;
			s.clear();
			
			while(a) s += (char)(a%10+'0'), a /= 10;
			
			reverse(s.begin(), s.end());
			for(int h = 1; h <= 6-s.length(); h++) A[p[i].in] += '0';
			
			A[p[i].in] += s;
			now++, i++;
		}
		
		string s;
		int a = p[i].ff;
		
		while(a) s += (char)(a%10+'0'), a /= 10;
		
			reverse(s.begin(), s.end());
		for(int h = 1; h <= 6-s.length(); h++) A[p[i].in] += '0';
		
		A[p[i].in] += s;
		
		a = now;
		s.clear();
		
		while(a) s += (char)(a%10+'0'), a /= 10;
		
			reverse(s.begin(), s.end());
		for(int h = 1; h <= 6-s.length(); h++) A[p[i].in] += '0';
		
		A[p[i].in] += s;
	}
	
	for(int i = 1; i <= m; i++)
		cout << A[i] << "\n";
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int n;
  cin >> n;
  string s[100100];
  long m=0,a=0,r=0,c=0,h=0;
  for (int i=0; i<n; i++){
  	cin >> s[i];
    if(s[i][0]=='M') m++;
    else if(s[i][0]=='A') a++;
    else if(s[i][0]=='R') r++;
    else if(s[i][0]=='C') c++;
    else if(s[i][0]=='H') h++;
  }
  
  long sum=0;
  
  sum= m*a*r+ m*a*c+ m*a*h+ m*r*c+ m*r*h+ m*c*h+ c*a*r+ h*a*r+ c*a*h+ c*h*r;
  
  cout << sum << endl;
  
}

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

int main(){
    int N, K;
    cin >> N >> K;
    int h;
    int count = 0;
    for(int i=0;i<N;i++){
        cin >> h;
        if(h >= K)count++;

    }
    cout << count << endl;
}

Measured memory_bytes: 256
#そのまま処理すると時間超過するので、ループを探索する

N, K = map(int, input().split())
A = list(map(int, input().split()))
 
#町の数だけ-1のチェックを生成する

flag = [-1] * N

#１番目の町は必ず踏むので、０にする

flag[0] = 0

#今いる町の位置i、初期値はリスト番号0

i = 0

#移動回数の初期値

num = 0
 
while True:

#移動回数を加算する

    num += 1

#町を移動する、リスト上では-1する必要がある

    i = A[i] - 1

#-1でない場合は、一度到達しているのでループを終了する

    if flag[i] != -1:

#flag[i]には何手目で到達したかが入っているので、ループに突入するまでの処理数としてiniに登録する

        ini = flag[i]
        break

    flag[i] = num

#loopに必要な数を求める、まずはループに突入するまでの処理数iniを引く
 
loop = num - ini
 
#loopに突入するまでの処理数よりも、与えられた処理数が多いとき

if K > ini:

#loopに突入するまでにかかる数を引く

    K -= ini

#ループに入るスタート位置＋ループ後の余の位置＋１
    
    t = flag.index(ini + K % loop) + 1

    print(t)

#それ以外の時、先に-1しているので+1して補正する

else:
    t = flag.index(K) + 1
    print(t)

Measured memory_bytes: 32296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n;
    cin >> n;
    if(n%1000 == 0){
        cout << 0 <<endl;
        return 0;
    }
    int p = n/1000;
    cout << (p+1)*1000 - n << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#define MAX 251

int main(){
  int n, i;
  int array[MAX];

  scanf("%d", &n);

  for( i=1; i<=n; i++){
    scanf("%d", &array[i]);
  }

  for( i=1; i<=n; i++){
    printf("node %d: key = %d, ", i, array[i]);
    if( i/2 >= 1 )printf("parent key = %d, ", array[i/2]);
    if( 2*i <= n )printf("left key = %d, ", array[i*2]);
    if( 2*i+1 <= n )printf("right key = %d, ", array[i*2+1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

/* {{{ Variables */
int K, X;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> K >> X;
  /* }}} */

  /* {{{ Output */
  int lower = max(-1000000, X-K+1);
  int upper = min(1000000, X+K-1);

  for (int i = lower; i <= upper; ++i) {
    if (i != lower) {
      cout << " ";
    }
    cout << i;
  }
  cout << endl;
  /* }}} */

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	line := ""
	s := ""
	for i := 0; i < W+2; i++ {
		line += "#"
	}
	fmt.Println(line)
	for i := 0; i < H; i++ {
		fmt.Scan(&s)
		fmt.Printf("#%s#\n", s)
	}
	fmt.Println(line)
}


Measured memory_bytes: 512
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <utility>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<string, pair<int,int>>> sp(N);
	for (int i = 0; i < N; i++) {
		cin >> sp[i].first >> sp[i].second.first;
		sp[i].second.first *= -1;
		sp[i].second.second = i + 1;
	}
	sort(sp.begin(), sp.end());
	for (int i = 0; i < N; i++)cout << sp[i].second.second << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

from copy import deepcopy

ABMAX = 400
HUGE = 10 ** 12

def main():
    n, ma, mb = map(int, input().split())
    sold = []
    for i in range(n):
        a, b, c = map(int, input().split())
        sold.append((a, b, c))
    mincost = dp(sold, n)
    print(find_mincost(mincost, ma, mb))

def find_mincost(mincost, ma, mb):
    res = HUGE
    for mult in range(1, ABMAX):
        if ma * mult > ABMAX:
            break
        if mb * mult > ABMAX:
            break
        res = min(res, mincost[ma * mult][mb * mult])
    return -1 if res == HUGE else res

def dp(sold, n):
    # mincost[a][b]: Minimum cost of achieving a, b
    mincost = [[HUGE for b in range(ABMAX + 1)] for a in range(ABMAX + 1)]
    mincost[0][0] = 0
    for a, b, c in sold:
        mincost = update(mincost, a, b, c)
    return mincost

def update(mincost, a, b, c):
    for ia in reversed(range(ABMAX + 1)):  # 配る
        for ib in reversed(range(ABMAX + 1)):
            na = ia + a
            nb = ib + b
            if na <= ABMAX and nb <= ABMAX:
                mincost[na][nb] = min(mincost[na][nb], mincost[ia][ib] + c)
    return mincost

main()


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

int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long count = 0;
  // long long cc = c, dd = d, cd = c * d;
  long long dr = d, cr = c;
  long long r = d % c;
  while (r != 0){
    dr = cr;
    cr = r;
    r = dr % cr;
  }
  long long koubaisu = (c * d)/cr;

  count += (b / c) + (b / d);
  count -= (b / koubaisu);
  long long bcount = b - count;
  count = ((a - 1) / c) + ((a - 1) / d);
  count -= (a - 1) / koubaisu;
  long long acount = (a - 1) - count;
  cout << bcount - acount << endl;

  // long long ci = 1;
  // while (true){
  //   if (c*ci >= a){
  //     if (c*ci <= b){
  //       count += 1;
  //       ci += 1;
  //       continue;
  //     }else{
  //       break;
  //     }
  //   }else{
  //     ci += 1;
  //     continue;
  //   }
  // }
  // long long di = 1;
  // while (true){
  //   if (d*di >= a){
  //     if (d*di <= b){
  //       count += 1;
  //       di += 1;
  //       continue;
  //     }else{
  //       break;
  //     }
  //   }else{
  //     di += 1;
  //     continue;
  //   }
  // }

  // long long dr = d, cr = c;
  // long long r = d % c;
  // while (r != 0){
  //   dr = cr;
  //   cr = r;
  //   r = dr % cr;
  // }
  

  // long long koubaisu = (c * d)/cr;
  
  // long long cdi = 1;
  // while (true){
  //   if (koubaisu * cdi >= a){
  //     if (koubaisu * cdi <= b){
  //       count -= 1;
  //       cdi += 1;
  //       continue;
  //     }else{
  //       break;
  //     }
  //   }else{
  //     cdi += 1;
  //     continue;
  //   }
  // }

  // // cout << 
  // // cout << ci << endl;
  // // cout << di << endl;
  // // cout << cdi << endl;
  // // cout << count << endl;

  // cout << (b - a + 1) - count << endl;
  
  // // for (int i = a; i <= b; i++){ 
  // // }
  
}

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

using uli = unsigned long int;
using lli = long long int;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define repa(a,i,x) for(int i=a;i<=x;i++)

int main(){
	int R;
	cin >> R;
	float ans;
	
	ans = 2 * 3.14 * R;
	
	
	cout << ans << endl;
}

Measured memory_bytes: 3792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

ll factorial(ll n) {
	if (n == 0) return 1;
	return n * factorial(n-1);
}

int main() {
	ll n;
	cin >> n;
	cout << factorial(n) << endl;
	return 0;
}

Measured memory_bytes: 2972
#include<iostream>
#include<list>
#include<iterator>
using namespace std;

int erase_alt(list<int> &lis, list<int>::iterator itr)
{
	int temp = *itr;
	lis.erase(itr);
	return temp;
}

int main()
{
	while (true)
	{
		list<int> list0;
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		for (int i=n; i > 0; i--)
		{
			list0.push_back(i);
		}
		for (int i = 0; i<r; i++)
		{
			int p, c;
			list<int>::iterator itr = list0.begin();
			cin >> p >> c;
			if (p == 1)continue;
			advance(itr, p - 1);
			list0.splice(list0.begin(), list0, itr, next(itr, c));

		}
		cout << *list0.begin() << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
long double dp[302][302][302];
int n, a = 0, b = 0, c = 0;
long double solve(int i, int j, int k) {
    if(i<0 || j<0 || k<0) return 0;
    if(dp[i][j][k] != -1) return dp[i][j][k];
    dp[i][j][k] = 1 + (i+j+k > 1 ? solve(i-1, j, k)*i/(i+j+k-1.0) : 0) + (i+j+k > 0 ? solve(i+1, j-1, k)*j*1.0/(i+j+k) + solve(i, j+1, k-1)*k*1.0/(i+j+k) : 0);
    return dp[i][j][k];
}
int main() {
    int i, j, k;
    for(i=0;i<302;++i) for(j=0;j<302;++j) for(k=0;k<302;++k) dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    cin >> n;
    for(i = 0; i < n; ++i) {
        cin >> j;
        a += j==1;
        b += j==2;
        c += j==3;
    }
    printf("%0.15Lf", solve(a, b, c));
    return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt1 = 0;
    int a = 0, b = 0;
    for (int i = n; i > 0; --i) {
        int cnt = 0;
        if (i % 2 == 0) {
            a = i;
            int c = i;
            while (c % 2 == 0) {
                c/=2;
                cnt++;
            }
        }
        if (cnt1 < cnt) {
            b = a;
            cnt1 = cnt;
        }
    }
    if (b == 0) {
        b = 1;
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <sstream>
#include <stdio.h>
#include<math.h>
using namespace std;

int main(){

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

    int now=1000000;

    for(int i=1;i<N;i++){
        int zen=0;
        int kou=0;

        for(int j=1;j<=i;j++){
            zen += W[j];
        }
        for(int k=i+1;k<=N;k++){
            kou += W[k];
        }
        int temp = zen-kou;
        if(now>abs(temp)){
            now = abs(temp);
        }

    }

    cout << now;

    return 0;
}

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

int main() {
    int h, w, cnt[55][55];
    cin >> h >> w;
    char s[55][55];
    for (int i = 0; i < 52; i++) {
        for (int j = 0; j < 52; j++) {
            s[i][j] = 0;
            cnt[i][j] = 0;
        }
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> s[i][j];
        }
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (s[i][j] == '.') {
                if (s[i - 1][j - 1] == '#') cnt[i][j]++;
                if (s[i - 1][j] == '#') cnt[i][j]++;
                if (s[i - 1][j + 1] == '#') cnt[i][j]++;
                if (s[i][j - 1] == '#') cnt[i][j]++;
                if (s[i][j] == '#') cnt[i][j]++;
                if (s[i][j + 1] == '#') cnt[i][j]++;
                if (s[i + 1][j - 1] == '#') cnt[i][j]++;
                if (s[i + 1][j] == '#') cnt[i][j]++;
                if (s[i + 1][j + 1] == '#') cnt[i][j]++;
                s[i][j] = 0;
            }
        }
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (s[i][j] != 0) cout << s[i][j];
            else cout << cnt[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys

h, w = list(map(int, input().split()))
field = [line.rstrip() for line in sys.stdin]

l = [[0] * (w + 2) for _ in [0] * (h + 2)]
r = [[0] * (w + 2) for _ in [0] * (h + 2)]
u = [[0] * (w + 2) for _ in [0] * (h + 2)]
d = [[0] * (w + 2) for _ in [0] * (h + 2)]

for i in range(1, h + 1):
    fi = field[i - 1]
    li = l[i]
    for j in range(1, w + 1):
        c = fi[j - 1]
        u[i][j] = u[i - 1][j] + 1 if c == '.' else 0
        li[j] = li[j - 1] + 1 if c == '.' else 0
for i in range(h, 0, -1):
    fi = field[i - 1]
    ri = r[i]
    for j in range(w, 0, -1):
        c = fi[j - 1]
        d[i][j] = d[i + 1][j] + 1 if c == '.' else 0
        ri[j] = ri[j + 1] + 1 if c == '.' else 0

ans = 0
for i in range(1, h + 1):
    li, ri, ui, di = l[i], r[i], u[i], d[i]
    ans = max(ans, max(li[j] + ri[j] + ui[j] + di[j] for j in range(1, w + 1)))
print(ans - 3)


Measured memory_bytes: 179080
H,W=gets.split.map(&:to_i)
ss = H.times.map { gets.chomp }

v = Array.new(H) { Array.new(W, 0)}
h = Array.new(H) { Array.new(W, 0)}

H.times do |i|
    l = 0
    s = ss[i]
    loop do
        pos = s.index('#', l)
        r = pos || W
        n = r-l
        l.upto(r-1) do |k|
            v[i][k] = n
        end
        break unless pos
        l = pos + 1
    end
end

W.times do |i|
    l = 0
    H.times do |j|
        if ss[j][i] == '#'
            n = j-l
            l.upto(j-1) do |k|
                h[k][i] = n
            end
            l = j+1
        end
    end
    if l != H
        n = H-l
        l.upto(H-1) do |k|
            h[k][i] = n
        end
    end
end

max = 0
H.times do |i|
    W.times do |j|
        n = v[i][j] + h[i][j] - 1
        max = n if max < n
    end
end

# p v
# p h
puts max

Measured memory_bytes: 85096
n = int(input())
a = [0]+list(map(int, input().split()))
for i in range(1,n+1):
    b = []
    b.append(f'node {i}: key = {a[i]}, ')
    if i != 1:
        b.append(f'parent key = {a[i//2]}, ')
    if 2*i <= n:
        b.append(f'left key = {a[i*2]}, ')
        if 2*i+1 <= n:
            b.append(f'right key = {a[i*2+1]}, ')
    print(''.join(b))
    
    
    
    
    


Measured memory_bytes: 5628
#include <cstdio>

#define maxn 1010
int s[maxn][maxn];
int main()
{
	int h, w, a, b; scanf("%d%d%d%d", &h, &w, &a, &b);
	for (int i = 1; i <= b; ++i)
		for (int j = 1; j <= a; ++j)
			s[i][j] = 1;
	for (int i = b + 1; i <= h; ++i)
		for (int j = a + 1; j <= w; ++j)
			s[i][j] = 1;
	for (int i = 1; i <= h; ++i, puts(""))
		for (int j = 1; j <= w; ++j)
			printf("%d", s[i][j] );
	return 0;
}

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


int N;
int x[10];
int y[10];

double dist(int i, int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx + dy*dy,0.5);
}

void solve(void)
{
    cin >> N;
    for(int i=1; i<=N;i++){
        cin >> x[i] >> y[i];
    }
    double sum = 0.0;
    vector<int> v(N);
    iota(v.begin(), v.end(),1);
    do
    {
        for(int i=0;i<N-1;i++) sum+=dist(v[i],v[i+1]);
    } while (next_permutation(v.begin(), v.end()));
    int factorial = 1;
    for (int i=1; i<=N; i++) factorial *= i;
    cout << fixed << setprecision(10)  << sum/factorial << endl;
    return ;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define sz(x) (int)(x.size())

signed main() {
    int n;
    cin >> n;
    n *= 2;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; i += 2) {
        ans += a[i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        String s = scan.next();

        int[] sum = new int[n];
        sum[0] = (s.charAt(0) == 'W') ? 0 : 1;
        for(int i = 1; i < n; i++) {
            sum[i] = (s.charAt(i) == 'W') ? 0 : 1;
            sum[i] += sum[i-1];
        }

        int min = sum[n-1]-sum[0];
        int turn1, turn2;
        for(int i = 1; i < n; i++) {
            turn1 = i-sum[i-1];
            turn2 = sum[n-1]-sum[i];
            min = (turn1+turn2 < min) ? turn1+turn2 : min;
        }

        System.out.println(min);
    }
}

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

int main(){
  string s;
  cin >> s;
  bool flag=(s[0]=='A');
  if(s[1]<'a')flag=false;
  int c=0;
  for(int i=2; i<s.length()-1; i++){
    if(s[i]=='C')c++;
    else if(s[i]<'a')flag=false;
  }
  if(c!=1)flag=false;
  if(s[s.length()-1]<'a')flag=false;
  if(flag)cout << "AC";
  else cout << "WA";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//
//using namespace __gnu_pbds;
using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

//#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)
/*
tree<
       int,
     null_type,
     less<int>,
     rb_tree_tag,
     tree_order_statistics_node_update>t;
*/

int main()
{
  int k;
  cin>>k;
  ll ans=0;
  for(int i=1; i<=k; i++){
    for(int j=1; j<=k; j++){
        for(int l=1; l<=k; l++){
           int gg=gcd(j,l);
           int g=gcd(gg, i);
           ans+=(ll)g;
        }
    }
  }
  cout<<ans<<endl;
    return 0;
}
/*
1
21 7
wudixiaoxingxingheclp
*/


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

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

int main() {
	string C;
	cin >> C;

	string abc = "abcdefghijklmnopqrstuvwxyz";
	int index = abc.find(C);
	cout << abc[index + 1];
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const ll MOD = 1e9 + 7;

ll dp[310][310];
ll dp2[310][310];

void add(ll &a, ll b) {
	a += b;
	a %= MOD;
}
int n, m;

int main() {
	cin >> n >> m;
	dp[1][1] = 1;
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <= j; ++k)
				dp2[j][k] = 0;
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <= j; ++k) {
				add(dp2[j + 1][k], dp[j][k] * (n - j));
				add(dp2[j][j], dp[j][k] * k);
				add(dp2[j][k], dp[j][k] * (j - k));
			}
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <= j; ++k)
				dp[j][k] = dp2[j][k];
	}
	cout << dp[n][n] << "\n";
	return 0;
}




Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int ans = 0;
	rep(i,0,SZ(s)) if(s[i] == '1') ans++;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256