akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
    return 0;
}

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

int k;
int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 
			14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main()
{
	cin >> k;
	cout << a[k - 1] << endl;
}


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

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  int bus = 1;
  vector<int> t(n);
  for (int i = 0; i < n; i++) cin >> t[i];
  sort(t.begin(), t.end());
  //普通に考えたらc人ずつ乗せる、Ti+k(iはそのバスの1人目)になるなら締め切ってbus++
  int saisyonokata = -1, genkai = 0, machi = 0;//乗り場で最も待ってる人、その人の限界時刻、待ってる人の数
  for (int i = 0; i < n; i++) {
    if(saisyonokata == -1) {
      saisyonokata = i;
      genkai = t[i] + k;
    }
    machi++;
    if(genkai < t[i]) {//最も待ってる人の限界時間を迎えたら
      bus++;
      saisyonokata = i;
      genkai = t[i] + k;
      machi = 1;
    }else if(machi == c && i != n - 1) {//c人目の人がバス乗り場に来る、n番目の人なら処理不要
      bus++;
      machi = 0;
      saisyonokata = -1;
    }
  }
  cout << bus;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[55];
int main()
{
    ll ans = 0,n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    while(1)
    {
        ll maxx = -1;
        int k = 0;
        for(int i=1;i<=n;i++)
        {
            if(a[i] > maxx){
                maxx = a[i],k = i;
            }
        }
        if(maxx < n)
            break;
        for(int i=1;i<=n;i++)
        {
            if(k == i)
                a[i] = maxx%n;
            else
                a[i] += maxx/n;
        }
        ans += (maxx/n);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
vector<double> p;

// DP テーブル
double dp[3100][3100];

int main() {
    cin >> N;
    p.resize(N);
    for (int i = 0; i < N; ++i) cin >> p[i];

    // 初期条件
    dp[0][0] = 1.0;

    // DP ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    // 答え
    double res = 0.0;
    for (int j = (N+1)/2; j <= N; ++j) res += dp[N][j];
    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 72448
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<int> a(N);
    cin >> a;

    int ans = 0;
    while (1) {
        if (count(ALL(a), 0) == N) {
            break;
        }
        int l = INF;
        REP(i, N) {
            if (a[i] > 0 && l == INF) {
                l = i;
            }
            if (a[i] == 0 && l != INF) {
                REPF(j, l, i) {
                    a[j]--;
                }
                ans++;
                l = INF;
            }
        }
        if (l != INF) ans++;
        REPF(j, l, N) {
            a[j]--;
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX


int wid[2];

lli dats[2][1505]={};
vector<lli> sums[2];

int main(void){
  for(;;){
    
    scanf("%d%d",wid,wid+1);
    if(wid[0]==0)break;

    rep(i,2){
      sums[i].clear();
      reg(j,1,wid[i]){
	scanf("%lld",&dats[i][j]);
	dats[i][j]+=dats[i][j-1];
      }
      rep(j,wid[i]){
	reg(k,j+1,wid[i]){
	  sums[i].push_back(dats[i][k]-dats[i][j]);
	}
      }
      sort(sums[i].begin(),sums[i].end());
      /*
      rep(j,sums[i].size()){
	printf("sums %d .. %lld\n",i,sums[i][j]);
	}*/
    }

    
    int p1=0,p2=0;
    lli ans = 0;
    
    while(p1<sums[0].size()){
      int ns = sums[0][p1];
      lli s1=0,s2=0;
      while(p1<sums[0].size()){
	if(ns==sums[0][p1]){
	  s1++;
	  p1++;
	}
	else break;
      }
      while(p2<sums[1].size() && ns>=sums[1][p2]){
	if(ns==sums[1][p2])s2++;
	p2++;
      }

      ans += s1*s2;
    }

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


  
  return 0;
}

Measured memory_bytes: 29960
import java.io.*;
 
class Main
{
  public static void main(String args[])
  {
    int num;
    String buf;
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      buf = br.readLine();
      num = Integer.parseInt(buf);
      System.out.println(num * num * num);
    } catch(Exception e) {}
  }
}


Measured memory_bytes: 24208
def Parent(i, A = list):
    if i == A[i]:
        return i
    else:
        return Parent(A[i], A)

N, K, L = map(int, input().split())

#数字の小さい方を親ノードとする
Road = [int(_) for _ in range(N)]
Rail = [int(_) for _ in range(N)]
for i in range(K):
    p, q = map(int, input().split())
    p, q = p-1, q-1
    pP, qP = Parent(p, Road), Parent(q, Road)
    if pP <= qP:
        Road[qP] = pP
    else:
        Road[pP] = qP
for i in range(L):
    r, s = map(int, input().split())
    r, s = r-1, s-1
    rP, sP = Parent(r, Rail), Parent(s, Rail)
    if rP <= sP:
        Rail[sP] = rP
    else:
        Rail[rP] = sP

Parents, Count = [], {}
for i in range(N):
    roadP, railP = Parent(i, Road), Parent(i, Rail)
    Parents.append((roadP, railP))
    if (roadP, railP) in Count:
        Count[(roadP, railP)] += 1
    else:
        Count[(roadP, railP)] = 1

Ans = []
for i in range(N):
    Ans.append(Count[Parents[i]])
print(" ".join(map(str, Ans)))


Measured memory_bytes: 75728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	int n, m;
	cin >> n >> m;
	vector<int> ns(n);
	rep(i, n) ns.at(i) = -1;
	int f = 0;
	int hu = 0;
	rep(i, m){
      int k, su;
      cin >> k >> su;
      if(k != n) hu++;
      if(ns.at(k-1) == -1){
        ns.at(k-1) = su;
      }else{
      	if(ns.at(k-1) != su) f = 1;
      }
    } 
	/*for(int i=0; i<n-1; i++){
      if(ns.at(i) == -1){
      }else if(ns.at(i) != 0){
      	break;
      }else{
      	f = 1;
        break;
      }
    }
  */
	if(ns.at(0) == 0 && n != 1) f = 1;
	if(f == 1){
      cout << -1 << endl;
    }else{
      int a = 0;
      rep(i, n){
          if(ns.at(i) != -1){
              a += ns.at(i)*pow(10, n-i-1);
          }
      }
      if(a < pow(10, n-1) && n!= 1) a += pow(10, n-1);
      cout << a << endl;
    }
}

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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
#define lson node<<1
#define rson (node<<1)+1

const int maxn=1e6+10;
const ll mod=1e9+7;
const double pi=acos(-1);
//const int N=2e5+10;

int a[2][maxn];
int n;
int sum(int x,int p)
{
    int ans=0;
    while(x>0)
    {
        ans+=a[p][x];
        x-=x&(-x);
    }
    return ans;
}

void add(int x,int v,int p)
{
    while(x<=n)
    {
        a[p][x]+=v;
        x+=x&(-x);
    }
}

int main()
{
    int p=0;
    int k;
    sint2(n,k);
    for(int i=1;i<=n;i++)
    {
        int x;
        sint(x);
        add(max(i-x,1),1,p);
        add(min(i+x+1,n+1),-1,p);
    }
//    for(int i=0;i<n;i++)
//        cout<<sum(i,p)<<" ";
//    cout<<endl;
    while(k--)
    {
        int ok=1;
        int nx=(p+1)%2;
        for(int i=0;i<=n;i++)
            a[nx][i]=0;
        for(int i=1;i<=n;i++)
        {
            int s=sum(i,p);
            if(s!=n)
                ok=0;
            add(max(i-s,1),1,nx);
            add(min(i+s+1,n+1),-1,nx);
        }
        if(ok)
            break;
        p=nx;
    }
    for(int i=1;i<=n;i++)
        printf("%d ",sum(i,(p+1)%2));
    return 0;
}



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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 2e5 + 10;

typedef long long LL;

void chkmin(LL &x, LL y){ x = x < y ? x : y; }

struct Segment_Tree{
	
	LL Min[N << 2], Min_neg[N << 2], Min_pos[N << 2];

	#define lc (o << 1)
	#define rc (o << 1 | 1)
	#define M ((L + R) >> 1)

	void init(){
		memset(Min, 0x3f, sizeof Min);
		memset(Min_neg, 0x3f, sizeof Min_neg);
		memset(Min_pos, 0x3f, sizeof Min_pos);
	}

	void update(int o, int L, int R, int x, LL val){
		chkmin(Min[o], val);
		chkmin(Min_neg[o], val - x);
		chkmin(Min_pos[o], val + x);
		if(L ^ R){
			if(x <= M) update(lc, L, M, x, val);
			else update(rc, M + 1, R, x, val);
		}
	}

	LL query(LL *val, int o, int L, int R, int l, int r){
		if(l <= L && R <= r) return val[o];
		else{
			LL ret = 1ll << 60;
			if(l <= M) chkmin(ret, query(val, lc, L, M, l, r));
			if(r > M) chkmin(ret, query(val, rc, M + 1, R, l, r));
			return ret;
		}
	}

}T;

int n, q, A, B;
int X[N];

int main(){

	scanf("%d%d%d%d", &n, &q, &A, &B);
	For(i, 1, q) scanf("%d", &X[i]);

	LL sum = 0;
	T.init();
	T.update(1, 1, n, A, abs(B - X[1])), T.update(1, 1, n, B, abs(A - X[1]));

	For(i, 2, q){
		int d = abs(X[i] - X[i - 1]);
		sum += d;

		LL ret = min(T.query(T.Min_pos, 1, 1, n, X[i], n) - X[i],
					  T.query(T.Min_neg, 1, 1, n, 1, X[i]) + X[i]) - d;
		T.update(1, 1, n, X[i - 1], ret);
	}

	printf("%lld\n", T.Min[1] + sum);
	return 0;
}

Measured memory_bytes: 19840
s = input()
cnt = len(s)-1
ans = 0
for i in range(2 ** cnt):
  sign = [""] * cnt
  for j in range(cnt):
    if (i >> j & 1):
      sign[j] = "+"
  formula = ""
  for k in range(cnt):
    formula += s[k] + sign[k]
  formula += s[cnt]
  ans += eval(formula)
print(ans)

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

int main(){

    int K, X;
    cin >> K >> X;

    int minX, maxX;
    minX = X - K + 1;
    maxX = X + K - 1;

    int imax = maxX - minX + 1;
    for(int i = 0; i < imax - 1; i++){
        cout << minX + i << " ";
    }
    cout << maxX << endl;

    return 0;
}

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

int main(){
	vector<int> a(28); rep(i,28) cin >> a[i];

	rep(i,30){
		bool jud = true;
		rep(j,28){
			if(a[j] == i+1) jud = false;
		}
		if(jud) cout << i+1 << endl;
	}
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

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

    rep(i, s.size()-1){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }

    rep(i, s.size()-2){
        if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
a,b,c=map(int,input().split())
if (a>b):
    n=a
    a=b
    b=n
if (b>c):
    n=b
    b=c
    c=n
if (a>b):
    n=a
    a=b
    b=n
print(str(a)+" "+str(b)+" "+str(c))


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

using namespace std;

#define INF 1001001001  //int32_t
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,k;
    cin >>n>>k;

    vector<int> res(n+1);
    res[0] = 1;

    for (int i = 1; i <= n; i++){
        res[i] = min(res[i-1]*2 , res[i-1]+k);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << res[n] << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <tuple>
#include <numeric>

using namespace std;
int main(void)
{
  int N, M;
  cin >> N >> M;
  uint64_t A[100000];
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  sort(A, A + N);
  tuple<uint64_t, uint64_t> B_C[100000];
  for (int i = 0; i < M; i++)
  {
    uint64_t B, C;
    cin >> B >> C;
    get<0>(B_C[i]) = B;
    get<1>(B_C[i]) = C;
  }
  sort(B_C, B_C + M,
    [](tuple<uint64_t, uint64_t> const& l,
       tuple<uint64_t, uint64_t> const& r)
    {
      return get<1>(l) > get<1>(r);
    });
  int dstIdx = 0;
  for (int i = 0; i < M; i++)
  {
    const uint64_t B = get<0>(B_C[i]);
    const uint64_t C = get<1>(B_C[i]);
    for (int j = 0; j < B && dstIdx < N && A[dstIdx] < C; j++)
    {
      A[dstIdx] = C;
      dstIdx++;
    }
  }
  cout << accumulate(A, A + N, (uint64_t)0) << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string arr[500000];
string dis[500000];
bool cmp(string s1,string s2)
{
    return s1<s2;
}
int main()
{
    string str;
    int n;
    while(cin>>str>>n)
    {
        int strLen = str.length();
        int cnt = 0;
        for(int i = 1; i <= strLen; i ++)
        {
            for(int j = 1; j <= n; j ++)
            {

                if(i - 1 + j <= strLen)
                {
                    cnt++;
                    arr[cnt] = str.substr(i - 1,j);
                    //cout<<arr[cnt]<<endl;
                }

            }
        }
        sort(arr + 1, arr + cnt + 1, cmp);
//        cout<<cnt<<endl;
//        for(int i = 1; i <= cnt; i ++){
//            cout<<arr[i]<<endl;
//        }
        int cas = 1;
        dis[1] =arr[1];
        for(int i = 1; i <= cnt; i ++)
        {


            if(dis[cas] != arr[i])
            {
                cas++;
                dis[cas] = arr[i];

            }
//            cout<<arr[i]<<" ";
//            cout<<cas<<" "<<dis[cas]<<endl;



        }
//        for(int i = 1; i <= cas; i ++){
//            cout<<dis[i]<<endl;
//        }
        cout<<dis[n]<<endl;
    }
}


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

using namespace std;

int main(){

  vector <int> a;
  int N,b;
  int num[100000] = {0};
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> b;
    a.push_back(b);
  }
  //sort(a.begin,a.end);
  for(int i = 0;i < N;i++){
    num[a[i]]++;
  }

  int max = num[0]+num[1]+num[2];
  for(int i = 1;i < 99998;i++){
    int m;
    m = num[i]+num[i+1]+num[i+2];
    if(max < m){
      max = m;
    }
  }

  cout << max << endl;
  
}


Measured memory_bytes: 1276
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimize("02")
using namespace std;
const int mod=1e9+7;
const int maxn=1e3+5;
long long n,m,dp[maxn][maxn];
char c[maxn][maxn];
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n>>m;
	dp[1][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c[i][j];
			if(i==1){
				if(c[i][j]=='.'){
					dp[i][j]=dp[i][j-1];
				}
			}
			else{
				if(c[i][j]=='.'){
					dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
				}
			}
		}
	}
	cout<<dp[n][m];
}


Measured memory_bytes: 9088
#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);
    int x = n/100000000 + n/10000000%10 + n/1000000%10 + n/100000%10 + n/10000%10 + n/1000%10 + n/100%10 + n/10%10 + n%10;
    if(n % x == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  char buf[1024];
  int N,D;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &N, &D);

  int **X=(int **)malloc(sizeof(int *)*N);
  rep(i,N){
    X[i]=(int *)malloc(sizeof(int)*D);
  }

  rep(i,N){
    rep(j,D){
      scanf("%d",&X[i][j]);
    }
    int c=getchar();
  }

  // rep(i,N){
  //   rep(j,D){
  //     printf("%d ", X[i][j]);
  //   }
  //   printf("\n");
  // }

  int count=0;
  rep(i,N){
    srep(j,i+1,N){
      int dist=0;
      rep(k,D){
        dist+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      }
      int dist2=sqrt(dist);
      if(dist==dist2*dist2){
        count++;
      }
    }
  }

  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
   public static void main(String[] args) throws Exception {
      int [][] color={ {0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255} };
      String [] name ={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
      
      Scanner sc = new Scanner(System.in);
   
      while(sc.hasNext()){
          String str = sc.nextLine();
          if(str.equals("0")) break;
          String ans = "";
          double max = 0;
          for(int i=0;i<8;i++){
              double d = Math.sqrt( (Integer.parseInt(str.substring(1,3),16)-color[i][0])*(Integer.parseInt(str.substring(1,3),16)-color[i][0]) + (Integer.parseInt(str.substring(3,5),16)-color[i][1])*(Integer.parseInt(str.substring(3,5),16)-color[i][1]) + (Integer.parseInt(str.substring(5,7),16)-color[i][2])* (Integer.parseInt(str.substring(5,7),16)-color[i][2]));
              if(d>max){
                  max=d;
                  ans=name[7-i];
              }
          }
          System.out.println(ans);
      }
      
   }
}


Measured memory_bytes: 33188
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll fact(ll n) {
	ll res = 1;
	for (ll i = n; i >= 1; i--)
	{
		res = (res * i) % mod;
	}
	return res;
}

int main()
{
	ll N, M;
	cin >> N >> M;

	if (abs(N - M) > 1) {
		cout << 0 << endl;
	}
	else {
		ll n = fact(N);
		ll m = fact(M);

		if (N == M)
		{
			n = (2 * n) % mod;
		}
		cout << (m*n % mod) << 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.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            char[] S = ("0" + in.next() + "0").toCharArray();

            int[] dp = new int[N + 1];

            for (int i = 1; i < N; i++) {
                dp[i + 1] = Math.max(dp[i + 1], dp[i]);

                if (S[i - 1] == '1' && S[i] == '0' && S[i + 1] == '1') {
                    int j = i - 1;
                    while (j >= 1 && S[j] == '1') {
                        dp[i + 1] = Math.max(dp[i + 1], dp[j - 1] + (i + 1 - j - 1));
                        j--;
                    }

                    j = i + 1;

                    while (j <= N && S[j] == '1') {
                        dp[j] = Math.max(dp[j], dp[i - 2] + (j - (i - 1) - 1));
                        j++;
                    }
                }
            }

            out.println(dp[N]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 35780
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq
INF = 10**9

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
        return self.dist

h, w = map(int, input().split())
ch, cw = map(int, input().split())
ch -= 1; cw -= 1
dh, dw = map(int, input().split())
dh -= 1; dw -= 1
field = []
block_num = 0
for _ in range(h):
    line = input().rstrip()
    field.append(line)
    block_num += line.count("#")
if h * w == 10**6 and block_num < 1000:
    print(0)
    exit()

edge = [[] for _ in range(h * w)]
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            continue
        frm = i * w + j
        for dx in range(-2, 3):
            nx = i + dx
            if nx < 0 or nx > h - 1:
                continue
            for dy in range(-2, 3):
                if dx == 0 and dy == 0:
                    continue
                ny = j + dy
                if ny < 0 or ny > w - 1:
                    continue
                if field[nx][ny] == "#":
                    continue
                dist = abs(dx) + abs(dy)
                if dist == 1:
                    edge[frm].append((nx*w + ny, 0))
                else:
                    edge[frm].append((nx*w + ny, 1))
        
DIJK = Dijkstra(edge)
dist = DIJK.calc(ch * w + cw)
if dist[dh * w + dw] == INF:
    print(-1)
else:
    print(dist[dh * w + dw])

Measured memory_bytes: 353804
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long int
#define ff first
#define ss second
#define u128 __int128
#define pb push_back
 
#define N 200010
#define MOD 1000000007


int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	int a[n + 1][n + 1];
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 0; j < n - 1; ++j)
			cin >> a[i][j];
	}

	int po[n + 1] = {};
	int ans = 0;
	while(1)
	{
		int done[n + 1] = {}, f = 0;
		for(int i = 1; i <= n; ++i)
		{
			if(po[i] == n - 1)
				continue;
			int k = a[i][po[i]];
			if(a[k][po[k]] == i && done[i] == 0 && done[k] == 0)
			{
				f = 1;
				done[i] = done[k] = 1;
				po[i]++, po[k]++;
			}
		}

		if(f == 0)
			break;

		ans++;
	}
	for(int i = 1; i <= n; ++i)
	{
		if(po[i] != n - 1)
		{
			ans = -1; break;
		}
	}
	if(ans == 0)
		ans = -1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, ans = 0, a;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    ans += a % 2;
  }
  printf("%s", ans ? "first" : "second");
  return 0;
}

Measured memory_bytes: 128
# 2019/02/06
# AtCoder Beginner Contest110 - A

# Input
abc = list(map(int,input().split()))

max = -1
min = 10
maxidx = -1
minidx = -1

# Search max
for i in range(3):
    if abc[i] > max:
        max = abc[i]
        maxidx = i

# Max * 10
abc[maxidx] = abc[maxidx]*10

# Sum
ans = 0
for i in range(3):
    ans += abc[i]

# Output
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
// #include"../RollingHash.cpp"
#include<bits/stdc++.h>

namespace ProconLib{
    using Hash=__int128;
    
    template<typename Iter>
    class RollingHash{
        int N;
        const static Hash MOD=Hash(1e18l)+9;
        const static Hash A=Hash(1e12l)+39;
        std::vector<Hash> powA;
        std::vector<Hash> h;
        public:
        // RollingHash():N(xs.size()),powA(N+1),h(N+1){
        //     for(int i=0;i<N;i++) h[i+1]=(h[i]*A+xs[i])%MOD;
        //     powA[0]=1;
        //     for(int i=0;i+1<N;i++) powA[i+1]=(powA[i]*A)%MOD;
        // }
        RollingHash(Iter begin,Iter end):N(0),h(1,0){
            for(;begin!=end;begin++){
                h.push_back((h[N]*A+(*begin))%MOD);
                N++;
            }
            powA.resize(N+1);
            powA[0]=1;
            for(int i=0;i+1<=N;i++) powA[i+1]=(powA[i]*A)%MOD;
        }
        Hash get(int l,int r){
            return (h[r]+(MOD-(h[l]*powA[r-l])%MOD))%MOD;
        }
        Hash getA(){return A;}
        Hash getMOD(){return MOD;}
    };

    
};

using namespace std;
using namespace ProconLib;
int main(){
    string s;
    cin>>s;
    int q;
    cin>>q;
    RollingHash<string::iterator> rh(s.begin(),s.end());
    const Hash MOD=rh.getMOD();
    const Hash A=rh.getA();
    vector<Hash> powA(2*1e6);
    powA[0]=1;
    for(int i=0;i+1<powA.size();i++){
        powA[i+1]=powA[i]*A%MOD;
    }
    auto calc=[&](int l,int r,int l1,int r1,int l2,int r2,int t){
        Hash hv=(rh.get(l1,r1)*powA[r2-l2]+rh.get(l2,r2))%MOD;
        vector<Hash> rept(21);
        rept[0]=hv;
        for(int i=0;i<20;i++){
            if((1LL<<i)*t<=s.size()+1) rept[i+1]=(rept[i]*powA[(1LL<<i)*t]+rept[i])%MOD;
        }
        // cerr<<(long long)(rept[1])<<endl;
        // cerr<<(long long)(rh.get(0,6))<<endl;
        for(int i=20;i>=0;i--){
            long long ub=(1LL<<i)*t+l;
            if(ub>r) continue;
            Hash h=rh.get(l,ub);
            if(h==rept[i]){
                l=ub;
            }
        }
        int lb=l,ub=min(r,l+t)+1;
        while(ub-lb>1){
            int mid=(lb+ub)/2;
            int len=mid-l;
            Hash h=0;
            if(r1-l1<len){
                len=mid-l-(r1-l1);
                h=(rh.get(l1,r1)*powA[len]+rh.get(l2,l2+len))%MOD;
            }
            else{
                h=rh.get(l1,l1+len);
            }
            if(rh.get(l,mid)==h) lb=mid;
            else ub=mid;
        }
        return lb;
    };
    while(q--){
        int l,r,t;
        cin>>l>>r>>t;
        l--;
        int x=calc(l,r,l,l+t,l,l,t);
        x++;
        x=calc(x,r,(x-l)%t+l,l+t,l,(x-l)%t+l,t);
        int y=-1;
        if(l+2*t<=s.size()){
            y=calc(l,r,l+t,l+2*t,l,l,t);
            y++;
            y=calc(y,r,(y-l)%t+l+t,l+2*t,l+t,(y-l)%t+l+t,t);
        }
        cout<<((x>=r || y>=r) ? "Yes" : "No")<<endl;
    }

    return 0;    
}


Measured memory_bytes: 37680
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    
    vector<int> positive, negative;
    REP(i, 0, N) {
        int a; cin >> a;
        if (a < 0) negative.push_back(a);
        else positive.push_back(a);
    }

    sort(ALL(positive), greater<int>());
    sort(ALL(negative));
    if (positive.size() == 0) {
        positive.push_back(negative.back());
        negative.pop_back();
    }
    if(negative.size() == 0) {
        negative.push_back(positive.back());
        positive.pop_back();
    }

    vector<pair<int, int>> ans; int cur = negative[0];
    REP(i, 0, positive.size() - 1) {
        ans.push_back({cur, positive[i]});
        cur -= positive[i];
    }

    ans.push_back({positive.back(), cur});
    cur = positive.back() - cur;

    REP(i, 1, negative.size()) {
        ans.push_back({cur, negative[i]});
        cur -= negative[i];
    }
    
    cout << cur << endl;
    for (auto a : ans) cout << a.first << " " << a.second << endl;

    return 0;
}

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n;
int h[110000];
int dp[110000];

main(){
  cin>>n;
  rep(i,n){
    cin>>h[i];
  }

  dp[1]=abs(h[1]-h[0]);
  FOR(i,2,n){
    //cout<<dp[i-2]<< ' '<<dp[i-1]<<endl;
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    //cout<<dp[i]<<endl;
  }

  cout<<dp[n-1]<<endl;
}


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

int main()
{
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long ans = 0;
  if (A >= K)
  {
    ans += K;
  }
  else
  {
    ans += A;
    K -= A;
    if (B < K)
    {
      K -= B;
      ans -= K;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int dp[150][150];
int num[150];
bool cmp(int a,int b)
{
    return a<b;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>num[i];
    }
    sort(num,num+n,cmp);
    int sum=0;
    for(int i=0;i<n;i++)
        sum+=num[i];
    if(sum%10!=0)
        cout << sum <<endl;
    else
    {
        /*int pos=0;
        while(sum%10==0)
        {
            sum-=num[pos];
            pos++;
        }*/
        bool flag=0;
        for(int i=0;i<n;i++)
        {
            int temp=sum-num[i];
            if(temp%10!=0)
            {
                cout << temp <<endl;
                flag=1;
                return 0;
            }
        }
        if(!flag)
            cout << 0 << endl;
        //cout << sum << endl;
    }
    //cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,z,x,c;
string s;
map <string , long long> m;
int main()
{
   cin>>n;
   for(int i=1;i<=n;i++){
    cin>>s;
    m[s]++;
    z=max(z,m[s]);
   }
   for(auto it : m){
      if(it.second==z)cout<<it.first<<endl;
   }
}


Measured memory_bytes: 25216
S = input()
T = input()
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()

candidates = []
for i in range(len(S) - len(T) + 1):
    for c1,c2 in zip(S[i:i+len(T)], T):
        if c1 != '?' and c1 != c2:
            break
    else:
        cand = S[:i] + T + S[i+len(T):]
        candidates.append(cand.replace('?','a'))

if candidates:
    print(min(candidates))
else:
    print('UNRESTORABLE')


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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N=1e3+1, mod= 1e9+7;
ll dp[(1<<12)+1];
int a[N],b[N],n,m,tot=0;

ll calc(int mask){
	
	if(mask== (1<<n)-1 ) return 0;
	
	ll &ans=dp[mask];
	if(ans!=1e16) return ans;
	for(int i=0;i<m;i++){
		if( b[i]&(tot^mask) ){
			ans=min( ans, a[i]+calc(mask|b[i]) );
		}
	}
	
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	fill(dp,dp+(1<<12)+1,1e16);
	
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int p;
		cin>>a[i]>>p;
		int mask=0;
		for(int i=0;i<p;i++){
			int x;
			cin>>x;
			mask|=(1<<(x-1));
		}
		tot|=mask;
		b[i]=mask;
	}
	
	if(tot!=(1<<n)-1) cout<<"-1";
	else cout<<calc(0);
    
    yogeshk972();
}



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

int main()
{
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}

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

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

    string aa, bb;
    for (int i = 0; i < b; i++)
    {
        aa.push_back(a+'0');
    }
    for (int i = 0; i < a; i++)
    {
        bb.push_back(b+'0');
    }

    string ans = min(aa, bb);
    cout << ans << endl;

    return 0;
}

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

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

  int ans;
  if (a<b) ans=b+max(a,b-1);
  else ans=a+max(a-1,b);

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6+69;
const int base = 311;
// dung igt thay cho gt luc tinh giai thua
//
// cach tao hoan vi tu n so : n*(n+1)/2;

vector<ll>cur;
vector<ll>adj[e];
ll dist[e];

ll st, ed;

void djk()
{
    queue<ll>q;
    q.push(st);
    while(q.size() != 0)
    {
        ll x = q.front();
        q.pop();
        for(auto j : adj[x])
        {
            if(dist[j] > dist[x] + 1)
            {
                dist[j] = dist[x] + 1;
                q.push(j);
            }
        }
    }
}

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i=1; i<=3*n + 69; i++)
    {
        dist[i] = 1e18;
    }
    for(int i=1; i<=k; i++)
    {
        ll a, b;
        cin >> a >> b;
        adj[a].pb(b + n);
        adj[a+n].pb(b + 2*(n));
        adj[a + 2*(n )].pb(b);

    }
    cin >> st >> ed;
    dist[st] = 0;
    djk();
    if(dist[ed] == 1e18) cout << -1;
    else cout << dist[ed]/3;

}


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

int main() {
  string N, a, b, c, d;
  cin >> N;
  
  a = N.at(0);
  b = N.at(1);
  c = N.at(2);
  d = N.at(3);
  
  if ( b!=c ) {
  cout << "No" << endl;
  }
  if ( b==c ) {
    if ( ( a==b ) || ( c==d ) ) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
 
int max_sum(int a[],int as,int b[],int bs,int m){
    int j=bs-1;
    int res=0;
    for(int i=0;i<as;i++){
        while(0<=j && m<a[i]+b[j])j--;
        if(j==-1)break;
        res=max(res,a[i]+b[j]);
    }
    return res;
}
 
int p[1000],p2[1000*1001/2];
int main(){
    int n,m;
    while(cin>>n>>m,n||m){
        int ans=0;
        for(int i=0;i<n;i++){
            cin>>p[i];
            if(p[i]<=m)ans=max(ans,p[i]);
        }
        sort(p,p+n);
        int n2=0;
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                int a=p[i]+p[j];
                p2[n2++]=a;
                if(a<=m)ans=max(ans,a);
            }
        }
        sort(p2,p2+n2);
        ans=max(ans,max_sum(p,n,p2,n2,m));
        ans=max(ans,max_sum(p2,n2,p2,n2,m));
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int N;
	scanf("%d", &N);
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int x;
		scanf("%d", &x);
		if (i % 2 && x % 2) ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3792
n = int(input())
a = list(map(int, input().split()))
find_num = 1
break_num = 0
for i in range(n):
    if a[i] == find_num:
        find_num += 1
    else:
        break_num += 1
if break_num == n:
    print(-1)
else:
    print(break_num)


Measured memory_bytes: 26268
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
using namespace std;
int a[52];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	sort(a+1,a+n+1,cmp);
	int sum=0;
	for(int i=1;i<=m;i++) sum+=a[i];
	cout<<sum<<endl;
	return 0;
}


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

void LCS(string x, string y, int m, int n)
{
    int L[m+1][n+1];


    for(int i = 0; i <= m; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            if(i == 0 || j == 0) L[i][j] = 0;
            else if(x[i - 1] == y[j - 1]) L[i][j] = L[i-1][j-1] + 1;
            else L[i][j] = max(L[i][j-1],L[i-1][j]);
        }
    }

    int index = L[m][n];
    char lcs[index+1];

    lcs[index] = '\0'; // set terminating char
    int i = m, j = n;

    while(i>0 && j>0)
    {
        if(x[i - 1] == y[j - 1])
        {
            lcs[index - 1] = x[i - 1];
            i--,j--,index--;
        }
        else if(L[i - 1][j] > L[i][j - 1]) i--;
        else j--;
    }
    cout<<lcs<<"\n";
}

int main()
{
    string x,y;

    cin>>x>>y;

    //cout<<"x = "<<x<<", y = "<<y<<"\n";
    int m = x.length();
    int n = y.length();

    LCS(x,y,m,n);

}


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

typedef struct{
  double x;
  double y;
}Point;

void koch(Point,Point,int);
 
int main()
{

  Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%f %f\n",a.x,a.y);
  koch(a,b,n);
  printf("%f %f\n",b.x,b.y);

  return 0;
}

void koch(Point a,Point b,int n)
{

  if(n==0) return;

  Point s,t,u;

  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;

  koch(a,s,n-1);
  printf("%f %f\n",s.x,s.y);
  koch(s,u,n-1);
  printf("%f %f\n",u.x,u.y);
  koch(u,t,n-1);
  printf("%f %f\n",t.x,t.y);
  koch(t,b,n-1);
}

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

using namespace std;

int main()
{
  int k,i,j,n;
  int s = 0;
  cin >> n;

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
        s += __gcd(__gcd(i,j),k);
      }
    }
  }

  cout << s;

  return 0;
}


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

