akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=1e5+50;
const ll mod=1e9+7;
using namespace std;
int i,rs;
string s,t;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>s>>t;
	for(i=0;i<lun(s);i++)if(s[i]!=t[i])rs++;
	cout<<rs<<endl;
	return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
int main(){
    int N, D;
    cin >> N >> D;
    vector<vector<int>> p(N, vector<int>(D, 0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            cin >> p[i][j];
        }
    }
    int num = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            double d = 0;
            for(int k = 0; k < D; k++){
                d += (double)((p[i][k]-p[j][k])*(p[i][k]-p[j][k]));
            }
            d = sqrt(d);
            if(floor(d) == ceil(d)) num++;
        }
    }
    cout << num;
    return 0;
}

Measured memory_bytes: 256
import collections

class UnionFind:
    def __init__(self, n):
        self.par = [k for k in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                #もし二つの木の高さが同じ状態で片方をもう片方に結合すると
                #結合後の木全体の高さは元々より1高くなる
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def tree_count(self):
        l = collections.Counter(self.par[1:])
        return len(l)


n,m = map(int,input().split())

uf = UnionFind(n)

#print(uf.par)
for i in range(m):
    x,y,z = map(int,input().split())
    uf.union(x,y)
    #print(uf.par)

for j in range(1,n+1):
    _ = uf.find(j)

print(uf.tree_count())





Measured memory_bytes: 18148
#include <iostream>
#include <vector>

using namespace std;
#define at(x) operator[](x)

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

  vector<int> A(N);
  for(auto i =0; i< N; i++) {
    cin >> A.at(i);
  }

  vector<int> DP(K+1);

  DP.at(0) = 0; // second
  for (auto i=1; i <= K; i++) {
    DP.at(i) = 0; // default second if cannot pick an action

    for (auto act : A) {
      if (act > i) break;

      if (DP.at(i-act) == 0) {
        DP.at(i) = 1;
        break;
      }
    }
  }

  if (DP.at(K) == 1) cout << "First\n"; else cout << "Second\n";
}

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

void get_turn(string S,int &num,int &turn){
    if(S.at(num)=='a'){
        turn = 0;
    }else if(S.at(num)=='b'){
        turn = 1;
    }else{
        turn = 2;
    }
    num++;
    
}
int main(){
    //入力
    string S_a,S_b,S_c;
    cin >> S_a;
    cin >> S_b;
    cin >> S_c;

    //処理
    int num_a,num_b,num_c,turn;
    turn = 0;
    num_a=0;
    num_b=0;
    num_c=0;
    bool end=false;
    while(end==false){
        if(turn==0){
            if(num_a==S_a.size()){
                end=true;
            }else{
                get_turn(S_a,num_a,turn);
            }
        }else if(turn==1){
            if(num_b==S_b.size()){
                end=true;
            }else{
                get_turn(S_b,num_b,turn);;
            }
            
        }else{
            if(num_c==S_c.size()){
                end=true;
            }else{
                get_turn(S_c,num_c,turn);;
            }
        }
        
    }

    //出力
    if(turn==0){
        cout << 'A' << endl;
    }else if(turn==1){
        cout << 'B' << endl;
    }else{
        cout << 'C' << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#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
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20  
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (int)1e9+2
# define maxn 100006
# define offset 1005

/*************************************************
struct Coupon {
    ll l;
    ll r;
    ll id;

    Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

    bool operator<(const Coupon& c) { // Sorting
        return l < c.l;    
    }
};

**************************************************/
vector<int>g[maxn];
int main()
{
  string s;
  cin >> s;
  int n=s.length();
  bool fnd=false;
  for(int i=0;i<n;i++)
  {
     if((i-2)<0)
       continue;
     if(s[i]!=s[i-2])
     {
       fnd=1;
       break;
     }
  }

  bool fnd2=false;
  if(s[0]==s[n-1])
    fnd2=1;

  if(!fnd)
  {
     cout << "Second";
     return 0;
  }

  if(n&1)
  {
     if(!fnd2)
      cout << "First";
    else
      cout << "Second";
  }
  else
  {
    if(!fnd2)
     cout << "Second";
    else
      cout << "First";
  }
}

Measured memory_bytes: 2816
n,k=map(int,input().split())
s=input()
x=["a","b","c"]
y=[0]*n
for i in range(n):
  y[i]=s[i]
  if s[k-1]=="A":
    y[k-1]="a"
    
  elif s[k-1]=="B":
    y[k-1]="b"
    
  elif s[k-1]=="C":
    y[k-1]="c"
    

print("".join(y))

Measured memory_bytes: 9096
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x,a;
    cin>>x>>a;
    char s[x];
    cin>>s;
    s[a-1] = s[a-1]+0x20;
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
int c[6], i, sum;
for(i=0;i<6;i++) {
scanf("%d",&c[i]);
}
if(1000<=c[0]+c[1]*5+c[2]*10+c[3]*50+c[4]*100+c[5]*500)
puts("1");
else puts("0");
return(0);
}

Measured memory_bytes: 584
defmodule Main do
  def main do
    [n, d] = IO.gets("")
             |> String.trim()
             |> String.split()
             |> Enum.map(&String.to_integer/1)
 
    IO.read(:all) 
    |> String.split() 
    |> Stream.map(&String.to_integer/1)
    |> Stream.chunk_every(2)
    |> Enum.reduce(0, fn [x, y], acc -> calc(x, y, d) + acc end)
    |> IO.puts()
  end
 
    def calc(x, y, d) do
        dist = :math.sqrt(x*x+y*y)
        if dist <= d, do: 1, else: 0
    end
end

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

int main() {
  int A, B;
  cin >> A >> B;

  cout << (A-B*2<0 ? 0 : A-B*2) << endl;
  return 0;
}

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

namespace ProgramingStudying2
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split();
            var n = int.Parse(nk[0]);
            var k = long.Parse(nk[1]);

            var a = Console.ReadLine().Split().Select(int.Parse).ToList();
            var ans1 = 0L;
            var ans2 = 0L;
            const long INF = (long)1000000007;

            //k個の部分列の中ごとにある転倒のカウント
            for(int i = 0; i < n - 1; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    if (a[i] > a[j])
                    {
                        ans1++;
                    }
                }
            }

            ans1 = ans1 * k % INF;

            //部分列間にある転倒のカウント
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (a[i] > a[j])
                    {
                        ans2++;
                    }
                }
            }

            if(k % 2 == 0)
            {
                ans2 = ans2 * k / 2 % INF;
                ans2 = ans2 * (k - 1) % INF;
            }
            else
            {
                ans2 = ans2 * (k - 1) / 2 % INF;
                ans2 = ans2 * k % INF;
            }

            Console.WriteLine((ans1 + ans2) % INF) ;
        }
    }
}


