akhauriyash/Code-Regression huggingface dataset:
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

const double pi = 3.141592653589793;
vector<double> x(101), y(101);
int n; 

inline double naiseki(const double& x1, const double& y1, const double& x2, const double& y2) {
  return x1 * x2 + y1 * y2;
}

// 角度 theta の方向を最終的に向くとして計算
// theta は radian
double calc(const double& theta) {
  double res = 0.0;
  double dx = cos(theta), dy = sin(theta);
  for (int i = 0; i < n; ++i) {
    res += max(0.0, naiseki(dx, dy, x[i], y[i]));
  }
  return res;
}

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

  auto start = chrono::system_clock::now();

  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  int step = 7777777;

  double ans = 0.0;

  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> r(0, step);

  auto msec = 0.0;

  do {
    double theta = 2.0 * pi * r(mt) / step;
    chmax(ans, calc(theta));
    auto end = chrono::system_clock::now();
    auto dur = end - start;
    msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  } while (msec <= 1996);

  cout << setprecision(15) << ans << '\n';

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long ll;

int main()
{
  int a, b, t;
  cin >> a >> b >> t;
  int ans = 0;
  int time = 1;

  while(a * time < t + 0.5)
  {
    ans += b;
    time++;
  }
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int n, m;
 
void merge(int *u, int *net, int oldnet, int newnet);
 
int main(int argc, char *argv[])
{
  int i, s, t, p, q;
  int *u;
  int *net;
 
  scanf("%d", &n);
  scanf("%d", &m);
  u = (int *)malloc(sizeof(int) * n);
  net = (int *)malloc(sizeof(int) * (m + 1));
  for (i = 0; i < n; i++) u[i] = -1;
  for (i = 0; i <= m; i++) net[i] = 0;
 
  p = 1;
 
  for (i = 0; i < m; i++) {
    scanf("%d", &s);
    scanf("%d", &t);
    if (s != t) {
      if (u[s] == -1 && u[t] == -1) {
    u[s] = p;
    u[t] = p;
    net[p] += 2;
    p++;
      } else {
    if (u[s] != -1 && u[t] == -1) {
      u[t] = u[s];
      net[u[s]]++;
    } else if (u[s] == -1 && u[t] != -1) {
      u[s] = u[t];
      net[u[t]]++;
    } else {
      if (u[s] != u[t]) {
        if (net[u[s]] > net[u[t]]) merge(u, net, u[t], u[s]);
        else merge(u, net, u[s], u[t]);
      }
    }
      }
    }
  }
 
  scanf("%d", &q);
 
  for (i = 0; i < q; i++) {
    scanf("%d", &s);
    scanf("%d", &t);
 
    if (s == t) printf("yes\n");
    else {
      if (u[s] == u[t] && u[s] != -1 && u[t] != -1) printf("yes\n");
      else printf("no\n");
    }
  }
 
  return 0;
}
 
void merge(int *u, int *net, int oldnet, int newnet)
{
  int i;
   
  for (i = 0; i < n; i++) {
    if (u[i] == oldnet) u[i] = newnet;
  }
 
  net[newnet] += net[oldnet];
  net[oldnet] = 0;
}

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

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

	int n, m;
	cin >> n >> m;
	vector<int> num(n, 1), red(n, 0);
	red[0] = 1;
	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		if(red[x]) {
			if(num[x] > 1) {
				red[y] = 1;
				num[x]--;
				num[y]++;
			} else {
				red[y] = 1;
				num[x]--;
				num[y]++;
				red[x] = 0;
			}
		} else {
			num[x]--;
			num[y]++;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += red[i];
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, ans = 9999999;
    int x[110]; 
    cin >> n;
    for(int i = 0; i < n; i++) cin >> x[i];
    //iは座標jは人
    for(int i = 0; i <= 100; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += (x[j] - i)*(x[j] - i);
        }
        ans = min(ans, sum);

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int M = sc.nextInt();
		int N = sc.nextInt();
		int K = sc.nextInt();
		char[][] map = new char[M][];
		for (int i = 0; i < M; ++i) {
			map[i] = sc.next().toCharArray();
		}
		int[][] J = new int[M + 1][N + 1];
		int[][] O = new int[M + 1][N + 1];
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
				J[i + 1][j + 1] = J[i][j + 1] + J[i + 1][j] - J[i][j] + (map[i][j] == 'J' ? 1 : 0);
				O[i + 1][j + 1] = O[i][j + 1] + O[i + 1][j] - O[i][j] + (map[i][j] == 'O' ? 1 : 0);
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < K; ++i) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			int c = Integer.parseInt(sc.next());
			int d = Integer.parseInt(sc.next());
			int jc = J[c][d] - J[a - 1][d] - J[c][b - 1] + J[a - 1][b - 1];
			int oc = O[c][d] - O[a - 1][d] - O[c][b - 1] + O[a - 1][b - 1];
			int ic = (d - b + 1) * (c - a + 1) - jc - oc;
			sb.append(jc + " " + oc + " " + ic + "\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 27000
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define mod %
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n , m ;
    cin >> n >> m ;
    ll nn = n+2 ,mm = m + 2 ;
    char grid[nn+1][mm+1] , c[n+1][m+1];
    forn(i ,  1,  nn){
       forn(j , 1 , mm){
         grid[i][j] = '#';
       }
    }
    vector<char> v ;
    forn(i  , 1 , n){
       forn(j , 1 , m ) {
         cin >> c[i][j] ;
         v.pb(c[i][j]);
       }
    }
    ll k = 0 ;
    forn(i , 2 , nn-1){
      forn(j , 2 , mm - 1){
         grid[i][j] = v[k++];
      }
    }
    forn(i , 1 , nn ) {
       forn(j , 1 , mm ) {
         cout << grid[i][j] ;
       }
       cout <<el ;
    }
    ro  ;
}































Measured memory_bytes: 384
#include<iostream>

using namespace std;
int main(){
  char b;
  cin>>b;
  if(b=='A'){
    cout<<"T";
  }
  else if(b=='T'){
    cout<<"A";
  }
  else if(b=='C'){
    cout<<"G";
  }
  else{
    cout<<"C";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <map>
using namespace std;

long long H, W, S, T;

int main() {
	cin >> H >> W >> S >> T;
	if ((H*W) % 2 == 0) cout << "Yes" << endl;
	else {
		if ((S + T) % 2 == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		String[] even;
		String[] odd = new String[n / 2];;;
		if (n % 2 == 0)
			even = new String[n / 2];
		else
			even = new String[n / 2 + 1];
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0)
				even[i / 2] = sc.next();
			else
				odd[i / 2] = sc.next();
		}
		if (n % 2 == 0) {
			for (int i = n / 2 - 1; i >= 0; i--)
				out.print(odd[i] + " ");
			for (int i = 0; i < n / 2 - 1; i++)
				out.print(even[i] + " ");
			if (n / 2 - 1 >= 0)
				out.println(even[n / 2 - 1]);
			else
				out.println();
		}
		else {
			for (int i = n / 2; i >= 0; i--)
				out.print(even[i] + " ");
			for (int i = 0; i < n / 2 - 1; i++)
				out.print(odd[i] + " ");
			if (n / 2 - 1 >= 0)
				out.println(odd[n / 2 - 1]);
			else
				out.println();
		}
		out.flush();
	}
}

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

inline ll cntSeq(string s) {
    ll cnt = 0;
    ll num = 0;
    REP(i, s.size() - 1) {
        if (s[i] == s[i + 1]) cnt++;
        else {
            if (cnt > 0) {
                cnt++;
                num += cnt / 2;
            }
            cnt = 0;
        }
    }
    if (cnt > 0) {
        cnt++;
        num += cnt / 2;
    }
    return num;
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s; cin >> s;
    ll n = s.size();
    ll k; cin >> k;

    ll cnt1 = cntSeq(s);
    ll cnt2 = cntSeq(s + s);

    ll cnt = 0;
    REP(i, n - 1)
        if (s[i] == s[i + 1]) cnt++;

    ll res = 0;
    if (cnt == n - 1) res = (n * k) / 2;
    else if (s[0] != s[n - 1]) res = cnt1 * k;
    else {
        if (cnt1 * 2 == cnt2) res = cnt1 * k;
        else {
            res = (cnt2 - cnt1) * (k - 1);
            res += cnt1;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

ll dp[3001][3001][2];
int main()
{
	int n, l, r, A[N];
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> A[i];
		dp[i][i][0] = A[i];
		dp[i][i][1] = -A[i];
	}
	for (int len = 2; len <= n; ++len)
	{
		for (int st = 1; st <= n - len + 1; ++st)
		{
			l = st;
			r = st + len - 1;
			dp[l][r][0] = max(A[l] + dp[l + 1][r][1], A[r] + dp[l][r - 1][1]);
			dp[l][r][1] = min(-A[l] + dp[l + 1][r][0], -A[r] + dp[l][r - 1][0]);
		}
	}
	cout << dp[1][n][0]; 
}


Measured memory_bytes: 139648
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        PriorityQueue<Task> queue = new PriorityQueue<>();
        PriorityQueue<Task> debug = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Task(b[i], a[i], i));
            debug.add(new Task(b[i]-a[i], a[i], i));
        }

//        while (!debug.isEmpty()) {
//            Task t = debug.poll();
//            //System.err.println(t);
//            System.err.println("starttime:"+t.s);
//            System.err.println("length:"+t.l);
//        }

        long time = 0;
        while (!queue.isEmpty()) {
            //System.err.println("time:"+time);
            Task t = queue.poll();
            //System.err.println(t);
            if(time <= t.s-t.l) {
                time += t.l;
            } else {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

class Task implements Comparable<Task> {
    long s, l, i;
    Task(long s, long l, int i) {
        this.s = s;
        this.l = l;
        this.i = i;
    }

    @Override
    public int compareTo(Task o) {
        return this.s != o.s ? Math.toIntExact(this.s - o.s)
                             : Math.toIntExact(this.l - o.l);
    }
    @Override
    public String toString() {
        return String.valueOf(this.i);
    }
}

Measured memory_bytes: 117016
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		HashMap<Integer,Integer>hm = new HashMap<Integer,Integer>();
		ArrayList<Integer>al = new ArrayList<Integer>();
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(hm.containsKey(a)) {
				hm.put(a,hm.get(a)+ b);
			}
			else {
			hm.put(a,b);
			al.add(a);
			}
		}
		Collections.sort(al);
		int num = 0;
		long sum = 0;
		
		for(int i = 0; i < al.size() ; i++) {
			int p = al.get(i);
			num += hm.get(p);
			if(num < m) {
				sum += (long)p * hm.get(p);
			}
			if(num >= m) {
				sum += (long)p * (m - num + hm.get(p));
				break;
			}
				
			}
		System.out.println(sum);
		}
	}

Measured memory_bytes: 99680
n=int(input())
a = list(map(int, input().split()))
b=[int(i) for i in input().split()]
ans=0
for i in range(n):
    if a[i] >= b[i]:
        ans +=b[i]
    else:
        ans+=a[i]
        if a[i]+a[i+1]<b[i]:
            ans+=a[i+1]
            a[i+1]=0
        else:
            ans+=b[i]-a[i]
            a[i+1]=a[i+1]+a[i]-b[i]
print(ans)

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

using namespace std;

inline void quit(){ exit(0); }

typedef long long ll;

ll mpow(ll _x, ll _y, ll _mod){
    if(_y==0) return 1;
    if(_y==1) return _x%_mod;
    if(_y&1) return (mpow(_x, _y-1, _mod)*_x)%_mod;
    ll _tmp = mpow(_x, _y>>1, _mod);
    return (_tmp*_tmp)%_mod;
}

ll a, b;
vector<ll> prime(1, 2);
bool isPrime[1000005];
ll ans=1;


int main(){
    cin>>a>>b;
    a=__gcd(a, b);


    fill(isPrime+2, isPrime+1000001, true);
    for(ll i=4; i<=1000000; i+=2)
        isPrime[i] = false;
    for(ll i=3; i<=1000000; i+=2){
        if(!isPrime[i]) continue;
        prime.push_back(i);
        for(ll j=i*i; j<=1000000; j+=i*2)
            isPrime[j] = false;
    }


    for(int i=0; i<(int)prime.size(); i++){
        ll tmp = prime[i];
        if(a%tmp==0){
            ans++;
            while(a%tmp==0) a/=tmp;
        }
    }
    if(a!=1LL) ans++;
    printf("%lld", ans);
}


Measured memory_bytes: 2424
import math
N=input()

def F(x,y):
	return max( len(str(x)),len(str(y)) )


def div_list(num):
    if num == 1:
        return [1]
    else:
        l = []
        l.append(1)
        for i in range(2, int(math.sqrt(num)) + 1):
            if num % i == 0:
                l.append(i)

        return l

a=div_list(N)

ans=11
for i in a:
	ans=min(ans,F(i,N/i))

print ans




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

int main(void) {

    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    int tmp = 0;
    rep(i,a+1)rep(j,b+1)rep(k,c+1){
        tmp = i*500 + j*100 + k*50;
        if(tmp == x) ans++;
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k){
    cout<<k<<endl;
  }
  else{
    if(a+b>=k){
      cout<<a<<endl;
    }
    else{
      cout<<a+(k-a-b)*(-1)<<endl;
    }
  }
  return(0);
}


Measured memory_bytes: 3624
N, M = [int(i) for i in input().split()]
Pn = [int(i) for i in input().split()]
XYm = [[int(i) for i in input().split()] for _ in range(M)]

class UnionFind:
  def __init__(self, N, arr=None):
    if arr is None:
      self.roots = [-1 for i in range(N)]
      self.ranks = [0 for i in range(N)]
    else:
      self.roots = arr[:]
      self.ranks = [0 for i in range(N)]
            
  def root(self, i):
    root = self.roots[i]
    if root < 0:
      return i
    else:
      return self.root(root)
      
  def union(self, i, j):
    x = self.root(i)
    y = self.root(j)
    if x == y:
      return
    if self.ranks[x] < self.ranks[y]:
      self.roots[x] = y
    else:
      self.roots[y] = x
      if self.ranks[x] == self.ranks[y]:
        self.ranks[x] += 1
  
  def same(self, i, j):
    return self.root(i) == self.root(j)
  
  def get_rank(self, i):
    root = self.root(i)
    return self.ranks[root]
  
uf = UnionFind(N)
for xy in XYm:
  x, y = xy
  uf.union(x-1, y-1)
  
count = 0
for i in range(N):
  count += 1 if uf.same(i, Pn[i]-1) else 0
print(count)



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

int main(){
long N, M;
  cin>>N>>M;
  pair<long, long>P[N];
  for(int i=0; i<N; i++){
   cin>>P[i].first>>P[i].second;}
 
  sort(P, P+N); // pairはP[i].firstを基準にsortされる
    // sort(P, P+N)の形でもsortできる
  
  long sum=0, drink=0;
   for(int i=0; i<N; i++){
     if(drink>=M){break;}
      sum+=P[i].first*min(M-drink, P[i].second);
       drink+=P[i].second; // sum>=Mになればいいのだから、P[i].secondの本数か
   }                // M-drinkの数を掛ければ合計金額が求まる
  
  cout<<sum;
}

Measured memory_bytes: 1792
/*
 * N Q
 * a1 b1
 * ...
 * an-1 bn-1
 * p1 x1
 * ...
 * pq xq
*/

#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <cassert>

using namespace std;
using Graph = vector< vector< int > >;

vector<bool> seen;
vector<long long> scores;
vector<long long> answer;

void dfs(const Graph &g, int i, long long score) {
  seen[i] = true;
  score = score + scores[i];
  answer[i] = score;

  for (auto next_v : g[i]) {
    if (seen[next_v]) continue;

    dfs(g, next_v, score);
  }
}

int main() {
  long long N, Q;
  cin >> N >> Q;

  Graph g(N);
  scores.assign(N, 0);


  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;

    g.at(a - 1).push_back(b - 1);
    g.at(b - 1).push_back(a - 1);
  }

  for (int i = 0; i < Q; i++) {
    int a, b;
    cin >> a >> b;
    scores[a - 1] = scores[a - 1] + b;
  }

  seen.assign(N, false);
  answer.assign(N, 0);

  dfs(g, 0, 0);

  for (int i = 0; i < N; i++) {
    cout << (i == 0 ? "" : " ") << answer[i];
  }

  cout << endl;
}


Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
double fonk(double x, double y){
	return x*x + y*y;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	deque<char> q;
	string s; cin>>s;
	for(int i = 0; i < s.size(); i++){
		q.push_back(s[i]);
	}
	int t; cin>>t;
	bool rev = 0;
	while(t--){
		int type; cin>>type;
		if(type == 1){
			rev ^= 1;
		}else{
			int where; char c; cin>>where>>c;
			where--;
			if(where == 0){
				if(!rev) q.push_front(c);
				else q.push_back(c);
			}else{
				if(!rev) q.push_back(c);
				else q.push_front(c);
			}
		}
	}
	if(!rev){
		while(!q.empty()){
			cout<<q.front();
			q.pop_front();
		}
	}
	else{
		while(!q.empty()){
			cout<<q.back();
			q.pop_back();
		}
	}
}

