akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	S = [s for s in S]

	# AABCBC = 4 (BCが2つ、その前にAが2つ) 2*2 = 4
	# ABCABC = 3 (1つのBCには前にAが1つ、もう1つは前にAが2つ) 2*1+1*1 = 3
	# => それぞれのBCの前にAがある数で回数が決まる！
	# f(x) = BCの前にあるAの数 * BCの数

	ans = 0
	sts = 0
	acnt = 0
	i = 0
	while i <= len(S)-2:
		if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	print(ans)

if __name__ == '__main__':
	main()	

Measured memory_bytes: 5096
/*
 * InsertionSort.cpp
 *
 *  Created on: 2014/07/25
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

void sort(vector<int>& a_rvecIntValue);

int main(void) {

	int iNum = 0;
	cin >> iNum;
	vector<int> vecIntValue;
	while (iNum) {
		int iIntValue = 0;
		cin >> iIntValue;
		vecIntValue.push_back(iIntValue);
		iNum--;
	}

	sort(vecIntValue);

	return 0;
}

void sort(vector<int>& a_rvecIntValue) {

	for (unsigned int i = 0; i < a_rvecIntValue.size(); i++) {

		if (i != 0) {

			int iIntValue = a_rvecIntValue.at(i);
			int j = i - 1;
			while ((j >= 0) && (a_rvecIntValue.at(j) > iIntValue)) {
				a_rvecIntValue.at(j+1) = a_rvecIntValue.at(j);
				j--;
			}
			a_rvecIntValue.at(j+1) = iIntValue;
		}

		for (unsigned int k = 0; k < a_rvecIntValue.size(); k++) {
			cout << a_rvecIntValue.at(k);
			if (k != a_rvecIntValue.size() - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1220
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))

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

template <typename T>
vector<T> Dijkstra(int s, vector<vector<pair<int, T>>>& G,
                   vector<int> & prev, const T INF = 1e9) {
    using P = pair<T, int>;
    int V = G.size();
    vector<T> dist(V, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);
    prev.assign(V, -1);
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            int to = G[v][i].first;
            T cost = G[v][i].second;
            if (dist[to] > dist[v] + cost) {
                dist[to] = dist[v] + cost;
                prev[to] = v;
                que.emplace(dist[to], to);
            }
        }
    }
    return dist;
}

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<P>> G(n);
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b, 1);
        G[b].emplace_back(a, 1);
    }
    vector<int> ans;
    Dijkstra(0, G, ans);
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++){
        cout << ans[i] + 1 << endl;
    }
    return 0;
}

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

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

    int n;
    cin >> n;
    vector<long long> A(n);
    REP(i, n) cin >> A[i];

    unordered_map<long long, long long> mp;
    vector<long long> B(n + 1);
    B[0] = 0;
    mp[0]++;
    for(int i = 0; i < n; i++){
        if(i > 0) B[i + 1] += B[i] + A[i];
        else B[i + 1] = A[i];
        mp[B[i + 1]]++;
    }

    long long ans = 0;
    for(auto x : mp){
        ans += x.second * (x.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

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

int main(void) {
    int N;
    cin>>N;
    int result = 0;
    for (int i = 0; i < N; i++)
    {
        int a_tmp;
        cin>>a_tmp;
        while (a_tmp % 2 == 0) {
            a_tmp /= 2;
            result++;
        }
    }
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 504
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 210000;

vector<int> eds[MAXN];

int n;
pair<int, int> go[MAXN];
int ad[MAXN];

void dfs1(int v, int p, pair<int, int> mx) {
	if (mx.second < v)
		mx.second = v;
	if (mx.second > mx.first)
		swap(mx.second, mx.first);
	go[v] = mx;
	for (int u: eds[v]) {
		if (u == p)
			continue;
		dfs1(u, v, mx);
	}
}
int ans[MAXN];

void dfs3(int v, int p, int cur) {
	cur += ad[v];
	ans[v] = cur;
	for (int u: eds[v]) {
		if (u == p)
			continue;
		dfs3(u, v, cur);
	}
}

vector<int> vv;

void dfs2(int v, int p) {
	vv.push_back(v);

	if (v == 0)
		++ad[0];
	else {
		int l = 0;
		int r = vv.size() - 1;
		while (r - l > 1) {
			int m = (r + l) >> 1;
			int x = vv[m];
			int fl = 0;
			if (go[x].first != x) {
				if (go[x].first == go[v].first)
					fl = 1;
			}
			else {
				if (go[x] == go[v])
					fl = 1;
			}
			if (fl)
				r = m;
			else
				l = m;
		}
		++ad[vv[r]];
	}


	for (int u: eds[v]) {
		if (u == p)
			continue;
		dfs2(u, v);
	}

	vv.pop_back();
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	dfs1(0, -1, {-1, -1});
	dfs2(0, -1);
	dfs3(0, -1, 0);
	for (int i = 1; i < n; ++i)
		cout << ans[i] - 1 << " ";
	cout << "\n";
	return 0;
}




Measured memory_bytes: 25464
s=input()
import re
#re.match は複数を対象にすればマッチする該当のものが返される。一つの時ifの後に持ってくると条件式として利用可能。
if re.match("^(dream|dreamer|erase|eraser)+$",s) :
       print("YES")
else:
       print("NO")
       
       

Measured memory_bytes: 6588
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1)return dp[n]=1;
  if(dp[n]!=-1)return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++)dp[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



Measured memory_bytes: 2148
s = input()
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
else:
    print(1)


Measured memory_bytes: 2940
Masu = []
def access(x,y):
    if x < 0 or y < 0 or x > 9 or y > 9:
        return
    Masu[y][x] += 1

for i in range(10):
    Masu.append([0,0,0,0,0,0,0,0,0,0])
kosu = 0
komax = 0
while True:
    try:
        
        x,y,s = map(int,input().split(","))
        if s == 1:
            for j in range(3):
                access(y +1 - j,x)
            access(y,x - 1)
            access(y,x + 1)

        elif s == 2:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
        elif s == 3:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
            access(y - 2,x)
            access(y + 2,x)
            access(y,x + 2)
            access(y,x - 2)
               
    except (EOFError,ValueError):
        for i in range(10):
            kosu += Masu[i].count(0)
        for j in range(10):
            if komax < max(Masu[j]):
                komax = max(Masu[j])
        print(kosu)
        print(komax)
        break

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

static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];

int d[N];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  d[s] = 0;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int v = 0; v < n; v++) {
      if (M[u][v] == 0) continue;
      if (d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
  }
};

int main() {
  int u, k, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }

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

  bfs(0);
  return 0;
};



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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  vector<vector<int> > a(4, vector<int> (4, 0));
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) cin >> a[i][j];
  vector<int> ok(101, 0);
  int n; cin >> n;
  for (int i = 0; i < n; ++i){
    int x; cin >> x;
    ok[x] = 1;
  }
  for (int i = 1; i <= 3; ++i){
    bool chk = true;
    for (int j = 1; j <= 3; ++j){
      if (not ok[a[i][j]]) chk = false;
    }
    if (chk == true){
      cout << "Yes"; return 0;
    }
  }
  for (int j = 1; j <= 3; ++j){
    bool chk = true;
    for (int i = 1; i <= 3; ++i){
      if (not ok[a[i][j]]) chk = false;
    }
    if (chk == true){
      cout << "Yes"; return 0;
    }
  }
  bool chk = true;
  for (int i = 1; i <= 3; ++i){
    for (int j = 1; j <= 3; ++j){
      if (i + j != 4) continue;
      if (not ok[a[i][j]]) chk = false;
    }
  }
  if (chk == true){
    cout << "Yes"; return 0;
  }
  chk = true;
  for (int i = 1; i <= 3; ++i){
    for (int j = 1; j <= 3; ++j){
      if (i != j) continue;
      if (not ok[a[i][j]]) chk = false;
    }
  }
  if (chk == true){
    cout << "Yes"; return 0;
  }
  cout << "No";
}



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

int main() {
	int N, c[30] = {};
	string S;
	cin >> N >> S;
	long long ans = 1, mod = 1000000007;
	vector<int> letter;

	for (int i = 0; i < N; i++) {
		c[S[i] - 'a']++;
	}

	for (auto &x : c) {
		ans *= x + 1;
		ans %= mod;
	}
	ans--;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;


void dfs(int sx,int sy,char stage[12][6],bool toErase[12][6],char color,int* count){
	if(toErase[sy][sx]) return;
	toErase[sy][sx] = true;
	(*count)++;
	for(int i=0;i<4;i++){
		int dx = sx + tx[i];
		int dy = sy + ty[i];

		if(dx < 0 || dx >= 6 
			|| dy < 0 || dy >= 12) continue;
		if(stage[dy][dx] != color) continue;
		
		dfs(dx,dy,stage,toErase,color,count);
	}
}

bool markBlock(bool toErase[12][6],char stage[12][6]){

	bool res = false;
	for(int y=0;y<12;y++){
		for(int x=0;x<6;x++){
			if(stage[y][x] == '.'
				|| stage[y][x] == 'O') continue;

			if(!toErase[y][x]){
				char color = stage[y][x];
				int count = 0;
				bool tmp[12][6];
				memcpy(tmp,toErase,sizeof(bool)*12*6);

				dfs(x,y,stage,toErase,color,&count);
				if(count < 4){
					memcpy(toErase,tmp,sizeof(bool)*12*6);
				}
				else{
					res = true;
				}
			}
		}
	}

	return res;
}

void eraseBlock(bool toErase[12][6],char stage[12][6]){
	for(int x=0;x<6;x++){
		for(int y=0;y<12;y++){
			if(stage[y][x] == '.'){
				toErase[y][x] = true;
				continue;
			}
			if(stage[y][x] == 'O'){
				for(int i=0;i<4;i++){
					int dx = x + tx[i];
					int dy = y + ty[i];
					if(dx < 0 || dx >= 6 
						|| dy < 0 || dy >= 12) continue;
					if(toErase[dy][dx] == true
						&& stage[dy][dx] != '.'
						&& stage[dy][dx] != 'O'){
							toErase[y][x] = true;
					}
				}
			}
		}
	}

	char nextStage[12][6];
	for(int x=0;x<6;x++){
		queue<char> que; 
		for(int y=12-1;y>=0;y--){
			if(!toErase[y][x]){
				que.push(stage[y][x]);
			}
		}

		int idx = 12-1;
		while(!que.empty()){
			nextStage[idx][x] = que.front();
			que.pop();
			idx--;
		}
		while(idx >= 0){
			nextStage[idx][x] = '.';
			idx--;
		}
	}

	memcpy(stage,nextStage,sizeof(char)*12*6);
}

void printStage(char stage[12][6]){
	for(int y=0;y<12;y++){
		for(int x=0;x<6;x++){
			printf("%c",stage[y][x]);
		}
		printf("\n");
	}
	printf("\n");
}

int main(){
	int n;

	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			char stage[12][6];
			bool toErase[12][6];
			memset(toErase,0,sizeof(toErase));

			for(int y=0;y<12;y++){
				string str;
				cin >> str;
				for(int x=0;x<6;x++){
					stage[y][x] = str[x];
				}
			}

			//printStage(stage);
			int res = 0;
			while(markBlock(toErase,stage)){
				eraseBlock(toErase,stage);
				memset(toErase,0,sizeof(toErase));
				res++;
				//printStage(stage);
			}
			printf("%d\n",res);
		}
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
const long long int INF_dp = 1<<29; 
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll h,w;
bool ma[51][51];
queue<tuple<int,int,int>> q;
int ck[51][51];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>h>>w;
    char inp;
    ll tmp  = 0;
    rep(i,h)rep(j,w){
        cin>>inp;
        if(inp == '#')ma[j][i] = false;
        else{ma[j][i] = true; tmp++;}
    }
    rep(i,51)rep(j,51)ck[i][j]=-1;
    q.push(make_tuple(0,0,1));
    while (q.size()>0){
        tuple<int,int,int> t = q.front();
        q.pop();
        if(get<0>(t)>=0 && get<0>(t)<w){
            if(get<1>(t)>=0 && get<1>(t)<h){
                if(ck[get<0>(t)][get<1>(t)]==-1){
                    for(int i=-1;i<=1;i++)for(int j = -1;j<=1;j++){
                        if(ma[get<0>(t)][get<1>(t)]){
                            ck[get<0>(t)][get<1>(t)] = get<2>(t);
                            if(i==0 || j==0)q.push(make_tuple(get<0>(t)+i,get<1>(t)+j,get<2>(t)+1));
                        }
                    }
                }
            }
        }
    }
    if(ck[w-1][h-1]!=-1)print(tmp - ck[w-1][h-1]);
    else print(-1);
    return 0;
}

Measured memory_bytes: 256
//Author:Barry Wang
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
#define X first
#define Y second
/*---define types---*/
typedef long long ll;
typedef list<int> li;
typedef queue<int> qi;
typedef deque<int> dqi;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef unsigned int uint;
/*---define variables---*/
const int inf=(1<<29);
int n;
vi E[100005];
int dis[100005][2];
/*---define function---*/

