akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};


int main(){
    string s,t;
    int n;
    cin >> n;
    cin >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
}


Measured memory_bytes: 256
def make_bigger_digit_runrunnum(srcNum):
    num_list = list()
    one_digit_num = srcNum % 10
    if one_digit_num == 9:
        num_list.append(srcNum*10 + one_digit_num - 1)
    elif one_digit_num == 0:
        num_list.append(srcNum*10 + one_digit_num + 1)
    else:
        num_list.append(srcNum*10 + one_digit_num - 1)
        num_list.append(srcNum*10 + one_digit_num + 1)
    num_list.append(srcNum * 10 + one_digit_num)
    return num_list


k = int(input())
count = 0
pre_num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
if 0 < k < 10:
    print(k)
else:
    count = 9
    while True:
        new_num_list = []
        for num in pre_num_list:
            new_num_list += make_bigger_digit_runrunnum(num)
        if k <= (len(new_num_list) + count):
            print(sorted(new_num_list)[k-count-1])
            break
        pre_num_list = new_num_list
        count += len(pre_num_list)

Measured memory_bytes: 11788
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    string S;
    cin >> S;

    vector<ll> idx;
    rep(i, S.length()) {
        if (S[i] == 'W') {
            idx.push_back(i);
        }
    }

    // repv(idx) cout << *it << " ";

    ll sum = 0;
    repv(idx) sum += (*it);

    ll N = idx.size();
    ll ans = sum - N * (N - 1) / 2;
    cout << ans << endl;

    return 0;
}


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

int main() {
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}

	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
using namespace std;

int main() {

	long N;
	cin >> N;

	vector<long> A(N + 1, 0);
	vector<long> B(N + 1, 0);

	for (long i = 0; i < A.size(); i++) {
		cin >> A[i];
	}
	for (long i = 1; i < B.size(); i++) {
		cin >> B[i];
	}
	B.push_back(0);

	long sum = 0;
	long val = 0;
	for (long i = 0; i < A.size(); i++) {
		val = min(A[i], B[i]);
		sum += val;
		A[i] -= val;

		val = min(A[i], B[i + 1]);
		sum += val;
		B[i + 1] -= val;
	}

	cout << sum << endl;

	return 0;
}



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

int main() {
  vector<int> group1 = { 1, 3, 5, 7, 8, 10, 12 };
  vector<int> group2 = { 4, 6, 9, 11 };
  vector<int> group3 = { 2 };
  
  int x, y;
  cin >> x >> y;
  
  vector<int> x_group;
  vector<int> y_group;
  for (int i=0; i<group1.size(); i++) {
    if(x == group1.at(i)) x_group = group1;
    if(y == group1.at(i)) y_group = group1;
  }
  for (int i=0; i<group2.size(); i++) {
    if(x == group2.at(i)) x_group = group2;
    if(y == group2.at(i)) y_group = group2;
  }
  for (int i=0; i<group3.size(); i++) {
    if(x == group3.at(i)) x_group = group3;
    if(y == group3.at(i)) y_group = group3;
  }
  if (x_group == y_group) {
    cout << "Yes" << endl;
  }
  else if (x_group != y_group) {
    cout << "No" << endl;
  }
  
}

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 tup = tuple<string, int, int>;

int main() {
    int n;
    cin >> n;
    vector<tup> rest(n);
    rep(i,n) {
        string s;
        int m;
        cin >> s >> m;
        rest.at(i) = make_tuple(s, m, i);
    }
    sort(rest.begin(), rest.end(), [](tup x, tup y) {
        if (get<0>(x) == get<0>(y)) {
            return get<1>(y) < get<1>(x);
        }
        return get<0>(x) < get<0>(y);
    });
    rep(i,n) cout << get<2>(rest.at(i)) + 1 << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    for (ll h = 1; h <= 3500; h++)
    {
        for (ll n = 1; n <= 3500; n++)
        {
            double w = (double)N * h * n / (4 * h * n - N * (n + h));
            if (w - (ll)w > 0)
            {
                continue;
            }
            else if (1 <= (ll)w && (ll)w <= 3500)
            {
                cout << h << ' ' << n << ' ' << (ll)w << endl;
                return 0;
            }
            else
            {
                continue;
            }
        }
    }
}

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

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