Measured memory_bytes: 976
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int x1,y1,x2,y2;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	int dx=x2-x1,dy=y2-y1;
	int x3=x2-dy,y3=y2+dx;
	int x4=x1-dy,y4=y1+dx;
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}

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

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

    long A[n+1];
    long B[n];

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

    long sum = 0;

    for (int i = 0; i < n;i++){
        for (int j = 0; j < 2;j++){
            if(B[i] >= A[j+i]){
                B[i] -= A[j+i];
                sum += A[j+i];
                A[j+i] = 0;
            }else{
                sum += B[i];
                A[j+i] -= B[i];
                B[i] = 0;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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


void solve(std::string S)
{
    int ans=0;
    int l=0,r=S.size()-1;
    while(l<r)
    {
        if(S[l]!=S[r])
            ans++;
        l++,r--;
    }
    cout<<ans<<endl;
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans, num, xor, cnt = 0, 0, 0, 0
for i in range(n):
    while cnt < n and (num + a[cnt] == xor ^ a[cnt]):
        num += a[cnt]
        xor ^= a[cnt]
        cnt += 1
    ans += cnt - i
    num -= a[i]
    xor ^= a[i]
print(ans)


Measured memory_bytes: 100904
// By Atul Rathore

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007



int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;

	int n, m, x;
	cin >> n >> m >> x;
	int a[n][m];
	int cost[n];
	f(n)
	{
		cin >> cost[i];
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	int ans = 1000000000;
	for (int i = 0; i < pow(2, n); i++)
	{
		int box[12] = {};
		int sumi[m] = {};
		int sume = 0;
		int j = 11;
		int ure = i;
		while (ure > 0 && j >= 0)
		{
			box[j] = ure % 2;
			ure /= 2;
			j--;
		}
		for (int k = 0; k < n; k++)
		{
			if (box[11 - k] == 1)
			{
				sume += cost[k];
				for (int y = 0; y < m; y++)
				{
					sumi[y] += a[k][y];
				}
			}
		}
		bool ji = true;
		for (int u = 0; u < m; u++)
		{
			if (sumi[u] < x)ji = false;
		}
		if (ji)ans = min(ans, sume);
	}
	if (ans == 1000000000)cout << -1;
	else
	{
		cout << ans;
	}



}


Measured memory_bytes: 4116
from collections import Counter
N = int(input())
blue = Counter([input() for _ in range(N)])
M = int(input())
red = Counter([input() for _ in range(M)])
Max = 0
for key in blue:
    if key in red:
        point = blue[key] - red[key]
    else:
        point = blue[key]
    
    if point>Max:
        Max = point
print(Max)

Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int N=0,M=0,X=0,Y=0;
  cin >> N >> M >> X >> Y;
  int x[N],y[M];
  for(int i=0;i<N;++i) cin >> x[i];
  for(int i=0;i<M;++i) cin >> y[i];
  sort(x,x+N);
  sort(y,y+M);
  if(x[N-1]<y[0]&&X<y[0]&&y[0]<=Y) cout << "No War" << endl;
  else cout << "War" << endl;

  return 0;
}

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

int main()
{
    string s;
    cin>>s;
    ll sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum = sum + s[i]-'0';
    }
    if(sum%9==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 3752
// Problem: C - Dubious Document
// Contest: AtCoder - AtCoder Regular Contest 071
// URL: https://atcoder.jp/contests/arc071/tasks/arc071_a
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6 + 5;

int n;
int m[26];

int32_t main() { cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  memset(m, 0x3f, sizeof m);
  for (int i = 1; i <= n; i++) {
    int c[26];
    memset(c, 0, sizeof c);
    string s;
    cin >> s;
    for (auto& x : s) {
      x -= 'a';
      c[x]++;
    }
    for (int i = 0; i < 26; i++) {
      m[i] = min(m[i], c[i]);
    }
  }
  for (int i = 0; i < 26; i++) {
    for (int j = 1; j <= m[i]; j++) {
      cout << (char)(i + 'a');
    }
  }
}

Measured memory_bytes: 3548
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    int A, B, C, D;
    A = a - '0';
    B = b - '0';
    C = c - '0';
    D = d - '0';

    rep(i, 0, 2) rep(j, 0, 2) rep(k, 0, 2) {
        int a = 0;
        a += A;

        if (i)
            a += B;
        else
            a -= B;
        if (j)
            a += C;
        else
            a -= C;
        if (k)
            a += D;
        else
            a -= D;
        if (a == 7) {
            cout << A << (i ? "+" : "-") << B << (j ? "+" : "-") << C
                 << (k ? "+" : "-") << D << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
def test():

	S = [0]*13
	H = [0]*13
	C = [0]*13
	D = [0]*13

	n = int(input())

	for num in range(n):
		
		card =input().split()
		kind = card[0]
		number = int(card[1])

		if kind == 'S':
			S[number-1] = 1
		elif kind == 'H':
			H[number-1] = 1
		elif kind == 'C':
			C[number-1] = 1
		elif kind == 'D':
			D[number-1] = 1

	for i in range(13):
		if S[i] == 0:
			print(f"S {i+1}")
	for i in range(13):
		if H[i] == 0:
			print(f"H {i+1}")
	for i in range(13):
		if C[i] == 0:
			print(f"C {i+1}")
	for i in range(13):
		if D[i] == 0:
			print(f"D {i+1}")


if __name__ == "__main__":
	test()


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

int main()
{
	int n,sat=0;
	cin>>n;
	int a[n],b[n],c[n-1];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<n;i++)
		cin>>c[i];
	sat=b[a[1]];
	for(int i=2;i<=n;i++)
	{
		sat+=b[a[i]];
		if(a[i]==(a[i-1]+1))	
			sat+=c[a[i]-1];
			
	}	
	cout<<sat<<endl;
	return 0;
}

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

void input(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

llong calcSumOfMultiple(const vector<int>& cnrvnNum)
{
  const int cnnMod = 1e9 + 7;
  llong nCumlSum = 0;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    nCumlSum += cnrvnNum[i];

  llong nSumOfMultpl = 0;

  for (int i = 0; i < cnrvnNum.size() - 1; ++i)
  {
    nCumlSum -= cnrvnNum[i];

    nSumOfMultpl += cnrvnNum[i] * ( nCumlSum % cnnMod );
    nSumOfMultpl %= cnnMod;
  }

  return nSumOfMultpl;
}
  
int main()
{
  vector<int> vnNum;
  
  input(vnNum);
  cout << calcSumOfMultiple(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 4008
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
double pi=3.141592653589793;

const int MOD = 1000000007;

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

vector<ll>G[100004];
vector<ll>memo(100004,-1);
ll dp(ll i){
	if(memo[i]!=-1)return memo[i];
	ll ret=0;
	ll size=G[i].size();
	for(int j=0;j<size;j++){
		ret=max(dp(G[i][j])+1,ret);
	}
	memo[i]=ret;
	return memo[i];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N,M;
	cin>>N>>M;
	vector<ll>inG[N+1];
	for(int i=0;i<M;i++){
		ll x,y;
		cin>>x>>y;
		G[x].push_back(y);
		inG[y].push_back(x);
	}
	ll ans=0;
	for(int i=1;i<=N;i++){
		ans=max(dp(i),ans);
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 13952
import numpy as np

N = int(input())
w = np.array(list(map(int,input().split())))
if N == 2:
    print(abs(w[1] - w[0]))
    exit(0)
res = np.cumsum(w)
s = res[-1]
c = s // 2
n = np.searchsorted(res, c, side='right')
if n == 0:
    ans = s - res[0]
else:
    ans = min(s - 2 * res[n - 1],2 * res[n] - s)
print(ans)

Measured memory_bytes: 12396
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <numeric>
#include <cmath>
#include<algorithm>
using namespace std;

#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i,n) for(int i=0; i<n; i++)
#define max(v) *max_element(all(v))
#define min(v) *min_element(all(v))

//maxを更新しつつ、変わったか返す
template<class T>bool chmax(T &former, const T &b) {if (former<b) {former=b;return true;} return false;}
template<class T>bool chmin(T &former, const T &b) {if (former>b) {former=b;return true;} return false;}

void input_int2(int &a, int &b) {
	cin >> a >> b;
	cin.ignore();
}

void input_int3(int &a, int &b, int &c) {
	cin >> a >> b >> c;	
	cin.ignore();
}

void input_int_array(int n,vector<int> &vec) {
	for (int i=0,tmp=0; i<n && cin >> tmp; i++) vec[i]=tmp;
}

void input_int_matrix(int n, int m, vector<vector<int>> &matrix) {
	int tmp;
	for(int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cin >> tmp;
			matrix[i][j] = tmp;
		}
	}
}

void input_int_var_array(int n,vector<int> &vec) {
	for (int tmp=0; cin >> tmp;) {
		vec.push_back(tmp);
	}
}

void input_int_var_matrix(int n, int m, vector<vector<int>> &matrix) {
	int tmp;
	for(int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cin >> tmp;
			matrix[i][j] = tmp;
		}
	}
}

void input_var_str(vector<string> & array) {
	string s;
	getline(cin, s);
	
	stringstream ss{s};
	while(getline(ss, s, ' ')) {
		array.push_back(s);
	}
}

void input_var_int(vector<int> &array) {
	string s;
	getline(cin, s);
	
	stringstream ss{s};
	while(getline(ss, s, ' ')) {
		array.push_back(stoi(s));
	}
}

void input_var_int(set<int> &array) {
	string s;
	getline(cin, s);
	
	stringstream ss{s};
	while(getline(ss, s, ' ')) {
		array.insert(stoi(s));
	}
}

template <typename T> void print_var_vector(vector<T> vec) {
	for(typename vector<T>::iterator i=begin(vec); i!=end(vec); i++) {
		cout << *i;
	}
	cout << endl;
}

void print_vector(int N, vector<int> vec) {
	for(int i=0; i<N; i++){
		cout << vec[i] << " ";
	}
	cout << endl;
}

int get_max_index(vector<int> vec) {
	vector<int>::iterator it = max_element(vec.begin(), vec.end());
	return distance(vec.begin(), it);
}

int gcd(int a, int b) {
	while(1) {
		if (a<b) swap(a, b);
		if(!b) break;
		a %= b;
	}
	return a;
}

int gcd(const vector<int> &list) {
	int a = list[0];
	for(auto i=1; i<list.size(); i++) {
		a = gcd(a, list[i]);	
	}
	return a;
}

const int MAX_N = 100000;
int N;
vector<int> a;

void input() {
	cin >> N;
	cin.ignore();
	a = vector<int>(N);
	input_int_array(N, a);
}

//単純に1つ消してGCDして、を繰り返すと終わらない。
// 差分計算でGCDを高速に求めたい。
int solve() {
	//あるiに着目すると、全体の最大公約数は、L(i)とR(i)の最大公約数に分解できる
	//L(i)は、i-1までの最大公約数。R(i)は、iからの最大公約数
	//ここでiを消した時の最大公約数はgcd(L(i), R(i+1))である。
	//Lは0から、RはN+1から漸化式が書けそうなので書いてみると
	//L(0)=0
	//L(i+1)=gcd(L(i),A(i))
	//R(N+1)=0
	//R(i)=gcd(R(i+1),A(i))
	vector<int> L(N+1,0), R(N+1,0);
	// 前もってL,Rを計算
	rep(i,N) {
		L[i+1] = gcd(L[i], a[i]);
		R[N-i-1] = gcd(R[(N-i-1)+1], a[N-i-1]);
	}
	//iを消した時のgcdを求めて最大値を取得
	int gcd_max = 0;
	rep(i, N) {
		int gcd_i = gcd(L[i], R[i+1]);
		chmax(gcd_max, gcd_i);
	}
	return gcd_max;
}

int main() {
	input();
	cout << solve() << endl;
}


Measured memory_bytes: 1408
n = int(input())
p = list(map(int, input().split(" ")))

cnt=0
for i in range(1,n-1):
  if p[i-1]<p[i] and p[i]<p[i+1]:
    cnt+=1
  if p[i-1]>p[i] and p[i]>p[i+1]:
  	cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
char a , b ;
cin >> a >> b ;
if (a<b)
{
    cout << "<" ;

}
else if(a>b)
{
    cout << ">" ;
}
else if (a==b)
{
    cout << "=" ;
}
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	priority_queue<ll> que;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		que.push(x);
	}
	for (int i = 0; i < m; i++) {
		ll x = que.top();
		que.pop();
		x /= 2;
		que.push(x);
	}
	ll sum = 0;
	while (!que.empty()) {
		sum += que.top();
		que.pop();
	}
	dump(sum);

	return 0;
}


Measured memory_bytes: 1400
import java.util.ArrayDeque;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}
	static IntStream INS(int n){
		return REPS(n).map(i->getInt());
	}
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	
	public static void main(String[]$){
		ArrayDeque<Integer>b=new ArrayDeque<>();
		boolean reverse=false;
		
		int n=getInt(),ar[]=INS(n).toArray();
		for(int i:ar){
			
			if(reverse)
				b.addLast(i);
			else
				b.addFirst(i);
			
			reverse^=true;
		};
		
		
		StringJoiner sj=new StringJoiner(" ");
		if(reverse) {
			while(!b.isEmpty())
				sj.add(String.valueOf(b.pollFirst()));
		}else {
			while(!b.isEmpty())
				sj.add(String.valueOf(b.pollLast()));
		}
		System.out.println(sj);
	}
}


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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = n - 1; i < (int)n; --i)
#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define RFOR(i, l, r) for (int i = (int)(r); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N;
    cin >> N;
    priority_queue<pair<int, int>> pq;
    REP(i, N) {
        int a;
        cin >> a;
        pq.emplace(a, i);
    }

    vll ans(N, 0);
    ll a, i, cnt = 1; 
    tie(a, i) = pq.top(); pq.pop();
    while (!pq.empty()) {
        ll b, j;
        tie(b, j) = pq.top(); pq.pop();
        ans[i] += (a - b) * cnt++;
        a = b, i = min(i, j);
    }
    ans[i] += a * cnt;

    REP(i, N) cout << ans[i] << endl;
    
    return 0;
}

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

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

int main()
{
    long long N, K;
    cin >> N >> K;
    long long div = 0;
    if(N == K){
        cout << 0 << endl;
    }
    else if(N > K){
        div = N / K;
        N = N - (div * K);
        cout << min(N, abs(N - K)) << endl;
    }
    else{
        cout << min(N, (abs(N - K))) << endl;
    }
}

Measured memory_bytes: 256
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]

dp = [float("INF")] * (H+1)
dp[0] = 0  # 添字：敵HP、　配列の中身：敵HPを削るのに必要な最小のMP

# 配るDP
for h in range(H):
    for a, b in ab:
        target = min(H, h + a)  # target: DPのうち、書き換える部分の添字。Hを超えた部分は考察する必要なし
        dp[target] = min(dp[target], dp[h] + b)

print(dp[-1])

Measured memory_bytes: 44124
#include<stdio.h>
#include<algorithm>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <iostream>
#include <string>
#include <time.h>
#include <functional>
using namespace std;

int dp[1001][1001] = { 0 };
int n, m;
string st1, st2;
int main(void) {
	cin >> st1;
	cin >> st2;
	n = st1.size();
	m = st2.size();
	dp[0][0] = 0;
	for (int i = 0; i <= n; ++i) dp[i][0] = i;
	for (int j = 0; j <= m; ++j) dp[0][j] = j;

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (st1[i - 1] == st2[j - 1]) dp[i][j] = dp[i - 1][j - 1];
			else {
				int	min = dp[i][j - 1] + 1;
				if (min > dp[i - 1][j] + 1) { min = dp[i - 1][j] + 1; }
				if (min > dp[i - 1][j - 1] + 1) { min = dp[i - 1][j - 1] + 1; }
				dp[i][j] = min;
			}
		}
	}
	printf("%d\n", dp[n][m]);
}

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

typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define test cout<<"#"
#define INF 1e9+5
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	ll ar[n][3];
	for(ll x = 0; x < n; x++)
	{
		cin>>ar[x][0]>>ar[x][1]>>ar[x][2];
	}
	
	vector<ll> ans(3);
	ans[0] = ar[0][0], ans[1] = ar[0][1], ans[2] = ar[0][2];
	ll a = ans[0], b = ans[1], c = ans[2];
	for(ll x = 1; x < n; x++)
	{
		ans[0] = ar[x][0] + max(b, c);
		ans[1] = ar[x][1] + max(a, c);
		ans[2] = ar[x][2] + max(a, b);
		a = ans[0], b = ans[1], c = ans[2];
	}
	cout<<max(a,max(b,c));
}

Measured memory_bytes: 2560
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
  vector<int64> a(n);
  int64 ret = 0;
  for (int k = 0; k < 4; ++k) {
    for (int i = 0; i < n; ++i) {
      a[i] = 0;
      if (k & 1) a[i] += x[i];
      else a[i] -= x[i];
      if (k & 2) a[i] += y[i];
      else a[i] -= y[i];
    }
    sort(a.begin(), a.end());
    ret = max(ret, a[n - 1] - a[0]);
  }
  cout << ret << '\n';
  return 0;
}


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

