akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;
using ll=long long;
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
 
int main() {

string N;
int n=0;
int nmax=0;
int ans=0;
  cin >> N;

  for(int i=0;i<N.size();i++){
    if(N[i]=='T'){
      n++;
      if(n>nmax){nmax=n;}
    }else{
      n--;
    }
  }



 
  cout << nmax*2<< endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int a, b;

	cin >> a >> b;

	if (a > b)
	{
		printf("a > b\n");
	}
	else if (a < b)
	{
		printf("a < b\n");
	} else {
		printf("a == b\n");
	}

	return 0;
}

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

#define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define ll unsigned long long

int main(){
	fast
	ll n;
	cin>>n;
	
	ll cnt=0;
	n--;
	
	for(int i = 1; i <n; i++)
	{
		cnt+=n/i;
	}
	cnt+=1;
	cout << cnt;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#ifdef LL
const ll inf = 1e9;
#else 
const ll inf = 1e18;
#endif

const int mod = 1e9 + 7;
const int mod2 = 998244353;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T mod){ a+=b; if(a>=mod){ a-=mod; } }
template <typename T>
T to_upper(T s){ transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
template <typename T>
T to_lower(T s){ transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }



int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

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

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

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

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

    cout<<dp[n]<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007

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

    ll n, m;
    cin >> n >> m;
    vector<ll> v(n, 0);
    vector<ll> pre(n + 1, 0);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());

    for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + v[i - 1];

    // debug
    // cout << "sorted array: ";
    // for (auto ii : v) cout << ii << " ";
    // cout << "\n presum: ";
    // for (auto ii : pre) cout << ii << " ";
    // cout << endl;

    ll lo = 2, hi = 200001;
    ll hap, cnt;

    while (hi - lo > 1) {
        ll c = (lo + hi) / 2;
        // debug
        // cout << "checking " << c << endl;
        cnt = 0;
        hap = 0;
        // minimum happiness for each handshake is c
        for (int i = 0; i < n; i++) {
            auto it = lower_bound(v.begin(), v.end(), c - v[i]);
            cnt += v.end() - it;
            int ind = it - v.begin();
            // debug
            // cout << i << " " << ind << endl;
            // cout << "count: +" << (v.end() - it) << endl;
            // cout << "hap: +" << (pre[n] - pre[ind] + (n - ind) * v[i]) << endl;
            hap += pre[n] - pre[ind] + (n - ind) * v[i];
        }
        // debug
        // cout << "total shakes: " << cnt << endl;
        if (cnt >= m) {
            lo = c;
        } else {
            hi = c;
        }
    }

    hap -= (cnt - m) * lo;

    cout << hap;

    return 0;
}

Measured memory_bytes: 1792
//
// Created by yamunaku on 2019/12/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    int ans=0;
    rep(i,n){
        if(a[i] == ans + 1) ans++;
    }
    if(ans==0) cout << -1 << endl;
    else cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] line = Console.ReadLine().Split(' ');
		int N = int.Parse(line[0]);
		int M = int.Parse(line[1]);
		int[] An = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

		int votes = An.Sum();
		int limit = votes / (4*M);;
		if(votes % (4*M) != 0){
				limit ++;
		}

		int counter = 0;
		bool can_choose = false;

		for(int i=0; i<N; i++){
				if(An[i] >= limit){
						counter ++;
				}
				if(counter >= M){
						can_choose = true;
						break;
				}
		}

		if(can_choose){
				Console.WriteLine("Yes");
		}else{
				Console.WriteLine("No");
		}
	}
}



Measured memory_bytes: 13396
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
vector<int> a;
int b[100000];
int c;
int k;
long long s;
int p, q;
int n, m;
int x, y, z;
c = 0;
	s = 0;
	q = 0;
	z = 0;
	s = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &k);
		s = s + k;
		a.push_back(k);
	}
	sort(a.begin(), a.end());
	z = 0;
	for (int i = n - 1; i>=0; i--){
		s = s - a[i];
		if (s * 2 < a[i]){
			z = n - i;
			break;
		}
	}


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

	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

// Knapsack
long long dp[100][100000]={0};

