akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;

	//num[i][j]: 先頭i,末尾j
	vector<vector<ll>> num(10, vector<ll>(10, 0));

	for (int i = 1; i <= n; i++) {
		string s = to_string(i);
		int b = s.front() - '0';
		int e = s.back() - '0';
		num[b][e]++;
	}

	ll ans = 0;
	rep(i, 10) {
		rep(j, 10) {
			ans += num[i][j] * num[j][i];
		}
	}

	out(ans);

	return 0;
}

Measured memory_bytes: 3692
#include <stdio.h>
#include <ctype.h>

int sp = 0;
int val[100];

void push(int d){
  val[sp++] = d;
}

int pop(void){
  return val[--sp];
}

int get_number(char *s){
	int  n = 0;
  // char to int
	while (*s >= '0' && *s <= '9') {
		n = n * 10 + (*s - '0');
		s++;
	}
	return n;
}

int calc_rpn(char *s){
	int  n,op2;

	while (*s) {

		if (isdigit((int)*s)) {
			n = get_number(s);
			push(n);
			while (n) {
				n /= 10;
				s++;
			}

		} else {
			switch (*s) {
        case '+':
          push(pop() + pop());
          break;
        case '-':
          op2 = pop();
          push(pop() - op2);
          break;
        case '*':
          push(pop() * pop());
          break;
			}
			s++;
		}
	}
	return pop();
}

int main(){
	char s[1000];
	scanf("%[^\n]*s", s);
	printf("%d\n",  calc_rpn(s));
}



Measured memory_bytes: 2072
import random
D = int(input())
c = list(map(int, input().split()))
last = [0] * 26
ans = []
S = []
prev_score = 0
maxsi_list = []

for d in range(1, D+1):
    s = list(map(int, input().split()))
    S += [s]
    maxs = float('-inf')
    maxss = float('-inf')
    maxi = -1
    maxii = -1
    cumsump = 0
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        cumsump += tmp
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        tmp2 = s[i] + cumsump - tmp
        if tmp2 > maxs:
            maxs = tmp2
            maxi = i
        if s[i] > maxss:
            maxii = i
            maxss = s[i]
    ans += [maxi+1]
    last[maxi] = d
    prev_score += maxs
    maxsi_list += [maxii+1]
best_ans = ans
best_score = prev_score
mergin = 1300
# mergin = 13000
schedule = [i for i in range(D)]
for tt in range(31):
    random.shuffle(schedule)
    for dd in schedule:
        last = [0] * 26
        score = 0
        for d in range(1, D+1):
            if dd == (d-1):
                maxc = 0
                maxci = -1
                for i in range(26):
                    cost = c[i] * (d - last[i])
                    if maxc < cost:
                        maxc = cost
                        maxci = i+1
                prev_a = ans[dd]
                ans[dd] = maxci
            td = ans[d-1] - 1
            cumsump = 0
            for i in range(26):
                if td != i:
                    tmp = -c[i] * (d - last[i])
                    cumsump += tmp
            last[td] = d
            score += S[d-1][td]+cumsump
        # if score <= prev_score-mergin:
        if score <= best_score-mergin:
            ans[dd] = prev_a
        elif best_score < score:
            best_ans = ans
            best_score = score
            prev_score = score
        else:
            prev_score = score
    random.shuffle(schedule)
    for dd in schedule:
        last = [0] * 26
        score = 0
        prev_a = ans[dd]
        ans[dd] = maxsi_list[dd]
        for d in range(1, D+1):
            td = ans[d-1] - 1
            cumsump = 0
            for i in range(26):
                if td != i:
                    tmp = -c[i] * (d - last[i])
                    cumsump += tmp
            last[td] = d
            score += S[d-1][td]+cumsump
        # if score <= prev_score-mergin:
        if score <= best_score-mergin:
            ans[dd] = prev_a
        elif best_score < score:
            best_ans = ans
            best_score = score
            prev_score = score
        else:
            prev_score = score

for a in best_ans:
    print(a)

Measured memory_bytes: 82728
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

ll N;
ll X[30], Y[30], P[30], dist[30];
ll dp[40000][20];
ll mincost[40000];

