akhauriyash/Code-Regression huggingface dataset:
import sys
import collections

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result



def main():
    N, A, B = [int(_) for _ in sys.stdin.readline().split()]
    V = sorted([int(_) for _ in sys.stdin.readline().split()], reverse=True)
    D = collections.defaultdict(lambda: 0)
    ans = 0

    for v in V:
        D[v] += 1

    for C in range(A, B+1):
        if (sum(V[:C]) / C) == (sum(V[:A]) / A):
            ans += comb(D[V[C-1]], V[:C].count(V[C-1]))

    print((sum(V[:A]) / A))
    print(ans)

main()


Measured memory_bytes: 3316
#import numpy as np
import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    A = first_input[0]
    B = first_input[1]
    C = first_input[2]
    D = first_input[3]

    while True:
        C = C-B
        if C<=0:
            print("Yes")
            break
        A = A-D
        if A<=0:
            print("No")
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 62056
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  a %= 2;
  b %= 2;
  c %= 2;
  if (a + b + c >= 2) {
    puts("Hom");
  } else {
    puts("Tem");
  }
  return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i+2 < n; ++i) {
        if(s.substr(i, 3) == "ABC"){
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

//TYPEDEF
typedef long long lld;
typedef unsigned long long u64;
typedef pair<int, int> pii;

//COMPARE
template<class T> inline T MIN(const T x, const T y) {
    return (x<y)?x:y;
}
template<class T> inline T MAX(const T x, const T y) {
    return (x>y)?x:y;
}

template<class T> inline void UPDMIN(T &x, const T y) {
    if(x>y)x=y;
}
template<class T> inline void UPDMAX(T &x, const T y) {
    if(x<y)x=y;
}

int main() {
    int n;
    while(scanf("%d", &n)!=EOF) {
        pair<int, int> foo(-1, -1);
        for(int i=0; i<n; i++) {
            int rnk, scr;
            scanf("%d%d", &rnk, &scr);
            UPDMAX(foo, make_pair(rnk, scr));
        }
        printf("%d\n", foo.first+foo.second);
    }
}

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))
cnt_list = [0 for i in range(N)]
sum_res = 0

for i in range(N):
  cnt_list[A_list[i] - 1] += 1

for i in range(N):
  sum_res += cnt_list[i] * (cnt_list[i] - 1) // 2

for i in range(N):
  print_res = sum_res
  if cnt_list[A_list[i] - 1] >= 2:
    print_res = sum_res - cnt_list[A_list[i] - 1] * (cnt_list[A_list[i] - 1] - 1) // 2 + (cnt_list[A_list[i] - 1] - 1) * (cnt_list[A_list[i] - 1] - 2) // 2
  
  print(print_res)
    

Measured memory_bytes: 26140
#include <iostream>
#include<string>
using namespace std;
int main() {
string a,b,c;
    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }


}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S;
int A[500000];

signed main(){
    cin >> S;
    memset(A, -1, sizeof(A));

    if(S[0] == '<') A[0] = 0;
    if(S.back() == '>') A[S.size()] = 0;
    rep(i, S.size()-1){
        if(S[i] == '>' && S[i+1] == '<'){
            A[i+1] = 0;
        }
    }
    
    rep(i, S.size()-1){
        if(S[i] == '<' && S[i+1] == '<' && A[i] != -1){
            A[i+1] = A[i]+1;
        }
    }
    if(S.back() == '<') A[S.size()] = A[S.size()-1] + 1;
    
    for(int i=S.size()-1; i>0; i--){
        if(S[i-1] == '>' && S[i] == '>' && A[i+1] != -1){
            A[i] = A[i+1]+1;
        }
    }
    if(S[0] == '>') A[0] = A[1] + 1;

    rep(i, S.size()-1){
        if(S[i] == '<' && S[i+1] == '>'){
            A[i+1] = max(A[i], A[i+2]) + 1;
        }
    }

    //rep(i, S.size()+1) cout << A[i] << endl;

    ll ans = 0;
    rep(i, S.size()+1) ans += A[i];
    cout << ans << endl;
}

Measured memory_bytes: 5804
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int r;cin>>r;
    cout<<3*r*r<<endl;
}

Measured memory_bytes: 256
S = input().split( ) 
a=int(S[0]) 
b=int(S[1])
c=int(S[2])
k=int(S[3])
t=2*a+b-k
if k <= a:
  print(str(k))
elif a < k <= a + b:
  print(str(a))
else: print(str(t))



Measured memory_bytes: 9084
#include <iostream>
#define ll long long int

