akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = map(int, input().split())

a = sorted(a, reverse=True)

Alice = 0
Bob = 0

if N % 2 == 0:
    for i in range(0,N-1,2):
        Alice += a[i]
        Bob += a[i+1]
else:
    Alice += a[0]
    for i in range(1,N-1,2):
        Bob += a[i]
        Alice += a[i+1]


print(Alice-Bob)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sorted(a_1) sort(a_1.begin(),a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(),a_1.rend())
#define t1(a_1) cout<<a_1<<endl;
#define t2(a_1) for(auto it_test : a_1) cout<<it_test<<" ";
#define end cout<<endl;

const int MAX = 1000001;
vector<long long >isprime(MAX , true); 
vector<long long >prime; 
vector<long long >SPF(MAX); 
void Seive(int N) 
{ 
    isprime[0] = isprime[1] = false ; 
   
    for (long long int i=2; i<N ; i++) 
    { 
        if (isprime[i]) 
        { 
            prime.push_back(i);  
            SPF[i] = i; 
        } 
  
        for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) 
        { 
            isprime[i*prime[j]]=false; 
   
            SPF[i*prime[j]] = prime[j] ; 
        } 
    } 
} 

ll expo(ll a, ll b, ll m) 
{ 
    if (b == 0) 
        return 1; 
    ll p = expo(a, b / 2, m) % m; 
    p = (p * p) % m; 
  
    return (b % 2 == 0) ? p : (a * p) % m; 
} 

void solve(){
	int n,k;
	cin>>n>>k;
	vector<int>arr(n);
	for(auto &i : arr) cin>>i;
	vector<int>dp(n,INT_MAX);
	dp[0]=0;
	dp[1] = abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		for(int j=1;j<=k && j<=i;j++)
			dp[i] = min(dp[i],abs(arr[i]-arr[i-j]) + dp[i-j]);
	}
	cout<<dp[n-1]<<endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}

return 0;
}

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

typedef pair<int, int> pii;

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  pii mat[n];
  int dp[n][n];
  int p[n + 1];

  //????????????
  for (int i = 0; i < n; i++) {
    cin >> mat[i].first >> mat[i].second;
  }
  for (int i = 0; i < n; i++) {
    p[i] = mat[i].first;
  }
  p[n] = mat[n - 1].second;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if(i != j)dp[i][j] = 1e9;
      else dp[i][j] = 0;
    }
  }
  //???????????§?????????
  //????????????DP
  for (int l = 2; l <= n; l++) {
    for (int i = 0; i <= n - l; i++) {
      int j = i + l - 1;
      for (int k = i; k < j; k++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] +
                       p[i]*p[k + 1]*p[j + 1]);
      }
    }
  }
  std::cout << dp[0][n - 1] << std::endl;
            
  return 0;
}

Measured memory_bytes: 1200
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    S=input()
    print('Yes' if S[2]==S[3] and S[4]==S[5] else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<stdio.h>

int main(){


    int a,b; 


    scanf("%d",&a);


    scanf("%d",&b);


    if(a<b){


        printf("a < b\n");


 }else if(a>b){


        printf("a > b\n");


 }else{


        printf("a == b\n");


 }


return 0;


}

Measured memory_bytes: 580
s = input()
is_good = True
for i, c in enumerate(s):
    if (i + 1) % 2 == 1:
        if c == 'L':
            is_good = False
            break
    else:
        if c == 'R':
            is_good = False
            break
print('Yes' if is_good else 'No')


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

// nCr
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
// usage:
//   combination comb(n+5);
//   ans = comb(n,r);
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

V pos[100005];

void solve_abc_d() {
	ll n, m;
	//ll a, b;
	//ll x, y;
	ll k;
	ll l_ans = 0;

	map<ll, ll> list;

	cin >> n;
	V a(n + 1);
	rep(i, n + 1) {
		cin >> a[i];
		pos[a[i]].push_back(i);
	}

	ll len1, len2;
	rep1(i, n) {
		if (pos[i].size() == 2) {
			len1 = pos[i][0];
			len2 = n - pos[i][1];
		}
	}

	combination comb(n + 5);

	vector<mint> l3(len1 + len2 + 1);

	rep(i, len1 + len2 + 1) {
		l3[i] = comb(len1 + len2, i);
	}

	mint ans = 0;
	mint multi = 2;
	mint c1, c2;
	rep1(i, n + 1) {
		if (i == 1) {
			ans = n;
		}
		else if (i == 2) {
			c1 = comb(len1, 1);
			c2 = comb(len2, 1);
			ans = comb(n + 1, i) - c1 - c2;
		}
		else {
			ans = comb(n + 1, i);
			if (len1 + len2 >= i - 1) {
				ans -= l3[i - 1];
			}
		}

		cout << ans.x << "\n";
	}

	return;
}

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

	solve_abc_d();

	return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

ll f(ll n) {
  if(n%2==0) return n/2;
  return 3*n+1;
}

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

  ll s;
  cin >> s;

  set<ll> st;
  st.insert(s);
  FOR(i, 2, 1000001) {
    s = f(s);
    if(st.find(s) != st.end()) {
      cout << i << endl;
      return 0;
    }
    st.insert(s);
  }

  assert(false);

  return 0;
}

