akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#pragma GCC optimize("O2")
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
const int mod = 1e9 + 7;
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
double distform(int x, int y, int z, int w) {//(x1,y1,x2,y2)
    return sqrt(1. * pow(x-z,2) + 1. * pow(y-w,2));
}
const int MAXN = 2e5+ 10;
const ll inf = 1e18;

int intlog(double base, double x) {
    return (int)(log(x) / log(base));
}
void read(vi & a) {
    for (int i = 0; i < sz(a); ++i) {
        cin >> a[i];
    }
}
const string x = "ABC";
int cnt(string s){
    int cnt = 0;
    for (int i = 0; i < sz(s) - sz(x) + 1; ++i) {
        if(s.substr(i,sz(x)) == x) cnt++;
    }
    return cnt;
}
int32_t main() {
    fio
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << cnt(s);

}






Measured memory_bytes: 3648
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N, X, T = LI()
    print(int(int(N/X)*T) if N%X==0 else int(int(N/X+1)*T))

main()



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

ans = [0 for i in range(n)]

for i in range(m):
    r,s = map(int,input().split())
    if n != 1 and r-1 == 0 and s == 0:
        ans = [-1]
        break
    if ans[r-1] != 0 and ans[r-1] != s:
        ans = [-1]
        break
    ans[r-1] = s
if n != 1 and ans[0] == 0:
    ans[0] = 1
sum = ""
for i in range(len(ans)):
    sum += str(ans[i])
print(sum)

Measured memory_bytes: 3064
import atexit
import io
import sys

buff = io.BytesIO()
sys.stdout = buff


@atexit.register
def write():
    sys.__stdout__.write(buff.getvalue())


n = input()
l = map(int, raw_input().split())
ans = int(1e9)
for i in xrange(len(l)-1):
	s1 = sum(l[i+1:])
	s2 = sum(l[:i+1])
	ans = min(ans, abs(s1-s2))
print ans



Measured memory_bytes: 29164
#include<stdio.h>

int main(void){
  int change;
  int buy;
  int count;

  while(1){
    scanf("%d",&buy);
    if(buy==0) break;

    change=1000-buy;
    count=0;
//    printf("now_change: %d\n",change);

    while(change>=500){
      change-=500;
      count++;
//      printf("now_change: %d\n",change);
    }
    while(change>=100){
      change-=100;
      count++;
//      printf("now_change: %d\n",change);
    }
    while(change>=50){
      change-=50;
      count++;
//      printf("now_change: %d\n",change);
    }
    while(change>=10){
      change-=10;
      count++;
//      printf("now_change: %d\n",change);
    }
    while(change>=5){
      change-=5;
      count++;
//      printf("now_change: %d\n",change);
    }
    while(change>0){
      change-=1;
      count++;
//      printf("now_change: %d\n",change);
    }
    printf("%d\n",count);
  }


  return 0;
}



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

int main(){
    stack<int> S;
    int a,b,x;
    string s;
    while(cin >> s){
        if(s[0] == '+'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            x = a + b;
            S.push(x);
        }
        else if(s[0] == '-'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            x = b-a;
            S.push(x);
        }
        else if(s[0] == '*'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            x = a * b;
            S.push(x);
        }
        else{
            S.push(atoi(s.c_str()));
        }
    }
    cout << S.top() << endl;
}


Measured memory_bytes: 3216
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        long n = long.Parse(Console.ReadLine());
        LinkedList<char> lst = new LinkedList<char>(s);

        Boolean inv = false;
        int cnt = 0;

        for (int i = 0; i < n; i++)
        {
            string inp = Console.ReadLine();
            Boolean adds = false;

            if (inp.Length == 5)
            {
                if (inp[2] == '1')
                {
                    adds = false;
                }
                else
                {
                    adds = true;
                }
                if (inv) adds = !adds;

                if (adds)
                {
                    lst.AddLast(inp[4]);
                }
                else
                {
                    lst.AddFirst(inp[4]);
                }
            }
            else
            {
                inv = !inv;
                cnt++;
            }
        }


        char[] ans = lst.ToArray();
        if (cnt % 2 == 1) ans = ans.Reverse().ToArray();

        Console.WriteLine(string.Concat(ans));

    }
}


