akhauriyash/Code-Regression huggingface dataset:
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	cout << (A - 1)*(B - 1) << endl;
	

	return(0);
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n; cin >> n;

	vector <int> l(n);

	for(int i = 0; i < n; i++){
		cin >> l[i];
	}

	sort(l.rbegin(), l.rend());

	int sum = accumulate(next(l.begin()), l.end(), 0);


	cout << (l[0] < sum ? "Yes" : "No") << endl;





	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define PB push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mod 100000000
// #define int ll

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;cin >> n;
	cout << pow(n,3) << endl;
	
 	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}

ll maxll(ll a,ll b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
int main(){
  fastIO();
  string s;
  cin>>s;
  ll sum = 0;
  for(int i=0;i<s.length();i++){
  	sum+=s[i]-48;
  }
  cout<<maxll((s[0]-57)+(9*s.length()-1),sum)<<endl;
}



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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
stack<int> st;
str s;
int n;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    cin>>s;
    st.push(s[0]);
    for(int i=1;i<s.size();i++){
        if(st.top()!=s[i]) st.push(s[i]);
    }
    cout<<st.size()<<newl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n){
    cin>>vec[i];
  }
  vector<int> vec1=vec;
  sort(vec1.begin(),vec1.end());
  int cnt=0;
  rep(i,n){
    if(vec[i]!=vec1[i]){
      cnt++;
    }
  }
  if(cnt<=2){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  } 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<utility>
#include<map>

const int mod = 1000000007;
struct mint {
	long long x;
	mint(long long x = 0) : x((x%mod + mod)%mod) {} 

	mint operator - () const { return mint(-x); } 

