akhauriyash/Code-Regression huggingface dataset:
s = input()

zen = int(s[0:2])
kou = int(s[2:4])

ym = False
my = False
if 1 <= zen and zen <= 12:
    my = True
if 1 <= kou and kou <= 12:
    ym = True

if my and ym:
    print('AMBIGUOUS')
elif my:
    print('MMYY')
elif ym:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	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;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}
int main() {
	map<ll, ll>A;
	ll N, M;
	cin >> N >> M;
	vector<ll>a(M), b(M);
	rep(i, M) {
		cin >> a[i] >> b[i];
		A[a[i] + b[i] * N] = 1;

	}
	rep(i, M) {
		if (a[i] == 1) {
			if (A[b[i] + N * N] == 1) {

				cout << "POSSIBLE";
				return 0;
			}

		}

	}
	cout << "IMPOSSIBLE";

}


Measured memory_bytes: 22144
#include <stdio.h>

int main()
{
  int s[100000];
  int t[50000];
  int n=0,q=0,i=0,count=0,left=0,mid=0,right=0;

  //データの入力
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&t[i]);

  //データの探索(二分探索)
  for(i=0;i<q;i++)
    {
      left = 0;
      right = n;
      while(1)
	{
	  if(left>=right)break;
	  mid = (left + right) / 2;
	  if(s[mid]==t[i])
	    {
	      count++;
	      break;
	    }
	  else if(t[i] < s[mid])right = mid;
	  else if (s[mid] < t[i])left = mid + 1;
	}
    }

  //出力
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2292
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for(int loop=0;loop<n;loop++){
		int h,w;
		cin >> h >> w;
		int i,j,k;
		int c[256];
		for(i=0;i<256;i++) c[i]=-2;
		c['.']=-1;
		
		char in;
		int num=0;
		int m[50][50];
		int nwse[10][4];
		for(i=0;i<10;i++){
			nwse[i][0]=1000;
			nwse[i][1]=1000;
			nwse[i][2]=-1;
			nwse[i][3]=-1;
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				cin >> in;
				if(c[in]==-2){
					c[in] = num;
					num++;
				}
				m[i][j]=c[in];
				if(c[in]!=-1){
					nwse[c[in]][0] = min(nwse[c[in]][0],i);
					nwse[c[in]][1] = min(nwse[c[in]][1],j);
					nwse[c[in]][2] = max(nwse[c[in]][2],i);
					nwse[c[in]][3] = max(nwse[c[in]][3],j);
				}
			}
		}
		int g[10][10];
		for(i=0;i<10;i++) for(j=0;j<10;j++) g[i][j]=0;
		
		int f=0;
		for(k=0;k<num;k++){
			for(i=nwse[k][0];i<=nwse[k][2];i++){
				for(j=nwse[k][1];j<=nwse[k][3];j++){
					if(m[i][j]==-1){
						f=1;
						break;
					}else if(m[i][j]!=k){
						g[m[i][j]][k]=1;
					}
				}
			}
		}
		if(f==1){
			cout << "SUSPICIOUS" << endl;
			continue;
		}
		
		int mark[10];
		for(i=0;i<10;i++) mark[i]=0;
		
		for(k=0;k<num;k++){
			for(i=0;i<num;i++){
				if(mark[i]==0){
					f=0;
					for(j=0;j<num;j++) if(g[j][i]==1) f=1;
					if(f==0){
						for(j=0;j<num;j++) g[i][j]=0;
						mark[i]=1;
					}
				}
			}
		}
		
		f=0;
		for(i=0;i<num;i++) if(mark[i]==0) f=1;
		if(f==0) cout << "SAFE" << endl;
		else cout << "SUSPICIOUS" << endl;
	}
	return 0;
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100], n;

