akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_A&lang=jp

#define NIL -1
#define MAX 100005

int n;
struct Node
{
    int l, r, p;
};
Node T[MAX];
int D[MAX];

static void setDepth(int id, int d) {
    D[id] = d;
    if (T[id].l != NIL) setDepth(T[id].l, d+1);
    if (T[id].r != NIL) setDepth(T[id].r, d);
}

static void print(int id) {
    cout << "node " << id << ": ";
    cout << "parent = " << T[id].p << ", ";
    cout << "depth = " << D[id] << ", ";

    if (T[id].p == NIL) cout << "root, ";
    else if (T[id].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    int i = 0;
    cout << "[";
    for (int c = T[id].l; c != NIL; c = T[c].r) {
        if (i > 0) cout << ", ";
        cout << c;
        i++;
    }
    cout << "]\n";
}

int main() {
    cin >> n;
    REP(i, n) T[i].l = T[i].r = T[i].p = NIL;

    REP(i, n) {
        int id, deg;
        cin >> id >> deg;

        int l = 0;
        REP(j, deg) {
            int c; cin >> c;
            if (j == 0) T[id].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = id;
        }
    }

    int root = 0;
    REP(i, n) if (T[i].p == NIL) root = i;
    setDepth(root, 0);

    REP(i, n) print(i);

    return 0;
}



Measured memory_bytes: 4628
class segtree:

    def __init__(self, n, identity):
        # identityは初期値
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_end_leaves = 2 ** (len(nb) - 1)
        else:
            self.num_end_leaves = 2 ** (len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)]
        self.identity = identity

    def update(self, x, val):
        actual_x = x + self.num_end_leaves
        self.array[actual_x] = val
        while actual_x > 0:
            actual_x = actual_x // 2
            self.array[actual_x] = self.array[actual_x * 2] | self.array[actual_x * 2 + 1]

    def get(self, q_left, q_right, arr_ind=1, leaf_left=0, depth=0):
        width_of_floor = self.num_end_leaves // (2 ** depth)
        leaf_right = leaf_left + width_of_floor - 1

        if leaf_left > q_right or leaf_right < q_left:
            return self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left, q_right, 2 * arr_ind, leaf_left, depth + 1)
            val_r = self.get(q_left, q_right, 2 * arr_ind + 1, leaf_left + width_of_floor // 2, depth + 1)
            return val_l | val_r

N = int(input())
S = list(input())
Q = int(input())
T = {}
j = 1
for i in range(97, 97+26):
    T[chr(i)] = j
    j *= 2

s_tree = segtree(N+1, 0)

for i in range(N):
    s_tree.update(i+1, T[S[i]])

for i in range(Q):
    A = list(input().split())
    a, b, c = A
    if a == "2":
        K = bin(s_tree.get(int(b), int(c)))[2:]
        d = 0
        for i in K:
            if i == "1":
                d += 1
        print(d)
    else:
        s_tree.update(int(b), T[c])

Measured memory_bytes: 172832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000 + 10;
struct point{
    ll x,y;
    point(){}
    point(ll x,ll y):x(x),y(y){}
    point operator + (point p){
        return point(x+p.x,y+p.y);
    }
    point operator - (point p){
        return point(x-p.x,y-p.y);
    }
    point operator * (ll k){
        return point(x*k,y*k);
    }
};
ll det(point a,point b){
    return a.x * b.y - a.y * b.x;
}
ll a[N],b[N],c[N];
point var[N];
int main(){
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    for(int i=0;i<n;i++) scanf("%lld",&b[i]);
    vector<pair<ll,ll> > vec;
    int pos = 0;
    for(int i=0;i<n;i++){
        if(a[i]>a[pos]) pos = i;
        vec.push_back({a[i],b[i]});
    }
    for(int i=0;i<=n;i++){
        a[i] = vec[(i+pos)%n].first;
        b[i] = vec[(i+pos)%n].second;
    }
    c[0] = 0, c[1] = 1;
    for(int i=1;i<n;i++) c[i+1] = 2*c[i]+2*b[i]-c[i-1];
    vector<point> v; int r = 0;
    for(int i=0;i<=n;i++){
        point p(i,a[i]-c[i]);
        while(r>=2&&det(v[r-1]-v[r-2],p-v[r-1])>=0) v.pop_back(), r--;
        v.push_back(p), r++;
    }
    ll ans = 0;
    for(int i=1;i<(int)v.size();i++){
        ans += (v[i-1].y+v[i].y)*(v[i].x-v[i-1].x+1);
        ans -= 2*v[i].y;
    }
    for(int i=0;i<n;i++) ans += 2*c[i];
    printf("%.12f\n",0.5*ans/n);
}


Measured memory_bytes: 17112
#include <stdio.h>

int main(void) {
  int x1, x2, x3, x4, x5;
  scanf("%d", &x1);
  scanf("%d", &x2);
  scanf("%d", &x3);
  scanf("%d", &x4);
  scanf("%d", &x5);

  if(x1 == 0)
  puts("1");
  else if(x2 == 0)
  puts("2");
  else if(x3 == 0)
  puts("3");
  else if(x4 == 0)
  puts("4");
  else if(x5 == 0)
  puts("5");


}


Measured memory_bytes: 1644
<?php
list($a, $b) = explode(' ', trim(fgets(STDIN)));

$a = (int) $a;
$b = (int) $b;


if ($b === 1) {
    echo 0;
    return;
}
$res = 0;
$curr = 0;

while (true) {
    if ($curr >= $b) {
        echo $res;
        break ;
    } elseif ($res > 0) {
        $curr--;
        $curr += $a;
        $res++;
    } else {
        $curr += $a;
        $res++;
    }
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define LL long long
using namespace std;

int main(){
  string S;
  cin >> S;
  S[5] = ' ';
  S[13] = ' ';
  cout << S << endl;
  return 0;
}


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

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

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

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

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vec<ll> A(M);
  REP(i, M) cin >> A[i];

  const auto l = lower_bound(ALL(A), X);
  const auto L = distance(A.begin(), l);
  const auto R = distance(l, A.end());
  const auto answer = min(L, R);
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 3608
n = int(input())
s = input()
f = 1
while f == 1:
  ns = ""
  pre_c = s[0]
  f = 0
  for c in s[1:]:
    if c != pre_c:
      ns += pre_c
    else:
      f = 1
    pre_c = c    
  ns += s[-1]
  s = ns
print(len(s))

  

Measured memory_bytes: 3316
//this library has many things needed for arrays, the asterisc means we get everything is inside, the dot says where is is inside, you need the ; to tell the line has ended, like in C
import java.util.*;

//the name of the main function has to be the same name of the program
//what public class mean in java: it means that other function scan also access the class. What happens if we dont make it public? Well, it stil works, but it will be visivle to code only in the same package
public class Main {
	//this is a method, it tells that it will execute the things that are inside, it takes string as args when we execute the program, it is optional. What if instead we use int? It does not work, it has to be String[] args
	public static void main(String[] args){
		//it is a class of the .util that is used to take input from the user. Why it is used as class?
		Scanner sc = new Scanner(System.in);
		// get a integer
		//nextInt is a method, it will take text and turn it into an integer. It is looking for space or line break? Yes, if it is a line break or a space it treats it the same way. How to consider it is different?
		char a[] = sc.next().toCharArray();
		// get two integers separated with half-width break
		System.out.println(a[0]-'0'+a[1]-'0'+a[2]-'0');
	}
}



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

int main(){
  int a, b;
  string s;
  cin >> a >> b >> s;
  
  bool ok = true;
  int l = s.size();
  for(int i = 0; i < l; i++){
    int k = s.at(i) - '0';
    if(i == a){
      if(k >= 0 && k <= 9) ok = false;
    }
    else{
      if(k < 0 || k > 9) ok = false;
    }
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7
 
D = [[0]*(K+1) for i in range(N+1)]
for i in range(1, N+1):
    D[i][1] = 1
for i in range(1, min(N, K)+1):
    D[i][i] = 1
for n in range(1, N+1):
    for k in range(2, min(n-1, K)+1):
        D[n][k] = (D[n-k][k] + D[n-1][k-1]) % MOD
print(D[N][K] % MOD)


Measured memory_bytes: 28828
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;

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


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

  int ans = 0;
  int mini = 0;
  rep(i, 5){
    if(a[mini] % 10 > a[i] % 10 && a[i] % 10 != 0){
      mini = i;
    }
  }

  rep(i, 5){
    if(i == mini) continue;
    ans += a[i];
    if(a[i] % 10 > 0){
      ans += - a[i] % 10 + 10;
    }
  }

  ans += a[mini];

  cout << ans << endl;


}


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

const int m=1000000007;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0,j=n-1;
    int cnt=0;
    while(i<j)
    {
        if(s[i]=='W' && s[j]=='R')
        {
            cnt++;
            i++;
            j--;
        }
        else if(s[i]=='R')
        {
            i++;
        }
        else if(s[j]=='W')
        {
            j--;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>



using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a)

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef  long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const double EPS = 1e-7;
const int MAX = 20 * 1000 + 47;
const int MAS = 1e5 * 6; 
const int MOD = 1000 * 1000 * 1000 + 7;


int main()
{
    int n;
    cin >> n; 
    VI a(n); 
    rep(i, n)
    {
        cin >> a[i]; 
    }
    VI dp(n,INF);
    dp[0] = 0;
    rep(i, n)
    {
        for (auto j : { i + 1, i + 2 })
        {
          if(j < n)
          {
              dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]));
          }
        }
    }
    cout << dp[n - 1]; 

    

}










Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

template <class T>
T gcm(T a, T b) {
    if (a < b) {
        T w = a;
        a = b;
        b = w;
    }

    while (b != 0) {
        T w = a % b;
        a = b;
        b = w;
    }

    return a;
}

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

    int res = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                res += gcm(a, gcm(b, c));
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
#define ALL(W) (W).begin(),(W).end()
int N,M,s[100000+10]={},a[100000+10];
signed main(){
  s[0]=1,s[1]=1;
  cin >> N >> M;
  rep(i,M) cin >> a[i];
  int x=0;
  if(a[x]==1) s[1]=0,x++;
  for(int i=2;i<=N;i++){
    //cout << a[lower_bound(ALL(a),i)-a.begin()] << endl;
    if(i==a[x] && x<M){
      s[i]=0;
      x++;
    }
    else s[i]=(s[i-2]%1000000007+s[i-1]%1000000007)%1000000007;
    //cout << "s[" << i << "]:" << s[i] << endl;
  }
  cout << s[N] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin >> N;
  vector<vector<int64_t>> vec(N,vector<int64_t>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  vector<vector<int64_t>> range(N,vector<int64_t>(2));
  for(int i=0; i<N; i++){
    range.at(i).at(1) = vec.at(i).at(0) - vec.at(i).at(1);
    range.at(i).at(0) = vec.at(i).at(0) + vec.at(i).at(1);
  }
  sort(range.begin(),range.end());
  int64_t ans = -1;
  int64_t end = range.at(0).at(0);
  for(int i=0; i<N; i++){
    if(range.at(i).at(1) < end){
      ans++;
    }
    else{
      end = range.at(i).at(0);
    }
    //cout << end << endl;
  }
  cout << N - ans << endl;
}

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

using namespace std;

#define D(x) x
#define REP(i,a,b) for (int i = (a); i < (b); ++i)
#define REPR(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int> > VII;

ll  L, N;
ll  X[200005];
ll XL[200005], XR[200005];

void solve() {
    cin >> L >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> X[i];
    }
    for (int i = 1; i <= N; ++i) {
        XL[i] = XL[i - 1] + X[i];
    }
    for (int i = N; i >= 1; --i) {
        XR[i] = XR[i + 1] + L - X[i];
    }

    ll result = 0;
    for (int x = 0; x <= N; ++x) {
        ll sum = 0;
        int l = x, r = N - x;
        int d = min(l, r);
        sum += 2 * (XL[l] - XL[l - d]);
        sum += 2 * (XR[l + 1] - XR[l + 1 + d]);
        if (l == r) {
            sum -=  min(X[l], L - X[l + 1]);
            result =  max(result, sum);
            continue;
        }
        if (l > r) {
            result =  max(result, sum + 2 * X[l - d] - X[l]);
            result =  max(result, sum - (L - X[l + 1]));
        } else if (r > l) {
            result =  max(result, sum + 2 * (L - X[l + 1 + d]) - (L - X[l + 1]));
            result =  max(result, sum - X[l]);
        }

    }
    cout << result << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

    solve();

    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
  int n,m,a[200050];
  cin>>m>>n;
  ll sum=0;
  for(int i=1;i<=m;i++)
  {
      cin>>a[i];
  }
   if(n>=m)
  {
      cout<<0<<endl;
      return 0;
  }
  sort(a+1,a+m+1,cmp);
  for(int i=n+1;i<=m;i++)
    sum+=a[i];
 cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

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

void insertionSort(int A[], int N){
int j,i,v;
for(i=1;i<N;i++){
 v=A[i];
 j=i-1;
 while(j>=0 && A[j]>v){
 A[j+1]=A[j];
 j--;
 }
A[j+1]=v;
trace(A,N);
}
}

int main(){
int N,i,j;
int A[100];

scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%d",&A[i]);
}

trace(A,N);
insertionSort(A,N);

return 0;
}



Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
// first -> color this node white; second -> color this node black
pair<int, int> dfs(vector<vector<int>> &graph, int curr, int par)
{
	int all_white_subtree = 1;
	int something_black_subtree = 0;
	for (auto i : graph[curr])
	{
		if (i != par)
		{
			auto p = dfs(graph, i, curr);

			something_black_subtree = p.second * all_white_subtree + something_black_subtree * (p.first + p.second);
			something_black_subtree %= MOD;
			all_white_subtree *= p.first;
			all_white_subtree %= MOD;
		}
	}
	return make_pair((something_black_subtree + all_white_subtree) % MOD, all_white_subtree);
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<vector<int>> graph(n);
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	auto z = dfs(graph, 0, -1);
	cout << (z.first + z.second) % MOD << "\n";
}



Measured memory_bytes: 12672
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

ll f(ll a){
    if(a%2!=0){
        ll b=(a+1)/2;
        if(b%2!=0) return 1;
        return 0;
    }
    ll b=a/2;
    if(b%2==0) return a;
    return 1^a;
}

signed main(){
    ll a,b;
    cin>>a>>b;
    cout<<(f(a-1)^f(b))<<endl;
}

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

int main(){ //11-B-theater
  int n,x;
  cin >> n;
  x = 0;
  for(int i = 0; i < n; i++){
    int l,r;
    cin >> l >> r;
    x += r+1-l;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N,M,Q;
int rank[100001],par[100001];
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(rank[x]<rank[y]){
    par[x]=y;
  }
  else{
    par[y]=x;
    if(rank[x]==rank[y])rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}
int main(){
  cin >> N >> M;
  for(int i=0;i<N;i++){
    par[i]=i;
    rank[i]=0;
  }
  for(int i=0;i<M;i++){
    int u,v;
    cin >> u >> v;
    unite(u,v);
  }
  cin >> Q;
  for(int i=0;i<Q;i++){
    int s,d;
    cin >> s >> d;
    if(same(s,d))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {
    public static void main (String[] args){
        solve1600();
    }

    public static void solve1600(){
        Scanner sc = new Scanner(System.in);
        while(true) {
            int m = sc.nextInt();
            int n_min = sc.nextInt();
            int n_max = sc.nextInt();
            if (m == 0 && n_min == 0 && n_max == 0) {
                break;
            }

            int[] tokuten = new int[m];
            int[] gap = new int[m-1];
            for (int i = 0; i < m; i++) {
                tokuten[i] = sc.nextInt();
                if(i != 0){
                    gap[i-1] = tokuten[i-1] - tokuten[i];
                }
            }
            int answer = 0;
            int gap_max = 0;
            for(int gap_index = n_min - 1; gap_index < n_max; gap_index++){
                if(gap_max <= gap[gap_index]){
                    gap_max = gap[gap_index];
                    if(gap_max == gap[gap_index]) {
                        answer = gap_index + 1;
                    } else {
                        answer = gap_index;
                    }
                }
            }
            System.out.println(answer);
        }
    }
}

Measured memory_bytes: 56636
using System;

namespace ALDS1_1_B_anothter
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = (Console.ReadLine().Split(' '));
            int x = Int32.Parse(input[0]);
            int y = Int32.Parse(input[1]);
            Console.WriteLine("{0}", euclid(x, y));
        }

        static string calcGCD(int x, int y)
        {
            for (int i = Math.Min(x, y); i >= 2; i--)
            {
                if (x % i == 0 && y % i == 0) { return i.ToString(); }
            }
            return "1";
        }

        static int euclid(int x, int y)
        {
            if (x < y)
            {
                Swap<int>(ref x, ref y);
            }

            while(y>0)
            {
                int r = x % y;
                x = y;
                y = r;
            }
            return x;
        }

        static void Swap<T>(ref T lhs, ref T rhs)
        {
            T temp;
            temp = lhs;
            lhs = rhs;
            rhs = temp;
        }
    }
}

Measured memory_bytes: 9268
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define vi vector < int >
        #define vii vector < long long int >
        #define CLR(a) memset((a),0,sizeof(a))
        #define mp make_pair
        #define hell 1000000007
        using namespace std;


        void solve()
        {
            ll i,j=0,r=200,p,q,k=0,ans=0,d,y=0,h,flag=0,n,m=0,a=hell,b=hell,id,c,h1,h2,a1,b1;
            cin>>n;
            cout<<3*n*n;



        }


        signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }

           /*

      void bfs( int i , int j)
           {
               vis[i][j]= true;
             queue < int > que;
             que.push(k);
             while(!que.empty())
             {
                int x= que.front();
                que.pop();
                 for ( int i=1;i<=n;i++)
                 {
                     if((!g[1][n] and g[x][i] ) or (g[1][n] and ! g[x][i]))
                     {
                       if(!vis[i])
                       {
                           que.push(i);
                           level[i]=level[x]+1;
                           vis[i]= true;
                       }
                     }
                 }
             }
           }

          ll int por(ll int a,ll int b)
             {
                ll int k=1;
                while(b>0)
                {
                    if(b%2) k=k*a,k%=hell;
                    b/=2;
                    a*=a; a%=hell;
                }
                return k;
             } */


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

namespace ABC111_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var v = Console.ReadLine().Split().Select(long.Parse).ToArray();

            if (v.Distinct().Count() == 1)
            {
                Console.WriteLine(n / 2);
                return;
            }

            var ve = new Dictionary<long, long>();
            var vo = new Dictionary<long, long>();

            for (long i = 0; i < v.Length; i++)
            {
                if (i % 2 == 0 || i == 0)
                {
                    if (ve.Keys.Contains(v[i])) ve[v[i]]++;
                    else ve.Add(v[i], 1);
                }
                else
                {
                    if (vo.Keys.Contains(v[i])) vo[v[i]]++;
                    else vo.Add(v[i], 1);
                }
            }

            var veMost = ve.OrderByDescending(x => x.Value).ToList();
            var voMost = vo.OrderByDescending(x => x.Value).ToList();

            var veTop = veMost[0].Key;
            var voTop = voMost[0].Key;

            if (veTop==voTop)
            {
                if (veMost[0].Value > voMost[0].Value) voTop = voMost[1].Key;
                else if (veMost[0].Value < voMost[0].Value) veTop = veMost[1].Key;
                else
                {
                    if (veMost[1].Value < voMost[1].Value) voTop = voMost[1].Key;
                    else veTop = veMost[1].Key;
                }
            }

            ve.Remove(veTop);
            vo.Remove(voTop);

            var cntve = ve.Select(x => x.Value).Sum();
            var cntvo = vo.Select(x => x.Value).Sum();

            Console.WriteLine(cntve + cntvo);
        }
    }
}


