akhauriyash/Code-Regression huggingface dataset:
//ProblemA.cpp

#include <iostream>

static std::istream & ip = std::cin;
static std::ostream & op = std::cout;

#if OJ_MYPC
#include <ojio.h>
#endif

#ifndef OPENOJIO
#define OPENOJIO
#endif

#if 1 || DEFINE
/***************************************************************/
typedef unsigned long long u64;
typedef long long s64;

typedef unsigned uint;

#define ABS(x) ((x) > 0 ? (x) : -(x))

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define MIN3(x, y, z) MIN(x, MIN(y, z))
#define MAX3(x, y, z) MAX(x, MAX(y, z))

#define FillZero(arr) memset(arr, 0, sizeof(arr));

/***************************************************************/
#endif //1 || DEFINE

#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>

//001
//op << setfill('0') << setw(3) << setiosflags(ios::right) << 1;

//op << fixed << setprecision(20);

using namespace std;

//ProblemA.cpp

int main(int argc, char* argv[])
{
	OPENOJIO;

	string s;
	ip >> s;

	for (int i = 0; i < 4; ++i)
		op << s[i];
	op << ' ';
	for (int i = 4; i < s.size(); ++i)
		op << s[i];
	op << endl;
	return 0;
}
/***************************************************************/


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 110;

int n[3], p[3];
char ch[3][N];

int main() {
    for (int i = 0; i < 3; ++i) {
        scanf("%s", ch[i] + 1);
        n[i] = strlen(ch[i] + 1);
    }
    for (int i = 0; ; i = ch[i][++p[i]] - 97)
        if (p[i] == n[i]) {
            putchar(i + 65);
            putchar('\n');
            return 0;
        }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a_li = list(map(int, input().split()))
# すべてのaを2で割る
a_li = [a // 2 for a in a_li]

from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

def count_div_2(a):
    cnt = 0
    while a % 2 == 0:
        a = a // 2
        cnt += 1
    return cnt

# a_lcm: aの最小公倍数, parity: すべてのaの偶奇性, cnt_div: すべてのaの2で割れる回数
a_lcm = 1
cnt_div = count_div_2(a_li[0])

# a_lcmを求める
flag = False
for a in a_li:
    a_lcm = lcm(a, a_lcm)
    # 偶奇が不一致、またはa_lcmがm以上の場合答えなし
    if cnt_div != count_div_2(a) or a_lcm > m:
        flag = True
        break

# 先程弾いた場合以外で答えを出す
if flag:
    ans = 0
else:
    ans = m // a_lcm
    ans = ans // 2 + ans % 2

print(ans)


Measured memory_bytes: 14356
import math
in_line = raw_input().split()
a = float(in_line[0])
b = float(in_line[1])
c = float(in_line[2])
print 0.5*a*b*math.sin(math.radians(c))
print a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(c)))
print b*math.sin(math.radians(c))

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

