akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

bool dp[100005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	string s; read(s);
	dp[0] = 1;
	rep(i, 1, sz(s) + 1) {
		if (i >= 5) dp[i] |= dp[i - 5] && s.substr(i - 5, 5) == "dream";
		if (i >= 7) dp[i] |= dp[i - 7] && s.substr(i - 7, 7) == "dreamer";
		if (i >= 5) dp[i] |= dp[i - 5] && s.substr(i - 5, 5) == "erase";
		if (i >= 6) dp[i] |= dp[i - 6] && s.substr(i - 6, 6) == "eraser";
	}
	die(dp[sz(s)] ? "YES" : "NO");
}


Measured memory_bytes: 592
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    ld r;
    cin>>r;

    ld ans=2*pi*r;
    cout<<fixed<<setprecision(10)<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        //cout<<"Case #"<<z<<": ";
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3804
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void add(ll &a, ll b) {
	a += b;
	if (a >= mod) a -= mod;
}

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

	ll n, w, m, k, h, ans = 0;

	string s, t;
	cin >> h >> w;
	vs a(h);
	vvll dp(h, vll(w,0));
	rep(i, h) cin >> a[i];
	dp[0][0] = 1;

	rep(i, h) {
		rep(j, w) {
			if (i + 1 < h && a[i + 1][j] == '.') add(dp[i + 1][j], dp[i][j]);
			if (j + 1 < w && a[i][j + 1] == '.') add(dp[i][j + 1], dp[i][j]);
		}
	}
	/*rep(i, h) {
		rep(j, w) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	cout << dp[h-1][w-1] << endl;
	return 0;
}


Measured memory_bytes: 9216
import java.util.*;

public class Main {
	public static void main(String[] args){
	Scanner scn = new Scanner(System.in);
      int p = scn.nextInt();
      int a = p%1000;
      int ans = 1000-a;
      if(a==0){
        System.out.println("0");
      }else{
      	System.out.println(ans);
      }
	}
}


Measured memory_bytes: 35512
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	while (cin >> n >> k&&n != 0 && k != 0) {
		long long k1[100], k2[100];
		bool l = true;
		int a;
		for (int i = 0; i < k; i++) {
			cin >> k1[i];
		}
		fill(k2, k2 + k, 0);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < k; j++) {
				cin >> a;
				if(l){
					k2[j] += a;
					if (k2[j] > k1[j]) l = false;
				}
			}
		}
		if (l) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 3068
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto & in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int64_t K;
int32_t A[200000];
std::set<int32_t> Apos[200000];
int32_t passed[200000];
bool used[200000];

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T & arr, const U & v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR & arr, const U & v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> K;
	for (size_t i = 0; i < N; i++)
	{
		in >> A[i]; --A[i];
		Apos[A[i]].insert(i);
	}


	fill_all(passed, -1);
	int32_t count = 1;
	int pos = 0;
	while (passed[pos] == -1) {
		passed[pos] = count;
		auto iter = Apos[A[pos]].upper_bound(pos);
		if (iter == Apos[A[pos]].end()) {
			++count;
			iter = Apos[A[pos]].begin();
		}
		pos = 1 + *iter;
		if (pos >= N) {
			pos -= N;
			assert(pos == 0);
			++count;
		}
	}
	int cir = count - passed[pos];
	K %= cir;
	if (K == 0) {
		out << "\n";
		return 0;
	}

	fill_all(passed, -1);
	count = 1;
	pos = 0;
	while (true) {
		passed[pos] = count;
		auto iter = Apos[A[pos]].upper_bound(pos);
		if (iter == Apos[A[pos]].end()) {
			if (count == K) {
				break;
			}
			++count;
			iter = Apos[A[pos]].begin();
		}
		pos = 1 + *iter;
		if (pos >= N) {
			++count;
			if (count == K) {
				break;
			}
			pos -= N;
			assert(pos == 0);
		}
	}
	if (pos >= N) {
		out << "\n";
		return 0;
	}

	std::vector<int32_t> stack;
	for (; pos < N; ++pos)
	{
		if (used[A[pos]]) {
			while (used[A[pos]])
			{
				used[stack.back()] = false;
				stack.pop_back();
			}
		}
		else {
			stack.push_back(A[pos]);
			used[A[pos]] = true;
		}
	}

	if (!stack.empty()) {
		auto back = stack.back();
		stack.pop_back();
		for (auto& i : stack) {
			out << i + 1 << ' ';
		}
		out << back + 1 << endl;
	}
	else {
		out << endl;
	}


	return 0;
}
#endif


Measured memory_bytes: 22900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] poi = new int[4];
		int[] lol = new int[114514];
		int Desc,Asc,kazu,a,b,c,exit;
		int count =0;
		int place=0;
		kazu = sc.nextInt();
		while(kazu != 0000){
			count =0;
			poi[0] = kazu/1000;
			poi[1] = (kazu - poi[0]*1000)/100;
			poi[2] = (kazu - poi[0]*1000-poi[1]*100)/10;
			poi[3] = kazu - poi[0]*1000-poi[1]*100-poi[2]*10;
			if(poi[0]==poi[1]&&poi[1]==poi[2]&&poi[2]==poi[3]&&poi[3]==poi[0]){
				lol[place] = 9999;
				place++;
			}else{
				int hantei = kazu;
				while(hantei!=6174){
					count++;
					for(a=3;a>=0;a--){                          
						for(b=0;b<a;b++){
							if(poi[b+1]>poi[b]){
								exit = poi[b+1];
								poi[b+1] = poi[b];
								poi[b] = exit;
							}
						}
					}
					Desc = poi[0]*1000+poi[1]*100+poi[2]*10+poi[3];
						for(a=3;a>=0;a--){                         							for(b=0;b<a;b++){
								if(poi[b+1]<poi[b]){
									exit = poi[b+1];
									poi[b+1] = poi[b];
									poi[b] = exit;
								}
							}
						}
					Asc = poi[0]*1000+poi[1]*100+poi[2]*10+poi[3];
					hantei = Desc - Asc;
					poi[0] = hantei/1000;
					poi[1] = (hantei - poi[0]*1000)/100;
					poi[2] = (hantei - poi[0]*1000-poi[1]*100)/10;
					poi[3] = hantei - poi[0]*1000-poi[1]*100-poi[2]*10;
				}
				lol[place] = count;
				place++;
			}
			kazu= sc.nextInt();
		}
		lol[place] = 114514;
		for(c=0;lol[c]!=114514;c++){
			if(lol[c]==9999){
				System.out.println("NA");
			}else{
				System.out.println(lol[c]);
			}
		}
	}
}

Measured memory_bytes: 38704
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll a, b; cin >> a >> b;
    if(a<=5) cout << 0 << endl;
    else if(a<=12) cout << b/2 << endl;
    else cout << b << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    else
    {
        return gcd(b, a % b);
    }
}

int main(){
    int N;
    cin >> N;
    
    vector<int> A(N, 0);
    int ans;
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
        ans = gcd(ans, A.at(i));
    }
    cout << ans << endl;
    

}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextLong()

  println(abc162b(n))
}

private fun abc162b(n: Long): Long {
  val ans = (1L..n).map { it }.filter { it % 3L != 0L && it % 5L != 0L }.sum()

  return ans
}


Measured memory_bytes: 77836
#include <bits/stdc++.h>
#define rep(i, z, n) for(ll i = z; i <= n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef unsigned long ul;
using namespace std;
int main(){
  int r;
  cin >> r;
  cout << 2.0*3.141592653589793238*double(r) << endl;
    
  return 0;
}


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

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

int main(void) {
	int a, b; cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
	return 0;
}

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


#define clr(arr,val) memset(arr,val ,sizeof arr)
typedef  long long ull;
typedef long long ll;


ll const oo=1e9 ;
int const SZ= (int)1e3+3;
const ll mod=(ll)1e9+7;

string str[SZ];
ll dp[SZ][SZ];
int r,c;
ll solve(int i ,int j){
    
    if(j<0 || j>=c)
        return 0;
    if(i<0 || i>=r)
        return 0;
    if(str[i][j]=='#')
        return 0;
    ll &ret=dp[i][j];
    if(~ret) return ret;
    if(i==r-1 && j==c-1)
        return 1;
    return ret=((solve(i+1,j)%mod)+(solve(i,j+1)%mod))%mod;
    
}
int main()
{
    cin>>r>>c;
    for(int i=0;i<r;i++)
        cin>>str[i]; 
    clr(dp,-1);
    cout<<solve(0,0)<<endl;
        
    return 0;
}

Measured memory_bytes: 13476
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; ++i) {
            a[i] = sc.nextInt();
        }
        print(a);
        insertion_sort(a);
        sc.close();
    }

    public static void print(int a[]) {
        for(int i = 0; i < a.length; ++i) {
            if(i != 0) System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println("");
    }
    public static void insertion_sort(int a[]) {
        for(int i = 1; i < a.length; ++i) {
            int v = a[i];
            int j = i - 1;
            while(j >= 0 && a[j] > v) {
                a[j+1] = a[j];
                --j;
            }
            a[j+1] = v;
            print(a);
        }
    }
}


Measured memory_bytes: 33712
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

#pragma endregion



int main(){
    string s;
    cin >> s;
    if(s[0] >= 'A' && s[0] <= 'Z')
        cout << "A" << endl;
    else
    {
        cout << "a" << endl; 
    }
    
    return 0;
}


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

using namespace std;

int main(){
    int n,q;
    while(cin >> n && n != 0){
        cin >> q;
        map<int,int> d;
        for(int i = 0;i < n; i++){
            int m; cin >> m;
            for(int j = 0; j < m; j++){
                int t; cin >> t;
                if(d.find(t) != d.end()){
                    d[t]++;
                }
                else{
                    d[t] = 1;
                }
            }
        }
        int ans = 0, num = 0;
        for(map<int,int>::iterator it = d.begin(); it != d.end(); it++){
            if(it->second > num){
                ans = it->first;
                num = it->second;
            }
        }
        if(num < q){
            cout << 0 << endl;
        }
        else cout << ans << endl;
    }

	return 0;
}




Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int w, h, xs, ys, xg, yg;
int mp[110][110];

bool dfs(int x, int y, int f) {
  if (x >= w || y >= h || x < 0 || y < 0 || mp[y][x] != f)
    return false;
  if (y == yg && x == xg && mp[y][x] == f)
    return true;
  mp[y][x] = 9;
  return dfs(x + 1, y, f) || dfs(x - 1, y, f) || dfs(x, y + 1, f) ||
         dfs(x, y - 1, f);
}

int main() {
  while (cin >> w >> h) {
    if (w == 0 && h == 0)
      break;
    int n;
    cin >> xs >> ys >> xg >> yg >> n;
    xs--;
    ys--;
    xg--;
    yg--;
    int c, d, x, y;
    rep(i, n) {
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int i = y - 1; i < y + 1; i++)
          for (int j = x - 1; j < x + 3; j++) {
            mp[i][j] = c;
          }
      } else {
        for (int i = y - 1; i < y + 3; i++)
          for (int j = x - 1; j < x + 1; j++) {
            mp[i][j] = c;
          }
      }
    }
    cout << (dfs(xs, ys, mp[ys][xs]) ? "OK" : "NG") << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct Chara{
	string name;
	ll vote;
	bool operator<(const Chara &c)const{
		if(vote!=c.vote) return vote>c.vote;
		return name<c.name;
	}
};

ll n,m,k,l;
vector<Chara> favs,unfavs;

bool Check(int x){
	if(x>k||x>m) return false;
	if(unfavs.size()<k-x+1) return true;

	ll cost=0;
	REP(i,0,x){
		cost+=max(0LL,unfavs[k-x].vote-favs[i].vote+(unfavs[k-x].name<favs[i].name));
		if(cost>l) return false;
	}
	
	return cost<=l;
}

void Solve(){
	while(true){
		cin >> n >> m >> k >> l;
		if(n+m+k+l==0) break;
		Chara charas[100010];
		REP(i,0,n) cin >> charas[i].name >> charas[i].vote;
		unordered_set<string> fav_names;
		REP(i,0,m){
			string name; cin >> name;
			fav_names.insert(name);
		}
		
		favs.clear(); unfavs.clear();
		REP(i,0,n){
			if(fav_names.find(charas[i].name)!=fav_names.end()) favs.push_back(charas[i]);
			else unfavs.push_back(charas[i]);
		}
		sort(favs.begin(),favs.end());
		sort(unfavs.begin(),unfavs.end());

		int lb=0,ub=min(m,k)+1;
		while(true){
			if(ub-lb<=1){
				if(Check(ub)) lb=ub;
				break;
			}
			int mid=(lb+ub)/2;
			if(Check(mid)) lb=mid;
			else ub=mid;
		}

		cout << lb << endl;
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 23920
#include <stdio.h>
#include <algorithm>
#include <unordered_map>
#include <string>
using namespace std;

const int N=1e5+1;
int a[N],n,m[N],k[N],s1[N],s2[N],n1,n2;

int main(){
	scanf("%d", &n);
	for(int i=0;i<n;++i) scanf("%d", a+i);
	for(int i=0;i<n;i+=2) ++m[a[i]];
	for(int i=0;i<N;++i) if(m[i]) s1[n1++] = i;
	sort(s1, s1+n1, [&](int a, int b){return m[a]>m[b];});
	for(int i=1;i<n;i+=2) ++k[a[i]];
	for(int i=1;i<N;++i) if(k[i]) s2[n2++] = i;
	sort(s2, s2+n2, [&](int a, int b){return k[a]>k[b];});
	if(s1[0]!=s2[0]){
		printf("%d\n", n-m[s1[0]]-k[s2[0]]);
	}
	else{
		int x;
		if(n1==1&&n2==1) x = n/2;
		else if(n1==1) x = m[s1[0]]+k[s2[1]];
		else if(n2==1) x = m[s1[1]]+k[s2[0]];
		else x = max(m[s1[0]]+k[s2[1]], m[s1[1]]+k[s2[0]]);
		printf("%d\n", n-x);
	}
	return 0;
}

Measured memory_bytes: 1664
from itertools import accumulate


# ある自然数未満までのエラトステネスの篩をつくる
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0, n) if s[i] and i > 1]


P = set(eratosthenes(10 ** 5 + 1))
like_2017 = [0] * (10 ** 5 + 1)
for n in range(10 ** 5 + 1):
    if (n in P) and ((n + 1) / 2 in P):
        like_2017[n] = 1

like_2017 = list(accumulate(like_2017))

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    print(like_2017[r] - like_2017[l - 1])


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

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

static const int dx[] = {-1, 0, 1, 0};
static const int dy[] = {0, -1, 0, 1};
int n;
int h, w;
int X1[1111], Y1[1111];
int X2[1111], Y2[1111];
bool maze[1111][1111];

inline bool check(int hx, int hy){ return 0 <= hx && hx < h - 1 && 0 <= hy && hy < w - 1;}

int main(int argc, char *argv[])
{
  while(cin >> w >> h, w){
    cin >> n;
    rep(i, n) cin >> Y1[i] >> X1[i] >> Y2[i] >> X2[i];

    vector<int> x, y;
    rep(i, n){
      x.push_back(X1[i]);
      x.push_back(X2[i]);
      y.push_back(Y1[i]);
      y.push_back(Y2[i]);
    }
    x.push_back(0);
    x.push_back(h);
    y.push_back(0);
    y.push_back(w);
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    rep(i, n){
      X1[i] = lower_bound(x.begin(), x.end(), X1[i]) - x.begin();
      X2[i] = lower_bound(x.begin(), x.end(), X2[i]) - x.begin();
      Y1[i] = lower_bound(y.begin(), y.end(), Y1[i]) - y.begin();
      Y2[i] = lower_bound(y.begin(), y.end(), Y2[i]) - y.begin();
    }
    h = x.size();
    w = y.size();
    
    rep(i, h) rep(j, w) maze[i][j] = false;
    rep(i, h) maze[i][w - 1] = true;
    rep(j, w) maze[h - 1][j] = true;
    rep(k, n) erep(i, X1[k], X2[k] - 1) erep(j, Y1[k], Y2[k] - 1) maze[i][j] = true;

    int res = 0;
    rep(i, h) rep(j, w) if(!maze[i][j]) {
      res += 1;
      maze[i][j] = true;
      queue<pair<int, int> > que;
      que.push(make_pair(i, j));
      while(!que.empty()){
        pair<int, int> here = que.front();  que.pop();
        int hx = here.first;
        int hy = here.second;
        rep(k, 4){
          int nx = hx + dx[k];
          int ny = hy + dy[k];
          if(!check(nx, ny)) continue;
          if(!maze[nx][ny]){
            maze[nx][ny] = true;
            que.push(make_pair(nx, ny));
          }
        }
      }
    }

    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1856
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
char str[60][11];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int S[60][11];
int e[200][200];
int L[200];
int R[200];
int Z[200];
int p;
bool ret;
struct wolf{
	int v[10];
	wolf(){
		for(int i=0;i<10;i++)v[i]=0;
	}
};
wolf dat[200];
wolf dfs(int a,int b){
	//printf("%d\n",a);
	wolf W=dat[a];
	for(int i=0;i<p;i++)if(e[a][i]&&i!=b){
		wolf V=dfs(i,a);
		for(int j=0;j<10;j++)W.v[j]+=V.v[j];
	}
	double ave=0;
	int div=0;
	for(int i=0;i<10;i++){ave+=(0.5+i)*W.v[i];div+=W.v[i];}
	ave/=div;
//	printf("%f %d %d\n",ave,L[a],R[a]);
	if(ave<0.00000001+L[a]||ave>0.9999999+R[a])ret=false;
	return W;
}
int main(){
	int a,b;
	while(scanf("%d%d",&b,&a),a){
		ret=true;
		for(int i=0;i<a;i++){
			scanf("%s",str[a-1-i]);
			for(int j=0;j<b;j++)S[i][j]=0;
		}
		p=1;
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(str[i][j]!='.'&&S[i][j]==0){
					queue<pair<int,int> >Q;
					Q.push(make_pair(i,j));
					S[i][j]=p;
					while(Q.size()){
						int row=Q.front().first;
						int col=Q.front().second;
						Q.pop();
						for(int k=0;k<4;k++)if(0<=row+dx[k]&&row+dx[k]<a&&0<=col+dy[k]&&col+dy[k]<b&&str[row][col]==str[row+dx[k]][col+dy[k]]&&!S[row+dx[k]][col+dy[k]]){
							S[row+dx[k]][col+dy[k]]=p;
							Q.push(make_pair(row+dx[k],col+dy[k]));
						}
					}
					p++;
				}
			}
		}
		for(int i=0;i<p;i++)
			for(int j=0;j<p;j++)
				e[i][j]=0;
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++)
				for(int k=0;k<1;k++)
					if(0<=i+dx[k]&&i+dx[k]<a&&0<=j+dy[k]&&j+dy[k]<b&&S[i][j]&&S[i+dx[k]][j+dy[k]]&&S[i][j]!=S[i+dx[k]][j+dy[k]]){
						e[S[i][j]][S[i+dx[k]][j+dy[k]]]=1;
					}
		for(int i=0;i<p;i++){L[i]=100;R[i]=-1;Z[i]=-1;dat[i]=wolf();}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(!S[i][j])continue;
				if(i==0||(S[i-1][j]&&S[i-1][j]!=S[i][j])){
					Z[S[i][j]]=i;
					L[S[i][j]]=min(L[S[i][j]],j);
					R[S[i][j]]=max(R[S[i][j]],j);
				}
				dat[S[i][j]].v[j]++;
			}
		}
		for(int i=0;i<b;i++)if(S[0][i]){
			dfs(S[0][i],-1);
			break;
		}
		if(ret)printf("STABLE\n");
		else printf("UNSTABLE\n");
	}
}

Measured memory_bytes: 1092
#include <stdio.h>

int main(void) {
	float x1,x2,x3,x4,y1,y2,y3,y4;
	int n,i;
	
	scanf("%d", &n);
	
	for(i=0; i<n; i++) {
	
		scanf("%f %f %f %f %f %f %f %f ", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
			
			if(x1==x2 && x3 == x4) printf("YES\n");
			else if(x1==x2 || x3==x4) printf("NO\n");
			else if( (y2-y1)/(x2-x1) == (y4-y3)/(x4-x3) ) printf("YES\n");
			else printf("NO\n");	
		
	}
	
	return 0;
}
		 

Measured memory_bytes: 620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef tuple<int, int, int, int> t4;
typedef pair<ll, ll> PL;
typedef long double ldouble;

vector <int> E[150050];

double D[150050], P[150050];

void pdfs(int x, int fa){
	D[x] = 0;
	int cnt = 0;
	for(int e : E[x])if(e != fa){
		pdfs(e, x);
		++cnt; D[x] += D[e] + 1;
	}
	if(cnt > 0)D[x] /= cnt;
}

double ans[150050];

void dfs(int x, int fa){
	double sum = 0;
	int cnt = 0;
	if(fa != -1)cnt++, sum += P[x] + 1;
	for(int e : E[x])if(e != fa)sum += D[e] + 1, cnt++;
	for(int e : E[x])if(e != fa){
		if(cnt == 1)P[e] = 0;
		else P[e] = (sum - D[e] - 1) / (cnt - 1);
		dfs(e, x);
	}
	ans[x] = sum / cnt;
}

void solve(){
	int n; scanf("%d", &n);
	if(n == 1){
		printf("0\n");
		return;
	}
	rep(i, n-1){
		int x, y; scanf("%d%d", &x, &y);
		E[x].pb(y);
		E[y].pb(x);
	}
	pdfs(1, -1);
	dfs(1, -1);
	for(int i=1;i<=n;i++)printf("%.12f\n", ans[i]);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 19968
a=input()
n=len(a)
if n<5 or n>10:
    print('NO')
    exit()

for i in range(2**(n+1)):
    s=""
    check=[""]*(n+1)
    for j in range(n+1):
        if ((i>>j)&1):
            check[j]="A"
    for k in range(n+1):
        s+=check[k]
        if k!=n:
            s+=a[k]
    if s=="AKIHABARA":
        print('YES')
        exit()
print('NO')

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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int ans = 0;
  
  for(int i=0; i<(n-2); i++) {
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
 double a,b,c,d;
  cin>>a>>b>>c>>d;
  double e=2*M_PI*c/12+M_PI/6*d/60;
  double f=2*M_PI*d/60;
  double g=abs(e-f);
  double h=min(g,2*M_PI-g);
  double l=a*a+b*b-2*a*b*cos(h); 
  cout<<setprecision(14)<<sqrt(l)<<endl;
}

Measured memory_bytes: 4172
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  
    {if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;  }  return res;  
}
bool sortinrev(const pair<vector<int>,int>&a,const pair<vector<int>,int>&b){if(a.fi==b.fi)return b.se>a.se;return a.fi>b.fi;}
void run(vector<int>v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void solve()
{
    int n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll dp[n];
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        vector<ll>v;
        for(int j=1;j<=min(k,i);j++)
        {
            v.pb(abs(a[i]-a[i-j])+dp[i-j]);
        }
        dp[i] = *min_element(v.begin(),v.end());
    }
    cout<<dp[n-1]<<endl;
    
    

}
int main() 
{ 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    
        solve();
    
        
    
    
    return 0; 
} 

Measured memory_bytes: 1792
cards = {
       'S': [0] * 13,
       'H': [0] * 13,
       'C': [0] * 13,
       'D': [0] * 13
}

n = int(input())

for i in range(n):
   s,num = input().split()
   num = int(num)
   cards[s][num - 1] = 1

for c in ["S","H","C","D"]:
   for i in range(13):
       if cards[c][i] == 0:
           print(c, str(i + 1))


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 2050;
 ll mod = 1e9+7;

int main(){
  int a;
  string s;
  cin >> a >> s;
  cout << ((a >= 3200) ? s:"red") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count = 0;
		int max = 0;
		int Hlist[] = new int[N];
		for(int i = 0; i < N; i++) {
			Hlist[i] = sc.nextInt();
		}
		for (int i = 0; i < N - 1; i++) {
			if (Hlist[i] >= Hlist[i + 1]) {
				count++;
			} else {
				count = 0;
			}
			if (max < count) {
				max = count;
			}
		}
		System.out.println(max);
	}

}

Measured memory_bytes: 49700
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n,a[102];
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int x=a[n-1]-a[0];
    cout<<x<<endl;
    
    
    
}

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

using namespace std;

int main(){
        string str;
        string res;
        int N;
        cin>>N>>str;
        for(int i=0;i<N;i++){
                if(str[i]==')'){
                        res+=')';
                        /*int now=i;
                        while(now>0&&res[now]==')'){
                                now--;
                        }
                        res.insert(now, "(");*/
                        res.insert(0, "(");
                }
                if(str[i]=='('){
                        int lef=1;
                        res+='(';
                        i++;
                        while(i<N&&lef>0){
                                if(str[i]=='('){
                                        lef++;
                                        res+='(';
                                }
                                else if(str[i]==')'){
                                        lef--;
                                        res+=')';
                                }
                                i++;
                        }
                        i--;
                        for(int j=0;j<lef;j++){
                                res+=')';
                        }
                }
                //cout<<res<<endl;
        }
        cout<<res<<endl;
        return 0;
}


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

