akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int N,C;
struct edge
{
    int from,to,cost;
    edge(int from,int to,int cost):from(from),to(to),cost(cost){}
};
vector<edge> es,both;
vector<T> other;
int K;
int D[105];
int bellmanford(int x)
{
    for(int i=0;i<N;i++)D[i]=INF;
    D[0]=0;
    vector<int> v;
    for(int i=0;i<K;i++)v.pb((x>>i)&1);
    both.clear();
    for(int i=0;i<K;i++)
    {
        int a,b,c;
        a = other[i].fi.fi;
        b = other[i].fi.sec;
        c = other[i].sec;
        if(v[i]==0)
        {
            both.pb(edge(b,a,0));
            if(c>0)both.pb(edge(a,b,c));
            else both.pb(edge(b,a,c));
        }
        else
        {
            both.pb(edge(a,b,0));
            if(c>0)both.pb(edge(b,a,c));
            else both.pb(edge(a,b,c));
        }
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<es.size();j++)
        {
            if(D[es[j].from]<INF&&D[es[j].to]>D[es[j].from]+es[j].cost)
            {
                if(i==N-1)return -1;
                D[es[j].to]=D[es[j].from]+es[j].cost;
            }
        }
        for(int j=0;j<both.size();j++)
        {
            if(D[both[j].from]<INF&&D[both[j].to]>D[both[j].from]+both[j].cost)
            {
                if(i==N-1)return -1;
                D[both[j].to]=D[both[j].from]+both[j].cost;
            }
        }
    }
    for(int i=0;i<N;i++)if(D[i]<0)return -1;
    int ret = 0;
    for(int i=0;i<N;i++)ret=max(ret,D[i]);
    return ret;
}
int main()
{
    scanf("%d %d",&N,&C);
    for(int i=0;i<C;i++)
    {
        string s;
        cin >> s;
        stringstream ss(s);
        int a,b,d;
        char op,ig,sign;
        ss >> a >> op;
        if(op!='*')ss >> ig;
        ss >> b >> sign >> d;
        a--;b--;
        if(op=='*')other.pb(T(P(a,b),(sign=='+'?-1:1)*d));
        else
        {
            if(op=='<')
            {
                es.pb(edge(b,a,0));
                if(sign=='-')es.pb(edge(a,b,d));
                else es.pb(edge(b,a,-d));
            }
            else
            {
                es.pb(edge(a,b,0));
                if(sign=='-')es.pb(edge(b,a,d));
                else es.pb(edge(a,b,-d));
            }
        }
    }
    K = (int)other.size();
    int ans = -1;
    for(int i=0;i<(1<<K);i++)ans = max(ans,bellmanford(i));
    if(ans==INF)printf("inf\n");
    else printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1300
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int rect = 0, diamond = 0;
		while (sc.hasNext()) {
			String[] ss = sc.next().split(",");
			int a = Integer.parseInt(ss[0]);
			int b = Integer.parseInt(ss[1]);
			int c = Integer.parseInt(ss[2]);
			if( a == b ) diamond++;
			if ( a * a + b * b == c * c)
				rect++;
		}
		System.out.println(rect);
		System.out.println(diamond);
		
	}

}

Measured memory_bytes: 12000
n = int(input())
mod = 10 ** 9 + 7

ten = [10]
nine = [9]
eight = [8]
for i in range(20):
    ten.append(ten[-1] ** 2 % mod)
    nine.append(nine[-1] ** 2 % mod)
    eight.append(eight[-1] ** 2 % mod)
ans = 0
num = bin(n)[2:]
temp10 = 1
temp9 = 2
temp8 = 1
for i in range(len(num)):
    if num[-i-1] == "1":
        temp10 *= ten[i]
        temp10 %= mod
        temp9 *= nine[i]
        temp9 %= mod
        temp8 *= eight[i]
        temp8 %= mod
ans = ans + temp10 - temp9 + temp8
ans %= mod
print(ans)