	mint& operator += (const mint& a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator -= (const mint& a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator *= (const mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}

	mint operator + (const mint& a) const { return mint(*this) += a;}
	mint operator - (const mint& a) const { return mint(*this) -= a;}
	mint operator * (const mint& a) const { return mint(*this) *= a;}

	//べき乗
	mint pow(long long t) const{
		if(!t) return 1;
		mint a = pow(t >> 1); 
		a *= a;
		if(t&1) a *= *this;
		return a;
	}

	//逆元を求める
	mint inv() const {
		return pow(mod - 2);
	}
	//割り算　prime（素数）
	mint& operator /= (const mint a) { return (*this) *= a.inv(); }
	mint operator / (const mint a) const { return mint(*this) /= a; }
};
//入出力
std::istream& operator >> (std::istream& is, const mint& a) { return is >> a.x; }
std::ostream& operator << (std::ostream& os, const mint& a) { return os << a.x; }

//最大公約数を求める関数
long long gcd_(long long x, long long y){
	// どちらかが0の場合
	if(x == 0) return y;
	if(y == 0) return x;
	//　どのような値でも、0をかければ0になれる

	if(x < y){
		long long tmp = x;
		x = y;
		y = tmp;
	}
	long long r = x % y;
	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}

int main(){
	int n;
	std::cin >> n;
	int zero = 0;
	std::map<std::pair<long long, long long>, std::pair<int, int>> mp;

	for(int i=0; i<n; i++){
		long long a, b;
		std::cin >> a >> b;
		// 例外処理
		if(a == 0 && b == 0){
			zero++;
			continue;
		}
		// a, bを標準化する
		long long g = gcd_(a, b);
		a /= g;
		b /= g;

		// 180度回転
		if(b < 0){
			a = -a;
			b = -b;
		}else if(b == 0 && a < 0){
			a = -a;
		}

		// 90度回転
		bool rot = false;
		if(a <= 0){
			rot = true;
			long long tmp = -a;
			a = b;
			b = tmp;
		}

		// mapへ格納
		if(rot){ //90度回転したものは、secondグループ
			mp[{a, b}].second++;
		}else{ //firstグループ
			mp[{a, b}].first++;
		}
	}

	mint ans = 1;
	for(auto p : mp){
		int s = p.second.first;
		int t = p.second.second;
		mint now = 1; //どちらのグループからも選ばないとき
		now += mint(2).pow(s)-1; //sからの選び方（1匹以上）
		now += mint(2).pow(t)-1; //tからの選び方（1匹以上）
		ans *= now;
	}
	ans -= 1;
	ans += zero;
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 16072
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int n, a, b;
  cin >> n >> a>> b;
  cout << min(n*a,b) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
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; }

const int NIL = -1;
const int INF = (1<<21);
const long long MOD = 1e9+7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};


int main() {
  int N; cin >> N;
  vector<long long> A(N);
  int minus = 0;
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    if (a < 0) minus++;
    A[i] = abs(a);
    ans+= A[i];
  }
  sort(A.begin(), A.end());
  if (minus % 2 == 1) {
    ans -= 2 * A[0];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4028
package main

import (
	"fmt"
)

const mod = int(1e9 + 7)

var ifac, fac []int

var pows map[int]map[int]int

func main() {
	const cmax = int(2e6 + 1)
	fac = make([]int, cmax)
	ifac = make([]int, cmax)
	inv := make([]int, cmax)
	fac[0], fac[1] = 1, 1
	ifac[0], ifac[1] = 1, 1
	inv[0], inv[1] = 1, 1
	for i := 2; i < cmax; i++ {
		fac[i] = (fac[i-1] * i) % mod
		inv[i] = (mod - inv[mod%i]*(mod/i)) % mod
		if inv[i] < 0 {
			inv[i] += mod
		}
		ifac[i] = (ifac[i-1] * inv[i]) % mod
	}

	var k int
	fmt.Scan(&k)
	var s string
	fmt.Scan(&s)
	n := len(s)
	sum := 1
	for i := 1; i <= k+n; i++ {
		sum *= 26
		sum %= mod
	}
	var isum int
	for i := 0; i < n; i++ {
		a := comb(k+n, i) * modpow(25, k+n-i)
		isum += a
		isum %= mod
	}

	ans := (sum - isum) % mod
	if ans < 0 {
		ans += mod
	}
	fmt.Println(ans)
}

func comb(n, r int) int {
	if r > n {
		return 0
	} else if r == 0 || r == n {
		return 1
	}
	t := (ifac[n-r] * ifac[r]) % mod
	return (t * fac[n]) % mod
}

func modpow(a, n int) int {
	res := 1
	for n > 0 {
		if n&1 > 0 {
			res *= a
			res %= mod
		}
		a = a * a % mod
		n >>= 1
	}
	return res
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 53500
import sys
sys.setrecursionlimit(10 ** 9)
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
D = [0] * N
D[0] = 1

C = 0
def dfs(n):
    global C
    if not 0 in D:
        C += 1
        return
    for i in G[n]:
        if D[i] == 1:
            continue
        D[i] = 1
        dfs(i)
        D[i] = 0

dfs(0)
print(C)

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


int main()
{
	
	int T_H,T_S;
	int A_H,A_S;
	
    //scanf("%d   %d",&T_H,&T_S);
	//scanf("%d   %d",&A_H,&A_S);
	cin>>T_H>>T_S>>A_H>>A_S;
	
	while(T_H>0){
	
	A_H=A_H-T_S;
	if(A_H<=0) {
	
		printf("Yes");
		break;
	}
	
	T_H=T_H-A_S;
    
	if(T_H<=0){
		
  		printf("No");
  		break;
    }
	
}
	return 0;
	
}

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

void chmin(int& a, int b){
    a = min(a, b);
}

int main(){
    int N;
    cin >> N;
    vector<int> Bi(N), Wi(N);
    vector<vector<int>> Bsum(2*N+1, vector<int>(N+1)), Wsum(2*N+1, vector<int>(N+1));
    for(int i=0; i<2*N; i++){
        char c;
        int a;
        cin >> c >> a;
        a--;
        Bsum[i+1] = Bsum[i];
        Wsum[i+1] = Wsum[i];
        if(c == 'B'){
            Bi[a] = i;
            for(int j=0; j<=a; j++) Bsum[i+1][j]++;
        }else{
            Wi[a] = i;
            for(int j=0; j<=a; j++) Wsum[i+1][j]++;
        }
    }
    
    vector<vector<int>> dp(N+1, vector<int>(N+1, 1e9));
    dp[0][0] = 0;
    for(int i=0; i<=N; i++) for(int j=0; j<=N; j++){
        if(i<N) chmin(dp[i+1][j], dp[i][j] + Wsum[Wi[i]][i] + Bsum[Wi[i]][j]);
        if(j<N) chmin(dp[i][j+1], dp[i][j] + Wsum[Bi[j]][i] + Bsum[Bi[j]][j]);
    }
    cout << dp[N][N] << endl;
}


Measured memory_bytes: 78848
#include<iostream>
#include<numeric>
#include<vector>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=b&&a>=c)cout<<b+c;
  else if(b>=c&&b>=a)cout<<c+a;
  else cout<<a+b;
}

Measured memory_bytes: 256
import sys

d = {}

for i in sys.stdin.readlines():
    s, n = i.split()
    if s in d:
        d[s].append(int(n))
    else:
        d[s] = [int(n)]

d = sorted(d.items())
for i in d:
    print(i[0])
    print(*sorted(i[1]))

Measured memory_bytes: 7564
# -*- coding: utf-8 -*-


def main():
    A, B = [int(_) for _ in input().split()]

    product = A * B
    for divisor in range(min([A, B]) // 2, 2, -1):
        if A % divisor == 0 and B % divisor == 0:
            A = A // divisor
            B = B // divisor
            product = product // divisor

    print(product)


def correct_1():
    A, B = [int(_) for _ in input().split()]

    for i in range(1, B + 1):
        if A * i % B == 0:
            print(A * i)
            break


def correct_2():
    A, B = [int(_) for _ in input().split()]

    def gcd(a, b):
        while b != 0:
            a, b = b, a % b
        return a

    def lcm(a, b):
        return a * b // gcd(a, b)

    print(lcm(A, B))


if __name__ == "__main__":
    correct_1()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  
  int cnt=0;
  int minwk = 200000+1;
  for(int i=0;i<N;i++){
    minwk=min(P.at(i),minwk);
    if(P.at(i)>minwk)
      cnt++;
  }
  
 cout<<N-cnt<<endl;
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &i:a)cin >> i;
	vector<int>cnt(n);

	for(auto i:a)cnt[i]++;
	ll ans = 1;
	if(n%2==0)
	{
		for(int i = 0;i<n;i++)
		{
			if(i%2)
			{
				if(cnt[i]==2){(ans*=2)%=MOD;}
				else ans = 0;
			}
		}
	}
	else
	{
		if(cnt[0]!=1)ans = 0;
		for(int i = 1;i<n;i++)
		{
			if(i%2==0)
			{
				if(cnt[i]==2)
				{
					(ans*=2)%=MOD;
				}
				else ans = 0;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define fi first
#define se second
#define MAXN 200005
#define pb push_back
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N,K;
int cnt[200005];
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    read(N);read(K);
    int64 ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
        cnt[i % K]++;
    }
    for(int i = 0 ; i < K ; ++i) {
        if((K - i) * 2 % K == 0) {
            ans += 1LL * cnt[i] * cnt[(K - i) % K] * cnt[(K - i) % K];
        }
    }
    out(ans);enter;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,R,c[100010];
ll fact[100010];

//
const int M=1<<17;
ll bit[M+1];
 
ll sum(int i){
	ll s=0;
	while(i){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}
 
void add(int i,ll x){
	while(i<=M){
		bit[i]+=x;
		i+=i&-i;
	}
}
//

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>N>>R && N){
		memset(bit,0,sizeof(bit));
		rep(i,N)c[i]=i+1;
		rep(i,R){
			int s,t;
			cin>>s>>t;
			swap(c[s-1],c[t-1]);
		}
	
		fact[0]=1;
		rep2(i,1,N+1)fact[i]=fact[i-1]*i%MOD;
		ll ans=0;
		rep(i,N){
			ans+=(c[i]-1-sum(c[i]-1)) * fact[N-1-i];
			ans%=MOD;
			add(c[i],1);
		}
		cout<<ans<<endl;
	}
}

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

int main(){
  int N,M,buf;
  cin >> N >> M;

  vector<int> data(N);
  int sum= 0;
  for(int i=0; i<N; i++){
    cin >> buf;
    data.at(i)= buf;
    sum+= buf;
  }

  int cnt= 0;
  for(int i=0; i<N; i++){
    if(4*M*data.at(i) >= sum) cnt++;
  }
  
  string ans= (cnt >= M) ? "Yes"
                         : "No";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

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

int main()
{
    int k;
    cin >> k;
    cout << (k/2)*((k+1)/2);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        static long mod = (long)Math.Pow(10, 9) + 7;

        public static void Main(string[] args)
        {
            long[] HW = Read(Console.ReadLine());
            long H = HW[0];
            long W = HW[1];

            int ans = 0;

            string[] map = new string[H];
            int[,] counts = new int[H, W];

            for (int i = 0; i < H; i++)
            {
                map[i] = Console.ReadLine();

                List<int> connectNum = new List<int>();
                for (int j = 0; j < W; j++)
                {
                    if (map[i][j] == '.') connectNum.Add(j);
                    if(map[i][j] == '#'||j==W-1)
                    {
                        int c = connectNum.Count;
                        foreach (var item in connectNum)
                        {
                            counts[i, item] += c;
                            ans = Math.Max(ans, counts[i, item]);
                        }
                        connectNum = new List<int>();

                    }
                }
            }




            for (int i = 0; i < W; i++)
            {
                List<int> connectNum = new List<int>();
                for (int j = 0; j < H; j++)
                {
                    //if (map[j][i] == '.') connectNum.Add(j);
                    //else
                    if (map[j][i] == '.') connectNum.Add(j);
                    if (map[j][i] == '#' || j == H - 1)
                    {
                        
                        int c = connectNum.Count;
     
                        foreach (var item in connectNum)
                        {
                            counts[item, i] += c-1;
                            ans = Math.Max(ans, counts[item, i]);
                        }
                        connectNum = new List<int>();

                    }
                }
            }


            Console.WriteLine(ans);
            Console.ReadLine();
        }

        private static long[] Read(string input)
        {
            string[] strings = input.Split(' ');
            long num = strings.Length;
            long[] ints = new long[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = long.Parse(strings[i]);
            }

            
            return ints;
        }
    }
}


Measured memory_bytes: 60844
import math
import itertools


N = int(input())

array = [list(map(int, input().split())) for _ in range(N)]

permutation_list = itertools.permutations([x for x in range(N)])

calc = [[0] * 10 for i in range(10)]
for i in range(N):
    for j in range(N):
        calc[i][j] = math.sqrt((array[i][0] - array[j][0]) ** 2 +
                               (array[i][1] - array[j][1]) ** 2)
        calc[j][i] = calc[i][j]

result = 0
count = 0
for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += calc[data[i - 1]][data[i]]
print(result / count)


Measured memory_bytes: 3064
n = int(input())
c = input()

w, r = 0, c.count('R')
ans = max(w, r)
for i in range(n):
   if c[i] == 'W':
      w += 1
   else:
      r -= 1
   res = max(w, r)
   ans = min(ans ,res)
print(ans)


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

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        String s = scanner.next();
        int[] count = new int[n + 1];
        count[0] = 0;
        for (int i = 1; i <= n; ++i) {
            count[i] = count[i - 1];
            if (s.charAt(i - 1) == '#')
                ++count[i];
        }
        int result = Integer.MAX_VALUE;
        for (int i = 0; i <= n; ++i) {
            result = Integer.min(result, count[i] + (n - i) - (count[n] - count[i]));
        }
        writer.println(result);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 26580
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

signed main(){
    string s;
    cin>>s;
    int n = s.size();
    
    map<char,int> hist;
    rep(i,s.size()){
        hist[s[i]]++;
    }
    
    int ans = n*(n-1)/2;
    
    for(char ch = 'a'; ch <= 'z'; ch++){
        int t = hist[ch];
        ans -= t*(t-1)/2;
    }
    
    cout<<ans+1<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> r(n+1), g(n+1), b(n+1);
    rep(i,n) {
        r[i+1] += r[i];
        g[i+1] += g[i];
        b[i+1] += b[i];
        if (s[i] == 'R') r[i+1]++;
        if (s[i] == 'G') g[i+1]++;
        if (s[i] == 'B') b[i+1]++;
    }
    ll ans = 0;
    rep(i,n) {
        if (s[i] == 'R') {
            ans += g[i+1]*(b[n]-b[i+1]);
            ans += b[i+1]*(g[n]-g[i+1]);
        } else if (s[i] == 'G') {
            ans += r[i+1]*(b[n]-b[i+1]);
            ans += b[i+1]*(r[n]-r[i+1]);
        } else if (s[i] == 'B') {
            ans += r[i+1]*(g[n]-g[i+1]);
            ans += g[i+1]*(r[n]-r[i+1]);
        }
    }
    ll mn = 0;
    repf(i,1,n-1) repf(j,1,(n+1)/2+1) {
        if (i-j >= 0 && i+j < n) {
            if (s[i-j] != s[i] && s[i] != s[i+j] && s[i+j] != s[i-j]) mn++;
        }
    }
    cout << ans - mn << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int h, w;
	cin>>h>>w;
	vector<string> s(h);
	rep(i, h) cin>>s[i];
	bool f = true;
	int r = 0, l = INF;
	for(int i = 0; i < w; i++){
		if(s[0][i] == '#'){
			l = min(l, i);
			r = max(r, i);
		}
	}
	int ll = INF, rr = 0;
	for(int i = 1; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#'){
				ll = min(ll, j);
				rr = max(rr, j);
			}
		}
		if(ll < l) f = false;
		if(rr < r) f = false;
		if(ll != r) f = false;
		l = ll;
		r = rr;
		ll = INF;
		rr = 0;
	}
	cout<<(f?"Possible": "Impossible")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

int main(int argc, char* argv[])
{
  int n, m, x;
  std::vector< int > va;

  std::cin >> n >> m >> x;
  for (int i = 0; i < m; i++) {
    int tmp;
    std::cin >> tmp;
    va.push_back(tmp);
  }

  int d_cnt = 0;
  int u_cnt = 0;
  std::vector< int >::iterator it;
  for (it = va.begin(); it != va.end(); it++) {
    if (*it < x) {
      d_cnt++;
    } else {
      u_cnt++;
    }
  }

  std::cout << std::min(d_cnt, u_cnt) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
int n,m,i,j,a[100005];
long long sum,uit;
int main()
{
	cin>>n;uit=1ll*n*(n+1)/2;
	fz1(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum%uit!=0){
		puts("NO");
		return 0;
	}
	sum/=uit;
	a[0]=a[n];
	fd1(i,n){
		a[i]=a[i]-a[i-1];
	}
	fz1(i,n){
		a[i]-=sum;
	}
	fz1(i,n){
		if(a[i]>0||(-a[i])%n!=0){
			puts("NO");
			return 0;
		}
		sum-=(-a[i])/n;
	}
	if(sum==0) puts("YES"); else puts("NO");
	return 0;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 100000000;
int n, x[10001][2], list[4], save[10001], l1 = 0, l2 = 0, ans = INF;
vector<int> v1, v2, v3;
int solve(int a){
	l1 = 0; l2 = 0;
	for (int i = 1; i < v2.size(); i++){
		if (v2[a + i] == v2[a]){
			l1++;
		}
		else
			break;
	}
	for (int i = 1; i < v2.size(); i++){
		if (v2[a - i] == v2[a]){
			l2++;
		}
		else
			break;
	}
	if (l1 + l2 >= 3){
		v2.erase(v2.begin() + a - l2, v2.begin() + a + l1 + 1);
		solve(a - l2-1);
	}
	else{
		return v2.size();
	}
}
int main(){
	while (true){
		cin >> n;
		if (n == 0){
			break;
		}
		for (int i = 1; i <= n; i++){
			cin >> x[i][0];
			v1.push_back(x[i][0]);
			if (i - list[x[i][0]] == 2){
				save[i - 1] = 2;
			}
			list[x[i][0]] = i;
			if (x[i][0] == x[i - 1][0] && x[i][0] == x[i - 2][0]){
				save[i + 1] = 1;
				save[i - 3] = 1;
			}
		}
		for (int i = 1; i <= n; i++){
			if (save[i] == 1){
				v2 = v1;
				v2.erase(v2.begin() + i - 1);
				if (x[i + 1][0] == x[i + 2][0] && x[i + 1][0] == x[i + 3][0]){
					v2.insert(v2.begin() + i - 1, x[i + 1][0]);
				}
				else if (x[i - 1][0] == x[i - 2][0] && x[i - 1][0] == x[i - 3][0]){
					v2.insert(v2.begin() + i - 1, x[i - 1][0]);
				}
				ans = min(solve(i - 1), ans);
			}
			else if (save[i] == 2 && x[i + 1][0] == x[i + 2][0]){
				v2 = v1;
				v2.erase(v2.begin() + i - 1);
				v2.insert(v2.begin() + i - 1, x[i + 1][0]);
				ans = min(solve(i - 1), ans);
			}
			else if (save[i] == 2 && x[i - 1][0] == x[i - 2][0]){
				v2 = v1;
				v2.erase(v2.begin() + i - 1);
				v2.insert(v2.begin() + i - 1, x[i - 1][0]);
				ans = min(solve(i - 1), ans);
			}
			else save[i] = 0;
		}
		cout << ans << endl;
		for(int i=1;i<=n;i++){
			//x[i][0]=0;
			//save[i]=0;
		}
		//list[0]=0;
		//list[1]=0;
		//list[2]=0;
		//list[3]=0;
		ans=INF;
		v1=v3;
	}
	return 0;
}

Measured memory_bytes: 1436
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

template <typename T>
struct SegTree {
    typedef function<T(T, T)> F;
    int n;
    F f;
    T ti;
    vector<T> dat;
    SegTree(){}
    SegTree(F f, T ti): f(f), ti(ti){}

    void init(int n_) {
        n = 1;
        while(n < n_) n <<= 1;
        dat.assign(n<<1, ti);
    }

    void build(const vector<T> &v) {
        int n_ = v.size();
        init(n_);
        for(int i = 0; i < n_; ++i) dat[n+i] = v[i];
        for(int i = n-1; i; --i) dat[i] = f(dat[(i<<1)|0], dat[(i<<1)|1]);
    }

    void set_val(int k, T x) {
        dat[k += n] = x;
        while(k >>= 1) dat[k] = f(dat[(k<<1)|0], dat[(k<<1)|1]);
    }

    T query(int a, int b) {
        if(a >= b) return ti;
        T vl = ti, vr = ti;
        for(int l = a+n, r = b+n; l < r; l >>= 1, r >>= 1) {
            if(l&1) vl = f(vl, dat[l++]);
            if(r&1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }

    template <typename C>
    int find(int st, C &check, T &acc, int k, int l, int r) {
        if(l+1 == r) {
            acc = f(acc, dat[k]);
            return check(acc) ? k-n : -1;
        }
        int m = (l+r)>>1;
        if(m <= st) return find(st, check, acc, (k<<1)|1, m, r);
        if(st <= 1 && !check(f(acc, dat[k]))) {
            acc = f(acc, dat[k]);
            return -1;
        }
        int vl = find(st, check, acc, (k<<1)|0, l, m);
        if(~vl) return vl;
        return find(st, check, acc, (k<<1)|1, m, r);
    }

    template <typename C>
    int find(int st, C &check) {
        T acc = ti;
        return find(st, check, acc, 1, 0, n);
    }
};

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

    auto f = [](ll a, ll b) { return max(a, b); };
    SegTree<ll> seg(f, 0);
    seg.build(vector<ll>(300005, 0));

    seg.set_val(avec[0], 1);
    for(int i = 1; i < n; ++i) {
        int cl = max(0, avec[i]-k);
        int cr = min(300000, avec[i]+k);
        seg.set_val(avec[i], seg.query(cl, cr+1)+1);
    }

    cout << seg.query(0, 300000) << endl;
}

Measured memory_bytes: 14856
#include <stdio.h>

void reverseString( char* input )
{
	int len;
	int i;
	char buf[20];
	
	for( i = 0, len = 0; input[i] != '\0'; i++, len++ );
	len--;
	
	for( i = len; i >= 0; i-- )
	{
		buf[ i ] = input[ len - i ];
	}
	for( i = 0; i < len + 1; i++ )
	{
		input[ i ] = buf[ i ];
	}
}

int main( void )
{
	char string[21];
	
	scanf( "%s", string );
	reverseString( string );
	printf( "%s\n", string );
	
	return (0);
}

Measured memory_bytes: 524
#include<stdio.h>
int main()
{
  int w,h,i,j;
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0 && w==0)break;
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	if(i%2!=0){
	  if(j%2!=0)printf("#");
	  if(j%2==0)printf(".");
	}
	if(i%2==0){
	  if(j%2!=0)printf(".");
	  if(j%2==0)printf("#");
	}
	if(j==w)printf("\n");
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] Z = new int[N];
        for(int n = 0; n < N; n++) {
            Z[n] = sc.nextInt();
        }
        int R = 0;
        int X = 0;

        for (int i = 0; i < N - 1; i++) { 
            for(int j = i + 1; j < N; j++) {
                X = Z[i] * Z[j];
                R = R + X;
            }
        }
        System.out.println(R);
    }
}

Measured memory_bytes: 25300
n,l=map(int,input().split())
a=[]
for i in range(1,n+1):
    a.append(l+i-1) 
a.sort()
for i in range(n):
    if a[i]>=0:
        m=a[i] 
        break 
    else:
        m=a[n-1]
ans=sum(a)-m 
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

const int pat[]={1,2,3,5,8,13,21};

int main(){
    ll dp[110][10];
    memset(dp,0,sizeof(dp));
    int H,W,K; cin>>H>>W>>K;
    dp[0][0]=1ll; //dp[i][j]: 高さi終了時にj番目にいる
    if(W==1){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            (dp[i+1][j]+=dp[i][j]*pat[max(0,j-1)]*pat[max(0,W-j-2)])%=MOD;
            if(j>0) (dp[i+1][j-1]+=dp[i][j]*pat[max(0,j-2)]*pat[max(0,W-j-2)])%=MOD;
            if(j<W-1) (dp[i+1][j+1]+=dp[i][j]*pat[max(0,j-1)]*pat[max(0,W-j-3)])%=MOD;
        }
    }

    cout<<dp[H][K-1]<<endl;

    return 0;
}



Measured memory_bytes: 256
//ALDS1_10C
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

static const int N=1001;

int lcs(string X,string Y){
 vector< vector<int> > c(N,vector<int>(N));
 int m=X.size();
 int n=Y.size();
 int maxl=0;
 X=' '+X;
 Y=' '+Y;
 for(int i=1;i<=m;i++){
  for(int j=1;j<=n;j++){
   if(X[i]==Y[j]){
    c[i][j]=c[i-1][j-1]+1;
   }else{
    c[i][j]=max(c[i-1][j],c[i][j-1]);
   }
   maxl=max(maxl,c[i][j]);
   }
  }
 return maxl;
 }

int main(){
 string s1,s2;
 int n;
 cin>>n;
 for(int i=0;i<n;i++){
  cin>>s1>>s2;
  cout<<lcs(s1,s2)<<endl;
 }
 return 0;
}

Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int a, b;
    cin >> a >> b;

