akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
long long n;
long long x,d,mx,mn,l1,l2,r1,r2;
long long f(long long y){
	mx=(n-y+n-1)*y/2;
	mn=y*(y-1)/2;
	return mx-mn+1;
}
long long g(long long y){//重叠部分 
	l1=(n-y+n-1)*y/2;
	l2=y*(y-1)/2;
	r1=(n-y-d+n-1)*(y+d)/2+x;
	r2=(y+d)*(y+d-1)/2+x;
	return max(min(l1,r1)-max(l2,r2)+1,0LL);
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>x>>d;
	if(d==0){
		if(x==0)
			cout<<1<<endl;
		else
			cout<<n+1<<endl;
		return 0;
	} 
	if(x==0){
		cout<<n*(n-1)/2+1<<endl;
		return 0;
	} 
	if(x<0){//负数难处理，化为正数 
		x=-x;
		d=-d;
	}
	long long gg=__gcd(x,d);//gcd
	x/=gg;
	d/=gg;
	long long res=0LL; 
	for(int i=0;i<=n;i++){//选i个 
		res+=f(i);
	}
	for(int i=0;i<=n;i++){
		if(i+d>=0&&i+d<=n)
			res-=g(i);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node);
Node treeMaximum(Node);
Node treeSearch(Node,int);
Node treeSuccessor(Node);
//void treeDelete(Node);
void insert (int);
void inorder (Node);
void preorder(Node);

//void transplant(Node,Node);

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
       inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
       scanf("%d", &x);
      //treeDelete(treeSearch(root, x));
      }
  }

  
  
  return 0;
}


Node treeMinimum(Node x){
  
  while(x->left != NIL){
    x = x->left;
  }

  return x;

}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){

  if(u == NIL || k == u->right) return u;
  if(k < u->parent) return treeSearch(u->right,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y; 

}

/*void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z.left == NIL)



}
*/

void insert(int k){
  Node y = NIL; // x parent
  Node x = root; 
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x; //parent set
    if( z->key < x->key) x = x->left;//左の子へ移動
    else x = x->right;//右の子へ移動
  }
  z->parent = y;

  //Tが空の場合
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z; //z を y の左の子にする
  else y->right = z; // z を yの右の子にする 

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u != NIL) {
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }

}




Measured memory_bytes: 25184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

ull mod_pow(ull x, ull n){
	ull res = 1;
	while (n){
		if(n&1) res *= x;
		x *= x;
		n /= 2;
	}
	return res;
}

ull mod_inv(ull x){
	return mod_pow(x, -1);
}

const ull mod = 1e9 + 7;

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

	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	int l = 0, r = 1;

	set<ull> st;
	ull val = s[0];
	ull inv = mod_inv(mod);
	while (m--){
		string t;
		cin >> t;
		if (t == "L++"){
			val -= s[l] * mod_pow(mod, r - l - 1);
			++l;
		}
		if (t == "L--"){
			--l;
			val += s[l] * mod_pow(mod, r - l - 1);
		}
		if (t == "R++"){
			val = val*mod + s[r++];
		}
		if (t == "R--"){
			val = (val-s[--r])*inv;
		}
		st.insert(val);
	}
	cout << st.size() << endl;


	return 0;
}