int main(int argc, char const *argv[]){
    int n, w;
    long long h[100][2];
    cin >> n >> w;
    for(int i=0;i<n;i++){
        cin >> h[i][0] >> h[i][1];
    }
    for(int j=h[0][0];j<=w;j++){
        dp[0][j]=h[0][1];
    }
    for(int i=1;i<n;i++){
        for (int j = 0; j <=w; ++j) {
            if(j<h[i][0]){
                dp[i][j]=dp[i-1][j];
                continue;
            }
            long long value=h[i][1];
            long long weight=h[i][0];
            chmax(dp[i][j], dp[i-1][j-weight] + value);
            chmax(dp[i][j], dp[i-1][j]);
        }
    }
    cout << dp[n-1][w] << endl;
}



Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main() {
    scanf("%lld %lld %lld",&a,&b,&c);
    if (a%2==0||b%2==0||c%2==0) printf("0\n");
    else printf("%lld\n",min(a*b,min(a*c,b*c)));
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  string s;cin>>s;
  rep(i,3) {
    if(s[i]=='1') s[i]='9';
    else if(s[i]=='9') s[i]='1';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
N,X,Y = list(map(int,input().split()))


ansli = [0] * (N)
for i in range(1,N):
    for j in range(i+1,N+1):
        ansli[min(abs(j-i),abs(X-i)+1+abs(Y-j))]+=1

for k in range(N):
    if k==0:
        continue

    print(ansli[k])

Measured memory_bytes: 3444
#include <stdio.h> 
int main(void) { 
int a,b,i; 
char op; 
for(i=1;i>0;i++){ 
scanf("%d %c %d",&a,&op,&b); 
if(op=='+') {printf("%d\n",a+b); 
}
else if(op=='-') 
{
printf("%d\n",a-b); 
}
else if(op=='*') 
{
printf("%d\n",a*b); 
}
else if(op=='/')
{ 
printf("%d\n",a/b); 
}else if(op=='?') 
{ break; 
} 
} 
return 0; 
} 





Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
	int a,p;
    cin>>a>>p;
    OUT((a*3+p)/2);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int cnt;

void insertionSort(int *A, int n, int g){

	int i, v, j;

	for(i=g; i<=n-1; i++){
		v=A[i];
		j=i-g;

		while(0<=j && v<A[j]){
			A[j+g]=A[j];
			j=j-g;
			cnt++;
		}
		A[j+g]=v;
	}
}

void shellSort(int *A, int n){

	int g[500], i;

	g[0]=1;
  int m=0;
  cnt=0;
	for(m=1; 3*g[m-1]+1<n+1; m++)
  {
    g[m]=g[m-1]*3+1;
  }
	printf("%d\n", m);

	for(i=m-1; i>=0; i--) {
		if(i!=0){printf("%d ", g[i]);}
    	else{printf("%d\n", g[i]);}
		insertionSort(A, n, g[i]);
 	}
}

int main(){
	int n;
	scanf("%d", &n);
	int A[n];
	for(int k=0; k<n; k++){
		scanf("%d", &A[k]);
	}
	shellSort(A, n);
	printf("%d\n", cnt);
	for(int l=0; l<n; l++)
  {
    printf("%d\n", A[l]);
  }

}



Measured memory_bytes: 5632
import numpy as np
k = int(input())
ab = input()
ab = ab.split()
[a, b] = ab
a, b = int(a), int(b)
a_k = a // k
b_k = b // k
if(b_k > a_k or a % k == 0 or b % k == 0):
  print('OK')
else:
  print('NG')

Measured memory_bytes: 27144
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a > b {
		fmt.Println("a > b")
	} else if a < b {
		fmt.Println("a < b")
	} else {
		fmt.Println("a == b")
	}
}


Measured memory_bytes: 1124
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int n;
int a[1 << 18], b[1 << 18];
int as[1 << 18], bs[1 << 18];
int ac[1 << 18], bc[1 << 18];
vector<int> am, bm;
vector<int> ds, dy[1 << 18];
int nds, ads, si[1 << 18];

int main() {
	scanf("%d", &n);
	cont(i, n) scanf("%d", a + i);
	cont(i, n) scanf("%d", b + i);
	cont(i, n) as[a[i]]++, bs[b[i]]++;
	int mxc = 0, sh = 0, sr = 0, sm = -1, sid;
	loop(i, 1 << 18) {
		if(as[i] + bs[i] > n) return 0 & puts("No");
		while(as[i] > bs[i]) ac[i]++, as[i]--;
		while(bs[i] > as[i]) bc[i]++, bs[i]--;
		cont(j, as[i]) sh++;
	}
	loop(i, 1 << 18) {
		if(as[i] > sh / 2) {
			while(as[i] > sh / 2) {
				as[i]--, bs[i]--;
				ac[i]++, bc[i]++;
				sh--;
			}
			sm = i;
		}
		sr = max(sr, ac[i]);
		sr = max(sr, bc[i]);
		if(sr == ac[i] || sr == bc[i]) sid = i;
	}
	if(~sm) sid = sm, sr = bc[sm];
	loop(i, ac[sid]) am.pub(sid);
	loop(i, bc[sid]) bm.pub(sid);
	loop(i, 1 << 18) if(i != sid) {
		loop(j, ac[i]) am.pub(i);
		loop(j, bc[i]) bm.pub(i);
	}
	loop(i, 1 << 18) {
		cont(j, as[i]) ds.pub(i);
		mxc = max(mxc, as[i]);
	}
	nds = ds.size(); ads = am.size();
	loop(i, nds) dy[ds[i]].pub(ds[(i + mxc) % nds]);
	loop(i, ads) dy[am[i]].pub(bm[(i + sr) % ads]);
	cont(i, n) {
		b[i] = dy[a[i]][si[a[i]]++];
	}
	puts("Yes");
	cont(i, n) printf("%d%c", b[i], " \n"[i == n]);
	return 0;
}


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

int main(){
	int A, B, Q; cin >> A >> B >> Q;

	vector<long long> s(A+2), t(B+2);
	for(int i=1; i<A+1; ++i) cin >> s[i];
	for(int i=1; i<B+1; ++i) cin >> t[i];
	s[0] = t[0] = -1e18;
	s[A+1] = t[B+1] = 1e18;

	while(Q--){
		long long X; cin >> X;
		auto NS = lower_bound(s.begin(), s.end(), X), NT = lower_bound(t.begin(), t.end(), X);
		auto nextS = *NS, nextT = *NT, prevS = *(NS-1), prevT = *(NT-1);

		long long ans = numeric_limits<long long>::max();
		
		ans = min(ans, max(nextS - X, nextT - X));
		ans = min(ans, max(X - prevS, X - prevT));
		ans = min(ans, X - 2*prevT + nextS);
		ans = min(ans, X - 2*prevS + nextT);
		ans = min(ans, -X + 2*nextT - prevS);
		ans = min(ans, -X + 2*nextS - prevT);

		cout << ans << endl;
	}
}


Measured memory_bytes: 2944
import java.io.*;

class Main {
	public static void main(String[] arg)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] div = br.readLine().split(" ");
		int a = Integer.parseInt(div[0]);
		int b = Integer.parseInt(div[1]);
		double c = Math.toRadians(Integer.parseInt(div[2]));

		double S = a*b*Math.sin(c)/2;
		double L = a+b+Math.sqrt(a*a+b*b-2*a*b*Math.cos(c));
		double H = b*Math.sin(c);
		System.out.printf("%.8f\n%.8f\n%.8f\n",S,L,H);
	}
}

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

