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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

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

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main()
{
    double t,x;
    cin>>t>>x;
    double res=t/x;
    cout<<res<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    vector<int> abc;
    for(int i=0;i<3;i++){
        int v;
        cin>>v;
        abc.push_back(v);
    }
    int ans=0;
    sort(abc.begin(),abc.end());
    while(abc[0]!=abc[1]){
        abc[0]+=2;
        ans++;
        sort(abc.begin(),abc.end());
    }
    while(abc[1]!=abc[2]){
        abc[1]++;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt();
			if (n == 0) break;
			int data[] = new int[7];
			for (int i = 0; i < n; i++)
			{
				int x = sc.nextInt();
				data[Math.min(x / 10, 6)]++;
			}
			for (int i = 0; i < 7; i++)
			{
				System.out.println(data[i]);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

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

	int h, w;
	cin >> h >> w;

	vector<vector<int> > cost(h, vector<int>(w));
	for(int i = 0; i < h; ++i) {
		string line;
		cin >> line;
		for(int j = 0; j < w; ++j)
			cost[i][j] = line[j] - '0';
	}

	vector<vector<int> > dp(h, vector<int>(w, INT_MAX));
	dp[0][0] = 0;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(i < h - 1)
				chmin(dp[i + 1][j], dp[i][j] + cost[i][j]);

			if(j < w - 1)
				chmin(dp[i][j + 1], dp[i][j] + cost[i][j]);
		}
	}

	cout << dp[h - 1][w - 1] << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1260
#!/usr/bin/env python3


def solve(n,a):
  a = list(sorted(a,reverse=True))
  first = a[0]
  b = a[1:]
  delta = [abs(x-first//2) for x in b]
  second = b[delta.index(min(delta))]
  return first,second

def main():
  N = int(input())
  a = list(map(int,input().split()))
  print(*solve(N,a))

if __name__ == '__main__':
  main()

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

#define sc second
#define fr first
#define mk make_pair
#define pb push_back
#define int long long

using namespace std;

const int N = (3e5 + 5);
const int inf = (1e9 + 7);

int n;
int a[N];
int dp[N];
int v[N];

main () {
    cin >> n;

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

    dp[0] = 1;

    for (int i = 1; i <= n; i ++) {
        if (a[i] != a[i - 1]){
            dp[i] += v[a[i]];
            v[a[i]] += dp[i - 1];
            v[a[i]] %= inf;
        }

        dp[i] += dp[i - 1];
        dp[i] %= inf;
    }
    cout << dp[n] % inf << endl;
}


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

const int INF = 1001001001;

int a[12][12];

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    rep(i,n) {
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }

    int ans = INF;
    rep(s, 1<<n) {
        int cost = 0;
        vector<int> d(m);
        rep(i,n) {
            if (s>>i&1) {
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }

        bool ok = true;
        rep(j,m) if (d[j] < x) ok = false;
        if (ok) ans = min(ans, cost);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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;
}

const int MOD = 1e9 + 7;
const ll INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 100020;


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

	int N; cin >> N;
	vector<int>L(N), R(N);
	REP(i, N) {
		cin >> L[i] >> R[i];
	}
	VSORT(L); VREVERSE(L);
	VSORT(R);
	ll res = 0, tmp = 0;
	REP(i, N) {
		tmp += L[i]; res = max(res, tmp);
		tmp -= R[i]; res = max(res, tmp);
	}
	tmp = 0;
	REP(i, N) {
		tmp -= R[i]; res = max(res, tmp);
		tmp += L[i]; res = max(res, tmp);
	}
	print(res*2);
}



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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	for (char c : s){
		if (c == '7'){
			cout << "Yes" << "\n";
			return 0;
		}
	}
	cout << "No" << "\n";	
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
vector<int> A[MAX_N];

int pre(const vi& vec) {
	int res = sz(vec);
	int prev = -1;
	rep(i, 0, sz(vec)) {
		if(prev == -1) prev = vec[i];
		else if(prev == vec[i]) {
			res -= 2; prev = -1;
		}
		else {
			prev = vec[i];
		}
	}
	return res;
}

void solve() {
	cin >> N >> M;
	rep(i, 0, N) {
		int b;
		cin >> b;
		A[b % M].pb(b);
	}
	rep(i, 0, M) {
		sort(all(A[i]));
	}
	int res = 0;
	rep(i, 0, M) {
		vi& vec1 = A[i];
		vi& vec2 = A[(M - i) % M];
		int n1 = sz(vec1), n2 = sz(vec2);
		int v1 = pre(vec1), v2 = pre(vec2);
		if(i == 0) {
			res += (n1 / 2) * 2;
			continue;
		}
		else if(M % 2 == 0 && i == M / 2) {
			res += (n1 / 2) * 2;
			continue;
		}
		if(n1 > n2) {
			swap(n1, n2); swap(v1, v2);
		}
		// debug(v1, n1, v2, n2);
		int tmp;
		if((n1 + n2) % 2 == 0) {
			if(v2 <= n1) {
				tmp = (n1 + n2) / 2;
			}
			else {
				tmp = n1 + (n2 - v2) / 2;
			}
		}
		else {
			if(v2 <= n1 + 1) {
				tmp = (n1 + n2) / 2;
			}
			else {
				tmp = n1 + (n2 - v2) / 2;
			}
		}
		res += tmp;
	}
	cout << res / 2 << "\n";
}
int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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


int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n)
    cin >> h[i];
  vector<int> dp(n, 0);
  for (int i = 1; i < n; i++)
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), i > 1 ? dp[i-2] + abs(h[i] - h[i-2]) : INT_MAX);
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 1e5+1;