Measured memory_bytes: 33608
n,q=map(int,input().split())
d = {}
ans = [0]*(n+1)
for i in range(n-1):
    sta,gol = map(int,input().split())
    d[gol] = sta

for i in range(q):
    sta,val = map(int,input().split())
    ans[sta]+=val
    

for i in range(n):
    gol = i+1
    if gol in d:
        ans[gol]+=ans[d[gol]]
    

for i in range(n):
    print(ans[i+1], " ",end="")

Measured memory_bytes: 101592
// E - Common Subsequence

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct ModInt {
    long long val;
    constexpr ModInt(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr ModInt operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr ModInt operator + (const ModInt& r) const noexcept { return ModInt(*this) += r; }
    constexpr ModInt operator - (const ModInt& r) const noexcept { return ModInt(*this) -= r; }
    constexpr ModInt operator * (const ModInt& r) const noexcept { return ModInt(*this) *= r; }
    constexpr ModInt operator / (const ModInt& r) const noexcept { return ModInt(*this) /= r; }
    constexpr ModInt& operator += (const ModInt& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr ModInt& operator -= (const ModInt& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr ModInt& operator *= (const ModInt& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr ModInt& operator /= (const ModInt& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const ModInt& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const ModInt& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const ModInt<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr ModInt<MOD> modpow(const ModInt<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = ModInt<MOD>;

int S[2000];
int T[2000];

// dp[i][j]: S の最初 i 文字と、T の最初 j 文字とからできる共通部分列のうち、
// S の最初の i 文字目のラスト (S[i-1]) と T の最初の j 文字目のラスト (T[j-1]) とが等しくて、
// かつこれを採用しているようなものの個数
mint dp[2001][2001];

// dp_sum[i][j]: dp[i][j]を含む二次元累積和
mint dp_sum[2001][2001];

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

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

	for (int j=0; j<M; j++) {
		cin >> T[j];
	}

	dp[0][0] = 1;
    for (int i=0; i<=N; i++) {
        dp_sum[i][0] = 1;
    }
    for (int j=0; j<=M; j++) {
        dp_sum[0][j] = 1;
    }


	for (int i=1; i<=N; i++) {
		for (int j=1; j<=M; j++) {
			if (S[i-1] == T[j-1]) {
				dp[i][j] = dp_sum[i-1][j-1];
			}

            // 二次元累積和
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] - dp_sum[i-1][j-1] + dp[i][j];
		}
	}

	mint ans = dp_sum[N][M];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 62592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	rep(i,n) cin >> a.at(i);
	int k=n/2,j=0;
	rep(i,n){
		if(i%2==0 && n%2==0){
			b.at(k+j)=a.at(i);
			j++;
		}
		else if(i%2==0 && n%2==1){
			b.at(k-j)=a.at(i);
			j++;
		}
		else if(i%2==1 && n%2==1){
			b.at(k+j)=a.at(i);
		}
		else{
			b.at(k-j)=a.at(i);
		}
	}
	rep(i,n-1) cout << b.at(i) << " ";
	cout << b.at(n-1) << endl;
}

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

int N, M;
#define maxN 100000
int passed[maxN + 10];
int numWA[maxN + 10];
int numAC, numPenalty;

void Solve()
{
  for (int i = 0; i < M; ++i){
    int p;
    string s;
    cin >> p >> s;
    if (passed[p] == 0){
      if (s == "AC"){
        ++numAC;
        passed[p] = 1;
      }
      else
        ++numWA[p];
    }
  }
  for (int i = 1; i <= N; ++i)
    numPenalty += passed[i] * numWA[i];

  cout << numAC << " " << numPenalty << endl;
}

void Init()
{
  for (int i = 0; i < maxN + 10; ++i){
    passed[i] = 0;
    numWA[i] = 0;
  }
  numAC = numPenalty = 0;

  cin >> N >> M;
}

void Clean(){}

int main(){ Init(); Solve(); Clean(); return 0; }


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

int main (){
  int a[4];
  for(int i=0;i<4;i++) cin>>a[i];
  int L = a[0]+a[1];
  int R = a[2]+a[3];
  if(L>R) cout<<"Left"<<endl;
  else if(L==R) cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;

return 0;}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int INF = 2e9 + 7;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << (a == b ? "Yes" : "No");
    return 0;
}


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

constexpr int MaxN = 100;

int main()
{
	int N;
	int A[2][MaxN];

	cin >> N;
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < N; ++j)
		{
			cin >> A[i][j];
		}
	}

	int max = 0;
	max += A[0][0];
	for (int i = 0; i < N; ++i)
	{
		max += A[1][i];
	}

	int X = max;
	for (int i = 1; i < N; ++i)
	{
		X = X - A[1][i - 1] + A[0][i];
		if (X > max)
		{
			max = X;
		}
	}

	cout << max << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, k; cin >> n >> k;
	vector<ll> X;
	for (int i=0; i<n; i++) {
		ll x; cin >> x;
		X.push_back(x);
	}
	ll mint = INF;
	for (int i=0; i + k - 1 < n; i++) {
		ll now;
		int j = i + k -1;
		if (X[j] <= 0) now = - X[i];
		else if (X[i] >= 0) now = X[j];
		else if (abs(X[i]) >= X[j]) now = 2 * X[j] - X[i];
		else now = - 2 * X[i] + X[j];
		
		if (now < mint) mint = now;
	}
	cout << mint << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> ap;
    vector<ll> am;
    rep(i, n) {
        ll tmp_a;
        cin >> tmp_a;
        if (tmp_a < 0) {
            am.push_back(abs(tmp_a));
        }
        else {
            ap.push_back(tmp_a);
        }
    }
    int ap_size = ap.size();
    int am_size = am.size();
    bool possible_plus = false;
    if (ap_size == 0) {
        if (!(k&1)) possible_plus = true;
    }
    else {
        if (n == k) possible_plus = !(am_size&1);
        else        possible_plus = true;
    }
    sort(ap.begin(), ap.end());
    sort(am.begin(), am.end());
    if (possible_plus) {
        reverse(ap.begin(), ap.end());
        reverse(am.begin(), am.end());
    }
    ll ans = 1;
    if (!possible_plus) {
        int idx_p = 0;
        int idx_m = 0;
        while(1) {
            if (idx_p + idx_m == k) break;
            if (idx_p == ap_size) {
                ans = (ans * am[idx_m]) % mod;
                ++idx_m;
            }
            else if (idx_m == am_size) {
                ans = (ans * ap[idx_p]) % mod;
                ++idx_p;
            }
            else if (ap[idx_p] < am[idx_m]) {
                ans = (ans * ap[idx_p]) % mod;
                ++idx_p;
            }
            else {
                ans = (ans * am[idx_m]) % mod;
                ++idx_m;
            }
        }
        //cout << ans << endl;
        cout << mod - ans << endl;
        return 0;
    }
    else {
        int idx_p = 0;
        int idx_m = 0;
        if (k&1) {
            ans = (ans * ap[0]) % mod;
            idx_p = 1;
            --k;
        }
        vector<ll> a_two_pair;
        while(1) {
            if (idx_p + 1 >= ap_size) break;
            a_two_pair.push_back(ap[idx_p] * ap[idx_p+1]);
            idx_p += 2;
        }
        
        while(1) {
            if (idx_m + 1 >= am_size || am.empty()) break;
            a_two_pair.push_back(am[idx_m] * am[idx_m+1]);
            idx_m += 2;
        }
        sort(a_two_pair.rbegin(), a_two_pair.rend());
        //for (auto t: a_two_pair) {
        //    cout << t << "  ";
        //}
        //cout << endl;
        //cout << ans << endl;
        rep(i, k/2) {
            ll tmp = a_two_pair[i] % mod;
            ans = (ans * tmp) % mod;
            //cout << ans << endl;
        }
        cout << ans << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 6592
N = int(input())
h = list(map(int, input().split()))


dp = [0] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]))

print(dp[-1])

Measured memory_bytes: 13980
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String[] s = sc.next().split("");
    String[] ss = "CODEFESTIVAL2016".split("");
    int  cnt = 0;
    for(int i = 0;i<s.length;i++){
      if(s[i].equals(ss[i]));
      else cnt++;
    }
    System.out.println(cnt);
  } 
}

