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

int n,w;
int m1[40];
int main() {
    scanf("%d", &n);
    scanf("%d", &w);
    for(int i = 1; i <= n;i++)m1[i]=i;
    for(int i = 0; i < w; i++){
        int a,b;
        scanf("%d,%d", &a, &b);
        int temp = m1[b];
        m1[b] = m1[a];
        m1[a] = temp;
    }
    for(int i = 1; i <= n;i++)printf("%d\n", m1[i]);
}

Measured memory_bytes: 3156
#include<stdio.h>

main()
{
	int n;
	int resident[5][4][11]={};
	
	scanf("%d",&n);
	
	int i;
	int b,f,r,v;
	
	for(i=0;i<n;i++){
		scanf(" %d %d %d %d",&b,&f,&r,&v);
		resident[b][f][r] += v;
		if(resident[b][f][r]>9){
			resident[b][f][r]=9;
		} else if(resident[b][f][r]<0){
			resident[b][f][r]=0;
		}
	}
	

	int h,j,k;
	int s;
	
	for(h=1;h<=4;h++){
		for(j=1;j<=3;j++){
			for(k=1;k<=10;k++){
				printf(" %d",resident[h][j][k]);
				if(k==10){
					printf("\n");
				}
			}
		}
		if(h<4){
			for(s=0;s<20;s++){
				printf("#");
			}
			printf("\n");
		}
	}
	
	return 0;
}
	
	

Measured memory_bytes: 600
## C - City Savers
N = int(input()) + 1
A = list(map(int,input().split()))
B = list(map(int,input().split())) + [0]
win = 0
remain = 0
for n in range(N):
    if A[n] < remain:
        win += A[n]
        A[n] = 0
    else:
        win += remain
        A[n] -= remain

    if A[n] < B[n]:
        win += A[n]
        remain = B[n] - A[n]
    else:
        win += B[n]
        remain = 0
print(win)

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli h,w;
	cin>>h>>w;

	lli c[10][10];
	REP(i,0,10)REP(j,0,10)cin>>c[i][j];

	REP(k,0,10)REP(i,0,10)REP(j,0,10)c[i][j] = min(c[i][j],c[i][k]+c[k][j]);

	lli ans = 0;

	REP(i,0,h)REP(j,0,w){
		lli a;
		cin>>a;
		if(a!=-1)ans += c[a][1];
	}

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

Measured memory_bytes: 256
N = int(input())
t, x, y = [], [], []

for i in range(N) :
    _t, _x, _y = map(int, input().split())
    t.append(_t)
    x.append(_x)
    y.append(_y)
    

cur_x = 0
cur_y = 0
cur_time = 0 
flg_possible = True

for i in range(N) :
    min_dist = abs(x[i] - cur_x) + abs(y[i] - cur_y)

    if min_dist > t[i] or not((t[i] - cur_time) % 2 == min_dist % 2):
        print("No")
        flg_possible = False
        break
    else :
        cur_x, cur_y, cur_time = x[i], y[i], t[i]
        