    int res = (a+b)/2;
    if((a+b)%2) res++;

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ret = 0;
            for (int i = 1; i <= n; i++)
                ret += getF5(i);
            Console.WriteLine(ret);
        }
    }
    public static int  getF5 (int n)
    {
        var ret = 0;
        while (true)
        {
            if (n % 5 == 0) { n /= 5; ret++; }
            else return ret;
        }
    }
}



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

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

    int N, L;
    cin >> N >> L;

    int pre_a;
    int last_idx = -1;
    cin >> pre_a;
    for (int i = 1; i < N; ++i) {
        int cur_a;
        cin >> cur_a;
        if (pre_a + cur_a >= L) {
            last_idx = i;
        }
      	pre_a = cur_a;
    }
    if (last_idx == -1) {
        cout << "Impossible" << '\n';
        return 0;
    }

    cout << "Possible" << '\n';

    for (int i = 1; i < last_idx; ++i) {
        cout << i << '\n';
    }
    for (int i = N - 1; i >= last_idx; --i) {
        cout << i << '\n';
    }

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int head[maxn], tot;
ll dp[maxn][2];
struct Edge {
    int u, v, next;
}edge[maxn];

void init() {
    memset(head, -1, sizeof(head)); tot = 1;
}
void add(int u, int v) {
    edge[++tot].u = u; edge[tot].v = v;
    edge[tot].next = head[u]; head[u] = tot;
}

