akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(void) {
  vector<string> st = {"Sunny", "Cloudy", "Rainy"};
  
  string s;
  cin >> s;
  if (s == st[0]) cout << st[1] << endl;
  else if (s == st[1]) cout << st[2] << endl;
  else cout << st[0] << endl;
  
  return 0;
}

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

long long num[200010],out,k;
unordered_map < long long , long long > m;

int main()
{
	int n;
	cin>>n>>k;
//	vector < int > num(n + 1,0);
	for(int i = 1;i <= n;i++)
	{
		long long in;
		cin>>in;
		num[i] = (num[i - 1] + in) % k;
	} 
	
	for(int i = 0;i <= n;i++)
	{
		num[i] = ((num[i] - i) % k + k) % k;
		if(i >= k) m[num[i - k]]--;
		out += m[num[i]];
		m[num[i]]++; 
	}
	cout<<out;
	
	return 0;
}


Measured memory_bytes: 10056
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int main(){
    int n, t;
    cin >> n >> t;
    vector<LL> a(n);
    vector<LL> b(n);
    REP(i, n) cin >> a[i] >> b[i];
    vector<LL> dp0(t + 1), dp1(t + 1);
    REP(i, n){
        for(int j = t - 1;j >= 0;j--) if (j + a[i] < t){
            dp1[j + a[i]] = max(dp1[j + a[i]], dp1[j] + b[i]);
        }
        REP(j, t) dp1[j] = max(dp1[j], dp0[j] + b[i]);
        for(int j = t - 1;j >= 0;j--) if (j + a[i] <= t){
            dp0[j + a[i]] = max(dp0[j + a[i]], dp0[j] + b[i]);
        }
    }
    cout << max(*max_element(ALL(dp0)), *max_element(ALL(dp1))) << endl;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve(boolean[] isp) {
		int n = in.nextInt();
		if (n == 0) return false;

		int cnt = 0;

		for (int i=n+1; i<=2*n; i++) {
			if (isp[i]) cnt++;
		}

		out.println(cnt);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		int MAX = 300000;
		boolean[] isp = new boolean[MAX];
		Arrays.fill(isp, true);
		isp[0] = isp[1] = false;
		for (int i=2; i<MAX; i++) {
			if (!isp[i]) continue;
			for (int j=i+i; j<MAX; j+=i) {
				isp[j] = false;
			}
		}

		while(solve(isp));
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

int main(void)
{
    using namespace std;
    string s;
    cin >> s;
    int res = 0;
    for(int i = 0; i < s.length(); ++i) {
        if (s.at(i) == '+')
            ++res;
        else
            --res;
    }
    cout << res << endl;
}

Measured memory_bytes: 384
from collections import deque
K=int(input())

if K<10: print(K); exit()

q=deque(list(range(1,10)))
anslist=list(range(1,10))
cnt=9

while cnt<=K:
    a=q.popleft()
    
    # aの1桁目
    a_1=int(str(a)[-1])

    # aの1桁目が0でない場合
    if a_1!=0:
        i=a*10+(a_1-1)
        q.append(i)
        anslist.append(i)
        cnt+=1

    # どのような場合も処理する
    i=a*10+a_1
    q.append(i)
    anslist.append(i)
    cnt+=1

    # aの1桁目が9でない場合
    if a_1!=9:
        i=a*10+(a_1+1)
        q.append(i)
        anslist.append(i)
        cnt+=1

print(anslist[K-1])

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

int main(){
  int N; cin >> N;
  int h[N];
  int dp[N];
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  dp[0] = 0;
  for(int i = 1; i < N; i++){
    if(i >= 2)dp[i] = min(dp[i-1] + fabs(h[i]-h[i-1]),dp[i-2] + fabs(h[i] - h[i-2]));
    else dp[i] = dp[i-1] + fabs(h[i]-h[i-1]);
  }
  cout << dp[N-1] << endl;
}

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

int main()
{
    int n, min, max;
    double sum;
    cin >> n;
    int a[n];

    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    
    min=a[0];
    max=a[0];
    sum=(double)a[0];
    
    for(int i=1;i<n;i++)
    {
        sum += (double)a[i];
        if(a[i] < min)
        {
            min = a[i];
        }
        if(a[i] > max)
        {
            max = a[i];
        }
    }
    cout << min << " " << max << " " << fixed << setprecision(0) << sum << endl;
    return 0;
}


Measured memory_bytes: 3288
import java.util.*;
 
public class Main { 
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();
		long ans = 0;
		if(k<a){
			ans += k*1;
			System.out.println(ans);
			return;
		} else {
			ans += a*1;
			k -= a;
		}
		if(k<b){
			ans += k*0;
			System.out.println(ans);
			return;
		} else {
			ans += b*0;
			k -= b;
		}
		if(k<c){
			ans += k*(-1);
			System.out.println(ans);
			return;
		} else {
			ans += c*(-1);
			k -= c;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27088
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    cin >> N;
    vector<ld> per(N);
    rep(i,N)cin >> per[i];
    vector<vector<ld>> memo(N + 1,vector<ld>(N + 1));
    memo[0][0] = 1;
    rep(i,N){
        rep(j,N + 1){
            if(j != N){
                memo[i + 1][j + 1] += memo[i][j] * per[i];
            }
            memo[i + 1][j] += memo[i][j] * (1 - per[i]);
        }
    }
    ld ans = 0;
    for(ll i = N / 2 + 1;i <= N;i++){
        ans += memo[N][i];
    }
    cout << fixed << setprecision(15);
    cout << ans << endl;
}

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

int main() {
   int N, K;
   cin >> N >> K;
   vector<int> price(N);
   for (int i = 0; i < N; i++) cin >> price[i];
   sort(price.begin(), price.end());
   int ans = 0;
   for (int i = 0; i < K; i++) ans += price[i];
   cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
int a[10004],b[10004];
signed main()
{
	int n;
	cin>>n;
	int m1=0,p2=0;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int i=0;i<n;i++){
		cin>>b[i];
	}
	for (int i=0;i<n;i++){
		if (a[i]>=b[i]){
			m1=m1+a[i]-b[i];
		}
		else if ((b[i]-a[i])%2==0){
			p2=p2+(b[i]-a[i])/2;
		}
		else {
			m1++;
			p2=p2+(b[i]-a[i])/2+1;
		}
	}
	if (m1>p2)  cout<<"No";
	else  cout<<"Yes";
	re 0;
}

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

int main()
{
    int a,b;
    while(cin >> a >> b){
    int sum = 0;
    if(b == 1) cout << "0" << endl;
	else{
		for(int i = 1; i <= 20; i++){
    		if(a * i - (i - 1) >= b){
    			sum = i;
    			break;
			}	
		}
		cout << sum << endl;
	} 
	}
    return 0;
}

Measured memory_bytes: 256
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
int n;
ll a[200005],sum,f[200005]; 
int main(){
    read(n);
	fr(i,1,n)read(a[i]);
	sum=a[1];
	f[1]=0,f[2]=0;
	fr(i,3,n+1)
	    if(i%2==0)f[i]=max(f[i-2]+a[i-1],f[i-1]);
	    else{
	    	f[i]=max(f[i-2]+a[i-1],sum);
	    	sum+=a[i];
		}
	cout<<f[n+1]<<endl;
	return 0;
}


Measured memory_bytes: 6768
import java.util.Scanner;

class Dice {
	private int up;
	private int front;
	private int right;
	private int left;
	private int back;
	private int down;
	
	Dice(int up,int front,int right,int left,int back,int down){
		this.up=up;	this.front=front; this.right=right;
		this.left=left; this.back=back; this.down=down;
	}
	
	void printUp(){	System.out.println(up); }
	
	void rotate(char c){
		int temp;
		if(c=='E'){
			temp=up; up=left; left=down; down=right; right=temp;
		}
		
		if(c=='N'){
			temp=up; up=front; front=down; down=back; back=temp;
		}
		
		if(c=='S'){
			temp=up; up=back; back=down; down=front; front=temp;
		}
		
		if(c=='W'){
			temp=up; up=right; right=down; down=left; left=temp;
		}
	}
		
			
}


class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		Dice d=new Dice(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());
		
		String com=scan.next();
		for(int i=0;i<com.length();i++)
			d.rotate(com.charAt(i));
		
		d.printUp();
	}
}


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

int main() 
{
    ll d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;


int main(){
    ll n,c;
    cin>>n>>c;
    vector<vector<ll> > s(c,vector<ll>(0)),t(c,vector<ll>(0));
    for(ll i=0;i<n;i++){
        ll s_,t_,c_;
        cin>>s_>>t_>>c_;
        s[c_-1].push_back(s_);
        t[c_-1].push_back(t_);
    }
    for(ll i=0;i<c;i++){
        sort(s[i].begin(),s[i].end());
        sort(t[i].begin(),t[i].end());
    }

    ll ans=0;
    for(ll time=0;time<100010;time++){
        ll sub=0;
        //cout<<"t="<<time<<endl;
        for(ll j=0;j<c;j++){
            sub+=min(upper_bound(s[j].begin(),s[j].end(),time)-s[j].begin()-(lower_bound(t[j].begin(),t[j].end(),time)-t[j].begin()),(long)1);
            //cout<<sub<<endl;
        }
        ans=max(sub,ans);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N,M;
    cin>>N>>M;
    int ans=0;
    vector<pair<int,int>>vec(N);
    REP(i,N){
        int a,b;
        cin>>a>>b;
        vec[i]=make_pair(a,b);
    }
    sort(vec.begin(),vec.end());
    REP(i,N){
        if(vec[i].second<M){
            ans+=vec[i].first*vec[i].second;
          	M-=vec[i].second;
        }
        else{
            ans+=vec[i].first*M;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <complex>
#include <cstdio>
#include <cstdlib>
using namespace std;

#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 RREP(i, n) for(int i=n-1;i>=0;i--)
#define RREPS(i, n) for(int i=n;i>0;i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int T, n, w, h;
int m;
int place(int x, int y, int dx, int dy){
	int step = 10000000;
	if(dx > 0) step = min(step, w - x);
	if(dx < 0) step = min(step, x);
	if(dy > 0) step = min(step, h - y);
	if(dy < 0) step = min(step, y);
	x += dx * step;
	y += dy * step;
	if(y == 0) return x;
	if(x == w) return w + y;
	if(y == h) return 2*w+h - x;
	if(x == 0) return 2*w+2*h - y;
	assert(false);
}


int solve(vector<pii> rng){
	int ans = 1;
	int tail = rng[0].first - 1;
	int start = tail;
	for(auto it : rng){
		int s, t;
		tie(t, s) = it;
		if(s <= tail) continue;
		if(start + m < t) continue;
		ans ++;
		tail = t-1;
	}
	return ans;
}
int main(){
	cin >> n >> w >> h;
	m = 2*w+2*h;
	vector<pii> rng;
	REP(i, n){
		int x, y;
		char f;
		cin >> x >> y >> f;
		int s, t;
		if(f == 'E'){
			s = place(x, y, 1, -1);
			t = place(x, y, 1, 1) + 1;
		}
		if(f == 'N'){
			s = place(x, y, 1, 1);
			t = place(x, y, -1, 1) + 1;
		}
		if(f == 'W'){
			s = place(x, y, -1, 1);
			t = place(x, y, -1, -1) + 1;
		}
		if(f == 'S'){
			s = place(x, y, -1, -1);
			t = place(x, y, 1, -1) + 1;
		}
		if(t <= s) t += m;
		rng.eb(t, s);
	}
	int ans = n;
	REP(_, 2*n){
		sort(ALL(rng));
		ans = min(ans, solve(rng));
		rng[0].first += m;
		rng[0].second += m;
		rng.eb(rng[0]);
		rng.erase(rng.begin());
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <utility>
#include <map>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;


int main()
{
    string s;
    cin>>s;
    bool ok=true;
    for(int i=0;i<99;i+=2)
    {
        if(s[i]=='L')
            ok=false;
    }
    for(int i=1;i<=99;i+=2)
    {
        if(s[i]=='R')
            ok=false;
    }
    if(ok==false)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
#include<random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const int MOD=1e9+7;

int main(){
  
  int n, m, x;
  cin >> n >> m >> x;
  int a[12][12];
  vector<int> c(n);
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  int ans = MOD;
  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 == MOD) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
w,h,x,y,r = map(int,raw_input().split())
if 0<=x-r<=w:
    if 0<=x+r<=w:
        if 0<=y-r<=h:
            if 0<=y+r<=h:
                print "Yes"
            else:
                print "No"
        else:
            print "No"
    else:
        print "No"
else:
    print "No"

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

int main() {
	bool s[13] = { false };
	bool h[13] = { false };
	bool c[13] = { false };
	bool d[13] = { false };
	int n;
	char l;
	int a;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> l >> a;
		if (l == 'S'){
			s[a-1] = true;
		}else if (l=='H'){
			h[a-1] = true;
		}else if (l=='C'){
			c[a-1] = true;
		}else if (l=='D'){
			d[a-1] = true;
		}
	}
	for (int i = 0; i < 13; i++){
		if (s[i] == false) {
			cout << "S " << i+1 << endl;
		}
	}
	for (int i = 0; i < 13; i++) {
		if (h[i] == false) {
			cout << "H " << i+1 << endl;
		}
	}
	for (int i = 0; i < 13; i++) {
		if (c[i] == false) {
			cout << "C " << i+1 << endl;
		}
	}
	for (int i = 0; i < 13; i++) {
		if (d[i] == false) {
			cout << "D " << i+1 << endl;
		}
	}
	cin >> l;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    string S; cin>>S;
    ll ans=0;
    for(int bit=0;bit<(1<<S.size()-1);bit++){
        ll now=0;
        for(int i=0;i<S.size();i++){
            now=now*10+S[i]-'0';
            if(bit & 1<<i){
                ans+=now;
                now=0;
            }
        }
        ans+=now;
    }
    cout<<ans;
    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    bool f = true;
    
    int a = 0, b = 0;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "A") a++;
        else b++;
        if (b > a) f = false;
    }
    if (a != b) f = false;
    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xmod int(1e9+7)
#define hmod 1223334444555553LL
using namespace std;

int n,q,t,f,p,r,node[200005],ans[200005];
vector <int> edge[200005];
bool vis[200005];
void dfs(int x,int sum){
	sum+=node[x]; vis[x]=true;
	ans[x]=sum;
	for (int i=0;i<edge[x].size();i++){
		dfs(edge[x][i],sum);
	}
}
int main(){
	scanf("%d%d",&n,&q);
	for (int i=1;i<n;i++){
		scanf("%d%d",&f,&t);
		edge[f].pb(t);
	}
	for (int i=1;i<=q;i++){
		scanf("%d%d",&p,&r);
		node[p]+=r;
	}
	dfs(1,0);
	for (int i=1;i<=n;i++){
		printf("%d",ans[i]);
		if (i < n)
		printf(" ");
	}
	printf("\n");
	return 0;
} 

Measured memory_bytes: 24192
N = int(input())
P = 998244353
A = [int(input()) for _ in range(N)]
s = sum(A)

def calc(m):
    X = [1] + [0] * s
    for a in A:
        for i in range(a, s+1)[::-1]:
            X[i] = (X[i] + X[i-a] * m) % P
    return X

Y = calc(2)
ans = sum([Y[i] for i in range(s//2+1)]) + (0 if s%2 else -calc(1)[s//2])
print((pow(3, N, P) - ans*3) % P)

Measured memory_bytes: 42292
import java.util.*;

public class Main{
    static String[] days = {"SUN","SAT","FRI","THU","WED","TUE","MON"};
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String day = sc.next();
        for(int i = 0; i < days.length; i++){
            if(day.equals(days[i])){
                System.out.println(i == 0 ? 7 : i);
            }
        }
    }
}


Measured memory_bytes: 19924
import java.util.*;
import java.io.*;
public class Main {
    static InputStreamReader r;
    public static void main(String[] args) throws Exception {
        r = new InputStreamReader(System.in);
        int N = nextInt();
        int M = nextInt();

        boolean[] CF = new boolean[N+1]; // 正解フラグ
        int[] WA = new int[N+1];
        for (int i = 0; i < M; i++) {
            int Pi = nextInt();
            if (CF[Pi] == true) {
                nextString();
                continue;
            }
            String Si = nextString();
            if (Si.equals("AC")) {
                CF[Pi] = true;
            }
            if (Si.equals("WA")) {
                WA[Pi]++;
            }
        }

        int AC = 0;
        int PE = 0;
        for (int i = 0; i < N+1; i++) {
            if (CF[i] == true) {
                AC++;
                PE += WA[i];
            }
        }

        System.out.println(AC + " " + PE);
    }

    public static String nextString() throws Exception {
        String res = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            res += (char)c;
        }
        return res;
    }

    public static int nextInt() throws Exception {
        return Integer.parseInt(nextString());
    }

    public static long nextLong() throws Exception {
        return Long.parseLong(nextString());
    }
}

Measured memory_bytes: 50452
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;
 
int main() {
    int n; cin >> n;
    ll ans = 0;
    rep1(i,n+1){
        if(i % 3 == 0 || i % 5 == 0){
            continue;
        }else{
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
class UnionFindVerSize():
    def __init__(self, N):
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self._parent = [n for n in range(0, N)]
        # グループのサイズ（個数）
        self._size = [1] * N

    def find_root(self, x):
        """ xの木の根(xがどのグループか)を求める """
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x]) # 縮約
        return self._parent[x]

    def unite(self, x, y):
        """ xとyの属するグループを併合する """
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        """ xが属するグループのサイズ（個数）を返す """
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        """ グループ数を計算して返す """
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans

import sys

input=sys.stdin.readline

N=int(input())
uf=UnionFindVerSize(10**5+1)
X=[[] for i in range(0,10**5+1)]
Y=[[] for i in range(0,10**5+1)]
for i in range(0,N):
    x,y=map(int,input().split())
    X[x].append(y)
    Y[y].append(x)

for i in range(0,10**5+1):
    if len(Y[i])>1:
        for j in range(1,len(Y[i])):
            uf.unite(Y[i][0],Y[i][j])

xgroup=[(uf.find_root(i),i) for i in range(0,10**5+1)]
xgroup.sort()
ans=0
stack=[xgroup[0][1]]
g=xgroup[0][0]
for i in range(1,10**5+1):
    if xgroup[i][0]==g:
        stack.append(xgroup[i][1])
    else:
        yco=[]
        for j in range(0,len(stack)):
            yco+=X[stack[j]]
        yco=set(yco)
        ans+=len(stack)*len(yco)
        stack=[xgroup[i][1]]
        g=xgroup[i][0]
yco=[]
for j in range(0,len(stack)):
    yco+=X[stack[j]]
yco=set(yco)
ans+=len(stack)*len(yco)
print(ans-N)

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

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,m;
    cin>>n>>m;
    VL a(n);
    REP(i,n)cin>>a[i];
    vector<PLL> cb(m);
    REP(i,m){
        LL b,c;
        cin>>cb[i].second>>cb[i].first;
    }

    SORT(a);
    SORT(cb);
    int index_a = 0;
    for(int i = m - 1; i >= 0; i--){
        LL b = cb[i].second;
        LL c = cb[i].first;
        int t = index_a + b;
        for(int j = index_a; j < n && j < t; j++){
            if(a[j] < c){
                a[j] = c;
                index_a = j + 1;
            }else{
                break;
            }
        }
    }
    LL ans = 0;
    REP(i,n)ans+=a[i];
    PUTS(ans);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define endl '\n'
#define maxn 1000000000000000000
using namespace std;


int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);

int n;
long long int temp1=1;
cin>>n;
long long int b[n];

for(int i=0;i<n;i++){
    cin>>b[i];
    if(b[i]==0){
        cout<<0;
        return 0;
    }
}

for(int i=0;i<n;i++){

    if(maxn/b[i]<temp1){cout<<-1;return 0;}
    temp1=temp1*b[i];

}
cout<<temp1;
return 0;

}


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

using namespace std;

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

  vector<vector<bool>> g(n, vector<bool>(n, false));
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a][b] = true;
    g[b][a] = true;
  }

  vector<int> order(n);
  iota(order.begin(), order.end(), 0);

  int ans = 0;
  do {
    bool ok = true;
    for (int i = 0; i < order.size() - 1 && ok; ++i) {
      if (!g[order[i]][order[i + 1]]) {
        ok = false;
      }
    }

    if (ok) {
      ans++;
    }
  } while (next_permutation(order.begin() + 1, order.end()));

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    /*考えたこと
    なんか見た感じ左から右へとみながら
    うまいこと操作していけば終わる問題にみえる
    i=piだったら右へとスワップを繰り返すとまずいか？
    いけそうなきがする
     */
    int n;
    cin>>n;
    int p[n];
    rep(i,n){
        cin>>p[i];p[i]--;
    }
    int ans=0;
    rep(i,n-1){
        if(p[i]==i){
            ans++;
            swap(p[i],p[i+1]);
        }
    }
    if(p[n-1]==n-1){ans++;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define pii pair <int, int>
#define print(x) for(auto it : x) cout << it << ' ';
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo

void solve() {
    string s, t; cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < sz(s); ++i) {
        ans += (s[i] != t[i]);
    }
    cout << ans;
}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    int test; cin >> test;
//    for(int tt = 0; tt < test; ++tt) {
        solve();
//    }
    return 0;
}

Measured memory_bytes: 3460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll n;cin>>n;
    vector<ll> v(n);
    rep(i,n)cin>>v[i];
    vector<PL> ans(0);


    for(int i=n-1;0<i;i--)
    {
        while(abs(v[i-1])<abs(v[i]) && v[i-1]>v[i]){
            v[i-1]+=v[i];
            ans.pb({i+1,i});
        }
    }

    for(int i=1;i<n;i++)
    {
        while(v[i-1]>v[i] && abs(v[i-1])>abs(v[i])){
            
            v[i]+=v[i-1];
            ans.pb({i,i+1});
        }
    }

    cout<<siz(ans)<<endl;
    rep(i,siz(ans)){
        cout<<ans[i].fi<<" "<<ans[i].se<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <cstring>

#define ll long long
#define ld long double
#define HS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f3f3f3f3f
#define point complex <double> 
#define pi acos(-1)
#define mod 1000000007


using namespace std;


int main() {
	HS;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int diffX = x2 - x1, diffY = y2 - y1;
	int x3, y3, x4, y4;
	x3 = x2 - diffY;
	y3 = y2 + diffX;
	x4 = x1 - diffY;
	y4 = y1 + diffX;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;


	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<double> x(8);
  vector<double> y(8);
  double graph[N][N]; 
  for(int i=0; i<N; i++) cin >> x.at(i) >> y.at(i);
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      double temp=(x.at(i)-x.at(j))*(x.at(i)-x.at(j))+(y.at(i)-y.at(j))*(y.at(i)-y.at(j));
      graph[i][j]=pow(temp, 0.5);
    }
  }
  double sum=0;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++) sum+=graph[i][j];
  }
  sum=sum/(double)N;
  std::cout << std::setprecision(18) << sum << endl;
}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val C = Array(N) { readLine()!!.toInt() }
    val D = ArrayList<Int>()

    for (i in C.indices) {
        if (D.isEmpty() || D.last() != C[i]) {
            D.add(C[i])
        }
    }

    val M = D.size
    val MOD = 1e9.toLong() + 7

    val dp = Array<ModInt>(M + 1) { ModInt(0L, MOD)}
    val sum = TreeMap<Int, ModInt>()

    dp[0] = ModInt(1L, MOD)
    for (i in D.indices) {
        val t = sum[D[i]] ?: ModInt(0L, MOD)

        dp[i + 1] = dp[i] + t
        sum[D[i]] = dp[i] + t
    }

    println(dp[M].value)
}

