akhauriyash/Code-Regression huggingface dataset:
#lamp
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
lists=[]
for i in range(h):
    b=list(input())
    lists.append(b)
    
right=[[0 for i in range(w)] for j in range(h)]
left=[[0 for i in range(w)] for j in range(h)]
up=[[0 for i in range(w)] for j in range(h)]
down=[[0 for i in range(w)] for j in range(h)]

#rightの累積和
for i in range(h):
    for j in range(w-1,-1,-1):
        if j==w-1:
            if lists[i][j]=="#":
                right[i][j]=0
            else:
                right[i][j]=1
        else:
            if lists[i][j+1]=="#":
                if lists[i][j]=="#":
                    right[i][j]=0
                else:
                    right[i][j]=1
            elif lists[i][j+1]==".":
                if lists[i][j]=="#":
                    right[i][j]=0
                else:
                    right[i][j]=right[i][j+1]+1


#leftの累積和
for i in range(h):
    for j in range(w):
        if j==0:
            if lists[i][j]=="#":
                left[i][j]=0
            else:
                left[i][j]=1
        else:
            if lists[i][j]=="#":
                left[i][j]=0
            else:
                left[i][j]=left[i][j-1]+1


#upの累積和
for i in range(w):
    for j in range(h):
        if j==0:
            if lists[j][i]=="#":
                up[j][i]=0
            else:
                up[j][i]=1
        else:
            if lists[j][i]=="#":
                up[j][i]=0
            else:
                up[j][i]=up[j-1][i]+1

                
#downの累積和
for i in range(w):
    for j in range(h-1,-1,-1):
        if j==h-1:
            if lists[j][i]=="#":
                down[j][i]=0
            else:
                down[j][i]=1
        else:
            if lists[j][i]=="#":
                down[j][i]=0
            else:
                down[j][i]=down[j+1][i]+1
                
maxi=0
for i in range(h):
    for j in range(w):
        maxi=max(maxi,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3)
print(maxi)           

Measured memory_bytes: 314632
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]
memo = []
ans = 0

def reverse_binary_serch(target, query):
    l = 0
    r = len(target) - 1
    while True:
        if r - l < 2:
            if target[l] < query:
                return l
            else:
                return r
        i = (l + r) // 2
        if target[i] >= query:
            l = i
        else:
            r = i

for ai in a:
    if not memo or memo[-1] >= ai:
        memo.append(ai)
    else:
        index = reverse_binary_serch(memo, ai)
        memo[index] = ai

print(len(memo))


Measured memory_bytes: 50396
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,n,hanako=0,taro=0;
	char t[101],h[101];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",t,h);
		if(strcmp(t,h)<0) hanako+=3;
		else if(strcmp(t,h)>0) taro+=3;
		else if(strcmp(t,h)==0) {
			hanako++;
			taro++;
		}
	}
	printf("%d %d\n",taro,hanako);
	return 0;
}

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