Measured memory_bytes: 9224
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long LL;
int main()
{
    int n,a[1005];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    int ans=1e9,t;
    for(int i=a[0];i<=a[n-1];i++)
    {
        t=0;
        for(int j=0;j<n;j++)
            t+=(i-a[j])*(i-a[j]);
        ans=min(ans,t);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{
    int n;
    int[] u, v, w, ans;
    bool[] visited;
    List<int>[] x, y;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');

        n = int.Parse(input[0]);
        u = new int[n];
        v = new int[n];
        w = new int[n];
        ans = new int[n];
        x = new List<int>[n];
        y = new List<int>[n];
        visited = new bool[n];
        for (int i = 0; i < n; i++)
        {
            x[i] = new List<int>();
            y[i] = new List<int>();
        }
        
        for(int i=0; i<n- 1; i++)
        {
            input = Console.ReadLine().Split(' ');
            u[i] = int.Parse(input[0]) - 1;
            v[i] = int.Parse(input[1]) - 1;
            w[i] = int.Parse(input[2]);

            x[u[i]].Add(v[i]);
            y[u[i]].Add(w[i]);
            x[v[i]].Add(u[i]);
            y[v[i]].Add(w[i]);
        }
        visited[0] =true;
        Solve(0);
        for (int i = 0; i < n; i++) Console.WriteLine(ans[i]);

    }

    public void Solve(int a)
    {
        DebugWL(a);
        for(int i=0; i<x[a].Count; i++)
        {
            if (!visited[x[a][i]])
            {
                visited[x[a][i]] = true;
                ans[x[a][i]] = ans[a] ^ (y[a][i] % 2);
                Solve(x[a][i]);
            }
        }
    }

    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 36484
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int t, c, a[5000], p=0;
  bool f, pr[30001];

  fill(pr, pr+30001, false);
  pr[2] = true;
  a[p++] = 2;
  for(int i = 3; i <= 30000; i+=2){
    f = true;
    for(int j = 3; j*j <= i; j+=2){
      if(i%j == 0){
	f = false;
	break;
      }
    }
    pr[i] = f;
    if(f){
      a[p++] = i;
    }
  }

  while(1){
    cin >> t;
    if(t == 0){
      break;
    }
    c = 0;

    for(int i = 0; a[i] < t/2; i++){
      int s = t - a[i];
      for(int j = i; s-a[j] < t && s-a[j] >= a[j]; j++){
	if(pr[s-a[j]]){
	  if(a[i] == a[j] && a[i] == s-a[j]){
	    c++;
	    break;
	  } else if(a[i]+a[j] > s-a[j]){
	    c++;
	  }
	}
      }
    }

    cout << c << endl;
  }

  return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

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

    int num_0 = 0;
    int num_1 = 0;
    REP(i,s.size()){
        if(s[i] == '0'){
            num_0++;
        }else{
            num_1++;
        }
    }

    cout<<2*min(num_0,num_1)<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int a,b,c,min;
  scanf("%d %d %d",&a,&b,&c);
   
  min = a + b;
  
  if( min > b + c) {
    min = b + c;
  }
  
  if( min > c + a) {
    min = c + a;
  }

  printf("%d", min);
  
}

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

using namespace std;
const int dx[2][6] = {{-1,  0,  1, 1, 1, 0}, {-1, -1,  0, 1, 0, -1}};
const int dy[]     = { 0, -1, -1, 0, 1, 1};
int field[102][102];
int W, H;
int ans;

void DFS(int x, int y)
{
	field[y][x] = 2;
	for(int i = 0; i < 6; ++i)
	{
		int nx = x + dx[(y + 1) % 2][i];
		int ny = y + dy[i];
		if(0 <= nx && nx <= W + 1 && 0 <= ny && ny <= H + 1)
		{
			if(field[ny][nx] == 1)
			{
				++ans;
			}
			else if(field[ny][nx] == 0)
			{
				DFS(nx, ny);
			}
		}
	}
}

void solve()
{
	cin >> W >> H;
	for(int i = 1; i <= H; ++i)
	{
		for(int j = 1; j <= W; ++j)
		{
			cin >> field[i][j];
		}
	}
	DFS(0, 0);
	cout << ans << endl;
}

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

Measured memory_bytes: 1444
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main(void) {
    char s1[300];
    char s2[101];
    char p[101];
    scanf("%s",s2);
    scanf("%s",p);
    
    strcpy(s1,s2);
    strcat(s1,s2);
    if(strstr(s1,p) == NULL){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}





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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    vector<int>r(5);
    rep(i, 5)cin >> r[i];
    sort(all(r));
    int index = 0,fast=10000,time=0;
    do {
        index = 0,time=0;
        while (index < 5) {
            if (time % 10 == 0) {
                time += r[index];
                index++;
            }
            else time++;
        }
        fast = min(fast, time);
    } while (next_permutation(all(r)));
    cout << fast << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll h, n;
    cin >> h >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vvl dp(n + 1, vl(20001, INF));
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 20000; j >= 0; --j) {
            chmin(dp[i][j], dp[i - 1][j]);
        }
        for (int j = 0; j <= 20000; ++j) {
            if (j - a[i - 1] >= 0 && dp[i][j - a[i - 1]] != INF)
                chmin(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]);
        }
    }
    ll ret = INF;
    for (int i = h; i <= 20000; ++i) {
        chmin(ret, dp[n][i]);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 160640
#include <cstdio>

int main(void)
{
	long a, b, c;
	long res;
	scanf("%ld %ld %ld", &a, &b, &c);
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		res = 0;
	}
	else if (a >= b && a >= c) {
		res = b * c;
	}
	else if (b >= a && b >= c) {
		res = a * c;
	}
	else {
		res = a * b;
	}

	printf("%ld\n", res);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int h[100000];
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	char	str[256];
	
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &h[i]);
	}

	for(i=n-1;i>0;i--) {
		if (h[i-1]>h[i]) h[i-1]--;
		if (h[i-1]>h[i]) { printf("No\n"); return 0; }

	}
	
	printf("Yes\n");


	return 0;
}


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

