akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cmath>
#include <numeric>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
//#define long long long
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    int N;
    cin >> N;
    int h[N];
    cins(h, h + N);
    int ans = 0;
    while(accumulate(h, h + N, 0)){
        bool looking = false;
        for(int i = 0; i < N; i++){
            if(h[i] && !looking){
                looking = true;
            }else if(!h[i] && looking){
                break;
            }
            if(looking){
                h[i]--;
            }
        }
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]

    flag = True
    for a in A:
        if a % 2 == 0:
            if a % 3 == 0 or a % 5 == 0:
                pass
            else:
                flag = False
                break
    if flag:
        print('APPROVED')
    else:
        print('DENIED')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PII pair<int,int>
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,b,a) for (int i=(b);i>=(a);--i)
typedef long long LL;
inline int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const int MAXN=300005,Mo=1000000007;
int n,m,q,a[MAXN],b[MAXN],f[105][105];
int getnext(){
	a[q]--;
	if (a[q]==0) { q--; return q+1; } else return q; 
}
int main(){
	n=read(); m=read(); q=read();
	FOR(i,1,q) a[i]=read();
	FOR(i,1,n) {
		if (i&1)
			FOR(j,1,m) f[i][j]=getnext();
		else
			ROF(j,m,1) f[i][j]=getnext();
	}
	FOR(i,1,n)
		FOR(j,1,m) printf("%d%c",f[i][j]," \n"[j==m]);
	return 0;
}

/*
*/


Measured memory_bytes: 384
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    string s;
    cin >> s;
    s[3]='8';
    cout << s << endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        l: [usize; 5],
    }

    let mut ans = 0;
    for i in 1..=5 {
        if l[i - 1] == 0 {
            ans = i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2124
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int h, w; cin >> h >> w;
    map<int, int> mp;
    multiset<int> cost;
    
    rep(i, w) {
        mp[i] = i;
        cost.insert(0);
    }
    
    rep(i, h){
        int a, b;
        cin >> a >> b;
        a--;
        auto it = mp.lower_bound(a);
        int mx = -1;
        while(it != mp.end() && it->fi <= b){
            mx = max(mx, it->se);
            int x = it->fi - it->se;
            cost.erase(cost.find(x));
            mp.erase(it++);
        }
        if(mx != -1 && b < w){
            cost.insert(b - mx);
            mp[b] = mx;
        }
        int ans = -1;
        if(!cost.empty()){
            ans = *cost.begin() + (i+1);
        } 
        cout << ans << endl;
    }
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 22340
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		long C[] = new long[27];
		for (int i = 1; i <= 26; i++) {
			C[i] = sc.nextLong();
		}
		long S[][] = new long[D + 1][27];
		for (int i = 1; i <= D; i++) {
			for (int j = 1; j <= 26; j++) {
				S[i][j] = sc.nextLong();
			}
		}

		long p = 0;
		int ans[] = new int[D + 1];
		int[] d = new int[27];
		for (int i = 1; i <= D; i++) {
			long maxAns = 0;
			for (int j = 1; j <= 26; j++) {
				long _ans = 0;
				for (int k = 1; k <= 26; k++) {
					if (j == k) {
						_ans += S[i][j];
						d[j] = 0;
					} else {
						_ans -= C[k] * (d[k] + 1);
					}
				}
				if(maxAns < _ans) {
					maxAns = _ans;
					ans[i] = j;
				}
			}
			p += maxAns;
			for (int j = 1; j <= 26; j++) {
				if (ans[i] != j)
					d[j]++;
			}
		}
		for (int i = 1; i <= D; i++) {
			System.out.println(ans[i]);
		}
	}
}


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

int main(){
  	int n,x,t;
    cin>>n>>x>>t;
    int res;
    if(n%x==0) res=(n/x)*t;
    else res=(n/x)*t+t;
    cout<<res<<endl;
    return 0; 
}


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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2 * i
#define rc(i) 2 * i + 1
//#define int long long
using namespace std;
using vi = vector<int>;
using ii = pair<int, int>;

const int MAXN = 1e5, INF = 1e9 + 5, MOD = 1e9 + 7;

struct SegmentTree {
    int n;
    vi a, t;

    int merge(int x, int y) { return x + y; }

    void build(int i, int l, int r) {
        if (l == r) {
            t[i] = a[l];
            return;
        }
        int mid = (l + r) / 2;
        build(lc(i), l, mid);
        build(rc(i), mid + 1, r);
        t[i] = merge(t[lc(i)], t[rc(i)]);
    }

