akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vvi g;
vi color;
ll one=0,two=0;
void dfs(int i,int p,int c){
    color[i]=c;
    for(ll x:g[i])if(x!=p)dfs(x,i,3-c);
}
int main(){
    ll n;cin>>n;
    g=vvi(n);
    rep(i,n-1){
        ll a,b;cin>>a>>b;a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    color=vi(n);
    dfs(0,-1,1);
    rep(i,n){
        if(color[i]==1)one++;
        else two++;
    }
    bool s=false;
    if(one<two){
        s=true;
        swap(one,two);
    }
    if(s)rep(i,n)color[i]=3-color[i];
    vi v(3);
    v[0]=(n+2)/3;
    v[1]=(n+1)/3;
    v[2]=n/3;
    if(two<v[0]){
        vi ans(n);
        int t1=0,t2=0,t3=1;
        rep(i,n){
            if(color[i]==2){
                ans[i]=3*t3;
                t3++;
            }
            else{
                if(t1*3+1>n){
                    if(t2*3+2>n){
                        ans[i]=3*t3;
                        t3++;
                    }
                    else{
                        ans[i]=3*t2+2;
                        t2++;
                    }
                }
                else{
                    ans[i]=t1*3+1;
                    t1++;
                }
            }
        }
        outv(ans);
        return 0;
    }
    int t1=0,t2=0,t3=1;
    vi ans(n);
    rep(i,n){
        if(color[i]==1){
            if(t1*3+1>n){
                ans[i]=3*t3;
                t3++;
            }
            else{
                ans[i]=t1*3+1;
                t1++;
            }
        }
        else{
            if(t2*3+2>n){
                ans[i]=3*t3;
                t3++;
            }
            else{
                ans[i]=t2*3+2;
                t2++;
            }
        }
    }
    outv(ans);
}

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

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

struct edge {
	int to;
	edge(int _to) : to(_to) {};
	bool operator<(const edge& rhs) {
		return this->to < rhs.to;
	};
	bool operator>(const edge& rhs) {
		return this->to > rhs.to;
	}
	bool operator==(const edge& rhs) {
		return this->to == rhs.to;
	}
};
using node = vector<edge>;
using graph = vector<node>;

void dfs(graph& g, int node, int d, VI& dist, vector<bool>& visit) {
	visit[node] = true;
	dist[node] = d;
	for (auto e : g[node]) {
		if (!visit[e.to]) dfs(g, e.to, d + 1, dist, visit);
	}
}

int diameter(graph& g) {
	int n = g.size();
	VI dist(n);
	vector<bool> visit(n);
	dfs(g, 0, 0, dist, visit);
	int max_idx = 0;
	int max_dist = -1;
	REP(i, n) {
		if (dist[i] > max_dist) {
			max_dist = dist[i];
			max_idx = i;
		}
	}
	visit = vector<bool>(n, false);
	dfs(g, max_idx, 0, dist, visit);
	max_dist = -1;
	max_idx = 0;
	REP(i, n) {
		if (dist[i] > max_dist) {
			max_dist = dist[i];
			max_idx = i;
		}
	}
	return max_dist;
}


int main() {
	int n;
	scanf("%d", &n);
	graph g(n);
	REP(i, n-1) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--, y--;
		g[x].PB(y);
		g[y].PB(x);
	}
	int d = diameter(g);
	if (d % 3 == 1)cout << "Second" << endl;
	else cout << "First" << endl;
	return 0;
}