int main(){
	int N, result, p, y, g, w;
    p = 0;
  	y = 0;
  	g = 0;
  	w = 0;
  	cin >> N;
  
  	for(int i = 0; i < N; i++){
      	string S;
      	cin >> S;
     	
		if	   (S == "P")
			p = 1;
      
      	else if(S == "Y")
          	y = 1;
      
        else if(S == "G")
          	g = 1;
      
        else if(S == "W")
          	w = 1;
    }
  	result = p + y + g + w;
  
  	if(result == 3)
  		cout << "Three" << endl;
  
  	else if(result == 4)
      	cout << "Four" << endl;
  
  	else
      	cout << "計算ミス" << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	m := make(map[int]int)
	for _, a := range as {
		m[a]++
	}
	cnt := len(m)
	if cnt%2 == 0 {
		cnt--
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 8960
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

long long int n,a,b,c;



int main(){
    
        
    while(cin >> n){
        if(n==0)break;
        
        long long int ans[4001]={0};
        int ans_n[4001]={0};
        
        bool flag=true;
        for(int i=0; i<n; i++){
            cin>>a>>b>>c;
            ans_n[i]=a;
            ans[a]+=b*c;
        }
        
        for(int i=0; i<n; i++){
            if(ans[ans_n[i]]>=1000000){
                cout<<ans_n[i]<<endl;
                ans[ans_n[i]]=0;
                flag=false;
            }
        }
        
        if(flag)cout<<"NA"<<endl;
    }
            
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int a[2];
  int b[2];
  cin >> a[0] >> b[0];
  cin >> a[1] >> b[1];

  int t = 0;
  while (1) {

    int op = t + 1;
    op %= 2;
    a[op] -= b[t];
    if (a[op] <= 0) {
      if (t == 0) cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;
    }
    
    t++;
    t %= 2;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int pow(int a,int b){
	int result=1;
	for(int i=0; i<b; ++i) result*=a;
	return result;
}

int main(){
	int N;
	while(std::cin >> N&&N!=-1){
		long long int i=0,ans=0;
		while(pow(4,i)<=N+1) ++i;
		--i;
		for( ; i>=0; --i){
			long long int tmp=pow(4,i);
			ans+=N/tmp*pow(10,i);
			N%=tmp;
		}
		cout << ans << endl;
	}
	return 0; 
}

Measured memory_bytes: 1156
import java.util.*;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    private void run() {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] H = new int[N];

        for (int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }

        List<List<Integer>> adj = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            adj.add(new ArrayList<>());
        }

        for (int i = 0; i < M; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;

            adj.get(u).add(v);
            adj.get(v).add(u);
        }

        int count = 0;
        for (int u = 0; u < N; u++) {
            boolean ok = true;
            for (int v : adj.get(u)) {
                if (H[v] >= H[u]) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                ++count;
            }
        }

        System.out.println(count);
    }

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


Measured memory_bytes: 71752
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <map>
#include <unordered_map>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <limits.h>
#include <tgmath.h>

using namespace std;

typedef uint16_t ui16;
typedef uint32_t ui32;
typedef uint64_t ui64;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef long double ld;
typedef pair<int, int> pr;

//template<typename T> inline T abs(T a) { return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a) { return a * a; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) {for (int i = 0; i < v.size(); ++i) cout << v[i] << " "; cout << endl; return cout; }
void print() { cout << endl; }
template<typename T, typename... Ts> void print(T x, Ts... xs) { cout << x << " "; print(xs...); };
template<typename T> void read(vector<T>& v) { for (int i = 0; i < v.size(); ++i) cin >> v[i]; };

// iterate through all endpoints
// perform bfs, for each vertex record max of vertex and current bfs value
// return max of all

int dfs(int v, const vector<vector<int>>& g, vector<int>& dp) {
    if (dp[v] != -1) return dp[v];
    int ans = 0;
    for (int e : g[v]) {
        ans = max(ans, 1 + dfs(e, g, dp));
    }
    dp[v] = ans;
    return ans;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N + 1, vector<int>());
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
    }

    int ans = 0;
    vector<int> dp(N + 1, -1);
    for (int i = 1; i <= N; ++i) {
        ans = max(ans, dfs(i, g, dp));
    }

    cout << ans << endl;

    return 0;
}









Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll K,X;
	cin>>K>>X;
	if(K*500>=X){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int cost[1100][1100];
int main()
{
	int H, W, M;
	cin >> H >> W >> M;
	set<pair<int, int>> K;
	map<int,int> Hs;
	map<int,int> Ws;
	fx(M) {
		int h, w;
		cin >> h >> w;
		K.insert(make_pair(h, w));
		Hs[h]++;
		Ws[w]++;
	}
	int maxiH = 0, maxiW = 0,h=0,w=0;
	fx(H) {
		maxiH = max(maxiH, Hs[x + 1]);
		if (maxiH== Hs[x + 1]) {
			h = x + 1;
		}
	}
	fx(W) {
		maxiW = max(maxiW, Ws[x + 1]);
		if (maxiW == Ws[x + 1]) {
			w = x + 1;
		}
	}
	if (K.count(make_pair(h,w))) {
		fx(H) {
			if (maxiH == Hs[x + 1] && x+1!=h && !K.count(make_pair(x+1,w))) {
				ce(maxiH + maxiW);
				return 0;
			}
		}
		fx(W) {
			if (maxiW == Ws[x + 1] && x + 1 != w && !K.count(make_pair(h, x+1))) {
				ce(maxiH + maxiW);
				return 0;
			}
		}
		ce(maxiH + maxiW - 1)
	}
	else {
		ce(maxiH + maxiW)
	}

    return 0;
}



Measured memory_bytes: 45732
import numpy as np

N, K = map(int, input().split())

A = list(map(int, input().split()))
A.sort()
key = A[0]

B = []
cnt = 1

for i in range(1,N):
    if key == A[i]:
        cnt += 1
    else:
        key = A[i]
        B.append(cnt)
        cnt = 1

B.append(cnt)

B.sort(reverse=True)

print(sum(B[K:]))


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

int main()
{
ll n ;
cin >> n ;
vector<vector<ll>> g(n);

rep(i, n-1){
  ll a;
  cin >> a;
  g[i+1].push_back(a-1);
  g[a-1].push_back(i+1);
}
vector<vector<ll>> st(n);
vector<ll> par(n);
vector<ll> ans(n);
queue<ll> q;
queue<ll> qq;

q.push(0);
par[0]=-1;
while(!q.empty()){
  ll p=q.front();
  q.pop();
  if(g[p].size()==1 && p!=0){qq.push(p);}
  for(auto r:g[p]){
    if(r==par[p])continue;
    par[r]=p;
    q.push(r);
  }
}
while(!qq.empty()){
  ll p=qq.front();
  qq.pop();
  st[par[p]].push_back(ans[p]+1);
  if(st[par[p]].size()==g[par[p]].size()){
    sort(st[par[p]].rbegin(),st[par[p]].rend());
    rep(i,st[par[p]].size())st[par[p]][i]+=i;
    ans[par[p]]=*max_element(st[par[p]].begin(),st[par[p]].end());
  }
  if(st[par[p]].size()==g[par[p]].size()-1 && par[p]!=0){
    sort(st[par[p]].rbegin(),st[par[p]].rend());
    rep(i,st[par[p]].size())st[par[p]][i]+=i;
    ans[par[p]]=*max_element(st[par[p]].begin(),st[par[p]].end());
    qq.push(par[p]);
  }
}
cout << ans[0] << endl;
return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) a[i] -= b[i];
  if(accumulate(ALL(a), 0ll) < 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<ll> pos;
  ll neg = 0;
  int ans = 0;
  rep(i, n) {
    if(a[i] < 0) {
      ++ans;
      neg += -a[i];
    }
    
    if(a[i] > 0) pos.push_back(a[i]);
  }
  sort(RALL(pos));
  rep(i, pos.size()-1) pos[i+1] += pos[i];
  if(neg > 0) ans += distance(pos.begin(), lower_bound(ALL(pos), neg)) + 1;
  cout << ans << endl;
}


Measured memory_bytes: 5400
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val H, W = in.nextInt
  val Maze = Array.fill(H)(in.next.toCharArray)

  println((for {
    y <- 0 until H
    x <- 0 until W
  } yield max(P(x, y))).max)

  case class P(x: Int, y: Int) {
    def nexts(maze: Array[Array[Char]]): List[P] = 
      List(P(x + 1, y), P(x - 1, y), P(x, y + 1), P(x, y - 1))
        .filter(p => 0 <= p.x && p.x < W && 0 <= p.y && p.y < H && maze(y)(x) == '.')
  }

  def max(s: P): Int = {
    val maze = Maze.map(_.clone)

    def step(curs: List[P], n: Int): Int = {
      if (curs.isEmpty) n - 2
      else {
        val nexts = curs.flatMap(_.nexts(maze)).distinct
        curs.foreach(p => maze(p.y)(p.x) = '#')
        step(nexts, n + 1)
      }
    }

    step(List(s), 0)
  }
}