    SegmentTree(int x, vi y) {
        n = x;
        a = y;
        t.assign(4 * n, 0);
        build(1, 0, n - 1);
    }

    void modify(int i, int l, int r, int pos, int val) {
        if (l > pos || r < pos) return;
        if (l >= pos && r <= pos) {
            t[i] = val;
            return;
        }
        int mid = (l + r) / 2;
        modify(lc(i), l, mid, pos, val);
        modify(rc(i), mid + 1, r, pos, val);
        t[i] = merge(t[lc(i)], t[rc(i)]);
    }

    int query(int i, int l, int r, int ql, int qr) {
        if (l > qr || r < ql) return 0;
        if (l >= ql && r <= qr) return t[i];
        int mid = (l + r) / 2;
        int resL = query(lc(i), l, mid, ql, qr);
        int resR = query(rc(i), mid + 1, r, ql, qr);
        return merge(resL, resR);
    }

    void modify(int p, int v) { modify(1, 0, n - 1, p, v); }

    int query(int l, int r) { return query(1, 0, n - 1, l, r); }
};

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    int n, q;
    cin >> n >> q;
    vi a(n);
    trav(x, a) {
        cin >> x;
        x--;
    }
    vector<ii> queries[n];
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        queries[r].eb(l, i);
    }
    vi last(n, -1), res(q);
    SegmentTree freq(n, vi(n, 0));
    for (int i = 0; i < n; i++) {
        if (last[a[i]] != -1) freq.modify(last[a[i]], 0);
        last[a[i]] = i;
        freq.modify(i, 1);
        for (auto[l, idx] : queries[i]) res[idx] = freq.query(l, i);
    }
    for (int i = 0; i < q; i++) cout << res[i] << "\n";
}

Measured memory_bytes: 42464
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N, M, X = sc.nextInt
  val A = Array.fill(M)(sc.nextInt)

  val a = (0 to X).count(A.contains(_))
  val b = (X to N).count(A.contains(_))

  println(math.min(a, b))
}


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

using namespace std;

class Point {
public:
	double x, y;
};

class LineInfo {
public:
	Point p1, p2;

	LineInfo() {
		p1.x = p1.y = p2.x = p2.y = 1001;
	}
};

LineInfo LineData[3];
Point CrossPoint[3];
double Result;


double Cross_Prouct(Point A, Point B, Point C) {					//ABxAC
	return (B.x - A.x)*(C.y - A.y) - (B.y - A.y)*(C.x - A.x);
}

void getCrossPoint(int index, Point s1p1, Point s1p2, Point s2p1, Point s2p2) {

	double d1 = fabs(Cross_Prouct(s2p1, s2p2, s1p1));
	double d2 = fabs(Cross_Prouct(s2p1, s2p2, s1p2));
	double t = d1 / (d1 + d2);
	CrossPoint[index].x = s1p1.x + (s1p2.x - s1p1.x)*t;
	CrossPoint[index].y = s1p1.y + (s1p2.y - s1p1.y)*t;
}

bool isIntersection(Point A, Point B, Point C, Point D) {
	if (max(A.x, B.x) < min(C.x, D.x)) {
		return false;
	}
	if (max(C.x, D.x) < min(A.x, B.x)) {
		return false;
	}
	if (max(A.y, B.y) < min(C.y, D.y)) {
		return false;
	}
	if (max(C.y, D.y) < min(A.y, B.y)) {
		return false;
	}
	if (Cross_Prouct(A, B, C)*Cross_Prouct(A, B, D) <= 0 &&
		Cross_Prouct(C, D, A)*Cross_Prouct(C, D, B) <= 0) {
		return true;
	}
	/*if (min(A.x, B.x) <= max(C.x, D.x) &&
		min(C.x, D.x) <= max(A.x, B.x) &&
		min(A.y, B.y) <= max(C.y, D.y) &&
		min(C.y, D.y) <= max(A.y, B.y) &&
		Cross_Prouct(A, B, C)*Cross_Prouct(A, B, D) <= 0 &&
		Cross_Prouct(C, D, A)*Cross_Prouct(C, D, B) <= 0) {
		return true;
	}*/
	return false;
}