#define pb push_back
#define ll long long

using namespace std;

// void printBrac(int i, int j){
// 	if (i == j)
// 	{
// 		printf("A%d", i);
// 	}
// 	else{
// 		printf("(" );
// 		printBrac(i,s[i][j]);
// 		printBrac(s[i][j]+1,j);
// 		printf(")");
// 	}
// }

int main(int argc, char const *argv[])
{
	int n, w, ng,wg;

	scanf("%d%d", &n, &w);
	vector<int> p, wt;

	p.pb(0);
	wt.pb(0);

	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d", &ng, &wg);
		wt.pb(ng);
		p.pb(wg);
	}

	// for (int i = 0; i <= n; ++i)
	// {
	// 	printf("%d ", p[i]);
	// }
	// printf("weight array\n");

	// for (int i = 0; i <= n; ++i)
	// {
	// 	printf("%d 	", wt[i]);
	// }

	ll dp[n+5][w+5];
	memset(dp, 0, sizeof(dp));
	int currentWeight=w;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= w; ++j)
		{
			if (wt[i] > j)
			{
				dp[i][j] = dp[i-1][j];
			}
			else if( j >=  wt[i] ){
				if(dp[i-1][j] <  p[i]+dp[i-1][j - wt[i]]){
					dp[i][j] = p[i]+dp[i-1][j - wt[i]];
				}
				else{
					dp[i][j]=dp[i-1][j];
				}
			}
		}
	}

	printf("%lld\n", dp[n][w]);
	// for (int i = 0; i <= n; ++i)
	// {
	// 	for (int j = 0; j <= w; ++j)
	// 	{
	// 		printf("%lld ", dp[i][j]);
	// 	}
	// 	printf("\n");
	// }

	// printf("s\n");
	// for (int i = 0; i < 7; ++i)
	// {
	// 	for (int j = 0; j < 7; ++j)
	// 	{
	// 		printf("%d ", s[i][j]);
	// 	}
	// 	printf("\n");
	// }
	// printBrac(1,6);
	return 0;
}




Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
class UnionFind {
private:
    vector<int> par, rank;
    