if(N == 1){
    cout << "Hello World" << endl; 
    return 0;
}else if(N == 2){
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
    return 0; 
}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;
int main()
{
    ll i,x=0;
    map<string,ll>m;
    string s;
    cin>>x;
    for(i=0; i<x; i++)
    {
        cin>>s;
        m[s]++;
    }
    x=m.size();
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 19216
#include <iostream>
#include <string>
#include <vector>

int main()
{
  std::string S;
  int Q;
  std::cin >> S >> Q;

  int num_1 = 0;
  std::vector<char> top, end;
  int T, F;
  char C;
  for (int i = 0; i < Q; i++)
  {
    std::cin >> T;
    if (T == 1) num_1++;
    else
    {
      std::cin >> F >> C;
      if (num_1 % 2 == 0)
      {
        if (F == 1) top.push_back(C);
        else end.push_back(C);
      }
      else
      {
        if (F == 1) end.push_back(C);
        else top.push_back(C);
      }
    }
  }
  if (num_1 % 2 == 0)
  {
    for (int i = top.size()-1; i >= 0; i--) std::cout << top.at(i);
    std::cout << S;
    for (int i = 0; i < end.size(); i++) std::cout << end.at(i);
    std::cout << std::endl;
  }
  else
  {
    for (int i = end.size()-1; i >= 0; i--) std::cout << end.at(i);
    for (int i = S.size()-1; i >= 0; i--) std::cout << S[i];
    for (int i = 0; i < top.size(); i++) std::cout << top.at(i);
    std::cout << std::endl;
  }
}


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

using namespace std;
typedef long long ll;
const int MAXN = 300100;
const int P = (1 << 17);
const int MAXP = 2 * P + 100;

int N, M;
vector <pair <int, int> > event[MAXN];
int seg[MAXP];

void upd (int x, int v)
{
    x += P;
    while (x)
    {
        seg[x] += v;
        x /= 2;
    }
}

int csum (int x)
{
    if (x >= P) return seg[1];
    x += P;
    int ctot = 0;
    while (x > 1)
    {
        if (x & 1) ctot += seg[x-1];
        x /= 2;
    }
    return ctot;
}

ll gogo (int K)
{
    ll ans = 0;
    for (int i = 0; i * K <= M; i++)
    {
        ll nc = csum ((i + 1) * K) - csum (i * K);
        ans += nc * i;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        int l, r;
        cin >> l >> r;
        l--;

        event[r-l].push_back(make_pair (l, r));
    }

    int nleft = N;
    for (int i = 1; i <= M; i++)
    {
        for (auto pp : event[i])
        {
            nleft--;
            upd (pp.first, -1);
            upd (pp.second, 1);
        }

        cout << nleft + gogo (i) << "\n";
    }
}

Measured memory_bytes: 13184
function Main(input) {

	input = input.split("\n");
	
    const X = parseInt(input[0]);

    if (X >= 30) {
        console.log( 'Yes');
    } else {
        console.log( 'No');
    }
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29680
from sys import stdin,stdout
input = stdin.readline
output = stdout.write
n = int(input())
ans = ''
while n>0:
    if n%26:ans+=chr(64+n%26)
    else:
        ans+='Z'
        n-=1
    n//=26
ans=ans[::-1]
print(ans.lower()+'\n')

Measured memory_bytes: 61796
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    ans = N
    N = abs(N - K * (N // K))
    if ans > N:
        ans = N
    N = abs(N -K)
    if ans > N:
        ans = N


    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61780
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		int[] cnt = new int[26];
		for(int i=0; i<H; i++) {
			char[] c = sc.next().toCharArray();
			for(int j=0; j<W; j++) {
				cnt[c[j]-'a']++;
			}
		}
		
		int[] mod = new int[3];
		for(int i=0; i<26; i++) {
			for(int j=2; j>=0; j--) {
				mod[j] += cnt[i]/(1<<j);
				cnt[i] %= (1<<j);
			}
		}
		
		System.out.println(check(H, W, mod) ? "Yes" : "No");
		
		sc.close();
	}
	
	static boolean check(int H, int W, int[] mod) {
		int[] need = new int[3];
		need[2] = (H/2)*(W/2);
		need[1] = (H%2)*(W/2) + (W%2)*(H/2);
		need[0] = (H%2)*(W%2);
		for(int i=2; i>=0; i--) {
			if(mod[i]<need[i])
				return false;
			if(i>0)
				mod[i-1] += (mod[i]-need[i])*2;
		}
		return true;
	}
}

Measured memory_bytes: 25428
#python3
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    print(sum([a[i] for i in range(n) if i%2 == 0]) - sum([a[i] for i in range(n) if i%2 !=0]))
main()



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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vll = V<ll>;
using VVll = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Msi = M<string, int>;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()


int main() {
    string s;
    cin >> s;
    s.replace(5, 1, " ");
    s.replace(13, 1, " ");
    std::cout << s << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n;
ll k;
int a[maxn]; 
ll sum[maxn];
ll calc(int x)
{
	ll ret = 0;
	for(int i = 1; i <= n; ++i)
		ret += upper_bound(a + 1, a + n + 1, x - a[i], greater<int>()) - 1 - a;
	return ret;
}
void solve(int x)
{
	ll ans = 0;
	for(int i = 1; i <= n; ++i)
	{
		int r = lower_bound(a + 1, a + n + 1, x - a[i], greater<int>()) - 1 - a;
		ans += sum[r] + 1ll * a[i] * r;
		k -= r;
	}
	ans += k * x;
	printf("%lld\n", ans);
}
int main()
{
	scanf("%d%lld", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, greater<int>());
	for(int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];
	int l = 2, r = 2e5;
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(calc(mid) >= k)
			l = mid + 1;
		else
			r = mid - 1;
	}
	solve(r);
	return 0;
}
		

Measured memory_bytes: 1536
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i,n) for(int i=0; i<(n); i++)
    using ll = long long;
    #define int long long
    using P = pair<int,int>;
    const int INF = 1000000000000000000;
    signed main(){
        int n;cin >> n;
        int a[n];
        int zero = 0;
        int inf = 0;
        rep(i,n){
            cin >> a[i];
            if(a[i] > INF){
                inf = 1;
                
            }
            if(a[i] == 0){
                zero = 1;
            }
        }
        int ans = 1;
        if(zero){
            cout << 0 << endl;
            return 0;

        }
        if(inf){
            cout << -1 << endl;
            return 0;
        }
        rep(i,n){
            if(ans > INF / a[i]){
                cout << -1 << endl;
                return 0;
            }
            ans *= a[i];
            if(ans > INF){
                cout << -1 << endl;
                return 0;
            }
        }
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

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

  ll left = 0, right = 0;
  int l = 0, r = N - 1;
  for(int i = 0; i < N; i++) {
    if(left <= right) {
      left += A[l];
      l++;
    } else {
      right += A[r];
      r--;
    }
  }
  cout << max(left, right) - min(left, right) << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n;
std::vector<pair<string, pair<int,int>>> p;

bool compare_by_b(pair<string, pair<int,int>> a, pair<string, pair<int,int>> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

int main(){
  cin >> n;
  p.resize(n);
  for (int x = 0; x < n; x++) {
    string a; int b;
    cin >> a >> b;
    p[x] = make_pair(a,make_pair(b,x+1));
  }
  sort(p.begin(),p.end());
  cout << endl;
  int test=0;
  int i=0;
  for (i = 0; i < n-1; i++) {
    if(p[i].first != p[i+1].first){
      for (int l=0;l<=test;l++) {
        cout << p[i-l].second.second << endl;
      }
      test=0;
    }else{
      test++;
    }
  }
  for (int l=0;l<=test;l++) {
    cout << p[i-l].second.second << endl;
  }
}


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

int main() {
int A,B,C;
  cin>>A>>B>>C;
  
  int M=max(A, max(B, C)), ans;
  for(int i=0; i<100; i++){
   if(i>=M && (3*i)%2==(A+B+C)%2){ // iはM以上、下記式より3*iと(A+B+C)はパリティ(%2による比較)が一致する
    ans=(3*i-(A+B+C))/2; // 問題文を読むと、毎回全体の合計が2ずつ増えていくので、
    break;               // 3*i-(A+B+C)を2で割った値が操作回数になる
   }
  }
  
  cout<<ans;
}


Measured memory_bytes: 256
N, W = [int(_) for _ in input().split()]

items = [[] for _ in range(4)]
w1, v = [int(_) for _ in input().split()]
items[0].append(v)

for i in range(N - 1):
    w, v = [int(_) for _ in input().split()]
    items[w - w1].append(v)

for i in range(4):
    items[i].sort(reverse=True)

S = []
for i in range(4):
    l = len(items[i])
    s = [0] * (l + 1)
    for j in range(l):
        s[j + 1] = items[i][j] + s[j]
    S.append(s)

ans = 0
for i in range(len(items[0]) + 1):
    for j in range(len(items[1]) + 1):
        for k in range(len(items[2]) + 1):
            for l in range(len(items[3]) + 1):
                v = S[0][i] + S[1][j] + S[2][k] + S[3][l]
                w = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l
                if w <= W:
                    ans = max(v, ans)
print(ans)


Measured memory_bytes: 42092
class UnionFind:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y]

N, M = [int(_) for _ in input().split()]

uf = UnionFind(N)
for m in range(M):
    A, B = [int(_) - 1 for _ in input().split()]
    uf.union(A, B)

print(max(uf.size))


Measured memory_bytes: 16116
import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String[] input = sc.nextLine().split(" ");
      
      int W = Integer.parseInt(input[0]);
      int H = Integer.parseInt(input[1]);
      int x = Integer.parseInt(input[2]);
      int y = Integer.parseInt(input[3]);
      int r = Integer.parseInt(input[4]);
      
      
      if ( 2 * r > H && 2 * r > W) {
         //if the rectangle is too small
         System.out.println("No");
      } else if ( x < r || W - r < x) {
         //if the circle is out horizontally
         System.out.println("No");
      } else if ( y < r || H - r < y) {
         //if the circle is out vertically
         System.out.println("No");
      } else {
         //else
         System.out.println("Yes");
      }
      
      
      
   }
}