int f(int y)
{
    int sol = 0;
    for (int i = 0; i < n; ++i)
        sol += (a[i] - y) * (a[i] - y);
    return sol;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int sol = 1e9;
    for (int i = -100; i <= 100; ++i)
        sol = min(sol, f(i));
    cout << sol;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include <typeinfo>
using namespace std;

int ctoi(char a){
  return a-'0';
}

int main(){
  string s;
  cin >> s;
  vector<vector<long> > dp(s.length(), vector<long>(13, 0));
  // init
  if(s[0] == '?'){
    for(int i=0;i<10;i++){
      dp[0][i] = 1;
    }
  }
  else{
    dp[0][ctoi(s[0])] = 1;
  }
  
  for(int i=1;i<s.length();i++){
    for(int j=0;j<13;j++){
      if(s[i]=='?'){
        for(int n=0;n<10;n++){
          dp[i][(j*10+n)%13] += dp[i-1][j];
          dp[i][(j*10+n)%13] = dp[i][(j*10+n)%13] % 1000000007;
        }
      }
      else{
        int n = ctoi(s[i]);
        dp[i][(j*10+n)%13] += dp[i-1][j];
        dp[i][(j*10+n)%13] = dp[i][(j*10+n)%13] % 1000000007;
      }
    }
  }
  
  cout << dp[s.length()-1][5] % 1000000007 << "\n";
}


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

const ll MOD = (ll) 1e9 + 7;

ll p(ll a, ll b){
    ll res = 1;
    a %= MOD;
    while(b){
        if(b&1) res = (res * a) % MOD;
        a *= a; a %= MOD;
        b >>= 1;
    }
    return res%MOD;
}

int main() {

    ll n , k  ;
    scanf("%lld%lld",&n,&k) ;
    ll i ;
    vector<ll> dp(k+5) ;
    for (i=k;i>0;--i) {
        ll mn = k/i ;
        ll gd = p(mn,n) ;
        ll ex = 0 ;
        //cout << i << ' ' << mn << endl ;
        for(ll j=i* 2; j<=k ;j+=i) {
            ex = (ex+dp[j])%MOD ;
            //cout << i ;
        }
        //cout << ex << ' ' ;
        dp[i] = (gd-ex+MOD)%MOD ;

    }
    ll ans = 0 ;
    for(i=1;i<=k;i++) {
        (ans+=dp[i]*i) ; ans%=MOD ;
       // cout << ans << endl ;
    }
    cout << ans%MOD << endl ;



    return 0 ;
}


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

#define int long long
#define rep(i, n) for (int i = 0; (int) (i) < n; i++)
#define reps(i, n) for (int i = 1; (int) (i) <= n; i++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << x << endl
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) { return b < a && (a = b, true); }
struct SetUp { SetUp() { cout << fixed << setprecision(20); }; } setUp;