int main()
{
    
    /*
    string s1;
    getline( cin, s1 );
    int n1 = s1.size();
    */
    int a,b;
    cin >> a >> b ;
    
    cout << a*b << endl;
      
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 100005

int main()
{
    int n;
    cin>>n;
    int ara[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
        if(ara[i]%2==0 && ara[i]%3!=0 && ara[i]%5!=0)
        {
            cout<<"DENIED"<<endl;
            return 0;
        }
    }
    cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define N 100

static int d[ N + 1 ][ N + 1 ];
static int m[ N + 1 ];
static int l[ N + 1 ];
static int k;

int
main (
  void
  )
{
  int i, j;

  for ( ; ; )
  {
    int res = 0;
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    memset ( d, 0, sizeof ( d ) );
    for ( i = 1; i <= n; ++i )
    {
      scanf ( "%d", &m[ i ] );

      for ( j = 0; j < m[ i ]; ++j )
      {
        int t;

        scanf ( "%d", &t );
        d[ i ][ t ] = 1;
      }
    }
    scanf ( "%d", &k );
    for ( i = 0; i < k; ++i )
    {
      scanf ( "%d", &l[ i ] );
    }

    for ( i = 1; i <= n; ++i )
    {
      for ( j = 0; j < k; ++j )
      {
        if ( !d[ i ][ l[ j ] ] ) break ;
      }
      if ( j == k )
      {
        if ( res )
        {
          res = 0;
          break ;
        }
        else
        {
          res = i;
        }
      }
    }

    printf ( "%d\n", res ? res : -1 );
  }


  return ( 0 );
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    string x;
    cin >> x;
    stack<char> st;
    rep(i, x.length()) {
        if ( st.empty() || st.top() == 'T' ) {
            st.push(x[i]);
        }
        else {
            if ( x[i] == 'T' ) {
                st.pop();
            }
            else {
                st.push(x[i]);
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 644
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define NUM_MAX 100000
#define BUF_SIZE (NUM_MAX*7+50)

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

struct ufind {
    int parent;
    int depth;
};

struct ufind *create_ufind(int vs) {
    struct ufind *ufind = malloc(vs * sizeof(struct ufind));
    int i;
    for(i = 0; i < vs; i++) {
        ufind[i].parent = i;
        ufind[i].depth = 0;
    }
    return ufind;
}

int find_root(struct ufind *ufind, int v) {
    struct ufind *elem = &ufind[v];
    int base = v;
    while(base != elem->parent) {
        base = elem->parent;
        elem = &ufind[base];
    }
    return base;
}

int is_connect(struct ufind *ufind, int v1, int v2) {
    int bv1 = find_root(ufind, v1);
    int bv2 = find_root(ufind, v2);
    return bv1 == bv2;
}

void unify(struct ufind *ufind, int v1, int v2) {
    int bv1 = find_root(ufind, v1);
    int bv2 = find_root(ufind, v2);
    struct ufind *uv1 = &ufind[bv1];
    struct ufind *uv2 = &ufind[bv2];
    if(uv1->depth >= uv2->depth) {
        if(uv1->depth == uv2->depth) uv1->depth++;
        uv2->depth = uv1->depth;
        uv2->parent = uv1->parent;
    } else {
        uv1->depth = uv2->depth;
        uv1->parent = uv2->parent;
    }
    return;
}

int main(void) {
    int num, queries;
    int arr[NUM_MAX];
    get_int2(&num, &queries);
    fget_array(arr, num);
    int i;
    for(i = 0; i < num; i++) arr[i]--;
    struct ufind *ufind = create_ufind(num);
    for(i = 0; i < queries; i++) {
        int x, y;
        get_int2(&x, &y);
        // 1-indexed -> 0-indexed
        x--; y--;
        if(!is_connect(ufind, x, y)) {
            unify(ufind, x, y);
        }
    }

    int cnt = 0;
    for(i = 0; i < num; i++) {
        // i -> arr[i]?
        cnt += is_connect(ufind, i, arr[i]);
    }
    printf("%d\n", cnt);

    return 0;
}

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

void printArray(int arr[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i) cout << " ";
        cout << arr[i];
    }
    cout << endl;
}

void bubbleSort(int arr[], int N, int &cnt) {
    bool done = false;
    while (!done) {
        done = true;
        for (int i = N-1; i > 0; --i) {
            int tmp = arr[i];
            if (arr[i-1] > arr[i]) {
                arr[i] = arr[i-1];
                arr[i-1] = tmp;
                done = false; 
                cnt++;
            }
        }
    }
}

int main() {
    int N; cin >> N;
    int cnt = 0;
    int arr[100];
    for (int i = 0; i < N; ++i) cin >> arr[i];

    bubbleSort(arr, N, cnt);
    printArray(arr, N);
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int b[32 + 1];
int ans[32 + 1];

int main()
{
  memset(b, 0, sizeof b);

  int N; scanf("%d", &N);
  bool minus = N < 0;

  if (minus) N = -N;

  int idx = 0;
  while (N > 0) {
    if (N & 1) b[idx++] = 1;
    else b[idx++] = 0;
    N >>= 1;
  }

  ans[0] = b[0];
  int carry = 0;
  for (int i = 1; i <= 32; i++) {
    if ((minus && i % 2 == 1) || (!minus && i % 2 == 0)) {
      ans[i] = b[i] + ans[i - 1] + carry;
      // printf("ans[%d]=(b[%d]=%d)+(b[%d]=%d)+(carry=%d)=%d\n",
      //        i, i, b[i], i - 1, b[i - 1], carry, ans[i]);
    }
    else {
      ans[i] = b[i] + carry;
      // printf("ans[%d]=(b[%d]=%d)+(carry=%d)=%d\n",
      //        i, i, b[i], carry, ans[i]);
    }

    if (ans[i] > 1) {
      carry = 1;
      ans[i] %= 2;
    }
    else {
      carry = 0;
    }
  }

  {
    int j = 32;
    for (;j >= 0 && ans[j] == 0; j--);

    if (j < 0) printf("0");
    else {
      for (;j >= 0; j--) printf("%d", ans[j]);
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
using System;

namespace AIDU {
   class AIZU0048
    {
      static string[] hierarchy = {
         "light fly","fly","bantam","feather",
         "light","light welter","welter","light middle",
         "middle","light heavy","heavy"
         };
      static double[] threshold= { 48d,51d,54d,57d,60d,64d,69d,75d,81d,91d};
      public static void Main() {
         string s;   double d;   int c;
         while (true) { s=Console.ReadLine();
            if (string.IsNullOrEmpty(s)) break;
            d=double.Parse(s);
            c=Array.BinarySearch(threshold,d);
            if (c<0) c=-c-1;
            Console.WriteLine(hierarchy[c]);
         }
      }
   }
}

Measured memory_bytes: 9640
string = input()
num = int(input())
o = 0
for _ in range(num):
    source = input().split(' ')
    if source[0] == 'print':
        print(string[int(source[1]):int(source[2]) + 1])
    elif source[0] == 'replace':
        string = string[:int(source[1])] + source[3] + string[int(source[2]) + 1:]
    else:
        string = string[:int(source[1])] + string[int(source[1]):int(source[2]) + 1 ][::-1] + string[int(source[2]) + 1:]


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

#define gc() getchar()

#define ri register int 

using std::max;

inline int read()
{
	int ret=0;char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))
	{
		ret=ret*10+ch-'0';
		ch=gc();
	}
	return ret;
}

const int MAXN=2e5+10;

int n,d;
int a[MAXN],b[MAXN],c[MAXN];
int l[MAXN],r[MAXN];

int main()
{
//	freopen("in.in","r",stdin);
	
	n=read();
	
	memset(r,-1,sizeof(r));
	memset(l,-1,sizeof(l));
	for(ri i=0;i<n;++i)
	{
		a[i]=read();
		r[a[i]]=i;
	}
	for(ri i=0;i<n;++i)
	{
		b[i]=read();
		if(l[b[i]]==-1)l[b[i]]=i;
	}
	
	for(ri i=1;i<=n;++i)if(l[i]!=-1 && r[i]!=-1)
		d=max(d,r[i]-l[i]+1);
	
	for(ri i=0;i<n;++i)
	{
		c[(i+d)%n]=b[i];
		if(a[(i+d)%n]==c[(i+d)%n])
		{
			printf("No\n");
			return 0;
		}
	}
	
	printf("Yes\n");
	for(ri i=0;i<n;++i)printf("%d ",c[i]);
	
	return 0;
}

Measured memory_bytes: 7532
#include <iostream>
#include <functional>
#include <vector>
#define int long long
using namespace std;

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> ws;
  for(int i = 0; i < n; ++i) {
    int w;
    cin >> w;
    ws.push_back(w);
  }
  function<bool(int)> isLoadable = [&](int p) {
    int iw = 0;
    for(int itrack = 0; itrack < k; ++itrack) {
      int track = 0;
      while(true) {
        track += ws[iw];
        if(track > p) break;
        ++iw;
        if(iw >= n) return true;
      }
    }
    return false;
  };
  int left = 0;
  int right = 100000 * 10000;
  int mid;
  while(right - left > 1) {
    mid = (left + right) / 2;
    (isLoadable(mid) ? right : left) = mid;
  }
  cout << right << endl;
  return 0;
}

Measured memory_bytes: 2068
#include <iostream>
constexpr int NUM = 7368792;
bool number[NUM];
int main()
{
	int m, n;
	while (std::cin >> m >> n && n && m) {
		for (int i = 0; i < NUM; i++) number[i] = true;
		for (int i = 0; i < n + 1; i++) {
			while (!number[m++]) {}
			number[--m] = 0;
			int year = m;
			while ((year += m) < NUM) number[year] = 0;
		}
		std::cout << m << std::endl;
	}
	return 0;
}

Measured memory_bytes: 10208
/**
 *      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 <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = 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'
// 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;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

template<typename T> std::vector<T> divisor(T n) {
  std::vector<T> res;
  for (T i = 1; i * i <= n; ++i) {
    if (n % i == 0){
      res.push_back(i);
      if (i * i != n){
        res.push_back(n / i);
      }
    }
  }
  std::sort(res.begin(), res.end());

  return res;
}

template<typename T> T gcd(T x, T y) {
  while (y > 0){
    T tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}

template<typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0) return 0;
  else return x * y / gcd(x, y);
}

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

  int64 a, b; cin >> a >> b;
  vector<int64> v1 = divisor(a);
  vector<int64> v2 = divisor(b);

  vector<int64> vec;
  for (int i = 0; i < (int) v1.size(); ++i) {
    if (binary_search(all(v2), v1[i])) {
      vec.emplace_back(v1[i]);
    };
  }

  int64 ans = 0;

  int n = vec.size();
  vector<int64> temp;
  temp.emplace_back(1);

  rep(i, n) {
    bool ok = true;
    if (any_of(all(temp), [&](int64 x){ return gcd(vec[i], x) != 1; })) {
      ok = false;
    }

    if (ok) {
      temp.emplace_back(vec[i]);
    }
  }
  cout << temp.size() - 1 << endl;

  return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strArray;
    int a , b;
    String op;
    String line;
    StringBuilder output = new StringBuilder();
    while (true) {
      line = br.readLine();
      strArray = line.split(" ");
      op = strArray[1];
      a = Integer.parseInt(strArray[0]);
      b = Integer.parseInt(strArray[2]);
      if (op.equals("+")) {
        output.append(Integer.toString(a + b)).append("\n");
      }
      else if (op.equals("-")) {
        output.append(Integer.toString(a - b)).append("\n");
      }
      else if (op.equals("*")) {
        output.append(Integer.toString(a * b)).append("\n");
      }
      else if (op.equals("/")) {
        output.append(Integer.toString(a / b)).append("\n");
      }
      else if (op.equals("?")) {
        break;
      }
    }
    System.out.print(output);
  }
}

Measured memory_bytes: 24120
import Control.Monad
import Data.Maybe

index :: [a] -> Int -> Maybe a
index xs = (\i -> do
    guard (0 <= i && i < n)
    return (xs !! i)
    )
    where
        n = length xs

index2 :: [[a]] -> Int -> Int -> Maybe a
index2 s i j= do
    row <- s `index` i
    elment <- row `index` j
    return elment

judge :: [[Char]] -> Int -> Int -> Bool
judge s i j =  canBlackPaint || canWhitePaint
    where
        up      = index2 s (i-1) j
        down    = index2 s (i+1) j
        left    = index2 s i (j-1)
        right   = index2 s i (j+1)
        aroundN = length . filter (== '#') . catMaybes $ [up, down, left, right]
        middle  = index2 s i j
        canBlackPaint = maybe False (== '#') middle && 1 <= aroundN
        canWhitePaint = maybe False (== '.') middle
        
main = do
    [h,w] <- map read . words <$> getLine
    s <- replicateM h getLine
    grid <- forM [0..(h-1)] (\i -> do 
        row <- forM [0..(w-1)] (\j -> do
            return $ judge s i j
            )
        return row
        )
    let isYes = and . map and $ grid
    if isYes then putStrLn "Yes" else putStrLn "No" 

Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, T; cin >> N >> T;
    vector<int> X;
    for (int i = 0; i < N; i++) {
        int t; cin >> t; X.push_back(t);
    }
    int ans = 0;
    for (int i = 1; i < N; i++) {
        ans += min(T, X[i] - X[i-1]);
    }
    ans += T;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <stack>
#include <queue>
using namespace std;

int main(){
    int H, W;
    char a[110][110];
    set<int> Hbacket;
    set<int> Wbacket;
    bool Wflag, Hflag;

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

    for(int i = 0 ; i < H ; ++i){
        Wflag = false;
        for(int j = 0; j < W; ++j){
            if(a[i][j] == '#'){
                Wflag = true;
            }
            if(Wflag){
                Wbacket.insert(j);
            }
            Wflag = false;
        }
    }

    for(int j = 0 ; j < W ; ++j){
        Hflag = false;
        for(int i = 0; i < H; ++i){
            if(a[i][j] == '#'){
                Hflag = true;
            }
            if(Hflag){
                Hbacket.insert(i);
            }
            Hflag = false;
        }
    }

    for(int i = 0 ; i < H; ++i){
        if(!Hbacket.count(i)){
            continue;
        }
        for(int j = 0; j < W; ++j){
           if(!Wbacket.count(j)){
               continue;
           }
           cout << a[i][j]; 
        }
        cout << endl;
    }  

}

Measured memory_bytes: 256
##### 解けた #####

# 順序を修正した番号を返す
def cardwo(c):
    return c+int(c==1)*20

A,B=list(map(int,input().split(" ")))
A,B=cardwo(A),cardwo(B) # 順序を修正した強さ

if A>B: # Aliceの方が強い場合
    print("Alice")
elif A<B: # Bobの方が強い場合
    print("Bob")
else: # 引き分けの場合
    print("Draw")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector <int> h(N);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    
    int ans = 0, active = 0;

    for(int i = 0; i < N; i++){
        if (active <= h[i]) {
            ans += h[i] - active;
            active = h[i];
        }else{
            active = h[i];
        }
    }

    cout << ans << endl;

    return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, sum = 0;
    cin >> n;
    vi a(n+1, 0);
    rep(i, n+1) cin >> a[i];
    rep(i, n){
        lli b;
        cin >> b;
        // iの街
        if(a[i] >= b){
            a[i] -= b;
            sum += b;
            b = 0;
        }
        else{
            sum += a[i];
            b -= a[i];
            a[i] = 0;
        }
        // i+1の街
        if(a[i+1] >= b){
            a[i+1] -= b;
            sum += b;
        }
        else{
            sum += a[i+1];
            a[i+1] = 0;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
import math
X, K, D = map(int, input().split())
ans = 10**16
minc_floor = math.floor(abs(X)/D)
minc_ceil = math.ceil(abs(X)/D)
min_kaisuu = K
# print(minc_ceil, minc_floor)
if minc_ceil <= K:
    for k in range(minc_floor, minc_ceil+1):
        for flug in [-1, 1]:
            if abs(X + flug*k*D) < abs(ans):
                ans = abs(X + flug*k*D)

                # print("ans" + str(ans))
                min_kaisuu = k
                # print(min_kaisuu)
    if (K-min_kaisuu) % 2 != 0:
        ans = min(abs(ans+D), abs(ans-D))
else:
    # ans = min(ans+K*D), abs(ans-K*D))
    if abs(X+K*D) > abs(X-K*D):
        ans = X-K*D
    else:
        ans = X+K*D
# print(min_kaisuu)
print(abs(ans))


Measured memory_bytes: 9156
#include <stdio.h>

int main(void)
{
    float a[8];
    int i, j, n;
    scanf("%d", &n);

    for(j=0; j<n; j++) {
        for(i=0; i<8; i++) scanf("%f", &a[i]);
        if((a[1]-a[3])/(a[0]-a[2]) == (a[5]-a[7])/(a[4]-a[6]))
            puts("YES");
        else
            puts("NO");
    }

    return (0);
}

Measured memory_bytes: 616
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val X, Y = in.next().toInt

  val MOD = 1e9.toInt + 7
  def repeatSquares(x: Long, n: Long): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % MOD, n/2)
    else
      (x * repeatSquares(x*x % MOD, n/2)) % MOD
  }

  val b = ((2.0 / 3) * Y - (1.0 / 3) * X).round.toInt
  val w = ((2.0 / 3) * X - (1.0 / 3) * Y).round.toInt



  def fact(n: Int, res: Long): Long = {
    if (n == 1)
      res
    else {
      fact(n-1, (res * n) % MOD)
    }
  }

  var ba = 1L
  var wa = 1L

  def factInv(n: Int, res: Long): Unit = {
    if(n == 0)
      ()
    else {
      if (n == b)
        ba = res
      if (n == w)
        wa = res

      factInv(n-1, (res * n) % MOD)
    }
  }

  if (b >= 0 && w >= 0 && b + 2*w == X && 2*b + w == Y) {

    var ans: Long = fact(w+b, 1L)
    factInv(b+w, repeatSquares(ans, MOD-2))
    ans *= ba
    ans %= MOD
    ans *= wa
    ans %= MOD


    println(ans)
  }
  else {
    println(0)
  }
}

// class ModComb(maxNum: Int, mod: Long) {

  // private def repeatSquares(x: Long, n: Long): Long = {
  //   if(n == 0)
  //     1
  //   else if(n % 2 == 0)
  //     repeatSquares(x*x % mod, n/2)
  //   else
  //     (x * repeatSquares(x*x % mod, n/2)) % mod
  // }

//   val fact = new Array[Long](maxNum + 1)

//   fact(0) = 1
//   for (i <- 1 to maxNum)
//     fact(i) = (i * fact(i-1)) % mod

//   val factInv = new Array[Long](maxNum + 1)



//   // nCk
//   def comb(n: Int, k: Int): Long = {
//     val numer = fact(n)
//     val denom = (factInv(n-k) * factInv(k)) % mod

//     (numer * denom) % mod
//   }

// }


object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 27080
#include <stdio.h>
#include <set>
#include <utility>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, now = 0;
  scanf("%lld", &n);
  ll a[3 * n], ans, an[n + 1];
  set< pair<ll, ll> > s, s2;
  set< pair<ll, ll> >::iterator it;
  pair<ll, ll> p, t;
  for(i = 0; i < 3 * n; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < 2 * n; ++i) s.insert(make_pair(a[i], i));
  it = s.end();
  it--;
  for(i = 0; i < n; ++i, --it) now += (*it).first, p = *it;
  an[n] = now;
  for(i = 2 * n - 1; i >= n; --i) {
    t = make_pair(a[i], i);
    if(t >= p) {
      it = s.find(p);
      it--;
      p = *it;
      now -= a[i], now += p.first;
    }
    s.erase(s.find(t));
    an[i - n] = now;
  }
  now = 0;
  for(i = n; i < 3 * n; ++i) s2.insert(make_pair(a[i], i));
  for(it = s2.begin(), i = 0; i < n; ++i, ++it) now += (*it).first, p = *it;
  ans = an[0] - now;
  for(i = n; i < 2 * n; ++i) {
    t = make_pair(a[i], i);
    if(t <= p) {
      it = s2.find(p);
      it++;
      p = *it;
      now -= a[i], now += p.first;
    }
    s2.erase(s2.find(t));
    if(ans < an[i - n + 1] - now) ans = an[i - n + 1] - now;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 22144
/**

  @@@@@@@  @@@@  @@@@  @@@@  @@@@  @ 
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @@@@  @@@@  @@@@  @  @  @

**/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define str string
#define pi pair
#define tup tuple
#define vec vector
#define temp template
#define tn typename

#define ff first
#define ss second
#define SZ(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define fr front 
#define bc back
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk make_pair

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++) 
#define ROF(i, a, b) for (ll i = (a); i >= (b); i--)
#define trav(a, x) for (auto &a : x)
#define popcount __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
#define gcd __gcd

// DEBUG
#define ts to_string
temp<tn A, tn B> str ts(pi<A, B> p);
temp<tn A, tn B, tn C> str ts(tup<A, B, C> p);
str ts(const str& s) { return '"' + s + '"'; }
str ts(const char* s) { return ts((str) s); }
str ts(bool b) { return (b ? "true" : "false"); }
str ts(vec<bool> v) { bool f = true; str res = "{";
FOR(i, 0, static_cast<ll>(v.size()) - 1) 
{ if (!f) res += ", "; res += ts(v[i]);
f = false; } res += "}"; return res; }
temp<size_t N> str ts(bitset<N> v) { str res = "";
trav(a, v) { res += (char) ('0' + a); } return res; }
temp<tn A> str ts(A v) { bool f = true; str res = "{";
trav(x, v) { if (!f) res += ", "; res += ts(x);
f = false; } res += "}"; return res; }
temp<tn A, tn B> str ts(pi<A, B> p) { 
  return "(" + ts(p.ff) + ", " + ts(p.ss) + ")"; }
temp<tn A, tn B, tn C> str ts(tup<A, B, C> t) {
  return "(" + ts(get<0>(t)) + ", " + ts(get<1>(t)) + ", " + ts(get<2>(t)) + ")"; }
void DBG() { cerr << endl; }
temp<tn H, tn... T> void DBG(H h, T... t) { cerr << " " << ts(h); DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", DBG(__VA_ARGS__);

// INPUT AND OUTPUT
temp<tn T> void re(T& x) { cin >> x; };
temp<tn H, tn... T> void re(H& h, T&... t) { re(h); re(t...); }
temp<tn T> void pr(T x) { cout << x; };
temp<tn H, tn... T> void pr(H h, T... t) { pr(h); pr(t...); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h1, m1, h2, m2, k;
  re(h1, m1, h2, m2, k);
  ll x = h2 * 60 + m2 - (h1 * 60 + m1);
  pr(x - k, '\n');
  return 0;
}

Measured memory_bytes: 3612
n,d = map(int,input().split())
lid,a,dis,b = [],0,[],[]
import itertools
for i in range(n):
    lid.append(list(map(int, input().split())))

dis = list(itertools.combinations(lid,2))

for i in range(len(dis)):
    for j in range(d):
        a += (dis[i][0][j]-dis[i][1][j])**2
        #print(a)
    a = a**0.5
    b.append(a)  
    a = 0
    
ans = 0
for i in range(len(b)):
    if b[i]%1 == 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='+')ans++;
        else ans--;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
import numpy as np
import copy
D = int(input())
c_list = np.array(list(map(int,input().split())))
s_list = [list(map(int,input().split())) for _ in range(D)]
last_d_list = np.array([0]*26)
s_max_list = [np.argmax(s_row) for s_row in s_list]

for day,s_row in enumerate(s_list):
    choice_d = None
    max_reward = -1
    for i,last_d in enumerate(last_d_list):
        reward = s_row[i] + (last_d+1)*c_list[i]# - sum(c_list)
        next_max_reward = -1
        for j,new_last_d in enumerate(last_d_list):
            if day+1==len(s_list):
                break
            if j!=i:
                next_reward = s_list[day+1][j] + (new_last_d+2)*c_list[j]
            else:
                next_reward = s_list[day+1][j] + c_list[j]
            if next_reward > next_max_reward:
                next_max_reward = next_reward
        reward += next_max_reward
        if reward > max_reward:
            max_reward = reward
            choice_d = i
    last_d_list+=1
    last_d_list[choice_d] = 0
    
    print(choice_d+1)
    

Measured memory_bytes: 27440
(* O(n^2) *)
let f () = Scanf.scanf " %d" @@ (+) 0
let n = f ()
let a_ss = Array.init 2 @@ fun _ -> Array.init n @@ fun _ -> f ()
let ans = ref 0
let _ =
  for i = 0 to n - 1 do
    let s1 = Array.sub a_ss.(0) 0 @@ i + 1 |> Array.fold_left (+) 0 in
    let s2 = Array.sub a_ss.(1) i @@ n - i |> Array.fold_left (+) 0 in
    ans := max !ans @@ s1 + s2
  done;
  Printf.printf "%d\n" !ans

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

ll solve() {
    ll INF = 1LL<<60;
    ll N, M;
    cin >> N >> M;
    vector<ll> L(M), R(M), C(M);
    //vector<pii> ri;
    vector<pii> li;
    for ( int i = 0; i < M; i++ ) {
        cin >> L[i] >> R[i] >> C[i];
        L[i]--, R[i]--;
        li.push_back(pii(L[i], i));
    }
    sort(li.begin(), li.end());
    priority_queue<pii, vector<pii>, greater<>> q;  //dp[L]+C,R
    int ii = 0;
    vector<ll> dp(N+1, INF);
    q.push(pii(0,0));
    for ( ll l = 0; l < N; l++ ) {
        while ( !q.empty() && q.top().second < l ) q.pop();
        if ( q.empty() ) return -1;
        dp[l] = q.top().first;
        while ( !q.empty() && q.top().second <= l ) q.pop();
        while ( ii < M && li[ii].first == l ) {
            int j = li[ii].second;
            q.push(pii(dp[l]+C[j], R[j]));
            ii++;
        }
    }
    if ( dp[N-1] == INF ) return -1;
    return dp[N-1];
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7792
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) {
		Input input = new Input();
		Converter conv = new Converter(); 
		
		int a = conv.intconv(input.input());
		int b = conv.intconv(input.input());
		int c = conv.intconv(input.input());
		
		System.out.println((a+b)*c/2);

	
	}
}




class Input{
	private String buf;
	BufferedReader bufferdReader = new BufferedReader(new InputStreamReader(System.in));
	
	public String input() {
	try{
		this.buf = bufferdReader.readLine();
	}catch(Exception e) {
		
	}
	return buf;
	}
}


class Converter{
	
	private int convInt=0;
	
	
	/**
	 * String→Int変換機
	 * @param convInt
	 * @return this.convInt
	 */
	public int intconv(String convInt){
		this.convInt = Integer.parseInt(convInt);
		return this.convInt;
	}
	
}

Measured memory_bytes: 32640
n, m = gets.strip.split("\s").map(&:to_i)
ac = Array.new(n, 0)
wa = Array.new(n, 0)

m.times do
  p, s = gets.strip.split("\s")
  next if ac[p.to_i - 1] >= 1
  
  if s == 'AC'
    ac[p.to_i - 1] += 1
  elsif s == 'WA'
    wa[p.to_i - 1] += 1
  end
end

acs = 0
was = 0
ac.each_with_index do |a, i|
  if a > 0
    acs += 1
    was += wa[i]
  end
end

print "#{acs} #{was}"


Measured memory_bytes: 3324
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define IMX INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
LL ans;
bool dd[15];
int ll;
char c[15];
void gen(int lv)
{
    if(lv==ll)
    {
        LL k=0;
        for(int i=1;i<=ll;i++)
        {
            k*=10;
            k+=c[i]-'0';
            if(dd[i])ans+=k,k=0;
        }
        ans+=k;
    }
    else
    {
        for(int i=0;i<=1;i++)
        {
            dd[lv]=i;
            gen(lv+1);
        }
    }
    return;
}
int main()
{
    scanf("%s",c+1);
    ll=strlen(c+1);
    gen(1);
    printf("%lld",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll n, mi = 1e+18;
    cin >> n;
    rep(i, 5){
        ll a;
        cin >> a;
        mi = min(mi, a);
    }

    cout << (n - 1 + mi) / mi + 4 << endl;

}

Measured memory_bytes: 256
def main():
    A, B, K = map(int, input().split())
    if K > A:
        K -= A
        A = 0
        if K > B:
            K -= B
            B = 0
            print(A, B)
        else:
            B -= K
            print(A, B)
    else:
        A -= K
        print(A, B)
main()

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX_M = 2e+5+10, MAX_Q = 1e+5+10, MAX_N = 500+10;

int main(int argc, char const *argv[]) {
  int n, m, Q, l[MAX_M], r[MAX_M], p[MAX_Q], q[MAX_Q], x[MAX_N][MAX_N]={0}, c[MAX_N][MAX_N]={0};
  cin >> n >> m >> Q;
  for (ll i = 0; i < m; i++) cin >> l[i] >> r[i];

  for (ll i = 0; i < Q; i++) cin >> p[i] >> q[i];
  for (ll i = 0; i < m; i++) x[l[i]][r[i]]++;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      c[i][j] = c[i][j-1] + x[i][j];
    }
  }
  for (int i = 0; i < Q; i++) {
    ll sum = 0;
    for (int j = p[i]; j <= q[i]; j++) sum += c[j][q[i]] - c[j][p[i]-1];
    cout << sum << endl;
  }
  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> x(N), y(N);
	unordered_map<int, unordered_set<int>> pos;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
		pos[x[i]].insert(y[i]);
	}
	int res = N;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int dx = x[j] - x[i], dy = y[j] - y[i];
			int cnt = 0;
			for (int k = 0; k < N; k++) {
				cnt += !(pos.count(x[k] + dx) && pos[x[k] + dx].count(y[k] + dy));
			}
			res = min(res, cnt);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, T; cin >> N >> T;
    vector<LLONG> As(N); for (auto &Ai : As) cin >> Ai;
    map<LLONG, int> diff2PairNumMap;
    LLONG minAi = As[0];
    // 各街において，それ以前の街でリンゴを買ったときの差額の最大値を計算:O(N)
    for (int i = 0; i < N; ++i)
    {
        minAi = min(minAi, As[i]);
        LLONG diff = As[i] - minAi;
        ++diff2PairNumMap[diff];
    }
    // 差額が最大となるペアをそれぞれ妨害する
    cout << diff2PairNumMap.rbegin()->second << endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<ii>
#define li long int
#define ll long long
#define lli long long int
#define vlli vector<lli>
#define vll vector<ll>
#define vl vector<long>
#define ld long double
#define ulli unsigned long long int
 
using namespace std;

void solve() {
    lli n;
    cin>>n;
    vlli a(n);
    REP(i, n)
        cin>>a[i];
    lli res = 0;
    for(lli i = 1; i < n; i++)
        if(a[i] < a[i - 1]) {
            res += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    cout<<res;
}

////1 1 1 1 1 0
//0 1 2 3 4 5 5

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    solve();
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

vector<ll> x;

void dfs(int cur,int pre,vector<vector<int>>& G){
    for(auto& u : G[cur]){
        if(u==pre) continue;
        x[u] += x[cur];
        dfs(u,cur,G);
    }
}

int main(){
    int n; cin >> n;
    int q; cin >> q;
    vector<vector<int>> G(n);
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    x.resize(n);
    rep(i,q){
        int p; cin >> p;
        p--;
        ll t; cin >> t;
        x[p] += t;
    }


    dfs(0,0,G);
    
    rep(i,n){
        cout << x[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 27392
n, m, x = gets.to_s.split.map{|e|e.to_i}
c = Array.new(n)
a = Array.new(n){ [] }
 
n.times do |i|
  c[i], *a[i] = gets.to_s.split.map{|e|e.to_i} 
end

inf = 10 ** 7
ans = inf
[0, 1].repeated_permutation(n) do |bit|
  
  cnt = 0
  # p bit
  rikaido = Array.new(m){ 0 }
  bit.each_with_index do |b, i|
    
    if b == 1
      
      cnt += c[i]
      
      m.times do |j|
        
        rikaido[j] += a[i][j]
        
      end
    end
  end
  
  ans = [ans, cnt].min if rikaido.all?{ |r| r >= x } 
end

puts ans == inf ? -1 : ans

Measured memory_bytes: 14492
#include<iostream>
using namespace std;
int main(){
int mid,final,re_exam,sum;
    while (1){
    cin>>mid>>final>>re_exam;
    if(mid == -1 && final == -1 && re_exam== -1 ) {
        break;
    }else {
            sum = mid + final;
            if (mid != -1 && final != -1 && sum >= 80) { cout << 'A' << endl; }
            if (mid == -1 || final == -1) { cout << 'F' << endl; }
            else if (mid != -1 && final != -1 && 80 > sum && sum >= 65) { cout << 'B' << endl; }
            else if (mid != -1 && final != -1 && 65 > sum && sum >= 50) { cout << 'C' << endl; }
            else if (mid != -1 && final != -1 && 50 > sum && sum >= 30 && re_exam >= 50) { cout << 'C' << endl; }
            else if (mid != -1 && final != -1 && 50 > sum && sum >= 30 && re_exam < 50) { cout << 'D' << endl; }
            else if (mid != -1 && final != -1 && 30 > sum ) { cout << 'F' << endl; }

             }
    }
return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, m;
  int a, b;
  //  int ans;
  int tmp; 
  int xmax, ymin; 
  
  //  cin >> N;
  cin >> n >> m;
  cin >> a >> b;

  xmax = a; ymin = b;
  for(int i; i<n; i++){    
    cin >> tmp;
    if(tmp > xmax){
      xmax = tmp;
    }
  }
  for(int i; i<m; i++){    
    cin >> tmp;
    if(tmp < ymin){
      ymin = tmp;
    }
  }
  
  if(xmax >= ymin){
    cout << "War" <<endl;
    return 0; 
  }
  cout << "No War" <<endl;
  return 0;
}
  


Measured memory_bytes: 256
n,k,q = map(int, input().split())
A = list(map(int, input().split()))

ans = 10**18
for x in A:
    B = []
    C = []
    for a in A:
        if a >= x:
            C.append(a)
        else:
            if len(C) >= k:
                C.sort()
                B += C[0:len(C)-k+1]
            C = []
    else:
        if len(C) >= k:
            C.sort()
            B += C[0:len(C)-k+1]
    if len(B) >= q:
        B.sort()
        ans = min(ans, B[q-1]-x)
print(ans)


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

long long N;
long long A[100005];

int main(){
	cin >> N;
	long long ans = 0;
	long long cur = 0;
	int dir = 0;

	for(long long i = 0; i < N; i++){
		long long num;
		cin >> num;
		if(i == 0){
			cur = num;
		}else if(dir == 1){
			if(cur <= num){
				cur = num;
			}else{
				cur = num;
				dir = 0;
				ans++;
			}
		}else if(dir == -1){
			if(cur >= num){
				cur = num;
			}else{
				cur = num;
				dir = 0;
				ans++;
			}
		}else{
			if(cur < num){
				cur = num;
				dir = 1;
			}else if(cur > num){
				cur = num;
				dir = -1;
			}else{
				cur = num;
				dir = 0;
			}
		}
	}
	cout << ans + 1 << endl;
}


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

int main(void){
    int x,a,b;
    cin >> x >> a >> b;
    int ans=(x-a)-(x-a)/b*b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define MAX 20

int main(){
	int count;
	std::cin >> count;
	//dp[計算した回数][計算したとこまでの合計]を宣言する
	std::vector<std::vector<unsigned long long int>> dp(count - 1);
	for(int i = 0; i < count - 1; ++i){
		dp[i].resize(MAX + 1, 0);
	}
	int num;
	std::cin >> num;
	//最初はそのまま入れる
	dp[0][num] = 1;
	for(int i = 1; i < count - 1; ++i){
		std::cin >> num;
		//条件から三つに分ける
		for(int sum = 0; sum < num; ++sum){
			dp[i][sum + num] += dp[i - 1][sum];
		}
		for(int sum = num; sum <= MAX - num; ++sum){
			dp[i][sum + num] += dp[i - 1][sum];
			dp[i][sum - num] += dp[i - 1][sum];
		}
		for(int sum = MAX - num + 1; sum <= MAX; ++sum){
			dp[i][sum - num] += dp[i - 1][sum];
		}
	}
	
	std::cin >> num;
	std::cout << dp[count - 2][num] << std::endl;
	
	return 0;
}
	

Measured memory_bytes: 1212
//Ahadul Haque, MBSTU,ICT
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define TEST int test; cin >> test ;while(test--)
#define endl "\n"
int main()
{
    ll n;
    cin>>n;
   ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;i*j<n;j++)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;






    return 0;
}








Measured memory_bytes: 3640
#include<stdio.h>

int main(){
	int a,b;
	for(a=1;a<10;a++){
		for(b=1;b<10;b++){
			printf("%d",a);
			printf("x");
			printf("%d",b);
			printf("=");
			printf("%d\n",a*b);
		}
	}
    return 0;
}

Measured memory_bytes: 928