int main() {
  //
  cin >> N;
  rep(i, 0, N) { cin >> X[i] >> Y[i] >> P[i]; }

  for (ll bit = 1; bit < (1 << N); ++bit) {
    using PP = pair<Pll, ll>;
    vector<PP> vec;
    rep(i, 0, N) {
      if (bit & (1 << i)) {
        vec.push_back(PP(Pll(X[i], Y[i]), P[i]));
      }
    }

    ll res = INF;
    for (int i = 0; i < vec.size(); ++i) {
      ll sumx = 0;
      ll sumy = 0;
      for (int j = 0; j < vec.size(); ++j) {
        sumx += abs(vec[j].first.first - vec[i].first.first) * vec[j].second;
        sumy += abs(vec[j].first.second - vec[i].first.second) * vec[j].second;
      }
      chmin(res, sumx);
      chmin(res, sumy);
    }

    mincost[bit] = res;
  }

  /*
    for (ll bit = 0; bit < (1 << N); ++bit) {
      cout << bit << " " << mincost[bit] << endl;
    }
    return 0;
    */

  for (ll bit = 0; bit < (1 << N); ++bit) {
    repe(i, 1, N) { dp[bit][i] = INF; }
    rep(i, 0, N) {
      if (bit & (1 << i)) {
        dp[bit][0] += min(abs(X[i]) * P[i], abs(Y[i]) * P[i]);
      }
    }
  }

  rep(i, 0, N) {
    for (ll bit = 0; bit < (1 << N); ++bit) {
      for (ll j = (1 << N) - 1; j >= 0; --j) {
        j &= bit;
        chmin(dp[bit][i + 1], dp[j][i] + mincost[bit ^ j]);
      }
    }
  }

  ll bitall = (1 << N) - 1;
  repe(i, 0, N) { cout << dp[bitall][i] << "\n"; }
}


Measured memory_bytes: 8908
S = input()
N = len(S)
maxim = (N + 1) // 2

def judge1(cnt):
    for i in range(cnt+1):
        if judge2(i, cnt):
            return cnt
    else: return False

def judge2(i, cnt):
    if i + cnt + 1 >= N:
        return True
    for j in range(i+1, i+2 + cnt):
        if S[i] == S[j]:
            return judge2(j, cnt)
    return False


if len(set(S)) == 1:
    print("0")
else:
    for i in range(0, maxim):
        c = 0
        ans = judge1(i)
        if ans:
            print(str(ans))
            c = 1
            break
    if c == 0:
        print(str(maxim))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    string input; cin >> input;
    vector<int> a(4);
    rep(i,4) a[i] = input[i]-'0';
    rep(x,1<<3) { //bit全探索
        int ans = a[0];
        string s;
        s += (char)input[0];
        rep(i,3) { //各位について
            if (x & 1<<i) { //iビット目が1
                ans += a[1+i];
                s += '+';
                s += input[1+i];
            }
            else {
                ans -= a[1+i];
                s += '-';
                s += input[1+i];
            }
        }
        if (ans == 7) {
            s += "=7";
            cout << s << endl;
            return 0;
        }
    }
} 

Measured memory_bytes: 3608
#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>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    vector<string> Graph(H);
    rep(i,H) cin >> Graph.at(i);

    vector<vector<int>> dist(H, vector<int>(W, -1)); // -1: 未訪問
    dist[0][0] = 0;

    int ans = -1;
    int wall = 0;
    rep(i,H) rep(j,W) if (Graph.at(i).at(j) == '#') ++wall;


    vector<string> G = Graph;
    vector<vector<int>> reached = dist;
    queue<P> que;

    que.push(make_pair(0, 0));
    dist[0][0] = 0;

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int direction = 0; direction < 4; ++direction) {
            int nh = p.first + dx[direction];
            int nw = p.second + dy[direction];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist.at(nh).at(nw) > -1) continue;
            if (Graph.at(nh).at(nw) == '#') continue;
            dist.at(nh).at(nw) = dist.at(p.first).at(p.second) + 1;
            if (nh == H - 1 && nw == W - 1) {
                ans = dist.at(nh).at(nw);
                break;
            }
            que.push(make_pair(nh, nw));
        }
    }
    if (ans == -1) cout << ans << endl;
    else 
    cout << H * W - wall - (ans + 1) << endl;
}


Measured memory_bytes: 3680
n, k, s = map(int, input().split())
A = [str(s) for i in range(k)]
if s < 10 ** 5:
    B = [str(s + 1) for j in range(n - k)]
else:
    B = [str(1) for j in range(n - k)]
C = A + B
print(" ".join(C))


Measured memory_bytes: 14232
#include<stdio.h>
int main()
{
	int n,x;
	int l[100];
	int i;
	int count=1;
	int d=0;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
	}
	for(i=0;i<n;i++){
		if(d+l[i]>x){
			break;
		}else{
			count+=1;
			d+=l[i];
		}
	}
	printf("%d",count);
}

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

