akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int cmp(const void* a, const void* b) {
	int x = *((const int*)a);
	int y = *((const int*)b);
	return x > y ? 1 : (x < y ? -1 : 0);
}

int N;
int A[200000];
int sort_temp[200000];

int get_id(int num) {
	int left = 0, right = N - 1;
	while (left <= right) {
		int mid = (left + right) / 2; /* どっかのサイトでは間違ってると主張されてるってやつ */
		if (sort_temp[mid] == num) return mid;
		else if (sort_temp[mid] < num) left = mid + 1;
		else right = mid - 1;
	}
	puts("Asumisu Kekkonn!!!");
	exit(1);
}

#define BIT_MAX 200000

int bit_table[BIT_MAX];

void bit_init(void) {
	int i;
	for(i=0;i<BIT_MAX;i++)bit_table[i]=0;
}

void bit_add(int pos,int value) {
	pos++;
	while(pos<=BIT_MAX) {
		bit_table[pos-1]+=value;
		pos+=pos & (-pos);
	}
}

int bit_sum(int pos) {
	int sum=0;
	pos++;
	while(pos>0) {
		sum+=bit_table[pos-1];
		pos-=pos & (-pos);
	}
	return sum;
}

int main(void) {
#if 0
	int i, j;
	uint64_t answer;
#endif
	int i;
	int gu_ki, ki_gu;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}

#if 0
	/* とりあえず奇数と偶数にわけてソートするぞ */
	/* ソートを書くのは面倒くさいぞ */
	/* 偶数 */
	for (i = 0, j = 0; i < N; i += 2, j++) sort_temp[j] = A[i];
	qsort(sort_temp, j, sizeof(int), cmp);
	for (i = 0, j = 0; i < N; i += 2, j++) A[i] = sort_temp[j];
	/* 奇数 */
	for (i = 1, j = 0; i < N; i += 2, j++) sort_temp[j] = A[i];
	qsort(sort_temp, j, sizeof(int), cmp);
	for (i = 1, j = 0; i < N; i += 2, j++) A[i] = sort_temp[j];
#endif
	/* 座標圧縮するぞ */
	for (i = 0; i < N; i++) sort_temp[i] = A[i];
	qsort(sort_temp, N, sizeof(int), cmp);

#if 0
	/* バブルソートの交換回数するぞ */
#ifdef NAIVE_9D5D05CF_E86C_4690_BEB6_AB1B261D60BA
	answer = 0;
	for (i = N - 1; i >= 0; i--) {
		for (j = 0; j < i; j++) {
			if (A[j] > A[j + 1]) {
				int temp = A[j];
				A[j] = A[j + 1];
				A[j + 1] = temp;
				answer++;
			}
		}
	}
#else
	bit_init();
	answer = 0;
	for (i = 0; i < N; i++) {
		/* 先頭まで行く手間 - これより前にある自分より小さいのの数 */
		answer += i - bit_sum(get_id(A[i]));
		bit_add(get_id(A[i]), 1);
	}
#endif

	printf("%"PRIu64"\n", answer);
#endif

	/* カウントするぞ */
	gu_ki = ki_gu = 0;
	for (i = 0; i < N; i++) {
		if (i % 2 == 0 && get_id(A[i]) % 2 != 0) gu_ki++;
		if (i % 2 == 1 && get_id(A[i]) % 2 != 1) ki_gu++;
	}
	if (gu_ki != ki_gu) {
		/* 偶数から奇数に来た奴と奇数から偶数に来た奴の数が一致しない */
		puts("impossible?");
		return 1;
	}
	printf("%d\n", gu_ki);

	return 0;
}

/*
操作2 = 1個あけた2個の要素の順番を反転

ABABABABABABABABABABAB
操作2ではこのAとBの間で入れ変えることはできない

操作1だけならバブルソートの交換回数→大きいのが前にあるほど不利

→WA
反例

6
1
10
2
20
3
30

1 10 2 20 3 30 → バブルソートの交換回数は3、奇数偶数それぞれソート済み
1 10 2 3 20 30 → 操作1
1 3 2 10 20 30 → 操作2
1 2 3 10 20 30 → 操作1 → 2回でできる

新方式 : 奇数に来るはずのが偶数、偶数に来るはずのが奇数に来てたらカウント
1 10 2 20 3 30
0 4  1 5  2 3 ← 座標圧縮
0 1  2 3  4 5 ← 位置
o x  x o  o o ← 偶奇が一致?

操作2でグループ内どこにでも移動できるから、隣合わせにして交換できる

*/