void solve() {

	if (!isIntersection(LineData[0].p1, LineData[0].p2, LineData[1].p1, LineData[1].p2)) {
		//三角形なし
		Result = 0.0;
		return;
	}
	if (!isIntersection(LineData[1].p1, LineData[1].p2, LineData[2].p1, LineData[2].p2)) {
		//三角形なし
		Result = 0.0;
		return;
	}
	if (!isIntersection(LineData[2].p1, LineData[2].p2, LineData[0].p1, LineData[0].p2)) {
		//三角形なし
		Result = 0.0;
		return;
	}

	for (int i = 0; i < 3; i++) {
		getCrossPoint(i, LineData[i].p1, LineData[i].p2, LineData[(i + 1) % 3].p1, LineData[(i + 1) % 3].p2);
	}

	Result = fabs(Cross_Prouct(CrossPoint[0], CrossPoint[1], CrossPoint[2])) / 2.0;
	//cout << Result << endl;
}

int main() {
	int x1, y1, x2, y2;

	while (1) {
		for (int i = 0; i < 3; i++) {
			cin >> x1 >> y1 >> x2 >> y2;
			if (i == 0 && x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0) {
				return 0;
			}
			LineData[i].p1.x = x1;
			LineData[i].p1.y = y1;
			LineData[i].p2.x = x2;
			LineData[i].p2.y = y2;
		}
		/*for (int i = 0; i < 3; i++) {
			cout << LineData[i].p1.x << " " << LineData[i].p1.y << " " << LineData[i].p2.x << " " << LineData[i].p2.y << endl;
		}*/
		solve();
		if (Result >= 1900000) {
			cout << "dai-kichi" << endl;
		}
		else if (Result >= 1000000) {
			cout << "chu-kichi" << endl;
		}
		else if (Result >= 100000) {
			cout << "kichi" << endl;
		}
		else if (Result > 0) {
			cout << "syo-kichi" << endl;
		}
		else {
			cout << "kyo" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3008
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define fcout cout << fixed << setprecision(10)
int main(){
    int n;
    cin >> n;
    int digsum = 0, a = n;
    while(a != 0){ // 各桁の和の計算
        digsum += a % 10; // 1の位を足して
        a /= 10;  //10で割る
    }
    if(n % digsum == 0) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int a,sum=0,cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        sum+=a;
        if(sum<=x)
        {
            cnt++;
        }
    }
    cout<<cnt+1<<endl;
}


Measured memory_bytes: 3664
n = int(input())
a = []
for i in range(2):
    a.append(list(map(int,input().split())))

dp = [[0 for i in range(n)] for i in range(2)]
dp[0][0] = a[0][0]
for i in range(1,n):
    dp[0][i] = dp[0][i-1] + a[0][i]
for i in range(n):
    dp[1][i] = max(dp[1][i-1],dp[0][i]) + a[1][i]

print(dp[1][n-1])


Measured memory_bytes: 3064
main
  :: IO ()
main = do
  n <- readLn
  a <- readLn
  putStrLn $ canPay' n a

canPay
  :: Int -> Int -> Bool
canPay n a = let r = n `rem` 500 in
  if r <= a
    then True
    else False

canPay'
  :: Int -> Int -> String
canPay' n a
  | canPay n a = "Yes"
  | otherwise  = "No"

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

int main(){
    int n,k; cin >> n >> k;
    string s; cin >> s;
    int sum = 0;
    char before = s[0];
    int cnt = 0; //色が変化した回数
    for(int i = 0; i < n; i++){
        if(before == s[i]){
            sum++;
        }else{
            sum++;
            before = s[i];
            cnt++;
        }
    }
    cnt++;
    if(cnt - 2*k > 1) cout << sum - (cnt - 2*k) << endl;
    else cout << sum - 1 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
int a , b , c , d;
cin >> a >> b >> c >> d;
cout << min({a + c , a + d , b + c , b + d}) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);

ll par[2134567];//親
ll depth[2134567];//木の深さ
//n要素で初期化
void init(ll n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		depth[i] = 0;
	}
}
//木の根を求める
ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(ll x, ll y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (depth[x] == depth[y])depth[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(ll x, ll y) {
	return find(x) == find(y);
}
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	string s, t;
	ll n, m, cnt = 0, ans = 0, a, b, c, d;
	cin >> n >> m; init(n + m + 5);
	rep(i, m) {
		cin >> a >> b; unite(a, b);
	}
	vector<ll> ok(n + 5);
	rep2(i, n) {
		if (ok[find(i)] == 0) { ok[find(i)] = 1; ans++; }
	}
	cout << ans - 1 << endl;
	return 0;
}

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

#define INF 987654321
#define ll long long
#define MOD 1000000007

int N;
vector<int> g[200201];
ll fa[200201], dp[200201], up[200201];
int sub[200201], usub[200201];

ll pw(ll a, ll n)
{
	ll ret = 1;
	while(n)
	{
		if (n&1) ret=ret*a%MOD;
		a=a*a%MOD;
		n>>=1;
	}
	return ret;
}

ll inv(ll a)
{
	return pw(a, MOD-2);
}

ll C(int n, int r)
{
	return fa[n]*inv(fa[r])%MOD*inv(fa[n-r])%MOD;
}

void DFS(int n, int prev)
{
	sub[n] = 1;
	for(auto next : g[n])
	{
		if (next == prev) continue;
		DFS(next, n);
		sub[n] += sub[next];
	}

	// cal dp
	int sz = sub[n] - 1;
	dp[n] = 1;
	for(auto next : g[n])
	{
		if (next == prev) continue;
		dp[n] *= dp[next]; dp[n] %= MOD;
		dp[n] *= C(sz, sub[next]); dp[n] %= MOD;
		sz -= sub[next];
	}
}

void DFS2(int n, int prev)
{
	// cal usub
	usub[n] = 1;
	if (prev != 0)
	{
		usub[n] += usub[prev];
		usub[n] += sub[prev]-1-sub[n];
	}

	// cal up
	if (prev == 0) up[n] = 1;
	else
	{
		up[n] = up[prev]*dp[prev]%MOD*inv(dp[n])%MOD*inv(C(sub[prev]-1,sub[n]))%MOD;
		up[n] *= C(usub[n]-2, usub[prev]-1);
		up[n] %= MOD;
	}
	for(auto next : g[n])
	{
		if (next == prev) continue;
		DFS2(next, n);
	}
}

int main()
{
	fa[0] = 1;
	for(int i=1; i<200201; i++)
		fa[i] = fa[i-1] * i % MOD;
	scanf("%d", &N);
	for(int i=0; i<N-1; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	DFS(1, 0);
	DFS2(1, 0);
	for(int i=1; i<=N; i++)
	{
		ll res = dp[i]*up[i]%MOD*C(N-1, sub[i]-1)%MOD;
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 20212
from collections import Counter

N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

def valid():
    if N%2:
        if ctr[0] != 1: return False
        i = 2
        while i <= N:
            if ctr[i] != 2: return False
            i += 2
    else:
        i = 1
        while i <= N:
            if ctr[i] != 2: return False
            i += 2
    return True

MOD = 10**9+7
print(2**(N//2) % MOD if valid() else 0)


Measured memory_bytes: 14820
s = input()
n = len(s)

s='|'+s+'|'

dp=[0]*(n+1)

#数列aの各項a_iについて、左右に連続する'<<<','>>>'の数をそれぞれカウント、
#その最大がa_iの最小値となる
R = [0]*(n+1)
L = [0]*(n+1)

#left count <<<
for i in range(1,n+1):
    if s[i]=='<':
        L[i] = L[i-1]+1
    else:
        L[i]=0
#right count >>>
for i in range(n-1,-1,-1):
    if s[i+1]=='>':
        R[i] = R[i+1]+1
    else:
        R[i]=0
ans=0
for i in range(n+1):
    ans+=max(R[i],L[i])
#print(L,R,s)
print(ans)




Measured memory_bytes: 32944
object Main {
  def main(args: Array[String]): Unit = {
    val input: List[String] = io.Source.stdin.getLines.toList
    val tmp = input(0).split(' ').map(_.toInt)
    val n = tmp(0)
    val m = tmp(1)
    val c = Array.fill(n)(0)
    (1 to m).foreach(i => {
      val tmp = input(i).split(' ').map(_.toInt)
      c(tmp(0) - 1) += 1
      c(tmp(1) - 1) += 1
    })
    c.foreach(println(_))
  }
}


Measured memory_bytes: 27340
#include <iostream>

using namespace std;

int map[14][14] = {0};

void bom(int XXX, int YYY) {
	map[XXX][YYY] = 0;
	int xmove[12] = {1, 0, -1, 0, 2, 0, -2, 0, 3, 0, -3, 0};
	int ymove[12] = {0, 1, 0, -1, 0, 2, 0, -2, 0, 3, 0, -3};
	for (int i = 0; i < 12; i++) {
		if (map[XXX+xmove[i]][YYY+ymove[i]] == 1) {
			bom(XXX+xmove[i], YYY+ymove[i]);
		}
	}
	return;
}

void bakuhatu(int XX, int YY) {
	bom(XX, YY);
	for (int i = 3; i < 11; i++) {
		for (int j = 3; j < 11; j++) {
			cout << map[j][i];
		}
		cout << endl;
	}
	return;
}

int main() {
	int n;
	char a;
	int X, Y;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int y = 3; y < 11; y++) {
			for (int x = 3; x < 11; x++) {
				cin >> a;
				map[x][y] = a - '0';
			}
		}
		cin >> X >> Y;
		X += 2;
		Y += 2;
		cout << "Data " << i+1 << ':' << endl;
		bakuhatu(X, Y);
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    bool ok = 1;
    string s;
    cin >> s;
    int n = sz(s);
    string t = s;
    reverse(all(t));
    ok &= (s == t);

    string u = s;
    s = s.substr(0, (n - 1) / 2);
    t = s;
    reverse(all(t));
    ok &= (s == t);
    s = u.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1);
    t = s;
    reverse(all(t));
    ok &= (s == t);
    cout << (ok ? "Yes" : "No") << endl;
}


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

ll mypow(ll x,ll n){
    ll ret=1;
    while(n>0){
        if(n&1==1){
            ret *=x;
        }
        x *=x;
        n >>=1;
    }
    return ret;
}

int main() {
    ll N,M;
    cin >> N >>M;
    vector<ll> x(N),y(N),z(N);
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ans =0;
    for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++){
        ll temp=0;
        vector<ll> A(N);
        for(int s=0;s<N;s++){
            A[s] = (mypow(-1,i)*x[s] + mypow(-1,j)*y[s]+mypow(-1,k)*z[s]);
        }
        sort(A.rbegin(),A.rend());
        for(int s=0;s<M;s++){
            // cerr <<"z=" << A[s] << endl; 
            temp += A[s];
        }
        // cerr <<"temp="<<temp << endl;
        ans = max(ans,temp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#define debug cout

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

vstring mp;
int mem[1010][1010][3];

int main() {
	int m,n,k;
	cin>>m>>n>>k;
	string s;
	rep(i,m){
		cin>>s;
		mp.PB(s);
	}
	memset(mem,0,sizeof(mem));
	repn(i,1,m)repn(j,1,n){
		rep(p,3)mem[i][j][p]=mem[i-1][j][p]+mem[i][j-1][p]-mem[i-1][j-1][p];
		if(mp[i-1][j-1]=='J')++mem[i][j][0];
		if(mp[i-1][j-1]=='O')++mem[i][j][1];
		if(mp[i-1][j-1]=='I')++mem[i][j][2];
	}
	int a,b,c,d;
	rep(i,k){
		cin>>a>>b>>c>>d;
		cout<<mem[c][d][0]-mem[c][b-1][0]-mem[a-1][d][0]+mem[a-1][b-1][0]<<" ";
		cout<<mem[c][d][1]-mem[c][b-1][1]-mem[a-1][d][1]+mem[a-1][b-1][1]<<" ";
		cout<<mem[c][d][2]-mem[c][b-1][2]-mem[a-1][d][2]+mem[a-1][b-1][2]<<endl;
	}
	return 0;
}

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

using namespace std;

char s[10005];

int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", s);
	
	int l = strlen(s);
	
	for (int i = 0; i < l; i++) {
		int num = s[i] - 'A';
		num = (num + n) % 26;
		s[i] = num + 'A';
		printf("%c", s[i]);
	}
	
	printf("\n");
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int a,b,c; cin>>a>>b>>c;
  for (int i=1; i<=b; i++) {
    if ((a*i)%b==c) {
      cout << "YES" << endl;
      return;
    }
  }
  cout << "NO" << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
	int a[n + 2];
	a[0] = 0;
    a[n + 1] = 0;
    for( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    int s = 0;
    for( int i = 1 ; i <= n + 1 ; i++ ){
        s += abs( a[i] - a[i - 1] );
    }
    for( int i = 1 ; i <= n ; i++ ){
        int ans = s;
        ans = ans - abs( a[i] - a[i - 1] ) - abs( a[i] - a[i + 1] ) + abs( a[i - 1] - a[i + 1] );
        cout << ans << endl;
    }
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int n,k;
bool isOK(double t,vector<double> &a){
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(a[i]<=t) continue;
        cnt += a[i]/t;
    }
    return cnt <= k;
}
int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    cin>>n>>k;
    vector<double> a(n);
    for(int i = 0; i < n; i++) cin>>a[i];
    double ng = 0,ok = INFL;
    int cnt = 0;
    while(cnt <= 60){
        double t = (ng+ok)/2;
        if(isOK(t,a)) ok = t;
        else ng = t;
        //cout<<ok<<endl;
        cnt++;
    }
    cout<<(int)(ok+0.5)<<endl;
}

Measured memory_bytes: 4752
n = int(input())
comforts = list(map(int,input().split()))
newcomforts = sorted(comforts, reverse=True)
x = 0
if n%2 == 0:
  for i in range(1, int(n/2)):
    x += newcomforts[i]
  print(x * 2 + newcomforts[0])
else:
  for i in range(1, int((n-1)/2)):
    x += newcomforts[i]
  print(x*2 + newcomforts[0] + newcomforts[int((n+1)/2-1)])

Measured memory_bytes: 31596
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  int ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353


#define mod   1000000007

#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash< ll > > ht;

// find_by_order()  // order_of_key
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};

 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                    > pq;*/


  int main()
{  fast;
   ll n;string s;cin>>n>>s;
   n%=26;
   for(auto &x:s)
   {
       for(ll i=0;i<n;i++)
       {
          if(x=='Z')x='A';else x++;
       }
   }
  cout<<s;
   return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;
  
  cin >> S;
  
  int count = 0;
  
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < S.size(); j++) {
      if (i == j) {
        continue;
      } else if (S.at(i) == S.at(j)) {
        count++;
      }
    }
  }
  
  if (count == 0) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  
}


Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

bool can(ll x, ll k, ll d, ll y)
{
    ll t = abs(x-y) / d;
    return t <= k && t % 2 == k % 2;
}

void solve()
{
    IN(x, k, d);
    ll a = x % d;
    ll b = x % d - d;
    ll res = 1LL<<55;
    if (can(x, k, d, x % d)) chmin(res, abs(x % d));
    if (can(x, k, d, x % d - d)) chmin(res, abs(x % d - d));
    if (can(x, k, d, x % d + d)) chmin(res, abs(x % d + d));
    if (can(x, k, d, x % d - d * 2)) chmin(res, abs(x % d - d * 2));
    if (can(x, k, d, x % d + d * 2)) chmin(res, abs(x % d + d * 2));
    if (res == 1LL<<55) {
        res = abs(x) - k * d;
    }
    cout << res << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int mod;
constexpr int MAX_N = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){ 
  int n;
  cin >> n >> mod;
  vector<vector<int>> g(n);
  rep(i,n-1) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }

  vector<mint> dp(n, 1);
  vector<mint> res(n);
  auto dfs1 = [&](auto&& f, int u = 0, int p = -1)->void{
    for (auto v : g[u]) {
      if (v == p) continue;
      f(f, v, u);
      dp[u] *= (dp[v] + 1);
    }
  };

  auto dfs2 = [&](auto&& f, mint pdp, int u = 0, int p = -1)->void{
    int deg =  g[u].size();
    for (int i = 0; i < deg; i++) if (g[u][i] == p) dp[g[u][i]] = pdp;
    vector<mint> left(deg + 1, 1);
    vector<mint> right(deg + 1, 1);
    for (int i = 0; i < deg; i++) left[i + 1] = left[i] * (dp[g[u][i]] + 1);
    for (int i = deg - 1; i >= 0; i--) right[i] = right[i + 1] * (dp[g[u][i]] + 1);

    res[u] = left[deg];

    for (int i = 0; i < deg; i++) {
      int v = g[u][i];
      if (v == p) continue;
      mint d = left[i] * right[i + 1];
      f(f, d, v, u);
    }
  };
  dfs1(dfs1);
  dfs2(dfs2, dp[0]);
  for (auto e : res) cout << e << endl;
  return 0;
} 

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

typedef long long ll;

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

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

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

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

#define pii pair<int,int>

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

int main()
{
	int n;
	cin >> n;
	ll ans = 0;
	FOR(i, 0, n){
		ll a;
		cin >> a;
		while(1){
			if(a % 2 == 0){
				a /= 2;
				ans++;
			}else{
				break;
			}
		}
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
import fractions
from functools import reduce
 
N = int(input())
lst = list(map(int,input().split()))
 
L = [0] * (N+1)
R = [0] * (N+1)
for i in range(N):
    L[i+1] = fractions.gcd(L[i], lst[i])
    R[N-i-1] = fractions.gcd(R[N-i], lst[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(L[i], R[i+1]))
print(ans)

Measured memory_bytes: 16072
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	static const ULL M = 1000000007;

	ULL dp[51][51][2500] = {};

	void Solve() {
		UL N, K; cin >> N >> K;
		if (K % 2 == 1) { cout << 0 << endl; return; }
		K /= 2;
		dp[0][0][0] = 1;
		for (UL n = 1; n <= N; n++) {
			for (UL pk = 0; pk <= K; pk++) {
				for (UL pl = 0; pl < n; pl++) {
					if (pk + pl > K) break;
					dp[n][pl + 1][pk + pl] += dp[n - 1][pl][pk];
					dp[n][pl][pk + pl] += dp[n - 1][pl][pk] * (2 * pl + 1);
					if (pl) dp[n][pl - 1][pk + pl] += dp[n - 1][pl][pk] * pl * pl;
				}
			}
			rep(l, n + 1) rep(k, K + 1) dp[n][l][k] %= M;
		}
		cout << dp[N][0][K] << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 51072
#include<iostream>

using namespace std;
int main()
{
int A,B,C;

cin>>A>>B>>C;

if(A==B && A!=C){
    cout<<"Yes"<<endl;
}
else if(B==C && A!=B){
      cout<<"Yes"<<endl;
}
else if(A==C && A!=B){
     cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}
return 0;
}


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

using namespace std;


int main()
{
  pair< int, int > Q[6];
  for(int i = 0; i < 6; i++) {
    cin >> Q[i].first >> Q[i].second;
    if(Q[i].first > Q[i].second) swap(Q[i].first, Q[i].second);
  }
  sort(Q, Q + 6);

  if(Q[0] == Q[1] && Q[2] == Q[3] && Q[4] == Q[5] && Q[0].first == Q[2].first && Q[2].second == Q[4].second && Q[0].second == Q[4].first) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }

}

Measured memory_bytes: 3108
import sys
import random

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
#t = [int(input()) for i in range(D)]
#M = int(input())
#Q = [list(map(int,input().split())) for i in range(M)]

def content(t):
    cont = 0
    last = [0]*26
    for i in range(D):
        cont += s[i][t[i]-1]
        last[t[i]-1] = i+1
        for j in range(26):
            cont -= c[j]*(i+1-last[j])
    return cont

def main():
    t = [random.randint(0,25)+1 for i in range(D)]
    prev = content(t)
    for i in range(100):
        d,q = random.randint(0,D-1), random.randint(0,25)
        prev_t = t[d]
        t[d] = q+1
        if prev>content(t):
            t[d] = prev_t
    print(*t,sep="\n")
        

if __name__ == '__main__':
    main()





Measured memory_bytes: 78136
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

typedef long long ll;

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

    vector<ll> costTo(n, INT_MAX);    //costTo[i] is the min cost required to get to i
    costTo[0] = 0;
    for (int i = 1; i < n; i++) {
        // printf("jump from %d\n", i);
        for (int j = max(0, i-k); j < i; j++) {
            // printf("    to %d\n", j);
            //try jumping from j
            costTo[i] = min(costTo[i], costTo[j] + abs(costs[i] - costs[j]));
        }
    }
    
    // for (int i = 0; i < n; i++) {
    //     printf("costTo[%d]=%d\n", i, costTo[i]);
    // }
    
    cout << costTo[n-1];

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
	map<int, int> mp;
	REP(i,6){ int a; cin >> a; mp[a]++; }
	for( auto& v : mp ) if( v.second >= 3 ) { cout << "NO" << endl; return 0; }
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, N = il()
    print(f(A, B, min(B - 1, N)))


if __name__ == '__main__':
    main()


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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    int res=999;
    for(int i=0;i+3<=s.size();i++){
        int tmp=abs(stoi(s.substr(i,3))-753);
        res=min(res,tmp);
    }
    p(res)
} 

Measured memory_bytes: 256
/*
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2015
?????????: Square Route
?????°:
18:51:30 ??????????????????
18:54:38 ??????????????¨
19:17:56 ??¨???????????????????????????
19:18:43 ?????°???
19:30:54 ?????°?????????????°???\???
19:31:54 Memory Limit Exceeded?????¨??????
19:33:37 ??¨?????????????????????????????????
?¢??????????????????????????????°?????°????????°?????????????????????????????????????????¨?????????????????????
19:45:01 ???????????????
19:46:02 ????????¨?????????????????£???????????????????????§????????¢????????????????????????
19:48:07 ???????????????????????????multiset???????????£????????????map???????????????map??????????????????1000????´????
19:53:28 ????????§????????????
19:54:37 ???????????¨???????????¨???
19:55:06 ????????????????´??????????????????????
19:57:49 ?????????????????¨??????
19:58:46 ??????????????°???????????¨?????????
*/

#include <set>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
#define ws WS //??????????????????????????§??????

int h[1500];
int w[1500];

// hsum[0] = 0;
// hsum[1] = h[0];
// hsum[2] = h[0] + h[1];
// hsum[3] = h[0] + h[1] + h[2];
int hsum[1501];
int wsum[1501];

// orig????´???????????±???????sum?????\?????????
void foo(int orig[], int sum[], int length)
{
	int tmp = 0;
	for(int i=0; i<length; i++) {
		sum[i] = tmp;
		tmp += orig[i];
	}
	sum[length] = tmp;
}

#define AA 1500000 
int hs[AA]; // hs[???] = ???????????°
int ws[AA]; // ws[???] = ???????????°


int main()
{
	while(true) {
		int N,M;
		cin >> N >> M;
		if(N == 0 && M == 0) {break;}
		for(int i=0; i<N; i++) {
			cin >> h[i];
		}
		for(int j=0; j<M; j++) {
			cin >> w[j];
		}

		foo(h,hsum,N);
		foo(w,wsum,M);

		for(int i=0;i<AA;i++){hs[i]=ws[i]=0;}

		// ?????£?¶???????h???????????¨?????£?¶???????w?????????????????´????????¨???????????£?????¢???????????????
		// hsum[a] - hsum[b] = wsum[c] - wsum[d]??????(a>b, c>d)
		// ????´????????????????????????????????????§????????£??????????????????????????????????????????????????????????????????????????????
		for(int i=0; i<=N; i++){
			for(int j=i+1; j<=N; j++){
				hs[hsum[j] - hsum[i]]++;
			}
		}
		
		for(int i=0; i<=M; i++){
			for(int j=i+1; j<=M; j++){
				ws[wsum[j] - wsum[i]]++;
			}
		}

		int ans = 0;
		for(int i=0;i<AA;i++){
			ans += hs[i] * ws[i];
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 14768
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end  
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define RB rbegin()
#define E end()
#define RE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int n,k, q;
    cin >> n >> k >> q;
    vi all(n,k);
    int t = q;
    while (t--)
    {
        int x;
        cin >> x;
        x--;
        all[x]++;
    }
    REP(i,0,n)
    {
        if (all[i]-q > 0)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define very_slow       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define inf             1e18
#define MAX             1e9
#define MIN            -1e9
#define no_of_test(x)        int x; cin>>x; while(x--)
//Actual Code Is At The Top
const int mod = 1e9 + 7;
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int32_t main()
{   
	very_slow
//	no_of_test(x)
	{  
      int n;
	  cin>>n;
	  cout<<(n+1)/2<<'\n';     
	}
	return 0;
}

Measured memory_bytes: 3616
// Problem : A - Red or Not
// Contest : AtCoder Beginner Contest 138
// URL : https://atcoder.jp/contests/abc138/tasks/abc138_a
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  cout.precision(16);
  cout << fixed;
  
  int a;
  string s;
  cin >> a >> s;
  
  if (a >= 3200) {
    cout << s;
    
    return 0;
  }
  
  cout << "red";
}


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

int main() {
  int n;
  cin >> n;
  bool flag = false;
  for (int i = 0; 4*i <= n; i++) {
    int a = n - 4 * i;
    if (a % 7 == 0) {
      flag = true;
      break;
    } 
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}




Measured memory_bytes: 256
from fractions import gcd
from decimal import *

a, b, c, d = list(map(Decimal, input().split()))
e = c * d / gcd(c, d)
print(int(b - a + 1 - ((b // c + b // d - b // e) - ((a - 1) // c + (a - 1) // d - (a - 1) // e))))

Measured memory_bytes: 5048