akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 1010;
const int mod = 1e9 + 7;
int dp[maxn][maxn];
int inv_pw[maxn][maxn];
int n, a, b, c, d;
struct Math{
    private: long long f[maxn];
    public:
    Math(){f[0] = 0;};
    long long add(long long x, long long y) { 
        x += y;
        if(x >= mod) x -= mod;
        if(x < 0) x += mod;
        if(x < 0 || x >= mod) x = (x + mod) % mod;
        return x;
    }
    long long mul(long long x, long long y) { return (add(x, mod) * add(y, mod)) % mod; }
    long long fast_pow(long long n, long long k){
            if(k == 0) return 1LL;
            long long ans = fast_pow(n, k >> 1);
            ans = mul(ans, ans);
            if(k & 1) ans = mul(n, ans);
            return ans;
    }
    long long inv(long long x) { return fast_pow(x, mod - 2); }
    void init_fact(){
        f[0] = 1LL;
        for(int i = 1 ; i < maxn ; ++i)
            f[i] = mul(i, f[i - 1]);
    }
    long long fact(int x){
        assert(x >= 0 && x < maxn);
        if(!f[0]) init_fact();
        return f[x];
    };
}math;

int solve(int i, int sz){
    if(i == n) return math.fact(n);
    if(sz > b) return 0;
    int &ret = dp[i][sz];
    if(~ret) return ret;
    ret = solve(i, sz + 1);
    if(i + c * sz > n) return ret;
    int j = i + c * sz, ng = c;
    int p = inv_pw[sz][c];
    while(j <= n && ng <= d){
        ret = math.add(ret, math.mul(inv_pw[ng][1], math.mul(p, solve(j, sz + 1))));
        p = math.mul(p, inv_pw[sz][1]);
        ng++;
        j += sz;
    }
    return ret;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    for(int i = 0 ; i < maxn ; ++i){
        inv_pw[i][0] = 1;
        inv_pw[i][1] = math.inv(math.fact(i));
        for(int j = 2 ; j < maxn ; ++j)
            inv_pw[i][j] = math.mul(inv_pw[i][j - 1], inv_pw[i][1]);
    }
    cin >> n >> a >> b >> c >> d;
    memset(dp, -1, sizeof dp);
    cout << solve(0, a) << '\n';
    return 0;
}