Measured memory_bytes: 1404
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(n, m) = readLine().split(' ').map(_.toInt)
    val coin = readLine().split(' ').map(_.toInt).sorted.reverse.toList

    val memo = Array.fill(n + 1, m + 1)(-1)

    def solve(money: Int, coin: List[Int], coinLength: Int): Int = {
      if (coinLength == 1) { // 1円しか残っていない時
        money
      } else if (memo(money)(coinLength) != -1) {
        memo(money)(coinLength)
      } else {
        val result = List(
          solve(money, coin.tail, coinLength - 1),
          if (money < coin.head) Int.MaxValue else 1 + solve(money - coin.head, coin, coinLength)
        ).min
        memo(money)(coinLength) = result
        result
      }
    }

    println(solve(n, coin, coin.length))
  }

}



Measured memory_bytes: 209116
#include <stdio.h>
#include <math.h>
int is_prime_number(int n){
    int i;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0) return 0;
    }
    return 1;
}

int main(void){
    int i,j,n,p[100]={0},count=0,temp;;
    int p2=0,p4=0,p14=0,p24=0,p74=0;
    scanf("%d",&n);
    for(i=2;i<=n;i++){
        if(is_prime_number(i)){
            p[i]+=1;
        }else{
            for(j=2;j<n;j++){
                if(is_prime_number(j)){
                    if(i%j==0){
                        temp=i;
                        while(temp%j==0){
                            temp/=j;
                            p[j]++;
                        }
                    }
                }
            }
        }
    }
    for(i=2;i<=n;i++){
        if(is_prime_number(i)){
            if(p[i]>=2){ p2++;}
            if(p[i]>=4){ p4++;}
            if(p[i]>=14){ p14++;}
            if(p[i]>=24){ p24++;}
            if(p[i]>=74){ p74++;}
        }
    }
    if(p2>=3&&p4>=2){
        count+=p4*(p4-1)*(p2-2)/2;
    }
    if(p4>=2&&p14>=1){
        count+=p14*(p4-1);
    }
    if(p2>=2&&p24>=1){
        count+=p24*(p2-1);
    }
    count+=p74;
    printf("%d\n", count);
    return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll X[200005];
//! 反時計回りにiまで進んだあと交互に燃やす移動距離
ll dpL[200005];
//! 時計回りにiまで進んだあと交互にもやす移動距離
ll dpR[200005];

int main()
{
    ll L, N;
    cin >> L >> N;
    REP(i, N)
    {
        cin >> X[i];
    }

    {
        ll s0 = 0;
        ll s1 = 0;
        dpL[N - 1] = 0;
        ll t = N - 1;
        for (int i = N - 2; i >= 0; --i)
        {
            s0 += L - X[N - 1 - (N - 2 - i) / 2];
            s1 += X[i] + X[i + 1] - X[t];
            dpL[i] = s0 + s1;
            if ((N - 1 - i) % 2 == 1)
                t--;
        }
    }
    {
        ll s0 = 0;
        ll s1 = 0;
        dpR[0] = 0;
        ll t = 0;
        FOR(i, N, 1)
        {
            s0 += X[(i - 1) / 2];
            s1 += (L - X[i]) + (L - X[i - 1]) - (L - X[t]);
            dpR[i] = s0 + s1;
            if (i % 2 == 1)
                t++;
        }
    }
    ll max = 0;
    //! 反時計回りにiまで進み、そこから交互に燃やしていく
    REP(i, N)
    {
        ll m = X[i] + dpL[i];
        //! X[N-1]->X[i+1]->X[N-2]->...
        max = std::max(m, max);
        //cout << "L:" << i << ":" << dpL[i] << endl;
    }
    //! 時計回りにiまで進み、そこから交互に燃やす
    for (int i = N - 1; i >= 0; --i)
    {
        ll m = L - X[i] + dpR[i];
        //! X[0]->X[i-1]->X[1]->...
        max = std::max(m, max);
        //cout << "R:" << i << ":" << dpR[i] << endl;
    }
    cout << max << endl;
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[][] commands = new string[n][];
            for (int i = 0; i < n; i++) commands[i] = Console.ReadLine().Trim().Split(' ');
            HashSet<string> S = new HashSet<string>();
            foreach (string[] x in commands)
                if (x[0].Equals("insert")) S.Add(x[1]); else Console.WriteLine(S.Contains(x[1]) ? "yes" : "no");
        }
    }
}



Measured memory_bytes: 173768
#include <iostream>                                                                                                          

typedef long long ll; 

int main(){
   ll X, Y;
   std::cin >> X >> Y;

   ll ans = 1;
   ll n = Y/X;
   while(n>1){
      n /= 2;
      ++ans;
   }   
   std::cout << ans << std::endl;
   return 0;
}

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