using namespace std;

int main(int argc, char const* argv[])
{
	ll x, y;
	cin >> x >> y;
	int res = 0;
	while(x <= y){
			x *= 2;
			res++;
	}
	cout << res <<endl;
	return 0;
}


Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
 
def inps() a=gets.chomp.split(" ")end
 
def copy(a) Marshal.load(Marshal.dump(a)) end
 
def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end
 
def na(n,d=0) Array.new(n,d)end
 
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
 
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
 
def inp() a=gets.chomp.split(" ").map(&:to_i)end
 
def r_up(a, b) (a+b-1)/b end
 
n = inp[0]
a = inp
t = []
n.times do |i|
  t[i] = [a[i],i+1]
end
t.sort!
ans = []
t.each do |a|
  ans.push(a[1])
end
puts ans.join(" ")

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

const ll INF = 1e18L + 5;

int main(){
    int n, w;
    cin >> n >> w;
    vector<int> ws(n), vs(n);
    rep(i,n) cin >> ws[i] >> vs[i];

    int sum_value = accumulate(vs.begin(),vs.end(),0);
    vector<ll> dp(sum_value + 1, INF);
    dp[0] = 0;
    rep(i,n){
        for(int value_already = sum_value - vs[i]; value_already >= 0; --value_already){
            dp[value_already + vs[i]] = min(dp[value_already + vs[i]],
                                            dp[value_already] + ws[i]);
        }
    }
    ll answer = 0;
    rep(i, sum_value + 1){
        if(dp[i] <= w){
            answer = max(answer, (ll)i);
        }
    }
    cout << answer << endl;
}


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

using namespace std;

int D, N, Ans;
int Endurance[100], getExperience[100], needExperience[100];
int DpCount[101][101];

const int INF = 2e9;

void solve() {
	int minLife, maxExperience;

	//fill_n(*DpCount, 101 * 10001, INF);
	for (int i = 0; i < 101; ++i) {
		fill(DpCount[i], DpCount[i] + 101, INF);
	}
	DpCount[D][0] = 0;

	for (int currentLife = D; currentLife > 0; --currentLife) {
		for (int currentExperience = 0; currentExperience < 101; ++currentExperience) {
			if (DpCount[currentLife][currentExperience] == INF) {
				continue;
			}
			for (int i = 0; i < N; ++i) {
				if (currentExperience < needExperience[i]) {
					continue;
				}
				minLife = max(0, currentLife - Endurance[i]);
				maxExperience = min(100, currentExperience + getExperience[i]);
				DpCount[minLife][maxExperience] = min(DpCount[minLife][maxExperience],
					DpCount[currentLife][currentExperience] + 1);
			}
		}
	}
		
	Ans = *min_element(DpCount[0], DpCount[0] + 101);
}

int main() {

	while (cin >> D >> N, D) {
		memset(Endurance, 0, sizeof(Endurance));
		memset(getExperience, 0, sizeof(getExperience));
		memset(needExperience, 0, sizeof(needExperience));
		for (int i = 0; i < N; ++i) {
			cin >> Endurance[i] >> getExperience[i] >> needExperience[i];
		}
		solve();
		if (Ans == INF) {
			cout << "NA" << endl;
			continue;
		}
		cout << Ans << endl;
	}

	return 0;
}



