akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template <class T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define eFOR(i, a, n) for (int i = (a); i <= (n); ++i)
#define rFOR(i, a, n) for (int i = (n)-1; i >= (a); --i)
#define erFOR(i, a, n) for (int i = (n); i >= (a); --i)
#define each(i, a) for (auto &i : a)
#define SORT(a) sort(a.begin(), a.end())
#define rSORT(a) sort(a.rbegin(), a.rend())
#define fSORT(a, f) sort(a.begin(), a.end(), f)
#define all(a) a.begin(), a.end()
#define out(y, x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define tp(a, i) get<i>(a)
#define line cout << "-----------------------------\n"
#define ENDL(i, n) ((i) == (n)-1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template <class T>
inline bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
inline void init()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v)
{
    for (auto &a : v)
        is >> a;
    return is;
}
template <class T>
inline istream &operator>>(istream &is, deque<T> &v)
{
    for (auto &a : v)
        is >> a;
    return is;
}
template <class T, class U>
inline istream &operator>>(istream &is, pair<T, U> &p)
{
    is >> p.first >> p.second;
    return is;
}
template <class T>
inline vector<T> vec(size_t a) { return vector<T>(a); }
template <class T>
inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template <class T, class... Ts>
inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template <class T, class... Ts>
inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template <class T>
inline void print(const T &a) { cout << a << "\n"; }
template <class T, class... Ts>
inline void print(const T &a, const Ts &... ts)
{
    cout << a << " ";
    print(ts...);
}
template <class T>
inline void print(const vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
        cout << v[i] << (i == v.size() - 1 ? "\n" : " ");
}
template <class T>
inline void print(const vector<vector<T>> &v)
{
    for (auto &a : v)
        print(a);
}
inline string reversed(const string &s)
{
    string t = s;
    reverse(all(t));
    return t;
}

int main()
{
    init();
    int x, y, b;
    cin >> x >> y;

    bool ans = 0;
    FOR(i, 0, x + 1)
    {
        b = x - i;
        if (2 * i + 4 * b == y)
            ans = 1;
    }
    if (ans)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}

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

using namespace std;

int solve(vector<int> &v, int m, int asked, int sig,
        vector<vector<int> > &memo)
{
    int n = v.size();
    int res = 128;
    int count = 0;
    for (int j = 0; j < n; j++) {
        if ((v[j] & asked) == (sig & asked)) {
            count++;
        }
    }
    if (count == 0) {
        return -1;
    }
    if (count == 1) {
        return 0;
    }
    if (memo[asked][sig] != 0) {
        return memo[asked][sig];
    }
    for (int j = 0; j < m; j++) {
        if ((asked & (1 << j)) == 0) {
            int l = solve(v, m, asked | (1 << j), sig, memo);
            int r = solve(v, m, asked | (1 << j), sig | (1 << j), memo);
            res = min(res, max(l, r) + 1);
        }
    }
    memo[asked][sig] = res;
    return res;
}

int main()
{
    int m, n;
    scanf("%d%d", &m, &n);
    while (m != 0) {
        vector<int> v(n);
        vector<vector<int> > memo(1 << m, vector<int>(1 << m));
        for (int j = 0; j < n; j++) {
            char s[12];
            scanf("%s", &s);
            for (int k = 0; k < m; k++) {
                if (s[k] == '1') {
                    v[j] |= (1 << k);
                }
            }
        }
        int res = solve(v, m, 0, 0, memo);
        printf("%d\n", res);
        scanf("%d%d", &m, &n);
    }
    return 0;
}

Measured memory_bytes: 17372
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, k, *x = map(int, read().split())

ans = float('inf')
for i in range(n - k + 1):
    right = x[i + k - 1]
    left = x[i]
    if right <= 0:
        time = abs(left)
    elif left <= 0 < right:
        time = abs(right-left)
        time += min(abs(right), abs(left))
    elif 0 < left:
        time = abs(right)
    ans = min(ans, time)
print(ans)


Measured memory_bytes: 18320
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> E;
const LL MOD = 1000000007LL;
LL x[100000];
LL y[100000];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> x[i], (x[i] += MOD) %= MOD;
	for (int i = 0; i < m; i++) cin >> y[i], (y[i] += MOD) %= MOD;
	LL sumX = 0;
	for (int i = 0; i < n; i++) {
		(sumX += x[i] * i) %= MOD;
		LL sub = (x[i] * (n - 1 - i)) % MOD;
		sumX = (sumX - sub + MOD) % MOD;
	}
	LL sumY = 0;
	for (int i = 0; i < m; i++) {
		(sumY += y[i] * i) %= MOD;
		LL sub = (y[i] * (m - 1 - i)) % MOD;
		sumY = (sumY - sub + MOD) % MOD;
	}
	cout << (sumX*sumY) % MOD << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			String s = "";
			while (sc.hasNextLine()) {
				s += sc.nextLine();
			}
			s = s.toLowerCase();
			int num[] = new int[26];
			for (int i = 0; i < s.length(); i++) {
				if (String.valueOf(s.charAt(i)).matches("[a-z]")) {
					num[(s.charAt(i) - 'a')]++;
				}
			}
			for (int j = 0; j < 26; j++) {
				System.out.println((char) (j + 'a') + " : " + num[j]);
			}
		}
	}
}