class ModInt (value: Long, val mod: Long) {
    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
    }

    val value = (value % mod + mod) % mod

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}


Measured memory_bytes: 76788
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	char ch;
	cin>>ch;
	if((int)(ch)>=65&&(int)(ch)<=90)
	cout<<"A";
	else
	cout<<"a";
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;
#define pp pair<ll,ll>
bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int n;
    cin>>n;
    vector<pp> v;
    ll x,y;
    REP(i,n)
    {
        cin>>x>>y;
        v.push_back({x+y,x-y});
    }
    sort(v.begin(),v.end());
    ll ans=0;
    ll end=INT64_MIN;
    for(auto i:v)
    {
        if(i.second >= end)
        {
            ans++;
            end=i.first;
        }
    }
    cout<<ans;
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    int n,m;
    std::cin >> n>>m;
    std::vector<int> k(m);
    std::vector<std::vector<int> > s(n);
    rep(i,m){
        std::cin >> k[i];
        rep(j,k[i]){
            int dum;
            std::cin >> dum;
            s[dum-1].pb(i);
        }
    }
    
    std::vector<int> p(m);
    rep(i,m)std::cin >> p[i];
    int ans=0;
    for (int bit = 0; bit <(1<<n); bit++) {
        /* code */
        std::vector<int> han(m,0);
        rep(i,n){
            if(bit&(1<<i)){
                rep(j,s[i].size())han[s[i][j]]++;
            }
        }
        bool b=1;
        rep(i,m){
            if((han[i]%2)!=p[i])b=0;
        }
        if(b)ans++;
    }
    std::cout << ans << std::endl;
}

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

