akhauriyash/Code-Regression huggingface dataset:
#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;
    cin >> n;
    vector <int> c(n),s(n),f(n),t(n,0);
    rep(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
    }

    int tt,a;

    rep(i,n-1){
        //cout << i << endl;
        tt=s[i];
        rep(j,n-i-1){
            //cout << j << endl;
            tt+=c[i+j];
            if(j==n-i-2){
                break;
            }
            if(tt<s[i+j+1]){
                tt=s[i+j+1];
            }
            if(tt%f[i+j+1]!=0){
                a=tt%f[i+j+1];
                tt+=f[i+j+1]-a;
            }
        }
        t[i]=tt;
    }

    rep(i,n){
        cout << t[i] << endl;
    }

    
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    long long k;
    cin >> n >> k;
    vector<int> town(n + 1);
    vector<bool> visit(n + 1, false);
    for (int i = 1; i <= n; i++)
    {
        int to;
        cin >> to;
        town[i] = to;
    }
    int now = town[1];
    visit[now] = true;
    vector<int> loop;
    visit[1] = true;
    k--;
    while (k != 0)
    {
        now = town[now];

        if (!visit[now])
        {
            visit[now] = true;
        }
        else
        {
            if (find(loop.begin(), loop.end(), now) != loop.end())
            {
                k--;
                break;
            }
            loop.push_back(now);
        }
        k--;
    }
    if (k > 0)
    {
        long long pos = k % loop.size();
        // cout << "pos = " << k << " % " << loop.size() << "= " << pos << endl;
        // cout << loop[pos] << endl;
        // for (auto &i : loop)
        // {
        //     cout << i << " ";
        // }
        cout << loop[pos];
    }
    else
        cout << now;
}

Measured memory_bytes: 4516
# -*- coding: utf-8 -*-


def main():
    from sys import setrecursionlimit
    setrecursionlimit(10 ** 7)

    n = int(input())
    graph = [list() for _ in range(n)]
    ans = [0 for _ in range(n - 1)]

    # KeyInsight:
    # 木の問題と再帰関数は相性がいい
    # See:
    # https://www.youtube.com/watch?v=7IlBVSglZqc
    for i in range(n - 1):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        graph[ai].append((bi, i))
        graph[bi].append((ai, i))

    def dfs(vertex, parent=-1, edge_color=-1):
        color_code = 1

        for to, edge_id in graph[vertex]:
            if to == parent:
                continue

            if color_code == edge_color:
                color_code += 1

            ans[edge_id] = color_code
            color_code += 1

            dfs(to, vertex, ans[edge_id])

    dfs(0)
    count = 0

    for g in graph:
        count = max(count, len(g))

    print(count)
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 87468
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

const LL MAXN = 1e5+10;
VLL adj[MAXN];
LL dist[MAXN], parent[MAXN];