    int find(int x) {
        if(par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }
public:
    UnionFind(int Max_Node) {
        par.resize(Max_Node);
        rank.resize(Max_Node);
    }
    
    void init(int n) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        
        if (rank[x] < rank[y])
            par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};


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

    int n, m;
    cin >> n >> m;
    vector<int> in(n+1);
    
    for (int i = 1; i <= n; i++) {
        cin >> in[i];
    }
    
    UnionFind uf(n + 10);
    uf.init(n+1);
    
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
        //uf.unite(b, a);
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (uf.same(in[i], i)) {
            //cout << in[i] << ":" << i+1 << endl;
            ans++;
            
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int a, b;
  cin >> a >> b;
  if(a < 6)
    cout << 0 << endl;
  else if(a < 13)
    cout << b / 2 << endl;
  else
    cout << b << endl;
  return 0;
}

Measured memory_bytes: 256
def extgcd(a, b, d = 0):
    g = a
    if b == 0:
        x, y = 1, 0
    else:
        x, y, g = extgcd(b, a%b)
        x, y = y, x - a//b *y
    return x,y,g
a, b = map(int, input().split())
print(*extgcd(a, b)[:2])


Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int a,b,c,d; cin >> a >> b >> c >> d;
    int tt = (c+b-1) / b;
    int at = (a+d-1) / d;
    if(tt >at){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <algorithm>
// #include <atcoder/all>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define rall(hoge) (hoge).rbegin(), (hoge).rend()
#define en '\n'
using Edge = pair<ll, ll>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
template <class T> bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x,y)*y ;}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> s(n);
    ll minus = 0;
    rep(i,n) {
        cin >> s[i];
        if (s[i] < 0) minus++;
    }

    sort(all(s));
    if (minus == n) {
        ll res = s[n-1];
        rep(i,n-1) {
            res -= s[i];
        }
        print(res);
        ll cur = s[n-1];
        rep(i,n-1) {
            cout << cur << " " << s[i] << '\n';
            cur -= s[i];
        }

    } else if (minus == 0) {
        ll res = -s[0];
        REP(i,1,n) {
            res += s[i];
        }
        print(res);
        ll cur = s[0];
        REP(i,1,n-1) {
            cout << cur << " " << s[i] << '\n';
            cur -= s[i];
        }
        cout << s[n-1] << " " << cur << '\n';
    } else {
        ll res = s[n-1];
        rep(i,minus) {
            res -= s[i];
        }
        REP(i,minus,n-1) {
            res += s[i];
        }
        print(res);
        ll cur = s[0];
        REP(i,minus,n-1) {
            cout << cur << " " << s[i] << '\n';
            cur -= s[i];
        }
        cout << s[n-1] << " " << cur << '\n';
        ll last = s[n-1]-cur;
        REP(i,1,minus) {
            cout << last << " " << s[i] << '\n';
            last -= s[i];

        }
    }
    

    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
