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

#define ms(s,n) memset(s,n,sizeof(s))
#define all(a) a.begin(),a.end()
#define present(t, x) (t.find(x) != t.end())
#define sz(a) int((a).size())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;

const int MOD = (int) 1e9+7;
const int INF = (int) 1e9+1;
inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll n,m,k;

void inp(){
	cin>>n>>m>>k;
	int a[n],b[m],ans=0,j=0;
	ll suma=0,sumb=0;
	FOR(i,0,n){
		cin>>a[i];
		suma+=a[i];
	}
	FOR(i,0,m)
		cin>>b[i];
	FORd(i,n+1,0){
		if(i<n)
			suma-=a[i];
		if(suma<=k){
			while(j<m&&suma+b[j]+sumb<=k){
				sumb+=b[j];
				j++;
			}
			ans=max(ans,i+j);
		}
	}
	cout<<ans<<endl;
}

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


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

int N;
int A[200];

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];
  int ans =0 ;
  while (1){
    bool odd_flag = false;
    for(int i=0;i<N;i++){
      if(A[i]%2 != 0){
        odd_flag = true;
        break;
      }
      A[i]/=2;
    }
    if(odd_flag) break ;
    ans++;
  }
  cout << ans << endl;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n, m;
    cin >> n >> m;

    REP(i, m) {
        ll a;
        cin >> a;
        n -= a;
    }

    if (n < 0) MSG(-1)
    else MSG(n)
}


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

int N, dp[3][100005], points[3][100005];

int solve(int i, int activity) {
	if (i>=N) {
		return 0;
	}
	
	if (dp[activity][i] != -1) {
		return dp[activity][i];
	}
	
	int x = solve(i+1, 0);
	int y = solve(i+1, 1);
	int z = solve(i+1, 2);
	
	if (activity == 0) {
		return dp[0][i] = points[0][i] + max(y, z);
	}
	
	if (activity == 1) {
		return dp[1][i] = points[1][i] + max(x, z);
	}
	
	return dp[2][i] = points[2][i] + max(x, y);
}

int main() {
	for(int i=0;i<3;i++) {
		for(int j=0;j<100005;j++) {
			dp[i][j] = -1;
		}
	}
	
	cin>>N;
	for(int i=0;i<N;i++) {
		for(int j=0;j<3;j++) {
			cin>>points[j][i];
		}
	}
	
	dp[0][N-1] = points[0][N-1];
	dp[1][N-1] = points[1][N-1];
	dp[2][N-1] = points[2][N-1];
	
	int ans = solve(0, 0);
	ans = max(ans, solve(0, 1));
	ans = max(ans, solve(0, 2));
	
	cout<<ans;
	return 0;
}

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



int main() {
  int H,W,i;
  cin>>H>>W;;
  string A[H];
  for(i=0;i<H;i++)cin>>A[i];

  for(i=0;i<W+2;i++){cout<<'#'; }
  cout<<endl;
  for(i=0;i<H;i++){
    cout<<"#";
    cout<<A[i];
    cout<<"#"<<endl;
  }
  for(i=0;i<W+2;i++){cout<<'#'; }
  cout<<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
    self.weight = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      r = self.Find_Root(self.root[x])
      self.weight[x] += self.weight[self.root[x]]
      self.root[x] = r
      return r
  def GetWeight(self, x):
    self.Find_Root(x)
    return self.weight[x]
  def Unite(self, x, y, w):
    w += self.GetWeight(x)
    w -= self.GetWeight(y)
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return False
    if self.rnk[x] < self.rnk[y]:
      x, y = y, x
      w = -w
    if self.rnk[x] == self.rnk[y]:
      self.rnk[x] += 1
    self.root[y] = x
    self.weight[y] = w
    return True
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x):
    return -self.root[self.Find_Root(x)]
  def Diff(self, x, y):
    return self.GetWeight(y) - self.GetWeight(x)
  
def main():
  N, M = map(int, input().split())
  lrd = [list(map(int, input().split())) for _ in range(M)]
  U = UnionFind(N)
  for i in range(M):
    l, r, d = lrd[i]
    if not U.isSameGroup(l, r):
      U.Unite(l, r, d)
    else:
      if U.Diff(l, r) != d:
        print('No')
        exit()
  print('Yes')
  
    
if __name__ == "__main__":
  main()

