akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <map>

#define INF (1 << 30)

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, a, b;
    cin >> n >> m;
    vector< vector<int> > e(n + 1);
    vector< pair<int, int> > p(n + 1, {0, INF});
    for (int i = 0; i < m; ++i) cin >> a >> b, e.at(a).push_back(b), e.at(b).push_back(a);
    queue<int> q;
    q.push(1);
    p.at(1) = {0, 0};
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i : e.at(v)) {
            if (p.at(i).second <= p.at(v).second + 1) continue;
            p.at(i) = {v, p.at(v).second + 1};
            q.push(i);
        }
    }
    cout << "Yes\n";
    for (int i = 2; i <= n; ++i) cout << p.at(i).first << endl;
    return 0;
}


Measured memory_bytes: 10760
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		ArrayList<Integer> listN = new ArrayList<Integer>();
		ArrayList<Integer> listX = new ArrayList<Integer>();

		int count = 0;

		while (true) {

			int n = input();
			int x = input();

			if (n == 0 && x == 0) {

				break;

			} else {

				listN.add(n);
				listX.add(x);

			}
		}

		for (int i = 0; i < listN.size(); i++) {

			for (int j = 1; j <= listN.get(i); j++) {

				for (int k = j + 1; k <= listN.get(i); k++) {

					for (int l = k + 1; l <= listN.get(i); l++) {

						if (j + k + l == listX.get(i)) {

							count++;

						}
					}
				}
			}

			System.out.println(count);
			count = 0;

		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int sum = 0;
        for (char x : s) sum += x - '0';
        if (a <= sum && sum <= b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3712
using System;

class Program
{
    static void Main(string[] args)
    {
        var na = Console.ReadLine().Split();
        var n = int.Parse(na[0]);
        var a = int.Parse(na[1]);

        var s = Console.ReadLine().Split();
        var x = new int[n + 1];
        for (int i = 0; i < n; i++)
        {
            x[i + 1] = int.Parse(s[i]);
        }

        var dp = new long[n + 1, n + 1, a * n + 1];
        dp[0, 0, 0] = 1;

        for (int i = 1; i < dp.GetLength(0); i++)
        {
            for (int j = 0; j < dp.GetLength(1); j++)
            {
                for (int k = 0; k < dp.GetLength(2); k++)
                {
                    if (0 < j && x[i] <= k)
                    {
                        dp[i, j, k] = dp[i, j, k] = dp[i - 1, j, k] + dp[i - 1, j - 1, k - x[i]];
                    }
                    else
                    {
                        dp[i, j, k] = dp[i, j, k] = dp[i - 1, j, k];
                    }
                }
            }
        }

        var ans = 0L;
        for (int j = 1; j <= n; j++)
        {
            ans += dp[n, j, a * j];
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 58720
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string>) {}
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2> buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (const auto e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1000000007;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/
inline int add(int a, int b, int mod = MOD) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
inline int sub(int a, int b, int mod = MOD) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
inline int mul(int a, int b, int mod = MOD) {
  return int((long long) a * b % mod);
}
int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int &z: a) cin >> z;
  for (int &z: b) cin >> z;
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < m; ++i) {
    auto new_dp = dp;
    int sum = 0;
    for (int j = 0; j < n; ++j) {
      sum = add(sum, dp[j]);
      if (a[j] == b[i]) {
        new_dp[j + 1] = add(new_dp[j + 1], sum);
      }
    }
    dp = new_dp;
  }
  int ans = 0;
  for (int z: dp) ans = add(ans, z);
  kek(ans);
  
  return 0;
}


Measured memory_bytes: 256
def parent(i)
  return i/2
end
def left(i)
  return i*2
end
def right(i)
  return i*2+1
end
n=gets.to_i
arr=gets.split.map(&:to_i)
arr.unshift(nil)
(1..n).each do |i|
  print "node #{i}: key = #{arr[i]}, "
  if parent(i)>=1
    print "parent key = #{arr[parent(i)]}, "
  end
  if left(i)<=n
    print "left key = #{arr[left(i)]}, "
  end
  if right(i)<=n
    print "right key = #{arr[right(i)]}, "
  end
  puts ""
end

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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<long long>());

    if (N % 2 == 0) {
        long long res = 0;
        for (int i = 0; i < N/2 - 1; ++i) res += A[i] * 2;
        res += A[N/2 - 1];
        res -= A[N/2];
        for (int i = N/2 + 1; i < N; ++i) res -= A[i] * 2;
        cout << res << endl;
    }
    else {
        long long res1 = 0;
        for (int i = 0; i < N/2 - 1; ++i) res1 += A[i] * 2;
        res1 += A[N/2 - 1] + A[N/2];
        for (int i = N/2 + 1; i < N; ++i) res1 -= A[i] * 2;
        
        long long res2 = 0;
        for (int i = 0; i < N/2; ++i) res2 += A[i] * 2;
        res2 -= A[N/2] + A[N/2 + 1];
        for (int i = N/2 + 2; i < N; ++i) res2 -= A[i] * 2;
        cout << max(res1, res2) << endl;
    }
}