Measured memory_bytes: 16256
/******************************************
*    AUTHOR:         julianferres         *
******************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define show(v,n) cerr << #v << " = "; forn(i,n) cerr << v[i] << " "; cerr << endl;
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
const int inf = 1<<30; // const ll inf = 1LL<<62;
const int mod = 1e9+7; // 998244353
const int N  = 3005;

ll dp[N][N],pre[N][N]; //dp[i][j] using i numbers and finish with j
int n; string s;

void add(ll &a, ll b){
	a+=b;
	if(a>=mod) a-=mod;
}

int main(){
    FIN;
    cin >> n >> s;
    dp[1][1] = 1;

    forr(i,2,n+1){
    	forr(a,1,i) pre[i-1][a] = pre[i-1][a-1] + dp[i-1][a];
    	forr(a,1,i+1){
    		ll l,r;
    		if(s[i-2] == '<') l = 1, r = a-1;
    		else l = a, r = i-1;
            if(l<=r) dp[i][a] = (pre[i-1][r]-pre[i-1][l-1]+mod)%mod;
    	}

    }

    ll ans = 0;
    forr(i,1,n+1) add(ans, dp[n][i]);
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 139648
#include <iostream>
#include <queue>

int main(){
    
    std::priority_queue<int> pq;
    int a;
    while(std::cin >> a) {
        pq.push(a);    }
    
    for (int i = 0; i < 3; ++i) {
        std::cout << pq.top() << "\n"; pq.pop();
    }
    
    return 0;
}


Measured memory_bytes: 3136
(function(input) {
    var a = parse(input);
    a = a.map(function(e) { return e.map(Number); });
    var n = a[0][0];
    var m = a[0][1];
    a.shift();
    
    var aa = a.slice(0, n);
    var b = a.slice(n, n + m).map(function(e) { return e[0]; });

    var c = [];
    for (var i = 0; i < n; i++) {
        var r = 0;
        for (var j = 0; j < m; j++) {
            r += aa[i][j] * b[j];
        }
        c.push(r);
    }
    console.log(c.join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function parse(str, sep, ter) {
    sep = sep || ' ';
    ter = ter || '\n';
    str = str.replace(/\n$/, '');
    var a = str.split(ter);
    for (var i = 0; i < a.length; i++) {
        a[i] = a[i].split(sep);
    }
    return a;
}

Measured memory_bytes: 10032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vi = vector<int>;
const int M = 10;

const vi ZERO(M,0);
vi I(M);

struct LazySegTree{
    int n;
    vector<vi> dat,lazy;
    //初期化
    LazySegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<vi>(2*n-1,ZERO);
        lazy=vector<vi>(2*n-1,I);

        rep(i,_n) dat[i+(n-1)][0] = 1;
        for(int i=n-2; i>=0; --i) dat[i][0] = dat[2*i+1][0]+dat[2*i+2][0];
    }
    void setLazy(int k, const vi &f){
        if(k >= 2*n-1) return;

        vi inv[M];
        rep(i,M) inv[lazy[k][i]].pb(i);

        rep(i,M){
            int nx = f[i];
            for(int j:inv[i]) lazy[k][j] = nx;
        }
    }
    void push(int k, int l, int r){
        if(lazy[k] != I){
            setLazy(2*k+1,lazy[k]);
            setLazy(2*k+2,lazy[k]);
        }

        vi n_dat(ZERO);
        rep(i,M) n_dat[lazy[k][i]] += dat[k][i];
        dat[k] = n_dat;

        lazy[k] = I;
    }
    void fix(int k, int l, int r){
        push(2*k+1,l,r);
        push(2*k+2,l,r);
        rep(i,M) dat[k][i] = dat[2*k+1][i]+dat[2*k+2][i];
    }
    //内部的に投げられるクエリ
    void _change(int a, int b, int k, int l, int r,int x, int y){
        if(r<=a || b<=l) return;
        if(a<=l && r<=b){
            vi f(I);
            f[x] = y;
            setLazy(k,f);
            return;
        }
        push(k,l,r);

        _change(a,b,2*k+1,l,(l+r)/2,x,y);
        _change(a,b,2*k+2,(l+r)/2,r,x,y);

        fix(k,l,r);
    }
    //[a,b)
    void change(int a, int b, int x, int y){
        return _change(a,b,0,0,n,x,y);
    }
    //内部的に投げられるクエリ
    int _count(int a, int b, int k, int l, int r, int x, int y){
        if(r<=a || b<=l) return 0;
        if(a<=l && r<=b){
            push(k,l,r);
            int ret = 0;
            for(int i=x; i<=y; ++i) ret += dat[k][i];
            return ret;
        }
        push(k,l,r);

        int vl=_count(a,b,2*k+1,l,(l+r)/2,x,y);
        int vr=_count(a,b,2*k+2,(l+r)/2,r,x,y);
        return vl+vr;
    }
    //[a,b)
    int count(int a, int b, int x, int y){
        return _count(a,b,0,0,n,x,y);
    }
};


const int N = 100010;
vector<int> G[N];

int L[N],R[N];
int sz = 0;

void dfs(int v, int p){
    L[v] = sz++;
    for(int e:G[v])if(e!=p) dfs(e,v);
    R[v] = sz++;
}

int main(){
    rep(i,M) I[i] = i;

    int n,q;
    scanf(" %d %d", &n, &q);

    rep(i,n-1){
        int u,v;
        scanf(" %d %d", &u, &v);
        G[u].pb(v);
        G[v].pb(u);
    }

    dfs(0,-1);

    LazySegTree s(sz);
    rep(i,q){
        int t,r,x,y;
        scanf(" %d %d %d %d", &t, &r, &x, &y);

        if(t==1) printf("%d\n", s.count(L[r],R[r]+1,x,y)/2);
        else s.change(L[r],R[r]+1,x,y);
    }
    return 0;
}



Measured memory_bytes: 87640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t;cin>>t;
    map<string,ll>mp;
    while(t--)
    {
        string s;cin>>s;
        mp[s]++;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;
}


Measured memory_bytes: 3568
import math

a,b=map(int,input().split())

for i in range(1,10001):
  a_num=math.floor(i*0.08)
  b_num=math.floor(i*0.1)
  if (a_num==a) and (b_num==b):
    print(i)
    exit()
    
print(-1)
  

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

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    for (size_t i = A; i <= B; i++) {
        string p = to_string(i);
        if (p[0]==p[4]&&p[1]==p[3]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	string s1, s2;
	int n, n1[100], n2[100];cin >> n;
	for(int g = 0;g < n;g++){
		cin >> s1 >> s2;
		for(int i = 0;i < 100;i++)n1[i] = n2[i] = 0;
		if(s1.size()>80 || s2.size()>80){
			cout << "overflow" << endl;
			continue;
		}
		for(int i = 0;i < s1.size();i++)n1[i] = s1[s1.size()-i-1] - '0';
		for(int i = 0;i < s2.size();i++)n2[i] = s2[s2.size()-i-1] - '0';
		
		for(int i = 0;i < 90;i++){
			n1[i] += n2[i];
			if(n1[i] > 9){n1[i] = n1[i]%10;n1[i+1]++;}
		}
		int flag = 0;
		for(int i = 90;i >= 0;i--){
			if(!flag && i == 0){cout << n1[0];break;}
			if(flag && i >= 80){flag = 2;break;}
			if(flag)cout << n1[i];
			if(!flag && i > 0 && n1[i-1] != 0)flag = 1;
		}
		if(flag == 2)cout << "overflow";
		cout << endl;
	}
	return 0; 
}

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

int main() {
  int n, h, oh, c = 0, maxc = 0;
  cin >> n >> h;

  REP(i, n - 1) {
    oh = h;
    cin >> h;
    if (oh >= h) {
      c++;
    } else {
      if (c > maxc) maxc = c;
      c = 0;
    }
  }
  if (c > maxc) maxc = c;

  cout << maxc << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 */