int main(){
    int n;
    cin >> n;
    ve<int> a(n+1);
    rep(i,n+1) cin >> a[i];
    sort(a.begin(), a.end());
    ve<int> sa(n);
    rep(i,n) sa[i] = a[i+1]-a[i];
    int ans = sa[0];
    rep(i,n-1) ans = __gcd(ans,sa[i+1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4028
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <deque>

using namespace std;

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

ll myabs(ll x){
    if(x > 0){
        return x;
    }
    else{
        return -x;
    }
}

int main(){
    ll n, z, w;
    cin >> n >> z >> w;
    ll a[2100];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    if(n > 2) {
        cout << max(myabs(a[n - 1] - w), myabs(a[n - 2] - a[n - 1])) << endl;
    }
    else{
        cout << myabs(a[n-1] - w) << endl;
    }


    return 0;
}


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

using namespace std;

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

	int e = sqrt(m) + 1;
	int best = 1e9;

	for(int i = 1; i < e; i++) {
		if(m % i != 0) continue;

		int a = i, b = m / a;

		if(a >= n && a < best) best = a;
		if(b >= n && b < best) best = b;
	}

	cout << m / best << endl;

	return 0;
}

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

int main(){
    int n, ans = 1, a;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a);
        if(a%2 == 0){
            if(a%3 == 0 || a%5 == 0) continue;
            else ans = 0;
        }
    }
    if(ans) printf("APPROVED\n");
    else printf("DENIED\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(T) __typeof((T).begin())
#define each(T, it) for(ITER(T) it =(T).begin(); it!=(T).end(); it++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;
 
int main(void){
    for(int n, m; cin >> n >> m, n;){
        vector<int> p;
        rep(i, n) p.pb(i + 1);

        int cur = -1;
        while(p.size() - 1)
            p.erase((cur = (cur + m) % p.size()) -- + p.begin());

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

Measured memory_bytes: 1228
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs

def main():
    n,k=map(int, input().split())
    A=[int(i) for i in input().split()]
    MOD = 10**9 + 7
    fac, invs = prepare(n,MOD)
    ans = 0
    A.sort()

    for i in range(n):
        tmp=0
        tmp2=0
        if i<n-k+1:
            tmp = (fac[n-(i+1)]%MOD * invs[k-1]%MOD * invs[n-(i+1) - (k-1)]%MOD)%MOD
        if i>=k-1:
            tmp2 = (fac[i]%MOD * invs[k-1]%MOD * invs[i-(k-1)]%MOD)%MOD
        #print("最大になる回数", tmp2, " 最小になる回数", tmp, "A[i]", A[i])
        ans = ans%MOD + (tmp2*A[i]%MOD - tmp*A[i]%MOD)%MOD
        ans%=MOD

    if k==1:
        ans = 0
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 64808
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int answer = 0;
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] countSweets = new int[n + 1];
    for (int i = 0; i < k; i++) {
      int d = sc.nextInt();
      for (int j = 0; j < d; j++) {
        int a = sc.nextInt();
        countSweets[a]++;
      }
    }
    for(int i = 1; i <= n; i++){
      if(countSweets[i] == 0) answer++;
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 45896
#include<iostream>
#include<climits>
#include<vector>

#define MAX 1100
#define INF 5000000

using namespace std;

int n,x[MAX],p[MAX];
int dp[MAX][5500];

int main(void)
{
    cin>>n;
    for(int i = 2;i <= n;i++) {
        cin>>p[i];
    }

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

    bool flag = true;
    for(int i = n;i >= 1;i--)
    {
        int f = INF;
        for(int j = 0;j <= x[i];j++)
            f = min(f,dp[i][j]);
        if(f == INF)
        {
            flag = false;
            break;
        }
        for(int j = x[p[i]];j >= 0;j--)
        {
            dp[p[i]][j] = min((j < f) ? INF : (dp[p[i]][j-f]+x[i]), (j < x[i]) ? INF : (dp[p[i]][j-x[i]]+f));
        }
    }

    if(flag)
    {
        cout<<"POSSIBLE"<<endl;
    } else {
        cout<<"IMPOSSIBLE"<<endl;
    }

    return 0;
}


Measured memory_bytes: 21760
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

llint n;
vector<int> vec, vec2;

int main(void)
{
	cin >> n;
	n++;
	
	int keta = 0;
	for(llint t = n; t; t/=2) keta++;
	
	int id = 1;
	for(int i = keta-2; i >= 0; i--){
		vec.push_back(id), vec2.push_back(id++);
		if(n & (1LL<<i)) vec.insert(vec.begin(), id), vec2.push_back(id++);
	}
	cout << vec.size()*2 << endl;
	for(int i = 0; i < vec.size(); i++) cout << vec[i] << " ";
	for(int i = 0; i < vec2.size(); i++) cout << vec2[i] << " ";
	
	return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,k;
    cin >> n >> k;
    int a[3];
    for (int i = 0;i < 3;++i) cin >> a[i];
    string t,s = "rsp";
    cin >> t;
    int ans = 0;
    for (int i = 0;i < k;++i) {
        int m = n/k;
        if (i < n%k) m++;
        vector<array<int,3>> dp(m+1,array<int,3>{0,0,0});
        for (int j = 0;j < m;++j) {
            for (int u = 0;u < 3;++u) for (int v = 0;v < 3;++v) if (u != v) {
                if (s[(v+1)%3] == t[j*k+i]) dp[j+1][v] = max(dp[j+1][v],dp[j][u]+a[v]);
                else dp[j+1][v] = max(dp[j+1][v],dp[j][u]);
            }
        }
        ans += *max_element(dp[m].begin(),dp[m].end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    int cnt = 0;
    REP(i,1,n+1) {
        if (to_string(i).size() % 2 == 0) continue;
        ++cnt;
    }
    cout << cnt << endl;
}

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

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n h ->
    let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> -b, a)) in
    Array.sort compare ab;

    let amax = Array.fold_left (fun acc (_, a) -> max acc a) 0 ab in

    let phase2 damage count =
        Printf.printf "%d\n" @@ count + (h - damage + amax - 1) / amax
    in

    let rec loop i damage count =
        if i = n then phase2 damage count else
            let (b, _) = ab.(i) in
            let damage, count = if -b >= amax then damage - b, count + 1
                                              else damage, count
            in
            if damage >= h then Printf.printf "%d\n" count else
                loop (i + 1) damage count
    in
    loop 0 0 0
)

Measured memory_bytes: 9336
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n); rep (i, n) cin >> a[i];
    ll mon = 1000, kabu = 0;
    rep (i, n) {
        if (i + 1 != i_len && a[i + 1] > a[i]) {
            ll x = mon / a[i];
            kabu += x;
            mon -= x * a[i];
        } else {
            ll y = kabu * a[i];
            kabu = 0;
            mon += y;
        }
        eprintf("%8lld %8lld\n", mon, kabu);
    }
    cout << mon << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
int n;
char s[maxx];
int ans[maxx];
int pos[maxx]; //预处理RL的位置

int main() { //只有出现RL才会出现位置往复切换
	scanf("%s", s + 1);
	n = strlen(s + 1);
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(s[i] == 'R' && s[i + 1] == 'L') pos[++cnt] = i;
	}
	for(int i = 1; i <= cnt; i++) {
		ans[pos[i]]++, ans[pos[i] + 1]++; //自身会回到自身的位置
		int cntL = 0, cntR = 0;
		for(int j = pos[i] + 2; j < pos[i + 1] ; j++) {
			if(s[j] == 'L') cntL++;
			else cntR++;
		}
		ans[pos[i] + 1] += cntL / 2;
		ans[pos[i]] += cntL - cntL / 2;
		ans[pos[i + 1]] += cntR / 2;
		ans[pos[i + 1] + 1] += cntR - cntR / 2;
	}
	//第一个RL之前R的分配
	int num = 0;
	for(int i = 1; i < pos[1]; i++) num++;
	ans[pos[1]] += num / 2;
	ans[pos[1] + 1] += num - num / 2;
	//最后一个RL之后L的分配
	num = 0;
	for(int i = pos[cnt] + 2; i <= n; i++) num++;
	ans[pos[cnt] + 1] += num / 2;
	ans[pos[cnt]] += num - num / 2;
	for(int i = 1; i <= n; i++) {
		if(i < n) printf("%d ", ans[i]);
		else printf("%d\n", ans[i]);
	}
	return 0;
}

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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const ll mod =1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int>v[100005];
    f(n){
        int a,b;
        cin >> a >> b;
        v[a].pb(b);
    }
    multiset<int>st;
    int ans = 0;
    f1(m){
        for(auto j:v[i]){
            st.insert(j);
        }
        if(st.size()){
            ans += *(--st.end());
            st.erase(--st.end());
        }
    }
    cout << ans << endl;
}

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

