akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
 
using namespace std;
 
const int MAX_N = 100000;
const int MAX_P = 100;
const int MAX_PRIME = (MAX_N+MAX_P)*2+100;
 
int prime[MAX_N];
int n_prime;
 
void init_prime() {
  prime[0] = 2;
  n_prime = 1;
   for (int i=3;i<MAX_PRIME;i++) {
    if (i%2 == 0) continue;
    bool ok = true;
    for (int j=3;j<=sqrt(i);j+=2) {
      if (i%j == 0) {
        ok = false;
        break;
      }
    }
    if (ok) prime[n_prime++] = i;
  }
}
 
int main() {
  init_prime();
  while (true) {
    int N, P;
    scanf("%d %d", &N, &P);
    if (N == -1 && P == -1) break;
    const int* p = upper_bound(prime, prime+n_prime, N);
    vector<int> t;
    for (int i=0;i<P;i++) {
      for (int j=i;j<P;j++) t.push_back(p[i]+p[j]);
    }
    sort(t.begin(), t.end());
    printf("%d\n", t[P-1]);
  }
  return 0;
}


Measured memory_bytes: 2764
//
// Created by Nivras on 2017/5/14.
//

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

class Task {
public:
    int times;
    char name[10];

    void read();
};

void Task::read() {
    scanf("%s%d", name, &times);
}

class TaskQueue {
public:
    Task data[101000];
    const int MAXLEN = 100100;
    int head;
    int tail;

    TaskQueue();
    void push(Task element);
    Task front();
    bool isEmpty();
};

TaskQueue::TaskQueue() {
    memset(data, 0, sizeof(data));
    head = tail = 0;
}

void TaskQueue::push(Task element) {
    data[tail] = element;
    tail = (tail + 1) % MAXLEN;
}

Task TaskQueue::front() {
    Task result = data[head];
    head = (head + 1) % MAXLEN;
    return result;
}

bool TaskQueue::isEmpty() {
    return head == tail;
}

int main()
{
    int n, pertime;
    scanf("%d%d", &n, &pertime);
    TaskQueue queue;
    for (int i = 0; i < n; i++) {
        Task tempTask;
        tempTask.read();
        queue.push(tempTask);
    }
    int nowtime = 0;
    while (!queue.isEmpty()) {
        Task nowTask = queue.front();
        if (nowTask.times <= pertime) {
            nowtime += nowTask.times;
            printf("%s %d\n", nowTask.name, nowtime);
        }
        else {
            nowTask.times -= pertime;
            nowtime += pertime;
            queue.push(nowTask);
        }
    }
    return 0;
}

Measured memory_bytes: 4288
N = int(input())
S = input()
ans = 0
right = 0
for left in range(N - 1):
    while right < N and (S[left : right] in S[right :]):
        right += 1
    if left == right:
        right += 1
    ans = max(ans, right - left - 1)