vector<pair<ll,ll>> nodes[maxn];
ll dis[maxn];

void solve()
{    
     ll n; cin >> n;
     fill(dis, dis+maxn, inf);
     ll m = n-1;
     while(m--){
          ll u,v,w; cin >> u >> v >> w;
          nodes[u].pb({v,w});
          nodes[v].pb({u,w});
     }

     priority_queue< pair<ll,ll> , vector<pair<ll,ll>> , greater<pair<ll,ll>> > pq;
     pq.push({0,1});
     dis[1]=0;
     while(!pq.empty()){

          ll curNode = pq.top().S;
          ll curWgt = pq.top().F;
          pq.pop();
          if( curWgt > dis[curNode])
               continue;

          for(auto ch : nodes[curNode]){

               if( curWgt + ch.S < dis[ch.F]){
                    dis[ch.F] = curWgt + ch.S;
                    pq.push({dis[ch.F], ch.F});
               }

          }

     }
     ll col[n+1];
     fill(col, col+n+1, 0);
     f(i,1,n+1){
          //cout << dis[i] << "<--" << endl;
          if(dis[i]%2==0)
               col[i]=1;
     }

     f(i,1,n+1)
          cout << col[i] << endl;

}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
        
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 12616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;


int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	ll n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	int reds = 0;
	int start = 0;
	for(int i=0; i<n; i++){
		if(s[i] == 'R'){
			reds++;
		}
	}
	for(int i=0; i<reds; i++){
		if(s[i] == 'W'){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3684
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

int W, H;
#define MH 60
#define MW 10
string F[MH + 1];

bool input() {
    cin >> W >> H;
    if (W == 0 && H == 0) return false;
    for (int i = 0; i < H; i++) {
        cin >> F[i];
    }
    reverse(F, F + H);
    return true;
}

double ml, mr, M;
int C;
const int dy[] = {0, 1, 0, -1},
          dx[] = {1, 0, -1, 0};
bool used[MH + 1][MW + 1];
bool used2[MH + 1][MW + 1];
void dfs2(int y, int x) {
    char c = F[y][x];
    double m = x + 0.5;
    M += m;
    C++;
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if (ny < 0 || ny >= H) continue;
        if (nx < 0 || nx >= W) continue;
        if (used2[ny][nx]) continue;
        if (F[ny][nx] != c && ny <= y) continue; 
        if (F[ny][nx] != '.') {
            used2[ny][nx] = true;
            dfs2(ny, nx);
        }
    }
}
void dfs(int y, int x) {
    char c = F[y][x];
    double m = x + 0.5;
    if (y == 0 || (F[y - 1][x] != '.' && F[y - 1][x] != c)) {
        ml = min(m - 0.5, ml);
        mr = max(m + 0.5, mr);
    }
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if (ny < 0 || ny >= H) continue;
        if (nx < 0 || nx >= W) continue;
        if (used[ny][nx]) continue;
        if (F[ny][nx] == c) {
            used[ny][nx] = true;
            dfs(ny, nx);
        }
    }
}