Measured memory_bytes: 256
def main():
    n, m, x = map(int, input().split())
    a = [int(x) - 1 for x in input().split()]
    count = [0 for _ in range(n)]
    for aa in a:
        count[aa] += 1
    for i in range(1, n):
        count[i] += count[i - 1]
    print(min(count[x - 1], count[n - 1] - count[x - 1]))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var T = Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();
		int M = int.Parse(Console.ReadLine());
		int[] P = new int[M];
		int[] X = new int[M];
        for(int i = 0; i < M; i++)
		{
			var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			P[i] = input[0];
			X[i] = input[1];
		}

		int sum = 0;
        for(int i = 0; i < N; i++)
		{
			sum += T[i];
		}
        for(var i = 0; i < M; i++)
		{
			Console.WriteLine(sum - T[P[i]-1] + X[i]);
		}


	}
}

Measured memory_bytes: 11220
// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
typedef long long ll;
typedef pair<int,int> Pii;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}
  
int main(){
    int d,t,s;
    read(d,t,s);
    if(t*s>=d){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 3064
def main():
    N = int(input())
    Ai = [int(a) for a in input().split()]
    Bi = [int(a) for a in input().split()]
    Ci = [int(a) for a in input().split()]
    s = 0
    for i in range(N):
        menu = Ai[i] - 1
        s += Bi[menu - 1]
        if i > 0 :
            if Ai[i] - Ai[i-1] == 1:
                s += Ci[Ai[i-1]-1]
    print(s)
main()

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
	long long a,b,c,k,t0,t1,t2,m;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
		k=k%4;
	if(k==0)
	printf("%lld\n",a-b);
	else{
	while(k--)
	{
		t0=a,t1=b,t2=c;
		a=t1+t2;
		b=t0+t2;
		m=a-b;
	}
	if(m>1e18)
	printf("Unfair\n");
	else
	printf("%lld\n",m);		
	}
	return 0;
} 

Measured memory_bytes: 128
'''aizu 0309
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0309
'''
# encoding: 'utf-8'

N = 1000000007

def main():
    node_n = int(input())
    nodes = list()
    for _ in range(node_n):
        nodes.append(Node(input()))
    for _ in range(node_n - 1):
        i, j = tuple([int(x) for x in input().split()])
        nodes[i-1].children.append(nodes[j-1])
        nodes[i-1].index.append(j-1)

    print(reduce_to_top(nodes).n % N)


def product(iterator):
    result = 1
    for element in iterator:
        result *= element % N
        result %= N
    return result


def step_reducing(nodes):
    last_parents = [node for node in nodes if node is not None and node.is_last_parent()]
    for parent in last_parents:
        parent.n = parent.number_of_cases()
        parent.children = list()
        for i in parent.index:
            nodes[i] = None
    return nodes


def reduce_to_top(nodes):
    while nodes[1:] != [None]*(len(nodes)-1):
        nodes = step_reducing(nodes)
    return nodes[0]


class Node:

    def __init__(self, kind, children=None, n=None, index=None):
        self.kind = kind
        if children is None:
            children = list()
        if index is None:
            index = list()
        self.children = children
        self.index = index
        self.n = n

    def number_of_cases(self):
        if self.n is not None:
            return self.n

        cases = self.generate_cases()
        if "E" in self.kind:
            result = product(cases)
            if "?" in self.kind:
                result += 1
            return result % N

        elif "A" in self.kind:
            result = sum(cases)
            if "?" in self.kind:
                result += 1
            return result % N

        elif "R" in self.kind:
            result = product((x+1 for x in cases))
            if "?" not in self.kind:
                result -= 1
            return result % N

        else:
            raise Exception("unreachable.")

    def generate_cases(self):
        for child in self.children:
            yield child.number_of_cases()

    def is_last_parent(self):
        bools = [child.children == [] for child in self.children]
        return bools and all(bools)


if __name__ == '__main__':
    main()

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

#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define MAXAS(x, v) x = max(x, v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define PI 3.141592653589793

#define MOD 1000000007L
// #define INF 100000000000

#define MAX_V 2000
#define INF 2147483647
//to,cost
typedef pair<long, long> P;

signed main() {
	string s;
	cin >> s;
	cout << s.substr(0, s.size() - 7 - 1) << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  ds <- map read . words <$> getLine :: IO [Int]
  print $ solve n ds

solve n ds = next - mid
  where
    sorted = sort ds
    mid = sorted !! (n `div` 2 - 1)
    next = sorted !! (n `div` 2)



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

using namespace std;

const int N = (int) 1e5 + 7;
int n, a[N];

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

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int sol = 0;
  for (int i = 1; i <= n; i++) {
    if (a[a[i]] == i) {
      sol++;
    }
  }
  cout << sol / 2 << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

vector<int> neig[100001];
int p[100001], l[100001], r[100001];
bool flag = 1;

pi fun(int u, int prev, pi p1)
{
	pi p2 = {p1.first - 1, p1.second + 1};
	if (p[u] != -1)
	{
		if (p[u] < p2.first || p[u] > p2.second)
		{
			flag = 0;
		}
		p2 = {p[u], p[u]};
	}
	l[u] = p2.first;
	r[u] = p2.second;
	for (int v : neig[u])
	{
		if (v != prev)
		{
			pi temp = fun(v, u, p2);
			l[u] = max(l[u], temp.first - 1);
			r[u] = min(r[u], temp.second + 1);
		}
	}
	if (l[u] > r[u])
	{
		flag = 0;
	}
	return {l[u], r[u]};
}

void fill(int u, int prev, int val)
{
	if (p[u] == -1)
	{
		if (val - 1 >= l[u] && val - 1 <= r[u])
		{
			p[u] = val - 1;
		}
		else
		{
			p[u] = val + 1;
		}
		// cout << u << " " << p[u] << endl;
	}
	if (abs(p[u] - val) != 1)
	{
		flag = 0;
	}
	for (int v : neig[u])
	{
		if (v != prev)
		{
			fill(v, u, p[u]);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		p[i] = -1;
	}
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		neig[a].pb(b);
		neig[b].pb(a);
	}
	int k;
	cin >> k;
	int start;
	for (int i = 1; i <= k; i++)
	{
		int v;
		cin >> v;
		start = v;
		cin >> p[v];
	}
	l[start] = p[start];
	r[start] = p[start];
	for (int v : neig[start])
	{
		pi temp = fun(v, start, {p[start], p[start]});
		l[start] = max(l[start], temp.first - 1);
		r[start] = min(r[start], temp.second + 1);
	}
	if (l[start] > r[start])
	{
		flag = 0;
	}
	if (!flag)
	{
		cout << "No" << endl;
		return 0;
	}
	for (int v : neig[start])
	{
		fill(v, start, p[start]);
	}
	if (!flag)
	{
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for (int i = 1; i <= n; i++)
	{
		cout << p[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 19544
#include <stdio.h>

int main (void)
{
   int a , b , c , d ,Bus , Train ;

   scanf("%d",&a);
   scanf("%d",&b);
   scanf("%d",&c);
   scanf("%d",&d);

   if(a>b)Bus = b;
   else Bus = a;

   if(c>d)Train = d;
   else Train = c;

   printf("%d\n",Bus + Train);

   return 0 ;

}


Measured memory_bytes: 128
import java.util.*;

public class Main {
	static final int MOD = 2019;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (b - a > MOD) {
			System.out.println(0);
			return;
		}
		int min = Integer.MAX_VALUE;
		for (int i = a; i < b; i++) {
			for (int j = i + 1; j <= b; j++) {
				min = Math.min(min, ((i % MOD) * (j % MOD) % MOD));
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 22740
N = int(input())
b = list(map(int, input().split()))

S = [0]*(N+1)

for n in range(N):
    S[n+1] = S[n] + ((-1)**n)*b[n]
    
ans = [0]*N
for n in range(N):
    ans[n] = b[n] - ((-1)**n)*S[n] + ((-1)**n)*(S[N]-S[n+1])
    
print(*ans)

Measured memory_bytes: 17624
// In the name of God
#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10;
const int MN = 5e3 + 10;

int n , k;
bitset<MN>L[MN] , R[MN];
int arr[MN];
vector<int> A , B;

void prep()
{
	L[0][0] = 1;
	for(int i=0;i<n;++i)
		L[i+1] = L[i] | (L[i]<<arr[i]);
	R[n][0] = 1;
	for(int i=n-1;~i;--i)
		R[i] = R[i+1] | (R[i+1]<<arr[i]);
}

void solve()
{
	int cnt = 0;
	for(int i=0;i<n;++i){
		A.clear() , B.clear();
		for(int j=0;j<MN;++j) if(L[i][j]) A.pb(j);
		for(int j=0;j<MN;++j) if(R[i+1][j]) B.pb(j);
	
		int sm = 0;	
		int p = Size(B)-1;
		bool is = false;
		for(int j=0;j<Size(A);++j){
			while(p >= 0 && B[p] + A[j] >= k) --p;
			if(p >= 0 && A[j] + B[p] + arr[i] >= k) is = true;
		}
		cnt += (!is);
	}
	cout << cnt << '\n';
}

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> n >> k;
	for(int i=0;i<n;++i)
		cin >> arr[i];
	prep();
	solve();
	return 0;
}


Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		List<List<Integer>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(b);
			list.get(b).add(a);
		}
		br.close();

		ArrayDeque<Integer> que = new ArrayDeque<>();
		que.add(0);
		que.add(list.get(0).get(0));
		Set<Integer> set = new HashSet<>();
		set.add(0);
		set.add(list.get(0).get(0));
		while (true) {
			boolean flg = true;
			List<Integer> list1 = list.get(que.peekFirst());
			for (Integer o : list1) {
				if (!set.contains(o)) {
					que.addFirst(o);
					set.add(o);
					flg = false;
					break;
				}
			}
			List<Integer> list2 = list.get(que.peekLast());
			for (Integer o : list2) {
				if (!set.contains(o)) {
					que.addLast(o);
					set.add(o);
					flg = false;
					break;
				}
			}
			if (flg) {
				break;
			}
		}

		System.out.println(que.size());
		StringBuilder sb = new StringBuilder();
		for (int i : que) {
			sb.append(i + 1).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    int c[n] = {};
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        c[--a]++;
        c[--b]++;
    }

    rep(i, n) OP(c[i]);
    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a= in.nextLong();
        long b= in.nextLong();
        long num_of_cookies = a+b;
        long k = in.nextLong();
        for(int i =0;i<k;i++)// 3
        {
            if(i%2==0)
            {
                b+=a/2;
                a/=2;
            }

                else {
                a += b / 2;
                b /= 2;
            }



        }
        System.out.println(a+" "+b);
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
int main(){
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};
  int m,n,s,w,e,i,r,k;
  int d[2][200]={0};
  while(scanf("%d",&m),m){
    n=s=w=e=0;
    for(i=1;i<m;i++){
      scanf("%d %d",&r,&k);
      d[0][i]=d[0][r]+Y[k];
      d[1][i]=d[1][r]+X[k];
      if(n<d[0][i])n=d[0][i];
      if(s>d[0][i])s=d[0][i];
      if(e<d[1][i])e=d[1][i];
      if(w>d[1][i])w=d[1][i];
    }
    printf("%d %d\n",n-s+1,e-w+1);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
const int mod=1000000007;
const int INF=1e18;

int ans[2005];
vector <int> gp[2005];
int n,x,y;
int dp[2005][2005];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>x>>y;
    f(i,1,n)
    {
        gp[i].push_back(i+1);
        gp[i+1].push_back(i);
    }
    dp[x][y]=1;
    dp[y][x]=1;
    f(i,1,n)
    {
        dp[i][i+1]=1;
        dp[i+1][i]=1;
    }
    f(i,1,n+1)
    {
        f(j,i+1,n+1)
        {
            dp[i][j]=min(j-i,abs(i-x)+abs(j-y)+1);
            ans[dp[i][j]]++;
        }
    }
    f(i,1,n)
    {
        cout<<ans[i]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 31232
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if (N % 2 == 0) {
            System.out.println("0.5");
        } else {
            System.out.println(((N - 1) / 2 + 1.0) / N);
        }
    }
}

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

using namespace std;

string s;
string ans = "KIHBR";

main ()
{
    cin >> s;
    if( s.size() > 9 )
    {
        puts("NO");
        return 0;
    }
    int h = 0;
    for( int i = 0; i < s.size(); i++ )
    {
        if( s[i] != ans[h] )
        {
            if( s[i] != 'A' )
            {
                puts("NO");
                return 0;
            }
            if( s[i] == 'A' && ( h == 2 || h == 1 ) )
            {
                puts("NO");
                return 0;
            }
        }
        if( s[i] == ans[h] )
            h ++;
        if( s[i] == s[i + 1] )
        {
            puts("NO");
            return 0;
        }
    }
    if( h == ans.size() )
    {
        puts("YES");
        return 0;
    }
    puts("NO");
}


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

int main() {
  string s1,s2;
  cin >>s1>>s2;
  if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
p=list(map(int,input().split()))
s=0
hoge=0
ans=0
for i in range(K):
    s+=p[i]
    temp=s
for j in range(N-K):
    s=s-p[j]+p[j+K]
    if temp<s:
        temp=s
        hoge=j+1

for k in range(K):
    ans+=(1+p[hoge+k])/2

print(ans)


Measured memory_bytes: 32020
#include <iostream>
using namespace std;
#define mod 1000000007
long long dp[55][55][2505];
int main()
{
	int n,o;
	scanf("%d%d",&n,&o);
	dp[0][0][0]=1;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<=i;j++)
		{
			for (int k=0;k<=o;k++)
			{
				dp[i+1][j][k+2*j]=(dp[i+1][j][k+2*j]+(2*j+1)*dp[i][j][k])%mod;
				dp[i+1][j+1][k+2*j]=(dp[i+1][j+1][k+2*j]+dp[i][j][k])%mod;
				if (j)
				dp[i+1][j-1][k+2*j]=(dp[i+1][j-1][k+2*j]+j*j*dp[i][j][k])%mod;
			}
		}
	}
	printf("%lld",dp[n][0][o]);
}

Measured memory_bytes: 53504
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    if (n == 3) { cout << "2 5 63\n"; return 0; }
    if (n == 4) { cout << "2 3 4 9\n"; return 0; }
    if (n == 5) { cout << "2 3 4 6 9\n"; return 0; }
    if (n == 6) { cout << "2 3 4 8 9 10\n"; return 0; }
    if (n == 7) { cout << "2 3 4 6 8 9 10\n"; return 0; }
    cout << "2 3 4 6 8 9 10 ";
    for (int k = 1; k < n/8; k++) {
        cout << 12*k << ' ' << 12*k + 2 << ' ' << 12*k + 3 << ' ' << 12*k + 4 << ' '
             << 12*k + 6 << ' ' << 12*k + 8 << ' ' << 12*k + 9 << ' ' << 12*k + 10 << ' ';
    }
    int r[8][10] = { {0}, {2, 4}, {0, 2, 4}, {2, 4, 8, 10}, {0, 2, 4, 8, 10},
                     {2, 3, 4, 8, 9, 10}, {0, 2, 3, 4, 8, 9, 10},
                     {0, 2, 3, 4, 6, 8, 9, 10} };
    for (int i = 0; i <= n%8; i++) cout << 12*(n/8) + r[n%8][i] << ' ';
    cout << endl;
}


Measured memory_bytes: 384
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
for i in range(N):
    a.append(a[i] +  A[i])
b = [0]
for i in range(M):
    b.append(b[i] + B[i])

ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47264
n, m= map(int, input().split())
L =[]
R =[]
for _ in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

t=min(R)-max(L)+1
if t <0:
    print("0")
else:
    print(t)

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

using namespace std;


int main()
{
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d;
  cin >> s;

  if(s[a - 1] == '#' || s[b - 1] == '#' || s[c - 1] == '#' || s[d - 1] == '#')
    {
      cout << "No" << endl;
      return 0;
    }

  bool tobi = false;
  if(c > d)
    {
      for (int i = b - 2;
           i < d - 1 && i < s.length() - 2;
           ++i)
        {
          if(s[i] == '.'
             && s[i + 1] == '.'
             && s[i + 2] == '.')
            {
              tobi = true;
              break;
            }
        }
    }
  else
    {
      tobi = true;
    }
  if(!tobi)
    {
      cout << "No" << endl;
      return 0;
    }
  else
    {
      for (int i = a - 1;
           i < c - 1 && i < s.length() - 1;
           ++i)
        {
          if(s[i] == '#' && s[i + 1] == '#')
            {
              cout << "No" << endl;
              return 0;
            }
        }
      for (int i = b - 1;
           i < d - 1 && i < s.length() - 1;
           ++i)
        {
          if(s[i] == '#' && s[i + 1] == '#')
            {
              cout << "No" << endl;
              return 0;
            }
        }
      cout << "Yes" << endl;
      return 0;
    }

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0) cout << b / x + 1 << endl;
    else cout << b / x - (a - 1) / x << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 25

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

int heightCheck(Node node[], int i){
  int height = 0;
  int left, right;

  if( node[i].left == -1 && node[i].right == -1 ) return height;
  else if( i == -1 ) return height;

  left = heightCheck(node, node[i].left);
  right = heightCheck(node, node[i].right);
  if( left > right ) return left+1;
  else return right+1;

}


main(){
  int n, i, j;
  int id, left, right, depth, parent;
  Node node[N];

  scanf("%d", &n);

  for( i = 0; i < n; i++){
    node[i].parent = -1;
    node[i].sibling = -1;
  }

  for( i = 0; i < n; i++){
    scanf("%d%d%d", &id, &left, &right);

    node[id].id = id;
    node[id].left = left;
    node[id].right = right;

    if( left != -1 || right != -1){
      node[left].parent = id;
      node[right].parent = id;
      node[left].sibling = right;
      node[right].sibling = left;
    }

  }

  for( i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d, ", node[i].id, node[i].parent, node[i].sibling);

    if( node[i].left == -1 && node[i].right == -1 ) printf("degree = 0, ");
    else if( node[i].left == -1 || node[i].right == -1 ) printf("degree = 1, ");
    else printf("degree = 2, ");

    depth = 0;
    parent = node[i].parent;
    while(1){
      if( parent == -1 ) break;
      else {
        parent = node[parent].parent;
        depth++;
      }
    }

    printf("depth = %d, ", depth);

    printf("height = %d, ", heightCheck(node, i));

    if( node[i].parent == -1 ){
      printf("root");
    }
    else if( node[i].left == -1 && node[i].right == -1){
      printf("leaf");
    }
    else printf("internal node");

    printf("\n");
  }

  return 0;

}

Measured memory_bytes: 604
#include <iostream>
#include <math.h>
using namespace std;

int Digit(int x);



int main(void) {
	
	int b, N, digit;
	b = 0;
	digit = 0;

	cin >> N;

	for(int i=1; i<=N; i++){
		digit = Digit(i);
		if(digit%2==1){
			b++;
		}
	}

	cout << b << endl;
}

int Digit(int number) {
	int d = 0;
	while(number!=0) {
		number/=10;
		d++;
	}
	return d;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#define clc(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int b[600];
int main()
{
    int n,m,i,j,k,s,t,x;
    char a[50];
    scanf("%s",a);
    s=strlen(a);
    clc(b,0);
    for(i=0;i<s;i++)
    {
        b[a[i]]++;
    }
    a[s]='a'-1;
    for(j=s-1;j>=-1;j--)
    {
        for(i=a[j+1]+1;;i++)if(b[i]==0)break;
        //printf("%d %c\n",j,i);
        if(i<='z')
        {
            for(k=0;k<=j;k++)printf("%c",a[k]);printf("%c\n",i);return 0;
        }
        b[a[j]]--;
    }
    printf("-1\n");
//zyxwvutsrqponmlkjihgfedcba
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<ll>a(n);
    ll cnt[60] = {};
    ll t = 0;
    rep(i,n){
        cin >> a[i];
        rep(j,60){
            if(a[i] & (1LL<<j))cnt[j]++;
        }
    }
    ll c[60] = {};
    ll d[60] = {};
    rep(i,60){
        if(k & (1LL<<i)){
            c[i] = (n-cnt[i])*(1LL<<i);
        }else{
            c[i] = cnt[i] * (1LL<<i);
        }
        d[i] = max(cnt[i],n-cnt[i]) * (1LL<<i);
    }
    ll ans = 0;
    rep(i,n)ans += a[i]^k;
    rep(i,60){
        if(!(k & (1LL<<i)))continue;
        ll temp = 0;
        for(int j = 59; j >= i+1; j--)temp += c[j];
        temp += cnt[i]*(1LL<<i);
        rep(j,i)temp += d[j];
        ans = max(ans, temp);
    }
    cout << ans << endl;
}

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

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
const int N = 1e6 + 9;
int m[N];

void mysol()
{
	memset(m, 0);
	int n; cin >> n;
	int arr[n];
	bool one = 0;
	for (int &a : arr) {
		cin >> a, m[a]++;
		if (a == 1)
			one = 1;
	}
	if (one)
	{
		if (m[1] > 1)
			cout << 0;
		else
			cout << 1;
		return;
	}
	int ans = 0;
	for (int a : arr)
	{
		if (m[a] > 1)
			continue;

		bool fg = true;
		for (int i = 2; i <= sqrt(a); i++)
		{
			if (a % i == 0)
			{
				if (m[i] or m[a / i])
				{
					fg = false;
					break;
				}
			}
		}
		if (fg)
			ans++;
	}
	cout << ans;



}

int32_t main()
{
	fast();
	// w(t)
	{
		mysol();
	}
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


Measured memory_bytes: 13020
// ABC088.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	//--Question A--
	int N,A;
	cin >>N >> A;
    if(N%500==0){
      cout << "Yes" << endl;
    }
	else if (N%500<A)
	{
		cout << "Yes" << endl;
	}
	else 
	{
		cout << "No" << endl;
	}
	
    return 0;
}


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

using namespace std;

typedef pair<int, int> P;

const int INF = 1001001001;

int dist1[100005];      // 頂点0からの距離
int dist2[100005];      // 頂点n-1からの距離

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    for(int i = 0; i < n-1; ++i){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    fill(dist1, dist1 + n, INF);
    dist1[0] = 0;
    queue<P> que;
    que.push(P(0, 0));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int v = p.first;
        int d = p.second;
        
        for(int i = 0; i < graph[v].size(); ++i){
            int v1 = graph[v][i];
            if(v1 == n-1)   continue;
            
            if(d + 1 < dist1[v1]){
                dist1[v1] = d + 1;
                que.push(P(v1, d + 1));
            }
        }
    }
    
    fill(dist2, dist2 + n, INF);
    dist2[n-1] = 0;
    que.push(P(n-1, 0));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int v = p.first;
        int d = p.second;
        
        for(int i = 0; i < graph[v].size(); ++i){
            int v1 = graph[v][i];
            if(v1 == 0)     continue;
            
            if(d + 1 < dist2[v1]){
                dist2[v1] = d + 1;
                que.push(P(v1, d + 1));
            }
        }
    }
    
    int cnt1 = 0, cnt2 = 0;
    for(int i = 1; i < n-1; ++i){
        if(dist1[i] <= dist2[i])    ++cnt1;
        else                        ++cnt2;
    }
    
    if(cnt1 > cnt2){
        cout << "Fennec\n";
    }
    else{
        cout << "Snuke\n";
    }
}

Measured memory_bytes: 6656
#include <iostream>
//#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    int n;
    list<int> a;
    int tmp_a;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        if(i%2==0){
            a.push_back(tmp_a);
        }else{
            a.push_front(tmp_a);
        }
    }

    if(n%2!=0){
        reverse(a.begin(), a.end());
    }

    for(auto itr=a.begin(); itr!=a.end(); itr++){
        cout << *itr << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 8448
#include<stdio.h>

 int main(){
 int a,b,c,d;
 
 scanf("%d %d %d",&a,&b,&c);
  
 if(a > b) {
    d = a;
      a = b;
      b = d;
  } if(b > c) {
    d = c;
    c = b;
    b = d;
 
  } if(a > b) {
    d = a;
    a = b;
    b = d;
  }
 printf("%d %d %d\n",a ,b ,c);
 return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n;
int calc(int x) {
    int ret=0;
    while(x) ret+=x%10,x/=10;
    return ret;
}
int main() {
    int ans=inf;
    n=gi();
    for(int i=1;i<n;i++) ans=min(ans,calc(i)+calc(n-i));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}


double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<int> l(n);
	rep(i, n)scanf("%d", &l[i]);
	sort(all(l));
	int ans = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; ++j) {
			for (int k = j + 1; k < n; ++k) {
				if (l[k] < l[i] + l[j] and l[i] != l[j] and l[j] != l[k] and l[i] != l[k])++ans;
			}
		}
	}
	printf("%d\n", ans);

	Please AC;
}


Measured memory_bytes: 3848
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_right

s = ns()
t = ns()

# 判定
ok = True
sset = set(list(s))
tset = set(list(t))
for ti in tset:
    if ti not in sset:
        ok = False

if not ok:
    print(-1)
else:
    n = len(s)
    nex = [[] for _ in range(26)]
    sdouble = s + s
    orda = ord("a")
    for i, si in enumerate(sdouble):
        nex[ord(si) - orda].append(i)

    bef = t[:1]
    cur = s.index(t[:1])
    ans = cur

    for ti in t[1:]:
        chridx = ord(ti) - orda
        dest = bisect_right(nex[chridx], cur)
        ans += (nex[chridx][dest] - cur)
        cur = ans % n

    print(ans+1)

Measured memory_bytes: 54740
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = [None] * n
    b = lmi()
    b.reverse()
    a[0] = b[0]
    for i in range(1, n-1):
        a[i] = min(b[i-1], b[i])
    a[n-1] = b[n-2]
    print(sum(a))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N, M;
    cin >> N >> M;
    int a[M], b[M], c[M];
    rep(i, M){
        cin >> a[i] >> b[i];
        c[i] = 0;
        rep(j, b[i]){
            int C; cin >> C;
            c[i] |= 1<<(C-1);
        }
    }
    int dp[1<<N];
    fill(dp, dp+(1<<N), inf);
    dp[0] = 0;
    rep(i, M){
        rep3(j, (1<<N)-1, 0){
            dp[j|c[i]] = min(dp[j|c[i]], dp[j]+a[i]);
        }
    }
    if(dp[(1<<N)-1] == inf) cout << -1 << endl;
    else cout << dp[(1<<N)-1] << endl;
}

Measured memory_bytes: 256
fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim()
        .split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())          // parse().ok() -> Option
        .collect()
}

