akhauriyash/Code-Regression huggingface dataset:
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2/3/2019, 9:10:55 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;

ll N;
ll K;
ll A[100010];
ll S[60][2];
ll DP[61][2];

int main()
{
  cin >> N >> K;
  for (auto i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  fill(&S[0][0], &S[0][0] + 60 * 2, 0);
  for (auto i = 0; i < 60; i++)
  {
    for (auto j = 0; j < N; j++)
    {
      if ((A[j] >> i) & 1)
      {
        S[i][0] += (1LL << i);
      }
      else
      {
        S[i][1] += (1LL << i);
      }
    }
    cerr << "S[" << i << "][" << 0 << "] = " << S[i][0] << endl;
    cerr << "S[" << i << "][" << 1 << "] = " << S[i][1] << endl;
  }
  DP[60][0] = 0;
  DP[60][1] = -1;
  for (auto i = 60 - 1; i >= 0; i--)
  {
    DP[i][0] = 0;
    DP[i][1] = -1;
    if ((K >> i) & 1)
    {
      DP[i][1] = max(DP[i][1], DP[i + 1][0] + S[i][0]);
      DP[i][0] = max(DP[i][0], DP[i + 1][0] + S[i][1]);
      if (DP[i + 1][1] < 0)
      {
        DP[i][1] = max(DP[i][1], S[i][0]);
      }
      else
      {
        DP[i][1] = max(DP[i][1], DP[i + 1][1] + S[i][0]);
        DP[i][1] = max(DP[i][1], DP[i + 1][1] + S[i][1]);
      }
    }
    else
    {
      DP[i][0] = max(DP[i][0], DP[i + 1][0] + S[i][0]);
      if (DP[i + 1][1] >= 0)
      {
        DP[i][1] = max(DP[i][1], DP[i + 1][1] + S[i][0]);
        DP[i][1] = max(DP[i][1], DP[i + 1][1] + S[i][1]);
      }
    }
    cerr << "DP[" << i << "][" << 0 << "] = " << DP[i][0] << endl;
    cerr << "DP[" << i << "][" << 1 << "] = " << DP[i][1] << endl;
  }
  cout << max(DP[0][0], DP[0][1]) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod=1e9+7;
const int nax=1e5+10;
int par[nax];
int root(int v){return par[v] < 0 ? v : (par[v] = root(par[v]));}
int merge(int x,int y){
    if((x = root(x)) == (y = root(y))) return 0 ;
	if(par[y] < par[x])	swap(x, y);
	par[x] += par[y];
	par[y] = x;
	return 1;
}
int main(){
	IOS;
	ll n,m;
	cin>>n>>m;
	pair<int,int>a[m];
	for (int i = 0; i < nax; ++i)
	{
		par[i]=-1;
	}
	for (int i = 0; i < m; ++i)
	{
		cin>>a[i].first>>a[i].second;
	}
	ll ans[m];
	ll tot=(n*(n-1))/2;
	for(int i=m-1;i>=0;--i){
		ans[i]=tot;
		ll x=root(a[i].first);
		ll y=root(a[i].second);
		if(x==y) continue;
		x=-par[x];
		y=-par[y];
		tot-=x*y;
		merge(a[i].first,a[i].second);
	}
	for (int i = 0; i < m; ++i)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

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

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

    vector<int> m(N+1);
    for (int i=1; i<N+1; i++) cin >> m.at(i);

    sort(m.begin(), m.end());
    int count = N;
    for (int i=1; i<N+1; i++) {
        X -= m.at(i);
    }
    while (X >= 0) {
        X -= m.at(1);
        count++;
    }
    cout << count -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,count=0;
cin >> n;
int a[n];
for (int i=0;i<n;i++){
cin >> a[i];
}
for (int i=0;i<n+1;i++){
if (a[i]==a[i+1]){
int jcount=2;
bool wsx=false;
for(int j=i+1;j<n;j++){
if (a[j]==a[j+1])jcount++;
else break;
}
i+=jcount-1;
count+=jcount/2;
}
}
cout << count << endl;
}

Measured memory_bytes: 256
H, W, N = map(int, input().split())
import sys
M = 10**9+7
def C(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % M

NNN = (2*10**5)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % M )
    inverse.append( ( -inverse[M % i] * (M//i) ) % M )
    g2.append( (g2[-1] * inverse[-1]) % M )

vs = []
for _ in range(N):
    X, Y = map(int, input().split())
    vs.append((X,Y))

d = [0] * N
d2 = [0] * N
vs.sort()
for i in range(N-1,-1,-1):
    x, y = vs[i]
    d2[i] = C(x+y-2,x-1)
    r = C(H-x+W-y, H-x)
    for j in range(N-1,i,-1):
        v, w = vs[j]
        r = (r - C(v-x+w-y, v-x) * d[j])%M
    d[i] = r
r = 0
for i in range(N):
    r = (r + d[i]*d2[i]%M)% M
r = (C(H+W-2, H-1) - r)%M
print(r)


Measured memory_bytes: 80880
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	REP(i, n) cin >> h[i];
	vector<ll> dp(n, INF * INF);
	dp[0] = 0;
	FOR(i, 1, n) {
		for(ll j = i - k; j <= i; j++) {
			if(j < 0) continue;
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	var result = "No"
	var ii int
	for ii = 0; ii <= 9; ii++ {
		var jj int
		for jj = 0; jj <= 9; jj++ {
			if ii*jj == n {
				result = "Yes"
				break
			}
		}
	}
	fmt.Printf("%s\n", result)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200003;
int n,k,cnt[MaxN];
int main() {
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;++i) {
        int x;
        scanf("%d",&x);
        cnt[x]++;
    }
    sort(cnt,cnt+MaxN);
    int i=0;
    while (!cnt[i]) i++;
    int sum=0;
    for (;i<=MaxN-k-1;++i) sum+=cnt[i];
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 1024
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;


int main(){
    IOS
    //freopen("output.txt","w",stdout);

    double r;
    cin>>r;
    cout<<2.0*pi*r<<"\n";
}


Measured memory_bytes: 3828
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		String s = sc.next();
		sc.close();
		int[] a = new int[4];
		for(int i = 0 ; i < 4 ; i++) a[i] = s.charAt(i) - 48;
		int sum , nn;
		int[] b = new int[3];
		char[] q = new char[3];
		for(int i = 0 ; i < 8 ; i++){
			nn = i;
			sum = a[0];
			for(int j = 0 ; j < 3 ; j++){
				b[j] = 1 & nn;
				nn /= 2;
				if(b[j] == 0){
					sum += a[j + 1];
					q[j] = '+';
				}else{
					sum -= a[j + 1];
					q[j] = '-';
				}
			}
			if(sum == 7){
				ou.print("" + a[0] + q[0] + a[1] + q[1] + a[2] + q[2] + a[3] + "=7\n");
				break;
			}
		}
		ou.flush();
    }
}

Measured memory_bytes: 41176
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;

int main(){
    int N,K;
    cin >> N >> K;
    int ans = 0;
    REP(i,N){
        int x;
        cin >> x;
        ans += 2*min(x,K-x);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N,A,B;
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
// #define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const int mod=1000000007;
const int inf=1e9;
const int N=2e6+10;

ll n,m,k;
ll a[N],b[N];

bool chk(int tot)
{
	// check(tot);
	bool ans=0;
	if(tot<=n and a[tot-1] <=k) return 1;
	if(tot<=m and b[tot-1] <=k) return 1;
	for(int i=0;i<=tot;i++)
	{
		int x=i;
		int y=tot-i;
		if(x>n or y>m) continue;
		ll sum=0;
		if(x) sum+=a[x-1];
		if(y) sum+=b[y-1];
		// check(sum);
		if(sum<=k) return 1;
	}
	
	return ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
    cin>>n>>m>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];
    for(int i=1;i<n;i++) a[i]+=a[i-1];
    for(int i=1;i<m;i++) b[i]+=b[i-1];
    int l=0,r=n+m+1;
	while((r-l)>1)
	{
		// check(l);check(r);
		int mid=(l+r)/2;
		if(chk(mid)) l=mid;
		else r=mid;
	}
	cout<<l;

    

    

    return 0;
} 

Measured memory_bytes: 6776
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long a, b;
    scan(a, b);
    writeln((a - 1) * (b - 1));
}


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

int main()
{
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  vector<int> res(4,0);
  cin >> n;
  string s;
  for(int i = 0;i<n;i++){
    cin >> s;
    if(s == "AC")res[0]++;
    if(s == "WA")res[1]++;
    if(s == "TLE")res[2]++;
    if(s == "RE")res[3]++;
  }
  cout << "AC x " << res[0] << endl;
  cout << "WA x " << res[1] << endl;
  cout << "TLE x " << res[2] << endl;
  cout << "RE x " << res[3] << endl;

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
string d;
const int D = 22;
ll mem[D][D][2][2];
ll C(int i, int j, bool carry_left, bool carry_right) {
    ll& ans = mem[i][j][carry_left][carry_right];
    if(ans == -1) {
        if(i > j) {
            ans = carry_left == carry_right;
        } else if(i == j) {
            ans = 0;
            for(int c = i == 0; c <= 9; c++) {
                int sum = c + d[i] + carry_right;
                ans += (carry_left ? sum >= 10 : sum < 10) and sum % 10 == c;
            }
        } else {
            ans = 0;
            for(int c1 = i == 0; c1 <= 9; c1++) {
                for(int c2 = 0; c2 <= 9; c2++) {
                    int sum1 = c1 + d[i], sum2 = c2 + d[j] + carry_right;
                    if(sum2 % 10 == c1 and (carry_left ? sum1 >= 10 : sum1 < 10) and sum1 % 10 == c2) {
                        ans += C(i + 1, j - 1, false, sum2 >= 10);
                    }
                    if(sum2 % 10 == c1 and (carry_left ? sum1 + 1 >= 10 : sum1 + 1 < 10) and (sum1 + 1) % 10 == c2) {
                        ans += C(i + 1, j - 1, true, sum2 >= 10);
                    }
                }
            }
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> d;
    for(char& c : d) c -= '0';
    memset(mem, -1, sizeof mem);
    ll ans = C(0, d.size() - 1, false, false);
    for(int i = 0; i < 10; i++) {
        reverse(d.begin(), d.end());
        d += char(0);
        reverse(d.begin(), d.end());
        memset(mem, -1, sizeof mem);
        ans += C(0, d.size() - 1, false, false);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c){
        cout << "1" << endl;
    }else if(a == b || b == c || c == a){
        cout << "2" << endl;
    }else{
        cout << "3" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,p[N],x,y,mx0,mx1,ct0,ct1,i,w[N],cnt;
int bi[2][N];
pair<int,int*>op[N*40];int oxb,en[N];
inline void add(int o,int x,int v){
	for(x=n-x+1;x<=n;x+=x&-x)
		op[++oxb]=make_pair(bi[o][x],bi[o]+x),bi[o][x]=max(bi[o][x],v);
}
inline int ask(int o,int x){int ans=-N;for(x=n-x+1;x;x-=x&-x)ans=max(ans,bi[o][x]);return ans;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n;for(i=1;i<=n;++i){cin>>p[i];if(p[i]>x)w[i]=2,x=p[i],++cnt;else w[i]=1;}
	memset(bi[1],250,sizeof bi[1]);
	for(i=n;i;--i){
		x=ask(1,p[i]);y=ask(0,p[i]);
		if(x+w[i]<=cnt)add(1^(w[i]&1),p[i],x+w[i]);
		if(y+w[i]<=cnt)add(w[i]&1,p[i],y+w[i]);en[i]=oxb;
	}
	if(ask(cnt&1,1)!=cnt){cout<<"-1\n";return 0;}
	for(i=1;i<=n;++i){
		for(;oxb>en[i+1];)*op[oxb].second=op[oxb].first,--oxb;
		int nmx1=mx1,nct1=ct1;
		if(p[i]>nmx1)nmx1=p[i],++nct1;
		cnt-=w[i]==2;
		if((cnt+ct0-nct1>=0 && ask((cnt+ct0-nct1)&1,nmx1)>=cnt+ct0-nct1)
			 || (cnt+nct1-ct0>=0 && ask((cnt+nct1-ct0)&1,max(1,mx0))>=cnt+nct1-ct0))cout<<'0',mx1=nmx1,ct1=nct1;
			else{cout<<'1';if(p[i]>mx0)mx0=p[i],++ct0;}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 63872
#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;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<string> aun(n); for(auto& in:aun) cin >> in;
    stack<int> st;
    for(int i = 0; i < n;i++){
        if(aun[i][0] == 'A'){
            st.push(1);
        }else{
            if(st.empty()){ cout << "NO" << endl; return 0;}
            st.pop();
        }
    }
    if(st.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 3220
n, y = map(int, input().split())

flag = False

for i in range(n + 1):
    for j in range(n - i + 1):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            print(i, j, n - i - j)
            exit()

print("-1 -1 -1") 


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
const int maxn=2e5+5;
ll a,b,c,d,ans;
signed main()
{
    //IOS;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>a>>b>>c>>d;
    ans=a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
using namespace std;
using ll = long long;
using LP = pair<ll, int>;
const ll inf = 1e18;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    int si, sj, gi, gj;
    cin >> si >> sj >> gi >> gj;
    si--; sj--; gi--; gj--;
    vector<string> g(h);
    rep(i, h) cin >> g[i];
    auto toId = [&](int i, int j, int v){
        return (i*w+j)*4+v;
    };
    auto modCeil = [&](ll x){
        return (x + k-1)/k*k;
    };
    //ここからダイクストラ
    vector<ll> dist(h*w*4, inf);
    priority_queue<LP, vector<LP>,greater<LP>> que;
    auto push = [&](int i, int j, int v, ll cost){
        int id = toId(i, j, v);
        if (dist[id] <= cost) return;
        dist[id] = cost;
        que.push(LP(cost,id));
    };
    //初期化
    rep(v, 4) push(si, sj, v, 0);
    while(!que.empty()){
        ll cost = que.top().first;
        int id = que.top().second;
        int i = id/4/w;
        int j = id/4%w;
        int v = id%4;
        que.pop();
        if (cost > dist[id]) continue;
        //方向替え
        rep(nv, 4) push(i, j, nv, modCeil(cost));
        //直進
        int ni = i + di[v], nj = j + dj[v];
        if (0 <= ni && ni < h && 0 <= nj && nj < w){
            if (g[ni][nj] == '.') {
                push(ni, nj, v, cost+1);
            }
        }
    }
    ll ans = inf;
    rep(i, 4) ans = min(ans, dist[toId(gi, gj, i)]);
    if (ans == inf) {
        cout << -1 << endl;
    }else
    {
        cout << modCeil(ans)/k << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 44188
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
b = list(map(int,input().split()))
a = [0] * n
a[0] = b[0]
a[-1] = b[-1]
for i,v in enumerate(zip(b,b[1::])):
    a[i+1] = min(v)
print(sum(a))

Measured memory_bytes: 3064
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a, v = geta(int)
    b, w = geta(int)
    t = gete(int)

    if v <= w:
        print("NO")
    elif (v - w) * t >= abs(b - a):
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 64744
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

struct edge{ int to;int cap;int rev; };
int m,n;

vector<edge> G[2012];
bool used[2012];
int a[511],b[511];

void add_edge(int from,int to){
    G[from].PB( (edge){to,1,(int)G[to].size()} );
    G[to].PB( (edge){from,0,(int)G[from].size()-1} );
}

int dfs(int v,int t,int f){
    if( v == t) return f;
    used[v] = true;
    REP(i,G[v].size()){
	edge &e = G[v][i];
	if(!used[e.to] && e.cap > 0){
	    int d = dfs(e.to,t,min(f,e.cap));
	    if(d > 0){
		e.cap -= d;
		G[e.to][e.rev].cap += d;
		return d;
	    }
	}
    }
    return 0;
}

int max_flow(int s,int t){
    int flow = 0;
    while(true){
	REP(i,m+n+2) used[i] = false;
	int f = dfs(s,t,INF);
	if(f == 0)return flow;
	flow += f;
    }
    return -1;
}

int gcd(int a,int b){ return a % b == 0 ? b : gcd(b,a%b); }

int main(){

    while(true){
	m,n;
	cin >> m >> n;
	if(m == 0 && n == 0) break;
	REP(i,n+m+2){
	    G[i].clear();
	}
	REP(i,n+m+2) used[i] = false;
	REP(i,m) {
	    cin >> a[i];
	    add_edge(0,i+1);
	}
	REP(i,n) {
	    cin >> b[i];
	    add_edge(i+1+m,n+m+1);
	}
	REP(i,m){
	    REP(j,n){
		if(gcd(a[i],b[j]) > 1){
		    add_edge(i+1,m+j+1);
		}
	    }
	}
	cout << max_flow(0,n+m+1) << endl;;
    }

    return 0;
}

Measured memory_bytes: 7604
#include <iostream> 
using namespace std; 
  
int main() {
int i;
cin >> i; 
long n, total = 0, min, max;
for(int x = 0; x < i; x++) {
cin >> n;
if(x == 0) {
min = n;
max = n;
}
total = total + n; 
if (n < min) {
min = n;
}
if (n > max) {
max = n;
}
}
cout << min << " " << max << " " << total << endl;
}


Measured memory_bytes: 3108
#include <cstdio>
#include <cstdlib>
#include <stack>
using namespace std;

int main(){
    char s[1000];
    stack<int> S;
    
    while(scanf("%s", s) != EOF){
        int a,b;
        a=b=0;
        if(s[0] == '+'){
            a=S.top();
            S.pop();
            b=S.top();
            S.pop();
            S.push(a+b);
        }else if(s[0] == '-'){
            b=S.top();
            S.pop();
            a=S.top();
            S.pop();
            S.push(a-b);
        }else if(s[0] == '*'){
            a=S.top();
            S.pop();
            b=S.top();
            S.pop();
            S.push(a*b);
        }else{
            S.push(atoi(s));
        }
    }
    printf("%d\n", S.top());
}


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

#define int long long
const int MOD=1e9+7;
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)(res*=n)%=MOD;
    (n*=n)%=MOD;
    k>>=1;
  }
  return res;
}
int Factorial[5234567],Finverse[5234567];
inline void Cinit(){// limit is 5e6 /// write pw /// this takes 792ms at AtCoder
  Factorial[0]=1;
  for(int i=1;i<5e6;i++)Factorial[i]=(Factorial[i-1]*i)%MOD;
  for(int i=0;i<5e6;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 0;if(k<0)return 0;
  if(!Factorial[0])Cinit();
  int res=Factorial[n];
  (res*=Finverse[k])%=MOD;
  (res*=Finverse[n-k])%=MOD;
  return res;
}
signed main(){
  int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
  cout<<((nCk(r2+c2+2,r2+1)-nCk(r1+c2+1,r1)-nCk(r2+c1+1,c1)+nCk(r1+c1,r1))%MOD+MOD)%MOD<<endl;
}


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

int main(){
	int k;
	string s;
	cin >> k >> s;
	int s_long = s.size();

	rep(i, min(k, s_long)){
		cout << s.at(i);
	}
	if(min(s_long, k) < s_long) cout << "...";
	cout << endl;

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll, ll>
#define pb push_back
#define rep0(i, n) for(ll i = 0;i<n;i++)
#define rep1(i, n) for(ll i = 1;i<n;i++)
#define all(v) v.begin(),v.end()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
const int N = 1e6 + 5;

void solve(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}
 
int main()
{
    fast;
    solve();
    // int t;
    // cin >> t;
    // while(t--){
    //     solve();
    // }
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e18L + 5;

void min_self(long long& a,long long b){
  a = min(a,b);
}

int main(){
  int n,w;
  cin>>n>>w;
  int wt[n],v[n];
  int sum = 0;
  for(int i=0;i<n;i++){
    cin>>wt[i]>>v[i];
    sum = sum + v[i];
  }
  vector<long long> dp(sum+1,INF);

  dp[0] = 0;
  for(int i = 0;i<n;i++){
    for(int value_already = sum - v[i];value_already>=0;value_already--){
      min_self(dp[value_already+v[i]],dp[value_already]+wt[i]);
    }
  }
  long long res = 0;
  for(int i =0;i<=sum;i++){
    if(dp[i]<=w){
      res = max(res,(long long) i);
    }
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 1024
import Control.Monad
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as BS
main=do
 [h,w]<-map read.words<$>getLine
 c<-replicateM 10 (map (read.BS.unpack).BS.words<$>BS.getLine)
 a<-replicateM h (map (read.BS.unpack).BS.words<$>BS.getLine)
 print(f (foldr (++) [] a) (g (k (zip [0..9] c)) [10000,0,10000,10000,10000,10000,10000,10000,10000,10000] (S.insert 1 S.empty)))
  where k [] = []
        k ((i,a):c) = (map (\(n,j)->(n,i,j)) (zip a [0..9]))++(k c)
        g c l s | (S.size s)==10 = l
                | otherwise = (\(n,i)->g c ((take i l)++[n]++(drop (i+1) l)) (S.insert i s)) (minimum(p l (m c s)))
        m [] s = []
        m ((a,i,j):c) s = if (not(S.member i s))&&(S.member j s) then ((a,i,j):(m c s)) else (m c s)
        p _ [] = []
        p l ((a,i,j):n) = (a+(l!!j),i):(p l n)
        f [] l = 0
        f (n:a) l = (l!!(abs n))+(f a l)

Measured memory_bytes: 2556
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

char S[200001];

void init();

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

    cin >> S;

    int l, r;
    u64 remain = 0;
    u64 ret = 0;
    for (l = 0; S[l]; ++l)
    {
        if (S[l] == 'A')
        {
            for (r = l + 1; S[r] == 'A'; ++r);
            if (S[r] && S[r + 1] && S[r] == 'B' && S[r + 1] == 'C')
            {
                ret += remain + r - l;
                S[r + 1] = 'A';
                remain = remain + r - l - 1;
                l = r;
            }
            else
            {
                remain = 0;
                l = r;
            }
        }
    }

    cout << ret << "\n";

    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>

using namespace std;

pair <long long, long long> a_neg_b_pair[100000];
int main(){
  int N;
  long long H;
  cin >> N >> H;
  for(int i = 0; i < N; i++){
    long long a;
    long long b;
    cin >> a >> b;
    a_neg_b_pair[i] = make_pair(a, - b);
  }

  sort(a_neg_b_pair, a_neg_b_pair + N);
  long long max_a = a_neg_b_pair[N - 1].first;
  vector <long long> throws;
  for(int i = 0; i < N; i++){
    if(max_a < - a_neg_b_pair[i].second){
      throws.push_back(- a_neg_b_pair[i].second);
    }
  }
  sort(throws.begin(), throws.end());
  reverse(throws.begin(), throws.end());

  long long ans = 0;
  for(int i = 0; i < throws.size(); i++){
    if(H <= 0){
      break;
    }
    H -= throws[i];
    ans ++;
  }

  if(H > 0){
    if(H % max_a == 0){
      ans += H / max_a;
    } else {
      ans += H / max_a + 1;
    }
  }

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

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main() {
  int N, X;
  cin >> N >> X;
  int d = 0, l, ret = 1;
  for (int i = 0; i < N; i++) {
    cin >> l;
    d += l;
    if (d <= X) ret++;
  }
  cout << ret << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  set<int> se;
  int col = 0;
  rep(i, n) {
    int a;
    cin >> a;
    a /= 400;
    if (a >= 8) {
      col++;
      continue;
    }
    se.insert(a);
  }
  cout << max(sz(se), 1) << " " << sz(se) + col << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 1;
  char temp = S[0];
  for (int i = 1; i < N; ++i) {
    if (temp != S[i]) ++ans;
    temp = S[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3296
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    long[] a = new long[n];
    long sum = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      sum += a[i];
    }
    long ans = 0;
    for(long i = 1; (i * i) <= sum; i++) {
      if((sum % i) == 0) {
        long d = i;
        long[] r = new long[n];
        long p = 0;
        for(int j = 0; j < n; j++) {
          r[j] = (a[j] % d);
          if(r[j] > 0) p++;
        }
        if(p == 0) {
          ans = Math.max(ans, d);
        } else { 
          Arrays.sort(r);
          long[] t = new long[n];
          long[] u = new long[n];
          t[0] = r[0];
          u[n - 1] = (d - r[n - 1]);
          for(int j = 1; j < n; j++) {
            t[j] = (t[j - 1] + r[j]);
          }
          for(int j = n - 2; j >= 0; j--) {
            u[j] = (u[j + 1] + d - r[j]);
          }
          long m = 0;
          for(int j = 0; j < n - 1; j++) {
            if((Math.abs(t[j] - u[j + 1]) % d) == 0) {
              if(Math.max(t[j], u[j + 1]) <= k) m++;
            }
          }
          if(m > 0) ans = Math.max(ans, d);
        }
        d = sum / i;
        r = new long[n];
        p = 0;
        for(int j = 0; j < n; j++) {
          r[j] = (a[j] % d);
          if(r[j] > 0) p++;
        }
        if(p == 0) {
          ans = Math.max(ans, d);
        } else { 
          Arrays.sort(r);
          long[] t = new long[n];
          long[] u = new long[n];
          t[0] = r[0];
          u[n - 1] = (d - r[n - 1]);
          for(int j = 1; j < n; j++) {
            t[j] = (t[j - 1] + r[j]);
          }
          for(int j = n - 2; j >= 0; j--) {
            u[j] = (u[j + 1] + d - r[j]);
          }
          long m = 0;
          for(int j = 0; j < n - 1; j++) {
            if((Math.abs(t[j] - u[j + 1]) % d) == 0) {
              if(Math.max(t[j], u[j + 1]) <= k) m++;
            }
          }
          if(m > 0) ans = Math.max(ans, d);
        }
      }
  }
  System.out.println(ans);
}
}

Measured memory_bytes: 38360
n = int(input())
si = [0]*n
for i in range(n):
    si[i] = input()

listarr = []
for s in si:
    arr = list(s)
    arr.sort()
    arr = tuple(arr
    )
    listarr.append(arr)
from collections import Counter

cont = Counter(listarr)
ans = 0
for i in cont.values():
    if i >= 2:
        num = (i*(i-1))//2
        ans += num

print(ans)


Measured memory_bytes: 33424
#include <algorithm>
#include <cstdio>
#include <iostream>
#include<string>
using namespace std;
#define ll long long
const int maxn = 3e5 + 9;
int main() {
    string a;
    cin >> a;
    int len = a.size();
    while(len--)printf("x");
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int x, y;
	for(int i = 1; ; i++){
		scanf("%d %d", &x, &y);
		if((x==0 && y==0))
			break;
		if(x > y)
		printf("%d %d\n", y, x);
		else
			printf("%d %d\n", x, y);
	}
	return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <iomanip>
//#include <cmath>
#include <queue>
#include <deque>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long double ld;
typedef long long ll;
typedef double db;
#define endl '\n'
#define pb push_back
#define pii pair<ll, ll>
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define optimize1() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#pragma warning(disable:4996)

using namespace std;

const int MX = 2e3 + 10;

int fv[4 * MX], n, tmm[2][MX], dp[MX][MX];

void upd(int x, int i) {
	i++;
	while (i < 4 * MX) {
		fv[i] += x;
		i += i & (-i);
	}
}


int sum(int i) {
	i++;
	int ans = 0;
	while (i > 0) {
		ans += fv[i];
		i -= i & (-i);
	}
	return ans;
}


signed main() {
	optimize1();
	cin >> n;
	char c;
	int x;
	for (int i = 0; i < 2 * n; ++i) {
		cin >> c >> x;
		int k = 1;
		if (c == 'W')
			k = 0;
		tmm[k][x - 1] = i;
	}
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
			dp[i][j] = 1e9 + 10;

	dp[0][0] = 0;
	for (int i = 0; i <= n; ++i) {
		if (i > 0)
			upd(1, tmm[0][i - 1]);
		for (int j = 0; j <= n; ++j) {
			if (j > 0)
				upd(1, tmm[1][j - 1]);
			if (i != n)
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + tmm[0][i] - sum(tmm[0][i]));
			if (j != n)
				dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + tmm[1][j] - sum(tmm[1][j]));
		}
		for (int j = 0; j < n; ++j)
			upd(-1, tmm[1][j]);
	}
	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 19372
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

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

int h, w, num;
char c[15][15];
string ans;

bool in(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

bool dfs(int x, int y, int dir, int cnt){
    if(cnt == 1){
        cout << ans << "\n";
        return true;
    }
    for(int i = -1; i <= 1; ++i){
        int nd = (dir + i + 4) % 4;
        int nx = x + dx[nd], ny = y + dy[nd];
        while(in(nx, ny) && c[nx][ny] == '.'){
            nx += dx[nd]; ny += dy[nd];
        }
        if(in(nx, ny)){
            c[x][y] = '.';
            if(nd == 0) ans += 'R';
            if(nd == 1) ans += 'D';
            if(nd == 2) ans += 'L';
            if(nd == 3) ans += 'U';
            if(dfs(nx, ny, nd, cnt - 1)) return true;
            c[x][y] = 'o';
            ans.pop_back();
        }
    }
    return false;
}

int main(){
    scanf("%d%d", &h, &w);
    int sx, sy, dir;
    rep(i, h)rep(j, w){
        scanf(" %c", &c[i][j]);
        num += (c[i][j] != '.');
        if(c[i][j] == 'L') sx = i, sy = j, dir = 2;
        if(c[i][j] == 'R') sx = i, sy = j, dir = 0;
        if(c[i][j] == 'U') sx = i, sy = j, dir = 3;
        if(c[i][j] == 'D') sx = i, sy = j, dir = 1;
    }
    dfs(sx, sy, dir, num);
}


Measured memory_bytes: 3296
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  int N;
  cin>>N;
  string s,t;
  cin>>s>>t;
  int tmp=-1;
  bool ok=false;
  for(int i=0;i<s.size();i++){
    if(s[i]==t[0]){
      for(int k=i;k<s.size();k++){
        if(s[k]!=t[k-i]){
          break;
        }
        if(k==s.size()-1){
          tmp=i;
          ok=true;
        }
      }
    }
    if(ok){
      break;
    }

  }
  if(tmp==-1){
    cout<<s.size()+t.size()<<endl;
  }else{
    cout<<tmp+t.size()<<endl;
  }


}






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

using namespace std;
int main()
{
    unsigned long long a = 0u;
    cin >> a;
    unsigned long long b = 0u;
    cin >> b;
    unsigned long long c = 0u;
    cin >> c;

    if (c < a + b)
    {
        cout << "No" << endl;
    }
    else if (4 * (a * b) < ((c - a - b) * (c - a - b)))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n;
    cin >> n;
    vector<lli> v;
    for1(i, 0, n)
    {
        lli k;
        cin >> k;
        v.pb(k);
    }
    lli ans = 0;
    sort(all(v));
    for1(i, 0, n)
    {
        for1(j, i + 1, n)
        {
            for1(k, j + 1, n)
            {
                if (v[i] + v[j] > v[k] && v[i] != v[j] && v[j] != v[k])
                {
                    ans += 1;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{

    string s;
    cin>>s;
  //  cout<<s<<endl;
    int   n=s.length();
    if(s[0]=='?')
    {
        if(s[1]=='?')
        {
            s[0]='P';
            s[1]='D';
        }
        else
        {
            if(s[1]=='D')
                s[0]='P';
            else
                s[0]='D';
        }
    }

    for(int i=1; i<n; i++)
    {
        if(s[i]=='?')
        {
            if(s[i-1]=='P')
                s[i]='D';
            else
            {
                if(s[i+1]=='D' || s[i+1]=='?')
                    s[i]='P';

                else
                    s[i]='D';

            }
        }
      //  cout<<s<<endl;
    }
    cout<<s<<endl;

}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
const int MOD = 1e9+7;


int main() {
	int N,K;
  	cin >> N >> K;
  	vi d(K);
  	set<int> A;
  	rep(i,K){
    	cin >> d[i];
        rep(j,d[i]){
        	int a;
          	cin >> a;
          	A.insert(a);
        }
    }
  	int n = A.size();
  	cout << N - n << endl;
}

Measured memory_bytes: 3632
n=int(input())
d={"M":0,"A":0,"R":0,"C":0,"H":0}
t=["M","A","R","C","H"]
ans=chk=0
for i in range(n):
    s=input()
    if s[0] in d:
        d[s[0]]+=1
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=d[t[i]]*d[t[j]]*d[t[k]]
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  vector<int> ans(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    int a=0;
    int b=vec.at(i);
      int j=0;
    while(a == 0){
      a = b%2;
        b = b/2;
        if (a == 0){
          j++;
        }
    }
    ans.at(i)=j;
    }
  int aannss=0;
  for (int i=0; i<N; i++){
    aannss = aannss + ans.at(i);
  }
  cout << aannss << endl;
        
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define llint long long

using namespace std;
//typedef pair<llint, llint> P;
typedef pair<llint, string> P;

llint n, Q;
string s[1005];
llint x[1005], y[1005];
vector<P> vec;

int main(void)
{
	while(1){
		cin >> n >> Q;
		if(n == 0 && Q == 0) break;
		
		for(int i = 1; i <= n; i++) cin >> s[i] >> x[i] >> y[i];
		
		llint q;
		for(int i = 1; i <= Q; i++){
			cin >> q;
			for(int j = 1; j <= n; j++){
				if(q >= y[j]-x[j]+1 && q <= y[j]){
					cout << s[j] << " " << x[j]-(y[j]-q) << endl;
					goto end;
				}
			}
			cout << "Unknown" << endl;
			end:;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3248
import itertools
N, M = map(int, input().split())
X, Y, Z = [], [], []
for i in range(N):
    x, y, z = map(int, input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)

ans = 0
for a, b, c in itertools.product([-1, 1], repeat=3):
    tmp = []
    for x, y, z in zip(X, Y, Z):
        tmp.append(a * x + b * y + c * z)
    tmp.sort(reverse=True)
    ans = max(ans, sum(tmp[:M]))

print(ans)


Measured memory_bytes: 3188