#include <bits/stdc++.h>
 
using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long


/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false)

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
// `chmax(a, b)` aがbより小さければ、aをbに上書きする。chminは逆
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; }

const int MOD = 1e9 + 7;
int main() {
    INIT();

    ll n,m;

    cin >> n >> m;
    REP(i,m) {
        ll a;
        cin >> a;
        n -= a;
        if(n < 0) {
            cout << fixed << -1;
            return 0;

        }
    }
    cout << fixed << n;
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  double ans = 0;
  ans = v.at(0)/pow(2, n-1);
  for(int i = 1; i < n; i++){
    ans += v[i]/pow(2, n - i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream> 
#include <string>
#include <cmath> 
#include <algorithm>
using namespace std;
int main() {
	int n, a, b, c;
	cin >> n;
	int v[n + 1][3] = {0};
	cin >> a >> b >> c;
	v[1][0] = a;
	v[1][1] = b;
	v[1][2] = c;
	for (int i = 2; i <= n; i++) {
		cin >> a >> b >> c;
		v[i][0] = a + max(v[i - 1][1], v[i - 1][2]);
		v[i][1] = b + max(v[i - 1][0], v[i - 1][2]);
		v[i][2] = c + max(v[i - 1][0], v[i - 1][1]);
	} 
	cout << max(max(v[n][0], v[n][1]), v[n][2]) << endl;
	return 0; 
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define MAX std::numeric_limits<lld>::max();
#define MIN std::numeric_limits<lld>::min();
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    dbl n, m;
    cin >> n;
    cin >> m;
    cout << (n*(n-1))/2 + (m*(m-1))/2 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    using namespace std;
    int p,q,r,min;
    int a[3];
    cin >> p >> q >> r;

    a[0] = p + q;
    a[1] = q + r;
    a[2] = p + r;

    for(int i = 0; i < 3 ; i++){
        if(i == 0){
            min = a[0];
        }else if(min > a[i]){
            min = a[i];
        }
    }
    cout << min;
}

Measured memory_bytes: 256
import Control.Monad

main = do

  a <- replicateM 3 $ map read . words <$> getLine

  n <- readLn

  b <- replicateM n readLn

  putStr $ solve a b

solve :: [[Int]] -> [Int] -> String

solve a' b

  | any eval line = "Yes"

  | otherwise = "No"

  where

    a = concat a'

    line = [0, 4, 8] : [2, 4, 6]

         : [[i .. i+2] | i <- [0, 3, 6]]

        ++ [[i, i+3, i+6] | i <- [0 .. 2]]

    eval = all (flip elem b) . map (a !!)

      

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <stack>
#include <cmath>
#include <cstdio>
#include <cstdlib> //atoi()を使うため
using namespace std;

int main()
{
  string word;
  int a, b, Ans;
  stack<int> S;
  while(cin>>word){
    if(word == "+"){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a+b);
    }
    else if(word == "-"){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(b-a);
    }
    else if(word == "*"){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a*b);
    }
    else{
      a = atoi(word.c_str());
      S.push(a);
    }

  }
  Ans = S.top();
  cout << Ans <<endl;
  return 0;
}


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

using namespace std;

int main(){

    int n; cin >>n;
    bool flag = true;

    map<string, int>  m;
    map<string, int>  ::iterator it; 

    for(int i=0; i<n; i++){
        string s; cin >> s;
        it = m.find(s);
        if(it != m.end()){
            it->second++;

        }
        else{
            m.insert(make_pair(s,1));

          //  *it.first = s;
          //  *it.second = 1;
        }

        
        }
        int max = 0;
        it = m.begin();
        while(it != m.end()){
            if(it->second > max) max = it->second;
            it++;
        }

        vector<string> v;
        it = m.begin();
        while(it != m.end()){
            if(it->second == max){
                v.push_back(it->first);
            }
            it++;
        }
        sort(v.begin(), v.end());
        for(int i=0; i<v.size(); i++){
            cout << v[i] << endl;
        }
  return 0;

    }
    
    
        
   


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

int main() {
  int x, a;
  int res = 0;
  cin >> x >> a;
  if (x<a) {
    res = 0;
  } else if (x>=a) {
    res = 10;
  }
    cout << res << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
string s[100006];
map<string, int>M;
signed main() {
	int n; cin >> n;
	rep(i, n) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
		M[s[i]]++;
	}
	int cnt = 0;
	for (auto itr = M.begin(); itr != M.end(); itr++) {
		int a = itr->second;
		cnt += a*(a - 1) / 2;
	}cout << cnt << endl;
}

Measured memory_bytes: 18176
import java.util.*;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 入力されるお札枚数
        int N = sc.nextInt();
        // 入力される金額
        int Y = sc.nextInt();


            for(int i = 0; i <= N; i++) {
        
                for (int j = 0; j <= N - i; j++) {

                    int z = N - i - j;
                    
                    int ans = i * 10000 + j * 5000 + z * 1000;
                    
                    if(ans == Y) {
                        System.out.println(i + " " + j + " " + z);
                        return;
                    }

                }
             }

             System.out.println("-1 -1 -1");
                
            sc.close();

        }

    }