typedef long long ll;
const int N = 1e6 + 7;
const ll mod = 1e9 + 7;
int a[N], n, vis[N];

vector<int>G[N];
void init(){
    int top = 0;
    for(int i = 1; i <= 1000; i++){
        for(int j = i ; j < N; j += i){
            if(i * i <= j){
                //sum[j] += i;
                G[j].push_back(i);
                if(j / i != i){
                   // sum[j] += (j / i);
                    G[j].push_back(j / i);
                }
            }
        }
    }

}


int main() {
    ios::sync_with_stdio(0);
    init();
    cin >> n;
    int f = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (f == 1) continue;
        for (int j = 0; j < G[a[i]].size(); j++) {
            if (G[a[i]][j] == 1) continue;
            if (vis[G[a[i]][j]] == 1) {
                f = 1;
                break;
            }
            vis[G[a[i]][j]]++;
        }
    }
    if (f == 0) {
        cout << "pairwise coprime\n";
    } else {
        int ans = a[1];
        for (int i = 2; i <= n; i++) {
            ans = __gcd(a[i], ans);
        }
        if (ans == 1) {
            cout << "setwise coprime\n";
        } else {
            cout << "not coprime\n";
        }
    }
    
    
  

   
}

Measured memory_bytes: 127320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll a[maxn],b[maxn];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<=n;i++)
	{
		cin>>a[i];
	}
//	cout<<"?"<<endl;
	for(int i=0;i<=n-1;i++)
	{
		cin>>b[i];
	}
	ll ans=0,pos=1,flag=0;
	for(int i=0;i<=n-1;i++)
	{
		if(b[i]>=a[i])
		{
			b[i]-=a[i];
			ans+=a[i];
			a[i]=0;
			if(b[i]>=a[i+1])
			{
				ans+=a[i+1];
				a[i+1]=0;
			}
			else
			{
				a[i+1]-=b[i];
				ans+=b[i];
			}
		}
		else
		{
			ans+=b[i];
			a[i]-=b[i];
		}
		
//		cout<<ans<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a>=b)
  {
      for(int i=1;i<=a;i++)
      {
          cout<<b;
      }
  }
  else if(b>a)
  {
      for(int j=1;j<=b;j++)
        cout<<a;
  }
return 0;
}



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

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

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

    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    if(s.size() == 4) cout << "Four" << endl;
    else if(s.size()==3) cout << "Three" << endl;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& vec){
    os << "[";
    for(const auto& v : vec){
        os << v << ",";
    }
    os << "]";
    return os;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const ll MOD = 1e9+7;
ll fact[200002];
ll fact_inv[200002];

ll mod_pow(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res = (res*x)%mod;
        x = (x*x)%mod;
        n>>=1;
    }
    return res;
}