if flg_possible == True :
    print("Yes")
        
        

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

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

	//初期値は大きい値
	int ans = S.size();

	//iは最初に使う色（0 or 1）
	for (int i = 0; i < 2; i++)
	{
		// iを最初に使う時に変えなければならないタイルの数
		int cnt = 0;

		for (int j = 0; j < S.size(); j++)
		{
			// (char)(0 + '0') -> '0';
			// (char)(1 + '0') -> '1';
			if ((j % 2 == 0) ^ (S[j] != (char)(i + '0'))) cnt++;
		}

		ans = min(ans, cnt);
	}

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}
char arr[26];
int main() {
  string s; cin >> s;
  for(char c:s) {
    arr[c-'a']++;
  }
  rep(i, 26) {
    if(arr[i]%2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e9

int a[100001][3] = {};
int b[100001][3] = {};

int main()
{
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	b[0][0] = a[0][0];
	b[0][1] = a[0][1];
	b[0][2] = a[0][2];
	REP(i, 1, n) {
		rep(j, 3) {
			rep(k, 3) {
				if (j != k) {
					b[i][j] = max(b[i][j], b[i - 1][k] + a[i][j]);
				}
			}
		}
	}
	int mx = 0;
	rep(i, 3) mx = max(mx, b[n - 1][i]);
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		int taps = 1;
		int con = 0;
		while (taps < line[1]) {
			taps = taps + line[0] - 1;
			con++;
		}

		System.out.println(con);
	}
}


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

int main() {
  int N, X, T, A;
  cin >> N >> X >> T;
  
  if (N % X > 0){
    A = N / X + 1;
    cin >> A;
  }
  else if(N % X == 0){
    A = N / X;
    cin >> A;
  }
  cout << A*T << endl;
}




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

int main(){
    int n,min,ans;
    cin >> n;
    int R[n];
    for ( int i = 0; i < n; i++)cin >> R[i];
    min = R[0];
    ans = R[1]-R[0];
    for ( int i = 1; i < n; i++){
        if( min > R[i] ){
            min = R[i];
        }else if( ans < R[i]-min){
            ans = R[i]-min;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1940
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())),reverse=True)
ab=[0 for _ in range(N)]
bc=[0 for _ in range(N)]

aind=0
cind=0
for i in range(N):
    b1=B[i]
    while aind<N and A[aind]<b1:
        aind+=1
    ab[i]=aind

    b2=B[-i-1]
    while cind<N and b2 < C[cind]:
        cind+=1
    bc[-i-1]=cind
print(sum([ab[i]*bc[i] for i in range(N)]))



Measured memory_bytes: 112996
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;

int n;
int x[110], y[110], h[110];

int main(){
	cin >> n;
	for (int i = 0; i < n; i++)cin >> x[i] >> y[i] >> h[i];
	for (int i = 0; i < n; i++)if (h[i] != 0)swap(x[i], x[0]), swap(y[i], y[0]), swap(h[i], h[0]);
	for (int cx = 0; cx <= 100; cx++){
		for (int cy = 0; cy <= 100; cy++){
			bool flag = true;
			int H = h[0] + abs(x[0] - cx) + abs(y[0] - cy);
			for (int i = 0; i < n; i++)if (h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0))flag = false;
			if (flag){
				printf("%d %d %d\n", cx, cy, H);
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 220
// 44

using namespace std;

const int MAXN = 18;

int arr[1 << MAXN];
int sol[1 << MAXN];

vector <int> bit;
int mx1, mx2;

void bkt(int lvl, int pos, int sz) {
    if(lvl == sz) {
        if(mx1 < arr[pos]) {
            mx2 = mx1;
            mx1 = arr[pos];
        }
        else if(mx2 < arr[pos]) {
            mx2 = arr[pos];
        }
    }
    else {
        bkt(lvl + 1, pos | bit[lvl], sz);
        bkt(lvl + 1, pos, sz);
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 0; i < (1 << n); i++) {
        cin >> arr[i];
    }
    for(int k = 1; k < (1 << n); k++) {
        int aux = k;
        bit.clear();
        while(aux > 0) {
            bit.push_back(lsb(aux));
            aux -= lsb(aux);
        }
        int sz = bit.size();
        mx1 = mx2 = -1e9;
        bkt(0, 0, sz);
        sol[k] = max(mx1 + mx2, sol[k - 1]);
        cout << sol[k] << "\n";
    }
    //cin.close();
    //cout.close();
    return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

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

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

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

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

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

    int n; std::cin >> n;
    int ans = 0;
    rep(i, n) {
        int a; std::cin >> a;
        ans += a-1;
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, a[N];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1 ; i <= n ; ++ i) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	int ans = 0;
	for(int i = 1 ; i <= n ; ++ i) {
		if(m - a[i] >= 0) {
			m -= a[i];
			++ ans;
		} else {
			a[i] = m, m = 0;
			break;
		}
	}
	if(m) -- ans;
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    int a[2* 100000];
    
    cin >> n;
    for(int i = 1; i < n; i++){
        cin >> a[i];
    }

    int bucket[2*100000] = {0};
    for(int i = 1; i < n; i++){
        bucket[a[i] - 1] = bucket[a[i] -1] + 1;
    }

    for(int i = 0; i< n; i++){
        cout << bucket[i] << endl;
    }

    return 0;
}

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

int a()
{
    std::string a;
    std::cin >> a;
    
    if(a[1] == 'B')
    {
        std::cout << "ARC" << std::endl;
    }
    else
    {
        std::cout << "ABC" << std::endl;
    }
    
    return 0;
}

int main(int argc, const char * argv[])
{
    a();
    return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <string>


using namespace std;

void KyoproResolve(istream& is, ostream& os)
{
	string S;
	is >> S;
	auto red = count(S.begin(), S.end(), '0');
	auto blue = count(S.begin(), S.end(), '1');
	os << red + blue - abs(red - blue) << '\n';
}


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

	KyoproResolve(cin, cout);
	return 0;
}


Measured memory_bytes: 512
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
#define MOD 1000000007
ll x, y, n, m, k, R, C;
ll a[MAXN], rsz[MAXN], csz[MAXN];
vector<ll> g;

struct shit {
    ll val;
    ll x;
    ll y;
};

bool operator <(const shit& x, const shit& y) {
    return x.val < y.val;
}

ll p[MAXN], s[MAXN], h[MAXN];

template<size_t N>
struct DSU {
    DSU() {
        for (int i = 0; i < N; i++) {
            color[i] = i;
            siz[i] = 1;
        }
    }

    int get(int v) {
        return (v == color[v]) ? v : (color[v] = get(color[v]));
    }

    void unite(int a, int b) {
        a = get(a);
        b = get(b);
        if (siz[a] > siz[b]) {
            swap(a, b);
        }
        if (a != b) {
            color[a] = b;
            siz[b] += siz[a];
            h[b] += h[a];
        }
    }

    int size(int x) {
        return siz[x];
    }

    int color[N];
    int siz[N];
};

DSU<MAXN> dsu;

vector<shit> f;
int main() {
    cin >> n >> R >> C;
    for (int i = 0; i < n; i++ ){
        ll x, y, z;
        cin >> x >> y >> z;
        f.push_back({z, x, y + R});
    }
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    for (int i = 1; i <= R+C; i++) {
        h[i] = 1;
    }

    ll ans = 0;
    for (auto v : f) {
        ll x = dsu.get(v.x);
        ll y = dsu.get(v.y);
        ll val = v.val;
        if (x == y) {
            if (h[x] == dsu.size(x)) {
                h[x]++;
                ans += val;
            }
        } else {
            if (h[x] + h[y] <= dsu.size(x) + dsu.size(y) + 1) {
                dsu.unite(x, y);
                ans += val;
            }
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int rev = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == 'E') rev++;
    }
    int min = rev;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] == 'W') rev++;
        if (s[i] == 'E') rev--;
        min = (min > rev) ? rev : min;
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3908
n, m, c = map(int, input().split())
B_list = list(map(int, input().split()))
A_list = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    temp_n = 0
    for j in range(m):
        temp_n += A_list[i][j] * B_list[j]
    if temp_n + c > 0:
        ans += 1

print(ans)

Measured memory_bytes: 38704
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
using ll = long long;

#define N 100010

int main() {
    int n, M;
    cin >> n >> M;
    int ans;
    

    //高さの入力
    vector<int64_t> h(N);
    vector<int64_t> ma(N);
    for (int i = 1; i <= n; i++) {
        cin >> h.at(i);
    }
    
    // 接続先の高さの最大値を求める
    for(ll i=0; i<M; i++){
        ll a,b;
        cin >> a >> b;
        ma[a] = max(ma[a], h[b]);
        ma[b] = max(ma[b], h[a]);
    }

    for(ll i=1; i<=n; i++){
        ans += h[i] > ma[i];
    }

    cout << ans << endl; 

}


Measured memory_bytes: 4828
n,m=map(int,input().split())

lis=[]

for i in range(m):
    nb=int(input())
    lis2=list(map(int,input().split()))
    for j in range(nb):
        if lis2[j] not in lis:
            lis.append(lis2[j])


ans=n-len(lis)
print(ans)


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

int main()
{
	int N;
	cin >> N;
	for (int i = 1; i <= N; ++i)
	{
		int temp = i;
		for (int j = 2; j <= i; ++j)
		{
			while(temp % j == 0)
			{
				A[j]++;
				temp /= j;
			}
		}
	}
	
	int cnt2 = 0, cnt4 = 0, cnt14 = 0, cnt24 = 0, cnt74 = 0;
	rep(i,N+1)
	{
		if (A[i] >= 2) cnt2++;
		if (A[i] >= 4) cnt4++;
		if (A[i] >= 14) cnt14++;
		if (A[i] >= 24) cnt24++;
		if (A[i] >= 74) cnt74++;
	}
	//cout << cnt2 << " " << cnt4 << " " << cnt14 << " " << cnt24 << " " << cnt74 << " " << endl;
	int ans = 0;
	ans += cnt74;
	ans += (cnt2-cnt24) * cnt24 + cnt24 * (cnt24-1);
	ans += (cnt4-cnt14) * cnt14 + cnt14 * (cnt14-1);
	ans += (cnt2-cnt4) * cnt4 * (cnt4-1) / 2 + cnt4 * (cnt4-1) * (cnt4-2) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n,m;cin>>n>>m;ll r;ll b,c;
    map <ll,ll> omp;ll sum=0;
    for(ll i=0;i<n;++i)
    {
        cin>>r;sum+=r;
        auto it=omp.find(r);
        if(it!=omp.end()){it->second++;}
        else
        {
            omp.insert(make_pair(r,1));
        }
    }
    //map <ll,ll> omp(mp.begin(),mp.end());
    for(ll i=0;i<m;++i)
    {
        cin>>b>>c;
        for(auto it=omp.begin();it!=omp.end();++it)
        {
            if(it->first>=c){break;}
            ll ran=min(b,it->second);
            sum+=((c-it->first)*ran);
            auto it1=omp.find(c);
            if(it1!=omp.end()){it1->second+=ran;}
            else{omp.insert(make_pair(c,ran));}
            b=b-ran;
            it->second=it->second-ran;
            if(it->second==0){omp.erase(it->first);}
            if(b<=0){break;}
        }
    }
    cout<<sum;
}

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

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// ***************************************

int main(void) {

	int N;
	cin >> N;

	vector<vector<ll>> dp(N + 1, vector<ll>(3, 0));
	REP(i, 3) {
		int x;
		cin >> x;
		dp[0][i] = 0;
		dp[1][i] = x;
	}

	FOR(i, 2, N + 1) {
		int x;
		cin >> x;
		dp[i][0] = x + max({dp[i - 2][0], dp[i - 1][1], dp[i - 1][2] });
		cin >> x;
		dp[i][1] = x + max({dp[i - 2][1], dp[i - 1][0], dp[i - 1][2] });
		cin >> x;
		dp[i][2] = x + max({ dp[i - 2][2], dp[i - 1][0], dp[i - 1][1] });
	}

	cout << max({ dp[N][0], dp[N][1], dp[N][2] }) << endl;


	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,n,z;
  long M,A;
  double m,a;
  cin >> N;
  n=0;
  M=1;
  m=0;
  z=0;
  while(n<N){
    cin >> A;
    if(A==0){
      n=N;
      cout << 0;
      z=1;
    }
    M = M*A;
    a = log10(A);
    m = m+a;
    n++;
  }
  if(z==0){
    if((m>18)||(M>1000000000000000000)){
      cout << -1;
    }
    else{
      cout << M;
    }
  }
}

Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			int N = cin.nextInt();
			if(N==0){
				break;
			}
			for(int i = 0;i<N;i++){
				System.out.println(c(cin.nextInt(),cin.nextInt(),cin.nextInt()));
			}
		}
	}
	static String c(int m,int e,int j){
		if(m==100||e==100||j==100){
			return "A";
		}
		if(m+e>=180){
			return "A";
		}
		if(m+e+j>=240){
			return "A";
		}
		if(m+e+j>=210){
			return "B";
		}
		if(m+e+j>=150&&(m>=80||e>=80)){
			return "B";
		}
		return "C";
	}
	
}

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

using namespace std;

map<int, int> cntsum;
vector<int> t[200001];
int cnt[200001];

void count(int r, int inc) {
    inc += cntsum[r];
    for(int i = 0; i < t[r].size() ; i++)
    {
        count(t[r][i], inc);
    }
    cnt[r] += inc;
}

int main(){
    int n, q;
    cin >> n >> q;

    int a, b;
    rep(i,n-1) {
        cin >> a >> b;
        t[a].push_back(b);
    }
    
    rep(i, q) {
        cin >> a >> b;
        cntsum[a] += b;
    }
  
    for( auto i = cntsum.begin(); i != cntsum.end() ; ++i ) {
//         cout << i->first << " " << i->second << "\n";
    }   
    
    count(1, 0);
    
//    count(a,b,parents);
    
    rep(i, n) {
        cout << cnt[i+1] << endl;
    }
}


Measured memory_bytes: 39168
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10, mod = 1e9 + 7;

int add (int a, int b) {
    return ((a += b) >= mod) ? a - mod : a;
}

inline int mul (int a, int b) {
    return 1LL * a * b % mod;
}

inline int power (int a, int b) {
    int res = 1;

    for ( ; b > 0 ; b >>= 1, a = mul(a, a))
        if (b & 1) res = mul(res, a);
    return res;
}

int f[nax], n, deg[nax], sz[nax];

vector<int> a[nax];

void dfs_sz (int nod = 1, int pa = 0) {

    for (int i : a[nod]) {
        if (i == pa) continue;
        dfs_sz(i, nod);
        sz[nod] += sz[i];
    }
    ++ sz[nod];
}

int inv[nax], ans = 1;

int b[nax];

int main () {
    f[0] = 1;

    scanf("%d", &n);

    for (int i = 1 ; i < n; ++ i) {
        int u, v;
        scanf("%d %d", &u, &v);
        a[u].push_back(v);
        a[v].push_back(u);
    }

    int base = 1;
    for (int i = 1 ; i <= n; ++ i) {
        base = mul(base, i);
        inv[i] = power(i, mod - 2);
    }


    int ans = 1;

    dfs_sz();

    for (int i = 1 ; i <= n ; ++ i) {
        ans = mul(ans, sz[i]);
    }

    function<void (int, int) > dfs = [&] (int nod, int pa) -> void {

        b[nod] = mul(base, power(ans, mod - 2));

        for (int i : a[nod]) {
            if (i == pa) continue;
            int pre_sz_nod = sz[nod];
            int pre_sz_i = sz[i];
            int pre_ans = ans;
            ans = mul(ans, inv[pre_sz_nod]);
            ans = mul(ans, inv[pre_sz_i]);
            sz[nod] = n - sz[i];
            sz[i] = n;
            ans = mul(ans, sz[nod]);
            ans = mul(ans, sz[i]);
            dfs(i, nod);
            sz[nod] = pre_sz_nod;
            sz[i] = pre_sz_i;
            ans = pre_ans;
        }
    };

    dfs(1, 0);

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



}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 20980
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    int a[100],b[100],c[100],d[100];
    for(int i=0;i<N;i++)cin>>a[i]>>b[i];
    for(int i=0;i<M;i++)cin>>c[i]>>d[i];
    for(int i=0;i<N;i++){
        int num=-1,ansmin=2100000000;
        for(int j=0;j<M;j++){
            if(abs(a[i]-c[j])+abs(b[i]-d[j])<ansmin){
                num=j;
                ansmin=abs(a[i]-c[j])+abs(b[i]-d[j]);
            }
        }
        cout<<num+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>

#pragma comment(linker, "/STACK:336777216")  

using namespace std;

const int MAXN = 100000 + 10;
const int Epsilon = 1e-8;

int N, K;
int A[MAXN], B[MAXN], C[MAXN];
int Order[MAXN];

bool Cmp(const int& i, const int& j)
{
	return A[i] * B[j] < A[j] * B[i];
}

double a[MAXN], b[MAXN], c[MAXN], d[MAXN];

bool Cmp2(const int& i, const int& j)
{
	if (fabs(d[i] * b[j] - d[j] * b[i]) > Epsilon)
		return d[i] * b[j] < d[j] * b[i];
	return i > j;
}

long long ans;
int tmp[MAXN];

void Merge(int l, int m, int r)
{
	int i = l;
	int j = m + 1;
	int k = l;
	while (i <= m && j <= r)
	{
		if (Order[i] > Order[j])
        {
			tmp[k ++] = Order[j ++];
			ans += (long long) (m - i + 1);
		}
		else
			tmp[k ++] = Order[i ++];
    }
    while (i <= m) tmp[k ++] = Order[i ++];
    while (j <= r) tmp[k ++] = Order[j ++];
	for (int i = l; i <= r; i ++) Order[i] = tmp[i];
}

void Merge_sort(int l, int r)
{
	if (l < r)
	{
		int m = (l + r) >> 1;
		Merge_sort(l, m);
		Merge_sort(m + 1, r);
		Merge(l, m, r);
    }
}

double GetOptimalPosition()
{
	double Left = -1e10, Right = 1e10;
	sort(Order, Order + N, Cmp);
	for (int i = 0; i < N; i ++)
	{
		a[i] = A[Order[i]];
		b[i] = B[Order[i]];
		c[i] = C[Order[i]];
	}
	long long Tot = N * (N - 1) / 2;
	for (int rep = 0; rep < 200; rep ++)
	{
		double Mid = (Left + Right) * 0.5;
		for (int i = 0; i < N; i ++) d[i] = c[i] - a[i] * Mid;
		sort(Order, Order + N, Cmp2);

		ans = 0;
		Merge_sort(0, N - 1);

		if (Tot % 2 == 1)
		{
			if (ans <= Tot / 2)
				Left = Mid;
			else
				Right = Mid;
		}
		else
		{
			if (ans < Tot / 2)
				Left = Mid;
			else
				Right = Mid;
		}
	}
	return Left;
}

void Work()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i ++)
		scanf("%d%d%d", &A[i], &B[i], &C[i]);

	for (int i = 0; i < N; i ++)
		Order[i] = i;

	for (int i = 0; i < N; i ++)
		if (B[i] < 0)
		{
			A[i] *= -1;
			B[i] *= -1;
			C[i] *= -1;
		}
	double Ans1 = GetOptimalPosition();
	for (int i = 0; i < N; i ++)
		swap(A[i], B[i]);
	for (int i = 0; i < N; i ++)
		if (B[i] < 0)
		{
			A[i] *= -1;
			B[i] *= -1;
			C[i] *= -1;
		}
	double Ans2 = GetOptimalPosition();
	printf("%.10lf %.10lf\n", Ans1, Ans2);
}

