akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
p = list(map(int, input().split()))

for i, j in enumerate(p):
    p[i] = (j*(j+1)/2) / j 
t_sum = sum(p[:k])
ans = t_sum
for i in range(n-k):
    t_sum = t_sum - p[i] + p[i+k]
    if ans < t_sum:
        ans = t_sum
print(ans)

Measured memory_bytes: 32232
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	string S;
	cin >> N >> S;
	int maxCount = 0;
	for (int i = 0; i < N; ++i)
	{
		bool exist[26];
		bool exist2[26];
        for(int j = 0; j < 26; j++){
            exist[j] = false; exist2[j] = false;
        }
		for (int j = 0; j < i; ++j)
		{
			exist[(int)(S[j] - 'a')] = true;
		}
		for (int j = i; j < N; ++j)
		{
			exist2[(int)(S[j] - 'a')] = true;
		}
		int count = 0;
		for (int j = 0; j < 26; ++j)
		{
			if(exist[j] && exist2[j])count++;
		}
		if(count > maxCount){
			maxCount = count;
		}
	}
	cout << maxCount << endl;
}

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

int main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) cin>>c[i][j];
    }
    vector<int> x(3),y(3);
    x[0]=0;
    y[0]=c[0][0];
    for(int i=1;i<3;i++){
        x[i]=c[0][i]-y[0];
        y[i]=c[i][0];
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(x[j]+y[i]!=c[i][j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int n, m = 0;
string s;
bool f[1000], g[1000];

int main()
{
	memset(f, 0, sizeof(f));
	memset(g, 0, sizeof(g));

	cin >> n >> s;

	int a = (s[0] - '0') * 100 + (s[1] - '0') * 10 + s[2] - '0';
	f[a] = 1;
	
	for (int i = 3; i < n; i++) {
		int a = s[i] - '0';

		for(int j = 0; j < 1000; j++)
			if (f[j]) {
				g[j] = 1;
				g[j - (j % 10) + a] = 1;
				g[j - (j % 100) + (j % 10) * 10 + a] = 1;
				g[(j % 100) * 10 + a] = 1;
			}

		memcpy(f, g, sizeof(g));
	}

	for (int i = 0; i < 1000; i++)
		if (g[i])
			m++;

	cout << m << endl;

	return 0;
}

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

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

using namespace std;

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

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

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

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

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int n, a , b;
    cin >> n >> a >> b;
    int ans = 0;
    FOR(i,0,n+1) {
        int sum = 0;
        int x = i;
        while (x > 0) {
            sum += x%10;
            x = x/10;
        }
        if (sum >= a && sum <= b)
            ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#include<string.h>
#define inf 9000000000000000000
#define maxn 200006
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
#define endl '\n'
#define mapint_iterator map<int,int> :: iterator
#define mapll_iterator map<ll,ll> :: iterator
#define setint_iterator set<int> :: iterator
#define setll_iterator set<ll> :: iterator
#define setpint_iterator set<pint> :: iterator
#define setpll_iterator set<pll> :: iterator
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<endl
#define cout2(a,b) cout<<a<<' '<<b<<endl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<endl
typedef priority_queue<ll,vector<ll>,greater<ll> > pqset;
typedef priority_queue<pint,vector<pint>,greater<pint> > pqset_ll;
#define pb push_back
#define fi first
#define se second
#include<ext/pb_ds/assoc_container.hpp>
ll dxk[]={0,0,1,-1,1,1,-1,-1};
ll dyk[]={1,-1,0,0,1,-1,1,-1};
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> os_pair;
#define acc (ios::sync_with_stdio(false),cin.tie(0))
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>0;i--)
#define repeat(i,start,n) for(ll i=start;i<n;i++)
#define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
//ifstream cin("b_read_on.txt"); ofstream cout("output3.txt");
//Chronology: Binary Search,Greedy,dp,dfs and similar
//Use (<<) for multiplication
//Use (>>) for division
// In dp, first try top-down,then bottom-up
//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(10);
// find_by_order -> value at index
// order_of_key -> index of value
void solve(int countu){
	int n;
	cin>>n;
	ll a[n+1]={0};
	rep(i,n-1){
		int b;
		cin>>b;
		a[b]++;
	}
	repeat(i,1,n+1)
		cout1(a[i]);
}
int main(){
    int t=1;
	//scanf("%d",&t);
	int countu=1;
    while(t--){
    	solve(countu);
    	countu++;
    }
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, K; cin >> N >> K;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll ans = 0;
	for (int i = 0; i < K; i++) {
		ans += a[i];
	}
	cout << ans << endl;
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int num = 100 * r + 10 * g + b;
  if (num % 4 == 0) {
    cout << "YES";
  }else {
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 1000000007ll;

LL m_pow(LL a,LL n)
{
    if(n == 0)return 1;
    LL half = m_pow(a,n/2);
    half *= half;
    half %= MOD;
    return (half * (n % 2 ? a : 1)) % MOD;
}
vector<LL>fact;
LL comb(LL n,LL r)
{
    LL shi = fact[n];
    LL bo1 = m_pow(fact[r],MOD - 2);
    LL bo2 = m_pow(fact[n - r],MOD - 2);
    shi *= bo1;
    shi %= MOD;
    shi *= bo2;
    shi %= MOD;
    return shi;
}

int main()
{
    fact.push_back(1);
    for(int i = 1;i < 5e6;++i)fact.push_back(fact.back() * i % MOD);
    int N,M,K;
    cin >> N >> M >> K;
    LL val = 1;
    LL ans = 0;
    for(int P = N;P <= N + M + K;++P)
    {
        int down = P-N-K;
        int up = M;
        if(P != N)val *= 2;
        val %= MOD;
        if(down > 0)
        {
            val -= comb(P-N-1,down-1);
            val += MOD;
            val %= MOD;
        }
        if(P-N > up)
        {
            val -= comb(P-N-1,up);
            val += MOD;
            val %= MOD;
        }
        LL plus = val;
        plus *= m_pow(3,N+M+K-P);
        plus %= MOD;
        plus *= comb(P-1,N-1);
        plus %= MOD;
        ans += plus;
        ans %= MOD;
        cerr << plus << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 67936
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<ll> a(n);
  REP(i,n) cin>>a[i];

  sort(ALL(a),greater<ll>());
  ll b=0,c=0;
  REP(i,n){
    if(i==0) continue;
    if(a[i-1]==a[i]){
      if(b==0) b=a[i];
      else{
        c=a[i];
        break;
      }
      i++;
    }
  }
  cout<<b*c<<endl;
  
  return 0;
}

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

int a[3];
int main()
{
    int x,y,z;
    while(cin>>a[0]>>a[1]>>a[2])
    {
        sort(a,a+3);
        int ans=0;
        ans+=a[2]-a[1];
        a[0]+=a[2]-a[1];
        int len=a[2]-a[0];
        int cnt=(a[2]-a[0])/2;
        ans+=cnt;
        if((a[2]-a[0])%2==1)
            ans+=2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

long long N;
long long M;

vector<long long> b(11000);
vector<long long> c(11000);
vector<long long> a(11000);

//ワーシャル–フロイド Warshall–Floyd
void solve() {
  ll cost[200][200];
  REP(i, 200) {
    REP(j, 200) { cost[i][j] = 1e8; }
    cost[i][i] = 0;
  }

  REP(i, M) {
    cost[a[i]][b[i]] = min(cost[a[i]][b[i]], c[i]);
    cost[b[i]][a[i]] = min(cost[b[i]][a[i]], c[i]);
  }

  REP(k, N) REP(i, N) REP(j, N) {
    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
  }

  ll ans = 0;
  REP(i, M) {
    if (cost[a[i]][b[i]] < c[i])
      ans++;
  }

  cout << ans << endl;
}

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

  cin >> N;
  cin >> M;

  for (int i = 0; i <= M - 1; i++) {
    cin >> a[i];
    a[i]--;
    cin >> b[i];
    b[i]--;
    cin >> c[i];
  }
  solve();
  return 0;
}


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

int graph[300][300] = {0};


int dik(int a, int b) {
  struct paircmp {
    bool operator()(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
  };
  priority_queue<pair<int, int>, std::vector<pair<int, int> >, paircmp > bfs;
  set<int> visited;
  bfs.push(make_pair(a, 0));
  while(!bfs.empty()) {
    auto cur = bfs.top();
    bfs.pop();
    visited.insert(cur.first);
    if (cur.first == b) {
      return cur.second;
    }
    for (int i = 0; i < 300; i++) {
      if (graph[cur.first][i] != 0) {
        if (!visited.count(i)) {
          //cout << "adding" << i << endl;
          //cout << "d" << cur.second+d << endl;
          bfs.push(make_pair(i, cur.second+graph[cur.first][i]));
        }
      }
    }
  }
  return -1;
}

int sd[300][300] = { 0};
int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> rs;
  for (int i = 0; i < r; i++) {
    int cit;
    cin >> cit;
    rs.push_back(cit);
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    graph[a][b] = c;
    graph[b][a] = c;
  }

  int md = INT_MAX;
  sort(rs.begin(), rs.end());
  do {
    int total = 0;
    //cout << "permutation:";
    //for (int i = 0; i < rs.size(); i++) {
    //  cout << rs[i] << " ";
    //}
    //cout << endl;

    for (int i = 0; i < rs.size()-1; i++) {
      if (sd[rs[i]][rs[i+1]] == 0) {
        int sp = dik(rs[i], rs[i+1]);
        //cout << "shorest path from " << rs[i] << " to " << rs[i+1] << " is " << sp << endl;
        sd[rs[i]][rs[i+1]] = sp;
        sd[rs[i+1]][rs[i]] = sp;
      } 
      //cout << "shorest path from " << rs[i] << " to " << rs[i+1] << " is " << sd[rs[i]][rs[i+1]] << endl;
      total += sd[rs[i]][rs[i+1]];
    }
    md = min(total, md);
    //cout << "total: " << total << endl;
  } while(next_permutation(rs.begin(), rs.end()));
  cout << md << endl; 

  return 0;
}


Measured memory_bytes: 1356
#include <stdio.h>
 
int main(void)
{
    int i, n, a;
    long int goukei = 0;
    int M = -1000000, m = 10000000;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a);
        goukei = goukei + a;
        if (a >= M)
        {
            M = a;
        }
        if(a <= m)
        {
            m = a;
        }
    }
    printf("%d %d %ld\n", m, M, goukei);
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z;
    cout << ' ';
    cout << x;
    cout << ' ';
    cout << y;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Flip solver = new Flip();
        solver.solve(1, in, out);
        out.close();
    }

    static class Flip {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long m = in.nextLong();

            long max = Math.max(n, m);
            long min = Math.min(n, m);

            if (min == 0) {
                out.println(0);
                return;
            }

            if (min == 1) {
                out.println(max == 1 ? 1 : max - 2);
                return;
            }
            if (min == 2) {
                out.println(0);
                return;
            }
            out.println((max - 2) * (min - 2));
        }

    }
}



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

#define LL long long int
#define mp make_pair
#define FOR(i, n) for(i = 0; i < n; ++i)
typedef vector <int> vi;
typedef vector <LL> vll;
typedef pair<LL, LL> iPair;
const int MOD = 1e9+7;

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

    LL t = 1;
    LL i,j;
    // cin>>t;
    
    while(t--)
    {
        int n;
        cin>>n;
        cout<<n*n*n;
        
    }

	return 0;
}


Measured memory_bytes: 256
import sys
H,N = map(int,input().split())
array = list(map(int,input().split()))

if not ( 1 <= H <= 10**9 and 1 <= N <= 10**5 ): sys.exit()
if not ( 1 <= min(array) and max(array) <= 10**4 ): sys.exit()

print('Yes') if sum(array) >= H else print('No')

Measured memory_bytes: 20468
#include <iostream>
#include <string>
#include <stdio.h>
// #define scanf " %s codekaze quiz"

using namespace std;
int main()
{   
    string s;
    cin>>s;
    bool flag = true;
    if( s.size()==6 && s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes";
    } 
    else{
        cout<<"No";
    }
   
    return 0;
}

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 argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N; cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    }
    else if (N == 2) {
        int A, B;
        cin >> A;
        cin >> B;
        cout << A + B << endl; 
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
using ll = long long int;

ll N, D, a, b;
ll x[100010], y[100010];

set< pair<ll, ll> > S;
map< ll, vector<ll> > mpx, mpy;
map< ll, set<ll> > stx, sty;
ll ans = 0;

void solve(ll x, ll y);
void search_pt(map<ll, vector<ll> > &mp, ll x, ll lb, ll ub, int mode);

void search_pt(map<ll, vector<ll> > &mp, map<ll, set<ll> > &st, ll t, ll lb, ll ub, int mode) {
    if(!mp.count(t)) return;
    int lb_idx = lower_bound(mp[t].begin(), mp[t].end(), lb) - mp[t].begin();
    int ub_idx = upper_bound(mp[t].begin(), mp[t].end(), ub) - mp[t].begin();
    ans += ub_idx - lb_idx;
    // printf("target = %lld [%lld, %lld], lb_idx = %d, ub_idx = %d\n", t, lb, ub, lb_idx, ub_idx);

    auto l = st[t].lower_bound(lb), r = st[t].upper_bound(ub);
    vector< pair<ll, ll> > cand;
    for(auto it=l; it!=r; it++) {
        ll X = (mode == 0 ? t : *it);
        ll Y = (mode == 1 ? t : *it);
        S.insert(make_pair(X, Y));
        cand.push_back(make_pair(X, Y));
    }

    for(auto p : cand) {
        ll X = p.first, Y = p.second;
        stx[X].erase(Y);
        sty[Y].erase(X);
    }

    for(auto p : cand) {
        ll X = p.first, Y = p.second;
        solve(X, Y);
    }
}

void solve(ll X, ll Y) {
    search_pt(mpx, stx, X-D, Y-D, Y+D, 0);
    search_pt(mpx, stx, X+D, Y-D, Y+D, 0);
    search_pt(mpy, sty, Y-D, X-D+1, X+D-1, 1);
    search_pt(mpy, sty, Y+D, X-D+1, X+D-1, 1);
}

int main() {
    scanf("%lld%lld%lld", &N, &a, &b);
    a--; b--;
    for(int i=0; i<N; i++) {
        ll p, q; scanf("%lld%lld", &p, &q);
        x[i] = p - q, y[i] = p + q;
        // printf("x = %lld, y = %lld\n", x[i], y[i]);
        mpx[ x[i] ].push_back(y[i]);
        mpy[ y[i] ].push_back(x[i]);
        if(i != a) stx[ x[i] ].insert(y[i]);
        if(i != a) sty[ y[i] ].insert(x[i]);
    }

    D = max(llabs(x[a] - x[b]), llabs(y[a] - y[b]));
    for(auto &vec : mpx) {
        sort(vec.second.begin(), vec.second.end());
    }
    for(auto &vec : mpy) {
        sort(vec.second.begin(), vec.second.end());
    }

    S.insert(make_pair(x[a], y[a]));
    solve(x[a], y[a]);

    printf("%lld\n", ans / 2);
    return 0;
}

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

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int n,d;
	cin>>n>>d;
	int i;
	pair<long long int,long long int> a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i].first>>a[i].second;
	}
	int ans=0;
	for(i=0;i<n;i++)
	{
		double x=sqrt(a[i].first*a[i].first+a[i].second*a[i].second);
		long long int xx=ceil(x);
		//cout<<xx<<" "<<d<<endl;
		if(xx<=d)
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    
	char str[1000001];
	int m = scanf("%s",str);
	if (m == EOF) {
		printf("scan error!\n");
		return 0;
	}

	//printf("%s\n", str);

	int N = strlen(str);
	//printf("%d\n", N);

	int* S;
	S = calloc(N, sizeof(int));

	int ban = 0;
	int R_num = 0;
	int L_num = 0;
	for (int i = 0; i < N; i++) {
		if (str[i] == 'R') {
			R_num++;
			if (str[i + 1] == 'L') {
				int o = 1;
				while (R_num) {
					o ^= 1;
					S[i + o]++;
					//printf("%d\n",R_num);
					R_num--;
				}
				ban = i;
			}

		}
		else {
			L_num++;
			if (str[i + 1] == 'R' || i == N-1) {
				while (L_num) {
					S[ban + (L_num % 2)]++;
					L_num--;
				}
			}
		}

	}

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


    free(S);
	return 0;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	vector<int>a(3);
	rep(i,3) cin >> a[i];
	int che = a[0] ;
	int flag = 0;
	SORT(a);
	if(a[0] %2 ==1 || a[1] %2 == 1 || a[2] %2 ==1 ){
		cout << 0 << endl;
		return 0 ;
	}
	if(a[0]==a[1]&&a[1]==a[2]){
		cout << -1 << endl;
	}else{
		//操作をやる
		int x,y,z;
		x = a[0] ,y=a[1], z=a[2]; 
		int count = 0 ;
		while(1){
			int X = x/2 ,Y = y/2 ,Z = z/2;
			x = Y + Z; 
			y = X + Z;
			z = X + Y; 
			count ++ ;
			if(x%2 ==1 || y%2 == 1||z%2==1){
				break;
			}else if(x==y && y == z){
				cout << -1 << endl;
				return 0 ;
			}
		}
		cout << count << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
signed main() {
	int N, ma, mb;
	cin >> N >> ma >> mb;
	int a, b, c;
	vector<int> W(N);
	vector<int> C(N);
	for (int i = 0; i < N; i++) {
		cin >> a >> b >> c;
		W[i] = a*mb - b*ma;
		C[i] = c;
	}
	int dp[20000];
	int tmp[20000];
	for (int i = 0; i < 20000; i++) {
		dp[i] = 1000000000;
	}
	dp[10000 + W[0]] = C[0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 20000; j++) {
			tmp[j] = dp[j];
		}
		for (int j = -500; j < 20000; j++) {
			if ((j + W[i] >= 0) && (j + W[i] < 20000)) {
				dp[j + W[i]] = min(tmp[j + W[i]], tmp[j] + C[i]);
			}
		}
		dp[W[i] + 10000] = min(tmp[W[i] + 10000], C[i]);
	}
	int res = dp[10000];
	if (res == 1000000000) {
		cout << -1 << endl;
	}
	else {
		cout << res << endl;
	}
	return 0;

}

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

int main() {
  int c[4][4] = {0};
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> c[i][j];
    }
  }
  int a[4] = {0}, b[4] = {0};
  for (a[1] = 0; a[1] <= 100; a[1]++) {
    for (a[2] = 0; a[2] <= 100; a[2]++) {
      for (a[3] = 0; a[3] <= 100; a[3]++) {
        b[1] = c[1][1] - a[1];
        b[2] = c[2][2] - a[2];
        b[3] = c[3][3] - a[3];
        bool flag = true;
        for (int i = 1; i <= 3; i++) {
          for (int j = 1; j <= 3; j++) {
            if (c[i][j] != a[i] + b[j]) {
              flag = false;
            }
          }
        }
        if (flag) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main() {

  ll N;
  cin >> N;
  ll x, y;
  set<ll> array1, array2, array3;
  UnionFind UF(3 * 1e5);
  REP(i, N){
    cin >> x >> y;
    array1.insert(2 * x - 1);
    array2.insert(2 * y);
    UF.unite(2 * x - 1, 2 * y);
  }
  ll count = 0;
  map<ll, ll> map1;
  map<ll, ll> map2;
  for(auto i : array1){
    x = UF.root(i);
    map1[x]++;
    array3.insert(x);
  }
    //cout << "x:" << i << endl;
  for(auto j : array2){
    y = UF.root(j);
    map2[y]++;
    array3.insert(y);
  }
  for(auto i: array3) count += map1[i] * map2[i];

  cout << (count - N) << endl;
  return 0;
}


Measured memory_bytes: 8832
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<stack>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
struct P
{
    int x;
    int y,z;
    bool operator<(const P &a)const
    {
       return x>a.x;
    }
};
struct S
{
    int x,y;
};
const int N=2e5+500;
vector<P> v[N];
int a,c,i,b,k,d,n,m,e=1987654321;
int l[N],o[N];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};
ll x,y,z[5][N],j[5][N],mod=1000000007;
P u[N];
stack<S> s;
queue<int> q;
string r,r1,r2;
bool as(int a,int b)
{
    return a>b;
}
ll f(int i,int n)
{
    if(l[i]==n) return 1;
    if(z[i][n]) return z[i][n];
    ll h,x=0;
    for(h=0;h<v[n].size();h++)
         if(j[i][n]==j[i][v[n][h].x]+v[n][h].y)   x+=f(i,v[n][h].x),x%=mod;
    return z[i][n]=x;
}
int main()
{
    int t,u,h;
    a=ri(),b=ri(),l[1]=ri(),l[2]=ri();
    for(t=1;t<=b;t++)
    {
        n=ri();m=ri(),i=ri();
        v[n].push_back({m,i});
        v[m].push_back({n,i});
    }
    memset(j,-1,sizeof(j));
    for(u=1;u<=2;u++)
    {
        j[u][l[u]]=0;
        q.push(l[u]);
        for(;q.size();q.pop())
        {
            for(h=0;h<v[q.front()].size();h++)
            if(j[u][v[q.front()][h].x]<0||j[u][v[q.front()][h].x]>j[u][q.front()]+v[q.front()][h].y)
            {
                j[u][v[q.front()][h].x]=j[u][q.front()]+v[q.front()][h].y;
                q.push(v[q.front()][h].x);
            }
        }
    }
    y=f(1,l[2]);
    x=y*y%mod;
    for(t=1;t<=a;t++)
        if(j[1][t]==j[2][t]&&j[2][t]*2==j[1][l[2]])    x-=f(1,t)*f(1,t)%mod*f(2,t)%mod*f(2,t)%mod,x+=mod,x%=mod;
    for(t=1;t<=a;t++)
        for(h=0;h<v[t].size();h++)
            if(v[t][h].y+j[1][t]+j[2][v[t][h].x]==j[1][l[2]]&&max(j[1][t],j[2][v[t][h].x])<min(j[1][t],j[2][v[t][h].x])+v[t][h].y)
                x-=f(1,t)*f(1,t)%mod*f(2,v[t][h].x)%mod*f(2,v[t][h].x)%mod,x+=mod,x%=mod;
    printf("%lld\n",x);
}

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

typedef long long ll;
typedef pair<int,int> P;
const ll mod = 1000000007;
//const ll mod = 998244353;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)


const int MAX_N = 200020;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void create_table(int n) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= n;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[n] = pow_mod(fact[n],mod-2);
    for (int i = n;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= n;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}
int main() {
    int h,w,n;
    cin >> h >> w >> n;
    create_table(h+w+10);
    vector<P> v(n);
    vector<ll> dp(n+1,0);
    for (int i = 0;i < n;++i) cin >> v[i].first >> v[i].second;
    sort(v.begin(),v.end());
    v.push_back(P(h,w));
    n++;
    for (int i = 0;i < n;++i) {
        dp[i] = combi(v[i].first+v[i].second-2,v[i].first-1);
        for (int j = 0;j < i;++j) if (v[j].first <= v[i].first && v[j].second <= v[i].second) {
            dp[i] -= dp[j]*combi(v[i].first-v[j].first+v[i].second-v[j].second,v[i].first-v[j].first);
            dp[i] %= mod;
        }
    }
    cout << (dp[n-1]+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll min(ll a,ll b)
{
  return a < b ? a : b;
}
ll func(vector<ll> val,vector<ll> wt,ll n,ll W)
{
  ll i,j,V=0;
  ll res=-1;
  for(i=0;i<n;i++)
    V+=val[i];
  
  int dp[n+1][V+1];
  
  for(i=0;i<=n;i++)
  {
    for(j=0;j<=V;j++)
    {
     if(j==0)
        dp[i][j]=0;
     else if(i==0)
       dp[i][j]=INT_MAX;
     else if(val[i-1]<=j)
        dp[i][j]=min(wt[i-1]+dp[i-1][j-val[i-1]],dp[i-1][j]);
     else
        dp[i][j]=dp[i-1][j];
    }
  }
  for(i=0;i<=V;i++)
  {
    if(dp[n][i]<=W)
      res=max(res,i);
      
  }
  return res;
}
int main()
{
  ll n,W,val,wt;
  vector<ll> v,w;
  cin>>n>>W;
  ll i;
  for(i=0;i<n;i++)
  {
    cin>>wt>>val;
    v.push_back(val);
    w.push_back(wt);
  }
  cout<<func(v,w,n,W)<<"\n";
}


Measured memory_bytes: 39680
#include <iostream>
using namespace std;
int main(void){
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B && B!=C)
    cout<<"Yes"<<endl;
    else if(A==C && C!=B)
    cout<<"Yes"<<endl;
    else if(B==C && C!=A)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <math.h>

int main(void){
  long N,bit[40];
  long long A,K;
  long long ans = 0,X = 0;
  int flag[40];
  int counter;
  scanf("%ld%lld",&N,&K);

  for(int i = 0;i < 40;i++){
    bit[i] = 0;
    flag[i] = 0;
  }

  for(int i = 0;i < N;i++){
    scanf("%lld",&A);
    counter = 0;
    while(A > 0){
      flag[counter] = 1;
      if(A%2 != 0){
        bit[counter]++;
      }
      counter++;
      A /= 2;
    }
  }
  counter = 0;
  long sample = K;
  while(sample > 0){
    flag[counter] = 1;
    counter++;
    sample /= 2;
  }

  for(int i = 39;i >= 0;i--){
    if(flag[i]){
      if(bit[i] > N-bit[i] || X+(long)pow(2,i) > K){
        ans += (long)pow(2,i)*bit[i];
      }else{
        ans += (long)pow(2,i)*(N-bit[i]);
        X += pow(2,i);
      }
    }
  }

  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct open
{
    long period[10];
};
struct profits
{
    long momney[11];
};
int cmp(const void *a,const void *b)
{
    return *(int*)b-*(int*)a;
}
long ownpow(long x,long n)
{
    long i,result=1;
    for(i=1;i<=n;i++)
    {
        result*=x;
    }
    return result;
}
int main()
{
    long profit[1024],i,j,k,time[100],result,t,n;
    long p[1024][10];
    struct open shop[100];
    struct profits gain[100];
    for(n=1;n<1024;n++)
    {
        k=n;
        for(i=0;i<10;i++)
        {
            t=pow(2,9-i);
            if(k/t==1)
                p[n-1][i]=1;
            else(p[n-1][i]=0);
            k%=t;
        }
    }
    /*for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            printf("%d ",p[i][j]);
        }
        printf("\n");
    }*/
    //profit[0]=-2555555;
    scanf("%ld",&k);
    for(i=0;i<k;i++)
    {
        for(j=0;j<10;j++)
        {
            scanf("%ld",&shop[i].period[j]);
        }
    }
    for(i=0;i<k;i++)
    {
        for(j=0;j<11;j++)
        {
            scanf("%ld",&gain[i].momney[j]);
        }
    }
    for(n=1;n<1024;n++)
    {
        for(i=0;i<k;i++)
        {
            time[i]=0;
        }
        for(i=0;i<10;i++)// 时段
        {
          for(j=0;j<k;j++)//店家
          {
              if(p[n-1][i]==1&&shop[j].period[i]==1)
                time[j]++;
          }
        }
        result=0;
        for(i=0;i<k;i++)
        {
            result+=gain[i].momney[time[i]];
        }
        profit[n-1]=result;
    }
    qsort(profit,1023,sizeof(profit[0]),cmp);
    printf("%ld\n",profit[0]);
    return 0;
}


Measured memory_bytes: 256
//題意の条件は「遷移先に含まれない最小の非負整数を書く」と言い換えらえる。木やDAGの場合は書き方が一意に定まる。
//なもりグラフの場合は、木を含むか・単なるループかによって書き方が異なる。単なるループの場合、ループ長の偶奇で判定できる。
//木を含む場合は、木の根を一つ取ってきて書く数aを決めると、書き方が一意に定まる。ここで書き方のルールを間違えると嵌るので注意。
//例えば、木の根rに直接つながる頂点に0,1,2,3,5,6,7,9,10が書かれているとき、rには4以上を書き込むのだが、5～7, 9～10は書き込めないことに注意する必要がある。
//グランディー数xの頂点が存在するためには、x*(x-1)/2辺以上が必要なので、制約より700以上の数はは絶対に書き込まないとしてよい。
//したがって、aに書き込む値を高々700通り試し、それぞれについてループ内の頂点に値を書き込み、矛盾判定をすればよい。
//実装は、グラフの辺の向きを逆にすると簡単。逆にする：i -> p_i

#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int p[200000], inV[200000];
set<int> gset[200000];
int g[200000];
int g2[200000];
bool isTree[200000];
vector<int> et[200000];

bool check(int start, int val) {
	int i, j;
	rep(i, n) g2[i] = g[i];
	g2[start] = val;
	
	//ループ内の頂点について、grundy数を決める.	
	rep(i, n) gset[i].clear();
	int pos = start;
	while (true) {
		int npos = p[pos];
		if (npos == start) break;
		rep(i, et[npos].size()) gset[npos].insert(g2[et[npos][i]]);
		rep(i, n) if (gset[npos].find(i) == gset[npos].end()) break;
		g2[npos] = i;
		pos = npos;
	}
	
	//rep(i, n) cout << g2[i] << " ";
	//cout << endl;
	
	//矛盾判定(頂点startについてのみ、おこなえばよい)
	rep(i, et[start].size()) gset[start].insert(g2[et[start][i]]);
	rep(i, n) if (gset[start].find(i) == gset[start].end()) break;
	return i == val;
}

int main() {
	int i, j;
	queue<int> que;
	
	cin >> n;
	rep(i, n) { cin >> p[i]; p[i]--; inV[p[i]]++; }
	rep(i, n) { if (!inV[i]) que.push(i); }
	
	while (!que.empty()) {
		int v = que.front(); que.pop();
		rep(i, n) if (gset[v].find(i) == gset[v].end()) break;
		g[v] = i;
		gset[v].clear();
		gset[p[v]].insert(g[v]);
		inV[p[v]]--;
		if (!inV[p[v]]) que.push(p[v]);
	}

	rep(i, n) isTree[i] = (gset[i].size() > 0);
	rep(i, n) if (isTree[i]) break;
	if (i == n) { cout << ((n % 2) ? "IMPOSSIBLE" : "POSSIBLE") << endl; return 0; }
	
	rep(i, n) {
		if (!isTree[i]) continue;
		rep(j, n) if (gset[i].find(j) == gset[i].end()) break;
		g[i] = j;
	}
	
	rep(i, n) if (isTree[i]) break;
	int start = i, g0 = g[start];
	rep(i, n) et[p[i]].push_back(i);
	
	rep(i, 700) if (check(start, g0 + i)) { cout << "POSSIBLE" << endl; return 0; }
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		var n = s.Length;
		for(int i = 0; i < n; i++)
		{
			s = s.Substring(0, s.Length-1);
			if(s.Length%2==1)
				continue;
			
			var t = s.Substring(0, s.Length / 2);
			var u = s.Substring(s.Length / 2);
			if(t==u)
			{
				Console.WriteLine(s.Length);
				return;
			}
		}
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 11092
/// Assembled By : FuadNafiz98

#include <bits/stdc++.h>

using namespace std;

#define dbg(x) { cerr << #x << " -- " << x << endl;}
#define             IO                                      ios_base::sync_with_stdio(0); cin.tie(0)

const int maxn = 100005;
int n, m, dp[maxn], best, path[maxn], root;
vector <pair <int, int> > adj[maxn];

int dfs(int node){
    if(dp[node] != -1) return dp[node];
    dp[node] = 0;
    for(int i = 0; i < (int)adj[node].size(); i++){
        int v = adj[node][i].first;
        if(dp[node] < dfs(v) + 1){
            dp[node] = dp[v] + 1;
        }
    }
    return dp[node];
}

int main(){
 IO;   
 cin >> n >> m;
 for(int i = 0; i < m; i++){
    int x,y;
    cin >> x >> y;
    x--,y--;
    adj[x].push_back({y, i + 1});
 }
 memset(dp, -1, sizeof(dp));
 best = -1;     
 for(int i = 0; i < n; i++){
    int mid = dfs(i);
    if(best < mid)
        best = mid;
 }
 cout << best << endl;
}

Measured memory_bytes: 8832
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int main(){

	int x, y, z;
	cin >> x >> y >> z;
	int cnt = 0;

	x -= z;
	while (1) {
		if (x - (y + z) >= 0) {
			x -= y + z;
			cnt++;
		}
		else
			break;
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = input().split()
B = [int(x) for x in B]
Ans = 0
for _ in range(N):
  A = input().split()
  s = C
  for j in range(M):
    s += int(A[j])*B[j]
  if s > 0:
    Ans +=1
print(Ans)

Measured memory_bytes: 3064
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	x,a,b=map(int,input().split())
	
	ans="dangerous"
	
	if b-a<=0:
		ans="delicious"
	elif b-a<=x:
		ans="safe"
	
	print(ans)
	
	






	
if __name__ == "__main__":
	main()


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  string s;
  cin>>s;

  ll cnt=0;
  REP(i,n){
    if(s[i]=='R')
      cnt++;
  }

  ll ans=0;
  REP(i,cnt){
    if(s[i]=='W')
      ans++;
  }

  cout<<ans<<endl;
}



Measured memory_bytes: 3768
(n,q),*t=[list(map(int,t.split()))for t in open(0)]
s=[0]
d=s*n
f=s+[1]*n
e=[[]for _ in d]
for a,b in t:
 if~-n:n-=1;e[a-1]+=b-1,;e[b-1]+=a-1,
 else:d[a-1]+=b
while s:
 v=s.pop()
 for w in e[v]:d[w]+=d[v]*f[w];s+=[w]*f[w];f[w]=0
print(*d)

Measured memory_bytes: 143972
x1,y1,x2,y2=list(map(int,input().split()))

if x2>=x1 and y2>=y1:
  x3=x2-abs(y2-y1);y3=y2+abs(x2-x1);x4=x3-abs(y3-y2);y4=y3-abs(x3-x2)

elif x2<=x1 and y2>=y1:
  x3=x2-abs(y2-y1);y3=y2-abs(x2-x1);x4=x3+abs(y3-y2);y4=y3-abs(x3-x2)

elif x2<=x1 and y2<=y1:
  x3=x2+abs(y2-y1);y3=y2-abs(x2-x1);x4=x3+abs(y3-y2);y4=y3+abs(x3-x2)

elif x2>=x1 and y2<=y1:
  x3=x2+abs(y2-y1);y3=y2+abs(x2-x1);x4=x3-abs(y3-y2);y4=y3+abs(x3-x2)

  
print(x3,y3,x4,y4)


Measured memory_bytes: 3064
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;

int main(){

    //freopen("planting.in", "r", stdin);
    //freopen("planting.out", "w", stdout);

    int n;
    long long cnt = 0;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++) cin >> arr[i];
    for(int i = 0; i < n - 2; i++){
        for(int j = i + 1; j < n - 1; j++){
            for(int k = j + 1; k < n; k++){
                if(arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k]){
                    if(arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[k] + arr[j] > arr[i]) cnt++;
                }
            }
        }
    }
    cout << cnt;
}


Measured memory_bytes: 3620
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
    int n;
    ll m;
    while(cin>>n>>m,n){
        vll v(n);
        rep(i,n){
            cin>>v[i];
        }
        sort(ALL(v));
        vll x;
        x.PB(0LL);
        rep(i,n){
            // x.insert(v[i]);
            x.PB(v[i]);
        }
        rep(i,n){
            rep(j,n){
                // x.insert(v[i]+v[j]);
                x.PB(v[i]+v[j]);
            }
        }
        sort(ALL(x));
        x.erase(unique(ALL(x)),x.end());
        // sort(ALL(x));
        ll ans=0;
        rep(i,x.size()){
            ll t=m-x[i];
            if(t<0) continue;
            auto it=upper_bound(ALL(x),t);
            if(it==x.begin()) continue;
            it--;
            maxs(ans,*it + x[i]);
        }
        cout<<ans<<endl;
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
      cout<<fixed<<setprecision(20);
    mainmain();
}

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

int main(){
	int N;
	cin>>N;
	vector<int> W(N);
	int sum = 0;
	for(int i=0;i<N;i++){
		cin>>W[i];
		sum+=W[i];
	}
	
	int ans = 9999999;
	
	int k = 0;
	for(int i=0;i<N;i++){
		k+=W[i];
		ans = min(ans,abs(k-(sum-k)));
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}

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

void chmin(int &a, int b) { a = min(a, b); }

int INF = 1e+9;
int h, w;
string s[100];
int dp[100][100];

int main() {
	int i, j;
	
	cin >> h >> w;
	rep(i, h) cin >> s[i];
	
	rep(i, h) rep(j, w) dp[i][j] = INF;
	
	dp[0][0] = (s[0][0] == '#');
	rep(i, h) {
		rep(j, w) {
			if (dp[i][j] == INF) continue;
			if (j + 1 < w) chmin(dp[i][j + 1], dp[i][j] + (s[i][j] == '.' && s[i][j + 1] == '#'));
			if (i + 1 < h) chmin(dp[i + 1][j], dp[i][j] + (s[i][j] == '.' && s[i + 1][j] == '#'));
		}
	}
	
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 256