void DFS(int x,const int& pre,const int& num)
{
	EACH(E[x],it)
	{
		int y=*it;
		if(y!=pre)
		{
			dis[y][num]=dis[x][num]+1;
			DFS(y,x,num);
		}
	}
}

/*---main code---*/
int main()
{
	FIO;
	cin>>n;
	for(int i=1;i<n;++i)
	{
		int x,y;
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	DFS(1,-1,0);
	DFS(n,-1,1);
	int cntf=0,cnts=0;
	for(int i=1;i<=n;++i)
	{
		if(dis[i][0]<=dis[i][1])
		{
			cntf++;
		}
		else
		{
			cnts++;
		}
	}
	if(cntf>cnts)
	{
		puts("Fennec");
	}
	else
	{
		puts("Snuke");
	}
	return 0;
}


Measured memory_bytes: 11264
#include <cstdio>
#include <cstdint>
#include <algorithm>

int64_t gcd(int64_t m, int64_t n) {
    while (n)
        std::swap(m%=n, n);

    return m;
}

int main() {
    int64_t N, X;
    scanf("%ld %ld", &N, &X);

    printf("%ld\n", 3*(N-gcd(N, X)));
    return 0;
}


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


ll countYakusu(ll x){
    vector<ll> vec;
    ll result=0;
    for(ll i = 1; i*i <= x; i++){
      if(x%i==0){
        result++;
        // vec.push_back(i);
        if(x!=i*i){
          result++;
          // vec.push_back(x/i);
        }
      }
    }
    cout << x << ":" << result << endl;
    return result;
}

// 間に合わない
void solve(ll N){
  ll result=0;
  for(ll i=1; i<=N; i++){
    for(ll l=1; l*l <= i; l++){
      if(i%l==0){
        result+=i;
        if(i!=l*l){
          result+=i;
        }
      }
    }
  }
  cout << result << endl;
}

// 約数の数を記録していく
// 実行時間：826 ms メモリ：42276 KB
void solve2(ll N){
  vector<int> record_yakusu(N+1,0);

  // 約数を全てカウント
  for(ll i=1; i<=N; i++){
    for(ll l=i; l <= N; l+=i){
      record_yakusu[l]++;
    }
  }

  ll result=0;
  for(ll i=1; i<=N; i++){
    result += i * record_yakusu[i];
  }
  cout << result << endl;

}

// solve2で同じループ2回回してるのもったいなくない？
void solve3(ll N){
  ll result=0;

  for(ll i=1; i<=N; i++){
    for(ll l=i; l <= N; l+=i){
      result += l;
    }
  }
  cout << result << endl;
}

int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);
  ll N;
  cin >> N;
  solve3(N);
  return 0;
}

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

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    if (n == 2) {
        cout << -1 << '\n';
        return 0;
    }
    int a[n+1]; 
    map<int, set<int>> cnt;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        a[i]--;
        cnt[a[i]].insert(i);
    }
    a[n] = -1;
    for (auto itr = cnt.begin(); itr != cnt.end(); (itr->second.size() ? ++itr : itr = cnt.erase(itr)));
    set<int> s;
    for (int i=0; i<n; i++) s.insert(i);
    int prev = n;
    vector<int> ans;
    for (int i=0; i<n-3; i++) {
        auto citr0 = cnt.begin();
        auto citr1 = ++cnt.begin();
        if (cnt.size() == 2 && citr0->second.size() == 1 && s.count(citr1->first)) {
            prev = citr1->first;
        } else if (cnt.size() == 2 && citr1->second.size() == 1 && s.count(citr0->first)) {
            prev = citr0->first;
        } else {
            auto itr = s.begin();
            if (*itr == a[prev]) itr++;
            prev = *itr;
        }
        ans.push_back(prev);
        s.erase(prev);
        cnt[a[prev]].erase(prev);
        if (cnt[a[prev]].size() == 0) cnt.erase(a[prev]);
    }
    for (auto &si:s) ans.push_back(si);
    do {
        bool success = true;
        int p = prev;
        for (int i=n-3; i<n; i++) {
            if (ans[i] == a[p]) {
                success = false;
                break;
            }
            p = ans[i];
        }
        if (success) break;
    } while (next_permutation(ans.begin() + n-3, ans.end()));
    for (auto &ai:ans) cout << ai + 1 << ' ';
    cout << '\n';
    return 0;
}