int p[18][100000], v[100000], d[100000];
vector<int>E[100000];
int lca(int u, int v) {
	if (d[u] > d[v])swap(u, v);
	rep(i, 18) {
		if ((d[v] - d[u]) >> i & 1)v = p[i][v];
	}
	if (u == v)return u;
	for (int i = 17; i >= 0; i--) {
		if (p[i][u] != p[i][v]) {
			u = p[i][u]; v = p[i][v];
		}
	}
	return p[0][u];
}
int main() {
	int n; scanf("%d", &n);
	p[0][0] = -1;
	for (int i = 1; i < n; i++) {
		scanf("%d", &p[0][i]); p[0][i]--;
		E[p[0][i]].push_back(i);
	}
	int c = 0;
	queue<int>que;
	memset(d, -1, sizeof(d));
	d[0] = 0; que.push(0);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		v[c++] = p;
		for (int v : E[p]) {
			if (d[v] == -1) {
				d[v] = d[p] + 1; que.push(v);
			}
		}
	}
	for (int i = 1; i < 18; i++) {
		rep(j, n) {
			if (p[i - 1][j] == -1)p[i][j] = -1;
			else p[i][j] = p[i - 1][p[i - 1][j]];
		}
	}
	ll sum = 0;
	rep(i, n - 1) {
		int u = lca(v[i], v[i + 1]);
		sum += d[v[i]] - d[u] + d[v[i + 1]] - d[u];
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 16564
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc088/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int c[3][3];
    int dup[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> c[i][j];
            dup[i][j] = c[i][j];
        }
    }
    rep(i, 3){
        rep(j, 3){
            dup[i][j] -= c[2][j];
        }
    }
    rep(i, 3){
        if(dup[i][0] != dup[i][1] || dup[i][1] != dup[i][2] || dup[i][2] != dup[i][0]){
            cout << "No" << "\n";
            return 0;
        }
    }
    rep(i, 3){
        rep(j, 3){
            dup[i][j] = c[i][j];
        }
    }
    rep(i, 3){
        rep(j, 3){
            dup[i][j] -= c[i][2];
        }
    }
    rep(i, 3){
        if(dup[0][i] != dup[1][i] || dup[1][i] != dup[2][i] || dup[2][i] != dup[0][i]){
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int []arr=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=scn.nextInt();
		}
		int idx=0;
		long tot=0;
		int  min=Integer.MAX_VALUE;
		for(int i=0;i<n;i++) {
			if(arr[i]<0) {
				idx++;
				idx%=2;
			}
			tot+=Math.abs(arr[i]);
			if(min>Math.abs(arr[i])) {
				min=Math.abs(arr[i]);
			}
			//System.out.println(tot);
		}
		//System.out.println(idx+" "+min+" "+tot);
		if(idx%2!=0)
		System.out.println(tot-2*min);
		else {
			System.out.println(tot);
		}
	}

}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