int main() {
  long long n,p,odd=0,ans=0;
  cin>>n>>p;
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    if(l%2==1)odd++;
  }
  if(odd==0){
    if(p==0)ans=pow(2,n);
    else ans=0;
  }
  else ans=pow(2,n-1);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n==1)printf("1\n");
if(n==2)printf("2\n");
if(n==3)printf("4\n");
if(n==4)printf("6\n");
if(n==5)printf("16\n");
if(n==6)printf("12\n");
if(n==7)printf("64\n");
if(n==8)printf("24\n");
if(n==9)printf("36\n");
if(n==10)printf("48\n");
if(n==11)printf("1024\n");
if(n==12)printf("60\n");
}


Measured memory_bytes: 2608
lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine(s::Array{SubString{String},1})=map(intSub,s)
function main()
    INF=2^60
    a,b,q=input()|>split|>intLine
    s=Array{Int}(a+2)
    s[1],s[a+2]=-INF,INF
    for i in 2:a+1
        s[i]=int(input())
    end
    t=Array{Int}(b+2)
    t[1],t[b+2]=-INF,INF
    for i in 2:b+1
        t[i]=int(input())
    end
    for _ in 1:q
        x=int(input())
        m=INF
        i=searchsortedlast(s,x)
        j=searchsortedlast(t,x)
        for v in view(s,i:i+1)
            for w in view(t,j:j+1)
                m=min(m,abs(x-v)+abs(v-w),abs(x-w)+abs(w-v))
            end
        end
        println(m)
    end
end
main()

Measured memory_bytes: 168072
#include<iostream>

using namespace std;
int main() {
	int N;
	cin >> N;
	if (1 <= N && N <= 9) {
		cout << N;
		return 0;
	}
	else if (10 <= N && N <= 99) {
		cout << "9";
		return 0;
	}
	else if (100 <= N && N <= 999) {
		cout << N - 90;
		return 0;
	}
	else if (1000 <= N && N <= 9999) {
		cout << "909";
		return 0;
	}
	else if (10000 <= N && N <= 99999) {
		cout << N - 9090;
		return 0;
	}
	else if (N == 100000) {
		cout << "90909";
	}
}

