akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll K;
    sll(K);
    ll V = 7;
    ll idx = 1;

    bool not_found = false;
    while(idx < 2*K){
        if(V % K==0){
            not_found = false;
            break;
        }else{
            not_found = true;
        }
        V = (V * 10 + 7) % K;
        ++idx;
    }

    if(not_found){
        cout << "-1" <<endl;
    }else{
        cout << idx <<endl;
    }


}

int main(){
    Main();
}

Measured memory_bytes: 3228
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> N >> M;
	vector<long double>dp(1 << N, -1);
	vector<long double>a(N);
	vector<long double>b(N);
	vector<long double>c(N);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	long double ans = 0;
	for (int i = 0; i < 1 << N; i++) {
		for (int j = 0; j < N; j++) {
			if (dp[i | (1 << j)] >= 0)continue;
			dp[i | (1 << j)] = dp[i];
			for (int k = 0; k < N; k++) {
				if ((i >> k) & 1) {
					dp[i | (1 << j)] += (a[j] - a[k])*(a[j] - a[k]);
					dp[i | (1 << j)] += (b[j] - b[k])*(b[j] - b[k]);
					dp[i | (1 << j)] += (c[j] - c[k])*(c[j] - c[k]);
				}
			}
		}
		int num = 0;
		for (int j = 0; j < N; j++) {
			num += (i >> j) & 1;
		}
		if (num == M) {
			ans = max(ans, dp[i]);
		}
	}
	cout << setprecision(20) << ans << endl;
}


Measured memory_bytes: 19220
// F - XOR Matching
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int m, k;
	cin >> m >> k;

	if (m == 0) {
		cout << (k == 0 ? "0 0" : "-1") << endl;
	} else if (m == 1) {
		cout << (k == 0 ? "0 0 1 1" : "-1") << endl;
	} else if (k >= (1 << m)) {
		cout << -1 << endl;
	} else {
		for (int i = (1 << m) -1 ; i > 0; i--) cout << (i ^ k) << ' ';
		cout << k << ' ';
		for (int i = 1; i < (1 << m); i++) cout << (i ^ k) << ' ';
		cout << k << endl;
	}

	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(n);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
using namespace std;

    vector<long> dp;

    long fib(int n){
        if(dp[n]!=-1) return dp[n];
        if(n==0) return 1;
        if(n==1) return 1;
        return dp[n]= fib(n-1)+fib(n-2);
    }

int main(){

    int n;
    cin>>n;

    dp.assign(n+1,-1);
    cout <<fib(n)<< endl;
   
}


