akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,k,ans=0;
cin >> n >> k;
int l[n];
for(int i=0;i<n;i++){
	cin >> l[i];
}

sort(l,l+n);

for(int i=n-1;i>=n-k;i--){
	ans += l[i]; 
}
cout << ans << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
n = input()
p = map(float, raw_input().split())

dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
    pi = p[i - 1]
    for j in range(i + 1):
        dp[i][j] = pi * dp[i - 1][j - 1] + (1 - pi) * dp[i - 1][j]
resp = 0
for i in range(n / 2 + 1, n + 1):
    resp += dp[n][i]
print(resp)


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

vector<vpii> g;
vi ans;
void dfs(int v, int p, int c) {
    int nc = 1;
    for (auto tp : g[v]) {
        int t = tp.first, en = tp.second;
        if (t == p) continue;
        if (nc == c) ++nc;
        ans[en] = nc;
        dfs(t, v, nc);
        ++nc;
    }
}

int main(){
    int n;
    cin >> n;
    g = vector<vpii>(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    ans = vi(n-1);
    dfs(0, 0, 0);
    int cnum = 0;
    rep(i, n-1) cnum = max(cnum, ans[i]);
    cout << cnum << endl;
    rep(i, n-1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 11056
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>A(n);
    for(int i=0; i<n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    cout << A[n-1]-A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;

int main(){
	ll N,M;cin >> N>>M;
	ll ans = N;

	for(int i=0;i<M;i++){
		ll A;cin >> A;
		ans -= A;
	}
	if(ans < 0){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll a,b,c,d,e,k,l,m,n,o=0,p,q,x,y,z,max1=0,ans;
    string s,t,u;
    cin>>a>>b;
    if (a>b) {
        o+=a+a-1;
    }
    else if(a<b){
        o+=b+b-1;
    }
    else{
        o+=a+b;
    }
    
    cout<<o<<endl;
}



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

// ITP1_8_C:   Counting Characters
int main(){
  char ch;
  std::vector<int> nums(26, 0);
  while (cin >> ch) {
    if ('a' <= ch && ch <= 'z') {
      nums[(ch - 'a')]++;
    } else if ('A' <= ch && ch <= 'Z') {
      nums[(ch - 'A')]++;
    }
  }
  for (int i = 0; i < 26; ++i) {
    cout << char('a' + i) << " : " << nums[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
const int MAXN=2e5+7;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i*i<=n;++i)
    {
        if(n%i==0)
        {
            if(i<(n/i-1))
            {
                ans+=n/i-1;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

template <typename T>
class FenwickTree
{
public:
  int N;
  vector<T> dat;

  FenwickTree(int n, T m = 0)
  {
    init(n, m);
  }

  void init(int n, int m)
  {
    N = n;
    dat.resize(n + 1);
    for (int i = 0; i < dat.size(); i++)
    {
      dat[i] = m;
    }
  }

  int64_t sum(int i)
  {
    T s = 0;
    while (i > 0)
    {
      s += dat[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i, T x)
  {
    while (i <= N)
    {
      dat[i] += x;
      i += i & -i;
    }
  }
};

int main()
{
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(N), S(N + 1, 0); // l <= x <= r -> S[r+1] - S[l]
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++)
  {
    S.at(i + 1) = S.at(i) + A.at(i);
  }
  vector<int64_t> B(N + 1);
  for (int i = 0; i <= N; i++)
  {
    B.at(i) = S.at(i) - K * i;
  }
  auto C = B;
  sort(C.begin(), C.end());
  int cnt = 1;
  map<int64_t, int64_t> mp;
  mp[C[0]] = 1;
  for (int i = 1; i <= N; i++)
  {
    if (C.at(i) > C.at(i - 1))
    {
      cnt++;
    }
    mp[C[i]] = cnt;
  }
  for (int i = 0; i <= N; i++)
  {
    B.at(i) = mp[B.at(i)];
  }
  int64_t ans = 0;
  FenwickTree<int> ft(cnt + 1);
  for (int i = 0; i <= N; i++)
  {
    ans += ft.sum(B.at(i));
    ft.add(B.at(i), 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 22804
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;



void solve() {

	string s;

	long long N;
	long long MIN = 1000000000000;

	cin >> N;
	
	for (int i = 1;i< sqrt(N)+1;i++) {
		
		if (N%i == 0) {
			long long M = i + N / i - 2;
			if (MIN > M)MIN = M;
		}
	}

	cout << MIN << endl;
	

}


int main() {
	solve();

}

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

int main(){
	int n, max;
	cin >> n;
	for (int z = 0; z < n;z++) {
		string x, xx, y, yy, outp;
		cin >> x >> y;
		if (cin.eof()) { break; }
		int lengx = x.size();
		int lengy = y.size();
		
		if (lengx > 80 || lengy > 80) {
			cout << "overflow" << endl;
			continue;
		}
		
		if (lengx < lengy){
			max = lengy;
		}
		else{
			max = lengx;
		}

		int m[81], n[81], wa[81];
		for(int i=0;i<81;i++){
			m[i] = 0;
			n[i] = 0;
			wa[i] = 0;
		}

		for (int i = 0; i<lengx; i++) {
			xx = x[lengx - i - 1];
			m[i] = stoi(xx);
		}
		for (int i = 0; i<lengy; i++) {
			yy = y[lengy - i - 1];
			n[i] = stoi(yy);
		}

		for(int i = 0; i < max; i++){
			wa[i] += n[i];
			wa[i] += m[i];

			if (wa[i]>=10){
				wa[i] -= 10;
				wa[i + 1] += 1;
			}

		}
		if(wa[80] == 1){
			cout << "overflow" << endl;
			continue;
		}

		int c = max;
		if(wa[max] == 1){
			c += 1;
		}

		for(int i=0;i<c;i++){
			outp += to_string(wa[c - i -1]);
		}
		cout << outp << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
#include<stdio.h>

int main(void){
  int a, i;
  
  scanf("%d", &a);
  
  double b[a], c = 0;
  
  for(i = 0; i < a; i++){
    scanf("%lf", &b[i]);
    c += 1.0 / b[i];
  }
  
  c = 1.0 / c;
  
  printf("%lf\n", c);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

//struct Point {
//	int x,y;
//};
//long long ccw(const Point& A, const Point& B, const Point& C) { // 시계방향이면 음수 
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
int d[5001][5001];

int main() { // 골드 1, 플레 1
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	string s; cin >> s;
	s = "9" + s;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (s[i] == s[j] && j - i - 1 >= d[i - 1][j - 1]) {
				d[i][j] = d[i - 1][j - 1] + 1; 
				ans = max(ans, d[i][j]);
			}
		}
	}
	cout << ans << '\n';



}

Measured memory_bytes: 96768
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

template<typename CostType>
/// \brief 辺の情報
struct Edge{
  int      to;
  CostType cost;

  Edge(int t, CostType c): to(t), cost(c){
  }
};

template<typename CostType>
class Graph{

private:

  /// \brief adjacent_list_[n]=ノードnの隣接リストを表すvector<Edge>
  std::vector<std::vector<Edge<CostType>>> adjacent_list_;

public:

  /// \brief 頂点数
  const int NODE_SIZE_;

  /// \brief コンストラクタ
  /// \param node_size 頂点数
  explicit Graph(const int node_size): NODE_SIZE_(node_size),
                                       adjacent_list_(node_size){
  }

  /// \brief 有向グラフの辺を生やす
  /// \param from 辺の根本の頂点の番号
  /// \param to 辺の先の頂点の番号
  /// \param cost 辺のコスト
  void SetDirectedEdge(const int from, const int to, const CostType cost){
    adjacent_list_[from].push_back(Edge<CostType>(to, cost));
  }

  /// \brief 無向グラフの辺を生やす
  /// \param node_a 一方の頂点の番号
  /// \param node_b もう一方の頂点の番号
  /// \param cost 辺のコスト
  void
  SetUndirectedEdge(const int node_a, const int node_b, const CostType cost){
    SetDirectedEdge(node_a, node_b, cost);
    SetDirectedEdge(node_b, node_a, cost);
  }

  /// \brief ある頂点の隣接リストを取得
  /// \param node_num 頂点の番号
  /// \return 隣接リスト
  std::vector<Edge<CostType>> GetAdjacentList(int node_num) const{
    return adjacent_list_[node_num];
  }
};

using namespace std;



int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;
  Graph<int> graph(n+1);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    graph.SetUndirectedEdge(a,b,1);
  }

  vector<int> path;
  vector<bool> visited(n+1,false);
  vector<int> prev_node(n+1);
  int start_node=1;

  int current_node=start_node;
  while(true){
    visited[current_node]=true;
    bool found_next=false;
    for(auto e:graph.GetAdjacentList(current_node)){
      if(!visited[e.to]){
        found_next=true;
        prev_node[e.to]=current_node;
        current_node=e.to;
        break;
      }
    }
    if(!found_next){
      int backtrack=current_node;
      while(true){
        if(backtrack==start_node) break;
        path.push_back(backtrack);

        backtrack=prev_node[backtrack];
      }

      break;
    }
  }

  current_node=start_node;
  while(true){
    visited[current_node]=true;
    path.push_back(current_node);
    bool found_next=false;
    for(auto e:graph.GetAdjacentList(current_node)){
      if(!visited[e.to]){
        found_next=true;
        current_node=e.to;
        break;
      }
    }
    if(!found_next){
      break;
    }
  }

  cout<<path.size()<<endl;
  for(int i=0;i<path.size()-1;i++){
    cout<<path[i]<<" ";
  }
  cout<<path.back()<<endl;




  return 0;
}


Measured memory_bytes: 7288
def main():
    N,K = map(int,input().split())
    XY = [list(map(int,input().split())) for _ in [0]*N]
    
    iX = [x for x,y in XY]
    iY = [y for x,y in XY]
    iX.sort()
    iY.sort()
    X = {x:i for i,x in enumerate(iX)}
    Y = {y:i for i,y in enumerate(iY)}

    c = [[0]*(N+1) for i in [0]*(N+1)]
    for x,y in XY:
        c[Y[y]+1][X[x]+1] = 1

    for i in range(N):
        ci1 = c[i+1]
        for j in range(N):
            ci1[j+1] += ci1[j]
    for i in range(N):
        ci1 = c[i+1]
        ci = c[i]
        for j in range(N):
            ci1[j+1] += ci[j+1]

    ans = 10**20
    for u in range(N):
        for d in range(u+K-1,N):
            l = 0
            r = K-1
            dY = iY[d]-iY[u]
            cd = c[d+1]
            cu = c[u]
            while r<N:
                if cd[r+1]+cu[l]-cu[r+1]-cd[l] >=K:
                    ans = min(ans, (iX[r] - iX[l])*dY)
                    l+=1
                else:r+=1

    print(ans)
main()

Measured memory_bytes: 3064
N = int(input())
S = input()

a_lst = ([i for i, x in enumerate(S) if x == 'A'])
count = 0
for j in a_lst:
    if len(S) >= j + 3:
        if S[j+1] == 'B' and S[j+2] == 'C':
            count += 1
print(count)

Measured memory_bytes: 9044
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr itr operator * () const { return i; }
    constexpr bool operator != (iterator x) const { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_): l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const { return l; }
  constexpr iterator end() const { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr itr operator * () const { return i; }
    constexpr bool operator != (iterator x) const { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const { return r; }
  constexpr iterator end() const { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  i64 A, V, B, W;
  std::cin >> A >> V >> B >> W;
  i64 T;
  std::cin >> T;
  if (V <= W) {
    std::cout << "NO\n";
    return 0;
  }
  else {
    if ((std::abs(A - B) + (V - W) - 1) / (V - W) <= T) {
      std::cout << "YES\n";
    }
    else {
      std::cout << "NO\n";
    }
    return 0;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void){
    int A, B, M;
    scanf("%d%d", &A, &B);
    M=A-B;
    if (A+B>M) M=A+B;
    if (A*B>M) M=A*B;
    printf("%d", M);
    return 0;
}


Measured memory_bytes: 128
N,Y=map(int,input().split())

res10000=-1
res5000=-1
res1000=-1

for a in range(0,N+1):
    for b in range(0,N-a+1):
        total=a*10000+b*5000+(N-a-b)*1000
        if total == Y:
            res10000=a
            res5000=b
            res1000=N-a-b
            
print(res10000,res5000,res1000)

Measured memory_bytes: 3064
import sys
cl = []

for _ in range(3):
    c = list(map(int,input().split()))
    cl.append(c)

if cl[0][0] + cl[1][1] != cl[1][0] + cl[0][1]:
    print("No")
    sys.exit()

if cl[1][1] + cl[2][2] != cl[1][2] + cl[2][1]:
    print("No")
    sys.exit()

if cl[0][0] + cl[2][2] != cl[0][2] + cl[2][0]:
    print("No")
    sys.exit()

print("Yes")

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

int main()
{
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  
  int sum;
  for(int i=0;i<n;i++)
    sum+=a.at(i);
  int result=0;
  
  for(int i=0;i<n;i++)
  {
    double x=a.at(i)/sum;
    double y=1/(4*m);
    
    if(a.at(i)*4*m>=sum)
      result++;
  }
  
  
  if(result>=m)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = ni();
		int m = ni();

		if (m % n == 0) {
			out(m + n);
		} else {
			out(m - n);
		}

	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static double min(double d, double e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 35816
#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ls p<<1
#define rs p<<1|1
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define int long long
#define vi vector<int>
#define mii map<int,int>
#define pii pair<int,int>
#define ull unsigned long long
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
char *fs,*ft,buf[1<<20];
#define gc() (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<20,stdin),fs==ft))?0:*fs++;
inline int read(){
int x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();}
return x*f;}
using namespace std;
const int N=2e5+5;
const int inf=0x7fffffff;
const int mod=998244353;
const double eps=1e-6;
vi e[N];int a[N],d[N],ans[N];
void dfs(int x,int y,int len)
{
    int pos=inf,tmp;
    if(a[x]>d[len])
    {
        d[++len]=a[x];
    }
    else
    {
        pos=lower_bound(d+1,d+len+1,a[x])-d;
        tmp=d[pos];
        d[pos]=a[x];
    }
    ans[x]=len;
    for(auto v:e[x])
    {
        if(v!=y)
        {
            dfs(v,x,len);
        }
    }
    if(pos!=inf)
    {
        d[pos]=tmp;
    }
}
signed main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        e[v].pb(u);e[u].pb(v);
    }
    d[1]=a[1];
    dfs(1,0,1);
    for(int i=1;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 31856
def 解():
    aD = [int(_) for _ in list(input().rstrip())]
    iA = 2**3
    for i in range(iA):
        iR = aD[0]
        for j in range(3):
            if i & (1 << j) :
                iR += aD[j+1]
            else:
                iR -= aD[j+1]
        if iR == 7:
            sR = str(aD[0])
            def buildSS(b):
                if b :
                    return "+"
                else:
                    return "-"
            for j in range(3):
                sR = "".join((sR,buildSS(i&(1<<j)),str(aD[j+1])))
            print("".join((sR,"=7")))
            exit()

解()



Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


//sizeによる実装
class UnionFind {
public:
	vector<int> s, p, es;
	map<int, int>sizemp;

	UnionFind() {}
	UnionFind(int size) {
		s.resize(size, 0);
		p.resize(size, 0);
		es.resize(size, 0);
		sizemp[1] = size;
		rep(i, 0, size)makeSet(i);
	}

	void makeSet(int x) {
		p[x] = x;
		s[x] = 1;
		es[x] = 0;
	}

	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	void unite(int x, int y) {
		x = findSet(x);
		y = findSet(y);
		es[x]++;
		if (x == y)return;
		if (s[x] < s[y])swap(x, y);
		int szx = size(x);
		int szy = size(y);
		sizemp[szx]--;
		sizemp[szy]--;
		sizemp[szx + szy]++;
		if (sizemp[szx] == 0)sizemp.erase(szx);
		if (sizemp[szy] == 0)sizemp.erase(szy);
		p[y] = x;
		s[x] += s[y];
		es[x] += es[y];
	}


	int findSet(int x) {
		if (x == p[x]) {
			return x;
		}
		else {
			return p[x] = findSet(p[x]);
		}
	}

	int size(int x) {
		return s[findSet(x)];
	}
	int esize(int x) {
		return es[findSet(x)];
	}
	int minsz() {
		auto beg = sizemp.begin();
		return beg->first;
	}
};
vector<int>near[101010];
vector<int>ng[101010];

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

	int N, M, K;
	cin >> N >> M >> K;
	UnionFind un = UnionFind(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		near[A].pb(B);
		near[B].pb(A);
		un.unite(A, B);
	}
	for (int i = 0; i < K; i++) {
		int C, D;
		cin >> C >> D;
		C--, D--;
		ng[C].pb(D);
		ng[D].pb(C);
	}
	for (int i = 0; i < N; i++) {
		int sz = un.size(i);
		sz -= (int)near[i].size();
		fore(x, ng[i])if (un.same(i, x))sz--;
		puts(sz-1);
	}

	return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
int main(){
    deque<int> A;
    int64_t x;
    int q, d, num;
    cin >> q;
    for (int i=0; i<q; i++){
        cin >> num;
        if (num == 0){
            cin >> d >> x;
            if (d == 0){
                A.insert(A.begin(), x);
            }else{
                A.push_back(x);
            }
        }else if (num == 1){
            cin >> d;
            cout << A.at(d) << endl;
        }else{
            cin >> d;
            if (d == 1){
                A.pop_back();
            }else{
                A.pop_front();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4572
import java.util.Scanner;
import java.lang.Math;
class Main{
  public static void main(String args[]){
    Scanner stdIn=new Scanner(System.in);
    int x=stdIn.nextInt();
    long[] a=new long[x];
    //input
    for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    }
    //print
    for(int i=0;i<x;i++){
      System.out.print(a[i]);
      if(i!=x-1) System.out.print(" ");
    }
    System.out.println();
    //sort
    long v;
    for(int i=1;i<x;i++){
      v=a[i];
      int j=i-1;
      while(j>=0&&a[j]>v){
        a[j+1]=a[j];
        a[j]=v;
        j--;
      }
      for(int k=0;k<x;k++){
        System.out.print(a[k]);
        if(k!=x-1) System.out.print(" ");
      }
      System.out.println();
    }
  }
}



Measured memory_bytes: 34328
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,k,t,k1,ans=0,sum=0;
    vector<ll> q,a,b;
    cin>>n>>k;
  k1=k;
    for(int i=0;i<n;i++){
        cin>>t;
        a.push_back(t);
    }
 
    while(k>0){
        q.push_back(k%2);
        k=k/2;
    }
 
    for(int i=0;i<q.size();i++){
        ll x=0,y=0;
        for(int j=0;j<a.size();j++){
            if(((1LL<<i)&a[j])==0){
                x++;
            }
            else{
                y++;
            }
        }
      //cout<<x<<" "<<y<<endl;
        if(x>y){
            b.push_back(1);
        }
        else{
            b.push_back(0);
        }
    }
 
    for(int i=q.size()-1;i>-1;i--){
        if(b[i]==1){
          //cout<<"ok"<<(1<<i)<<endl;
            if((ans+(1LL<<i))<k1+1){
              ans+=(1LL<<i);
            }
          //cout<<ans<<endl;
        }
    }
  //cout<<ans<<endl;
 
    for(int i=0;i<a.size();i++){
        sum+=a[i]^ans;
    }
    cout<<sum<<endl;
}

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

vector<vector<string>> memo;
// index, val
int f(int i, int j, string& s1, string& s2)
{
    if(i == 0 || j == 0)
        return 0;
    if(s1[i-1] == s2[j-1])
            return f(i-1,j-1, s1, s2) + 1;
    else
        return max(f(i, j-1, s1, s2), f(i-1, j, s1, s2));
}

string lcs(int i, int j, string& s1, string& s2)
{
    if(i == 0 || j == 0)
        return "";
    if(!memo[i][j].empty())
        return memo[i][j];
    if(s1[i-1] == s2[j-1])
    {
        string s = lcs(i-1, j-1, s1, s2);
        memo[i][j] = s + s1[i-1];
        return memo[i][j];
    }
    else
    {
        string m1 = lcs(i, j-1, s1, s2);
        string m2 = lcs(i-1, j, s1, s2);

        memo[i][j] = m1.size() > m2.size() ? m1 : m2;
        return memo[i][j];
    }
}

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    if(s1.empty() || s2.empty())
    {
        cout << "" << endl;
        return 0;
    }

    // RECURSIVE + MEMO
//    memo.resize(s1.size()+1, vector<string>(s2.size()+1));
//    string answer = lcs(s1.size(), s2.size(), s1, s2);
//    cout << answer << endl;


    // 2D DP
//    vector<vector<string>> dp(s1.size() + 1, vector<string>(s2.size()+1));
//    //dp[i][j] = lcs of first i and j characters
//    //dp[i][0] = "", dp[0][j] = ""
//    //dp[i][j] =


//    for(int i = 1; i <= s1.size(); i++)
//    {
//        for(int j = 1; j <= s2.size(); j++)
//        {
//            if(s1[i-1] == s2[j-1])
//                dp[i][j] = dp[i-1][j-1] + s1[i-1];
//            else
//            {
//                auto& ss1 = dp[i-1][j];
//                auto& ss2 = dp[i][j-1];
//                dp[i][j] = ss1.size() > ss2.size() ? ss1 : ss2;
//            }
//        }
//    }


//    cout << dp[s1.size()][s2.size()] << endl;

    // 1D DP
    vector<string> dp(s2.size() + 1);

    for(int i = 1; i <= s1.size(); i++)
    {
        vector<string> tmp(s2.size()+1);
        for(int j = 1; j <= s2.size(); j++)
        {
            if(s1[i-1] == s2[j-1])
                tmp[j] = dp[j-1] + s1[i-1];
            else
            {
                tmp[j] = dp[j].size() > tmp[j-1].size() ? dp[j] : tmp[j-1];
            }
        }
        dp = tmp;
    }

    cout << dp[s2.size()] << endl;
    return 0;
}


Measured memory_bytes: 16796
r1,c1,r2,c2 = map(int,input().split())
MOD = 10**9 + 7
MAX = 2 * (10**6) + 1

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1

for i in range(2, MAX):
	fac[i] = fac[i-1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i-1] * inv[i] % MOD

def com(n,k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n-k] % MOD)

ans = com(r1+c1, r1)
if r1 == r2 or c1 == c2:
	if r1 != r2:
		for r in range(r1+1, r2+1):
			ans = (ans + com(r+c1, r)) % MOD
	if c1 != c2:
		for c in range(c1+1, c2+1):
			ans = (ans + com(r1+c, r1)) % MOD
	print(ans % MOD)
	exit()

diff_c = c2 - c1
keisu = [com(diff_c+i, i+1) for i in range(r2 - r1)]
t_keisu = [0]
for k in keisu:
	t_keisu.append((t_keisu[-1] + k) % MOD)
for r in range(r1+1, r2+1):
	tmp = com(r+c1, r)
	ans = (ans + tmp + tmp * t_keisu[r1 - r]) % MOD

diff_r = r2 - r1
keisu = [com(diff_r+i, i+1) for i in range(c2 - c1)]
t_keisu = [0]
for k in keisu:
	t_keisu.append((t_keisu[-1] + k) % MOD)
for c in range(c1 + 1, c2 + 1):
	tmp = com(r1+c, c)
	ans = (ans + tmp + tmp * t_keisu[c1 - c]) % MOD

print(ans)

Measured memory_bytes: 173616
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int main(){

  double a,b;
  cin>>a>>b;
  printf("%.10f\n",a*b/3.305785);
  
  return 0;
}

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

using namespace std;

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


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

    int N;
    cin >> N;
    vector<int> a(N);
    int mi = 0, ma = 0, miat, maat;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (a[i] < mi) {
            miat = i;
            mi = a[i];
        }
        if (a[i] > ma) {
            maat = i;
            ma = a[i];
        }
    }

    vector<P> ops;
    if (mi < 0 && ma > 0) {
        if (abs(ma) > abs(mi)) {
            for (int i = 0; i < N; i++) {
                if (i != maat) {
                    ops.push_back(P(maat, i));
                    a[i] += a[maat];
                }
            }
        } else {
            for (int i = 0; i < N; i++) {
                if (i != miat) {
                    ops.push_back(P(miat, i));
                    a[i] += a[miat];
                }
            }
        }
    }

    bool ispos = true;
    for (int i = 0; i < N; i++) {
        if (a[i] < 0)
            ispos = false;
    }

    if (ispos) {
        ma = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] >= ma) {
                maat = i;
                ma = a[i];
            }
        }
        ops.push_back(P(maat, 0));
        for (int i = 1; i < N; i++) {
            ops.push_back(P(i - 1, i));
        }
    } else {
        mi = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] <= ma) {
                miat = i;
                mi = a[i];
            }
        }
        ops.push_back(P(miat, N - 1));
        for (int i = N - 1; i >= 1; i--) {
            ops.push_back(P(i, i - 1));
        }
    }

    cout << ops.size() << endl;
    for (P p : ops) {
        cout << p.first + 1 << " " << p.second + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
	string s, t, u;
	int a, b;
	
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	
	if(s==u) {
		a--;
	} else {
		b--;
	}
	
	cout<<a<<" "<<b<<endl;
	
	return 0;
}


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

using namespace std;

int main() {
  	string s;
  	cin >> s;
  	int n = s.size();
    bool even = 0;
  	if (s[0] != s[n - 1])
    	even = 1;
  	if (even == !(n % 2))
    	cout << "Second";
  	else
      	cout << "First";
}

Measured memory_bytes: 512
N, X = map(int, input().split())
x = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return(gcd(b, a % b))

x.sort()
dist = []
for i in range(N-1):
    dist.append(x[i+1] - x[i])

ans = abs(X - x[0])
for i in range(N-1):
    ans = gcd(ans, dist[i])

print(ans)





Measured memory_bytes: 14252
def f(k,a,b,t):
	if k == 0:
		return t
	

	if t >= a:
		if b-a > 2 and k >= 2:
			return f(k%2, a,b,t + k/2 * (b-a))
		else:
			return f(0, a, b, t + k)
	else:
		dist=  a-t
		return f(k-min(k,dist), a, b, t + min(k,dist))

k,a,b = map(int, raw_input().split())
print f(k,a,b,1)

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

int main() {
  int a, b;
  int cnt = 0;
  map<int, int> m;

  for(int i = 0; i < 3; i++){
      cin >> a >> b;
      m[a] += 1;
      m[b] += 1;
  }

  for(auto itr: m){
      if(itr.second >= 2) cnt++;
  }

  if(cnt >= 2) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
int N;
double ave;
cin >>N;
vector<int> a(N);
rep(i,N){
	cin >> a.at(i);
	ave +=a.at(i);
}
ave/=N;
int ans=0;
rep(i,N){
	if (abs(a[ans]-ave)>abs(a[i]-ave))
		ans=i;
}
cout <<ans;
}

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

def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

s = int(input())

if s == 1 or s == 2:
    print(4)
    exit()
ans = 2
while s > 1:
    s = f(s)
    ans += 1

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef unsigned long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

//#define DEBUG

int main()
{
	vector<int> va,vb,vc;
	int n, in;

	//read
	cin >> n;
	rep(i,n)
	{
		cin >> in;
		va.push_back(in);
	}
	rep(i,n)
	{
		cin >> in;
		vb.push_back(in);
	}
	rep(i,n-1)
	{
		cin >> in;
		vc.push_back(in);
	}

	//solve
	int sum = 0;
	rep(i,n)
	{
		sum += vb[i];
	}
	#ifdef DEBUG
		cout << "sum = " << sum << endl;
	#endif

	rep(i,n-1)
	{
		if(va[i] == (va[i+1] - 1))
		{
			sum += vc[va[i] - 1];
		#ifdef DEBUG
			cout << "vc[" << i << "] = " << vc[i] << endl;
		#endif
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right
from copy import deepcopy

def grid_wall(grid, h, w, wall='#'):
    G = [[wall]*(w+2) for _ in range(h+2)]
    for hi in range(h):
        G[hi+1][1:w+1] = grid[hi]
    return G

def solve():
    H, W = MI()
    ch, cw = MI()
    dh, dw = MI()
    G = LLS(H)
    GW = grid_wall(G, H, W)
    GW[dh][dw] = 'G'
    # print(GW)

    move = [(0, 1), (0, -1), (1, 0), (-1, 0)]

    used = deepcopy(GW)
    used[ch][cw] = '#'
    d = deque([(0, ch, cw, used)])

# for _ in range(5):
    while d:
        # print(d)
        tmp2 = []
        while d:
            m, h, w, u = d.popleft()

            for dh in range(-2, 3):
                for dw in range(-2, 3):
                    nh, nw = dh+h, dw+w
                    if not 0 <= nh <= H or not 0 <= nw <= W:
                        continue
                    if u[nh][nw] == '#':
                        continue

                    if (dh, dw) in move:
                        # print(nh, nw)
                        if u[nh][nw] == '#':
                            continue
                        elif u[nh][nw] == 'G':
                            print(m)
                            return
                        d.append((m, nh, nw, u))
                        u[nh][nw] = '#'
                        continue

                    if u[nh][nw] == '#':
                        continue
                    # elif u[nh][nw] == 'G':
                    #     print(mp)
                    #     return
                    tmp2.append((m+1, nh, nw))

        # print(tmp2)
        # mp = mp + 1
        for mm, nh, nw in tmp2:
            if u[nh][nw] == '#':
                continue
            elif u[nh][nw] == 'G':
                print(mm)
                return
            u[nh][nw] = '#'
            d.append((mm, nh, nw, u))

    print(-1)

if __name__ == '__main__':
    solve()



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

int main()
{
    
    int A[100][100]{0};
    
    int n, m;
    int a;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a;
            A[i][j] = a;
        }
    }

    int b[100] { 0 };
    int bn;

    for(int i=0; i<m; ++i){
        cin >> bn;
        b[i] = bn;
    }
    
    int c[100]{0};
    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j){
            c[i] = (A[i][j] * b[j]) + c[i];
        }
    }
    
    for(int i=0; i<n; ++i){
        cout << c[i] << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
signed main(){
  string o,e;
  cin>>o>>e;
  int len=o.size();
  len*=2;
  if(o.size() > e.size())
    len--;

  for(int i=0;i<len;i++){
    if(i%2 == 0)
      cout<<o[i/2];
    else
      cout<<e[i/2];
  }
  cout<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   long long a[N];
   long long tot=0;
   for (int i = 0; i < N; i++)
   {
      cin >> a[i];
      tot ^= a[i];
   }
   for(int i=0;i<N;i++){
      long long ans = tot^a[i];
      cout << ans << " ";
   }
   cout << endl;
   return 0;
}


Measured memory_bytes: 5124
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10 ** 9
dp = [INF] * N
dp[0] = 0
for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j > N - 1:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[-1])

Measured memory_bytes: 84652
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
void solve() {
    int n, W;
    cin >> n >> W;
    vector<int> w(n), v(n);
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
 
    vector<vector<ll>> dp(n + 1, vector<ll>(1e5 + 5, 1e18));
    dp[0][0] = 0;
 
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < dp[i].size(); j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i - 1] >= 0 && dp[i - 1][j - v[i - 1]] < 1e18) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
            }
            if (j > ans && dp[i][j] <= W) {
                ans = j;
            }
        }
    }
    cout << ans;
}
 
int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int t = 1;
    // cin >> t;
    while (t--) solve();
 
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    
    for(int i = 111; i < 1000; i+=111)
    {
        if(i>=n)
        {
            cout<<i<<endl;
            break;
        }
    }
    
    

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    int now=0;
    vvc c(H+2,vc(W+2,'.'));
    rep(i,H){
        rep(j,W){
            cin >> c[i+1][j+1];
        }
    }
    bool b=true;
    rep(i,H){
        rep(j,W){
            if(c[i+1][j+1]=='#'){
                if(c[i][j+1]==c[i+2][j+1]&&c[i+1][j]==c[i+1][j+2]&&c[i][j+1]==c[i+1][j]&&c[i][j+1]=='.')b=false;
            }
        }
    }
    if(b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3676
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

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

    if (s == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;


    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

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

int main(void){
int N, Y;

cin >> N >> Y;

int itiman, gosen, sen;
itiman = -1;
gosen = -1;
sen = -1;

for (int i = 0; i <= N; i++){
    for (int j = 0; j <= N; j++){
        int k = N - i -j;
        if ((i*10000 + j*5000 + k*1000) == Y && k>=0){
            itiman = i;
            gosen = j;
            sen = k;
            break;
        } 

    }
}

cout << itiman << " "<< gosen << " " << sen << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll a, b;
    cin>>a>>b;
    cout<<a*b;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N;
LL Y;

int main(void)
{
	cin >> N >> Y;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= N - i; ++j) {
			int k = N - i - j;
			if (i * 1000 + j * 5000 + k * 10000 == Y) {
				cout << k << " " << j << " " << i << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1\n";
	return 0;
}


Measured memory_bytes: 256