Measured memory_bytes: 24448
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin >> n;
	int a[110];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = -100;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (ans < abs(a[i] - a[j]))ans = abs(a[i] - a[j]);
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int n;cin>>n;
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];
    }
    int mi=p[0],ans=1;
    for(int i=1;i<n;i++){
        chmin(mi,p[i]);
        if(mi==p[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int ac = 0, wa = 0, tle = 0, re = 0;
	rep(i, n) {
		string s;
		cin >> s;
		if (s == "AC") ac++;
		else if (s == "WA") wa++;
		else if (s == "TLE") tle++;
		else re++;
	}
	cout << "AC x " << ac << "\n";
	cout << "WA x " << wa << "\n";
	cout << "TLE x " << tle << "\n";
	cout << "RE x " << re << "\n";
	return 0;
}


Measured memory_bytes: 3636
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1611&lang=jp
//ダルマ落とし
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
#if 0
ll solve(){
  ll n; cin>>n;
  if(n==0) return -1;
  vector<ll> wn(n);
  for(auto&& w:wn) cin>>w;

  auto dfs = [&](auto&& self,ll l, ll r)->ll{
    ll ret=0;
    if(l+1>=r) return ret;
    FOR(k,l,r-1){
      if(abs(wn.at(k)-wn.at(k+1))>=2)continue;
      chmax(ret, self(self,l,k)+self(self,k+2,r)+2);
    }
    return ret;
  };

  ll ans=dfs(dfs, 0,n);
  cout<<ans<<endl;
  return ans;
}
#endif
ll solve2(){
  ll n; cin>>n;
  if(n==0) return -1;
  vector<ll> wn(n);
  for(auto&& w:wn) cin>>w;

  vector<vector<ll>> dp(n,vector<ll>(n+1));
  FOR(len,1,n){
    FOR(l,0,n){
      ll r=l+len;
      if (r>=n)break;
      if(len-1 == dp[l+1][r-1]){
        if (abs(wn.at(l)-wn.at(r))<2){
          dp[l][r] = dp[l+1][r-1]+2;
        } 
      }
      dump("-",len,l,r);
      //kで区切る
      for(ll k=l;k<r;++k){
        chmax(dp[l][r],dp[l][k]+dp[k+1][r]);
        dump(l,k,k+1,r,dp[l][r]);
      }
    }
  }
  dump(dp);
  ll ans=dp[0][n-1];
  cout<<ans<<endl;
  return ans;
}
int main() {
#if LOCAL&01
  //std::ifstream in("./test/sample-1.in");
  std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  while(solve2() >= 0){
    //break;
  }
  return 0;
}


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

int main(){
    int N, L;
    cin >> N >> L;
    int aji_min_abs = 100000;
    int aji_min;
    for(int i=0; i<N; i++){
        int aji = L+i;
        if(abs(aji) <= aji_min_abs){
            aji_min_abs = abs(aji);
            aji_min = aji;
        }
    }
    cout << N*(L-1) + N*(N+1)/2 - aji_min;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100][100001];
int main()
{
  ll n,i,W,j;
  cin>>n>>W;
  ll w[n],v[n];
  for(i=0;i<n;i++)
   cin>>w[i]>>v[i];
  for(i=w[0];i<=W;i++)
   dp[0][i]=v[0];
  for(i=1;i<n;i++)
  {
      for(j=1;j<=W;j++)
      {
          dp[i][j]=dp[i-1][j];
          if(j-w[i]>=0 && dp[i-1][j-w[i]]+v[i]>dp[i][j])
            dp[i][j]=dp[i-1][j-w[i]]+v[i];
          if(dp[i][j-1]>dp[i][j])
           dp[i][j]=dp[i][j-1];
      }
  }
  cout<<dp[n-1][W];
  return 0;
}

Measured memory_bytes: 78336
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m, qu;
    cin >> n >> m >> qu;
    vi l(m), r(m);
    for (int i = 0; i < m; ++i) {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }
    vi p(qu), q(qu);
    for (int i = 0; i < qu; ++i) {
        cin >> p[i] >> q[i];
        p[i]--;
        q[i]--;
    }
    vvi cnt(n, vi(n, 0));
    for (int i = 0; i < m; ++i) {
        cnt[l[i]][r[i]]++;
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cnt[i][j] += cnt[i - 1][j];
        }
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cnt[j][i] += cnt[j][i - 1];
        }
    }
    for (int i = 0; i < qu; ++i) {
        cout << cnt[n - 1][q[i]] - (p[i] == 0 ? 0 : cnt[p[i] - 1][q[i]]) << "\n";
    }

    return 0;
}

Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main(){
int n,i,a[1000];
cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	for(i=n;i>=1;i--){
		if(i==n){
			cout<<a[i];
		}else{
			cout<<" "<<a[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define rep1(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (long long i = (long long)(n); i <= (long long)(m); 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 (a > b) { a = b; return 1; } return 0; }
// const long long mod = 1e9 + 7;

int main() {
    long long n, a, b;
    cin >> n; cin >> a; cin >> b;
    long long div = n / (a + b);
    long long mod = n % (a + b);
    cout << (div * a) + std::min(a, mod) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint()
{
	int x=0,p=1;char c;
	c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//
string s=".#";
int n,m;
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
string ans[200];
//
int main()
{
	scanf("%d%d",&n,&m);
	printf("100 100\n");
	rep(i,50)rep(j,100)ans[i].push_back(s[0]);
	for(int i=50;i<100;i++)rep(j,100)ans[i].push_back(s[1]);
	n--;m--;
	int p1=1,p2=-1;
	while (m>0)
	{
		p2+=2;
		if(p2>=100)
		{
			p2-=100;
			p1+=2;
		}
		ans[p1][p2]=s[1];
		m--;
	}
	p1=51,p2=-1;
	while (n>0)
	{
		p2+=2;
		if(p2>=100)
		{
			p2-=100;
			p1+=2;
		}
		ans[p1][p2]=s[0];
		n--;
	}
	rep(i,100)
	{
		cout<<ans[i]<<endl;
	}
	return 0;	
} 

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

void print(ll x[], ll n)
{
	for(int i = 0; i < n; i++)
		cout << x[i] << " ";
	cout << endl;
}
int x[100009], n, k;
int dp[100009];
ll cost(int i)
{
	if(i==n-1)
		return 0;
	if(i >= n)
		return 100000000000;
	if(dp[i] != -1)
		return dp[i];
	ll ans = 100000000000;
	for(int j = i+1; j < min(n, i+k+1); j++)
		ans = min(ans, abs(x[j]-x[i]) + cost(j));
	dp[i] = ans;
	return dp[i];
}

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

	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> x[i];
	memset(dp, -1, sizeof dp);
	cout << cost(0) << endl;

	return 0;
}

Measured memory_bytes: 5760
/*
SHERAJUL ARIFIN
Dept. of CSE,
IUT.
*/

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[3][3],b[10];
    int x[3][3]= {0};
    int flag=0;
    int i,j,k,n;
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            cin>>a[i][j];
        }
    }

    cin>>n;
    for(i=0; i<n; i++)
        cin>>b[i];
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            for(k = 0; k < n; k++)
            {
                if(a[i][j] == b[k])
                    x[i][j] = 1;
            }
        }
    }
    for(i=0; i<3; i++)
    {
        if(x[i][0] && x[i][1] && x[i][2])
            flag=1;
    }
    for(i=0; i<3; i++)
    {
        if(x[0][i] && x[1][i] && x[2][i])
            flag=1;
    }
    if(x[0][0] && x[1][1] && x[2][2])
        flag=1;
    else if(x[0][2] && x[1][1] && x[2][0])
        flag=1;
    if(flag==1)
        cout<<"Yes";
    else if(flag==0)
        cout<<"No";
    return 0;
}



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

using namespace std;

int main() {

    int N, K; cin >> N >> K;

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

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

    int ans = 1e9;
    for (int i = 0; i < N-K+1 ; ++i) {
        ans = min(ans, h[i+K-1] - h[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<string>
#include<set>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;

int main(){//A
/*
    int l,r,d;
    cin>>l>>r>>d;
    int c=0;
    rep(i,l,r+1){
        if(i%d==0) c++;
    }
    cout<<c<<endl;
    */
   //B
   /*
    int n;
    cin>>n;
    int c=0;
    vector<int> a(n);
    rep(i,0,n){
        cin>>a[i];
        if(i%2==0&&a[i]%2!=0) c++;
    }
    cout<<c<<endl;
    */
   //C
   int n;
   cin>>n;
   map<int, int> f;
   rep(x,1,sqrt(n)){
       rep(y,1,sqrt(n)){
           rep(z,1,sqrt(n)){
               int fn=x*x+y*y+z*z+x*y+y*z+z*x;//同じになった数のみに着目してその回数を加算できる
               f[fn]++;//出力の際に使わないfnも存在し得る
           }
       }
   }
   rep(i,0,n){
       cout<<f[i+1]<<endl;
   }
  //D
  /*
  int n;
  cin>>n;
  rep(i,0,n){

  }
  */
}

Measured memory_bytes: 5412
import java.util.*; 
 
class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
		String k=sc.next();
        String l=sc.next();
		String[] a=k.split("");
  		String[] b=l.split("");
  		int co=0;
  
		for(int c=0;c<k.length();c++){
    		if(!a[c].equals(b[c])){
             co=1;
              break;
            }
    	}
    
 	if(co==1){
    		System.out.println("No");
    	}else{
     		System.out.println("Yes");
   	 }
 
    	System.out.println();
    }
}

Measured memory_bytes: 35520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int mod =1000000007;
const int INF = 1e18;
#define rep(i,a,n) for(int i=a;i<n;i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double n;
    cin>>n;
    for(int i=(int)(n*0.9);i<=n;i++){
        if(i*27/25==n){cout<<i;return 0;}
    }
    cout<<":(";
}

Measured memory_bytes: 256
n = int(input())
ab = 0
a = 0
b = 0
ba = 0
for i in range(n):
    s = input()
    ab = ab + s.count('AB')
    start_b = s[:1] == 'B'
    end_a = s[-1:] == 'A'
    if start_b:
        b = b + 1
    if end_a:
        a = a + 1
    if start_b and end_a:
        ba = ba + 1

b = b - ba
a = a - ba

ans = ab #ABが普通に含まれた数
if ba > 0:
    ba_joind = ba - 1 #B*Aを連結して生じるAB
    if b > 0:
        b = b - 1
        ba_joind = ba_joind + 1
    if a > 0:
        a = a - 1
        ba_joind = ba_joind + 1
    ans = ans + ba_joind
if b > 0 and a > 0:
    ans = ans + min(a, b)
print(ans)

Measured memory_bytes: 3064
S=input()
T=input()
st=S
c=""
buf=""
flag=0
for i in range(len(S)):
    buf=st[:len(st)-1]
    c=st[len(st)-1]
    st="".join((c,buf))
    if (st==T):
        flag=1
        break

if flag==0:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 38256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int N,M,Q;
vector<int> gen;
vector<P> li;
vector<P> pt;

int main() {
  cin >> N >> M >> Q;
  M--;
  gen.resize(N+M);
  li.resize(Q);
  pt.resize(Q);
  rep(i,N) {
    gen[i+M] = 1;
  }
  rep(i,Q) {
    cin >> li[i].first >> li[i].second >> pt[i].first >> pt[i].second;
    li[i].first--;
    li[i].second--;
  }
  int ans = 0;
  do{
    int A[N];
    int cnt = 1;
    int idx = 0;
    rep(i,N+M) {
      if(gen[i] == 0)cnt++;
      if(gen[i] == 1) {
	A[idx] = cnt;
	idx++;
      }
    }
    int tmp = 0;

    rep(i,Q) {
      int a = li[i].first;
      int b = li[i].second;
      int c = pt[i].first;
      int d = pt[i].second;
      if(A[b]-A[a] == c) tmp += d;
    }
    ans = max(tmp,ans);

    
  }while(next_permutation(all(gen)));
 
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra
    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl A(n);
        vl B(n);
        rep(i,n)cin>>A[i]>>B[i];
        sort(all(A));
        sort(all(B));
        if(n%2==0){
            ll x=A[n/2-1]+A[n/2];
            ll y=B[n/2]+B[n/2-1];
            cout<<abs(x-y)+1<<endl;
        }else{
            ll x=A[n/2];
            ll y=B[n/2];
            cout<<abs(y-x)+1<<endl;
        }
    }

Measured memory_bytes: 6360
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

using LL = long long;

LL n, c;
LL w[123], v[123];
LL memo[123][123][345];
const LL INF = -12345678901234567;
LL dp(int i, int j, int d)
{
	if (j < 0 || d < 0)return INF;
	if (i == 0)
	{
		if (j != 0 || d != 0)return INF;
		return 0;
	}
	if (~memo[i][j][d])return memo[i][j][d];
	LL ans = dp(i - 1, j - 1, d - w[i - 1]) + v[i - 1];
	ans = max(ans, dp(i - 1, j, d));
	return memo[i][j][d] = ans;
}

LL w0;
int main(void)
{
	memset(memo, 0xff, sizeof(memo));
	cin >> n >> c;
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i] >> v[i];
		if (i == 0)w0 = w[0];
		w[i] -= w0;
	}
	LL ans = 0;
	for (LL j = 0; j <= n; ++j)
	{
		for (LL d = 0; d <= 3 * n; ++d)
		{
			if (w0 * j + d <= c)
			{
				LL can = dp(n, j, d);
				ans = max(ans, can);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 41088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n, l;
    string s;
    vector<string> vec;

    cin >> n >> l;
    for (int i=0; i<n; i++) {
        cin >> s;
        vec.push_back(s);
    }

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

    for (int i=0; i<n; i++) {
        cout << vec[i];
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
main = do 
 n <- (read::String->Double) <$> getLine
 k <- (read::String->Double) <$> getLine
 xx <- map (read::String->Double) .words <$> getLine
 let ikichi = k / 2 
 print .sum .map (\x->ceiling $ 2*(ikichi-abs (x-ikichi))) $ xx

 {-
 let diff = abs(x - ikichi)
 let dist = ikichi - diff
 -}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	VLL A(N);
	for (LL n = 0; n < N; n++)cin >> A[n];
	map<LL, LL> ind;
	for (LL n = 0; n < N; n++) {
		auto itr = ind.find(A[n] - (n + 1));
		if (itr == ind.end()) {
			ind.insert(PLL(A[n] - (n + 1), 1));
		}
		else {
			itr->second++;
		}
	}
	map<LL, LL> ind2;
	for (LL n = 0; n < N; n++) {
		auto itr = ind2.find(A[n] + (n + 1));
		if (itr == ind2.end()) {
			ind2.insert(PLL(A[n] + (n + 1), 1));
		}
		else {
			itr->second++;
		}
	}
	LL ans = 0;
	for (PLL i1 : ind) {
		auto itr = ind2.find(-i1.first);
		if (itr == ind2.end())continue;
		ans += i1.second * itr->second;
	}
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 27516
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
int A,B,C,D;
char s[14];
int LiangJiaJun(){
    scanf("%s",s+1);
    A=s[1]-'0';
    B=s[2]-'0';
    C=s[3]-'0';
    D=s[4]-'0';
    for(int j=-1;j<=1;j+=2)
    for(int k=-1;k<=1;k+=2)
    for(int l=-1;l<=1;l+=2){
        if(A+j*B+k*C+l*D==7){
            cout<<A;
            if(j==-1)cout<<"-";else cout<<"+";
            cout<<B;
            if(k==-1)cout<<"-";else cout<<"+";
            cout<<C;
            if(l==-1)cout<<"-";else cout<<"+";
            cout<<D<<"="<<7<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np


TEST_INPUT = [
    """
    4 3
    3 3 -4 -2
    """,
    """
    10 40
    5 4 3 2 -1 0 0 0 0 0
    """,
    """
    30 413
    -170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
    """
]
ANSWER = [
    "-6",
    "6",
    "448283280358331064"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def query(a, n, a_arr_p, a_arr_n, n_zeros, k):

    # return (num of pairs <= a) < k

    if a >= 0:
        # negative
        res = len(a_arr_p) * len(a_arr_n)
        # zero
        res += n_zeros * (n - n_zeros) + n_zeros * (n_zeros - 1) // 2
        # p * p
        res_pp = np.searchsorted(a_arr_p, a // a_arr_p, side="right").sum()
        res_pp -= (a_arr_p * a_arr_p <= a).sum()
        res += res_pp // 2
        # n * n
        res_nn = np.searchsorted(a_arr_n, a // a_arr_n, side="right").sum()
        res_nn -= (a_arr_n * a_arr_n <= a).sum()
        res += res_nn // 2
    else:
        # p * n
        res = len(a_arr_p) * len(a_arr_n) - np.searchsorted(a_arr_n, (a_arr_p - a - 1) // a_arr_p, side="left").sum()
    # print(a, res)
    if res >= k:
        return True
    else:
        return False


def solve(n, k, a_list):

    left = - 10 ** 18 - 1
    right = 10 ** 18 + 1
    center = 0

    a_arr = np.array(a_list)

    a_arr_p = a_arr[a_arr > 0]
    a_arr_n = - a_arr[a_arr < 0]
    n_zeros = (a_arr == 0).sum()
    a_arr_p.sort()
    a_arr_n.sort()

    while left<right:
        center=(left+right)//2
        if query(center, n, a_arr_p, a_arr_n, n_zeros, k):
            right=center
        else:
            left=center+1

    return right


def input_and_solve(ih):
    n, k = map(int, ih.input().split())
    a_list = list(map(int, ih.input().split()))
    res = solve(n, k, a_list)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        # print(res, ans)
        assert str(res) == str(ans)


if __name__ == "__main__":
    #test()
    main()


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

int main(){
  string S;
  cin>>S;
  int N=S.length();
  int i=0;
  int count=0;
  int maxc=0;
  while(i<N){
    if((S[i]=='A')||(S[i]=='T')||(S[i]=='G')||(S[i]=='C')){
      count++;
      maxc=max(maxc,count);
      i++;
    }
    else {
      count=0;
      i++;
    }
  }
  cout<<maxc<<endl;
  

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable

object Main {
  def solve(sc: => Scanner, N: Int): Unit = {
    if (N != 0) {
      val stack1 = mutable.Stack[Char]()
      val stack2 = mutable.Stack[Char]()
      var f: Boolean = false
      sc.next.foreach(c =>
        c match {
          case '<' => {
            if (!f) stack2.push(stack1.pop())
            f = true
          }
          case '>' => {
            if (f) stack1.push(stack2.pop())
            f = false
          }
          case '-' =>
          case x =>
            if (f) {
              if (stack1.size == 0) {
                stack2.push(x)
              } else {
                stack2.push(stack1.pop())
              }
            } else {
              if (stack2.size == 0) {
                stack1.push(x)
              } else {
                stack1.push(stack2.pop())
              }
            }
        }
      )
      while (stack1.size != 0) stack2.push(stack1.pop())
      println(stack2.toList.mkString(""))
      solve(sc, N - 1)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc, sc.nextInt)
  }
}

Measured memory_bytes: 50192
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;


signed main() {
	ios::sync_with_stdio(false);
	static const int MMAX = 20;
	static const int NMAX = 50000;
	static const int INFTY = (1<<29);
	
	int n, m;
	cin >> n >> m;
	int C[21];
	int T[NMAX + 1];
	for (int i = 1; i <= m; i++) cin >> C[i];
	rep(i, NMAX) T[i] = INFTY;
	T[0] = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j + C[i] <= n; j++) {
			T[j + C[i]] = min(T[j + C[i]], T[j] + 1);
		}
	}

	cout << T[n] << endl;
	return 0;
}




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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

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

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

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


Measured memory_bytes: 256
L,R = list(map(int, input().split()))
if R - L >= 2019:
  print(0)
else:
  M=2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      K=i * j % 2019
      if K < M:
        M = K
  print(M)

Measured memory_bytes: 3060
#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<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int main() {
    int n;
    cin >> n;
    int x = 0;
    FOR(i,1,n) x += (i % 2);
    printf("%.15f\n", (double)x / n);

    return 0;
}


Measured memory_bytes: 256
import math

A, B = map(int, input().split())

min_A = math.ceil(A * 100 / 8)
max_A = (A + 1) * 100 / 8
min_B = math.ceil(B * 100 / 10)
max_B = (B + 1) * 100 / 10

if (min_A <= min_B and min_B < max_A):
    ans = min_B
elif (min_B <= min_A and min_A < max_B):
    ans = min_A
else:
    ans = -1

print(ans)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] a = new int[N];
        for(int i = 0; i < N; i++)
        {
            a[i] = int.Parse(Console.ReadLine()) - 1;
        }
        int current = 0;
        for (int i = 1; i <= N; i++)
        {
            if(a[current] == 1)
            {
                Console.WriteLine(i);
                return;
            }
            else
            {
                current = a[current];
            }
        }
        Console.WriteLine(-1);
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

bool BatchCheck(string s){
	bool isBatch = true;
	int n = (int)s.size();
	for (int i = 0; i < n; ++i)
	{
		if(s[i]!=s[n-i-1]) isBatch = false;
	}
	return isBatch;
}

int main() {
	
	int a,b; cin >> a >> b;
	int ans = 0;
	for (int i = a; i < b+1; ++i)
	{
		
		if(BatchCheck( to_string(i) ) ) ans++;
	}

	cout << ans << endl;

}


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

using namespace std;

vector<int> eratosu(1000100, 1);

int solve(long N, int P) {
    vector<long> keep;
    int k;
    vector<int> sosu;
    int count = 0;
    for (int i = N + 1; count < P; i++) {
        if (eratosu[i] == 1) {
            sosu.push_back(i);
            count++;
        }
    }
    for (int i = 0; i < P; i++) {
        for (long j = i; j < P; j++) {
            long a = (sosu[i] + sosu[j]);
            keep.push_back(a);
        }
    }

    // for (int i : keep) cout << i << " ";
    // cout << endl;

    sort(keep.begin(), keep.end());
    // cout << keep.size();
    return keep[P - 1];
    return 0;
}

int main(void) {
    int N, P;
    vector<int> ans;
    eratosu[0] = 0;
    eratosu[1] = 0;
    for (int i = 2; i * i < eratosu.size(); i++) {
        if (eratosu[i] == 1) {
            for (int j = 2 * i; j < eratosu.size(); j += i) {
                eratosu[j] = 0;
            }
        }
    }

    // for (int i : sosu) cout << i << " ";
    while (1) {
        cin >> N >> P;
        if (N == -1 && P == -1) break;
        ans.push_back(solve(N, P));
    }
    for (int i : ans) cout << i << endl;
    return 0;
}


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


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

  int div2=0;
  while(N>1){
    div2 += 1;
    N /= 2;
  }
  long long int ans = pow(2, div2+1) -1;
  cout << ans << endl;

}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var N, M int
	fmt.Scanf("%d %d\n", &N, &M)
	r := make([]int, N)
	for i := 0; i < N; i ++ {
		if i == 0 && N > 1 {
			r[0] = 1
		} else {
			r[i] = 0
		}
	}
	var re string
	cache := map[int]int{}
	for i := 0; i < M; i ++ {
		var j, n int
		fmt.Scanf("%d %d\n", &j, &n)
		if N > 1 && j == 1 && n == 0 {
			re = "-1"
			break
		}
		if num, exists := cache[j]; exists && num != n {
			re = "-1"
			break
		}
		r[j-1] = n
		cache[j] = n
	}
	if re != "-1" {
		for _, n := range r {
			re += fmt.Sprint(n)
		}
	}
	fmt.Println(re)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;ll k;
	cin >> n >> k;
	vector<ll> pos,neg;
	rep(i,0,n){
		int x;
		cin >> x;
		if(x >= 0)pos.push_back(x);
		else neg.push_back(x);
	}
	sort(all(pos));
	sort(neg.rbegin(), neg.rend());
	ll l = LLONG_MIN/2, r = LLONG_MAX/2;
	ll ans = -1;
	while(l <= r){
		ll cnt = 0;
		ll m = l + (r-l)/2;
		if(m >= 0){
			int ptr = pos.size() - 1;	
			rep(i,0,pos.size()){
				while(ptr >= 0 && pos[ptr] * pos[i] > m)--ptr;
				cnt += max(ptr-i, 0);
			}
			ptr = neg.size() - 1;	
			rep(i,0,neg.size()){
				while(ptr >= 0 && neg[ptr] * neg[i] > m)--ptr;
				cnt += max(ptr-i, 0);
			}
		}
		int ptr = 0;	
		for(int i = neg.size() - 1;i >= 0; --i){
			while(ptr < pos.size() && pos[ptr] * neg[i] > m)++ptr;
			cnt += pos.size() - ptr;
		}
		if(cnt >= k){
			ans = m;
			r = m - 1;
		}
		else{
			l = m + 1;	
		}
	}
	cout << ans << '\n';
}


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

int dp[100005];
vector<int>adj[100005];

bool visited[100005];

void visit(int vertex)
{
    dp[vertex] = 0;
    visited[vertex] = 1;
    for(int child: adj[vertex])
    {
        if(!visited[child]){
            visit(child);
        }
        dp[vertex] = max(dp[vertex], 1 + dp[child]);
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i = 0; i < m; i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
    }

    for(int i = 1; i <= n; i++)
    {
        if(!visited[i])
        {
            visit(i);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ans = max(ans,dp[i]);
    }
    cout<<ans<<endl;

}


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

typedef long long ll;
ll MOD = 1e9+7;
pair<ll,ll> ab[100000];
int main()
{
	int n;
	ll m;
	cin>>n>>m;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ll a;
		ll b;
		cin>>a>>b;
		ab[i]=make_pair(a,b);
	}
	sort(ab,ab+n);
	ll now=0;
	int i=0;
	while(now<m)
	{
		now+=ab[i].second;
		ans+=ab[i].second*ab[i].first;
		if(now>m)
		{
			ans-=ab[i].first*(now-m);
		}
		i++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repv(i,a,b) for(ll i=b-1;i>=a;i--)
#define MAXN 300005
#define endl "\n"

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;}

ll l,r,minn=LONG_LONG_MAX;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>l>>r;
    if(l<2019 && r<2019)
    {
        ll minn=LONG_LONG_MAX;
        for(ll i=l;i<r;i++)
        {
            for(ll j=i+1;j<=r;j++)
            {
                ll p=(i*j)%2019;
                minn=min(minn,p);
            }
        }
        cout<<minn<<endl;
    }
    else if(l<=2019 && r>=2019) cout<<0<<endl;
    else if(l>2019 && r>2019)
    {
        ll p=r%2019;
        if(r-l>=p) cout<<0<<endl;
        else
        {
            ll minn=LONG_LONG_MAX;
            for(ll i=l;i<r;i++)
            {
                for(ll j=i+1;j<=r;j++)
                {
                    ll p=(i*j)%2019;
                    minn=min(minn,p);
                }
            }
            cout<<minn<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K;
    cin >> N >> K;

    int num = 1;

    for (int i = 0; i < N; i++) {
        if (num <= K) {
            num *= 2;
        }
        else {
            num += K;
        }
    }

    cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
vector<int> S[MAX],dis(MAX);
ll N;

void BFS(){
    queue<int> Q;
    dis[0]=0;
    Q.push(0);
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(dis[b]!=-1) continue;
            dis[b]=dis[a]+1;
            Q.push(b);
        }
    }
}


int main(){
    int M;cin>>N>>M;
    vector<pair<int,int>> T(M);
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
        T[i]=make_pair(a,b);
    }
    for(int i=0;i<N;i++){
        dis[i]=-1;
    }

    BFS();

    bool flag=true;

    for(int i=0;i<M;i++){
        int a=T[i].first;
        int b=T[i].second;
        if((dis[a]-dis[b])%2==0) flag=false;
    }

    if(flag){
        ll red=0,blue=0;
        for(int i=0;i<N;i++){
            if(dis[i]%2) red++;
            else blue++;
        }
        cout<<red*blue-M<<endl;
    }else{
        cout<<N*(N-1)/2-M<<endl;
    }


}

Measured memory_bytes: 7040
//code by lynmisakura.wish to be accepted!
/*************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

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

int main(void) {
	string s;cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		if(s[i] == 'U' or s[i] == 'D')continue;
		else if (s[i] == 'R' and i % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
		else if (s[i] == 'L' and i % 2 == 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

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

  int ans_sugar = 0, ans_water = 100*a;
  double density = 0.0;
  for (int i = 0; i <= 30; i++) {
    for (int j = 0; j <= 30; j++) {
      if (i == 0 && j == 0) continue;
      for (int k = 0; k <= 100; k++) {
        for (int m = 0; m <= 100; m++) {
          int water = 100*a*i + 100*b*j;
          int sugar = c*k + d*m;
          if (water + sugar <= f && sugar <= (a*i + b*j)*e) {
            double tmp_density = (double)sugar / (water + sugar);
            if (density < tmp_density) {
              density = tmp_density;
              ans_sugar = sugar;
              ans_water = water;
            }
          }
        }
      }
    }
  }

  cout << ans_water + ans_sugar << ' ' << ans_sugar << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(){
	char a[4];
	scanf("%s",a);
	if(strcmp(a,"SUN")==0)
		printf("7\n");
	else if(strcmp(a,"MON")==0)
		printf("6\n");
	else if(strcmp(a,"TUE")==0)
		printf("5\n");
	else if(strcmp(a,"WED")==0)
		printf("4\n");
	else if(strcmp(a,"THU")==0)
		printf("3\n");
	else if(strcmp(a,"FRI")==0)
		printf("2\n");
	else if(strcmp(a,"SAT")==0)
		printf("1\n");
	return 0;
}

Measured memory_bytes: 128