Measured memory_bytes: 23124
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  function primeNumber (num) {

    //2 は素数なので true を返す
    if(num === 2) {
        return true;
    } else {

        for(i = 2; i < num; i++) {

        //2以上の数で割ったとき余りが0になれば false を返す。つまり素数ではない。
            if(num % i === 0) {
                return false;
                break;
            }

            //ループが最後まで行く、つまり割れる数がなかったら true を返す。つまり素数。
            if(i + 1 === num) {
                return true;
            }
        }
    }
}

  
 var x = Number(lines[0]);

 while(true){
   var a = primeNumber(x);
   if(a == true){
     console.log(x);
     break;
   }
   x++;
 }
});

Measured memory_bytes: 7628
///created: 28/May/2019 19:59:28

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 1;
typedef long long ll;

int n, g[41][2], ans[41];
ll k, a[N];

void assign(ll v) {
	for (int i = 0; i <= 40; ++i) {
		g[i][v & 1]++;
		v >>= 1;
	}
}

int main() {
	memset(g, 0, sizeof g);
	memset(ans, 0, sizeof ans);
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		assign(a[i]);
 	}
 	for (int i = 0; i <= 40; ++i) {
 		if (g[i][1] > g[i][0])
 			ans[i] = 0;
 		else ans[i] = 1;
 	}
 	ll res = 0, sum = 0;
 	for (int i = 40; i >= 0; --i) {
 		if (ans[i] && res + (1ULL << i) <= k)
 			res += (1ULL << i);
 	}
	for (int i = 1; i <= n; ++i)
		sum += (a[i] ^ res);
	printf("%lld", sum);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
#define FIND(v,i) find(v.begin(),v.end(),i);

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int h,w;
    cin >> h >> w;
    string s[h];
    bool bb=0;
    REP(i,h) cin >> s[i];
    REP(i,h+2){
        REP(j,w+2){
            if(i==0||i==h+1) bb=1;
            if(j==0||j==w+1) bb=1;
            if(bb) cout << "#";
            else cout << s[i-1][j-1];
            bb=0;
        }
        cout << endl;
    }
/////////////////////////////////////////////
}

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

int main() {
  int N;
  cin >> N;
  
  vector <string> S(N);
  map<string, int> A;
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
    A[S.at(i)] = 1;
  }
  
  cout << A.size();
  
  
}


Measured memory_bytes: 25144
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int x = sc.nextInt();
    int i = 1;
    while (true) {
      if (i*x%360==0) {
        System.out.println(i);
    	break;
      }
    	i++;
    }
    
    sc.close();
  }
}