Measured memory_bytes: 3132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int N = sc.nextInt();
		String s = null;
		if(N % 2 != 0) {
			System.out.println("No");
			System.exit(0);
		}else {
			s = sc.next();
		}
		int i = 0;
		for(; i < N / 2; i++) {
			sb.append(s.charAt(i));
		}
		String a = sb.toString();
		sb = new StringBuilder();

		for(; i < N; i++) {
			sb.append(s.charAt(i));
		}
		String b = sb.toString();

		if(a.equals(b)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(n)), b(m,vector<char>(m));
    rep(i, n) {
        string s; cin >> s;
        rep(j, n) a[i][j] = s[j];
    }
    rep(i, m) {
        string s; cin >> s;
        rep(j, m) b[i][j] = s[j];
    }

    rep(y, n-m+1) rep(x, n-m+1) {
        bool ok = true;
        rep(i,m) rep(j,m) {
            if(a[y+j][x+i] != b[j][i]) ok = false;
        }
        if(ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm> 
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
ll dp[N],ans=0;
ll n,k;
ll quickpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(){
	ios::sync_with_stdio(false);
	cin.tie(0);
}
int main()
{
	init();
	cin>>n>>k;
	for(ll i=k;i>=1;i--)
	{
		dp[i]=quickpow(k/i,n);
		for(ll j=i*2;j<=k;j+=i)
		dp[i]-=dp[j];
		ans=(ans+i*dp[i]%mod)%mod;
	}
	cout<<(ans+mod)%mod;
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int n,ans=0;
    string a,b,c;
    cin>>n>>a>>b>>c;
    
    for(int i = 0; i < n; i++)
    {
        if(a[i]==b[i] && b[i]==c[i])
        {

        }
        else if(a[i]==b[i] || b[i]==c[i]||c[i]==a[i])
        {
            ans++;
        }
        else 
        {
            ans+=2;
        }
    }
    

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := nextInt()

	childs := make([][]int, n)

	all := n + m - 1
	for i := 0; i < all; i++ {
		a := nextInt() - 1
		b := nextInt() - 1
		childs[b] = append(childs[b], a)
	}

	depth := make([]int, n)
	for i := 0; i < n; i++ {
		depth[i] = -1
	}
	parents := make([]int, n)

	for i := 0; i < n; i++ {
		ps := len(childs[i])
		if ps == 0 {
			// root
			parents[i] = -1
		} else if ps == 1 {
			parents[i] = childs[i][0]
		} else {
			maxdepth := -1
			maxid := -1
			for _, a := range childs[i] {
				depth := findDepth(depth, childs, a)
				if depth > maxdepth {
					maxdepth = depth
					maxid = a
				}
			}
			parents[i] = maxid
		}
	}

	//fmt.Println(childs)
	//fmt.Println(parents)
	//fmt.Println(depth)
	for _, p := range parents {
		fmt.Println(p + 1)
	}
}

func findDepth(depth []int, childs [][]int, i int) int {
	if depth[i] != -1 {
		return depth[i]
	}
	maxdepth := -1
	for _, a := range childs[i] {
		depth := findDepth(depth, childs, a)
		if depth > maxdepth {
			maxdepth = depth
		}
	}
	maxdepth++
	depth[i] = maxdepth
	return maxdepth
}


Measured memory_bytes: 38272
x, y = map(int, input().split())
listi = [x, y]
list1 = [1, 3, 5, 7, 8, 10, 12]
list2 = [4, 6, 9, 11]
list3 = [2]

for i in listi:
    list1.append(i)
    list2.append(i)
    list3.append(i)

if len(set(list1)) == len(list1)-2 or len(set(list2)) == len(list2)-2 or len(set(list3)) == len(list3)-2:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef pair<int,int> pii;
typedef set<int>::iterator it;
int n,fa[N],cnt;
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
set<int> *S[N],*T[N];
queue<pii> Q;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		fa[i]=i;
		S[i]=new set<int>();
		T[i]=new set<int>();
	}
	for (int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		S[u]->insert(v);
		S[v]->insert(u);
	}
	for (int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		if (S[u]->count(v)){
			Q.push(pii(u,v));
			S[u]->erase(v);
			S[v]->erase(u);
		}
		else{
			T[u]->insert(v);
			T[v]->insert(u);
		}
	}
	while (!Q.empty()){
		int u=Q.front().first,v=Q.front().second;Q.pop();
		u=find(u);v=find(v);
		//printf("merge(%d,%d)\n",u,v);
		cnt++;
		if (S[u]->size()+T[u]->size()<S[v]->size()+T[v]->size()) swap(u,v);
		fa[v]=u;
		for (it i=S[v]->begin();i!=S[v]->end();++i){
			int x=*i;
			S[x]->erase(v);
			if (T[u]->count(x)){
				Q.push(pii(u,x));
				T[u]->erase(x);
				T[x]->erase(u);
			}
			else{
				S[x]->insert(u);
				S[u]->insert(x);
			}
		}
		S[v]->clear();
		for (it i=T[v]->begin();i!=T[v]->end();++i){
			int x=*i;
			T[x]->erase(v);
			if (S[u]->count(x)){
				Q.push(pii(u,x));
				S[u]->erase(x);
				S[x]->erase(u);
			}
			else{
				T[u]->insert(x);
				T[x]->insert(u);
			}
		}
		T[v]->clear();
	}
	puts(cnt==n-1?"YES":"NO");
	return 0;
}

Measured memory_bytes: 35456
ans=1000000000
d,g=map(int,input().split())
p=[];c=[]
for i in range(d):
    P,C=map(int,input().split())
    p.append(P);c.append(C)