fn main() {
    let input = read_to_vec::<i32>();

    for x in &input {
        if (*x != 5) && (*x != 7) {
            println!("NO");
            return;
        }
    }

    if input[0] + input[1] + input[2] == 17 {
        println!("YES");
        return;
    }
    println!("NO");
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
#define MAX 1000

int Ans[150];
char X[MAX],Y[MAX];

int counter(int,int);
int main(){
    int n,i,j;
    
    scanf("%d",&n);

    
    for(i=0;i<n;i++){
        scanf("%s",X);
        scanf("%s",Y);
        Ans[i]=counter(strlen(X),strlen(Y));
    }
    for(i=0;i<n;i++)
        printf("%d\n",Ans[i]);
    
    return 0;
}

int counter(int Xlen,int Ylen){
    int C[Ylen+1][Xlen+1];
    
    int i,j;
    for(i=0;i<=Ylen;i++){
        for(j=0;j<=Xlen;j++){
            C[i][j]=0;
        }
    }
    
    for(i=1;i<=Ylen;i++){
        for(j=1;j<=Xlen;j++){
            if(X[j-1]==Y[i-1]) C[i][j] = C[i-1][j-1]+1;
            else if(C[i-1][j]>=C[i][j-1]) C[i][j] = C[i-1][j];
            else C[i][j] = C[i][j-1];
        }
    }
    /*
    for(i=0;i<=Ylen;i++){
        for(j=0;j<=Xlen;j++){
            printf("%d ",C[i][j]);
        }
        printf("\n");
    }
     */
    return C[Ylen][Xlen];
    
}

Measured memory_bytes: 4512