void dfs(int u, int fa) {
    int cnt = 0;
    dp[u][0] = 1; dp[u][1] = 1;
    for (int i = head[u]; i != -1; i = edge[i].next) {
        int to = edge[i].v;
        if (to == fa) continue;
        cnt++;
        dfs(to, u);
        dp[u][0] = (dp[u][0] * dp[to][1]) % mod;
        dp[u][1] = (dp[u][1] * (dp[to][0] + dp[to][1]) % mod) % mod;
    }

}

int main() {
    //freopen("in.in", "r", stdin);
    int n, u, v;
    cin >> n;
    init();
    for (int i = 1; i <= n - 1; i++) {
        cin >> u >> v; add(u, v); add(v, u);
    }
    dfs(1, 0);
    cout << (dp[1][0] + dp[1][1]) % mod << endl;
    return 0;
}

Measured memory_bytes: 18688
// AOJ 1004
#include<algorithm>
#include<cstdio>

bool isprime[10001];

void sieve()
{
	std::fill( isprime, isprime+10001, true );
	isprime[0] = isprime[1] = false;
	for( int i = 2; i <= 10000; ++i )
		if( isprime[i] )
			for( int j = i*2; j <= 10000; j += i )
				isprime[j] = false;

	return;
}

int main()
{
	sieve();

	int n;
	while( scanf( "%d", &n ) != EOF )
	{
		int ans = 0;
		for( int i = 0; i != n; ++i )
			if( isprime[i+1] && isprime[n-i] )
				++ans;

		printf( "%d\n", ans );
	}

	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A<C && C<B){
    cout << "Yes" << endl;
  }
  else if(B<C && C<A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define white 0
#define gray 1
#define black 2

int t,n,g[MAX][MAX] = {0};
int d[MAX],f[MAX],color[MAX] = {white};
void dfs(void);
void visit(int);

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      g[u-1][v-1] = 1;
    }
  }
  dfs();
  return 0;
}