Measured memory_bytes: 23764
N = int(input())
S = input()
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r * g * b
for i in range(N-2):
    t = 1
    while i + 2 * t < N:
        if(S[i] != S[i+t] and S[i] != S[i+2*t] and S[i+t] != S[i+2*t]):
            ans -= 1
        t += 1
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    cins(all(a));
    rep(i,n) a[i]--;
    vector<bool> t(n,0);
    ll index,now = 0,c = 0;
    while(true){
        if (t[now]){
            index = now;
            break;
        }
        c++;
        t[now] = 1;
        now = a[now];
    }
    ll cnt = 0;
    now = 0;
    while(now != index){
        now = a[now];
        cnt++;
    }
    c -= cnt;
    ll ans = 0;
    if (k <= cnt){
        rep(i,k){
            ans = a[ans];
        }
        PRINT(ans+1);
    }
    else{
        k -= cnt;
        k %= c;
        rep(i,k){
            index = a[index];
        }
        PRINT(index+1);
    }
}


Measured memory_bytes: 4784
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;

int main() {
	int n, m;

	while(true){
		cin >> n >> m;
		if(!n && !m){
			break;
		}

		vector< pair< string, int > > N;
		vector< string > M;

		for(int i = 0; i < n; i++) {
			string str;
			int point;
			cin >> str >> point;

			N.push_back(make_pair( str, point ));
		}

		for(int i = 0; i < m; i++) {
			string str;
			cin >> str;

			M.push_back( str );
		}

		int ans = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				bool flag = true;
				for(int k = 0; k < 8; k++) {
					if(N[i].first[k] != M[j][k] && N[i].first[k] != '*') {
						flag = false;
						break;
					}
				}
				if(flag) {
					ans += N[i].second;
				}
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1276
gets
arr = gets.split(' ').map(&:to_i)
arr_g = arr.group_by(&:itself).to_a

sum = 0
arr_g.each do |a|
  if a.last.length < a.first
    sum += a.last.length
  elsif a.last.length > a.first
    sum += a.last.length - a.first
  end
end
p sum


Measured memory_bytes: 23172
#include <cstdio>
#include <cmath>

using namespace std;

const int mod=998244353;
const double eps=0.00000001;

struct punct
{
    int x,y;
};

punct v[210];
int put[210];

int egal(double a,double b)
{
    if(abs(a-b)<eps) return 1;
    return 0;
}

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&v[i].x,&v[i].y);
    put[0]=1;
    for(int i=1;i<=n;i++) put[i]=(1LL*put[i-1]*2)%mod;
    int sol=put[n];
    sol--;
    sol=(sol-n+mod)%mod;
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
        {
            double a=0;
            int p=0;
            if(v[i].x!=v[j].x) a=1.0*(v[i].y-v[j].y)/(v[i].x-v[j].x);
            else p=1;
            double b=1.0*v[i].y-a*v[i].x;
            int cnt=0;
            for(int k=j+1;k<=n;k++)
                if(p==1) {if(v[k].x==v[i].x) cnt++;}
                else if(egal(1.0*v[k].y,a*v[k].x+b)==1) cnt++;
            sol=(sol-put[cnt]+mod)%mod;
        }
    printf("%d",sol);
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int s[10], c[10];

int main(void)
{
    int N,M;
    cin >> N >> M;
    int n = 1000;
    if(N == 1) n = 10;
    if(N == 2) n = 100;

    REP(i, M){
        cin >> s[i] >> c[i];
    }

    if(N==3)
    Rep(i, 100, n){
        bool f = true;
        vector<int> num(N);
        num[2] = i%10;
        num[1] = (i/10)%10;
        num[0] = (i/100)%10;
        REP(j, M){
            if(num[s[j]-1] != c[j]) f = false;
        }
        if(f){
            pr(i);
            return 0;
        }
    }
    else if(N==2)
    Rep(i, 10, n){
        bool f = true;
        vector<int> num(N);
        num[1] = i%10;
        num[0] = (i/10)%10;
        REP(j, M){
            if(num[s[j]-1] != c[j]) f = false;
        }
        if(f){
            pr(i);
            return 0;
        }
    }
    else if(N==1)
    REP(i, n){
        bool f = true;
        vector<int> num(N);
        num[0] = i%10;
        REP(j, M){
            if(num[s[j]-1] != c[j]) f = false;
        }
        if(f){
            pr(i);
            return 0;
        }
    }
    pr(-1);
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("unroll-loops")
     
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <chrono>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <functional>
    #include <iomanip>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <climits>
    #include <list>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <random>
    #include <ratio>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <unordered_map>
    #include <unordered_set>
    #include <utility>
    #include <vector>
    using namespace std;
     
    typedef long long ll;
    typedef long double LD;
    #define int ll
    #define double LD
    #define pb push_back
    #define mp make_pair
    #define REP(i,n) for (int i = 0; i < n; i++)
    #define loop(i,n) for (int i = 0; i < n; i++)
    #define FOR(i,a,b) for (int i = a; i < b; i++)
    #define REPD(i,n) for (int i = n-1; i >= 0; i--)
    #define FORD(i,a,b) for (int i = a; i >= b; i--)
    #define remax(a,b) a = max(a,b)
    #define remin(a,b) a = min(a,b)
    #define mem(a, b) memset(a, b, sizeof a)
    #define append push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define print(x) cout << (x) << endl
    #define PRECISION(x) cout << fixed << setprecision(x)
    #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
     
    const double PI=acos(-1);
    const int MOD = 1000000007;
    const int FMOD = 998244353;
    const double eps = 1e-9;
     
    mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
  
 
	signed main()
	{
		int n;
		cin>>n;
		string s;
		cin>>s;
		set<int> st[26];
		int q;
		cin>>q;
		for(int i=0;i<n;i++)
		{
			st[s[i]-'a'].insert(i);
		}
		while(q--)
		{
			int type;
			cin>>type;
			if(type==1)
			{
				int idx;
				char c;
				cin>>idx>>c;
				idx--;
				for(int i=0;i<26;i++)
				{
					if(st[i].find(idx)!=st[i].end())
					{
						st[i].erase(idx);
						break;
					}
				}
				st[c-'a'].insert(idx);
				s[idx]=c;
			}
			else
			{
				int ans=0;
				int l,r;
				cin>>l>>r;
				l--;
				r--;
				for(int i=0;i<26;i++)
				{
					auto p=st[i].lower_bound(l);
					if(p!=st[i].end() && *p<=r)
					ans++;
				}
				cout<<ans<<endl;
			}
		}
	}

Measured memory_bytes: 24196
#include <iostream>
#include <cstring>
using namespace std;
int main(){
	int kupc[4];
	string str;
	cin>>str;
	memset(kupc,0,sizeof(kupc));
	for(string::iterator it=str.begin();it!=str.end();it++){
		if((*it)=='K')kupc[0]++;
		else if((*it)=='U')kupc[1]++;
		else if((*it)=='P')kupc[2]++;
		else if((*it)=='C')kupc[3]++;
	}
	cout<<min(kupc[0],min(kupc[1],min(kupc[2],kupc[3])))<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional> 

using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int (i)=0;(i)<(n);++(i))
#define rep(i,st,ed) for(register int (i)=(st);(i)<=(ed);++(i))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<typename T> inline T qmin(const T a,const T b) {return a<b?a:b;}
template<typename T> inline T qmax(const T a,const T b) {return a>b?a:b;}
template<typename T> inline void getmin(T &a,const T b) {if(a>b) a=b;}
template<typename T> inline void getmax(T &a,const T b) {if(a<b) a=b;}

inline void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=1e9+7;
const ll linf=1e17+7;
const int N=3e5+7;

int a[N],n;

int main(){
	scanf("%d",&n);
	n*=3;
	for(int i=1;i<=n;++i) scanf("%d",a+i);
	sort(a+1,a+n+1);
	ll tot=0;
	for(int i=n-1;i>n/3;i-=2) tot+=(ll)a[i];
	printf("%lld\n",tot); 
	return 0;
} 

Measured memory_bytes: 1408
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  vll cnt(n, 0);
  rep(i, m) {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    cnt[u]++;
    cnt[v]++;
  }

  string ans = "YES";
  rep(i, n) {
    if (cnt[i] & 1) {
      ans = "NO";
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int main(void){
    #ifdef ccsnoopy
        freopen("D:/Code/in.txt","r",stdin);
    #endif

    int a,b;
    sc(a);sc(b);

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

    if(a > 0){
        cout << "Positive";
        return 0;
    }

    if(b < 0){
        int selisih = b-a;
        if(selisih % 2){
            cout <<"Positive";
        }else cout << "Negative";
    }



    return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S=="A") cout << "T" << endl;
    if(S=="T") cout << "A" << endl;
    if(S=="C") cout << "G" << endl;
    if(S=="G") cout << "C" << endl;
}

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

using namespace std;

int main() {
	int N, M, C;
	cin >> N >> M >> C;

	vector<int> B(M);
	for (int i = 0; i < M; i++) cin >> B.at(i);

	vector<int> W;

	for (int i = 0; i < N; i++) {
		int Q = 0;
		for (int j = 0; j < M; j++) {
			int A;
			cin >> A;
			Q += A * B.at(j);
		}
		W.push_back(Q);
	}

	int answer = 0;

	for (int i = 0; i < N; i++) {
		if (W[i] + C > 0) answer++;
	}

	cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// vector<int> vec(3); = vector<int> vec={0,0,0}
// vec.at()
// sort(num.begin(),num.end(), greater<int>());
// reverse(num.begin(),num.end());
 
// 切り上げ　a/b+1
//  1からNの総和　N*(N+1)/2
 
int main() {
  int a,b,h;
  cin >> a >> b >> h;
  
  cout << (a+b)*h /2 << endl;

}

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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

vector<int> soinsuuCnt;

void soinsuubunkai(int a)
{
	int p = 2;
	while(a > 1){
		if(a % p == 0){
			int cnt = 0;
			while(a % p == 0){
				a /= p;
				cnt++;
			}
			soinsuuCnt.pb(cnt);
		}else{
			p++;
		}
	}
}

ll mypow(int a, int b)
{
	ll retval = 1;
	if(b == 1)return a;
	if(b % 2 == 0){
		ll m = mypow(a, b / 2);
		retval = (m * m) % MOD;
	}else{
		retval = (mypow(a,b-1) * a) % MOD;
	}
	return retval;
}

ll comb(int n, int r)
{
	r = min(r, n-r);
	ll retval = 1;
	FOR(i,0,r){
		retval *= (n-i);
		retval %= MOD;
		retval *= mypow(i+1, MOD-2);
		retval %= MOD;
	}
	return retval;
}

int main()
{
	int n,m;
	cin >> n >> m;
	soinsuubunkai(m);
	ll ans = 1;
	FOR(i,0,(int)soinsuuCnt.size()){
		ans *= comb(soinsuuCnt[i] + n - 1, n-1);
		ans %= MOD;
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,q;cin>>n>>k>>q;
  vi A(n);
  ll ans=llINF;
  for(auto &a:A)cin>>a;
  for(int i=0;i<n;i++){
    vi ansvec;
    vi tmp;
    for(int j=0;j<n;j++){
      if(A[j]<A[i]){
	if(tmp.size()>=k){
	  sort(ALL(tmp));
	  for(int ii=0;ii<tmp.size()-k+1;ii++)
	    ansvec.pb(tmp[ii]);
	}
	tmp.clear();
      }else{
	tmp.pb(A[j]);
      }
    }
    if(tmp.size()>=k){
      sort(ALL(tmp));
      for(int j=0;j<tmp.size()-k+1;j++)
	ansvec.pb(tmp[j]);
    }
    if(ansvec.size()>=q){
      sort(ALL(ansvec));
      //cout<<ansvec[q-1]<<" "<<ansvec[0]<<endl;
      ans=min(ans,ansvec[q-1]-ansvec[0]);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);


	int n, x;
	cin >> n >> x;
	if (x == 1 || x == n + n - 1)
	{	
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	vector < int > a(n + n - 1);
	a[n - 1] = x;
	int cur = x;
	for (int i = n; i < n + n - 1; i++)
	{
		cur++;
		if (cur > n + n - 1)
			cur -= n + n - 1;
		a[i] = cur;	
	}
	for (int i = 0; i < n; i++)
	{
		cur++;
		if (cur > n + n - 1)
			cur -= n + n - 1;
		a[i] = cur;	
	}
	for (int i = 0; i < n + n - 1; i++)	
		cout << a[i] << endl;

	return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    template<class A, class B>inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B>inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int n, k;
        read n >> k;
        int cnt = 0;
        n -= k;
        k--;
        cnt++;
        cnt += (n+k-1)/k;
        echo cnt fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); echo std::fixed << std::setprecision(8); int main_result = Rlyeh::call_of_Cthulhu(114514); return main_result;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int n;
	cin>>n>>s;
	for(int i=0;i<s.size();i++){
		s[i]+=n;
		if(s[i]>'Z') s[i]-=26;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

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

int main()
{
    int n;
    cin >> n;
    int digit = 0;
    int num = 0;
    int i,j;
    for(i = 1;i <= n;++i){
        digit = 0;
        j = i;
        while(j){
            j /= 10;
            ++digit;
        }
        if(digit%2){
            ++num;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
   char m[100010];
   int a,b;
   while (cin>>m)
    {
       a=strlen(m);
       if (m[0]==m[a-1])b=a-3;
       else b=a-2;
       if (b%2==1) cout<<"First"<<endl;
       else cout<<"Second"<<endl;
    }
   return 0;
}


Measured memory_bytes: 384
# Param: Integer a
# Param: Integer b
# Return: (u, v, d) s.t. a*u + b*v = gcd(a, b) = d
def extended_gcd(a, b)
	u0 = 1
	u1 = 0

	return u0, u1, a if b.zero?

	d0 = a	# d0 = a * u0 + b * v0
	d1 = b	# d1 = a * u1 + b * v1

	loop do
		q, r = d0.divmod(d1)
		return u1, (d1 - a * u1) / b, d1 if r.zero?

		d0, d1 = d1, r
		u0, u1 = u1, u0 - q * u1
	end
end

puts extended_gcd(*gets.split.map(&:to_i)).first(2).join(' ')

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

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll power(ll x, ll y)
{
    ll res = 1;

    while (y > 0) {

        if (y & 1)
            res = res * x;


        y = y >> 1;
        x = x * x;
    }
    return res;
}

vector<int> w[200010];

int a1[100000000];
int b1[100000000];
int c1[100000000];
int d1[100000000];


int vis[200010];

void dfs(int nxt , int prev , int val)
{
    vis[nxt] += val;
    for(int i=0;i<(int)w[nxt].size();i++)
        if(w[nxt][i]!=prev)
            dfs(w[nxt][i],nxt,vis[nxt]);
}

int main()
{
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        w[a].push_back(b);
        w[b].push_back(a);
    }
    for(int i=0;i<q;i++){
        int p,x;
        cin>>p>>x;
        vis[p]+=x;
    }
    dfs(1,0,0);
    for(int i=1;i<=n;i++) cout<<vis[i]<<" ";
    cout<<'\n';
    return 0;
}


Measured memory_bytes: 30464
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;
	string s, s1, s2;

	cin >> n >> s;

	ll ans = 0;
	ll cnt;

	FOR(i, 1, n) {
		cnt = 0;
		s1 = s.substr(0, i);
		s2 = s.substr(i);
		vector<bool> v1(26, false);
		REP(j, s1.size()) {
			v1[s1[j] - 'a'] = true;
		}
		vector<bool> v2(26, false);
		REP(j, s2.size()) {
			v2[s2[j] - 'a'] = true;
		}
		REP(j, 26) {
			if (v1[j] && v2[j]) {
				cnt++;
			}
		}
		ans = max(ans, cnt);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import heapq
n, m = [int(i) for i in input().split()]
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for _ in range(m):
  value = heapq.heappop(a)
  value /= 2
  heapq.heappush(a, value)
for i in range(n):
  a[i] = int(-a[i])
print(sum(a))

Measured memory_bytes: 20456
import collections
N,K = list(map(int,input().split()))
R,S,P = list(map(int,input().split()))
t = str(input())
C = collections.Counter(t)
ans = C["r"]*P + C["s"]*R + C["p"]*S
T = [t[i] for i in range(len(t))]
for i in range(K,N):
    if T[i] == T[i-K]:
        if T[i] == "r":
            ans -= P
            T[i] = "v"
        elif T[i] == "s":
            ans -= R
            T[i] = "v"
        else:
            ans -= S
            T[i] = "v"
print(ans)

Measured memory_bytes: 48880
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;

int main() {
    int A,B,T;
    cin >> A >> B >> T;
    int sum = 0;
    for(int t = A;t <= T; t+= A){
        sum += B;
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t,a[maxn];
int main()
{
    int i,j;
    scanf("%d",&n);
    ll ret=0,ok=0;
    rep(i,1,n)scanf("%d",&a[i]),ret+=a[i],ok+=i;
    if(ret%ok!=0)return 0*puts("NO");
    ll x=ret/ok,p=0;
    a[n+1]=a[1];
    rep(i,1,n)
    {
        ll q=a[i]-a[i+1],qq=(q+x)/n;;
        if(qq*n-x!=q)return 0*puts("NO");
        if(qq<0||qq>x)return 0*puts("NO");
        p+=qq;
    }
    if(p!=x)return 0*puts("NO");
    puts("YES");
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(long long i=(a);i<(b);++i)
#define per(i,a,b) for(long long i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll n;
vector<vector<ll> > vv;
ll d[100100];
ll dd[100100];
ll ddd[100100];

ll dfs(ll a, ll p, ll c){
  if(vv[a].sz==1&&p!=-1){
    if(a==n-1){
      d[a] = 1;
      return 1;
    }
    else return 0;
  }
  ll res = 0;
  rep(i,0,vv[a].sz){
    if(vv[a][i]==p)continue;
    res |= dfs(vv[a][i],a,c+1);
  }
  if(a==n-1){
    res = 1;
  }
  d[a] = res;
  return res;
}

void dfs2(ll a, ll p, ll c, ll c1){
  if(vv[a].sz==1&&p!=-1){
    return;
  }
  rep(i,0,vv[a].sz){
    if(vv[a][i]==p)continue;
    dfs2(vv[a][i],a,c+1,c1);
  }
  if(d[a]==1&&c<=c1){
    dd[a] = 1;
  }
  if(d[a]==1&&c>c1){
    dd[a] = 2;
  }
  return;
}

void dfs3(ll a, ll p){
  if(vv[a].sz==1&&p!=-1){
    ddd[a] = 1;
    return;
  }
  rep(i,0,vv[a].sz){
    if(vv[a][i]==p)continue;
    if(dd[vv[a][i]]==2)continue;
    dfs3(vv[a][i],a);
  }
  ddd[a] = 1;
  return;
}

int main() {
  cin>>n;
  vector<vector<ll> > vv_(n,vector<ll>());
  vv = vv_;
  vector<ll> v;
  rep(i,0,n-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    vv[a].pb(b);
    vv[b].pb(a);
  }
  if(n==2){
    cout << "Snuke" << endl;
    return 0;
  }
  clr(d,0);
  dfs(0,-1,0);
  ll c = 0;
  rep(i,0,n){
    if(d[i]==1)c++;
  }
  clr(dd,0);
  dfs2(0,-1,0,(c-1)/2);
  clr(ddd,0);
  dfs3(0,-1);
  ll fen = 0;
  ll sun = 0;
  rep(i,0,n){
    if(ddd[i]==1)fen++;
    else sun++;
  }
  if(n%2==0){
    if(sun>=fen){
      cout << "Snuke" << endl;
    }
    else{
      cout << "Fennec" << endl;
    }
    return 0;
  }
  if(sun>fen){
    cout << "Snuke" << endl;
  }
  else{
    cout << "Fennec" << endl;    
  }
  return 0;
}

Measured memory_bytes: 18176