akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string w, s;

	cin >> w;

	int cnt = 0;
	for (; cin >> s;)
	{
		if (s == "END_OF_TEXT")
		{
			break;
		}

		transform(s.begin(), s.end(), s.begin(), ::tolower);

		if (w == s)
		{
			cnt ++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		//ペンキの種類
		int count = 1;
		//条件分岐
		if(a == b) {
			if(b == c) {
				System.out.println(count);
				return;
			}else {
				count++;
				System.out.println(count);
				return;
			}
		}else if (a == c) {
			count++;
			System.out.println(count);
			return;
		}else if(b == c) {
			count++;
			System.out.println(count);
		}else {
			count += 2;
			System.out.println(count);
		}
	}

}


Measured memory_bytes: 20820
import sys
from copy import deepcopy
input = sys.stdin.readline
n,m=map(int,input().split())
d=[[100000]*n for _ in range(n)]
a=[0]*m
b=[0]*m
c=[0]*m
for i in range(m):
  a0,b0,c0=map(int,input().split())
  a[i]=a0-1
  b[i]=b0-1
  c[i]=c0
  d[a0-1][b0-1]=c0
  d[b0-1][a0-1]=c0
for i in range(n):
  d[i][i]=0
d2=deepcopy(d)
for k in range(n):
  for i in range(n):
    for j in range(n):
      d[i][j]=min(d[i][j],d[i][k]+d[k][j])
count=0
for i in range(n):
  for j in range(i):
    if d2[i][j] != 100000 and d[i][j]!=d2[i][j]:
      count+=1
print(count)


Measured memory_bytes: 3956
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int A,B;
  cin >> A >> B;
  cout << ((A+B) % 24) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n,x,t;
    cin >> n >> x >> t;
    int a = n/x;
    if(a>0) {
        if(n%x) a++;
    } else a++;
    cout << a*t << endl;
}

Measured memory_bytes: 3644
/*      ex5_3
        Tarara  */
#include <stdio.h>

// height, widthの最大長+5
#define MAX_LENGTH 100 + 5

int height, width;                  // 場の横幅, 高さ
char field[MAX_LENGTH][MAX_LENGTH]; // 場の状態

int exsitsBlackCellinRow(int row);
int exsitsBlackCellinCol(int col);

int main(void)
{
    int is_whites_rows[MAX_LENGTH]; // 全て白の行であることの真偽値
    int is_whites_cols[MAX_LENGTH]; // 全て白の列であることの真偽値

    int i, j;
    // 入力
    scanf("%d %d", &height, &width);
    for (int i = 0; i < height; i++)
    {
        scanf("%s", field[i]);
    }

    // 各列・各行が全て白であるかを調べる
    for (i = 0; i < height; i++)
        is_whites_rows[i] = !exsitsBlackCellinRow(i);
    for (i = 0; i < width; i++)
        is_whites_cols[i] = !exsitsBlackCellinCol(i);

    // 出力
    for (i = 0; i < height; i++)
    {
        if (is_whites_rows[i])
            continue;

        for (j = 0; j < width; j++)
        {
            if (is_whites_cols[j])
                continue;
            printf("%c", field[i][j]);
        }
        printf("\n");
    }
    return 0;
}

// 指定した列が全て黒ならば1，そうでなければ偽を返す．
int exsitsBlackCellinCol(int col)
{
    int i;
    for (i = 0; i < height; i++)
    {
        if (field[i][col] == '#')
            return 1;
    }
    return 0;
}

// 指定した行が全て黒ならば1，そうでなければ偽を返す．
int exsitsBlackCellinRow(int row)
{
    int i;
    for (i = 0; i < width; i++)
    {
        if (field[row][i] == '#')
            return 1;
    }
    return 0;
}


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

const unsigned n_MAX=100000000;
int n,m;
char bef[n_MAX],aft[n_MAX],ans[n_MAX];


void solve(char& a){
	for(int i=0; bef[i]!='\0'; i++){
		if(bef[i]==a){
			a = aft[i];
			return;
		}
	}
}

void input1(){
	int i=0;
	for(; i<n; i++)
		cin >> bef[i] >> aft[i];
	bef[i]='\0';
}

void input2(){
	for(int i=0; i<m; i++){
		cin >> ans[i];
		solve(ans[i]);
	}
}

int main(){
	while(true){
		cin >> n;
		if(n==0)
			return 0;
		input1();
		cin	>> m;
		input2();
		cout << ans << endl;
	}
}