Measured memory_bytes: 28388
while n = gets.chomp.to_i
    if n==0
        break
    end
    
    s = gets.chomp.split(" ").map{|item| item.to_i}
    
    ave=0.0
    n.times{ |idx|
        ave += s[idx]
    }
    ave/=n
    
    a=0.0
    n.times{ |idx|
       a+=(s[idx]-ave)**2
    }
    a/=n
    a=Math::sqrt(a)
    
    puts a
end

Measured memory_bytes: 8880
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	int dp[n];
	memset(dp,100000000,sizeof(dp));
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
	    dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
	}
	int ans=dp[n-1];
	cout<<ans;
	return 0;
}









Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	if (s == "ABC") s = "ARC";
	else s = "ABC";
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3564
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
const ll MOD = 1e9 + 7;
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vector<ll> >
#define ins insert
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
ll cnt( ll x ){
	s ss=to_string(x);
	return (ll)ss.size();
	}
int main(){
	ll n , ans = 0;
	cin >> n;
	for( ll i = 1; i <= n; i++ ){
	if(cnt(i)&1)ans++;
	}
	cout << ans << endl;
	
	
	
	
	
	
	





return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i <b; i++)
using pii = pair<int,int>;
#define all(a) a.begin(), a.end()

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; }

pii keta(int K){
    int A = 0, B = 0;
    B = K % 10;
    while(K >= 10){
        K /= 10;
    }
    A = K;
    return make_pair(A, B);
}