int N;
signed main() {
    cin >> N;
    cout << (N + 1) / 2 / (double) N << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N = int(readline())

    divs = divisors(N)
    ans = INF
    for d in divs[: (len(divs) + 1) // 2]:
        ans = min(ans, max(len(str(d)), len(str(N // d))))

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9384
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

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

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = Counter(v for _, v in C.items())

print((H - 2) * (W - 2) - sum(D.values()))
for i in range(1, 10):
    print(D[i])


Measured memory_bytes: 178260
#include<iostream>
#include<cstdio>
#include<vector>
const int N=2e5+5;
char s[2][N];int n;
bool check(std::vector<int> &a,std::vector<int> &b,int pos,int len) {
    int L=1,R=len;
    for(int i=a.size()-1;~i;--i) {
        if(b[i]==1) {
            if(a[i]==-1) R=std::min(R+1,len);
            else L=std::max(L-1,1);
        }
        else {
            if(a[i]==-1) L++;
            else R--;
        }
        if(L>R) return false;
    }
    return pos>=L&&pos<=R;
}
bool solve(char l,char r,int pos,int len) {
    std::vector<int> a,b;
    for(int i=1;i<=n;i++) {
        for(int j=0;j<2;j++) {
            if(s[j][i]==l) {
                b.push_back(j);
                a.push_back(-1);
            }
            if(s[j][i]==r) {
                b.push_back(j);
                a.push_back(1);
            }
        }
    }
    return check(a,b,pos,len);
}
int main() {
    int h,w,r,c;
    scanf("%d%d%d",&h,&w,&n);
    scanf("%d%d%s%s",&r,&c,s[0]+1,s[1]+1);
    printf("%s",solve('L','R',c,w)&&solve('U','D',r,h)?"YES":"NO");
    return 0;
}


Measured memory_bytes: 3532
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
int ans;
int main() {
	int a, b, c, X;
	cin >> a >> b >> c >> X;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				int x, y, z;
				x = i * 500;
				y = j * 100;
				z = k * 50;
				if (x + y + z == X)ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

	int l[10], v[2];
	double x;
	
/*	while(scanf("%d", &l[0]) != EOF){
		for(int i=1; i<10; i++){
			scanf("%d", &l[i]);
			l[i] += l[i-1];
		}
		scanf("%d, %d", &v[0], &v[1]);
*/
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,"
			,&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v[0],&v[1]) != EOF){

		for(int i=1; i<10; i++){
			l[i] += l[i-1];
		}

//		for(int i=0; i<10; i++)
//			cout << l[i] << " ";
//		cout << v[0] << " " << v[1] << endl;
		
		x = (double)l[9] * v[0] / (v[0] + v[1]);
//cout << x << " " << endl;
		for(int i=0; i<10; i++){
			if(x <= (double)l[i]){
				cout << i+1 << endl;
				break;
			}
		}
	}

	return 0;

}

Measured memory_bytes: 1208
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
class UnionFind {
    vector<int> p;//p[i]はiの属する組織
public:
    UnionFind(int n){
        p = vector<int>(n);
        for(int i = 0; i < n; i++){
            p[i] = i;
        }
        return;
    }

    void printState() {
        if (DEBUG) {
            cout << "---" << endl;
            for (int i = 0; i < p.size(); i++) {
                printf("%dの親は%d\n", i, p[i]);
            }
            cout << "---" << endl;
        }
    }

/* xの属する集合を返す */
    int find(int x) {
        if (p[x] == x) return x;
        return p[x] = find(p[x]);
    }

/* yにxを統合する */
    void unite(int x, int y) {
        p[find(x)] = p[find(y)];
    }

/* xとyが属する集合が同じかを判定する */
    bool same(int x, int y) {
        return find(x) == find(y);
    }

};


int main() {
    int N,M;
    cin >> N >> M;
    vector<pair<int,int> > ev;
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        ev.emplace_back(a,b);
    }
    int ans = 0;
    rep(i,0,M){
        UnionFind uf(N);
        rep(j,0,ev.size()){
            if(i != j){
                uf.unite(ev[j].first,ev[j].second);
            }
        }

        rep(j,1,N){
            if(!uf.same(0,j)){
                ans++;
                break;
            }
        }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int[] states;
	static int[] belongs;
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		states = new int[n];
		belongs = new int[n];
		for (int i = 0; i < n; i++) {
			belongs[i] = i;
			states[i] = 0;
		}
		for(int i = 0; i < m; i++) {
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			int d = sc.nextInt();
			if(!merge(l,r,d)) {//マージに成功するかどうか
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
	public static boolean merge(int l, int r, int d) {
		int lb = updateBelongs(l);//親の所属をだす
		int rb = updateBelongs(r);
		if(lb == rb) {//２点の親同士の所属が同じか
			return states[r] == states[l] + d;//同じなら満たしているかどうか
		} else {
			belongs[rb] = lb;//所属が違うなら右の人の親の所属を左の親と合わせる
			states[rb] = states[l] + d - states[r];//右の人の親の距離を変える
			return true;
		}
	}
	public static int updateBelongs(int a) {
		if(a == belongs[a]) {//aさんの所属番号がaかどうか(所属番号の親かどうか
			return a;
		} else {
			int temp = belongs[a];
			belongs[a] = updateBelongs(belongs[a]);//親を辿って親の所属番号にする
			states[a] += states[temp];//距離を更新
			return belongs[a];
		}
	}
}

Measured memory_bytes: 150672
#include <iostream>
#include <string>
#include <list>
#include <algorithm>

int main() {

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

	int n;
	std::cin >> n;
	std::list<int> l;

	for (int i = 0; i < n; i++) {
		std::string op;
		int x;
		std::cin >> op;
		if(op == "insert" || op == "delete")
			std::cin >> x;
			
		if (op == "insert")
			l.push_front(x);
		else if (op == "deleteFirst")
			l.pop_front();
		else if (op == "deleteLast")
			l.pop_back();
		else if (op == "delete") {
			std::list<int>::iterator i = std::find(l.begin(), l.end(),x);
			if( i != l.end())
				l.erase(i);
		}
	}

	for (std::list<int>::iterator i = l.begin(); i != l.end(); ++i) {
		if (++i != l.end())
			std::cout << *(--i) << " ";
		else
			std::cout << *(--i) << std::endl;
	}


	return 0;
}

Measured memory_bytes: 34428
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)==3)
    {
        if(a+b>=c)
            printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
const int N = 1e5 + 5;
const db pi = acos(-1.0);
inline LL gcd(LL a, LL b) {return a % b == 0 ? b : gcd(b, a % b);}
inline LL read() {
    LL x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-')f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
struct poi {
    int x, y;
}a[N];
inline bool cmp(const poi &a, const poi &b) {
    return a.x < b.x;
}
int n, m;
int main() {
    n = read(); m = read();
    for (int i = 1; i <= n; ++i) {
        a[i].x = read(); a[i].y = read();
    }
    sort(a + 1, a + 1 + n, cmp);
    LL ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (m >= a[i].y) {
            m -= a[i].y;
            ans += 1LL * a[i].x * a[i].y;
        }
        else {
            ans += 1LL * a[i].x * m;
            break;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <vector>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <set>
#include <string>
#include <utility>
#include <cmath>
#include <limits>
#include <iomanip>

typedef long long ll;
typedef unsigned long long ull;
#define sq(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
#define iter(i, j) for(auto i = j.begin(); i != j.end(); ++i)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end()  
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IMAX std::numeric_limits<int>::max()
#define IMIN std::numeric_limits<int>::min()
using namespace std;
template <class T> T count_multiples_of(T x, T upper_bound, T lower_bound)
{
    T ans = upper_bound / x - lower_bound / x;
    if(lower_bound % x == 0) return ans + 1;
    else return ans;
}
ll C(ll n, ll k) 
{ 
    ll C[n + 1][k + 1]; 
    ll i, j; 
    for(i = 0; i <= n; i++) 
    { 
        for(j = 0; j <= min(i, k); j++) 
        { 
            if (j == 0 || j == i) 
                C[i][j] = 1; 
            else
                C[i][j] = C[i - 1][j - 1] + 
                          C[i - 1][j]; 
        } 
    } 
    return C[n][k]; 
}
template <class T> void display_1D_vector(vector<T> v)
{
    ll n = v.size();
    rep(i, n) cout << v[i] << " ";
    cout << endl;
}

template <class T> void display_2D_vector(vector< vector<T> > v)
{
    ll n = v.size(), m = v[0].size();
    rep(i, n)
    {   
        rep(j, m) cout << v[i][j] << " ";
        cout << endl;
    }
}
int fast_exp(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
    }
    return res;
}

int main()
{
    fast_io
    //file_io
    int h, n; cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vector<vi> dp(n + 1, vi(h + 1));
    rep(i, n + 1) dp[i][0] = 0;
    reps(i, 1, h + 1) dp[0][i] = 1000000000;
    reps(i, 1, n + 1)
        reps(j, 1, h + 1)
            dp[i][j] = min(dp[i - 1][j], min(dp[i - 1][max(j - a[i - 1], 0)] + b[i - 1], dp[i][max(j - a[i - 1], 0)] + b[i - 1]));
    cout << dp[n][h];
    return 0;
}


Measured memory_bytes: 39424
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int arr[105],arr2[105];
int val2,val1;
int32_t main() {

    fast
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin>>arr[i]>>arr2[i];
    }
    for(int i=0;i<n-2;i++){
        if(arr[i]==arr2[i] && arr[i+1]==arr2[i+1] && arr[i+2]==arr2[i+2]){
            cout<<"Yes";
            return 0;
        }

    }
    cout<<"No";


    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

 int main(){

  ll n,a,b;
  cin>>n>>a>>b;

   if(a > b){
      cout<<"0"<<endl;
      return 0; }
   else if( n < 2 && a != b){
      cout<<"0"<<endl;
   return  0 ;}

  ll maxi_sum = b*(n-1)+a;
  ll mini_sum = a*(n-1)+b;

  cout<<maxi_sum-mini_sum+1<<endl;



 return 0;
 }

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

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

    a = new int[n];

    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    int sum = 0;
    int dif = 0;
    for(int i = 0; i < n; i++){
        if(i&1) dif += a[i];
        else sum += a[i];
    }

    cout << sum-dif << " ";



    for(int i = 1; i < n; i++){
        if(i&1){
            dif += a[i-1];
            sum -= a[i-1];

            cout << dif-sum << " ";
        }else{
            sum += a[i-1];
            dif -= a[i-1];

            cout << sum-dif << " ";
        }
    }

    cout << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define maxn 300005
#define mod 1000000007
 
 
int main()
{
    fastio;
    int x;
    cin>>x;
    int t1=360,t2=x;
    int an=1;
    for(int i=2;i<=sqrt(t2);i++)
    {
        int c1=0,c2=0;
        while(t2%i==0)
        {
            c1++;
            t2/=i;
        }
        while(t1%i==0)
        {
            t1/=i;
            c2++;
        }
        if(c1>c2)
        {
            an*=pow(i,c1-c2);
        }
    }
    if(t2>1)
    {
        if(t1%t2!=0)
        an*=t2;
    }
    cout<<(an*360)/x<<"\n";
    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	string s,t;
	cin>>n>>s>>t;
	
	string ans = "";
	for(int i=0;i<n;i++){
		ans += s[i];
		ans += t[i];
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3592
#!/usr/bin/env python3
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
x = int(input())
for i in range(x, 1000000):
    if is_prime(i) == True:
        break
print(i)

Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1));

ll scoring(vector<ll> t)
{
    ll ans = 0;
    vector<ll> last(d + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        last[t[i]] = i;

        for (int j = 1; j <= 26; j++)
        {
            ans -= c[j] * (i - last[j]);
        }
    }

    return ans;
}

int main(void)
{
    auto start = chrono::system_clock::now();
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<ll> BestT(d + 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    ll score = scoring(BestT);

    while (1)
    {
        vector<ll> t = BestT;

        int a, b;

        do
        {
            a = rand() % d + 1;
            b = rand() % d + 1;
        } while (a == b);

        swap(t[a], t[b]);

        if (scoring(t) > score)
        {
            BestT = t;
        }

        auto end = std::chrono::system_clock::now(); // 計測終了時刻を保存
        auto dur = end - start;                      // 要した時間を計算
        auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();

        if (msec >= 1950)
        {
            break;
        }
    }

    for (int i = 1; i <= d; i++)
    {
        printf("%lld\n", BestT[i]);
    }
}


Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <map>
#include <set>
#define FOR(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    n-=2;
    int first;
    cin >> first;
    vector<int> V(n);
    for(int i=0;i<n;i++){
        cin >> V[i];
    }
    int result;
    cin >> result;
    vector<ll> O(21);
    O[first] = 1;
    for(int i=0;i<n;i++){
        vector<ll> NO(21);
        for(int j=0;j<=20;j++){
            int ne1 = j + V[i];
            int ne2 = j - V[i];
            if(ne1 <= 20 && ne1 >= 0){
                NO[ne1] += O[j];
            }
            if(ne2 <= 20 && ne2 >= 0){
                NO[ne2] += O[j];
            }
        }
        O = NO;
    }
    cout << O[result] << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N,vector<int>(N,0));
    REP(i,M){ 
        int a,b; cin >> a >> b; a--;b--;
        G[a][b] = 1;
        G[b][a] = 1;
    }

    vector<int> way(N);
    REP(i,N) way[i] = i;

    int ans = 0;
    do{
        if(way[0] == 0){
            bool ok = true;
            REP(i,N-1){
                if(G[way[i]][way[i+1]]==0) ok = false;
            }
            if(ok) ans ++;
        }
    }while(next_permutation(ALL(way)));
    cout << ans << endl;
    return 0;
}

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

int main(){
	string s, ans;
	ans = string();
	getline(cin, s);
	int l = s.length();
	for (int i = 0; i < l; ++i){
		char ch = s[i];
		if (islower(ch)) ans += toupper(ch);
		else if (isupper(ch)) ans += tolower(ch);
		else ans += ch;
	}
	cout << ans << endl;
	return 0;
}

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

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

using namespace std;

int main()
{
	char S[1000];
	unsigned long long K;

	scanf("%s", S);
	cin >> K;

	for (unsigned long long ull = 0; ull < K; ull++)
	{
		if (S[ull] == '1')
		{
			continue;
		}
		else
		{
			cout << S[ull] << endl;
			return 0;
		}
	}

	cout << "1" << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first 
#define s second 
using namespace std;
const int mod=1e9+7;
int logi(int n){int p=0;while(n/2){n=n/2;p++;}return p;}
int poww(int x,int y){int pro=1;while(y){if(y&1)pro=((pro%mod)*(x%mod)%mod);y=y>>1;x=((x%mod)*(x%mod)%mod);}return pro;}
int poww2(int x,int y){int pro=1;while(y){if(y&1)pro=pro*x;y=y>>1;x=x*x;}return pro;}
bool isprime(int n){ if(n==1) return false; for(int i=2;i<=sqrt(n);i++)	if(n%i==0) return false; return true;}
vector<vector<int>> adj(2e5);
vi visited(2e5,0);
/*

*/

void solve()
{
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(v[i]!=v[j]&&v[j]!=v[k]&&v[k]!=v[i])
				{
					if(v[i]+v[j]>v[k]) cnt++;
				}
			}
		}
	}
	cout<<cnt;
}
int32_t main() {
/*#ifndef ONLINE_JUDGE
	//for getting input from input.txt
	freopen("input.txt","r",stdin);
	//for writing output to output.txt
	freopen("output.txt","w",stdout);
#endif*/
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 9424
#include<iostream>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=1e5+5;
int main()
{
	int n;
	scanf("%d",&n);
	int i,j;
	int a[maxn],dp[maxn];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}	
	//int cnt=1;
	int ans=0,res=0;
 	for(i=0;i<n;i++){
 		 dp[i+1]=INF;
        if(i>=1&&a[i-1]>a[i])
			ans=i;
        else 
			dp[i+1] = dp[ans]+1;
        if(i>=1&&a[i-1]<a[i])
			 res=i;
        else 
		dp[i+1]=min(dp[i+1],dp[res]+1); 
    }
	printf("%d\n",dp[n]);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;

int H, W;
vs S;
vvb visited;
ll black = 0, white = 0;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};

void dfs(int y, int x, char color)
{
    visited[y][x] = true;
    if(color == '#') black++;
    else white++;

    REP(i, 4)
    {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(0 <= ny && ny < H && 0 <= nx && nx < W && !visited[ny][nx] && S[ny][nx] != color)
        {
            dfs(ny, nx, S[ny][nx]);
        }
    }
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> H >> W;
    S.resize(H); REP(i, H) cin >> S[i];
    visited.resize(H, vb(W, false));

    ll ans = 0;
    REP(i, H)
    {
        REP(j, W)
        {
            black = white = 0;
            if(!visited[i][j] && S[i][j] == '#') dfs(i, j, '#');
            ans += black * white;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#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 FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> vec(1001001,{-1,-1});
    rep(i,n) {
        int a;
        cin>>a;
        vec[a].first=i;
    }
    rep(i,m) {
        int b;
        cin>>b;
        vec[b].second=i;
    }
    
    ll ans=1;
    set<int> as,bs;
    for(int i=n*m; i>0; i--) {
        int a,b;
        tie(a,b)=vec[i];
        
        if(a==-1 && b==-1) {
            ll total=n*m-i;
            ll now=(ll)(sz(as)*sz(bs))-total;
            ans=(ans*now)%MOD;
        }
        else if(a==-1) {
            ll now=sz(as);
            ans=(ans*now)%MOD;
            bs.insert(b);
        }
        else if(b==-1) {
            ll now=sz(bs);
            ans=(ans*now)%MOD;
            as.insert(a);
        }
        else {
            as.insert(a);
            bs.insert(b);
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8192
# -*- coding: utf-8 -*-
# D - We Like AGC
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
N = int(readline())
# dp[i][j][k][l] := i桁目 3文字前 ２文字前 1文字前
dp = [[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
dp[0][3][3][3] = 1

for i in range(N):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                if dp[i][j][k][l] == 0:
                    continue
                for a in range(4):
                    if k == 0 and l == 1 and a == 2:
                        continue
                    if k == 1 and l == 0 and a == 2:
                        continue
                    if k == 0 and l == 2 and a == 1:
                        continue
                    if j == 0 and l == 1 and a == 2:
                        continue
                    if j == 0 and k == 1 and a == 2:
                        continue
                    dp[i+1][k][l][a] += dp[i][j][k][l] 
                    dp[i+1][k][l][a] %= MOD
ans = 0

for j in range(4):
    for k in range(4):
        for l in range(4):  
            ans += dp[N][j][k][l]
            ans %= MOD
print(ans)       

Measured memory_bytes: 74716
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)

int main() {
	int A, B;
	cin >> A >> B;

	if (B % A == 0) {
		cout << A + B << endl;
	}
	else {
		cout << B - A << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1001001001;
const double EPS = 1e-10;

struct Edge { ll from_x, from_y, to_x, to_y, cost; };
using P_Graph = map<P, vector<Edge>>;

int n;
vector<P> xy,yx;
P_Graph g;

template<typename T = ll>
T prim(P_Graph &g) {
    using TP = pair<T, P>;

    T res = 0;
    map<P, bool> used;
    priority_queue<TP, vector<TP>, greater<TP>> pq;
    pq.push(TP(0, P(xy[0].first, xy[0].second)));
    while(!pq.empty()) {
        auto t = pq.top(); pq.pop();
        auto cost = t.first, v = t.second;
        if(used[v]) continue;
        used[v] = true;
        res += cost;
        for(auto e : g[v]){
            pq.push(TP(e.cost, P(e.to_x, e.to_y)));
        }
    }
    return res;
}

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

    cin>>n;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        xy.emplace_back(P(x,y));
        yx.emplace_back(P(y,x));
    }
    sort(xy.begin(),xy.end());
    sort(yx.begin(),yx.end());
    for(int i=1;i<n;i++){
        g[xy[i-1]].emplace_back((Edge){xy[i-1].first,xy[i-1].second,xy[i].first,xy[i].second,xy[i].first-xy[i-1].first});
        g[xy[i]].emplace_back((Edge){xy[i].first,xy[i].second,xy[i-1].first,xy[i-1].second,xy[i].first-xy[i-1].first});
        g[P(yx[i-1].second,yx[i-1].first)].emplace_back((Edge){yx[i-1].second,yx[i-1].first,yx[i].second,yx[i].first,yx[i].first-yx[i-1].first});
        g[P(yx[i].second,yx[i].first)].emplace_back((Edge){yx[i].second,yx[i].first,yx[i-1].second,yx[i-1].first,yx[i].first-yx[i-1].first});
    }
    ll ans=prim(g);
    cout<<ans<<endl;
}

Measured memory_bytes: 43612
N, Q = [int(i) for i in input().split()]
S = input()
lrList = [[int(i) for i in input().split()] for _ in range(Q)]

ACNum = 0
ACList = [0]
for i in range(1, len(S)):
    if S[i - 1] == "A" and S[i] == "C":
        ACNum += 1
    ACList.append(ACNum)

for q in range(Q):
    l, r = lrList[q][0], lrList[q][1]
    ans = ACList[r - 1] - ACList[l - 1]
    print(ans)


Measured memory_bytes: 24472
#include<stdio.h>

int main(){
    int h,w;
    int H,W,i;
    
    for(i=1;;){
        scanf("%d %d",&h,&w);
        if(h+w==0)break;
        for(H=1;H<=h;H++){
            if(H%2==0){
                for(W=1;W<=w;W++){
                    if(W%2==0)
                    printf("#");
                    else printf(".");
                    
                }
                printf("\n");
                
            }
            else {
                for(W=1;W<=w;W++){
                    if(W%2==1)
                    printf("#");
                    else printf(".");
                    
                }
                printf("\n");
                
            }
        }printf("\n");
    }return 0;
}


Measured memory_bytes: 2108
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] a = new int[n];
        int before = 0;
        int count = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int color = sc.nextInt();
            
            if (color == before) {
                count++;
            } else {
                sum += (count + 1) / 2;
                count = 0;
            }
            before = color;
        }
        sum += (count + 1) / 2;
        so.println(sum);
    }
}


Measured memory_bytes: 24916
package main

import (
	"fmt"
	"math"
)

func main() {
	var a,b float64
	fmt.Scan(&a,&b)
	
	for i := 13.0; i <= 1000.0; i++ {
		taxa := math.Trunc(i * 0.08)
		taxb := math.Trunc(i * 0.1)
		if taxa == a && taxb == b {
			fmt.Println(i)
			return
		}
	}
	fmt.Println("-1")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d,e,k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    if(e-a>k)cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n, q; cin >> n >> q;
  vector<vector<ll>> adj(n+1);
  vector<bool> visited(n+1, false);
  vector<ll> cnt(n+1, 0);
  rep(i, n-1) {
    ll a, b; cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  rep(i, q) {
    ll pi, xi; cin >> pi >> xi;
    cnt[pi] += xi;
  }

  queue<ll> qn, qc;
  qn.push(1); qc.push(cnt[1]);
  visited[1] = true;

  while (!qn.empty()) {
    int i = qn.front(); qn.pop();
    int c = qc.front(); qc.pop();

    for (int j = 0; j < adj[i].size(); j++) {
      int k = adj[i][j];
      if (visited[k]) continue;

      // debug2(i, k);

      visited[k] = true;
      cnt[k] += c;
      qn.push(k);
      qc.push(cnt[k]);
    }
  }

  cout << cnt[1];
  for (int i = 2; i <= n; i++)
    cout << " " << cnt[i];
  cout << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 19440
#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int x, ans=0;
  for(int i=0; i<N; i++){
    cin >> x;
    ans += 2 * min(x, K-x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split(" "))
b_k = list(map(int, format(k+1, "b").zfill(40)[::-1]))
target = [ 0 for _ in range(40) ]
numbers = list(map(int, input().split(" ")))
for i in numbers:
  for idx, v in enumerate(format(i, "b")[::-1]):
    if v=="1":
      target[idx] += 1
best = [ 1 if n > 2*target[i] else 0 for i in range(40) ]

maxr = sum(numbers)
for i in range(len(b_k)):
  if b_k[i] == 1:
    maxr = max(maxr, sum((2**idx)*(t if r==0 else n-t) for idx, (t, r) in enumerate(zip(target, best[:i] + [0] + b_k[i+1:]))))
print(maxr)

Measured memory_bytes: 14708
<?php
list($S,$T)=sscanf(fgets(STDIN),"%s %s");
list($A,$B)=sscanf(fgets(STDIN),"%d %d");
list($U)=sscanf(fgets(STDIN),"%s");
if($S == $U){
    printf("%d %d",$A-1,$B);
}else{
    printf("%d %d",$A,$B-1);
}

Measured memory_bytes: 3828
#include <vector>
    #include <list>
    #include <map>
    #include <set>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <bitset>
    #include <algorithm>
    #include <functional>
    #include <numeric>
    #include <utility>
    #include <sstream>
    #include <iostream>
    #include <iomanip>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <string>
    #include <climits>
    #include <tuple>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> P;
    typedef tuple<int,int,int,int> T;
     
     
     
     
    int bit[100003],n;
    int sum(int i){
        int s=-1;
        while(i>0){
            s=max(bit[i],s);
            i-=i&-i;
        }
        return s;
    }
    void add(int i,int x){
        while(i<=n){
            bit[i]=max(bit[i],x);
            i+=i&-i;
        }
    }
    int main(){
        int a,b;
        cin>>a>>b;
        int x[100001];
        for(int i=0;i<a;i++){
            cin>>x[i];
        }
        int res=1;
        a=a-b;
        if(a>0)
        res+=(a-1)/(b-1)+1;
        cout<<res<<endl;

    }


Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

""" Input
S = input().rstrip()
N = int(input())
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

N, K = map(int, input().split())
people = [0] * N

for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    A = list(map(lambda x: x - 1, A))
    for a in A:
        people[a] += 1

print(people.count(0))


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

 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      String S=sc.next();
      int N=S.length();
      String anslst[]=new String[N];
      ArrayList<Integer[]> rlc=new ArrayList<>();

      for(int i=0;i<N;i++){
          anslst[i]="0";
      }
      for(int i=0;i<N;i++){
          Integer tmp[]=new Integer[2];
          int j=0;
          
          while(i+j<N && S.charAt(i)==S.charAt(i+j)){
              j++;
          }
          tmp[0]=i;
          tmp[1]=j;
          rlc.add(tmp);
          i+=j-1;
      }

      for(int i=0;i<rlc.size();i+=2){
          Integer[] r=rlc.get(i);
          Integer[] l=rlc.get(i+1);

          anslst[l[0]]=String.valueOf(r[1]/2+(l[1]+1)/2);
          anslst[l[0]-1]=String.valueOf((r[1]+1)/2+l[1]/2);
      }
      out.println(String.join(" ", anslst));
      
      out.close();
   }

   public static int binarySearch(Integer[] a,int x)
   {
       int right=a.length-1;
       int left=0;

       while(right-left>0){
           int center=(right+left)/2;

           if(x>a[center]){
               left=center+1;
           }else{
               right=center; 
           }
       }
       return right;
   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 34984
import sys
sys.setrecursionlimit(10**5)

N = int(input())

def rec(N, m) :
    if N < 6 :
        return N + m
    
    
    a, b = float('inf'), float('inf')
    six = 6
    while six * 6 <= N :
        six *= 6
    if N >= six :
        a = rec(N - six, m + 1)
    
    nine = 9
    while nine * 9 <= N :
        nine *= 9
    if N >= nine :
        b = rec(N - nine, m + 1)
    
    return min(a, b)
        
print(rec(N, 0))

Measured memory_bytes: 49880
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;


void solve(std::string S, std::string T){
    int res = 0;
    // if(S.size() - T.size() == 0) { 
    //     REP(i, S.size()) { 
    //         if(S[i] == T[i]) { 
    //             res++;
    //         }
    //     }
    //     cout << res << endl;
    // }

    REP(i, S.size()-T.size()+1) { 
        int res_r = 0;
        REP(j, T.size()) { 
            if(S[i+j] == T[j]) { 
                res_r += 1;
            }
        }
        if(res_r > res) { 
            res = res_r;
        }
    }
    cout << T.size() - res << endl;
}

// 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)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3560