Measured memory_bytes: 70084
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int mod=1e9+7,yuzu=2e5;
ll jic[yuzu|10]={1},inv[yuzu|10]={1};

ll kasumi(ll a,ll b=mod-2){
ll s=1;
for (;b;b>>=1,a=a*a%mod) if (b&1) s=s*a%mod;
return s;
}

ll cal(ll a,ll b){
return jic[a]*inv[b]%mod*inv[a-b]%mod;
}

int main(){
re0 i,j;
for (i=1;i<=yuzu;++i) jic[i]=jic[i-1]*i%mod;
for (i=yuzu;i;--i) inv[i]=kasumi(jic[i]);
int n=read(),m=read(),a=n-read()+1,b=read();
ll ans=0;
for (i=1;i<a;++i){
  ans=(ans+cal(b+i-2,i-1)*cal(n-i+m-b-1,m-b-1)%mod)%mod;
  } 
write(ans);
}

Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
	char t[100001];
	scanf("%s", t);
	int len = strlen(t);
	int pc = 0;
	int ans = 0;
	REP(i, len) {
		if (t[i] == 'p')pc++;
	}
	printf("%d\n", len/2-pc);
	return 0;
}

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

#define int long long
//#define ll int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(vec) (vec).begin(),(vec).end()
#define vint vector<int>
#define pint pair<int,int>
#define vpint vector<pint>

int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
void unite(int x,int y){x=find(x);y=find(y);if(x==y)return;if(rnk[x]<rnk[y]){par[x]=y;}else{par[y]=x;if(rnk[x]==rnk[y])rnk[x]++;}}
bool same(int x,int y){return find(x)==find(y);}