int main() {
	rep(i, 0, (LL)MAXN) {
		dist[i] = -1;
		parent[i] = -1;
	}
	sll(n); sll(m);
	rep(i, 0, m) {
		sll(a); sll(b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	} 
	// BFS
	deque<LL> q;
	q.push_back(1);
	dist[1] = 0;
	parent[1] = 0;
	while(!q.empty()) {
		LL curr = q.front(); q.pop_front();
		for(LL next : adj[curr]) {
			if(dist[next] == -1 && parent[next] == -1) {
				dist[next] = dist[curr] + 1;
				parent[next] = curr;
				q.push_back(next);
			}
		}
	}
	rep(i, 1, n+1) {
		if(dist[i] == -1) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	rep(i, 2, n+1)	pll(parent[i]), nl;
}


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

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;

int arr[NMAX];
int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
vector<int> v;

void solve()
{
    cin>>n;

    for(int i=1;i<=1000002;i++){
        v.pb(i*(i+1)/2);
    }

    // v.lower_bound(v.begin(),v.end(),n) - v.begin();
    int cnt = 0;
    vector<pii> pr;

    for(int i=2;i*i<=n;i++){
        cnt = 0;
        while(n%i == 0){
            n = n/i;
            cnt++;
        }
        if(cnt > 0)
            pr.pb({i,cnt});
    }

    if(n > 1){
        pr.pb({n,1});
    }  
    int ans = 0;
    for(auto x:pr){
        int f = upper_bound(v.begin(),v.end(),x.ss) - v.begin();
        ans += f;
    }
    cout<<ans;
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 11616
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        long [] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextLong();
        Arrays.sort(a);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    if (a[i] + a[j] > a[k] && a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) ans++;
                }
            }
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 33228
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007

ll n,m,k;
// ll ans = 0;
// vector<ll> a(N);
// const int M = 2;
// void dfs(vector<int> &A) {
//     // 終端条件 --- 10 重ループまで回したら処理して打ち切り
//     ll sum = std::accumulate(A.begin(), A.end(), 0LL);
//     if (sum > k) {
//       if(sum.size() > ans){
//         ans = sum.size();
//       }
//       return;
//     }

//     for (int v = 0; v < M; ++v) {
//         A.push_back(v);
//         dfs(A);
//         A.pop_back(); // これが結構ポイント
//     }
// }

int main(){
  
  cin>>n;
  vector<string> s(n);
  rep(i, n){
    cin >> s[i];
  }
  // vector<ll> a(n),b(m);
  // ll sum = 0;
  // rep(i, n){
  //   cin >> a[i];
  // }
  // rep(i,m){
  //   cin >> b[i];
  // }

  vector<ll> ans(4);
  rep(i, n){
    if(s[i] == "AC") ans[0]++;
    if(s[i] == "WA") ans[1]++;
    if(s[i] == "TLE") ans[2]++;
    if(s[i] == "RE") ans[3]++;
  }

  
    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;
  
  


  return 0;
}

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

    int main(void){
        int n, sum = 0;
        cin >> n;
        vector<int> d(n);
        for (int i = 0; i < n;i++){
            cin >> d.at(i);
        }
        for (int i = 0; i < n-1;i++){
            for (int j = i+1; j < n;j++){
                sum += d.at(i) * d.at(j);
            }
        }
        cout << sum << endl;
        return 0;
    }


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

using namespace std;
 
using tint = long long;
using ld = long double;
 
#define forsn(i, s, n) for(int i = int(s); i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
 
using vi = vector<tint>;
 
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
 
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
 
#define DBG(x) cerr << #x << " = " << x << endl;
 
const int MOD = 1e9+7;
const int MX = 3005;
const int INF = 1e9;
const ld PI = acos(ld(-1)); 
 
const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
 
bool valid(int x, int y, int n, int m){
	return (0<=x && x<n && 0<=y && y<m);
}
 
void NACHO(string name = "", bool file = 0){
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(file){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
 
int main(){
    NACHO();
	tint n, d; cin >> n >> d;
	d*=d;
	int ret = 0;
	forn(i, n){
		tint x, y; cin >> x >> y;
		if(x*x+y*y <= d) ret++; 
	}
	cout << ret << endl;
}


Measured memory_bytes: 3664
S = input()
T = input()

ans = len(S)

for i in range(len(S)):
  if (i+len(T)-1) >= len(S):
    break
    
  dif = 0
  for j in range(len(T)):
    if S[i+j] != T[j]:
      dif+=1
  ans = min(ans,dif)
  
print(ans)

Measured memory_bytes: 8928
t = int(input())
i = 0
def Right_Tri(m,n,o):
    a = (n**2+o**2)**(0.5)
    if m == a:
        return True

while(i<t):
    m,n,o = map(int, input().split())
    if (Right_Tri(m,n,o) or Right_Tri(n,o,m) or Right_Tri(o,m,n) == True):
        print("YES")
    else:
        print("NO")
    i += 1


Measured memory_bytes: 5660
#include <cstdio>
#include <algorithm>
using namespace std;
const int md=1000000007;
int n,i,r,a,p,z;
int main() {
  scanf("%d",&n);
  for (r=1, i=0; i<n; i++) {
    scanf("%d",&a);
    if (i>0) r=(r*(z+1LL))%md;
    z=min(z+1,(a+1)/2);
    p=a;
  }
  printf("%d\n",r);
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
d = [i for i in input().split()]

while True:
  s_l = list(str(n))
  frag = True
  for de in d:
    if de in s_l:
      frag = False
      continue
  if frag:
    print(n)
    break
  n += 1

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N=in();
    vector<string> W(N);

    REP(i,N)cin>>W[i];

    bool ans=true;
    REP(i,N-1){
        if(W[i][W[i].length()-1]!=W[i+1][0])ans=false;
    }
    sort(all(W));
    REP(i,N-1){
        if(W[i]==W[i+1])ans=false;
    }
    isYes(ans);
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int x = sc.nextInt();
		int cnt = 1;
		int value = 0;
		for (int i = 0; i < n; i ++){
			value += sc.nextInt();
			if(value <= x)
				cnt++;
		}
		out.println(cnt);

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int n,m;
    cin >> n >> m;
    if(n==m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	string s;
	cin >> s;
	vector<char> str;
	for(long long i=0;i<s.size();i++){
		str.push_back(s.at(i));
	}

	vector<char> answer;
	for(long long i=0;i<s.size();i++){
		if(str.at(i) == '0'){
			answer.push_back('0');
		}else if(str.at(i) == '1'){
			answer.push_back('1');
		}else if(str.at(i) == 'B' && !(answer.empty())){
			answer.pop_back();
		}

	}

	for(auto ans : answer){
		cout << ans;
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

class Dice {
public:
	int n[6];

	Dice() {
		for (int i = 0;i<6;i++) {
			cin >> n[i];
		}
	}
	int N() {
		int x;
		x = n[0];
		n[0] = n[1];
		n[1] = n[5];
		n[5] = n[4];
		n[4] = x;
		return n[0];
	}
	int E() {
		int x;
		x = n[0];
		n[0] = n[3];
		n[3] = n[5];
		n[5] = n[2];
		n[2] = x;
		return n[0];
	}
	int W() {
		int x;
		x = n[0];
		n[0] = n[2];
		n[2] = n[5];
		n[5] = n[3];
		n[3] = x;
		return n[0];
	}
	int S() {
		int x;
		x = n[0];
		n[0] = n[4];
		n[4] = n[5];
		n[5] = n[1];
		n[1] = x;
		return n[0];
	}
};

int main() {

	Dice d;
	int n, a, b;
	string m;
	cin >> n;

	for (int i = 0;i < n;i++) {
		cin >> a >> b;
		while (a != d.n[0] || b != d.n[1]) {
			if (rand() % 2 == 1) {
				d.N();
			}
			else {
				d.E();
			}
		}
		cout << d.n[2] << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
n = int(input())
A = list(map(int,input().split()))

ans = float('inf')
x = 0
y = sum(A)

if n==2:
    print(abs(A[0]-A[1]))
    exit()

for i in range(1,n-1):
    x += A[i-1]
    y -= A[i-1]
    ans = min(abs(x-y),ans)

print(ans)

Measured memory_bytes: 24812
#include <string>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
using namespace std;

int main(){
    vector<int> table;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            table.push_back(i*j);
        }
    }
    bool check = false;
    int n;
    cin >> n;
    for(int ele : table){
        if(ele == n){
            check = true;
        }
    }
    if(check){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double A,B;
  cin >> A >> B;
  for (int i = B * 10; i < (B + 1) * 10; i++){
    if (i * 0.08 >= A && i * 0.08 < A + 1){
      cout << i << endl;
      break;
    }
    else if (i == B * 10 + 9){
      cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		String Sunny = "Sunny";
		String Cloudy = "Cloudy";
		String Rainy = "Rainy";

		String i = in.next();

		System.out.println(Sunny.equals(i) ? Cloudy :
			               Cloudy.equals(i) ? Rainy :
			               Rainy.equals(i) ? Sunny : "");

	}

	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
	}

}

Measured memory_bytes: 20308
#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, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n;
	m = n;
	ll count5 = 0;
	if (n % 2LL != 0) {
		cout << "0\n";
	} else {
		count5 = m / 10LL;
		m /= 10LL;
		while (m != 0) {
			count5 += m / 5LL;
			m /= 5LL;
		}
		cout << count5 << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int r = Integer.parseInt(br.readLine());
        
        out.println(3 * r * r);
        out.close();
        
    }
}

Measured memory_bytes: 32880
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define INFLL (1LL << 60)
#define INF (1 << 30)
using namespace std;
typedef long long ll;

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

class UF
{
	vector<int> par;
public:
	UF(int n) {
		par.resize(n);
		rep(i, n) par[i] = i;
	}
	int root(int x) {
		if (x == par[x]) return x;
		else return par[x] = root(par[x]);
	}
	bool same(int x, int y) { return root(x) == root(y); }
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		par[x] = y;
		return true;
	}
};
struct Edge { int from, to, cost; };

ll kruskal(vector<Edge>& edges, int vnum) {
	sort(edges.begin(), edges.end(), [](Edge a, Edge b) {
		return a.cost < b.cost;
		});
	ll sum = 0;
	UF uf = UF(vnum);
	for (Edge e : edges) {
		if (uf.unite(e.from, e.to)) {
			sum += e.cost;
		}
	}
	return sum;
}
int main()
{
	int N; cin >> N;
	vector<int> X(N), Y(N);
	rep(i, N) {
		cin >> X[i] >> Y[i];
	}
	vector<pair<int, int>> ps(N);	//点(x,y)の管理
	vector<pair<int, int>> xs(N);	//xと点id
	vector<pair<int, int>> ys(N);	//yと点id
	rep(i, N) {
		ps[i] = make_pair(X[i], Y[i]);
		xs[i] = make_pair(X[i], i);
		ys[i] = make_pair(Y[i], i);
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());

	vector<Edge> edges((N - 1) * 2);
	rep(i, N - 1) {
		edges[i].from = xs[i].second;
		edges[i].to = xs[i + 1].second;
		edges[i].cost = xs[i + 1].first - xs[i].first;

		edges[i + N - 1].from = ys[i].second;
		edges[i + N - 1].to = ys[i + 1].second;
		edges[i + N - 1].cost = ys[i + 1].first - ys[i].first;
	}
	cout << kruskal(edges, N) << endl;
	return 0;
}


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

#define INF (1 << 29)
#define rep2(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define EPS 1e-10

using namespace std;

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

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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    ll ans = a[0]-1;
    ll step = 2;
    rep2(i,1,N){
        int p = step;
        if(a[i]==step){
            step++;
        } else if(a[i] > step){
            ans += (a[i]-1)/p;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 768
#include <stdio.h>

int main(void){
  int d, ans;
  
  scanf("%d", &d);
  for(int i = 1; i <= d;i++){
    char buf[100];
    sprintf(buf, "%d", i);
    int count = 0;
    int j = 0;
    while(buf[j]!= '\0'){
      count++;
      j++;
    }
    if(count %2 == 1){
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
from heapq import heappush, heappop, heappushpop
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

Q = int(input())
L = []
R = []

B = 0
M = 0

for _ in range(Q):
    q = inpl()
    if len(q) == 3:
        B += q[2]
        if len(R) == 0:
            L.append(-q[1])
            R.append(q[1])
            continue

        M += min(abs(-L[0] - q[1]), abs(R[0] - q[1])) * (not (-L[0] <= q[1] <= R[0]))
        if q[1] < R[0]:
            heappush(L, -q[1])
            heappush(R, -heappushpop(L, -q[1]))
        else:
            heappush(R, q[1])
            heappush(L, -heappushpop(R, q[1]))
    else:
        print(-L[0], B+M)

Measured memory_bytes: 19044
#include <bits/stdc++.h>
 
using namespace std;
 
#define MOD 10007
 
int N,dp[1050][1<<3];
char sch[1050];
 
int getNum(char c){
    if(c == 'J'){
	return 0;
    }else if(c == 'O'){
	return 1;
    }
    return 2;
}
 
int main(){
    cin >> N >> sch;
    memset(dp,0,sizeof(dp));
   
    for(int i = 0 ; i < (1<<3) ; i++){
	if((1<<getNum('J') & i) && (1<<getNum(sch[0]) & i)){
	    dp[0][i] = 1;
	}
    }
    for(int i = 1 ; i < N ; i++){
	for(int j = 0 ; j < (1<<3) ; j++){
	    for(int k = 0 ; k < (1<<3) ; k++){
		if(j & k){
		    if(!(k & (1<<getNum(sch[i])))) continue;
		    dp[i][k] = dp[i][k] + dp[i-1][j];
		    dp[i][k] %= MOD;
		}
	    }
	}
    }
    int ans = 0;
    for(int i = 0 ; i < (1<<3) ; i++){
	ans += dp[N-1][i];
	ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

template<typename M, typename T>
struct lazy_segment_tree{
	typedef function<M(M, M)> F;
	typedef function<M(M, T)> EVAL;
	typedef function<T(T, T)> G;
	int size;//2冪
	vector<M> val;//1-indexed
	vector<T> lazy;//遅延情報を入れる
	F f;//結合関数
	EVAL eval;//モノイドに作用素を作用させる関数
	G g;//作用素の結合関数 A->Bの順に作用させるとg(A, B)
	M em;//モノイドの単位元
	T et;//作用素の単位元

	lazy_segment_tree(int N, vector<M> &data, F f, EVAL eval, G g, M em, T et) : f(f), eval(eval), g(g), em(em), et(et){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, em);
		lazy.assign(2 * size, et);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = N; i < size; i++) val[size + i] = em;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	void propagate(int k){
		if(lazy[k] != et && k < size){
			lazy[2 * k + 0] = g(lazy[2 * k + 0], lazy[k]);
			lazy[2 * k + 1] = g(lazy[2 * k + 1], lazy[k]);
		}
		val[k] = eval(val[k], lazy[k]);
		lazy[k] = et;
	}

	//[l, r)に対してAを作用させたときの[s, t)の値を求める
	M update(int l, int r, T A, int k, int s, int t){
		propagate(k);
		if(t <= l || r <= s){
			return val[k];
		}
		else if(l <= s && t <= r){
			lazy[k] = g(lazy[k], A);
			propagate(k);
			return val[k];
		}
		else{
			return val[k] = f(update(l, r, A, 2 * k, s, (s + t) / 2), update(l, r, A, 2 * k + 1, (s + t) / 2, t));
		}

	}

	//[l, r)に対してAを作用させる
	void update(int l, int r, T A){
		M res = update(l, r, A, 1, 0, size);
	}

	M query(int l, int r, int k, int s, int t){
		propagate(k);
		if(t <= l || r <= s){
			return em;
		}
		else if(l <= s && t <= r){
			return val[k];
		}
		else{
			return f(query(l, r, 2 * k, s, (s + t) / 2), query(l, r, 2 * k + 1, (s + t) / 2, t));
		}
	}

	//[l, r)の演算の結果を返す
	M query(int l, int r){
		return query(l, r, 1, 0, size);
	}
};

//query:sum
//update:add
//(pair<int, int>, int, sum, eval, g, em, et)
//x = (値, 区間の長さ)
const pair<int, int> em(0, 0);
const int et = 0;

pair<int, int> sum(pair<int, int> x, pair<int, int> y){
	return pair<int, int>(x.first + y.first, x.second + y.second);
}

pair<int, int> eval(pair<int, int> x, int a){
	return pair<int, int>(x.first + a * x.second, x.second);
}

int g(int a, int b){
	return a + b;
}

int main(){
	int N, Q, i;
	scanf("%d%d", &N, &Q);
	vector<pair<int, int> > data(N + 1, pair<int, int>(0, 1));
	lazy_segment_tree<pair<int, int>, int> t(N + 1, data, sum, eval, g, em, et);
	for(i = 0; i < Q; i++){
		int c;
		scanf("%d", &c);
		if(c == 0){
			int l, r, x;
			scanf("%d%d%d", &l, &r, &x);
			t.update(l, r + 1, x);
//			printf("update(%d, %d, %d)\n", l, r + 1, x);
		}
		else{
			int k;
			scanf("%d", &k);
			printf("%d\n", t.query(k, k + 1).first);
		}
	}
	return 0;
}


Measured memory_bytes: 6820
import 'dart:async';
import 'dart:io';
import 'dart:convert';

Stream<String> get lineStream =>
    stdin.transform(utf8.decoder).transform(const LineSplitter());

Future<List<String>> readLines() async {
  final lines = <String>[];
  await for (var line in lineStream) {
    lines.add(line);
  }
  return lines;
}

void main() async {
  final lines = await readLines();
  final x = int.parse(lines[0]);
  var k = 1;
  while (((k * x) % 360) != 0) {
    k++;
  }
  print('$k');
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    rep(i, h) cin >> grid[i];
    vector<vector<int>> right(h, vector<int>(w, 0));
    vector<vector<int>> left(h, vector<int>(w, 0));
    vector<vector<int>> down(h, vector<int>(w, 0));
    vector<vector<int>> up(h, vector<int>(w, 0));

    rep(i, h) {
        int cnt = 0;
        rep(j, w) {
            if (grid[i][j] == '.') {
                right[i][j] = ++cnt;
            } else {
                cnt = 0;
            }
        }
        cnt = 0;
        for (int j = w - 1; j >= 0; j--) {
            if (grid[i][j] == '.') {
                left[i][j] = ++cnt;
            } else {
                cnt = 0;
            }
        }
    }
    rep(j, w) {
        int cnt = 0;
        rep(i, h) {
            if (grid[i][j] == '.') {
                down[i][j] = ++cnt;
            } else {
                cnt = 0;
            }
        }
        cnt = 0;
        for (int i = h - 1; i >= 0; i--) {
            if (grid[i][j] == '.') {
                up[i][j] = ++cnt;
            } else {
                cnt = 0;
            }
        }
    }
    int ans = 0;
    rep(i, h) {
        rep(j, w) {
            if (grid[i][j] == '.') {
                int score = right[i][j] + left[i][j] + down[i][j] + up[i][j] - 3;
                ans = max(ans, score);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 67200
import sys
S = list(str(input()))
length = len(S)

half = int((length-1)/2)
halfhalf = int(half/2)
condition3 = int((length+3)/2)

for i in range(half):
    if S[i] != S[-i-1]:
        print("No")
        sys.exit()
halfS = S[:half]
if len(halfS) == 1:
    pass
else:
    for i in range(halfhalf):
        if halfS[i] != halfS[-i-1]:
            print("No")
            sys.exit()

S3 = S[condition3-1:]
if len(S3) == 1:
    pass
else:
    half_S3 = int(len(S3)/2)
    for i in range(half_S3):
        if S3[i] != S3[-i-1]:
            print("No")
            sys.exit()
print("Yes")

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

int main(void){
    int t;
    int n,m,p;
    int ans;
    vector<int>x;
    while(true) {
        cin >> n>>m>>p;
        if(n==0)break;
        x=vector<int>(0);
        ans=0;
        for(int i=0;i<n;i++){
            cin>>t;
            x.push_back(t);
            ans+=t;
        }
        ans=ans*(100-p);
        if(x[m-1]!=0)ans=ans/x[m-1];
        else ans=0;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = -1e15;
const ll MOD = 1e9 + 7;
const int MAXN = 132000;

ll DP[MAXN];
ll hitung[MAXN];
int n;
ll A[20][20];

ll cari(ll now) {
	ll &ret = hitung[now];
	if (ret != INF) return ret;
	ret = 0;
	REP(i, n) {
		FOR(j, i + 1, n - 1) {
			if ((1 << i) & now) if ((1 << j) & now) {
				ret = (ret + A[i][j]);
			}
		}
	}
	return ret;
}

ll rek(ll now) {
	//cout << now << '\n';
	if (now == (1 << n) - 1) return 0;
	ll &ret = DP[now];
	if (ret != -1) return ret;
	ret = 0;
	ll sek = ~now;
	for(int i = 31; i >= n; i--) {
		//cout << sek << ' ' << (1 << i) << "MANTAP\n";
		sek = sek ^ (1 << i);
		
	}
	//cout << sek << "eA\n";
	for(ll i = sek; i; i = (i - 1) & sek) {
		ret = max(ret, cari(i) + rek(now | i));
	}
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	REP(i, n) REP(j, n) cin >> A[i][j];
	memset(DP, -1, sizeof DP);
	REP(i, MAXN) hitung[i] = INF;
	cout << rek(0) << '\n';
}

Measured memory_bytes: 2304
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s, ret;
  cin >> s;
  for (auto& c : s) {
    if (c == 'B') {
      if (ret.size()) ret.pop_back();
    } else {
      ret.push_back(c);
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d1 = []
    d2 = []
    for i in range(n):
        t = sys.stdin.readline().split()
        tmp = "".join(t)
        d1.append(int(tmp))
    for i in range(n):
        d2.append(na())

    ans = -10**9
    for i in range(1, 2 ** 10):
        cost = 0
        for j in range(n):
            b = i & int(str(d1[j]),2)
            b = list(format(b, "b"))
            b = [int(n) for n in b]
            b = sum(b)
            cost += d2[j][b]

        ans = max(ans, cost)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42712
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define ff first
#define ss second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int fact(int n,int in_mod){
    int f=1;
    for(int i=1;i<=n;i++) f=(f*i)%in_mod;
    return f;
}
int ncr(int n,int r,int in_mod){
    return (((fact(n,in_mod)*mod_inv(fact(r,in_mod),in_mod))%in_mod)*mod_inv(fact(n-r,in_mod),in_mod))%in_mod;
}

void solve()
{
    int x,n;
    cin>>x>>n;
    set<int> st;
    for(int i=0;i<n;i++) {
        int xx;
        cin>>xx;
        st.insert(xx);
    }
    for(int i=0;i<=105;i++){
        int a=x-i;
        if(!st.count(a)){
            cout<<a<<endl;
            return ;
        }
        a=x+i;
        if(!st.count(a)){
            cout<<a<<endl;
            return ;
        }
    }
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed<<setprecision(10);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    //cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((long double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
int r;
int n;
list<int>v;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>n;
    while(n--){
        int x;
        cin>>x;
        if(!r)v.push_back(x);
        else if(r)v.push_front(x);
        r=1-r;
    }
    if(!r)for(auto i=v.begin();i!=v.end();i++)cout<<*i<<' ';
    else for(auto i=v.rbegin();i!=v.rend();i++)cout<<*i<<' ';
}


Measured memory_bytes: 8448
a = input()

if a[0]=='R' and a[1]=='R' and a[2]=='R':
  res = 3
elif  a[0]=='R' and a[1]=='R':
  res = 2
elif  a[1]=='R' and a[2]=='R':
  res = 2  
elif  a[0]=='R':
  res = 1
elif  a[1]=='R':
  res = 1
elif  a[2]=='R':
  res = 1 
else:
  res = 0

res = int(res)
print(res)

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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, -1, 0, 1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;

class SegmentTree {
public:
    unsigned int n = 1;
    vector<int> dat;

    SegmentTree(const vector<int> &v) {
        while (n < v.size()) { n *= 2; }   // sz以上の最小の2冪
        dat.resize(2 * n - 1, INT_MAX);

        // 最下段
        for (int i = 0; i < v.size(); ++i) {
            dat[i + n - 1] = v[i];  // 最下段はn - 1からはじまる
        }
        // 木の全体を更新
        for (int i = n - 2; i >= 0; --i) {
            dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    // 元の配列でのidxをxにし、木を更新
    void update(int idx, int x) {
        idx += n - 1;   // 木での対象のインデックス
        dat[idx] = x;
        while (idx > 0) {
            idx = (idx - 1) / 2;                                  // 親のインデックス
            dat[idx] = min(dat[idx * 2 + 1], dat[idx * 2 + 2]);   // 左の子と右の子
        }
    }

    // 区間[a, b)の最小値
    int query(int a, int b) {
        return this->query(a, b, 0, 0, n);
    }

private:

    // [a, b)の最小値をノードk（区間[l, r]）から検索
    int query(int a, int b, int k, int l, int r) {
        assert(a < b && l < r);
        // 範囲外
        if (r <= a || b <= l) {
            return INT_MAX;
        }
        // 完全に含む
        if (a <= l && r <= b) {
            return this->dat[k];
        }
            // 一部含む
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);    // 左の子
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);    // 右の子
            return min(vl, vr);
        }
    }
};


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

    int N, Q;
    cin >> N >> Q;

    vector<int> v(N, 2147483647);
    SegmentTree st(v);
    FOR(i, 0, Q) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            st.update(x, y);
        }
        else {
            print(st.query(x, y + 1));
        }
    }
}




Measured memory_bytes: 4204
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

int main()
{
    int N;
    std::cin >> N;

    int x[N] = {0};
    int y[N] = {0};
    int h[N] = {0};
    for (int i = 0; i < N; ++i) {
        std::cin >> x[i] >> y[i] >> h[i];
    }

    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            int buf = 0, H = 0, x_ans = i, y_ans = j;
            bool solved = true;
            for (int k = 0; k < N; ++k) {
                if (h[k] != 0) {
                    H = h[k] + std::abs(i - x[k]) + std::abs(j - y[k]);
                    break;
                }
            }

            for (int k = 0; k < N; ++k) {
                if (h[k] != std::max(H - std::abs(i - x[k]) - std::abs(j - y[k]), 0)) {
                    solved = false;
                    break;
                }
            }

            if (solved) {
                std::cout << x_ans << " " << y_ans << " " << H << std::endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
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, a[N];

void solve(){

   int health1, strength1;
   int health2, strength2;

   cin >> health1 >> strength1;
   cin >> health2 >> strength2;

   int turn = 0;
   while(true){
      
      if (turn == 0){
         health2 -= strength1;
         if (health2 <= 0){
            cout<<"Yes";
            return ;
         }
      }
      else{
         health1 -= strength2;
         if (health1 <= 0){
            cout<<"No";
            return ;
         }
      }
      turn = 1 - turn;
   }

}

int32_t main(){_
   
   int t = 1;
   //cin >> t;

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

   return 0;
}

Measured memory_bytes: 3652
import java.io.*;
import java.util.*;
 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      //begin
      out.println((int) (Math.pow(sc.nextInt(), 2)) * 3);
      //end
      out.close();
   }
 
   public static PrintWriter out;
      
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
      long nextLong() {
          return Long.parseLong(next());
      }
      double nextDouble() {
          return Double.parseDouble(next());
      }
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

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

const ll mod = 1e9 + 7;
ll n, a, b, c, d;
ll dp[1010][1010];
ll fact[1010], fact_inv[1010], inv[1010];

long long mod_pow(long long x, long long n){
    if(n == 0) return 1;
    long long res = mod_pow(x * x % mod, n / 2);
    if(n & 1) res = res * x % mod;
    return res;
}

long long combination(long long n, long long k){
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod;
}

int main(){
    cin >> n >> a >> b >> c >> d;
    
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < 1010; i++) dp[i][0] = 1;

    fact[0] = fact_inv[0] = 1;
    for(int i = 1; i < 1010; i++){
        inv[i] = mod_pow(i, mod - 2);
        fact[i] = fact[i - 1] * i % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }

    for(int i = a; i <= b; i++){
        for(int j = 0; j <= n; j++){
            if(dp[i][j] == 0) continue;
            ll p = 1;
            if(j != 0) (dp[i + 1][j] += dp[i][j]) %= mod;
            for(int k = 1; k <= d; k++){
                if(j + i * k > n) break;
                p = p * combination(n - j - i * (k - 1), i) % mod * inv[k] % mod;
                if(c <= k && k <= d){
                    (dp[i + 1][j + i * k] += dp[i][j] * p % mod) %= mod;
                    // cout << i << ' ' << j << ' ' << k << ' ' << p << " " <<   dp[i][j] << ' ' << dp[i + 1][j + i * k] << endl;              
                }
            }
        }
    }
    // for(int i = a; i <= b + 1; i++){
    //     for(int j = 0; j <= n; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[b + 1][n] << endl;
}

Measured memory_bytes: 8320
import scala.collection._
import scala.collection.generic._
import scala.io.StdIn

object Main extends App {
  val inputs = StdIn.readLine().split(" ")
  val stack = inputs.foldLeft(new Stack()){ (acc, elem) => acc.push(elem) }
  println(stack.pop)
}

class Stack(val elems: List[String]){
  def this() = this(Nil)

  def push: (String) => Stack = {
    case "+" =>
      val (x1, x2, xs) = pop2
      new Stack((x1 + x2).toString :: xs)
    case "-" =>
      val (x1, x2, xs) = pop2
      new Stack((x2 - x1).toString :: xs)
    case "*" =>
      val (x1, x2, xs) = pop2
      new Stack((x1 * x2).toString :: xs)
    case elem =>
      new Stack(elem :: elems)
  }

  def pop: String = elems.head

  def pop2: (Int, Int, List[String]) = {
    elems match {
      case x1 :: x2 :: xs =>
        (x1.toInt, x2.toInt, xs)
      case _ => (0, 0, elems)
    }
  }
}

Measured memory_bytes: 43692