Measured memory_bytes: 26284
from collections import defaultdict
n,q=map(int,input().split())
Edges=defaultdict(list)
for _ in range(n-1):
    a,b=map(int,input().split())
    Edges[a-1].append(b-1)
Nodes = [0]*n
for _ in range(q):
    p,x=map(int,input().split())
    Nodes[p-1] += x

def dfs(Edges,Nodes):
    visited = [False]*(len(Nodes))
    stack = []
    stack.append((0, 0))

    while len(stack)>0:
        current, preval = stack.pop()
        if visited[current]:
            continue
        visited[current] = True
        Nodes[current] += preval
        preval = Nodes[current]
        for i in Edges[current]:
            stack.append((i, preval))
    return Nodes

Nodes = dfs(Edges,Nodes)

print(" ".join(list(map(str,Nodes))))

Measured memory_bytes: 123564
// 2015/03/09 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;

	if(b1==1 && b2==0 && b3==0){
		cout << "Close" << endl;
	}
	else if(b1==0 && b2==1 && b3==0){
		cout << "Close" << endl;
	}
	else if(b1==1 && b2==1 && b3==0){
		cout << "Open" << endl;
	}
	else if(b1==0 && b2==0 && b3==1){
		cout << "Open" << endl;
	}
	else{
		cout << "Close" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

const long long INF = 1LL << 60;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    rep(i, n){
        if(a.at(i)%2==0 && (a.at(i)%3==0 || a.at(i)%5==0)){
            continue;
        }
        else if(a.at(i)%2!=0) continue;
        else{
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
  int flag = 0;
  long long result = 1;
  cin >> N;
  vector<long long> A(N);
  for(int a = 0;a < N;a++)cin >> A[a];
  sort(A.begin(),A.end());
  for(int a = 0;a < N;a++){
    if(result != 0){
    if(1000000000000000000 / result < A[a]){
     result = -1;
      break;
    }
    }
   result *= A[a]; 
  }
  cout << result << endl;

}


Measured memory_bytes: 4052
A, B, C, K = map(int,input().split())

n_a = 0
n_b = 0
n_c = 0

if K > A:
  n_a = A

  if K-A > B:
    n_b = B
    n_c = K-A-B
  
  if K-A == B:
    n_b = B
    n_c = 0
  
  if K-A < B:
    n_b = K-A
    n_c = 0 

if K == A:
  n_a = K
if K < A:
  n_a = K

print(n_a+(-1)*n_c)



Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int r; cin >> r;
    cout << 3*r*r << endl;
}

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

const int mod = 1e9 + 7;

map < int, int > primes (int x) {
  map < int, int > res;
  for (int i = 2; i * i <= x; ++i) {
    while (x % i == 0) {
      x /= i;
      ++res[i];
    }
  }
  if (x != 1)
    ++res[x];
  return res;
}

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

  int n;
  cin >> n;
  map < int, int > pows;
  for (int i = 2; i <= n; ++i) {
    map < int, int > here = primes(i);
    for (auto pr: here) 
      pows[pr.first] += pr.second;
  }
  int64_t ans = 1;
  for (auto pr: pows) 
    (ans *= (pr.second + 1)) %= mod;
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main(){
    int n;
    cin >> n;
    vi a(n);

    rep(i, n){
        cin >> a[i];
    }

    int mini;
    int tmp = INF;
    mini = INF;
    while(true){
        rep(i, n){
            if(a[i]!=0){
                mini = min(mini, a[i]);
                //cout << i << ":" << a[i] << endl;
            }
        }
        //ゼロじゃないなかで一番小さいのを選ぶ

        //cout << tmp << ":" << mini << endl; 
        if(tmp == mini) break;

        rep(i, n){
            if(a[i] == mini) continue;
            a[i] %= mini;
            //cout << i << "::" << a[i] << endl;
        }
        //miniでないやつは割った余りを挿入

        //rep(i, n) cout << i << "::" << a[i] << endl;

        tmp = mini;
        //今回のミニを覚えておく
    }

    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {long s=1;
			int a = int.Parse(Console.ReadLine());
            for (int f = 2;f<a+1;f++) s*=f;
            Console.WriteLine(s);
		}
	}
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int a, b;
    cin >> a >> b;
    setint st;
    st.insert(a);
    st.insert(b);
    REP(i, 1, 4)
    {
        if (st.count(i) == 0)
        {
            cout << i << endl;
            return;
        }
    }
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#include <vector>
using namespace std;
int pow(int n){
    if(n==0)return 1;
    else return pow(n-1)*10;
}
int getRank(int N){
    if(N==0)return 0;
    else return getRank(N/10)+1;
}
int head(int N, int order){
    return N/pow(order-1);
}
int tail(int N, int order){
    return N % pow(order-1);
}
int get(int rank, int N){
    return (N/pow(rank))%10;
}
vector<vector<vector<vector<int>>>> memo=  vector<vector<vector<vector<int>>>>(10,
 vector<vector<vector<int>>>(2,
 vector<vector<int>>(2,
 vector<int> (2,0))));
//no limit
int solve(int order, int seven, int five, int three){
    if(memo[order][seven][five][three]!=0)return memo[order][seven][five][three];
    if(order==0)return seven&&five&&three?1:0;
    else return memo[order][seven][five][three]=solve( order-1, 1, five, three)
    +solve( order-1, seven, 1, three)
    +solve( order-1, seven, five, 1);
}
//limit
int solve(int order, int N, int seven, int five, int three){
    if(order==0)return seven&&five&&three?1:0;
    else {
        int headN=head(N,order);
        int tailN=tail(N,order);
        if(headN>=8)
        return solve( order-1, 1, five, three)
        +solve( order-1, seven, 1, three)
        +solve( order-1, seven, five, 1);
        if(headN==7)    
        return solve(order-1, tailN, 1, five, three)
        +solve(order-1, seven, 1, three)
        +solve(order-1, seven, five, 1);
        if(headN==6)    
        return solve(order-1, seven, 1, three)
        +solve(order-1, seven, five, 1);
        if(headN==5)    
        return solve(order-1, tailN, seven, 1, three)
        +solve(order-1, seven, five, 1);
        if(headN==4)    
        return solve(order-1, seven, five, 1);
        if(headN==3)    
        return solve(order-1, tailN, seven, five, 1);
        else return 0;
    }
}
int main(){
    int N;
    cin>>N;
    int NnogetRank = getRank(N);
    int sum =0;
    for(int i=1;i<=NnogetRank;i++){
        sum+=solve(i,N,0,0,0);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000
int A[MAX+1],H;
void maxHeapify(int);
int left(int l){
  return 2*l;
}
int right(int r){
  return 2*r+1;
}
int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
void maxHeapify(int i){
  int l,r,largest,t;
  l=left(i);
  r=right(i);
  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;
  if(largest!=i){
    t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxHeapify(largest);
  }
  
}



Measured memory_bytes: 3688
n,m,x = gets.chomp.split(" ").map(&:to_i)

a = Array.new.map{Array.new}
n.times do |i|
  a[i] = gets.chomp.split(" ").map(&:to_i)
end
ans = 100000000
ans_c_flag = 0

[0, 1].repeated_permutation(n) do |bits|
  exp = Array.new(m,0)
  sum = 0
  (0...bits.length).each do |i|
    if bits[i] == 1
      (0...m).each do |j|
        exp[j] += a[i][j+1]
      end
      sum += a[i][0]
    end
  end
  if exp.all? {|v| v >= x} && sum < ans
    ans = sum
    ans_c_flag = 1
  end
end

print "-1" if ans_c_flag == 0
print ans if ans_c_flag == 1

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

void solve() {
    map<int,int> line;
    int add = 0;
    y.push_back(0);
    x.push_back(0);
    rep(i,n) {
        int a; cin>>a;
        add += a;
        y.push_back(add);
    }
    add = 0;
    rep(i,m) {
        int a; cin>>a;
        add += a;
        x.push_back(add);
    }
    rep(i,y.size()) rep(j,x.size()) line[y[i]-x[j]]++;

    int ans = 0;
    map<int,int>::iterator it = line.begin();
    while(it!=line.end()) {
        ans += it->second*(it->second-1)/2;

        it++;
    }

    cout<<ans<<endl;
    y.clear();
    x.clear();

}

int main() {
    while(cin>>n>>m) {
        if(n+m==0) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 28028
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int H,W; cin >> H >>W;
    vector<vector<char>> m(H+2,vector<char>(W+2,'@'));
    for(int i = 1; i <= H;++i)for(int j =1 ; j<=W;j++)cin>>m[i][j];
    int dx[8] = {0,1,1,1,0,-1,-1,-1},dy[8] = {-1,-1,0,1,1,1,0,-1};
    vector<vector<int>> v(H+2,vector<int>(W+2,-1));
    for(int i = 1; i <= H;++i)for(int j =1 ; j<=W;j++){
        if(m[i][j]=='#')continue;
        int cnt=0;
        for(int k=0;k < 8;k++){
            int nx = i+dx[k],ny=j+dy[k];
            if(m[nx][ny]=='#')cnt++;}v[i][j]=cnt;
    }
    for(int i = 1; i <= H;++i){for(int j =1 ; j<=W;j++){if(v[i][j]==-1)cout<<'#';else cout<<v[i][j];}cout<<endl;
        
    }
    return 0;
}


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

namespace CSharpSample01
{
    
    
    class Program
    {

        static bool BinarySearch(int key, int[] a)
        {

            int left = 0;
            int right = a.Length - 1;

            while(left <= right)
            {
                int mid = (left + right) / 2;

                if (a[mid] == key) return true;
                else if(a[mid] < key)
                {
                    left = mid + 1;
                }
                else
                {
                    right = mid - 1;
                }
            }
            
            return false;
        }
        



        static void Main(string[] args)
        {
            int sn = int.Parse(Console.ReadLine());
            int[] S = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int tn = int.Parse(Console.ReadLine());
            int[] T = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int cnt = 0;

            for(int i = 0; i < tn; i++)
            {
                if (BinarySearch(T[i], S)) cnt++;
            }

            Console.WriteLine(cnt);
        }
    }
}


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

int main(){
    ll n ;
    cin>>n ;
    ll A[n],B[n],C[n];
    for(ll i=0;i<n;i++){
        cin>>A[i]>>B[i]>>C[i];
    }
    for(ll i=n-2;i>=0;i--){
        A[i]=max(B[i+1]+A[i],C[i+1]+A[i]);
        B[i]=max(A[i+1]+B[i],C[i+1]+B[i]);
        C[i]=max(B[i+1]+C[i],A[i+1]+C[i]);
    }
    ll ans = max({A[0],B[0],C[0]});
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k, a, b;
  cin >> n >> k;
  b = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a < k - a) {
      b += 2 * a;
    }
    else {
      b += 2 * (k - a);
    }
  }
  cout << b << endl;
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int X, Y, Z, K; 
  cin >> X >> Y >> Z >> K;

  vector<int> A(X);
  REP(i, X) cin >> A[i];

  vector<int> B(Y);
  REP(i, Y) cin >> B[i];

  vector<int> C(Z);
  REP(i, Z) cin >> C[i];

  vector<int> D;
  REP(i, X) REP(j, Y){
    D.emplace_back(A[i]+B[j]);
  }
  sort(ALL(D), greater<>());

  vector<int> ans;
  REP(i, min(K, (int)D.size())) REP(j, Z){
    ans.emplace_back(D[i]+C[j]);
  }
  sort(ALL(ans), greater<>());

  REP(i, K){
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 43112
#include "bits/stdc++.h"
// Custom Header {{{
#define all(x) x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
#define repr(i,s,t) for (i64 i = (n); i >= (t); --i)
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

struct Edge { // {{{
    int src, to;
    i64 cost;
    Edge(int src,  int to, i64 cost) : src(src), to(to), cost(cost) {}
    Edge(int to, i64 cost = 0) : Edge(-1, to, cost) {}
    Edge() {}
    bool operator< (const Edge &o) const { return cost < o.cost; }
    bool operator> (const Edge &o) const { return cost > o.cost; }
};
using Edges = vector<Edge>;
using WGraph = vector<vector<Edge>>;
using UGraph = vector<vector<int>>;
// }}}

//@@@@@@@@
//@ snippet bellmanFord
//@ options head
// If it find NEGATIVE-CYCLE, it returns EMPTY.
vector<i64> bellmanFord(const WGraph &G, int src) // {{{
{
    const int V = G.size();
    vector<i64> dist(V, LINF);
    dist[src] = 0;

    bool updated = true;
    for (int i = 0; updated && i < V-1; ++i) {
        updated = false;
        rep(s, V) if (dist[s] < LINF) {
            for (const auto &e : G[s]) updated |= chmin(dist[e.to], dist[s] + e.cost);
        }
    }

    rep(s, V) for (const auto &e : G[s]) {
        if (dist[s] + e.cost < dist[e.to]) return {};
    }

    return dist;
}
// }}}
//@@@@@@@

/*
   Verified On: 2019-08-11
   https://atcoder.jp/contests/abc137/tasks/abc137_e
*/
void arrivableNodeDFS(int u, const WGraph &G, bool vist[])
{
    if (!vist[u]) {
        vist[u] = true;
        for (const auto &e : G[u]) arrivableNodeDFS(e.to, G, vist);
    }
}
void ABC137_E() // {{{
{
    int N, M, P;
    cin >> N >> M >> P;

    WGraph G(N), revG(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        c -= P;
        G[a].emplace_back(a, b, -c);
        revG[b].emplace_back(b, a, -c);
    }

    bool canArrive[2555] {};
    bool canGoal[2555] {};

    arrivableNodeDFS(0, G, canArrive);
    arrivableNodeDFS(N-1, revG, canGoal);

    WGraph H(N);
    rep(u, N) {
        if (canArrive[u] && canGoal[u]) {
            for (const auto &e : G[u]) H[u].emplace_back(e);
        }
    }

    const auto cost = bellmanFord(H, 0);
    if (cost.empty()) {
        cout << -1 << endl;
    } else {
        cout << max<i64>(0, -cost[N-1]) << endl;
    }
}
// }}}

signed main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ABC137_E();
    return 0;
}


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

int main(){
    //cout<<(3485*1202*3167)/(4*1202*3167-3485*1202-3485*3167)<<endl;
    long long a;
    bool check = false;
    cin>>a;
    for(long long c=1;c<=3500;c++){
        for(long long d=c;d<=3500;d++){
            //cout<<a<<" "<<c<<" "<<d<<endl;
            if((4*c*d-a*d-a*c)>0){
                if((a*c*d)%(4*c*d-a*d-a*c)==0){
                    cout<<(a*c*d)/(4*c*d-a*d-a*c)<<" "<<c<<" "<<d<<endl;
                    check=true;
                }
            }
            if(check)
                break;
        }
        if(check)
            break;
    }

}
//392962 1202 3167


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

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

int main()
{
    int a,b,c,d;
    std::cin >> a >> b >> c >> d;

    int s = (a > c) ? a : c;
    int e = (b < d) ? b : d;
    int ans = (e > s) ? e - s : 0;
    std::cout <<  ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N,Q = map(int,input().split())
d = defaultdict(list)

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

c = defaultdict(int)

for _ in range(Q):
    p,x = map(int,input().split())
    c[p] += x

ans = [0 for i in range(N)]
que = [(1,0,-1)]
while len(que)>0:
    tmp = []
    for v,x,par in que:
        x += c[v]
        ans[v-1] = str(x)
        for w in d[v]:
            if w != par:
                tmp.append((w,x,v))
    que = tmp

print(*ans)


Measured memory_bytes: 104584
#include <stdio.h>

int
main(void)
{
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);

	int res;
	if (A == B)
		res = C;
	else if (B == C)
		res = A;
	else
		res = B;

	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

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

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

using namespace std;

const long long MOD = 1000000007;

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

	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;

	if (s == u) --a;
	if (t == u) --b;

	cout << a << " " << b << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    string s;
    cin >> n >> s;

    int white[n + 1] = {};
    int black[n + 1] = {};

    rep(i, 0, n) {
        if (s[i] == '.') {
            white[i + 1] = white[i] + 1;
            black[i + 1] = black[i];
        } else {
            white[i + 1] = white[i];
            black[i + 1] = black[i] + 1;
        }

    }

    int ans = 1000000000;
    rep(i, 0, n + 1) {
        int x = black[i] - black[0];
        int y = white[n] - white[i];
        ans = min(ans, x + y);
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
	char n[5] = "";
	for (int i = 0; i < 4; i++)
		cin >> n[i];
	sort(n, n + 4);
	cout << (string(n) == "1479" ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

n=int(input())
cnt=0
#curは今の数字
def dfs(cur,f3,f5,f7):
		global cnt
		#print(cur,f3,f5,f7,cnt)
		if cur>n:
			return
		elif f3&f5&f7:
			cnt+=1
		dfs(cur*10+3,True,f5,f7)
		dfs(cur*10+5,f3,True,f7)
		dfs(cur*10+7,f3,f5,True)

dfs(0,False,False,False)
print(cnt)







Measured memory_bytes: 41840
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int T = Integer.parseInt(sc.next());
        System.out.println(T/A*B);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define MOD 1000000007

using namespace std;

void upd(ll st[], ll i, ll l, ll r, ll l1, ll val)
{
    if(l>l1 || r<l1)
        return;
    if(l == r)
    {
        st[i] = max(st[i], val);
        return;
    }
    
    ll mid = (l+r)/2;
    upd(st,2*i+1,l,mid,l1,val);
    upd(st,2*i+2,mid+1,r,l1,val);
    
    st[i] = max(st[2*i+1], st[2*i+2]);
}

ll que(ll st[], ll i, ll l, ll r, ll l1)
{
    if(l>l1)
        return 0;
    if(l == r)
        return st[i];
    if(r<=l1)
        return st[i];
    ll maxi = 0;
    ll mid = (l+r)/2;
    maxi = max({maxi, que(st,2*i+1,l,mid,l1), que(st,2*i+2,mid+1,r,l1)});
    return maxi;
}

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll ht[n], arr[n];
   for(ll i=0;i<n;i++)
        cin>>ht[i];  
   
   for(ll i=0;i<n;i++) 
        cin>>arr[i];
   
   ll lim = ceil(log2(n));
   lim = (1ll<<(lim + 1)) - 1;
   ll st[lim];
   memset(st,0,sizeof(st));
   
   pair<ll,ll> hold[n];
   for(ll i=0;i<n;i++)
   {
       hold[i].first = ht[i];
       hold[i].second = i;
   }
   
   sort(hold,hold+n);
   
   upd(st,0,0,n-1,hold[0].second,arr[hold[0].second]);
   ll ans = arr[hold[0].second];
   
   //cout<<"ans = "<<ans<<"\n";
   
   for(ll i=1;i<n;i++)
   {
       ll temp = que(st,0,0,n-1,hold[i].second);
       temp+=arr[hold[i].second];
       //cout<<"arr[i] = "<<arr[hold[i].second]<<"\n";
       //cout<<"at "<<hold[i].first<<" temp = "<<temp<<"\n";
       ans = max(temp,ans);
       upd(st,0,0,n-1,hold[i].second,temp);
   }
   
   cout<<ans;
   
   return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <math.h>
using namespace std;

int main(void)
{
	int n, cnt = 0;

	cin >> n;

	for(int i = 0; i < n; i++) {
		long num;
		bool flag = true;
	
		cin >> num;

		for(int j = 2; j <= (int)sqrt((double)num) && flag == true; j++) {
			if(num % j == 0) {
				flag = false;
				break;
			}
		}

		if(flag == true || num == 2)	cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	ll n,m,h,w,ans,s[2000],t[2000];
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		s[0]=t[0]=ans=0;
		rep(i,n)cin>>s[i+1],s[i+1]+=s[i];
		rep(i,m)cin>>t[i+1],t[i+1]+=t[i];
		ll a[2000000]={},b[2000000]={};
		rep(i,n)REP(j,i+1,n+1)a[s[j]-s[i]]++;
		rep(i,m)REP(j,i+1,m+1)b[t[j]-t[i]]++;
		rep(i,2000000)ans+=a[i]*b[i];
		print(ans);
	}
}



Measured memory_bytes: 34324
N, K = map(int, input().split())
b = [0]
for _ in range(N):
    b.append(b[-1] + int(input()) - K)

# 座標圧縮
c = {}
for i, v in enumerate(sorted(set(b))):
    c[v] = i + 1

# BIT
data = [0] * (N + 2)
def add(i):
    while i <= N + 1:
        data[i] += 1
        i += i & -i
def get(i):
    s = 0
    while i:
        s += data[i]
        i -= i & -i
    return s

ans = 0
for v in b:
    ans += get(c[v])
    add(c[v])
print(ans)

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

int main () {
	
	long long int n=0, a=0, b=0, i=0, x=0;
	vector <long long int> val;

	scanf("%lld %lld %lld", &n, &a, &b);

	for (i=0; i<n; i++) {
		scanf("%lld", &x);
		val.push_back(x);
	}

	long long int aux=0, aux2=0;
	long long int ini=0, fin=0, med=0;
	bool flag=0;

	ini = 1;
	fin = 1000000000;
	med = (ini+fin) / 2;

	while (ini != fin) {

		med = (ini+fin)/2;

		aux = med * b;
		x = a-b;
		aux2 = 0;
		for (i=0; i<n; i++) {
			if ((val[i]-aux) > 0) {
				aux2 += (val[i]-aux)/x;
				if ((val[i]-aux)%x != 0) aux2++;
				//aux2 += ((val[i]-aux)+a-1) / a;
			}
		}

		if (aux2 <= med) flag=1;
		else flag = 0;

		if (flag) fin = med;
		else ini = med+1;

		
	}

	printf("%d\n", ini);

	return 0;
}

Measured memory_bytes: 1400