int main(){
    int N; cin >> N;
    //int t = N, k = 0;
    ll ans = 0;
    /* while(t > 0){
        t /= 10;
        k++;
    } */
    map<pii,int> mp;
    rep(i, 1, N + 1){
        mp[keta(i)]++;
    }
    for(auto e: mp){
        int A = e.first.first, B = e.first.second;
        ans += mp[{B,A}] * e.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	long N, K; cin >> N >> K;
	long A[200009]; for (int i = 0; i < N; i++) cin >> A[i];
	long pool[200009] = {}; for (int i = 0; i < N; i++) pool[A[i]]++;

	sort(pool + 1, pool + N + 1);
    
    for(int i = 1; i <= N - K; i++) res += pool[i];
    
	cout << res << endl;
}

Measured memory_bytes: 3328
// atcoder/code-festival-2016-qualb/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<int> a(n);
    cin >> a;

    lli x = a[0] - 1;
    int z = 2;
    for (int i = 1; i < a.size(); ++i) {
      if (z == a[i]) ++z;
      if (a[i] <= z) continue;
      x += (a[i] / z) - (a[i] % z == 0);
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def solve():
    point = 0

    point += sum(B)

    for j in range(N - 1):
        if A[j + 1] == A[j] + 1:
            point += C[A[j] - 1]

    return point


print(solve())


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H;
  cin >> H;
  int W;
  cin >> W;
  vector<string> A(H);
  for (int i = 0; i < H; i++) {
    cin >> A.at(i);
  }
  vector<bool> gyo(H, false);
  vector<bool> retsu(W, false);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A.at(i).at(j) == '#') {
        gyo.at(i) = true;
        retsu.at(j) = true;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    if (gyo.at(i)) {
      for (int j = 0; j < W; j++) {
        if (retsu.at(j)) {
          cout << A.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}
        
  
                 


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

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

int main() {
  int const d[] = {4,1,2,1,2,1,4,1,4,1,2,1,2,1,4,1,4};
  vector<int> p(8);
  while(cin>>p[0]) {
    REP(i,7)
      cin >> p[i+1];

    int mi = 1<<30;
    int ansp = 0;
    vector<int> ansv(8,9);
    REP(i,8) {
      int tmp = 0;
      REP(j,8) {
        if (p[j]>d[i+j])
          tmp += p[j]-d[i+j];
      }
      if (mi >= tmp) {

        vector<int> tmpv(8); 
        REP(j,8)
          tmpv[j] = d[i+j];
        if (mi>tmp)
          ansv = tmpv;
        else if (ansv>tmpv)
          ansv = tmpv;
        mi = tmp;
      }
    }
    REP(i,8) {
      if (i) cout << " ";
      cout << ansv[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
use std::io::stdin;
fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let (n, m) = {
        let mut sp = s.split_whitespace().map(|x| x.parse::<usize>().unwrap());
        (sp.next().unwrap(), sp.next().unwrap())
    };
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let a: Vec<_> = s
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect();

    let sum: usize = a.iter().sum();
    let line = (sum - 1) / (4 * m) + 1;
    let ok = a.iter().filter(|&&x| x >= line).count();

    if ok >= m {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int n, a[8], k = 0;
    double x[8], y[8], sum = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        a[i] = i;
    }
    do {
        for (int i = 0; i < n - 1; ++i) {
            sum += sqrt(pow(x[a[i]] - x[a[i + 1]], 2) + pow(y[a[i]] - y[a[i + 1]], 2));
        }
        k++;
    } while(next_permutation(a, a + n));
    cout << fixed << setprecision(10);
    cout << sum / k << endl;

    return 0;
}

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

using namespace std;
const int MXN = 405;
const long long INF = 1e18 + 5;

long long dp[MXN][MXN] , p[MXN];

long long recur(int l , int r){
    if(dp[l][r] != INF){
        return dp[l][r];
    }
    for(int i = l ; i < r ; i++){
        dp[l][r] = min(dp[l][r] , recur(l , i) + recur(i + 1 , r) + p[r] - p[l - 1]);
    }
    return dp[l][r];
}

int main(){
    int n;
    scanf("%d" ,&n);
    for(int i = 0 ; i < MXN ; i++){
        for(int j = 0 ; j < MXN ; j++){
            dp[i][j] = INF;
        }
    }
    for(int i = 1 ; i <= n ; i++){
        scanf("%lld" ,&p[i]);
        dp[i][i] = 0;
        p[i] += p[i - 1];
    }
    recur(1 , n);   
    printf("%lld" ,dp[1][n]);
}

Measured memory_bytes: 1536
while (m, f, r = gets.split(" ").map(&:to_i)) != [-1, -1, -1]
  if m + f < 30 or m < 0 or f < 0
    puts "F"
  elsif m + f >= 80
    puts "A"
  elsif m + f >= 65
    puts "B"
  elsif m + f >= 50 or r >= 50
    puts "C"
  else
    puts "D"
  end
end

Measured memory_bytes: 6100
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
      
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
    
UF = UnionFind(2*H*W)
## 横方向につながっているか
for i in range(H):
  hold = []
  for j in range(W):
    if S[i][j] == '#':
      hold = []
    elif len(hold) == 0:
      hold = [(i,j)]
    else:
      UF.Unite(hold[0][0]*W+hold[0][1], i*W+j)

## 縦方向につながっているか
for j in range(W):
  hold = []
  for i in range(H):
    if S[i][j] == '#':
      hold = []
    elif len(hold) == 0:
      hold = [(i,j)]
    else:
      UF.Unite(hold[0][0]*W+hold[0][1]+(H*W), i*W+j+(H*W))
      
solver = []
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      continue
    else:
      var = UF.Count(i*W+j) + UF.Count(i*W+j+(H*W)) - 1
      solver.append(var)

print(max(solver))
      
    



Measured memory_bytes: 430836
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s2 = sc.next();
		for(int i=0;i<3;i++) {
			if (s.charAt(i)!=s2.charAt(2-i)) {
				System.out.print("NO");
				return ;
			}
		}
		System.out.print("YES");
		return ;
	}
}

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

A,B,C,D=map(int,input().split())

c1=B//C
c2=(A-1)//C

cd1=B//((C*D)//gcd(C,D))
cd2=(A-1)//((C*D)//gcd(C,D))

d1=B//D
d2=(A-1)//D


print(str(int(B-A+1-(c1-c2)-(d1-d2)+(cd1-cd2))))

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  for (int i = 1; i < N; i++) {
    string s, tmp;
    cin >> s;
    for (int i = 0; i < S.size(); i++)
      for (int j = 0; j < s.size(); j++)
        if (S.at(i) == s.at(j)) {
          tmp += S.at(i), s.at(j) = ' ';
          break;
        }
    S = tmp;
  }
  sort(S.begin(), S.end());
  cout << S << "\n";
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<llll> vllll;
typedef vector<int> vi;
typedef vector<ull> vull;

// TIMER
std::clock_t __start;
double __duration;
void start_timer() { __start = std::clock(); }
void print_timer() {
	__duration = (std::clock() - __start) / (double)CLOCKS_PER_SEC;
	std::cout << "Duration (msec): " << __duration * 1000 << '\n';
}
// END TIMER

//PI
# define M_PI		3.14159265358979323846
// fast input
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
//char _;

template <class T>
T min_(T a, T b) { return (a < b ? a : b); }
template <class T>
T max_(T a, T b) { return (a > b ? a : b); }
double EPS = 1e-9;
bool eq_(const double& lhs, const double &rhs) {
	return (fabs(lhs - rhs) < EPS);
}

const int INF = int(2e9);
const ll INF_LL = LLONG_MAX;


vll prices;
ll N, X;
vector<vll> best_price_for_color;
vll results;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> X;
	prices.resize(N);
	results.resize(N);
	best_price_for_color.assign(N + 1, vll(N + 1, 0));
	for (int i = 0; i < N; ++i) {
		cin >> prices[i];
		best_price_for_color[0][i] = prices[i];
		results[0] += prices[i];
	}
	for (int k = 1; k < N; ++k) {
		results[k] = X*k;
		for (int i = 0; i < N; ++i) {
			best_price_for_color[k][i] =
				min(best_price_for_color[k - 1][i],
				prices[i - k < 0 ? i - k + N : i-k]);
			results[k] += best_price_for_color[k][i];
		}
	}
	ll res = INF_LL;
	for (int i = 0; i < N; ++i) {
		res = min(res, results[i]);
	}
	cout << res << '\n';
}



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

int main() {
    string S;
    cin >> S;
    int p = 0;
    bool ok = true;
    while(p < S.size()) {
        if(S[p] == 'd' && p+5 <= S.size()) {
            if(p+7 <= S.size() && S.substr(p, 7) == "dreamer") {
                if(S[p+7] == 'a') {
                    p += 5;
                } else {
                    p += 7;
                }
            } else if(S.substr(p, 5) == "dream") {
                p += 5;
            } else {
                ok = false;
                break;
            }
        } else if(S[p] == 'e' && p+5 <= S.size()) {
            if(p+6 <= S.size() && S.substr(p, 6) == "eraser") {
                p += 6;
            } else if(S.substr(p, 5) == "erase") {
                p += 5;
            } else {
                ok = false;
                break;
            }
        } else {
            ok = false;
            break;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
}


Measured memory_bytes: 512
s = list(input())

ans0 = 0
ans1 = 0

for i,se in enumerate(s):
    if i%2==0:
        if se=='0':
            ans1 += 1
        else: ans0 += 1
    else:
        if se=='0':
            ans0 += 1
        else: ans1 += 1

print(min(ans0, ans1))

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String N = sc.next();
        char[] W = new char[N.length()+1];
        W[0]='0';
        for(int i=0;i<N.length();i++){
            W[i+1] = N.charAt(i);
        }
        //System.out.println(sum2(W));
        //assert(sum2(W) == sum(W, W.length-1));
        System.out.println(sum2(W));
    }

    private static int sum2(char[] N){
        int dp0,dp1;
        dp0=0;
        dp1=1;
        for(int i=1;i<N.length;i++){
            int n0,n1;
            int c = N[i]-'0';
            n0 = Math.min(dp0 + c, dp1 + (10 - c));
            n1 = Math.min(dp1 + (10-c-1), dp0+c+1);
            dp0 = n0;
            dp1 = n1;
        }
        return dp0;
//        return Math.min(dp0, dp1);
    }
}

Measured memory_bytes: 35896
N=int(input())
SET=set()
table=list(map(int,input().split()))

for i in range(len(table)):
    SET.add(table[i])

ans=0

num_query=int(input())
num_array=list(map(int,input().split()))

for i in range(len(num_array)):
    if num_array[i] in SET:
        ans+=1

print("%d"%ans)


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

int main() {
    string S;
    cin >> S;
    map<string, string> tmp;
    tmp["Sunny"] = "Cloudy";
    tmp["Cloudy"] = "Rainy";
    tmp["Rainy"] = "Sunny";

    cout << tmp[S] << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    graph = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        graph[b].append(a)
    
    fen_dist, sun_dist = [0] * N, [0] * N
    
    def dfs1(node, parent, dist):
        fen_dist[node] = dist
        for child in graph[node]:
            if child != parent:
                dfs1(child, node, dist + 1)
    
    def dfs2(node, parent, dist):
        sun_dist[node] = dist
        for child in graph[node]:
            if child != parent:
                dfs2(child, node, dist + 1)
    
    dfs1(0, -1, 0)
    dfs2(N - 1, -1, 0)
    
    cnt_fen, cnt_sun = 0, 0
    for i in range(N):
        if fen_dist[i] <= sun_dist[i]:
            cnt_fen += 1
        else:
            cnt_sun += 1
    
    if cnt_fen <= cnt_sun:
        print('Snuke')
    else:
        print('Fennec')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 143280
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


	    while (true) {
		    String[] line = br.readLine().split(" ");

		    int m = Integer.parseInt(line[0]);
		    int f = Integer.parseInt(line[1]);
		    int r = Integer.parseInt(line[2]);

		    if (m == -1 && f == -1 && r == -1) break;

		    String rank = "";
		    if (m == -1 || f == -1) {
		    	rank = "F";
		    	System.out.println(rank);
		    	continue;
		    }

		    m = (m == -1) ? 0 : m;
		    f = (f == -1) ? 0 : f;
		    r = (r == -1) ? 0 : r;

		    if (80 <= m + f) {
		    	rank = "A";
		    } else if (65 <= m + f && m + f < 80) {
		    	rank = "B";
		    } else if (50 <= m + f && m + f < 65) {
		    	rank = "C";
		    } else if (30 <= m + f && m + f < 50) {
		    	if (50 <= r) {
			    	rank = "C";
		    	} else {
			    	rank = "D";
		    	}
		    } else 	if (m + f < 30) {
		    	rank = "F";
		    }

		    System.out.println(rank);
	    }
	}
}

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

const int N = 100005, inf = 0x3f3f3f3f;

int n, head[N], tot;
struct edge { int to, nxt; } e[N << 1];
void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}

int p[N], rec, l[N], r[N];
void dfs0(int x, int f = 0, bool dep = 0) {
	if (p[x] != -1) {
		l[x] = r[x] = p[x];
		if ((rec |= 1 << (dep ^ p[x] & 1)) == 3)
			std::cout << "No\n", std::exit(0);
	} else l[x] = -inf, r[x] = inf;
	for (int i = head[x]; i; i = e[i].nxt) if (e[i].to != f) {
		dfs0(e[i].to, x, dep ^ 1);
		l[x] = std::max(l[x], l[e[i].to] - 1);
		r[x] = std::min(r[x], r[e[i].to] + 1);
	}
}
void dfs1(int x, int f = 0) {
	if (f) l[x] = std::max(l[x], l[f] - 1), r[x] = std::min(r[x], r[f] + 1);
	for (int i = head[x]; i; i = e[i].nxt) if (e[i].to != f) dfs1(e[i].to, x);
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, x, y; i < n; ++i)
		std::cin >> x >> y, link(x, y);
	for (int i = 1; i <= n; ++i) p[i] = -1;
	int k, root; std::cin >> k;
	for (int i = 0, x, y; i < k; ++i)
		std::cin >> x >> y, p[x] = y, root = x;
	dfs0(root), dfs1(root);
	for (int i = 1; i <= n; ++i)
		if (l[i] > r[i]) std::cout << "No\n", std::exit(0);
	std::cout << "Yes\n";
	for (int i = 1; i <= n; ++i)
		std::cout << l[i] << '\n';
	return 0;
}

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

struct node{
  node* right;
  node* left;
  int key,priority;
};

  
node* rightRotate(node* t) {
  node* s = t->left;
  t->left = s->right;
  s->right = t;
  return s;
}

node* leftRotate(node* t) {
  node* s = t->right;
  t->right = s->left;
  s->left = t;
  return s;
}
node* newNode(int key, int priority){
  node* t = new node;
  t->left=NULL; t->right = NULL;
  t->key = key; t->priority = priority;
  return t;
}

node* insert(node* t, int key, int priority) {
  if(t == NULL) return newNode(key,priority);

  if(key == t->key) return t;

  if(key < t->key) {
    t->left = insert(t->left, key, priority);
    if(t->priority < t->left->priority) t = rightRotate(t);
  }else{
    t->right = insert(t->right, key, priority);
    if(t->priority < t->right->priority) t = leftRotate(t);
  }
  return t;
}
node* _delete(node*,int);
node* mydelete(node* t, int key){
  if(t == NULL) return NULL;
  if(key < t->key) t->left = mydelete(t->left, key);
  else if(key > t->key) t->right = mydelete(t->right, key);
  else return _delete(t, key);
  return t;
}

node* _delete(node* t, int key){
  if(t->left == NULL && t->right == NULL) return NULL;
  else if(t->left == NULL) t = leftRotate(t);
    else if(t->right == NULL) t = rightRotate(t);
    else {
      if(t->left->priority > t->right->priority) t = rightRotate(t);
      else t = leftRotate(t);
    }
    return mydelete(t,key);
}


void find(node* t, int key) {
  while(t != NULL && key != t->key) {
    if(key < t->key) t = t->left;
    else t = t->right;
  }
  if(t == NULL) cout << "no" << endl;
  else cout << "yes" << endl;
}

void inorder(node* t) {
  if(t==NULL) return;
  inorder(t->left);
  cout << " " << t->key;
  inorder(t->right);
}

void preorder(node* t) {
  if(t == NULL) return;
  cout << " " << t->key;
  preorder(t->left);
  preorder(t->right);
}

int main() {
  node* root=NULL;
  int n,key,priority;
  string s;
  
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> s;
    if(s == "insert") {
      cin >> key >> priority;
      root = insert(root, key, priority);
    }
    else if(s == "find") {
      cin >> key;
      find(root, key);
    }
    else if(s == "delete") {
      cin >> key;
      root = mydelete(root, key);
    }
    else if(s == "print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 9448
#include<stdio.h>
#include <iostream>
#include <string.h>

using namespace std;

typedef struct{
    char name[11];
    int time;
}Process;

class ProcessQueue{
public:
    ProcessQueue(int size):
        m_size(size),
        m_head(0),
        m_tail(0),
        number(0)
    {
        m_process = new Process[m_size];
    };

    ~ProcessQueue(){
        delete[] m_process;
    };

    void enQueue(Process process){
        m_process[m_tail] = process;
        number++;
        m_tail = (++m_tail)%m_size;
    };

    Process deQueue(){
        number--;
        if(m_head < m_size-1){
            m_head++;
            return m_process[m_head-1];
        }else{
            m_head = 0;
            return m_process[m_size-1];
        }
    };

    int getNumber(){
        return number;
    }

private:
    int m_head;
    int m_tail;
    int m_size;
    int number;
    Process* m_process;

};

int main(){

    int n,q,totaltime=0;
    scanf("%d%d",&n,&q);

    ProcessQueue queue(n);

    Process tmp;
    for(int i = 0; i < n; i++){
        scanf("%s%d",&tmp.name,&tmp.time);
        queue.enQueue(tmp);
    }

    while(queue.getNumber() != 0){
        tmp = queue.deQueue();
        if(tmp.time - q > 0){
            totaltime += q;
            tmp.time -= q;
            queue.enQueue(tmp);
        }else{
            totaltime += tmp.time;
            printf("%s %d\n",tmp.name,totaltime);
        }
    }

}

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

int main(){
    int j = 0;
    int x = 0;
    int y = 0;
    while (1) {
        cin >> x >> y;
        if ((x == 0)&(y == 0)) break;
        if (x<=y) cout << x << " "<< y << endl;
        else cout << y << " "<< x << endl;
        j++;
    }
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main { //YES! (Pay attention to indexing variables when debugging)
	//You tend to get them mixed up; Don't doubt your algorithmic thinking cuz you're a beast!

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		int X = input.nextInt();
		long[][] data = new long[N][M+1]; //Extra slot for cost
		for (int i = 0; i < N; i++) {
			data[i][0] = input.nextInt();
			for (int j = 1; j <= M; j++) {
				data[i][j] = input.nextInt();
			}
		}
		long cost = Integer.MAX_VALUE;
		String[] possibilities = Recur(N).split(" ");
		for (int i = 0; i < possibilities.length; i++) {
			String x = possibilities[i];
			long[] cmp = new long[M];
			long curcost = 0;
			for (int j = 0; j < N; j++) {
				if (x.charAt(j)=='Y') {
					curcost+=data[j][0];
					for (int k = 1; k<=M; k++) {
						cmp[k-1]+=data[j][k];
					}
				}
			}
			boolean exceeded = true;
			for (int j = 0; j < M; j++) {
				if (cmp[j]<X) {
					exceeded=false;
					break;
				}
			}
			if (exceeded) cost = Math.min(cost, curcost);
		}
		if (cost!=Integer.MAX_VALUE) System.out.println(cost);
		else System.out.println(-1);
	}
	public static String Recur(int N) {
		if (N==1) return "Y N ";
		String[] arr = Recur(N-1).trim().split(" ");
		String ans = "";
		for (int i = 0; i < arr.length; i++) {
			ans+=arr[i]+"Y ";
		}
		for (int i = 0; i < arr.length; i++) {
			ans+=arr[i]+"N ";
		}
		return ans.trim();
	}
}


Measured memory_bytes: 45320
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll n,k,s;
    cin >> n >> k >> s;
    rep(i,k) cout << s << ' ';
    ll m=(s==1e9)?s-1:1e9;
    rep(i,n-k) cout << ' ' << m;
    cout << endl;
   
    return 0;   
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using coord = pair<int, int>;

int main() {
    int W, H;
    cin >> H >> W;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    vector<vector<int>> dist(H, vector<int>(W, -1));

    deque<coord> deq;
    deq.emplace_front(ch - 1, cw - 1);
    dist[ch - 1][cw - 1] = 0;
    while (!deq.empty()) {
        int h = deq.front().first;
        int w = deq.front().second;
        deq.pop_front();
        for (int i = h - 1; i <= h + 1; i++) {
            for (int j = w - 1; j <= w + 1; j++) {
                if (i >= 0 && i < H && j >= 0 && j < W && (i == h || j == w)) {
                    if (S[i][j] == '.' &&
                        (dist[i][j] == -1 || dist[i][j] > dist[h][w])) {
                        dist[i][j] = dist[h][w];
                        deq.emplace_front(i, j);
                    }
                }
            }
        }
        for (int i = h - 2; i <= h + 2; i++) {
            for (int j = w - 2; j <= w + 2; j++) {
                if (i >= 0 && i < H && j >= 0 && j < W) {
                    if (S[i][j] == '.' && dist[i][j] == -1) {
                        dist[i][j] = dist[h][w] + 1;
                        deq.emplace_back(i, j);
                    }
                }
            }
        }
    }

    // for (int h = 0; h < H; h++) {
    // for (int w = 0; w < W; w++) {
    // cout << dist[h][w] << " ";
    // }
    // cout << endl;
    // }

    cout << dist[dh - 1][dw - 1] << endl;

    return 0;
}


Measured memory_bytes: 9524
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

const ll N=5e5+5;

ll sp[N];

void sieve(){
  for(int i=2;i<N;i++)sp[i]=i;

    for(int i=2;i*i<N;i++){
      if(sp[i]==i){
      for(int j=i*i;j<N;j+=i){
        sp[j]=i;
      }
    }
}

}

ll fac[N],inv[N];

ll p=1e9+7;

void fill(){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%p;
    inv[i]=powM(fac[i],p-2,p);
  }
}

ll c(ll a,ll b,ll p){
if(a<b)return 0;

  return (fac[a]*inv[a-b]%p)*(inv[b])%p;
}


ll lcm(ll a,ll b)
{
  return (a*b)/(__gcd(a,b));
}

int main()
{ 

  IOS;


ll a,b,c,d;

cin>>a>>b>>c>>d;

ll l1=a%c?c+a-a%c:a,r1=b-b%c;

ll l2=a%d?d+a-a%d:a,r2=b-b%d;

ll e=lcm(c,d);

ll l3=a%e?e+a-a%e:a,r3=b-b%e;

ll cnt=0;

if(l1<=r1){
cnt+=1+(r1-l1)/c;
}



if(l2<=r2){
cnt+=1+(r2-l2)/d;
}

if(l3<=r3){
cnt+=-1-(r3-l3)/e;
}

cnt=(b-a+1)-(cnt);

cout<<cnt<<endl;

return 0;
 
}



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

int main() {
  vector<int> A(3);
  int K;
  cin >> A.at(0) >> A.at(1) >> A.at(2);
  cin >> K;
  for(int i = 0; i < K; i++) {
    sort(A.begin(), A.end()); 
    A.at(2) = A.at(2) * 2; 
  }
  cout << A.at(0) + A.at(1) + A.at(2) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[40][40][40][40],dp2[40][40][40][40],vi[40][40][40][40];
int u[40][40],su[40][40];
int h,w,s,a;
int sum(int si,int sj,int ti,int tj){
  //ti--;tj--;
  return su[ti][tj]-su[ti][sj]-su[si][tj]+su[si][sj];
}
void dfs(int si,int sj,int ti,int tj){
  if(vi[si][sj][ti][tj]) return;
  vi[si][sj][ti][tj]=1;
  int val=sum(si,sj,ti,tj);
  int res=1,res2=s-(a-val);
  //cout<<si<<" "<<sj<<" "<<ti<<" "<<tj<<endl;
  //cout<<res2<<" "<<a<<" "<<val<<endl;

  if(res2<0) return;
  for(int i=si+1;i<ti;i++){
    dfs(si,sj,i,tj);
    dfs(i,sj,ti,tj);
    if(dp[si][sj][i][tj]<0||dp[i][sj][ti][tj]<0) continue;
    if(dp[si][sj][i][tj]+dp[i][sj][ti][tj]==res){
      res2=max(res2,min(dp2[si][sj][i][tj],dp2[i][sj][ti][tj]));
    }
    if(dp[si][sj][i][tj]+dp[i][sj][ti][tj]>res){
      res=dp[si][sj][i][tj]+dp[i][sj][ti][tj];
      res2=min(dp2[si][sj][i][tj],dp2[i][sj][ti][tj]);
    }
  }
  for(int j=sj+1;j<tj;j++){
    dfs(si,sj,ti,j);
    dfs(si,j,ti,tj);
    if(dp[si][sj][ti][j]<0||dp[si][j][ti][tj]<0) continue;
    if(dp[si][sj][ti][j]+dp[si][j][ti][tj]==res){
      res2=max(res2,min(dp2[si][sj][ti][j],dp2[si][j][ti][tj]));
    }
    if(dp[si][sj][ti][j]+dp[si][j][ti][tj]>res){
      res=dp[si][sj][ti][j]+dp[si][j][ti][tj];
      res2=min(dp2[si][sj][ti][j],dp2[si][j][ti][tj]);
    }
  }
  
  //cout<<si<<" "<<sj<<" "<<ti<<" "<<tj<<endl;
  //cout<<res<<" "<<res2<<endl;
  
  dp[si][sj][ti][tj]=res;
  dp2[si][sj][ti][tj]=res2;
}
int main(){
  while(cin>>h>>w>>s,h||w||s){
    memset(dp,-1,sizeof(dp));
    memset(dp2,-1,sizeof(dp2));
    memset(u,0,sizeof(u));
    memset(su,0,sizeof(su));
    memset(vi,0,sizeof(vi));

    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin>>u[i][j];
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)
	su[i+1][j+1]=su[i+1][j]+u[i][j];
      for(int j=0;j<w;j++)
	su[i+1][j+1]+=su[i][j+1];
    }
    a=su[h][w];
    dfs(0,0,h,w);
    cout<<dp[0][0][h][w]<<" "<<dp2[0][0][h][w]<<endl;
  }
  return 0;
}

Measured memory_bytes: 33104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void wri(ll a){write(a); putchar(' ');}
inline void writeln(ll a){write(a); puts("");}
const int N=100005;
ll sz[N];
int f[N],ans[N],fa[N];
pair<int,pair<int,int> > e[N];
inline int gf(int x){
	return fa[x]==x?x:fa[x]=gf(fa[x]);
}
signed main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++)sz[fa[i]=i]=read();
	for(int i=1;i<=m;i++){
		int s=read(),t=read(),w=read();
		e[i]=mp(w,mp(s,t));
	}
	sort(&e[1],&e[m+1]);
	int cnt=0;
	for(int i=1;i<=m;i++){
		int s=e[i].second.first,t=e[i].second.second,w=e[i].first;
		int tx=gf(s),ty=gf(t);
		if(tx==ty){if(sz[tx]<w){f[tx]++;cnt++;} continue;}
		fa[tx]=ty; sz[ty]+=sz[tx]; f[ty]+=f[tx]; f[ty]++; cnt++; //cout<<sz[ty]<<" "<<cnt<<endl;
		if(sz[ty]>=w){cnt-=f[ty]; f[ty]=0;}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3072
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	int w, h, n; cin >> w >> h >> n;
	int minx = 0, maxx = w, miny = 0, maxy = h;
	for (int i = 0; i < n; i++){
		int x, y, a; cin >> x >> y >> a;
		if (a == 1)minx = max(minx, x);
		else if (a == 2)maxx = min(maxx, x);
		else if (a == 3)miny = max(miny, y);
		else if (a == 4)maxy = min(maxy, y);
	}
	cout << max(0, maxx - minx)*max(0, maxy - miny) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
int R,C;
long long result[1001][1001];
int countPaths() 
{ 
	if (result[0][0]==-1) 
		return 0; 
	for (int i=0; i<R; i++) 
	{ 
		if (result[i][0] == 0) 
			result[i][0] = 1;  
		else
			break; 
	} 
	for (int i=1; i<C; i++) 
	{ 
		if (result[0][i] == 0) 
			result[0][i] = 1;  
		else
			break; 
	} 
	for (int i=1; i<R; i++) 
	{ 
		for (int j=1; j<C; j++) 
		{ 
			if (result[i][j] == -1) 
				continue; 
			if (result[i-1][j] > 0) 
				result[i][j] = (result[i][j] + result[i-1][j])%1000000007; 
			if (result[i][j-1] > 0) 
				result[i][j] = (result[i][j] + result[i][j-1])%1000000007; 
		} 
	}  
	result[R-1][C-1]%=1000000007;
	return (result[R-1][C-1] > 0)? result[R-1][C-1] : 0; 
} 

// Driver code 
int main() 
{ 
	int n,m;
	cin>>n>>m;
	R=n;C=m;
	string a[n];
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			//cin>>a[i][j];
			if (a[i][j]=='.'){
				result[i][j]=0;
			}
			else {
				result[i][j]=-1;
			}
			//result[i][j]=a[i][j];
		}
	} 
	cout << countPaths(); 
	return 0; 
} 


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    ll l, r;
    cin >> l >> r;

    ll ans = (ll) 1e17;
    ll ops = 0;

    for(ll i = l; i <= min(l + 2019, r); i++) {
        for(ll j = i + 1; j <= min(l + 2019, r); j++) {
            ops++;
            ans = min(ans, (i*j) % 2019);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256