akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
lli r,c;

mat f(8,vll(8));

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

bool judge(lli x,lli y){
    for(lli i = 0;i < 8;i++){
        for(lli t = x,s = y;t >= 0 && t < 8 && s >= 0 && s < 8;t += dx[i],s += dy[i]){
            if(f[t][s] == 1) return false;
        }
    }
    return true;
}

bool dfs(lli p,lli d){
    if(d == 8) return true;
    for(lli i = p;i < 64;i++){
        if(judge(i%8,i/8)){
            f[i%8][i/8] = 1;
            if(dfs(i+1,d+1)) return true;
            f[i%8][i/8] = 0;
        }
    }
    return false;
}

int main(){
    cin >> n;
    for(lli i = 0;i < n;i++){
        cin >> r >> c;
        f[r][c] = 1;
    }
    dfs(0,n);
    for(lli i = 0;i < 8;i++){
        for(lli j = 0;j < 8;j++){
            if(f[i][j]) cout << "Q";
            else cout << ".";
        }
        cout << endl;
    }
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll cnt = 0;
    while (B <= A) {
        B *= 2;
        ++cnt;
    }
    while (C <= B) {
        C *= 2;
        ++cnt;
    }

    if (cnt <= K) {
        prints()("Yes");
    }
    else {
        prints()("No");
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/05/25  Problem: ABC 127 C / Link: http://abc127.contest.atcoder.jp/tasks/abc127_c  ----- */

using T = LL;
pair<T, T>common_range(vector<pair<T, T>> seg) {
	T L = seg.front().first;
	T R = seg.front().second;
	for (auto &&it : seg) {
		L = max(L, it.first);
		R = min(R, it.second);
	}
	return pair<T, T>(L, R);
}

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

	LL N, M; cin >> N >> M;
	vector<LL> L(M), R(M);
	vector<PLL>s;
	for (int i = 0; i < M; ++i) {
		cin >> L[i] >> R[i];
		s.push_back(PLL(L[i], R[i]));
	}
	auto it = common_range(s);
	LL ans = it.second - it.first + 1;
	if (ans < 0)ans = 0;


	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 5104
import math

N = int(input()) - 1

B = [2 for i in range(N)]

for i in range(2, math.ceil(math.sqrt(N))+1):
  for j in range(2*i, N+1, i):
    B[j-1] += 1

    if math.ceil(math.sqrt(N)) < j//i:
      B[j-1] += 1

print(sum(B)-1)

Measured memory_bytes: 142340
#include <stdio.h>

int main() {
 char a[11],b[101];
 int c,d=0,e;
 scanf("%s",&a);
 while(1){
   scanf("%s",&b);
   if(strcmp("END_OF_TEXT",b)==0)
   break;
   for(c=0;c<101;c++){
   if(b[c]>='A'&&b[c]<='Z')
   b[c]=b[c]+32;}
   if(strcmp(a,b)==0)
     d++;}  
 printf("%d\n",d);
  return 0;
}


Measured memory_bytes: 2032
S = int(input())
counter = 0
ans = 1
if S <= 2 or S == 4:
    print('4')
    exit()
else:
    while True:
        if S % 2 == 0:
            S = S // 2
            ans += 1
            if S == 4:
                counter += 1
                if counter == 2:
                    print(ans)
                    exit()
        else:
            S = 3 * S + 1
            ans += 1
            if S == 4:
                counter += 1
                if counter == 2:
                    print(ans)
                    exit()


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<Int> A(N);
        for (int i = 0; i < N; ++i) cin >> A[i];

        Int X = 0;
        for (int i = 0; i < N; ++i) {
            X ^= A[i];
        }

        vector<Int> B(N);
        for (int i = 0; i < N; ++i) {
            B[i] = (~X) & A[i];
        }

        int bi = 0;
        for (Int mask = (1ll << 61); mask > 0; mask >>= 1) {
            int i = bi;
            for (; i < N; ++i) {
                if (mask & B[i]) {
                    break;
                }
            }
            if (i < N) {
                swap(B[i], B[bi]);

                for (int j = 0; j < N; ++j) {
                    if (mask & B[j] && j != bi) {
                        B[j] ^= B[bi];
                    }
                }
                bi++;
            }
        }
        Int Y = 0;
        for (int i = 0; i < N; ++i) {
            Y ^= B[i];
        }

        Int ans = Y * 2 + X;

        cout << ans << endl;
    }

};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sum[214514];
signed main(){
	sc(s)
	int n=s.size();
	int bcnt=0;
	int ans=0;
	rep(0,i,n){
		if(s[i]=='B')bcnt++;
		else sum[i-bcnt]=bcnt;
	}
	rep(0,i,n-bcnt)ans+=sum[i];
	c(ans)
}		