Measured memory_bytes: 3108
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, C: int, B: "List[int]", A: "List[List[int]]"):
    ans = 0
    for i in range(N):
        t = C
        for j in range(M):
            t += A[i][j] * B[j]
        if t > 0:
            ans += 1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    A = [[int(next(tokens)) for _ in range(M)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, M, C, B, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62028
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
  int n;
  long long x;
  cin >> n >> x;
  long long a[n];
  long long sum = 0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  sort(a,a+n);
  int ans = 0;
  long long y = x;
  rep(i,n){
    if(y>=a[i]){
      ans++;
      y-=a[i];
    }
    else{
      break;
    }
  }
  if(ans == n && x!=sum){
    cout << n-1 << endl;
  }
  else{
    cout << ans << endl;
  }
}


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


int main()
{
	string s; 
	cin >> s; 

	int ans = 1000; 
	for (int i = 0; i < s.size()-2; ++i)
	{
		int num = abs((s[i] - '0')*100 + (s[i+1] - '0')*10 + (s[i+2] - '0') - 753); 
		ans = min(ans,num); 
	}

	cout << ans << endl; 

	return 0; 

}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

bool operator < (pair<int, string> a, pair<int, string> b) {
	if (a.first < b.first) return (true);
	if (a.first > b.first) return (false);
	return (a.second < b.second);
}

void Main() {
	int N, M; cin >> N >> M;
	int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	vint A(M); cin >> A;
	sort(rbegin(A), rend(A));
	vector<pair<int, string>> dp(N+1, make_pair(-INF, ""));
	dp[0] = make_pair(0, "");

	for (int i = 0; i < M; i++) {
		int c = cost[A[i]];
		for (int j = 0; j < N; j++) {
			auto nd = dp[j];
			nd.first++;
			nd.second += (char)(A[i]+'0');
			if (j+c <= N && dp[j+c] < nd) {
				dp[j+c] = nd;
			}
		}
	}
	cout << dp[N].second << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 38220
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c=0,d=1,e,f,g,h,n,m,mx=0,x,y,ans=0;
  cin>>n;
  int aa[n];
  rep(i,0,n) cin>>aa[i];
  sort(aa,aa+n); reverse(aa,aa+n);
  rep(i,0,n){
    c+=aa[i]*d;
    d*=-1;
  }
  co(c);
    
  return 0;
}

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

using namespace std;

int a[51], MaxDuong, MaxAm, n, posduong, posam;
int cnt, x[10000], y[10000];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if(MaxDuong < a[i])
        {
            MaxDuong = a[i];
            posduong = i;
        }
        if(MaxAm > a[i])
        {
            MaxAm = a[i];
            posam = i;
        }
    }
    if(abs(MaxDuong) > abs(MaxAm))
    {
        for(int i = 1; i <= n; i++)
        {
            if(a[i] < 0)
            {
                x[++cnt] = posduong;
                y[cnt] = i;
            }
        }
        for(int i = 2; i <= n; i++)
        {
            x[++cnt] = i - 1;
            y[cnt] = i;
        }
    }
    else
    {
        for(int i = 1; i <= n; i++)
        {
            if(a[i] > 0)
            {
                x[++cnt] = posam;
                y[cnt] = i;
            }
        }
        for(int i = n - 1; i >= 1; i--)
        {
            x[++cnt] = i + 1;
            y[cnt] = i;
        }
    }
    cout << cnt << '\n';
    for(int i = 1; i <= cnt; i++) cout << x[i] << ' ' << y[i] << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static int count(int n){
        int cnt = 1;
        int num = 1;
        while(true){
            num = 3 * num + 1;
            if(n < num)
                break;
            cnt++;
        }
        return cnt;
    }
    public static void shellSort(int A[], int n){
        int cnt = 0;
        int m = count(n);
        int G[] = new int[m];
        int x = 1;
        for(int i = 0 ; i < m ; i++){
            G[m-1 - i] = x;
            x = 3*x + 1;
        }
        for(int i = 0 ; i < m ; i++){
            for(int j = G[i] ; j < n ; j++){
                int v = A[j];
                int k = j - G[i];
                while(k >= 0 && A[k] > v){
                    A[k+G[i]] = A[k];
                    k -= G[i];
                    cnt++;
                }
                A[k+G[i]] = v;
            }
        }
        System.out.println(m);
        for(int i = 0 ; i < m-1 ; i++)
            System.out.print(G[i] + " ");
        System.out.println(G[m-1]);
        System.out.println(cnt);
        for(int i = 0 ; i < n ; i++)
            System.out.println(A[i]);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int A[] = new int[n];
        for(int i = 0 ; i < n ; i++)
            A[i] = sc.nextInt();
        shellSort(A,n);
    }
}


Measured memory_bytes: 299788
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, l;
    cin >> n >> l;

    vector <int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    deque <int> deq;
    for (int i = 0; i < l; i++) {
        while (!deq.empty() && a[deq.back()] >= a[i]) deq.pop_back();
        deq.push_back(i);
    }
    cout << a[deq.front()];

    for (int i = l; i < n; i++) {
        if (deq.front() == i - l) deq.pop_front();
        while (!deq.empty() && a[deq.back()] >= a[i]) deq.pop_back();
        deq.push_back(i);
        cout << ' ' << a[deq.front()];
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 6796
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int W = sc.nextInt();

		int w[] = new int[n];
		int v[] = new int[n];

		for(int i = 0; i < n; i++){
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}

		long dp[][] = new long[n + 1][W + 1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < w[i]; j++){
				dp[i + 1][j] = dp[i][j];
			}
			for(int j = w[i]; j <= W; j++){
				dp[i + 1][j] = Math.max(dp[i][j], v[i] + dp[i][j - w[i]]);
			}
		}