Measured memory_bytes: 4036
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
 
ans = 0
tmp = -1
for a in A:
    ans += B[a-1]
    if a-tmp == 1:
        ans += C[tmp-1]
    tmp = a
print(ans)

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

int getMin(int a,int b,int c){
    int r=a*100+b*10+c;
    return abs(753-r);
}

int main(){
    string s;
    cin>>s;
    int min=INT_MAX;
    for(int i=0;i<s.size()-2;i++)
    {
        int k=getMin(s[i]-'0',s[i+1]-'0',s[i+2]-'0');
        if(k<min){
            min=k;
        }
    }
    cout<<min;
}

Measured memory_bytes: 3616
n = int(input())
dp = [[0]*4 for i in range(n+1)]
mod = 10**9+7

dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 1
dp[1][0] = dp[1][1] = dp[1][2] = dp[1][3] = 4

for i in range(2,n):
    for j in range(4):
        dp[i][j] = sum(dp[i-1])%mod
    dp[i][1] -= dp[i-2][0]
    dp[i][2] -= (dp[i-2][0] + dp[i-2][1])
    if i >= 3:
        dp[i][2] -= 3*dp[i-3][0]
        dp[i][1] += dp[i-3][1]
        

print(sum(dp[n-1])%mod)
    




Measured memory_bytes: 3064
using System;

namespace A___Double_Helix
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Console.ReadLine();

            switch (b)
            {
                case "A":
                    Console.WriteLine("T");
                    break;
                case "G":
                    Console.WriteLine("C");
                    break;
                case "C":
                    Console.WriteLine("G");
                    break;
                case "T":
                    Console.WriteLine("A");
                    break;
                default:
                    break;
            }
        }
    }
}


