akhauriyash/Code-Regression huggingface dataset:
def pff(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf
def examD():
    N = I()
    d = defaultdict(int)
    for i in range(2,N+1):
        cur  = pff(i)
        for key,j in cur.items():
            d[key] +=j
#    print(d)
    Num = defaultdict(int)
    for i in d.values():
        for j in [3,5,15,25,75]:
            if i>=j-1:
                Num[j] +=1
            else:
                break
#    print(Num)
    ans = 0
    ans += (Num[5]*(Num[5]-1)//2)*(Num[3]-2)
    ans += Num[15]*(Num[5]-1)
    ans += Num[25]*(Num[3]-1)
    ans += Num[75]
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Switches | diff Switches.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Switches.cpp && ./a.out

/*
 
 5/26/2019
 
 5:05-
 
 */

const int MAX_N=1e2+1;
int P[MAX_N],K[MAX_N],S[MAX_N][MAX_N];
int N,M;

int masks[MAX_N];
void solve() {
  REP(i,M) {
    int m=0;
    REP(j,K[i]) m|=(1<<(S[i][j]-1));
    masks[i]=m;
  }
  int res=0;
  REP(mask,1<<N) {
    int cnt=0;
    REP(i,M) {
      int x=mask&masks[i];
      int p=__builtin_popcount(x);
      cnt+=p%2==P[i];
    }
    res+=cnt==M;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,M) {
    cin>>K[i];
    REP(j,K[i]) cin>>S[i][j];
  }
  REP(i,M)cin>>P[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int x;
    int i = 0;

    while(true){
      x = sc.nextInt();
      if(i==10000 || x==0) break;
      System.out.printf("Case %d: %d\n", i+1, x);
      i++;
    }

    //for(int j=0; j<i; j++) System.out.printf("Case %d: %d\n", j+1, num[j]);
  }
}



Measured memory_bytes: 66808
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;


int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	string s;
	string ans;
	cin >> s;
	rep(i, s.size()) {
		if (i % 2 == 0) {
			ans.push_back(s[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
H,W=map(int, input().split(' '))
Map = [list("A" + input() + "A") for i in range(H)]
Map.insert(0,["A"]*(W+2))
Map.append(["A"]*(W+2))
ans = [[] for i in range(H)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if Map[i][j] == "#":
            ans[i-1].append("#")
        else:
            minenum = 0
            for (x,y) in [(i-1,j-1),(i-1,j),(i-1,j+1),(i,j-1),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1)]:
                if Map[x][y] == "#":
                    minenum += 1
            ans[i-1].append(minenum)
for x in ans:
    print(*x,sep="")

Measured memory_bytes: 3572
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k=[0]*60
  n=I()
  l=LI()

  for x in l:
    _a=bin(x)[2:]
    a=_a.zfill(60)

    for i,y in enumerate(a):
      if y=='1':
        k[59-i]+=1

  ans=0
  for i,x in enumerate(k):
    ans+=(n-x)*x*(2**i)
    ans%=mod

  return ans%mod

# main()
print(main())


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

typedef long long int ll;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	ll sum = 0LL;
	for (int i = 1; i <= n; i++){
		ll x = floor((double) n/i);
		sum += (ll) i*x*(x+1)/2;
	}
	cout << sum << '\n';
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FIO                     ios::sync_with_stdio(false); cin.tie(nullptr)
#define TC(t)                   int t; cin >> t; for(int i = 1; i <= t; i++)
#define deb(x)                  cerr << #x << " = " << x << endl
#define deb2(x, y)              cerr << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)             for(i = a; i < n; i++)
#define f1(i, a, n)             for(i = a; i <= n; i++)
#define ini(x, y)               memset(x, y, sizeof(x))
#define all(x)                  x.begin(), x.end()
#define sz(x)                   x.size()
#define ll                      long long int
#define pb                      push_back
#define ppb                     pop_back
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define M                       1000000007
#define endl                    '\n'
#define bits(x)                 __builtin_popcountll(x)
#define zrbits(x)               __builtin_ctzll(x)
#define vi                      vector<int>
#define pii                     pair<int,int>
#define vpii                    vector<pii>
#define ordered_set             tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define multi_ordered_set       tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>

const int N = 1e5 + 1;
const int MX = 1e9;
const ll INF = 1e18;

using namespace std;
using namespace __gnu_pbds;

inline ll ceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
inline ll mod(ll x) {return ( (x % M + M) % M );}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {for(auto& x : v) os << x << " "; return os << '\n';}

void solve() {
        ll n;
        cin >> n;
        string s = "ACL";
        while(n--) cout << s;
        cout << endl;
}

int main () {
        FIO;
        // TC(t)
        solve();
        return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


// |a-(sum-a)| = |2*a-sum|

int main(){
  int N,M; cin>>N>>M;
  vector<int> fr1;
  umap<int,int> toN;
  int a,b;
  REP(i,M){
    cin >> a>> b;
    if(a==1){fr1.push_back(b);}
    else if(b==N){toN[a]=1;}
  }
  bool ok = false;
  for(int x:fr1){
    if(toN[x]==1){ok=true; break;}
  }
  cout << (ok?"POSSIBLE":"IMPOSSIBLE");
}

Measured memory_bytes: 8896
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Solve{
	final Scanner in = new Scanner(System.in);
	
	int n, m, p, a, b;
	boolean solve(){
		n = in.nextInt();
		m = in.nextInt();
		p = in.nextInt();
		a = in.nextInt()-1;
		b = in.nextInt()-1;
		if(n == 0) return false;
		int[] h = new int[n];
		for(int i=0; i<n; i++) h[i] = in.nextInt();
		Node[] node = new Node[m];
		int[][] dist = new int[m][m];
		for(int i=0; i<m; i++){
			node[i] = new Node(i);
		}
//		
//		for(int i=0; i<p; i++){
//			for(int j=0; j<p; j++){
//				
//			}
//		}
		for(int i=0; i<p; i++){
			int x = in.nextInt()-1;
			int y = in.nextInt()-1;
			int z = in.nextInt();
			node[x].createEdge(node[y]);
			node[y].createEdge(node[x]);
			dist[y][x] = dist[x][y] = z;
		}
		Queue<Pos> qu = new PriorityQueue<Pos>();
		BitSet used = new BitSet();
		qu.add(new Pos(a, (1<<n)-1, 0));
		double res = -1;
		while(!qu.isEmpty()){
			Pos p = qu.poll();
			if(used.get(p.id)) continue;
			if(p.p == b){
				res = p.time;
				break;
			}
			used.set(p.id);
			for(Node v: node[p.p].edge){
				for(int i=0; i<n; i++){
					if((p.tic&1<<i)==0) continue;
					qu.add(new Pos(v.id, p.tic&~(1<<i)
							, p.time+(double)dist[p.p][v.id]/h[i]));
				}
			}
		}
		System.out.println(res < 0 ? "Impossible" : res);
		return true;
	}
}

class Pos implements Comparable<Pos>{
	int p;
	int tic;
	int id;
	double time;
	Pos(int p, int tic, double time){
		this.p = p;
		this.tic = tic;
		id = p|(tic<<5);
		this.time = time;
	}
	
	@Override
	public int compareTo(Pos o) {
		return Double.compare(time, o.time);
	}
}

class Node{
	int id;
	ArrayList<Node> edge = new ArrayList<Node>();
	Node(int id){
		this.id = id;
	}
	
	void createEdge(Node nd){
		edge.add(nd);
	}
}

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

Measured memory_bytes: 97172
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int a, b, x;
  cin >> a >> b >> x;
  int area  = a * b;
  double x2 = (double)x / a;
  double tanv;
  if (x2 * 2 > area) {
    double k = (area - x2) * 2 / a;
    tanv = k / a;
  } else {
    double k = x2 * 2 / b;
    tanv = b / k;
  }
  cout << atan(tanv) * 180 / M_PI << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
#define sz(x) int(x.size())
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

const int INF = 1e9 + 7;
using pii = pair<int, int>;

#define NDEBUG

int main() {
    int N, M;
    cin >> N >> M;
    auto G = vectors(0, N, 0);
    repeat(i, M) {
        int u, v;
        cin >> u >> v;
        G[u - 1].push_back(v - 1);
    }
    int S, T;
    cin >> S >> T;
    --S, --T;
    auto d = vectors(INF, N, 3);
    queue<pii> que;
    d[S][0] = 0;
    que.emplace(0, 3 * S + 0);
    while (!que.empty()) {
        pii p = que.front();
        int v = p.second / 3;
        int m = p.second - 3 * v;
        que.pop();
        if (p.first > d[v][m]) continue;
        for (int to : G[v]) {
            if (d[to][(m + 1) % 3] > d[v][m] + 1) {
                d[to][(m + 1) % 3] = d[v][m] + 1;
                que.emplace(d[v][m] + 1, 3 * to + (m + 1) % 3);
            }
        }
    }
    int res = d[T][0];
    if (res == INF) {
        cout << -1 << endl;
    } else {
        assert(res % 3 == 0);
        cout << res / 3 << endl;
    }
}

Measured memory_bytes: 13996
import heapq
n=int(input())
abs=sorted([list(map(int,input().split())) for _ in range(n)])
s=0
best=0
heap=[]
for k in range(1,n+1):
    while(s < n and abs[s][0] <= k+1):
        heapq.heappush(heap, abs[s][1])
        s+=1
    while(len(heap) > 0 and heap[0] <= k):
        heapq.heappop(heap)
    if(len(heap) >= k):
        best = k
print(best)

Measured memory_bytes: 33108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && a!=c) || (b==c && b!=a) || (a==c && a!=b))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
N, A, B = list(map(int, input().split(" ")))
X_list = list(map(int, input().split(" ")))

val = 0

for X1, X2 in zip(X_list[:-1], X_list[1:]):
    A_val = A*(X2-X1) 
    if A_val > B:
        val += B
    else:
        val += A_val
print (val)

Measured memory_bytes: 14252
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

n,m = map(int,readline().split())
g = [[] * n for i in range(n)]
for i in range(m):
    u, v = map(int,readline().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
    
ans = [-1]*n
from collections import deque

que = deque()
que.append((0,1))
chk = [False]*n
chk[0] =True
cnt = 1
while que:
    now,p = que.popleft()
    if cnt == n:
      break
    for i in g[now]:
        if not chk[i]:
          ans[i] = p
          chk[i] = True
          cnt += 1
          que.append((i,i+1))

if cnt!=n:
  print('No')
  exit()
  
print('Yes')
for i in ans[1:]:
  print(i)

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

int main()
{
    long long x, k, d, y, z, ans;

    cin >> x >> k >> d;

    x=abs(x);

    y=x/d;
    z=x%d;

    if(y>k)
        cout << z+(y-k)*d << endl;
    else
    {
        y-=k;
        if(y&1)
            cout << d-z << endl;
        else
            cout << z << endl;
    }

}

Measured memory_bytes: 3624
#include<stdio.h>
int n, A[50];
int solve(int i, int m){
  if(m == 0){return 1;}
  if(i >= n){return 0;}
  int res = solve(i + 1,m) || solve(i + 1,m - A[i]);
  return res;
}
int main(){
  int q , M, i;
  scanf("%d", &n);
  for(i = 0;i < n; i++){
    scanf("%d" ,&A[i]);
  }
  scanf("%d", &q);
  for(i = 0;i < q;i++){
    scanf("%d", &M);
    if(solve(0,M)){
      printf("yes\n");
    }
    else {printf("no\n");}
  }
  return 0;
}



Measured memory_bytes: 2064
n, m = map(int, input().split())
*x, = map(int, input().split())
*y, = map(int, input().split())

MOD = 10**9+7


def calc(v, l):
    r = 0
    for i in range(l):
        r = r + i*v[i] - (l-1-i)*v[i]
        r %= MOD
    return r


print((calc(x, n)*calc(y, m)) % MOD)


Measured memory_bytes: 86816
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  cin >> n;
  
  vector<int> p(n);
  vector<int> q={};
  int sum=0;
  
  rep(i,n){
  cin>>p[i];
    if(p[i]%10!=0) q.pb(p[i]);
  sum+=p[i];
  }

  if(sum%10!=0) {
  cout << sum << endl;
  return 0;
  }
  
  sort(all(q));
  
  vector<int> r={};
  
  if(q!=r) {
  cout << sum-q[0] << endl;
  return 0;
  }
  
  cout << 0 << endl;
  
}


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

const int MAXN = 200010;
typedef std::pair<int, int> pi;
std::set<int> qry[MAXN], out[MAXN];
std::set<pi> S;
int n;
void chk(int x, int y) {
	if (x > y) std::swap(x, y); if (x == y) return ;
	if (out[x].count(y)) S.emplace(x, y);
}
void chk2(int x, int y) {
	if (x > y) std::swap(x, y); if (x == y) return ;
	if (qry[x].count(y)) S.emplace(x, y);
}
void del(int x, int y) {
	if (x > y) std::swap(x, y); if (x == y) return ;
	S.erase(pi(x, y));
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, out[t1].insert(t2), out[t2].insert(t1);
	for (int i = 1, t1, t2; i < n; ++i) {
		std::cin >> t1 >> t2;
		qry[t1].insert(t2), qry[t2].insert(t1);
		chk(t1, t2);
	}
	int cnt = 0;
	while (!S.empty()) {
		pi t = *S.begin(); S.erase(S.begin()); ++cnt;
		int x = t.first, y = t.second;
		if (out[x].size() + qry[x].size() > out[y].size() + qry[y].size())
			std::swap(x, y);
		for (auto u : out[x]) {
			out[u].erase(x), del(u, x);
			if (u != y) out[u].insert(y), out[y].insert(u);
		}
		for (auto u : qry[x]) {
			qry[u].erase(x), del(u, x);
			if (u != y) qry[u].insert(y), qry[y].insert(u);
		}
		for (auto u : out[x]) chk2(u, y);
		for (auto u : qry[x]) chk(u, y);
		out[x].clear(), qry[x].clear();
	}
	std::cout << (cnt == n - 1 ? "YES" : "NO") << std::endl;
	return 0;
}


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

using namespace std;

using ll = long long;

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

    ll ans = 0;

    for(ll j = 1; j <= N; j++){
        ll Y = N/j;
        ans += (1 + Y)*Y*j/2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>

using namespace std;

int main(){
  int N , L,t = 0,r = -2000,m;

  cin >> N >> L;
  
  for(int i = 1;i <= N; ++i){
    m = L + i - 1;
    t += m;
    if(abs(m) < abs(r))
      r = m;
  }

  cout << t - r << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
 
 
#define HEIGHT_MAX 1000
#define N_MAX 100
 
 
int main(int argc, char **argv)
{
    char inputline[14];
    int n, m, line_a;
    int height, line_p, line_q;
    int i, j;
    int roof;
    int map[N_MAX][HEIGHT_MAX];
     
     
    while( 1 ){
    roof = 0;
    for( i = 0; i < 100; i++){
        for( j = 0; j < 1000; j++)
            map[i][j] = i;
    }
     
    fgets( inputline, sizeof( inputline ), stdin );
    sscanf( inputline, "%d%d%d", &n, &m, &line_a );
    if( n == 0 && m == 0 && line_a == 0 )
        break;
    if( n > N_MAX || n < 2 ||
        m > HEIGHT_MAX || m < 0 ||
        1 > line_a || line_a > n ){
            return -1;
    }
    line_a--;
     
    for(i = 0; i < m; i++){
        fgets( inputline, sizeof( inputline ), stdin );
        sscanf( inputline, "%d%d%d", &height, &line_p, &line_q );
        if( height < 1 || height > 1000 ||
            line_p < 1 || line_p >= line_q || line_q > n ){
                return -1;
            }
        line_p--;
        line_q--;
        height--;
        if( map[line_p][height] != line_p || map[line_q][height] != line_q )
            return 1;
        else{
            map[line_p][height] = line_q;
            map[line_q][height] = line_p;
        }
        if (roof < height)
            roof = height;
    }
     
    for(i = roof; i >= 0; i-- )
        line_a = map[line_a][i];
     
     
    line_a++;
    printf("%d\n", line_a);
     
    }
     
    return 0;
     
}

Measured memory_bytes: 2064
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main()

{
    IOS;
    //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);
     int n;
     cin>>n;
     set<string>st;
     rep(i,n) {string s;
        cin>>s;
        st.insert(s);
     }
     cout<<st.size()<<endl;

     return 0;

}
///Alhamdulillah


Measured memory_bytes: 19256
import scala.collection.mutable
object Main extends App {

  val line = scala.io.StdIn.readLine()
  val count = mutable.Map[Char, Int]()
  line.foreach{c =>
    val now = count.getOrElse(c, 0)
    count.put(c , now + 1) }

  val isBeautiful = count.values.forall(_ % 2 == 0)

  println(if (isBeautiful) "Yes" else "No")
}

Measured memory_bytes: 21436
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    D = defaultdict(lambda: 0)

    for a in A:
        D[a] += 1

    r = 0
    for k,v in D.items():
        if k < v:
            r += v - k
        elif k > v:
            r += v

    print(r)

main()


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

using namespace std;
#define BUF (100005)
#define ll long long 

int n;
char s[BUF][11];
ll c[258];

int main(void){
	cin >> n;

	for(int i=0;i<n;i++){
		char tmp[14];
		cin >> tmp;
		c[tmp[0]]++;
	}

	ll ans = 0;

	ans+= c['M']*c['A']*c['R'];
	ans+= c['M']*c['A']*c['C'];
	ans+= c['M']*c['A']*c['H'];
	ans+= c['M']*c['R']*c['C'];
	ans+= c['M']*c['R']*c['H'];
	ans+= c['M']*c['C']*c['H'];
	ans+= c['A']*c['R']*c['C'];
	ans+= c['A']*c['R']*c['H'];
	ans+= c['A']*c['C']*c['H'];
	ans+= c['R']*c['C']*c['H'];

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int count=0;
  int ans=0;
  vector<int> x(5);
  vector<int> y(5);
  for(int i=0;i<5;i++){
    cin>>x.at(i);
    if(x.at(i)%10==0){y.at(i)=10;}
    else{y.at(i)=x.at(i)%10; count++;}
  }
  for(int i=0;i<5;i++){
    int y;
    y=x.at(i)/10;
    ans+=y*10;
  }
  sort(y.begin(),y.end());
  if(y.at(0)!=10)ans+=y.at(0);
  if(count>0)ans+=(count-1)*10;
  
  cout<<ans<<endl;
  
  
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;
#define coutt(t)         cout << #t << ":" <<  " (" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

class Compare
{
public:
    bool operator()(tup t1, tup t2) {
        lli a1,b1,c1;
        tie(a1,b1,c1) = t1;
        lli a2,b2,c2;
        tie(a2,b2,c2) = t2;

        return c1 < c2;
    }
};


int main() {
    lli n,m;
    cin2(n,m);
    tup t[m];
    REP(i,0,m) {
        lli pi, yi;
        cin >> pi >> yi;
        t[i] = tup(pi,yi,i);
    }
    sort(t, t+m);
    lli cur_pref = get<0>(t[0]);
    lli cur_id = 1;
    REP(i,0,m) {
        lli pref = get<0>(t[i]);
       if (cur_pref != pref) {
            cur_pref = pref;
            cur_id = 1;
        }
        get<1>(t[i]) = cur_id;
        cur_id++;
    }
    sort(t, t+m, Compare());
    REP(i,0,m) {
        lli a,b,c;
        tie(a,b,c) = t[i];
        string a_str = to_string(a);
        string b_str = to_string(b);
        string a_pre = string(6-a_str.length(), '0');
        string b_pre = string(6-b_str.length(), '0');
        cout << a_pre + a_str + b_pre + b_str << endl;


    }

}


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

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


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

int cross(int x1,int y1,int x2,int y2){return x1*y2-x2*y1;}
int dot(int x1,int y1,int x2,int y2){return x1*x2+y1*y2;}
int32_t main()
{
   //ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
   int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
   int q; scanf("%d",&q);
   while(q--)
   {
   	  int x,y; scanf("%d%d",&x,&y);
   	  int p=cross(x-x1,y-y1,x2-x1,y2-y1);
   	  if(p<0) puts("COUNTER_CLOCKWISE");
   	  else if(p>0) puts("CLOCKWISE");
   	  else
   	  {
   	  	
   	  	 if(dot(x-x1,y-y1,x2-x1,y2-y1)<0) puts("ONLINE_BACK");
   	  	 else if(dot(x1-x2,y1-y2,x-x2,y-y2)<0) puts("ONLINE_FRONT");
   	  	 else  puts("ON_SEGMENT");  
   	  }
   }
return 0;
}
/*

*/


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <set>

using namespace std;

void divs(set<long long>& S, long long t){
    if(t > 1) S.insert(t);
    for(long long d=2;d*d<=t;d++){
        if(t%d != 0) continue;
        S.insert(d);
        S.insert(t/d);
    }
}

long long test(long long N, long long K){
    while(N%K == 0) N /= K;
    return N%K;
}

int main(){
    long long N;
    while(cin >> N){
        set<long long> S;
        divs(S, N);
        divs(S, N-1);
        int res = 0;
        for(auto& t : S) if(test(N, t) == 1) ++res;
        cout << res << endl;
    }
}

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


using namespace std;
#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 repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T> constexpr void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n, q;
ll k;
int num[100005];
void solve() {
    cin >> n >> k >> q;

    rep(i, q) {
        int a;
        cin >> a;
        --a;

        ++num[a];
    }

    rep(i, n)
        if (q - num[i] < k) cout << "Yes" << endn;
        else cout << "No" << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    solve();

    cout << flush;

    return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M, X[int(1e5 + 5)];
int Count[int(1e5 + 5)], Same[int(1e5 + 5)];

int main(){
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> X[i];
  sort(X, X + N);

  int cnt = 1;
  for (int i = 0; i < N; i++){
    if (X[i] == X[i + 1]){
      cnt++;
      continue;
    }
    Count[X[i] % M] += cnt;
    Same[X[i] % M] += cnt / 2;
    cnt = 1;
  }

  int ans = Count[0] / 2;
  if (M % 2 == 0) ans += Count[M / 2] / 2;

  for (int i = 1; i < (M + 1) / 2; i++){
    int now = min(Count[i], Count[M - i]);
    Count[i] -= now; Count[M - i] -= now;
    now += min(Same[i], Count[i] / 2);
    now += min(Same[M - i], Count[M - i] / 2);
    ans += now;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=2005;
ll A,B,C[M][M],S[M][M+1],dp[2*M][M];

int main(){
	cin>>A>>B;
	C[0][0]=S[0][1]=dp[0][0]=1;
	for(int i=1;i<M;i++) for(int j=0;j<=i;j++) C[i][j]=(C[i-1][j]+(j?C[i-1][j-1]:0))%mod;
	for(int i=1;i<M;i++) for(int j=1;j<=i+1;j++) S[i][j]=(C[i][j-1]+S[i][j-1])%mod;
	for(int i=1;i<2*M;i++) for(int j=0;j<=min(M,i);j++){
		if(j) dp[i][j]=(dp[i-1][j]+S[j-1][j]-S[j-1][max(0,min(j,2*j-i-1))]+mod)%mod;
		else dp[i][j]++;
	}
	ll res=0;
	for(int i=0;i<=A;i++) for(int j=max(1ll,B-A+i);j<=B;j++) (res+=C[B-1][j-1]*dp[A-i][B-j])%=mod;
	cout<<res<<endl;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

vii dp;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(30);

    int n,weight; cin >> n >> weight;
    vi w(n), v(n); rep(i,n) cin >> w[i] >> v[i];
    dp.resize(n+1, vi(100001, inf));
    dp[0][0] = 0;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= 1000*n; ++j) {
            if(j-v[i] >= 0) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }

    int ans;
    for(int i = 1000*n; i >= 0; --i) {
        if(dp[n][i] <= weight) {
            ans = i;
            break;
        }
    }
    cout << ans << '\n';

// 復元
    // int i = n-1;
    // int j = ans;
    // while(i>=0 && j>=0) {
    //     if(j-v[i] >= 0 && dp[i+1][j] == dp[i][j-v[i]] + w[i]) {
    //         cout << i+1 << '\n';
    //         j = j-v[i];
    //         --i;
    //     }
    //     else {
    //         --i;
    //     }
    // }
}

Measured memory_bytes: 40192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int data[n];
  for(int i=0;i<n;i++){
    cin >> data[i];
    if(i != n-1) cout << data[i] << " ";
    else cout << data[i] << endl;
  }

  for(int i=1;i<n;i++){
    int v = data[i];
    int j=i-1;
    while(j >= 0 && data[j] > v){
      data[j+1]=data[j];
      j--;

    }
    data[j+1] = v;
    for(int i=0;i<n;i++){
      if(i != n-1) cout << data[i] << " ";
      else cout << data[i] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3028
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	sort(ALL(v), greater<>());
	if (n % 2 == 1) {
		ll ans1 = 0;
		rep(i,n/2) ans1 += 2 * v[i];
		rep(i,2) ans1 -= v[n/2 + i];
		for (int i = n/2 + 2; i < n; i++) ans1 -= 2 * v[i];

		ll ans2 = 0;
		sort(ALL(v));
		rep(i,n/2) ans2 -= 2 * v[i];
		rep(i,2) ans2 += v[n/2 + i];
		for (int i = n/2 + 2; i < n; i++) ans2 += 2 * v[i];

		cout << max(ans1, ans2) << endl;
	} else {
		ll ans = 0;
		rep(i,n/2-1) ans += 2 * v[i]; 
		ans += v[n/2-1];
		ans -= v[n/2];
		for (int i = n/2+1; i < n; i++) ans -= 2 * v[i];
		cout << ans << endl;
		
	}
}

Measured memory_bytes: 4016
import copy
h,w,k = map(int,input().split())
grid = [list(input()) for i in range(h)]
# print(grid)
ans = 0
for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        t = copy.deepcopy(grid)
        a = i
        b = j
        while a:
            if a&1:
                for l in range(w):
                    t[cnt][l] = "."
            a = a >> 1
            cnt += 1
        cnt = 0
        while b:
            
            if b&1:
                # print(h,cnt,b,t)
                for l in range(h):
                    t[l][cnt] = "."
            b = b >> 1
            cnt += 1
        cnt = 0
        for l in t:
            cnt += l.count("#")
        if cnt == k:
            ans += 1
            # print(t)
        # if i == 0 and j == 3:
        #     print(t)
print(ans)
                

Measured memory_bytes: 9348
# include<bits/stdc++.h>
using namespace std;
int main(){
	string weather[4] = {"Sunny", "Cloudy", "Rainy", "Sunny"};
  	string inp;
  	cin >> inp;
  	for(int i = 0; i < 3; i++){
    	if(inp == weather[i])
          cout << weather[i+1]<<'\n';
    }
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
S = ins()


def flip(x):
    if x == "S":
        return "W"
    else:
        return "S"


def solve():
    for p in ["SS", "SW", "WS", "WW"]:
        buf = list(p)
        for i in range(1, N):
            if (buf[i] == "S" and S[i] == "o") or (buf[i] == "W" and S[i] == "x"):
                buf.append(buf[i - 1])
            else:
                buf.append(flip(buf[i - 1]))
        assert len(buf) == N + 1
        if buf[0] != buf[-1]:
            continue
        buf.pop()
        if buf[1] == buf[-1]:
            if (buf[0] == "S" and S[0] == "x") or (buf[0] == "W" and S[0] == "o"):
                continue
        else:
            if (buf[0] == "S" and S[0] == "o") or (buf[0] == "W" and S[0] == "x"):
                continue
        return "".join(buf)
    return -1


print(solve())


Measured memory_bytes: 10192
#include<iostream>
#include<vector>
using ll =long long;
using namespace std;
//10^9=10億 intの限界寸前
int main(){
	//どこか地点を一か所決めて直進するのが最善
	int k,n;
	vector<ll> a,d;
	cin >> k >> n;
	ll abuf;
	while(cin >> abuf) a.push_back(abuf);
	ll max=k-a[a.size()-1];
	if(max<0) max*=-1;
	max+=a[0];
	ll sum=max;
	for(int i=0;i<a.size()-1;i++)
	{
		if(a[i+1]-a[i]>max) max=a[i+1]-a[i];
		sum +=a[i+1]-a[i];
	}
	cout << sum-max;
	return 0;
}

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

#define ll long long

int sum(string s){
    int n = s.size();
    int ans = 0l;
    for(int i=0;i<n;i++) ans += (int)(s[i]-'0');
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s; cin >> s;
    int n = s.size();
    int sm = sum(s);
    while(sm > 9){
        s = to_string(sm);
        sm = sum(s);
    }
    if(sm%9==0) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Vec v(n);
    Vec r;
    Vec l;
    Vec s(n);
    ll tmpl,tmpr;
    rep(i,n){
        cin>>v[i];
        if(i==0){
            l.pb(v[i]);
            tmpl = v[i];
        }else{
            tmpl = __gcd(v[i],tmpl);
            l.pb(tmpl);
        }
    }
    reverse(ALL(v));
    rep(i,n){
        if(i==0){
            r.pb(v[i]);
            tmpr = v[i];
        }else{
            tmpr = __gcd(v[i],tmpr);
            r.pb(tmpr);
        }
    }

    rep(i,n){
        if(i==0){
            s[i]=r[n-2];
        }else if(i==n-1){
            s[i]=l[n-2];
        }else{
            s[i]=__gcd(l[i-1],r[n-2-i]);
        }
    }
    sort(ALL(s),greater<ll>());
    cout<<s[0]<<endl;
    return  0;
}


Measured memory_bytes: 4212
from collections import Counter
import copy
from itertools import combinations


def A(s):
  if s == 'RRR':
    return 3
  elif s == 'RRS':
    return 2
  elif s == 'RSR':
    return 1
  elif s == 'SRR':
    return 2
  elif s == 'RSS':
    return 1
  elif s == 'SRS':
    return 1
  elif s == 'SSR':
    return 1
  elif s == 'SSS':
    return 0
  l = 0
  max_l = 0
  for i in range(len(s)):
    if i == 0 and s[i] == 'R':
      l += 1
    elif s[i - 1] == s[i] and s[i] == 'R':
      l += 1
    else:
      l = 0
    if l > max_l:
      max_l = l
  return max_l


def B(N, Ls):

  def _can_tri(a, b, c):
    if a == b or a == c or b == c:
      return False
    tmp_a, tmp_b, tmp_c = sorted([a, b, c])
    if tmp_a + tmp_b > tmp_c:
      return True
    return False

  ans = 0
  for i in range(N):
    for j in range(i + 1, N):
      for k in range(j + 1, N):
        if _can_tri(Ls[i], Ls[j], Ls[k]):
          # print(i + 1, j + 1, k + 1)
          ans += 1
  return ans


def C():
  pass


def main():
  # s = input()
  # print(A(s))
  N = int(input())
  Ls = [int(x) for x in input().split(' ')]
  print(B(N, Ls))


if __name__ == '__main__':
  main()


Measured memory_bytes: 9620