ll x, y, t, f[100];

int main(){
    cin >> x >> y;
    for (int i = 0; i < 65; i++) f[i] = pow(2, i);
    t = y/x;
    for (int i = 0; i < 65; i++){
        if (f[i] == t) {
            cout << i + 1;
            break;
        }
        else if (f[i] > t){
            cout << i;
            break;
        }
    }
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())    
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    count = 0
    before = -1
    for i in range(N):
        if before == A[i] - 1:
            count += C[A[i-1]-1]
        count += B[A[i]-1]
        before = A[i]
    print(count)

Measured memory_bytes: 3064
import sys
def main():
    input = sys.stdin.readline
    n,m,d = map(int, input().split())

    n_ud = max(0, n-2*d)
    ud = 2 if d != 0 else 1
    ans = 0
    for i in range(m-1):
        ans += n_ud*ud + (n-n_ud)
    print(ans/n/n)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define rint register int
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1e5+10;
const int inf=0x3f3f3f3f;

int n,cnt,ans;
int arr[maxn];

signed main(){
	scanf("%lld",&n);
	for(rint i=1;i<=n;++i) scanf("%lld",&arr[i]);
	for(rint i=1;i<=n;++i) if(arr[i]<0) ++cnt;
	for(rint i=1;i<=n;++i) ans+=abs(arr[i]);
	if(cnt%2==1){
		int mn=inf;
		for(rint i=1;i<=n;++i) mn=min(mn,abs(arr[i]));
		ans-=2*(abs(mn));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define forr(i,x,y) for(int i=x;i< y;i++)
#define sci(x) int x; cin>>x;
#define scii(x,y) int x,y; cin>>x>>y;
#define sciii(x,y,z) int x,y,z; cin>>x>>y>>z;
#define tc(x) sci(x); while(x--)
int main(){
    int k;
    string str;
    cin>>k>>str;
    if(str.length()<=k)cout<<str<<endl;
    else {
        for(int i=0;i<k;i++)cout<<str[i];
        cout<<"..."<<endl;
    }
    return 0;
}

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

int main() {
    int n, k, x, y, res = 0;
    cin >> n;
    cin >> k;
    cin >> x;
    cin >> y;
    for (int i = 1; i <= n; ++i) {
        if(i <= k) {
            res += x;
        } else {
            res += y;
        }
    }

    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

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

    int count=0,pt=1;
    vector<bool> check(n+1,false);
    bool reach=false;
    while(!reach){
        if(a[pt]==pt)break;
        if(check[pt])break;
        check[pt]=true;
        pt=a[pt];
        count++;
        if(pt==2)reach=true;
    }

    if(reach)cout << count << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	ll A, B, N, b;
	cin >> A >> B >> N;
	if(B>N) b = N;
	else b = B-1;
	ll max_x = 0;
	for(ll i = 0; i < 100000; i++)	max_x = max(max_x, A*(b-i)/B - A*((b-i)/B));
	cout << max_x << endl;
	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int r,g,b;

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

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

using namespace std;

int main(){

    int N,M,X;
    cin >> N >> M >> X;
    vector<int>A(M+1);
    for(int i=1;i<=M;i++) cin >> A[i];

    int left = 0;
    int right = 0;

    for(int i=1;i<=M;i++){
        if(A[i] < X)left++;
    }

    right = M - left;

    int z = min(left,right);
    cout << z << endl;
    
    return 0;
}


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

int main()
{
  int a[4], b[4];
  int n;
  while(1)
  {
    cin >> n;
    if(!n)
      break;
    while(n)
    {
      for(int i = 0; i < 4; i++)
        cin >> a[i];
      for(int i = 0; i < 4; i++)
        cin >> b[i];

      cout << a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3] << " "
           << a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2] << " "
           << a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1] << " "
           << a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0] << endl;
      n--;
    }
  }
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val xs = readLine()!!.split(" ").map(String::toInt)
    val sorted = xs.groupBy { it }.mapValues { it.value.size }.values.sorted()
    val ans = if (sorted.size <= k) 0 else sorted.slice(0 until (sorted.size - k)).sum()
    println(ans)
}


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

int main() {
	int n;
	cin >> n;
	vector<int> C(n);
	int md = 0;
	rep(i, n) {
		int x;
		cin >> x;
		C[x]++;
		if (i == 0 && x != 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	if (C[0] != 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < C[i]; j++) {
			ans *= C[i-1];
			ans %= 998244353;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3752