Measured memory_bytes: 29356
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(void){
  int rate;
  cin >> rate;

  if(rate < 1200){
    cout << "ABC" << endl;
  } else if(rate < 2800){
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        typedef long long int ll;
        typedef unsigned long long int ull;
        ull ma(ull a,ull b)
        {
            return max(a,b);
        }
        int main()
        {
            std::ios::sync_with_stdio(false);
            cin.tie(0);
        	int n,w;
        	cin>>n>>w;
        	vector<vector<ull>> dp(n+1,vector<ull> (w+1));
         
        	for(int i=1;i<n+1;i++)
        	{
        		int s;
        		ull v;
        		cin>>s>>v;
         
         
        		for (int j=0;j<w+1;j++)
        			{
        				if(s>j)
                            {dp[i][j]=dp[i-1][j];}
        				else
        				{dp[i][j]=ma(dp[i-1][j], dp[i-1][j-s]+v);}
        			}
        	}
        	cout<<dp[n][w];
         
         
         
         
         
            return 0;
        }

Measured memory_bytes: 83040
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n,k,q;
	cin >> n >> k >> q;
	vector<int> a(q);
	for(int i=0;i<q;i++)
	{
		cin >> a[i];
		a[i]--;
	}
	
	vector<int> score(n,k);
	for(int i=0;i<q;i++)
	{
		score[a[i]]++;
	}

	for(int i=0;i<n;i++)
	{
		cout << (score[i]>q ? "Yes":"No") << endl; 
	}




}


Measured memory_bytes: 1408
h,w = map(int,raw_input().split())

n = int(input())

arr = map(int,raw_input().split())

field = [[0 for i in range(w)] for j in range(h)]


x = 0
y = 0
d = 1
p = 0

for i in range(h*w):

	if arr[p] == 0:
		p += 1

	field[y][x] = str(p + 1)
	arr[p] -= 1

	x = x + d
	if x == -1 or x == w:
		x -= d
		y += 1
		d *= -1

for i in range(h):
	print ' '.join(field[i])


Measured memory_bytes: 3588
s = input()
x1 = s[:2]
x2 = s[1:3]
x3 = s[2:4]

if len(list(x1)) == len(set(x1)) and len(list(x2)) == len(set(x2)) and len(list(x3)) == len(set(x3)):
    print("Good")
else:
    print("Bad")

Measured memory_bytes: 3060
#include<iostream>
#include<deque>
#include<algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;

	deque<char> q;
	for (char c : s)q.push_back(c);
	bool flip = false;

	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			flip = !flip;
		}
		else {
			int f;
			cin >> f;
			char c;
			cin >> c;
			if (flip)  f = 3 - f;
			if (f == 1) {
				q.push_front(c);
			}
			else q.push_back(c);
		}
	}

	if (flip) reverse(q.begin(), q.end());

	for (int i = 0; i < q.size(); i++) {
		cout << q.at(i);
	}
	cout << endl;

	
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(d + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        last[t[i]] = i;

        for (int j = 1; j <= 26; j++)
        {
            ans -= c[j] * (i - last[j]);
        }
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    // printf("%lld\n", scoring(BestT));

    ll BestScore = scoring(BestT);

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1);
    ll count = 0;
    while (1)
    {
        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        ll score = scoring(t);

        if (score > BestScore)
        {
            BestT = t;
            BestScore = score;
            count++;
        }

        auto end = chrono::system_clock::now(); // 計測終了時刻を保存
        auto dur = end - start;                      // 要した時間を計算
        auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();

        if (msec >= 1950)
        {
            // printf("%lld\n", count);
            break;
        }
    }

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

    // printf("%lld\n", scoring(BestT));
}


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

using namespace std;