int A[100005];
int B[100005];
int C[100005];
ll dp1[100005];
ll dp2[100005];
int main () {
  ios::sync_with_stdio(false);
  cin >> N;
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i) cin >> B[i];
  for(int i = 0; i < N; ++i) cin >> C[i];
  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);
  
  ll i = 0;

  // second level
  for(int k = 1; k <= N; ++k) {
    while(i < N && A[i] < B[k - 1]) i++;
    dp1[k] = dp1[k - 1] + i;
  }

  // third level
  i = 0;
  for(int k = 1; k <= N; ++k) {
    while(i < N && B[i] < C[k - 1]) i++;
    dp2[k] = dp2[k - 1] + dp1[i];
  }
  cout << dp2[N] << endl;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
#define testcases ll t; cin>>t; while(t--)

using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    s="*"+s;t="*"+t;
    vector<vector<int>> dp(3001,vector<int>(3001,0));
    vector<vector<int>> v(3001,vector<int>(3001,0));

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s[i]==t[j])
            {
                dp[i][j]=1+dp[i-1][j-1];
                v[i][j]=1;
                continue;
            }
            else if(dp[i-1][j]>dp[i][j-1]) v[i][j]=2;
            else v[i][j]=3;
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    //cout<<dp[n][m]<<" ";
    string ans="";
    while(n!=0&&m!=0)
    {
        if(v[n][m]==1) ans.pb(s[n]),n-=1,m-=1;
        else if(v[n][m]==2) n--;
        else m--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


Measured memory_bytes: 70912
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String S = sc.nextLine();

        char[] chars = S.toCharArray();

        if(chars[2]==chars[3] && chars[4]==chars[5]) {
            System.out.println("Yes");
    } else {
            System.out.println("No");
        }
    }
}

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