//		for(int i = 1; i <= n; i++){
//			for(int j = 1; j <= W; j++){
//				System.out.print(dp[i][j] + " ");
//			}
//			System.out.println();
//		}

		System.out.println(dp[n][W]);
	}

}


Measured memory_bytes: 132188
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 == 0)
    {
        cout << "Alice" << endl;
    }
    else
    {
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;
using P = pair<ll, ll>;

const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void fail() {
  cout << -1 << endl;
  exit(0);
}

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int mod = 1e9 + 7;
// const int mod = 998244353;

int main(){
    double R;
    cin >> R;
    cout << 2 * R * 3.14159265 << endl;
}

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

#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int ans = INF;
int n, k;

int func(int now, int cnt) {
    if ( cnt == n ) return now;
    return min(func(now*2, cnt+1), func(now+k, cnt+1));
}
signed main() {
    cin >> n >> k;
    cout << func(1, 0) << endl;
}


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

bool ques(ll n){
    cout<<"? "<<n<<endl;
    string ans;
    cin>>ans;
    return (ans=="Y");
}

int main(void){
    int d=1e9;
    if(ques(d)){
        while(d>1 && ques(d-1)) d/=10;
        cout<<"! "<<d<<endl;
    }else{
        while(d/=10,!ques(d));
        ll l=d,r=d*10;
        while(l+1<r){
            ll m=(l+r)/2;
            if(ques(m*10)) r=m;
            else l=m; 
        }
        cout<<"! "<<r<<endl;
    }
    return 0;
}


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

int main() {

    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = N-1;

    rep(i, N) {
        x -= a[i];
        if (x < 0) {
            ans = i;
            break;
        } else if (x == 0) {
            ans = i+1;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	int n;
	
	string abc = "abcdefghijklmnopqrstuvwxyz";
	string abc2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	string abc3 = abc + abc2 + abc + abc2;

	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> key(n);
		for (int i = 0; i < n; i++) {
			cin >> key[i];
		}
		string s;
		cin >> s;

		string ans;

		int sz = abc3.size();

		for (int i = 0; i < s.size(); i++) {
			for (int j = sz - 1; j >= 0; j--) {
				if (s[i] == abc3[j]) {
					ans += abc3[j - key[i%n]];
					break;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
void Main(){
    int N = read();
    if (N == 1) {
        printf("Hello World\n");
    }
    else {
        int A = read(), B = read();
        printf("%d\n", A+B);
    }
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	string S,T;
	cin >> S >> T;

	int N = S.size();
	int M = T.size();

	int best = 0;
	for(int i = 0; i < N - M + 1; i++){
		string aux = S.substr(i,M);

		int n = 0;
		for(int j = 0; j < M; j++){
			n += (aux[j] == T[j]);
		}

		best = max(best,n);

	}

	cout << M - best << endl;
	
	return 0;
}


Measured memory_bytes: 3656
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M = MAP()
    AB = [LIST() for _ in range(M)]

    uf = UnionFind(N)
    ans = [N*(N-1)//2]
    for i, (A, B) in enumerate(AB[::-1]):
        if i != M-1:
            tmp = ans[-1]
            if not uf.same(A-1, B-1):
                tmp -= uf.size(A-1)*uf.size(B-1)
            ans.append(tmp)
            uf.union(A-1, B-1)

    print(*ans[::-1], sep="\n")

if __name__ == '__main__':
    main()


Measured memory_bytes: 39040
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;};
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
int main(){
    ll A,B;
    cin>>A>>B;
    cout<<lcm(A,B)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int k, s; cin >> k >> s;
    int ans=0,sum=0;
    for (int i=0; i<=k; i++){
        for (int j=0; j<=k; j++){
            sum = 0;
            sum+= (i+j);
            if (0<=(s-sum) && (s-sum)<=k) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
s = list(map(int, list(input())))
n = len(s)

countdic = {}
mod = 2019

num = 0
d = 1
for i in range(1,n+1):
    num += s[n-i]*d
    num %= mod
    if num in countdic:
        countdic[num] += 1
    if num not in countdic:
        countdic[num] = 1
    d = (10*d)%mod

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

if 0 in countdic:
    ans += countdic[0]

print(ans)

Measured memory_bytes: 12268
#include<iostream>

using namespace std;
int main()
{
    int n,a[101];
    cin>>n;int s=0,sum=0;
    for(int i=0;i<n;i+=1){
        cin>>a[i];
        if(a[i]%2==0){
           s++;
           if(a[i]%3==0 || a[i]%5==0){
              sum++;
           }
        }
    }
    if(s==sum) cout<<"APPROVED\n";
    else cout<<"DENIED\n";


    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF (9e18)
#define int ll
#define EPS (1e-6)
#define DB(x) #x<<":"<<x<<" "
using namespace std;
using ll=long long;
using pii=pair<int,int>;

void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	b%=MOD;
	int ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int a[100010];
bool vis[100010];

int32_t main() {
	INIT();
	//code...
	int n; cin>>n;
	For(i,0,n-1) cin>>a[i+1];
	memset(vis,0,sizeof(vis));
	int now=1;
	int ans=0;
	bool ac=true;
	while(now!=2){
		if(vis[now]){
			ac=false;
			break;
		}
		vis[now]=true;
		now=a[now];
		ans++;
	}
	if(ac) cout<<ans<<"\n";
	else cout<<"-1\n";
	return 0;
}


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

#define el '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define DEBUG cerr << "DEBUG >>> " 
#define ms(a,b) memset(a, b, sizeof(a))

typedef long long ll;

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

  double n, k;
  cin >> n >> k;
  double ans = 0;
  for(ll i = 1; i <= n; i++){
    ll cur = i, cnt = 0;
    while(cur < k){
      cur *= 2;
      cnt++;
    }
    ans += 1/(double)(1<<cnt);
  }
  ans /= n;
  cout << fixed << setprecision(9) << ans << el;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  map<ll, ll> mp;
  int n;
  cin >> n;
  rep(i, n) {
    int p;
    cin >> p;
    mp[p] += 1;
  }

  ll ans = 0;
  for (auto itr : mp) {
    if (itr.second > itr.first) {
      ans += abs(itr.first - itr.second);
    } else if (itr.second < itr.first) {
      ans += itr.second;
    }
  }

  cout << ans <<endl;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int m_mul(int x, int y) {
    return 1LL * x * y % MOD;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, pos = 0, neg = 0, zero = 0;
    cin >> n >> k;
    vector<int> a(n);
    for (int& it : a) {
        cin >> it;
        if (it > 0)
            pos++;
        else if (it < 0)
            neg++;
        else
            zero++;
    }
    // cout << pos << ' ' << neg << ' ' << zero << endl;
    int ans = 1;
    if (pos == 0) {
        if (k > neg) {
            ans = 0;
        } else {
            if (k % 2 == 1) {
                if (zero > 0)
                    ans = 0;
                else {
                    sort(a.rbegin(), a.rend());
                    for (int i = 0; i < k; i++)
                        ans = m_mul(ans, abs(a[i]));
                    ans = MOD - ans;
                }
            } else {
                sort(a.begin(), a.end());
                for (int i = 0; i < k; i++)
                    ans = m_mul(ans, abs(a[i]));
                if (ans < 0)
                    ans += MOD;
            }
        }
    } else {
        if (pos + neg < k) {
            ans = 0;
        } else {
            sort(a.begin(), a.end(),
                 [](int x, int y) { return abs(x) > abs(y); });
            // for (int i = 0; i < n; i++)
            //     cout << a[i] << " ";
            // cout << endl;

            int i = 0;
            vector<int> P, N;
            for (i = 0; i < k; i++) {
                if (a[i] > 0)
                    P.push_back(a[i]);
                else if (a[i] < 0)
                    N.push_back(a[i]);
            }
            if ((int)N.size() % 2 == 1 && k < n) {
                int nxp = 0, nxn = 0;
                for (; i < n; i++) {
                    if (a[i] < 0 && !nxn)
                        nxn = a[i];
                    else if (a[i] > 0 && !nxp)
                        nxp = a[i];
                    if ((nxn && nxp) || a[i] == 0)
                        break;
                }
                // int x = (P.empty() ? 1 : P.back());
                if (P.empty() || (ll)nxp * P.back() >= (ll)nxn * N.back()) {
                    N.pop_back();
                    P.push_back(nxp);
                } else {
                    P.pop_back();
                    N.push_back(nxn);
                }
            }
            for (int it : P)
                ans = m_mul(ans, it);
            for (int it : N)
                ans = m_mul(ans, it);
            if (ans < 0)
                ans += MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5000
using System;
using System.IO;//StreamWriterのために必要
using System.Collections.Generic;//List型を使うために必要

namespace dotnetproj
{
    class Program
    {
        static void Main(string[] args)
        {
            int count=0;
            string input = Console.ReadLine();
            char[] chars = input.ToCharArray();
            foreach(char c in chars){
                if(c=='1') count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

constexpr LL mod = 1e9 + 7;

int main() {

    LL N, M;
    cin >> N >> M;

    vector<LL> S(N), T(M);
    for (int i = 0; i < N; i++) cin >> S[i];
    for (int j = 0; j < M; j++) cin >> T[j];

    vector<vector<LL>> dp(N + 1, vector<LL>(M + 1, 0));
    for (int i = 0; i <= N; i++) for (int j = 0; j <= M; j++) if (i == 0 || j == 0) dp[i][j] = 1;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (S[i] == T[j]) {
                dp[i + 1][j + 1] =  dp[i + 1][j] + dp[i][j + 1];
                dp[i + 1][j + 1] %= mod;
            } else {
                dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
                dp[i + 1][j + 1] %= mod;
                dp[i + 1][j + 1] -= dp[i][j];
                dp[i + 1][j + 1] += mod;
                dp[i + 1][j + 1] %= mod;
            }
        }
    }


    cout << dp[N][M] << endl;
}

































Measured memory_bytes: 31616
N = int(input())
count = 0
flag = False
for i in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
    else:
        count = 0
    if count >= 3:
        flag = True
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62272
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s; cin>>s;
	int cnt[3] ={0};
	rep(i,s.size()){
		++cnt[s[i]%3];
	}
	bool ans = true;
	if(abs(cnt[0]-cnt[1])>=2)ans = false;
	if(abs(cnt[2]-cnt[1])>=2)ans = false;
	if(abs(cnt[0]-cnt[2])>=2)ans = false;
	cout<<((ans)?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 512
(k, s) = map(int, input().split(" "))
cnt = 0
for i in range(0, k+1):
    if s - i <= 2 * k:
        x = min(k, s - i) + 1
        for j in range(0, x):
            if s - i - j <= k:
                cnt += 1
print(cnt)


Measured memory_bytes: 41308
#include <bits/stdc++.h>
using namespace std;
int a[100];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int minj = i;
    for (int j = i; j < n; j++) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    if (i != minj) {
      swap(a[i], a[minj]);
      cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (i ? " " : "") << a[i];
  }
  cout << "\n" << cnt << "\n";
}


Measured memory_bytes: 3100
main = do
  n <- readLn
  if ((mod n 10 == mod (div n 10) 10) && (mod (div n 10) 10 == mod (div n 100) 10)) || ((mod (div n 10) 10 == mod (div n 100) 10) && (mod (div n 100) 10 == mod (div n 1000) 10))
    then putStrLn "Yes"
    else putStrLn "No"

Measured memory_bytes: 508
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll a,b,c,d,ans=0;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}
int Main(void){
    cin>>a>>b>>c>>d;
    ll LCM=lcm(c,d);
    a--;
    ll ansA=a-(a/c+a/d)+a/LCM;
    ll ansB=b-(b/c+b/d)+b/LCM;
    cout<<ansB-ansA<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 256
import java.util.*
import java.math.*

fun main(args: Array<String>) {
//    var (r, d, x) = readLine()!!.split(" ").map { it.toInt() }
    var N = readLine()!!.toInt()
//    val S = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
    val W = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    var s1 = W.sum()
    var s2 = 0
    var ans = s1
    for (w in W) {
        s1 -= w
        s2 += w
        ans = Math.min(ans, Math.abs(s1-s2))
    }
    println(ans)
}


Measured memory_bytes: 37568
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let r: i64 = read();
    let g: i64 = read();
    println!("{}", g + (g - r));
}


Measured memory_bytes: 4352
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

def calc():
    result = 0
    for i in range(N):
        x = min(A[i], B[i])
        A[i] -= x
        B[i] -= x
        result += x
        x = min(A[i + 1], B[i])
        A[i + 1] -= x
        B[i] -= x
        result += x
    return result

print(calc())


Measured memory_bytes: 82020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
int N; cin >> N;
VVI A(2, VI(N)); rep(i, 0, 2) {rep(j, 0, N) scanf("%d", &A[i][j]);}

// 累積和
VVI s(2, VI(N+1, 0));
rep(i, 0, 2) partial_sum(ALL(A[i]), s[i].begin()+1);

int maxi=0;
rep(i, 1, N+1){
    maxi = max(maxi, s[0][i] + s[1][N] - s[1][i-1]);
}

cout << maxi << "\n";

return 0;
}

// 境界，出力文字列 チェック



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

#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
const int MOD =1e9+7;
const int64_t INF = INT64_MAX;


int32_t main(){
    //ios_base::sync_with_stdio(false);cin.tie();
    //If you hack my code , You are gay;
    int n;
    cin>>n;
    int ans=0;
    int tmp=n;
    vector<int> sum(50);
    for(int i=1;i<50;i++){
        sum[i]=sum[i-1]+i;
    }
    for(int i=2;i*i<=n;i++){
        int cnt=0;
        while(n%i==0){
            cnt++;
            n/=i;
        }
        ans+=upper_bound(all(sum),cnt)-sum.begin()-1;
       // cout<<i<<" "<<cnt<<" "<<upper_bound(all(sum),cnt)-sum.begin()-1<<endl;
    }
    if(n>1) ans++;
    cout<<ans;
    return 0;
}

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

using namespace std;



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

	for(int i = A; i <= B; ++i) {
		if (i % K == 0) {
			cout << "OK" << '\n';
			return 0;
		}
	}

	cout << "NG" << '\n';

	return 0;	
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()


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

  int n;
  cin >> n;

  vector<vector<pii>> edge(n);
  vi a(n-1),b(n-1);

  rep(i,n-1){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
    edge[a[i]].push_back(make_pair(b[i],i));
    edge[b[i]].push_back(make_pair(a[i],i));
  }

  vi ret(n-1);
  int cnt = 0;

  queue<pii> q;
  rep(i,edge[0].size()){
    cnt++;
    q.push(edge[0][i]);
    ret[edge[0][i].second] = cnt;
  }

  while(!q.empty()){
    pii cur = q.front();
    int c = 0;
    q.pop();
    rep(i,edge[cur.first].size()){
      if(cur.second == edge[cur.first][i].second)continue;
      c++;
      if(ret[cur.second] == c)c++;
      ret[edge[cur.first][i].second] = c;
      q.push(edge[cur.first][i]);
    }
    cnt = max(c,cnt);
  }
  
  cout << cnt << endl;
  rep(i,n-1)cout << ret[i] << endl;
}


Measured memory_bytes: 7808
import collections
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
cnt = collections.Counter(a).most_common()
heapq.heapify(cnt)


for i, set_bc in enumerate(bc):
    now0,now1 = heapq.heappop(cnt)
    b,c = set_bc
    if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
    tmpb = 0
    for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
    if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
if now1 != 0:
    heapq.heappush(cnt,(now0,now1))
ans = 0

for i in range(len(cnt)):
    val, num = heapq.heappop(cnt)
    ans += val * num
print(ans)


Measured memory_bytes: 35008
#include<set>
using namespace std;
#include<iostream>
int	main(){

/*	int N, C, c[100], n;
	cin >> N;
	C = 0;
	n = 0;

	for (int i = 0; i <N; i++ ){
		cin >> c[i];
		C+= c[i];
	}

	for (int i = 0; i <N; i++ ){
		if (c[i] <= 0.1*C){
			n+= 30;
		}
	}
	cout << n << endl;
}
	/*
	while(true){
	
	int A,B,C,D,E,F,G,H,I,J,answer;
		
	cin >> A;
	if(A == 0) return 0;
	cin >> B >> C >> D >> E >> F >> G >> H >> I >> J;
	answer = A - B - C - D-E-F-G-H-I-J;
	cout << answer << endl;

	}
	*/
	/*
	int A,B,C,D,E,F;

	cin >> A, B, C, D;
	if(A < B, C, D){ 
		cout << B + C + D << endl;
	}
	
	else if(B < A, C, D){
		cout << A + C + D << endl;
	}

	else if(C < A && C < B && C < D){
		cout << A + B + D << endl;
	}

	else if(D < A && D < B && D < C){
		cout << A + B + C << endl;
	}

	if(E < F){
		cout << F << endl;
	}

	else{
		cout << E << endl;
	}
	
	return 0;
}*/
	/*
	int N, M;
	cin >> N >> M;
	cout << N + M << endl << N - M << endl << N * M << endl << N / M << endl;
}*/

/*int N, M; 
	cin >> N >> M;
	cout << N % M << endl;
}*/

/*	int N;
	cin >> N;
	cout << -(N % 2)+1 ;
}*/

	/*int A, B, C, D, E ;
	cin >> A >> B >> C >> D >> E;
	cout << (A + B + C + D + E) / 5 ;
}*/

	/*int A, B, C, D ;
	cin >> A >> B >> C >> D;
	cout << (A + B + C + D) / 60 << endl << (A + B + C + D) % 60 << endl;
	*/

/*	int A,B;
	cin >> A >> B;
	cout << ( A + B ) / 2 << endl;*/

/*	int m, f, b;
	cin >> m >> f >> b;

	if ( m + f >= b && m <= b ){
		cout << b - m << endl;
	}
	
	if ( m + f > b && m > b ){
		cout << 0 << endl;
	}


	if ( m + f < b ){
		cout << "NA" << endl;
	}*/

/*	int X , x ;
	cin >> X ;

	x = X % 7 ;

	if ( x == 2 ){
		cout << "sat" << endl;
	}

	if ( x == 3 ){
		cout << "sun" << endl;
	}

	if ( x == 4 ){
		cout << "mon" << endl;
	}

	if ( x == 5 ){
		cout << "tue" << endl;
	}

	if ( x == 6 ){
		cout << "wed" << endl;
	}

	if ( x == 0 ){
		cout << "thu" << endl;
	}

	if ( x == 1 ){
		cout << "fri" << endl;
	}*/

	int a , b , N ;
	cin >> a >> b >> N ;

	int s[100] , f[100];
	for ( int i=0 ; i<N ; i++ ){
		cin >> s[i] >> f[i];
	
		if (( s[i] <= a && a < f[i]) || s[i] < b && b <= f[i] || s[i] >= a && f[i] <= b ){
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}



Measured memory_bytes: 3092
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int dis1[N], dis2[N];
vector<int> v[N];
int col[N];
void dfs(int x, int dis[], int p = 0)
{
	dis[x] = dis[p] + 1;
	for (auto& y : v[x])
	{
		if (y == p) continue;
		dfs(y, dis, x);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1, dis1);
	dfs(n, dis2);
	int cnt1 = 0;
	int cnt2 = 0;
	for (int i = 1; i <= n; i++)
	{
		if (dis1[i] <= dis2[i]) cnt1++;
		else cnt2++;
	}
	if (cnt1 > cnt2) puts("Fennec");
	else puts("Snuke");
	return 0;
}

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

using namespace std;

int main(void){
  string str;
  
  cin >> str;
  
  if(str.length() < 4) cout << "No" << endl;
  else if(str.substr(0, 4) != "YAKI") cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
 
const int N=2e5+5,N3=2018;
int a[N],p[N],q[N];
int dp[N3][N3];
int solve(int s,int n){
    // if(n==1)return
    for(int i=1;i<=n;++i)p[i]=p[i-1]+a[i];
    for(int i=n;i>=1;--i)q[i]=q[i+1]+(s-a[i]);
    int res=0;
    for(int i=1;i<=n;++i){
        int r=n-i;
        int m=r/2,pot=a[i];
        if(r&1){
            pot+=a[i];
            pot+=s-a[i+m+1];
            if(m)pot+=(p[i+m]-p[i])*2;
            if(r>1)pot+=q[i+m+2]*2;
        }else{
            if(r){
                pot+=a[i];
                if(m>1)pot+=(p[i+m-1]-p[i])*2;
                pot+=q[i+m+1]*2;
                pot+=a[i+m];
            }
        }
        upx(res,pot);
    }
    return res;
}
int32_t main() {
 
    int s,n;
    cin>>s>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    int ans=solve(s,n);
    for(int i=1;i<=n;++i)a[i]=s-a[i];
    reverse(a+1,a+n+1);
    upx(ans,solve(s,n));
    cout<<ans<<'\n'; 
    return 0;
}

Measured memory_bytes: 8340
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0LL);
    set<int> s;
    for(int i = 1; i * i <= sum; i++)
        if(sum % i == 0){
            s.insert(i);
            s.insert(sum / i);
        }
    int ans = 1;
    for(int x : s){
        int p = 0;
        vector<int> r(n);
        for(int i = 0; i < n; i++)
            r[i] = a[i] % x;
        sort(r.begin(), r.end());
        int t = accumulate(r.begin(), r.end(), 0LL);
        int l = n - t / x;
        p = accumulate(r.begin(), r.begin() + l, 0LL);
        if(p <= k)
            ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N,K,i,j,res=0,ans=0;
	int a[50],plate[50];
	scanf("%d%d",&N,&K);
	for(i=0;i<N;i++)
	scanf("%d",a+i);
	int R=min(N,K);
	for(int A=0;A<=R;A++){
		for(int B=0;B<=R-A;B++){
			for(i=0;i<A;i++)
			plate[i]=a[i];
			for(j=0;j<B;j++)
			plate[i+j]=a[N-j-1];
			sort(plate,plate+A+B);
			i=0;
			while(i<K-(A+B)&&plate[i]<0){
				i++;
			}
			int s=0;
			for(;i<A+B;i++)
			s+=plate[i];
			ans=max(ans,s);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s="CODEFESTIVAL2016",s1;
int ans;
int main(){
	cin>>s1;
	for(int i=0;i<16;i++){
		if(s[i]!=s1[i])ans++;
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256