akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int n,p[40],t[40];
int dp[41][3];
main()
{
	while(cin>>n,n)
	{
		for(int i=0;i<n;i++)
		{
			cin>>p[i]>>t[i];
			for(int j=0;j<3;j++)dp[i][j]=1e9;
		}
		if(p[0]<=t[0])dp[0][0]=p[0];
		for(int i=0;i<n-1;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(j<2)
				{
					int d=abs(p[i]-p[i+1]);
					if(d*(j+2)<=t[i+1]-t[i])
						dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+d);
				}
				if(p[i]*(j+2)+p[i+1]<=t[i+1]-t[i])dp[i+1][0]=min(dp[i+1][0],dp[i][j]+p[i]+p[i+1]);
			}
		}
		int ans=1e9;
		for(int j=0;j<3;j++)ans=min(ans,dp[n-1][j]+p[n-1]);
		if(ans<1e9)cout<<"OK "<<ans<<endl;
		else
		{
			int id=n-1;
			while(id>=0&&dp[id][0]==1e9&&dp[id][1]==1e9&&dp[id][2]==1e9)id--;
			cout<<"NG "<<id+2<<endl;
		}
	}
}



Measured memory_bytes: 3004
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let n: usize = read!();
    let d: isize = read!();
    let mut v = 0;
    for _ in 0..n {
        let a: isize = read!();
        let b: isize = read!();
        if (a*a)+(b*b)<=d*d {
            v+=1;
        }
    }
    println!("{}",v);
}


Measured memory_bytes: 2188
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl;


//UnionFind群
class UnionFind {
protected:
    vector<int> par;
    vector<int> data;
    int cnt;
public:
    UnionFind() : par(1), data(1), cnt(1) {};

    UnionFind(int N);

    int root(int x);

    int marge(int x, int y);

    bool same(int x, int y);

    int add();

    int add(int x);

    inline int getSize(int x) { return data.at(root(x)); };

    int allroot();

    inline bool isroot(int x) { return (par.at(x) == -1); };
};

UnionFind::UnionFind(int N) : par(N), data(N), cnt(N) {
    for (int i = 0; i < N; i++) {
        par.at(i) = -1;
        data.at(i) = 1;
    }
}


int UnionFind::root(int x) {
    if (par.at(x) == -1) return x;
    return par.at(x) = root(par.at(x)); // 経路圧縮
}

int UnionFind::marge(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return rx;
    else { // ノード数の少ない方に接続
        if (data.at(rx) < data.at(ry)) swap(rx, ry);
        par.at(ry) = rx;
        data.at(rx) += data.at(ry);
        return rx;
    }
}

bool UnionFind::same(int x, int y) {
    return root(x) == root(y);
}

int UnionFind::add() {
    par.push_back(cnt);
    cnt++;
    return cnt - 1;
}

int UnionFind::add(int x) {
    par.push_back(cnt);
    cnt++;
    return marge(x, cnt);
}

int UnionFind::allroot() {
    int cnt = 0;
    for (const auto it : par) {
        if (it == -1) cnt++;
    }
    return cnt;
}

struct UF {
    vector<int> par;

    UF(int N) : par(N) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        else {
            par[rx] = ry;
            return;
        }
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int ansYes(bool y) {
    if (y) cout << "Yes" << endl; else cout << "No" << endl;
}

//約数の数を数える
int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}


int main() {
    vector<int> a(999);
    for (int i = 0; i < 999;i ++){
        a.at(i) = (i+2)*(i+3)/2 - (i+1)*(i+2)/2;
    }
    int  b , c;
    cin >> b >> c;
    for (int i = 0; i < 999 ; i++){
        if (c - b  == a.at(i)) {
            cout << (i+1)*(i+2)/2 - b << endl;
        }
    }
}



Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <complex>
#include <set>
#include <cassert>

using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}


double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

int main(){
  int N;
  while(cin >> N, N){
    vector<L>Ls;
    
    int cp = 0;
    int cnt = 0;
    set<pair<int, int> >S;
    for(int i=0;i<N;i++){
      int x1, y1, x2, y2;
      cin >>x1>>y1>>x2>>y2;
      P p1((double)x1, (double)y1), p2((double)x2,(double)y2);
      Ls.push_back(L(p1, p2));
    }
    for(int i=0;i<N;i++){
      vector<P>CPs;      
      for(int j=i+1;j<N;j++){
	if(!intersectSS(Ls[i], Ls[j])) continue;
	P p = crosspoint(Ls[i], Ls[j]);
	if(p == Ls[i][0] || p == Ls[i][1]) continue;
	if(p == Ls[j][0] || p == Ls[j][1]) continue;
	bool check =true;
	for(auto &cps: CPs){
	  if(abs(cps-p) < EPS) check = false;
	}
	if(check) CPs.push_back(p);
      }
      cp += CPs.size() + 1;
    }
    
    cout << cp + 1<< endl;;    
  }
  return 0;
}

Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999