int main(){
    string N;
    cin>>N;
    int count=0;
    for(int i=0;i<N.size();i++){
        int n=N.at(i)-'0'; 
        count += n;
    }
    if(count%9==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
}


Measured memory_bytes: 3632
from itertools import groupby

S = input()
T = (len(tuple(v)) for _, v in groupby(S))

ans = []
for r, l in zip(T, T):
    t = (r + 1) // 2 + l // 2
    ans += [0] * (r - 1) + [t, r + l - t] + [0] * (l - 1)

print(*ans)


Measured memory_bytes: 7228
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N;
	cin >> N;

	vector<int> A(N), B(N), C(N - 1);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N - 1; i++) cin >> C[i];

	int ans = accumulate(B.begin(), B.end(), 0);
	for (int i = 0; i < N - 1; i++) if (A[i] == A[i + 1] - 1)ans += C[A[i] - 1];

	cout << ans << endl;

	return 0;
}

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

int main(){
  while(1){
    int a,b,c,d;
    string s,jfen[9];
    cin>>s;
    if(s=="#")break;
    int h=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='b')jfen[h]+='b';
      else if(s[i]=='/')h++;
      else
	for(int j=0;j<s[i]-'0';j++)
	  jfen[h]+='.';
    }
    cin>>a>>b>>c>>d;
    jfen[a-1][b-1]='.';
    jfen[c-1][d-1]='b';
    string ans;
    for(int i=0;i<=h;i++){
      int x=0;
      for(int j=0;j<jfen[i].size();j++){
	if(jfen[i][j]=='b'){
	  if(x)ans+=x+'0';
	  ans+='b';
	  x=0;
	}else x++;
      }
      if(x)ans+=x+'0';
      if(i!=h)ans+='/';
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

const int N = 1003;

int n, m;

char mat[N][N];

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int dist[N][N];

void bfs(int x, int y) {
	memset(dist, -1, sizeof dist);
	dist[x][y] = 0;
	deque<pair<int, int>> q;
	q.emplace_back(x, y);
	while(!q.empty()) {
		tie(x, y) = q.front(); q.pop_front();
		for(int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx < 1 or nx > n) continue;
			if(ny < 1 or ny > m) continue;
			if(mat[nx][ny] != '.') continue;
			if(dist[nx][ny] != -1 and dist[nx][ny] <= dist[x][y]) continue;
			dist[nx][ny] = dist[x][y];
			q.emplace_front(nx, ny);
		}
		for(int i = -2; i <= 2; i++) for(int j = -2; j <= 2; j++) {
			int nx = x + i;
			int ny = y + j;
			if(nx < 1 or nx > n) continue;
			if(ny < 1 or ny > m) continue;
			if(mat[nx][ny] != '.') continue;
			if(dist[nx][ny] != -1) continue;
			dist[nx][ny] = dist[x][y] + 1;
			q.emplace_back(nx, ny);
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);

	int cx, cy;
	scanf("%d %d", &cx, &cy);
	int sx, sy;
	scanf("%d %d", &sx, &sy);

	for(int i = 1; i <= n; i++) scanf(" %s", mat[i] + 1);

	bfs(cx, cy);

	printf("%d\n", dist[sx][sy]);
}


Measured memory_bytes: 8664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main() {

    int n; cin >>n;
    vector<int> a;
    int count10 = 0;
    int count = 0;
    for (int i = 0; i < n; i++) {
        int c; cin >> c;
        if (c % 10 == 0) {
            count10 += c;
        } else {
            count += c;
            a.push_back(c);
        } 
    }

    sort(a.begin(), a.end());

    if (a.size()) {
        int i = 0;
        while (count % 10 == 0 && i < a.size() - 1) {
            count -= a[i];
        }
        cout << count + count10 << endl;
    } else {
        cout << 0 << endl;
    } 
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())

lis = [[0] * 10 for i in range(10)]

for i in range(N+1):

    s = str(i)

    lis[int(s[0])][int(s[-1])] += 1

ans = 0

for i in range(9):

    i += 1

    for j in range(9):

        j += 1

        ans += lis[i][j] * lis[j][i]

print (ans)


Measured memory_bytes: 40428
// Problem : A - ABC Swap
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b); swap(a, c);
	cout << a << " " <<  b << " " << c << endl;
	return 0;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 1e9

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

    int N, M;
    int X, Y;
    vector<int> x, y;

    cin >> N >> M >> X >> Y;
    int num;
    for (int i = 0; i < N; i++) {
        cin >> num;
        x.push_back(num);
    }
    for (int i = 0; i < M; i++) {
        cin >> num;
        y.push_back(num);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if (x[N-1] < y[0] && X<y[0]-1 &&x[N-1] < Y) cout << "No War" << endl;
    else cout << "War" << endl;
}