Measured memory_bytes: 31584
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N,K;
  cin >> N >> K;
  vector<ll> n(N);
  for(int i=0;i<N;i++) cin >> n[i];

  for(int i=K;i<N;i++){
    if(n[i-K]<n[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define lowbit(i) ((i)&(-(i)))
#define lson(i) ((i)<<1)
#define rson(i) ((i)<<1|1)
#define fi first
#define se second
#define m_p(x,y) make_pair((x),(y))
using namespace std;

typedef long long ll;typedef unsigned long long ul;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef queue<int> qii;typedef queue<pii> qpi;

const int inf=0x3f3f3f3f;
const int maxn=17;

int w,h,a[maxn],b[maxn];
string s[maxn],cmp[maxn];

void dfs1(int x,bool f){
	if(x==w){
		puts("YES");
		exit(0); 
	}
	if(b[x]!=-1) dfs1(x+1,f);
	else{
		int i,j;
		for(i=x+1;i<w;i++){
			if(b[i]!=-1) continue;
			for(j=0;j<h;j++){
				if(s[j][x]!=s[a[j]][i])
					break;
			}
			if(j==h){
				b[x]=i;
				b[i]=x;
				dfs1(x+1,f);
				b[x]=b[i]=-1;
			}
		}
		if(!f){
			for(j=0;j<h;j++){
				if(s[j][x]!=s[a[j]][x])
					break;
			}
			if(j==h){
				b[x]=x;
				dfs1(x+1,1);
				b[x]=-1;
			}
		}
	}
}

void dfs(int now,bool f){
	if(now==h){
		dfs1(0,w%2==0);
	}
	else if(a[now]!=-1) dfs(now+1,f);
	else{
		int i;
		for(i=now+1;i<h;i++){
			if(a[i]==-1&&cmp[now]==cmp[i]){
				a[i]=now;
				a[now]=i;
				dfs(now+1,f);
				a[i]=a[now]=-1;
			}
		}
		if(!f){
			a[now]=now;
			dfs(now+1,1);
			a[now]=-1;
		}
	}
}

int main(){
// 	freopen("","r",stdin);
// 	freopen("","w",stdout);
	memset(a,-1,sizeof(a));
	memset(b,-1,sizeof(b));
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		cin>>s[i];
		cmp[i]=s[i];
		sort(cmp[i].begin(),cmp[i].end());
	}
	dfs(0,h%2==0);
	puts("NO");
	return 0;
}



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

using namespace std;
#define int long long
#define INF 10e9

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    vector<vector<int> >LCS(s.size()+1,vector<int>(t.size()+1));
    
    for(int i=0;i<=s.size();i++)
    {
        for(int j=0;j<=t.size();j++)
        {
            if(i==0 || j==0)
            {
                LCS[i][j]=0;continue;
            }
            
            if(s[i-1] == t[j-1])
            {
               // cout<<s[i-1]<<t[j-1]<<" "s[i-1] == t[j-1]<<" ";
                LCS[i][j]=LCS[i-1][j-1]+1;
                continue;
            }
            LCS[i][j]=max(LCS[i-1][j],LCS[i][j-1]);
        }
        //for(int j=0;j<=t.size();j++)
        //cout<<LCS[i][j]<<" ";
        //cout<<endl;
    }
//    print(LCS);
string ans="";
    int i=s.size(),j=t.size();
    //int cnt=0;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
      //      cnt++;
            ans+=s[i-1];
            i--;j--;continue;
        }
        if(LCS[i][j]==LCS[i-1][j])
        {
            i--;continue;
        }
        j--;
    }
    //cout<<cnt;
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
    
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

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

    string s, t;
    cin >> s >> t;
    int n = SZ(s), m = SZ(t);
    vvi dp(n + 1, vi(m + 1, 0));
    dp[n - 1][m - 1] = s[n - 1] == t[m - 1];
    R0F (i, n - 2)
        dp[i][m - 1] = s[i] == t[m - 1] ? 1 : dp[i + 1][m - 1];
    R0F (i, m - 2)
        dp[n - 1][i] = s[n - 1] == t[i] ? 1 : dp[n - 1][i + 1];
    R0F (i, n - 2)
        R0F (j, m - 2)
            dp[i][j] = max({dp[i + 1][j + 1] + (s[i] == t[j]), dp[i + 1][j],
                            dp[i][j + 1]});

    for (int i = 0, j = 0; i < n && j < m;) {
        if (s[i] == t[j] && dp[i + 1][j + 1] + 1 == dp[i][j]) {
            cout << s[i];
            ++i;
            ++j;
        } else if (dp[i + 1][j] == dp[i][j])
            ++i;
        else
            ++j;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 35584
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

vector<int> dijkstra(int s, vector<vector<P>> &G){
    int n = G.size();
    vector<int> dist(n, inf);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(que.size()){
        int ccost, cv;
        tie(ccost, cv) = que.top(); que.pop();

        if(dist[cv] < ccost) continue;

        for(auto nxt : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = nxt;
            
            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist;
}

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

    int n, x, y; cin>>n>>x>>y;
    x--, y--;
    vector<vector<P>> G(n);
    for(int i=0; i+1<n; i++){
        int u = i, v = i + 1;
        G[u].emplace_back(v, 1);
        G[v].emplace_back(u, 1);
    }
    G[x].emplace_back(y, 1);
    G[y].emplace_back(x, 1);

    vector<int> ans(n, 0);
    for(int i=0; i<n; i++){
        auto dist = dijkstra(i, G);
        for(auto j:dist) ans[j]++;
    }

    for(int i=1; i<n; i++) cout << ans[i] / 2 << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
struct edge{int s,t,n;}e[200010];
int n,h[200010],f[200010];
 
void dfs(int x,int fa)
{
	int s=0,sum=0,k=1,p=0;
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if (y!=fa)  dfs(y,x),s|=sum&f[y],sum|=f[y];
	while ((k<s)||(sum&k))  {k<<=1;p++;}
	//f[x]=(sum^(sum&(k-1)))|k;
f[x]=(sum>>(p)<<(p))|k;
}
 
void work()
{
	scanf("%d",&n);
	for (int i=1,u,v,tot=0; i<n; i++)
		{
			scanf("%d %d",&u,&v);
			e[++tot]=(edge){u,v,h[u]},h[u]=tot;
			e[++tot]=(edge){v,u,h[v]},h[v]=tot;
		}
	dfs(1,0);
	printf("%d",int(log2(f[1])));
}
 
int main()
{
	work();
	return 0;
}

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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int h, w; std::cin >> h >> w;
  vector<string> grid(h); rep(i, h) std::cin >> grid[i];
  vector<vi> cost(h, vi(w, inf));
  vi que;
  rep(i, h) rep(j, w) {
    if (grid[i][j] == '.') continue;
    cost[i][j] = 0;
    que.pb(i*w+j);
  }
  int ans = 0;
  rep(i, que.size()) {
    int x = que[i]%w, y = que[i]/w;
    srep(dx, -1, 2) srep(dy, -1, 2) if (dx*dx+dy*dy==1) {
      int nx = x+dx, ny = y+dy;
      if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
      if (grid[ny][nx] == '#' || cost[ny][nx] != inf) continue;
      cost[ny][nx] = cost[y][x] + 1;
      chmax(ans, cost[ny][nx]);
      que.pb(ny*w+nx);
    }
  }
  std::cout << ans << "\n";
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin>>N;
    ll ans = 0;
    for (int i=1;i*i<=N;i++) {
        ans = i;
    }
    cout<<ans*ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char a[11], b[11], c[11];
  scanf("%s%s%s", a, b, c);
  printf("%c%c%c\n", a[0] - 32, b[0] - 32, c[0] - 32);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <limits>
#include <cstring>
#include <functional>
#include <iomanip>

using namespace std;

using ll = long long;

#define rep(i, N) for(int i = 0;i < N;i++)
#define LARGE INT_MAX / 2

struct point { int x, y; };

typedef pair<int, int> P;

int N;
int x;
int recieve[100];
int ans;


int main() {
	cin >> N >> x;
	rep(i, N) {
		cin >> recieve[i];
	}

	sort(recieve, recieve + N);

	rep(i, N) {
		if (x - recieve[i] >= 0) {
			x -= recieve[i];
			ans++;
		}
		else {
			break;
		}
	}
	if (x != 0 && ans == N) {
		ans--;
	}
	cout << ans;
	return 0;
}

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

using namespace std;
#define endl "\n"
#define FILEIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define LL long long 
#define mod 1000000007LL
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
//#define p push
#define I insert
#define bg begin()
#define ed end()
#define sz size()
#define all(v) v.begin(),v.end()
typedef vector<LL> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef map<LL ,LL > mii;
//typedef priority_queue<int> pq;
typedef queue<int>que;
typedef stack<int>stk;
#define Inf 100000005LL
#define f first
#define s second





vi vect_2pow;
void pow_of_2(){
    vect_2pow.assign(32,0);
      for(int i=0;i<=32;i++){
           LL y = 1<<i;
           vect_2pow[i]=y;
      }
}
bool Ispalindrome(string str){
        LL len = str.size();
		bool flag;
		for(int i=0;i<len/2;i++){
				if(str[i]==str[len-i-1])
				     {
						 flag=0;
						 continue;
					 }
					 else 
					    {
							flag=1;
							break;
						}
			}
		if (flag==1)
		  return false;
		else return true;  
		
}
vector<LL> prime_check;
mii get_high_prime;
int high_prime_factor(){
	//cout<<"ecd";
	LL max_prime=0;
	for(int i=2;i<100000;i++)
	{
		LL n=i;
		
		while(n%2==0)
		{
			max_prime=2;
			n>>=1;
		}
		for(int j=3;j<=sqrt(n);j++)
		{
			while(n%j==0){
				max_prime=j;
				n/=j;
			}
		}
		if(n>2)
		  max_prime=n;
		  
		//prime_check.pb(max_prime);
		get_high_prime[i]=max_prime;
	}
	
			
}

//const LL inf = 10e+9;
void max_self(LL &a,LL b){
	a=max(a,b);

}
int main()
{
	 
	int n,w;
	cin>>n>>w;
	vi dp(w+1);
	for(int i=0;i<n;i++)
	{
		int weight,value;
		cin>>weight>>value;
		for(int weight_already=w-weight;weight_already>=0;weight_already--)
		//for(int weight_already=0;weight_already<=w-weight;++weight_already)
		{
			//cout<<weight_already<<" "<<weight_already+weight<<endl;
			max_self(dp[weight_already+weight],dp[weight_already]+value);
			//cout<<dp[weight_already+weight]<<" "<<dp[weight_already]+value<<endl;

		}
	}
	//cout<<endl;
	LL ans=0;
	for(int i=0;i<=w;i++){
		//cout<<dp[i]<<" ";
	   ans=max(ans,dp[i]);
	}

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
#include <string>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    string s;
    int a=0;
    int b=0;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='A'){
            a++;
        }else{
            b++;
        }
    }
    if(a>0 && b>0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l;
string x[101];
bool cmp(string x,string y) {
	return x  < y;
}
int main() {
	cin>>n>>l;
	for(int i=0;i<n;++i)
		cin>>x[i];
	sort(x,x+n,cmp);
	for(int i=0;i<n;++i)
		cout<<x[i];
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;;
using ll = long long;

int main() {
	
	int K, N, mb = 0;
	cin >> K >> N;
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	A.push_back(A[0]+K);
	rep(i, N+1) {
		if (i > 0) {
			if (A[i] - A[i - 1] > mb) {
				mb = A[i] - A[i - 1];
			}
		}
	}
	cout << K - mb << endl;
	
	return 0;
}

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

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int N = fs.nextInt(), M = fs.nextInt();
		int[] a = fs.nextIntArray(N);
		int[][] q = new int[M][2];
		for(int i = 0; i < M; i++) {
			q[i] = fs.nextIntArray(2);
		}
		Arrays.sort(q, (x, y) -> Integer.compare(y[1], x[1]));
		Arrays.sort(a);
		int[] arr2 = new int[N];
		for(int i = 0, ptr = 0; i < q.length && ptr < N; i++) {
			int left = q[i][0];
			while(left-->0 && ptr < N) {
				arr2[ptr++] = q[i][1];
			}
		}
		int last = 0;
		for(int i = 0; i < N; i++) {
			if(a[i] < arr2[last]) {
				a[i] = arr2[last++];
			}
		}
		
		long res = 0;
		for(int i : a) res += i;
		out.println(res);
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}

	}

}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"1"<<endl;}else cout<<"0"<<endl;//条件によってYes、Noを出力する
#define ld long double
int main(){
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;
  YN(m1!=m2);
}

Measured memory_bytes: 3620