Measured memory_bytes: 256
#include<cstdio>
char op[13][5];
char s[7];
void make(){
	int i;
	for(i=0;i<8;i++){
		int p=i,t=0;
		while(t<3){
			op[i][t]=(p&1==1)?'1':'0';
			t++;
			p/=2;
		}
	}
}
int num(int x){
	return s[x]-'0';
}
int main(){
	scanf("%s",s);
	int i,j,t;
	make();
	for(i=0;i<8;i++){
		int sum=num(0);
		for(j=0,t=1;j<3;t++,j++){
			if(op[i][j]=='0')sum+=num(t);
			else sum-=num(t);
		}
		if(sum==7){
			printf("%d",num(0));
			for(j=1;j<4;j++)printf("%c%d",(op[i][j-1]=='0')?'+':'-',num(j));
			printf("=7\n");
			return 0;
		}
	}
		
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int l=s.length();
	int count=0;
	while(s!=t&&count<l){
		count++;
		string a="";
		a+=s[l-1];
		a+=s.substr(0,l-1);
		s=a;
		if(s==t)
			break;
	}
	if(s==t)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=2019;
lli dp[N],ans;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    lli i,j,n=s.length();
    
    for(i=0;i<n;i++)
    {
        dp[0]++;
        lli dp1[2019],cur=s[i]-'0';
        memset(dp1, 0LL, sizeof(dp1));
        for(j=0;j<2019;j++)
        {
            dp1[(j*10+cur)%2019]+=dp[j];
        }
        for(j=0;j<2019;j++)
        {
            dp[j]=dp1[j];
        }
        ans+=dp[0];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int N = 1 << 17;

//?????????????????????0?§???????
//????°????????±???????????????°??????(RMQ)

//?????°???????????¨???????????°??????????????????

int n,n_,q,ud[2*N-1],t[2*N-1];

//?????????
//n_???x??\??????????°????2????????????
void init(int x)
{
	//?°????????????????????´???°???2???????????????
	n_=1;
	while(n_<x){
		n_*=2;
	}
	rep(i,2*n_-1){
		ud[i] = (int)((1LL<<31) -1LL);
		t[i] = -1;
	}
}

//k????????????????????§??????
int find(int k)
{
	P res;
	//????????????
	k += n_-1;
	res.first = ud[k];
	res.second = t[k];
	//?????????????????´??°
	while(k>0){
		k = (k-1)/2;
		if(t[k] > res.second){
			res.first = ud[k];
			res.second = t[k];
		}	
	}
	return res.first;
}

//[a,b)???????°????????±??????????
//k??????????????????
//????????????query(a,b,0,0,n_)??¨???????????¶???(n_??¨???????????¨?????¨???)
void update(int a,int b,int k,int l,int r,int val,int id)
{
	if(r <= a || b <= l){
		return;
	}
	if(a <= l && r <= b){
		ud[k] = val;
		t[k] = id;
	}else{
		update(a,b,2*k+1,l,(l+r)/2,val,id);
		update(a,b,2*k+2,(l+r)/2,r,val,id);
	}
}
int main()
{
	scanf("%d%d",&n,&q);
	init(n);
	rep(i,q){
		int x;
		scanf("%d",&x);
		if(x==0){
			int s,t,u;
			scanf("%d%d%d",&s,&t,&u);
			update(s,t+1,0,0,n_,u,i);
		}else{
			int s;
			scanf("%d",&s);
			printf("%d\n",find(s));
		}
	}
	return 0;
}

Measured memory_bytes: 5240
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if(t * s >= d) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3648
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object Main extends App {

  def pow5(x: Long) = x * x * x * x * x
  val x = StdIn.readInt()
  val map = (-1000L to 1000L).map(a => pow5(a) -> a).toMap
  val set = map.keySet
  val good = map.filter { case (k, _) => set.contains(x + k) }
  val ans = (map(x + good.head._1) , good.head._2)
  println(s"${ans._1} ${ans._2}")

  def readIntPair: (Int, Int) = {
    val Array(x, y) = StdIn.readLine().split(" ").map(_.toInt)
    (x, y)
  }
}

Measured memory_bytes: 58496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(ll i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;


int main() {
    int a,b,c,k;cin>>a>>b>>c>>k;
    int ans = 0;
    if(k>a) {
        k-=a;
        ans += a;
        if(k>b) {
            k-=b;
            if(k>0) {
                ans -= k;
            }
        }
    } else {
        ans += k;
    }
    cout << ans;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, q;
map<int, vector<int> > events;
multiset<int> ms;

int32_t main(){_

   cin>>n>>q;

   for (int i = 0; i < n; ++i)
   {
      int s, t, x;
      cin>>s>>t>>x;
      s -= x;
      t -= x;
      events[s].emplace_back(x);
      events[t].emplace_back(-x);
   }

   auto it = events.begin();
   for (int i = 0; i < q; ++i)
   {
      int x;
      cin>>x;
      while(it != events.end() and (*it).first <= x){
         for(auto i: (*it).S){
            if(i >= 0)ms.insert(i);
            else ms.erase(ms.find(-i));
         }
         ++it;
      }
      if(sz(ms))cout<<*ms.begin()<<endl;
      else cout<<-1<<endl;
   }

   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works

Measured memory_bytes: 54400
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n; cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    ll vmax = 1e18;

    ll prod = a[0];
    reps(i, 1, n){
        ll vtemp = prod * a[i];
        if((vtemp > vmax) || (vtemp < prod)){
            cout << -1 << endl;
            return 0;
        }
        if(prod > 1e9 && a[i] > 1e9){
            cout << -1 << endl;
            return 0;
        }
        prod *= a[i];
    }

    cout << prod << endl;
    return 0;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
int cc,tt;
long long a[10000],b[10000];
int s(long long a){int t=0;while(a)t+=a%10,a/=10;return t;}
int main()
{
	long long pw=1;
	for(int i=1;i<=15;i++)
	{
		for(int j=1;j<140;j++)if(j*pw!=1)a[++cc]=j*pw-1; 
		pw=pw*10;
	}
	sort(a+1,a+cc+1);cc=unique(a+1,a+cc+1)-a-1;
	for(int i=1;i<=cc;i++)if(a[i]<=1e15)
	{
		bool f=1;
		for(int j=i+1;j<=cc;j++)if(a[j]<=1e15)if(a[i]*s(a[j])>a[j]*s(a[i])){f=0;break;}
		if(f==1)b[++tt]=a[i];
	}
	int k;scanf("%d",&k);
	for(int i=1;i<=k;i++)printf("%lld\n",b[i]);
	return 0;
}

Measured memory_bytes: 256
#112
from itertools import product

N=int(input())
px,py,ph=[],[],[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)
        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

for Cxi,Cyj in product(range(101),range(101)):

    if len(ph)!=1:
        preH=Calc_H(Cxi,Cyj,px[0],py[0],ph[0])
        for i in range(len(ph)):
            nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
            if nowH!=preH:
                break
            preH=nowH
        else:
            print(Cxi,Cyj,nowH)
            break
    else:
        print(px[0],py[0],ph[0])
        break

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);

    ll ans=0,num=0;
    rep(i,n){
        cin >> a[i];
        b[i]=abs(a[i]);
        if(a[i]<0){
            num++;
        }
        ans+=b[i];
    }
    sort(b.begin(),b.end());
    if(num%2==1){
        ans-=2*b[0];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int q = sc.nextInt();
        long[] s = new long[a+2];
        long[] t = new long[b+2];
        s[0] = (long) -Math.pow(10, 12);
        t[0] = (long) -Math.pow(10, 12);
        s[a+1] = (long) Math.pow(10, 12);
        t[b+1] = (long) Math.pow(10, 12);
        for (int i = 1; i <= a; i++) s[i] = sc.nextLong();
        for (int i = 1; i <= b; i++) t[i] = sc.nextLong();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            long p = sc.nextLong();
            int sidx = Arrays.binarySearch(s, p);
            sidx = (sidx < 0) ? ~sidx : sidx;
            int tidx = Arrays.binarySearch(t, p);
            tidx = (tidx < 0) ? ~tidx : tidx;
            long d = Long.MAX_VALUE;
            d = Math.min(d, Math.abs(p - s[sidx]) + Math.abs(s[sidx] - t[tidx]));
            d = Math.min(d, Math.abs(p - s[sidx]) + Math.abs(s[sidx] - t[tidx-1]));
            d = Math.min(d, Math.abs(p - s[sidx-1]) + Math.abs(s[sidx-1] - t[tidx]));
            d = Math.min(d, Math.abs(p - s[sidx-1]) + Math.abs(s[sidx-1] - t[tidx-1]));
            d = Math.min(d, Math.abs(p - t[tidx]) + Math.abs(t[tidx] - s[sidx]));
            d = Math.min(d, Math.abs(p - t[tidx]) + Math.abs(t[tidx] - s[sidx-1]));
            d = Math.min(d, Math.abs(p - t[tidx-1]) + Math.abs(t[tidx-1] - s[sidx]));
            d = Math.min(d, Math.abs(p - t[tidx-1]) + Math.abs(t[tidx-1] - s[sidx-1]));
            sb.append(d).append("\n");
        }

        System.out.println(sb.toString());
        sc.close();
    }

}


Measured memory_bytes: 97228
import sys
from collections import deque
import copy
def main():
    N, K = map(int, input().split())
    p = [int(i) for i in input().split()]
    p.sort()
    ans = 0
    for i in range(K):
        ans += p[i]
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

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

    int n;
    while(cin>>n,n){
        vector<int> w(n);
        for(int i=0;i<n;i++) cin>>w[i];
        vector<vector<int> > dp(400,vector<int>(400,0));//dp[i][j]:=i~j??????????????????
        vector<vector<int> > res(400,vector<int>(400,0));
        for(int i=0;i<n-1;i++) if(abs(w[i]-w[i+1])<=1){
            dp[i][i+1]=1;
        }
        for(int i=4;i<=n;i+=2){
            for(int j=0;j+i<=n;j++){
                if(dp[j+1][j+i-2] && abs(w[j]-w[j+i-1])<=1){
                    dp[j][j+i-1]=1;
                    continue;
                }
                for(int k=2;k<i;k+=2){
                    if(dp[j][j+k-1] && dp[j+k][j+i-1]){
                        dp[j][j+i-1]=1;
                        break;
                    }
                }
            }        
        }
        for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(dp[i][j]){
            res[i][j]=j-i+1;
        }
        for(int k=0;k<n-1;k++){
            for(int i=0;i<=k;i++){
                for(int j=k+1;j<n;j++){
                    res[i][j]=max(res[i][j],res[i][k]+res[k+1][j]);
                }
            }
        }
        cout<<res[0][n-1]<<endl;
    }
}

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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
   string s; cin >> s;
   int n = s.size();
   int res;
   if (n % 2) {
     int m = (n - 1) / 2;
     char c = s[m];
     int i = 1;
     while (i <= m) {
       if (s[m + i] != c or s[m - i] != c) break;
       i++;
     }
     res = m + i;
   } else {
     int m = n / 2;
     char c = s[m];
     int i = 1;
     while (i <= m) {
       if (s[m + i - 1] != c or s[m - i] != c) break;
       i++;
     }
     res = m + i - 1;
   }
   cout << res << '\n';
  return 0;
}

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