template<class T>
class segtree{
private:
    vector<T> dat;
    int _size;  //the number of leaves
    T _init;
    
public:
    segtree(int __size=0 , T init=numeric_limits<T>::max() ):_size(__size) , _init(init) , dat(4*__size,init){
        if(__size==0)return ;
        int x=1;
        while(x<_size)x*=2;
        _size = x;
    }
    
    void update(int m,T x){
        int i = m+_size;
        dat[i].second = x.second;
        dat[i].first += x.first;
        while(i!=1){
            dat[i/2] = max(dat[i],dat[i^1]);
            i/=2;
        }
    }
    
    // call find(s,t)
    T find(int s,int t,int num=1,int a=0,int b=-1){
        if(b==-1)b=_size-1; //I couldn't "int b=_size".
        if(b<s||t<a)return _init;
        if(s<=a&&b<=t)return dat[num];
        return max( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );
    }
    int size(){return _size;}
};

int main(){
    int n,q;
    cin>>n>>q;
    segtree<pii> st(n,pii(0,0));     //100 datas
    rep(i,n){
        st.update(i,pii(0,-1*i));
    }
    rep(i,q){
        int a,v;
        cin>>a>>v;
        a--;
        st.update(a,pii(v,-1*a));
        cout<<-1*st.find(0,n).second+1<<" "<<st.find(0,n).first<<endl;
    }
    
}

Measured memory_bytes: 32260
#include<stdio.h>