int main(){
    char c;
    cin >> c;
    if(c != 'z') cout << char(c + 1) << endl;
    else cout << 'a' << endl;
}

Measured memory_bytes: 256
#coding:utf-8
import fractions

def main():
    N=int(input())
    num=list(map(int,input().split()))
    gcd=0
    gcd_list_front=[]
    gcd_list_back=[]
    gcd_list_front.append(num[0])
    gcd_list_back.append(num[-1])

    for  i in range(1,N-1):
        gcd_list_front.append(fractions.gcd(gcd_list_front[i-1],num[i]))
        gcd_list_back.append(fractions.gcd(gcd_list_back[i-1],num[-i-1]))
    gcd_list_back.reverse()

    gcd=max(gcd_list_back[0],gcd_list_front[-1])
    for i in range(0,N-2):
       temp_gcd=fractions.gcd(gcd_list_front[i],gcd_list_back[i+1])
       if temp_gcd>gcd:
           gcd=temp_gcd
    print(gcd)


if  __name__=="__main__":
    main()


Measured memory_bytes: 16132
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var a, b int
	for i := 1; i*i <= n; i++ {
		if n%i != 0 {
			continue
		}
		a = i
		b = n / i
	}

	fmt.Println(a + b - 2)
}


Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<cstdio>

using namespace std;