Measured memory_bytes: 58028
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,x;
int main(){
    n=read();
    int tt=0;
    int ans=0;
    for(int i=1;i<=n;i++){
    	x=read();
    	if(x>=tt) ans++;
    	tt=max(tt,x);
	}
	cout<<ans;
	
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct topological_sort{
    vector<vector<int>> graph;
    vector<bool> done,open;
    vector<int> res;
    bool success;
    topological_sort(vector<vector<int>> &graph):graph(graph),done(graph.size()),open(graph.size()){
        //rep(i,0,v) topo_dfs(i);
        success=true;
        rep(i,0,graph.size()){
            if(!dfs(i)){
                success=false;
                break;
            }
        }
        reverse(res.begin(),res.end());
    }
    bool dfs(int v){
        if(open[v]) return false;
        if(done[v]) return true;
        open[v]=true;
        done[v]=true;
        for(auto &u:graph[v]) if(!dfs(u)) return false;
        open[v]=false;
        res.push_back(v);
        return true;
    }
};

void solve(){
    int v,e;
    cin >> v >> e;
    vector<vector<int>> graph(v);
    rep(i,0,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
    }
    topological_sort ts(graph);
    cout << int(!ts.success) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int dist(pii a, pii b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}

int main() {
    int n,m;cin>>n>>m;
    vector<pii>s(n);rep(i,n)cin>>s[i].first>>s[i].second;
    vector<pii>c(m);rep(i,m)cin>>c[i].first>>c[i].second;
    
    for(auto i =0; i<n;i++){
        int len = INT_MAX;
        int ind = -1;
        for(auto j =0;j<m;j++){
            if(len > dist(s[i],c[j])) {len = dist(s[i],c[j]); ind = j;}
        }
        cout << ind+1 << endl;
    }
    
    return 0;
}







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

int main(){
    int a, b;
    cin >> a;
    cin >> b;
    string s;
    cin >> s;
    for(int i=0;i<a;i++){
        if(!(s[i] >= 48 && s[i] <= 57)){
            cout << "No" << endl;
            return 0;
        }
    }
    if(s[a] != 45){
        cout << "No" << endl;
        return 0;
    }
    for(int i=a+1;i<a+b+1;i++){
        if(!(s[i] >= 48 && s[i] <= 57)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ir = new Resolver(new ConsoleReader());
            Console.WriteLine(ir.Resolve());
        }
    }

    public class Resolver
    {
        IInputReader InputReader { get; }
        public List<string> Messages { get; set; } = new List<string>();

        int[] nab; 

        public void ParseLines(){
            nab = InputReader.ReadLine().Split(' ').ToList().Select(x => int.Parse(x)).ToArray();
        }

        public string Resolve()
        {
            if(nab[0] >= nab[1] + nab[2]) 
            {
                return Math.Min(nab[1], nab[2]) + " " + 0;
            }

            return Math.Min(nab[1], nab[2]) + " " + (nab[1] + nab[2] - nab[0]);
        }


        public Resolver(IInputReader inputReader)
        {
            InputReader = inputReader;
            ParseLines();
        }

    }

    public interface IInputReader
    {
        string ReadLine();
    }

    class ConsoleReader : IInputReader
    {
        string IInputReader.ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13396
// C++ 14
#include <math.h>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <string>

#define ll long long
#define Int ll
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define EPS 0.000000001
#define fequals(a,b) (fabs((a) - (b)) < EPS)

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (const Vector2 v) const { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (const Vector2 v) const { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (const double k) const { return Vector2(x * k, y * k); }
  Vector2 operator / (const double k) const { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 const v) { return x * v.x + y * v.y; }
  double cross (Vector2 const v) { return x * v.y - y * v.x; }
  
  bool parallel(Vector2 &other) {
    return fequals(fabs(dot(other)), length() * other.length());
  }
  
  bool orthogonal(Vector2 &other) {
    return fequals(0, dot(other));
  }
  
  bool operator < (const Vector2 &v) {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_N 1001
Int N;
Vector2 p0, p1, p2, v01;
string msgs[5] = {"COUNTER_CLOCKWISE", "CLOCKWISE", "ONLINE_BACK", "ONLINE_FRONT", "ON_SEGMENT"};

void solve() {
  Vector2 v02 = p2 - p0;
  double cross_ = v01.cross(v02);
  if (cross_ > 0.0) {
    cout << msgs[0] << endl;return;
  }
  else if (cross_ < 0.0) {
    cout << msgs[1] << endl;return;
  }
  
  double dot_ = v01.dot(v02);
  if (dot_ < 0.0) {
    cout << msgs[2] << endl;return;
  }
  if (v01.length() - v02.length() >= 0) cout << msgs[4] << endl;
  else cout << msgs[3] << endl;
}

void input() {
  cin >> p0 >> p1 >> N;
  v01 = p1 - p0;
  while (cin >> p2) {
    solve();
  }
}

int main() {
  cout.precision(15);
  input();
}


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

struct data {
  long long s, t, x;
};

struct sdata {
  long long t, x;
  bool flag;
};

bool asc(const data &l, const data &r) {
  if(l.x != r.x) return l.x < r.x;
  return l.t < r.t;
}

bool ascs(const sdata &l, const sdata &r) {
  if(l.t != r.t) return l.t < r.t;
  if(l.x != r.x) return l.x < r.x;
  return !l.flag;
}

long long n, q;
vector<long long> d, ans;
vector<data> v;
vector<sdata> vs;
set<long long> s;

void solve();

int main() {
  cin >> n >> q;
  v.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> v[i].s >> v[i].t >> v[i].x;
    v[i].s -= v[i].x;
    v[i].t -= v[i].x;
    vs.push_back({v[i].s, v[i].x, 1});
    vs.push_back({v[i].t, v[i].x, 0});
  }
  sort(vs.begin(), vs.end(), ascs);
  d.resize(q);
  ans.assign(q, -1);
  for(int i = 0; i < q; ++i) cin >> d[i];
  solve();
  for(int i = 0; i < q; ++i) cout << ans[i] << endl;
  return 0;
}

void solve() {
  long long vssize = n * 2;
  for(long long i = 0, j = 0; i < q; ++i) {
    long long nd = d[i];
    while(j < vssize && vs[j].t <= nd) {
      if(vs[j].flag)
        s.insert(vs[j].x);
      else
        s.erase(vs[j].x);
      ++j;
    }
    if(s.empty())
      ans[i] = -1;
    else
      ans[i] = (*s.begin());
  }
}


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

#ifdef __LOCAL_DEBUG__
# define _debug(fmt, ...) fprintf(stderr, "\033[94m%s: " fmt "\n\033[0m", \
    __func__, ##__VA_ARGS__)
#else 
# define _debug(...) ((void) 0)
#endif
#define rep(i, n) for (int i=0; i<(n); i++)
#define Rep(i, n) for (int i=1; i<=(n); i++)
#define range(x) (x).begin(), (x).end()
typedef long long LL;
typedef unsigned long long ULL;

int main() {
  int n, nn; cin >> n; nn = n;
  int s = 0;
  while (n) {
    s += n % 10;
    n /= 10;
  }
  if (nn % s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int max=0;
    int sum=0;
    for(int i=0;i<N;i++){
        if(a[i]>max)
            max=a[i];
        sum+=a[i];}
    cout<<sum-max/2;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax=100005;
int t[nmax];
int n,c,k,lst,ans,i;
int main()
{
    cin>>n>>c>>k;
    for(i=1;i<=n;i++)
    {
       cin>>t[i];
    }
    sort(t+1,t+n+1);
    lst=1;ans=1;
    for(i=2;i<=n;i++)
    {
        if(t[i]-t[lst]>k||i-lst+1>c)
        {
            lst=i;
            ans+=1;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        scanner.close();
 
        int sLen = s.length();
        boolean flag = true;
        String []w = {"dreameraser", "dreamerase", "dreamer", "eraser",
                "dream", "erase"};
        int begin = 0;
        int end = 0;
        while(flag) {
            if(begin == sLen) {
                if(sLen == 0) {
                    System.out.println("NO");
                    break;
                }else {
                    System.out.println("YES");
                    flag = false;
                    break;
                }
            }else {
                for(int i = 0; i < 7; i++) {
                    if(i == 6) {
                        System.out.println("NO");
                        System.exit(0);
                    }
                    end = begin + w[i].length();
                    //System.out.println("end " + end);
                    if(end <= sLen) {
                        String sub = s.substring(begin, end);
                        //System.out.println(sub);
                        if(sub.equals(w[i])) {
                            begin = end;
                            //System.out.println(i + " " + begin);
                            break;
                        }
                    }
                }
            }
 
        }
 
    }
}

Measured memory_bytes: 28480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 2e5 + 2, mod = 1e9 + 7;

#define temptts template <class T, class... Ts>
temptts int add(T f) { return f; } temptts int add(T f, Ts... ts) { return (f + add(ts...)) % mod; }
temptts int sub(T f) { return f; } temptts int sub(T f, Ts... ts) { return (f - sub(ts...) + 1ll * mod * mod) % mod; }
temptts int mul(T f) { return f; } temptts int mul(T f, Ts... ts) { return (1ll * f * mul(ts...)) % mod; }
int binpow(ll n, ll k) { int ans = 1; while (k) { if (k & 1) ans = mul(ans, n); n = mul(n, n), k >>= 1; } return ans; }
ll powr(ll x, int k) { ll res = 1; while (k) { if (k & 1) { if (x && mod / x < res) return 0; res = res * x; } if (x && mod / x < x) x = 0; x = x * x; k >>= 1; } return res; }
int inv(int n) { return binpow(n, mod - 2); }
struct precompute { int f[N]; precompute() { f[0] = 1; for (int i = 1; i < N; i++) f[i] = mul(f[i - 1], i); } int operator() (int n) { return f[n]; } } fact;
int C(int n, int k) { return mul(fact(n), inv(mul(fact(k), fact(n - k)))); }

struct edge {
  int u, v;
  ll w;
  bool operator < (const edge &o) const {
    return w > o.w;
  }
} e[N];

int n, m, s, t;
bool vis[N];
ll ds[N], dt[N];
int cs[N], ct[N];
vector<int> adj[N];

void dijkstra(int s, ll* d, int* c) {
  priority_queue<edge> pq;
  for (int i = 1; i <= n; i++) {
    d[i] = 1e18;
    vis[i] = 0;
  }
  pq.push({s, s, d[s] = 0});
  c[s] = 1;
  while (!pq.empty()) {
    int v = pq.top().v;
    pq.pop();
    if (vis[v]) continue;
    vis[v] = 1;
    for (auto& i : adj[v]) {
      int u = v ^ e[i].u ^ e[i].v;
      ll w = e[i].w;
      if (d[v] < 1e18 && d[u] > d[v] + w) {
        c[u] = c[v];
        pq.push({v, u, d[u] = d[v] + w});
      } else if (d[u] == d[v] + w) {
        c[u] = add(c[u], c[v]);
      }
    }
  }
}

int32_t main() { cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m >> s >> t;
  for (int i = 1, u, v, w; i <= m; i++) {
    cin >> u >> v >> w;
    e[i] = {u, v, w};
    adj[u].push_back(i);
    adj[v].push_back(i);
  }
  dijkstra(s, ds, cs);
  dijkstra(t, dt, ct);
  ll ans = 0;
  for (int v = 1; v <= n; v++) {
    if (ds[v] + dt[v] == ds[t] 
    && 2 * ds[v] == ds[t] 
    && 2 * dt[v] == dt[s]) {
      ll cc = mul(cs[v], ct[v]);
      ans = add(ans, mul(cc, cc));
    }
  }
  for (int i = 1; i <= m; i++) {
    int u = e[i].u, v = e[i].v;
    ll w = e[i].w;
    if (ds[u] + dt[v] + w == ds[t] 
    && 2 * ds[u] < ds[t] 
    && 2 * dt[v] < dt[s]) {
      ll cc = mul(cs[u], ct[v]);
      ans = add(ans, mul(cc, cc));
    }
    if (ds[v] + dt[u] + w == ds[t] 
    && 2 * ds[v] < ds[t] 
    && 2 * dt[u] < dt[s]) {
      ll cc = mul(cs[v], ct[u]);
      ans = add(ans, mul(cc, cc));
    }
  }
  cout << sub(mul(cs[t], ct[s]), ans);
}

Measured memory_bytes: 21696
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var s = br.readLine();
      final var t = br.readLine();

      System.out.println(t.startsWith(s) ? "Yes" : "No");
    }
  }
}


Measured memory_bytes: 32588
#include <bits/stdc++.h>
typedef long long ll;
static const ll INF = 100000000000000;
using namespace std;

int n,m; 
struct edge{
    int to;
    int from;
    ll cost;
};

vector<edge> g;

int main(){
    cin>>n>>m;
    ll ans = 0;
    ll d[1100];

    for(int i=0; i<m; i++){
        struct edge add;
        cin>>add.from;
        add.from--;
        cin>>add.to;
        add.to--;
        cin>>add.cost;
        add.cost *=(-1);
        g.push_back(add);
    }

    for(int i=0; i<1100; i++){
        d[i] = INF;
    }

    d[0] = 0;

    ll comp;
    
    for(int j=0; j<n-1; j++){
        for(int i=0; i<m; i++){
            d[g[i].to] = min(d[g[i].to],d[g[i].from]+g[i].cost);
        }
    }

    comp = d[n-1];

    for(int i=0; i<m; i++){
        if(d[g[i].to] > d[g[i].from]+g[i].cost){
            d[g[i].to] = min(d[g[i].to],d[g[i].from]+g[i].cost);
        }
    }


    if(comp != d[n-1]) cout<<"inf"<<endl;
    else cout<<(-1)*d[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
const int mod = 998244353;
vector<int> fac;
long long inv(long long a, long long b = mod){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int choose(int a, int b){
//    cout << a << " " << b <<endl;
    assert(b <= a && b >= 0);
    int ans = fac[a] * inv(fac[b]);
    assert(ans >= 0);
    ans %= mod;
    ans *= inv(fac[a-b]);
    assert(ans >= 0);
    ans %= mod;
    assert(ans >= 0);
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n,m;cin >> n >> m;
    fac.resize(n+m*5 + 2);
    fac[0] = 1;
    FOR1(i, n+m*5)fac[i] = fac[i-1]*i, fac[i] %= mod;

    int ans = choose(n-1 + 3*m, n-1);
    int tot = 0;
    for(int odds = 0; odds<= min(n, m*3); odds++){
        if((3*m - odds) % 2)continue;
        int dist = choose(n, odds);
        int remains = 3*m - odds; 
        int toSub = choose((remains/2) + n-1, n-1);
    //    cout << odds << " " << dist << " " << toSub <<endl;
        tot += toSub*dist;
        tot %= mod;
    }
    assert(tot == ans);
    ans -= choose(m-1 + n-1, n-1)*n;
    ans %= mod;
    for(int odds = m+1; odds <= min(n, 3*m); odds++){
        if((3*m - odds) % 2)continue;
        //debug(odds);
        int distribute = choose(n, odds);
        int remains = 3*m - odds; 

        int toSub = choose((remains/2) + n-1, n-1);
        //cout << odds << " " << distribute << " " << toSub <<endl;
        int temp = toSub * distribute;
        temp %= mod;
        ans -= temp;
        ans %= mod;
        while(ans < 0)ans += mod;
    }
    //debug(ans);
    while(ans < 0)ans += mod;
    cout <<ans;

}

Measured memory_bytes: 27648
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
anssum = 0
for i in B:
    moreB = N-bisect.bisect_right(C,i)
    lessB = bisect.bisect_left(A,i)
    anssum += moreB*lessB
print(anssum)

Measured memory_bytes: 105444
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int dh[4]={0,1,0,-1};
int dw[4]={1,0,-1,0};

ll n,m;
string s,t;
ll gcd(ll a,ll b){
      if(b==0) return a;
      if(a<b) return gcd(b,a);
      return gcd(b,a%b);
}
ll lcm(ll a,ll b){
      return (a*b)/gcd(a,b);
}

int main(){ 
      cin>>n>>m;
      cin>>s>>t;
      ll g=gcd(n,m);
      bool ok=true;
      for(ll i=0;i<g;i++){
            if(s[(n*i)/g]!=t[(m*i)/g]) ok=false;
      }
      if(ok) cout<<lcm(n,m)<<endl;
      else cout<<-1<<endl;

      return 0;
}


Measured memory_bytes: 512
#include <cstdio>
inline int ceill(int x,int y) { if (x%y) return (int)(x/y)+1; return x/y; }
int main()
{
	int n,x,t;
	scanf("%d%d%d",&n,&x,&t);
	printf("%d\n",ceill(n,x)*t);
	return 0;
}

Measured memory_bytes: 3252
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;


int main() {
  int a,b;
  cin >> a>>b;
  cout << a*b-a-b+1 << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	VI a(n+1), b(n+1);
	rep2(i, 1, n+1) cin >>a[i];
	
	repr(i, n, 1){
		ll sm = a[i];
		for(ll j=i+i; j<=n; j+=i) sm +=b[j];
		b[i] = sm%2;
	}
	VI ans;
	rep(i, n+1) if(b[i]==1) ans.push_back(i);
	cout << sz(ans)<<"\n";
	if(sz(ans)){
		for(auto x:ans) cout << x <<" "; cout <<"\n";
	}
	return 0;
}


Measured memory_bytes: 3192
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<functional>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
long long mod = 1000000007;
using namespace std;
int main(void)
{
	int N,max=0;
	int s[100010],sum=0;
	scanf("%d", &N);
	rep(i, N) {
		scanf("%d", &s[i]);
		sum += s[i];
		if (max < s[i]) {
			max = s[i];
		}
	}
	if (max < sum - max) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string.h>
using namespace std;

int main() {
  int n;
  int a[100000] = {0};
  cin >> n;
  int x, ans,sz=0;
  for (int i=0; i < n; i++){
      cin >> x;
      a[x-1] += 1;
  }
  x = -1;
  for(int i=0; i< 100000; i++){
      sz += a[i];
      if(sz == n/2){ x = i; break;}
      else if(sz > n/2) break;
  }
  if(x==-1) ans = 0;
  else{
      for(int i = x+1; x < 100000; i++){
          if(a[i]>0) {ans = i-x; break;}
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N,M; cin >> N >> M;
  vector<pair<int, int>> A(N);
  rep(i,N) cin >> A[i].first >> A[i].second;

  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());

  //priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  priority_queue <int, vector<int>, greater<int>> pq;
  rep(i,N) {
    if (A[i].first <= M-pq.size()) pq.push(A[i].second);
    else if (!pq.empty()){
      if (pq.top() < A[i].second) {
        pq.pop();
        pq.push(A[i].second);
      }
    }
  }

  int sum = 0;
  while(!pq.empty()) {
    sum += pq.top();
    pq.pop();
  }

  cout << sum << endl;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
    return x*f;
}
const int N=2e5+28;
int n,a[N],b[N];
signed main(){
    //freopen("night.in","r",stdin);
    //freopen("night.out","w",stdout);
    n=read()*2-1;
    for(int i=1;i<=n;i++)a[i]=read();
    int l=0,r=0x7fffffff,ans=0x7fffffff;
    while(l<=r){
	int mid=(l+r)>>1;
	for(int i=1;i<=n;i++)
	    b[i]=(a[i]>mid);
	int p1=n/2,p2=n/2+2;
	int re=-1;
	for(;p1;p1--,p2++){
	    if(b[p1]==b[p1+1]){
		re=b[p1];
		break;
	    }
	    if(b[p2]==b[p2-1]){
		re=b[p2];
		break;
	    }
	}
	if(re==-1)re=b[1];
	if(re==0)ans=mid,r=mid-1;
	else l=mid+1;
    }
    printf("%lld",ans);
    return 0;
}
/*
7
1 2 3 4 3 2 1
5
1 9 2 3 6
*/


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
typedef long long int llint;
int main(void){
	
	llint defference[3],c[3][3];
	
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin >> c[i][j];
		}
	}
	
	for(int i=0;i<2;i++){
		
		for(int j=0;j<3;j++){
			defference[j] = c[i][j] - c[i+1][j];
		}
		for(int j=0;j<2;j++){
			if(defference[j] != defference[j+1]){
				cout << "No" << endl;
				return 0;
			}
		}
		for(int j=0;j<3;j++){
			defference[j] = c[j][i] - c[j][i+1];
		}
		for(int j=0;j<2;j++){
			if(defference[j] != defference[j+1]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = gets.split.map &:to_i
hs = gets.split.map &:to_i

bs = Array.new(n).map{ Array.new }

m.times{
	a, b = gets.split.map &:to_i

	bs[a - 1] << hs[b - 1]
	bs[b - 1] << hs[a - 1]
}

count = 0

bs.each_with_index{ |x,i|
	if x.size == 0 || x.max < hs[i] then
		count += 1
	end
}

puts count

Measured memory_bytes: 27460
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int A, B;
	cin >> A >> B;
	int res = B;
	if(A <= 12) res /= 2;
	if(A <= 5) res = 0;

	cout << res << '\n';

	return 0;
}

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

typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;

#pragma GCC optimize ("-O3")
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define all(v) v.begin(), v.end()
#define FOR(i, j, k, in) for(li i=j; i<k; i+=in)
#define RFOR(i, j, k, de) for(li i=j; i>=k; i-=de)
#define rep(i,j,k) FOR(i, j, k, 1)
#define rrep(i,j,k) RFOR(i, j, k, 1)
#define repc(v) for(auto it=v.begin(); it!=v.end(); it++)
#define T ll t; cin>>t; while(t--)

int main(){
  FAST

  int x,y,z;
  cin>>x>>y>>z;
  
  cout<<z<<" "<<x<<" "<<y;
  
  return 0;
}








Measured memory_bytes: 384
buf=input().split()
N=int(buf[0])
M=int(buf[1])

thres=10**9+7

if abs(N-M)==1:
    N=min(N,M)
    retVal=1
    for i in range(1,N+1):
        retVal*=(i**2)
        if retVal>=thres:
            retVal=retVal%thres
    retVal*=(N+1)
    if retVal>=thres:
        retVal=retVal%thres
    print(retVal) 
elif N==M:
    retVal=2
    for i in range(1,N+1):
        retVal*=(i**2)
        if retVal>=thres:
            retVal=retVal%thres
    print(retVal)
else:
    print(0)

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  REP1(i, 1000) {
    const int x = static_cast<int>(floor(i * 0.08));
    const int y = static_cast<int>(floor(i * 0.1));
    if (x == A && y == B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> price(n);
    for(int i=0;i<n;i++){
        cin>>price[i];
    }
    sort(price.begin(), price.end());
    int total=0;
    for(int i=0;i<k;i++){
        total += price[i];
    }
    cout<<total<<endl;
    return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	double R;
	cin >> R;

	double pi = 3.14159265353238;

	double ans = 2.0 * pi * R;
	cout << fixed << setprecision(10) << ans << "\n";


	return 0;
}


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

int main(){
  char N[100100];cin>>N;
  string S=N;
  int z=0,o=0,cnt=0;
  for(int i=0;i<S.length();i++){
    if(S[i]=='0'){
      z++;
    }else{
      o++;
    }
    cnt++;
  }
  cout<<S.length()-abs(z-o)<<endl;
}


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

// int gcd(int x,int y){
	// if(x>y) swap(x,y);
	
	// if(y%x==0) return x;
	// else gcd(y%x,x);
// }

int main(){
	int n;
	cin>>n;
	
	int a1;
	cin>>a1;
	int ans=a1;
	for(int i=0;i<n-1;++i){
		int a;
		cin>>a;
		
		ans=__gcd(ans,a);
	}
	
	cout<<ans<<endl;
}//abc118_c 解説参考.

Measured memory_bytes: 256
#112
n, t0 = map(int, input().split())
ans = 10000000000
for _ in range(n):
    c, t = map(int, input().split())
    if(t<=t0 and c<=ans):
        ans = c

if(ans==10000000000):
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3060
def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    D = [0] * (10**5+1)
    for i in range(N):
        D[A[i]] += 1

    ans = sum(A)
    for _ in range(Q):
        B, C = map(int, input().split())
        if D[B] != 0:
            ans -= B * D[B]
            ans += D[B] * C
            D[C] += D[B]
            D[B] = 0
            print(ans)
        else:
            print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 84396
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin>>s>>t;
    bool flag = true;
    if(t.length() == s.length() + 1) {
    	for(int i = 0; i < s.length(); i++) {
    		if(s[i] != t[i]) {
    			flag = false;
    		}
    	}
    } else {
    	flag = false;
    }
    if(flag) {
    	cout<<"Yes\n";
    } else {
    	cout<<"No\n";
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll k;cin>>k;
    string s;cin >>s;
    if(s.size()<=k){
        cout <<s<<endl;
    }
    else {
        cout <<s.substr(0,k)<<"..."<<endl;
    }
    return 0;
}



Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
  static void Main(string[] args) {
    int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    int N = input[0];
    int A = input[1];

    int[] x = new int[N + 1];
    input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    for (int i = 0; i < N; ++i) {
      x[i + 1] = input[i];
    }

    long[,,] dp = new long[N + 1, N + 1, N * A + 1];

    for (int i = 0; i < N; ++i) dp[i, 0, 0] = 1;

    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= i; ++j) {
        for (int k = 1; k <= N * A; ++k) {
          if (k < x[i]) {
            dp[i, j, k] = dp[i - 1, j, k];
          } else {
            dp[i, j, k] = dp[i - 1, j, k] + dp[i - 1, j - 1, k - x[i]];
          }
        }
      }
    }

    long ans = 0;
    for (int j = 1; j <= N; ++j) {
      ans += dp[N, j, j * A];
    }

    Console.WriteLine(ans);
  }
}


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

int main() 
{
  int A,B,C,K;
  int sum = 0;
  
  cin >> A >> B >> C >> K;
  
  if(A >= K)
  {
    sum = K;
  }
  else if((A + B) >= K)
  {
    sum = A;
  }
  else
  {
    sum = A - (K - A - B);
  }
  
  cout << sum << endl;
  
  
}


Measured memory_bytes: 3632
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1172&lang=jp
*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll solve(ll n){
    bool isprime[n*2 + 1];
    memset(isprime, true, sizeof isprime);
    for(ll i=2;i*i<=2*n;i++){
        for(ll j=i;j<=n*2;j+=i){
            isprime[j] = false;
        }
    }
    ll cnt = 0;
    for(ll i=n+1;i<=2*n;i++){
        if(isprime[i]) cnt++;
    }
    return cnt;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    while(1){
        ll n; cin >> n;
        if(n == 0) break;
        ll ans = solve(n);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3372
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  vector<int> a(N);
  cin >> a;
  vector<vector<int>> g(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> dp(N + 2, INF);
  vector<int> ans(N);
  function<void(int, int)> dfs = [&](int v, int p) {
    auto it = lower_bound(all(dp), a[v]);
    int prev = *it;
    *it = a[v];
    ans[v] = lower_bound(all(dp), INF) - dp.begin();
    for (auto u : g[v]) {
      if (u == p) continue;
      dfs(u, v);
    }
    *it = prev;
  };
  dfs(0, -1);
  for (int i = 0; i < N; i++) cout << ans[i] << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 33720
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,a[8],p[8],b[8],f[305][305][33];
double ans;
int Solve()
{
    memset(f,0,sizeof(f));
    f[0][a[n+1]*n][0]=1;
    for(int i=0;i<n*m;++i) for(int j=i+1;j<=n*m;++j) for(int k=0;k<1<<n;++k) if(f[i][j][k])
    {
        f[i+1][j][k]+=f[i][j][k];
        int r=i%n+1;
        if(!(k&(1<<r-1))) f[i+1][min(n*m,max(j,i+a[p[r]]*n))][k|(1<<r-1)]+=f[i][j][k];
    }
    return f[n*m][n*m][(1<<n)-1];
}
void dfs(int x)
{
    if(x>n){ans+=Solve();return;}
    for(int i=1;i<=n;++i) if(!b[i]) p[x]=i,b[i]=1,dfs(x+1),b[i]=0;
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;++i) a[i]=read();
    sort(a+1,a+n+1);--n;dfs(1);
    for(int i=1;i<=n;++i) ans/=i*m;
    printf("%.15lf",ans);
    return 0;
}

Measured memory_bytes: 12288
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N, X, Distance, sum = 0, count = 1;
	vector<int> L;
	cin >> N;
	cin >> X;
	for (int i = 0; i < N; i++) {
		cin >> Distance;
		L.push_back(Distance);
	}
	for (int i = 0; i < L.size(); i++) {
		sum += L[i];
		if (X < sum) {
			break;
		}
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

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


signed main(){
	int h,w,k;
	cin>>h>>w>>k;
	string s[303];
	rep(i,h)cin>>s[i];
	vector<vi> a(h,vi(w));

	int top=-1;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#'){
				top=i;
				break;
			}
		}
		if(top>-1) break;
	}
	vi cnt(h,0);
	rep(i,h){
		rep(j,w)cnt[i]+=s[i][j]=='#';
	}

	int c=1;
	FOR(i,top,h-1){
		if(cnt[i]==0){
			rep(j,w){
				a[i][j]=a[i-1][j];
			}
			continue;
		}
		int tmp=c;
		a[i][0]=c;
		
		if(s[i][0]=='#'&&cnt[i]>1) c++;

		FOR(j,1,w-1){
			a[i][j]=c;
			if(s[i][j]=='#'&&cnt[i]>1&&c-tmp<cnt[i]-1)c++;
		}
		c++;

		if(i+1<h&&cnt[i]==0&&cnt[i+1]==0) c--;
	}
	for(int i=top-1;i>=0;i--){
		rep(j,w)a[i][j]=a[i+1][j];
	}

	rep(i,h){
		// printf("cnt[%2d]=%2d ",i,cnt[i]);
		rep(j,w){
			if(j>0)cout<<' ';
			cout<<a[i][j];
			// printf("%3d",a[i][j]);
		}
		cout<<endl;
	}



	return 0;
}

Measured memory_bytes: 4448
#include<stdio.h>
#include<string>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int n,q,t;
   string name;
   queue<pair<string,int> > Q;
   cin>>n>>q;
   for(int i=0;i<n;i++)
   {
       cin>>name>>t;
       Q.push(make_pair(name,t));
   }
   pair<string,int> u;
   int elaps=0,a;
   while(!Q.empty())
   {
       u=Q.front();
       Q.pop();
       a=min(u.second,q);
       u.second-=a;
       elaps+=a;
       if(u.second!=0)
       {
           Q.push(u);
       }
       else
       {
           cout<<u.first<<" "<<elaps<<endl;
       }
   }
   //return 0；
}

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

#define ff      first
#define ss      second
#define pb      push_back
#define ll      long long
#define MX      100005
#define inf     1000000
#define mod     1000000007
#define endl    "\n"

#define W(t)            while(t--)
#define all(v)          v.begin(),v.end()
#define ZERO(a)         memset(a,0,sizeof(a))
#define MINUS(a)        memset(a,-1,sizeof(a))
#define rep(i,a,b)      for(i = a; i < b; i++)
#define IOS             ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

int main()
{
	IOS

	ll t,n,i;
	string s;
	cin>>s;
	if(s[s.size()-1]!='s')
		cout<<s<<"s";
	else
		cout<<s<<"es";
}

Measured memory_bytes: 3620
import sys

h,w = map(int,input().split())
c = [None]*h
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    c[i] = input()
    
for i in range(h):
    for j in range(w):
        a = 0
        b = 0
        for k in range(4):
            nx = j + dx[k]
            ny = i + dy[k]
            if c[i][j] == '#' and 0<=nx and nx<w and 0<=ny and ny<h:
                b += 1
                if c[ny][nx] == '.':
                    a += 1
                    
        if a == b and b != 0:
            print("No")
            sys.exit()
            
print("Yes")

Measured memory_bytes: 40560
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    string S,T;cin>>S>>T;
    int N_S=S.size();
    int N_T=T.size();
    string dp[2][3010];

    for(int i=1;i<=N_S;i++){
        for(int j=1;j<=N_T;j++){
            if(dp[0][j].size()>dp[0][j-1].size())        dp[1][j]=dp[0][j];
            else if(dp[1][j-1].size()>dp[0][j-1].size()) dp[1][j]=dp[1][j-1];
            else{
                if(S[i-1]==T[j-1]) dp[1][j]=dp[0][j-1]+S[i-1];
                else               dp[1][j]=dp[0][j-1];
            }
        }
        for(int j=1;j<=N_T;j++)
            dp[0][j]=dp[1][j];
    }
    cout<<dp[0][N_T]<<endl;

    return 0;
}

Measured memory_bytes: 7824