def search(i,sm,cnt,mx):
    global ans,d,g,p,c
    if(i==d):
        if(sm<g):
            for i in range(p[mx]-1):
                sm+=100*(mx+1)
                cnt+=1
                if(sm>=g):
                    ans=min(ans,cnt)
                    break
        else:
            ans=min(ans,cnt)
        return;
    search(i+1,sm,cnt,i)
    search(i+1,sm+(i+1)*100*p[i]+c[i],cnt+p[i],mx)

search(0,0,0,0)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
ll maxx=0;
struct node{
	int a,b,c,num;
}u[55];
int n,m,q,v[11];
void dfs(int minn,int i){
	rep(j,minn,m){
		v[i]=j;
		if(i<n)dfs(j,i+1);
		else {
			ll cou=0;
			rep(k,1,q){
				if(v[u[k].b]-v[u[k].a]==u[k].c)cou+=u[k].num;
			}maxx=max(cou,maxx);
		}
	}
}
int main()
{
	sc(n);sc(m);sc(q);
	rep(i,1,q){
		sc(u[i].a);sc(u[i].b);sc(u[i].c);sc(u[i].num);
	}v[1]=1;
	dfs(1,2);
	pf("%lld\n",maxx);
}


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

typedef pair<int,pair<int,int> > trp;

trp dp[3005][3005];

int main()
{
    string s,t;
    string a="0",b="0";

    cin>>s>>t;
    a+=s;
    b+=t;


    int len1=s.length();
    int len2=t.length();

    for(int i=1;i<=len1;i++){
        for(int j=1;j<=len2;j++){
            if(dp[i][j].first<dp[i-1][j].first){
                dp[i][j]=dp[i-1][j];
            }
            if(dp[i][j].first<dp[i][j-1].first){
                dp[i][j]=dp[i][j-1];
            }
            if(a[i]==b[j]){
                if(dp[i][j].first<dp[i-1][j-1].first+1){
                    dp[i][j].first = max(dp[i][j].first,dp[i-1][j-1].first+1 );
                    dp[i][j].second.first = i;
                    dp[i][j].second.second = j;
                }
            }
        }
    }

    vector <int> v1;
    int now = dp[len1][len2].first;
    int last = len2 +1 ;

    for(int i=len1; i && now ; i--){
        for(int j=1;j<last;j++){
            if(dp[i][j].first == now){
                now--;
                v1.push_back(dp[i][j].second.first);
                last = dp[i][j].second.second;
                i = dp[i][j].second.first;
                //cout<<last<<" ";
                break;
            }
        }
    }


    for(int i=v1.size()-1;i>=0;i--){
        cout<<a[v1[i]];
    }

    return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	unordered_set<int> st;
	forn(i,n){
		int x;
		cin>>x;
		if(st.count(x)){
			cout<<"NO";
			return 0;
		}
		st.insert(x);
	}
	cout<<"YES";
    return 0;
}