int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 3456
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll m, d; cin >> m >> d;
    ll d1 = d / 10;
    ll res = 0;
    for(ll i = 1; i <= m; i++){
        for(ll j = 2; j <= d1; j++){
            for(ll k = 2; k < 10; k++){
                if(i == j * k && j * 10 + k <= d){
                    res++;
                }
            }
        }
    }
    cout << res;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std; long long N, A[87], CurrentMoney=1000; int main() 
{
  cin>>N;
  for(int i=1; i<=N; i++) cin>>A[i];
  for(int i=1; i<=N-1; i++) {
    long long Stocks=0; if(A[i]<A[i+1]) Stocks=CurrentMoney/A[i];CurrentMoney+=(A[i+1]-A[i])*Stocks;}
  cout<<CurrentMoney<<endl;}

Measured memory_bytes: 3608
require 'prime'

primes = Prime.each(50000).to_a

while (n = gets.to_i) > 0
    i = 0
    j = (primes.find_index{|x| x > n} || primes.size) - 1

    count = 0
    while
        s = primes[i] + primes[j]
        count += 1 if s == n
        break if i == j
        if s < n
            i += 1
        else
            j -= 1
        end
    end
    p count
end

Measured memory_bytes: 9708
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    S.erase(S.end()-1);
    if(S.length()%2)S.erase(S.end()-1);
    while(S.length()){
        if(S.substr(0,S.length()/2) == S.substr(S.length()/2,S.length()/2)){
            cout << S.length() << endl;
            return 0;
        }
        S.erase(S.end()-2,S.end());
    }
}

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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 )
	   a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
			return false;
	return true;
}