Measured memory_bytes: 35804
using namespace std; 
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll,ll>  
#define MOD 998244353
#define mit map::iterator
#define pii pair<ll,ll>
#define rep(i,a,b)	for(ll i=a;i< b;i++)
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
typedef  long long   int  ll;
//stringstream convert; 
  //  convert << number; 
  //  string s = convert.str();
 ll fact[500005],invfact[500005]; 
 ll power(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
 ll inv(ll x)
{
	return power(x,MOD-2);
}
ll divide(ll x, ll y)
{
	return (x*inv(y))%MOD;
}
ll C(ll n, ll k)
{
	if(k > n) return 0;
	return divide(fact[n], (fact[n - k]*fact[k])%MOD);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
} 
void init(){
	ll p=MOD;
	fact[0]=1;
	ll i;
	for(i=1;i<500005;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=power(fact[i],p-2);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
priority_queue < pair<ll,ll> , vector<pair<ll,ll> >,greater<pair<ll,ll> > > gq;
void ghost()
{   
  	ll i=0,j=0,k=0,l=0,n,r=-10000000000,t=0,q=0,x,y,m;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	if(i%3==0||i%5==0)
    	continue;
    	k=k+i;
	}
	cout<<k<<endl;
}
signed main()
{int test=1;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//cin>>test;
while(test--)
ghost();
return 0;
}

  

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

int main(void){
    char s[1000000];
    unsigned long long int K;
    scanf("%s",s);
    scanf("%lld",&K);

    int len = strlen(s);
    char alla[1000000];
    int i;
    for (i=0; i<len; i++)
        alla[i] = 'a';
    alla[i] = '\0';

    for( i=0; i<len; i++ ){
        if (K >= ('z'+1) - s[i] && s[i] != 'a'){
            K -= ('z'+1) - s[i];
            s[i] = 'a';
        }
    }
    for( i=0; i<K; i++ ){
        if( s[len-1] == 'z' )
            s[len-1] = 'a';
        else
            s[len-1] += 1;
    }

    printf("%s",s);
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;

ll n, a[100001], b[100001], c[100001];
ll ai[100001] = {}, bi[100001] = {}, ci[100001] = {};
int main()
{

    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    for (ll i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    sort(b, b + n);

    for (ll i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    sort(c, c + n);
    ll tmp = 0;
    for (ll i = 0; i < n; i++)
    {
        ll j;
        for (j = tmp; b[j] < c[i] && j < n; j++)
        {
            ci[i]++;
        }
        tmp = j;
        if (i > 0)
            ci[i] += ci[i - 1];
    }
    tmp = 0;
    for (ll i = 0; i < n; i++)
    {
        ll j;
        for (j = tmp; a[j] < b[i] && j < n; j++)
        {
            bi[i]++;
        }
        tmp = j;
        if (i > 0)
            bi[i] += bi[i - 1];
        ai[i] = ai[i - 1] + bi[i];
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        if (ci[i] > 0)
            ans += ai[ci[i] - 1];
    }
    cout << ans;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int N; cin>>N;
    int x=0;
    int ans=1000000000;
    for(int i=1;i<N;i++){
        x=0;
        int j=N-i;
        int I=i; int J=j;
        int k=10,l=10,m,n;
        while(l>0||n>0){
            k=J%10; l=J/10;
            m=I%10; n=I/10;
            x=x+k+m;
            J=J/10; I=I/10;
        }
        ans=min(ans,x);
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n = gets.to_i
a = []
a_temp = []
n.times { a << gets.to_i }
n.times {|i| a_temp << a[i]}
max = a.max
num = a.count(max)
if a.uniq.count != 1
  a_temp.delete(max)
  max2 = a_temp.max
end
n.times do |i|
  puts (a[i]!=max||num>1) ? max : max2
end


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


int main(){
	int N;cin >> N;
	vector<int> A(N);
	rep(i,N){
		int a;cin >> a;
		A[a-1] = i + 1;
	}
	rep(i,N){
		cout << A[i] << " ";
	}
	cout << endl;
}














Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> s(H);
  for(int i=0;i<H;i++)  cin >> s.at(i);

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s.at(i).at(j)=='#'){
        bool flag=false;
        if(j>0 && s.at(i).at(j-1)=='#')  flag=true;
        else if(j<W-1 && s.at(i).at(j+1)=='#')  flag=true;
        else if(i>0 && s.at(i-1).at(j)=='#')  flag=true;
        else if(i<H-1 && s.at(i+1).at(j)=='#')  flag=true;
        if(!flag){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int X[100000];
  for(int i = 0; i < m; i++) {
    cin >> X[i];
  }

  sort(X, X+m, greater<int>());

  int D[100000];
  for(int i = 0; i < m - 1; i++) {
    D[i] = X[i] - X[i+1];
  }
  sort(D, D+m-1, greater<int>());

  int ans = 0;
  for(int i = n - 1; i < m; i++) {
    ans += D[i];
  }

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


Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
using namespace std;
char ch[200005];
int main(){
	scanf("%s",ch);
	int len=strlen(ch);
	for(int i=0;i<len;++i){
		if(ch[i]=='?'){
			ch[i]='D';
		}
	}
	printf("%s\n",ch);
	return 0;
}


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

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, m) cin >> b.at(i);
    rep(i, n) {
        rep(j, m) {
            cin >> a.at(i).at(j);
        }
    }

    int ans = 0;
    rep(i, n) {
        int k = 0;
        rep(j, m) {
            k +=  a.at(i).at(j) * b.at(j);
        }
        k += c;
        if(0 < k) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

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

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define pb push_back
#define sor(vec) sort(vec.begin(),vec.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define fr first
#define sc second

int main(){
	ll n,k;
	cin >> n >> k;
	
	ll ret = 0;
	for(ll i = 1 ; i <= (n-2)%11 ; i ++){
		for(int j = 1 ; j <= 5 ; j ++){
			ll x = (7*(i+1)+(j+1)-7)*9;
			if(x%11 == k)ret ++;
		}
	}
	ret += ((n-2)/11)*5;
	
	cout << ret << endl;
}



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

int main() {
    string str;
    cin >> str;
    int n=0,w=0,s=0,e=0;
    rep(i, str.size()){
        if (str[i] == 'N') n++;
        if (str[i] == 'W') w++;
        if (str[i] == 'S') s++;
        if (str[i] == 'E') e++;
    }
    string ans = "Yes";
    if (n==0 && s!=0) ans = "No";
    if (e==0 && w!=0) ans = "No";
    if (s==0 && n!=0) ans = "No";
    if (w==0 && e!=0) ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = list(str(input()))
dp = [0] * n
for j in range(n-1):
  if s[j] == "A" and s[j+1] == "C":
    dp[j+1] = 1 + dp[j]
  else:
    dp[j + 1] = dp[j]
for i in range(q):
  l, r = map(int, input().split())
  print(dp[r-1] - dp[l-1])

Measured memory_bytes: 56440
import math 

def dosuu(h,m):
    rad=abs((2*math.pi)*((6*m-(30*h+m/2))/360))
    
    return rad

a,b,h,m=map(int,input().split())

kaku=dosuu(h,m)

rad=math.cos(kaku)

long=(a**2+b**2-2*a*b*rad)**(1/2)
print(long)

Measured memory_bytes: 9428
#include <cstdio>
#include <vector>

int main() {
  size_t N;
  scanf("%zu", &N);

  int res = 0;
  std::vector<int> T(N);
  for (int& t: T) {
    scanf("%d", &t);
    res += t;
  }

  int M;
  scanf("%d", &M);
  for (int i = 0; i < M; ++i) {
    int P, X;
    scanf("%d %d", &P, &X);
    --P;
    printf("%d\n", res-T[P]+X);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int n;
  cin>>n;
  vector<int>v(2*n);
  rep(i,2*n)cin>>v[i];
  sort(all(v));
  int ans=0;
  rep(i,n*2){
    ans+=v[i];
    i++;
  }
  cout<<ans<<endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;

const int MAXN = 100005;

int path[MAXN << 1], depth[MAXN << 1], idx[MAXN];  // idx: index of node in dfs path
vi adjList[MAXN];

class SparseTable {	 // return index of minimum number
private:
    int n, h;
    vvi t;

    int combine(int l, int r){
        if (l == -1 || r == -1) return max(l,r);
        return depth[l] < depth[r] ? l : r;
    }
public:
    SparseTable(int size){
        n = size; h = ( n == 1 ? 1 : ceil(log2(n)));
        t.assign(h, vi());

        t[0].assign(n,0);
        for (int i = 0; i < n; i++) t[0][i] = i;
        for (int i = 1; i < h; i++) {
            t[i].assign(n,0);
            for (int j = 0; j + (1<<i) <= n; j++){
                t[i][j] = combine(t[i-1][j],t[i-1][j+(1<<(i-1))]);
            }
        }
    }
    int query(int l, int r){                            // query in range v[l,r)
        int p = 31 - __builtin_clz(r-l);
        return combine(t[p][l],t[p][r-(1<<p)]);
    }
};

// build dfs path, depth
int cnt = 0;
void dfs(int curr, int d){
    idx[curr] = cnt;
    
    path[cnt] = curr;
    depth[cnt++] = d;
    for (int i = 0; i < adjList[curr].size(); i++){
        dfs(adjList[curr][i],d+1);

        path[cnt] = curr;
        depth[cnt++] = d;
    }
}
int N, M, Q, v;

int main(){

    scanf("%d",&N);
    for (int u = 0; u < N; u++){
        scanf("%d",&M);
        for (int i = 0; i < M; i++){
            scanf("%d",&v);

            adjList[u].push_back(v);
        }
    }

    // rooted as 0
    dfs(0,0);
    SparseTable st(cnt);

    scanf("%d",&Q);
    for (int i = 0, u, v, l, r; i < Q; i++){
        scanf("%d%d",&u,&v);

        l = idx[u], r = idx[v]; if (l > r) swap(l,r);

        int id = st.query(l,r+1);
        printf("%d\n",path[id]);
    }

    return 0;
}

Measured memory_bytes: 27164
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e,f,g,h, i, j, k, l, m, n, o, p, q, r,s,t,u;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	a = min(a, b);
	a = min(a, c);
	d = min(d, e);
	e = a + d;
	cout << e-50 << endl;
	return 0;
}

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

int main() {  
	int N;
  	cin >>N;
  string s;
  map<string,int>counter;
  for(int i=0;i<N;i++){
  	cin >>s;
	counter[s]+=1;
  }
  int smax=0;
  for(auto k :counter){
  smax= max(smax,k.second);
  }
  for(auto j:counter){
  if(j.second==smax){cout << j.first <<endl;}
  }
}

Measured memory_bytes: 25216
N,L,T = map(int, input().split())
X = [0]*N
W = [0]*N
for n in range(N):
    X[n],W[n] = map(int, input().split())
index = 0
#after T
for n in range(N):
    X[n] += ((-1)**(W[n]+1))*T
    index += X[n]//L
    X[n] %= L
index %= N
X.sort()
X = X[index:] + X[:index] #No.1 wo hajimeni mottekuru.
for n in range(N):
    print(X[n])

Measured memory_bytes: 9336
int main(void){
  int N, tmp, count = 0;
  scanf("%d", &N);
  int A[N];
  for(int i=0; i<N; i++) scanf("%d", &A[i]);

  for(int i=0; i<N; i++){
    int minj = i;
    for(int j=i; j<N; j++){
      if(A[j] < A[minj]) minj = j;
    }
    if(minj != i) count += 1; 
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
  }
  
  for(int k=0; k<N; k++){
    printf("%d",A[k]);
    if(k<N-1) printf(" ");
  }

  printf("\n%d\n", count);
  
  return 0;
}


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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; j < (n); k++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a * b / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

// { x in (l, r] | x mod m = a } の要素数
LL cmCI(LL l, LL r, LL m, LL a) { assert(m > 0); return max(0LL, fl(r - a, m) - fl(l - a, m)); }
LL cmCD(LL l, LL r, LL m, LL a) { return cmCI(l    , r - 1, m, a); }
LL cmII(LL l, LL r, LL m, LL a) { return cmCI(l - 1, r    , m, a); }
LL cmID(LL l, LL r, LL m, LL a) { return cmCI(l - 1, r - 1, m, a); }

int main() {
	LL n, m;
	cin >> n >> m;
	vector<LL> a(n);
	inc(i, n) { cin >> a[i]; }
	
	auto solve = [&]() -> int {
		set<int> se;
		inc(i, n) {
			int c = 0;
			LL aa = a[i];
			until(aa % 2 != 0) { c++; aa /= 2; }
			se.insert(c);
		}
		if_not(SI(se) == 1) { return 0; }
		
		LL l = 1;
		inc(i, n) {
			l = lcm(l, a[i]);
			if(l > 2 * m) { return 0; }
		}
		
		return cmII(2, 2 * m, 2 * l, l);
	};
	
	cout << solve() << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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;}

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

  vi to[200005];
  vi ans;

  int N, Q; cin >> N >> Q;
  REP(i,N-1) {
    int a, b; cin >> a >> b;
    --a; --b;
    to[a].PB(b);
    to[b].PB(a);
  }

  ans.resize(N);
  REP(i,Q) {
    int p, x; cin >> p >> x;
    --p;
    ans[p] += x;
  }

  vector<bool> checked(N,false);
  queue<int> que;
  que.push(0);
  checked[0] = true;

  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto &next : to[node]) {
      if (!checked[next]) {
        ans[next] += ans[node];
        que.push(next);
        checked[next] = true;
      }
    }
  }

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

Measured memory_bytes: 15604
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;

	int x = stoi(s.substr(0, 2));
	int y = stoi(s.substr(2));

	// cout << x << endl;
	// cout << y << endl;

	bool can_month1 = (1 <= x && x <= 12);
	bool can_month2 = (1 <= y && y <= 12);

	string ans = "NA";
	if (can_month1 && can_month2) {
		ans = "AMBIGUOUS";
	} else if (can_month1) {
		ans = "MMYY";
	} else if (can_month2) {
		ans = "YYMM";
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
from itertools import cycle

INITIALIZE = 32

while True:

    input_count = int(input())

    if input_count == 0:
        break

    get_list = [int(item) for item in input().split(" ")]

    ohajiki = INITIALIZE

    for get_count in cycle(get_list):

        ohajiki -= (ohajiki - 1) % 5
        print(ohajiki)

        if get_count < ohajiki:
            ohajiki -= get_count
            print(ohajiki)
        else:
            print(0)
            break



Measured memory_bytes: 5648
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var c = ReadText().ToCharArray();

            var rcount = c.Where(x => x == 'R').Count();
            var wcount = N - rcount;
            var count = 0;
            var jMax = N - 1;

            for (var i = 0; i < rcount; i++)
            {
                if (c[i] == 'R')
                {
                    continue;
                }
                for (var j = jMax; j > i; j--)
                {
                    if (c[j] == 'R')
                    {
                        c[i] = 'R';
                        c[j] = 'W';
                        count++;
                        jMax = j - 1;
                        break;
                    }

                }
            }
            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 29388
#include<bits/stdc++.h>
using namespace std;
#define     debug       printf("\n<<CameHere<<\n")
#define     mem(x,y)    memset(x, y, sizeof(x))
#define     all(qz)     qz.begin(),qz.end()
#define     rall(qz)    qz.rbegin(),qz.rend()
#define     inf         LLONG_MIN
#define     INF         LLONG_MAX
#define     mod         1000000007
#define     Sqr(x)      ((x)*(x))
#define     ll          long long
#define     mk          make_pair
#define     pb          push_back
#define     pi          acos(-1.0)
#define     cos(a)      cos(a*pi/180)
#define     sin(a)      sin(a*pi/180)
#define     tan(a)      tan(a*pi/180)

ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/
ll ar[8][8];
ll n,m,k;

ll fn(ll x,ll y){
    ll br[8][8];
    for(ll i=0;i<8;i++){
        for(ll j=0;j<8;j++){
            br[i][j]=ar[i][j];
        }
    }
    for(ll i=0;i<7;i++){
        ll xx=(1<<i)&x;
        if(xx!=0){
            for(ll j=1;j<=m;j++){
                br[n-i][j]=0;
            }
        }
    }
    for(ll i=0;i<7;i++){
        ll xx=(1<<i)&y;
        if(xx!=0){
            for(ll j=1;j<=n;j++){
                br[j][m-i]=0;
            }
        }
    }
    ll cnt=0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(br[i][j]==1) cnt++;
        }
    }
    //cout<<x<<" "<<y<<" "<<cnt<<endl;
    return cnt;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //ll n,m,k;
    cin>>n>>m>>k;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            char ch;
            cin>>ch;
            if(ch=='#'){
                ar[i][j]=1;
            }
        }
    }
    ll rr=pow(2,n);
    ll cc=pow(2,m);
    //cout<<rr<<" "<<cc<<endl;
    ll ans=0;
    for(ll i=0;i<rr;i++){
        for(ll j=0;j<cc;j++){
            if(fn(i,j)==k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



















Measured memory_bytes: 4072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int col[8]={};
int cou=0;
int colors=0;
int b;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>b;
		b/=400;
		if(b>7){
			cou++;
		}else{
			if(col[b]==0){
				colors++;
			}
			col[b]=1;
		}
	}
	if(colors==0){
		cout<<1<<" ";
	}else{
		cout<<colors<<" ";
	}
	colors+=cou;
	cout<<colors<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((ll)2e5+5)
#define MOD ((ll)1e9 + 7)
#define INF ((ll)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<ll,ll>
#define mid ((l+r)/2)

ll n;
ll d[MAXN];
unordered_map <ll, ll> mp;
ll ans;

int check(ll x)
{
	for (ll i = 2; i*i <= x; i++)
		if(x%i==0 && (mp[i] or mp[x/i]))
			return 0;

	return (mp[x] <= 1);
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n;
	for (ll i = 0; i < n; ++i)
	{
		cin >> d[i];
		mp[d[i]]++;
	}

	if(mp[1])
	{
		cout << int(mp[1]==1) << endl;
		return 0;
	}

	for (ll i = 0; i < n; ++i)
		ans += check(d[i]);

	cout << ans << endl;
}

/* stuff you should look for
	* ll overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Measured memory_bytes: 33260