Measured memory_bytes: 256
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        ans = min_p-1
    elif x == max_p:
        if max_p-1 == p[len(p)-2]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p-1, max_p+1):
            if i == p[j]:
                j += 1
                if len(p) == j:
                    im_i = p[j-1] +1
                    if abs(ans-x) > abs(im_i-x):
                        ans = im_i
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,ans;
    cin >> n;
    ans = (n/11)*2;
    if(n%11  > 6)ans+=2;
    else if(n%11 <=6 && n%11 > 0)ans++;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int r = 0;
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      r = max(r, K - a.at(N - 1) + a.at(0));
    }
    else {
      r = max(r, a.at(i + 1) - a.at(i));
    }
  }
  cout << K - r << endl;
}

Measured memory_bytes: 1024
// B.

#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	int h, w;
	cin >> h >> w;
	vector<string> b(h);
	for (int i = 0; i < h; ++i) {
		cin >> b[i];
	}
	vector<int> cnt(w);
	for (int j = 0; j < w; ++j) {
		for (int i = 0; i < h; ++i) {
			cnt[j] += b[i][j] == '.';
		}
	}
	string e(w, '.');
	for (int i = 0; i < h; ++i) {
		if (b[i] != e) {
			for (int j = 0; j < w; ++j) {
				if (cnt[j] < h) {
					cout << b[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

vvi bfs(vector<vector<char>> &s, int x, int y) {
  vi dx = {0, -1, 0, 1};
  vi dy = {-1, 0, 1, 0};
  int H = s.size();
  int W = s[0].size();
  vvi d(H, vi(W, INF));
  queue<pii> que;
  que.push(pii(x, y));
  d[y][x] = 0;

  while(!que.empty()) {
    pii p = que.front(); que.pop();
    rep(i, 0, 4) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (nx > -1 && nx < W && ny > -1 && ny < H) {
        if (s[ny][nx] != '#' && d[ny][nx] == INF) {
          que.push(pii(nx, ny));
          d[ny][nx] = d[p.second][p.first] + 1;
        }
      }
    }
  }
  return d;
}

void solve() {
  VAR(int, H, W);
  vector<vector<char>> s(H, vector<char>(W));
  int sum = 0;
  rep(i, 0, H) {
    rep(j, 0, W) {
      in(s[i][j]);
      sum += (s[i][j] == '.');
    }
  }

  int d = bfs(s, 0, 0)[H - 1][W - 1];

  if (d == INF) {
    print(-1);
  } else {
    print(sum - d - 1);
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 998244353 

void func()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    loop(i,1,n+1){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    loop(i,2,n+1){
        a[i]=a[i]+a[i-1];
    }
    cout<<a[k]<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3664
alphabet = ['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']
n = input()
string_s = input()
n = int(n)
ans_s = ""

for s in string_s:
    index_s = alphabet.index(s)
    if index_s + n >= 26:
        ans_s = ans_s + alphabet[(index_s + n) - 26]
    else:
        ans_s = ans_s + alphabet[index_s + n]
print(ans_s)

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <inttypes.h>
#include <time.h>

using namespace std;

typedef long long tnum;

#define loop(i, num) for(int i = 0; i < num; i++)

tnum* tnumAlloc(int num);
tnum scanNum();
int scanInt();
tnum* scanNums(int);
char* scanChars(int maxlength);
string scanString();
void printlnNums(int count, tnum* nums);
void printlnNum(tnum num);
void printString(string str);

#define min(a,b) (a <= b ? a : b)
#define max(a,b) (a >= n ? a : b)

#define concatVectors(dest, src) dest.insert(dest.end(), src.begin(), src.end());

int main() {
    tnum n = scanNum();
    tnum mod = 1000000007;

    if(n == 1) {
        printf("0");
        return 0;
    }

    tnum all = 1;
    tnum sub = 1;
    tnum add = 1;

    loop(i, n){
        all *= 10;
        all %= mod;
        sub *= 9;
        sub %= mod;
        add *= 8;
        add %= mod;
    }

    sub *= 2;
    sub %= mod;

    tnum res = all - sub + add;

    if(res < 0) res += mod;
    if(res < 0) res += mod;
    if(res < 0) res += mod;
    res %= mod;

    printlnNum(res);

    return 0;
}

//have to be free()
tnum* tnumAlloc(int num) {
	return (tnum*)calloc(num,sizeof(tnum));
}

tnum scanNum() {
	tnum ret;
    cin >> ret;

    return ret;
}

int scanInt() {
	tnum ret;
    cin >> ret;

    return ret;
}

//have to be free()
tnum* scanNums(int num) {
	tnum* buf;
	tnum* tmp;
	buf = tnumAlloc(num);
	for (int i = 0; i < num; i++) {
		cin >> buf[i];
	}

	return buf;
}

//have to be free()
char* scanChars(int maxlength) {
	char* ret = (char*)malloc(maxlength+1);
	scanf("%s", ret);

	return ret;
}

//have to be free()
string scanString() {
	string ret;
	cin >> ret;
	return ret;
}

void printlnNum(tnum num) {
    cout << num << endl;
}

// can be used for debugging
void printlnNums(int count, tnum *nums) {
	loop(i, count) {
		cout << nums[i];
		if (i != count - 1) printf(" ");
	}
	printf("\n");
}

void printString(string str) {
	cout << str;
}


Measured memory_bytes: 3624
#include <stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a > b)
		printf("a > b\n");
	else if (a < b)
		printf("a < b\n");
	else
		printf("a == b\n");
	return 0;
}

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

int main(){
  int a, sum = 0; cin >> a;
  for(int i=1; i<=a; i++)
  {int b; cin >> b;
  if(b%2 == 0 && b%3 != 0 && b%5 != 0) sum+=1;}

if(sum == 0){cout << "APPROVED";}
else{cout << "DENIED";}

return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

using namespace std;

int main()

{

    int sx,sy,tx,ty;

    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);

    for(int i=1;i<=(ty-sy);i++)printf("U");

    for(int i=1;i<=(tx-sx);i++)printf("R");

    for(int i=1;i<=(ty-sy);i++)printf("D");

    for(int i=1;i<=(tx-sx);i++)printf("L");

    printf("L");

    for(int i=1;i<=(ty-sy)+1;i++)printf("U");//这四个判断条件+1是因为事先或时候都多走了一步，所以要走回来

    for(int i=1;i<=(tx-sx)+1;i++)printf("R");

    printf("D");

    printf("R");

    for(int i=1;i<=(ty-sy)+1;i++)printf("D");

    for(int i=1;i<=(tx-sx)+1;i++)printf("L");

    printf("U\n");

    return 0;

}

 


Measured memory_bytes: 256
n = int(input())
dp = list(list(map(int, input().split())) for _ in range(n))
for i in range(1, n):
    dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] += max(dp[i - 1][2], dp[i - 1][0]);
    dp[i][2] += max(dp[i - 1][0], dp[i - 1][1]);
print(max(dp[n - 1]))


Measured memory_bytes: 30580
#include <iostream>
#include <map>
#include <string.h>
using namespace std;

int main(int args, char *argv[])
{
    map<string, int> cnt;

    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string tmp;
        cin >> tmp;
        cnt[tmp]++;
    }

    int M;
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        string tmp;
        cin >> tmp;
        cnt[tmp]--;
    }

    int m;
    for (auto it = cnt.begin(); it != cnt.end(); ++it)
    {
        m = max(m, it->second);
    }

    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}
int main()
{
  int N;
  cin >> N;
  vector<int> A(N+1);
  FOR(i,1,N+1) cin >> A[i];
  
  vector<int> B;
  for(int i=N;i>0;i--){
    vector<ll> vec=divisor(i);
    if(A[i]%2==1){
      for(auto x:vec){
        A[x]++;
      }
      B.push_back(i);
    }
  }
  cout << B.size() << endl;
  if(B.size()>0){
    REP(i,B.size()){
      cout << B.at(i);
      if(i!=B.size()){
        cout << " ";
      }
    }
    cout << endl;
  }
}

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

#define ll long long
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
ll vis[mm];
int main()
{
	ll n,m,i,j,x,k;
    cin>>n;
    k=n%10;
    if(k==2||k==4||k==5||k==7||k==9) 
    printf("hon\n");
    else if(k==3)
    printf("bon\n");
    else if(k==0||k==1||k==6||k==8)
    printf("pon\n");
}

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

int main(void) {
    char c;
    int idx = 1;
    bool pos = true;
    while(isalpha(c=getchar())){
        if(idx%2==0){
            if(c=='R')
                pos = false;
        }else{
            if(c=='L')
                pos = false;
        }
        idx++;
    }
    if(pos)
        printf("Yes");
    else
        printf("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll o = a/d;
    ll t = c/b;
    if(a%d!=0) o++;
    if(c%b!=0) t++;

    if(t>o) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  string S,T,U;
  cin>>S>>T;
  
  int A,B;
  cin>>A>>B;
  
  cin>>U;
  if(S==U)
    --A;
  else
    --B;
  
  cout<<A<<" "<<B<<endl;
  
}


Measured memory_bytes: 256
import sys

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


def main():
    a, b = map(int, readline().split())

    print(str(min(a, b)) * max(a, b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61748
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vec a(3*n),m(n);
    rep(i,n*3){
        cin>>a[i];
        if(range(i,n,2*n)) m[i-n]=a[i]; 
    }
    priority_queue<ll,vec,greater<ll>> Q;
    int sum=0;
    rep(i,n){
        sum+=a[i];
        Q.push(a[i]);
    }
    vec memo(n+1);
    memo[0]=sum;
    rep(i,n){
        if(m[i]>Q.top()){
            sum+=m[i];sum-=Q.top();
            Q.pop();Q.push(m[i]);
        }
        memo[i+1]=sum;
        // cout<<sum<<endl;
    }
    priority_queue<ll> p;
    sum=0;
    rep(i,n){
        sum+=a[i+2*n];
        p.push(a[i+2*n]);
    }
    vec memon(n+1);
    memon[n]=sum;
    rep(i,n){
        int j=n-1-i;
        if(m[j]<p.top()){
            sum+=m[j];sum-=p.top();
            p.pop();p.push(m[j]);
        }
        memon[j]=sum;
        // cout<<sum<<endl;
    }
    int ans=-INF;
    rep(i,n+1){
        chmax(ans,memo[i]-memon[i]);
    }
    cout<<ans<<endl;

    
}

Measured memory_bytes: 6644
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

const ll maxN = 200005;
ll n;
vector<ll> adj[maxN];
ll c[maxN];
ll sz[maxN];
ll done[maxN];
ll ans[maxN];

void dfs(ll u, ll p) {
	sz[u] = 1;
	ll done_before = done[c[u]];
	for(auto v : adj[u]) {
		if(v != p) {
			done[c[u]] = 0;
			dfs(v, u);
			sz[u] += sz[v];
			ll cnt = sz[v] - done[c[u]];
			ans[c[u]] += cnt*(cnt+1)/2;
			// cout<<u+1<<" -> "<<cnt<<" = "<<sz[v]<<" - "<<done[c[u]]<<endl;
		}
	}
	done[c[u]] = done_before + sz[u];
}

void solve(ll tc) {
	cin>>n;
	for(ll i=0; i<n; ++i) {
		cin>>c[i];
		--c[i];
	}
	for(ll i=0; i<n-1; ++i) {
		ll u, v;
		cin>>u>>v;
		adj[u-1].pb(v-1);
		adj[v-1].pb(u-1);
	}
	dfs(0, -1);
	for(ll i=0; i<n; ++i) {
		ll cnt = sz[0] - done[i];
		ans[i] += cnt*(cnt+1)/2;
		cout<<n*(n+1)/2 - ans[i]<<endl;
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin>>t;
    for(ll tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

Measured memory_bytes: 36328
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int N, C, S, F, T[500] = {0};

int main()
{
  cin >> N;

  REP(i, N - 1)
  {
    cin >> C >> S >> F;
    T[i] = S + C;
    REP(j, i)
    {
      T[j] = (S < T[j] ? S + (int)((T[j] - S + F - 1) / F) * F : S) + C;
    }
  }

  REP(i, N)
  {
    cout << T[i] << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  double ave = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    ave += (double)(a[i]);
  }
  ave /= n;
  int p = 0;
  double mi = abs((double)(a[0]) - ave);
  for(int i = 1; i < n; i++){
    double d = abs((double)(a[i]) - ave);
    if(d < mi){
      p = i;
      mi = d;
    }
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int c(const void *c1,const void *c2){
    return *(int *)c1-*(int *)c2;
}

int main(void){
    int r,x,y,o,n,m,i,map[200][2],map1[1000][2],t;
    for(;scanf("%d",&n),n;){
        for(i=0;i<n;i++)
            scanf("%d %d",&map[i][0],&map[i][1]);
        scanf("%d",&m);
        for(i=0;i<m;i++)
            scanf("%d %d",&map1[i][0],&map1[i][1]);
        qsort(map,n,sizeof(int)*2,c);
        qsort(map1,m,sizeof(int)*2,c);
        for(i=0;i<m;i++){
            x=map1[i][0]-map[0][0]; 
            y=map1[i][1]-map[0][1];
            for(o=1,r=i+1;o<n;o++){
                for(t=0;t<m;t++){
                    if(map[o][0]+x == map1[t][0] && map[o][1]+y == map1[t][1])
                        break;
                }
                if(t == m)
                    break;
            }
            if(o == n)
                break;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 1752
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    string t;
    cin >> t;
    for(int i=0;i<t.size();i++){
        if(t[i]=='?'){
            cout << 'D' ;
        }else{
            cout << t[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 3752
#include<cstdio>
#define abs(x) ((x>0)?x:(-(x)))
int H,W,D,A;
int Q,L,R;
int px[90001] ,py [90001];
int d[90001];
int  main()
{
    scanf ("%d %d %d",&H,&W,&D);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            scanf ("%d",&A);
            px[A]=i,py[A]=j;
        }
    }
    for(int i=D+1;i<=H*W;i++){ 
        d[i]=d[i-D]+abs(px[i]-px[i-D])+ abs(py[i]-py[i-D]);
    } 
    scanf ("%d",&Q);
    while(Q--){ 
        scanf ("%d%d",&L,&R);
        printf ("%d\n",d[R]-d[L]);
    } 
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <string.h>

#define MAX 1010

int main()
{
	char str[MAX];
	int number, strsize;

	scanf( "%d\n", &number );

	for ( int i = 0 ; i < number ; i++ ) { 
		fgets( str, MAX, stdin );
		
		for ( int j = 0 ; str[j] != '\0' ; j++ ) {
			if ( str[j] == 'H' && str[j+1] == 'o' && str[j+2] == 's' && str[j+3] == 'h' && str[j+4] == 'i' && str[j+5] == 'n' && str[j+6] == 'o' ) {
					str[j+6] = 'a';
			}
		}
		printf( "%s", str ); 
	}
	return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    vector<vector<int>>vec(N,vector<int>(2));
    for(int i=0;i<N;i++){
        for(int j=0;j<2;j++){
            cin >>vec.at(i).at(j);
        }
    }
    int count=0;
    for(int i=0;i<N;i++){
       if(vec.at(i).at(0)==vec.at(i).at(1)){
           count++;
       }
       else{
           count=0;
       }       
       if(count==3){
        cout<<"Yes"<<endl;
        return 0;
        }

    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = INT_MAX / 2;

int main() {
    int N; cin >> N;
    int ans = INF;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        int cnt = 0;
        while(a%2==0){
            a /= 2;
            cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fr(i,a,b) for(ll i=a;i < b;i++)
#define fe(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(auto it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>
#define MAXN 100005
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define case(x) cout<<"Case #"<<x+1<<": "
#define endl "\n"
#define preturn(X) cout<<(X)<<endl; return 0
const int MOD = 1e9+7;
ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

int32_t main(){
    int n, k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n)cin>>h[i];
    vector<int> cost(n,1e9 + 10);
    cost[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k && (i+j) < n; j++){
            cost[i+j] = min(cost[i+j], cost[i] + abs(h[i+j] - h[i]) );
        }
    }
    cout<<cost[n-1]<<endl;
}

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

#define int long long
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; }

signed main(){
	string s;
	cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC") << endl;

	return 0;
}


Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline

def dfs(u,par):
  ans_list[u]+=ans_list[par]  
  for v in tree_list[u]:
    if v!=par:
      dfs(v,u)      
  return

N,Q=map(int,input().split())

tree_list=[[] for _ in range(N+1)]
for i in range(N-1):
  a,b=map(int,input().split())
  tree_list[a].append(b)
  tree_list[b].append(a)
#print(tree_list)

ans_list=[0]*(N+1)
for i in range(Q):
  p,x=map(int,input().split())
  ans_list[p]+=x

dfs(1,0)

print(*ans_list[1:])

Measured memory_bytes: 230908
#include <bits/stdc++.h> 
using namespace std; 
int main(){
  int N,J=0;
  cin >> N;
  int L = N * 2;
  
  vector <int> D(N*2);
  
  for(int i=0; i<L; i=i+2){
    cin >> D.at(i);
    cin >> D.at(i+1);
    
    if(D.at(i) == D.at(i+1)){
      J++;
    }
       
    else {
      J = 0;
    }
    
    if(J == 3){
      break;
    }
       
  }
     
  if(J >= 3){
    cout << "Yes" << endl;
  }     
       
  else if(J <= 2){
    cout << "No" << endl;
  }
  
 
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int ask(ll v) {
	string S;
	cout<<"? "<<v<<endl;
	cin>>S;
	return S[0]=='Y';
}

void ans(ll v) {
	cout<<"! "<<v<<endl;
	exit(0);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	ll p10=10000000000LL;
	for(i=10;i>=1;i--) {
		if(ask(p10)==1) break;
		p10/=10;
	}
	
	if(i==10) {
		p10=10000000000LL;;
		for(i=10;i>=1;i--) {
			if(ask(p10-1)==0) ans(p10);
			p10/=10;
		}
	}
	if(i==0) {
		for(i=10;i<=90;i+=10) {
			if(ask(i)==1) ans(i/10);
		}
	}
	ll ret=0,cm=0;
	for(;p10>=1;p10/=10) {
		int cur=-1;
		int dd[4]={8,4,2,1};
		FOR(j,4) if(cur+dd[j]<10) {
			ll tmp=ret+(cur+dd[j])*p10;
			ll tmp2=cm*10+(cur+dd[j]);
			if(ask(tmp2*1000000000LL)==0) cur+=dd[j];
		}
		cm=cm*10+cur;
		ret+=p10*cur;
	}
	
	
	ans(ret+1);
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int D;
    cin >> D;
    ll c[26];
    rep(i, 26) cin >> c[i];
    ll s[D][26];
    rep(i, D){
        rep(j, 26) cin >> s[i][j];
    }
    int pre[26];
    fill(pre, pre+26, -1);
    int t[D];
    rep(i, D){
        ld tmp[26];
        rep(j, 26){
            tmp[j] = s[i][j] + c[j]*(i-pre[j])*((ld)(D-i)/(ld)(26));
        }
        int res = -1;
        ld m = -INF;
        rep(j, 26){
            if(chmax(m, tmp[j])) res = j;
        }
        pre[res] = i;
        t[i] = res;
        //cout << res+1 << endl;
    }
    ll tmp = 0;
    set<int> ids[26];
    rep(i, 26) ids[i].insert(-1);
    rep(i, D){
        //cin >> t[i]; t[i]--;
        tmp += s[i][t[i]];
        pre[t[i]] = i;
        ids[t[i]].insert(i);
        rep(j, 26){
            tmp -= c[j]*(i-pre[j]);
        }
    }
    rep(i, 26) ids[i].insert(D);
    rep(k, 100){
        rep(i, D){
            rep(j, 26){
                int d, q;
                //cin >> d >> q;
                d = i, q = j;
                int p = t[d];
                ll ans = tmp-s[d][p]+s[d][q];
                set<int>::iterator it1, it2;
                it1 = ids[p].upper_bound(d);
                it2 = ids[q].upper_bound(d);
                int a1, a2, b1, b2;
                b1 = *it1, b2 = *it2;
                it1--, it1--, it2--;
                a1 = *it1, a2 = *it2;
                ans -= c[p]*(b1-d)*(d-a1);
                ans += c[q]*(b2-d)*(d-a2);
                if(chmax(tmp, ans)){
                    t[d] = q;
                    ids[p].erase(d);
                    ids[q].insert(d);
                }
            }
        }
    }
    rep(i, D) cout << t[i]+1 << endl;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define MOCK 0

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

const int N = 18;
ll a[1 << N], b[1 << N], ans[1 << N];

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
#if MOCK
  REP(i, 0, 1 << n) a[i] = i;
#else
  REP(i, 0, 1 << n) cin >> a[i];
#endif
  REP(bits, 0, 1 << n) {
    int comp = (1 << n) - 1 - bits;
    int sub = comp;
    while (1) {
      int sup = (1 << n) - 1 - sub;
      ans[sup] = max(ans[sup], b[sup] ? b[sup] + a[bits] : 0);
      if (sup != bits)
        b[sup] = max(b[sup], a[bits]);
      if (sub == 0) break;
      sub = (sub - 1) & comp;
    }
  }
  REP(i, 1, 1 << n) {
    ans[i] = max(ans[i], ans[i - 1]);
  }
#if !MOCK
  REP(i, 1, 1 << n) {
    cout << ans[i] << "\n";
  }
#endif
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
using namespace std;

const int MOD = 1000000007;

int main() {

	int N, M;
	int a[100], b[100];
	int road[100];

	cin >> N >> M;
	for (int i = 1; i <= N; i++) {

		road[i] = 0;

	}
	for (int i = 1; i <= M; i++) {

		cin >> a[i] >> b[i];
		road[a[i]]++;
		road[b[i]]++;

	}

	for (int i = 1; i <= N; i++) {

		cout << road[i] << endl;

	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		int min = Long.toString(N).length();
		for(long i = 2; i * i <= N; i++) {
			if(N % i == 0) {
				min = Math.min(min, Long.toString(N / i).length());
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < 19; i++) {
		cout << (s[i] == ',' ? ' ' : s[i]);
	}
	return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    int A, B;
    cin >> A >> B;
    if (A <= 8 && B <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()

typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int main(){
    int n; cin >> n;
    
    string s[n];
    rep(i,n) cin >> s[i];
    
    rep(i,n-1){
        Rep(j,i+1,n){
            if(s[i] == s[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    rep(i,n-1){
        ll x = s[i].size();
        
        if(s[i][x-1] != s[i+1][0]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    
}






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

bool comp(string a, string b) {
    if(a+b < b+a)
        return true;
    else
        return false;
}

int main() {
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    vector<string>a(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end(), comp);

    for(auto i : a)
        cout << i;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans = 1E15;
int main(){
  long long n,cnt=0,med=0;
  cin >> n;
  int a[n];
  int b = a[0],c=a[0];
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i] -= (i+1);
  }
  sort(a,a+n);
  if(n%2==0){
     med = (a[n/2]+a[(n-1)/2])/2;
  } 
  else med = a[n/2];
  for(int j=-1;j<=1;j++){
    long long sum=0;
    for(int i=0;i<n;i++) sum += abs(a[i]-(med+j));
    ans = min(ans,sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024