void solve() {
    memset(used, 0, sizeof(used));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (F[i][j] != '.' && !used[i][j]) {
                ml = 1e10; mr = 0;
                M = 0;
                C = 0;
                used[i][j] = true;
                dfs(i, j);
                memset(used2, 0, sizeof(used2));
                used2[i][j] = true;
                dfs2(i, j);
                double M1 = M;
                M /= C;
                if (ml < M && M < mr) {
                    //cout << F[i][j] << "\t" ;
                    //cout << M1 << "\t" << C << "\t";
                    //cout << ml << " " << M << " " << mr << endl;
                    continue;
                } else {
                    //cout << F[i][j] << endl;
                    //cout << ml << " " << M << " " << mr << endl;
                    cout << "UNSTABLE" << endl;
                    return;
                }
            }
        }
    }
    cout << "STABLE" << endl;
}

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

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

using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    int all_xor = 0;
    rep(i, N) {
        cin >> A[i];
        all_xor ^= A[i];
    }
    vector<int> B(N);
    rep(i, N) {
        B[i] = all_xor ^ A[i];
    }

    cout_h(B);
}


Measured memory_bytes: 4840
import java.util.Scanner;
public class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine(); 
    if(str.charAt(2) == str.charAt(3) && str.charAt(4) == str.charAt(5))
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}


Measured memory_bytes: 35708
N = gets.to_i
S = gets.chomp

eData = Array.new(N+1, 0)
wData = Array.new(N+1, 0)

1.upto(N) do |i|
  eData[i] = eData[i - 1] + (S[i - 1] == 'E' ? 1 : 0)
  wData[i] = wData[i - 1] + (S[i - 1] == 'W' ? 1 : 0)
end

result = []
1.upto(N) do |i|
  result << eData[N] - eData[i] + wData[i - 1] - wData[0]
end

p result.min