Measured memory_bytes: 8520
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{
    char s[101];
    scanf("%s", s);
    int in = strlen(s) - 2;
    printf("%c%d%c\n", s[0], in, s[strlen(s)-1]);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
/************ Combination wtih MOD ************
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// preprocess for some tables
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; 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;
  }
}
// combination
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*******************************************************/
/********** UnionFind ***************
struct UnionFInd {
vector<ll> par;
UnionFInd(ll N) : par(N) {
for (ll i = 0; i < N; i++) {
par[i] = i;
}
}
ll root(ll x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
if (rx == ry) return;
par[rx] = par[ry];
}
bool same(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
*************************************/
/***********************************
ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }

  ll r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
***********************************/
int main(int argc, char *argv[]) {
  // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  ll k;
  cin >> k;

  unordered_set<ll> s;
  ll remain = 7 % k;
  ll ans = 1;
  s.insert(remain);
  while (true) {
    if (remain == 0) {
      break;
    }
    remain = (remain * 10 + 7) % k;
    if (s.find(remain) != s.end()) {
      ans = -1;
      break;
    }
    s.insert(remain);
    ans += 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 42652
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

bool dfs(const std::vector<int> &balls, std::vector<int> l, std::vector<int> r, int i){
	if(i == balls.size()){
		return true;
	}
	if(!l.empty() && l.back() > balls[i] && !r.empty() && r.back() > balls[i]){
		return false;
	}
	bool is_success = false;

	if(l.empty() || l.back() < balls[i]){
		l.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ 
		return true;
	}
	else if(r.empty() || r.back() < balls[i]){
		r.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ return true; }


	return false;
}

int main(int argc, char **argv){
	int n;
	std::vector<int> balls(10);

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
#if INPUT_FROM_FILE
			ifs >> balls[j];
#else
			std::cin >> balls[j];
#endif
		}

		std::vector<int> l, r;
		if(dfs(balls, l, r, 0)){
			std::cout << "YES" << std::endl;
		}
		else{
			std::cout << "NO" << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  priority_queue< l64 > q;
  for (int i = 0; i < n; ++i) {
    l64 a;
    cin >> a;
    q.push(a);
  }
  l64 prev = -1;
  l64 h = 0, w = 0;
  while (!q.empty()) {
    l64 t = q.top();
    q.pop();
    if (prev==t) {
      if (h==0) {h=t;}
      else {w=t; break;}
      prev = -1;
    } else {
      prev = t;
    }
  }
  cout << h * w << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
	double a,b,c,d;
	cin>>a>>b>>c>>d;
	double sz=30*c+(d/60*30);
	double fz=d/60*360;
	double x=abs(sz-fz)/180*3.1415926535;
	cout<<fixed<<setprecision(9)<<sqrt(a*a+b*b-2*a*b*cos(x));
	
}

Measured memory_bytes: 3592
import java.util.*;
import java.io.*;

class Main {

	static Node[] node = null;

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		node = new Node[n];

		for (int i=0; i<n; i++) {
			node[i] = new Node();
		}

		for (int i=0; i<n; i++) {
			String line = br.readLine();
			String[] str = line.split(" ");
			int id = Integer.parseInt(str[0]);
			int k = Integer.parseInt(str[1]);
			node[id].child = new int[k];
			for (int j=0; j<k; j++) {
				int c = node[id].child[j] = Integer.parseInt(str[j+2]);
				node[c].parent = id;
			}
		}

		for (int i=0; i<n; i++) {
			if (node[i].parent == -1) {
				set(node[i],0);
				break;
			}
		}

		for (int i=0; i<n; i++) {
			StringBuilder sb = new StringBuilder();
			sb.append("node ").append(i).append(": parent = ").append(node[i].parent);
			sb.append(", depth = ").append(node[i].depth).append(", ").append(node[i].type).append(", [");
			for (int j=0; j<node[i].child.length; j++) {
				sb.append(node[i].child[j]);
				if (j < node[i].child.length - 1)
					sb.append(", ");
			}
			sb.append("]");
			System.out.println(sb);
		}

		br.close();
	}

	static void set(Node nd,int depth){
		nd.depth = depth;

		if (nd.child.length == 0 && nd.parent != -1) {
			nd.type = "leaf";
			return;
		}else if(depth != 0) {
			nd.type = "internal node";
		}

		for (int i=0; i<nd.child.length; i++) {
			set(node[nd.child[i]],depth+1);
		}
	}

	static class Node{
		int parent = -1;
		int depth = 0;
		String type = "root";
		int[] child = null;
	}
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l.at(i);
  
  sort(l.begin(), l.end());
  
  ll ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      int left = j, right = n, keep = l[i] + l[j];
      while (right - left > 1) {
        int mid = (left + right) / 2;
        if (keep > l[mid]) left = mid;
        else right = mid;
      }
      ans += left - j;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
#define boost ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

int main(){
	boost;
	int n;
	cin>>n;
	bool flag=false;
	for(int i=1;i<=9;i++){
		if(n%i==0 && (n/i)<=9){
			flag=true;
		}
	}

	if(flag){
		cout<<"Yes"<<'\n';
	}else{
		cout<<"No"<<'\n';
	}
	return 0;
}

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

int main() {
	int N, M, P;
	while (cin >> N >> M >> P) {
		if (N == 0 && M == 0 && P == 0) return 0;
		int A, B = 0;
		for (int i = 1; i <= N; i++) {
			int X;
			cin >> X;
			if (i == M) A = X;
			B += X;
		}
		if (A == 0) cout << 0 << endl;
		else cout << B * (100 - P) / A << endl;
	}
}


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

int main() {

	string S;
  	int i=0;
  	int FLUG=0;
  int num;
S="oooooooooo";
    cin >> S;

  num=S.size();
  if(num%2==0){
    
  
  for(i=0;i<num-1;i=i+2){
    if(S.at(i)=='h'&&S.at(i+1)=='i'){
    FLUG++;
    }else{
      FLUG=0;
      i=num;
    }
   // cout<<S.at(i)<<endl;
   // cout<<S.at(i+1)<<endl;
    
  }
    
  }
  /*
  for(i=0;i<num-1;i++){
  if(S.at(i)=='h'){
  	if(S.at(i+1)=='i'){
      FLUG++;
      i=i+1;
    }else{
      FLUG=0;
    }
  }else{
    FLUG=0;
  }
  }
  */
    if(FLUG>=1){
    cout << "Yes" <<endl;
    }else{
      cout << "No" <<endl;
    }
    
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,tmp;

  while(1){
    scanf("%d %d",&a,&b);
    if((a==0)&&(b==0)) break;
    if(a>b){
      tmp=a;
      a=b;
      b=tmp;
    }
    printf("%d %d\n",a,b);
  }

  return 0;
}

Measured memory_bytes: 600
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        w: i64,
        a: i64,
        b: i64,
    }
    if a + w < b {
        println!("{}", b - a - w);
    } else if b + w < a {
        println!("{}", a - b - w);
    } else {
        println!("0");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){

    int N,K,x,ans=0;
    cin>>N>>K;

    for(int i=1;i<=N;i++){
        cin>>x;
        ans+=min(abs(K-x),x)*2;

    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
fn solve(a: u16, b: u16) -> String {
    (if a * b % 2 == 0 { "Even" } else { "Odd" }).to_string()
}

fn main() {
    let (a, b) = read_tup2();

    println!("{}", solve(a, b));
}

fn read_tup2<T: std::str::FromStr + Copy>() -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v = s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect::<Vec<T>>();
    (v[0], v[1])
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> multi_vector(size_t a){return vector<T>(a);}template<class T, class... Ts>auto multi_vector(size_t a, Ts... ts){return vector<decltype(multi_vector<T>(ts...))>(a, multi_vector<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N, K;
  cin >> N >> K;
  vector<ll> h(N);
  for(auto&& i : h){
    cin >> i;
  }
  sort(all(h));
  ll ans{MOD};
  rep(i, 0, N-K+1){
    ans = min(ans, h[i+K-1]-h[i]);
  }
  cout << ans << rt;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();

		int hash[] = new int[n];
		int dist[] = new int[n];
		int weight[] = new int[n];

		for (int i = 0; i < n; i++) {
			hash[i] = sc.nextInt();
			dist[i] = sc.nextInt();
			weight[i] = sc.nextInt();
		}

		double[][] dp = new double[1 << n][n];
		double[][] dpw = new double[1 << n][n];
		String[][] str = new String[1<<n][n];
		
		for (int i = 0; i < 1 << n; i++) {
			Arrays.fill(dp[i], Double.MAX_VALUE);
			Arrays.fill(dpw[i], Double.MAX_VALUE);
		}

		for (int i = 0; i < n; i++) {
			int shi = 1 << i;
			dp[shi][i] = dist[i] * 7;
			dpw[shi][i] = 7 + weight[i];
			str[shi][i] = String.valueOf(hash[i]);
		}

		for (int i = 1; i < 1 << n; i++) {
			for (int j = 0; j < n; j++) {
				int shj = 1 << j;
				if ((i & shj) == 0) {
					continue;
				}

				int dept = i & ~shj;
				for (int k = 0; k < n; k++) {
					int shk = 1<<k;
					if ((dept & shk) == 0) {
						continue;
					}
					if (dp[i][j] > dp[dept][k] + Math.abs(dist[k] - dist[j])
							* dpw[dept][k]) {
						dp[i][j] = dp[dept][k] + Math.abs(dist[k] - dist[j])
								* dpw[dept][k];
						dpw[i][j] = dpw[dept][k] + weight[j];
						str[i][j] = str[dept][k]+" "+hash[j];
					}
				}
			}
		}
		String ret ="" ;
		double min = Double.MAX_VALUE;
//		System.out.println(Arrays.deepToString(dp));
		for(int i = 0; i < n ; i++){
			if(min > dp[(1<<n) -1][i]){
				min = dp[(1<<n) -1][i];
				ret = str[(1<<n) -1][i];
			}
		}
		System.out.println(ret);
		
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 45000
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/07/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll s; cin>>s;
  ll a = (s-1)/(ll)1e9+1;
  cout << 0<<" "<<0<<" "<<(ll)1e9<<" "<<1<<" "<<((ll)1e9*a-s)<<" "<<a<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double PI=3.1415926535897932;
const double LIT=0.000000001;

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define PRO(a,b) a=(a*b)%mod

ll N; vec d;
priority_queue<P> Q;

void input(){
    cin>>N;
    rep(i,N){
        ll x; cin>>x;
        d.pb(x);
    }
    rep(i,N) Q.push(mp(d[i],i));
}


ll dp[2001][2001];

ll Solve(){
    rep(i,N){
        ll x=Q.top().first, z=Q.top().second;
        Q.pop();
        rep(j,i+1) {
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+(N-1-j-z)*x);
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(z-(i-j))*x);
        }
    }
    ll ans=0;
    rep(i,N+1) ans=max(dp[N][i],ans);
    return ans;
}

int main(){
    input();
    cout<<Solve()<<endl;
}

Measured memory_bytes: 26288
#include <bits/stdc++.h>
#define ep emplace_back
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>

typedef long long ll;

using namespace std;

int main()
{
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    if (t.substr(0,s.size())==s) {
        cout << "Yes";
    }else cout <<"No";
    return 0;
}


Measured memory_bytes: 3604
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int X = getint(), Y = getint(), A = getint(), B = getint(), C = getint();

	int abc[400000];
	auto a = abc;
	auto b = abc + A;
	auto c = abc + A + B;

	rep(i, A + B + C) a[i] = getint();

	nth_element(a, b - X, b);
	nth_element(b, c - Y, c);
	ll kotae = 0;
	if (B - Y) {
		for (auto i = b - 1; i >= b - X; i--)* (i + B - Y) = *i;
		nth_element(c - X - Y, c + C - X - Y, c + C);

		for (auto kari = c + C - X - Y; kari < c + C; kari++) kotae += *kari;
	}
	else {
		memcpy(c + C, b - X, X * sizeof(int));
		nth_element(c - Y, c + C - Y, c + C + X);

		for (auto kari = c + C - Y; kari < c + C + X; kari++) kotae += *kari;
	}
	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String content = sc.next();
        int LPCount = 0;
        int RPCount = 0;
        for (int i = 0; i < content.length(); i++) {
            if (content.charAt(i) == '(') {
                LPCount++;
            }
            else if (content.charAt(i) == ')') {
                if (LPCount > 0) {
                    LPCount--;
                }
                else {
                    RPCount++;
                }
            }
        }

        for (int i = 0; i < RPCount; i++) {
            content = "(" + content;
        }
        for (int i = 0; i < LPCount; i++) {
            content = content + ")";
        }

        System.out.println(content);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int i;
  bool n,e,w,s,ans;
  string sc;
  cin >> sc;
  n=e=w=s=false;
  for (i=0;i<sc.size();i++){
    if (sc[i]=='N') n=true;
    else if (sc[i]=='E') e=true;
    else if (sc[i]=='W') w=true;
    else s=true;
  }
  ans=(n&&s)||(!n&&!s);
  ans&=(e&&w)||(!e&&!w);
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[100009],n;
int d1(){
  int sum=0,ans=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      if(sum+a[i]>=0)ans+=abs((-1-sum-a[i])),sum=-1;
      else sum+=a[i];
    }
    else{
      if(sum+a[i]<=0)ans+=abs((1-sum-a[i])),sum=1;
      else sum+=a[i];
    }
  }
  return ans;
}
int d2(){
  int sum=0,ans=0;
  for(int i=0;i<n;i++){
    if(i%2==1){
      if(sum+a[i]>=0)ans+=abs((-1-sum-a[i])),sum=-1;
      else sum+=a[i];
    }
    else{
      if(sum+a[i]<=0)ans+=abs((1-sum-a[i])),sum=1;
      else sum+=a[i];
    }
  }
  return ans;
}
main(){
  cin>>n;
  r(i,n)cin>>a[i];
  cout<<min(d1(),d2())<<endl;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vl h(n);
  rep(i,n)cin>>h[i];
  ll dp[100001];
  dp[1]=0;
  dp[2]=abs(h[1]-h[0]);
  for(ll i=3;i<=n;i++){
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]));
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
//
//  gcd_hard.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

ll solve(int n, int k) { // find number of sequence has max divisor: 1
  ll no_of_sequence = pow(k, n);
  for (int j=2; j<=k; j++) {
    no_of_sequence -= solve(n, k/j);
  }
  return no_of_sequence;
}

ll pow_mod(ll x, ll y) {
  // return x^y % mod
  if (y == 0) return 1;
  ll a = pow_mod(x, y/2);
  a = (a * a) % mod;
  if (y & 1) a = (a * x) % mod;
  return a;
}

int main(int argc, const char* argv[]) {

  int n, k;
  std::cin >> n >> k;
  ll dp[k+1];
  // dp[1] = 1;
  // for (int i=2; i<=k; i++) {
  //   ll total_sequence = pow_mod(i, n);
  //   for (int j=2; j<=i; j++) {
  //     total_sequence -= dp[i/j];
  //   }
  //   dp[i] = total_sequence;
  // }
  ll cnt = 0;
  // for (int i=1; i<=k; i++) {
  //   int number_divisible_by_i = k / i;
  //   // std::cout << "total sequance has max divisor " << i << ": " << dp[number_divisible_by_i] << std::endl;
  //   (cnt += i*dp[number_divisible_by_i]) %= mod;
  // }

  for (int i=k; i>0; i--) {
    ll total_sequence = pow_mod(k/i, n); // devides by i
    int j = 2;
    while(i*j <= k) {
      total_sequence = (total_sequence - dp[j*i] + mod) % mod;
      j++;
    }

    dp[i] = total_sequence;
    (cnt += i*total_sequence) %= mod;
  }

  std::cout << cnt << std::endl;
  return 0;
}


Measured memory_bytes: 4464
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

s = rs()
f = True
for i in range(len(s)):
    if f and s[i] == 'A':
        a = i
        f = False
    if s[i] == 'Z':
        z = i
print(z - a + 1)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, t;
	cin >> n >> t;
	int ans = 1e9;
	rep(i, n){
		int c, tt;
		cin >> c >> tt;
		if(tt > t) continue;
		ans = min(ans, c);
	}
	if(ans == 1e9) cout << "TLE" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
     
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        Dice dice = new Dice(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        int a = stdIn.nextInt();
        for(int i = 0; i < a; i++) {
            int T = stdIn.nextInt();
            int S = stdIn.nextInt();
            Dice copy = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
             
            int ans = solv(T,S,copy,0); 
            System.out.println(ans);
        }
    }
    public static int solv(int a, int b, Dice dice,int count) {
        if(dice.Top == a && dice.S == b) return dice.E;
        if(count == 4) return -1;
        int ans = -1;
        Dice tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnN();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnS();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnE();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnW();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
         
        return ans;
    }
     
     
     
}
 