Measured memory_bytes: 936
N, K = map(int, input().split())
X = list(map(int, input().split()))
cost = []
for i in range(0, N-K+1):
    #window = X[i:i+K]
    #cost.append(window[-1]-window[0] + min(abs(window[-1]), abs(window[0])))
    cost.append(X[i+K-1]-X[i] + min(abs(X[i+K-1]), abs(X[i])))
print(min(cost))

Measured memory_bytes: 14252
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

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

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

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

signed main() {
    solve();
    
    return 0;
}

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

using namespace std;


int main(){
    int n;
    cin >> n;
    priority_queue<int> q;
    rep(i, 2*n){
        int l;
        cin >> l;
        q.push(l);
    }

    ll sum = 0;
    rep(i, n){
        q.pop();
        sum += q.top();
        q.pop();
    }
    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
  int wc[10], wsum=0, kc[10], ksum=0;
  
  for(int i = 0 ; i < 10 ; i++) {
    cin >> wc[i];
  }
  for(int i = 0 ; i < 10 ; i++) {
    cin >> kc[i];
  }
  sort(wc, wc+10);
  sort(kc, kc+10);
  
  for(int i = 9 ; i > 6 ; i--) {
    wsum += wc[i];
    ksum += kc[i];
  }
  cout << wsum << ' ' << ksum << endl;
  return 0;
}

Measured memory_bytes: 0
enum class Op(val chr: Char){
    plus('+'),
    minus('-')
}


fun reccalc(acc: Int, accStr: String, ary: List<Int>, op: Op): String?{
    if(ary.isEmpty()){
        return if(acc == 7) accStr else null
    }
    val v : Int
    val s : String
    when(op){
        Op.plus -> {
            v = acc + ary.first()
            s = "$accStr+${ary.first()}"
        }
        Op.minus -> {
            v = acc - ary.first()
            s = "$accStr-${ary.first()}"
        }
    }
    val rest = ary.subList(1, ary.size)
    return reccalc(v, s, rest, Op.plus) ?: reccalc(v, s, rest, Op.minus)
}

fun main(args: Array<String>) {
    val ns = readLine()!!.map{it.toString().toInt()}
    val head = ns.first()
    val rest = ns.subList(1, 4)
    val ret = reccalc(head, "$head", rest, Op.plus) ?: reccalc(head, "$head", rest, Op.minus)
    print("${ret!!}=7")
}