Measured memory_bytes: 19968
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
char s[5];int ans;
int main(){
	scanf("%s",s); 
	for(int i=0;i<=2;i++)
	 if(s[i]=='1')ans++;
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main :: IO()
main = do
    [n,h] <- map read . words <$> getLine
    abt <- replicateM n $ map read . words <$> getLine
    print $ calcAns h (transpose abt)
        where
            calcAns h [as,bs]
                | sum bs' >= h = partial h bs'
                | otherwise = length bs' + ceiling (fromIntegral (h - sum bs') / fromIntegral amax)
                where
                    amax = maximum as
                    bs' = sortBy (flip compare) $ filter (> amax) bs
            partial h l = partial' h l 0
            partial' h (b:bs) i
                | h <= b = i + 1
                | otherwise = partial' (h-b) bs (i+1)


Measured memory_bytes: 183676
def selectionSort(N, A):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            k = A[i]
            A[i] = A[minj]
            A[minj] = k
            count += 1
    print(" ".join(map(str, A)))
    print(count)


n = int(input())
a = list(map(int, input().split()))
selectionSort(n, a)


Measured memory_bytes: 5600
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    count = 0
    for i, ai in enumerate(a):
        if (i+1) % 2 == 1 and ai % 2 == 1:
            count += 1
    print(count)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> a(N);
  int64_t x=0;
  for(int i=0;i<N;i++){
    cin >> a.at(i);
    x^=a.at(i);
  }
  for(int i=0;i<N;i++){
    cout << (x^a.at(i));
    if(i==N-1){
      cout << endl;
    }else{
      cout << " ";
    }
  }
  return 0;
}


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

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

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

    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i < N; i++) {
        A[i] += A[i - 1];
    }


    ll mini = INF<ll>;
    for (int i = 0; i < 2; i++) {
        bool plus = (bool)i;
        ll bias = 0;
        ll cnt = 0;
        for (int j = 0; j < N; j++) {
            if ((plus and A[j] + bias > 0) or ((not plus) and A[j] + bias < 0)) {
                ;
            } else if (plus) {
                cnt += 1 - (A[j] + bias);
                bias += 1 - (A[j] + bias);
            } else {
                cnt += (A[j] + bias) + 1;
                bias -= (A[j] + bias) + 1;
            }
            plus = not plus;
        }
        mini = min(mini, cnt);
    }
    cout << mini << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