void dfs(){
  int u;
  t = 0;
  for(u=0;u<n;u++)
    if(color[u] == white)visit(u);
  for(u=0;u<n;u++)
    printf("%d %d %d\n",u+1,d[u],f[u]);
}

void visit(int u){
  int v;
  color[u] = gray;
  d[u] = ++t;
  for(v=0;v<n;v++){
    if(g[u][v] == 0)continue;
    if(color[v] ==white)visit(v);
  }
  color[u] = black;
  f[u] = ++t;
}


Measured memory_bytes: 2112
/*
 * Click `Run` to execute the snippet below!
 */

import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long ans = 0;
    long k = 1;
    while(H >= 1){
      ans += k;
      k *= 2;
      H /= 2;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 27048
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int m, d; cin >> m >> d;
	
	int ans = 0;
	for (int i = 1; i < m+1; i++) {
		for (int j = 1; j < d+1; j++) {
			int x = j / 10;
			int y = j % 10;

			if (x < 2 || y < 2)continue;

			if (i == (x*y))ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# 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;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int a[N];
string s;

void sol (int x, int y) {
	for (int i = 1; i <= n; i ++) {
		a[i] = -1;
	}

	a[1] = x;
	a[2] = y;
	a[n+1] = x;
	for (int i = 2; i < n; i++) {
		bool nxt = 0; 
		if (a[i] == 1) nxt ^= 1;
		if (s[i] == 'x') nxt ^= 1;
		a[i+1] = (a[i-1] ^ nxt);
	}

	for (int i = 1; i <= n; i ++) {
		int l = i-1;
		int r = i+1;
		if (r > n) r = 1;
		if (l < 1) l = n;

		bool nxt = 0; 
		if (a[i] == 1) nxt ^= 1;
		if (s[i] == 'x') nxt ^= 1;

		if(!nxt) {
			if (a[l] != a[r]) return;
		} else {
			if (a[l] == a[r]) return;
		} 

	}

	for (int i = 1; i <= n; i ++)
		cout << (a[i] ? "W" : "S");
	exit(0);
}

int main () {
	SpeedForce;
	cin >> n >> s;
	s = '#' + s;


	for (int a = 0; a < 2; a++) {
		for (int b = 0; b < 2; b++) {
			sol(a, b);
		}
	}

	puts("-1");

   	return Accepted;
}

// B...a

Measured memory_bytes: 1024
def solve(ary)
  count = {}
  ary.each{|n|
    if count.include?(n)
      count[n] += 1
    else
      count[n] = 1
    end
  }
  count.map{|key, val|
    if key > val
      val
    elsif key < val
      val - key
    else
      0
    end
  }.inject(:+)
end

def main
  n = STDIN.gets
  ary = STDIN.gets.split(" ").map{ |x| x.to_i }
  puts solve(ary)
end

main


Measured memory_bytes: 18052
#include <iostream>
#include <string>
#include <algorithm>
#define llint long long

using namespace std;

llint a, b;

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

	cin >> a >> b;
	
	for(int i = 0; i <= 1000005; i++){
		if(i * 108 / 100 - i == a && i * 110 / 100 - i == b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<string> vs(n);
  for(Int i=0;i<n;i++) cin>>vs[i];

  set<string> ss(vs.begin(),vs.end());
  if((Int)ss.size()!=n){
    cout<<"No"<<endl;
    return 0;
  }
  for(Int i=1;i<n;i++)
    if(vs[i-1].back()!=vs[i].front()){
      cout<<"No"<<endl;
    return 0;
    }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
N, M = tuple(map(int, input().split()))
v = [[int(x) for x in input().split()] for j in range(N)]
v2 = [[v[i][0]*p + v[i][1]*q + v[i][2]*r for i in range(N)] for p in [1, -1] for q in [1, -1] for r in [1, -1]]
v3 = [sorted(v2[i], reverse=True) for i in range(8)]
m = 0
for i in range(8):
    n = sum(v3[i][:M])
    if n > m:
        m = n

print(m)

Measured memory_bytes: 3572