signed main() {
  int n;
  cin >> n;

  vvi cnt(10, vi(10));
  rep(i, 1, n+1){
    int t = i%10, s;
    int tmp = i;
    while(tmp){
      s = tmp%10;
      tmp /= 10;
    }
    cnt[s][t]++;
  }

  int ans = 0;
  rep(i, 1, 10) rep(j, 1, 10){
    ans += cnt[i][j] * cnt[j][i];
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

// ALDS1_8_A
public class Main {
	Node root = null;
	
	void preParse(Node node) {
		if (node == null) return;
		System.out.print(" " + node.number);
		preParse(node.left);
		preParse(node.right);
	}
	
	void inParse(Node node) {
		if (node == null) return;
		inParse(node.left);
		System.out.print(" " + node.number);
		inParse(node.right);
	}
	
	void postParse(Node node) {
		if (node == null) return;
		postParse(node.left);
		postParse(node.right);
		System.out.print(" " + node.number);
	}
	
	void insert(List T, Node node) {
		Node y = null;
		Node x = root;
		while (x != null) {
			y = x;
			if (node.number < x.number) x = x.left;
			else x = x.right;
		}
		node.parent = y;
		if (y == null) root = node;
		else if (node.number < y.number) y.left = node;
		else y.right = node;
	}
	
	void run() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		List<Node> T = new LinkedList<Node>();
		for (int i = 0; i < n; i++) {
			String str = br.readLine();
			switch(str.charAt(0)) {
			case 'i':
				Node node = new Node(Integer.parseInt(str.split(" ")[1]));
				insert(T, node);
				break;
			case 'p':
				inParse(root);
				System.out.println();
				preParse(root);
				System.out.println();
				break;
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}

class Node {
	int number;
	Node parent = null;
	Node left = null;
	Node right = null;
	Node(int number) {
		this.number = number;
	}
}


Measured memory_bytes: 149032
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def COM(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod

mod = 10**9+7

K = int(input())
S = input()
N = len(S)
max = N+K
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
modlist1 = []
modlist2 = []
a = 1
b = 1
for i in range(K+1):
    modlist1.append(a)
    modlist2.append(b)
    a = a*26%mod
    b = b*25%mod

ans = 0
for i in range(K+1):
    x = COM(N+K-i-1,N-1)
    y = modlist1[i]
    z = modlist2[K-i]
    xyz = ((x*y%mod)*z)%mod
    ans = (ans+xyz)%mod
print(ans)


Measured memory_bytes: 214940
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    N, T = MI()
    cur = int(10**9)

    for i in range(N):
        c, t = MI()
        if t <= T and cur > c:
            cur = c

    if cur == 10**9:
        print('TLE')
    else:
        print(cur)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65004
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> //tuple<ll,ll,ll>
#define pr(x) cout << x << endl;
using namespace std;

int main(){
 int n; cin >> n;
 int sum=0;
 int tmp=n;
 while(tmp>0){
   sum+=tmp%10;
   tmp/=10;
 }
 if(n%sum==0) cout << "Yes" << endl;
 else pr("No"); 
return 0;
}


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

struct Card { char suit,value; };

void bubble( struct Card A[], int N){
  for(int i=0;i<N;i++){
    for(int j = N -1;j >= i;j--){
      if(A[j].value < A[j-1].value){
	Card t = A[j]; A[j] = A[j-1];A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N){
  for(int i =0;i<N;i++){
    int minj = i;
    for(int j =i;j<N;j++){
      if(A[j].value < A[minj].value)minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N){
  for(int i = 0;i<N;i++){
    if(i > 0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[], int N){
  for(int i = 0;i<N;i++){
    if(C1[i].suit != C2[i].suit)return false;
  }
  return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i = 0;i<N;i++){
    C2[i] = C1[i];
  }

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }
  else{
    cout << "Not stable" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>

int main()
{
	long long A;
	char B[6];
	scanf("%lld", &A);
	scanf("%s", B);
	
	int i, b = 0;
	for (i = 0; B[i] != 0; i++) if (B[i] != '.') b = b * 10 + (B[i] - '0');
	printf("%lld\n", A * b / 100);
	fflush(stdout);
	return 0;
}

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

int V;
vector<int> G[200];

int bfs(int r, int group[]) {
    int res = 0;
    queue<int> q;
    q.push(r);
    group[r] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i = 0; i < G[v].size(); i++) {
            int to = G[v][i];
            if (group[to] != -1 && abs(group[to] - group[v]) != 1) return -1;
            if (group[to] == -1) {
                res = group[to] = group[v] + 1;
                q.push(to);
            }
        }
    }
    return res;
}

int main() {
    int ans = 0;
    cin >> V;
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            char c;
            cin >> c;
            if (c == '1') G[i].push_back(j);
        }
    }
    for (int i = 0; i < V; i++) {
        int group[200], cnt;
        fill(group, group + 200, -1);
        cnt = bfs(i, group);
        if (cnt == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, cnt + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const int N = 1e2+9, M = 1e5+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
int n,k,a[N];
LL memo[N][M];
LL solve(int i=0,int rem=k)
{
  if(rem==0) return 1;
  if(rem<0 || i==n) return 0;
  
  LL &ret = memo[i][rem];
  if(~ret) return ret;

  ret =(solve(i+1,rem)%MOD+solve(i,rem-1)%MOD-solve(i+1,rem-a[i]-1)%MOD+MOD)%MOD;
  return ret; 
}
int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;++i) scanf("%d",a+i);
  printf("%lld",solve());
  
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 91648
n = int(input())

dist = [[0] * n for _ in range(n)]
town = []
for i in range(n):
   x, y = map(int, input().split())
   town.append([x, y])

for i in range(n):
   for j in range(i+1, n):
      d = ((town[i][0]-town[j][0])**2+(town[i][1]-town[j][1])**2)**0.5
      dist[i][j] = d
      dist[j][i] = d

dist2 = [sum(x) for x in dist]
print(sum(dist2)/n)


Measured memory_bytes: 3064
def cnct(lint,lim):
    global list753
    global list357
    lint1int=lint*10+3
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2int=lint*10+5
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3int=lint*10+7
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 

list753=[3,5,7]
list357=set()
k=int(input())
for b in list753:
    cnct(b,k)
print(len([x for x in list357 if list(str(x)).count("3")>0 and list(str(x)).count("5")>0 and list(str(x)).count("7")>0]))

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

int main() {
  int N, K, A = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    if(A < K)
    A *= 2;
    else
    A += K;
  }
  cout << A;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int N, Q, A[200020], B[200020], C[200020];
struct str{
	str(int s, int e, int l):s(s), e(e), l(l){}
	int s, e, l;
	bool operator<(const str &o)const{
		return l < o.l;
	}
};

vector <str> E;
int P[200020];
int p[200020];
int Find(int x){
	return p[x] == x ? x : p[x] = Find(p[x]);
}

void solve(){
	scanf("%d%d", &N, &Q);
	rep(i, N)P[i] = 2e9;
	for(int i=1;i<=Q;i++){
		scanf("%d%d%d", A+i, B+i, C+i);
		E.emplace_back(A[i], B[i], C[i]);
		P[A[i]] = min(P[A[i]], C[i] + 1);
		P[B[i]] = min(P[B[i]], C[i] + 2);
	}
	for(int i=1;i<N+N;i++){
		P[i%N] = min(P[(i-1)%N] + 2, P[i%N]);
	}
	rep(i, N)E.emplace_back(i, (i+1)%N, P[i]), p[i] = i;
	sort(all(E));
	ll ans = 0;
	for(auto e : E){
		int x = Find(e.s), y = Find(e.e);
		if(x != y)p[x] = y, ans += e.l;
	}
	printf("%lld", ans);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 998244353;
const ll MAX = 3e3+23;
const ll inf = 1e18+7;


int main(){
  fastio;
  ll q;
  string s;
  cin>>s>>q;
  bool flag =0;
  while(q--){
    ll t;
    cin>>t;
    if(t==1) flag = !flag;
    else{
        ll k;
        string c;
        cin>>k>>c;
        if(k==1){
            if(flag) s+=c;
            else s.insert(0,c);
        }else{
            if(!flag) s+=c;
            else s.insert(0,c);
        }
    }
  }
  if(flag) reverse(all(s));
  cout<<s<<"\n";
  return 0; 
}

Measured memory_bytes: 3836
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int i;
    string s;
    vector<int>v;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='0')
            v.push_back(0);
       else if(s[i]=='1')
            v.push_back(1);
        else
        {
            if(v.empty())
                continue;
            else
                v.pop_back();
        }
    }
    for(i=0;i<v.size();i++)
        cout<<v[i];
    cout<<"\n";

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a.substr(a.size()-1,1) == b.substr(0,1)&& b.substr(b.size() - 1, 1) == c.substr(0, 1)) {
			cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;



#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 3000000+10;
#define endl '\n'
#define int ll
ll power(ll x, ll n) {
	ll res = 1;
	for (; n > 0; n >>= 1) {
	if (n & 1) res = (res * x) % mod;
	x = (x * x) % mod;
	}
	return res;
}
const int ALPHA = 26;
vector<vector<int>> trie;
bool dfs(int u)
{	
	bool check =0;
	for(int i= 0;i<26;i++)
	{
		if(trie[u][i]!=-1)
		{	
			
			bool k = (!(dfs(trie[u][i])));
			check|=k;
		}
	}
	return check;
}
bool dfs1(int u)
{	
	bool check =0;
	bool child = false;
	for(int i= 0;i<26;i++)
	{
		if(trie[u][i]!=-1)
		{	
			child = true;
			bool k = (!(dfs1(trie[u][i])));
			check|=k;
		}
	}
	if(!child)
		return true;
	return check;
}
int32_t main()
{   

    IOS 
	string s;
	cin>>s;
	string a = s.substr(0,(s.size()-1)/2);
	string b = (s.substr((s.size()+3)/2 - 1));
	bool check = (s==(string(s.rbegin(),s.rend())));
	bool check1 = (a==(string(a.rbegin(),a.rend())));
	bool check2 = (b==(string(b.rbegin(),b.rend())));
	if(check&&check1&&check2)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	
   
		
	  


    
	
    
    
   
     
       
    

 
}






Measured memory_bytes: 256
a, b, k = map(int,input().split())
if b-a+1 >= 2*k:
    aa = [a+i for i in range(k)]
    bb = [b-i for i in range(k)]
    cc = sorted(aa+bb)
    for s in cc:
        print(s)
else:
    for s in range(a,b+1):
        print(s)


Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll C, ll mod){
  ll ans = 1; C = min(C, N - C);
  for (ll i = 1; i <= C; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}


int main(){
  int N; cin >> N;
  vector <int> ans(N + 1);
  fill(ans.begin(), ans.end(), -1);
  ans[0] = 0;

  vector <int> cand;
  int now = 1;
  while (now <= N){
    cand.push_back(now);
    now *= 6;
  }
  now = 1;
  while (now <= N){
    cand.push_back(now);
    now *= 9;
  }
  
  queue <int> que; que.push(0);
  while (!que.empty()){
    int now = que.front(); que.pop();

    for (int i = 0; i < cand.size(); i++){
      if (now + cand[i] > N) continue;
      int next = now + cand[i];

      if (ans[next] == -1){
        que.push(next);
        ans[next] = ans[now] + 1;
      }
    }
  }
  cout << ans[N] << endl;


  return 0;
}


Measured memory_bytes: 768
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    for i in n..1000 {
    	if i % 111 == 0 {
        	println!("{}", i);
            return;
        }
    }
    println!("1111");
}

Measured memory_bytes: 4352
#include <stdio.h>
int main(void){
    int N,k,sum,M=0;
    scanf("%d",&N);
    int a[N+1];
    int b[N+1];
    int c[N+1];
    for(int i=1;i<=N;i++){
        scanf("%d",&a[i]);
    }
    
    for(int j=N;j>0;j--){
        if(j>N/2){
            b[j]=a[j];
        }else{
        k = 2*j ;
        sum =0;
        while(k<=N){
            sum = (sum + b[k])%2;
            k+=j;
        }
        b[j] = (a[j] +sum)%2;
        }
        if(b[j]==1){
                M+=b[j];
               c[M]=j;
        }
    }
    printf("%d\n",M);
    if(M>0){
    for(int i=1;i<M;i++){
        printf("%d ",c[i]);
    }
        printf("%d\n",c[M]);
    }
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const char sp = ' ';

int N, M, A[200000], Z[200000], L[200000], R[200000], T[200001], C[200001];
bool B[200000], D[200000], F[200001], vis[200001];
vector<int>v[200001];
vector<pair<int, int>>e[200001];
vector<int>res;

int par(int x) {
	if (T[x] == x)return x;
	return T[x] = par(T[x]);
}

void uni(int x, int y) {
	x = par(x);
	y = par(y);
	T[y] = x;
}

int dfs(int x) {
	vis[x] = true;
	int cnt = 0;
	for (auto p : e[x]) {
		if (vis[p.first])continue;
		int t = dfs(p.first);
		if (t & 1)res.push_back(p.second);
		cnt += t;
	}
	cnt += C[x];
	return cnt;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		Z[i] = A[i];
	}
	sort(Z, Z + N);
	for (int i = 0; i < N; i++) {
		D[lower_bound(Z, Z + N, A[i]) - Z] = B[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i];
		L[i] = lower_bound(Z, Z + N, L[i]) - Z;
		R[i] = upper_bound(Z, Z + N, R[i]) - Z;
	}
	for (int i = 0; i <= N; i++) {
		T[i] = i;
	}
	for (int i = 0; i < M; i++) {
		uni(L[i], R[i]);
	}
	for (int i = 0; i <= N; i++) {
		v[par(i)].push_back(i);
	}
	bool f = false;
	for (int i = 0; i < N; i++) {
		f ^= F[i];
		if (f^D[i]) {
			auto it = upper_bound(v[par(i)].begin(), v[par(i)].end(), i);
			if (it == v[par(i)].end()) {
				cout << -1 << endl;
				return 0;
			}
			F[*it] ^= true;
			f ^= true;
			C[i]++;
			C[*it]++;
		}
	}
	for (int i = 0; i <= N; i++) {
		T[i] = i;
	}
	for (int i = 0; i < M; i++) {
		if (par(L[i]) != par(R[i])) {
			uni(L[i], R[i]);
			e[L[i]].push_back({ R[i],i });
			e[R[i]].push_back({ L[i],i });
		}
	}
	for (int i = 0; i <= N; i++) {
		if (!vis[i]) {
			if (dfs(i) & 1) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	sort(res.begin(), res.end());
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); i++) {
		cout << res[i] + 1;
		if (i != res.size() - 1)cout << sp;
	}
	cout << endl;
}

Measured memory_bytes: 19576
#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int b[100][100];
long long c[100][100];

int main() {

    // 1. input.
    int n = 0, m = 0, l = 0;
    scanf("%d %d %d", &n, &m, &l);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int v;
            scanf("%d", &v);
            a[i][j] = v;
        }
    }
    
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            int v;
            scanf("%d", &v);
            b[i][j] = v;
        }
    }
    
    // 2. calculate the matrix.
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            long long v = 0;
            for(int k = 0; k < m; k++) v += a[i][k] * b[k][j];
            c[i][j] = v;
        }
    }
    
    // 3. output answer.
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            printf("%lld", c[i][j]);
            if(j < l - 1) printf(" ");
        }
        printf("\n");
    }
    return 0;
    
}