int up[2000][2000];
int dn[2000][2000];
int ri[2000][2000];
int le[2000][2000];
string s[2000];
int h,w;

int main(){
    cin>>h>>w;
    for (int i = 0; i < h; i++) cin>>s[i];
    //////////////up
    for(int j = 0; j < w; j++){
        if(s[0][j]=='.') up[0][j]=1;
        else up[0][j]=0;
    }
    for (int i = 1; i < h; i++){
        for (int j = 0; j < w; j++){
            if(s[i][j]=='.') up[i][j]=up[i-1][j]+1;
            else up[i][j]=0;
        }
    }
    ////////////le
    for(int j = 0; j < h; j++){
        if(s[j][0]=='.') le[j][0]=1;
        else le[j][0]=0;
    }
    for (int i = 1; i < w; i++){
        for (int j = 0; j < h; j++){
            if(s[j][i]=='.') le[j][i]=le[j][i-1]+1;
            else le[j][i]=0;
        }
    }
    ////////////dn
    for(int j = w-1; j>=0; j--){
        if(s[h-1][j]=='.') dn[h-1][j]=1;
        else dn[h-1][j]=0;
    }
    for (int i = h-2; i>=0; i--){
        for (int j = 0; j < w; j++){
            if(s[i][j]=='.') dn[i][j]=dn[i+1][j]+1;
            else dn[i][j]=0;
        }
    }
    ////////////ri
    for(int j = h-1; j >=0 ; j--){
        if(s[j][w-1]=='.') ri[j][w-1]=1;
        else ri[j][w-1]=0;

    }
    for (int i = w-2; i >= 0; i--){
        for (int j = 0; j <h ; j++){
            if(s[j][i]=='.') ri[j][i]=ri[j][i+1]+1;
            else ri[j][i]=0;
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            if(ans<up[i][j]+dn[i][j]+ri[i][j]+le[i][j]-3)
                ans = up[i][j]+dn[i][j]+ri[i][j]+le[i][j]-3;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 66816
#include <bits/stdc++.h> 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;


int main(){
    string s;
    cin >> s;
    cout(s.substr(0,3));
    return 0;
}

Measured memory_bytes: 3624
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
flag = True
for i in range(3):
    if S[i] == S[i+1]:
        flag = False

print('Good' if flag else 'Bad')
# 

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <queue>

#define INF (int)(1e9 + 7)
#define int long long

using namespace std;

signed main()
{
    int Q;
    scanf("%lld", &Q);
    int sumx = 0;
    //always left.size() = right.size() or left.size() = right.size()+1
    priority_queue<int> left;
    priority_queue<int, vector<int>, greater<int>> right;
    left.push(-INF);
    right.push(INF);
    int sumb = 0;

    for (int i = 0; i < Q; i++)
    {
        int q;
        scanf("%lld", &q);
        if (q == 1)
        {
            int b, x;
            scanf("%lld%lld", &x, &b);

            if (i == 0)
            {
                left.push(x);
            }
            else
            {
                int pminx = left.top();
                sumx += abs(pminx - x);

                //push
                if (x <= right.top())
                {
                    left.push(x);
                }
                else
                {
                    right.push(x);
                }

                //adjust size
                if (right.size() > left.size())
                {
                    left.push(right.top());
                    right.pop();
                }
                if (left.size() > right.size() + 1)
                {
                    right.push(left.top());
                    left.pop();
                }

                //
                int nminx = left.top();
                int dx = nminx - pminx;
                int n = right.size() + left.size() - 2;
                int index = (n - 1) / 2;
                if (dx >= 0)
                {
                    sumx += (index * 2 - n) * dx;
                }
                else
                {
                    sumx += ((index + 1) * 2 - n) * dx;
                }
            }

            sumb += b;
        }
        else
        {
            printf("%lld %lld\n", left.top(), sumx + sumb);
        }
    }

    return 0;
}

Measured memory_bytes: 3828
# import sys
# input = sys.stdin.readline
import itertools


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    w, h, n = input_list()
    zahyou = [[0]*w for _ in range(h)]
    for _ in range(n):
        x, y, a = input_list()
        umeru(zahyou, x, y, a)
    ans = 0
    for hz in zahyou:
        ans += hz.count(0)
    print(ans)

def umeru(zu, x, y, a):
    for Y, row in enumerate(zu):
        for X, v in enumerate(row):
            if a == 1:
                if X < x:
                    zu[Y][X] = 1
            if a == 2:
                if X > x - 1:
                    zu[Y][X] = 1
            if a == 3:
                if Y < y:
                    zu[Y][X] = 1
            if a == 4:
                if Y > y - 1:
                    zu[Y][X] = 1


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 73716
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;
use std::mem::swap;

const MIN: i64 = std::i64::MIN;

#[fastout]
fn main() {
    input! {
    d: usize,
    c: [i64; 26],
    s: [[i64; 26]; d]
    }
    let mut dp = vec![vec![vec![vec![]; 27]; 26]; d + 1];
    for i in 0..=d {
        for j in 0..26 {
            for k in 0..27 {
                dp[i][j][k].push(MIN)
            }
        }
    }
    for i in 0..26 {
        for j in 0..27 {
            dp[0][i][j][0] = 0;
        }
    }
    for i in 0..d {
        for j in 0..26 {
            for k in 0..26 {
                let t = dp[i][k][0][0] - (1..27)
                    .fold(0, |acc, x| acc + if j != x - 1 { (i as i64 + 1 - dp[i][k][x][dp[i][k][x].len() - 1]) * c[x - 1] } else { 0 }) + s[i][j];
                if t > dp[i + 1][j][0][0] {
                    dp[i + 1][j][0][0] = t;
                    for l in 1..27 {
                        dp[i + 1][j][l] = dp[i][k][l].clone();
                        if j == l - 1 {
                            dp[i + 1][j][l].push(i as i64 + 1);
                        }
                    }
                }
            }
        }
    }
    let mut ans = vec![vec![]; 26];
    ans[0].push(MIN);
    for i in 0..26 {
        if ans[0][0] < dp[d][i][0][0] { swap(&mut ans, &mut dp[d][i]) }
    }
    let mut plan = vec![0; d];
    for i in 1..27 {
        for j in 0..ans[i].len() {
            if ans[i][j] == 0 { continue; }
            plan[ans[i][j] as usize - 1] = i;
        }
    }
    for i in plan {
        println!("{}", i);
    }
}


Measured memory_bytes: 28792
N,M=map(int,input().split())
n=['0']*N
a=0
for i in range(M):
    s,c=map(str,input().split())
    if n[int(s)-1]!='0' and n[int(s)-1]!=c:
        a=1
    if s=='1' and c=='0' and N!=1:
        a=1
    n[int(s)-1]=c
if n[0]=='0' and N!=1:
    n[0]='1'
if a==0:
    print(''.join(n))
else:
    print(-1)

Measured memory_bytes: 61408
from fractions import gcd
N,M = map(int,input().split())
s = input()
t = input()
n = N//gcd(N,M)
m = M//gcd(N,M)
for i in range(gcd(N,M)):
    if s[i*n] == t[i*m]:
        continue
    else:
        print(-1)
        break
else:
    print(N*M//gcd(N,M))
                


Measured memory_bytes: 5432
X = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

d = make_divisors(X) 

ans =[0,0]

for i in d:

  for j in range(-10000,10000):
    if j**5 - (j-i)**5 == X:
      print(j,j-i)
      exit()

Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int> c(n,k-q);
  for(int i=0;i<q;i++){
    int a;
    cin>>a;
    c[a-1]++;
  }
  for(int i=0;i<n;i++)
    cout<<(c.at(i)>0?"Yes":"No")<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
 
int sumdigit(int x){
  if(x/10==0) return x;
  return sumdigit(x/10)+x%10;
  }

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

   if(n[0]==n[1]&&n[1]==n[2]||n[1]==n[2]&&n[2]==n[3]) cout <<"Yes" <<endl;
   else cout << "No" <<endl;
}

Measured memory_bytes: 256