string s;

int main()
{
	cin >> s;
	if ( s == "MON" )
		cout << "6\n";
	if ( s == "TUE" )
		cout << "5\n";
	if ( s == "WED" )
		cout << "4\n";
	if ( s == "THU" )
		cout << "3\n";
	if ( s == "FRI" )
		cout << "2\n";
	if ( s == "SAT" )
		cout << "1\n";
	if ( s == "SUN" )
		cout << "7\n"; 
	return 0;
}


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

int n, m;
multiset< int > t;

int main()
{
	cin >> n;
	for(int i = 1, x; i <= n; ++i)
		scanf( "%d", &x ), t.insert(x);
	cin >> m;
	for(int i = 1, x; i <= m; ++i)
	{
		scanf( "%d", &x );
		if(t.find(x) != t.end()) t.erase(t.find(x));
		else 
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 9728
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, N, M);
    vector<vector<int>> G(N);

    vector<int> H(N);
    read(H);

    rep(i, 0, M) {
        var(int, a, b);
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int cnt = 0;
    rep(i, 0, N) {
        bool ok = true;
        for (int x : G[i]) {
            ok &= H[i] > H[x];
        }

        if (ok) ++cnt;
    }

    print(cnt);

    return 0;
}


Measured memory_bytes: 8712
n = int(input())
count = {}
for _ in range(n):
  type = input()
  count.setdefault(type, 0)
  count[type] += 1
for type in ['AC', 'WA', 'TLE', 'RE']:
  if type in count:
    print(type + ' x ' + str(count[type]))
  else:
    print(type + ' x 0')

Measured memory_bytes: 9136
N = int(input())
A = list(map(int, input().split()))
t = 1
a = 10 ** 18

if 0 in A:
    t = 0
else:
    for i in A:
        t *= i
        if t > a:
            break

if t > a:
    print("-1")
else:
    print(t)

Measured memory_bytes: 21420
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int N,A;
    cin >> N >> A;
    if(N%500 <= A) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  long int ans = 1;
  for (int i = 1; i <= N; i++) {
    ans *= i;
    ans %= (1000000000+7);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  string m;
  int n,k;
  cin>>n>>k;
  cin>>m;

  if (m[k-1]=='A'){
      m[k-1]='a';
  }
  else if(m[k-1]=='B'){
      m[k-1]='b';
  }
  else if(m[k]=='C'){
      m[k-1]='c';
  }
  cout<<m<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <array>
#include <set>
#include <iomanip>
#include <map>
#include <cmath>

using namespace std;

typedef long long ll;

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

    vector<int> vs(n);

    ll sum_f = 0;
    ll sum_e = 0;
    for (auto &v : vs)
    {
        cin >> v;
        sum_f += v;
    }
    sum_f -= vs.back();
    sum_e += vs.back();
    ll min_diff = abs(sum_f - sum_e);

    for (int i = vs.size() - 2; i > 0; i--)
    {
        sum_f -= vs[i];
        sum_e += vs[i];
        min_diff = min<ll>(min_diff, abs(sum_f - sum_e));
    }
    cout << min_diff << endl;
}

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

typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10, mod = 1e9+7;

void solve() {
    int n; cin >> n;
    while (n >= 1000) {
        n -= 1000;
    }

    if (n == 0) {
        cout << 0 << endl;
        return;
    }
    cout << 1000 - n << endl;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; 
    while (t--) solve();
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rint register int
#define LL long long
#define maxn 20007
#define inf 1000000000
#define mod 100000007
#define	QAQ freopen ("cantor.in", "r", stdin); freopen ("cantor.out", "w", stdout);
using namespace std;
inline int rf(){int r,s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;%>
int main()
{
	//QAQ 
	int n=rf(),ans=0;
	
	char a[100001];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]!=a[i-1]) ans++;
	}
	
	printf("%d",ans);
	
    return 0;
}
/*
We Secure. We Contain. We Protect
We programme. We submit. We accepted


JXU4RDc3JXU3ODAxJXVGRjBDJXU2NzAwJXU4RDc3JXU3ODAxJXVGRjBDJXU1MjFEJXU4RDVCJXU5MDFBJXU4RkM3JXVGRjAx
10
1 2 3 1 2  3 4 6 2 3


*/

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