int main() {
	int N, count = 0;
	cin >> N;
	vector<int> V(N);
	vector<int> C(N);

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

	for (int i = 0; i < N; i++) {
		if (V[i] - C[i] > 0) count += V[i] - C[i];
	}

	cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	long long x;
	while (~scanf("%lld", &x)) {
		ll ans = x / 11 * 2;
		ans += (x - ans / 2 * 11 > 0) + (x - ans / 2 * 11 > 6);
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
const int MOD=1000*1000*1000+7,N=405;
using namespace std;
typedef long long ll;
ll n,c,A[N],B[N],PW[N][N];
vector<ll>dp(N,0);
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    cin>>n>>c;
    for(int i=1;i<N;i++){
        PW[i][0]=1;
        for(int j=1;j<N;j++)PW[i][j]=(i*PW[i][j-1])%MOD;
    }
    for(int i=1;i<N;i++){
        for(int j=0;j<N;j++)PW[i][j]=(PW[i][j]+PW[i-1][j])%MOD;
    }
    dp[0]=1;
    for(int i=1;i<=n;i++)cin>>A[i];
    for(int i=1;i<=n;i++)cin>>B[i];
    for(int i=1;i<=n;i++){
        vector<ll>nw=vector<ll>(N,0);
        //for(ll vl=a[i];vl<=b[i];vl++){
            for(int cu=0;cu<=c;cu++){
                //ll prod=1;
                for(int a=0;a<=cu;a++){
                    ll prod=PW[B[i]][a]-PW[A[i]-1][a];
                    prod=((prod%MOD)+MOD)%MOD;
                    nw[cu]+=prod*dp[cu-a];
                    nw[cu]%=MOD;
                    //prod=(prod*vl)%MOD;
                }
            }
        //}
        dp=nw;
    }
    cout<<dp[c]<<'\n';
    return 0;
}


Measured memory_bytes: 4960
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    K, N = lr()
    A = lr()
    ans = 0
    for i in range(N-1):
        ans = max(A[i+1]-A[i], ans)
    ans = max(K-A[N-1]+A[0], ans)
    print(K-ans)
resolve()

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

int field[8];

int zerocount()
{
	int count=0;
	for(int i=0;i<8;i++){
		if(field[i] == 0)
			count++;
	}
	return count-4;
}

int main()
{
	bool flag;
	while(cin >> field[0]){
		for(int i=1;i<8;i++){
			cin >> field[i];
		}
		switch(zerocount()){
			case 0:
				cout << 'B' << endl;
				break;
			case 1:
				flag = true;
				for(int i=0;i<8;i++){
					if(field[i] != 0 && flag == true){
						if((field[i] - field[i+2]) < 0){
							cout << 'D' << endl;
							flag = false;
							break;
						}else{
							cout << 'F' << endl;
							flag = false;
							break;
						}
					}
				}
				break;
			case 2:
				flag = true;
				for(int i=0;i<8;i++){
					if(field[i] != 0 && flag == true){
						if((field[i] - field[i+1]) == 0){
							cout << 'A' << endl;
							flag = false;
							break;
						}else if(field[i] - field[i+1] < 0){
							cout << 'G' << endl;
							flag = false;
							break;
						}else{
							cout << 'E' << endl;
							flag = false;
							break;
						}
					}
				}
				break;
			case 3:
				cout << 'C' << endl;
				break;
			default:
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 0
// ワーシャル フロイド法 : 動的計画法で実装
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

const int MAX_V = 100;
const int MAX_E = 9900;
const int INF = 0x7FFFFFFF;

int main(void)
{

    int V, E;
    int first, second, weight;
    bool b_negativeLoop = false;

    // 辺の重みを格納する配列
    int edgeWeight[MAX_V + 1][MAX_V + 1];

    for(int i = 0; i < MAX_V; i++)
    {
        for(int j = 0; j < MAX_V; j++)
        {
            if( i == j )
            {
                // 自分自身に対しては, ゼロで初期化する
                edgeWeight[i][j] = 0;
            }
            else
            {
                // 初期値として, 無効値を代入
                edgeWeight[i][j] = INF;
            }

        }
    }

    cin >> V >> E;

    for(int i = 0; i < E; i++)
    {
        cin >> first >> second >> weight;

        edgeWeight[first][second] = weight;
    }

    // ワーシャル フロイド法の実施
    for(int k = 0; k < V; k++)          // 経由する頂点
    {
        for(int i = 0; i < V; i++)      // 開始頂点
        {
            for(int j = 0; j < V; j++)  // 終了頂点
            {
                if( edgeWeight[i][k] != INF && edgeWeight[k][j] != INF )
                {
                    // 最短経路の探索 ( kを経由しない場合と, kを経由する場合で最小値を求める )
                    edgeWeight[i][j]
                        = min(edgeWeight[i][j], edgeWeight[i][k] + edgeWeight[k][j]);
                }
            }
        }
    }

    // 負の閉路の探索
    for(int p = 0; p < V; p++)
    {
        if( edgeWeight[p][p] < 0 )
        {
            // 負の閉路が存在する
            b_negativeLoop = true;
            printf("NEGATIVE CYCLE\n");
            break;
        }
    }

    if( b_negativeLoop == false )
    {
        // 結果の表示
        for(int i = 0; i < V; i++)
        {
            for(int j = 0; j < V; j++)
            {
                if( j != 0 )
                {
                    printf(" ");
                }

                if( edgeWeight[i][j] >= INF )
                {
                    printf("INF");
                }
                else
                {
                    printf("%d", edgeWeight[i][j]);
                }
            }

            printf("\n");
        }
    }

    return 0;
}



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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int[] a = new int[3];
        for (int i = 0; i < 3; i++) a[i] = sc.NextInt();
        int d = sc.NextInt();
        Console.WriteLine(Math.Abs(a[2] - a[0]) <= d || (Math.Abs(a[2] - a[1]) <= d && Math.Abs(a[1] - a[0]) <= d) ? "Yes" : "No");
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, 0, N) cin >> p[i];
    vector<int> r(N);
    rep(i, 0, N) r[p[i] - 1] = i + 1;
    vector<int> A(N), B(N);
    rep(i, 0, N)
    {
        A[i] = 30000 * (i + 1);
        B[i] = 30000 * (N - (i + 1)) + r[i];
    }
    rep(i, 0, N)
    {
        cout << A[i] << " ";
    }
    cout << endl;
    rep(i, 0, N)
    {
        cout << B[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1024
#include "stdio.h"
#include <stdlib.h>

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

int N, Y;

int main(void){
	int minus_mai = 0;
	int i=0, j=0;
	
	scanf("%d%d", &N, &Y);

	//全部%1000!=0ならだめ
	//全部1000なら必須枚数が>=Nじゃないとだめ
	//全部10000なら必須枚数が<=Nじゃないとだめ
	if(Y%1000!=0 || Y/1000<N || Y/10000>N){
		printf("-1 -1 -1\n"); 
		goto RETURN;
	}

	minus_mai = Y/1000 - N;

	i--;
	minus_mai += 9;

	while(minus_mai>0){
		i++;
		minus_mai -= 9;

		if(minus_mai%4==0){
			j = minus_mai/4;
			if((Y/1000-i*10-j*5)<0) continue;
			if(i<0||j<0){
				printf("-1 -1 -1\n"); 
			}else{
				printf("%d %d %d\n", i, j, Y/1000-i*10-j*5); 
			}
			goto RETURN;
		}

	};

	printf("-1 -1 -1\n"); 

RETURN:
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

template<typename Monoid>
class SegTree {
public:
	Monoid* tree;
	size_t size;
	int32 i;
	//?????????????????????
	SegTree(size_t length) {
		--length;
		size = length & 0xffff0000 ? length & 0xffff0000 : length;
		size = size & 0xff00ff00 ? size & 0xff00ff00 : size;
		size = size & 0xf0f0f0f0 ? size & 0xf0f0f0f0 : size;
		size = size & 0xcccccccc ? size & 0xcccccccc : size;
		size = size & 0xaaaaaaaa ? size & 0xaaaaaaaa : size;
		size = length ? size << 1 : 1;
		++length;
		tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
	}
	//?????????
	void set() {
		size <<= 1;
		for (i = 0;i < size;++i) tree[i].set();
		size >>= 1;
	}
	//tree[index]???data?????´??°
	void update(size_t index, Monoid &data) {
		index += size;
		tree[index].update(data);
		while (index >>= 1) tree[index] = tree[index << 1] + tree[index * 2 + 1];
	}
	//[begin,end)??????????????????
	Monoid range(size_t begin, size_t end) {
		Monoid retL, retR;
		for (begin += size, end += size;begin < end;begin >>= 1, end >>= 1) {
			if (begin & 1) retL = retL + tree[begin++];
			if (end & 1)  retR = tree[end - 1] + retR;
		}
		return retL + retR;
	}
};

struct SUM {
	int32 e;
	SUM() { set(); }
	SUM(int32 x) { e = x; }
	void set() { e = 0; }
	void update(SUM b) { e += b.e; }
	SUM operator+(SUM &other) {
		return  SUM(e + other.e);
	};
};

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int32 n, q;
	cin >> n >> q;
	SegTree<SUM> t(n);
	bool c;
	int32 x, y;
	SUM z;
	rep(i, 0, q) {
		cin >> c;
		if (c) {
			cin >> x >> y;
			printf("%d\n", t.range(x, y + 1).e);
		}
		else {
			cin >> x >> z.e;
			t.update(x, z);
		}
	}
	return 0;
}

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

int main() {
    int N; cin >> N;
    string S = to_string(N);
    int sum = 0;
    for (int i = 0; i < S.size(); i++) {
        sum += S[i] - '0';
    }
    if (N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int A, B;
	cin >> A >> B;
	int i = 0;
	if (B == 1) {
		cout << 0 << endl;
		return 0;
	}
	while (true) {
		if ((A - 1) * i + A >= B) {
			break;
		}
		else {
			i++;
		}
	}
	cout << i + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    long long n , num = 2 ;
    long long cnt = 1 ;
    cin >> n ;
    long long x = 1;

        while(n > 1)
        {
            cnt += num ;
            n = n / 2 ;
            x = num * n ;
            num *= 2 ;
        }
    cout << cnt <<"\n" ;
}



Measured memory_bytes: 3592
#include <iostream>
#include <string>

using namespace std; 

int main()
{
    string name;
    int a, b, c;
    
    cin >> a >> b >> c;
    if((a < b) && (b < c)){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        if(a[i]<a[i+1]&&a[i+1]<a[i+2]||a[i]>a[i+1]&&a[i+1]>a[i+2])
            count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var r, g, b, ans int

func main() {
	fmt.Scan(&r, &g, &b)
	if (r*100+g*10+b)%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i][0] == a[j][0] {
		return a[i][1] > a[j][1]
	}
	return a[i][0] > a[j][0]
}


Measured memory_bytes: 512
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = LI()
    a.sort()
    if a == [5, 5, 7]:
        print("YES")
    else:

        print("NO")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  bool ans=false;
  for(int i=0;i<=25;i++){
    int sum=4*i;
    if(sum==N){
      ans=true;
    }
    for(int j=0;j<=14;j++){
      sum+=7;
      if(sum==N){
        ans=true;
      }
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
  int h,a;
  cin >> h >> a;
  int k;
  k=h/a;
  if(h/a==h/(a+0.0)){
    cout << k << endl;
  }
  else{
    cout << k+1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  string s; cin >> s;
  int n = s.size();
  vector<int> a(4);
  rep(i, n) {
    if (s[i] == 'N') {
      a[0]++;
    } else if (s[i] == 'S') {
      a[1]++;
    } else if (s[i] == 'E') {
      a[2]++;
    } else {
      a[3]++;
    }
  }

  if (a[0]*a[1] == 0 && a[0]+a[1]>0) {
    cout << "No" << endl;
  } else if (a[2]*a[3] == 0 && a[2]+a[3]>0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def generate_graph(v_info):
    for info in v_info:
        adj_info = info[2:]
        for each in adj_info:
            adj_matrix[int(info[0]) - 1][int(each) - 1] = 1
    return adj_matrix


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertex_num = int(_input[0])
    adj_matrix = [[0] * vertex_num for _ in range(vertex_num)]
    vertex_info = list(map(lambda x: x.split(), _input[1:]))
    # assert len(vertex_info) == vertex_num

    ans = generate_graph(vertex_info)
    for v_result in ans:
        print(*v_result)

Measured memory_bytes: 8372
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool CHMAX(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool CHMIN(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  ll a;
  long double b;
  cin >> a >> b;

  COUT((ll)(a*b));
  return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

int main()
{
  static int mod = 1000000007;
  int H, W;
  cin >> H >> W;
  vector <string> a(H);

  for( int i=0;i<H;i++ )
    cin >> a[i];

  vector <vector<int>> dp(H, vector<int>(W));

  dp[0][0] = 1;
  for( int i=0;i<H;i++ )
    for( int j=0;j<W;j++ )
      {
	if( i<H-1 && a[i+1][j] == '.' )
	  dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod;
	if( j<W-1 && a[i][j+1] == '.' )
	  dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod;	  
      }

  cout << dp[H-1][W-1] << endl;
}


Measured memory_bytes: 5248
import java.util.Scanner;


public class Main {
  public static void main(String[] args) {
	  Scanner stdIn = new Scanner(System.in);
	  try {
		  String preContestName = stdIn.next();
		  if (!preContestName.equals("ABC") && !preContestName.equals("ARC")) return;
		  char[] postContestName = preContestName.toCharArray();
		  if (postContestName[1] == 'B') {
			  postContestName[1] = 'R';
		  } else if (postContestName[1] == 'R') {
			  postContestName[1] = 'B';
		  }
		  System.out.println(postContestName);
	  } catch (Exception e) {
		  e.printStackTrace();
	  } finally {
		  stdIn.close();
	  }
  }
}

Measured memory_bytes: 35624
#include<iostream>
using namespace std;
string str;
int p;
int exp();
int term();
int factor();


int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    p=0;  
    cin>>str;
    cout<<exp()<<endl;
  }
  return 0;
}


int exp(){
  int val=term();
  while(str[p]=='+'||str[p]=='-'){
    if(str[p]=='+'){
      p++;
      val+=term();
    }
    else if(str[p]=='-'){
      p++;
      val-=term();
    }
  }
  return val;
}


int term(){
  
  int val=factor();
  while(str[p]=='*'||str[p]=='/'){
    if(str[p]=='*'){
      p++;
      val*=factor();
    }
    else if(str[p]=='/'){
      p++;
      val/=factor();
    }
  }
  return val;
}


int factor(){
  int val=0;
  
  if(str[p]=='('){
    p++;    
    val=exp();
    p++;
  }
  else{
    while('0'<=str[p]&&str[p]<='9'){
      val*=10;
      val+=(str[p]-'0');   
      p++;
    }
  }
  return val;
}

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



int main(){
  string S;
  cin>>S;
  
  int a,b;
  
  a=(S.at(0)-'0')*10 + S.at(1)-'0';
  b=(S.at(2)-'0')*10 + S.at(3)-'0';
  
  bool OKa=false, OKb=false;
  
  if(a<13 && a!=0)
    OKa=true;
  if(b<13 && b!=0)
    OKb=true;
  
  if(OKa && OKb)
    cout<<"AMBIGUOUS";
  else if(!OKa && !OKb)
    cout<<"NA";
  else if(OKa)
    cout<<"MMYY";
  else if(OKb)
    cout<<"YYMM";
  
}



Measured memory_bytes: 256
A,B,C = input().split()
K = int(input())
first = "N"
second = "N"
f = 1
s = 1
nokori = K
for i in range(1,K):
    if int(A) < int(B)*f:
        first = "Y"
        break
    else:
        f *= 2
        nokori -= 1
if int(A) < int(B)*f:
        first = "Y"
if first == "Y":
    for o in range(1,nokori+1):
        if int(B)*f < int(C)*s:
            second = "Y"
            break
        else:
            s *= 2
    if int(B)*f < int(C)*s:
            second = "Y"
        
if first == "Y" and second == "Y":
    print("Yes")
else:
    print("No")

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++) cin >> v[i];
  sort(v.rbegin(), v.rend());
  
  int a;
  int alice = 0, bob = 0;
  for(int i=1; i<=n; i++) {
    if(i%2==1) alice += v[i-1]; 
    else bob += v[i-1];
  }
  cout << alice-bob << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k,draw[10][10];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>h>>w>>k;
    for(int bit=0;bit<(1<<(w-1));bit++){
        ll data[10];
        cnt=0;
        fl=true;
        rep(i,w-1){
            if(bit&(1<<i)){
                data[cnt++]=i;
            }
        }
        sort(data,data+cnt);
        rep(i,cnt-1){
            if(data[i]+1==data[i+1])fl=false;
        }
        if(!fl)continue;
        rep(from,w){
            ll now=from;
        rep(i,cnt){
            if(data[i]==now)now++;
            else if(data[i]==now-1)now--;
        }
        draw[from][now]++;
        }
    }
    ll dp[100+10][10];
    rep(i,100+7){
        rep(j,9){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    rep(i,h){
        rep(kk,w){
            cnt=0;
            rep(j,w){
                (cnt+=draw[j][kk]*dp[i][j])%=MOD;
            }
            (dp[i+1][kk]+=cnt)%=MOD;
        }
    }
    Cout(dp[h][k-1]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]==',')s[i]=' ';
    }
    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

int n;
int a[110],f[20000];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	memset(f,0,sizeof(f));
	f[0]=1;
	for (int i=1;i<=n;++i)
		for (int j=10000;j>=0;--j)
			if (f[j]){
				f[j+a[i]]=1;
			}
	for (int i=10000;i;--i)
		if (f[i] && i%10!=0){
			printf("%d\n",i);
			return 0;
		}
	puts("0");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long int ll;

int digit(int i){
    int count = 0;
    while(i > 0){
        i/=10;
        ++count;
    }
    return count;
}

int dfs(string S, const int keta, const int N, bool i3, bool i5, bool i7){
    if(S.size() == keta){
        if(atoi(S.c_str()) <= N && i3 && i5 && i7)return 1;
        else return 0;
    }
    int ret = 0;
    ret += dfs(S + '3', keta, N, true, false||i5, false||i7) + dfs(S + '5', keta, N, false||i3, true, false||i7) + dfs(S + '7', keta, N, false||i3, false||i5, true);
    return ret;
}

int main(){
    int N;cin >> N;
    int keta = digit(N);
    int ans = 0;
    for(int i = 3;i <= keta;++i){
        ans += dfs("", i, N, false, false, false);
    }
    cout << ans;
}


Measured memory_bytes: 256
[n, m] = map(int, input().split())
sign = [
    [x,y,z]
    for x in [1,-1]
    for y in [1,-1]
    for z in [1,-1]
]
points = [[] for _ in sign]
for _n in range(n):
    [xi, yi, zi] = map(int, input().split())
    for i, [x,y,z] in enumerate(sign):
        points[i].append(xi*x + yi*y + zi*z)
sums = []
for ps in points:
    ps.sort()
    ps.reverse()
    total = sum(ps[0:m])
    sums.append(total)
print(max(sums))


Measured memory_bytes: 3316
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "c.cpp"

int main() {
  ll k;
  cin >> k;

  ll sum = 0;
  rep(i, k) {
    rep(j, k) {
      rep(l, k) {
        sum += gcd(i+1, gcd(j+1, l+1));
      }
    }
  }

  cout << sum << el;
}


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

const int N=2020;
int n;
int a[N],p[N];
ll dp[N][N];

ll f(int l,int r)
{
    int dep=l+r+1;
    if (dep>n) {
        return 0;
    }
    if (dp[l][r]!=-1) return dp[l][r];
    if (dep==n) {
        return dp[l][r]=1LL*a[p[n]]*abs(l+1-p[n]);
    }
    ll res=max(1LL*a[p[dep]]*abs(l+1-p[dep])+f(l+1,r), 1LL*a[p[dep]]*abs(n-r-p[dep])+f(l,r+1));
    return dp[l][r]=res;
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        p[i]=i;
    }
    sort(p+1,p+n+1,[&](const int &i,const int &j){ return a[i]>a[j]; });
    memset(dp,-1,sizeof(dp));
    printf("%lld\n",f(0,0));
    return 0;
}

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

int sposoby[100005];

int n, k;
vector <int> G[100005];

void dfs(int v, int p){
	int moz = k-1-(p != -1);
	for (auto u: G[v]){
		if (u == p)
			continue;
		sposoby[u] = moz;
		moz--;
		dfs(u, v);
	}
}
const int mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n-1; ++i){
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(1, -1);
	sposoby[1] = k;
	long long wynik = 1;
	for (int i = 1; i <= n; ++i){
		wynik *= sposoby[i];
		wynik %= mod;
	}
	cout << wynik << "\n";
}

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

using namespace std;

typedef long long ll;

int main(){
    int n, x, y, z = 0;
    vector<int> a;
    cin >> n >> x;
    for(int b = 0; b < n; b++){
        cin >> y;
        a.push_back(y);
    }
    sort(a.begin(), a.end());

    while(z <= n){
        x -= a[z];        
        if(x < 0)break;
        z++;
    }
    if(x == 0)cout << z-1 << endl;
    else if(x > 0)cout << n-1 << endl;
    else cout << z << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using std::cin;using std::cerr;
using std::max;using std::min;
#define N 200005
#define ll long long
#define db double
#define pb push_back
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
int n,a,b,ecnt,last[N],fa[N],flag;ll Max1,Max2,l,r,mid,Min[N];
struct node
{
	ll x,y;
	friend bool operator==(node t1,node t2) {return t1.x==t2.x&&t1.y==t2.y;}
	friend bool operator<(node t1,node t2) {return t1.x<t2.x||t1.x==t2.x&&t1.y<t2.y;}
};
std::vector<node>S[N],tp;
struct road{int to,v,nex;}e[N];
void adde(int u,int v,int w) {e[++ecnt]=(road){v,w,last[u]},last[u]=ecnt;}
void dfs(int x,ll d=0)
{
	if(d>Max1) Max2=Max1,Max1=d;
	else Max2=max(Max2,d);
	for(int k=last[x];k;k=e[k].nex) dfs(e[k].to,d+e[k].v);
}
void Solve(int x)
{
	if(flag) return;
	int to1=0,to2=0;S[x].clear();
	for(int k=last[x];k;k=e[k].nex)
	{
		to1?to2=e[k].to:to1=e[k].to;
		for(int i=0,sz=S[e[k].to].size();i<sz;i++)
			S[e[k].to][i].x+=e[k].v,S[e[k].to][i].y+=e[k].v;
	}
	if(!to1) return void(S[x].pb({0,0}));
	int sz1=S[to1].size(),sz2=S[to2].size();
	if(sz1>sz2) std::swap(to1,to2),std::swap(sz1,sz2);
	std::reverse(S[to2].begin(),S[to2].end());
	sz1=std::unique(S[to1].begin(),S[to1].end())-S[to1].begin();
	sz2=std::unique(S[to2].begin(),S[to2].end())-S[to2].begin();
	S[to1].resize(sz1),S[to2].resize(sz2);
	Min[0]=S[to2][0].x;
	for(int i=1;i<sz2;i++) Min[i]=min(Min[i-1],S[to2][i].x);
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].x+S[to2][j].y>mid;j--);
		if(~j) tp.pb((node){Min[j],S[to1][i].y});
	}
	std::reverse(S[to1].begin(),S[to1].end());
	std::reverse(S[to2].begin(),S[to2].end());
	Min[0]=S[to2][0].y;
	for(int i=1;i<sz2;i++) Min[i]=min(Min[i-1],S[to2][i].y);
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].y+S[to2][j].x>mid;j--);
		if(~j) tp.pb({S[to1][i].x,Min[j]});
	}
	if(tp.empty()) return void(flag=1);
	std::sort(tp.begin(),tp.end());
	node tmp;S[x].pb(tmp=tp[0]);
	for(int i=1,sz=tp.size();i<sz;i++) if(tp[i].x>tmp.x&&tp[i].y<tmp.y) tmp=tp[i],S[x].pb(tmp);
	tp.clear();
}
bool Judge()
{
	flag=0;
	for(int i=n;i;i--) Solve(i);
	return !flag;
}
int main()
{
//	freopen("cc.in","r",stdin);
//	freopen("cc.out","w",stdout);
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d%d",&a,&b),adde(a,i,b);
	dfs(1);
	for(l=0,r=Max1+Max2;l<r;) mid=l+r>>1,Judge()?r=mid:l=mid+1;
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 33012
def main():
    length = int(input())
    target = list(map(int, input().split()))
    max_num = max(target)
    answer = []
    for _ in range(length):
        for i in range(max_num - 1, -1, -1):
            if len(target) >= i + 1 == target[i]:
                target.pop(i)
                answer.append(i + 1)
                break
        else:
            print(-1)
            answer = []
            break
    if answer:
        for i in range(-1, -length - 1, -1):
            print(answer[i])


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
struct coo{
	int x;
	int y;
	int h;
}c[110];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c[i].x;
		cin>>c[i].y;
		cin>>c[i].h;
	}
	int ch;
	int p=0;
	while(c[p].h==0) p++;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int ch=c[p].h+abs(i-c[p].x)+abs(j-c[p].y);
			int f=0;
			for(int k=0;k<n;k++)
			{
				int hh=ch-abs(i-c[k].x)-abs(j-c[k].y);
				if(hh<0) hh=0;
				if(hh!=c[k].h)
				{
					f=1;
					break;
				}
			}
			if(!f)
			{
				cout<<i<<' '<<j<<' '<<ch<<endl; return 0;
			} 
		}
	}
} 