ll invp(ll x,ll mod){
    return mod_pow(x,mod-2,mod);
}

ll nCr(ll n,ll r,ll mod){
    assert(n>=r);
    ll ret = fact[n];
    ret = (ret * fact_inv[r]) % mod;
    ret = (ret * fact_inv[n-r]) % mod;
    return ret;
}

int main(){
    ll H,W,A,B;
    cin>>H>>W>>A>>B;

    fact[0]=1;
    for(int i=1;i<200002;i++) fact[i]=(fact[i-1]*i)%MOD;
    for(int i=0;i<200002;i++) fact_inv[i]=invp(fact[i],MOD);


    ll ans = 0;
    for(int i=B+1;i<=W;i++){
        int le = i-1;
        int hi = H-A-1;
        ll tmp1 = nCr(le+hi,hi,MOD);
        int ri = W-i;
        int un = A-1;
        ll tmp2 = nCr(ri+un,un,MOD);
        ll tmp = (tmp1 * tmp2) % MOD;
        ans = (ans+tmp) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
N = int(input())

if N == 1:
    print(1)
    exit()

lis = []
tmp = 0
for n in range(N+1):
    tmp += n
    lis.append(tmp)
    if tmp>=N:
        break

iranaiKazu = lis[-1] - N
for i in range(1,len(lis)):
    if i == iranaiKazu:
        continue
    print(i)

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

int main(){
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    ll x;
    cin >> x;
    double y;
    cin >> y;
    
    ll y1 = 100*y + 0.5;
    x *= y1;
    x = x/100;
    cout << x << endl;
}

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

int main()
{
	int A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	cout << (C * max(0, -A) + (A <= 0 ? D : 0) + E * (B - max(0, A))) << endl;
	return 0;
}



Measured memory_bytes: 3092
N, Q = map(int, input().split())
S = str(input())
SD = {}

cnt = 0
for n in range(1, N):
    if S[n-1] + S[n] == "AC":
        cnt += 1
    SD[n] = cnt

for q in range(1, Q+1):
    l, r = map(int, input().split())
    print(SD.get(r-1, 0)-SD.get(l-1, 0))


Measured memory_bytes: 16624
#include <vector>
#include <unordered_set>
#include <cstdio>
using namespace std;

namespace std{
	template<typename T>
	inline void hash_combine(size_t& seed, T const& v){
		seed ^= hash<T>()(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
	}
	template<typename A,typename B>
	class hash<pair<A,B>>{
		public:
		size_t operator()(pair<A,B> const &p) const{
			size_t seed=0;
			hash_combine(seed,p.first);
			hash_combine(seed,p.second);
			return seed;
		}
	};
}

int main(){
	long long H,W;
	int N;
	scanf("%lld%lld%d",&H,&W,&N);
	vector<long long>v(10);
	unordered_set<pair<int,int>>points;
	v[0]=(H-2)*(W-2);
	for(;N--;){
		int h,w;
		scanf("%d%d",&h,&w);h--,w--;
		points.emplace(h,w);
		for(int h0=-1;h0<2;h0++)for(int w0=-1;w0<2;w0++){
			if(1<=h+h0&&h+h0<H-1 && 1<=w+w0&&w+w0<W-1){
				int t=0;
				for(int h1=-1;h1<2;h1++)for(int w1=-1;w1<2;w1++){
					t+=points.find({h+h0+h1,w+w0+w1})!=points.end();
				}
				v[t-1]--;
				v[t]++;
			}
		}
	}
	for(auto &e:v)printf("%lld\n",e);
}

Measured memory_bytes: 4388
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<typename T>
void chmax(T &a, T b) {
    a = max(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int nlist[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    REP(i, 0, M) {
        cin >> A[i];
    }
    sort(rbegin(A), rend(A));
    auto dp = make_v(N + 1, -1);
    dp[N] = 0;
    for (int i = N; i > 0; i--) {
        if (dp[i] != -1) {
            REP(j, 0, M) {
                int cnt = nlist[A[j] - 1];
                if (i - cnt >= 0) {
                    chmax(dp[i - cnt], dp[i] + 1);
                }
            }
        }
    }
    int R = 0;
    while (R < N) {
        REP(j, 0, M) {
            int cnt = nlist[A[j] - 1];
            if (R + cnt <= N && dp[R] == dp[R + cnt] + 1) {
                cout << A[j];
                R += cnt;
                break;
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define SUM(a) accumulate(all(a), int(0))
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

signed main() {
  int a;
  cin >> a;
  string b;
  cin >> b;
  b = b.substr(0, b.size() - 3) + b.substr(b.size() - 2, 2);
  int c = stoi(b);
  int ans = a * c / 100;
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

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 (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll dp[3005];

int main() {
    ll N, T;
    cin >> N >> T;
    vc<pair<ll, ll>> A(N);
    rep(i, N) cin >> A[i].first >> A[i].second;
    sort(all(A));

    ll ans = 0;
    vl M(N + 1);
    repr(i, N) M[i] = max(M[i + 1], A[i].second);

    rep(i, N){
        auto [w, v] = A[i];
        chmax(ans, dp[T - 1] + M[i]);
        repr(j, T - w) chmax(dp[j + w], dp[j] + v);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3724
a,b,c,d,=map(int,input().split())
x=a*c
y=a*d
z=b*c
w=b*d
s=b*d
if(w<x and z<x and y<x):
  print(x)
elif(w<y and z<y and x<y):
  print(y)
elif(w<z and x<z and y<z):
  print(z)
elif(y<w and z<w and x<w):
  print(w)
else:
  print(s)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int total = A + B + C;
	if (total >= 22)cout << "bust";
	else cout << "win";
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		long[] A = new long[N];
		for(int i = 0; i < N; i++)
			A[i] = GetLong();

		Comparison<Tuple<long, int>> comp = ((x, y) => x.Item1.CompareTo(y.Item1));
		var pq = new PriorityQueue<Tuple<long, int>>(N + 1, comp);
		for(int i = 0; i < N; i++)
			pq.Push(Tuple.Create(A[i], 1));

		while(pq.Size > 1)
		{
			var min = pq.Pop();
			var semiMin = pq.Pop();
			long newSize = min.Item1 + semiMin.Item1;
			if(min.Item1 * 2 >= semiMin.Item1)
				pq.Push(Tuple.Create(newSize, min.Item2 + semiMin.Item2));
			else
				pq.Push(Tuple.Create(newSize, semiMin.Item2));
		}

		Console.WriteLine(pq.Pop().Item2);
	}
}


public class PriorityQueue<T>
{
	public long Size { get; private set; } = 0;
	public long MaxSize { get; private set; } = 0;
	private T[] m_heap;
	private Comparison<T> Comp = null;
	
	public PriorityQueue(long maxSize, Comparison<T> comp)
	{
		if(maxSize <= 0)
			throw new Exception();
		MaxSize = maxSize;
		m_heap = new T[maxSize];

		Comp = comp;
	}
	
	public void Push(T x)
	{
		if(Size == MaxSize)
			throw new Exception("Queue is full.");
		
		long i = Size++;
		while(i > 0)
		{
			long p = (i - 1)/2;
			if(Comp(m_heap[p], x) <= 0)
				break;
			m_heap[i] = m_heap[p];
			i = p;			
		}
		m_heap[i] = x;		
	}
	
	public T Pop()
	{
		if(Size == 0)
			throw new Exception("Queue is empty.");
		
		T result = m_heap[0];
		T x = m_heap[--Size];
		long i = 0;
		while(i * 2 + 1 < Size)
		{
			long c1 = i * 2 + 1, c2 = i * 2 + 2;
			if(c2 < Size && Comp(m_heap[c2], m_heap[c1]) < 0)
				c1 = c2;
			if(Comp(m_heap[c1], x) >= 0)
				break;
			m_heap[i] = m_heap[c1];
			i = c1;
		}
		m_heap[i] = x;
		
		return result;		
	}	
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 29916
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DIHateFactorization {
public:
    ll f(ll a) {
      return a*a*a*a*a;
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll x; cin >> x;
      ll a = -1000;
      while(true) {
        ll mi = -2000;
        ll ma = a;
        while (mi+1 < ma) {
          ll med = (mi+ma)/2;
          //debug(a, mi, ma, med);

          if (f(a)-f(med) < x) {
            ma = med;
          } else if (f(a)-f(med) == x) {
            cout << a << ' ' << med << endl;
            return;
          } else {
            mi = med;
          }
        }
        a++;
      }
    }


};

signed main() {
  DIHateFactorization solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include <string.h>
int main(){
 char C[11];
 char D[11];
 int i=0;
 scanf("%s",C);
 scanf("%s",D);
 int p=strlen(C);
 for(i=0;i<p+1;i++){
   if(i==p){
    printf("Yes");
   }
   else if(C[i]!=D[i]){
    printf("No");
    break;
   }
 }
 return 0;
}

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

struct UnionFind
{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n)
    {
        for (auto i = 0; i < n; i++)
        {
            par.push_back(i);
            sizes.push_back(1);
        }
    }

    int find(int x)
    {
        if (x == par[x])
        {
            return x;
        }
        else
        {
            return par[x] = find(par[x]);
        }
    }

    // 2つのデータx, yが属する木をマージする
    void unite(int x, int y)
    {
        // データの根ノードを得る
        x = find(x);
        y = find(y);

        // 既に同じ木に属しているならマージしない
        if (x == y)
            return;

        // xの木がyの木より大きくなるようにする
        if (sizes[x] < sizes[y])
            swap(x, y);

        // xがyの親になるように連結する
        par[y] = x;
        sizes[x] += sizes[y];
        // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
    }

    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    // データxが含まれる木の大きさを返す
    int size(int x)
    {
        return sizes[find(x)];
    }
};

struct Edge
{
    int a, b, cost;

    bool operator<(const Edge &o) const
    {
        return cost < o.cost;
    }
};

struct Graph
{
    int n;
    vector<Edge> es;

    int kruskal()
    {
        sort(es.begin(), es.end());
        UnionFind uf(n);
        int min_cost = 0;
        for (auto i = 0; i < es.size(); i++)
        {
            Edge& e = es[i];
            if (!uf.same(e.a, e.b))
            {
                min_cost += e.cost;
                uf.unite(e.a, e.b);
            }
        }
        return min_cost;
    }
};

Graph input_graph(){
    Graph g;
    int n;
    cin >> n;
    g.n = n;
    pair<int, int> node[n];
    pair<int, int> node_x[n];
    pair<int, int> node_y[n];

    for (auto i = 0; i < n; i++)
    {
        cin >> node[i].first >> node[i].second;
    }

    for (auto i = 0; i < n ; i++)
    {
        node_x[i].first = node[i].first;
        node_x[i].second = i;

        node_y[i].first = node[i].second;
        node_y[i].second = i;
    }
    sort(node_x, node_x + n);
    sort(node_y, node_y + n);

    for (auto i = 0; i < n - 1; i++)
    {
        Edge e1, e2;
        e1.a = node_x[i].second;
        e1.b = node_x[i+1].second;
        e1.cost = abs(node_x[i + 1].first - node_x[i].first);
        g.es.push_back(e1);

        e2.a = node_y[i].second;
        e2.b = node_y[i+1].second;
        e2.cost = abs(node_y[i + 1].first - node_y[i].first);
        g.es.push_back(e2);
    }
    

    return g;

}

int main()
{
    Graph g = input_graph();
    cout << g.kruskal() << endl;
    return 0;
}

Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=1e5+5;
int mul(int a,int b){return (long long)a*b;}
typedef long long ll;
int n,x,a[N];
int main()
{
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int now=0,ans=1;
    for(int i=1;i<=n;i++)
    {
        if(now+a[i]>x) break;
        now+=a[i];
        ans++;
    }
    cout<<ans<<endl;
}


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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 2e5+100;
const int LOG = 20;

int a[N];
int nxt[N][LOG], prv[N][LOG];
long long nxt_sum[N][LOG], prv_sum[N][LOG];

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, K;
    cin >> n >> K;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 1; i <= n; i++) {
        if(a[n]-a[i] < K) nxt[i][0] = -1;
        else {
            int lo = i+1, hi = n;
            while(hi > lo) {
                int mid = lo+hi>>1;
                if(a[mid]-a[i] >= K) hi = mid;
                else lo = mid+1;
            }
            nxt[i][0] = lo;
        }
        nxt_sum[i][0] = i;
    }
    for(int i = 1; i <= n; i++) {
        if(a[i]-a[1] < K) prv[i][0] = -1;
        else {
            int lo = 1, hi = i-1;
            while(hi > lo) {
                int mid = (lo+hi+1)>>1;
                if(a[i]-a[mid] >= K) lo = mid;
                else hi = mid-1;
            }
            prv[i][0] = lo;
        }
        prv_sum[i][0] = i;
    }

    for(int k = 1; k < LOG; k++) {
        for(int i = 1; i <= n; i++) {
            if(nxt[i][k-1] == -1) nxt[i][k] = -1;
            else {
                nxt[i][k] = nxt[nxt[i][k-1]][k-1];
                nxt_sum[i][k] = nxt_sum[i][k-1] + nxt_sum[nxt[i][k-1]][k-1];
            }

            if(prv[i][k-1] == -1) prv[i][k] = -1;
            else {
                prv[i][k] = prv[prv[i][k-1]][k-1];
                prv_sum[i][k] = prv_sum[i][k-1] + prv_sum[prv[i][k-1]][k-1];
            }
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int l, r;
        cin >> l >> r;
        int m = 1;
        int cur = l;
        for(int k = LOG-1; k >= 0; k--) {
            if(nxt[cur][k] != -1 && nxt[cur][k] <= r) {
                cur = nxt[cur][k];
                m += (1<<k);
            }
        }
        int curl = l, curr = r;
        long long lsum = 0, rsum = 0;
        for(int k = LOG-1; k >= 0; k--) {
            if((m >> k) & 1) {
                lsum += nxt_sum[curl][k];
                rsum += prv_sum[curr][k];
                curl = nxt[curl][k];
                curr = prv[curr][k];
            }
        }
        long long ans = rsum - lsum + m;
        cout << ans << "\n";
    }
}





Measured memory_bytes: 98168
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    char ch;
    cin>>ch;
    if(ch >='a')
        cout<<"a";
    else
        cout<<"A";
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 3608
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <functional>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

int ar[4];

int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //srand(time(NULL));
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    int n = 4;
    forn(i, n)
        cin >> ar[i];
    sort(ar, ar + 4);
    if (ar[0] == 1 && ar[1] == 4 && ar[2] == 7 && ar[3] == 9)
        cout << "YES";
    else
        cout << "NO";


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n,u,v;
    cin >> n >> u >> v;

    vector<int> tmpv;
    vector<vector<int>> edge(n + 1, tmpv);

    rep(i,n){
        int a,b;
        cin >> a >> b;

        edge[a].pback(b);
        edge[b].pback(a);
    }


    if(u != v){
        vector<int> aoki_step(n + 1, -1);
        queue<pair<int,int>> q;
        q.push(mpair(v, 0));

        while(!q.empty()){
            int node = q.front().first;
            int step = q.front().second;

            if(aoki_step[node] == -1){
                aoki_step[node] = step;

                rep(i, edge[node].size()){
                    q.push(mpair(edge[node][i], step + 1));
                }
            }

            q.pop();
        }

        //aoki_stepが完成、

        vector<int> tak_step(n + 1, -1);

        q.push(mpair(u, 0));

        while(!q.empty()){
            int node = q.front().first;
            int step = q.front().second;

            if(tak_step[node] == -1){
                tak_step[node] = step;

                rep(i, edge[node].size()){
                    q.push(mpair(edge[node][i], step + 1));
                }
            }

            q.pop();
        }

        int ans = 0;

        rep(i,n){
            //cerr << aoki_step[i + 1] << " " << tak_step[i + 1] << endl;
            if(aoki_step[i + 1] >= tak_step[i + 1]){
                ans = max(ans, aoki_step[i + 1]);
            }
        }

        cout << ans - 1 << endl;

    }else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 6784
n = int(input())

ma = 0
prem = 0
maxi = -1
for i in range(n):
  x = int(input())
  
  if ma < x:
    prem = ma
    ma = x
    maxi = i
    
  elif prem < x:
    prem = x
    
for i in range(n):
  if maxi == i:
    print(prem)
  else:
    print(ma)

Measured memory_bytes: 4668
n, q = gets.split.map(&:to_i)
processes = readlines.map(&:split).each { |p| p[1] = p[1].to_i }

time = 0
until processes.empty?
  p = processes.shift
  p[1] = p[1] - q
  time += q
  if p[1] > 0  # 残っていれば末尾に回す
    processes.push(p)
  else
    time += p[1]
    puts "#{p[0]} #{time}"
  end
end



Measured memory_bytes: 19032
#include <iostream>
#include<algorithm>
#include <string>
#include<vector> 
#include<queue>
using namespace std;

int main() {
	int n; cin >> n;
	int a, b, c;
	
	while (true) {
		a = (n / 100);
		b = (n - (100 * a)) / 10;
		c = (n - (100 * a) - (10 * b));
		if (a == b && b == c) {
			cout << n << endl;
			return 0;
		}
		else n++;
	}
	return 0;

}


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

namespace ABC175
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            int n = int.Parse(Console.ReadLine());
            int[] l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(l);
            Array.Reverse(l);
            int ans = 0;
            if(n < 3)
            {
                Console.WriteLine(0);
                return;
            }
            for(int i = 0; i < n - 2; i++)
            {
                for(int j = i + 1; j < n -1; j++)
                {
                    for(int k = j + 1; k < n; k++)
                    {
                        if (l[i] < l[j] + l[k] && l[i] != l[j] && l[j] != l[k] && l[i] != l[k])
                        {
                            //Console.WriteLine("{0} {1} {2}", l[i], l[j], l[k]);
                            ans++;
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

typedef long long ll;
constexpr ll INF = LLONG_MAX;

struct M{
    ll all, lmax, rmax, mmax;
};

template <typename Monoid>
struct SegmentTree{
private:
    using F = function<Monoid(Monoid, Monoid)>;
    int N;
    vector<Monoid> node;
    F f;
    Monoid e;  // identity element

public:
    SegmentTree(){}
    SegmentTree(F f, Monoid e):f(f), e(e){}
    void init(int sz){
        N = 1;
        while(N < sz) N <<= 1;
        node.assign(2*N-1, e);
    }
    void build(vector<Monoid>& v){
        int sz = int(v.size());
        init(sz);
        for(int i=0; i<sz; i++){
            node[i+N-1] = v[i];
        }
        for(int i=N-2; i>=0; i--){
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }
    void update(int k, Monoid x){
        k += N-1;
        node[k] = x;
        while(k > 0){
            k = (k-1)/2;
            node[k] = f(node[2*k+1], node[2*k+2]);
        }
    }
    // [a,b)
    Monoid query(int a, int b){return query(a, b, 0, 0, N);}
    Monoid query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a) return e;
        if(a <= l && r <= b) return node[k];
        Monoid vl, vr;
        vl = query(a, b, 2*k+1, l, (l+r)/2);
        vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

auto M_merge = [&](M a, M b){
    M res;
    res.all = a.all + b.all;
    res.lmax = max(a.lmax, a.all + b.lmax);
    res.rmax = max(b.rmax, a.rmax + b.all);
    res.mmax = max({a.mmax, b.mmax, a.rmax+b.lmax});
    return res;
};

SegmentTree<M> seg(M_merge,M({0,0,0,0}));

int main(){
    ll n, q;
    cin >> n >> q;
    vector<M> v(n);
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        v[i] = M({a,max(a,0LL),max(a,0LL),max(a,0LL)});
    }
    seg.build(v);
    cout << seg.query(0,n).mmax << endl;
    for(int i=0;i<q;i++){
        ll k, x;
        cin >> k >> x;
        k--;
        seg.update(k, M({x,max(x,0LL),max(x,0LL),max(x,0LL)}));
        cout << seg.query(0,n).mmax << endl;
    }
    return 0;
}


Measured memory_bytes: 14196
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
const ll inf = (ll)(1e18),mod = (ll)(1e9+7), MX= 100001; 
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

 

void solve(){
    int n,m;
  cin>>n;
  ll total = 0;
  ll ans = 0;
  vector<int> a(n);
  	for(int i = 0; i<n; i++){
    	cin>>a[i];
      ans += total*a[i];
      total+=a[i];
    }
  	cout<<ans<<endl;

    return;
}

int main()
{
    int T = 1;
    // cin>>T;
    while(T--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 256