int main() {
  double n, m, x, sum = 0;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> x;
    n -= x;
  }

  if (n < 0)
    cout << "-1" << endl;
  else
    cout << n << endl;
}

Measured memory_bytes: 3788
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    boolean allEven = true;
    for (int i = 0; i < N; i++) {
      int a = sc.nextInt();
      if (a%2 != 0) {
        allEven = false;
      }
    }
    System.out.println(allEven ? "second" : "first");
  }
}

Measured memory_bytes: 48564
n = int(input())
a = list(map(int, input().split()))
l = [0] * n
h = [0] * n

for i in range(n):
    if 0 <= i + a[i] < n:
        l[i + a[i]] += 1
    if 0 <= i - a[i] < n:
        h[i - a[i]] += 1

ans = 0
for ll, hh in zip(l, h):
    ans += ll * hh

print(ans)


Measured memory_bytes: 92820
#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++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define mod 1000000007

int main(){
    int n;
    cin >>n;
    string s1,s2;
    cin >> s1 >> s2;
    llong ans;
    int i;
    if(s1[0]==s2[0]){
        ans=3;
        i=1;
    }
    else{
        ans=6;
        i=2;
    }
    while(i < n){
        if(s1[i-1] == s2[i-1]){
            ans= ans*2 %mod;
            if(s1[i]==s2[i]) i+=1;
            else i+=2;
        }
        else{
            if(s1[i] == s2[i]) i+=1;
            else{
                ans= ans * 3 %mod;
                i+=2;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [0]
dp.append(abs(h[1]-h[0]))
if n > 2:
    for i in range(2,n):
        dp.append(min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]))
print(dp[-1])

Measured memory_bytes: 55528
import java.util.*;

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

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		int outlet = 1;

		while (B > outlet) {
			outlet--;
			outlet += A;
			ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
A,B = list(map(int,input().split()))

S = input()

s0 = ord('0')
ans ='Yes'
if len(S) == A+B+1 and S[A]=='-':
    for x in S[:A]+S[A+1:]:
        if s0 <= ord(x) and ord(x) <= s0+9:
            continue
        else:
            ans = 'No'
            break
else:
    ans='No'
print(ans)

Measured memory_bytes: 3060
from time import time
import random


def main():
    random.seed(0)

    now = time()

    MAX = 26

    # 入力
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]

    # 初期解を貪欲法で求める
    t = []
    prev = [0] * MAX
    for day, row in enumerate(s, 1):
        mxi = 1
        mx = 0
        for i, (es, ec) in enumerate(zip(row, c), 1):
            point = es + ec * (day - prev[i - 1])
            if point > mx:
                mx = point
                mxi = i

        prev[mxi - 1] = day
        t.append(mxi)

    # 初期解に対する満足度を計算
    last = [0] * MAX
    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    # 変更を検討する日にちの選ばれやすさ
    d_li = []
    for i in range(1, d + 1):
        ln = max(1, (-(i - d // 2) ** 2 + d ** 2 // 4) // 500)
        d_li += [i] * ln

    d_li = list(range(1, d + 1))
    di_max = len(d_li) - 1

    # 各日にちにおいて変更を検討するコンテストの選ばれやすさ
    sc = []
    for day, row in enumerate(s, 1):
        app = []
        for i, (es, ec) in enumerate(zip(row, c), 1):
            ln = max(1, (es + ec * (d ** 2 // 4 - (day - d // 2) ** 2)) // 200)
            app += [i] * ln
        sc.append(app)

    # 時間の許す限り更新を検討する
    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, len(sc[ed-1]) - 1)
        eq = sc[ed-1][qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")


if __name__ == "__main__":
    main()


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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  bool can = false;
  int price = 10000000;
  for (int bit = 0; bit < (1<<N); bit++) {
    int tmp = 0;
    vector<int> learn(M, 0);
    for (int i = 0; i < N; i++) {
      if (bit & (1<<i)) {
        tmp += C[i];
        for (int j = 0; j < M; j++) {
          learn[j] += A[i][j];
        }
      }
    }
    sort(learn.begin(), learn.end());
    if (learn[0] >= X) {
      can = true;
      if (price > tmp) price = tmp;
    }
  }
  if (can) cout << price << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, M;
    cin >> N >> M;
    int X[100000];
    for(int i=0;i<M;i++)
        cin >> X[i];
    
    if(M <= N){
        cout << 0 << endl;
        return 0;
    }
    // 昇順ソート
    sort(X, X + M);
    // 右隣の地点との距離
    int d[100000];
    for(int i=0;i<M-1;i++){
        d[i] = X[i+1] - X[i];
    }
    // 昇順ソート
    sort(d, d + M - 1);
    int ans = 0;
    // M - N 個の未到達地点を訪れる
    for(int i=0;i<M-N;i++)
        ans += d[i];

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
int main(){
    int n,m,ans;
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        ans += i;
    }
    for (int i = 1; i < m; i++) {
        ans += i;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin>>N;
  map<string,int> mp;
  int ma=0;
  rep(i,N){
    string S; cin>>S;
    mp[S]++;
    ma=max(ma,mp[S]);
  }
  vector<string> ans;
  for(auto m:mp){
    if(m.second==ma){
      ans.push_back(m.first);
    }
  }
  sort(ans.begin(),ans.end());
  rep(i,ans.size()){
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 25584
using System;
using System.Collections.Generic;

class AIZU0023
    {
        public static void Main() {
            double v,y,storycon; string s;
            int story;
            //t=v/9.8, y=v^2/19.6, 5*story-5>=v^2/19.6, story>=v^2/98+1
            Queue<int> compost = new Queue<int>();
            while (true) {
                s=Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;
                v=double.Parse(s);
                y=v*v/19.6;
                storycon=(y+5)/5;
                story=(int)Math.Ceiling(storycon);
                compost.Enqueue(story);
                Console.WriteLine(compost.Dequeue());
            }
        }
    }

Measured memory_bytes: 10120
#include<stdio.h>

int A[1000000],n;
int BinarySearch(int);

int main(){
  int i,b,c,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&c);
    if(BinarySearch(c))sum++;
  }
  printf("%d\n",sum);

  return 0;
}
int BinarySearch(int x){
  int left=0;
  int right=n;
  int mid;

  while(left < right){
    mid=(left + right)/2;
    if(x==A[mid])return 1;
    if(x > A[mid])left=mid+1;
    else if(x<A[mid])right=mid;
  }
  return 0;
}



Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q, a, b;
int main() {
	scanf("%lld", &q);
	while(q--) {
		scanf("%lld%lld", &a, &b);
		if(a > b) swap(a, b);
		if(a == b) cout << a+a-2 << endl;
		else if(a+1 == b) cout << a+a-2 << endl;
		else  {
			ll c = sqrt(a*b) + 10;
			while(c*c >= a*b) --c;
			if(c*(c+1) >= a*b) cout << c+c-2 << endl;
			else cout << c+c-1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
int main(){
	int h,w;
	while(1){
		std::cin>>h>>w;
		if(w == 0 && h == 0) break;
		for(int i = 0,k = 0; i < h; k = ++i){
			for(int j = 0; j < w; ++j){
				if(k % 2 == 0)
					std::cout<<"#";
				else
					std::cout<<".";
				++k;
			}
			std::cout<<std::endl;
		}
		std::cout<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1156
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#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';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    int price[1010];
    int c[1010];
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        price[i] = a;
        c[i] = 0;
        rep(bi, b) {
            int x;
            cin >> x;
            x--;
            c[i] |= 1 << x;
        }
    }

    int dp[5000];
    rep(i, 5000) dp[i] = INF;

    rep(i, m) {
        if (dp[c[i]] > price[i]) dp[c[i]] = price[i];
    }

    for (int key_used = 1; key_used <= n; key_used++) {
    rep(i, 1 << n) {
        for (int j = i + 1; j < 1 << n; ++j) {
            if (dp[i | j] > dp[i] + dp[j]) dp[i | j] = dp[i] + dp[j];
        }
    }
    }

    int ans = dp[(1 << n) - 1];
    if (ans == INF)
        print(-1);
    else
        print(ans);



    return 0;
}



Measured memory_bytes: 256