Measured memory_bytes: 888
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


void update(long[] bit, int pos, long val) {
  for (int x = pos; x < cast(int)(bit.length); x |= x + 1) {
    chmax(bit[x], val);
  }
}
long getMax(long[] bit, int pos) {
  long ret = 0;
  for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {
    chmax(ret, bit[x]);
  }
  return ret;
}

int N;
int[] H;
long[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      H = new int[N];
      A = new long[N];
      foreach (i; 0 .. N) {
        H[i] = readInt() - 1;
      }
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }
      long ans = -1;
      auto bit = new long[N];
      bit[] = 0;
      foreach (i; 0 .. N) {
        const res = bit.getMax(H[i]);
        chmax(ans, res + A[i]);
        bit.update(H[i], res + A[i]);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 20288
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+7;
int n;
int num[MAX];
int ans;

int main() {
	cin>>n;
	for(int i=0; i<n-1; i++) cin>>num[i];
	if(n==2) ans=num[0]*2;
	else if(n==3) ans=num[0]+num[1]+min(num[0], num[1]);
	else if(n>3) {
		ans+=num[0]+num[n-2];
		for(int i=0; i<n-2; i++) ans+=min(num[i], num[i+1]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys

N = int(input())

count = 0
result = 'No'
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
        if count == 3:
            print('Yes')
            sys.exit()
    else:
        count = 0

print('No')


Measured memory_bytes: 9188
#include<stdio.h>

int main(void)
{
	int i,a,b,c,d=0,e;

	scanf("%d %d %d",&a,&b,&c);

	if(a>=b){
		e=b;
	}else{
		e=a;
	}

	for(i=e;;i--){
		if((a%i==0)&&(b%i==0)){
			d=d+1;
		}
		if (d>=c) break;
	}
	printf("%d\n",i);

	return 0;
}


Measured memory_bytes: 128