akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
//ll MOD = 1000000007;
ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/


int main(){
  string S, T;
  cin >> S >> T;
  ll sl = S.size(), tl = T.size();
  vector<ll> sumS(sl + 1), sumT(tl + 1);
  sumS[0] = 0, sumT[0] = 0;
  rep(i, sl){
    if(S[i] == 'A') sumS[i+1] = sumS[i] + 1;
    else sumS[i+1] = sumS[i];
  }
  rep(i, tl){
    if(T[i] == 'A') sumT[i+1] = sumT[i] + 1;
    else sumT[i+1] = sumT[i];
  }

  ll Q;
  cin >> Q;
  rep(i, Q){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll sa = sumS[a-1] - sumS[b] + 2 * b - 2 * a + 2;
    ll ta = sumT[c-1] - sumT[d] + 2 * d - 2 * c + 2;
    sa %= 3;
    ta %= 3;
    if(sa == ta){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for(int i = 1; i <= n; i++){
        int num = i;
        double pro = (double)(1) / (double)(n);
        while(num < k){
            num *= 2;
            pro /= (double)(2);
        }
        ans += pro;
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    int start, X[100000];
    for(int i=0;i<N;i++)
        cin >> X[i];

    ll walk, ans = 0;
    for(int i=1;i<N;i++){
        walk = A*(X[i] - X[i-1]);
        ans += min(walk, B);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;

struct Node{
    int col,num;
};


int n,m,k,a,b;
Node A[100002];
int ss[100002]={};
vi friends[100005];
vi blocks[100005];

void search(int x,int s){
    A[x].col++;
    A[x].num=s;
    REP(i,friends[x].size()){
        if(A[friends[x][i]].col==0) search(friends[x][i],s);
    }
}


void solve(){
    int p=0;
    int s=0;
    while(p<=n){
        if(A[p].col==0){
            search(p,s);
            s++;
        }
        p++;
    }
}

int main(){
    cin>>n>>m>>k;

    REP(i,m){
        cin>>a>>b;
        friends[a-1].push_back(b-1);
        friends[b-1].push_back(a-1);
    }
    REP(i,k){
        cin>>a>>b;
        blocks[a-1].push_back(b-1);
        blocks[b-1].push_back(a-1);
    }
    REP(i,n) A[i].col=0;

    solve();
    REP(i,n) ss[A[i].num]++;
    int z;



    REP(i,n){
        z=0;
        REP(j,blocks[i].size()){
            if(A[i].num==A[blocks[i][j]].num) z++;
        }
        if(i==0) cout<<ss[A[i].num]-z-friends[i].size()-1;
        else cout<<" "<<ss[A[i].num]-z-friends[i].size()-1;
    }
    cout<<endl;
}

Measured memory_bytes: 13056
n = gets.to_i
s = gets.chomp
d = 0
max = 0
s.each_char{|c|
    case c
    when "("
        d -= 1
    when ")"
        d += 1
        if d > max
            max = d
        end
    end
}
warn [d, max].inspect
puts "(" * max + s + ")" * (max - d)


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

using namespace std;

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

    vector<int> S(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &S[i]);

    size_t q;
    scanf("%zu", &q);

    vector<int> T(q);
    for (size_t i=0; i<q; ++i)
        scanf("%d", &T[i]);

    ptrdiff_t C=0;
    for (size_t i=0; i<q; ++i)
        C += !!count(S.begin(), S.end(), T[i]);

    printf("%tu\n", C);
    return 0;
}

Measured memory_bytes: 2740
import itertools as it
n = int(input())
l = [int(i) for i in input().split()]
c = it.combinations(l,3)
ans = 0

for i in c:
    if i[0]+i[1]>i[2] and i[1]+i[2]>i[0] and i[2]+i[0]>i[1]:
        if i[0]!= i[1] and i[1]!= i[2] and i[0]!= i[2]:
            ans +=1
print(ans)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define ll long long
#define NM (int)2e5
using namespace std;

ll v[NM],dp[NM];

int main()
{   int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>v[i];
    /// dp[i]=cost minim din 1 in n
    dp[2]=abs(v[1]-v[2]);
    for(int i=3; i<=n; i++)
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 5148
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[101];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int sum1 = 0, sum2 = 0;
	for (int i = n - 1; i >= 0; i -= 2)
		sum1 += a[i];
	for (int i = n - 2; i >= 0; i -= 2)
		sum2 += a[i];
	cout << sum1 - sum2;
	return 0;
}

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

int main(){
  int n,m;
	cin >> n >> m;
  long long a[n+1][3];
  long long maxn=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++) cin >> a[i][j];
	}

	for(int i=0;i<8;i++){
		vector<long long> vec;
		for(int j=1;j<=n;j++){
			long long S=0;
			for(int k=0;k<3;k++){
				if((i/(1<<k))%2==0) S+=a[j][k];
				else S-=a[j][k];
			}
			vec.push_back(S);
		}
		sort(vec.begin(),vec.end()); reverse(vec.begin(),vec.end());
		long long ans=0;
		for(int j=0;j<m;j++) ans+=vec[j];
		maxn = max(maxn,ans);
	}
	cout << maxn << endl;
}

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

s = sr()
if s[0] == s[1] == s[2] == 'R':
    print(3)
elif s[0] == s[1] == 'R' or s[1] == s[2] == 'R':
    print(2)
elif s[0] == 'R' or s[1] == 'R' or s[2] == 'R':
    print(1)
else:
    print(0)


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

using i64 = int64_t;

string convert(string s){
    map<char, char> mp;
    string res = "";
    char alph = 'a';
    for(char c: s){
        if(mp[c] == 0){
            res.push_back(alph);
            mp[c] = alph;
            alph++;
        }else{
            res.push_back(mp[c]);
        }
    }
    return res;
}

int main(){
    string s, t;
    cin >> s >> t;
    cout << (convert(s) == convert(t) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 1552
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String[] fst = sc.nextLine().split(" ");
		BigInteger n = new BigInteger(fst[0] + "");
		BigInteger T = new BigInteger(fst[1] + "");
		
		BigInteger MAX = new BigInteger("1000000000");
		
		String input = sc.nextLine();
		
		BigInteger sum = new BigInteger("0");
		for(String in : input.split("\\+")){
			//System.out.println(in);
			
			int num = Integer.parseInt(in.split("\\^")[1]);
			sum = sum.add(n.pow(num).multiply(T));
			
		}
		
		System.out.println(sum.compareTo(MAX) <= 0 ? (sum + "") : "TLE");
	}

}

Measured memory_bytes: 17376
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
int main() {
    int h, w; cin >> h >> w;
    char s[h][w];
    int cnt = 0;
    rep(i, h) rep(j, w) {
        cin >> s[i][j];
        if (s[i][j] == '.') cnt++;
    }
    queue<pair<pair<int, int>, int> > q;
    q.push({{0, 0}, 0});
    
    int reached[h][w];
    rep(i, h) rep(j, w) reached[i][j] = -1;
    reached[0][0] = 0;
    while (!q.empty()) {
        int y = q.front().first.first;
        int x = q.front().first.second;
        int cost = q.front().second;
        q.pop();
        int dy[] = {0, 0, -1, 1};
        int dx[] = {1, -1, 0, 0};
        rep(i, 4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (s[ny][nx] == '#' || reached[ny][nx] != -1) continue;
            reached[ny][nx] = cost + 1;
            if (ny == h - 1 && nx == w - 1) {
                cout << cnt - (reached[h - 1][w - 1] + 1) << endl;
                return 0;
            }
            q.push({{ny, nx}, reached[ny][nx]});
        }
    }
    cout << -1 << endl;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct _data_st
{
    int rows, columns;
    struct _data_st *next;
} data_st;

int main(int argc, char *argv[])
{
    data_st *head = NULL, *tail = NULL;
    for (int rows, columns; scanf("%d %d", &rows, &columns) == 2 && (rows || columns);)
    {
        data_st *data = (data_st *)malloc(sizeof(data_st));
        *data = (data_st){.rows = rows, .columns = columns, .next = NULL};
        head = head ?: data;
        if (tail)
        {
            tail->next = data;
        }
        tail = data;
    }
    while (head)
    {
        data_st *data = head;
        head = head->next;
        for (int row = 0; row < data->rows; ++row)
        {
            for (int isdot = !!(row % 2), column = 0; column < data->columns; isdot = !isdot, ++column)
            {
                printf("%c", isdot ? '.' : '#');
            }
            printf("\n");
        }
        printf("\n");
        free(data);
    }
    tail = NULL;
    return 0;
}



Measured memory_bytes: 2144
# -*- coding: utf-8 -*-
import math

# input
N = int(input())

# solve
def divisor(n):
    i = 1
    l = list()
    while i * i <= n:
        if n % i == 0:
            l.append(i)
            l.append(n // i)
        i += 1
    l = list(set(l))
    return l

l = sorted(divisor(N))
ans = 10 ** 12
for i in range(math.ceil(len(l) / 2)):
    ans = min(l[i] - 1 + l[len(l) - i - 1] - 1, ans)

# output
print(ans)


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

using namespace std;

bool is_doubled(string s) {
	if (s.size() % 2 != 0) return false;
	for (int i = 0; i < s.size() / 2; i++) {
		if (s[i] != s[s.size() / 2 + i]) return false;
	}
	return true;
}

int main(int argc, char *argv[]) {
	string S;
	cin >> S;

	while (!S.empty()) {
		S.pop_back();
		if (is_doubled(S)) {
			cout << S.size() << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main()
{
	char S[200];
	int i = 0;

	scanf("%s",S);

	while(S[i] != '\0')
	{
		if(S[i] >= 'a' && S[i] <= 'z')
			S[i] = 'x';
		i++;
	}
	
	printf("%s\n",S);
	return 0;
}


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

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

    if (N % 2 == 1) {
        double ans = (N / 2 + 1) / (double)N;
        cout << setprecision(10) << ans << endl;
    }
    else {
        double ans = (N/ 2) / (double) N;
        cout << setprecision(10) << ans << endl;
    }
}


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

using namespace std;

int main(){
  string s;
  string t;
  cin >> s;
  cin >> t;
  
  int n = (int)s.size();
  int m = (int)t.size();
  
  int i;
  for(i = n - 1; i >= m - 1; i--){
    int j;
    for(j = m - 1; j >= 0; j--){
      if(s[i - m + j + 1] == t[j] || s[i - m + j + 1] == '?') continue;
      else break;
    }
    
    if(j == -1) break;
  }
  
  if(i < m - 1){
    cout << "UNRESTORABLE" << endl;
  }else{
    for(int j = 0; j < n; j++){
      if(j >= i - m + 1 && j <= i){
        cout << t[j - i + m - 1];
      }else{
        if(s[j] == '?') cout << 'a';
        else cout << s[j];
      }
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll X, N;
    set<ll> p;
    cin >> X >> N;
    rep(i, N)
    {
        ll t;
        cin >> t;
        p.insert(t);
    }
    {
        for (ll i = 0;; ++i)
        {
            if (p.find(X-i) == p.end())
            {
                cout << X-i;
                break;
            }
            if (p.find(X + i) == p.end())
            {
                cout << X + i;
                break;
            }
        }
    }

    // 
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(20)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N;
    cin >> N;
    double y = 0, b = 0;
    REP(i, N)
    {
        double x;
        string s;
        cin >> x >> s;
        if (s == "JPY")
            y += x;
        else
            b += (380000 * x);
    }
    cout << OF64 << y + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
  
int main(void){
  string s,t;
  cin >> s>> t;
  t.pop_back();
  if(s==t) {
    cout << "Yes" << endl;
  }
  else{ 
    cout << "No" << endl;
      }
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int n, m, N;
int work(int x)
{
    return x < 0 ? 0 : x;
}
int main()
{
    cin >> n >> m >> N;
    int wl = 0, wr = n;
    int hl = 0, hr = m;
    for(int x, y, a, i = 0; i < N; i++)
    {
        cin >> x >> y >> a;
        if(a == 1) wl = max(wl, x);
        if(a == 2) wr = min(wr, x);
        if(a == 3) hl = max(hl, y);
        if(a == 4) hr = min(hr, y);
    }
    cout << work(wr - wl) * work(hr - hl) << endl;
    return 0;
}


Measured memory_bytes: 384
import itertools
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
import bisect
import sys
sys.setrecursionlimit(10**9)

def main():
    K = int(input())
    A,B = map(int,input().split())

    ok = False
    for k in range(A,B+1):
        if k % K == 0:
            ok = True


    print("OK" if ok else "NG")





if __name__ == "__main__":
  main()


Measured memory_bytes: 27208
import numpy as np
n,k=map(int,input().split())
m=np.zeros((3*k,3*k),dtype=int)
l=2*k
o=0
for _ in range(n):
  x,y,c=input().split()
  x,y=int(x)%l,int(y)%l
  t=c=='W'
  m[x,y]+=1-2*t
  o+=t
for _ in range(2):
  m[l:]=m[:k]
  m=np.cumsum(m,axis=0)
  m[:l]=m[k:]-m[:l]
  m=m.T
m=m[:l,:l]
print(o+(m+np.roll(np.roll(m,k,axis=0),k,axis=1)).max())

Measured memory_bytes: 153088
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		int[] arr=new int[n];
		
		for(int i=0;i<n;i++)
		{
			arr[i]=s.nextInt();
		}
		
		int[] dp=new int[n];
		
		for(int i=1;i<n;i++)
		{
			int one=Integer.MAX_VALUE;
			int two=Integer.MAX_VALUE;
			
			if(i-1>=0)
			{
				one=dp[i-1]+Math.abs(arr[i]-arr[i-1]);
			}
			if(i-2>=0)
			{
				two=dp[i-2]+Math.abs(arr[i]-arr[i-2]);
			}
			
			dp[i]=Math.min(one,two);
		}
		
		System.out.println(dp[n-1]);
		
	}
	
}

Measured memory_bytes: 52444
import java.util.*;

public class Main{
	public static void main(String[] args) {
      int []cnt=new int[5];
      boolean ans=true;
      Scanner in =new Scanner(System.in);
      for (int i=0;i<6;i++){
        int a=in.nextInt();
      	if (++cnt[a]==3)ans=false;
     
      }
     if (!ans)System.out.println("NO");
        else System.out.println("YES");
      
      return;
    }
}


Measured memory_bytes: 22612
def BC133_E():
    n, k = map(int, input().split())
    d = [set() for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(int, input().split())
        d[a - 1].add(b - 1)
        d[b - 1].add(a - 1)
    stack = [(0, 0)]
    visited = set()
    res = []
    while stack:
        i, l = stack.pop(0)
        visited.add(i)
        c = len(d[i] - visited)
        if c != 0:
            if l == len(res):
                res.append([c])
            else:
                res[l].append(c)
        for j in d[i]:
            if j not in visited: stack.append((j, l + 1))
    ans = k
    MOD = 10**9 + 7
    for i in range(len(res)):
        if i == 0:
            c = k - 1
            for m in range(res[0][0] - 1):
                c = ((k - m - 2) * c) % MOD
            ans = (ans * c) % MOD
        else:
            for j in res[i]:
                c = k - 2
                for m in range(j - 1):
                    c = ((k - m - 3) * c) % MOD
                ans = (ans * c) % MOD
    print(ans)


BC133_E()

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)

const ll N = 123456;
const ll mod = 998244353;
const ld eps = 1e-5;

ll a[N];
ll b[N];
ll dp[123][N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cout.precision(10);

    int n , w;

    cin >> n >> w;

    rep(i , 1 , n) cin >> b[i - 1] >> a[i - 1];
    rep(i , 0 , n) {
        rep(j , 0 , w) {
            if(i == 0 || j == 0) {
                dp[i][j] = 0;
            }
            else if(b[i - 1] <= j) {
                dp[i][j] = max(dp[i - 1][j] ,  a[i - 1] + dp[i - 1][j - b[i - 1]]);
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 100224
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    int a[110];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a, a+n, greater<int>());
    int alice=0;
    int bob=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            alice+=a[i];
        }
        else bob+=a[i];
    }
    cout<<alice-bob<<endl;
}

Measured memory_bytes: 256
H,W = map(int, input().split())

def calc(H,W,ans):
    for i in range(1,H):
        Sa = i * W
        h = (H-i) // 2
        Sb = h * W
        Sc = (H-i-h) * W
        d1 = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
        w = W // 2
        Sb = (H-i) * w
        Sc = (H-i) * (W-w)
        d2 = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
        if ans > min(d1,d2): ans = min(d1,d2)
    return ans

ans = 1000000
ans = calc(H,W,ans)
ans = calc(W,H,ans)

print(ans)

Measured memory_bytes: 3064
matrix = []
r, c = map(int, input().split())

for i in range (r): #行の構築
    _line = list(map(int, input().split()))
    _line.append(sum(_line))
    matrix.append(_line)

_col_sum = [] #列の構築
for j in range (c+1):
    num = 0
    for i in range (r):
        num += matrix[i][j]
    _col_sum.append(num)

matrix.append(_col_sum)

for i in range (r+1):
    print(" ".join(map(str, matrix[i])))


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

using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n), b(n + 1);
	int d = 0, r = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		b[a[i]]++;
		d = max(d, a[i]);
	}
	bool flag = true;
	if(d % 2 == 0){
		r = d / 2;
		if(b[r] < 1){
			flag = false;
		}
		if(flag){
			b[r]--;
			for(int i = r + 1; i <= d; i++){
				if(b[i] < 2){
					flag = false;
					break;
				}
				b[i] -= 2;
			}
		}
	}else{
		r = d / 2 + 1;
		for(int i = r; i <= d; i++){
			if(b[i] < 2){
				flag = false;
				break;
			}
			b[i] -= 2;
		}
	}
	if(flag){
		for(int i = r; i >= 1; i--){
			if(b[i] > 0){
				flag = false;
			}
		}
	}
	if(flag){
		printf("Possible\n");
	}else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 256
#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 FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n,a,b;
  cin>>n>>a>>b;
  cout<<min(n*a,b)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long
int n,k;
string s;

int main(){
  cin>>s;
  int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';

  bool f1= (a*10+b)>12 || (a*10+b)<=0;
  bool f2= (c*10+d)>12 || (c*10+d)<=0;

  if(f1&&f2){
    cout<<"NA"<<endl;
  }
  else if(f1){
    cout<<"YYMM"<<endl;
  }
  else if(f2){
    cout<<"MMYY"<<endl;
    
  }
  else{
    cout<<"AMBIGUOUS"<<endl;
  }

  

	return 0;
}


Measured memory_bytes: 256
import sys


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


a,b,c = LI()
if a<b<c:
    print('Yes')
else:
    print('No')


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n, t;
	float a;
	cin >> n >> t;
	cin >> a;

	vector<int> h(n);
	rep (i, 0, n)
		cin >> h[i];

	float good = t - h[0] * 0.006;
	int place = 0;
	rep (i, 1, n) {
		float tmp = t - h[i] * 0.006;
		if (abs(a - good) > abs(a - tmp)) {
			good = tmp;
			place = i;
		}
	}

	cout << place + 1 << endl;

	return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UnionFind
{
    int i;
    vector<int> par;
    vector<int> size;
    UnionFind(int n): par(n),size(n,1){
        for(i = 0;i < n;++i){
            par.at(i) = i;
        }
    }
    
    int root(int x){
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = root(par.at(x));
        }
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return;
        }else{
            if(size.at(rx) < size.at(ry)){
                swap(rx,ry);
            }
            par.at(ry) = rx;
            size.at(rx) += size.at(ry);
            return;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size.at(root(x));
    }
};

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    UnionFind uf(n);
    for(i = 0;i < m;++i){
        ll a,b;
        cin >> a >> b;
        --a;    --b;
        uf.unite(a,b);
    }
    ll ans = 0;
    for(i = 0;i < n;++i){
        if(uf.root(i) != i) continue;
        ll tmp = uf.get_size(i);
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4840
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(X: int):
    A=100
    ans=1
    while True:
        A=int(A*1.01)
        if X<=A:
            print(ans)
            exit()
        else:
            ans+=1
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
//Diameter of a Tree
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

static const int MAX = 100000;

struct Edge {
public:
    int t, w;
    Edge(int t, int w): t(t), w(w) {}
};

int N;
vector<Edge> G[MAX];
queue<int> Q;
bool visited[MAX];
int d[MAX];

void bfs(int u) {
    int v;
    for (int i = 0; i < MAX; i++) {
        visited[i] = false;
        d[i] = 0;
    }
    Q.push(u);
    visited[u] = true;
    while (!Q.empty()) {
        v = Q.front();
        Q.pop();
        for (auto e : G[v]) {
            if (!visited[e.t]) {
                Q.push(e.t);
                visited[e.t] = true;
                d[e.t] = d[v] + e.w;
            }
        }
    }
}

int diameter() {
    int x, y, maxd = 0;
    bfs(0);
    for(int i = 0; i < N; i++) {
        if(maxd < d[i]) {
            maxd = d[i];
            x = i;
        }
    }
    bfs(x);
    maxd = 0;
    for(int i = 0; i < N; i++) {
        if(maxd < d[i]) maxd = d[i];
    }
    return maxd;
}

int main() {
    int s, t, w;
    cin >> N;
    for(int i = 1; i < N; i++) {
        cin >> s >> t >> w;
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }

    cout << diameter() << endl;
}



Measured memory_bytes: 10012
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


template <typename T>
inline std::string to_bin_str(T n, std::size_t digit_num) {
    std::string str;
    while (n > 0) {
        str.push_back('0' + (n & 1));
        n >>= 1;
    }
    str.resize(digit_num, '0');
    std::reverse(str.begin(), str.end());
    return str;
}


int main(void){
	int N;	cin >> N;
  int V[N], C[N];
  string b[int(pow(2, N))];
  int ans = 0;

  rep(i,N)  {
    int a;
    cin >> a;
    V[i] = a;
  }
  rep(i,N)  {
    int a;
    cin >> a;
    C[i] = a;
  }
  rep(i,int(pow(2, N))) {
    b[i] = to_bin_str(i, N);
  }

  rep(i,int(pow(2, N)))  {
    int X = 0;
    int Y = 0;
    rep(j,N)  {
      if (b[i][j] == '1') {
        X += V[j];
        Y += C[j];
      }
    }
    ans = max(ans, X-Y);
  }



	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 90368
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
#define all(A) A.begin(), A.end()
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

int A[100][100];
int B[100][100];
bool dp[100][100][40000];

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, 0, H) rep(j, 0, W) cin >> A[i][j];
    rep(i, 0, H) rep(j, 0, W) cin >> B[i][j];

    rep(i, 0, H) rep(j, 0, W) rep(k, 0, 40000) dp[i][j][k] = 0;
    
    int N = (H+W) * 80;
    int d = A[0][0] - B[0][0];
    dp[0][0][d+N] = 1;
    dp[0][0][-d+N] = 1;

    rep(i, 0, H) {
        rep(j, 0, W) {
            d = A[i][j] - B[i][j];
            rep(k, 0, 2*N+1) {
                if (i != 0) {
                    if (0 <= k-d && k-d <= 2*N) {
                        dp[i][j][k] |= dp[i-1][j][k-d];
                    }
                    if (0 <= k+d && k+d <= 2*N) {
                        dp[i][j][k] |= dp[i-1][j][k+d];                    }
                    }
                if (j != 0) {
                    if (0 <= k-d && k-d <= 2*N) {
                        dp[i][j][k] |= dp[i][j-1][k-d];
                    }
                    if (0 <= k+d && k+d <= 2*N) {
                        dp[i][j][k] |= dp[i][j-1][k+d];
                    }
                }
            }
        }
    }

    int ans = inf;
    
    rep(k, 0, 2*N+1) {
        if (dp[H-1][W-1][k]) {
            ans = min(ans, abs(k-N));
        }
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll a,b,k;

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

  cin>>a>>b>>k;
  for(ll i=100;i>=1;i--){
    if(a%i==0&&b%i==0){
      k--;
      if(k==0){
        cout<<i<<endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
from itertools import permutations
n = int(input())
xy = [[int(i) for i in input().split()] for _ in range(n)]
d, r = 0, 0
for route in permutations(range(n)):
    r += 1
    for i in range(n - 1):
        xi, yi = xy[route[i]]
        xj, yj = xy[route[i + 1]]
        d += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5
print(d / r)

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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)1e5 + 7;

string a;
int u[5];

int main () {
        cin >> a;

        for (int i = 0; i < a.size(); i ++) {
                u[a[i] - 'a'] ++;
        }
        int mn = min(u[0],min(u[1],u[2]));

        u[0] -= mn;
        u[1] -= mn;
        u[2] -= mn;

        if (u[0] + u[1] + u[2] > 2 || !(u[0] < 2 && u[1] < 2 && u[2] < 2)) {
                cout << "NO";
        }
        else
                cout << "YES";
}


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

int main() {

  int N, M;
  cin >> N >> M;
  int sum = 0;
  
  for (int i = 1; i < N; i++) {
    sum += i;
  }
  for (int i = 1; i < M; i++) {
    sum += i;
  }
  
  cout << sum << endl; 
  

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define MAX 10000 
#define NIL -1

using namespace std;

typedef struct{
    int parent;
    int left;
    int right;
}Node;

Node T[MAX];
int Depth[MAX], Height[MAX];

void setDepth(int u, int d){
    if(u == NIL) return;
    Depth[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
    Height[u] = max(h1, h2);
    return Height[u];
}

int getSibling(int u){
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left == u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
    if(T[T[u].parent].right == u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
    return NIL;
}

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    int degree = 0;
    if(T[u].left != NIL) degree++;
    if(T[u].right != NIL) degree++;
    cout << "degree = " << degree << ", ";
    cout << "depth = " << Depth[u] << ", ";
    cout << "height = " << Height[u] << ", ";
    if(T[u].parent == NIL) cout << "root" << endl;
    else if(degree == 0) cout << "leaf" << endl;
    else cout << "internal node" << endl;
}

int main(){
    int n, i, p, x = 0;
    scanf("%d", &n);
//    cin >> n;

    for(i = 0; i < n; i++){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }

    for(i = 0; i < n; i++){
        scanf("%d", &p);
        scanf("%d%d", &T[p].left, &T[p].right);
//        cin >> p >> T[i].left >> T[i].right;
        if(T[p].left != NIL) T[T[p].left].parent = p;
        if(T[p].right != NIL) T[T[p].right].parent = p;
    }
    
    for(i = 0; i < n; i++){
        if(T[i].parent == NIL) x = i;
    }

    setDepth(x, 0);
    setHeight(x);

    for(i = 0; i < n; i++) print(i);

    return 0;
}


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

int main()
{
    int N, M;
    string S;
    cin >> N >> M >> S;

    stack<int> res;
    int pos = N;
    while (pos > 0)
    {
        int next = -1;
        for (int d = M; d > 0; d--)
        {
            if (pos - d < 0)
            {
                continue;
            }
            if (S.at(pos - d) == '0')
            {
                next = pos - d;
                res.push(d);
                break;
            }
        }
        if (next < 0)
        {
            cout << -1 << endl;
            return 0;
        }
        pos = next;
    }
    while (res.size())
    {
        cout << res.top() << " ";
        res.pop();
    }
    cout << endl;
}

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

int main(void){

    char s[1002];
    int n;
    int flag[4] = {0};
    int i;

    scanf("%s", s);
    n = strlen(s);

    for(i = 0; i < n; i++){
        if(s[i] == 'E') flag[0] = 1;
        if(s[i] == 'W') flag[1] = 1;
        if(s[i] == 'S') flag[2] = 1;
        if(s[i] == 'N') flag[3] = 1;
    }

    if((flag[0] == 1 && flag[1] == 0) || (flag[0] == 0 && flag[1] == 1) || (flag[2] == 1 && flag[3] == 0) || (flag[2] == 0 && flag[3] == 1)) printf("No\n");
    else printf("Yes\n");

    return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(){
  int result=999;
  int i,tmp;
  char s[11];
  
  scanf("%s",s);
  
  for(i=0;i<strlen(s)-2;i++){
    tmp=(s[i]-'0')*100;
    tmp+=(s[i+1]-'0')*10;
    tmp+=s[i+2]-'0';
    tmp=753-tmp;
    if(tmp<0) tmp=0-tmp;
    if(tmp<result) result=tmp;
  }
  
  printf("%d",result);
}

Measured memory_bytes: 128
s = gets.chomp.split("").map(&:to_i)

even = Array.new(s.size){|idx| idx % 2}
odd  = Array.new(s.size){|idx| (idx+1) % 2}

count = [0,0]
s.each_with_index do |c,i|
  if c != even[i]
    count[0] += 1
  end

  if c!= odd[i]
    count[1] += 1
  end

end

puts count.min

Measured memory_bytes: 9340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll MAX=300053;
const ll MOD=1000000007;
vector<ll> conn[MAX],dir[MAX],now;
ll N,cnt[MAX],par[MAX],fact[MAX],chk[MAX],fin=1,npar[MAX],inv_dir[MAX];
void build(ll x, ll px){
    if(npar[x]!=0) return;
    npar[x]=px; now.push_back(x);
    for(ll i=0;i<conn[x].size();i++) if(px!=conn[x][i]) build(conn[x][i],x);
}
ll power(ll x,ll y){
    if(y==0) return 1;
    ll t=power(x,y/2);
    if(y%2) return t*t%MOD*x%MOD;
    return t*t%MOD;
}
pll counter(ll x){
    ll t1=1,t2=1;
    for(ll i=0;i<dir[x].size();i++){
        pll tmp=counter(dir[x][i]);
        t1+=tmp.first,t2*=tmp.second*power(fact[tmp.first],MOD-2)%MOD; t2%=MOD;
    }
    t2*=fact[t1-1]; t2%=MOD;
    return make_pair(t1,t2);
}
ll calc(ll x){
    ll val[2]={1,1},pt=-1;
    for(ll i=0;i<2;i++){
        for(pt++;pt<conn[x].size();pt++) if(par[conn[x][pt]]==0) break;
        build(x,conn[x][pt]);
        for(ll j=0;j<now.size();j++) {
            ll t=now[j];
            for(ll k=0;k<conn[t].size();k++) {
                if(conn[t][k]==npar[t]) break;
                dir[t].push_back(conn[t][k]),inv_dir[conn[t][k]]++;
            }
        }
        for(ll j=0;j<now.size();j++) {
            ll t=now[j];
            if(chk[t]==0&&inv_dir[t]==0) {
                pll tmp=counter(t);
                val[i]*=tmp.second*power(fact[tmp.first],MOD-2)%MOD; val[i]%=MOD;
            }
        }
        while(!now.empty()){ll t=now.back(); dir[t].clear(); inv_dir[t]=0; npar[t]=0; chk[t]=i; now.pop_back();}
    }
    return (val[0]+val[1])%MOD;
}
int main(){
    scanf("%lld",&N);
    for(ll i=1;i<=2*N;i++){
        ll t1,t2;
        scanf(" %lld %lld",&t1,&t2); t2+=N;
        cnt[t1]++, cnt[t2]++;
        conn[t1].push_back(t2);
        conn[t2].push_back(t1);
    }
    for(ll i=1;i<=2*N;i++) sort(conn[i].begin(),conn[i].end());
    for(ll i=1;i<=2*N;i++) {
        if(cnt[i]<=1) now.push_back(i);
    }
    while(!now.empty()){
        ll u=now.back(),up=0;
        now.pop_back();
        if(cnt[u]==1){
            cnt[u]=0;
            for(ll i=0;i<conn[u].size();i++) if(par[conn[u][i]]==0){
                cnt[conn[u][i]]--; up=conn[u][i];
                if(cnt[conn[u][i]]<=1) now.push_back(conn[u][i]);
            }
            par[u]=up;
        }
        else{
            printf("0\n");
            return 0;
        }
    }
    for(ll i=1;i<=2*N;i++) if(par[i]==0&&conn[i].size()<2){
        printf("0\n");
        return 0;
    }
    fact[0]=1;
    for(ll i=1;i<=2*N;i++) fact[i]=fact[i-1]*i%MOD;
    for(ll i=1;i<=2*N;i++){
        if(par[i]==0&&chk[i]==0) {
            fin*=calc(i),fin%=MOD;
        }
    }
    fin*=fact[2*N],fin%=MOD;
    printf("%lld\n",fin);
}



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

def main():
    N = int(readline())
    f = [0 for _ in range(N+1)]
    for i in range(1, N+1):
        j = i
        while j <=N:  
            f[j] += 1
            j += i
    ans = 0
    for i in range(1, N+1):
        ans += i*f[i]
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 218896
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){


  ll n,m;cin>>n>>m;
  ll s[n],t[m];
  REP(i,n){
    cin>>s[i];
  }
  REP(i,m){
    cin>>t[i];
  }

  ll ans = 1;

  ll dp[n][m];
  ll sumDP[n][m];
  REP(i,n){
    REP(j,m){
      dp[i][j] = 0;
      sumDP[i][j] = 0;
    }
  }

  REP(i,n){
    REP(j,m){
      if(s[i]==t[j]){
        if(i==0||j==0){
          dp[i][j] = 1;
        }else{
          dp[i][j] = sumDP[i-1][j-1] + 1;
          dp[i][j] %= MOD;
        }
      }
      if(i==0){
        if(j==0){
          sumDP[i][j] = dp[i][j];
        }else{
          sumDP[i][j] = sumDP[i][j-1] + dp[i][j];
        }
        
        sumDP[i][j] %= MOD;
      }else if(j==0){
        sumDP[i][j] = sumDP[i-1][j] + dp[i][j];
        sumDP[i][j] %= MOD;
      }else{
        sumDP[i][j] = (sumDP[i-1][j] + sumDP[i][j-1] - sumDP[i-1][j-1] )  + dp[i][j];
        sumDP[i][j] %= MOD;
      }
      //cout<<sumDP[i][j]<<" "<<i<<" "<<j<<endl;
    }
  }

  /*REP(i,n){
    REP(j,m){
      cout<<sumDP[i][j]<<"  ";
    }
    cout<<endl;
  }
  cout<<endl;
  REP(i,n){
    REP(j,m){
      cout<<dp[i][j]<<"  ";
    }
    cout<<endl;
  }*/

  ans += sumDP[n-1][m-1];
  ans %= MOD;
  while(ans<0){
    ans += MOD;
    ans %= MOD;
  }

  cout<<ans<<endl;



 

  return 0;
}

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

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

	int W, H, N;
	int x, y, a;
	scanf("%d %d %d", &W, &H, &N);

	int edge[5] = {-1, 0, W, 0, H};
	for (int i = 0; i < N; i++) {
		scanf("%d %d %d", &x, &y, &a);
		switch (a) {
			case 1:
				edge[1] = max(x, edge[1]);
				break;
			case 2:
				edge[2] = min(x, edge[2]);
				break;
			case 3:
				edge[3] = max(y, edge[3]);
				break;
			case 4:
				edge[4] = min(y, edge[4]);
				break;
			default:
				break;
		}
	}
	// printf("%d %d %d %d \n", edge[1], edge[2], edge[3], edge[4]);
	printf("%d", max(0, (edge[2] - edge[1])) * max(0, (edge[4] - edge[3])));
	return 0;
}


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

int main() {
  int n; cin >>n;
  int keta=0,x=n;
  while(x){
    keta+=x%10;
    x/=10;
  }
  if(n%keta==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    import numpy as np
    n,d=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    cnt=0
    for j in range(n-1):
        for k in range(j+1,n):
            a=np.array(l[j])-np.array(l[k])
            if (np.linalg.norm(a))%1==0:
                cnt+=1
    print(cnt)
resolve()

Measured memory_bytes: 12244
#include "bits/stdc++.h"

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);


int main(){
  int a, b;
  cin >> a >> b;
  DEBUG(a); DEBUG(b);
  cout << max(a - b, max(a + b, a * b)) << endl;
}


Measured memory_bytes: 256