Measured memory_bytes: 3312
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <map>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;

string C(string s){
	string s1(s.begin()+1, s.end());
	string s2(s.begin(), s.begin()+1);
	return s1 + s2;
}

string A(string s){
	reverse(s.begin(), s.end());
	return s;
}

string J(string s){
	string s1(s.end()-1, s.end());
	string s2(s.begin(), s.end()-1);
	return s1 + s2;
}

string E(string s){
	int n = s.size();
	int d = (n / 2);
	string s1(s.begin(), s.begin() + d), s2(s.begin() + d, s.end() - d), s3(s.end() - d , s.end());
	return s3 + s2 + s1;
}

string M(string s){
	for(int i = 0; i < (int)s.size(); i++){
		if(isdigit(s[i])){
			if(s[i] == '9') s[i] = '0';
			else s[i] = (char)(s[i] + 1);
		}
	}
	return s;
}

string p(string s){
	for(int i = 0; i < (int)s.size(); i++){
		if(isdigit(s[i])){
			if(s[i] == '0') s[i] = '9';
			else s[i] = (char)(s[i] - 1);
		}
	}
	return s;
}

int main(){
	int n;
	string order, s;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> order >> s;
		for(int j = (int)order.size()-1; j >= 0; j--){
			switch(order[j]){
			case 'A': s = A(s);
				break;
			case 'C': s = C(s);
				break;
			case 'E': s = E(s);
				break;
			case 'M': s = M(s);
				break;
			case 'P': s = p(s);
				break;
			default:
				s = J(s);
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 0
s1=input()
s2=input()
n1,n2=len(s1),len(s2)
dp=[[-1 for j in range(n2+1)] for i in range(n1+1)]
for i in range(n1,-1,-1):
    for j in range(n2,-1,-1):
        if i==n1 or j==n2:
            dp[i][j]=0
        else:
            if s1[i]==s2[j]:
                dp[i][j]=1+dp[i+1][j+1]
            else:
                dp[i][j]=max(dp[i][j+1],dp[i+1][j])
n=""
i,j=0,0
while i<n1 and j<n2:
    if dp[i][j]==dp[i+1][j]:
        i+=1
    elif dp[i][j]==dp[i][j+1]:
        j+=1
    else:
        n+=s1[i]
        i+=1
        j+=1
print(n)

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

int main(){
    int N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] != B[i] && A[i] != C[i] && B[i] != C[i]) {
            ans += 2;
        }
        else if(A[i] == B[i] && A[i] == C[i]) {
            continue;
        } 
        else {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string res = "";
    rep(i, 3) rep(j, 3) {
        char c;
        cin >> c;
        if (i == j) res += c;
    }
    cout << res << endl;
    return 0;
}

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

int f[100005];
int n,m;
int ans;

int root(int x){
    if(f[x]==x)return x;
    return f[x]=root(f[x]);
}

void unite(int x,int y){
    x=root(x);
    y=root(y);
    f[x]=y;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        f[i]=i;
    }
    for(int i=1;i<=m;i++){
        int x,y,z;
        cin>>x>>y>>z;
        unite(x,y);
    }
    for(int i=1;i<=n;i++){
        ans+=(f[i]==i);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
H, W = map(int, input().split())
zlst = [0] * (W + 2)
b1 = []
b1.append(zlst)
for h in range(H):
  lst1 = [0]
  str1 = input()
  for s in str1:
    if s == '.':
      lst1.append(0)
    else:
      lst1.append(1)
  lst1.append(0)
  b1.append(lst1)
b1.append(zlst)

#nboard = [[] for i in range(H)]
for i in range(H):
  nstr = ''
  for j in range(W):
    if b1[i + 1][j + 1] == 1:
      nstr = nstr + '#'
    else:
      nstr = nstr + str(
        b1[i][j] + b1[i][j+1] + b1[i][j+2] + b1[i+1][j] + 
        b1[i+1][j+2] + b1[i+2][j] + b1[i+2][j+1] + b1[i+2][j+2])
  print(nstr)



Measured memory_bytes: 9168
import sys

def solve(n):
    print(luca(n))
    # print(luca_other(n))

def luca(n):
    result = [0 for i in range(n+1)]
    result[0] = 2
    result[1] = 1
    for i in range(2,n+1):
        result[i] = result[i-1] + result[i-2]
    return result[n]

def luca_other(n):
    if n == 0:
        return 2
    (x, y) = (2, 1)
    for i in range(n-1):
        (x, y) = (y, x + y)
    return y

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    n = int(ws[0])
    return (n,)

def main():
    solve(*readQuestion())

# Uncomment before submission
main()


Measured memory_bytes: 3064