Measured memory_bytes: 2180
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s = sc.next();
        if (s.charAt(a) != '-') {
            System.out.println("No");
            System.exit(0);
        }
        for (int i = 0; i < a; i++) {
            if (Character.isDigit(s.charAt(i)))
                ;
            else {
                System.out.println("No");
                System.exit(0);
            }
        }
        for (int i = a + 1; i < a + b + 1; i++) {
            if (Character.isDigit(s.charAt(i)))
                ;
            else {
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 21844
import bisect
n, q = map(int, input().split())
s = input()
cnt = 0
apoint = []
cpoint = []
for i in range(len(s) - 1):
    if s[i] + s[i + 1] == 'AC':
        cnt += 1
        apoint.append(i)
        cpoint.append(i)
# print('cnt:', cnt)
# print('acpoint:', apoint)
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    left = bisect.bisect_left(apoint, l)
    right = bisect.bisect_left(cpoint, r)
    print(right - left)


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

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  rep(i,n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || (MX+1)/ans < a || ans*a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int F[100];

int Fibo(int n){
  int i;
  F[0] = 1;
  F[1] = 1;
  for(i=2;i<=n;i++){
    F[i] = F[i-1] + F[i-2];
  }
}

int main(){
  int n;
  scanf("%d",&n);
  Fibo(n);
  printf("%d\n",F[n]);
  
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n,a,b; cin >> n >> a >> b;
    if (a*n > b)
    {
        cout << b << endl;
    } else {
        cout << a*n;
    }
    return 0;
}

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

using namespace std;

typedef pair<int,pair<int,int> > edge;
#define FIRST(p) ((p).second.first)
#define SECOND(p) ((p).second.second)
#define WEIGHT(p) ((p).first)
#define EDGE(a,b,w) (make_pair(w,make_pair(a,b)))

int ds(vector<int> &v,int i){
  if(v[i]==i) return i;
  else return v[i]=ds(v,v[i]);
}

int iter(vector<edge> &e,int n){
  vector<int> v(n);
  for(int i=0;i<n;i++)v[i]=i;
  int wmax=0,wmin=WEIGHT(e[e.size()-1]);
  int cnt=0;
  for(int i=e.size()-1;i>=0&&cnt!=n-1;i--){
    edge a=e[i];
    int f=FIRST(a),s=SECOND(a);
    int d1=ds(v,f),d2=ds(v,s);
    if(d1!=d2){
      cnt++;
      if(d1<d2) v[d2]=d1;
      else v[d1]=d2;
      wmax=WEIGHT(a);
    }
  }
  if(cnt==n-1)
    return wmax-wmin;
  else
    return -1;
}

int solve(vector<edge> &e,int n){
  sort(e.begin(),e.end(),greater<edge>());
  int tmp,ans = 0x7FFFFFFF;
  while(e.size()>=n-1){
    tmp = iter(e,n);
    if(tmp!=-1)
      ans = min(ans,tmp);
    e.pop_back();
  }
  if(ans==0x7FFFFFFF)
    return -1;
  else
    return ans;
}

int main(){
  int n,m;
  while(cin>>n>>m, n+m){
    vector<edge> e(m);
    for(int i=0;i<m;i++){
      int a,b,w;cin>>a>>b>>w;
      e[i]=EDGE(a-1,b-1,w);
    }
    cout << solve(e,n) << endl;
  }
  return 0;
}

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

int main(){
    int a,b,k;cin>>a>>b>>k;int g = __gcd(a,b);
    vector<int> v;for(int i=1;i<=g;i++){if(!(g%i))v.push_back(i);}
    cout<<v[v.size()-k];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
ll binsearch(ll x, vector<ll> v)
{
  ll l = 0, r = v.size() - 1, mid, ans = 0;
  while (l <= r)
  {
    mid = (l + r) / 2;
    if (v[mid] < x)
      l = mid + 1, ans = mid;
    else if (v[mid] > x)
      r = mid - 1;
    else
      return mid;
  }
  return ans;
}
int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll  n;
  cin >> n;
  map<string, int>mp;
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    mp[s]++;

  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;


}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <set>
using namespace std;

int main(void) {
	int N, buf;
	scanf("%d", &N);
	vector<int> P = vector<int>(N, 0);
	for (int i = 0; i < N; i++) {
		scanf("%d", &buf);
		P[i] = buf - 1;
	}

	auto frontcheck = vector<int>(N, 0);
	for (int i = 0; i < N; i++) {
		if (P[i] == 0) {
			frontcheck[P[i]] = 1;
			continue;
		}
		frontcheck[P[i]] = 1 + frontcheck[P[i]-1];
	}

	auto backcheck = vector<int>(N, 0);
	for (int i = N-1; i >= 0; i--) {
		if (P[i] == N-1) {
			backcheck[P[i]] = 1;
			continue;
		}
		backcheck[P[i]] = 1 + backcheck[P[i] + 1];
	}

	int max = 0;
	for (int i = 0; i < N; i++) {
		if (frontcheck[i] > max) {
			max = frontcheck[i];
		}
		if (backcheck[i] > max) {
			max = backcheck[i];
		}
	}

	printf("%d\n", N - max);
	return 0;
}

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

int main(){
  string shop[5]={"A","B","C","D","E"};
  string ans_char;
  int mo,af,ans_int;
  while(1){
    cin >> mo >> af;
    if(mo == 0 && af == 0) break;
    ans_int = mo + af;
    ans_char = shop[0];
    for(int i=1;i<=4;i++){
      cin >> mo >> af;
      if(ans_int < mo + af){
	ans_int = mo + af;
	ans_char = shop[i];
      }
    }
    cout << ans_char << " " << ans_int << endl;
  }
}

Measured memory_bytes: 1204
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

#define int long long

signed main(){
	int ans = 0;
	int k, n;
	int a[300000];
	cin >> k >> n;
	for(int i = 0; i < n; i++)cin >> a[i];
	a[n] = a[0] + k;
	for(int i = 0; i < n; i++){
		int d;
		d = a[i + 1] - a[i];
		if(d > ans)ans = d;
	}
	cout << k - ans << endl;
	return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> T(n), X(n), Y(n);
    REP(i, n) cin >> T[i] >> X[i] >> Y[i];

    int t = 0, x = 0, y = 0;
    bool f = true;
    REP(i, n){
        int dt, dx, dy;
        dt = T[i] - t;
        dx = abs(X[i] - x);
        dy = abs(Y[i] - y);
        if(dt == dx + dy);
        else if(dt > dx + dy){
            if(dt % 2 == (dx + dy) % 2);
            else f = false;
        }else f = false;
        
        if(f);
        else break;
        t = T[i]; x = X[i]; y = Y[i];
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1408
def solve(str)
  left1, left2, right = str.match(/(.+)\+(.+)=(.+)/).to_a[1..-1]
  for i in "1".."9"
    l1, l2, r = left1.gsub("X", i), left2.gsub("X", i), right.gsub("X", i)
    if (l1.to_i + l2.to_i == r.to_i)
      return i
    end
  end
  l1, l2, r = left1.gsub("X", "0"), left2.gsub("X", "0"), right.gsub("X", "0")
  if (check(l1) and check(l2) and check(r) and (l1.to_i + l2.to_i == r.to_i))
    return 0
  else
    return "NA"
  end
end
def check(str)
  return (str.to_i.to_s == str)
end
while (str = gets)
  puts solve(str.chomp)
end

Measured memory_bytes: 8924
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int cntn = 0;
    int cntw = 0;
    int cnts = 0;
    int cnte = 0;

    rep(i, N) {
        if(S[i] == 'N') {
            cntn = 1;
        }
        else if(S[i] == 'W') {
            cntw = 1;
        }
        else if(S[i] == 'S') {
            cnts = 1;
        }
        else if(S[i] == 'E') {
            cnte = 1;
        }
    }

    if( (cntn + cnts == 1) || (cntw + cnte == 1) ) {
        cout << "No";
    } 
    else {
        cout << "Yes";
    }

    cout << endl;
    return 0;
}

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

typedef long long ll;
ll MOD = 1e9+7;


int main()
{
	int n;
	int ans=0;
	string s[10000];
	int fb=0;
	int la=0;
	int fbla=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>s[i];
	
	for(int i=0;i<n;i++)
	{
		if(s[i][s[i].size()-1]=='A' && s[i][0]=='B')
			fbla++;
		else if(s[i][0]=='B')
			fb++;
		else if(s[i][s[i].size()-1]=='A')
			la++;
		
		int j=0;
		while(j<s[i].size()-1)
		{
			if(s[i][j]=='A' && s[i][j+1]=='B')
				ans++;
			j++;
		}
	}
	ans+=min(fb,la);
	fb-=min(fb,la);
	la-=min(fb,la);
	if(fb>0 || la>0)
		ans+=fbla;
	else if(fbla>1)
		ans+=fbla-1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    int x,y; cin >> x >> y;
    cout << x + y/2 << endl;
    
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

string as[1000];
int bs[1000];
signed main(){
	int n,m;
	cin >> n;
	string s;
	int cnt = 0;
	bool flg = false;
	int x;
	rep(i,n){
		cin >> s;
		if(cnt == 0){
			as[cnt] = s;
			bs[cnt]++;
			++cnt;
			continue;
		}
		flg = false;
		rep(j,cnt){
			if(as[j] == s){
				flg = true;
				x = j;
				break;
			}
		}
		if(flg){
			bs[x]++;
		}
		else{
			as[cnt] = s;
			bs[cnt]++;
			++cnt;
		}
	}
	cin >> m;
	rep(i,m){
        cin >> s;
		flg = false;
        rep(j,cnt){
            if(as[j] == s){ 
                flg = true;
                x = j;
                break;
            }   
		}
        if(flg){
              bs[x]--;
           }   
        else{
                as[cnt] = s;
                bs[cnt]--;
                ++cnt;
            }      
    }  
	sort(bs,bs+cnt,greater<int>());
	if(bs[0] < 0) cout << 0 << '\n';
	else cout << bs[0] << '\n';
	return 0;
}


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

long long a[200005];

int main()
{
    string str;
    cin >> str;
    long long n = str.size();

    long long op = 0;

    for(long long i = 0; i < n; ++i){
        if(str[i] == 'A'){
            a[i]++;
            if(i){
                a[i] += a[i - 1];
            }
        }
        if(i >= 2 && str[i] == 'C' && str[i - 1] == 'B' && str[i - 2] == 'A'){
            op += a[i - 2];
            str[i] = 'A';
            a[i] = a[i - 2];
        }
    }

    cout << op << "\n";
    return 0;
}


Measured memory_bytes: 2180
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>

using namespace std;

constexpr int mod = 1000000007;

inline
int modMultiple(int a, int b){return (static_cast<long long>(a) * b) % mod;}

int main()
{
    int N;
    scanf("%d\n", &N);
    int result = 1;
    int k = 0;
    for (int i = 0; i < N; ++i){
        int Xi;
        scanf("%d", &Xi); getchar();
        while (Xi < k * 2 + 1){
            result = modMultiple(result, k + 1);
            --k;
        }
        ++k;
    }
    for (; k > 0; --k){
        result = modMultiple(result, k);
    }
    printf("%d\n", result);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;



int main() {
  ll N,K;
  cin >> N >> K;
  ll A[N],F[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> F[i];
  sort(A,A+N);
  sort(F,F+N);
  reverse(F,F+N);
  ll left = -1;
  ll right = 1e13;

  while (right - left > 1) {
    ll mid = (right + left) / 2;
    ll res = 0;
    for (int i = 0; i < N; i++) {
      res += max(A[i] - (mid / F[i]),0LL);
    }
    if (res > K) {
      left = mid;
    } else {
      right = mid;
    }
  }

  cout << right << endl;
  return 0;
}

Measured memory_bytes: 6724
import math

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


def is_ok(x):
    cnt = 0
    for a in A:
        while math.floor(a) > x:
            cnt += 1
            a /= 2
        # cnt += math.ceil(math.log(a / x))
    return cnt <= M

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

X = bisect(-1, max(A))
ans = 0
cnt = 0
for a in A:
    while math.floor(a) > X:
        cnt += 1
        a /= 2
    ans += math.floor(a)
ans -= math.ceil(X / 2) * (M - cnt)
print(ans)


Measured memory_bytes: 85128
#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 ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int x1,x2,y1,y2;

  cin >> x1 >> y1 >> x2 >> y2;

  int dx = x2 - x1;
  int dy = y2 - y1;

  cout << x2 - dy << " " << y2 + dx << " " << x1 - dy  << " " << y1 + dx << endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdlib.h> 
#include<cstring>
#include<map>
#include<list>
#include<stdio.h>
#include<cmath>
#include<iomanip>
#include<stack>
#include<bitset>
#include<vector>
#include<time.h>
#include<algorithm> 
#include<queue>
#include<set>
#include<deque>
#define mod 1e9+7
#define inf 1e18 
typedef long long ll;
typedef long double ld;
using namespace std;
typedef list<ll> li;
typedef list<ll>::iterator lt;
ll b[15];
vector<ll>a;
ll s,n;
void dfs(ll x){
	if(x==13){
		//for(ll i=0;i<n;i++)cout<<a[i];
		vector<ll>c(a);
		vector<ll>::iterator it=c.begin();
		advance(it,n);
		sort(c.begin(),it);
		//for(ll i=0;i<n;i++)cout<<c[i];
		ll Min=inf;
		for(ll i=0;i<n-1;i++){
			Min=min(Min,c[i+1]-c[i]);
		}
		s=max(Min,s);
		return;
	}
	ll i=x;
	if(b[i]==1){
		a.push_back(i);
		dfs(x+1);
		a.pop_back();
		a.push_back(24-i);
		dfs(x+1);
		a.pop_back();
	}
	if(b[i]==2){
		a.push_back(i);
		a.push_back(24-i);
		dfs(x+1);
		a.pop_back();
		a.pop_back();
	}
	if(b[i]==0)dfs(x+1);
	return;
}
int main(){	
    cin>>n;
    bool flag=false;
    ll Min=inf;
    for(ll i=1;i<=n;i++){
    	if(n>23){
    		flag=true;
    		break;
		}
    	ll x;
    	scanf("%lld",&x);
    	b[x]++;
    	Min=min(Min,x);
    	if(b[x]>=3||x==0){
    		flag=true;
    		break;
		}
	}
	if(flag)printf("0");
	else{
		dfs(1);
		printf("%lld",min(s,Min));
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char mp[1005][1005];
int h,w;
struct node{
	int x,y,step;
};
int vis[1005][1005];
queue<node>q;
int tox[]={1,0,0,-1};
int toy[]={0,1,-1,0};
int main()
{
	cin >> h >> w;
	int cnt=0;
	node s;
	for(int i=0;i<h;i++)
	{
		scanf("%s",mp[i]);
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(mp[i][j]=='#')
			{
				vis[i][j]=1;
				s.x=i;
				s.y=j;
				s.step=0;
				q.push(s);
			}
		}
	}
	node t;
	int op=0;
	while(!q.empty())
	{
		s=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			int x=s.x+tox[i];
			int y=s.y+toy[i];
			if(x<h&&x>=0&&y>=0&&y<w)
			{
				if(mp[x][y]=='.'&&!vis[x][y])
				{
					mp[x][y]='#';
					vis[x][y]=1;
					t.x=x;
					t.y=y;
					t.step=s.step+1;
					q.push(t);
					op=max(op,t.step);
				}
			}
		}
	}
	printf("%d\n",op);
    return 0;
}

Measured memory_bytes: 17296
#include<stdio.h>

int main(void)
{
	int a,b,c,tmp;
	scanf("%d%d%d",&a,&b,&c);
	
	if(a > b){
		tmp = a;
		a = b;
		b = tmp;
	}
	if(b > c){
		tmp = b;
		b = c;
		c = tmp;
	}
	if(a > b){
		tmp = a;
		a = b;
		b = tmp;
	}

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

Measured memory_bytes: 596
/**
 *   created: 04 July 2019  20:06:43
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

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

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int a,b,c;
		cin>>a>>b>>c;
		cout<<min(a*b,c);
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
class UnionFind{
    int size;
    int[] parent;
    int[] height;
    public UnionFind(int size){
        this.size = size;
        parent = new int[size];
        height = new int[size];
        for(int i=0;i<size;i++){
            parent[i]=i;
            height[i]=0;
        }
    }
    private boolean isRoot(int node){
        return node==parent[node];
    }
    private int getRoot(int node){
        if(isRoot(node)) return node;
        else{
            parent[node] = getRoot(parent[node]);
            return parent[node];
        }
    }
    public void union(int node1, int node2){
        if(height[node1]>height[node2])parent[getRoot(node2)] = getRoot(node1);
        else parent[getRoot(node1)] = getRoot(node2);
    }
    public boolean find(int node1, int node2){
        return getRoot(node1)==getRoot(node2);
    }
    public int countGroup(){
        int ans = 0;
        for(int i=0;i<size;i++) if(isRoot(i)) ans++;
        return ans;
    }
}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        UnionFind G = new UnionFind(N);
        for(int m=0; m<M; m++){
            int X = sc.nextInt()-1;
            int Y = sc.nextInt()-1;
            int Z = sc.nextInt();
            G.union(X,Y);
        }
        System.out.println(G.countGroup());

    }
}


Measured memory_bytes: 91968
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }

const LL MOD = 1000000007;

int main(){
    LL n;
    cin >> n;
    vector<LL> col(n);
    vector<LL> next(n, -1);
    vector<LL> prev(200001, -1);
    for(LL i = 0; i < n; ++i){
        cin >> col[i];
        if(prev[col[i]] >= 0 && prev[col[i]] + 1 < i){
            next[prev[col[i]]] = i;
        }
        prev[col[i]] = i;
    }

    vector<LL> dp(n+1);
    dp[0] = 1;
    for(LL i = 0; i < n; ++i){
        if(next[i] >= 0){
            dp[next[i]] = (dp[next[i]] + dp[i]) % MOD;
        }
        dp[i+1] = (dp[i+1] + dp[i]) % MOD;
    }

    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n; cin >> n;
	int a, b, c;
	int ans = 0;
	a = n%10;
	b = n/10%10;
	c = n/100%10;
	if(a==1){
		ans++;
	}
	if(b==1){
		ans++;
	}
	if(c==1){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

ll n;
string s;

ll a[100010]={0};
bool f1,f2;

signed main(){
    cin>>n>>s;

    for(int i=0;i<2;++i){
        for(int j=0;j<2;++j){
            a[0]=i,a[1]=j;
            f1=false,f2=false;
            for(int k=2;k<n;++k){
                if(a[k-1]==1&&s[k-1]=='o'||a[k-1]==0&&s[k-1]=='x')a[k]=a[k-2];
                else a[k]=1-a[k-2];
            }
            if(a[0]==1){
                if((s[0]=='o')==(a[1]==a[n-1])){
                   f1=true;
                }
            }
            if(a[0]!=1){
                if((s[0]=='o')!=(a[1]==a[n-1])){
                    f1=true;
                }
            }

            if(a[n-1]==1){
                if((s[n-1]=='o')==(a[n-2]==a[0])){
                   f2=true;
                }
            }
            if(a[n-1]!=1){
                if((s[n-1]=='o')!=(a[n-2]==a[0])){
                    f2=true;
                }
            }
            if(f1&&f2)i=2,j=2;
        }
    }

    if(!(f1&&f2)){
        cout<<-1<<endl;
        return 0;
    }

    for(int i=0;i<n;++i){
        if(a[i]==1)printf("S");
        else printf("W");
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 1408
def cross(a,b):
  return a.real*b.imag-a.imag*b.real

def intersection(p0,p1,p2,p3):
  a1=p3-p2
  b1=p0-p2
  b2=p1-p2
  s1=cross(b1,a1)
  s2=cross(a1,b2)
  c1=p0+(p1-p0)*s1/(s1+s2) #面積比を使う
  return c1

q=int(input())

for _ in [0]*q:
  x_y=map(int,input().split())
  p0,p1,p2,p3=[x+y*1j for x,y in zip(*[x_y]*2)]
  c1=intersection(p0,p1,p2,p3)
  print('{:.10f} {:.10f}'.format(c1.real,c1.imag))



Measured memory_bytes: 5652
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct Edge
{
	int MFrom;
	int MTo;
};

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector< vector<int> > Vertex(n);
		vector<Edge> Vec(m);
		for(int i = 0; i < m; ++i)
		{
			cin >> Vec[i].MFrom >> Vec[i].MTo;
			Vec[i].MFrom--; Vec[i].MTo--;
		}
		for(int i = 0; i < m; ++i)
		{
			Edge e = Vec[i];
			Vertex[e.MFrom].push_back(e.MTo);
			Vertex[e.MTo].push_back(e.MFrom);
		}
		set<int> Set;
		for(int i = 0; i < Vertex[0].size(); ++i)
		{
			int To = Vertex[0][i];
			Set.insert(To);
			for(int j = 0; j < Vertex[To].size(); ++j)
			{
				Set.insert(Vertex[To][j]);
			}
		}
		Set.count(0) ? cout << Set.size() - 1 : cout << Set.size();
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
<?php

$n = trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));

$sum = 0;
for($i = 0;$i < count($a);$i++) {
	$sum += 1 / (double)$a[$i];
}
echo 1 / $sum."\n";
// echo $tmp;
// $a = [];
// $sum = 0;
// for($i = 0;$i < $n;$i++) {
// 	$tmp = trim(fgets(STDIN));
// 	echo $tmp."\n";
// 	// $sum += (1 / $tmp);
// }

// echo sprintf('%.3f', 1/$sum);

// $arr = [$input[0]];
// $tmp = '';
// for($i = 1;$i < strlen($input);$i++) {
//   $m = count($arr);
//   $tmp .= $input[$i];

//   if($arr[$m - 1] === $tmp) {

//   } else {
//     $arr[] = $tmp;
//     $tmp = '';
//   }
// }

// echo count($arr)."\n";

Measured memory_bytes: 4728
fun main(args: Array<String>) {
    val (A, B) = readLine()!!.split(" ").map(String::toInt)
    val S = readLine()!!
    if ("^[0-9]{${A}}-[0-9]{${B}}$".toRegex().matches(S)) {
        println("Yes")
    } else {
        println("No")
    }
}



Measured memory_bytes: 37900
from collections import deque

N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

MOD = 10 ** 9 + 7

n_minus = 0
for a in A:
    if a < 0:
        n_minus += 1

if N == K:
    ans = 1
    for a in A:
        ans *= a
        ans %= MOD
    print(ans)

elif n_minus == N and K % 2 == 1:
    A = sorted(A, key=lambda x: 10 ** 9 if x == 0 else abs(x))

    ans = 1
    for i in range(K):
        ans *= A[i]
        ans %= MOD

    print(ans)

else:
    A = sorted(A, key=lambda x: abs(x), reverse=True)
    padding = None
    plus = deque()
    minus = deque()
    buf_p = deque()
    buf_m = deque()

    for a in A:
        if a >= 0:
            if padding is None and K % 2 == 1:
                padding = a
            else:
                buf_p.append(a)

                if len(buf_p) == 2:
                    plus.append(buf_p.popleft() * buf_p.popleft())
        else:
            buf_m.append(a)

            if len(buf_m) == 2:
                minus.append(buf_m.popleft() * buf_m.popleft())

    ans = 1
    if padding is not None:
        ans *= padding
        ans %= MOD

    for _ in range(K // 2):
        if len(plus) == 0:
            ans *= minus.popleft()
            ans %= MOD
        elif len(minus) == 0:
            ans *= plus.popleft()
            ans %= MOD
        elif plus[0] >= minus[0]:
            ans *= plus.popleft()
            ans %= MOD
        else:
            ans *= minus.popleft()
            ans %= MOD

    print(ans)


Measured memory_bytes: 33420
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, L;
    cin >> N >> L;
    int min = L;
    int sum = 0;
    int z = 0;
    int s = 0;
    for(int i = 1; i <= N; i++){
        sum = sum + i + L -1;
        if(i+L-1 < 0){
            z = (i+L-1) * -1;
        }else{
            z = i+L-1;
        }
        if(min < 0){
            s = min * -1;
        }
        if(z < s){
            min = (i + L  -1);
        }
    }
    if(min < 0){
        sum = sum - min;
    }else{
        sum = sum - min;
    }
    cout << sum << endl;
    return 0;
}

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

#define int int64_t

int MOD = 1000000007;

int maxHappiness(int **A, int N, int val, int **dp)
{
    if(N == -1)
        return 0;

    if(dp[N][val] != -1)
        return dp[N][val];

    int option1 = INT_MIN, option2 = INT_MIN, option3 = INT_MIN;

    if(val != 0)
        option1 = A[N][0] + maxHappiness(A, N - 1, 0, dp);

    if(val != 1)
        option2 = A[N][1] + maxHappiness(A, N - 1, 1, dp);

    if(val != 2)
        option3 = A[N][2] + maxHappiness(A, N - 1, 2, dp);

    return dp[N][val] = max(option1, max(option2, option3));
}

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

    int N;
    cin >> N;

    int **A = new int*[N]();
    for(int i=0; i<N; i++)
        A[i] = new int[3];

    for(int i=0; i<N; i++)
        cin >> A[i][0] >> A[i][1] >> A[i][2];

    int **dp = new int*[N]();
    for(int i=0; i<N; i++)
        dp[i] = new int[4];

    for(int i=0; i<N; i++)
        dp[i][0] = dp[i][1] = dp[i][2] = -1;

    int ans1 = maxHappiness(A, N - 1, 0, dp);

    for(int i=0; i<N; i++)
        dp[i][0] = dp[i][1] = dp[i][2] = -1;

    int ans2 = maxHappiness(A, N - 1, 1, dp);

    for(int i=0; i<N; i++)
        dp[i][0] = dp[i][1] = dp[i][2] = -1;

    int ans3 = maxHappiness(A, N - 1, 2, dp);

    cout << max(ans1, max(ans2, ans3));

    for(int i=0; i<N; i++)
        delete [] dp[i];
    delete [] dp;

    for(int i=0; i<N; i++)
        delete [] A[i];
    delete [] A;

    return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << (x) << '\n'
typedef long long lint;
const int INF = 2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const lint LINF = 1e18;
typedef vector<int> vint;
typedef pair<int, int> pint;
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> T print(T &x) {
    cout << x << '\n';
    return 0;
}
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;
}
int modulo(int a, int b, int n) {
    long long x = 1, y = a;
    while(b > 0) {
        if(b % 2 == 1) {
            x = (x * y) % n; // multiplying with base
        }
        y = (y * y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

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

    int N = in(), W = in();
    int w[N + 1], v[N + 1];
    rep(i, 1, N + 1) { cin >> w[i] >> v[i]; }
    vector<vector<lint>> dp(N + 10, vector<lint>(100001, LINF));
    dp[0][0] = 0;
    rep(i, 1, N + 1) {
        rep(j, 100001) {
            if(j - v[i] >= 0) {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    int ans = 100000;
    while(dp[N][ans] > W) {
        ans--;
    }
    print(ans);
}

Measured memory_bytes: 87296
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
string S;cin >> S;
ll Ans = 0;

rep(i, 0, 3){
    
    if(S[i] == 'R')Ans++;
    
    }

if(S == "RSR")Ans--;

cout << Ans;

}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>

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

void assignGroup(int v, int *group, int g, std::vector<std::vector<int>> r) {
  // std::cout << v << '\n';
  if (group[v] == g) return;
  group[v] = g;

  for (int u : r[v]) { assignGroup(u, group, g, r); }
}

int main() {
  int n, m;
  std::cin >> n >> m;
  int h[n];
  rep(i, n) std::cin >> h[i];

  int group[n];
  rep(i, n) group[i] = -1;

  std::vector<std::vector<int>> r(n);

  int a, b;
  rep(i, m) {
    std::cin >> a >> b;
    --a;
    --b;
    if (std::find(r[a].begin(), r[a].end(), b) == r[a].end()) r[a].push_back(b);
    if (std::find(r[b].begin(), r[b].end(), a) == r[b].end()) r[b].push_back(a);
  }

  int cnt = 0;
  rep(i, n) {
    int v = i, maxh = h[i];
    for (int u : r[i]) {
      // printf("i: %d(%d), u:, %d(%d)\n", i, h[i], u, h[u]);
      if (maxh <= h[u]) {
        // std::cout << i << u << '\n';
        v = u;
        break;
      }
    }
    if (v == i) ++cnt;
  }

  std::cout << cnt << '\n';

  // int g = 0;
  // rep(i, n) {
  //   if (group[i] == -1) {
  //     assignGroup(i, group, g, r);
  //     ++g;
  //   }
  // }
  //
  // rep(i, n) std::cout << group[i] << '\n';
  //
  // int ans = g;
  // rep(i, g) {
  //   int max = -1;
  //   rep(j, n) {
  //     if (group[j] == g && h[i] > max) { max = h[i]; }
  //   }
  //
  //   int same = 0;
  //   rep(j, n) {
  //     if (group[j] == g && h[i] == max) { ++same; }
  //   }
  //   if (same > 1) --ans;
  // }

  // std::cout << ans << '\n';

  return 0;
}


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

int main(){
    double A,B,H,M;
    cin>>A>>B>>H>>M;

    double l,s;
    l = (double)(30*H) + M/2;
    s = 6*M;

    double ang;
    ang = min(l-s,360-l+s);
    ang = ang*(M_PI/180);

    double length = A*A+B*B-2*A*B*cos(ang);
    length = sqrt(length);

    cout<<setprecision(10)<<fixed;
    cout<<length<<endl;

    return 0;
}

Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INF = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];


void dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i=0; i<n; i++){
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = WHITE;
    
    while(!PQ.empty()){
        pair<int, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        
        // ????°??????????????????????????????§???????????°????????????
        if (d[u] < f.first * (-1) ) continue;

        for(int j=0; j<adj[u].size(); j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1), v));
                color[v] = GRAY;
            }
        }
    }

    for(int i=0; i<n; i++){
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
}




int main() 
{
    ios::sync_with_stdio(false);
    
    cin >> n;
    int k, c, u, v;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }
    
    dijkstra();
    
    return 0;
}

Measured memory_bytes: 8108
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ll n,i,j,w,ans;
  scanf("%lld %lld",&n,&w);
  vector<pair<ll,ll>>a(n);
  vector<ll>dp(100005,w+1);
  vector<ll>tmp(100005,w+1);
  for(i=0;i<n;i++){
    scanf("%lld %lld",&a[i].first,&a[i].second);
  }
  dp[0] = 0;
  for(i=n-1;i>=0;i--){
    for(j=100004;j>=0;j--){
      if(j>=a[i].second){
        dp[j] = min(dp[j],dp[j-a[i].second]+a[i].first);
      }
    }
  }
  ans = 0;
  for(i=100004;i>=0;i--){
    if(dp[i]<=w){
      ans = i;
      break;
    }
  }
  printf("%lld",ans);
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static final long M = 1_000_000_007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] c = new long[n];
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextLong();
		}
		Arrays.sort(c);
		long[] t = new long[n + 1];
		t[0] = 1;
		for (int i = 1; i <= n; i++) {
			t[i] = t[i - 1] * 2;
			t[i] %= M;
		}

		long answer = 0;
		for (int i = 0; i < n; i++) {
			int l = i, r = n - 1 - i;
			long a = t[r];
			if (r != 0) a = (a + (t[r - 1] * r)) % M;
			a = a * t[l] % M;
			a = a * c[i] % M;

			answer += a;
			answer %= M;
		}
		answer *= t[n];
		System.out.println(answer % M);
	}
}


Measured memory_bytes: 90948
K = int(input())
s = 0
def gcd(a,b):
    if a == 1 or b == 1:
        return 1
    elif a == 0 or b == 0:
        return max(a,b)
    else:
        if a > b:
            return gcd(a%b,b)
        else:
            return gcd(a,b%a)
for i in range (1,K + 1):
    for j in range (i + 1,K + 1):
        x = gcd(i,j)
        for k in range (j + 1,K + 1):
            s = s + 6 * gcd(x,k)
for i in range(1,K + 1):
    for j in range (i + 1,K + 1):
        s = s + 6 * gcd(i,j)
                    
for i in range(1,K + 1):
    s = s + i

print(s)

Measured memory_bytes: 9224