Measured memory_bytes: 11092
/*input
1 3
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

#define fast_cin() ios_base::sync_with_stdio(false)
#define pb push_back
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug1(x) cerr << x << endl;
#define debug2(x,y) cerr << x << " " << y << endl;
#define debug3(x,y,z) cerr << x << " " << y << " " << z << endl;
#define FOR(i, a, b) for (ll i=a; i<(b); i++)
#define FORR(i, a, b) for (ll i=a; i>=(b); i--)
ll INF = 2000000000000000001;
double EPS = 1e-9;
ll nextll(){ll inp; cin>>inp; return inp;}
string nextStr(){string inp; cin>>inp; return inp;}
double nextDouble(){double inp; cin>>inp; return inp;}
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n,k;
	cin>>n>>k;
	ll val = n/k;
	ll ans = val*val*val;
	if(k%2){
		cout<<ans<<endl;
		return 0;
	}
	val = (n+(k/2))/k;
	ans+=val*val*val;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  ll a;long double b;cin>>a>>b;
  ll bAlt = b * 100 + 0.1;
  print(a*bAlt/100);
  return 0;
}


Measured memory_bytes: 3716
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_num(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

set<pair<int, pair<int, int>>>st;
int n;
int main() {
	cin >> n;
	REP(i, n) {
		vector<int> a(3);
		REP(j, 3)cin >> a[j];
		sort(ALL(a));
		st.insert(make_pair(a[0], make_pair(a[1], a[2])));
	}
	cout << n - (int)st.size() << endl;
}


Measured memory_bytes: 3196
N = int(input())
K = int(input())

def countInRangeUtil(pos, cnt, tight, num): 
    if pos == len(num): 
        if cnt == K: 
            return 1
        return 0
    if dp[pos][cnt][tight] != -1: 
        return dp[pos][cnt][tight] 
    ans = 0
    limit = 9 if tight else num[pos] 
    for dig in range(limit + 1): 
        currCnt = cnt 
        if dig != 0: 
            currCnt += 1
        currTight = tight 
        if dig < num[pos]: 
            currTight = 1
        ans += countInRangeUtil(pos + 1, currCnt, currTight, num) 
    dp[pos][cnt][tight] = ans 
    return dp[pos][cnt][tight] 
  
def countInRange(x): 
    global dp, K, M
    num = []
    while x: 
        num.append(x % 10) 
        x //= 10
    num.reverse() 
    dp = [[[-1, -1] for i in range(M)] for j in range(M)] 
    return countInRangeUtil(0, 0, 0, num)

dp = []
M = 101
print(countInRange(N))

Measured memory_bytes: 4084
N = int(input())
X = []
flag = True
dt=0
dx=0
dy=0

for i in range(N):
    X.append([int(i) for i in input().split()])

for i in X:
     dt = abs(i[0] - dt)
     dx = abs(i[1] - dx)
     dy = abs(i[2] - dy)
     if dx + dy > dt:
         flag = False
     elif (dt - dx - dy) % 2 == 1:
         flag = False

if flag == False:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 21108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    string S,T;
    cin >> S >> T;
    
    string SS = S;
    for (int i = 0; i <= int(S.length()); i++) {
        string NS = SS[S.length()-1] + SS.substr(0, int(S.length()-1));
        if (NS == T) {
            cout << "Yes" << endl;
            return 0;
        }
        SS = NS;
    }
    cout << "No" << endl;
    
    return 0;
}




Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(A: int, B: int):
    print(A + B if B % A == 0 else B - A)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


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

#define INF 1e15

template <typename T>
struct Graph {
    int V, E;
    struct Edge {
        int from, to;
        T cost;
    };
    vector<vector<Edge>> edge;
    vector<vector<T>> dist;
    vector<Edge> es;

    Graph(int V, int E) : V(V), E(E) {
        edge.assign(V, vector<Edge>(0));
        dist.assign(V, vector<T>(0));
    }

    void input(bool is_direct, bool inputc, bool index0 = false) {
        int a, b;
        T c = 0;
        for (int i = 0; i < E; i++) {
            cin >> a >> b;
            if (inputc) cin >> c;
            if (!index0) a--, b--;
            edge[a].push_back((Edge){a, b, c});
            es.push_back((Edge){a, b, c});
            if (!is_direct) {
                edge[b].push_back((Edge){b, a, c});
                es.push_back((Edge){b, a, c});
            }
        }
        if (!is_direct) E *= 2;
    }

    void add_edge(int from, int to, T cost, bool is_direct) {
        edge[from].push_back({from, to, cost});
        es.push_back({from, to, cost});
        if (!is_direct) {
            edge[to].push_back({to, from, cost});
            es.push_back({to, from, cost});
            E++;
        }
        E++;
    }
    bool warshall_floid() {
        dist.assign(V, vector<T>(V, INF));
        for (int v = 0; v < V; v++) {
            for (int i = 0; i < edge[v].size(); i++) {
                dist[v][edge[v][i].to] = edge[v][i].cost;
            }
            dist[v][v] = 0;
        }
        for (int k = 0; k < V; k++) {
            for (int i = 0; i < V; i++) {
                for (int j = 0; j < V; j++) {
                    if (dist[i][k] != INF && dist[k][j] != INF)
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        for (int i = 0; i < V; i++) {
            if (dist[i][i] < 0) return false;
        }
        return true;
    }
};

int main() {
    int V, E;
    ll L;
    cin >> V >> E >> L;
    Graph<ll> g(V, E), gl(V, 0);
    g.input(false, true);
    g.warshall_floid();
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            if (g.dist[i][j] <= L) {
                gl.add_edge(i, j, 1, true);
            }
        }
    }
    gl.warshall_floid();
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        if (gl.dist[s][t] == INF)
            cout << -1 << endl;
        else
            cout << gl.dist[s][t] - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 9584
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
if read string () = "ABC" then "ARC" else "ABC"
|> printfn "%s"

Measured memory_bytes: 29488
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

int n;
vector<int>p;
ll solve(){
   ll ans=0;
   rep(i,n){
       if(i==p[i]){
           ans++;
           if(i<n-1)
           swap(p[i],p[i+1]);
       }
   }

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

    cin>>n;
    p.resize(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 640
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

W, H, N = mapint()
x1, y1 = 0, 0
x2, y2 = W, H
for _ in range(N):
    x, y, a = mapint()
    if a==1:
        x1 = max(x1, x)
    elif a==2:
        x2 = min(x2, x)
    elif a==3:
        y1 = max(y1, y)
    else:
        y2 = min(y2, y)

print(max(x2-x1, 0)*max(y2-y1, 0))

Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if(a>=b){
    cout << "delicious" << endl;
}
    else if(a<b && b-a<=x){
    cout << "safe" << endl;
}
    else if(a<b && b-a>x){
    cout << "dangerous" << endl;
}
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val sequence = readLine()!!.split(" ").map { it.toInt() }

    var diffCount = 0
    for (i in 1..N) {
        if (sequence[i-1] != i) {
            diffCount += 1
        }
    }

    if (diffCount == 2 || diffCount == 0) {
        println("YES")
    } else {
        println("NO")
    }
}


Measured memory_bytes: 36140
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())

if (n>=1000):
    print("ABD")
else:
    print("ABC")





Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n;
ll k,a[N],L,R;
int main(){
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    sort(a,a+n);
    L=-2e18,R=2e18;
    while(L+1!=R){
        ll Mid=(L+R)/2;
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<0){
                int l=i,r=n;
                while(l+1!=r){
                    int mid=(l+r)/2;
                    if(a[i]*a[mid]<=Mid) r=mid;
                    else l=mid;
                }
                cnt+=n-r;
            }
            else{
                int l=i,r=n;
                while(l+1!=r){
                    int mid=(l+r)/2;
                    if(a[i]*a[mid]<=Mid) l=mid;
                    else r=mid;
                }
                cnt+=l-i;
            }
        }
        if(cnt<k) L=Mid;
        else R=Mid;
    }
    printf("%lld",R);
    return 0;
}
//#include <bits/stdc++.h>
//using namespace std;
//typedef long long ll;
//int n;
//ll k,arr[202020],st,en;
//main()
//{
//	scanf("%d%lld",&n,&k);
//	for(int i=0;i<n;i++) scanf("%lld",arr+i);
//	sort(arr,arr+n); st=-2e18; en=2e18;
//	while(st+1!=en)
//	{
//		ll mid=(st+en)/2;
//		ll gesu=0;
//		for(int i=0;i<n;i++)
//		{
//			if(arr[i]<0)
//			{
//				int l=i,r=n;
//				while(l+1!=r)
//				{
//					int m=(l+r)/2;
//					if(arr[i]*arr[m]<=mid) r=m;
//					else l=m;
//				} gesu+=n-r;
//			} else
//			{
//				int l=i,r=n;
//				while(l+1!=r)
//				{
//					int m=(l+r)/2;
//					if(arr[i]*arr[m]<=mid) l=m;
//					else r=m;
//				} gesu+=l-i;
//			}
//		} if(gesu<k) st=mid;
//		else en=mid;
//	} printf("%lld",en);
//}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int K; cin >> K;
  for (int i = 0; i < K; i++) {
    int x; cin >> x; x--;
    Input[x] = i + 1;
  }
  for (int i = 0; i < K; i++) {
    cout << Input[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 1152
#include <stdio.h>
int main(void){
    int i;
    double c,ans,n,a[1000];
    scanf("%lf", &n);
    for(i = 0;i < n;i ++){
        scanf("%lf", &a[i]);
    }
    ans = 0;
    for(i = 0;i < n;i ++){
        c = 1 / a[i];
        ans = ans + c;
    }
    ans = 1 / ans;
    printf("%.5lf\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it,o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;


bool hate[10];

bool valid(int n){
    stringstream ss;
    ss << n;
    string s = ss.str();
    rep(i, s.length()){
        if(hate[s[i]-'0'])return false;
    }
    return true;
}

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, k){
        int t;
        cin >> t;
        hate[t] = true;
    }

    while(1){
        if(valid(n)){
            cout << n << endl;
            break;
        }
        n++;
    }


    return 0;
}


Measured memory_bytes: 256
from itertools import combinations
n = int(input())
root = 1 + 8 * n
if int(root ** 0.5) ** 2 != root:
    print('No')
    exit()

k = (1 + int(root ** 0.5)) // 2
ans = [[] for _ in range(k)]

for i, a in enumerate(combinations(range(k), 2)):
    s, t = a
    ans[s].append(i + 1)
    ans[t].append(i + 1)
print('Yes')
print(k)
for List in ans:
    print(k - 1, *List)

Measured memory_bytes: 12624
40
NYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

Measured memory_bytes: 6384
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cmath>
using namespace std;

void solve(void) {

  int N;
  cin >> N;
  vector<int> P(N);
  vector<int> Q(N);
  for (int pi = 0; pi < N; ++pi) cin >> P[pi];
  for (int qi = 0; qi < N; ++qi) cin >> Q[qi];

  vector<int> num(N);
  iota(num.begin(), num.end(), 1);


  int a = 0, b = 0;
  int pos = 0;
  do {
    ++pos;
    bool p_flag = true, q_flag = true;
    for(int ni = 0; ni < N; ++ni) {
      if (num[ni] != P[ni]) p_flag = false;
      if (num[ni] != Q[ni]) q_flag = false;

      if (!(p_flag) && !(q_flag)) break;
    }

    if(p_flag) a = pos;
    if(q_flag) b = pos;
  }while(next_permutation(num.begin(), num.end()));

  cout << abs(a - b) << endl;
}

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

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

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

  int n, m;
  cin >> n >> m;
  priority_queue<int, vector<int>, greater<int>> pq;
  rep(i, 0, n) {
    int a;
    cin >> a;
    pq.push(a);
  }

  vector<P> vec(m);
  rep(i, 0, m) {
    int b, c;
    cin >> b >> c;
    vec[i] = make_pair(c, b);
  }
  sort(vec.rbegin(), vec.rend());

  rep(i, 0, m) {
    rep(j, 0, vec[i].second) {
      int x = pq.top();
      if (x < vec[i].first) {
        pq.pop();
        pq.push(vec[i].first);
      } else {
        break;
      }
    }
  }

  ll ans = 0;
  rep(i, 0, n) {
    ans += pq.top();
    pq.pop();
  }

  cout << ans << endl;
}


Measured memory_bytes: 1528
#include <stdio.h>

int main(){
  
  int N,k[10001]={0},i,n1=0,nac=0,c=0;
  
  while(1){
    
    scanf("%d",&N);
    if( N==0 ) break;
    
    for(i=0;i<N;i++){
      scanf("%d",&k[i]);
      if(k[i] == 0) nac++;
      else if(k[i]==1){
	n1++;
	nac++;
      }else c++;
    }
    
    if( nac==N ) puts("NA");
    else printf("%d\n",c+n1+1);
    
    c=0;
    nac=0;
    n1=0;
  }
  return 0;

}

Measured memory_bytes: 656
#include<bits/stdc++.h>
    using namespace std;
    int main(){
      long long x;
      cin>>x;
      long long ans;
      for(long long i=1;i<=x;i++){
      	if((i*(i+1)/2)>=x){
          ans=i;
          break;
        }
      }

      cout<<ans<<endl;
    }

Measured memory_bytes: 256
# coding: UTF-8
# ?§???????????????? S ???????????????????????§???h:m:s ?????¢?????????????????????????????????????????????
# ????????§???h ????????????m ??? 60 ???????????????s ??? 60 ??????????§???¨????????????

S = input()

h = S / 3600
m = (S - h*3600) / 60
s = (S - h*3600 - m*60)

print "%d:%d:%d" %(h,m,s)

Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
//ll mod = 1000000007;
void solve() {
	vec <ii> v;
	testcases{
		int x, y;
		cin >> x >> y;
		v.pb(MP(x, y));
	}
	bool is = false;
	FOR(i, 0, v.size() - 2) {
		if (v[i].FF == v[i].SS && v[i + 1].FF == v[i + 1].SS && v[i + 2].FF == v[i + 2].SS) {is = true; br;}
	}
	if (is)cout << "Yes\n";
	else cout << "No\n";
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}

Measured memory_bytes: 3600
const fs = require('fs')
const stdin = fs.readFileSync('/dev/stdin', 'utf8')

let [A,B] = stdin.split('\n')[0].split(' ').map(Number)

let coin = 0

for(let i = 0; i < 2; i++){
  if(A<B){
    coin += B
    B--
  }else {
    coin += A
    A--
  }
}

console.log(coin)

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};


int main(){
    int t, x;
    cin >> t >> x;
    cout << (double)t / x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
#define MAXN 1000000007
 
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,k,q,t;
	cin>>n>>k>>q;
	ll arr[n];
	for (ll i=0;i<n;i++) {
		arr[i]=0;
	}
	for (ll i=0;i<q;i++) {
		cin>>t;
		arr[t-1]+=1;
	}
	for (ll i=0;i<n;i++) {
		if (arr[i]<=q-k) {
			cout<<"No"<<endl;
		}
		else {
			cout<<"Yes"<<endl;
		}
	}
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int A[111111],B[111111];

vint G[111111];

struct UnionFindTree{
    vector<int>par,sz,sumB,ans;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        sumB.resize(n);
        ans.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        sumB[x]+=sumB[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

signed main(){
    cin>>N>>M;
    rep(i,N){
        cin>>A[i]>>B[i];
        chmax(A[i],B[i]);
    }
    rep(i,M){
        int a,b;cin>>a>>b;a--;b--;G[a].pb(b);G[b].pb(a);
    }

    vpint lis;
    rep(i,N)lis.pb({A[i]-B[i],i});
    sort(all(lis));

    UnionFindTree uf(N);
    rep(i,N){
        int v=lis[i].se;

        int uku=lis[i].fi;
        uf.sumB[v]=B[v];
        for(auto u:G[v]){
            if(uf.sumB[uf.find(u)]==0||uf.areSame(u,v))continue;
            int tmp=uf.ans[uf.find(u)];
            chmax(tmp,lis[i].fi-uf.sumB[uf.find(u)]);
            chmin(uku,tmp);
            uf.unite(v,u);
        }
        uf.ans[uf.find(v)]=uku;
    }

    cout<<uf.ans[uf.find(lis.back().se)]+accumulate(B,B+N,0ll)<<endl;
    return 0;
}


Measured memory_bytes: 13296
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Program{
  static void Main()
  {
    int number = int.Parse(Console.ReadLine());
    if(number < 3) {
      Console.WriteLine(0);
    }
    else{
       string[] numbersString = Console.ReadLine().Split(' ');
       List<int> numbers = new List<int>();
       for (int i = 0; i < number; i++)
       {
         numbers.Add(int.Parse(numbersString[i]));
       }
    
       var convinations = GetCombination(numbers, 3);
       int result = 0;
       foreach(var combi in convinations)
       {
         int a = combi[0];
         int b = combi[1];
         int c = combi[2];
         bool diff = !(a==b || b==c || a==c);
         bool canBeTriangle = a+b>c && a+c>b && b+c>a;
         if(diff && canBeTriangle) result++;
       }
       Console.WriteLine(result);
    }
  }
  
  static List<List<int>> GetCombination(List<int> self, int n)
    {
        return Enumerable.Range(0, n-1)
          .Aggregate(
                Enumerable.Range( 0, self.Count - n + 1 )
                    .Select( num => new List<int> { num } ),
                ( list, _ ) => list.SelectMany(
                    c => Enumerable.Range( c.Max() + 1, self.Count - c.Max() - 1 )
                            .Select( num => new List<int>( c ) { num } )))
            .Select(c => c.Select( num => self[ num ] )
                    .ToList())
          .ToList();
    }
}

Measured memory_bytes: 52812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

ll powpow(ll a,ll N) {
    ll n = 1;
    for(int i=0; i<N; i++) {
        n *= a;
        n %= C;
    }
    return n;
}

int main(){
    //長さNの数列
    ll N;
    cin >> N;
    ll ans = powpow(10, N)%C - (powpow(9, N)%C + powpow(9, N)%C) + powpow(8, N)%C;
    ans %= C;
    if(ans < 0) ans += C;
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int N = 2e5 + 5, mod = 1e9 + 7;

int n;
int siz[N], mul[N], ans[N];
vector<int> g[N];

int pw(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1)
            res = (ll)res * x % mod;
        x = (ll)x * x % mod;
        y >>= 1;
    }
    return res; 
}

void dfs(int u, int fa) {
    siz[u] = 1, mul[u] = 1;
    for (auto v : g[u]) 
        if (v != fa) {
            dfs(v, u);
            siz[u] += siz[v];
            mul[u] = (ll)mul[u] * mul[v] % mod;
        }
    mul[u] = (ll)mul[u] * siz[u] % mod;
}

void dfs2(int u, int fa, int fromFa) {
    if (u != 1)
        ans[u] = (ll)mul[u] * pw(siz[u], mod - 2) % mod * n % mod * fromFa % mod;
    else 
        ans[u] = (ll)mul[u] * fromFa % mod; 
    for (auto v : g[u]) 
        if (v != fa) {
            int tmp = (ll)fromFa * mul[u] % mod * pw(mul[v], mod - 2) % mod * pw(siz[u], mod - 2) % mod * (n - siz[v]) % mod;
            dfs2(v, u, tmp);
        }
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 0);
    dfs2(1, 0, 1);
    int x = 1;
    for (int i = 1; i <= n; i++)
        x = (ll)x * i % mod;
    for (int i = 1; i <= n; i++)
        cout << (ll)x * pw(ans[i], mod - 2) % mod << '\n';
    return 0; 
}

Measured memory_bytes: 16244
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
int dp[3010][3010];
int V[3010];
int solve(int r,int l,bool wh){
    if(dp[r][l]!=INF)return dp[r][l];
    int res;
    if(r==l){
        if(wh)res=V[r];
        else res=-V[r];
    }
    else{
        if(wh)
            res=max(solve(r+1,l,!wh)+V[r],solve(r,l-1,!wh)+V[l]);
        else
            res=min(solve(r+1,l,!wh)-V[r],solve(r,l-1,!wh)-V[l]);
    }
    return dp[r][l]=res;
}
signed main(void){
    int n;cin>>n;
    rep(i,3010)rep(j,3010)dp[i][j]=INF;
    rep(i,n)cin>>V[i];
    cout<<solve(0,n-1,true)<<endl;
}

Measured memory_bytes: 71168
#include <stdio.h>
int main (void){
    int n;
    scanf("%d",&n);
    int b=0,c=0,d=0;
    int a[100000];
    for (int i=0;i<n;i++){
        a[i]=i+1;
    }
    for (int i=0;i<n;i++){
        if(a[i]<10){
            b+=1;
        }
        if(a[i]<1000&&a[i]>99){
            c+=1;
        }
        if(a[i]<100000&&a[i]>9999){
            d+=1;
        }
    }
    int sum=0;
    sum=b+c+d;
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000007

int main() {
	int cnt[100001],ans=0;
	rep(i, 100001)
		cnt[i] = 0;
	int n;
	cin >> n;
	rep(i, n)
	{
		int a;
		cin >> a;
		if (a<=100000)
		cnt[a]++;
		else ans++;
	}
	rep(i, 100001) {
		if (cnt[i] < i)
			ans += cnt[i];
		else
			ans += cnt[i] - i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<int,int>x;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".in","w",stdout);
	int a,b,c;
	cin>>a>>b>>c;
	x[a]++;
	x[b]++;
	x[c]++;
	if(x[a]==1)cout<<a<<endl;
	else if(x[b]==1)cout<<b<<endl;
	else cout<<c<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vpll a(N);
  REP(i,N){
    IN(a[i].first);
    a[i].second = i;
  }
  sort(ALL(a));

  set<ll> st;

  ll ans = 0;
  REP(i,N){
    ll left, right;
    st.insert(a[i].second);
    auto itr = st.find(a[i].second);
    if(itr==st.begin()){
      left = -1;
    }else{
      itr--;
      left = *itr;
      itr++;
    }
    itr++;
    if(itr==st.end()){
      right = N;
    }else{
      right = *itr;
    }

    //debug_print(left, right, a[i].second);

    ans += a[i].first * (a[i].second-left)*(right-a[i].second);
  }


  OUT(ans);

  return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int sumfind(int n){
  int sum=0;
  while(n>0){
    sum += n%10;
    n = n/10;
  }
  return sum;
}

int main(){
  int n;
  cin>>n;
  int sum=sumfind(n);
  if(n%sum==0){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}


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

using namespace std;

const int N = 1e5;

vector < pair < int , int > > edge;
vector < int > G[N + 5];
int deg[N + 5];
map < int , int > hass[N + 5];
int ans[N + 5];

void dfs(int u, int p, int c){
	int cc = 1;
	for(int v : G[u]){
		if(v == p) continue;
		if(cc == c) cc++;
		ans[hass[u][v]] = cc;
		dfs(v, u, cc);
		cc++;
	}
}

int main(){
	int n; cin >> n;
	for(int i=0; i<n-1; i++){
		int u,v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
		hass[u][v] = hass[v][u] = i;
		deg[u]++; deg[v]++;
	}
	dfs(1,0,0);
	int maxi = 0;
	for(int i=0; i<n-1; i++) maxi = max(maxi, ans[i]);
	cout << maxi << endl;
	for(int i=0; i<n-1; i++) cout << ans[i] << endl;
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    int K = S.size();
    if (S[K-1] == 's') {
        cout << S << "es" << endl;
    }else {
        cout << S << "s" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder strb = new StringBuilder();

        ArrayDeque<Word> dfs = new ArrayDeque<>();
        dfs.addFirst(new Word(n));
        while(!dfs.isEmpty()){
            Word tmp = dfs.removeLast();
            if(tmp.length < n){
                for(int i = 0 ; i <= tmp.useMax ; i++){
                    dfs.addFirst(tmp.append((char)('a'+i)));
                }
            }else{
                strb.append(tmp.data);
                strb.append("\n");
            }
        }
        System.out.println(strb.toString());
    }
}

class Word{
    char[] data;
    int length;
    int useMax;

    Word(int n){
        data = new char[n];
        length = 0;
        useMax = 0;
    }

    Word(Word tar){
        this.data = new char[tar.data.length];
        for(int i = 0; i < tar.length ; i++){
            this.data[i] = tar.data[i];
        }
        this.length = tar.length;
        this.useMax = tar.useMax;
    }

    Word append(char c){
        Word tmp = new Word(this);
        tmp.data[tmp.length] = c;
        tmp.length++;
        if(c >= (char)('a'+tmp.useMax)){
            tmp.useMax++;
        }
        return tmp;
    }

    @Override
    public String toString() {
        return String.valueOf(data);
    }
}

Measured memory_bytes: 43556
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    if(S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR")
      cout << 1 << endl;
    if(S == "RRR")
      cout << 3 << endl;
    if(S == "SSS")
      cout << 0 << endl;
    if(S == "RRS" || S == "SRR")
      cout << 2 << endl;
}

Measured memory_bytes: 3112