int main(){

  int a[1000]={0},n,temp=0;

  while(cin >> n) a[n]++;

  for(int i=0;i<=100;i++){
    if(temp<a[i]) temp=a[i];
  }

  for(int i=0;i<=100;i++){
    if(temp==a[i]) cout << i << endl;
  }

}

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

list = [list(map(int,input().split())) for i in range(m)]
l = list[0][0]
r = list[0][1]

for i in range(m):
    l = max(l, list[i][0])
    r = min(r, list[i][1])

if l <= r:
    print(r - l + 1)
else:
    print(0)

Measured memory_bytes: 27336
n = gets.chomp.to_i
arr1 = gets.chomp.split(' ')
arr2 = []

(0...n).each do |i|
  arr1[i] = arr1[i].split('')
  arr1[i][1] = arr1[i][1].to_i
  arr2[i] = arr1[i]
end

def is_same?(arr1, arr2, n)
  (0...n).each do |i|
    if arr1[i] != arr2[i]
      return false
    end
  end
  return true
end

def bubble_sort(arr, n)
  swap_times = 0
  flag = true
  i = 0
  while flag && i < n - 1
    flag = false
    j = n - 1
    while j >= i + 1
      if arr[j][1] < arr[j - 1][1]
        swap_times += 1
        tmp = arr[j]
        arr[j] = arr[j - 1]
        arr[j - 1] = tmp
        flag = true
      end
      j -= 1
    end
    i += 1
  end
