akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    S = input()
    center = len(S) // 2

    if len(S) % 2 == 0:
        c = 1
        while True:
            if (center - 1 + c) < len(S) and S[center - c] == S[center - 1 + c] and S[center - c] == S[center]:
                # if S[center - c] == S[center]:
                # print(c, center - c, center - 1 + c, S[center - c], S[center])
                c += 1
            else:
                # print(c, S[center - c], S[center - 1 + c])
                # c -= 1
                break
        print(c + center - 1)
    else:
        c = 0
        while True:
            if (center + c) < len(S) and S[center - c] == S[center + c] and S[center] == S[center - c]:
                c += 1
            else:
                break
        print(c + center)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65192
//
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int tt;
  tt = 1;
  while (tt--)
  {
    string s;
    cin >> s;
    int i, count = 0;
    vector<int> v;
    for (i = 0; i < s.length(); i++)
    {
      if (s[i] == 'R')
      {
        count = 0;
        while (s[i] == 'R')
        {
          count++;
          i++;
        }
        i--;
        v.push_back(count);
      }
    }
    sort(v.begin(), v.end());
    if (v.size() == 0)
    {
      cout << "0" << endl;
    }
    else
    {
      cout << v[v.size() - 1] << " " << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
int main(void){
  int r0,w,c,r,i;
  while(1){
    scanf("%d %d %d %d",&r0,&w,&c,&r);
    if(r0+w+c+r==0)
      break;
    for(i=0;;i++){
      if((r0+i*r)>=(c*w))
	break;
    }
    printf("%d\n",i);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n;
  vector<i64> h;
  cin >> n;
  read_n(h, n);
  i64 a = h[0], ans = 1;
  for (i64 i = 1; i < n; ++i) {
    if (h[i] >= a) {
      ++ans;
      a = h[i];
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std ;
 
 
int main()
{
	int H1, M1, H2, M2, K,tmp,tmp2,tmp3;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
  if(M2>=M1){
    tmp = H2-H1;
    tmp2=M2-M1;
  }else{
    tmp = H2-H1-1;
    tmp2=M2-M1+60;
  }
	tmp3=tmp*60+tmp2;
  if(tmp3>=K){
  	cout << tmp3-K << "\n";
  }else{
    cout << 0 << "\n";
  }
  return 0;
}

Measured memory_bytes: 3628
/**
* ============================
* stay hungry stay foolish
* @Author:pubgoso
* @DateTime: 2019-04-06 19:38:04
* ============================
*/
#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int n,a[N],k;
int main(){
	ios::sync_with_stdio(false);
	for(int i=1;i<=5;i++)cin>>a[i];
	int now=0;
	int ans=2e9;
	for(int i=1;i<=5;i++){
		now=0;
		for(int j=1;j<=5;j++){
			if(j==i)continue;
			now+=a[j];
			while(now%10)now++;
		}
		now+=a[i];
		ans=min(ans,now);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/**
 * Created by hiroqn on 13/10/08.
 */
var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
function main() {
  var temp = input[0].split(' '),
      n = +temp[0],
      t = +temp[1],
      arr = input[1].split('+').map(function (str) {
        return +str[2];
      }),
      max = Math.max.apply(null, arr),
      ans;
  if (max * Math.log(n) * Math.LOG10E > 9 - Math.log(t) * Math.LOG10E) {
    console.log('TLE');
    return;
  }
  ans = arr.reduce(function (p, c) {
    return p + Math.pow(n, c);
  }, 0);
  if (ans > 1e+9 / t) {
    console.log('TLE');
  } else {
    console.log(ans * t);
  }
}

Measured memory_bytes: 7652
#include <iostream>

using namespace std;

int main() {
	int n;
	int *S;
	int q;
	int *T;
	cin >> n;
	S = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> S[i];
	}

	cin >> q;
	T = new int[q];
	for (int i = 0; i < q; ++i) {
		cin >> T[i];
	}

	int count = 0;
	for (int i = 0; i < q; ++i) {
		for (int j = 0; j < n; ++j) {
			if (S[j] == T[i]) {
				++count;
				break;
			}
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    bool ans = a.back() == b[0] && b.back() == c[0];
    cout << (ans? "YES" : "NO") << endl;
}

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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define endl "\n"
vector< vector<pair<int, int>> > g(100006);
int node = 0;
int ans = -1;

void getnode(int u, int par, int dis) {
	int flg = 0;
	for (int i=0; i<g[u].size(); i++) {
		if (g[u][i].first != par) {
			getnode(g[u][i].first, u, g[u][i].second+dis);
			flg = 1;
		}
	}
	if (flg == 0) {
		if (dis > ans) {
			ans = dis;
			node = u;
		}
	}
}


void testCase() {
	int n;
	cin >> n;
	for (int i=1; i<n; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		g[u].push_back(make_pair(v, w));
		g[v].push_back(make_pair(u, w));
	}
	getnode(0, -1, 0);
	//cout << node << endl;
	ans = -1;
	getnode(node, -1, 0);
	cout << ans << endl;
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	testCase();
	return 0;
}


Measured memory_bytes: 12936
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());

		int count = 0;
		for(int i=1; i<=N; i++) {
			if(i % 2 == 0)continue;
			int a=0;
			for(int j=1;j<=i; j++) {
				if(i%j == 0) a++;
			}
			if(a==8)count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <math.h>

int main()
{
    int n,s[1000],i,sum=0;
    double m,a=0;
    
    while(1){
    scanf("%d",&n);
    if( n == 0 ){
    break;
    }
    
    for( i = 0; i < n; i++){
      scanf("%d",&s[i]);
      sum += s[i];
    }
    m=(double)sum/n;
    for( i = 0; i < n; i++){
      a += ((s[i]-m)*(s[i]-m));
    }
    printf("%f\n",sqrt((double)a/n));
    sum=0; a=0;
  }
  return 0;
}


Measured memory_bytes: 2112
fun main(args: Array<String>) {
    val n = readInt()
    val s = List(n) { readString() }

    val m = s.filter { it[0] == 'M' }.size.toLong()
    val a = s.filter { it[0] == 'A' }.size.toLong()
    val r = s.filter { it[0] == 'R' }.size.toLong()
    val c = s.filter { it[0] == 'C' }.size.toLong()
    val h = s.filter { it[0] == 'H' }.size.toLong()

    val ans =
        m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h
    println(ans)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()

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

int main(){
    int n;
    cin >> n;
    string s;
    int p;
    vector<tuple<string,int,int>> book(n);
    for (int i = 0;i < n;i++){
        cin >> s >> p;
        book.at(i) = make_tuple(s,-p,i+1);
    }
    sort(book.begin(),book.end());

    for (int i = 0;i < n;i++){
        cout << get<2>(book.at(i)) << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
const int maxn = 1e5 + 10;
using namespace std;

int main()
{
    char a[maxn];
    char b[27];
    for (int i = 0; i < 26; i++)
        b[i] = 'a' + i;
    cin >> a;
    int ok = 1, h = 0;
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < strlen(a); j++) {
            if (a[j] == b[i]) {
                ok = 0;
                break;
            }
        }
            if (!ok)
                ok = 1;
            else {
                    cout << b[i] << endl;
                    h = 1;
                    break;
                }
    }
    if (!h)
        cout << "None" << endl;
    return 0;
}


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

int main(){
  unsigned long long n;
  cin>>n;
  string s;
  while(n){
     n--;
     s+='a'+(n%26);
     n/=26;
  }
  reverse(s.begin(),s.end());
  cout<<s<<endl;
}  


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 110;
int vis[maxn];
void run_case()
{
    int x, n;
    cin >> x >> n;
    for (int i = 1; i <= n; i++)
    {
        int cur;
        cin >> cur;
        vis[cur] = 1;
    }
    // if (n == 0)
    // {
    //     cout << x << "\n";
    //     return;
    // }
    int ans = INF;
    int res = INF;
    for (int i = x; i <= maxn; i++)
    {
        if (abs(i - x) < res && (!vis[i]))
        {
            res = abs(i - x);
            ans = i;
        }
    }
    for (int i = x - 1; i >= 0; i--)
    {
        if (abs(i - x) <= res && (!vis[i]))
        {
            res = abs(i - x);
            ans = i;
        }
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const long size=1e5 +1;
long dist[size];
bool visited[size];
int indeg[size];
vector<long>edges[size];

void dfs(long a)
{
    if(!visited[a])
    visited[a]=1;
    
    for(long i:edges[a])
    {
        dist[i]=max(dist[i],dist[a]+1);
        --indeg[i];
        if(indeg[i]==0)
        dfs(i);
    }
    
}

int main() {
	// your code goes here
	
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long n,m;
	cin>>n>>m;
	long i,j;
	long a,b;
	for(i=0;i<m;i++)
	{
	    cin>>a>>b;
	    edges[a].push_back(b);
	    indeg[b]++;
	    
	}
	
	for(int i=1;i<=n;i++)
	{
	    if(!visited[i]&&indeg[i]==0)
	    dfs(i);
	}
	
	long ans=0;
	for(i=1;i<=n;i++)
	{
	    ans=max(ans,dist[i]);
	}
	
	cout<<ans;
	return 0;
}


Measured memory_bytes: 10112
def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


INF = 10 ** 16
n, m, l = map(int, input().split())
mat = [[INF] * n for _ in range(n)]
for i in range(n):
    mat[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    mat[a - 1][b - 1] = c
    mat[b - 1][a - 1] = c
mat = warshall_floyd(n, mat)
fuel_mat = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1
fuel_mat = warshall_floyd(n, fuel_mat)
q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    d = fuel_mat[s - 1][t - 1]
    if d == INF:
        print(-1)
    else:
        print(d - 1)


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const int INF = 1001001001;

int n,m;
string s;
//Write From this Line

const int mod = 1e9+7;
int main()
{
	cout << setprecision(10);
	cin >> n >> m ;
	vector<pair<int,int>> key;
	rep(i,m){
		int a , b ;
		cin >> a >> b ;
		int s = 0 ;
		rep(j,b){
			int c ;
			cin >> c;
			c-- ;
			s |= 1<<c;//c=3 なら0001になる
		}
		key.emplace_back(s,a);
	}

	vector<int> dp(1<<n, INF); //2^n 箱の数の2乗のテーブルが必要

	dp[0] = 0 ;
	rep(s,1<<n){
		rep(i,m){
			int t = s | key[i].first;
			int cost = dp[s] + key[i].second;
			dp[t] = min(dp[t],cost);
		}	
	}
	int ans = dp.back();
	if (ans == INF) ans = -1 ;
	cout << ans << endl;

}


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

int main() {
  int x, t;
  cin >> x >> t;
  int ans = 0;
  if(t>= x) ans = 0;
  
  else ans = x-t;
  cout << ans << endl;
}

Measured memory_bytes: 3576
import math
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

m=10**9 + 7 
sys.setrecursionlimit(1000010)
(A,B) = list(map(int,input().split()))
# print(A,B)
print( lcm(A,B))

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

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

    int out;
    if(S == "SUN") {
        out = 7;
    } else if(S == "MON") {
        out = 6;
    } else if(S == "TUE") {
        out = 5;
    } else if(S == "WED") {
        out = 4;
    } else if(S == "THU") {
        out = 3;
    } else if(S == "FRI") {
        out = 2;
    } else if(S == "SAT") {
        out = 1;
    }

    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <ll, pair <ll, ll>>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 5e2 + 10;

ll n, m, k, t;

bool lft[maxn][maxn];

vector <pll> go = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

vector <ll> A;

inline bool in(ll x, ll y) {
    return x >= 0 && y >= 0 && x < n && y < n;
}
 
inline pll get_coord(ll c) {
    ll x = c / n, y = c % n;
    return mp(x, y);
}
 
inline ll geti(ll x, ll y) {
    return x * n + y;
}

ll ANS[maxn][maxn];

void dfs(ll x, ll y) {
    for (auto p : go) {
        ll nx = x + p.first, ny = y + p.second;
        if (!in(nx, ny)) {
            continue;
        }
        ll dans = ANS[x][y];
        if (!lft[x][y]) {
            dans++;
        }
        if (dans < ANS[nx][ny]) {
            ANS[nx][ny] = dans;
            dfs(nx, ny);
        }
    }
}

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    cin >> n;
    A.resize(n * n);
    for (q = 0; q < n * n; q++) {
        cin >> A[q];
        A[q]--;
    }
    for (q = 0; q < n; q++) {
        for (w = 0; w < n; w++) {
            ANS[q][w] = min({q, n - q - 1, w, n - w - 1});
        }
    }
    ll ans = 0;
    for (q = 0; q < n * n; q++) {
        pll p = get_coord(A[q]);
        ans += ANS[p.first][p.second];
        lft[p.first][p.second] = 1;
        dfs(p.first, p.second);
    }
    cout << ans;
    return 0;
}


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

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(const char* s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int64 s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    cout << "(";
    print(p.first, false);
    cout << ", ";
    print(p.second, false);
    cout << ")";

    if (endline) print();
}

template <typename T>
void print(T& t, bool endline = true) {
    cout << "[";
    for (auto it = t.begin(); it != t.end(); ++it) {
        if (it != t.begin()) cout << ", ";
        print(*it, false);
    }
    cout << "]";

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

bool c(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.first + a.second > b.first + b.second); 
} 

int64 get_h(int x, int y, int h, int cx, int cy) {
    int64 ret = 0LL + h + abs(x - cx) + abs(y - cy);

    return ret;
}

int64 calc_h(int x, int y, int h, int cx, int cy) {
    int64 ret = max(0, h - abs(x - cx) - abs(y - cy));

    return ret;
}

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
    int n;

    cin >> n;

    vector<vector<int>> v(n, vector<int> (3, 0));

    for(int i = 0; i < n; ++i) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }

    int64 prev = -1;
    bool valid = true;

    for(int i = 0; i <= 100; ++i) {
        for(int j = 0; j <= 100; ++j) {
            valid = true;
            prev = -1;
            for(auto& a : v) {
                if(a[2] != 0) {
                    prev = get_h(a[0], a[1], a[2], i, j);
                    break;
                }
            }

            for(auto& a : v) {
                int64 h = calc_h(a[0], a[1], prev, i, j);
                // cout << i << " " << j << " " << h << endl;
                if (a[2] != h) {
                    valid = false;
                    break;
                }
            }

            if(valid) {
                cout << i << " " << j << " " << prev << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

int main(){
    string str;
    while (1) {
        cin >> str;
        if (str == "0") {
            break;
        }
        int l = str.length();
        int result = 0;
        for (int i = 0; i < l; i++){
            result += str[i] - '0';
            
        }
        cout << result << endl;
    }
}


Measured memory_bytes: 3208
/*
[agc030] B - Tree Burning
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 2e5;

ll L;
int N;
ll X[MAX_N];
ll s[MAX_N + 1];

ll solve() {
    ll ans = 0;
    for (int k = 0; k < 2; k++) {
        s[0] = 0;
        for (int i = 0; i < N; i++) {
            s[i + 1] = s[i] + X[i];
        }

        for (int i = 0; i < N; i++) {
            int t = (N + i - 1) / 2 + 1;
            ll c = (s[t] - s[i] + L * (N - t) - s[N] + s[t]) * 2 -
                   (((N - i) % 2 == 0) ? (L - X[t]) : X[t - 1]);
            ans = max(ans, c);
        }

        for (int i = 0; i < N; i++) {
            X[i] = L - X[i];
        }
        reverse(X, X + N);
    }
    return ans;
}

int main() {
    cin >> L >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, b, a) for(int i = (b); i >= (a); i--)
using namespace std;
const int N = 1e5 + 9, inf = 0x3f3f3f3f;
int n, minn = inf, maxx, sum, a[N];
int main(){
    scanf("%d", &n);
    rep(i, 1, n) {
        scanf("%d", &a[i]);
        minn = min(minn, a[i]), maxx = max(maxx, a[i]);
    }
    rep(i, 1, n) if(a[i] != minn && a[i] != maxx) {
        printf("No\n");
        return 0;
    }
    if(minn == n - 1 && maxx == n - 1){
        printf("Yes\n");
        return 0;
    }
    if(minn == maxx){
        if(minn <= n / 2) printf("Yes\n");
        else printf("No\n");
        return 0;
    }
    rep(i, 1, n) if(a[i] == minn) sum++;
    //cout << maxx << " " << minn << " " << sum << endl;
    if(maxx != minn + 1 || maxx <= sum || maxx > (n - sum) / 2 + sum) printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 640
def fn(n)
  res = 1
  n.step(1, -2) do |i|
    break if n < 2
    res *= i
  end
  res
end

def count_r(n)
  rev = n.to_s.reverse
  res = 0
  rev.chars.each { |i| break if i != '0'; res += 1 }
  res
end

n = gets.to_i
if n.odd?
  puts "0"
  exit
end

# prepared_res = count_r(fn(n))
res = 0
res += n / 10
n /= 10
while n >= 5
  res += n / 5
  n /= 5
end
# res += n / 250
puts res
# puts prepared_res
# puts count_r  fn(10)
# puts count_r  fn(20)
# puts count_r  fn(30)
# puts count_r  fn(40)
# puts count_r  fn(50)
# puts count_r  fn(80)
# puts count_r  fn(96)
# puts count_r  fn(100)
# puts count_r  fn(110)
# puts count_r  fn(140)
# puts count_r  fn(150)


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	double r;
	double x,y;
	
	scanf("%lf",&r);
	x=r*r*3.141592653589;
	y=2*r*3.141592653589;
	printf("%f %f\n",x,y);
return 0;
}

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] spl = s.split(" ");
	double a = Double.parseDouble(spl[0]);
	double b = Double.parseDouble(spl[1]);
	double x = (a + b) / 2;
    System.out.println((int)Math.ceil(x));
    sc.close();
  }
}

Measured memory_bytes: 21844
n = int(input())
a=[int(x) for x in input().split()]
i=0
cnt=0
x=1
hozon=0
while i<n:
	if a[i]==x:
		x+=1
	else:
		cnt+=1
	i+=1
	
if x == 1:
	cnt = -1
print(int(cnt))

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);

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

    long long ans = 0;
    for (int i=0; i<N/2; i++) {
        // 手前
        ans += A.at(i) / 2;
        A.at(i) %= 2;
        int k = min(A.at(i), A.at(i+1));
        A.at(i) -= k;
        A.at(i+1) -= k;
        ans += k;

        // 後ろ
        ans += A.at(N-1-i) / 2;
        A.at(N-1-i) %= 2;
        k = min(A.at(N-1-i), A.at(N-2-i));
        A.at(N-1-i) -= k;
        A.at(N-2-i) -= k;
        ans += k;
    }

    if (N % 2) {
        ans += A.at(N/2) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <unordered_map>

class Base{
  private:
  	std::unordered_map<char, char> t;
  
  public:
  	Base () {
      t['A'] = 'T';
      t['T'] = 'A';
      t['G'] = 'C';
      t['C'] = 'G';
    }
  
  	void Sol ( char b ) {
      std::cout << t[b] << std::endl;
    }
};

int main (void){
  char b; std::cin >> b;
  Base b_; b_.Sol(b);
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<tuple>
#include<algorithm>

using namespace std;

#define REP(i, n) for(int i=0;i<(int)n;i++)
#define REPS(i, n) for(int i=1;i<=(int)n;i++)
#define RREP(i, n) for(int i=n-1;i>=0;i--)
#define RREPS(i, n) for(int i=n;i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
#define endl '\n'
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

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;
}
enum DIR { LEFT, RIGHT, FRONT, BACK, BOTTOM, TOP };
int rotm[4][6]={
	{5,4,2,3,0,1},
	{0,1,5,4,2,3},
	{0,1,4,5,3,2},
	{4,5,2,3,1,0}
};

struct Dice{
	vi d, x;
	Dice(vi d):d(d), x(6){
		
	}
	
	inline int &operator[](int i){
		return d[i];
	}
	
	inline void rot(int k){
		REP(i, 6) x[rotm[k][i]] = d[i];
		d = x;
	}
	
	
	inline int check(){
		if(d[BOTTOM] == -1) return 0;
		if(d[BOTTOM] + d[TOP] > d[LEFT] + d[RIGHT] + d[FRONT] + d[BACK]) return 0;
		if(d[LEFT] + d[RIGHT] > d[BOTTOM] + d[TOP] + d[FRONT] + d[BACK]+1) return 0;
		if(d[FRONT] + d[BACK] > d[BOTTOM] + d[TOP] + d[LEFT] + d[RIGHT]+1) return 0;
		return 1;
	}
	
};
int n;
string db = "ENSW";
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	while(1){
		vi t(6);
		REP(i, 6) cin >> t[i];
		sort(ALL(t));
		if(t[5] == 0) break;
		int n = accumulate(ALL(t), 0);
		string ans(n, 'Z');
		do{
			Dice dice(t);
			string tmp;
			int f = 0;
			REP(itr, n){
				if(tmp.size() != itr) break;
				REP(i, 4){
					dice.rot(i);
					dice[BOTTOM] --;
					if(dice.check()){
						tmp.pb(db[i]);
						break;
					}
					dice[BOTTOM] ++;
					dice.rot(3-i);
				}
				if(!f && ans[itr] < tmp[itr]) continue;
				f |= ans[itr] > tmp[itr];
			}
			if(tmp.size() == n) ans = min(ans, tmp);
		}while(next_permutation(ALL(t)));
		int p, q;
		cin >> p >> q; p--;
		if(ans[0] == 'Z') cout << "impossible" << endl;
		else cout << ans.substr(p, q-p) << endl;
	}
}

Measured memory_bytes: 1352
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    bool f = true;
    int sum = 0;
    int MIN = INF;
    rep(i, 0, n){
        cin >> a[i] >> b[i];
        sum += a[i];
        if(a[i] > b[i]) chmin(MIN, b[i]);
        if(a[i] != b[i]) f = false;
    }
    if(f){
        cout << 0 << endl;
        return 0;
    }
    sum -= (MIN == INF ? 0 : MIN);
    cout << sum << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, a, t;
bool ok = true;

int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", &a);
		if(a != i+1) t++;
	}
	puts(t < 3 ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>

using namespace std;

int main(){
        double x;
        string s;
        cin >> s;
        x = atof(s.c_str());
        x = pow(x,3);
        cout << fixed  << setprecision(0)  << x << endl;

        return 0;
}


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

typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define __m int mid=(l+r)>>1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

template<class T>
inline bool rd(T &num) {
    char in;bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}
template<class T, class S>
inline bool rd(T &num1, S &num2){return rd(num1)&&rd(num2);}
template<class T, class S, class Z>
inline bool rd(T &num1, S &num2, Z &num3){return rd(num1)&&rd(num2)&&rd(num3);}
template<class T>
inline void _wr(T num){if(num>9)_wr(num/10);putchar('0'+num%10);}
template<class T>
inline void wr(T num){if(num < 0)putchar('-'),num=-num;_wr(num);}

void debug_out(){cerr<<endl;}
string to_string(string s){return '\"'+s+'\"';}
string to_string(char* s){return to_string((string)s);}
string to_string(bool s){return s?"true":"false";}
template<class T>
string to_string(T array);
template<class T,class S>
string to_string(pair<T,S>s){return '('+to_string(s.first)+','+to_string(s.second)+')';}
template<class T>
string to_string(T array){
    bool first=true;string res="[";
    for(const auto&e : array){
        if(!first)res+=",";first=false;res+=to_string(e);
    }
    return res+=']';
}
template<class Head, class... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}

string nico = "NicoNicoNi";
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#define io ios::sync_with_stdio(0)
#else
#define debug(...)
#define infile(x)
#define outfile(x)
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#endif

#define rep(a,b,c) for(register int (a)=(b);(a)<(c);++(a))
#define per(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
#define none(a) memset(a,-1,sizeof(a))
#define clr(a) memset(a,0,sizeof(a))
#define inf(a) memset(a,0x3f,sizeof(a))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define space putchar(' ')
#define enter puts("")
#define endl '\n'
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define lowbit(x) (x&-x)

const int maxn = 2e5+7;
const int inf  = 0x3f3f3f3f;
const ll  linf  = (1ll*inf)<<32|inf;
const int mod  = 1e9 + 7;
const int none = -1;
const double eps = 1e-7;

vector<int> num;
int main(){
    io;
    rep(i,0,5){
        int k;
        cin>>k;
        num.pb(k);
    }
    sort(num.begin(), num.end(), [](int a,int b){
            int ax = a%10,bx=b%10;
            if(ax==0)ax=10;
            if(bx==0)bx=10;
            return ax<bx;
    });
    debug(num);
    int ans = 0;
    per(i,4,1){
        if(ans%10)ans+=10-ans%10;
        ans+=num[i];
    }
    if(ans%10)
        ans+=10-ans%10;
    ans+=num[0];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

matrix = [list('#' * (w + 2))]
count_sharp = 0
for _ in range(h):
    C = list(input())
    count_sharp += C.count('#')
    matrix.append(['#'] + C + ['#'])
matrix.append(list('#') * (w + 2))

B = [[] for _ in range(10000)]


for i in range(h+2):
    for j in range(w+2):
        if matrix[i][j] == '.':
            if matrix[i-1][j] == '.':
                B[100*i+j].append(100*(i-1) + j)
            if matrix[i][j-1] == '.':
                B[100*i+j].append(100*i + j - 1)
            if matrix[i][j+1] == '.':
                B[100*i+j].append(100*i + j + 1)
            if matrix[i+1][j] == '.':
                B[100*i+j].append(100*(i+1) + j)

# print(matrix)
def solver(matrix, h, w, count_):
    path = [10000000] * 10000
    depth = 0
    path[101] = 0
    reached = [101]
    stack = []
    stack.append(101)
    while len(stack) > 0:
        depth += 1
        for _ in range(len(stack)):
            val = stack.pop(0)
            for j in matrix[val]:
                if j not in set(reached):
                    path[j] = min(depth, path[j])
                    reached.append(j)
                    stack.append(j)

    if path[h*100 + w] == 10000000:
        print(-1)
    else:
        print(h * w - path[h*100+w] - 1 - count_)
solver(B, h, w, count_sharp)


Measured memory_bytes: 10296
n, k = map(int, input().split())
s = input()
arr = []

if(s[0] == '0'):
  arr.append(0)
for i in range(n-1):
  if(s[i] != s[i+1]):
    arr.append(i+1)
arr.append(n)
if(s[-1] == '0'):
  arr.append(n)
    
width = 2*k + 1
len_arr = len(arr)

if(2*k >= len_arr):
  ans = arr[-1]
else:
  ans = arr[2*k]
  left = 2
  while True:
    if(left + width > len_arr):
      break
    tmp = arr[left + width - 1] - arr[left - 1]
    ans = max(ans, tmp)
    left += 2
print(ans)




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

int main() {
    int N;
    string S;
    cin >> N;
    int count = 0;
    rep(i, N) {
         cin >> S;
         if (S == "Y") {
             cout << "Four" << endl;
             break;
         }
         else
         {
             count += 1;
         }
         if (count == N)
         {
             cout << "Three" << endl;
         }
        }
    return 0;
}

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

class _Class
{
	void _()
	{
		var _N = _Ns();
		var _s = _Ss()[0];
		var _t = _Ss()[0];

		for (int a = 0; a < _N[0]; a++)
		{
			int i = 0;
			for (;i<_N[0]-a;i++){
				if (_s[i+a]!=_t[i])
					break;
			}
			if (i==_N[0]-a) {
				Console.WriteLine(_N[0]+a);
				return;
			}
		}	
		
		Console.WriteLine(_N[0]*2);

	}

	static void Main(string[] args)
  {
    new _Class()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}



Measured memory_bytes: 2648
#include<stdio.h>
int main()
{
  int n, i, j, ans=0;
  scanf("%d", &n);
  int a[n+1];
  for(i=1; i<=n; i++)
  {
    scanf("%d", a+i);
    for(j=1; a[i]%2==0; j++) a[i]/=2;
    ans+=j-1;
  }
  printf("%d", ans);
  return 0;
}

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

int main(){

    int n,m;

    cin >> n >> m;

    vector<int> d(m+1,0);
    int k;
    rep(i,n){
        cin >> k;
        rep(j,k){
            int t;
            cin >> t;
            d[t]++;
        }
    }
    int ans=0;
    rep(i,m+1){
        if(d[i]==n) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	bool exists = e - a > k;
	cout << (exists ? ":(" : "Yay!") << endl;


	return 0;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())
ans = [0]*(n-1)
for i in range(1, n):
  for j in range(i+1, n+1):
    d = min(j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
    ans[d-1] += 1

for i in range(len(ans)):
  print(ans[i])


Measured memory_bytes: 9284
using System;
using System.Linq;

class B
{
    static void Main(string[] args)
    {
        var N = Input.Int();

        var rests = new Rest[N];
        string[] input;
        for (int i = 0; i < N; i++)
        {
            input = Input.StrArray();
            rests[i] = new Rest()
            {
                name = input[0],
                point = int.Parse(input[1]),
                index = i,
            };
        }

        Array.Sort(rests);
        for (int i = 0; i < rests.Length; i++)
        {
            rests[i].rank = i + 1;
        }

        Array.Sort(rests);

        for (int i = 0; i < rests.Length; i++)
        {
            Console.WriteLine(rests[i].rank);
        }


    }

    internal class Rest : IComparable
    {
        public string name;
        public int point;
        public int rank = 0;
        public int index;

        public int CompareTo(object obj)
        {
            if (obj == null) throw new ArgumentNullException();

            Rest other = obj as Rest;

            if (other == null) throw new ArgumentException();
            if (this.rank > 0)
            {
                int res = this.name.CompareTo(other.name);
                if (res != 0) return res;

                res = this.point.CompareTo(other.point);
                if (res != 0) return res * -1;

                return 0;
            }

            return this.index.CompareTo(other.index);
        }
    }

    /** Input Class */
    internal static class Input
    {
        /** input int */
        public static int Int() => int.Parse(Console.ReadLine());

        /** input str */
        public static string Str() => Console.ReadLine();

        /** input array of int */
        public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        /** input array of string */
        public static string[] StrArray() => Input.Str().Split(' ');

        /** input array of char */
        public static char[] charArray() => Input.Str().ToCharArray();
    }

}

Measured memory_bytes: 13408
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)
        E[v].append(u)

    q=int(input())
    VDC=[None]*q
    for i in range(q):
        v,d,c=map(int,input().split())
        v-=1
        VDC[i]=(v,d,c)
    VDC.reverse()

    dp=[[0]*11 for _ in range(n)]
    ans=[0]*n

    for v,d,c in VDC:
        Q=deque([(v,d)])
        dp[v][d]=1
        while(Q):
            v,d=Q.popleft()
            if(d>0):
                if(not dp[v][d-1]):
                    dp[v][d-1]=1
                    Q.append((v,d-1))
                for nv in E[v]:
                    if(dp[nv][d-1]): continue
                    dp[nv][d-1]=1
                    Q.append((nv,d-1))
            if(ans[v]==0):
                ans[v]=c

    print(*ans,sep='\n')
resolve()

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

using namespace std;

#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define REV(i,n) for(int (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

char mp[2222][2222];
int le[2222][2222];
int ri[2222][2222];
int up[2222][2222];
int dow[2222][2222];

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	REP(i, 2222)REP(j, 2222)mp[i][j] = '#';

	int h, w;cin >> h >> w;
	REP(i, h)REP(j, w)cin >> mp[i+1][j+1];
	h += 2;w += 2;

	REP(i, h){
		int pre = 0;
		REP(j, w){
			if(mp[i][j] == '#'){
				pre = j;
			}
			le[i][j] = pre;
		}
		REV(j, w){
			if(mp[i][j] == '#'){
				pre = j;
			}
			ri[i][j] = pre;
		}
	}

	REP(j, w){
		int pre;
		REP(i, h){
			if(mp[i][j] == '#'){
				pre = i;
			}
			up[i][j] = pre;
		}
		REV(i, h){
			if(mp[i][j] == '#'){
				pre = i;
			}
			dow[i][j] = pre;
		}
	}

	int ans = 0;
	REP(i, h){
		REP(j, w){
			if(mp[i][j] == '#')continue;
			int tmp = 1;
			tmp += j - le[i][j] - 1;
			tmp += ri[i][j] - j - 1;
			tmp += i - up[i][j] - 1;
			tmp += dow[i][j] - i - 1;
			ans = max(ans, tmp);
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << " " << #y << " = " << y << endl
#define Max 300005
#define PI 3.141592653589793
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
#define mod 1000000007
#define INF (LL)1e18

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

LL bigmod(LL b,LL p)
{
    if(p == 0)return 1;
    LL my = bigmod(b,p/2);
    my*=my;
    my%=mod;
    if(p & 1)my*=b,my%=mod;
    return my;
}
int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n,int pos)
{
    return (bool)(n & (1 << pos));
}

LL ara[100],n;

LL F()
{
	LL ret = 0;
	while(1)
	{
		sort(ara+1,ara+n+1);
		if(ara[n] < n)break;
		LL need = ara[n] - (n-1);
		LL item = need / n;
		if(need % n)item++;
		ara[n] -= (n * item);
		for(LL i = 1; i < n; i++)ara[i] += item;
		ret += item;
	}
	return ret;
}

int main()
{
	//FI;
	LL i;
	sl(n);
	rep(i,n)sl(ara[i]);
	LL ret = F();
	pl(ret); NL;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
int main() {	
	ll n,cnt=0;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	bool NonDeFlag = false;
	bool NonIncFlag = false;
	for (ll i = 0; i < n-1; i++) {
		if ((NonDeFlag == false)&&(a[i] < a[i + 1])) {
			NonIncFlag = true;
		}
		else if ((NonIncFlag == false) && (a[i] > a[i + 1])) {
			NonDeFlag = true;
		}
		else if ((NonIncFlag == true) && (a[i] > a[i + 1])) {
			cnt++;
			NonIncFlag = false;
			NonDeFlag = false;

		}
		else if ((NonDeFlag == true) && (a[i] < a[i + 1])) {
			cnt++;
			NonIncFlag = false;
			NonDeFlag = false;
		}
		else {
			continue;
		}
	}
	cout << cnt+1 << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int n,S[50];

int solve(int a,int b)
    {
     if (b==0) return 1;
     if (a>=n) return 0;
     int c = solve(a+1,b) || solve(a+1,b-S[a]);
     return c;
     }


int main()
{
 int x,y,i;

 scanf("%d",&n);

 for(i=0;i<n;i++) scanf("%d",&S[i]);
 scanf("%d",&x);

 for(i=0;i<x;i++)
 {
  scanf("%d",&y);
  if(solve(0,y))printf("yes\n");
  else printf("no\n");
  }

return 0;
}






Measured memory_bytes: 2604
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		list.add(n);
		int ans = 0;
		for (int i = 2;; i++) {
			if (n % 2 == 0) {
				n /= 2;
				if (list.contains(n)) {
					ans = i;
					break;
				}
				list.add(n);
			} else {
				n = 3 * n + 1;
				if (list.contains(n)) {
					ans = i;
					break;
				}
				list.add(n);
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int mul(int a,int b){return (long long)a*b;}
typedef long long ll;
ll w,h,x,y;
int main()
{
    srand(time(0));
    scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
    long long a=min(x*h,(w-x)*h),b=min(y*w,(h-y)*w);
    int f=1;
    
    if(w*h%2==0)
    {
    if(a<w*h/2||b<w*h/2) f=0;
        printf("%lld %d\n",w*h/2,f);
    }
    else
    {
        if(a<=w*h/2||b<=w*h/2) f=0;
        printf("%lld.5 %d\n",w*h/2,f);
    }
}


Measured memory_bytes: 256
from collections import deque
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split( )))
B = list(map(int, input().split( )))
cnt = 0
for i in range(N):
  if A[i] >= B[i]:
    cnt += B[i]
  else:
    cnt += A[i]
    d = B[i] - A[i]
    if d <= A[i+1]:
      cnt += d
      A[i+1] -= d
    else:#つまり d > A[i+1]
      cnt += A[i+1]
      A[i+1] = 0
#  print('i=', i, cnt)

print(cnt)

Measured memory_bytes: 24532