Measured memory_bytes: 9476
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N; cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 高さが全部 0 になるまでやる
    int res = 0;
    while (true) {
        // 最高高さが 0 だったらおしまい
        if (*max_element(h.begin(), h.end()) == 0) break;
        
        // 区間分割する
        int i = 0;
        while (i < N) {
            if (h[i] == 0) ++i; // 0 なら何もせずに次に進む
            else {
                ++res; // 区間の始まり
                while (i < N && h[i] > 0) {
                    --h[i]; // ついでに引いとく
                    ++i; // 区間の終わりまで一気に
                }
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int x;
    cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}











Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

ll D = 365;
ll C[26] = {};
ll S[365][26] = {};

ll score(const vector<ll> &ans){
  ll ret = 0;
  ll last[26] = {};
  rep(i,D){
    ret += S[i][ans[i]];
    last[ans[i]] = i+1;
    rep(j,26){
      ret -= C[j] * (i+1 - last[j]);
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  cin>>D;
  rep(i,26){
    cin>>C[i];
  }
  rep(i,D){
    rep(j,26){
      cin>>S[i][j];
    }
  }

  vector<ll> ans(D), last(26, -1);
  rep(i,D){
    ll best_eval = -LINF;
    ll best_type = -1;
    rep(j,26){
      ll eval = C[j] * pow((i - last[j]), 1.5) + S[i][j];
      if(best_eval < eval){
        best_eval = eval;
        best_type = j;
      }
    }
    ans[i] = best_type;
    last[best_type] = i;
  }
  cerr << "score:" << score(ans) << endl;

  rep(i,D){
    cout<<ans[i] + 1 << endl;
  }
  return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> G(n + 1);
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> buff(n + 1);
  for (int i = 1; i <= q; ++i) {
    int p, x;
    cin >> p >> x;
    buff[p] += x;
  }
  vector<int> res(n + 1);
  function<void(int, int, int)> dfs = [&](int u, int prv, int p) {
    res[u] = prv + buff[u];
    for (auto v : G[u]) {
      if (v != p) {
        dfs(v, prv + buff[u], u);
      }
    }
  };
  dfs(1, 0, 0);
  for (int i = 1; i <= n; ++i) {
    cout << res[i] << " \n"[i == n];
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 33664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    
    ll sum = 0;

    for(ll i = 1; i <= N; i++)
    {
        if(i % 3 == 0 && i % 5 == 0)continue;
        else if(i % 3 == 0)continue;
        else if(i % 5 == 0)continue;
        else sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
def mahou(p2, p1):
    return abs(p2[0] - p1[0]) + abs(p2[1] - p1[1])

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]

Map = [[0, 0] for i in range(H * W + 1)]
for i in range(len(A)):
    for j in range(len(A[i])):
        Map[A[i][j]] = [i + 1, j + 1]

keiro = [[0 for i in range(D)] for j in range(H * W // D + 1)]

for i in range(D, H * W):
    keiro[i // D][i % D] = mahou(Map[i + 1], Map[i + 1 - D]) + keiro[i // D - 1][i % D]
        
for l, r in LR:
    print(keiro[(r - 1) // D][(r - 1) % D] - keiro[(l - 1) // D][(l - 1) % D])

Measured memory_bytes: 47712
N, M = map(int, input().split())

a_arr = []
b_arr = []
for _ in range(N):
    a, b = map(int, input().split())
    a_arr.append(a)
    b_arr.append(b)
    
c_arr = []
d_arr = []
for _ in range(M):
    c, d = map(int, input().split())
    c_arr.append(c)
    d_arr.append(d)

for n in range(N):
    ans = 0
    min_dis = 4 * 10**8 + 1
    for m in range(M):
        dis = abs(a_arr[n] - c_arr[m]) + abs(b_arr[n] - d_arr[m])
        if dis < min_dis:
            min_dis = dis
            ans = m + 1
    print(ans)

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N;
  cin >> N;
  vector<int> A(N, 0);
  int a;
  rep (i, N-1) {
    cin >> a;
    A[a-1]++;
  }
  rep(i, N) {
    cout << A[i] << endl;
  }
}


Measured memory_bytes: 3940
#include <stdio.h>
#include <complex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;

double cross(const P& a, const P& b) { return imag(conj(a)*b); }

P ps[4];

bool is() {
    const double sig = cross(ps[1]-ps[0], ps[2]-ps[0]);
    rep (i, 4) {
        const int j = (i+1)%4;
        const int k = (i+2)%4;
        if (cross(ps[j]-ps[i], ps[k]-ps[i])*sig < 0) return false;
    }
    return true;
}

int main() {
    double x[4], y[4];
    while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
                x, y, x+1, y+1, x+2, y+2, x+3, y+3) != EOF) {
        rep (i, 4) ps[i] = P(x[i], y[i]);
        puts(is() ? "YES" : "NO");
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
double d,x,ans;
int n;
int main(){
	scanf("%d%lf%lf",&n,&x,&d);
	while(n!=0){
		ans+=x+n*d-d/2;
		x=(n+1.0)/n*x+5*d/(2*n);
		d=(n+2.0)/n*d;
		--n;
	}
	printf("%.10lf\n",ans);
	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int k;
            for(k=0;(i>>k&1)==(j>>k&1);k++);
            printf("%d%c",k+1," \n"[j==n]);
        }
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll N , K ; cin >> N >> K ;
  vector<ll> l;
  rep(i,N){
    ll inp; cin >> inp;
    l.pb(inp);
  }
  sort(rall(l));
  ll ans = 0;
  rep(i,K)ans += l[i];

  cout << ans << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
n = str(n)
n = n[-1]
Hon = [str(2),str(4),str(5),str(7),str(9)]
Pon = [str(0),str(1),str(6),str(8)]
if n in Hon:
    print('hon')
elif n in Pon:
    print('pon')
else :
    print('bon')

Measured memory_bytes: 9100
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll k,a,b;cin>>k>>a>>b;
    for(ll i=a;i<=b;i++){
        if(i%k==0)return cout<<"OK" , 0;
    }
    cout<<"NG";
}


Measured memory_bytes: 3648
#include <stdio.h>
void maxHeapify(int);
void buildMaxHeap(void);
int H,A[500000];  
int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  } 
  
  buildMaxHeap();
  
  for(i=1;i<H;i++){
    printf(" %d",A[i]);
  } 
  printf(" %d\n",A[i]);

  return 0;
}


void buildMaxHeap(void){
  int i;
  for(i=H/2;i>=1;i--)
    {
      maxHeapify(i);
    }
}


void maxHeapify(int i){
  int l,r,largest,tmp;
  l=i*2;
  r=i*2+1;
  if(l<=H && A[l]>A[i]){
    largest=l;
  } 
  else largest=i;
  if(r<=H && A[r]>A[largest]){
    largest=r;
  }
  if(largest!=i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
long long n,p,ncf[1000009];
long long cf(long long i,long long n){
	long long j=i;i=1;
	while(n--){
		i*=j;
	}
	return i;
}
int main()
{
	cin>>n>>p;
	if(n==1){
		cout<<p;return 0;
	}
	if(n>50){
		cout<<1;return 0;
	}
	long long i,ans;
	for(i=1;cf(i,n)<=p;++i){
		if(p%cf(i,n)==0)ans=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    x_list = list(map(int, input().split()))

    x_min = min(x_list)
    x_max = max(x_list)
    hp_min = None

    for i in range(x_min, x_max+1):
        tmp_hp = 0
        for j in x_list:
            tmp_hp += (j - i)**2
        if (hp_min is None) or (tmp_hp < hp_min):
            hp_min = tmp_hp

    print(hp_min)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    rep(i, q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    int ans = 0;
    vector<int> A(n, 1);
    bool valid = true;
    while(valid){
        int sum = 0;
        rep(i, q){
            if(A[b[i]] - A[a[i]] == c[i])sum += d[i];
        }
        ans = max(ans, sum);
        
        int idx = n-1;
        while(A[idx] == m){
            if(idx == 0){
                valid = false;
                break;
            }
            idx--;
        }
        A[idx]++;
        for(int i = idx + 1; i < n; i++){
            A[i] = A[idx];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
# 2020/04/12
# AtCoder Beginner Contest 162 - B

# Input
n = int(input())

# Calc
ans = 0
for i in range(1, n+1):
    if i % 5 == 0 or i % 3 == 0:
        continue
    else:
        ans = ans + i

# Output
print(ans)


Measured memory_bytes: 9156
#include<stdio.h>
int main(){
int x,y,i,a,b;
b=0;
scanf("%d%d%d",&x,&y,&a);
for (i=x;i<=y;i++){
if (a%i==0){
b=b+1 ;}
}
printf("%d\n",b);
return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef long long ll;

int main(void){
	int n, k;
	cin >> n >> k;

	int sum = 0;
	vector<int> a(n);
	REP(i, n){
		cin >> a[i];
		sum += a[i];
	}

	priority_queue<int> que;
	for(int i = 1; i*i <= sum; i++){
		if(!(sum%i)){
			que.push(i);
			if(i != sum/i) que.push(sum/i);
		}
	}

	int ans = 0, mod;
	vector<int> r(n);
	while(1){
		if(!que.empty()){
			mod = que.top();
			que.pop();
		}else break;
		REP(i, n){
			r[i] = a[i]%mod;
		}
		sort(r.begin(), r.end());
		REP(i, n){
			if(!i) continue;
			r[i] += r[i-1];
		}
		REP(i, n){
			//cout << r[i] << "<=" << k << ' ' << (n-1-i)*mod-(r[n-1]-r[i]) << "<=" << k << endl;
			if(r[i] <= k && r[i] == (n-1-i)*mod-(r[n-1]-r[i])){
				ans = mod;
				break;
			}
		}
		if(ans) break;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n= int(input())
m=int(input())
inf=1001001001
data =[[inf]*n for i in range(n)]

for i in range(m):
    a,b,c,d= map(int,input().split(","))
    data[a-1][b-1]= c
    data[b-1][a-1]= d
s,g,V,P = map(int,input().split(","))

for k in range(n):
    for i in range(n):
        for j in range(n):
            if data[i][j]>data[i][k]+data[k][j]:
                data[i][j]= data[i][k]+data[k][j]
                
print(V-P-data[s-1][g-1]-data[g-1][s-1])


Measured memory_bytes: 5604
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <math.h>
#include <vector>
 
#define MOD 1000000007
typedef long long ll;
 
using namespace std;

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

	string s, t;
	ll ans = 0;
	cin >> s >> t;
	for(int i = 0; i<s.length(); i++) {
		if(s[i] != t[i]) ans++;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	while(1){
		int n, x[4], y[4], count=0;
		bool flag = false;
		
		cin >> n;
		if(n==0) break;
	
		while(n!=6174){
			int a=0, b=0;
			//printf("%d\n", n);
			
			for(int i=0; i<4; ++i){
				x[i] = (n%(int)pow(10, 4-i) - n%(int)pow(10, 3-i)) / (int)pow(10, 3-i);
				y[i] = (n%(int)pow(10, 4-i) - n%(int)pow(10, 3-i)) / (int)pow(10, 3-i);
			}
			if(x[0]==x[1] && x[1]==x[2] && x[2]==x[3]){
				flag=true;
				break;
			}	
		
			sort(x, x+4);
			for(int i=0; i<4; ++i)
				a+=pow(10,3-i)*x[i];
			
			sort(y, y+4, greater<int>());
			for(int i=0; i<4; ++i)
				b+=pow(10,3-i)*y[i];
	
			n=b-a;
			
			++count;
		}
	
		if(flag) printf("NA\n");
		else printf("%d\n", count);
	}
	
	return 0;
}

Measured memory_bytes: 1212
//Name: Snakes
//Level: 2
//Category: 文字列,オートマトン
//Note: 

/**
 * AとBは別々に判定する。
 */
#include <iostream>
#include <string>

using namespace std;

bool snakeA(const string &s) {
    auto it = begin(s);
    int cnt = 0;
    if(*it++ != '>') return false;
    if(*it++ != '\'') return false;
    while(true) {
        const char c = *it++;
        if(c == '#') break;
        else if(c == '=') ++cnt;
        else return false;
    }
    if(cnt == 0) return false;
    while(cnt--) {
        if(*it++ != '=') return false;
    }
    if(*it++ != '~') return false;
    return it == end(s);
}

bool snakeB(const string &s) {
    auto it = begin(s);
    if(*it++ != '>') return false;
    if(*it++ != '^') return false;
    bool ok = false;
    while(true) {
        const char c = *it++;
        if(c == '~') break;
        else if(c != 'Q') return false;

        if(*it++ != '=') return false;
        ok = true;
    }
    if(!ok) return false;
    if(*it++ != '~') return false;
    return it == end(s);
}

bool solve(bool first) {
    string s;
    cin >> s;
    if(snakeA(s)) cout << "A" << endl;
    else if(snakeB(s)) cout << "B" << endl;
    else cout << "NA" << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    bool first = true;
    int N;
    cin >> N;
    while(N-- && solve(first)) {
        first = false;
    }
    return 0;
}

Measured memory_bytes: 1200
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
r = 0
for n in range(N):
  A = list(map(int,input().split()))
  temp = 0
  for i in range(M):
    temp += A[i]*B[i]
  temp += C
  if temp > 0:
    r += 1
print(r)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
2^20=1048576
使いそう
FMFMFMFMFMFM
とかありうる

5
FMFMV

FMVFV
FMVFM

7
FMFMFMV

2個置きに出るのが続くけど
FMVFMVM

FVFVFVFVとかの可能性もあるわけ
0と1だして、入れ替わってる場所を見つけるとか
でも２回あると戻っちゃう。
7/2=3
0=3=Fだった場合0-3にある
ちがったら4-6にあるとか？
11,5,2

FVFMFMV
1 50000
1 25000 50000 75000
0 2 4 6..
N-2,N-4,... 0

0 3 6として
0==3なら0~3にある
0!=3なら4~6にある？
FMFMFMV

0 2 4
3
個数見て、奇数個かつ同じなら、その中にある
偶数個かつ違うならその中にある？
MVFM
MVMF

FMFMVFM

FMFMFMVFM

FVMFMFMFM=9

FVMFM FMFM 前半部にあるのがわかる
なぜなら、FVFMF MVMF 後半にないといけなくなる
low=0 high=4
FVM 奇数個で違う＝low-midにある

FMFMF MFVMとか
low=4 high=8

FMFVM
mid=6
FMF 
low=6 high=8
いけてそう

FMVFMFM =7

low=0 mid=3 high=6
FMVF
low=0 high=3

うーん、、WA抜けない
なんなんだ


*/
int main(){
  ll N; cin>>N;
  string S;
  char C;
  cout<<0<<endl;
  cin>>S;
  C=S[0];
  ll low=0,high=N-1,mid=(high+low)/2;
  if(C=='V') return 0;
  while(1){
    if(high-low<=3){
      while(low<=high){
        cout<<low<<endl;
        cin>>S;
        if(S[0]=='V') return 0;
        low++;
      }
      return 0;
    }
    cout<<mid<<endl;
    string S; cin>>S;
    if(S[0]=='V') return 0;
    ll m=mid-low+1;//項数
    if(m%2==1){//奇数個で同じFMFならそこにはない
      if(C==S[0])
        low=mid;
      else
        high=mid;
    }
    else{//偶数個
      if(C==S[0])//そこにある
        high=mid;
      else
        low=mid;
    }
    if(low==mid) C=S[0];
    mid=(low+high)/2;
  }
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len(stuff) (int) stuff.size()

#define int long long
// #define float long double 
#define ll long long
#define ld long double

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const int inf = (int) 1e16;
const int upper = (int) 2e5 + 50;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;
signed main () {
	start_routine();
	speed();
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif	
	int m, k; 
	cin >> m >> k;
	if (k == 0) {
		vector<int> ans;
	for (int i = 0; i <= (1LL << m) - 1; i += 1) ans.push_back(i);
	for (int i = 0; i <= (1LL << m) - 1; i += 1) ans.push_back(i);
	sort(all(ans));
	for (auto i: ans) cout << i << ' ';
		return 0;
	}
	if (k >= (1LL << m)) {
		cout << -1;
		return 0;
	}
	deque<int> ans;
	ans.push_back(k);
	for (int i = 0; i < (1LL << m); i += 1) if (i != k) ans.push_back(i), ans.push_front(i);
	ans.push_back(k);
	int pos1[(1LL << m) + 1], pos2[(1LL << m) + 1];
	for (int i = 0; i < (1LL << m); ++i) pos1[i] = -1, pos2[i] = -1;
	int pre[(1LL << (m + 1)) + 1];
	for (int i = 0; i < len(ans); i += 1) {
		if (pos1[ans[i]] == -1) pos1[ans[i]] = i;
		else pos2[ans[i]] = i;
	}
	pre[0] = ans[0];
	for (int i = 1; i < len(ans); i += 1) pre[i] = pre[i - 1] ^ ans[i];
	for (int i = 0; i < (1LL << m); i += 1) {
		int x;
		if (pos1[i] >= 1) x = pre[pos2[i]] ^ pre[pos1[i] - 1];
		else x = pre[pos2[i]];
		if (x != k) {
			cout << -1;
			return 0;
		}
	} 
	for (auto i: ans) cout << i << ' ';
 	end_routine();		
}

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

class Node {
  public:
    Node* prev;
    Node* next;
    int value;
};

class DoublyLinkedList {
  private:
    Node* first;
  public:
    DoublyLinkedList() {
      first = NULL;
    }
    void insert(int n);
    void deleteN(int n);
    void deleteFirst();
    void deleteLast();
    bool isEmpty();
    void print();
};

void DoublyLinkedList::insert(int n) {
  Node* node = new Node();
  node->value = n;

  if (isEmpty()){
    first = node;
    node->prev = node;
    node->next = node;
  } else {
    node->prev = first->prev;
    node->next = first;
    first->prev->next = node;
    first->prev = node;
    first = node;
  }
}

void DoublyLinkedList::deleteN(int n) {
  if (isEmpty()) return;
  Node* node = first;
  do {
    if (node->value == n) {
      if (node == first) {
        if (node->next == node) {
          first = NULL;
        } else {
          node->prev->next = node->next;
          node->next->prev = node->prev;
          first = node->next;
        }
      } else {
        node->prev->next = node->next;
        node->next->prev = node->prev;
      }
      break;
    }
    node = node->next;
  } while (node != first);
}

void DoublyLinkedList::deleteFirst() {
  if (isEmpty()) return;
  if (first->next == first) {
    first = NULL;
    return;
  }
  first->next->prev = first->prev;
  first->prev->next = first->next;
  first = first->next;
}

void DoublyLinkedList::deleteLast() {
  if (isEmpty()) return;
  Node* last = first->prev;
  if (last == first) {
    first = NULL;
    return;
  }
  last->prev->next = first;
  first->prev = last->prev;
}

bool DoublyLinkedList::isEmpty() {
  return first == NULL;
}

void DoublyLinkedList::print() {
  if (isEmpty()) return;
  Node* node = first;
  while (true) {
    cout << node->value;
    node = node->next;
    if (node == first) break;
    cout << ' ';
  }
  cout << endl;
}

int main() {
  int n;
  string command;
  int value;
  DoublyLinkedList* list = new DoublyLinkedList();

  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command == "insert") {
      cin >> value;
      list->insert(value);
    } else if (command == "delete") {
      cin >> value;
      list->deleteN(value);
    } else if (command == "deleteFirst") {
      list->deleteFirst();
    } else if (command == "deleteLast") {
      list->deleteLast();
    }
  }

  list->print();

  return 0;
}

Measured memory_bytes: 35600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
int n;
int a[N];
struct uzi{
    int a,b;
};
vector<uzi>v[33];
int vis[333];
int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=1;j<=a[i];j++){
            int s,t;
            cin>>s>>t;
            s--;
            v[i].pb({s,t});
        }
    }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        vector<int>x;
        for(int j=0;j<n;j++)vis[j]=0;
        for(int j=0;j<n;j++){
            if((1<<j)&i)x.pb(j),vis[j]=1;
        }
        int sta=0;
        for(auto k:x){
            if(sta)break;
            for(auto ne:v[k]){
                if(ne.b==0&&vis[ne.a]){
                    sta=1;
                    break;
                }
                if(ne.b&&vis[ne.a]==0){
                    sta=1;
                    break;
                }
            }
        }
        if(!sta)ans=max(ans,(int)x.size());
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Ll long long
using namespace std;
const int N=5e2+5;
char a[N][N];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++)
			if(j==1||(i&1)||a[i][j]=='#')
				cout<<'#';else cout<<'.';
		cout<<'.';
		cout<<endl;
	}
	cout<<endl;
	for(int i=1;i<=n;i++){
		cout<<'.';
		for(int j=2;j<=m;j++)
			if(j==m||!(i&1)||a[i][j]=='#')
				cout<<'#';else cout<<'.';
		cout<<endl;
	}
}

Measured memory_bytes: 1024
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import collections
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    v = list(map(int,ipti().split()))
    v1 = [0] * ((n+1) // 2)
    v2 = [0] * (n // 2)

    for i in range(n):
        if i % 2 == 0:
            v1[i//2] = v[i]
        else:
            v2[i//2] = v[i]

    c1 = collections.Counter(v1)
    c2 = collections.Counter(v2)
    c1 = c1.most_common()
    c2 = c2.most_common()

    v1n = (n+1) // 2
    v2n = n // 2

    ans = 0

    if c1[0][0] == c2[0][0]:
        if len(c1) > 1 and len(c2) > 1:
            temp1 = v1n + v2n -c1[0][1] -c2[1][1]
            temp2 = v1n + v2n -c1[1][1] - c2[0][1]
            ans = min(temp1, temp2)
        elif len(c1) == 1 and len(c2) > 1:
            temp1 = v1n
            temp2 = v1n + v2n - c1[0][1] - c2[1][1]
            ans = min(temp1, temp2)
        elif len(c1) > 1 and len(c2) == 1:
            temp1 = v1n + v2n - c1[1][1] - c2[0][1]
            temp2 = v2n
            ans = min(temp1, temp2)
        else:
            temp1 = v2n
            temp2 = v1n
            ans = min(temp1, temp2)
    else:
        if len(c1) > 1 and len(c2) > 1:
            ans = v1n + v2n - c1[0][1] -c2[0][1]
        elif len(c1) == 1 and len(c2) > 1:
            ans = v2n - c2[0][1]
        elif len(c1) > 1 and len(c2) == 1:
            ans = v1n - c1[0][1]
        else:
            ans = 0

    print(ans)


if __name__ == '__main__':
    main()


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

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

using namespace std;
using lint=long long;

template<class T> T gcd(const T& a,const T& b){ return b==0?a:gcd(b,a%b); }
template<class T> T lcm(const T& a,const T& b){ return a/gcd(a,b)*b; }

int main(){
	lint a,b; cin>>a>>b; cout<<lcm(a,b)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//すぬけくんの放送は見たのに、やっぱり実装はぜんぜんつかめず超苦戦

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


	ll L, R;
	cin >> L >> R;

	ll mod = 1e9 + 7;
	ll dp[65][2][2][2] = {};
	dp[0][0][0][0] = 1;

	rep(i, 60) {
		int l = (L >> (59 - i)) & 1;
		int r = (R >> (59 - i)) & 1;

		rep(j, 2) rep(k, 2) {
			rep(m, 2) {
				ll kazu = dp[i][j][k][m] % mod;
				//cesp(i);
				//cesp(j);
				//cesp(k);
				//ce(m);
				//cesp(l);
				//ce(r);
				//ce(dp[i][j][k][m]);


				
				rep(l2, 2) rep(r2, 2) {
					if (j == 0 && l > l2) continue;
					if (k == 0 && r < r2) continue;
					if (l2 > r2) continue;
					if (m == 0) {
						if (l2 & r2) dp[i + 1][j | (l ^ l2)][k | (r ^ r2)][1] += kazu;
						else if (!l2 & !r2) dp[i + 1][j | (l ^ l2)][k | (r ^ r2)][0] += kazu;
					}
					else {
						dp[i + 1][j | (l ^ l2)][k | (r ^ r2)][1] += kazu;
					}
				}

			}
		}
	}

	ll kotae = 0;
	rep(j, 2) rep(k, 2) {
		rep(m, 2) {
			kotae += dp[60][j][k][m];
		}
	}
	co(kotae % mod);

	Would you please return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool is_key = false;
  for (int l = 0; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      string t = "";
      rep(i, l) t += s[i];
      for (int i = r; i < n; ++i) t += s[i];
      if (t == "keyence") is_key = true;
    }
  }
  if (is_key) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3632