Measured memory_bytes: 15476
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int k;
  scanf("%d",&k);
  for(int i=0;i<k;i++){
    printf("ACL");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    int X,A,B;
    scanf("%d%d%d",&X,&A,&B);
    printf("%d\n",(X-A)%B);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    int N,M;
    string A[51],B[51];
    cin >> N >> M;
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    for(int i = 0;i < M;i++){
        cin >> B[i];
    }
    for(int i = 0;i <= N-M;i++){
        for(int j = 0;j <= N-M;j++){
            for(int k = 0;k < M;k++){
                if(A[i+k].substr(j,M) != B[k])break;
                if(k==M-1){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
str = input()
for _ in range(int(input())):
    a = input().split()
    if a[0] == "print":
        print(str[int(a[1]):int(a[2]) + 1])
    elif a[0] == "replace":
        str = str[:int(a[1])] + a[3] + str[int(a[2]) + 1:]
    else:
        str = str[:int(a[1])] + str[int(a[1]):int(a[2]) + 1][::-1] + str[int(a[2]) + 1:]


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> lj(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        lj[u].push_back(v);
        lj[v].push_back(u);
    }
    vector<int> fa(n), num(n);
    function<int(int, int)> dfs = [&](int k, int pre) {
        fa[k] = pre;
        num[k] = 1;
        for (auto i : lj[k]) {
            if (i != pre) {
                num[k] += dfs(i, k);
            }
        }
        return num[k];
    };
    dfs(0, 0);
    int now = n - 1, sum = -1;
    while (now != 0) {
        now = fa[now];
        sum++;
    }
    now = n - 1;
    for (int i = 0; i < sum / 2; i++) {
        now = fa[now];
    }
    if (num[0] - num[now] > num[now]) cout << "Fennec\n";
    else cout << "Snuke\n";
}


Measured memory_bytes: 15872
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-7;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");

void solve()
{
	string s;
	cin >> s;
	if (s == "SSS") cout << 0;
	else if (s == "RRR") cout << 3;
	else if (s == "RRS" || s == "SRR") cout << 2;
	else cout << 1;
}

int main()
{
	cout << setprecision(2) << fixed;
	cin.tie();
	cout.tie();
	//freopen("input.txt", "r", stdin);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	gg;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstdint>
#include <iostream>

using namespace std;

int main() {
  int64_t n;
  int64_t a[5];
  cin >> n;
  int64_t mina = (1UL << 63) - 1;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
    mina = min(mina, a[i]);
  }
  int64_t ans = 4 + (n - 1) / mina + 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
L, R = gets.chomp.split.map(&:to_i)

ans = 2019

if L % 2019 == 0 || R % 2019 == 0
  puts 0
  exit 0
end

if L / 2019 < R / 2019
  puts 0
  exit 0
end

(L..R).to_a.combination(2) do |r, l|
  ans = [ans, r * l % 2019].min
end

puts ans

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		long sum = t;
		for (int i = 0; i < n - 1; i++) {
			sum += Math.min(t, a[i + 1] - a[i]);
		}
		System.out.println(sum);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 64288
N, *D, = [list(map(int, s.split())) for s in open(0)]
N, D = N[0], D[0]
takoyaki_sum = 0
for i in range(N):
    for j in range(N):
        if i != j:
            takoyaki_sum += D[i]*D[j] 
        
print(int(takoyaki_sum/2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll d;cin>>d;
    ll G;cin>>G;
    vector<ll>pt(1<<d);
    vector<pll>pc(d);
    vector<ll>cnt(1<<d);
    rep(i,d){
        ll p,c;
        cin>>p>>c;
        pc[i]=mp(p,c);
    }
    rep(i,1<<d){
        rep(j,d){
            if((1<<j)&i){
                pt[i]+=(j+1)*100*pc[j].first+pc[j].second;
                cnt[i]+=pc[j].first;
            }
        }
    }
    ll mi=inf;
    rep(i,1<<d){
        if(pt[i]>=G){
            mi=min(cnt[i],mi);
        }else{
            ll k=cnt[i];
            for(int j=d-1;j>=0;j--){
                if(!((1<<j)&i)){
                    if((pc[j].first-1)*(j+1)*100+pt[i]>=G){
                        k+=(G-pt[i]+(j+1)*100-1)/((j+1)*100);
                        mi=min(k,mi);
                    }
                    break;
                }
            }
        }
    }
    cout<<mi<<endl;
}

Measured memory_bytes: 256
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		string s,t;
		cin >> s >> t;
		ll int n = s.length();;
		ll int ans = 0;
		for(ll int i = 0; i < n; i++)
		{
			if(s[i] != t[i])
			{
				ans ++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

void swap ( vector<int> &v, int a, int b )
{
	int tmp = v[a];
	v[a] = v[b];
	v[b] = tmp;
}

int SelectionSort ( vector<int> &v )
{

	int i,j,count=0,min_index;

	for ( i = 0 ; i < v.size() ; i++ )
	{
		min_index = i;
		for ( j = i ; j < v.size() ; j++ )
		{
			if ( v[min_index] > v[j] )
			{
				min_index = j;
			}
		}
		if ( min_index != i )
		{
			swap ( v, min_index, i );
			count++;
		}
	}

	return count;
}

void show ( vector<int> &v )
{
	int i;
	for ( i = 0 ; i < v.size()-1 ; i++ )
	{
		cout << v[i] << " ";
	}
	cout << v[i] << endl;
}

int main () 
{

	vector<int> v;
	int N,n,count=0;

	cin >> N;

	while ( N-- )
	{
		cin >> n;
		v.push_back ( n );
	}

	count = SelectionSort ( v );

	show ( v );

	cout << count << endl;;

return 0;
}



Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
using namespace std;
int mapp[12][10005],n,m,ans;

void fan(int x)
{
    for(int i=0;i<m;++i)
        mapp[x][i]^=1;
}

int zong()
{
    int sum=0;
    for(int j=0;j<m;++j)
    {
        int nowsum=0;
        for(int i=0;i<n;++i)
        {
            if(mapp[i][j]==0)
                nowsum++;
        }
        sum+=max(nowsum,n-nowsum);
    }
    return sum;
}

void dfs(int r)
{
    if(r==n)
    {
        ans=max(ans,zong());
        return ;
    }
    fan(r);
    dfs(r+1);
    fan(r);
    dfs(r+1);

}

int main()
{
    while(cin>>n>>m)
    {
        if(n==0&&m==0)
            break;
        ans=-1;
        for(int i=0;i<n;++i)
        {
            for(int j=0;j<m;++j)
            {
                cin>>mapp[i][j];
            }
        }
        dfs(0);
        cout<<ans<<endl;
    }
}


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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using Pair = pair<int, int>;
const ll mod = 1e9 + 7;

int main(int argc, char const* argv[])
{
  int h, a;
  cin >> h >> a;

  int ans = (h+a-1)/a;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int H, N;
  scanf("%d%d", &H, &N);
  for (int i = 0; i < N; ++i) {
    int A;
    scanf("%d", &A);
    H -= A;
    if (H <= 0) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define N (ll)(1e17+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
ll n,dp[100005],k;
vector <ll> v;
ll f(ll pos)
{
     if(dp[pos]!=-1)
      return dp[pos];
     if(pos==n-1)
      return 0;
     //return dp[pos]=min(abs(v[pos+1]-v[pos])+f(pos+1),abs(v[pos+2]-v[pos])+f(pos+2)); 
     ll i,x=min(n-pos-1,k),mn=1000000000;
     for(i=1;i<x+1;i++)
     {
          mn=min(mn,abs(v[pos+i]-v[pos])+f(pos+i));
     }
     return dp[pos]=mn;
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll t=1;
   //cin>>t;
   while(t--)
   {    
        ll i,x,ans;
        cin>>n>>k;
        memset(dp,-1,sizeof(dp));
        for(i=0;i<n;i++)
        {
             cin>>x;
             v.pb(x);
        }
        ans=f(0);
        cout<<ans<<"\n";
   }
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
typedef pair <int, int> P;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;

using namespace std;



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

	int res = 0;
	while (s.size()>1) {
		if (s[0] == s[s.size() - 1]) {
			s.erase(s.begin());
			s.erase(s.end() - 1);
		}
		else if (s[0] == 'x') {
			s.erase(s.begin());
			res++;
		}
		else if (s[s.size() - 1] == 'x') {
			s.erase(s.end() - 1);
			res++;
		}
		else {
			cout << -1 << endl;
			return 0;
		}

	}
	cout << res << endl;


	
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n; cin>>n;
  vector<ii> ans;
  priority_queue<int> qa;
  priority_queue<int, vector<int>, greater<int>> qb;
  ll p=0;
  for (int i=0; i<n; i++) {
    int x; cin>>x;
    if (x==1) {
      int a,b; cin>>a>>b;
      if (!qa.empty()&&!qb.empty() && (a<qa.top() || qb.top()<a)) {
        p += min(abs(a-qa.top()), abs(a-qb.top()));
      }
      p += b;

      qa.push(a); qb.push(a);
      int ta = qa.top();
      int tb = qb.top();
      if (ta > tb) {
        qa.pop(); qb.pop();
        qa.push(tb); qb.push(ta);
      }
    } else {
      ans.push_back(make_pair(qa.top(), p));
    }
  }

  for (int i=0; i<(int)(ans.size()); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}

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


Measured memory_bytes: 5620
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

struct circle{
    double x;
    double y;
    double r;
};

double getcost(circle a,circle b){
    double dist = sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    return max(0.0,dist-(a.r + b.r));
}

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

    double xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;

    vector<circle> s;
    s.push_back(circle{xs,ys,0.0});
    s.push_back(circle{xt,yt,0.0});
    int n;
    cin >> n;
    for(int i = 2; i < n+2; i++){
        double x,y,r;
        cin >> x >> y >> r;
        s.push_back(circle{x,y,r});
    }

    vector<vector<double>> cost(n+2,vector<double>(n+2,(double)(1333333333333333333)));
    vector<double> d(n+2,(double)(1333333333333333333));
    d[0] = 0;
    vector<bool> used(n+2,false);

    for(int i = 0; i < n+2; i++){
        for(int j = 0; j < n+2; j++){
            if(i == j)continue;

            double c = getcost(s[i],s[j]);
            cost[i][j] = c;
        }
    }
    
    while(true){
        int v = -1;
        for(int u = 0; u < used.size(); u++){
            if(!used[u] && (v == -1 || d[u] < d[v]))
            v = u;
        }
        if(v == -1){
            break;
        }

        used[v] = true;
        for(int u = 0; u < d.size(); u++){
            d[u] = min(d[u], d[v] + cost[v][u]);
        }
    }
    
    cout << fixed;
    cout << setprecision(17) << d[1] << endl;

    return 0;
}

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

int main()
{
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << static_cast<char>(s1[0] + 'A' - 'a');
  cout << static_cast<char>(s2[0] + 'A' - 'a');
  cout << static_cast<char>(s3[0] + 'A' - 'a');
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                sb.append(i).append("x").append(j).append("=").append(i * j).append("\n");
            }
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 26192
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xys <- U.unfoldrN n parseInt2 <$> B.getContents
    print $ solve n xys

solve :: Int -> U.Vector (Int, Int) -> Int
solve n xys = go 0 . map snd . sortBy (flip compare)
    . U.toList
    $ U.map (\(x, y) -> (x + y, (x, y))) xys
  where
    go !acc ((x, _):(_, y):xys) = go (acc + x - y) xys
    go acc [(x, _)] = acc + x
    go acc [] = acc

-------------------------------------------------------------------------------
type Parser a = B.ByteString -> Maybe (a, B.ByteString)

parseInt :: Parser Int
parseInt = B.readInt . B.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (B.readInt . B.dropWhile isSpace)
        <*> StateT (B.readInt . B.unsafeTail)


Measured memory_bytes: 37244
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

#define MOD 1000000007
unsigned long long power_mod(unsigned long long m, unsigned long long n) {
	return (n == 0 ? 1 : n % 2 == 0 ? power_mod((m % MOD) * (m % MOD) % MOD, n / 2) : m % MOD * power_mod(m % MOD, n - 1)) % MOD;
}
signed main() {
	int m = in(), n = in();
	cout << power_mod(m, n) << endl;
}


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

int main()
{
    string S;
    int ans = 0;

    cin >> S;

    for(int i = 0; i < S.size(); i++) {
        ans += (S[i] == 'g') - (S[i] == 'p');
    }

    cout << ans / 2 << endl;

    return (0);
}


Measured memory_bytes: 512
import math
n=int(input())
p=print
i=input
a=[int(s) for s in i().split()]
b=[int(s) for s in i().split()]
m1=0
m2=0
m3=0
m4=0
for x,y in zip(a,b):
    fabs=math.fabs(x-y)
    m1+=fabs
    m2+=fabs**2
    m3+=fabs**3
    m4=max(fabs,m4)
p(m1)
p(pow(m2,1/2))
p(pow(m3,1/3))
p(m4)


Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,m,i;
    cin>>n>>m;
    int ara[n+5];
    int total=0;
    for(i=0;i<n;i++)
    {
        cin>>ara[i];
        total+=ara[i];
    }
    double x=1/(4.0*(double)m);
    int ans=0;
    for(i=0;i<n;i++)
    {
        if((((double)ara[i])/(double)total)>=x)
            ans++;
    }
    if(ans>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, b = 0, sum = 0, num = 0, ans = 0;
	char a; cin >> n;
	for(int h = 0; h < n; h++){
		cin >> a;
		if (a == 'O' && num == 1) {
			ans++; b++;
		}
		if (a == 'X' && sum == 1) {
			ans++; b++;
		}
		sum = 0; num = 0;
		if (a == 'O' && b == 0) {
			sum++;
		}
		if (a == 'X' && b == 0) {
			num++;
		}
		b = 0;
	}
	cout << ans << endl;
	cin >> n;
}


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

int main(){
  int K,N;
  cin >>K>>N;
  vector<int> A(N);
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  
  vector<int> sub(N);
  for (int i=0;i<N-1;i++){
    sub[i] = A[i+1]-A[i];
  }
  sub[N-1] = A[0]+K-A[N-1];
  
  sort(sub.begin(),sub.end());
  
  cout<<K-sub[N-1]<<endl;
}

Measured memory_bytes: 1792
#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];
   }
   vector<int> b(n);
   b[0]=0;
   for(int i=1;i<n;i++)
   {
       b[i]=b[i-1]+abs(a[i]-a[i-1]);
       for(int j=i-1;j>=0&&j>=i-k;j--)
       b[i]=min(b[i],b[j]+abs(a[i]-a[j]));
   }
   cout<<b[n-1];
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int nextc = 1;
  for (int i = 0; i < N - 1; i++){
    nextc *= K - 1;
  }
  cout << K * nextc << endl;
}

Measured memory_bytes: 256
//  यस्य स्मरणमात्रेण जन्मसंसारबन्धनात् ।  विमुच्यते नमस्तस्मै विष्णवे प्रभविष्णवे ॥
 
 
 
/****
*     Author- Indrajeet Mishra
*             MNNIT Allahabad, Prayagraj
*             Chemical Engineering undergraduate
 
 
 
****/
 
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
 
#include <bits/stdc++.h>
#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define test(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }
#define debug(x) do { std::cerr << x; } while (0)
#define endl "\n"
#define pb push_back
#define pf push_front
#define vll vector<ll>
#define dll deque<ll>
#define sll set<ll, greater <ll>>
#define mll map<ll, ll>
#define vii vector<int>
#define dii deque<int>
#define sii set <int, greater <int>>
#define mii map<int, int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define inv2 500000004
#define inv6 166666668
#define N 1000005
#define inf 200000000
#define eps 1e-10
#define PI 3.14159265359
#define all(v) (v).begin(),(v).end()
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define gcd(a,b) __gcd(a,b)

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 

using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a=0,b=0;cin>>a>>b;
    ll p=a-(2*b);
    if(p<0)p=0;
    cout<<p;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 101
#define INF (100000001)

void enqueue(int);
int dequeue();
int isEmpty();
int isFull();

void bfs(int);

int head = 0;
int tail = 0;
int p[N];
int n, M[N][N], d[N];

int main() {
    int i, j;
    int u, k, v;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
    return 0;
}

void bfs(int s) {
    int i, j;
    int u;

    head = 0;
    tail = 0;

    enqueue(s);
    for (i = 0; i < n; i++) {
        d[i] = INF;
    }
    d[s] = 0;

    while (!isEmpty()) {
        u = dequeue();
        for (j = 0; j < n; j++) {
            if (M[u][j] == 0) continue;
            if (d[j] != INF) continue;
            d[j] = d[u] + 1;
            enqueue(j);
        }
    }
    for (i = 0; i < n; i++) {
        printf("%d %d\n", i+1, (d[i] == INF) ? (-1) : (d[i]));
    }
}

void enqueue(int key){
    if (isFull()) {
        return;
    }
    if (tail == N) tail = 0;
    p[tail] = key;
    tail++;
}

int dequeue() {
    int key;
    if (isEmpty()) {
        return -1;
    }
    key = p[head];
    if (head + 1 == N) {
        head = 0;
    } else {
        head ++;
    }

    return key;
}

int isEmpty() {
    return head == tail;
}

int isFull() {
    return head == (tail + 1) % N;
}



Measured memory_bytes: 2068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    string aa = "NG";
    for (int i = 0; i < c - b + 1; i++) {
        if ((b + i) % a == 0)aa = "OK";
    }
    cout << aa << endl;
}

Measured memory_bytes: 3628
n=int(input())
a=list(map(int,input().split()))

cnt=[0]*((10**6)+1)

for elem in a:
    cnt[elem]+=1

unique=[]

for i in range((10**6)+1):
    if cnt[i]==1:
        unique.append(i)

cnt=[0]*((10**6)+1)

a=list(set(a))

for elem in a:
    for i in range(elem*2,(10**6)+1,elem):
        cnt[i]+=1

ans=0
for elem in unique:
    if cnt[elem]==0:
        ans+=1

print(ans)


Measured memory_bytes: 47380
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);
    
    string s;
    while (cin >> s) {
        int a, b;
        int n = s.size();
        for (int i = n; i > 0; i--) {
            if (s[i] == 'Z') {
                a = i;
                break;
            }
        }
        FOR(j,0,n)
            if (s[j] == 'A') {
                b = j;
                break;
            }
        cout << a - b + 1 << endl;
    }
}


Measured memory_bytes: 720
#include<cstdio>
#define int long long
#define min(a,b)((a)<(b)?(a):(b))
#define max(a,b)((a)>(b)?(a):(b))
const int N=1e5+3;
int n,m,a[N],b[N],ans1=-1e18,ans2=1e18,s;
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	  scanf("%lld",a+i),b[i]=a[i]+b[i-1];
	s=0;
	for(int i=m;i<=n;i++)s+=max(a[i],0);
	for(int i=m;i<=n;i++){
	  s=s-max(a[i],0)+max(a[i-m],0);
	  ans1=max(b[i]-b[i-m]+s,ans1);
	}
	s=0;
	for(int i=m;i<=n;i++)s+=min(a[i],0);
	for(int i=m;i<=n;i++){
	  s=s-min(a[i],0)+min(a[i-m],0);
	  ans2=min(b[i]-b[i-m]+s,ans2);
	}
	s=0;
	for(int i=1;i<=n;i++)s+=a[i];
	printf("%lld",max(ans1,s-ans2));
	return 0;
}

Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
};

typedef vector<set<Edge>> Graph;
signed main(void) {

	int n;
	cin >> n;

	string s;
	cin >> s;

	int Min = n;

	
	vector<int> wc(n + 1);
	int bc = 0;
	for (int i = n - 1; 0 <= i; i--) {
		wc[i] = wc[i + 1];
		if (s[i] == '.') wc[i]++;
	}


	REP(i, n + 1) {
		chmin(Min, bc + wc[i]);

		bc += s[i] == '#';
	}

	cout << Min << endl;
	return 0;
}

Measured memory_bytes: 1924
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A=[INT() for i in range(5)]
K=INT()

if max(A)-min(A)>K:
    print(':(')
else:
    print('Yay!')


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

using namespace std;

class segmented_sieve_t: public vector< int >
{
    /// Set your CPU's L1 data cache size (in bytes) here

    static constexpr int L1D_CACHE_SIZE = 32768; static constexpr int TRUE = 255;

    struct segment_t
    {
        int primes, multiples; segment_t( int p, int m ) : primes( p ), multiples( m ) {}
    };

public:

    segmented_sieve_t( const int limit )
    {
        size_t q = 0; int Sqrt = sqrt( limit ), Segment_Size = max( Sqrt, L1D_CACHE_SIZE ), P = Sqrt + 1;

        vector< segment_t > prime; char sieve[ Segment_Size ], is_prime[ P ]; memset( is_prime, TRUE, P ), push_back( 2 );

        // we sieve primes >= 3
        for ( int low = 0, i = 3, i2 = 9, n = 3, s = 3, s2 = 9; low <= limit; low += Segment_Size )
        {
            memset( sieve, TRUE, Segment_Size );

            // current segment = [low, high]
            int high = min( low + Segment_Size - 1, limit );

            // generate sieving primes using simple sieve of Eratosthenes
            for ( int t = i2; t <= high; i2 = ( t += ++i << 2 ), i++ )
                if ( is_prime[ i ] )
                    for ( int j = t; j <= Sqrt; j += i )
                        is_prime[ j ] = 0;

            // initialize sieving primes for segmented sieve
            for ( int t = s2; t <= high; s2 = ( t += ++s << 2 ), s++ )
                if ( is_prime[ s ] )
                    prime.emplace_back( s, t - low ), q++;

            // sieve the current segment
            for ( size_t l = 0; l < q; l++ )
            {
                int j = prime[ l ].multiples;

                for ( int k = prime[ l ].primes << 1; j < Segment_Size; j += k )
                    sieve[ j ] = 0;

                prime[ l ].multiples = j - Segment_Size;
            }

            int k = n - low;

            for( int p = high - low; k <= p; k += 2 )
                if ( sieve[ k ] ) // n =  low + k is a prime
                    push_back( low + k );

            n = low + k;
        }
    }

    bool exists( int p ) const
    {
        return binary_search( cbegin(), cend(), p );
    }

    const_iterator lower_bound( int p ) const
    {
        return std::lower_bound( cbegin(), cend(), p );
    }

    const_iterator upper_bound( int p ) const
    {
        return std::upper_bound( cbegin(), cend(), p );
    }

    int index( int p ) const
    {
        auto it = lower_bound( p );

        if ( it == cend() or *it != p )
            return -1;

        return it - cbegin();
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n; cin >> n; segmented_sieve_t prime( 55555 );

    for( int p = 11, count = 0; count < n; p += 10 )
        if( prime.exists( p ) )
            count++, cout << p << ' ';
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using ll = unsigned long long;
using namespace std;

struct RestaurantInfo{
    string city;
    int point;
    int orig_id;
};

int main(void) {
    int n;
    cin >> n;

    string *s = new string[n];
    int *p = new int[n];

    RestaurantInfo *c = new RestaurantInfo[n];

    for(int i =0; i < n; ++i) {
        cin >> c[i].city >> c[i].point;
        c[i].orig_id = i+1;
    }

    sort(c, c+n, [](const RestaurantInfo& a, const RestaurantInfo& b){
        if (a.city != b.city){
            return a.city < b.city;
        } else {
            return a.point > b.point;
        };});

    for(int i = 0; i < n; ++i) {
        cout << c[i].orig_id << endl;
    }

    return 0;
}

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

const int N = 4e3 + 2;

int x, y, sum;
string order;
vector<int> a, b;
bool f[2][2 * N];

bool check(vector<int> x, int des) {
  memset(f, 0, sizeof f);
  int sz = (int)x.size();
  f[0][0] = true;
  sum = 0;
  for (int i = 0; i < sz; i++) {
    sum += x[i];
    int st = i & 1;
    memset(f[st ^ 1], 0, sizeof f[st ^ 1]);
    for (int j = 0; j <= 8000; j++) {
      if(j + x[i] <= 8000 && f[st][j] == true) f[st ^ 1][j + x[i]] = true;
      f[st ^ 1][j] |= f[st][j];
    }
  }
  for (int i = 0; i <= sum; i++) {
    if (f[sz & 1][i] == true && sum - 2 * i == des) {
      return true;
    }
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> order;
  cin >> x >> y;
  y = abs(y);
  int firstAdd = -1;
  int sLen = (int)order.length(), dir = 1;
  for (int i = 0; i < sLen; i++) {
    int pt = i;
    while (order[pt] != 'T' && pt < sLen) pt++;
    dir ^= 1;
    if (firstAdd == -1) {
      firstAdd = pt - i;
      i = pt;
      continue;
    }
    if (pt - i == 0) {
      continue;
    }
    if (dir == 0) a.push_back(pt - i); // hori
    else b.push_back(pt - i);
    i = pt;
  }
  x -= firstAdd; 
  x = abs(x);
  bool flag = true;
  flag &= check(a, x);
  flag &= check(b, y);
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
import sys

flag = 0
d1 = {}
d2 = {}
for line in sys.stdin:
  if line == "\n":
    flag = 1
  elif flag == 0:
    c,d = map(int,line.split(","))
    if c in d1:
      d1[c] += 1
    else:
      d1[c] = 1
  else:
    c,d = map(int,line.split(","))
    if c in d2:
      d2[c] += 1
    else:
      d2[c] = 1
sorted(d1.items(), key=lambda x: x[0])
sorted(d2.items(), key=lambda x: x[0])

for i in d1:
  if i in d2:
    print(str(i) + " " + str(d1[i]+d2[i]))

Measured memory_bytes: 7744
from bisect import bisect_left
M = 200001
n = int(input())
l = [None] * n
ans = 10 ** 18
for i in range(n):
    x, y, u = input().split()
    u = ('R', 'U', 'L', 'D').index(u)
    l[i] = (int(x), int(y), u)
for _ in range(4):
    l.sort(key=lambda x: x[0])
    xy = [[] for _ in range(M * 2 - 1)]
    yx = [[] for _ in range(M * 2 - 1)]
    xs = [[] for _ in range(M)]
    k = []
    for i, t in enumerate(l):
        x, y, u = t
        u %= 4
        if u == 1:
            xy[x + y].append(x)
        elif u == 3:
            yx[x - y + M].append(x)
        elif u == 2:
            xs[y].append(x)
        else:
            k.append((x, y))
        l[i] = (-y + M - 1, x, u + 1)
    for x, y in k:
        idx = bisect_left(xs[y], x)
        if idx < len(xs[y]):
            ans = min(ans, (xs[y][idx] - x) * 5)
        idx = bisect_left(xy[x + y], x)
        if idx < len(xy[x + y]):
            ans = min(ans, (xy[x + y][idx] - x) * 10)
        idx = bisect_left(yx[x - y + M], x)
        if idx < len(yx[x - y + M]):
            ans = min(ans, (yx[x - y + M][idx] - x) * 10)
if ans == 10 ** 18:
    print('SAFE')
else:
    print(ans)


Measured memory_bytes: 324004
n, m = [int(x) for x in input().split()]
a = set([int(input()) for _ in range(m)])
# a = [int(x) for x in input().split()]
 
memo = [0]*(n + 1)
 
for i in range(n+1):
  if i in a:
    continue
  else:
    if i == 0 or i == 1:
      memo[i] = 1
    else:
      memo[i] = (memo[i-1] + memo[i-2])%((10**9)+7)
 
print(memo[n])

Measured memory_bytes: 13216
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int,readline().split())

g = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,readline().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
    

order = []
parent = [-1]*n
st = [0]
while st:
    v = st.pop()
    order.append(v)
    for c in g[v]:
        if parent[v] != c:
            parent[c] = v
            st.append(c)

INF = 1<<30
high = [INF]*n
low = [-INF]*n
val = [INF]*n

k, = map(int,readline().split())
for _ in range(k):
    v,p = map(int,readline().split())
    high[v-1] = low[v-1] = val[v-1] = p

for v in order[:0:-1]:
    p = parent[v]
    #elif val[v]== INF: # vに好きな数書ける
    h,l = high[v]+1,low[v]-1
    
    if h >= INF:
        pass
    elif high[p]>=INF:
        high[p] = h
        low[p] = l
    elif (high[p]-h)&1==0: #偶奇一致
        if h < high[p]: high[p] = h
        if l > low[p]: low[p] = l
        if high[p] < low[p]:
            print("No")
            break
    else: #偶奇違ってダメ
        print("No")
        break
    #print(v,val,high,low)
    
else: #OK
    print("Yes")
    for v in order:
        if val[v] == INF:
            val[v] = low[v]
        for c in g[v]:
            high[c] = min(high[c],val[v]+1)
            low[c] = max(low[c],val[v]-1)
    
    
    print(*val,sep="\n")








Measured memory_bytes: 37648
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, K;
  cin >> N >> K;
  ll ans1 = 0, ans2 = 0;
  for (int i = 1; i <= N; i++) {
    if (i % K == 0) ans1++;
    if (i % K == K / 2) ans2++;
  }
  if (K % 2 == 0) {
    cout << ans1 * ans1 * ans1 + ans2 * ans2 * ans2 << endl;
  } else {
    cout << ans1 * ans1 * ans1 << endl;
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int ma = 0, mi = 1e5, k;
    for (int i = 0; i < 5;i++)
    {
        int t;
        cin >> t;
        ma = max(ma, t);
        mi = min(mi, t);
    }
    cin >> k;
    cout << (ma - mi <= k ? "Yay!" : ":(") << endl;
    return 0;
}


Measured memory_bytes: 888