end

def selection_sort(arr, n)
  swap_times = 0
  (0..n-2).each do |i|
    minj = i
    (i..n-1).each do |j|
      if arr[j][1] < arr[minj][1]
        minj = j
      end
    end
    tmp = arr[i]
    arr[i] = arr[minj]
    arr[minj] = tmp
    if i != minj
      swap_times += 1
    end
  end
end

bubble_sort(arr1, n)
print "#{arr1.map { |obj| obj.join }.join(' ')}\nStable\n"
selection_sort(arr2, n)
print "#{arr2.map { |obj| obj.join }.join(' ')}\n"
if is_same?(arr1, arr2, n)
  print "Stable\n"
else
  print "Not stable\n"
end


Measured memory_bytes: 6908
n = int(input())
a = [input().split() for i in range(n)]
b = [[a[i][0],int(a[i][1]),i+1]for i in range(n)]
b.sort(key=lambda b:(b[0],-b[1]))
print(*[b[i][2] for i in range(n)],sep="\n")

Measured memory_bytes: 3060
from collections import deque

def main():
    N,M=map(int,input().split())
    x = [tuple(map(int,input().split())) for i in range(M)]
    
    for i in range(0,1001):
        i = str(i)
        if len(i)==N:
            if all([i[t[0]-1]==str(t[1]) for t in x]):
                print(i)
                exit() 
    print(-1)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3316
class BST:
  def __init__(self):
    self.root = None
  
  def insert(self, data):
    z = Node(data)
    y = None
    x = self.root

    while x:
      y = x
      if z.data < x.data:
        x = x.left
      else:
        x = x.right
    z.parent = y
    if y == None:
      self.root = z
    elif z.data < y.data:
      y.left = z
    else:
      y.right = z

  def print(self):
    print('',' '.join(map(str, self.root.inorder())))
    print('',' '.join(map(str, self.root.preorder())))


class Node():
  def __init__(self, data):
    self.data = data
    self.left, self.right = None, None

  def inorder(self):
    in_list = []
    if self.left:
      in_list += self.left.inorder()
    in_list += [self.data]
    if self.right:
      in_list += self.right.inorder()
    return in_list
  
  def preorder(self):
    pre_list = []
    pre_list += [self.data]
    if self.left:
      pre_list += self.left.preorder()
    #pre_list += [self.data]
    if self.right:
      pre_list += self.right.preorder()
    return pre_list

tree = BST()
n = int(input())
for _ in range(n):
  inp = input().split()
  if len(inp) == 2:
    tree.insert(int(inp[1]))
  else:
    tree.print()



Measured memory_bytes: 141444