struct pp{int a1,a2;} mx1[300001],mx2[300001],c[4];

int a[300001],lastans=0,n;

bool cmp(pp o,pp p) {return o.a1<p.a1;}

void dfs(int o)
{
	if(mx1[o].a1) return;
	mx1[o].a1=a[o];mx1[o].a2=o;
	mx2[o].a1=-1;mx2[o].a2=-1;
	for(int i=1;i<=n;i++)
		if(o&(1<<(i-1)))
		{
			int yu=o^(1<<(i-1));
			dfs(yu);
			c[0]=mx1[o];c[1]=mx2[o];
			c[2]=mx1[yu];c[3]=mx2[yu];
			sort(c,c+4,cmp);
			mx1[o]=c[3];
			int j=2;
			while((j>=0)&&(c[j].a2==c[3].a2)) j--;
			mx2[o]=c[j];
		}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<1<<n;i++) scanf("%d",&a[i]);
	dfs((1<<n)-1);
	for(int i=1;i<1<<n;i++)
	{
		lastans=max(lastans,mx1[i].a1+mx2[i].a1);
		printf("%d\n",lastans);
	}
	return 0;
}

Measured memory_bytes: 8448
#include<iostream>

#include<bits/stdc++.h>

using namespace std;


int main()
{
    int h,n;
    cin>>h>>n;
    int a[n],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int gcd(int a, int b){
  if(a < b){
    swap(a, b);
  }
  if(a % b == 0) return b;
  
  return gcd(b, a % b);
}

int main(){

  llong k;
  cin >> k;

  llong ans = 0;
  for(int i = 1; i <= k; ++i){
    for(int j = 1; j <= k; ++j){
      for(int l = 1; l <= k; ++l){
        ans += gcd(i, gcd(j, l));
      }
    }
  }
  cout << ans << endl;
  return 0;
}



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

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

using namespace std;

signed main(){
  int a[5];
  int k;
  cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>k;
  int flag=0;
  if((a[4]-a[0])>k)flag=1;
  /*
  rep(i,4){
    if((a[i+1]-a[i])>k){
      cout << "dou"<<endl;
      flag=1;
    } 
  }
  */
  if(flag==0){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
#include "stdlib.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())


int main(){
  int n;
  cin>>n;
  vll l(n);
  REP(i,n){
    cin>>l[i];
  }
  sort(l.begin(),l.end());
  int ans=0;
  REP(i,n-2){
    FOR(j,i+1,n-1){
      auto iter=lower_bound(l.begin()+j+1,l.end(),l[i]+l[j])-1;
      int n=iter-l.begin();
      ans+=n-j;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256