int main() {
  int an[5],k;
  scanf("%d%d%d%d%d",&an[0],&an[1],&an[2],&an[3],&an[4]);
  scanf("%d",&k);

if(an[4]-an[0] <= k)printf("Yay!");
else printf(":(");

  return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int N;
string S[310];
string SS[310];

bool check(int A) {
    rep(i, N) {
        rep(j, N) {
            int ni = (i + A) % N;
            SS[ni][j] = S[i][j];
        }
    }

    rep(i, N) {
        rep(j, N) {
            if (SS[i][j] != SS[j][i]) return false;
        }
    }
    return true;
}

int main() {
    cin >> N;
    rep(i, N) {
        string s;
        cin >> s;
        S[i] = SS[i] = s;
    }
    int ans = 0;
    rep(A, N) {
        if (check(A)) ans += N;
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
N = int(input())
a = [int(i) for i in input().split()] 
b =[0]*(N+1)
for i in range(N):
    b[i+1]= b[i] + a[i]
b.sort()
j = 0
num = 0
v = 0
while j < N:
    if b[j+1] == b[j]:
        v = v+1
    else:
        num = num + (v*(v+1))//2
        v = 0
    j = j +1
num = num + (v*(v+1))//2
print(num)

Measured memory_bytes: 26136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if (a[n - 1] - a[0] > 1) {
        cout << "No" << '\n';
        return 0;
    }
    if (a[n - 1] == a[0]) {
        if (a[0] <= n / 2 || a[0] == n - 1) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }
        return 0;
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != a[0]) {
            x = n - i;
            break;
        }
    }
    if (n - x + 1 <= a[n - 1] && a[n - 1] <= n - x + x / 2) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

ll gcd(ll x, ll y) {
    if (x > y) swap(x, y);
    ll m = 1;
    while (m != 0) {
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

int main() {

//    ifstream cin("C:\\Users\\riku\\Downloads\\subtask01-03.txt");

    ll n, m;
    cin >> n >> m;

    string s, t;
    cin >> s >> t;

    ll l = lcm(n, m);

    map<ll, char> x;

    rep(i, n) x[l / n * i] = s[i];

    rep(i, m) x[l / m * i] = t[i];

    rep(i, n) if (x[l / n * i] != s[i]) {
            cout << -1 << endl;
            ret();
        }

    cout << l << endl;
}


Measured memory_bytes: 14068
#define _USE_MATH_DEFINES
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <nmmintrin.h>
#include <immintrin.h>
#include <mmintrin.h>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,P) scanf("%d %d %d %d",&n,&m,&o,&P)
#define SINT5(n,m,o,P,q) scanf("%d %d %d %d %d",&n,&m,&o,&P,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 1'010'000'000; // 0x3C33'6080
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second




int main() {
	ll a, b;
	cin >> a >> b;
	ll c = a + b;
	if (c % 2 == 1) {
		puts("IMPOSSIBLE");
	} else {
		cout << c / 2 << endl;
	}

}


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

using namespace std;
typedef long long ll;
const int N=1e3+10;

ll n, m, p, k, a[N], b[N], c[N];

struct Node{
	ll x, y, z;
	bool operator < (const Node& rhs) const {
		return a[x]+b[y]+c[z]<a[rhs.x]+b[rhs.y]+c[rhs.z];
	}
};


struct state{
	ll x, y, z;
	bool operator < (const state& rhs) const {
		if (x!=rhs.x) return x<rhs.x;
		else if (y!=rhs.y) return y<rhs.y;
		else return z<rhs.z;
	}
};

int main() {
	cin>>n>>m>>p>>k;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=m; i++) cin>>b[i];
	for(int i=1; i<=p; i++) cin>>c[i];
	sort(a+1, a+n+1);
	reverse(a+1, a+n+1);
	sort(b+1, b+m+1);
	reverse(b+1, b+m+1);
	sort(c+1, c+p+1);
	reverse(c+1, c+p+1);
	priority_queue<Node> Q;
	set<state> S;
	Q.push(Node{1, 1, 1});
	while(1) {
		Node u=Q.top();Q.pop();
		if (S.count(state{u.x, u.y, u.z})) continue;
		S.insert(state{u.x, u.y, u.z});	
		cout<<a[u.x]+b[u.y]+c[u.z]<<endl;
		if (S.size()==k) break;
		if (u.x!=n) Q.push(Node{u.x+1, u.y, u.z});	
		if (u.y!=m) Q.push(Node{u.x, u.y+1, u.z});	
		if (u.z!=p) Q.push(Node{u.x, u.y, u.z+1});	
	}

	return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	ls := make([]int, n*2)
	for i := 0; i < n*2; i++ {
		fmt.Scan(&ls[i])
	}
	sort.Ints(ls)

	ans := 0
	for i := 0; i < n*2; i += 2 {
		ans += ls[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{
   int xgyou,xretu;
   int yretu;
   static int x[101][101];
   static int y[101][101];
   int i,j;
   int k;
   long long sum;
   sum = 0;
   scanf("%d",&xgyou);
   scanf("%d",&xretu);
   for (i = 1; i <= xgyou; i++){
      for (j = 1; j <= xretu; j++){
         scanf("%d",&x[i][j]);
      }
   }

   for (i = 1; i <= xretu; i++){
      scanf("%d",&y[i][0]);

   }
   for (i = 1;i <= xgyou; i++){
      for (k = 1;k <= xretu; k++){
         sum += x[i][k]*y[k][0];
      }
      printf("%lld",sum);
      sum = 0;
      printf("\n");
   }


   return 0;
}

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

#define ll long long

using namespace std;

int main(){
    ll n,b,r;
    cin>>n>>b>>r;
    ll ans = n/(r+b)*b;
    ll val = n%(r+b);
    if(val>b)val=b;
    ans += val;
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#define rep(i,p) for(int i=0;i<p;i++)
#define pb push_back
using namespace std;
int N,W,temp1,temp2;
std::vector<int> v;
std::vector<int> w;
int dp[150][10100] = {0};
int main(){
  cin >> N >> W;

  v.pb(0);
  w.pb(0);

  rep(i,N) {
    cin >> temp1 >> temp2;
    v.pb(temp1); // ??????
    w.pb(temp2); // ??????
  }

  for (int i=1; i<=N; i++)
    for (int c=1; c<=W; c++) {
      temp1 = v.at(i);
      temp2 = w.at(i);
      if (c-temp2 < 0)
        dp[i][c] = dp[i-1][c];
      else
        dp[i][c] = max(temp1+dp[i-1][c-temp2],dp[i-1][c]);
    }
  // rep(i,N+1) {
  //   rep(c,W+1) cout << dp[i][c] << " ";
  //   cout << endl;
  // } 
  cout << dp[N][W] << endl;
  return 0;
}

Measured memory_bytes: 5272
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
 
int main(){
    int n;
    cin >> n;
    vector<int> s(n,0);
    int f=0;
    REP(i,n){
        int a;
        cin >> a;
        int a1 = (n-a-1)/2;
        s[a1]++;
        // cout << a1 << " " << s[a1] << endl;
    }

    llong ans = 1;
    REP(i,n/2){
        if(s[i]!=2){
            cout << 0 << endl;
            f=1;
            break;
        }
        ans = ans*2;
        if(ans > 1000000007){
            ans = ans - 1000000007;
        }
    }
    if(n%2==1 && f==0){
        if(s[n/2]!=1){
            cout << 0 << endl;
            f=1;
        }
    }

    if(f==0){
        cout << ans << endl;
    }

    return 0;
}

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

const int SIZE=(1<<20);
int p[200010], ans[200010], loc[200010];

struct RMQ{
	int data[SIZE*2];
	void update(int n, int x){
		n += SIZE-1;
		data[n]=x;
		while(n>0){
			n=(n-1)/2;
			data[n]=min(data[n*2+1], data[n*2+2]);
		}
	}
	int query(int a, int b, int k, int l, int r){
		if(b<=l || r<=a) return 1e9;
		if(a<=l && r<=b) return data[k];
		else return min(query(a, b, k*2+1, l, (l+r)/2), query(a, b, k*2+2, (l+r)/2, r));
	}
};

RMQ even, odd;

struct section{
	int L, R, mn;
	section(int inputtedL, int inputtedR){
		L=inputtedL, R=inputtedR;
		if(L%2==0) mn=even.query(L/2, R/2, 0, 0, SIZE);
		else mn=odd.query(L/2, R/2, 0, 0, SIZE);
	}
	bool operator<(const section a) const{
		return mn < a.mn;
	}
	bool operator>(const section a) const{
		return mn > a.mn;
	}
};

priority_queue<section, vector<section>, greater<section>> pq;

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i){
		cin >> p[i];
		loc[p[i]]=i;
	}
	for(int i=0; i*2<N; ++i){
		even.update(i, p[i*2]);
		odd.update(i, p[i*2+1]);
	}
	pq.push(section(0, N));
	for(int i=0; i*2<N; ++i){
		int ss=pq.top().mn, lt=pq.top().L, rt=pq.top().R;
		pq.pop();
		if(lt<loc[ss]){
			pq.push(section(lt, loc[ss]));
		}
		int tt;
		if(loc[ss]%2==0) tt=odd.query(loc[ss]/2, rt/2, 0, 0, SIZE);
		else tt=even.query(loc[ss]/2+1, rt/2+1, 0, 0, SIZE);
		if(loc[ss]+1<loc[tt]){
			pq.push(section(loc[ss]+1, loc[tt]));
		}
		if(loc[tt]<rt){
			pq.push(section(loc[tt]+1, rt));
		}
		ans[i*2]=ss, ans[i*2+1]=tt;
	}
	cout << ans[0];
	for(int i=1; i<N; ++i) cout << ' ' << ans[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 15604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;

int main() {
  int N,X;
  cin>>N>>X;
  
  vector<int> l(N);
  for(int i=0;i<N;++i){
    cin>>l[i];
  }
  
  int count=0;
  int sum=0;
  
  for(int i=0;i<N;++i){
    sum+=l[i];
    if(sum<=X)
      ++count;
  }
  
  cout<<count+1<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int pivot = partition(arr, 0, n-1);

        StringBuilder sb = new StringBuilder("");
        sb.append(arr[0]);
        for (int i = 1; i < n; i++) {
            sb.append(" ");
            if (i == pivot) {
                sb.append("[").append(arr[i]).append("]");
            } else {
                sb.append(arr[i]);
            }
        }
        System.out.println(sb);
    }

    public static int partition(int[] arr, int left, int right) {
        int x = arr[right];
        int i = left - 1;
        int temp;
        for (int j = left; j <= right - 1; j++) {
            if (arr[j] <= x) {
                i++;
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
        i++;
        temp = arr[i];
        arr[i] = arr[right];
        arr[right] = temp;
        return i;
    }
}

Measured memory_bytes: 67880
h,w = map(int,input().split())
grid = []
grid.append(["."]*(w+2))
for i in range(h):
    a = list(input())
    a.insert(0,".")
    a.append(".")
    grid.append(a)
grid.append(["."]*(w+2))
for i in range(1, h+1):
    for j in range(1, w+1):
        nei = [grid[i+1][j], grid[i-1][j], grid[i][j-1], grid[i][j+1]]
        if grid[i][j] == "#" and "#" not in nei:
            print("No")
            exit()
print("Yes")





Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
	double a, b;
	int x, y;
	double z;
	scanf("%lf %lf", &a, &b);
	x = a/b;
	y = (int) a % (int) b;
	z = a/b;
	printf("%d %d %.5lf\n", x, y, z);
	return 0;
}


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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=3e2+10, maxm=5e3+10, lg=31, mod=1e9+7, inf=1e18;

ll n,k,M,dp[maxn][maxn],ps[maxn][maxn],C[maxn][maxn];

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>k>>M;
	C[0][0]=1; for(int i=1;i<maxn;i++){
		C[i][0]=1; for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%M;
	}
	for(int i=0;i<=k;i++) dp[1][i]=1, ps[1][i]=k+1-i;
	for(int i=2;i<=n+1;i++)for(int j=k;j>=0;j--){
		for(int s=1;s<=i-1;s++) dp[i][j]+=ps[s][j+1]*dp[i-s][j]%M*C[i-2][s-1]%M, dp[i][j]%=M;
		ps[i][j]=(ps[i][j+1]+dp[i][j])%M;
		//cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
	}
	cout<<dp[n+1][0];
	
	return 0;
}





Measured memory_bytes: 5832
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int h,w;

int main(){
  int ans=0;
  cin >> h >> w;
  vvi a(h, vi(w));  // h * w の2次元配列
  vvi b(h, vi(w));  // h * w の2次元配列
  REP(i,h){
    REP(j,w){
      cin>>a[i][j];
    }
  }

  REP(i,h){
    REP(j,w){
      cin>>b[i][j];
      a[i][j]=abs(a[i][j]-b[i][j]);
    }
  }


  
  vector<vector<char>> c(w, vector<char>(6401,0));  // h * 6401 の2次元配列
  
  REP(i,h){
    REP(j,w){
      int t=a[i][j];
      vector<char> c2(6401,0);
      if (i+j==0)
        c2[a[0][0]]=1;
      
      if (j!=0){
        REP(k,6401){
          if (c[j-1][k]==1){
            c2[abs(k-t)]=1;
            if (k+t<6401)
              c2[k+t]=1;
          }
        }
      }

      if (i!=0){
        REP(k,6401){
          if (c[j][k]==1){
            c2[abs(k-t)]=1;
            if (k+t<6401)
              c2[k+t]=1;
          }
        }
      }

      REP(k,6401)
        c[j][k]=c2[k];
    }
  }










  REP(k,6401){
    if (c[w-1][k]==1){
      cout<<k<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 768
import bisect
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
c.sort()
answer = 0
for i in b:
	x = bisect.bisect_right(c,i)
	y = bisect.bisect_left(a,i)
	answer += (n-x)*y
print(answer)

Measured memory_bytes: 23232
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
const int M = 1000000007;
int n, m, k, ans;
int A[1002];
int main()
{
    cin >> n >> m >> k >> ans;
    int cnt = 0;
    while (n > 0 and k > 0)
    {
        if (cnt & 1)
        {
            n -= ans;
        }
        else k-=m;
        cnt++;
        //cout << n << "," << k << " ";
    }
    if (k <= 0) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3624
#include<stdio.h>
#define MAX 100
#define INFTY 100000000

int min[MAX+1][MAX+1];//i~jの行列の最小
int p[MAX+1];

int Min(int a,int b){
  return a<b?a:b;
}

void MatrixChain(int n){
  int l,r,cut,size;
 
  for(size=1;size<=n-1;size++){
    for(l=1;l<=n-size;l++){
      r=l+size;
      min[l][r]=INFTY;

      for(cut=l;cut<=r-1;cut++){
	min[l][r]=Min(min[l][r],min[l][cut]+min[cut+1][r]+p[l-1]*p[cut]*p[r]);//計算して、最少更新
      }
    }
  }
}

int main(){
  int n;
  int i;
  int waste;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
    if(i==n-1)scanf("%d",&p[i+1]);
    else  scanf("%d",&waste);//行をむだに　読み込む　
    //ほしいのはp0行　あとずっと列
  }

  for(i=0;i<=n;i++)min[i][i]=0;
  MatrixChain(n);
  printf("%d\n",min[1][n]);//1からnの最小

  return 0;
}



Measured memory_bytes: 2084
#include<stdio.h>
int main()
{
  int a,b,n[4] = {0},i;
  scanf("%d%d",&a,&b);
  n[a]++,n[b]++;
  for(i = 1; i <= 3; i++)
    if(!n[i]) printf("%d\n",i);
  return 0;
}

  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  vector<int> v(26, 0);
  rep(i, 0, s.size()) v[s[i] - 'a']++;
  rep(i, 0, 26) {
    if (v[i] % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int i;
	int j;
	int k;
	int N, M;
	int Nsum = 1;
	int	Msum = 0;
	int	sum = 0;
	int maxcost = 0;
	string s[200];
	string t[200];
	cin >> N ;
	for (i = 0; i < N; ++i) {
		cin >> s[i];
	}
	cin >> M;
	for (i = 0; i < M; ++i) {
		cin >> t[i];
	}
	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			if (i != j) {
				if (s[i] == s[j]) {
					++Nsum;//N[i]の重複カウント
				}
			}
		}

		for (k = 0; k < M; ++k) {
			if (s[i] == t[k]) {
				++Msum;//M[i]の重複カウント
			}
		}
		sum = Nsum - Msum;

		maxcost = max(sum, maxcost);
		Nsum = 1;
		Msum = 0;
		sum = 0;

	}

	cout << maxcost << endl;
}

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

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b){
  return a < b ? a : b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;

  scanf("%d %d", &n, &q);

  for(i = 1 ; i <= n ; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }

  return 0;
}



Measured memory_bytes: 11896
a,b,C=map(float,input().split())
import math
r=C*(math.pi)/180
S=1/2*a*b*(math.sin(r))
c=(a**2+b**2-2*a*b*(math.cos(r)))**(1/2)
L=a+b+c
h=b*(math.sin(r))
print(S)
print(L)
print(h)


Measured memory_bytes: 5696
def kannon()
  loop{
    n = gets.to_i
    if n == 0
      break
    end
    a = []
    a[1] = 1
    a[2] = 2
    a[3] = 4
    if n > 3
      for i in 4..n
        a[i] = a[i-1] + a[i-2] + a[i-3]
      end
    end
    if a[n]%3650 == 0
      puts a[n]/3650
    else
      puts a[n]/3650 + 1
    end
  }
end

kannon()

Measured memory_bytes: 8584
s = input()
a = ('01' * 10 ** 5)[:len(s)]
b = ('10' * 10 ** 5)[:len(s)]

n_a = 0
n_b = 0
for c, d in zip(s, a):
    n_a += 1 if c == d else 0

for c, d in zip(s, b):
    n_b += 1 if c == d else 0
print(min([n_a, n_b]))


Measured memory_bytes: 3504
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int kNumAlphabets = 26;

vi used;
vvi edge;
string res;

void dfs(int v, set<int> from){
    if(used[v]){
        if(from.find(v) != from.end()) res = "no";
        return;
    }

    used[v] = true;
    from.insert(v);

    rep(u, kNumAlphabets){
        if(edge[v][u]) dfs(u, from);
    }
}

int main(void){
    for(int n; cin >> n, n; cout << res << endl){
        res = "yes";
        edge = vvi(kNumAlphabets, vi(kNumAlphabets));

        string pre; cin >> pre;
        rep(i, n - 1){
            string cur; cin >> cur;

            bool same = true;
            rep(j, min(pre.size(), cur.size())){
                if(pre.at(j) != cur.at(j)){
                    edge[pre.at(j) - 'a'][cur.at(j) - 'a'] = true;
                    same = false;
                    break;
                }
            }
            if(same && cur.size() < pre.size()) res = "no";

            pre = cur;
        }

        rep(u, kNumAlphabets){
            used = vi(kNumAlphabets);
            dfs(u, set<int>());
        }
    }

	return 0;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 100000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

struct edge { int to; int cost; };
typedef pair<int,int> P; //first:cost second:vertex (if cost is double plz change)
vector<edge> tree[MAX];
/*
tree[v][i] : edge {vertex x, cost of path [v -> x] } ("i"th path of vertex v)
*/
int d[2][MAX]; //min cost of vertex:s to vertex:i

void dijkstra(int s,int x){
    priority_queue< P,vector<P>,greater<P> > que;
    fill(d[x],d[x]+MAX,INF); // d = {INF,INF,...,INF}
    d[x][s] = 0;
    que.push(P(d[x][s],s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[x][v] < p.first){continue;}
        for(int i = 0;i < tree[v].size();i++){
            edge e = tree[v][i];
            if(d[x][e.to] > d[x][v] + e.cost){
                d[x][e.to] = d[x][v] + e.cost;
                que.push(P(d[x][e.to],e.to));
                //cout << "Push" << sp << e.to << sp << d[e.to] << endl;
            }
        }
    }
}

int main(){
    int N,u,v;
    cin >> N >> u >> v;
    u--;
    v--;
    Rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        edge e = {b,1};
        tree[a].push_back(e);
        e = {a,1};
        tree[b].push_back(e);
    }
    int ans;
    dijkstra(u,0);
    dijkstra(v,1);
    //cout << d[1][u]%2 << endl;
    ans = d[1][u];
    ans -= 1;
    Rep(i,N){
        if(d[1][i] > d[0][i])ans = max(ans,d[1][i]- 1);
    }
    cout << ans;
    //cin >> N;
}

Measured memory_bytes: 8076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

long long dp[51][2501];

int n, a, x;

int main()
{
	read(n, a);
	dp[0][0]=1;
	for(int i=1; i<=n; ++i){
		read(x);
		for(int u=i-1; 0<=u; --u){
			for(int j=0, T=u*50; j<=T; ++j){
				dp[u+1][j+x] += dp[u][j];
			}
		}
	}
	ll ans=0;
	for(int i=1; i<=n; ++i){
		ans += dp[i][i*a];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 896
K, N = map(int, input().split())
A = list(map(int, input().split()))

D = [0]*N

for i in range(N-1):
  D[i] = A[i+1] - A[i]
D[N-1] = A[0] - A[N-1] + K
      
D.sort()
print(K - D[N-1])

Measured memory_bytes: 25836
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> place(r);
  for(int i=0; i<r; i++) cin >> place[i];
  sort(place.begin(), place.end());
  vector<vector<int>> dist(n+1, vector<int> (n+1,1e9));
  for(int i=0; i<m; i++){
    int a, b, c;
    cin >> a >> b >> c;
    dist[a][b] = c;
    dist[b][a] = c;
  }
  for(int k=1; k<n+1;k++){
    for(int i=1; i<n+1; i++){
      for(int j=1; j<n+1; j++){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int ans = 1e9;
  do{
    int cnt = 0;
    for(int i=0; i<r-1; i++) cnt += dist[place[i]][place[i+1]];
    ans = min(ans, cnt);
  }while(next_permutation(place.begin(), place.end()));
  cout << ans << endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    int ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=i-1;j>=0;j--){
            auto itr = lower_bound(a.begin(),a.end(),a.at(i)-a.at(j)+1);
            ans+=max((j-(itr-a.begin())), (long)0);
        }
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
result = list()

while True:
    data = list(input().split())
    if data[1] == "+":
        result.append(int(data[0]) + int(data[2]))
    elif data[1] == "-":
        result.append(int(data[0]) - int(data[2]))
    elif data[1] == "*":
        result.append(int(data[0]) * int(data[2]))
    elif data[1] == "/":
        result.append(int(data[0]) // int(data[2]))
    elif data[1] == "?":
        break
    else:
        continue

for i in range(len(result)):
    print(result[i])



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

int main() {
  string S;
  cin >> S;
  int direction[4] = {};
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'N')
      direction[0]++;
    if (S[i] == 'W')
      direction[1]++;
    if (S[i] == 'S')
      direction[2]++;
    if (S[i] == 'E')
      direction[3]++;
  }
  if ((direction[0] == 0 && direction[2] == 0 && direction[1] == 0 &&
       direction[3] == 0) ||
      (direction[0] == 0 && direction[2] == 0 && direction[1] >= 1 &&
       direction[3] >= 1) ||
      (direction[0] >= 1 && direction[2] >= 1 && direction[1] == 0 &&
       direction[3] == 0) ||
      (direction[0] >= 1 && direction[2] >= 1 && direction[1] >= 1 &&
       direction[3] >= 1))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,x=0;
    cin>>a>>b;
    for(int i=1;i<=a;i++){
        if(i==a){
            for(int j=1;j<=b;j++){
                if(i==j)
                    x++;
            }
        }
        else{
            for(int j=1;j<=31;j++){
                if(i==j)
                    x++;
            }
        }
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
X=list(map(int,input().split()))
import numpy as np
a=np.searchsorted(X, 0, side='left')
if a==N:
  X=np.insert(X,a,0)
  N+=1
  K+=1
elif X[a]!=0:
  X=np.insert(X,a,0)
  N+=1
  K+=1
ans=10**18
i=a-K+1 if K-1<a else 0
while i<=a and i+K-1<N:
  l=-X[i]
  r=X[i+K-1]
  if l>r:
    l,r=r,l
  ans=min(ans,2*l+r)
  i+=1
print(ans)

Measured memory_bytes: 17980
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ a, b, k ] <- readIntegers
	let
		a' = max 0 $ a - k
		k' = k - ( a - a' )
		b' = max 0 $ b - k'
	printf "%lld %lld\n" a' b'

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define ll long long
#define F(type, i, a, b) for(type i = a; i <= b; i ++)
#define RF(type, i, a, b) for(type i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cerr<<" ["<<#a<<"->"<<a<<"] "
#define next_line cerr<<'\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it ++)

using namespace std;

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

void solve()
{
    //If you cannot approach a problem
    //directly in the way it is proposed then try to think from backwards
    string s;
    cin>>s;
    int max_s = 0;
    F(int, i, 0, 2){
        int j = 0;
        while((i + j < 3) && (s[i + j] == 'R'))
            j ++;
        max_s = max(max_s, j);
    }
    cout<<max_s<<'\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        freopen("Debug.txt", "w", stderr);
    #else
    #endif
        solve();
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin>>N;
  int sum=0;
  
  for(int i=0;i<N;i++){
  int l,r;
    cin>>l>>r;
    sum+=r-l+1;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public Main(){
        Scanner SC = new Scanner(System.in);

        int N = SC.nextInt();
        String S = SC.next();

        int C = 0, R = 0;
        for(int i=0;i<N;i++){
            if(S.charAt(i) == 'A'){
                C = 1;
            } else if (C == 1 && S.charAt(i) == 'B'){
                C = 2;
            } else if (C == 2 && S.charAt(i) == 'C'){
                C = 0;
                R++;
            } else {
                C = 0;
            }
        }

        System.out.println(R);
    }
    public static void main(String[] args){
        Main m = new Main();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define INF 1e18
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N;
    cin >> N;
    vi d(N);
    REP(i, N) cin >> d.at(i);

    if (N%2 == 0) {
        sort(all(d));
        int half = N/2;
        print(d.at(half) - d.at(half-1));
    } else {
        print(0);
    }
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 640
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int r = scanner.nextInt();
			if ((n | r) == 0)
				break;
			int[] card = new int[n];
			for (int i = 1; i <= n; i++)
				card[n - i] = i;
			int[] tmp = new int[n];
			while (r-- > 0) {
				int p = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				for (int i = 0; i < p; i++)
					tmp[i] = card[i];
				for (int i = 0; i < c; i++)
					card[i] = card[i + p];
				for (int i = 0; i < p; i++)
					card[i + c] = tmp[i];
			}
			System.out.println(card[0]);
		}
	}
}

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

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

  map<string, int> res;
  int vmax = 1;
  rep(i,N) {
    string s;
    cin >> s;
    if (res.count(s)) {
      res[s]++;
      if (res[s]>vmax) {
        vmax = res[s];
      }
    }
    else {
      res[s] = 1;
    }

  }

  // Keyの値が小さい順にループ
  
  vector<string> ans;
  for (pair<string, int> p : res) {
    string key = p.first;
    int value = p.second;
    if (vmax == value) {
      ans.push_back(key);
    }
  }
  sort(ans.begin(),ans.end());
  rep(i,ans.size()) {
    cout << ans.at(i) << endl;
  }
  
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
 
#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
 
const int N = (int) 2e5 + 7;
const int INF = (int) 1e9 + 7;
 
int a[N];
int ans[N];
vector<int> g[N];
multiset<int> ms;
 
void dfs(int s, int p) {
	ms.insert(a[s]);
	multiset<int>::iterator it = ms.lower_bound(a[s]);
	int rem = -1;
	if (++it != ms.end()) {
		rem = *it;
		ms.erase(it);
	}
	ans[s] = ms.size();
 
	for (int i = 0; i < g[s].size(); ++i) {
		if (g[s][i] != p)
			dfs(g[s][i], s);
	}

	ms.erase(a[s]);
	if (rem != -1) {
		ms.insert(rem);
	}
 
}
 
 
int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
 
	int n;
	sf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		sf("%d", &a[i]);
	}
 
	for (int i = 0; i < n - 1; ++i) {
		int x, y;
		sf("%d %d", &x, &y);
		g[x].pp(y);
		g[y].pp(x);
	}
 
	dfs(1, 0);
 
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", ans[i]);
	}
 
	return 0;
}


Measured memory_bytes: 28328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef long long ll;

/*
   a[i] = a[0] + D * i


   S+T = totalSum
   S = totalSum - T


   (S-T) = (totalSum - T) - T = totalSum - 2*T

   so the question is: how many different sums T are there because
   each sum T maps to a unique value of (S-T)

   knapsack?

consider: a[1] + a[3] + a[4]
        = 3*a[0] + D*1 + D*3 + D*4
        = 3*a[0] + D*(1+3+4)

So if you choose 3 numbers, you can get all the numbers 3*a[0] + D*X
where X is in the range: [0+1+2, (n-3)+(n-2)+(n-1)] which is O(n^2) numbers

this is an interval of values.

group these intervals by (k*a[0])%D. Now intervals from different groups won't intersect

Perform sweepline on each bucket. Answer is sum of lengths of union of segments


*/

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,x,d;
    cin >> n >> x >> d;
    if(d == 0) {
        if(x != 0) {
            cout << n+1;
        } else {
            cout << 1;
        }
        return 0;
    }
    if(d < 0) {
        d = -d;
        x = -x;
    }
    map<int, vector<pair<int, int>>> buckets;
    int sum1 = 0;
    int sum2 = 0;
    bool seenZero = false;
    buckets[0].push_back({0,0});
    for(int len=1;len<=n;++len) {

        sum1 += len-1;
        sum2 += n-len;

        const int L = len*x + d*sum1;
        const int R = len*x + d*sum2;

        buckets[(L%d+d)%d].push_back({L,R});
    }
    int res = 0;
    for(auto &p : buckets) {
        sort(p.second.begin(), p.second.end());
        int startL = -1e18;
        int maxR = -1e18;
        for(auto &interval : p.second) {
            if(maxR < interval.first) {
                if(startL != (int)-1e18) {
                    res += (maxR - startL+d-1)/d+1;
                }
                startL = interval.first;
            }
            maxR = max(maxR, interval.second);
        }
        res += (maxR - startL+d-1)/d+1;
    }
    cout << res;
}


Measured memory_bytes: 22144
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();
        String t = sc.nextLine();

        int flag =0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i) != t.charAt(i)){
                flag =1;
                break;
            }
        }

        if(flag==1){
            System.out.println("No");
        }else if(flag==0 && (s.length()+1 == t.length())){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35684