int main(){
    string s1, s2;
    int N, M, A, B, C;
    cin >> N >> M;
    for(int i = 0; i <= 1000; i++){
        for(int j = 0; j <= 1000; j++){
            if(2 * i + 4 * j == M && i + j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;


int main() {
	string s;
	ll n, memo = 2,count=0;
	cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	while (n) {
		if (abs(n) % memo != 0) {
			s.insert(0, "1");
			n -= ((count % 2 == 0) ? (memo/2) : (-1 * (memo/2)));
		}
		else {
			s.insert(0, "0");
		}
		memo *= 2;
		count++;
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>

int main(){
	int mozi;
	char alpha[]="abcdefghijklmnopqrstuvwxyz";
	int count[26]={0};
	int loop;
	
	while((mozi=getchar())!=EOF){
		if(isupper(mozi)){
			mozi=tolower(mozi);
		}
		for(loop=0;loop<26;loop++){
			if(mozi==alpha[loop]){
				count[loop]++;
			}
		}
	}
		
		for(loop=0;loop<26;loop++){
			printf("%c : %d\n",alpha[loop],count[loop]);
		}
	
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n,m,k,cnt;
char s[310][310];
int ans[310][310];
bool vis[310];
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m); read(k);
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int j=1;j<=m;j++) {
		int lst=0;
		for (int i=1;i<=n;i++)
			if (s[i][j]=='#') {
				cnt++;
				for (int k=lst+1;k<=i;k++) ans[k][j]=cnt;
				lst=i;
			}
		for (int k=lst+1;k<=n;k++) ans[k][j]=cnt;
		if (!lst) {
			if (!vis[j-1]) vis[j]=0;
			else vis[j]=1;
			for (int i=1;i<=n;i++) ans[i][j]=ans[i][j-1];
		} else vis[j]=1;
	}
	for (int j=m;j>=1;j--)
		if (!vis[j]) {
			for (int i=1;i<=n;i++)
				ans[i][j]=ans[i][j+1];
		}
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=m;j++) printf("%d ",ans[i][j]);
		printf("\n");
	}
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 1280
using System;
using System.Linq;
using System.Collections.Generic;


namespace Test1 {

    class ClassMain {


        public static void rikuSearch(int[,] map, int y, int x) {
            if (y < 0 || map.GetLength(0) <= y || x < 0 || map.GetLength(1)<=x) { return; }
            if (map[y, x] == 0) { return; }
            map[y, x] = 0;
            rikuSearch(map, y + 1, x);
            rikuSearch(map, y - 1, x);
            rikuSearch(map, y , x+1);
            rikuSearch(map, y , x-1);
            rikuSearch(map, y + 1, x+1);
            rikuSearch(map, y + 1, x-1);
            rikuSearch(map, y - 1, x+1);
            rikuSearch(map, y - 1, x-1);        
        }

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int n = ints[0]; 
                //int n = int.Parse(line);                
                if(n==0){break;}
                int p = ints[1];

                int[] stones = new int[n];
                int currentPosi = 0;
                int currentStone = p;
                while (true) {
                    if (currentStone > 0) {
                        stones[currentPosi]++;
                        if (stones[currentPosi] == p) {
                            break;
                        }
                        currentStone--;
                        currentPosi=(currentPosi+1)%n;
                    }
                    else {
                        currentStone += stones[currentPosi];
                        stones[currentPosi] = 0;
                        currentPosi = (currentPosi + 1) % n;
                    }
                }
                Console.WriteLine(currentPosi);

            }   
        }   
    }
}

Measured memory_bytes: 5892
<?php
list($k, $t) = ints();
$a = ints();
echo array_sum($a) - max($a) >= max($a) - 1 ? 0 : max($a) - 1 - (array_sum($a) - max($a));
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16232
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int n, k;
int a[200001];
int main()
{
	cin >> n >> k;
	REP(i, 0, n) {
		int aa;
		cin >> aa;
		a[aa]++;
	}

	sort(a, a + 200001, greater<int>());

	int cnt = 0;
	REP(i, k, 200001) {
		if (a[i] <= 0) {
			break;
		}
		cnt += a[i];
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl


int main(){
	li m;
	cin>>m;
	rep(k,m){
		string a,b;
		cin>>a>>b;
		li sa=sz(a),sb=sz(b);
		if(sa>sb)rep(i,sa-sb)b="0"+b;
		else rep(i,sb-sa)a="0"+a;
		
		//p2(a,b);
		
		li n=sz(a);
		li co=0;
		vector<li> res;
		
		for(li i=n-1; i>=0; i--){
			li tmp=((a[i]-'0')+(b[i]-'0'))+co;
			if(tmp>9){
				co=1;
				tmp-=10;
			}
			else co=0;
			
			res.pb(tmp);
		}
		if(co>0)res.pb(1);
		
		if(sz(res)>80)puts("overflow");
		else{
			rep(i,sz(res)){
				cout<<res[sz(res)-i-1];
			}
			puts("");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1252
#pragma region include, macro
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> l(n);
	int ma = -1;
	int sum = 0;
	for(int i = 0; i < n; ++i){
		cin >> l[i];
		ma = max(l[i], ma);
		sum += l[i];
	}
	if(sum - ma > ma){
		cout << "Yes" << endl; 
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
N, K = map(int, input().split())
point = list(map(int, input().split())) #R, S, P
T = input()
te = ["r", "s", "p"]
past = []
ans = 0

for i,char in enumerate(T):
    index_win = (te.index(char) + 2) % 3
    te_win = te[index_win]
    if i >= K:
        if te_win == past[i - K]:
            past.append("$")
            continue
        else:
            ans += point[index_win]
    else:
        ans += point[index_win]
    past.append(te_win)

print(ans)


Measured memory_bytes: 78652
#include <stdio.h>
#define N 10000

typedef struct{
    int p;
    int l;
    int r;
}Node;

Node T[N];
int n, D[N], H[N];
void setDepth(int,int);
int setHeight(int);
int getSibling(int);
    
    
int main(){
    int i, v, l, r, deg, root=0;
    
    scanf("%d", &n);
    
    for(i=0; i<n; i++) T[i].p = -1;
    
    for(i=0; i<n; i++){
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if(l != -1) T[l].p = v;
        if(r != -1) T[r].p = v;
    }
    
    for(i=0; i<n; i++){
        if(T[i].p == -1) root = i;
    }
    
    setDepth(root, 0);
    setHeight(root);
    
    for(i=0; i<n; i++){
        printf("node %d: ", i);
        printf("parent = %d, ", T[i].p);
        printf("sibling = %d, ", getSibling(i));
        deg = 0;
        if(T[i].l != -1) deg++;
        if(T[i].r != -1) deg++;
        printf("degree = %d, ", deg);
        printf("depth = %d, ", D[i]);
        printf("height = %d, ", H[i]);
        
        if(T[i].p == -1) printf("root\n");
        else if(T[i].l == -1 && T[i].r == -1) printf("leaf\n");
        else printf("internal node\n");
    }
    
    return 0;
}

void setDepth(int u, int d){
    if(u == -1) return;
    D[u] = d;
    setDepth(T[u].l, d+1);
    setDepth(T[u].r, d+1);
}

int setHeight(int u){
    int h1=0, h2=0;
    if(T[u].l != -1) h1 = setHeight(T[u].l) + 1;
    if(T[u].r != -1) h2 = setHeight(T[u].r) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
    if(T[u].p == -1) return -1;
    if(T[T[u].p].l != u && T[T[u].p].l != -1) return  T[T[u].p].l;
    if(T[T[u].p].r != u && T[T[u].p].r != -1) return T[T[u].p].r;
    return -1;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>                          
using namespace std;    
int n,ans; 
int main(){	
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		int num=1;
		for(int j=2;j<=i;j++)
		    if(i%j==0&&j%2!=0) num++;
		if(num==8) ans++;
	}
	cout<<ans; 
	return 0;
}

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

using namespace std;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin>>n;
  vector<ll> h(n);
  rep(i,n) cin>>h[i];
  
  for(ll i=n-2;i>=0;i--){
    if(h[i]>h[i+1]+1){
      cout<<"No"<<endl;
      return 0;
    }else if(h[i]>h[i+1]){
      h[i]--;
    }
  }
  
  cout<<"Yes"<<endl;
 

}





Measured memory_bytes: 1024
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long
#define pii pair<intt,intt>

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();
#define endl '\n'

const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;

const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;

const intt INF = 2LL * 1000000000;

/***************/

intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

intt gcd (intt a, intt b) {
    while (b > 0) {
        intt t = a % b;
        a = b, b = t;
    }
    return a;
}

intt lcm (intt a, intt b) {
    return (a / gcd (a, b)) * b;
}

intt is_prime (intt n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/**************************/

pii arr[maxx]; intt idx = 0;
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    IO;
    intt n, k;
    cin >> n >> k;
    for (intt i = 1; i <= n; i++) {
        intt a, b;
        cin >> a >> b;
        if (a > k) {
            continue;
        }
        arr[++idx] = {a, b};
    }
    intt msk = 0, res1 = 0, res2 = 0;
    for (intt i = 29; i >= 0; i--) {
        if (k >> i & 1) {
            res2 = 0;
            for (intt j = 1; j <= idx; j++) {
                if (((arr[j].F >> i) | (msk >> i)) == (msk >> i)) {
                    res2 += arr[j].S;
                }
            }
            res1 = max (res1, res2);
            msk |= (1 << i);
        }
    }
    res2 = 0;
    for (intt i = 1; i <= idx; i++) {
        if ((msk | arr[i].F) == msk) {
            res2 += arr[i].S;
        }
    }
    res1 = max (res1, res2);
    cout << res1 << endl;
    return 0;
}


Measured memory_bytes: 1920
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}
bool check(string s)
{
	for (int i=0; i<sz(s); i++)
	{
		if (s[i]!=s[sz(s)-i-1])
			return false;
	}
	return true;
}
void solve()
{
//Read Comments below main

	string s;
	cin>>s;
	int n=sz(s);
	// cout<<check(s)<<endl;
	if (check(s.substr(0,(n-1)/2)) && check(s.substr((n+1)/2,(n-1)/2)) && check(s))
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constraint is of the order of 15-20, think of bitmask DP.
// 2)When some constraint is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 256
using System;
class _0001 {
    public static void Main() {
        var hs = new int[10];
        for (var i = 0; i < 10; i++) hs[i] = int.Parse(Console.ReadLine());
        Array.Sort(hs);
        for (var i = 0; i < 3; i++) Console.WriteLine(hs[9 - i]);
    }
}


Measured memory_bytes: 9280
# D - Match Matching

N, M = map(int, input().split())
A = list(int(x) for x in input().split())
match_list = [('0', 6), ('1', 2), ('2', 5), ('3', 5), ('4', 4), ('5', 5), ('6', 6), ('7', 3), ('8', 7), ('9', 6)]
MA = []
for a in A:
    MA.append(match_list[a])
MA.sort(key=lambda x: x[0], reverse=True)

# dp[i] := i本のマッチを使って作れる最大桁数
dp = [-1] * (N+1)
dp[0] = 0
for i in range(N+1):
    for j in range(M):
        if i-MA[j][1] >= 0:
            dp[i] = max(dp[i], dp[i-MA[j][1]] + 1)

remain_keta = dp[N]
remain_match = N
ans = ''
for i in range(dp[N]):
    for ma in MA:
        # 大きい数字から一桁使った時に、
        # 残り桁がちょうど一桁減っている場合
        if remain_match >= ma[1] and dp[remain_match - ma[1]] == remain_keta - 1:
            ans +=  ma[0]
            remain_keta -= 1
            remain_match -= ma[1]
            break

print(ans)

Measured memory_bytes: 3420
<?php
  fscanf(STDIN,"%d %d",$a,$b);
  $s = trim(fgets(STDIN));
  for($i=0; $i<$a+$b+1; $i++){
    if( $i == $a ){
      if($s[$i] != "-"){
        echo "No\n";
        exit;
      }
    }else{
      if(!ctype_digit($s[$i])){
        echo "No\n";
        exit;
      }
    }
  }
  echo "Yes\n";

Measured memory_bytes: 4604
# 文字列Sの入力
S = input()
# 文字列Tの入力
T = input()
# 正解数をカウントする変数
Count = 0

# 一文字ずつ比較し一致する場合はカウントアップ
for i in range(3):
  if S[i] == T[i]:
    Count = Count + 1

print("{}".format(Count))

Measured memory_bytes: 2940
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll n;  cin >> n;
  string s;  cin >> s;
  deque<char> dq;
  dq.push_back(s[0]);
  for(int i = 1; i < n; i++){
    if(dq.front() != s[i]){
      dq.push_front(s[i]);
    }
  }
  cout << dq.size();
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
const int MN = 5e5+5, MOD=1e9+1;
ll lcm (ll a, ll b) {return a*b/__gcd(a,b);}
ll multiplyMod(ll a, ll b) { return (a % MOD * b % MOD) % MOD; }
ll addMod(ll a, ll b) { return (a % MOD + b % MOD) % MOD; }
ll subMod(ll a, ll b) { return (a % MOD - b % MOD) % MOD; }
int n;
int arr[MN];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int res;
    cin >> res;
    for (int i = 0, z; i < n - 1; i++) {
        cin >> z;
        res ^= z;
    }
    cout << ((res == 0) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#! /usr/bin/env python3

def maximizeVacation(swimming, bugs, homework):
    '''
    Each of swimming, bugs, and homework represents a list of values for that activity on day i of the list.
    Return the maximum value possible such that an activity cannot be performed consecutively.
    '''
    n = len(swimming) 
    justSwam =      [0] * n
    justBugged =    [0] * n
    justDidHw =     [0] * n

    justSwam[0] = swimming[0]
    justBugged[0] = bugs[0]
    justDidHw[0] = homework[0]

    for i in range(1, n):
        justSwam[i] = max(justBugged[i-1], justDidHw[i-1]) + swimming[i]
        justBugged[i] = max(justSwam[i-1], justDidHw[i-1]) + bugs[i]
        justDidHw[i] = max(justSwam[i-1], justBugged[i-1]) + homework[i]

        '''
        justSwam[i] = max(justBugged[i-1], justDidHw[i-1]) + justSwam[i-1] 
        justBugged[i] = max(justSwam[i-1], justDidHw[i-1]) + justBugged[i-1]
        justDidHw[i] = max(justSwam[i-1], justBugged[i-1]) + justDidHw[i-1]
        '''

    return max(justSwam[n-1], justBugged[n-1], justDidHw[n-1])

def main():
    '''
    print("Vacation dynamic programming problem")
    print(maximizeVacation([10, 20, 30], [40, 50, 60], [70, 80, 90]))
    print(maximizeVacation([100], [10], [1]))
    print(maximizeVacation([6, 8, 2, 7, 4, 2, 7], [7, 8, 5, 8, 6, 3, 5], [8, 3, 2, 6, 8, 4, 1]))
    '''
    n = int(input())

    swimming = [0] * n
    bugs = [0] * n
    homework = [0] * n

    for i in range(n):
        values = input()
        values = values.split()
        swimming[i] = int(values[0])
        bugs[i] = int(values[1])
        homework[i] = int(values[2])

    print(maximizeVacation(swimming, bugs, homework))

if __name__ == '__main__':
    main()


Measured memory_bytes: 26756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  vector<int> p(n);
  for (int i=0;i<n;i++){
    cin >> p.at(i);
  }
  
  int c=0;
  
  for (int i=0;i<n;i++){
    if (p.at(i)!=i+1)c++;
  }
  
  if (c<3) cout << "YES" <<endl;
  else cout << "NO" <<endl;
      
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  
  ll mini = 0;
  ll maxi = 1e5 +1;
  
  rep(i, 0, m) {
    ll l, r;
    cin >> l >> r;
    if(l > mini) mini = l;
    if(r < maxi) maxi = r;
  }  
  
  ll ans = maxi -mini +1;
  if(ans > 0)
    cout << ans << "\n";
  else
    cout << 0 << "\n";

}


Measured memory_bytes: 256