int n,m,x[1002],y[1002],z[1002];

int ppp[8][1002];

signed main(){
    cin>>n>>m;
    REP(i,n)cin>>x[i]>>y[i]>>z[i];
    REP(b,8){
        int p=b&4?1:-1;
        int q=b&2?1:-1;
        int r=b&1?1:-1;
        REP(i,n){
            ppp[b][i]=x[i]*p+y[i]*q+z[i]*r;
        }
    }
    int ans=0;
    REP(b,8){
        sort(ppp[b],ppp[b]+n);
        int val=0;
        REP(i,m){
            val+=ppp[b][n-1-i];
        }
        ans=max(ans,val);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
N = int(input())
w = 0
for i in range(10 ** 5):
    if i * (i + 1) // 2 < N <= (i + 1) * (i + 2) // 2:
        w = i + 1
        break
for i in range(w, 0, -1):
    if N >= i:
        print(i)
        N -= i

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N,K;
  cin >> N >> K;
  vector<int> P(N);
  vector<ll> C(N);
  rep(i,N){
    cin >> P.at(i);
    P.at(i)--;
  }
  rep(i,N)  cin >> C.at(i);

  ll ans=-1e18;
  rep(i,N){
    int now=i;
    ll total=0;
    vector<ll> sum;

    while(1){
      now=P.at(now);
      total += C.at(now);
      sum.p_b(total);
      if(now==i)  break;
    }

    rep(j,sz(sum)){
      if(j>=K)  break;
      if(total<=0){
        chmax(ans,sum.at(j));
      }
      else{
        chmax(ans,total*((K-1-j)/sz(sum)) + sum.at(j));
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3828
n = gets.chomp.to_i
cnt = 0
h = {}
n.times do
  s = gets.chomp.split("").sort.join("")
  if !h.has_key?(s)
    h[s] = 0
  else
    h[s] += 1
  end
end
h.each do |key, k|
  cnt += k * (k+1) / 2
end
puts cnt


Measured memory_bytes: 18428
import sys

line = sys.stdin.readline().strip()
N = int(line)
line = sys.stdin.readline().strip()
A = [int(x) for x in line.split()]

#N = 4
#A = [-2, -6, -1, -4]
#A = [0, 1, 0, 0]

#print(N)
#print(A)
vs = sorted([(x, i) for i, x in enumerate(A)])
k = vs[0] if abs(vs[0][0]) > abs(vs[-1][0]) else vs[-1]
#print(k)

tejun = []

def mv(i, j):
    tejun.append((i, j))
    A[j] += A[i]
    #print("*", i, j, A)

if k[0] > 0:
  mv(k[1], 0)
  mv(k[1], 0)
  for i in range(1, N):
      mv(i - 1, i)
      mv(i - 1, i)
elif k[0] < 0:
  mv(k[1], N - 1)
  mv(k[1], N - 1)
  for i in range(N, 1, -1):
      mv(i - 1, i - 2)
      mv(i - 1, i - 2)
else:
    pass

print(len(tejun))
for t in tejun:
    print(t[0] + 1, t[1] + 1)


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 99999999
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool augment(const Graph& g, int u,
    vector<int>& matchTo, vector<bool>& visited) {
  if (u < 0) return true;
  FOR(e, g[u]) if (!visited[e->dst]) {
    visited[e->dst] = true;
    if (augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
int bipartiteMatching(const Graph& g, int L, Edges& matching) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  REP(u, L) if (matchTo[u] >= 0) // make explicit matching
    matching.push_back( Edge(u, matchTo[u], 1) );
  return match;
}

int main(){
	int i,X,Y,E,s,t,e;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d%d%d",&X,&Y,&E);
		Graph g(X+Y);
		for(;E--;)scanf("%d%d",&s,&t),g[s].push_back(Edge(s,X+t,1)),g[X+t].push_back(Edge(X+t,s,1));
		Edges matching;
		bipartiteMatching(g,X,matching);
		printf("%d\n",matching.size());
	//}
}

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

int main()
{
	double x[2], y[2];
	for (int i = 0; i < 2; i++)
		scanf("%lf%lf", x + i, y + i);
	printf("%lf\n", hypot(x[0] - x[1], y[0] - y[1]));

	return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>

void trace(int A[], int N) {
    int i;
    for (i = 0; i < N - 1; i++) printf("%d ", A[i]);
    printf("%d\n", A[N-1]);
}

int selectionSort(int A[], int N) {
    int i, j, minj, count;
    count = 0;
    for (i = 0; i < N - 1; i++) {
        minj = i;
        for (j = i + 1; j <  N; j++) {
            if (A[minj] > A[j]) minj = j;
        }
        if (minj != i) {
            int tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            count++;
        }
    }
    return count;
}

int main(void) {
    int i;
    int N; // 入力数
    int A[100]; // ソートする配列
    int count;
    scanf("%d", &N);
    for (i = 0; i < N; i++) scanf("%d", A + i);
    count = selectionSort(A, N);
    trace(A, N);
    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 1960
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{int from,to,cost;};
vector<edge> es(100); //辺の集合
vector<int> d(100,INFi);//最短距離
int V,E;//頂点数、辺数

int main(){
    string s;cin>>s;
    string ans;
    if(stoi(s.substr(0,2))>=1&&stoi(s.substr(0,2))<=12) ans+="MM";
    else ans+="YY";
    if(stoi(s.substr(2,2))>=1&&stoi(s.substr(2,2))<=12) ans+="MM";
    else ans+="YY";
    if(ans=="MMMM"){
        cout<<"AMBIGUOUS"<<endl;
        return 0;
    }
    else if(ans=="YYYY"){
        cout<<"NA"<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  static long[][] sol;
  static boolean[][] flag;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    sol = new long[N][N];
    flag = new boolean[N][N];
    int[] arr = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = sc.nextInt();
    }
    if (N == 1) {
      System.out.println(arr[0]);
    } else {
      System.out.println(solve(arr, 0, N - 1));
    }
  }


  private static long solve(int[] arr, int i, int length) {
    if (i == length) {
      return arr[i];
    } else {
      if (!flag[i + 1][length]) {
        sol[i + 1][length] = solve(arr, i + 1, length);
        flag[i + 1][length] = true;
      }
      if (!flag[i][length - 1]) {
        sol[i][length - 1] = solve(arr, i, length - 1);
        flag[i][length - 1] = true;
      }
      return Math.max((arr[i] - sol[i + 1][length]), (arr[length] - sol[i][length - 1]));
    }
  }

}


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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int count=1;
  for(int i = N - 2; i >= 0; i--){
    if(d.at(i+1) > d.at(i)){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main(void) {
  while(1) {
    int n, x;
    cin >> n >> x;

    if(n == 0 && x == 0) break;

    int a[301]={0};
    for(int i=1; i<=n; i++) {
      for(int j=1; j<=n; j++) {
        for(int k=1; k<=n; k++) {
          if(i == j || j == k || i == k) continue;
          a[i+j+k]++;
        }
      }
    }
    cout << a[x]/6 << endl;
  }
}



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

long long cnt(long long a, long long b, long long d, long long e)
{
	if (d >= 0 && b >= 0 && e >= 0 && a >= 0)
		return b+(d/2)*2+(e/2)*2+(a/2)*2;
	return -1e7;
}

int main()
{
	long long a, b, c, d, e, f, g;
	cin >> a >> b >> c >> d >> e >> f >> g;
	cout << max(cnt(a, b, d, e), cnt(a-1, b, d-1, e-1)+3) << endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {

    ll n = 0;
    cin >> n;
    //奇数番
    vector<pi > odd(101000);
    for(ll i = 0; i < odd.size(); i++){
        odd[i].first = 0;
        odd[i].second = i+1;
    }
    //偶数番
    vector<pi > even(101000);
    for(ll i = 0; i < even.size(); i++){
        even[i].first = 0;
        even[i].second = i+1;
    }

    ll max_odd = -1;
    ll max_even = -1;
    
    for(ll i = 1; i <= n; i++){
        ll t; cin >> t;

        if(i % 2 == 1){
            even[t].first++;
            //max_even = max(max_even, even[t].first);
        }else{
            odd[t].first++;
            //max_odd = max(max_odd, odd[t].first);
        }
    }

    sort(odd.rbegin(), odd.rend());
    sort(even.rbegin(), even.rend());

    if(odd[0].second == even[0].second){
        ll t1_ans = n / 2 - odd[1].first + n / 2 - even[0].first;
        ll t2_ans = n / 2 - odd[0].first + n / 2 - even[1].first;
        
        cout << min(t1_ans, t2_ans) << endl;

    }else{
        cout << n / 2 - odd[0].first + n / 2 - even[0].first << endl;
    } 

}

Measured memory_bytes: 3456
//Bismillah hirrahmanir Rahim
        #include<bits/stdc++.h>
        #define ll long long
        #define pb push_back
        #define dbug printf("I am here\n");
        #define Fast ios_base::sync_with_stdio(false); cin.tie(0);
        const int m = 10e6;
        using namespace std;

        int main(){
          Fast;
   ll ar[3];
   for(int i=0;i<3;i++)cin>>ar[i];

   sort(ar,ar+3);
   ll a,b,c;
   a = ar[2]-ar[1];
   b = ar[2] -ar[0];

   int cnt = 0;
      if( a%2 &&  b%2){
    cnt = (a/2 )+ (b/2) ;
    cnt+=1;
   }
  else  if( a%2==0 && b%2==0){
    cnt = (a/2 )+ (b/2) ;
   }
   else if( a%2==0){
    cnt+= (a/2)+2;
    cnt+= b/2;
   }
   else if( b%2==0){
    cnt+= (b/2)+2;
    cnt+= a/2;
   }
   cout<<cnt;
           return 0;

        }


Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long ans=0;
		long q=0;
		if((s[1]&1)==0&&s[1]/2<=s[0]){
			q=(s[0]-(s[1]/2))/s[1]+1;
			ans+=q*q*q;
		}
		if(s[0]>=s[1]){
			q=s[0]/s[1];
			ans+=q*q*q;
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 13268
s = list(input())
t = list(input())
 
def f(s, t):
  s.sort()
  t.sort(reverse=True)
  s_sum = 0
  t_sum = 0
  for i in range(len(s)):
    s[i] = ord(s[i])
  
  for i in range(len(t)):
    t[i] = ord(t[i])
  
  for i in range(len(s)):
    if not i + 1 >= len(t):
      s_sum += s[i]
      t_sum += t[i]

      if s_sum < t_sum:
        return 'Yes'
      elif s_sum > t_sum:
        return 'No'
    else:
      break

  if len(s) < len(t):
    return 'Yes'
  else:
    return 'No'

print(f(s, t))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

int even(int n) {
  return (n % 2 == 0) ? 1 : 0;
}

int main() {
  int i;
  long long int n, u_val[100000], v_val[100000], w_val[100000];
  scanf("%lld", &n);
  for(i = 0; i < n - 1; i++) {
    scanf("%lld %lld %lld", &u_val[i], &v_val[i], &w_val[i]);
    u_val[i]--;
    v_val[i]--;
  }

  long long int *ans;
  ans = (long long int*)malloc(sizeof(long long int) * n);
  for(i = 0; i < n; i++) ans[i] = -1;

  int node1 = u_val[0];
  int node2 = v_val[0];
  int dist  = w_val[0];
  ans[node1] = 0;
  if(even(dist)) ans[node2] = ans[node1];
  else           ans[node2] = 1 - ans[node1];

  int count = 0;
  while(1) {
    for(i = 1; i < n; i++) {
      node1 = u_val[i];
      node2 = v_val[i];
      dist  = w_val[i];
      if(ans[node1] != -1 && ans[node2] == -1) {
        if(even(dist)) ans[node2] = ans[node1];
        else           ans[node2] = 1 - ans[node1];
      } else if(ans[node1] == -1 && ans[node2] != -1) {
        if(even(dist)) ans[node1] = ans[node2];
        else           ans[node1] = 1 - ans[node2];
      }
    }
    for(i = 0; i < n; i++) {
      if(ans[i] == -1) count++;
    }
    if(count == 0) {
      break;
    }
    count = 0;
  }

  for(i = 0; i < n; i++) printf("%lld\n", ans[i]);

  free(ans);

  return 0;
}


Measured memory_bytes: 3456
n = int(input())
a = sorted([x, i] for i, x in enumerate(list(map(int, input().split()))))
f = [[0 for j in range(n)] for i in range(n)]
for i in range(n-1, -1, -1):
    f[i][i] = a[0][0]*abs(a[0][1]-i)
    for j in range(i+1, n):
        f[i][j] = max(f[i+1][j]+a[j-i][0]*abs(a[j-i][1]-i), f[i][j-1]+a[j-i][0]*abs(a[j-i][1]-j))
print(f[0][n-1])

Measured memory_bytes: 101700
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		String s = sc.next();
		int b = Integer.parseInt(sc.next());
		if(s.equals("+")) {
			System.out.println(a + b);
		} else {
			System.out.println(a - b);
		}
	}
}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long
#define vec pair<int,int>
#define x first
#define y second

const int N=2e5+5;
vec f[N];
int n,L[N],R[N],s[N],lim,a[N],c[N],b[N];
double ans;

vec mk(vec x,vec y){
	return vec(y.x-x.x,y.y-x.y);
}

int cj(vec x,vec y){
	return x.x*y.y-x.y*y.x;
}

signed main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<=n;i++) read(b[i]);
	int k=max_element(a+1,a+1+n)-a;
	rotate(a+1,a+k,a+1+n);
	rotate(b+1,b+k,b+1+n);
	a[n+1]=a[1];
	for(int i=3;i<=n+1;i++){
		c[i]=2*(b[i-1]+c[i-1])-c[i-2];
		a[i]-=c[i];
	}
	for(int i=1;i<=n+1;i++) f[i].y=a[i],f[i].x=i;
	for(int i=0;i<=n+1;i++){
		while(lim>1&&cj(mk(f[s[lim-1]],f[s[lim]]),mk(f[s[lim-1]],f[i]))>=0) lim--;
		s[++lim]=i;
	}
	L[0]=0;R[n+1]=n+1;
	for(int i=1;i<=lim;i++) L[s[i]]=R[s[i]]=s[i];
	for(int i=1;i<=n;i++) if(!L[i]) L[i]=L[i-1];
	for(int i=n;i;i--) if(!R[i]) R[i]=R[i+1];
	for(int i=1;i<=n;i++){
		ans+=c[i];
		if(L[i]==R[i]) ans+=a[i];
		else ans+=((i-L[i])*a[R[i]]+(R[i]-i)*a[L[i]])*1.0/(R[i]-L[i]);
	}
	printf("%.12lf",ans/n);
}

Measured memory_bytes: 16124
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int N;
    cin >> N;
    vector<pair<int, int>> res;
    if (N % 2 == 0) {
        int dame = 1;
        int st = N;
        while (st != 0) {
            for (int i = 1; i <= N; i++) {
                if (i == dame || st >= i)
                    continue;
                res.push_back({st, i});
            }
            st--;
            dame++;
        }
    } else {
        int dame = 0;
        int st = N;
        while (st != 0) {
            for (int i = 1; i <= N; i++) {
                if (st == N)
                    continue;
                if (i == dame || st >= i)
                    continue;
                res.push_back({st, i});
            }
            st--;
            dame++;
        }
    }

    cout << res.size() << endl;
    for (auto r : res) {
        cout << r.first << " " << r.second << endl;
    }
}

Measured memory_bytes: 384
def main():
    mod=10**9+7
    n=int(input())
    a=input()+'z'
    if a[0]=='W':
        print(0)
        return 0
    x=[]
    cnt=1
    for i in range(2*n):
        if a[i]==a[i+1]:
            cnt+=1
        else:
            x.append(cnt)
            cnt=1
    lx=len(x)
    if lx==1:
        ans=1
        for i in range(2,n+1):
            ans=ans*i%mod
        print(ans)
        return 0
    if x[0]%2==0 or x[-1]%2==0:
        print(0)
        return 0
    y=[1]
    now=1
    cnt=1
    for i in range(lx-1):
        if x[i]%2!=0:
            cnt+=now
            y.append(cnt)
        else:
            now*=-1
            cnt+=now
            y.append(cnt)
    if y[-1]>1 or 0 in y:
        print(0)
        return 0
    z=[1]+[y[i+1]-y[i] for i in range(lx-1)]
    ans=1
    for i in range(lx):
        if x[i]%2==0:
            ans=ans*pow(y[i],x[i]//2,mod)%mod
        else:
            ans=ans*pow(y[i],(x[i]-1)//2+(z[i]==-1),mod)%mod
    for i in range(2,n+1):
        ans=ans*i%mod
    print(ans)
main()

Measured memory_bytes: 16104
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <unordered_set>


using namespace std;


int main()
{
    int P, Q, R;
    cin >> P >> Q >> R;
    int maximum = std::max(std::max(P,Q), R);
    cout << P+Q+R-maximum << endl;
    return 0;
}

Measured memory_bytes: 256
# 解説AC
N,K,Q = map(int, input().split())
A = [int(i) for i in input().split()]

ans = float("inf")

# A[i]: 最小値X
for i in range(N):
    # 最大値Yの候補
    can = []

    # A[left:right]: A[i]以上の連続部分列
    left = 0
    while left < N:
        right = left
        while right < N and A[i] <= A[right]:
            right += 1

        # 連続部分列長
        L = right - left

        tmp = sorted([A[j] for j in range(left, right)])
        can += tmp[:max(0, L - K + 1)]

        left = right + 1
    
    # Q番目に小さいものがYの最小値
    can.sort()
    if len(can) >= Q:
        ans = min(ans, can[Q - 1] - A[i])

print(ans)

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

using namespace std;

int main(void)
{
    int N; cin >> N;
    int top = 0;
    int total = 0;

    for(int i = 0; i < N; ++i)
    {
        int h;

        cin >> h;

        if(h >= top)
        {
            top = h;
            total++;
        }
    }

    cout << total << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <numeric>
#include <random>
#include <memory>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <cstring>
#include <cassert>
#include <bitset>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif
#define int ll
//#pragma GCC optimize("Ofast")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define sz(x) int((x).size())

#ifndef LOCAL
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#else
	mt19937 rng(228);
#endif

const int N = 2e5 + 7;
const int inf = INT_MAX / 2;
const ll INF = LLONG_MAX / 3;
const int MOD = 998244353;
const ld eps = 1e-6;
const string cars[] = {"🚗", "🚕", "🚙"};

int n, k;
int used[N];
vector < int > g[N];

void dfs_ans(int u, int k);

void dfs(int u, int k) {
	if (k == 0) {
		cout << u << endl;
		exit(0);
	}
	if (used[u]) {
		int diff = used[u] - k;
		k %= diff;

		dfs_ans(u, k);
	}
	used[u] = k;

	for (int v : g[u]) {
		dfs(v, k - 1);
	}
}

void dfs_ans(int u, int k) {
	if (k == 0) {
		cout << u << endl;
		exit(0);
	}

	for (int v : g[u]) {
		dfs_ans(v, k - 1);
	}
}

signed main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(9);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;

		g[i].push_back(x);
	}

	dfs(1, k);
	
	return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B, K;
    cin >> A >> B >> K;
    int cnt = 0;
    for(int i = min(A, B);i >= 1;i--) {
        if(A % i == 0 && B % i == 0) {
            //cout << i << endl;
            cnt++;
        }
        if(cnt == K) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

int main() {
  int D, N, X=1;
  cin >> D >> N;
  if(N%100!=0){
    rep(i, D) X=X*100;
    X=N*X;
  }
  else{
    rep(i, D) X=X*100;
    X=(N+1)*X;
  }
  cout << X << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1<<29;
int main() {
    int n, m;
    cin >> n >> m;

    int dp[50010];
    fill_n(dp, n+1, INF);
    dp[0] = 0;

    for (int i = 0; i < m; i++)
    {
        int w;
        cin >> w;
        for (int j = w; j < n+1; j++)
        {
           if(dp[j-w] != INF) dp[j] = min(dp[j-w] + 1, dp[j]);
        }
    }

    if(dp[n] == INF) cout << "-1" << endl;
    else cout << dp[n] << endl;
}


Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB" || s == "CCC")
    cout << "No";
    else
    cout << "Yes";
}









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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int n;
	cin >> n;
	vector<long long> b(n);	
	for(int i = 0; i < n; ++i){
		cin >> b[i];
	}

	int cnt_zero = 0;
	int cnt_neg = 0;
	long long tot = 0;
	long long min_abs = 1e18;
	for(int i = 0; i < n; ++i){
		if(b[i] == 0) cnt_zero++;
		if(b[i] < 0){
			cnt_neg++;
		} 
		tot += abs(b[i]);
		min_abs = min(min_abs, abs(b[i]));
	}

	long long res = 0;
	if( cnt_zero > 0 || (cnt_neg % 2 == 0) ){
		res = tot;
	}else{
		res = tot - 2 * min_abs;
	}

	cout << res;
    return 0;
}


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

using ll = long long;
using P = pair<int, int>;
using edge = struct {int to; ll cost;};

#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

const int di[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dj[] = {0, -1, 0, 1, 1, -1, 1, -1};
const int INF = 1001001001;

const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  ll nn = a[n-1];
  ll temp = a[n-1];
  int index = n-1;
  rep(i, n-1) {
    if(abs(nn/2 - a[i]) < temp) {
      temp = abs((nn+1)/2 - a[i]);
      index = i;
    }
  }
  cout << nn << " " << a[index] << "\n";
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int N;
  vector<int> L;
  cin >> N;
  for(int i=0; i<N; i++){
    int l;
    cin >> l;
    L.push_back(l);
  }
  sort(L.begin(), L.end());

  int ans = 0;

  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      int target = L[i] + L[j];
      int index = lower_bound(L.begin(), L.end(), target) - L.begin();
      if(index > j && index > i){
        ans += max(0, index - (j+1));
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
n, q = map(int, input().split())
edge = [[] for _ in range(n)]
count = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    count[p] += x

not_yet = [True] * n
not_yet[0] = False
stack = [0]
while stack:
    parent = stack.pop()
    for child in edge[parent]:
        if not_yet[child]:
            count[child] += count[parent]
            not_yet[child] = False
            stack.append(child)
print(*count)
    

Measured memory_bytes: 55856