akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100005
#define mp make_pair
const ll mod=1000000007;
vector<ll> a(3*MAX);
vector<ll> maxsum(MAX);
vector<ll> minsum(MAX);
int main() {
	ios::sync_with_stdio(false);
	int n,i,j;
	cin>>n;
	for(i=0;i<3*n;i++)
		cin>>a[i];
	ll sum1=0,sum2=0;
	priority_queue<ll> mx;
	priority_queue<ll,vector<ll>,greater<ll> > mn;
	for(i=0,j=3*n-1;i<n,j>=2*n;i++,j--){
		sum1+=a[i];
		sum2+=a[j];
		mn.push(a[i]);
		mx.push(a[j]);
	}
	maxsum[0]=sum1;
	minsum[0]=sum2;
	for(;i<2*n,j>=n;i++,j--){
		maxsum[i-n+1]=maxsum[i-n];
		minsum[2*n-j]=minsum[2*n-j-1];
		if(mn.top()<a[i]){
			maxsum[i-n+1]+=a[i]-mn.top();
			mn.pop();
			mn.push(a[i]);
		}
		if(mx.top()>a[j]){
			//cout<<mx.top()<<endl;
			minsum[2*n-j]+=a[j]-mx.top();
			mx.pop();
			mx.push(a[j]);
		}
	}
	/*for(int i=0;i<=n;i++)
		cout<<maxsum[i]<<" "<<minsum[i]<<endl;*/
	ll ans=LLONG_MIN;
	for(i=0,j=n;i<=n,j>=0;i++,j--){
		ans=max(ans,maxsum[i]-minsum[j]);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

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

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  
  string s;
  cin >> s;

  int n = SZ(s);
  vi dp(n + 1);
  ll ans = 0;

  for (int i = n - 2; i >= 0; --i) {
    if (s.substr(i, 2) == "BC") {
      dp[i] = dp[i + 2] + 1;
    } else if (s[i] == 'A') {
      dp[i] = dp[i + 1];
      ans += dp[i];
    }
  }

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



Measured memory_bytes: 1300
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

int main(void){
  int N;
  cin >> N;
  int sum = keta_sum(N);
  if (N%sum == 0) cout << "Yes" << endl;
  else cout <<"No" << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  int n=s.length();
  s+="..";
  vector<vector<int>> dp(n+5,vector<int>(3,0));
  dp[0][0]=1;
  dp[1][1]=1;
  if(s[0]!=s[1])dp[1][0]=2;
  dp[2][0]=dp[1][1]+1;
  if(s[1]!=s[2])dp[2][0]=max(dp[2][0],dp[1][0]+1);
  dp[2][1]=2;

  for(int i=3;i<n;++i){
      dp[i][0]=dp[i-1][1]+1;
      dp[i][1]=dp[i-2][0]+1;
      if(s[i]!=s[i-1])dp[i][0]=max(dp[i][0],dp[i-1][0]+1);
      //if(s.substr(i-1,2)!=s.substr(i-3,2))dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
  }
  /*
  rep(i,n){
      cout<<dp[i][0]<<" ";
  }
  cout<<endl;
  rep(i,n){
      cout<<dp[i][1]<<" ";
  }
  cout<<endl;
  */
  cout<<max(dp[n-1][0],dp[n-1][1])<<"\n";
  return 0;
}

Measured memory_bytes: 14484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	for(ll i=0;i<3;i++){
		cout <<s[i];
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int pl,cn,wi,cs;
    while(cin>>pl,pl){
        cin>>cn>>wi>>cs;
        vector<string> vs,ans;
        string s;
        cin.ignore();
        while(getline(cin,s),s!="?"){
            if(s.size()==0) vs.pb(string(wi,'.'));
            else if(s.size()<=wi){
                while(s.size()%wi!=0) s+='.';
                vs.pb(s);
            }
            else{
                int curl=0;
                while(s.size()-curl>=wi){
                    vs.pb(s.substr(curl,wi));
                    curl+=wi;
                }
                if(curl!=s.size()){
                    string ls=s.substr(curl);
                    while(ls.size()%wi!=0) ls+='.';
                    vs.pb(ls);
                }
            }
        }
        int nump=(vs.size()-1)/(cn*pl)+1;
        if(vs.empty()) nump=0;
        string sp(cs,'.');
        string pad(wi,'.');
        rep(k,nump){
            rep(i,cn){
                rep(j,pl){
                    if(vs.size()>k*pl*cn+(j+i*pl)){
                        if(i==0) ans.pb(vs[k*pl*cn+(j+i*pl)]);
                        else ans[k*pl+j+k]+=sp+vs[k*pl*cn+(j+i*pl)];
                    }
                    else{
                        if(i==0) ans.pb(pad);
                        else ans[k*pl+j+k]+=sp+pad;
                    }
                }
            }
            ans.pb("#");
        }
        ans.pb("?");
        rep(i,ans.size()) cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>

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

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

	if (a > b) {
		d = b;
		b = a;
		a = d;
	} 
	
	if (b > c) {
		d = c;
		c = b;
		b = d;
	}

	if (a > b) {
		d = b;
		b = a;
		a = d;
	}

	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;


int main(void)
{
	int N, T;

	cin >> N >> T;

	int cost = 1001;
	for(int i = 0; i < N; ++i)
	{
		int ci, ti;
		cin >> ci >> ti;
		if(T >= ti)
		{
			if(cost >= ci)
			{
				cost = ci;
			}
		}
	}

	if(cost == 1001)
	{
		cout << "TLE" << endl;
	}
	else
	{
		cout << cost << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// Problem : B - Mix Juice
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
//#define int ll
const int MOD = 1000000007;

int a[1005];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int k, n; cin >> n >> k;
    rep(i, n) cin >> a[i];
    sort(a, a+n);
    ll ans = 0;
    rep(i, k) ans += a[i];
    cout << ans << endl;
}



Measured memory_bytes: 3656
import Foundation

let line = readLine()!.components(separatedBy: " ")

let A = Double(line[0])!
let B = Double(line[1])!
let H = Double(line[2])!
let M = Double(line[3])!

let T = H * 60.0 + M

let a = T / 720.0 * 360 * Double.pi / 180.0
let b = M / 60.0 * 360 * Double.pi / 180.0

let ax = A * sin(a)
let ay = A * cos(a)
let bx = B * sin(b)
let by = B * cos(b)
let distance = sqrt(pow(ax - bx, 2) + pow(ay - by, 2))
print(distance)


Measured memory_bytes: 14828
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a * b << " " << 2 * a + 2 * b << endl;
}


Measured memory_bytes: 3116
import sys
import math
n, m = map(int, input().split())
mod = 10 ** 9 + 7
if n == m:
    ans = math.factorial(n) % mod
    ans = (ans * math.factorial(m)) % mod
    ans = (ans * 2) % mod
elif abs(n - m) >= 2:
    ans = 0
else:
    ans = math.factorial(n) % mod
    ans = (ans * math.factorial(m)) % mod
print(ans)

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

using namespace std;
using ll = long long;

int main() {
	
	ll N, M, tmp;
	priority_queue<ll> A;
	
	cin >> N >> M;
	for(int i=0; i<N; i++) {
		cin >> tmp;
		A.push(tmp);
	}
	
	ll c;
	for(int i=0; i<M; i++) {
		c = A.top();
		A.pop();
		A.push(c/2);
	}
	
	ll f = 0;
	for(int i=0; i<N; i++) {
		f += A.top();
		A.pop();
	}
	cout << f << endl;
	
	return 0;
}


Measured memory_bytes: 1400
from itertools import combinations_with_replacement as comb_rplc

N, M, Q = list(map(int, input().split()))
A = []
B = []
C = []
D = []
for i in range(Q):
    in1, in2, in3, in4 = list(map(int,input().split()))
    A.append(in1 - 1)
    B.append(in2 - 1)
    C.append(in3)
    D.append(in4)
    
ans = 0
for seq in comb_rplc(range(1, M + 1), N):
    temp = 0
    for i in range(Q):
        if seq[B[i]] - seq[A[i]] == C[i]:
            temp += D[i]
        ans = max(ans, temp)
print(ans)

Measured memory_bytes: 73572
def Judge(x,y):
    if(x<y):
        print("<")
    elif(x==y):
        print("=")
    elif(x>y):
        print(">")

txt = input()
dic = txt.split(" ")

x = int(dic[0], 16)
y = int(dic[1], 16)

Judge(x,y)


Measured memory_bytes: 3060
import itertools

n, m, q = map(int, input().split())
abcd = [0] * q
for i in range(q):
    a, b, c, d = map(int, input().split())
    abcd[i] = [a, b, c, d]

pat = list(itertools.combinations_with_replacement(range(1, m+1), n))

ans = 0
for l in pat:
    cnt = 0
    for i in range(q):
        if l[abcd[i][1]-1] - l[abcd[i][0]-1] == abcd[i][2]:
            cnt += abcd[i][3]
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 21628
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
    [n] <- readInt
    t   <- concat <$> replicateM n readInt
    print $ foldr1 lcm t



Measured memory_bytes: 508
#include <stdio.h>
int main()
{
	int n;
	int i = 1;
	while(1){
		scanf("%d", &n);
		if(n == 0){
			break;
		} else {
			printf("Case %d: %d\n", i, n);
			i++;
		}
	}
	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a == 3) {
        ans += 100000;
    }
    else if (a == 2) {
        ans += 200000;
    } else if (a == 1) {
        ans += 300000;
    }
    if (b == 3) {
        ans += 100000;
    }
    else if (b == 2) {
        ans += 200000;
    } else if (b == 1) {
        ans += 300000;
    }
    if (a == b && a == 1) ans += 400000;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;

int main()
{
	int N, A, B;
	cin >> N;
	cin >> A;
	cin >> B;
	if (N * A <= B)
	{
		cout << N * A << endl;
	}
	else if (N * A > B)
	{
		cout <<  B << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc084.contest.atcoder.jp/tasks/abc084_d>
問題文============================================================
 「N も (N+1)÷2 も素数」を満たす奇数 N を 2017に似た数 とします。
 
 Q 個のクエリが与えられます。
 
 クエリ i(1≦i≦Q) では奇数 li,ri が与えられるので、
 li≦x≦ri かつ 2017に似た数 となる奇数 x の個数を求めてください。
=================================================================

解説=============================================================

================================================================
*/
const ll MAX_PRIME = 100000;
vector<int> primes(MAX_PRIME + 1);
vector<int> is_prime(MAX_PRIME + 1,true);
vector<int> prime2017(MAX_PRIME + 1,0);
vector<int> cusum(MAX_PRIME + 1,0);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}

void init(){
    init_primes();
    for(int i = 1; i <= MAX_PRIME; i++){
        if(is_prime[i] && is_prime[(i+1)/2]){
            prime2017[i] = true;
        }
    }
    for(int i = 0; i < MAX_PRIME;i++){
        cusum[i+1] = cusum[i] + prime2017[i+1];
    }
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    init();
    ll Q; cin >> Q;
    while(Q--){
        ll l,r; cin >> l >> r;
        cout << cusum[r] - cusum[l-1] << endl;
    }
	return 0;
}


Measured memory_bytes: 2424
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7;
const int larg = 1e5;

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

int main() {
	int N;
	int a[100];
	cin >> N;
	rep(i, N){
		cin >> a[i];
	}
	sort(a, a+N);
	int sum = 0;
	rep(i, N){
		if(i%2 == 0) sum += a[N-i-1];
		else sum -= a[N-i-1];
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll X; cin >> X;
    if (X>29) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<math.h>

typedef struct {
  double x, y;
} Point;

void print(Point );
void kock(int, Point , Point );

int main(){
  Point p1, p2;
  int n;
  
  scanf("%d", &n);
  
  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  print(p1);
  kock(n, p1, p2);
  print(p2);
  
  return 0;
}
void print(Point p){
  printf("%.8f %.8f\n", p.x, p.y);
}

void kock(int n, Point p1, Point p2){

  Point s, t, u;
  double rad = 60.0*(acos(-1)/180.0);

  if ( n == 0 ) return;
  
  s.x = (2.0 * p1.x + 1.0 * p2.x)/3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y)/3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x)/3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y)/3.0;
  u.x = (t.x - s.x) * cos(rad) - (t.y - s.y ) * sin(rad) + s.x;
  u.y = (t.x - s.x) * sin(rad) + (t.y - s.y ) * cos(rad) + s.y;
  
  kock(n-1, p1, s);
  print(s);
  kock(n-1, s, u);
  print(u);
  kock(n-1, u, t);
  print(t);
  kock(n-1, t, p2);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  map<int, string> mps;

  int ac = 0;
  int wa = 0;
  rep (i, m) {
    int x;
    string s;
    cin >> x >> s;
    if (s == "WA" && mps[x] != "AC") {
      ++mp[x];
    } else if (s == "AC" && mps[x] != "AC") {
      ++ac;
      mps[x] = "AC";
    }
  }

  for (int i = 1; i <= n; i++) {
    if (mps[i] == "AC") {
      wa += mp[i];
    }
  }
  cout << ac << " " << wa << endl;


  return 0;
}


Measured memory_bytes: 16112
fn main() {
    let n: i32 = read();
    println!("ABC{}", n);
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 10e9 as u64 + 7;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

Measured memory_bytes: 4352
def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999
    maxnum = 0
    if depth > 0 and d < D:
        for i in range(26):
            point = p
            point += s[d][i]
            point += changepoint(c, d, i, last)
            nlast = []
            nlast.extend(last)
            nlast[i] = d
            z, point = choose(D, c, s, d+1, nlast, depth-1, point)
            if point > maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, p


def changepoint(c, d, num, last):
    point = 0
    for j in range(26):
        if j != num:
            point -= c[j]*(d-last[j])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 2, 0)
        print(num+1)


main()


Measured memory_bytes: 69148
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a=int(input())
s=input()
if a<3200:
    print("red")
else:
    print(s)

Measured memory_bytes: 10276
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	string a,b;
	cin>>a>>b;
	if(a.at(0)==b.at(2)&&a.at(1)==b.at(1)&&a.at(2)==b.at(0)){
		ce("YES")
	}else{
		ce("NO")
	}
	
}

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

typedef long long ll;
using namespace std;
int main()
{
	int a;
	cin >> a;
	if (a < 1200) {
		cout << "ABC" << endl;
	}
	if (1200 <= a) {
		cout << "ARC" << endl;
	}
}

Measured memory_bytes: 256
import numpy as np
n, k = list(map(int, input().split()))
r, s ,p = list(map(int, input().split()))
e = input()

e_list = np.array(list(map(int, list(e.replace("r", "0").replace("s", "1").replace("p", "2")))))
score_map = [p, r, s]

ans = 0
for i in range(k):
    e = list(e_list[i:][::k])
    now = -2
    score = 0
    for ee in e:
        if ee == now:
            now = -1
        else:
            now = ee
            score += score_map[now]
    ans += score
#     print(e, ans)

print(ans)

Measured memory_bytes: 17088
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(Arr.length!=0){
   var result=[];
   var NT=(Arr.shift()).split(" ").map(Number);
   for(var i=0;i<NT[0];i++){
      var arr=(Arr.shift()).split(" ");
      var a=arr[0].split(":").map(function(v){return parseInt(v,10);});
      if(i>0){
         var A=a[0]*60+a[1];
         var B=b[0]*60+b[1];
         if(A-B>=NT[1])result.push(c+" "+(A-B));
      }
      var b=arr[2].split(":").map(function(v){return parseInt(v,10);});
      var c=arr[3];
   }
   if(result.length==0){
      console.log(0);
   }else{
      console.log(result.length);
      result.forEach(function(v){
         console.log(v);
      });
   }
}

Measured memory_bytes: 7648
#include<iostream>
using namespace std;
int main()
{
	int H, W;
	while (true)
	{
		cin >> H >> W;
		if (!H || !W)
			break;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
				if (i % 2 != 0)
				{
					if (j % 2 != 0)
						cout << '#';
					else
						cout << '.';
				}
				else
				{
					if (j % 2 != 0)
						cout << '.';
					else
						cout << '#';
				}
			cout << endl;
		}
		cout << endl;
	}
}


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

int main()
{
	int N;
	cin >> N;
	ll T, res = 1;
	while (N--) {
		cin >> T;
		res = res / __gcd(res, T) * T;
	}
	cout << res << endl;
	return 0;
}


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

int main (){
    double a,b,c,s,l,h,seigen,yogen;
    double pai =3.1415926;

    scanf("%lf %lf %lf",&a,&b,&c);
    seigen = sin(c/180*pai);
    yogen = cos(c/180*pai);
    s=a*b*seigen/2;
    l=a+b+sqrt(a*a+b*b-2*a*b*yogen);
    h=b*seigen;
    printf("%f\n%f\n%f\n",s,l,h);

    return 0;
}

Measured memory_bytes: 648
N = int(input())
S = input()
from collections import deque
C =[deque([]),deque([]),deque([])]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = len(C[0])*len(C[1])*len(C[2])

for i in C[0]:
    for j in C[1]:
        if max(i,j) + abs(j-i)<N and S[max(i,j) + abs(j-i)] == "B":
            count -= 1
        if min(i,j) - abs(j-i)>=0 and S[min(i,j) - abs(j-i)] == "B":
            count -= 1
        if (i + j)%2 == 0 and S[(i + j)//2] == "B":
            count -= 1


print(count)


Measured memory_bytes: 9612
N,M,X = map(int,input().split())
C = []
A = []
for i in range(N):
    CA = list(map(int,input().split()))
    C.append(CA[0])
    A.append(CA[1:])

ans = float('inf')
for n in range(2**N):
    a = [0]*M
    c = 0
    for i in range(N):
        if n&(2**i)==2**i:
            for j in range(M):
                a[j] += A[i][j]
            c += C[i]
    f = True
    for i in range(M):
        if a[i] < X:
            f = False
    if f:
        ans = min(ans,c)

if ans==float('inf'):
    ans = -1

print(ans)

Measured memory_bytes: 68580
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
int a[2];
int main(void)
{
	int n,res=1,t=1,k,i;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&k);
		a[k%2]++;
	}
	FOR(i,0,n) res*=3;
	FOR(i,0,a[0]) t*=2;
	printf("%d\n",res-t);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, L, Q, W, H, T, X, Y, S;

int main()
{
    cin >> N >> K;
    vector<ll> card(N);
    for (auto& i : card)
        cin >> i;

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

    int needMax = 0;
    for (int start = 0; start < card.size(); ++start) {
        ll sum = 0;
        int len = start;
        for (int j = start; j < card.size(); ++j) {
            sum += card[j];
            len++;
            if (sum >= K) {
                needMax = max(needMax, len);
                sum -= card[j];
            }
        }
    }

    cout << N - needMax << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
bool dp[46][100000];
bool vis[100000];
int main() {
	int K;
	cin >> K;
	dp[1][1] = 1;
	for (int i = 1; i <= 45; i++) {
		memset(vis, 0, sizeof(vis));
		for (int j = 1; j < K; j++) {
			if (!dp[i][j] || vis[j]) continue;
			vis[j] = 1;
			int now = (j * 10) % K;
			while (!vis[now]) {
				dp[i][now] = vis[now] = 1;
				now = (now * 10) % K;
			}
		}
		if (dp[i][0]) {
			cout << i << endl;
			break;
		}
		for (int j = 1; j < K; j++) {
			if (!dp[i][j]) continue;
			for (int k = 1; k <= 9; k++) {
				if (i + k > 45) break;
				dp[i + k][(j * 10 + k) % K] = 1;
			}
		}
	}
}

Measured memory_bytes: 4224
sx, sy, tx, ty = map(int, input().split())

u = "U" * (ty - sy)
d = "D" * (ty - sy)
r = "R" * (tx - sx)
l = "L" * (tx - sx)

s1 = u + r 
s2 = d + l
s3 = "LU" + s1 + "RD"
s4 = "RD" + s2 + "LU"
print(s1 + s2 + s3 + s4)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;

int main()
{
  int N, c;
  c = 0;
  cin >> N;
  int res = N;

  while(1)
  {
    c += res % 10;
    res /= 10;
    if(res == 0)
    break;
  }
  if(N % c == 0)
  {
    cout << "Yes";
  }else{
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

s = input()
n = len(s)

ans = [0] * n
p = []
for i in range(n - 1):
    if s[i] == 'R' and s[i + 1] == 'L':
        p.append(i)
        ans[i] += 1
        ans[i + 1] += 1

for i, c in enumerate(s):
    if ans[i] > 0:
        continue
    if c == 'L':
        to = bisect_left(p, i) - 1
    else:
        to = bisect_left(p, i)
    # dist = abs(i - p[to])
    # print(p[to], dist)
    # if dist % 2 == 0:
    if (i - p[to]) % 2 == 0:
        ans[p[to]] += 1
    else:
        ans[p[to] + 1] += 1
print(*ans)


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



int main(){
  
  int64_t a,b,x;
  cin>>a>>b>>x;
  
  int64_t bi=b/x;
  int64_t ai=a/x;
  
  if(a%x==0) cout<<bi-ai+1<<endl;
  else cout<<bi-ai<<endl;
}

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

namespace ALDS1_4_C2
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int N = int.Parse(input);

            HashSet <string>  dict = new HashSet<string>();

            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine();
                string[] command = input.Split(' ');

                switch (command[0])
                {
                    case "insert":
                        dict.Add(command[1]);
                        break;

                    case "find":
                        if (dict.Contains(command[1]))
                        {
                            Console.WriteLine("yes");
                        } else
                        {
                            Console.WriteLine("no");
                        }
                        break;
                }
            }
        }
    }
}

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

int main() {
  int A,B;
  cin >>A>>B;
  int C=13;
  int ans=0;
  for(int i=0;i<10000;i++){
    int D=C*0.08;
    int E=C*0.10;
    if(i==9999){
      cout<<-1<<endl;
      break;
    }
    else if(D==A){
      ans++;
      if(E==B){
        ans++;
        if(ans==2){
          cout<<C<<endl;
          break;
        }
        else{
          ans*=0;
          C++;
        }
      }
      else{
        ans*=0;
        C++;
      }
    }
    else{
      ans*=0;
      C++;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
 
public class Main
{
    public static void main(String[] args)
    {
	Scanner cin = new Scanner(System.in);
	int N = cin.nextInt();
	for(int i=1; i<=N; i++){
		int[] len = new int[3];
		for(int j=0; j<3; j++){ len[j] = cin.nextInt();}
		Arrays.sort(len);
		if(len[0]*len[0] + len[1]*len[1] == len[2]*len[2]){System.out.println("YES");} else{System.out.println("NO");}
	}
    }
}

Measured memory_bytes: 12000
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int A,B,X;
	cin>>A>>B>>X;
	int MIN = A;
	int MAX = A+B;
	if(A<=X && X<=MAX){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
int A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
int max_value = 0, max_index = 0;
int min_value = MAX, min_index = 0;
int sum = 0;

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

int main() {
    cin >> N >> M;
    int x_max = -100, x;
    int y_min = 100, y;
    cin >> x >> y;
    x_max = max(x_max, x);
    y_min = min(y_min, y);
    rep(i, N){
        cin >> x;
        x_max = max(x_max, x);
    }
    rep(i, M){
        cin >> y;
        y_min = min(y_min, y);
    }
    if(x_max<y_min) cout << "No War";
    else cout << "War";
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int main()
{
    char c;
    cin >> c;

    if (c == 'A')
    {
        cout << 'T';
    }

    if (c == 'T')
    {
        cout << 'A';
    }
    if (c == 'C')
    {
        cout << 'G';
    }
    if (c == 'G')
    {
        cout << 'C';
    }

    return 0;
}

Measured memory_bytes: 256
n = input()
a = list(map(int, input().split()))

a.sort(reverse=True)

ans = a[0]

mid = int(len(a) / 2)
for i in range(1, mid):
    ans = ans + a[i] * 2
if len(a) % 2 == 1:
    ans = ans + a[mid]

print(ans)


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

int main(){
  string s;
  cin >> s;
  int cnt1, cnt2;
  cnt1 = cnt2 = 0;
  REP(i, s.length()){
    if(i % 2 && s[i] == '0'){
      cnt1++;
    }
    else if(i % 2 == 0 && s[i] == '1')
      cnt1++;
    if(i % 2 && s[i] == '1'){
      cnt2++;
    }
    else if(i % 2 == 0 && s[i] == '0')
      cnt2++;
  }
  cout << min(cnt1, cnt2) << endl;
  
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5+10;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

int main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int K, ti = 0, tn = 0;
    string isono[128], nakajima[128];
    cin >> K;
    REP(i,K){
    	cin >> isono[i];
    }
    REP(i,K){
    	cin >> nakajima[i];
    }
    
    string win("");
    REP(i,K){
    	if(isono[i] == "tameru"){
    		if(nakajima[i] == "kougekida"){
    			if(tn == 0){
    				win = "Isono-kun";
    			}
    			else{
    				win = "Nakajima-kun";
    			}
    			break;
    		}
    		else if(nakajima[i] == "tameru"){
    			tn = min(tn + 1, 5);
    		}
    		ti = min(ti + 1, 5);
    	}
    	else if(isono[i] == "kougekida"){
    		if(nakajima[i] == "tameru"){
    			if(ti == 0){
    				win = "Nakajima-kun";
    			}
    			else{
    				win = "Isono-kun";	
    			}
    			break;
    		}
    		else if(nakajima[i] == "kougekida"){
    			if(ti == tn){
    				ti = tn = 0;
    			}
    			else if(ti > tn){
  	    			win = "Isono-kun";
    				break;   				
    			}
    			else if(ti < tn){
 	    			win = "Nakajima-kun";
    				break;
    			}
    		}
    		else if(nakajima[i] == "mamoru"){
    			if(ti == 5){
     	    		win = "Isono-kun";
     	    		break;
    			}
    			else if(ti == 0){
    				win = "Nakajima-kun";
    				break;
    			}
    			else{
    				ti = 0;
    			}
    		}
    	}
    	else if(isono[i] == "mamoru"){
    		if(nakajima[i] == "kougekida"){
    			if(tn == 5){
  	    			win = "Nakajima-kun";
  	    			break;
    			}
    			else if(tn == 0){
    				win = "Isono-kun";
    				break;
    			}
    			else{
    				tn = 0;
    			}
    		}
    		else if(nakajima[i] == "tameru"){
    			tn = min(tn + 1, 5);
    		}
    	}
    }
    if(win == ""){
    	cout << "Hikiwake-kun" << endl;
    }
    else{
    	cout << win << endl;
    }
	return 0;
}

Measured memory_bytes: 1224
open System
open System.Linq;


let input = stdin.ReadLine().Split()|>Array.map int
let N=input.[0]
let K=input.[1]
let h = stdin.ReadLine().Split()|>Array.map int
[<EntryPoint>]
let sf argv =
    h
    |>Seq.sumBy (fun x -> if (x >= K) then 1 else 0)
    |>printfn "%d"
    0 

Measured memory_bytes: 20828
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def main():
    N, M = in_nn()

    ans = 1
    for i in sorted(make_divisors(M), reverse=True):
        if i * N <= M and M % i == 0:
            ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
#include <stdio.h>

int main()
{
    
    int a,b,c;
 
    scanf("%d %d %d",&a,&b,&c);
    
    if((a<b)&&(b<c))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
   

    return 0;
}

Measured memory_bytes: 580
#include <iostream>

using namespace std;

int main()
{
    int x, a, b;
    cin >> x;
    bool found = false;

    for (long long i = -200; i <= 200; i++)
    {
        for (long long j = -200; j <= 200; j++)
        {
            if(((i*i*i*i*i)- (j*j*j*j*j)) == x)
            {
                cout << i << " " << j;
                found = true;
                break;
            }
            if(found)
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
class UnionFind:
    def __init__(self, size):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.table = [-1 for _ in range(size)]

    # 集合の代表を求める
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    # 併合
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                # 小さいほうが個数が多い
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    # 部分集合とその要素数を返す
    def subsetall(self):
        a = []
        for i in xrange(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

N, M = map(int, input().split())
p = list(map(int, input().split()))

s = UnionFind(N)

for i in range(M):
  a, b = map(int, input().split())
  s.union(a-1,b-1)

ans = 0
for i in range(N):
  if p[i] == i+1: ans +=1
  elif s.find(p[i]-1) == s.find(i): ans+=1
print(ans)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

// ====================================================================

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0; i < h; i++) {
    cin >> g[i];
  }

  int ans = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (g[y][x] == '.') {
        int dist[h][w];
        memset(dist, -1, sizeof(dist));
        dist[y][x] = 0;
        queue<pair<int, int>> que;
        que.push(make_pair(y, x));
        while (!que.empty()) {
          int ny, nx;
          tie(ny, nx) = que.front();
          que.pop();
          for (int i = 0; i < 4; i++) {
            int nexty = ny + dy[i], nextx = nx + dx[i];
            if (nexty >= h || nexty < 0 || nextx >= w || nextx < 0) continue;
            if (g[nexty][nextx] == '.' && dist[nexty][nextx] == -1) {
              dist[nexty][nextx] = dist[ny][nx] + 1;
              que.push(make_pair(nexty, nextx));
            }
          }
        }

        int ma = 0;
        for (int yy = 0; yy < h; yy++) {
          for (int xx = 0; xx < w; xx++) {
            // if (dist[yy][xx] == -1)
            //   cout << 'W';
            // else
            //   cout << dist[yy][xx];
            ma = max(ma, dist[yy][xx]);
          }
          // cout << endl;
        }
        // cout << endl;
        ans = max(ans, ma);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n;
int a[3],b[3];
int dp1[4][10010],dp2[4][25000000];
signed main(){
	cin>>n;
	rep(i,3)cin>>a[i];
	rep(i,3)cin>>b[i];
	for(int i=1;i<=3;i++){
		for(int j=0;j<=n;j++){
			dp1[i][j]=max(dp1[i][j],dp1[i-1][j]);
			dp1[i][j+a[i-1]]+=max(0ll,dp1[i][j]+b[i-1]-a[i-1]);
		}
	}
	int ans=0;
	for(int i=1;i<=3;i++){
		rep(j,n+1){
			ans=max(ans,dp1[i][j]+j);
		}
	}
	n=ans;
	for(int i=1;i<=3;i++){
		for(int j=0;j<=n;j++){
			dp2[i][j]=max(dp2[i][j],dp2[i-1][j]);
			dp2[i][j+b[i-1]]+=max(0ll,dp2[i][j]+a[i-1]-b[i-1]);
		}
	}
	ans=0;
	for(int i=1;i<=3;i++){
		rep(j,n+1){
			ans=max(ans,dp2[i][j]+j);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define in2(x, y) int x,y;cin>>x>>y
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

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

#define lim5 100002
#define lim9 1000000002

int CanMake(int a, int b, int c) {
	if (a < b + c && b < c + a && c < a + b) {
		return 1;
	}
	return 0;
}

int main() {
	in(n);
	bool f = false;

	repp(i, 9) {
		if (n % i == 0 && (n / i) < 10){
			f = true;
			break;
		}
	}

	cout << (f ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _n = stdin.split('\n')[0]
const n = Number(_n)
const nArr = _n.split('').map(Number)

const sum = nArr.reduce((p, c) => p + c)

console.log(n % sum === 0 ? 'Yes' : 'No')


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int qsort_char_compare_ascend(const void* a, const void* b) {
	return *(char*)a - *(char*)b;
}
void ascendOrder(int size, char* array) {//昇順
	qsort(array, size, sizeof(char), qsort_char_compare_ascend);
}

int main() {
	int N; cin >> N;
	vector<string> words;
	for (int i = 0; i < N; i++) {
		char buf[11]; cin >> buf;
		ascendOrder(10, buf);
		string str = buf;
		words.push_back(str);
	}

	sort(words.begin(), words.end());

	long count = 0;
	long k = 0;
	string past = "yahoo";
	for (auto itr = words.begin(); itr != words.end(); itr++) {
		if (*itr != past) {
			if (k >= 2) {
				count += (k * (k - 1)) / 2;
			}
			k = 0;
			past = *itr;
		}
		k++;
	}
	count += (k * (k - 1)) / 2;
	cout << count << endl;;
	return 0;
}


Measured memory_bytes: 5748
#include <iostream>
#include <algorithm>
using namespace std;

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

    int odd = 0;
    for (int i = 1; i <= N; i += 2)
    {
        ++odd;
    }

    cout << fixed << ((double) odd) / N << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcount(x);};
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int n; cin >> n;
    vector<int> x(n),y(n),p(n);
    rep(i,n) cin >> x[i] >> y[i] >> p[i];
    vl ans(n+1,linf);
    vvl tate(1<<n,vl(n,linf)), yoko(1<<n,vl(n,linf));
    rep(bit,1<<n){
        rep(i,n){
            chmin(tate[bit][i], abs(x[i]));
            chmin(yoko[bit][i], abs(y[i]));
            rep(j,n){
                if(bit>>j & 1){
                    chmin(tate[bit][i], abs(x[i] - x[j]));
                    chmin(yoko[bit][i], abs(y[i] - y[j]));
                }
            }
        }
    }
    rep(bit,1<<n){
        int pcnt = pcount(bit);
        int stop = 1;
        for(int sub=bit; stop>0; sub=(sub-1)&bit){
            stop = sub;
            ll sum = 0;
            rep(i,n){
                sum += min(tate[sub][i], yoko[bit-sub][i]) * p[i];
            }
            chmin(ans[pcnt], sum);
        }
    }
    rep(i,n+1) cout << ans[i] << "\n";
}

Measured memory_bytes: 12936