Measured memory_bytes: 31944
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
vector<int> op1[200005], op2[200005];
map<char, int> mp1, mp2;
char s[200005], t[200005];
int main()
{
	scanf("%s%s", s, t);
	if (strlen(s) != strlen(t))
	{
		printf("No\n");
	}
	else
	{
		for (int i = 0; s[i]; i++)
		{
			if (mp1.count(s[i]))
			{
				op1[mp1[s[i]]].push_back(i);
			}
			else
			{
				mp1[s[i]] = i;
				op1[mp1[s[i]]].push_back(i);
			}
			if (mp2.count(t[i]))
			{
				op2[mp2[t[i]]].push_back(i);
			}
			else
			{
				mp2[t[i]] = i;
				op2[mp2[t[i]]].push_back(i);
			}
		}
		for (int i = 0; i < 200005; i++)
		{
			if (op1[i].size() != op2[i].size())
			{
				printf("No\n");
				return 0;
			}
			else
			{
				for (int j = 0; j < op1[i].size(); j++)
				{
					if (op1[i][j] != op2[i][j])
					{
						printf("No\n");
						return 0;
					}
				}
			}
		}
		printf("Yes\n");
	}
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif

const int N = 5e5 + 5;
int seg[4*N];
string s;
int n;

void upd(int p, int l, int r, int k, char c){
    if(l == r and l == k){
        int z = 0;
        z |= (1 << int(c - 'a'));
        seg[p] = z;
    } else if(l > k or r < k) return;
    else {
        int mid = (l+r)/2;
        upd(p+p, l, mid, k, c);
        upd(p+p+1, mid+1, r, k, c);
        seg[p] = seg[p+p] | seg[p+p+1];
    }
}

int query(int p, int l, int r, int a, int b){
    if(l >= a and r <= b) return seg[p];
    if(l > b or r < a) return 0;
    int mid = (l+r)/2;
    return query(p+p, l, mid, a, b) | query(p+p+1, mid+1, r, a, b);
}

int query(int l, int r){
    return __builtin_popcount(query(1, 1, n, l, r));
}

int main(){
    fcin;

    cin >> n;
    cin >> s;

    for(int i = 0; i < n; i++) upd(1, 1, n, i+1, s[i]);

    int q;
    cin >> q;

    while(q--){
        int t;  cin >> t;
        if(t == 1){
            int i;
            char c;
            cin >> i >> c;
            upd(1, 1, n, i, c);
        } else {
            int l, r;
            cin >> l >> r;
            cout << query(l, r) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 7068
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e18
#define mod pow(10,9)+7
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
#define lcm(x,y)  (x*y)/__gcd(x,y)


int32_t main()
{
//	c_p_c();
	int n, l;
	cin >> n >> l;
	int a[n];
	int i;
	int co = 0;
	int cn = 0;
	for (i = 0; i < n; i++) {
		a[i] = l + i;
		if (a[i] == 0)
			co++;
		else if (a[i] < 0)
			cn++;
	}


	if (co)
		cout << accumulate(a, a + n, 0);
	else if (cn == n)
		cout << accumulate(a, a + n, 0) - *max_element(a, a + n) << endl;
	else
		cout << accumulate(a, a + n, 0) - *min_element(a, a + n);





	return 0;
}

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

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for (int i=0; i<N; i++){
    cin >> L[i];
  }

  int D = 0;
  int i = 0;
  int ans = 0;
  while(D <= X){
    if (i > N) break;
    ans++;
    D += L[i];
    i++;
  }
  cout << ans << endl;
  return 0;
}


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

signed main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)cin >> a[i];
	int fv = 0;
	int sv = 0;
	int fi = 0;
	int si = 0;
	for (int i = 0; i < n; ++i) {
		if (fv < a[i]) {
			sv = fv;
			si = fi;
			fv = a[i];
			fi = i;
		}
		else if (sv < a[i]) {
			sv = a[i];
			si = i;
		}
	}
	for (int i = 0; i < n; ++i) {
		if (i == fi)cout << sv << endl;
		else cout << fv << endl;
	}
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,c;
	cin>>n>>c;
	vector<vector<int>> d(c,vector<int>(c)),g(n,vector<int>(n));
	rep(i,c){
		rep(j,c){
			cin>>d[i][j];
		}
	}
	rep(i,n){
		rep(j,n){
			cin>>g[i][j];
			g[i][j]--;
		}
	}
	vector<vector<int>> sum(3,vector<int>(c,0));
	rep(r,3)rep(i,c){
		rep(x,n)rep(y,n){
			if((x+y)%3!=r) continue;
			sum[r][i]+=d[g[x][y]][i];
			//cout<<g[x][y]<<' '<<c<<' '<<d[g[x][y]][c]<<' '<<sum[r][i]<<endl;
		}
	}
	int ans=INF;
	rep(i,c)rep(j,c)rep(k,c){
		if(i==j || j==k || k==i) continue;
		chmin(ans,sum[0][i]+sum[1][j]+sum[2][k]);
		//cout<<sum[0][i]+sum[1][j]+sum[2][k]<<endl;
	}
	cout<<ans<<endl;
}

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

int main() {
	long long N, ans = 0, B;
	cin >> N;

	for (int i = 1; i <= sqrt(N); i++) {
		if ((double)N / (double)i == (double)(N / i)) {
			B = N / i;
		}
	}

	while (1){
		ans++;
		B = B / 10;
		if (B == 0)break;
	}
	cout << ans << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

int main() {
  int N , M;
  cin >> N >> M;
  
  vector<vector<int>> c(N);
  vector<int> P(M);
  vector<int> Y(M);

  rep(i, M) {
    cin >> P[i] >> Y[i];
    c[--P[i]].push_back(Y[i]);
  }

  rep(i, N) { sort(c[i].begin(), c[i].end()); }
  rep(i, M) {
    ll id = lower_bound(c[P[i]].begin(), c[P[i]].end(), Y[i]) -  c[P[i]].begin();
    printf("%06d%06lld\n", P[i] + 1, id + 1);
  }
}

Measured memory_bytes: 7808
k=int(input())
num=7%k
ans=-1

if k%2==0 or k%5==0:
	ans=-1
else:
	for i in range(1,k+10):
		# print(num)
		if num==0:
			ans=i
			break
		num=(num*10+7)%k

print(ans)

Measured memory_bytes: 9096
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  int n,count = 0;
  cin >> n;
  vector<string> s;
  s.clear();
  string str;
  for(int i = 0; i < n; i++){
  	cin >> str;
    s.push_back(str);
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  
  cout << s.size() << endl;
  return 0;
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define WHITE 0
#define GRAY 1
#define BLACK 2

//節点uからでる枝の構造体の定義
typedef struct slobj_{
    struct slobj_ *next;
    int v; //uから枝が伸びている節点v
}* slobj;

//slobj型のリストの定義
typedef struct{
    slobj head;
    slobj tail;
}* slist;

//グラフの構造体の定義
typedef struct{
    int n; //節点数
    slist* E; //枝リストの配列E[0]~E[n-1],未ソート単方向
}* graph;

//vにnを持つslobj型のリスト要素のメモリ確保+作成する関数
slobj slobj_new(int n){
    slobj p;
    NEW(p,1);
    p->v=n;
    p->next=NULL;
    return p;
}

//slist型のメモリを1個確保し、空リスト1つを作る関数
slist slist_new(void){
    slist L;
    NEW(L,1);
    L->head=NULL;
    L->tail=NULL;
    return L;
}

//各slistを空リストにした,節点nのgraph型のメモリを確保する関数(Eは0カウント)
graph graph_new(int n){
    graph G;
    NEW(G,1);
    
    G->n=n;
    
    NEW(G->E,G->n);
    int i;
    for(i=0;i<G->n;i++){
        G->E[i]=slist_new();
    }
    
    return G;
}

//リストLの末尾に要素rを追加する関数
void slist_append_tail(slist L,slobj r){
    if(L->head==NULL){
        L->head=r;
        L->tail=r;
    }
    else{
        L->tail->next=r;
        L->tail=r;
    }
    
    return;
}

//節点i(0~n-1)から節点j(0~n-1)に枝を追加する関数
void add_edge(graph G, int i, int j){
    //枝データを追加
    slobj p=slobj_new(j);
    slist_append_tail(G->E[i],p);

    return;
}

//根(節点i)からの長さをdfs
void dfs(graph G, int i, long* d, int* color){
    color[i]=GRAY;
	slobj p=G->E[i]->head;
	while(p!=NULL){
		if(color[p->v]==WHITE){ //未探索なら
			d[p->v]+=d[i];
			dfs(G,p->v,d,color);
		}
		p=p->next;
	}
    color[i]=BLACK;
	return;
}

int main(void){
    int N,Q;
    scanf("%d%d",&N,&Q);

    graph G = graph_new(N);

    //無向グラフに枝を追加
    for(int i=0;i<N-1;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        add_edge(G,a-1,b-1);
        add_edge(G,b-1,a-1);
    }

    //頂点に付いているカウンターの値
    long d[N];
    for(int i=0;i<N;i++) d[i]=0;

    //カウンターの値を標準入力から入れる
    for(int i=0;i<Q;i++){
        int p;
        long x;
        scanf("%d%ld",&p,&x);
        d[p-1]+=x;
    }

    //頂点を訪れたかどうかを格納する配列
    int color[N];
    for(int i=0;i<N;i++) color[i]=0;

    dfs(G,0,d,color);

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

    return 0;
}

Measured memory_bytes: 37504
n = int(input())
T = list(map(int, input().split()))
m = int(input())
P, X = [], []
for _ in range(m):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

tot = sum(T)
for i in range(m):
    ans = tot - T[P[i]-1] + X[i]
    print(ans)


Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
 
 
class Main
{
    public static void main(String[] args)
    {
        int ans = 0;
        
        Scanner scanner = new Scanner(System.in);
        String n = scanner.next(); 
        
        int a = Integer.parseInt(n);
        int b = n.length();
        if(a % 100 == 0){
            System.out.println("10");
        }else if(a > 10){
            for(int i = 0;i<b;i++){
                char ch = n.charAt(i);
                ans += Character.getNumericValue(ch);
            }
            System.out.println(ans);
        }else{
            System.out.println(n);
        }
        scanner.close();
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    P(min(a,b)+min(c,d));
    
	return  0;
}

Measured memory_bytes: 256
import itertools

n=int(input())
a=list(map(int,input().split()))
count=0

n=list(itertools.combinations(a,3))

for i in n:
  if i[0]!=i[1] and i[1]!=i[2] and i[0]!=i[2]:
    if i[0]+i[1]>i[2] and i[0]+i[2]>i[1] and i[2]+i[1]>i[0]:
      count+=1

print(count)

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
int color[404][404] = {};
int visited[404][404] = {};

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

    int h, w; cin >> h >> w;
    vector<string> field(h);
    rep(i, h) cin >> field[i];
    rep(i, h) rep(j, w) color[i][j] = (field[i][j] == '#');

    ll ans = 0;
    rep(i, h) rep(j, w) {
        if(visited[i][j]) continue;
        visited[i][j] = 1;
        ll cntB = 0, cntW = 0;
        queue<P> que;
        que.push(P(i, j));
        while(que.size()) {
            P p = que.front();
            que.pop();
            int y = p.first, x = p.second;
            if(color[y][x]) cntB++;
            else cntW++;
            rep(k, 4) {
                int nx = x+dx[k];
                int ny = y+dy[k];
                if(nx < 0 || ny < 0 || w <= nx || h <= ny) continue;
                if(visited[ny][nx]) continue;
                if(color[ny][nx] == color[y][x]) continue;
                visited[ny][nx] = 1;
                que.push(P(ny, nx));
            }
        }
        ans += cntB*cntW;
    }
    cout << ans << '\n';
    return 0;
}

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

typedef vector<long double> arr;
typedef vector<arr> mat;
inline arr mul(const mat &a,arr &b){
  arr res(b.size(),0);
  for(Int i=0;i<(Int)b.size();i++)
    for(Int j=0;j<(Int)a[i].size();j++)
      (res[i]+=a[i][j]*b[j]);
  return res;
}
inline mat mul(const mat &a,const mat &b){
  mat res(a.size(),arr(b[0].size(),0));
  for(Int i=0;i<(Int)a.size();i++)
    for(Int j=0;j<(Int)b[0].size();j++)
      for(Int k=0;k<(Int)b.size();k++)
	(res[i][j]+=a[i][k]*b[k][j]);
  return res;
}
inline mat mat_pow(mat a,Int n){
  mat res(a);
  for(Int i=0;i<(Int)a.size();i++)
    for(Int j=0;j<(Int)a[i].size();j++)
      res[i][j]=(i==j);
  while(n){
    if(n&1) res=mul(a,res);
    a=mul(a,a);
    n>>=1;
  }
  return res;
}


const double EPS=1E-8;
using vec = arr;
vec gauss_jordan(const mat& A,const vec& b){
  Int n=A.size();
  mat B(n,vec(n+1));
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      B[i][j]=A[i][j];
  for(Int i=0;i<n;i++) B[i][n]=b[i];
  for(Int i=0;i<n;i++){
    Int pivot=i;
    for(Int j=i;j<n;j++)
      if(abs(B[j][i])>abs(B[pivot][i])) pivot=j;
    swap(B[i],B[pivot]);
    if(abs(B[i][i])<EPS) return vec();
    for(Int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
    for(Int j=0;j<n;j++){
      if(i!=j){
	for(Int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
      }
    }
  }
  vec x(n);
  for(Int i=0;i<n;i++) x[i]=B[i][n];
  return x;
}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  Int s,n,k;
  cin>>s>>n>>k;
  s=abs(s);
  if(s==0||n*k==1){
    cout<<s<<endl;
    return 0;
  }
  if(n==1){
    if(s%k) cout<<-1<<endl;
    else cout<<s/k<<endl;
    return 0;
  }
  
  Int x=n*k-1,y=n*k+1;
  
  arr dp(y,0);
  dp[0]=1;
  for(Int i=0;i<k;i++){
    arr nx(y,0);
    for(Int j=0;j<y;j++)
      for(Int a=1;a<=n;a++)
	if(j+a<y) nx[j+a]+=dp[j]/n;
    swap(dp,nx);
  }
  
  mat A(x,arr(x,0));
  for(Int i=1;i<=x;i++){
    for(Int j=1;j<=n*k;j++){
      if(i==j) continue;
      A[i-1][abs(i-j)-1]+=dp[j];
    }
  }
  
  for(Int i=0;i<x;i++) A[i][i]-=1.0;
  
  vec m(x,-1);
  vec b=gauss_jordan(A,m);
  
  if(s<=x){
    cout<<b[s-1]<<endl;
    return 0;
  }
  
  mat T(y,arr(y,0));
  T[0][0]=T[y-1][0]=1;
  for(Int i=0;i<x;i++) T[i+1][i+2]=1.0;
  
  for(Int i=1;i<y;i++) T[y-1][y-i]=dp[i];
  
  b.emplace(b.begin(),0);
  b.emplace(b.begin(),1);
  
  T=mat_pow(T,s-x);
  arr z=mul(T,b);
  cout<<z.back()<<endl;
  return 0;
}



Measured memory_bytes: 3880
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
ll K;
vector<ll> A,B;
void input(){
    fast_io();
    cin >> N >> M >> K;
    A = fetch_vec<ll>(N);
    B = fetch_vec<ll>(M);
}

int solve(){
    vector<ll> AS(N+1,0);
    vector<ll> BS(M+1,0);
    for (int i = 0; i < N; i++) AS[i+1] = AS[i]+A[i];
    for (int i = 0; i < M; i++) BS[i+1] = BS[i]+B[i];
    BS.push_back(LL_INF);
    int ans = 0;
    DBG(AS)
    DBG(BS)
    for (int i = 0; i <= N; i++)
    {
        if(AS[i]>K) break;
        int it = upper_bound(BS.begin(),BS.end(),K-AS[i])-BS.begin();
        if(it) it--;
        DBG(i)
        DBG(it)
        ans = max(ans,i+it);
    }
    cout << ans << endl; 
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 11112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  vector<ll> ans(2);
  sort(all(A), greater<ll>());
  rep(i, n) ans[i%2] += A[i];
  cout << ans[0]-ans[1] << endk;
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>

#define MAX 100000

int main()
{
	int A, B, ans;
	scanf("%d %d", &A, &B);
	if(A>=10 || B>= 10){
		printf("-1\n");
		return 0;
	}
	ans = A*B;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;

const int maxn = 1e5 + 5;
int n;
vector<int> G[maxn];
int dis[2][maxn];
void bfs(int id){
    queue<int> q;
    memset(dis[id],0x3f3f3f3f,sizeof(dis[id]));
    if(id == 0){
        q.push(1);
        dis[0][1] = 0;
    }else{
        q.push(n);
        dis[1][n] = 0;
    }
    while(!q.empty()){
        int p = q.front();q.pop();
        for(int i = 0;i < G[p].size();i++){
            int v = G[p][i];
            if(dis[id][v] == 0x3f3f3f3f){
                dis[id][v] = dis[id][p] + 1;
                q.push(v);
            }
        }
    }
}

int main(){
    while(cin >> n){
        for(int i = 1;i <= n;i++) G[i].clear();
        for(int i = 1;i < n;i++){
            int a,b;
            scanf("%d%d",&a,&b);
            G[a].push_back(b);
            G[b].push_back(a);
        }
        bfs(0);bfs(1);
        int num[2] = {0};
        for(int i = 1;i <= n;i++){
            if(dis[0][i] <= dis[1][i]) num[0]++;
            else num[1]++;
        }
        if(num[0] > num[1]) printf("Fennec\n");
        else printf("Snuke\n");
    }
    return 0;
}


Measured memory_bytes: 6656
s=str(input())
s=list(s)
l=len(s)
ans=0
temp=0
for i in range(0,l):
  if s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T":
    temp=temp+1
    ans=max(ans,temp)
  else:
    temp=0
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
template <typename T>
using vec = std::vector<T>;

int N, M, X;
int ans = 1e9 + 7;
vec<int> C(12);
vec<vec<int>> A(12, vec<int>(12, 0));

void dfs(int now, int cost, vec<int> Xs) {
    if (now == N) {
        bool flag = true;
        for (auto e : Xs)
            if (e > 0) flag = false;
        if (flag) ans = min(ans, cost);
        return ;
    }

    dfs(now+1, cost, Xs);
    for (int i = 0; i < M; ++i)
        Xs[i] -= A[now][i];
    dfs(now+1, cost + C[now], Xs);
}

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

    rep(i, N) {
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }

    dfs(0, 0, vec<int>(M, X));
    cout << (ans == (int)1e9 + 7 ? -1 : ans) << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int a, b;
    cin >> a >> b;

    if (b % a == 0) {
        P(a + b);
    }
    else {
        P(b - a);
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static ConsoleApplication.Utils;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var hw = ReadInts().ToArray();
            var s = new string[hw[0]][];
            var res = "";
            for (var i = 0; i < hw[0]; ++i)
            {
                s[i] = ReadStrings().ToArray();
                if (!s[i].Any(str => str.Equals("snuke"))) continue;
                var column = s[i].Select((str, idx) => new {str, idx}).Where(e => e.str.Equals("snuke")).Select(e => e.idx).First();
                res = ((char)((int)'A' + column)).ToString() + (i + 1);
                break;
            }
            WriteLine(res);
        }
    }

    public static class Utils
    {
        #region Extensions for IO

        public static long ReadLong()
            => ReadLine().ToLong();
        public static int ReadInt()
            => ReadLine().ToInt();

        public static IEnumerable<int> ReadInts()
            => ReadStrings().Select(int.Parse);

        public static IEnumerable<string> ReadStrings()
            => ReadLine().Split(' ');

        public static IEnumerable<string> ReadLines(int n)
        {
            foreach (var i in Enumerable.Range(0, n))
            {
                yield return ReadLine();
            }
        }

        #endregion

        #region Extensions of int

        public static bool IsOdd(this int n)
            => !n.IsEven();

        public static bool IsEven(this int n)
            => n % 2 == 0;

        public static bool CanDivideWith(this int n, int divisor)
            => n % divisor == 0;

        #endregion

        #region Extensions of string

        public static int ToInt(this string str)
            => int.Parse(str);

        public static long ToLong(this string str)
            => long.Parse(str);

        public static double ToDouble(this string str)
            => double.Parse(str);

        public static bool IsNullOrEmpty(this string str)
            => string.IsNullOrEmpty(str);

        #endregion

        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
        }

        public static IEnumerable<T> Peek<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
            return source;
        }
    }
}


Measured memory_bytes: 3160
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let n = match iter.next().unwrap().parse::<i32>() {
		Ok(m) => m,
		_ => panic!(""),
	};
	let d = match iter.next().unwrap().parse::<i32>() {
		Ok(m) => m,
		_ => panic!(""),
	};
	println!("{}", (n+2*d)/(2*d + 1));
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int D, d = 26;
	cin >> D;
	vector<int>c(d);
	rep(i, 0, d)cin >> c[i];
	
	vector<int>ans;
	rep(j, 1, D+1) {
		vector<pair<long long int, int>>s(d);
		rep(i, 0, d) {
			cin >> s[i].first;
			s[i].second = i + 1;
			s[i].first += j*c[i] * D * (D + 1) / 2;
		}
		sort(s.begin(), s.end());
		ans.push_back(s[d - 1].second);
	}
	for (auto a : ans)cout << a << endl;;
}



Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

void solve() {
    int N, ans = 0;
    cin >> N;
    vector<pair<int, int>> red(N), blue(N);
    rep(i, N) cin >> red[i].second >> red[i].first;
    rep(i, N) cin >> blue[i].first >> blue[i].second;
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    rep(i, N) for (int j = N - 1; j >= 0; j--) {
        if (red[j].second < blue[i].first and red[j].first < blue[i].second) {
            ans ++;
            red[j] = make_pair(300, 300);
            break;
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

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

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

signed main() {
  init();
  string S;
  ll w;
  cin >> S >> w;

  string ans = "";
  rep(i, S.size()) if (i % w == 0) ans += S[i];
  ANS;
  return 0;
}

Measured memory_bytes: 3624
n = int(input())
A = list(map(int, input().split()))

cnt = [0,0]

for i in [0,1]:
    tmp_sum = 0
    for j, a in enumerate(A):
        tmp_sum += a
        if (i + j) % 2 == 0 and tmp_sum <= 0:
            cnt[i] += abs(tmp_sum) + 1
            tmp_sum += abs(tmp_sum) + 1
        elif (i + j) % 2 == 1 and tmp_sum >= 0:
            cnt[i] += tmp_sum + 1
            tmp_sum -= tmp_sum + 1

print(min(cnt))
            

Measured memory_bytes: 14332
#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;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll n, k;
vector<ll> a, f;

bool isOK(ll x) {
    ll cost = 0;
    rep(i, n){
        cost += max(0ll, a[i] -  x/f[i]);
    }

    if (cost <= k) return true;
    else return false;
}

ll binary_search() {
    ll ng = -1;
    ll ok = 1e+18+7;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}



int main(){
    cin >> n >> k;
    rep(i, n){
        ll t;
        cin >> t;
        a.push_back(t);
    }
    rep(i, n){
        ll t;
        cin >> t;
        f.push_back(t);
    }

    sort(a.rbegin(), a.rend());
    sort(f.begin(), f.end());

    cout << binary_search() << endl;

    return 0;
}


Measured memory_bytes: 5360
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main() {
	ll a,b,c;
  	cin >> a >> b >> c;
  	ll ans = 0;
  if(a + b > c) cout << b + c << endl;
  else if(a + b == c) cout << a + b + b << endl;
  else cout << a + b + b + 1<< endl;
}

Measured memory_bytes: 256
function calc_seq(xs)
    seq = Int[]
    count = 1
    for i = 1:length(xs)-1
        if xs[i] == xs[i+1]
            count += 1
        else
            push!(seq, count)
            count = 1
        end
    end
    push!(seq, count)
    seq
end

function form_seq(xs)
    seq = calc_seq(xs)
    # 0始まりのとき先頭に0を追加する
    if xs[1] == 0
        seq = vcat(0, seq)
    end
    # 偶数のとき語尾に0を追加する
    m = length(seq)
    if m % 2 == 0
        seq = vcat(seq, 0)
    end
    seq
end

function main(n, k, xs)
    seq = form_seq(xs)
    m = length(seq)
    i = 1
    if i + 2k > m
        print(n)
        return
    end
    val = sum(seq[i:i+2k])
    biggest = val
    i += 2
    while i + 2k <= m
        val += sum(seq[i+2k-1:i+2k]) - sum(seq[i-2:i-1])
        if biggest < val
            biggest = val
        end
        i += 2
    end
    print(biggest)
end

n, k = [parse(Int, x) for x in split(chomp(readline()))]
str = chomp(readline())
xs = zeros(Int, n)

for (i, s) in enumerate(str)
    xs[i] = parse(Int, s)
end

main(n, k, xs)

Measured memory_bytes: 164208
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define pp pair<int,int>
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
int main() {
	int n, a, b,ans=0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n;++i) {
		int nn=0,j=i;
		while (j > 0) {
			nn += j % 10;
			j /= 10;
		}
		if (nn >= a&&nn <= b)ans += i;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int A, B, C, K; cin>>A>>B>>C>>K;
    int max_num=0;
    int sum_all = A+B+C;
    max_num = max({A, B, C});
    int ans = sum_all + max_num*pow(2,K);
    ans -= max_num;
    cout<<ans<<endl;
}

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

typedef long long int ll;

int main(){
	ll n, k;
	cin>>n>>k;
	map<ll,ll> ab;
	for(ll i=0; i<n; i++){
		ll a, b;
		cin>>a>>b;
		ab[a]+=b;
	}
	
	ll ans=0;
	for(auto x : ab){
		if(k<=x.second){
			ans=x.first;
			break;
		}
		k-=x.second;
	}
	cout<<ans<<endl;
}

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

using namespace std;

using int64 = long long;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

vector<vector<Edge>> ReadUndirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge(v1, v2));
    graph[v2].push_back(Edge(v2, v1));
  }
  return graph;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  auto graph = ReadUndirectedGraph(n, n - 1, true);

  function<int64(int, int)> dfs = [&](int v, int p) -> int64 {
    vector<int> cs;
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      cs.push_back(e.to);
    }
    if (cs.size() == 0) {
      return xs[v];
    }

    int64 value_sum = 0;
    for (int c : cs) {
      int64 value = dfs(c, v);
      if (value < 0) return -1;
      if (value > xs[v]) return -1;
      value_sum += value;
    }
    if (value_sum > xs[v] * 2) return -1;
    if (xs[v] * 2 - value_sum > xs[v]) return -1;
    return xs[v] * 2 - value_sum;
  };
  for (int r = 0; r < n; r++) {
    if (graph[r].size() == 1) {
      int64 dfs_value = dfs(graph[r][0].to, r);
      if (dfs_value < 0 || dfs_value != xs[r]) {
        cout << "NO" << endl;
      } else {
        cout << "YES" << endl;
      }
      return 0;
    }
  }
}

Measured memory_bytes: 22144
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;
#define MAX_N 100000
ll A[MAX_N];
int main(){
  int N;
  cin >> N;
  REP(i,N) cin >> A[i];
  ll s = 0;
  ll ans = 0;
  REP(i,N){
    if(A[i] == 0){
      ans += s/2;
      s = 0;
    }
    else s += A[i];
  }
  ans += s/2;
  cout << ans << endl;
  return 0;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

int x,y,z;
int main() {
    scanf("%d%d%d",&x,&y,&z);
    int ans = (x-z)/(y+z);
    pout(ans);
    return 0;
}

Measured memory_bytes: 256