akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
int main(){
    int h,w,k; cin>>h>>w>>k;
    vector<vector<long>> dp(h+1,vector<long>(w,0));
    dp[0][0]=1;
    int num[]={1,2,3,5,8,13,21};
    for(int i=1;i<=h;i++){
        for(int j=0;j<w;j++){
            int l=j-1,r=w-1-(j+1);
            if(l<0)
                l=0;
            if(r<0)
                r=0;
            int n=num[r]*num[l];
            int a=num[r];
            if(l-1>=0)
                a*=num[l-1];
            int b=num[l];
            if(r-1>=0)
                b*=num[r-1];
            if(j-1>=0)
                dp[i][j-1]+=(dp[i-1][j]*a)%INF;
            if(j+1<w)
                dp[i][j+1]+=(dp[i-1][j]*b)%INF;
            dp[i][j]+=(dp[i-1][j]*n)%INF;
        }
    }
    cout<<dp[h][k-1]%INF;
}

Measured memory_bytes: 256
/*  ex3_4
    potter0723sw  */

//方針：Nを１〜９で割ってみて商が１〜９かつ余りが０か調べる

#include <stdio.h>

int main(void) {
	int N,quotient,remainder,d;//dはdevide
	scanf("%d", &N);
	d = 1;
	while(d <= 9){//1~9まで調べる
		quotient = N / d;//商
		remainder = N % d;//余り
    	if(quotient >= 1 && quotient <= 9 && remainder == 0){//商が１〜９かつ余りが０
			printf("Yes\n");
			break;//Yesを出力してwhile脱出
		}
		d += 1;
	}
	if(d == 10){//１〜９まで試してダメだった場合d=10なのでその時にNoを出力
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
import copy
N, M = map(int, input().split())
S_array = list(map(int, input().split()))
T_array = list(map(int, input().split()))

mod = 10**9 + 7

add_num_array = [0] * N
ans_array = [0] * (N + 1)
ans_old = [1] * (N + 1)

for t in T_array:
    ans_array[0] = 1
    for i, s in enumerate(S_array):
        if s == t:
            add_num_array[i] = (add_num_array[i] + ans_old[i]) % mod
        ans_array[i + 1] = (ans_array[i] + add_num_array[i]) % mod
    ans_old = copy.deepcopy(ans_array)
    # print(ans_array)
print(ans_array[-1])

Measured memory_bytes: 119644
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

// 151-d
int main() {
    int s, w;
    cin >> s >> w;
    if (w >= s)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    ios_base::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    vector<pair<int, int> > sp;
    vector<vector<bool> > b(h, vector<bool> (w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#' && !b[i][j]) {
                sp.push_back({1, 0});
                b[i][j] = true;
                queue<pair<pair<int, int>, bool> > q;
                q.push({{i, j}, 1});
                while(!q.empty()) {
                    pair<int, int> v = q.front().first;
                    bool color = q.front().second;
  //                  cout << v.first << " " << v.second << " " << color << endl;
                    q.pop();
                    for (int k = 0; k < 4; k++) {
                        int x = v.first + dx[k];
                        int y = v.second + dy[k];
                        if (0 <= x && x < h && 0 <= y && y < w && !b[x][y]) {
                            if (color && s[x][y] == '.') {
                                sp.back().second++;
                                q.push({{x, y}, !color});
                                b[x][y] = true;
                            }
                            else if (!color && s[x][y] == '#') {
                                q.push({{x, y}, !color});
                                b[x][y] = true;
                                sp.back().first++;
                            }
                        }
                    }
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < sp.size(); i++) {
        ans += 1ll*sp[i].first*sp[i].second;
    }
    cout << ans;
    return 0;
}

 

Measured memory_bytes: 2680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;



int main()
{
    int N;
    cin >> N;
    double n_;
    n_ = sqrt(N);
    int N_ = (int)n_;
    cout << N_ * N_ << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int a;
        cin >> a;
        if (a != i) cnt++;
    }
    YES(cnt == 2 || cnt == 0);
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
using namespace std;

int main() {
    string snuke = "snuke";
    int A, B;
    char c = 65;    // A
    if (scanf("%d %d", &A, &B) < 2) return 0;

    char tmp[8];
    bool flg = false;
    for (int i = 0; i < A; i++)
    {
        for (int j = 0; j < B; j++)
        {
            if (scanf("%s", tmp) < 1) return 0;
            if (tmp == snuke)
            {
                c = c + j;
                printf("%c%d\n", c, i + 1);
                flg = true;
                break;
            }
        }
        if (flg) break;
    }
    return 0;
}


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

int main() {
  int N;
  set<int> S;
  cin >> N;
  for (int i=0; i < N; i++) {
 	int input;
    cin >> input;
    S.insert(input);
  }
  
  cout << S.size() << endl;

}

Measured memory_bytes: 3580
#include "bits/stdc++.h"
using namespace std;
template<class  T> inline bool chmin(T& a,T b)
{
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const long long INF = 1LL << 60;
int N;
long long h[100010];
long long dp[100010];

long long rec(int i) {
	if (dp[i] < INF) return dp[i];
	if (i == 0) return 0;

	long long res = INF;
	chmin(res, rec(i - 1) + abs(h[i] - h[i - 1]));
	if (i > 1) chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]));

	return dp[i] = res;
}

int main(){
    int N; cin >> N;
	for (int i = 0; i < N; i++)	cin >> h[i];
	for (int i = 0; i < 100010; ++i) dp[i] = INF;

	cout << rec(N - 1) << endl;

}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    vector<int> rg(n);
    rg[n-1]=a[n-1];
    for(int i = n-2; i >=0 ; i--) {
        rg[i] = __gcd(rg[i+1],a[i+1]);
    }
    lg[0]=rg[0];
    rg[n-1]=lg[n-1];

//    for(int i = 0; i < n; i++) {
//        cout << lg[i] << " ";
//    }
//    cout << "\n";
//    for(int i = 0; i < n; i++) {
//        cout << rg[i] << " ";
//    }
//    cout << "\n";

    int ans=0;
    int tm;
    for(int i = 0; i < n; i++) {
        tm=__gcd(lg[i],rg[i]);
        ans=max(tm,ans);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int r, g; cin >> r >> g;
  cout << g * 2 - r << "\n";
  return 0;
}


Measured memory_bytes: 256
import fractions

N=int(input())
alist=list(map(int,input().split()))

lcm=1
for a in alist:
  lcm=lcm*a//fractions.gcd(lcm,a)
  
#print(lcm)
answer=0
for a in alist:
  answer+=(lcm-1)%a
  
print(answer)


Measured memory_bytes: 5432
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int x;
  cin >> x;
  cout <<(x<1200?"ABC":"ARC") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int data[100];
  int v;
  int i;
  for(i = 0;i < n;i++){
    cin >> data[i];
  }
  for(i = 1;i < n;i++){
    v = data[i];
    for(int j = 0;j < n - 1;j++){
      cout << data[j] << " ";
    }
    cout << data[n - 1] << endl; 
    int j = i - 1;
    while(v < data[j] && j >= 0){
      data[j + 1] = data[j];
      j--;
    }
    data[j + 1] = v;
  }
  for(i = 0;i < n - 1;i++){
    cout << data[i] << " ";
  }
  cout << data[i] << endl;
  return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
string str;
int n,k,a[MAXN];
int main()
{
    cin>>str;
    n=(int)str.size();
    int now=0,cnt=0;
    ll ans=0;
    while(now<n)
    {
        if(str[now]=='A') {cnt++; now++;}
        else if(str[now]=='B'&&now!=n-1&&str[now+1]=='C') {ans+=cnt; now+=2;}
        else {cnt=0; now++;}
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 640
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);

  trace(A, n);
  for ( j = 2; j <= n; j++ ){
    int key = A[j];
    int i = j - 1;
    while( i > 0 && A[i] > key ){
      A[i+1] = A[i];
      i--;
    }
    A[i+1] = key;

    trace(A, n);
  }

  return 0;
}




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

int main(void) {
	// your code goes here
	char a[101],b[101];
	gets(a);
	gets(b);
	int l=	strlen(a),x = strlen(b),i = 0;
	if(l<x)
	printf("LESS");
	else if(l>x)
	printf("GREATER");
	else
	{
	for(i = 0;a[i]!='\0';i++)
	{
		if(a[i]>b[i])
		{
			printf("GREATER");
			break;
		}
		else if(a[i]<b[i])
		{printf("LESS");
		break;
		}
		
	
	}
	if(a[i]=='\0')
	printf("EQUAL");
	}
	return 0;
}


Measured memory_bytes: 128
import sys

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    ans = []
    a = (sum(A[::2]) - sum(A[1::2]))//2
    ans.append(2*a)
    for i in range(N-1):
        b = A[i] - a
        ans.append(2*b)
        a = b

    print(*ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14108
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)((n) - 1); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define sqrt sqrtl
#define fill(x,y) memset(x,y,sizeof(x))
#define length(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) for(intl i = 0; i < length(a);i++)cin >> a[i]
#define debug(x) cout << #x << ":" << x << endl
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    intl a[3];
    cin(i,a);
    sort(a, a + 3);
    fp(!(a[0] + a[1] - a[2]));
    return 0;
}

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


int N, M, L;
vector<vi> near;

int BFS(int s, int t){
  int dist[300];
  rep(i,N) dist[i] = -1;
  queue<int> que;

  dist[s] = 0;
  que.push(s);

  while (!que.empty()){
    int v = que.front(); que.pop();

    for (int nv: near[v]){
      if (dist[nv] != -1) continue;
      if (v == s) dist[nv] = 0;
      else dist[nv] = dist[v] + 1;
      if (nv == t) return dist[nv];
      que.push(nv);
    }
  }
  return -1;
}

int main(){
  cin >> N >> M >> L;
  near.resize(N);
  ll dist[300][300];
  rep(i,N) rep(j,N){
    if (i == j) dist[i][j] = 0;
    else dist[i][j] = INF;
  }
  rep(i, M){
    int A, B, C; cin >> A >> B >> C;
    dist[A-1][B-1] = C;
    dist[B-1][A-1] = C;
  }

  rep(k,N) rep(i,N) rep(j,N) if (dist[i][j] > dist[i][k] + dist[k][j]) dist[i][j] = dist[i][k] + dist[k][j];

  rep(i,N-1) {
    for (int j=i+1; j<N; j++) {
      if (dist[i][j] <= L){
        near[i].push_back(j);
        near[j].push_back(i);
      }
    }
  }

  int Q; cin >> Q;
  rep(i,Q){
    int s, t; cin >> s >> t;
    cout << BFS(s-1, t-1) << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
typedef pair<int,int> P;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

vector<P> g[111111];
int d[111111];

void dfs(int v=0,int p=0){
  if(d[v]!=-1)return;
  d[v]=p;
  for(int i=0;i<g[v].size();i++){
    int to=g[v][i].fi;
    int cost=g[v][i].se;
    dfs(to,(cost+p)%2);
  }
}

signed main(){
  int n;
  cin>>n;
  fill_n(d,111111,-1);
  rep(i,n-1){
    int u,v,w;
    cin>>u>>v>>w;
    u--,v--;
    g[u].pb(P(v,w));
    g[v].pb(P(u,w));
  }
  dfs();
  rep(i,n)cout<<d[i]<<endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int pay;
    while(pay < n){pay += 1000;}
    cout << pay - n << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		if(s==t){
			cout<<"Yes"<<endl;
			return 0;
		}
		else{
			string u=s;
			for(int j=0;j<s.size();j++){
				s[j] = u[(j+1)%s.size()];
			}
		}
	}
	cout<<"No"<<endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  double n;
  cin >> n;

  int x = (n + (1.08 - 0.01)) / 1.08;
  if ((int)n == (int)(x * 1.08)) {
    cout << x << '\n';
  } else {
    cout << ":(" << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main()
{
    int n, m, i;
    int j;
    int sum = 0;
    int t[N], p[N], x[N];
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &t[i]);
        sum += t[i];
    }
    scanf("%d", &m);
    for (i = 0; i < m; ++i)
        scanf("%d%d", &p[i], &x[i]);

    for (i = 0; i < m; ++i)
    {
        j = p[i] - 1;
        printf("%d\n", sum + x[i] - t[j]);
    }
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;
const ll INF = 1LL << 60;
const double PI = acos(-1.0);



int main() {
	double n, m, d;
	cin >> n >> m >> d;
	double ans = (n - d)*(m - 1) / (n*n);
	if (d != 0)ans *= 2.0;
	cout <<fixed<<setprecision(6)<< ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(ll i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
// const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll INF = 1e18L + 5;
#define mod 1000000007
 
const int mxN = 5e3 + 1;
ll p[mxN];
ll c[mxN];
ll n, M;
 
 
int main()
{
FIO
 
    cin >> n >> M;
    FOR(n) cin >> p[i];
    FOR(n) cin >> c[i];
    ll ans = -INF;
    Rep(i,1,n)
    {
        ll j = p[i];
        vt<ll> vec;
        ll moves = M;
        vt<bool> vis(n+1, 0);
        while(!vis[j])
        {
            vis[j] = 1;
            j = p[j];
        }
        ll k = p[i];
        ll cur = 0;
        // cout << j << endl;
        while(k != j && moves)
        {
            cur += c[k];
            ans = max(ans, cur);
            // cout << cur << endl;
            moves--;
        }
        ll stable = cur;
        if(!moves) continue;
        vec.pb(c[j]);
        k = p[j];
        while(k != j)
        {
            vec.pb(vec.back() + c[k]);
            k = p[k];
        }
        ll temp = moves / sz(vec);
        cur += temp * vec.back();
        ll id = moves % sz(vec);
        // ans = max(ans, cur);
        if(id) 
            ans = max(ans, cur + *max_element(vec.begin(), vec.begin() + id));
        if(moves /sz(vec))
        {
            ll maxi = *max_element(all(vec));
            ans = max(ans, max(stable, cur - vec.back()) + maxi);
        }
        else
            ans = max(ans, stable + *max_element(vec.begin(), vec.begin() + id));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3788
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
      
      Scanner in = new Scanner(System.in);
      int k = in.nextInt();
		int[] a = {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};
      
       
		
      System.out.println(a[k-1]);
      
    }
}


Measured memory_bytes: 23636
import numpy as np
h, w = map(int, input().split())
grid = np.array([list(input()) for _ in range(h)])
new_grid = np.zeros(grid.shape, dtype='object')

dx = [1, 0, -1, 0, 1, 1, -1, -1]
dy = [0, 1, 0, -1, 1, -1, 1, -1]
for x in range(h):
    for y in range(w):
        if grid[x, y] == '#':
            new_grid[x, y] = '#'
        else:
            cnt = 0
            for i in range(8):
                nx = x + dx[i]
                ny = y + dy[i]
                if nx >= 0 and nx < h and ny >= 0 and ny < w:
                    if grid[nx, ny] == '#':
                        cnt += 1
            new_grid[x, y] = str(cnt)
for i in range(h):
    print(''.join(new_grid[i]))

Measured memory_bytes: 12516
#coding utf-8
from collections import deque
S = input()
T = input()

s = len(S)
t = len(T)

word =[]

for i in range(s):
  for j in range(t):
    if S[i+j:i+j+1] =="?" or S[i+j:i+j+1]==T[j:j+1]:
      if j==t-1:
        tmp = S[0:i]+T+S[i+j+1:]
        for k in range(s):
          if tmp[k:k+1] =="?":
            tmp =tmp[0:k]+"a"+tmp[k+1:]
        word.append(tmp)
    else:
      break

word.sort()

if not word:
  print("UNRESTORABLE")
else:
  print(word[0])
  



Measured memory_bytes: 3316
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    String str = sc.next();
    boolean test = true;

    for(int i=0; i < A; i++){
        if(Character.isDigit(str.charAt(i))){
            
        }else{
            test = false;
            break;
        }
    }
    for(int i=A+1; i < A+B+1; i++){
        if(Character.isDigit(str.charAt(i))){
            
        }else{
            test = false;
            break;
        }
    }
    if(str.matches(".*"+"-"+".*")){
         
    }else{
        test = false;
    }
    if(test){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }
  }
}

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

int main() {
  string a;
  cin >> a;
  
  if(a=="Sunny")
    cout << "Cloudy" << endl;
  if(a=="Cloudy")
    cout<<"Rainy"<<endl;
   if(a=="Rainy")
    cout<<"Sunny"<<endl;
    
    
    }
  
    

Measured memory_bytes: 256
N, M, C = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
res = 0
for _ in range(N):
    if sum([x*y for x, y in zip([int(i) for i in input().split()], B)]) + C > 0:
        res += 1
print(res)


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<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>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double 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 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define mp make_pair


int main() {
  pii a, b;
  cin >> a.first >> a.second >> b.first >> b.second;
  pii vec = b - a;
  vec = pii(-vec.second, vec.first);
  pii c = b + vec;
  cout << c.first << " " << c.second << " ";
  vec = pii(-vec.second, vec.first);
  c = c + vec;
  cout << c.first << " " << c.second << endl;
}  
         
                                        
     
                            
                            


Measured memory_bytes: 256
import java.util.*;
public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        long[] a = new long[n];
        for(int i=0; i<n; i++){
            a[i] = Long.parseLong(sc.next());
        }
        
        long z = (long)1e18;
        
        Arrays.sort(a);
        long ans = 1;
        for(int i=0; i<n; i++){
            if(a[i]==0){
                System.out.println(0);
                return;
            }
            if(z/a[i]<ans){
                System.out.println(-1);
                return;
            }
            ans *= a[i];
        }
        
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 61004
N = int(input())
A = [int(input()) for i in range(N)]
V = 1
ans = 0
for i in range(N):
    #print(V, ans)
    if(A[i] > V):
        t = (A[i]-1)//V
        ans += t
        A[i] -= V*t
        if(A[i]+1 > V):
            A[i] = 1
    V = max(V,A[i]+1)
    
print(ans)


Measured memory_bytes: 7200
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = 1ll << 60;
ll h[100010];
ll dp[100010];

int main()
{

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

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

    for (int i = 0; i < 100010; ++i)
        dp[i] = INF;
    dp[0] = 0;

    for (int i = 0; i < n; ++i)
    {
        for (int j = 1; j <= k; ++j)
        {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[n - 1];

    return 0;
}

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

using namespace std;

int main()
{
	string a, b, c;
	double ans;
	cin >> a >> b;
	c = a + b;
	ans = sqrt(stoi(c));
	if (ceil(ans) == floor(ans)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
/* 
    Author : Jeff Ahn
    Sun 14 Jun 2020 01:28:26 PM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const map<T,T> &vec){ os<< "{"; for (auto p : vec) os << "(" << p.first << "," << p.second << "), "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_map<T,T>&vec){ os<< "{"; for (auto p : vec) os << "(" << p.first << "," << p.second << "), "; os << "}"; return os; }


signed main() {
  fastio;
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if (!a)
    cout << 1 << endl;
  else if (!b) 
    cout << 2 << endl;
  else if (!c) 
    cout << 3 << endl;
  else if (!d) 
    cout << 4 << endl;
  else if (!e) 
    cout << 5 << endl;
  
}


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

int Parent(int x){return x / 2;}
int Left(int x) {return 2 * x;}
int right(int x){return 2 * x + 1;}

int main(){

  int H;
  int i, l, r, p, A[252];
  cin >> H;
  rep(i,H) cin >> A[i + 1];
  for(i = 1; i <= H ; i ++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(Parent(i) >= 1) cout << "parent key = " << A[Parent(i)] << ", ";
    if(Left(i) <= H) cout << "left key = " << A[Left(i)]<< ", ";
    if(right(i) <=H)cout << "right key = " << A[right(i)]<< ", ";
    cout << endl;
  }



  return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,x;
    scanf("%d",&n);
 
    for(int i = 1; i<= n; i++)
    {
        if(i%3 == 0){
            printf(" %d",i);
        }else{
            x = i;
            do{
                if(x%10 == 3){
                    printf(" %d",i);
                    break;
                }
                x /=10;
            }while(x);
        }
    }
    printf("\n");
}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	int h, w,d;
	cin >> h >> w >>d;
	map<int,P> mp;
	rep(i,h){
		rep(j,w){
			int a;
			cin >> a;
			mp[a] = {i,j};
		}
	}
	vector<int> cost[d+1];
	for(int i = 1; i <= d; i++) {
		cost[i].push_back(0);
		int ind = i;
		int bef = 0;
		while(ind + d <= h * w){
			P from = mp[ind];
			P to = mp[ind + d];
			int to_next = 0;
			to_next = abs(from.first - to.first) + abs(from.second - to.second);
			//debug(to_next);
			cost[i].push_back(bef + to_next);
			bef += to_next;
			ind += d;
		}
		//for(auto x:cost[i]){
		//	cout << x <<" ";
		//} cout << endl;
	}
	int q;
	cin >> q;
	rep(i,q){
		int l, r;
		cin >> l >> r;
		int root = l %d;
		if(root == 0)root+= d; // cost[root]を見る
		// l ,  rまで行くまでに何回か
		int toL = (l + d - 1) / d - 1; 
		int toR = (r + d - 1) / d - 1; 
	//	debug(toL);
	//	debug(toR);
	//	debug(cost[root][toL]);
	//	debug(cost[root][toR]);
		cout << cost[root][toR] - cost[root][toL] << endl;
	}
}


Measured memory_bytes: 11008
#include <iostream>
#include <algorithm>
#include <utility>
#include <fstream>
#include <iomanip>
#include <complex>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int N = 3e6 + 5, inf = 1e9, mod = 1e9 + 7;
using namespace std;

int n, a[25][25];
ll dp[25][N];

ll solve(int row, int mask)
{
    if(row == n)
        return 1;
    if(dp[row][mask] != -1)
        return dp[row][mask];
    ll ret = 0;
    for(int col = 0; col < n; col++)
    {
        if(a[row][col] && !((1 << col) & mask))
            ret = (ret + solve(row + 1, mask | (1 << col))) % mod;
    }
    return dp[row][mask] = ret;
}

int main()
{
    IO
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> a[i][j];
    cout << solve(0, 0) << '\n';
    return 0;
}

Measured memory_bytes: 589572
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        List<int> list = new List<int>();
        for (int i = 0; i < N; i++) list.Add(NextInt());
        for (int i = 0; i < N; i++)
        {
            if (i + 1 < list[i]) { Console.WriteLine(-1); return; }
        }
        List<int> answer = new List<int>();
        bool[] done = Enumerable.Repeat(true, N).ToArray();
        for (int i = 0; i < N; i++)
        {
            int max_index = 0;
            int count = 0;
            for (int j = 0; j < N; j++) {
                if (done[j]) count++;
                if (list[j] == count && done[j]) {
                    max_index = j;
                }
            }
            answer.Add(list[max_index]);
            done[max_index] = false;
        }
        answer.Reverse();
        answer.ForEach(Console.WriteLine);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13524
import math
n,d=map(int,input().split())
x=[0]*n
y=[0]*n
a=0
for i in range(n):
	x[i],y[i]=map(int,input().split())
	if math.sqrt(x[i]*x[i]+y[i]*y[i])<=d:
		a+=1
print(a)


Measured memory_bytes: 24620
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 300 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k;

int main(){
    ios;
    cin>>n;
    int ans=0;
    rep(i,1,n){
        int x; cin>>x;
        if(i&1){
            if(x&1) ++ans;
        }
    }
    cout<<ans;
    return 0;
}
/*


*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 3616
import java.util.*;
import java.io.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        // int t = sc.nextInt();
        
        // while(t-->0){
            int k = sc.nextInt();
            String s = sc.next();
            if(s.length() > k){
                System.out.println(s.substring(0, k) + "...");
            } else{
                System.out.println(s);
            }
        // }
    }
}

Measured memory_bytes: 38584
#include<stdio.h>
#include<string.h>
int main(){
  char x[8];
  scanf("%s",x);
  if(strcmp(x,"Sunny") == 0)printf("Cloudy");
  else if(strcmp(x,"Cloudy") == 0)printf("Rainy");
  else if(strcmp(x,"Rainy") == 0)printf("Sunny");
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c;
    scanf("%d/%d/%d", &a, &b, &c);
    if (b <= 4) cout << "Heisei";
    else cout << "TBD";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
string a[2],b;
string s[2][1001];
int p[2];
void dfs(int x){
  r(i,a[x].size()){
    if(a[x][i]=='"'){
      i++;s[x][p[x]]+='"';
      while(i<a[x].size()&&a[x][i]!='"')s[x][p[x]]+=a[x][i++];
      p[x]++;
    }else{
      while(i<a[x].size()&&a[x][i]!='"')s[x][p[x]]+=a[x][i++];
      p[x]++;
      i--;
    }
  }
}
main(){
  while(cin>>a[0],a[0]!="."){
    cin>>a[1];
    p[0]=p[1]=0;
    r(i,2)r(j,1001)s[i][j]="";
    r(i,2)dfs(i);
    if(p[0]!=p[1])cout<<"DIFFERENT"<<endl;
    else{
      int f1=0,f2=0;
      r(i,p[0])if(s[0][i]!=s[1][i]){
        if(s[0][i][0]=='"'&&s[1][i][0]=='"')f1++;
        else f2++;
      }
      if(f2||f1>1)cout<<"DIFFERENT"<<endl;
      else if(f1)cout<<"CLOSE"<<endl;
      else cout<<"IDENTICAL"<<endl;
    }
  }
}

Measured memory_bytes: 3180
//Catchharsh
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    #define see(x) cout<<#x<<" = "<<x<<endl
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (ll x,ll n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    int main()
    {   
         IOS;
         ll n1,m1,n2,m2,i,j,k;
         string s;
         cin>>m1>>n1>>m2>>n2;

         if(m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12)
         {
          if(n1==31) cout<<1;
          else cout<<0;
         }
         else
         {
          if(m1==2&& n1==28) return cout<<1,0;
          else if(m1==2&&n1!=28) return cout<<0,0;
           if(n1==30) cout<<1;
           else
            cout<<0;
         }

         
         cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
    }

Measured memory_bytes: 256
def main():
    from collections import Counter
    N = int(input())
    A = list(map(int,input().split()))

    ans = 0
    countA = Counter(A)

    ans = 0

    num_odd = 0
    for v in countA.values():
        if v % 2 == 1:
            ans += 1
        else:
            num_odd += 1
    if num_odd % 2 == 0:
        ans += num_odd
    else:
        ans += num_odd -1


    print(ans)

main()

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

int main(){
  int a,b,c,d,e,na,nb,nc;

  while(cin >> a >> b >> c >> d >> e,a){
    cin >> na >> nb >> nc;

    if(d<=nc){
      cout << a*na + b*nb + e*nc << endl;
    }else{
      int res = a*na + b*nb + c*nc;
      for(int i=0;i<=d;i++){
	res = std::min(res,a*na + b*nb + e*d);
	(nc)?nc--:((nb)?nb--:na--);
	if(na<0)break;
      }
      cout << res << endl;
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>  // std::greater<T>()

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) *min_element(ALL(vec))
#define MAX(vec) *max_element(ALL(vec))
#define SUM(vec) accumulate(ALL((vec)), 0)  // 第3引数は初期値

// func declaration
template <class T> void printVec(vector<T>);
template <class T> void calcVec(vector<T>&, int, char);
bool checkMultiple(vector<int>&, int);

// const
const int INF = 10000000;

/*MEMO
辞書順
abc < abcd, atcoder < atlas
*/

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> vec(N);
    REP(i, N) cin >> vec.at(i);
    int sum = SUM(vec);
    int min = MIN(vec);
    int nokori = (X - sum) / min;
    cout << N + nokori << endl;

    return 0;
}


// function
template <class T> void printVec(vector<T> vec) {
    // 1要素ずつ、空白・改行なしで出力
    REP(i, vec.size()) {
        cout << vec.at(i);
    }
    cout << endl;
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    if (ch == '+') {
        REP(i, vec.size()) {
            vec.at(i) += num;
        }
    } else if (ch == '-') {
        REP(i, vec.size()) {
            vec.at(i) -= num;
        }
    } else if (ch == '*') {
        REP(i, vec.size()) {
            vec.at(i) *= num;
        }
    } else if (ch == '/'){
        REP(i, vec.size()) {
            vec.at(i) /= num;
        }
    } else if (ch == '%') {
        REP(i, vec.size()) {
            vec.at(i) %= num;
        }
    }
}

bool checkMultiple(vector<int> &vec, int num) {
    // vecの中身が、numの倍数かどうかのチェック
    int count = 0;
    REP(i, vec.size()) {
        if (vec.at(i)%num != 0) count++;
    }
    return (count == 0);
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(max(a,c) - min(a,c) <= d){
    cout << "Yes";
    return 0;
  }
  else if(max(a,b) - min(a,b) <= d && max(c,b) - min(c,b) <= d ){
   cout << "Yes";
    return 0;
  }
  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1,n-1):
    second = p[i]
    scope = sorted([ p[i-1], p[i], p[i+1] ])
    if scope[0] < second and second < scope[2]:
        cnt += 1

print(cnt)

Measured memory_bytes: 9156
#include <iostream>

using namespace std;

long long n, ans=1, a[1005];
void f(int p) {
    int i;
    for(i=2; p>1; ) {
        if(p % i == 0) {
            a[i]++;
            p /= i;
        } else {
            i++;
        }
    }
}

void g(int p) {
    int i;
    for(i=2; p>1; i++) {
        while(p % i == 0) {
            a[i]++;
            p /= i;
        }
    }
}

int main()
{
    int i;
    cin >> n;
    for(i=2; i<=n; i++) {
        g(i);
    }
    for(i=2; i<=n; i++) {
        ans = ans * (a[i]+1) % 1000000007;
    }
    cout << ans;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int n1 = N/1000, n2 = N/100 - n1*10, n3 = N/10 - n1*100 - n2*10,n4 = N%10;
  if ( (n1 == n2 && n2 == n3) || (n2 == n3 && n3 == n4) ) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(size_t i=0;i<(size_t)(n);i++)
#define rrep(i,n) for(size_t i=(size_t)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

void dfs(int v, const vector<vi> &g, vi &used){
  if(used[v]) return;
  used[v] = 1;
  for(auto u : g[v]) dfs(u,g,used);
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<vi> g(n+m);
  rep(i,n){
    int k; cin >> k;
    rep(j,k){
      int l; cin >> l;
      g[i].eb(l-1 + n);
      g[l-1 + n].eb(i);
    }
  }

  vi used(n+m,0);
  dfs(0,g,used);
  rep(i,n){
    if(used[i] == 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<bool> x(10,1);
    for(int i=0;i<k;i++)
    {
        int d;
        cin >> d;
        x[d]=0;
    }
    for(int i=n;;i++)
    {
        bool ok=1;
        int a=i;
        while(a)
        {
            ok&=(x[a%10]);
            a/=10;
        }
        if(ok)
        {
            cout << i << "\n";
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256