akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int n,q;
vector<int> G[200005];
vector<ll> cnt(200005, 0), ans(200005, 0);

void dfs(int from, int now, ll score){
    score += cnt[now];
    ans[now] = score;

    for(auto to:G[now]){
        if(to != from){
            dfs(now, to, score);
        }
    }
}

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

    cin >> n >> q;
    for(int i=0; i<n-1; ++i){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for(int i=0; i<q; ++i){
        int p, x; cin >> p >> x;
        cnt[p] += x;
    }

    dfs(-1, 1, 0);

    for(int i=1; i<=n; ++i){
        if(i > 1) cout << ' ';
        cout << ans[i];
    }
    cout << endl;
    
    return 0;
}



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

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

    long long ans = 0;
    vector<int> num(N + 1);
    for (int i = 1; i <= N; i++) {
        for (int j = i; j <= N; j += i) {
            num[j]++;
        }
        ans += (long long)i * num[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 42328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static void Main(string[] args)
    {
        var N = NextInt();
        var M = NextInt();
        var uf = new UnionFind(N + 1);

        for (int m = 0; m < M; m++)
        {
            uf.Unite(NextInt(), NextInt());
        }
        Console.WriteLine(uf.GetSize().Count() - 2);
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
    /// <summary>
    /// UnionFind木
    /// </summary>
    public class UnionFind
    {
        private int[] data;

        public UnionFind(int size)
        {
            data = new int[size];
            for (int i = 0; i < size; i++) data[i] = -1;
        }

        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);

            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }

        public bool IsSameGroup(int x, int y)
        {
            return Root(x) == Root(y);
        }

        public IEnumerable<int> GetSize()
        {
            foreach (var c in data.Where(_ => _ < 0).ToArray())
            {
                yield return -c;
            }

            yield break;
        }

        private int Root(int x)
        {
            return data[x] < 0 ? x : data[x] = Root(data[x]);
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {
	ll n, d, x, y, ans = 0;
	cin >> n >> d;
	while (n--) {
		cin >> x >>y;
		if (x*x + y*y <= d * d)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll INF = 5e15;
int main(){
    vector<priority_queue<ll, vector<ll>, function<bool(ll, ll)>>> v = {
        priority_queue<ll, vector<ll>, function<bool(ll, ll)>>([](const ll &a, const ll &b){return a > b;}),
        priority_queue<ll, vector<ll>, function<bool(ll, ll)>>([](const ll &a, const ll &b){return a < b;})
    };
    ll N;
    cin >> N;
    vector<ll> A(3 * N);
    for(auto &a : A) cin >> a;
    vector<vector<ll>> val(2, vector<ll>(N + 1));
    for(ll i = 0; i <= 1; i++){
        ll sum = 0;
        for(ll j = 0; j < N; j++){
            sum += A[j];
            v[i].push(A[j]);
        }
        val[i][0] = sum;
        for(ll j = 0; j < N; j++){
            v[i].push(A[N + j]);
            sum += A[N + j];
            sum -= v[i].top();
            v[i].pop();
            val[i][j + 1] = sum;
        }
        reverse(A.begin(), A.end());
    }
    reverse(val[1].begin(), val[1].end());
    ll ans = -INF;
    for(ll i = 0; i < N + 1; i++) ans = max(ans, val[0][i] - val[1][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7284
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

int main(){

  int f=0;
  string n;

  cin>>n;
  for(int i=0;i<n.size()/2;i++){
    if(n[i]!=n[n.size()-i-1]){
      f=1;
      break;
    }
  }

  if(f) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <istream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#include <string.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <list>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vi lnum;
typedef long double ld;

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define f first
#define s second

const int MOD9 = 1e9 + 7;
const int MOD91 = 1e9 + 9;
const ll MOD12 = 1e12 + 39LL;
const ll MOD15 = 1e15 + 37LL;
const ll INF = 1000LL * 1000* 1000* 1000* 1000* 1000;
const int base = 330;
const int MAXN = 2e5 + 6;
const double EPS = 1e-12;

using namespace std;
int Sum = 0;
const ll mod = 1000 * 1000 * 1000 + 7;
int n;
int a[100000];
int pref[1000000] , suf[100000];
int b[100000];
int main()
{
	scanf("%d" , &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d" , &a[i]);
		if(!i)
		{
			pref[i] = a[i];
		}
		else
			pref[i] = pref[i - 1] + a[i];
	}
	for(int i = 0; i < n; i++)
	{
		scanf("%d" , &b[i]);
	}
	for(int i = n - 1; i >= 0; i--)
		suf[i] = suf[i + 1] + b[i];
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		ans = max(ans , pref[i] + suf[i]);
	}
	cout << ans;
	//freopen("input.txt" , "r" , stdin);

	//system("pause");
}







Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    s=list(input())
    if s[2]==s[3] and s[4]==s[5]:
        print("Yes")
    else:
        print("No")




if __name__ == "__main__":

    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

//注意事項
// MAX_N と t はしっかり設定
// used[i] は毎回初期化
struct edge{
    ll to, cap, inv;
};
const int MAX_N = 301;
vector<vector<edge> > G(MAX_N, vector<edge>(0));
vector<bool> used(MAX_N, false);
int t;
int dfs(int v, int f) {
    if (v == t) return f;
    used[v] = true;
    //cout<<v<<' '<<f<<endl;
    for (edge &e : G[v]) {
        if (e.cap > 0 && !used[e.to]) {
            int nf = dfs(e.to, min(ll(f), e.cap));
            if (nf > 0) {
                e.cap -= nf;
                G[e.to][e.inv].cap += nf;
                return nf;
            }
        }
    }
    return 0;
}

void add_edge(ll a, ll b, ll c){
    bool directed = false;
    G[a].push_back((edge){b, c, G[b].size()});
    G[b].push_back((edge){a, 0, G[a].size() - 1});
    if(!directed) {
        G[b].push_back((edge) {a, c, G[a].size()});
        G[a].push_back((edge) {b, 0, G[b].size() - 1});
    }
}
int main(){
    cin>>H>>W;
    //頂点0 ~ H-1、H ~ H+W-1、スタートH+W,ゴールH+W+1
    rep(i,H){
        cin>>S;
        rep(j,W){
            if(S[j] == 'S'){
                add_edge(i, H + W, 400);
                add_edge(H + j, H + W, 400);
            }else if(S[j] == 'T') {
                add_edge(i, H + W + 1, 400);
                add_edge(H + j, H + W + 1, 400);
            }else if(S[j] == 'o'){
                add_edge(i, H + j, 1);
            }
        }
    }
    ll ans = 0;
    t = H + W + 1;
    int plus = dfs(H + W, 400);
    while(plus > 0){
        ans += plus;
        rep(i, H + W + 2) used[i] = false;
        plus = dfs(H + W, 400);
    }
    cout<<(ans > 300 ? -1 : ans)<<endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>


using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >>C;
    int tmp = B/A;
    int ans = 0;
    if (tmp<=C)
    {
        ans = tmp;
    }else
    {
        ans = C;
    }
    
    cout << ans << endl;

    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <string.h>
#include<algorithm>
#include <numeric>      // std::accumulate
#include <iomanip>      // std::setprecision


using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define v           vector <int>
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define EPS			 1e-9
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;

bool cmp(const pair<int, int>& a, const pair<int, int>& b)
{
    return (a.second < b.second);
}

int gcd(int a, int b) 
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
long long power(ll n, ll k) 
{
    if (k == 0) return 1;
    ll sq = (power(n, k / 2));
    sq = (sq * sq);
    if (k % 2 == 1)
        sq = (sq * n);
    return sq;
}
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;
}
string to_binary(int x) 
{
    string s;
    while (x > 0) 
    {
        s += (x % 2 ? '1' : '0');
        x /= 2;
    }
    reverse(s.begin(), s.end());
    return s;
}
bool isPerfect(ll x)
{
    if (x < 1) 
        return false;
    ll root(round(sqrt(x)));
    return x == root * root;
}
void solve()
{
    int n;
    cin >> n;
    
    v a(n + 1);

    lp(i, 1, n+1)
    {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1 ; i <= n ; i+=2)
    {
        if (a[i] % 2 == 1)
            ans += 1;
    }

    cout << ans << "\n";
}

int main()
{
    IOS;    
    
    int tt;
    tt = 1;
    // cin >> tt;
    while (tt--)
    {
        solve();
    }
    
}
       

Measured memory_bytes: 3100
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import ceil, floor
import numpy as np
from collections import defaultdict, deque,Counter
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    k = int(input())
    a, b = map(int, input().split())
    flag = False
    for i in range(1000):
        if a <= k * i <= b:
            flag = True
    if flag:
        print("OK")
    else:
        print("NG")


if __name__ == '__main__':
    main()

Measured memory_bytes: 27144
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

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; }
const int INF = 1001001001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

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

  ll k;
  cin >> k;

  if (k <= 12) {
    cout << k << endl;
    return 0;
  }

  vector<ll> lun;
  lun.reserve(2 * k);
  queue<ll> q;
  for (int i = 1; i <= 9; i++) {
    lun.push_back(i);
    q.push(i);
  }
  ll count = 9;
  while (!q.empty()) {
    ll v = q.front(); q.pop();
    ll x = v % 10;
    if (x != 0) {
      lun.push_back(v * 10 + x - 1);
      q.push(v * 10 + x - 1);
      count++;
    }
    lun.push_back(v * 10 + x);
    q.push(v * 10 + x);
    count++;
    if (x != 9) {
      lun.push_back(v * 10 + x + 1);
      q.push(v * 10 + x + 1);
      count++;
    }
    if (lun.size() >= k) break;
  }

  cout << lun[k-1] << endl;

  return 0;
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        String a = f.readLine();
        if (Character.isUpperCase(a.charAt(0))) {
            out.println('A');
        } else {
            out.println('a');
        }

        out.close();
    }
}


Measured memory_bytes: 32680
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
a=sorted(a)
ans=0
count=0
memo=a[0]
for i in range(n):
    x=a[i]
    if x==memo:
        count+=1
    else:
        memo=a[i]
        if count%2==1:
            ans+=1
        count=1
if count%2==1:
    ans+=1
print(ans)


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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  rep(i, n) {
    int work;
    cin >> work;
    if (m.count(work) > 0) {
      cout << "NO" << endl;
      return 0;
    } else {
      m[work] = 1;
    }
  }
  cout << "YES" << endl;
  return 0;
}

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
#define int ll
int T;
const int maxn = 3e3+7;
int n;
//ll a[maxn];
int dp[maxn][maxn];

//check T
void solve()
{
    //cin >> n; rep(i, 0, n) cin >> a[i];
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    const int mod = 998244353;
    //rep(i, 1, c+1) rep(j, 1, d+1) dp[i][j] = 0;
    rep(i, a, c+1) rep(j, b, d+1)
    {
        //if(i > a && j > b) { dp[i][j] += mod-dp[i-1][j-1]*(i+j-2); dp[i][j] %= mod;}
        if(i == a && j == b) {dp[i][j] = 1; continue;}
        dp[i][j] = 0;
        if(i > a && j >= b){ dp[i][j] += dp[i-1][j]*(j); dp[i][j] %= mod; }
        if(i >= a && j > b){ dp[i][j] += dp[i][j-1]*(i); dp[i][j] %= mod;}
        if(i > a && j > b) { dp[i][j] += mod-dp[i-1][j-1]*(i-1)%mod*(j-1)%mod; dp[i][j] %= mod;}
        //dp[]
    }
    /*rep(i, 1, c+1)rep(j, 1, d+1)
    {
        cerr << dp[i][j] << " \n"[j==d];
    }*/
    cout << dp[c][d] << endl;
    return;
}


//g++ -o out -std=c++11 A.cpp

signed main()
{
    fastIO();
    T = 1;
    //cin >> T; //this
    rep(tc, 1, T+1)
    {
        //cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 74060
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    ll a = 0, b = 0, c = 0;

    REP(i, SIZE(S))
    {
        if (S[i] == 'a')
            a++;
        if (S[i] == 'b')
            b++;
        if (S[i] == 'c')
            c++;
    }

    ll min = a;
    if (min > b)
    {
        min = b;
    }
    if (min > c)
    {
        min = c;
    }

    a -= min;
    b -= min;
    c -= min;

    if (a > 1 || b > 1 || c > 1)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
#include <string.h>
 
#define M 1046527
#define L 14
 
char H[M][L];
 
int char2int(char c) {
  switch (c) {
    case 'A': return 1;
    case 'C': return 2;
    case 'G': return 3;
    case 'T': return 4;
    default: return 0;
  }
}
 
long long getKey(char str[]) {
  long long ret = 0, p = 1;
  int i;
  for(i = 0; str[i] != '\0'; i++) {
    ret += p * char2int(str[i]);
    p *= 5;
  }
  return ret;
}
 
int h1(int key) {
  return key % M;
}
 
int h2(int key) {
  return 1 + (key % (M - 1));
}
 
int find(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}
 
int insert(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}
 
int main(void) {
  int i, n;
  char str[L], cmd[9];
  for(i = 0; i < M; i++) {
    /* initialize hash */
    H[i][0] = '\0';
  }
 
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s %s", cmd, str);
 
    if(cmd[0] == 'i') {
      insert(str);
    } else {
      if(find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 17064
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353//1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   vi a(n);
   int s=0;
   map<int,int>mp;
   rep(i,0,n)
   {
       cin>>a[i];
       s+=a[i];
       mp[a[i]]++;
   }
   int q;
   cin>>q;
   while(q--)
   {
       int b,c;
       cin>>b>>c;
       int cnt=mp[b];
       mp[b]=0;
       s-=(cnt*b);
       s+=(cnt*c);
       mp[c]+=cnt;
       cout<<s<<endl;
   }
}


Measured memory_bytes: 10004
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    int N;
    cin >> N;
    ll maxel=0;
    ll sum=0;
    REP(_,N) {
        ll l;
        cin >> l;
        sum += l;
        chmax(maxel,l);
    }
    if (maxel < (sum-maxel)) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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


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

A.sort()
B.sort()
C.sort()

ans = 0
ai = 0
ci = 0

for b in B:
    while ai < n and A[ai] < b:
        ai += 1
    while ci < n and C[ci] <= b:
        ci += 1
    ans += ai * (n - ci)

print(ans)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n),b(n);
    //方針:自分が幸福度高い皿を取りたいし、相手の幸福度高い皿を先にとってしまいたい
    //->おのおのa[i]+b[i]が高い順に取っていけばいいのでは？
    priority_queue<pair<int64_t,int>> dish;
    rep(i,n){
        cin>>a[i]>>b[i];
        dish.push(mp(a[i]+b[i],i));
    }
    vector<bool> eaten(n,false);
    int64_t tp=0,ap=0;
    rep(turn,n){
           while(eaten[dish.top().second]){
               dish.pop();
           }
           eaten[dish.top().second]=true;
           if(turn%2==0)tp += a[dish.top().second];
           else ap += b[dish.top().second];
           dish.pop();
    }
    cout<<tp-ap<<endl;
}

Measured memory_bytes: 6932
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
//#define s second
#define MOD (long long)1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define nax (int)1e5+1
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	void solve(){
		int n;
		cin>>n;
		vector<int> v(n);
		for(int i=0;i<n;i++){
			cin>>v[i];
		}
		int ans =1;
		int	min_so_far = v[0];
		for(int i=1;i<n;i++){
			if(min_so_far >= v[i] ){
				ans++;
				min_so_far = v[i];
			}
		}
		cout<<ans;
	} 
};
 
int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();
 
 return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
use proconio::marker::*;

fn type_of<T>(_: T) -> String{
    let a = std::any::type_name::<T>();
    return a.to_string();
}

#[fastout]
fn main() {
    input! {
        mut s:Chars,
    }
    
    s.sort();
    let s2:String=s.iter().collect();
    println!("{}",if s2=="abc"{"Yes"}else{"No"});
}

Measured memory_bytes: 2176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, i321) => {
        read_value!($next, i32) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: i32, m: i32, ... }
//
// # array
// input! { n: i32, v: [i32; n], }
//
// # matrix
// input! { n: i32, m: i32, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: i32,
//     w: i32,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: i32, b: i32, c: i32,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input! { x: chars, y: chars }
    let mut x = x.clone();
    x.reverse();
    let x: String = x.into_iter().collect();
    let y: String = y.into_iter().collect();
    if x == y {
        println!("{}", "YES");
    } else {
        println!("{}","NO");
    }
}

Measured memory_bytes: 4352
#include<stdio.h>

int main(){
	long long int i,n,num;
	int digit;
	int min = 12;

	scanf("%lld",&n);

	i = 1;
	while( i*i <= n ){
		if( n%i == 0 ){
			num = n/i;
			digit = 0;
			while( num != 0 ){
				num /= 10;
				digit++;
			}

			if( min > digit ) min = digit;
		}
		i++;
	}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
signed main(void){
    int n, m; cin>>n>>m; //n is goal, m is step
    string s; cin>>s;
    //スタートs[n-1]
    vector <int> ans;
    int now = n;
    while(now>0){
        for(int i=m;i>=0;i--){
            if(i == 0) {cout<<-1<<endl; return 0;}
            if(now - i <= 0){
                ans.push_back(now);
                rrep(j,ans.size()){
                    cout<< ans[j] <<' ';
                }
                return 0;
            }
            if(s[now - i] == '0'){
                ans.push_back(i);
                now -= i;
                break;
            }
        }
    }
    cout<<endl;
}


Measured memory_bytes: 1528
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int fun(int arr[], int n);
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n ;i++)
    {
        cin>>arr[i];
    }
    cout<<fun(arr,n);
    cout<<endl;

    return 0;
}
int fun(int arr[], int n)
{
    if(n==0)
        return 0;
    if(n==1)
        return arr[0];
  	if(n==2)
      	return abs(arr[0]-arr[1]);
    int dp[n][2];
    dp[0][0]=0;
    dp[0][1]=0;
    dp[1][0]=abs(arr[1]-arr[0]);
    dp[1][1]=0;
    for(int i=2; i<n; i++)
    {
        if(i==2)
        {
            dp[i][0]=abs(arr[i]-arr[i-1])+dp[i-1][0];
            dp[i][1]=abs(arr[i]-arr[i-2]);
        }
        else if(i==3)
        {
            dp[i][0]=abs(arr[i]-arr[i-1])+min(dp[i-1][0],dp[i-1][1]);
            dp[i][1]=abs(arr[i]-arr[i-2])+dp[i-2][0];
        }
        else
        {
            dp[i][0]=abs(arr[i]-arr[i-1])+min(dp[i-1][0],dp[i-1][1]);
            dp[i][1]=abs(arr[i]-arr[i-2])+min(dp[i-2][0],dp[i-2][1]);
        }
        
    }
    return min(dp[n-1][0],dp[n-1][1]);
    
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
typedef struct{
    int head;
    int tail;
    int right;
    int left;
    int up;
    int down;
} dice;
dice s(dice a) {
    int buf;
    buf = a.tail;
    a.tail = a.down;
    a.down = a.head;
    a.head = a.up;
    a.up = buf;
	return a;
}
dice n(dice a) {
	return s(s(s(a)));
}
dice e(dice a) {
    int buf;
    buf = a.tail;
    a.tail = a.right;
    a.right = a.head;
    a.head = a.left;
    a.left = buf;
	return a;
}
dice w(dice a) {
	return e(e(e(a)));
}
dice rev(dice a) {
	return e(e(a));
}
dice round(dice a) {
	int buf;
	buf = a.right;
	a.right = a.up;
	a.up = a.left;
	a.left = a.down;
	a.down = buf;
	return a;
}
bool same(dice a, dice b) {
	dice c = a;
	rep(i,4) {
		if(c.head == b.head && c.tail == b.tail && c.up == b.up && c.down == b.down && c.right == b.right && c.left == b.left) return true;
		c = round(c);
	}
	return false;
}

int main() {
    int k, a[105][6];
	cin >> k;
	rep(i,k) {
		rep(j,6) {
	        cin >> a[i][j];
		}
	}
	rep(i,k) {
		rep2(j,i+1,k) {
			dice da, db;
			da.head = a[i][0];
			da.down = a[i][1];
			da.right = a[i][2];
			da.left = a[i][3];
			da.up = a[i][4];
			da.tail = a[i][5];
			db.head = a[i+j][0];
			db.down = a[i+j][1];
			db.right = a[i+j][2];
			db.left = a[i+j][3];
			db.up = a[i+j][4];
			db.tail = a[i+j][5];	
			if(same(da,db) || same(s(da), db) || same(n(da), db) || same(e(da), db) || same(w(da), db) || same(rev(da), db)) {
				cout << "No" <<endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;	
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemC
{
    class Program
    {
        static int div = 1000000007;
        static void Main(string[] args)
        {

            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = read[0];
            var M = read[1];


            var stairs = new int[M];
            var noSol = false;
            for (int i = 0; i < M; i++)
            {
                stairs[i] = int.Parse(Console.ReadLine());
                if (i != 0 && stairs[i] - stairs[i - 1] == 1)
                    noSol = true;
            }
            if (noSol)
                Console.WriteLine(0);
            else
            {
                var stepNums = new int[M + 1];
                for (int i = 0; i < stairs.Length + 1; i++)
                {
                    stepNums[i] =  M == 0 ? N :
                        i == 0 ? stairs[i] - 1: 
                        i != M ? stairs[i] - stairs[i - 1] - 2 : N - stairs[M - 1] - 1;
                }
                var stepNumsMax = stepNums.Max();
                var combs = new int[M + 1];
                var ret = 1;
                for(int i = 0; i < stepNums.Length;i++)
                {
                    ret = (int)((long)ret * (long)FibDiv(stepNums[i]) % div);
                }
                Console.WriteLine(ret);
            }

        }
        static Dictionary<int, int> FibDivs = new Dictionary<int, int>();
        static int FibDiv(int n)
        {
            if (FibDivs.ContainsKey(n))
                return FibDivs[n];
            else
            {
                if (n >= 3)
                    FibDivs.Add(n, FibDiv(n - 1) % div + FibDiv(n - 2) % div);
                else if (n == 1)
                    FibDivs.Add(1, 1);
                else if (n == 2)
                    FibDivs.Add(2, 2);
                else if (n == 0)
                    FibDivs.Add(0, 1);

                return FibDivs[n];
            }
        }
        static int CalcCombNumDiv(int n, int twoCnt)
        {
            return SequenceNum(n, twoCnt) / SequenceNum(twoCnt, twoCnt) % div;
        }
        static int SequenceNum(int n, int cnt)
        {
            if (n == 1 || cnt == 0)
                return 1;
            else
                return n * SequenceNum(n - 1, cnt - 1);
        }
        static int Combination(int n, int m)
        {
            if (n == 0) return 0;
            else if (m == 1) return 1;
            else if (n == m) return 1;
            else
                return n * Combination(n - 1, m - 1) / m;
        }
    }
}


Measured memory_bytes: 18272
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
double L[21],a[21],b[21];
int n,m;
int bit_count(int bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

double comp(int k) {
  vector <int> lab;
    for(int i=0;i<n;i++)
    if((k&(1<<i)) != 0) lab.push_back(i);

  double sum = 0;
  for(int i=0;i<lab.size();i++)
    for(int j=i+1;j<lab.size();j++) {
      double x = L[lab[i]] - L[lab[j]];
      double y = a[lab[i]] - a[lab[j]]; 
      double z = b[lab[i]] - b[lab[j]]; 
      double xyz = x*x + y*y + z*z;
      sum += xyz;
    }
  return sum;
}

int main() {
  cin >> n >> m;
  for(int i=0;i<n;i++) cin >> L[i] >> a[i] >> b[i];

  double ans = 0;
  for(int i=0;i<(1<<n);i++)
    if(bit_count(i) == m) ans = max(ans,comp(i));

  printf("%.15f\n",ans);

  return 0;
}

Measured memory_bytes: 1264
import sys
input = sys.stdin.readline
N = int(input())

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

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

T = int(input())
for i in range(N-1):
    T_ = int(input())
    T = lcm(T, T_)

print(T)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	while(1){
        int a[10]={0};
        int n;
        int b;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>b;
            if(b<=9)a[0]++;
            else if(b<=19)a[1]++;
            else if(b<=29)a[2]++;
            else if(b<=39)a[3]++;
            else if(b<=49)a[4]++;
            else if(b<=59)a[5]++;
            else a[6]++;
        }
        for(int i=0;i<7;i++){
            cout<<a[i]<<endl;

        }

	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
#include <algorithm>

int MOD;

std::vector<int> edges[100005];

int dp[100005];
int ans[100005];
int N;

void dfs1(int node){
  dp[node]=1;
  for(int child:edges[node]){
    edges[child].erase(std::find(edges[child].begin(),edges[child].end(),node));
    dfs1(child);
    dp[node]=1LL*dp[node]*dp[child]%MOD;
  }
  dp[node]=(dp[node]+1)%MOD;
  //printf("dp[%d]=%d\n",node,dp[node]);
}

void dfs2(int node,int up){
  //printf("dfs2(%d,%d)\n",node,up);
  std::vector<int> prefix(edges[node].size());
  std::vector<int> suffix(edges[node].size());
  for(int i=0;i<edges[node].size();i++){
    prefix[i]=suffix[i]=dp[edges[node][i]];
  }
  for(int i=1;i<edges[node].size();i++){
    prefix[i]=1LL*prefix[i-1]*prefix[i]%MOD;
  }
  for(int i=(int)edges[node].size()-2;i>=0;i--){
    suffix[i]=1LL*suffix[i+1]*suffix[i]%MOD;
  }
  for(int i=0;i<edges[node].size();i++){
    //printf("prefix[%d][%d]=%d\n",node,i,prefix[i]);
    //printf("suffix[%d][%d]=%d\n",node,i,suffix[i]);
    int child=edges[node][i];
    int curr=up;
    if(i+1<edges[node].size()) curr=1LL*curr*suffix[i+1]%MOD;
    if(i-1>=0) curr=1LL*curr*prefix[i-1]%MOD;
    dfs2(child,(curr+1)%MOD);
  }
  ans[node]=1LL*up*(dp[node]+MOD-1)%MOD;
}

int main(){
  scanf("%d %d",&N,&MOD);
  for(int i=0;i<N-1;i++){
    int X,Y;
    scanf("%d %d",&X,&Y);
    X--,Y--;
    edges[X].push_back(Y);
    edges[Y].push_back(X);
  }
  dfs1(0);
  dfs2(0,1);
  for(int i=0;i<N;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}


Measured memory_bytes: 17664
def main():
    S = input()

    AC(S)


def AC(S):
    n = len(S)
    a = [0] * (n-1)

    def rec(i, n):
        ans = 0
        if i == n:
            ss = list(S)
            for j, x in enumerate(a):
                if x == 1:
                    ss[j] = ss[j] + "+"
            #print("".join(ss))
            for x in "".join(ss).split("+"):
                ans += int(x)
            return ans

        a[i] = 1
        ans += rec(i + 1, n)
        a[i] = 0
        ans += rec(i + 1, n)
        return ans
    ans = rec(0, n-1)
    print(ans)


def WA(S):
    ans = 0
    for n in range(len(S)):
        x = f(S, n)
        ans += x

    print(ans)


def f(S, n):
    ans = 0
    if n == 0:
        ans = int(S)
    elif len(S) - 1 == n:
        ans = sum(map(int, S))
    elif n == 1:
        for i in range(len(S)-1):
            x = int(S[:i+1]) + int(S[i+1:])
            ans += x
            print(S, n, i, x)
    else:
        for i in range(len(S)-1):
            x = S[:i+1]
            y = S[i+1:]
            if len(y) > n - 1:
                ans += int(x) + f(y, n-1)

    print(S, n, ans, sep="\t")
    return ans


if __name__ == '__main__':
    main()


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



int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  string s; cin >> s;
  bool ok = 1;
  for (int i = 1; i <= (int) s.size(); ++i) {
    if (i & 1) {
      if (!(s[i - 1] == 'R' or s[i - 1] == 'U' or s[i - 1] == 'D')) {
        ok = 0;
      }
    } else {
      if (!(s[i - 1] == 'L' or s[i - 1] == 'U' or s[i - 1] == 'D')) {
        ok = 0;
      }
    }
  }
  cout << (ok? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
Sw = []
for i in range(M):
    k, *ss = list(map(int, input().split()))
    Sw.append((k, ss))
ps = list(map(int, input().split()))
for idx,p in enumerate(ps):
    Sw[idx] = (Sw[idx][0], Sw[idx][1], p)
# print(Sw)

def is_on(sw_i, strbi, pi):
    # print(sw_i, strbi, pi)
    return len(list(filter(lambda x:x, map(lambda i: bool(int(strbi[i-1])), sw_i[1]))))%2 == pi

cnt = 0

for strb in [str(bin(x))[2:] for x in range(0, 2**N)]:
    if all(map(lambda sw: is_on(sw, strb.zfill(N), sw[2]), Sw)):
        cnt += 1

print(cnt)


Measured memory_bytes: 3188
// This is my template for fast solving

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
// #include <complex>
// #include <random>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
// const ll INF = 1e18;
// const ld INF = 1e20;
// const ll MOD = 1e9 + 7;
// const ld EPS = 1e-10;
// const ld PI = acos(-1);

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i];
        if (i + 1 != v.size()) {
            os << " ";
        }
    }
    return os;
}



void kek(int i, string& s, vector<int>& v) {
    v[i] = 0;
    int j = i + 1;
    while (j < v.size() && s[j - 1] == '<') {
        v[j] = max(v[j - 1] + 1, v[j]);
        ++j;
    }

    j = i - 1; 
    while (j >= 0 && s[j] == '>') {
        v[j] = max(v[j + 1] + 1, v[j]);
        --j;
    }
}

void solve() {
    string s;
    cin >> s;
    vector<int> v(s.length() + 1, 0);
    if (s[0] == '<') {
        kek(0, s, v);
    }
    if (s[s.length() - 1] == '>') {
        kek(s.length(), s, v);
    }
    for (int i = 0; i < s.length() - 1; ++i) {
        if (s[i] == '>' && s[i + 1] == '<') {
            kek(i + 1, s, v);
        }
    }
    ll ans = 0;
    for (auto x : v) {
        ans += x;
    }
    cout << ans << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    solve();
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    for (int i = 1; i < MAX; ++i) {
        if (A * i % B == C) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()


def solve():
    K = ni()
    S = ns()
    if len(S) > K:
        print(S[:K] + "...")
    else:
        print(S)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 9128