class Dice {
    int Top; //1
    int Bottom; //6
    int N; //   5
    int S; //   2
    int W; //左 4
    int E; //右 3
    Dice(int a, int b, int c, int d, int e, int f) {
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }
    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }
    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }
    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }
    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }
     
}


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

using ll = long long;

const int MAXN = 1.1e5;
int N;
int A[MAXN];

int bit[MAXN*2];
void reset() {
	for (int i = 0; i <= 2*N; i++) {
		bit[i] = 0;
	}
}
int query(int a) {
	assert(a <= 2 * N);
	int res = 0;
	for (; a; a -= a & (-a)) {
		res += bit[a];
	}
	return res;
}
void update(int a) {
	assert(a <= 2 * N);
	a++;
	for (; a <= 2 * N; a += a & (-a)) {
		bit[a] ++;
	}
}

ll go(ll v) {
	// we want to count # sequences where median is < v
	// # sequences where (#<v) is > (#>=v)
	ll res = 0;
	int pref = N;
	reset();
	update(pref);
	for (int i = 0; i < N; i++) {
		if (A[i] < v) {
			pref ++;
		} else {
			pref --;
		}
		assert(pref >= 0);
		res += query(pref);
		update(pref);
	}
	return res;
}

int M;
int V[MAXN];
int main() {
	ios_base::sync_with_stdio(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	ll T = ll(N) * ll(N + 1) / 2;
	for (int i = 0; i < N; i++) {
		V[i] = A[i];
	}
	M = N;
	sort(V, V + M);
	M = int(unique(V, V + M) - V);
	int mi = 0, ma = M;
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		if (go(V[md]) * 2 <= T) {
			mi = md;
		} else {
			ma = md;
		}
	}
	cout << V[mi] << '\n';

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  ll S; cin >> S;
  ll x1, y1, x2, y2, n;
  n = 1000000000;
  if (S%n != 0){
    x1 = 1 + S/n;
    x2 = (n - S%n);
  } else{
    x1 = S/n;
    x2 = 0;
  }
  y2 = n;
  y1 = 1;
  
  cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = int(1e9) + 7


def wa(n, a):
    return ((n*(n+1))//2 * a) % MOD


ans = 0
# 内部の転倒数
for n in range(N):
    # 内部
    a = 0
    nA = A[n+1:]
    t = A[n]
    for na in nA:
        if t > na:
            a += 1
    temp = wa(K, a)
    ans += temp
    ans = ans % MOD

    # 外部
    b = 0
    nA = A[:n+1]
    for na in nA:
        if t > na:
            b += 1
    temp = (b * K*(K-1)//2)%MOD
    ans += temp
    ans = ans % MOD

print(ans)


Measured memory_bytes: 3188