int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		sum += a % 2;
	}
	if (sum % 2 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    vector<int> cs(n+1, 0);
    rep(i,n) cs[i+1] = cs[i] + p[i];

    int max_sum = 0;
    rep(i,n-k+1) {
        int tmp_sum = cs[i+k] - cs[i];
        max_sum = max(max_sum, tmp_sum);
    }

    cout << fixed << setprecision(12);
    cout << (max_sum + k) / 2.0 << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=1000000007;
signed main(){
  int N;
  cin>>N;
  vector<string> A(2);
  for(string &S:A)
    cin>>S;
  int ans=1,i=1;
  bool b=true;
  if(A[0][0]==A[1][0])
    b=true,ans=3;
  else
    b=false,i++,ans=6;
  for(;i<N;i++){
    if(A[0][i]==A[1][i]){
      if(b)
        ans=ans*2%M;
      b=true;
    }
    else{
      if(b)
        ans=ans*2%M;
      else
        ans=ans*3%M;
      b=false,i++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
typedef vector<ll> poly;
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
poly operator+(poly x,poly y){
	poly ret(10,0);
	rep(i,10) ret[i]=x[i]+y[i];
	return ret;
}
poly operator-(poly x,poly y){
	poly ret(10,0);
	rep(i,10) ret[i]=x[i]-y[i];
	return ret;
}
poly operator*(poly x,poly y){
	poly ret(10,0);
	rep(i,10) rep(j,10-i) ret[i+j]+=x[i]*y[j];
	return ret;
}
int deg(poly x){
	for(int i=9;i>=0;i--) if(x[i]!=0) return i;
	return -1;
}
void showpoly(poly x){
	int g=0;
	rep(i,10) g=gcd(g,x[i]);
	if(g) rep(i,10) x[i]/=g;
	int N=deg(x);
	if(x[N]<0) x=poly(10,0)-x;
	for(int i=N;i>=0;i--){
		if(x[i]==0) continue;
		if(i!=N&&x[i]>0) cout<<"+";
		if(x[i]==-1) cout<<"-";
		else if(x[i]!=1) cout<<x[i];
		if(i==0){
			if(x[i]==1||x[i]==-1) cout<<"1";
		}else if(i==1){
			cout<<"x";
		}else{
			cout<<"x^"<<i;
		}
	}
	puts("");
}
string s;
int num(int &it){
	int x=0;
	while(isdigit(s[it])){
		x=x*10+s[it]-'0';
		it++;
	}
	return x;
}
poly X(10,0);
poly cons(int x){
	poly a(10,0);
	a[0]=x;
	return a;
}
poly ex(poly x,int p){
	poly ret=cons(1);
	rep(i,p) ret=ret*x;
	return ret;
}
poly expr(int& it);
poly primary(int& it){
	if(s[it]=='('){
		it++;
		poly ret=expr(it);
		it++;
		return ret;
	}
	if(isdigit(s[it])) return cons(num(it));
	if(s[it]=='x'){
		it++;
		return X;
	}
	assert(false);
}
poly factor(int& it){
	poly ret=primary(it);
	if(s[it]=='^'){
		it++;
		int x=num(it);
		ret=ex(ret,x);
	}
	return ret;
}
poly term(int& it){
	poly ret=factor(it);
	while(s[it]!=')'&&s[it]!='+'&&s[it]!='-'){
		poly x=factor(it);
		ret=ret*x;
	}
	return ret;
}
poly expr(int& it){
	poly ret;
	if(s[it]=='-') ret=cons(0)-term(++it);
	else ret=term(it);
	while(s[it]=='+'||s[it]=='-'){
		char c=s[it++];
		poly x=term(it);
		if(c=='+') ret=ret+x;
		else ret=ret-x;
	}
	return ret;
}
int main(){
	X[1]=1;
	while(true){
		cin>>s;
		if(s[0]=='.') break;
		s+=")";
		int it=0;
		poly x=expr(it);
		cin>>s;
		s+=")";
		it=0;
		poly y=expr(it);
		if(deg(x)<deg(y)) swap(x,y);
		while(deg(y)>=0){
			int N=deg(x),M=deg(y);
			rep(i,N-M+1){
				ll a=x[N-i],b=y[M];
				ll c=b/gcd(a,b);
				rep(j,10) x[j]*=c;
				c=x[N-i]/b;
				rep(j,M+1) x[N-i-j]-=c*y[M-j];
				ll g=0;
				rep(j,10) g=gcd(g,x[j]);
				if(g) rep(j,10) x[j]/=g;
			}
			swap(x,y);
		}
		showpoly(x);
	}
}

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

int main(){
	int nums[3];
	for (int i = 0; i < 3; i++) cin >> nums[i];
	int fives = count(nums, nums+3, 5);
	int sevens = count(nums, nums+3, 7);
	cout << (fives == 2 and sevens == 1 ? "YES" : "NO") << "\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (k - 1 < i)
			ans += y;
		else
			ans += x;

	}
	cout << ans << "\n";
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int p[100000],pcnt[100001],a[100001],b[100001],c[100001];
main(void){
	int n,m,i,ima,x,t,tt,sum;
	cin>>n>>m;
	for(i=0;i<m;i++) cin>>p[i];
	ima=p[0];
	for(i=0;i<=m;i++) pcnt[i]=0;
	for(i=1;i<m;i++){
		x=p[i]-ima;
		if(x>=0){
			pcnt[ima]++;
			ima=ima+x;
			pcnt[ima]--;
		}
		else{
			pcnt[ima]--;
			ima=ima+x;
			pcnt[ima]++;
		}
	}
	for(i=1;i<n;i++) pcnt[i]=pcnt[i]+pcnt[i-1];
	sum=0;
	for(i=1;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	for(i=1;i<n;i++) sum+=min(c[i]+b[i]*pcnt[i],a[i]*pcnt[i]);
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 6964
#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 <unordered_set>
using namespace std;
typedef long long unsigned int ll;

int main() {
  ll H, W;
  cin >> H >> W;
  vector<vector<int>> stage(H, vector<int>(W, 0));
  deque<pair<int, int>> remaining;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      if (s[j] == '.') continue;
      stage[i][j] = 1;
      remaining.push_back(make_pair(i, j));
    }
  }
  int ans = 0;
  while (!remaining.empty()) {
    deque<pair<int, int>> _next;
    for (auto p: remaining) {
      int i = p.first;
      int j = p.second;
      stage[i][j] = 2;
      if (i > 0 && stage[i-1][j] == 0) {
        stage[i-1][j] = 1;
        _next.push_back(make_pair(i-1, j));
      }
      if (i < H - 1 && stage[i+1][j] == 0) {
        stage[i+1][j] = 1;
        _next.push_back(make_pair(i+1, j));
      }
      if (j > 0 && stage[i][j-1] == 0) {
        stage[i][j-1] = 1;
        _next.push_back(make_pair(i, j-1));
      }
      if (j < W - 1 && stage[i][j+1] == 0) {
        stage[i][j+1] = 1;
        _next.push_back(make_pair(i, j+1));
      }
    }
    remaining = _next;
    ans++;
  }
  if (ans == 0) {
    cout << 0 << endl;
  } else {
    cout << ans - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 12432
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;

int n;
int a[101010];
int sum = 0;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum += abs(a[i]-a[i-1]);
    }
    sum += abs(a[n]);

    for(int i=1;i<=n;i++){
        printf("%d\n", sum - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]));
    }


}


Measured memory_bytes: 1536