print(ans)

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

 
int main() {
  int a,b,c,k,i,big,gcd,flag;
  cin >> k;
  int64_t sum=0;
  for(a=1;a<=k;a++){
    for(b=1;b<=k;b++){
      for(c=1;c<=k;c++){
        big=200;flag=0;
        if(big>a)
          big=a;
        if(big>b)
          big=b;
        if(big>c)
          big=c;
        for(i=big;i>0;i--){
          if(a%i==0&&b%i==0){
            if(c%i==0){
              gcd=i;
              flag=1;
            }
          }
          if(flag==1)
            break;
        }
        sum+=gcd;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const double pi = acos(-1.0);

double calc(double x, double y){
    return fmin(fmin(fabs(x - y), fabs(x - y + 2 * pi)), fabs(x - y - 2 * pi));
}

int main() {
    int n;
    cin >> n;
    VD x(n), y(n);
    REP(i,n){
        cin >> x[i] >> y[i];
    }
    VI p(n);
    REP(i,n) p[i] = i;
    double ans = 1e9;
    do {
        double s = 0.0, t = 0.0;
        double xp = 0.0, yp = 0.0;
        REP(i,n){
            double xq = x[p[i]], yq = y[p[i]];
            double u = atan2(yq - yp, xq - xp);
            // cout << t * 180 / pi << " " << u * 180 / pi << endl;
            s += calc(t, u);
            xp = xq;
            yp = yq;
            t = u;
        }
        s += calc(t, atan2(-yp, -xp));
        ans = fmin(ans, s);
    }while (next_permutation(ALL(p)));
    ans *= 180.0 / pi;
    printf("%.15f\n", ans);
    return 0;
}



Measured memory_bytes: 3448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
ll t[1000];

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

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


int main() {
	cin >> n;
	rep(i, n)cin >> t[i];
	ll num = t[0];
	FOR(i, 1, n) {
		num = lcm(num, t[i]);
	}
	cout << num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

bool check(string &s, int i) {
  bool ret = true;
  rep(j, s.size()) {
    if (s[j] - 'a' != i) {
      ret = false;
      break;
    }
  }
  return ret;
}

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

  ll N; cin >> N;

  // 1/w = 4/N - 1/h - 1/n
  // = (4hn - Nn - nh)/Nhn


  for(int h=1; h<=3500; h++) {
    for(int n=1; n<=3500; n++) {
      ll u = N*h*n;
      ll d = 4*h*n - N*n - N*h;
      // 1/w = d/u;
      if (d > 0 && u > 0 && u%d == 0) {
        cout << h << ' ' << n << ' ' << u/d << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int  n, i;
  long long ans=0;
  scanf("%d\n", &n);
  for(i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  printf("%lld", ans);
  
  return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int digitsum(int x){
  int sum=0;
  while(x>0){
    sum+=(x%10);
    x/=10;
  }
  return sum;
}

int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max({a*c,a*d,b*c,b*d})<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template<typename T, typename E>
struct segment_tree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  typedef function<E(E,E)> H;
  typedef function<E(E,int)> P;

  vector<T> data;
  vector<E> lazy;

  F f;
  G g;
  H h;

  int n;

  T tid;
  E eid;

  P p;
  segment_tree(int size, F f, G g, H h, T tid, E eid, P p=[](E a, int b){b=0;return a+b;}):f(f),g(g),h(h),tid(tid),eid(eid),p(p){
    n = 1;
    while(n<size) n<<=1;
    data.assign(2*n-1,tid), lazy.assign(2*n-1,eid);
  }
  segment_tree(vector<T> v,F f, G g, H h, T tid, E eid, P p=[](E a, int b){return a;}):f(f),g(g),h(h),tid(tid),eid(eid),p(p){
    int size = v.size();
    n = 1;
    while(n<size) n<<=1;
    assign(v);
  }
  void assign(vector<T> v){
    assert((int)v.size()<=n);
    for(size_t i=0;i<v.size();++i) data[i+n-1] = v[i];
    for(int i=v.size();i<n;++i) data[i+n-1] = tid;
    for(int i=n-2;i>=0;--i) data[i] = f(data[2*i+1],data[2*i+2]);
    lazy.assign(2*n-1,eid);
  }
  inline void eval(int k, int len){
    if(lazy[k]!=eid){
      data[k] = g(data[k],p(lazy[k],len));
      // k has children.
      if(len > 1){
        lazy[2*k+1] = h(lazy[2*k+1],lazy[k]);
        lazy[2*k+2] = h(lazy[2*k+2],lazy[k]);
      }
      lazy[k] = eid;
    }
  }
  void update(int i, E x){
    update(i,i+1,x,0,0,n);
  }
  void update(int a,int b,E x){
    update(a,b,x,0,0,n);
  }
  void update(int a, int b, E x,int k, int l, int r){
    eval(k,r-l);

    // [l,r) out of [a,b)
    if(b<=l||r<=a) return;
    // [l,r) in [a,b)
    if(a<=l && r<=b){
      lazy[k] = h(lazy[k],x);
      eval(k,r-l);
    }else{
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      data[k] = f(data[2*k+1],data[2*k+2]);
    }
  }
  T find(int i){
    return find(i,i+1,0,0,n);
  }
  // [a,b)
  T find(int a,int b){
    return find(a,b,0,0,n);
  }
  T find(int a,int b,int k,int l,int r){
    eval(k,r-l);

    // [l,r) out of [a,b)
    if(r<=a||b<=l) return tid;

    // [l,r) in [a,b)
    if(a<=l&&r<=b) return data[k];

    // else
    return f(find(a,b,2*k+1,l,(l+r)/2),find(a,b,2*k+2,(l+r)/2,r));
  }
};
struct range_minimum_query{
  int ui = -1;
  function<int(int,int)> upd8 = [](int a, int b){return b!=-1?b:a;};
  function<int(int,int)> mini = [](int a, int b){return min(a,b);};
  int mi = INT_MAX;
  segment_tree<int,int> seg;
  range_minimum_query(int n):seg(n,mini,upd8,upd8,mi,ui){}

  int getmin(int a, int b){
    return seg.find(a,b);
  }
  void update(int i, int x){
    return seg.update(i,x);
  }
};
int main(){
  int n,q;
  cin >> n >> q;
  range_minimum_query rmq(n);
  for(int i=0;i<q;++i){
    int com,s,t;
    cin >> com >> s >> t;
    if(com==0){
      rmq.update(s,t);
    }else{
      cout << rmq.getmin(s,t+1) << endl;
    }
  }
}



Measured memory_bytes: 4928
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int> e[202020];
bool v[202020];
bool mark[202020];
vector<int> path;
vector<int> the_path;
int COOL;
int cnt = 0;

void dfs(int n) {
	if(v[n]) return;
	v[n] = true;
	path.pb(n);
	if(n == COOL) {
		the_path = path;
	}
	for(int i = 0; i < e[n].size(); i++) {
		dfs(e[n][i]);
	}
	path.pop_back();
	return;
}

void dfs2(int n) {
	if(v[n] || mark[n]) return;
	v[n] = true;
	cnt++;

	for(int i = 0; i < e[n].size(); i++) {
		dfs2(e[n][i]);
	}
	return;
}

int main() {
	int n; cin >> n;
	COOL = n;
	memset(v, false, 202020);
	for(int i = 0; i < n-1; i++) {
		int a, b; cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1);
	vector<int> blacks;
	vector<int> whites;
	int itrsize = the_path.size()/2;
	if(the_path.size()%2 == 1) itrsize++;
	for(int i = itrsize; i < the_path.size(); i++) {
		mark[the_path[i]] = 1;
	}
	mark[n] = 1;
	memset(v, false, 202020);

	dfs2(1);
	if(cnt > n/2) {
		cout << "Fennec";
	} else {
		cout << "Snuke";
	}
	
	return 0;
}


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

int main(){
	int n, m;
	std::vector<int> aList;
	std::vector<bool> isRedContainer;

	std::cin>>n>>m;

	aList.resize(n, 1);
	isRedContainer.resize(n, false);
	isRedContainer[0]= true;

	for(int i=0; i<m; i++){
		int push, pop;
		std::cin>>pop>>push;

		push-=1;
		pop-=1;

		if(isRedContainer[pop])
			isRedContainer[push]= true;

		aList[pop]--;
		aList[push]++;

		if(aList[pop]==0)
			isRedContainer[pop]=false;
	}

	int ans=0;
	for(int i=0; i<n; i++)
		if(isRedContainer[i])
			ans++;

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
int n,a[1005];
using namespace std;
int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  int l=0,cnt=0;
  while(l<n)
  {
    int r=l;
    while(r<n && a[l]==a[r])
      r++;
    cnt++;
    l=r;
  }
  cout<<cnt<<endl;
  system("pause");
  return 0;
}

Measured memory_bytes: 504
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
  return 0;
}


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

int mincost( int *arr , int *dp , int n , int i  ){
  if(i==0){
      dp[0] = 0 ;
      return 0 ;
  }
  if(i==1){
      dp[1] = max(arr[1] - arr[0] , arr[0] -arr[1]) ;
      return dp[1] ;
  }

  if( dp[i]!= -1){
      return dp[i] ;
  }

  int x = mincost(arr , dp , n , i-1) + max( arr[i] - arr[i-1] , arr[i-1] - arr[i]) ;
  int y = mincost( arr , dp , n , i-2) + max( arr[i] - arr[i-2] , arr[i-2] - arr[i]) ;
  int ans = min( x , y) ;
  return dp[i] = ans  ;
}


int main() {
    int n ;
    cin>> n;
    int arr[n] ;
    for( int i = 0 ;i< n ; i++){
        cin>>arr[i] ;
    }
      int dp[n] ;
    for( int i = 0 ;i< n ; i++){
        dp[i] = -1 ;
    }
  
    cout<<mincost( arr , dp , n , n-1)<<endl ;

    return 0 ;
}


Measured memory_bytes: 8832
#include<stdio.h>
#define N 100
void swap(int *x, int *y);
int main(){
  int n,i,j,count=0,a[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
	swap(a+j,a+(j-1));
	count++;
      }
    }
  }
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[n-1]);
  printf("%d\n",count);
  return 0;
}

void swap(int *x,int *y){
  int z;
  z= *x;
  *x=*y;
  *y=z;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,c;
vi a;

int main(){
	cin>>n>>m>>c;
	a=vi(m);
	for(auto &i:a) cin>>i;
	int res=0;
	for(int i=0;i<n;i++){
		int t=c;
		for(int j=0;j<m;j++){
			int x;
			cin>>x;
			t+=x*a[j];
		}
		if(t>0) res++;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=1e7+5+5e6;
using namespace std;
const ll INF=1e15+7;
const ll mod=1e9+7;
ll n,m,p;
char str[maxn];
int main()
{
    scanf("%s",str+1);
    int len=strlen(str+1);
    int s=1,e=len;
    int res=0;
    while(s<=e)
    {
        if(str[s]!=str[e])res++;
        s++;
        e--;
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#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) {
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 {
#ifdef LOCAL
~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 << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<vector<ll>>dp(n+1,vector<ll>(2,-inf));
    dp[0][0]=a[0];
    dp[0][1]=-a[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][0]+a[i],dp[i-1][1]-a[i]);
        dp[i][1]=max(dp[i-1][1]+a[i],dp[i-1][0]-a[i]);
    }
    //debug()<<dp;
    cout<<dp[n-1][0]<<endl;
}


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

#define dbg(x) cout << #x"=" << x << endl;
typedef long long LL;
const int MAX_N = 1e6+100;
bool is[MAX_N];

int main(){
   // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    memset(is, true, sizeof is);
    vector<int> a;
    for(int i = 2; i < MAX_N; ++i){
        if(is[i]){
            a.push_back(i);
            for(int j = 2*i; j < MAX_N; j += i){
                is[j] = false;
            }
        }
    }
    int x;
    cin >> x;
    cout << *lower_bound(a.begin(), a.end(), x) << endl;
    return 0;
}

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char x;
    int gs=0,cnt=0;
    while(scanf("%c",&x)==1)
    {
        if(x=='C')
            gs++;
        if(x=='F'&&gs)
        {
            cnt++;
            break;
        }
    }
    if(cnt)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
#define dvec vector<vector<int>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

int
rec(int v, vector<int> &dp, dvec &graph)
{
  if(dp[v] != -1) return dp[v];

  int res = 0;
  for(auto next : graph[v]){
    int tmp = rec(next, dp, graph);
    if(res < tmp + 1) res = tmp + 1;
  }

  return dp[v] = res;

}


int main() {

  int N, M; cin >> N >> M;
  vector<vector<int>> graph(N);
  vector<int> in(N);
  rep(i, 0, M){
    int x, y; cin >> x >> y;
    --x, --y;
    graph[x].push_back(y);
    in[y] += 1;
  }

  vector<int> dp(N);
  rep(i, 0, N) dp[i] = -1;

  int res = 0;
  rep(i, 0, N){
    int tmp = rec(i, dp, graph);
    if(res < tmp) res = tmp;
  }

  cout << res << endl;

}


Measured memory_bytes: 12064
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, nulong long_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<double> a;

bool check(int n, int k, double m) {
    int need = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= m) {
            continue;
        }
        int tmp = a[i] / m;
        need += tmp;
    }
//    cout << m << " " << need << '\n';
    return need <= k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        double x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    int cnt = 0;
    double L = 1.0, R = a.back();
    while (cnt < 1000) {
        double m = (L + R) / 2.0;
//        cout << L << " " << R << " " << m << '\n';
        if (check(n, k, m)) {
            R = m;
        } else {
            L = m;
        }
        cnt++;
    }
    int x = ceil(R);
    cout << x << '\n';
    return 0;
}


Measured memory_bytes: 5424
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;

int main() {
	int a,b,c;
	cin >> a;
	cin >> b;
	cin >> c;

	if (a + b >= c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> p(N);
    for (int &i : p) cin >> i;

    int ans = 0;
    rep(i, N-1) {
        if (p[i] == i+1) {
            swap(p[i], p[i+1]);
            ans++;
        }
    }
    if (p.back() == N) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> minNum(N);
    rep(i,N){
        cin >> P[i];
        if(i==0){
            minNum[i]=P[i];
            continue;
        }
        if(minNum[i-1]>P[i]){
            minNum[i]=P[i];
        }else{
            minNum[i]=minNum[i-1];
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(P[i]<=minNum[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
import bisect

S = input()

R = []
L = []
for i,s in enumerate(S):
    if s=="R":
        R.append(i)
    else:
        L.append(i)

ans = [0]*len(S)    
for i,s in enumerate(S):
    if s=="R":
        l = bisect.bisect_left(L, i)
        if (L[l]-i)%2 == 1:
            ans[L[l]-1] += 1
        else:
            ans[L[l]] += 1
    else:
        r = bisect.bisect_left(R, i)-1
        if (i-R[r])%2 == 1:
            ans[R[r]+1] += 1
        else:
            ans[R[r]] += 1
            
print(*ans)

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

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

int main()
{
    int n;
    cin >> n;
    vector<int> answer(n, 0);
    rep(i, n-1){
        int buf; cin >> buf;
        ++answer[buf-1];
    }
    rep(i, n) cout << answer[i] << endl;
    return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a, v, b, w, t;
	cin>>a>>v>>b>>w>>t;
	long long d=abs(a-b);
	if(v<=w){
		cout<<"NO";
	}
	else{
		long long ds=v-w;
		if(t*ds>=d){
			cout<<"YES";
		}
		else cout<<"NO";
	}
}

Measured memory_bytes: 3636
/**
*    author:  souzai32
*    created: 08.08.2020 00:20:35
**/

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

int main() {

    long long int n,k;
    cin >> n >> k;
    vector<tuple<int,int>> ab(n);
    int a,b;
    rep(i,n){
        cin >> a >> b;
        ab.at(i)=make_tuple(a,b);
    }

    sort(ab.begin(),ab.end());

    int i=0;
    int ans;
    while(i<n){
        k-=get<1>(ab.at(i));
        if(k<=0) break;
        i++;
    }

    cout << get<0>(ab.at(i)) << endl;

    return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
int main(){
    string str;
    cin >> str;
    if(str.find("a") != string::npos && str.find("b") != string::npos && str.find("c") != string::npos){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#define MAXN 200005
#define PLI pair<long long,int>
#define fi first
#define se second
#define mp make_pair
//#define ivorysi
using namespace std;
typedef long long int64;
int N;
int64 A[MAXN];
map<int64,int> mmm;
void Solve() {
	scanf("%d",&N);
	for(int i = 1 ; i <= N ; ++i) scanf("%lld",&A[i]);
	mmm[0] = 1;
	int64 ans = 0;
	for(int i = 1 ; i <= N ; ++i) {
		A[i] += A[i - 1];
		ans += mmm[A[i]];
		mmm[A[i]] += 1;
	}
	printf("%lld\n",ans);
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
string s;
map<string, vector<string> > g, g2;
void solve(int steps, string a, string b){
    if (steps == n){
        g[a].push_back(b);
        return;
    }
    solve(steps+1, a+s[steps], b);
    solve(steps+1, a, b+s[steps]);
}
void Solve(int steps, string a, string b){
    if (steps == n){
        g2[a].push_back(b);
        return;
    }
    Solve(steps+1, a+s[2*n-steps-1], b);
    Solve(steps+1, a, b+s[2*n-steps-1]);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;
    string s1 = "", s2 = "";
    solve(0, s1, s2);
    Solve(0, s1, s2);
    int ans = 0;
    for (map<string, vector<string> >::iterator it = g.begin(); it != g.end(); it++){
        pair<string, vector<string> > p = *it;
        if (!g2.count(p.first)) continue;
        vector<string> F = p.second, S = g2[p.first];
        sort(F.begin(), F.end());
        sort(S.begin(), S.end());
        map<string, int> gg;
        for (int i=0; i < F.size(); i++) gg[F[i]]++;
        for (int i=0; i < S.size(); i++) ans += gg[S[i]];
    }
    cout << ans;
    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,a,b;

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

  cin>>n>>a>>b;
  cout<<min(a*n,b)<<endl;

  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  Test
//
//  Created by momoc on 2019/8/18.
//  Copyright © 2019年 momoc. All rights reserved.
//

#include <iostream>
#include <cstdio>
typedef long long ll;
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    scanf("%d",&n);
    double sum = 0;
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        sum +=1.0/a;
        //cout<<sum<<endl;
    }
    double ans=1/sum;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K;
int A[int(2e5+5)], B[int(2e5+5)];

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];

  for (int i = 0; i < K; i++){
    fill(B, B + N, 0);

    for (int j = 0; j < N; j++){
      int m = max(0, j - A[j]);
      int M = min(N, j + A[j]) + 1;

      B[m]++; B[M]--;
    }
    for (int j = 1; j < N; j++){
      B[j] += B[j-1];
    }

    bool flag = true;
    for (int j = 0; j < N; j++){
      if (A[j] != B[j]) flag = false;
    }

    if (flag) break;
    for (int j = 0; j < N; j++) A[j] = B[j];
  }

  cout << A[0];
  for (int i = 1; i < N; i++) cout << " " << A[i];
  cout << endl;


  return 0;
}


Measured memory_bytes: 5180
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,M,K; cin>>N>>M>>K;
	vector<int> A(M), B(M), C(K), D(K);
	vector<vector<int>> adj(N);
	for (int i=0; i<M; i++)
		cin>>A[i]>>B[i], A[i]--, B[i]--, adj[A[i]].push_back(B[i]), adj[B[i]].push_back(A[i]);
	for (int i=0; i<K; i++)
		cin>>C[i]>>D[i], C[i]--, D[i]--;
	vector<int> ret(N,0);
	vector<set<int>> gp;
	map<int,int> idx;
	set<int> vis;
	int iter=0;
	for (int i=0; i<N; i++) {
		if(vis.count(i))
			continue;
		vis.insert(i);
		queue<int> q; q.push(i);
		set<int> g;
		while(!q.empty()) {
			int cur=q.front(); q.pop();
			g.insert(cur);
			idx[cur]=iter;
			for (auto nxt : adj[cur]) {
				if(vis.count(nxt))
					continue;
				vis.insert(nxt);
				q.push(nxt);
			}
		}
		gp.push_back(g);
		iter++;
	}

	for (auto g : gp) {
		int sz=g.size();
		for (auto x : g)
			ret[x]=sz-1;
	}

	for (int i=0; i<M; i++)
		if(idx[A[i]]==idx[B[i]])
			ret[A[i]]--, ret[B[i]]--;
  for (int i=0; i<K; i++)
    if(idx[C[i]]==idx[D[i]])
      ret[C[i]]--, ret[D[i]]--;
	for (int i=0; i<N; i++) {
		if(i) cout<<" ";
		cout<<ret[i];
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 27384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
using namespace std;

int main()
{
	int N;
	string S;
	vector<string> vec;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
		vec.push_back(S);
		sort(vec.begin(), vec.end());
		vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
	}
	if (vec.size() == 4) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;

	}

	return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
numeros = [int(x) for x in input().split()]
saida = sys.maxsize

for i in range(min(numeros), max(numeros)+1):
	valor = 0
	for j in numeros:
		valor += (j-i)**2
	
	saida = min(valor, saida)

print(saida)



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

// main.cpp

int main() {
  std::int_fast64_t N;
  std::cin >> N;
  std::unordered_map<std::string, std::int_fast64_t> map;
  for (std::int_fast64_t i = 0; i < N; ++i) {
    std::string s_i;
    std::cin >> s_i;
    map.insert(std::make_pair(s_i, 0));
    ++map[s_i];
  }
  std::int_fast64_t M;
  std::cin >> M;
  for (std::int_fast64_t i = 0; i < M; ++i) {
    std::string s_i;
    std::cin >> s_i;
    map.insert(std::make_pair(s_i, 0));
    --map[s_i];
  }

  std::cout << std::max<std::int_fast64_t>(
    0,
    std::max_element(
      map.begin(),
      map.end(),
      [](const std::pair<std::string, std::int_fast64_t>& lhs, const std::pair<std::string, std::int_fast64_t>& rhs) {
        return lhs.second < rhs.second;
      }
    )->second
  ) << std::endl;
  return 0;
}

Measured memory_bytes: 384
n, m, q = map(int, input().split())
data = [list(map(int, input().split())) for i in range(q)]

def listup(n, m):
    d = []
    c = [1 for i in range(n)]
    while True:
        d.append(tuple(c))
        if c == [m for i in range(n)]:
            break
        c[n - 1] += 1
        if c[n - 1] > m:
            for i in range(n - 1):
                if c[n - 2 - i] == m:
                    continue
                c[n - i - 2] += 1
                for j in range(i + 1):
                    c[n - i - 1 + j] = c[n - i - 2]
                break
    return d

d = listup(n, m)
dmax = 0
for i in range(len(d)):
    cura = d[i]
    di = 0
    for j in range(q):
        if cura[data[j][1] - 1] - cura[data[j][0] - 1] == data[j][2]:
            di += data[j][3]
    if dmax < di:
        dmax = di

print(dmax)

Measured memory_bytes: 98204
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>

void roll(std::vector<int> &v, char c) {
    if (c == 'E') {
        char tmp = v[0];
        v[0] = v[3];
        v[3] = v[5];
        v[5] = v[2];
        v[2] = tmp;
    } else if (c == 'S') {
        char tmp = v[0];
        v[0] = v[4];
        v[4] = v[5];
        v[5] = v[1];
        v[1] = tmp;
    } else if (c == 'N') {
        char tmp = v[0];
        v[0] = v[1];
        v[1] = v[5];
        v[5] = v[4];
        v[4] = tmp;
    } else {
        char tmp = v[0];
        v[0] = v[2];
        v[2] = v[5];
        v[5] = v[3];
        v[3] = tmp;
    }
}

int main(){
    std::vector<int> v(6);
    for (int i = 0; i < 6; i++) {
        std::cin >> v[i];
    }

    int n;

    std::cin >> n;

    for (int i = 0; i < n; i++) {
        int top, front;
        std::cin >> top >> front;

        if(v[1] != front) {
            if (v[4] == front) roll(v, 'N');
            while (v[0] != front) {
                roll(v, 'E');
            }
            roll(v, 'S');
        }
        while (v[0] != top) roll(v, 'E');
        std::cout << v[2] << std::endl;
    }

    return 0;
}

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

int n,k,ans=1e9;

void func(int cur, int ops){
  if(ops>=n){
    ans = min(ans,cur);
  }
  else {
    func(cur*2,ops+1);
    func(cur+k,ops+1);
  }
}

int main(){

  cin >> n >> k;
  func(1,0);
  cout << ans << endl;

  return 0;
}

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

const int MOD = 998244353;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll dp[3030][3030];

int main() {
    int n, s;
    cin >> n >> s;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    dp[0][0] = 1;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3030; j++) {
            if (j >= a[i]) {
                dp[i + 1][j] += dp[i][j - a[i]];
                dp[i + 1][j] %= MOD;
            }
            dp[i + 1][j] += dp[i][j] * 2LL;
            dp[i + 1][j] %= MOD;
        }
    }
    ans = dp[n][s];
    cout << ans << endl;
}

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



namespace Test1 {

    class ClassMain {



        public static bool[] primes = Enumerable.Repeat(true,1000000+1).ToArray();
        public static void initTable() {
            primes[0] = false;
            primes[1] = false;
            for (int i = 2; i < 1000000 / 2; i++) {
                if (primes[i]) {
                    for (int j = 2; i * j <= 1000000; j++) {
                        primes[i * j] = false;
                    }
                }
            }
        }



        public static void Main(String[] args) {
            string line;
            initTable();
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                int count = 0;
                for (int i = 2; i <= n/2; i++) {
                    if (primes[i] == false) { continue; }
                    if (primes[n - i]) { count++; }
                }
                Console.WriteLine(count);


    
            }
        }


    }

    
}

Measured memory_bytes: 8324
n, k = map(int, input().split())
p = list(map(int, input().split()))

p = list(map(lambda x: (sum(list(range(x + 1)))) / x, p))
tmp = sum(p[:k])
ans = tmp
for i in range(1, (n - k + 1)):
    tmp = tmp + p[i + k - 1] - p[i - 1]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 79368
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

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

  rep(i, str.size()){
    if(i % 2 == 0){
      if(str[i] == 'L'){
        cout << "No" << endl;
        break;
      }
    }else{
      if(str[i] == 'R'){
        cout << "No" << endl;
        break;
      }
    }
    if(i == str.size()-1)
      cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    double a,b,x;
    cin >> a >> b >> x;
    double area = x / a;
    double ans = 0;
    if(area < a*b/2.0){
        double s = area * 2.0 / b;
        ans = atan(b / s);
    }else{
        double up = area * 2.0 / a - b;
        ans = atan((b-up) / a);
    }
    
    cout << fixed << setprecision(10) << ans * 180.0 / M_PI << endl;
    return 0;
}

Measured memory_bytes: 256
//JOI2010-2011本選問４歩くサンタクロース(Walking Santa)
#include<iostream>
#include<cstdio>
#include<deque>
#include<algorithm>
using namespace std;
int main(){

	long long sum = 0LL, osum = 0LL;
	long long f1, f2, f3, cnt, w, h, L, HL, temp, oxy[2][2], *LXY[2], ox, oy, max = 0;
	deque<long long> XY[2];
	scanf("%lld %lld",&w, &h);
	scanf("%lld",&L);
	for(f1 = 0; f1 < 2; f1++)
		LXY[f1] = new long long [L];
	//100k
	for(f1 = 0; f1 < L; f1++){
		scanf("%lld %lld",&LXY[0][f1], &LXY[1][f1]);
		XY[0].push_back(LXY[0][f1]);
		XY[1].push_back(LXY[1][f1]);
	}
	//1m
	stable_sort( XY[0].begin(), XY[0].end() );
	stable_sort( XY[1].begin(), XY[1].end() );
	HL = (L + 1) / 2;
	//x軸での最小値の点、y軸での最小値の点を探す
	//200k
	if(L == 1){
		printf("0\n");
		printf("%lld %lld\n",LXY[0][0],LXY[1][0]);
	}
	else{
		for(f1 = 0; f1 < 2; f1++){
			cnt = 0;
			temp = XY[f1][cnt];
			cnt++;
			while(cnt < HL){
				while(cnt < L && temp == XY[f1][cnt])
					cnt++;
				if(cnt < HL)
					temp = XY[f1][cnt];
			}
			oxy[0][f1] = XY[f1][cnt-1];
			oxy[1][f1] = XY[f1][cnt];
		}
		//400k
		for(f2 = 0; f2 < 2; f2++){
			for(f3 = 0; f3 < 2; f3++){
				sum = 0LL;
				max = 0LL;
				for(f1 = 0; f1 < L; f1++){
					temp = (long long)abs(LXY[0][f1] - oxy[f2][0]) + abs(LXY[1][f1] - oxy[f3][1]);
					sum += temp * 2;
					if(sum < 0)
						break;
					if(max == 0 || max < temp)
						max = temp;
				}
				sum -= max;
				if(sum > 0 && (osum == 0 || osum > sum || osum == sum && ox >= oxy[f2][0] && oy > oxy[f3][1])){
					osum = sum;
					ox = oxy[f2][0];
					oy = oxy[f3][1];
				}
			}
		}
		printf("%lld\n", osum);
		printf("%lld %lld\n", ox, oy);
	}
	return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    string s,ps;
    int n;
    set<string> st;
    cin >> n;
    cin >> ps;
    st.insert(ps);
    for (int i = 0; i < n-1; i++) {
        cin >> s;
        if (st.find(s) != st.end() or s[0] != ps.back()) {
            cout << "No" << endl;
            return 0;
        }
        st.insert(s);
        ps = s;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n, k;
long long  a = 0, b = 0;
int main() {
    cin >> n >> k;
    a = n/k;
    if (k % 2 != 0) {
            cout << a * a * a;
            return 0;
    }
    b = n/(k/2) - n/k;
    long long r = a * a * a + b * b * b;
    cout << r;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
typedef long long int ll;

ll *dp;
ll *a;
/*
ll solution(int s)
{

    if (dp[s] != 0)
    {
        return dp[s];
    }

    dp[s] += min(solution(s+1), (solution(s+2)));
    return dp[s];
}
*/
int main()
{
    string x,y;
    //char a;
    getline(cin, x);
    getline(cin, y);
    //cout<<x<<"\n"<<"\n"<<y;
    int m = x.length();int r, c;
    int n = y.length();
    int dp[m+1][n+1] ;
    int len=0;
    for(int i=0;i<=m;i++)dp[i][0] = 0;
    for(int i=0;i<=n;i++)dp[0][i] = 0;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(x[i-1]==y[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);

        }
    }
    string res = "";
    int i=m, j =n;
    while(i>0&&j>0){
        if(i==0||j==0)
            break;
        else if(dp[i-1][j]==dp[i][j])
            i--;
        else if(dp[i][j-1]==dp[i][j])
            j--;
        else{
                //cout<<x[i-1]<<" ";
            j--;res+=x[i-1];i--;
        //cout<<res<<"\n";
        }
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
//  cout<<dp[n][W]<<endl;
    return 0;
}


Measured memory_bytes: 38828
x = int(input())
def f1(a, b): return a**5 - b**5
def f2(a, b): return a**5 + b**5
for f, sign_b in ((f1, 1), (f2, -1)):
    b = 0
    while f(a := b + 1, b) <= 10**9:
        while f(a, b) <= 10**9 and f(a, b) != x:
            a += 1
        if f(a, b) == x:
            print(a, sign_b * b)
            exit(0)
        b += 1


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define int long long

struct UnionFind {
    vector<int> Parent;
    vector<int> Size;

    UnionFind(int N) : Parent(N), Size(N,1){
        for(int i = 0; i < N; i++) Parent[i] = i;
    }

    int root(int A) {
        if (Parent[A] == A) return A;
        return Parent[A] = root(Parent[A]);
    }

    bool merge(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) return false;

        if (Size[A] < Size[B]) swap(A, B);

        Size[A] += Size[B];
        Parent[B] = A;
        return true;
    }

    bool issame(int A, int B) {
        return root(A) == root(B);
    }

    int findsize(int A) {
        return Size[root(A)];
    }
};

signed main() {
  int n,m;
  cin >> n >> m;

  UnionFind Tree(n);
  for (int i = 0; i < m; i++) {
    int a,b;
    cin >> a >> b;
    a--, b--;
    Tree.merge(a,b);
  }

  set<int> st;
  for (int i = 0; i < n; i++) {
    st.insert(Tree.root(i));
  }

  int ans = st.size();
  cout << ans - 1 << '\n';
}




Measured memory_bytes: 8496
from copy import copy
import random
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
    ps = [0]*26
    for j in range(26):
        pl = copy(last)
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[j] -= c[k]*(i+1-pl[k])
    idx = ps.index(max(ps))
    last[idx] = i+1
    ans[i] = idx+1
    score += max(ps)
T = 3000
for k in range(41000):
    na = copy(ans)
    x = random.randint(1,365)
    y = random.randint(1,365)
    if x == y:
        continue
    na[x-1],na[y-1] = na[y-1],na[x-1]
    last = [0]*26
    ns = 0
    for i in range(D):
        last[na[i]-1] = i+1
        ns += s[i][na[i]-1]
        for j in range(26):
            ns -= c[j]*(i+1-last[j])
    if k%100 == 0:
        T *= 0.98
    p = pow(math.e,-abs(ns-score)/T)
    if ns > score or random.random() < p:
        ans = na
        score = ns
for a in ans:
    print(a)

Measured memory_bytes: 87944
import sys
sys.setrecursionlimit(10**7)
INF=10**9+7
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    n, k = LI()
    graph=[[] for i in range(n)]
    for i in range(n-1):
        a,b=LI()
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=1
    check=[False]*n
    stack=[0]
    ans=1
    while len(stack)>0:
        x=stack.pop()
        check[x]=True
        count=0
        for i in graph[x]:
            if not check[i]:
                count+=1
                stack.append(i)
        if x==0:
            temp=1
            for i in range(count):
                temp=temp*(k-1-i)%INF
            ans=ans*temp%INF
        else:
            temp=1
            for i in range(count):
                temp=temp*(k-2-i)%INF
            ans=ans*temp%INF
    print((ans*k)%INF)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65072
#include<iostream>
using namespace std;
int main()
{
		int a,b,c,d,e;
		cin>>e;
		a=e/1000;
		d=e%10;
		e=e/10;
		c=e%10;
		e=e/10;
		b=e%10;

 		if(a+b+c+d==7) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
	else	if(a-b+c+d==7) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
	else	if(a+b-c+d==7) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
	else	if(a+b+c-d==7) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
	else	if(a+b-c-d==7) cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
	else	if(a-b-c-d==7) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
	else	if(a-b-c+d==7) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
	else	if(a-b+c-d==7) cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    vector<int> arr(N);
    vector<int> arr1(N);

    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    for (int j = 0; j < N; j++) {
        cin >> arr1[j];
    }

    int ans = 0;
    for (int k = 0; k < N; k++) {
        if (arr[k] - arr1[k] > 0) {
            ans += (arr[k] - arr1[k]);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include<algorithm>
using namespace std;
double a[50];
int n,k;
double sum;
bool cmp(double a,double b)
{
    return a>b;
}
int main()
{
    while(~scanf("%d%d",&n,&k))
    {
        sum = 0;
        for(int i = 0;i<n;i++)
        {
            scanf("%lf",a+i);
        }
        sort(a,a+n,cmp);
        for(int i = 0;i<k;i++)
        {
            sum += a[i];
        }
        printf("%.0f\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256