akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

int dp[2][1 << 22];

int main(void){
	while(1){
		int n, m; cin >> n >> m;
		if(!n && !m) break;

		int b[505][505]={0};
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				char c; cin >> c;
				b[i][j] = c - '0';
			}
		}

		int ans = 0;
		if(n <= 22){
			int S = 1 << n;
			for(int i=0; i<S; i++){
				int cnt = 0;
				int ingredient[501]={0};//材料
				for(int j=0; j<n; j++){
					if((i & (1<<(j))) == 0) continue;
					cnt++;
					for(int k=0; k<m; k++) ingredient[k] ^= b[j][k];
				}
				bool flag = true;
				for(int j=0; j<m; j++){
					if(ingredient[j] == 1){
						flag = false;
						break;
					}
				}
				if(flag) ans = max(ans, cnt);
			}
		}else{
			int B[501]={0};
			for(int i=0; i<n; i++){
				for(int j=0; j<m; j++){
					B[i] += (b[i][j] << j);
				}
			}

			int S = 1 << m;
			fill(dp[0], dp[2], INT_MIN);
			dp[1][0] = 0;
			for(int i=0; i<n; i++){
				for(int j=0; j<S; j++){
					dp[i%2][j^B[i]] = max(dp[i%2][j^B[i]], dp[(i+1)%2][j] + 1);
					dp[i%2][j] = max(dp[i%2][j], dp[(i+1)%2][j]);
				}
			}
			ans = dp[(n+1)%2][0];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 36860
def may_eq(s, t):
    return all(c_s == '?' or c_s == c_t for c_s, c_t in zip(s, t))


def main():
    s = input()
    t = input()

    if not '?' in s:
        print(s)
        return

    if len(t) > len(s):
        print('UNRESTORABLE')
        return

    for i in reversed(range(0, len(s) - len(t) + 1)):
        if may_eq(s[i:i + len(t)], t):
            s = s[:i] + t + s[i + len(t):]
            s = s.replace('?', 'a')
            print(s)
            return

    print('UNRESTORABLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
//freopen("input.txt" , "r" , stdin);
//freopen("output.txt" , "w" , stdout);
#define ll long long
#define endl  '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REP1(i1,n)  for(ll i=1;i<n;i++)
#define pb push_back
#define mk make_pair
int main()
{
   IOS
  ll n,k;
  cin>>n>>k;
  ll a[n];
  for(ll i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  ll ans=0;
  for(ll i=0;i<k;i++)ans+=a[i];
  cout<<ans<<endl;

}
    //for(ll i=0;i<len;i++)cout<<v[i]<<" ";



/*

Alhamdulilla...

*/


Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, k, i, j;
	scanf("%d%d", &n, &k);
	vi a;
	for (i = 0; i < n; i++) {
		int b;
		scanf("%d", &b);
		if (b < k) {
			a.push_back(b);
		}
	}
	int ans = 0;
	n = a.size();
	sort(a.begin(), a.end());
	int left = 0, right = n;
	while (left < right) {
		int i0 = (right + left) / 2;
		vii dp(n + 1, vi(k + 1));
		dp[0][0] = 1;
		for (i = 0; i < n; i++) {
			for (j = 0; j <= k; j++) {
				if (dp[i][j]) {
					if (j + a[i] <= k && i != i0) {
						dp[i + 1][j + a[i]] = 1;
					}
					dp[i + 1][j] = 1;
				}
			}
		}
		bool flag = false;
		for (j = k - a[i0]; j < k; j++) {
			if (dp[n][j]) {
				flag = true;
				break;
			}
		}
		if (flag) {
			right = i0;
		}
		else {
			left = i0 + 1;
		}
	}
	cout << left << endl;
}

Measured memory_bytes: 98224
h,w=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
s=[list(input()) for _ in range(h)]

Ch,Cw=Ch-1,Cw-1
Dh,Dw=Dh-1,Dw-1
from collections import deque
todo=deque([[0,Ch,Cw]])
d=[[-1]*w for _ in range(h)]
d[Ch][Cw]=0
toho=[[0,1],[0,-1],[1,0],[-1,0]]
wiz=[[2,2],[2,1],[2,0],[2,-1],[2,-2],[1,2],[1,1],[1,-1],[1,-2],[0,2],[0,-2],[-1,2],[-1,1],[-1,-1],[-1,-2],[-2,2],[-2,1],[-2,0],[-2,-1],[-2,-2]]
while todo:
  cnt,nh,nw=todo.popleft()
  if d[nh][nw]<cnt:continue
  for dh,dw in toho:
    if 0<=nh+dh<h and 0<=nw+dw<w and s[nh+dh][nw+dw]!='#':
      if d[nh+dh][nw+dw]==-1 or d[nh+dh][nw+dw]>cnt:
        d[nh+dh][nw+dw]=cnt
        todo.appendleft([cnt,nh+dh,nw+dw])
  for dh,dw in wiz:
    if 0<=nh+dh<h and 0<=nw+dw<w and s[nh+dh][nw+dw]!='#':
      if d[nh+dh][nw+dw]==-1 or d[nh+dh][nw+dw]>cnt+1:
        d[nh+dh][nw+dw]=cnt+1
        todo.append([cnt+1,nh+dh,nw+dw])
print(d[Dh][Dw])


Measured memory_bytes: 155824
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <bitset>

using namespace std;

int N;
vector<vector<pair<int, bool>>> n;

int main(int argc, char const *argv[])
{
    cin >> N;
    n.resize(N);
    for (int i = 0; i < N; i++)
    {
        int an;
        cin >> an;
        vector<pair<int, bool>> a(an);
        for (int j = 0; j < an; j++)
        {
            int x, y;
            cin >> x >> y;
            a.at(j) = make_pair(x, y);
        }
        n.at(i) = a;
    }

    int m(0);
    for (int i = 0; i < (1 << N); i++)
    {
        int mm(0);
        bitset<15> b(i);
        for (int j = 0; j < N; j++)
        {
            if (b.test(j))
            {
                for (auto e : n.at(j))
                {
                    if (b.test(e.first - 1) == e.second)
                    {
                    }
                    else
                    {
                        goto no;
                    }
                }
            }
            else
            {
                continue;
            }
        }
        for (int j = 0; j < N; j++)
        {
            if (b.test(j))
                mm++;
        }
        m = max(m, mm);
    no:
        continue;
    }
    cout << m << endl;

    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

char st[110];
int main(){
	scanf("\n%s", st);
	cout << st[0] << st[1] << st[2] << endl;
    return 0;
}


Measured memory_bytes: 3760
/*
	Date:2020.5.10
	Name:Aliemo
*/
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define rr register

#define MAXN 1010
#define inf 1e18

using namespace std;

inline int read(int &T) {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) {f |= ch == '-'; ch = getchar();}
	while (isdigit(ch)) {s = s * 10 + (ch ^ 48); ch = getchar();}
	return T = f ? -s : s;
}

void print(int x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}

char s[MAXN], c[MAXN];

signed main() {
	cin >> s >> c;
	int lens = strlen(s);
	int lenc = strlen(c);
	for (rr int i = 0; i < lens; i++)
		if (s[i] != c[i]) {
			puts("No");
			return 0;
		}
	puts("Yes");
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <queue>
#include <cstdlib>
using namespace std;

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

	for (int i = 0; i < S.size(); i++) {
		if ((int)S.at(i) + N > 90) {
			S.at(i) = 64 + (((int)S.at(i) + N) - 90);
		}
		else {
			S.at(i) += N;
		}
		cout << S.at(i);
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 200010
#define M 19
ll x[N];
ll t[2][N][M], dp[2][1<<M];
ll n, V, m;
bool res[N];

void calc(ll t[N][M]){
	rep(i, M){
		ll V2 = V>>i;
		ll r = n;
		t[n][i] = n;
		for(ll j = n-1; j >= 0; j--){
			t[j][i] = r;
			if(j>0&&x[j]-x[j-1]>V2) r = j;
		}
		if(V2==0) return;
	}
}

int main(){
	cin>>n>>V;
	rep(i, n) cin>>x[i];
	calc(t[0]);
	reverse(x, x+n);
	rep(i, n) x[i] *= -1;
	calc(t[1]);

	while(V>=(1<<m)) m++;
	m++;
	rep(i, 2){
		ll *dp2 = dp[i];
		rep(j, 1<<m){
			rep(k, m){
				if(1&(j>>k)) continue;
				chmax(dp2[j|(1<<k)], t[i][dp2[j]][k]);
			}
		}
	}
	rep(i, n){
		if(t[0][i][0]!=i+1) continue;
		int i2 = t[1][n-1-i][0];
		//cerr<<n-i2<<" "<<i<<endl;
		rep(j, 1<<m){
			int j2 = (1<<m)-1-j;
			if(dp[0][j&~1]>=n-i2&&dp[1][j2&~1]>=n-i-1) res[i+1] = 1;
			//cerr<<j<<": "<<dp[0][j&~1]<<" "<<dp[1][j2&~1]<<endl;
		}
	}
	rep(i, n){
		cout<<(res[t[0][i][0]]?"Possible":"Impossible")<<endl;
	}
	return 0;
}


Measured memory_bytes: 71552
#include <bits/stdc++.h>
using namespace std;
const int Maxn=100005;
int n,m,q;
int vt[Maxn],d[Maxn],c[Maxn];
vector <int> g[Maxn];
int dp[Maxn],col[Maxn];
void dfs(int v,int d,int c)
{
	if (!col[v]) col[v]=c;
	if (dp[v]>=d || d==0) return;
	dp[v]=d;for (int i=0;i<g[v].size();++i)
		dfs(g[v][i],d-1,c);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	scanf("%d",&q);
	for (int i=0;i<q;++i) scanf("%d%d%d",vt+i,d+i,c+i);
	for (int i=q-1;i>=0;--i) dfs(vt[i],d[i],c[i]);
	for (int i=1;i<=n;++i) printf("%d\n",col[i]);
	return 0;
}

Measured memory_bytes: 8440
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (int)1e9+4
#define INFL (ll)1e18+4
#define md (int)1e9+7
#define mx 10000000  //use fixed<<setprecion 
#define mk make_pair
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back 
#define onell(x) __builtin_popcountll(x)
#define one(x) __builtin_popcount(x)
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi; 
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;
const int mxn=300300;
int c[mxn],d[mxn];
void solve(){
int n=0,x=0,y=0,z=0,m=0,k=0;
cin>>n>>m>>k;mez(c);
set<pi>s;
vi a(k+1),b(k+1);
rep(i,0,k){
cin>>a[i]>>b[i];
c[a[i]]++,d[b[i]]++;
s.insert({a[i],b[i]});
}
vi f,e;
for(int i=1;i<=n;i++)y=max(y,c[i]);
for(int i=1;i<=m;i++)x=max(x,d[i]);
for(int i=1;i<=n;i++){
	if(c[i]==y){
		e.pb(i);
	}
}
for(int i=1;i<=m;i++){
	if(d[i]==x){
		f.pb(i);
	}
}
int ans=x+y-1;
for(int i=0;i<sz(e);i++){
	for(int j=0;j<sz(f);j++){
		if(s.count({e[i],f[j]})==0){
			cout<<ans+1;
			return;
		}
	}
}
cout<<ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
 // cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}


Measured memory_bytes: 26140
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

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

	int n=s.size();
	int count_0=0,count_1=0;
	
	for(int i=0;i<n;i++){
		if(s[i]=='0'){
			count_0++;
		}else{
			count_1++;
		}
	}
	int diff=count_0-count_1;
	if(diff<0){
		diff=0-diff;
	}

	cout << n-diff << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll int fre[1002][1002];
int main()
{
int mx=0;
int n;
   cin>>n;
   for(int i=n;i<=999;i++)
   {
       int x=i,f=0,cnt=1,a,b;
       while(x!=0)
       {
              b=x%10;
               x=x/10;
           if(f==0)
           {
               a=b;
               f=1;


           }
          else if(f!=0&&a==b)
           {

             cnt++;
           }

       }

       if(cnt==3)
       {
           cout<<i<<endl;
           return 0;
       }
   }

    return 0;

}


Measured memory_bytes: 256
import numpy as np
 
N = int(input())
l = list(map(int,input().split()))
a = np.array(l)
count = 0

for i in range(len(a)):
    if a[i]%2 == 0:
        if a[i]%3 != 0 and a[i]%5 != 0:
            count += 1

if count:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 12388
#include <stdio.h>

int main(void)
{
  int a;
  scanf("%d",&a);
  if (a%10 == 3) printf("bon");
  else if (a%10 == 0 || a%10 == 1 || a%10 == 6 || a%10 == 8) printf("pon");
  else printf("hon");
  printf("\n");
  return 0;
}

Measured memory_bytes: 1704
function main(input) {
  var a = input[0].split(" ");
  if(a[0]==a[1])console.log(a[2]);
  else if(a[2]==a[1])console.log(a[0]);
  else if(a[0]==a[2])console.log(a[1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>


using namespace std;

int main() {
	int n, a[100000];
	int cnt = 0;
	int ans = 1;
	int serch = 1;
	int s=0;

	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int tmp = a[0];
	
for(cnt=0;cnt<n;cnt++){
	serch = a[tmp - 1];
	tmp = serch;
	ans++;
	if (a[0]==2) {
		ans = 1;
		break;
	}
	if (serch == 2) {
		break;
	}
	if (cnt == n - 1) {
		ans = -1;
		break;
	}
}

	cout<< ans << endl;





}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, Q, S, T;
    cin >> N >> Q >> S >> T;
    vector<ll> A(N + 1);
    vector<ll> dif(N);
    rep(i, N + 1) { cin >> A[i]; }
    rep(i, N) { dif[i] = A[i + 1] - A[i]; }
    ll res = 0;
    rep(i, N) { res -= (dif[i] >= 0 ? S * dif[i] : T * dif[i]); }
    rep(i, Q) {
        ll l, r, x;
        cin >> l >> r >> x;
        res += (dif[l - 1] >= 0 ? S * dif[l - 1] : T * dif[l - 1]);
        if(r < N)
            res += (dif[r] >= 0 ? S * dif[r] : T * dif[r]);
        dif[l - 1] += x;
        if(r < N)
            dif[r] -= x;
        res -= (dif[l - 1] >= 0 ? S * dif[l - 1] : T * dif[l - 1]);
        if(r < N)
            res -= (dif[r] >= 0 ? S * dif[r] : T * dif[r]);
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 6020
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
 
n = int(input())
edge = [[] for _ in range(n)]
edge_dict = dict()
 
for i in range(n - 1):
    a, b = [int(item) - 1 for item in input().split()]
    edge[a].append(b)
    edge[b].append(a)
    if a > b:
        edge_dict[(b, a)] = i
    else:
        edge_dict[(a, b)] = i
 
m = int(input())
uv = []
for _ in range(m):
    uv.append([int(item) - 1 for item in input().split()])
 
def dfs(p, v, dest):
    if v == dest:
        return [v]
    if p != -1 and len(edge[v]) == 1:
        return False
    for nv in edge[v]:
        if nv == p:
            continue
        ret = dfs(v, nv, dest)
        if ret:
            return ret + [v]
    return False
 
# edge-bitset of each constraint
target_edge = [0] * m
for i, (u, v) in enumerate(uv):
    ret = dfs(-1, u, v)
    for uu, vv in zip(ret, ret[1:]):
        if uu > vv:
            uu, vv = vv, uu
        if (uu, vv) in edge_dict:
            target_edge[i] |= (1 << edge_dict[(uu, vv)])

# edge-bitset of each set of constraints
edgest = [0] * 2**m
for i in range(1, 2**m):
    lsb = i & (-i)
    edgest[i] = edgest[i ^ lsb] | target_edge[lsb.bit_length() - 1]
 
# dp[set of constraints]
dp = [0] * 2**m
dp[0] = 1 << (n - 1)
ans = dp[0]
for i in range(1, 2**m):
    lsb = i & (-i)
    n_edgest = edgest[i]
    p_edgest = edgest[i ^ lsb]
    limit_num = bin(n_edgest ^ p_edgest).count("1")
    dp[i] = dp[i ^ lsb] >> limit_num
    if bin(i).count("1") % 2 == 0:
        ans += dp[i]
    else:
        ans -= dp[i]
print(ans)

Measured memory_bytes: 86008
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int max = *max_element(X.begin(), X.end());
    int min = *min_element(X.begin(), X.end());
    int ans=10000000, sum=0;

    for (int i = min; i <= max; i++) {
        for (int j = 0; j < N; j++) {
            sum += (X[j] - i) * (X[j] - i);
        }
        if (ans > sum) ans = sum;
        sum = 0;
    }

    cout << ans << endl;
}

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

int N,M,X;
int main (){
    cin >> N >> M >> X;
    int A[M];
    for(int i=0; i<M; i++){
        cin >> A[i];
    }
    int c = 0;
    for(int i=X; i<N+1; i++){
        for(int j=0; j<M; j++) if( A[j] == i ) c++;
    }
    int d = 0;
    for(int i=X; i>0; i--){
        for(int j=0; j<M; j++) if( A[j] == i ) d++;
    }
    int ans = min(c,d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val A = LongArray(N)
    val X = LongArray(N)
    val Y = LongArray(N)
    val Z = LongArray(N)
    repeat(N) { n ->
        val (x, y, z) = listOfLong()
        X[n] = x
        Y[n] = y
        Z[n] = z
    }
    var ans = 0L
    for (n in 0 until 8) {
        for (m in 0 until N) {
            A[m]  = (if ((n and 0b001) == 0) X[m] else -X[m])
            A[m] += (if ((n and 0b010) == 0) Y[m] else -Y[m])
            A[m] += (if ((n and 0b100) == 0) Z[m] else -Z[m])
        }
        A.sortDescending()
        var w = 0L
        for (m in 0 until M) w += A[m]
        if (ans < w) ans = w
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextLong() = java.lang.Long.parseLong(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }


Measured memory_bytes: 38232
f = lambda x: x+1 if x<=1000 else 2001-x
while 1:
    try:
        n = input(); p = min(n, 2000); ans = 0;
        for i in xrange(n-p,p+1):
            ans += f(i)*f(n-i);
        print ans
    except EOFError:
        break

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    lint a[N];
    cins(a, a + N);
    int num = 0;
    for(int i = 1; i < N; i++){
        if(a[num] > a[i]){
            num = i;
        }
    }
    cout << num + 1 << endl;
}



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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int odd = (N + 1) / 2;
		int even = N - odd;
		Console.WriteLine((double) odd / (double) N);
		
		
	}
	int N;
	public Sol(){
		N = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
n,k,s=map(int,input().split())
if s==1 or s==2:
    l=[s]*k+[s+1]*(n-k)
    print(" ".join(list(map(str,l))))
else:
    l=[s]*k+[s-1]*(n-k)
    print(" ".join(list(map(str,l))))

Measured memory_bytes: 56892
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  string s;
  cin >> s;
  ll ans = 0;
  int n = s.size();
  vi a(n+1);
  rep(i, n) {
    if (s[i] == '<') chmax(a[i+1], a[i]+1);
  }
  drep(i, n) {
    if (s[i] == '>') chmax(a[i], a[i+1]+1);
  }
  rep(i, n+1) ans += a[i];
  cout << ans << endl;
}

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

int main() {
  ll n,m;
  cin >> n >> m;
  vector<P> gakusei(n), check(m);
  rep(i,n) {
    ll a,b;
    cin >> a >> b;
    gakusei[i].first = a;
    gakusei[i].second = b;
  }
  rep(i,m) {
    ll c,d;
    cin >> c >> d;
    check[i].first = c;
    check[i].second = d;
  }
  ll ans = 1e10;
  int cnt;
  rep(i,n)rep(j,m) {
    ll tmp;
    tmp = abs(gakusei[i].first-check[j].first) + abs(gakusei[i].second-check[j].second);
    if (tmp < ans) {
      ans = tmp;
      cnt = j;
    }
    if (j == m-1) {
      cnt++;
      cout << cnt << endl;
      ans = 1e10;
      cnt = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<iterator>
#include<sstream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[s.size()-1]!='s')
    {
        cout<<s<<"s"<<endl;
    }
    else
    {
        cout<<s<<"es"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint {
    int x;

    Mint() : x(0) {}
    Mint(long long t) {
        x = t % MOD;
        if (x < 0) x += MOD;
    }

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n, m;
    cin >> n >> m;
    ll x[n], y[m];
    rep(i, n) {
        cin >> x[i];
    }
    rep(i, m) {
        cin >> y[i];
    }
    Mint<> X, Y;
    rep(i, n - 1) {
        X += (x[i + 1] - x[i]) * (i + 1) * (n - (i + 1));
    }
    rep(i, m - 1) {
        Y += (y[i + 1] - y[i]) * (i + 1) * (m - (i + 1));
    }
    cout << X * Y << endl;
    return 0;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if(S==U){
        cout << A-1 MM B << endl;
    }else{
        cout << A MM B-1 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N + 2];
    long sum = 0;
    A[0] = 0;
    A[N + 1] = 0;
    for (int i = 1; i <= N; i++) {
      A[i] = sc.nextInt();
      sum += Math.abs(A[i] - A[i - 1]);
    }
    sum += Math.abs(A[N + 1] - A[N]);

    for (int i = 1; i <= N; i++) {
      int add = Math.abs(A[i - 1] - A[i + 1]);
      int sub = Math.abs(A[i - 1] - A[i]) + Math.abs(A[i] - A[i + 1]);
      System.out.println(sum + add - sub);
    }
  }
}

Measured memory_bytes: 62576
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

//方針
//dp[i][何個入れたか][重さ-w1]
//dp[N+1][N+1][4*N+1]

int main(){
    int N;
    cin >> N;
    ll W, w[N], v[N];
    cin >> W;
    FOR(i, 0, N) cin >> w[i] >> v[i];
    ll w0 = w[0];
    FOR(i, 0, N) w[i] -= w0;
    ll dp[N+1][N+1][3*N+1];
    FOR(i, 0, N+1) FOR(j, 0, N+1) FOR(k, 0, 3*N+1) dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    FOR(i, 0, N){
        FOR(j, 0, i+1){
            FOR(k, 0, 3*N+1){
                if(dp[i][j][k]==-1) continue;
                //入れない
                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                //入れる
                if(W >= k+j*w0) dp[i+1][j+1][k+w[i]] = max(dp[i][j][k] + v[i], dp[i+1][j+1][k+w[i]]);
            }
        }
    }
    ll ans = 0;
    FOR(i, 1, N+1){
        FOR(j, 1, i+1){
            FOR(k, 0, 3*N+1){
                ll cost = (ll)(k + (ll)j * w0);
                if(W >= cost) ans = max(ans, dp[i][j][k]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 24192
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
using namespace std;
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
const ll inf = 0x3f3f3f3f3f3f3f3f;
#define ull unsigned long long
const int maxn = 2e5+10;
const ll mod=1e9+7;
#define MAXN 40100
ll gcd(ll T, ll b) { return b == 0 ? T : gcd(b, T % b); }
ll lcm(ll T, ll b) { return T / gcd(T, b) * b; }
ll mul(ll a,ll b, ll c) {
    ll ans = 0;
    while(b) {
        if(b&1) {
            ans= (ans+a)%c;
            b--;
        }
        b>>=1;
        a=(a+a)%c;
    }
    return ans;
}
 
ll powmod(ll a,ll b,ll c) {
    ll ans = 1;
    while(b) {
        if(b&1) {
            ans = mul(ans,a,c);
            b--;
        }
        b>>=1;
        a=mul(a,a,c);
    }
    return ans ;
}
 
ll exgcd(ll a,ll b,ll &x,ll &y) {
    if(b==0)
    {
        x=1;y=0;
        return a; 
    }
    ll r=exgcd(b,a%b,x,y);
    ll temp=y;
    y=x-(a/b)*y;
    x=temp;
    return r;
}

const ll INF = 0x3f3f3f3f3f3f3f3f;
int pre[maxn];
int siz[maxn];
int ans;
void init() {
    for(int i=0;i<maxn;i++) {
        pre[i]=i;
        siz[i]=1;
    }
}
int find(int x) {
    while(x!=pre[x]) {
        pre[x]=pre[pre[x]];
        x=pre[x];
    }
    return x;
}
void join(int x,int y) {
    int fx=find(x),fy=find(y);
    if(fx!=fy) {
        pre[fx]=fy;
        siz[fy]+=siz[fx];
        if(siz[fy]>ans) {
            ans=siz[fy];
        }
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    init();
    ans=1;
    while(m--) {
        int x,y;
        cin>>x>>y;
        join(x,y);
        // join(y,x);
    }
    cout<<ans<<endl;

    return 0;
}







Measured memory_bytes: 5220
#include <stdio.h>

int main ()
{
	int A, B, C, D;

	2 < A < 100;
	2 < B < 100;
		scanf ("%d", &A);
		scanf ("%d", &B);
	C = A - 1;
	D = B - 1;
		printf ("%d", C * D);
	return 0;
}

Measured memory_bytes: 128
x,n = map(int,input().split())
ans = float('inf')
find = -1

if n == 0:
    ans = x
    
else:
    p = list(map(int,input().split()))
    next = []
    next.append(x)
    while find == -1:
        y = next.pop(0)
        if all(y != p[i] for i in range(n)):
            ans = y
            find = 0
        else:
            if len(next) == 0:
                next.append(y - 1)
                next.append(y + 1)
            elif y < x:
                next.append(y - 1)
            else:
                next.append(y + 1)
        
print(ans)

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

int main() {
  	int A,B;
  	cin >> A >> B;
  
  	if( A >= B+1 )
      	cout << A + A - 1 << endl;
  	else if( A <= B-1 )
      	cout << B + B - 1 << endl;
  	else
      	cout << A + B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222





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

  vll a[MAX];
  vpll p;
  cin >> n >> m;
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    p.pb(pll(x, y));
    a[x].pb(y);
  }
  rep(i, n + 1) sort(all(a[i]));
  rep(i, m) {
    ll x = p[i].first, y = p[i].second;
    ans = lower_bound(all(a[x]), y) - a[x].begin();
    string t;
    s = to_string(x);
    t = to_string(ans + 1);
    rep(i, 6 - s.length()) cout << "0";
    cout << s;
    rep(i, 6 - t.length()) cout << "0";
    cout << t;
    cout << endl;
  }


	return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    vector<int> id(n), id2(n);
    for (int i = 1; i <= n; i++) {
        id.at(i - 1) = i;
        id2.at(i - 1) = i;
    }
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> q.at(i);
    }
    int pi = 1;
    if (p != id) {
        while (next_permutation(id.begin(), id.end())) {
            pi++;
            if (id == p) break;
        }
    }
    id = id2;
    int qi = 1;
    if (q != id) {
        while (next_permutation(id.begin(), id.end())) {
            qi++;
            if (id == q) break;
        }
    }
    cout << abs(pi - qi) << endl;
    return 0;
}

Measured memory_bytes: 3604
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

#include <iostream>

using namespace std;

void scans(string & str) {
	char c;
	scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {

	string s;
	scans(s);
	s.pop_back();
	while (s.substr(0, s.length() / 2) != s.substr(s.length() / 2, s.length() - 1) || s.length() % 2) {
		s.pop_back();
	}
	printf("%d\n", s.length());

 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n),b(100001,0);
  rep(i,n){
    cin >> a.at(i);
    b.at(a.at(i))++;
  }
  ll ans=0,maxi=0;
  for(int i=1;i<100000;i++){
    maxi=b.at(i-1)+b.at(i)+b.at(i+1);
    ans=max(ans,maxi);
  }
  cout << ans;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long


const int N=2e3+5;

int dp[N];

int solve(int n)
{
    if(n==0)
    {
        return 1;
    }
    if(n==1 or n==2)return 0;
    int &ans=dp[n];
    if(ans!=-1)return ans;
    int op=0;
    for(int i=n;i>=3;i--)
    {
        op+=solve(n-i);
        op%=mod;
    }
    return ans=op;
}


void solve()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof dp);
    int ans=solve(n);
    
     cout<<ans;
}   

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD ;
        a = (a * a)%MOD ;

        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
void solve(){

    ll n;
    cin>>n;
    ll a[n+1];
    for(int i =1;i<=n;i++){
        cin>>a[i];
    }
    ll ans = INF;
    for(ll x = -100;x<=100;x++){
        ll cur = 0;
        for(int i =1;i<=n;i++){
            cur += abs(a[i]-x)*abs(a[i]-x);
        }
        ans=min(ans,cur);
    }
    cout<<ans<<endl;
}




int main()
{
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }
     
 
 
    return 0;     
    
        
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

using namespace std;

int dp[100010][18];

int main(){
	int n;
	cin >> n;
	vector<int>x(n);
	rep(i,n)cin >> x[i];
	int l,q;
	cin >> l >> q;
	for(int k=0;k<18;k++){
		if(k==0){
			for(int i=0;i<n;i++){
				int p = lower_bound(x.begin(),x.end(),x[i]+l+1)-x.begin()-1;
				dp[i][0] = p;	
				//cerr << i << " " << p << endl;
			}
		}else{
			for(int i=0;i<n;i++){
				dp[i][k] = dp[dp[i][k-1]][k-1];
			}
		}
	}
	rep(zz,q){
		int a,b;
		cin >> a >> b;
		a--;b--;
		if(a>b)swap(a,b);
		int ans = 0;
		for(int k=17;k>=0;k--){
			if(dp[a][k]<b){
				ans += 1<<k;

				//cerr << a << " " << (1<<k) << " " << dp[a][k] << endl;
				a = dp[a][k];
			}
		}
		cout << ans+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int i=0;
  string s;
  int flag=0;
  
  for (i=0; i<N; i++){
    cin >> s;
    if (s == "Y"){
      flag =1;
    }
    if (i==N-1 && flag==1){
      cout << "Four" << endl;
    }
    else if(i==N-1 && flag ==0){
      cout << "Three" << endl;
    }
  }
  
}

Measured memory_bytes: 256
from collections import deque
N,Q= map(int, input().split())
tree = [[] for _ in range(N)]
counter = [0]*N
visited = [False]*N
q = deque([0])

for i in range(N-1):
    a,b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for i in range(Q):
    p,x = map(int, input().split())
    counter[p-1] += x

while q:
    parent = q.popleft()
    visited[parent] = True
    for child in tree[parent]:
        if visited[child]:
            continue
        counter[child] += counter[parent]
        q.append(child)
print(*counter)

Measured memory_bytes: 56084
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n + 1, 0);
	vector<int> ans(n + 1, 0);
	int ansV = 0;
	for (int i = 1; i < n + 1; i++)
	{
		cin >> a[i];
	}

	for (int i = n; i > 0; i--)
	{
		if (a[i] != ans[i] % 2)
		{
			for (int j = 1; j <= sqrt(i); j++)
			{
				if (i % j == 0)
				{
					ans[j]++;
					if (j != 0 && j * j != i)
					{
						ans[i / j]++;
					}
				}
			}

			b[i] = 1;
			ansV++;
			ans[i]++;
		}
		//for (int j = i; i > 0; j--)
		//{
		//	if()
		//}
	}

	cout << ansV << endl;
	for (int i = 1; i < n + 1; i++)
	{
		if (b[i] == 1)
		{
			cout << i;
			if (i < n)
			{
				cout << " ";
			}
		}
	}
	cout << endl;

}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N+1),B(N);
    for(int i=0;i<=N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> B[i];
    
    ll ans=0;
    for(int i=0;i<N;i++){
        ans+=min(B[i],A[i]);
        B[i]-=min(B[i],A[i]);
        if(B[i]!=0){
            ans+=min(B[i],A[i+1]);
            A[i+1]-=min(B[i],A[i+1]);
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1792
n = int(input())
hs = list(map(int, input().split()))

hs.insert(0, hs[0])

dp = [0] * len(hs)

for i in range(2, n+1):
  step1 = dp[i-1] + abs(hs[i]-hs[i-1])
  step2 = dp[i-2] + abs(hs[i]-hs[i-2])
  dp[i] = min([step1, step2])

print(dp[n])


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
    if(a==b){
       if(a!=c) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
       return 0;
	}
    if(a==c){
       if(a!=b) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
       return 0;
    }
    if(b==c){
       if(b!=a) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
       return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256