akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

#define int long long
#define dotimes(i, n) for (int i : range(n))

using namespace std;

class range {
  class iterator {
    int i, s;
  public:
    iterator(int i, int s): i(i), s(s) {}
    int& operator*() {
      return i;
    }
    void operator++() {
      i += s;
    }
    bool operator!=(iterator const& that) {
      return i < that.i;
    }
  };
  iterator b, e;
public:
  range(int e): b({0, 1}), e({e, 1}) {}
  range(int b, int e): b({b, 1}), e({e, 1}) {}
  range(int b, int e, int s): b({b, s}), e({e, s}) {}
  iterator begin() {
    return b;
  }
  iterator end() {
    return e;
  }
};

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

template<typename T>
inline bool maxs(T& a, T const& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
inline bool mins(T& a, T const& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  const int N = rint();
  const int K = rint();
  int a[N];
  dotimes(i, N)
    a[i] = rint();
  int r = 1e12;
  dotimes(k, 1 << (N - 1)) {
    int h = a[0];
    int c = 0, s = 0;
    dotimes(i, N - 1) {
      if ((k >> i) & 1) {
        c++;
        if (h >= a[i+1]) {
          h++;
          s += h - a[i+1];
        } else
          h = a[i+1];
      } else if (h < a[i+1])
        goto fail;
    }
    if (c >= K - 1)
      mins(r, s);
  fail:
    ;
  }
  wint(r);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
using ll = long long;
const int mod = 1000000007;

int main() {
	string s, key = "keyence";
	int n = 0,m=0;
	cin >> s;
	for (int i = 0; i < s.size()&&n<7; i++) {
		if (s[i] == key[n])n++;
		else break;
	}
	for (int i = s.size() - 1; i >= 0 && m<7; i--) {
		if (s[i] == key[6-m])m++;
		else break;
	}
	if (n+m>=7)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<climits>

#define ll long long int
#define llu unsigned long long int
#define N 100001
using namespace std;

vector<int> dp(N,-1);
int main(){
	int n;
  cin>>n;
  vector<int> v(n+1);
  v[0]=2*N;
  for(int i=1;i<n+1;i++){
  cin>>v[i];
  }
  dp[0]=N;
  dp[1]=0;
  dp[2]=abs(v[1]-v[2]);
  for(int i=3;i<=n;i++){
  	dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
  }
  cout<<dp[n];

return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

struct ta{
  int num;
  int eo;
  int parent;
};

int main(){
  LL n,m;
  cin >> n >> m;
  vector<list<int>> e(n);
  int u,v;
  for(int i=0;i<m;i++){
    cin >> u >> v;
    u--,v--;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  vector<int> searched(n,-1);
  queue<struct ta> bfs;
  struct ta now;
  LL nibu=0,notnibu=0,ikko=0;
  int count=0;
  bool isnibu;
  for(int i=0;i<n;i++){
    if(searched[i]==-1){
      isnibu=true;
      searched[i]=0;
      bfs.push({i,0,-1});
      count=0;
      while(!bfs.empty()){
        count++;
        now=bfs.front();
        bfs.pop();
        for(auto itr=e[now.num].begin();itr!=e[now.num].end();itr++){
          if(searched[(*itr)]==-1){
            searched[(*itr)]=1-now.eo;
            bfs.push({(*itr),1-now.eo,now.num});
          }else if(searched[(*itr)]==now.eo){
            isnibu=false;
          }
        }
      }
      if(count==1) ikko++;
      else if(isnibu) nibu++;
      else notnibu++;
    }
  }
  // cout << ikko << nibu << notnibu << endl;
  cout << 2*ikko*n-ikko*ikko+(nibu+notnibu)*(nibu+notnibu)+nibu*nibu << endl;
  return 0;
}


Measured memory_bytes: 15232
x,n = map(int,input().split())

if n != 0:
    p = list(map(int,input().split()))
else:
    print(x)
    exit()

s = 1000000000

for i in range(-100,102):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p:
    print(x - s)
else:
    print(x + s)

Measured memory_bytes: 9196
S = input()
s1 = list(S)
s2 = list(S)

ans1 = 0
ans2 = 0
for i,t in enumerate(s1):
    if i%2 == 0:
        if t == "0":
            ans1 += 1
    else:
        if t == "1":
            ans1 += 1


for i,t in enumerate(s1):
    if i%2 == 0:
        if t == "1":
            ans2 += 1
    else:
        if t == "0":
            ans2 += 1
print(min (ans1,ans2))


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  vector<int> v(3);
  rep(i,0,3) cin>>v[i];
  sort(all(v));
  int cnt = 0;
  while(true){
    if(v[0]==v[1] && v[1]==v[2]) break;
    if(v[0]<v[2] &&  v[1]<v[2]){
        v[0]++; v[1]++;
        cnt++;
    }else if(v[0]<v[2]){
        v[0] += 2;
        cnt++;
    }
    sort(all(v));
  }
  cout<<cnt<<endl;
  return 0;
}   

Measured memory_bytes: 3628
const N = '2019/04/30';
var s:packed array[1..10] of char; t:packed array[1..10] of char ;i:integer; c:char;
begin
  i:=0;
  repeat read(c); s[i+1]:=c; i:=i+1 until (i = 10) or eoln  ; 
  if i<10 then write('Heisei')
  else if not eoln then write('TBD')
  else if s > N then write('TBD') else write('Heisei')
end.

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

vector<double> x,y;

int f(int n){return (n==1)?1:n*f(n-1);}

double g(double i,double j){return sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));}

int main(){
	int n;
	cin>>n;
	
	x.resize(n);
	y.resize(n);
	REP(i,n) cin>>x[i]>>y[i];
	
	double sum=0;
	double cnt=2*f(n-1);
	REP(i,n-1)for(int j=i+1;j<n;++j){
		sum+=g(i,j)*cnt;
	}
	
	double ans=sum/f(n);
	printf("%.10f",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if(0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int,int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n;
vector<pair<int, int> > edges;
vector<pair<int, int> > vec[MAXN+1];
int ans[MAXN+1];
set<int> aux[MAXN];
int vis[MAXN];
int grau[MAXN];

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

  cin >> n;
  int tam = 0;
  for(int i=0;i<n-1;i++){
    int a, b;
    cin >> a >> b;
    vec[a].push_back({b, i+1});
    vec[b].push_back({a, i+1});
    grau[a]++, grau[b]++;
    tam = max({tam, grau[a], grau[b]});
  }

  queue<int> q;
  q.push(1);
  vis[1] = 1;
  int atual = 1;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(auto i : vec[u]){
      if(ans[i.S] == 0){
        // cout << u << " - " << i.F << endl;
        while(aux[i.F].find(atual) != aux[i.F].end()
        or aux[u].find(atual) != aux[u].end()){
          atual++;
          if(atual > tam) atual = 1;
        }
        // cout << "Atual : " << atual << endl;

        ans[i.S] = atual;
        aux[u].insert(atual);
        aux[i.F].insert(atual);
        if(atual > tam) atual = 1;
        q.push(i.F);
      }
    }
  }

  cout << tam << endl;
  for(int i=1;i<=n-1;i++) cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 28800
#include <cstdio>

int n, m, ans, *left, *possible;

int main() {
  scanf("%d%d", &n, &m);
  left = new int[n];
  possible = new int[n];
  for (int i = 0; i < n; ++i) {
    left[i] = 1;
  }
  possible[0] = 1;
  while(m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    possible[--v] |= possible[--u];
    if(!--left[u]) {
      possible[u] = 0;
    }
    ++left[v];
  }
  for (int i = 0; i < n; ++i) {
    ans += possible[i];
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
  
int main(){
    int flag[101];
    int f;
    int num;
    int i = 0, j = 0;
    for(i = 0;i <= 101;i++){
        flag[i] = 0;
    }
    for(i = 1;i <= 9;i++){
        for(j = 1;j <= 9;j++){
            f = i * j;
            flag[f] = 1;
        }
    }
    scanf("%d",&num);
    if(flag[num] == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

int main(){
    int n; cin >> n;
    set<int> A;
    for(int i=0;i<n;i++) {int a; cin >> a; A.emplace(a);}

    int ok = (n-(int)A.size()) % 2;
    if(ok) cout << A.size() - 1 << endl;
    else cout << A.size() << endl;

    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
 using namespace std;
 
 // #define  int           long long
 #define pb                push_back
 #define ppb               pop_back
 #define pf                push_front
 #define ppf               pop_front
 #define all(x)            (x).begin(),(x).end()
 #define uniq(v)           (v).erase(unique(all(v)),(v).end())
 #define sz(x)             (int)((x).size())
 #define fr                first
 #define sc                second
 #define pint              pair<int,int>
 #define rep(i,a,b)        for(int i=a;i<b;i++)
 #define mem1(a)           memset(a,-1,sizeof(a))
 #define mem0(a)           memset(a,0,sizeof(a))
 #define ppc               __builtin_popcount
 #define ppcll             __builtin_popcountll
 #define vint			   vector<int>
 #define vpint			   vector<pair<int,int>>
 #define mp                make_pair


 void reader() 
 { 
 #ifndef ONLINE_JUDGE 
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout); 
 #endif
 }
 
 void fastIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);}
 
 
 
 void solve()
 {
 
 string s;
 cin>>s;
 int ctr=0;
 if(s[0]=='R'||s[1]=='R'||s[2]=='R')
 	ctr=1;


 rep(i,0,2)
 	if(s[i]=='R'&&s[i+1]=='R')
 			ctr++;
 	
 	cout<<ctr;
 
 
 cout<<"\n";
 }
 
 
 
 signed main()
 {
 	reader(); fastIO();
 	long long t=1;
 	//cin>>t;
 	while(t--) solve();
 	return 0;
 }

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

int main(){
  ll n;cin>>n;
  vector<pair<ll,ll>>work(n);
  ll a,b;
  for(ll i=0;i<n;i++){
    cin>>a>>b;
    work.at(i)={b,a};
  }
  sort(work.begin(),work.end());
  ll sum=0;
  bool ans=true;
  for(ll i=0;i<n;i++){
    sum+=work.at(i).second;
    if(sum>work.at(i).first){
      ans=false;
      break;
    }
  }
  if(ans){
    cout <<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }
}

Measured memory_bytes: 6436
#include<iostream>
using namespace std;
int h, w;
int main() {
	while (cin >> h >> w, h) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (!i || i == h-1 || !j || j == w-1) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3096
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

char a[100004];

int main() {
    scanf("%s", a);
    int n = 0, v = 0;
    for (char *p = a; *p; p++) {
        if (*p == '0')
            v++;
        n++;
    }
    int vv = n-v;
    v = MIN(v, vv);
    printf("%d\n", 2*v);

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int solve(int ,int);

int A[2000];
int mi[2000];
int n;

int main(){
  
  int q,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
  }

  for(i=0;i<q;i++){
    if(solve(0,mi[i])==1) printf("yes\n");
    if(solve(0,mi[i])==0) printf("no\n");
  }
  
  return 0;

}

int solve(int i,int m){
  int res;
  if(m==0) return 1;
  if(i>=n) return 0;
  res=solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
 		
int main() {

int H,W;
cin>>H>>W;
vector<string> S(H);
fx(H){
  cin>>S.at(x);
}
int road=0;
fx(W){
	fy(H){
		if(S.at(y).at(x)=='.'){
			road++;
		}
	}
}

queue<int> ax;
queue<int> ay;
ax.push(1);
ay.push(1);
int field[60][60];

fx(52){
	fy(52){
		field[x][y]=5000;
	}
}
field[1][1]=1;
while(ax.size()>0){
	int x=ax.front();
	int y=ay.front();
	ax.pop();ay.pop();
	if(x+1<=H&&S.at(x).at(y-1)=='.'){
		if(field[x+1][y]>field[x][y]+1){
			field[x+1][y]=field[x][y]+1;
			ax.push(x+1);ay.push(y);
		}
	}
	if(x-1>0&&S.at(x-2).at(y-1)=='.'){
		if(field[x-1][y]>field[x][y]+1){
						field[x-1][y]=field[x][y]+1;
			ax.push(x-1);ay.push(y);
		}
	}

	if(y+1<=W&&S.at(x-1).at(y)=='.'){
		if(field[x][y+1]>field[x][y]+1){
			field[x][y+1]=field[x][y]+1;
			ax.push(x);ay.push(y+1);
		}
	}
	if(y-1>0&&S.at(x-1).at(y-2)=='.'){
		if(field[x][y-1]>field[x][y]+1){
			field[x][y-1]=field[x][y]+1;
			ax.push(x);ay.push(y-1);
		}
	}
	
}
  if(road-field[H][W]<0){
    ce(-1)
  }else{
	ce(road-field[H][W])
  }
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int X, Y;
    cin >> X >> Y;
    if(llabs(X - Y) > 1){
        cout << "Alice";
    }else{
        cout << "Brown";
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main(){
    int N;
    cin >> N;
    int L[N*2];
    REP(i,N*2){
        cin >> L[i];
    }
    sort(L, L+N*2);
    int ret = 0;
    REP(i,N){
        ret += L[i*2];
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()

    ans = 1
    for a in range(1, N-1):
        num_b = (N-1) // a
        ans += num_b

    print(ans)


main()


Measured memory_bytes: 82992
# C
s = str(input())

s = list(s)
s = list(map(lambda x: int(x), s))

count_odd = [0 for i in range(2)]
count_even = [0 for i in range(2)]

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 0:
            count_even[0] += 1
        else:
            count_even[1] += 1
    else:
        if s[i] == 0:
            count_odd[0] += 1
        else:
            count_odd[1] += 1

ans = 0
if max(count_even) > max(count_odd):
    if count_even[0] >= count_even[1]:
        ans = count_even[1] + count_odd[0]
    else:
        ans = count_even[0] + count_odd[1]
else:
    if count_odd[0] >= count_odd[1]:
        ans = count_odd[1] + count_even[0]
    else:
        ans = count_odd[0] + count_even[1]
    
print(ans)

Measured memory_bytes: 4776
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(void){
    int x,i;
    i = 1;
    while(1){
        cin >> x;
        if (x == 0) break;
        cout << "Case " << i << ": " << x << endl;
        i += 1;
    }
    return 0;
}

Measured memory_bytes: 1160
x, y = map(int, input().split())

rwd_dict = {1: 300000, 2: 200000, 3:100000}

rwd_x = rwd_dict.get(x, 0)
rwd_y = rwd_dict.get(y, 0)
rwd_1 = 0
if x == 1 and y == 1:
    rwd_1 = 400000

rwd = rwd_x + rwd_y + rwd_1

print(rwd)

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
vector<vi> p;
bool used[9];
vi v;
void f(int idx, int n) {
    if (idx == n) {
        p.pb(v);
        return;
    }
    for (int i = 1; i <= n; ++i) {
        if (used[i]) continue;
        used[i] = true;
        v[idx] = i;
        f(idx + 1, n);
        used[i] = false;
    }
}
void solve(){
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vi b(n);
    for (int i = 0; i < n; ++i) cin >> b[i];
    v.resize(n);
    f(0, n);
    int q, r;
    for (int i = 0; i < p.size(); ++i) {
        if (p[i] == a) q = i;
        if (p[i] == b) r = i;
    }
    cout << abs(q - r);
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 3384
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;
 
 int main()
 { 
   int n;
   while(cin>>n)
   {
     string s;
     long long int kk[5]={0};
     while(n--)
     {
       cin>>s;
       if(s[0]=='M') kk[0]++;
       else if(s[0]=='A') kk[1]++;
       else if(s[0]=='R') kk[2]++;
       else if(s[0]=='C') kk[3]++;
       else if(s[0]=='H') kk[4]++;          
     }             
     long long int ans=0;
     for(int i=0;i<5;i++)
       for(int j=i+1;j<5;j++)
         for(int k=j+1;k<5;k++)
           ans=ans+kk[i]*kk[j]*kk[k];
     cout<<ans<<endl;
   }
   return 0;
 }
 

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
struct RollingHash{
    static constexpr int SZ = 323456;
    static constexpr int mod = 1e9+7;
     ll basemod[2] = {1007, 1000000021};
     ll basepow[2][SZ];
    vector<int> pre[2];
    const string s;
    const int n;
    void make(){
        rep(i,2){
            basepow[i][0] = 1;
            rep(j,SZ-1){
                basepow[i][j+1] = (long long)basepow[i][j] * basemod[i] % mod;
            }
        }
    }
    RollingHash(const string &_s) : s(_s),n((int)s.size()){
        if(!basepow[0][0])make();
        pre[0].resize(n + 1);
        pre[1].resize(n + 1);
        rep(i,2){
            rep(j,n){
                pre[i][j+1] =((long long)pre[i][j] * basemod[i] % mod + (int)s[j]) % mod;
            }
        }
    }
    // [l,r)
    ll cal_hash(int l, int r){
        ll a = (pre[0][r] - pre[0][l] * basepow[0][r-l] % mod + mod) % mod;
        ll b = (pre[1][r] - pre[1][l] * basepow[1][r-l] % mod + mod) % mod;
        return (ll)(a<<30) + b;
    }
};
int n;
string s;
bool ok(int k,RollingHash &rh){
    map<ll,int> mp;
    bool f = false;
    for(int i = 0; i < n - k + 1; i++){
        show(i,k);
        ll h = rh.cal_hash(i,i+k);
        if(mp.count(h)){
            if(mp[h] <= i - k)return true;
        }else{
            mp[h] = i;
        }
    }
    return false;
}
int main(){
    cin >> n >> s;
    int l = 0;
    int r = n;
    RollingHash rh(s);
    while(r - l >1){
        int mid = (l + r) / 2;
        if(ok(mid,rh)){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout << l << endl;
}

Measured memory_bytes: 5632
// Problem : A - Kenken Race
// Contest : AtCoder Grand Contest 034
// URL : https://atcoder.jp/contests/agc034/tasks/agc034_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}

ll n, m, a, b, temp, x, y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	ll c, d;
	cin >> a >> b;
	cin >> c >> d;
	cin >> str;
	if (c < d)
	{
		ll dpb[n + 10] = { 0 };
		ll dpa[n + 10] = { 0 };
		dpb[b - 1] = 1;
		dpa[a - 1] = 1;
		if (str[b] != '#')
			dpb[b] = 1;
		if (str[a] != '#')
			dpa[a] = 1;
		for (int i = b + 1; i < d; i++)
		{
			if (str[i] == '#')
				continue;
			if (dpb[i - 1] == 1 || dpb[i - 2] == 1)
				dpb[i] = 1;
		}

		for (int i = a + 1; i < c; i++)
		{
			if (str[i] == '#')
				continue;
			if (dpa[i - 1] == 1 || dpa[i - 2] == 1)
				dpa[i] = 1;
		}

		if (dpb[d - 1] != 1)
		{
			cout << "No";
			return 0;
		}

		if (dpa[c - 1] != 1)
		{
			cout << "No";
			return 0;
		}

		cout << "Yes";
		return 0;
	}
	else
	{
                 str.pb('.');
		ll dpa[n + 1] = { 0 };
		ll dpb[n + 1] = { 0 };
		ll revdpa[n + 1] = { 0 };
		ll revdpb[n + 1] = { 0 };
		dpb[b - 1] = 1;
		dpa[a - 1] = 1;
		if (str[b] != '#')
			dpb[b] = 1;
		if (str[a] != '#')
			dpa[a] = 1;
		for (int i = b + 1; i < d; i++)
		{
			if (str[i] == '#')
				continue;
			if (dpb[i - 1] || dpb[i - 2])
				dpb[i] = 1;
		}
		for (int i = a + 1; i < c; i++)
		{
			if (str[i] == '#')
				continue;
			if (dpa[i - 1] || dpa[i - 2])
				dpa[i] = 1;
				//deb(d);
		}

		//deb(d);
		if (dpb[d - 1] != 1)
		{
			cout << "No";
			return 0;
		}

		if (dpa[c - 1] != 1)
		{
			cout << "No";
			return 0;
		}

		revdpa[c - 1] = 1;
		revdpb[d - 1] = 1;
		if (str[d - 2] != '#')
			revdpb[d - 2] = 1;
		if (str[c - 2] != '#')
			revdpa[c - 2] = 1;
		for (int i = c - 3; i >= a - 1; i--)
		{
			if (str[i] == '#')
				continue;
			if (revdpa[i + 1] || revdpa[i + 2])
				revdpa[i] = 1;
		}

		for (int i = d - 3; i >= b - 1; i--)
		{
			if (str[i] == '#')
				continue;
			if (revdpb[i + 1] || revdpb[i + 2])
				revdpb[i] = 1;
		}

		for (int i = b - 1; i <= d - 1; i++)
		{
			if (str[i - 1] == '.' && str[i] == '.' && str[i + 1] == '.')
			{
				if (revdpa[i + 1] && dpa[i - 1] && dpb[i])
				{
					cout << "Yes";
					return 0;
				}
			}
		}

		cout << "No";
	}
}

Measured memory_bytes: 6608
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

   int x;  cin >> x;
   if(x >= 1200) {
      cout << "ARC" << endl;
   } else {
      cout << "ABC" << endl;
   }

   return 0;
}


Measured memory_bytes: 256
// abc171_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(100005, 0);
  ll A_sum = 0;
  rep(i, N) {
    int tmp;
    cin >> tmp;
    A[tmp]++;
    A_sum += tmp;
  }
  int Q;
  cin >> Q;
  rep(i, Q) {
    ll B, C;
    cin >> B >> C;
    ll value = A[B];
    A[B] = 0, A[C] += value;
    A_sum = A_sum + (C - B) * value;
    cout << A_sum << endl;
  }

  return 0;
}


Measured memory_bytes: 3936
const main = input => {
    const N = parseInt(input.trim());
    let count = 0;
    for (let i = 1; i <= N; i++) {
        if (!(i % 3 == 0 || i % 5 == 0)) {
            count += i;
        }
    }

    console.log(count);
};

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 35136
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;



ll a, b;
int main()
{
        cin>> a >> b;
        if(a <= 9 && b <= 9) {
                cout << a*b << endl;
        }else cout << "-1\n";
        return 0;
}


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

int main()
{
	int n;					//?????°
	int num[200][3];		//num[i][j] = ?????¬?????????i+1???j+1??????????¨???\?????????
	int score[200] = {0};	//score[i] = ?????¬?????????i+1???????????¢
	int i, j, k;			//???????????¨?????°
	
	cin >> n;
	for( i = 0; i < n; i++ ){
		for( j = 0; j < 3; j++ ){
			//?????¬?????????i+1???j+1??????????¨???\??????????????\?????????
			cin >> num[i][j];
		}
	}
	
	//3?????????????????????
	for( i = 0; i < 3; i++ ){
		//?????¬?????????j+1???????????¢????????????
		for( j = 0; j < n; j++ ){
			//??°????????????
			for( k = 0; k < n; k++ ){
				if( j == k )
					continue;
				if( num[j][i] == num[k][i] )
					break;
			}
			//??°??¨????????´??????????????°???????????¢???????????????
			if( k == n )
				score[j] += num[j][i];
		}
	}
	
	//?????¬?????????1???n???????????¢???????????????
	for( i = 0; i < n; i++ ){
		cout << score[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define N 1000009
using namespace std;
typedef long long LL;

int solve(int x)
{
    if(x == 2) return 1;
    if(x == 4 || x == 6 || x == 9 || x == 11) return 2;
    return 3;
}

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);
    if(solve(x) == solve(y)) puts("Yes");
    else puts("No");
    return 0;
}


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

#define MAX_X 4
#define MAX_Y 50
#define MAX_N 50

using namespace std;
typedef pair<int,int> event;

int main(){
	int X,Y,Z;
	cin >> X >> Y >> Z;
	while(X){
		int V[MAX_X];
		for(int i = 0; i < X; ++i){
			cin >> V[i];
		}
		map<int,event> ev;
		for(int i = 0; i < Z; ++i){
			int n, e, a;
			cin >> n >> e >> a;
			ev[n] = event(e,a);
		}
		//i番目のマスでj円持っている確率
		double p[MAX_N+1][100*MAX_N] = {0};
		p[0][0] = 1;
		for(int i = 0; i < Y; ++i){
			for(int j = 0; j < 100*MAX_N; ++j){
				if(p[i][j]){
					for(int k = 0; k < X; ++k){
						if(ev.find(i+V[k]) == ev.end()){
							p[min(i+V[k],Y)][j] += p[i][j]/X;
						}else{
							switch(ev[i+V[k]].first){
								case 1:
									p[min(i+V[k]+ev[i+V[k]].second,Y)][j] += p[i][j]/X;
									break;
								case 2:
									p[i+V[k]][j+ev[i+V[k]].second] += p[i][j]/X;
									break;
								case 3:
									p[i+V[k]][max(0, j-ev[i+V[k]].second)] += p[i][j]/X;
									break;
							}
						}
					}
				}
			}
		}
		double E = 0;
		for(int i = 0; i < 100*MAX_N; ++i){
			E += p[Y][i]*i;
		}
		cout << (int)E << endl;
		cin >> X >> Y >> Z;
	}
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 100100;
const ll MOD = 1e9+7;

int h[MAXN];

int main()
{
    FAST_IO;

    int n; cin >> n;
    FOR(i, 1, n) cin >> h[i];

    FOR(i, 2, n) if (h[i] < h[i-1]) h[i]++;

    bool ok = true;
    FOR(i, 2, n) if (h[i] < h[i-1]) ok = false;

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "

const int mod = 1e9+7;
ll power(ll base, ll p)
{
  ll ret = 1 % mod;
  while (p)
    {
      if (p&1) ret = ret * base % mod;
      p >>= 1;
      base = base * base % mod;
    }
  return ret;
}

ll inverse(ll base)
{
  return power(base, mod-2);
}
const int N = 2e5+1;
ll f[N], inv[N];
inline ll cb(ll n, ll k)
{
  if (n < k || n < 0 || k < 0) return 0;
  return f[n] * inv[k] % mod * inv[n-k] % mod;
}
void init()
{
  f[0] = 1;
  for (ll i = 1; i < N; ++i) f[i] = f[i-1] * i % mod;
  inv[N-1] = inverse(f[N-1]);
  for (int i = N-1; i >= 1; --i) inv[i-1] = inv[i] * i % mod;
}
int main()
{
  init();
  int n, m, k; scanf("%d %d %d", &n, &m, &k);
  ll ans = 0;
  ll cnt_per_pair = cb(n*m-2, k-2);
  //  cerr << "cnt_per_pair = " << cnt_per_pair << endl;
  for (int t = 0; t < 2; ++t, swap(n, m))
    for (int i = 1; i <= (n-1); ++i)
      (ans += 1ll * i * (n-i) % mod * m % mod * m % mod) %= mod;
  (ans *= cnt_per_pair) %= mod;
  printf("%lld\n", ans);
}

// 126 * 6 / 36


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
  int n, x[100], y[100];
  cin >> n;
  for (int i=0; i<n; i++) cin >> x[i];
  for (int i=0; i<n; i++) cin >> y[i];
  double d[4] = {};
  for (int p=1; p<4; p++) {
    for (int i=0; i<n; i++) d[p] += pow(fabs(x[i]-y[i]), p);
    d[p] = pow(d[p], 1.0/p);
  }
  for (int i=0; i<n; i++) {
    d[0] = (d[0]<fabs(x[i]-y[i])?fabs(x[i]-y[i]):d[0]);
  }
  for (int p=1; p<4; p++) {
    printf("%f\n", d[p]);
  }
  printf("%f\n", d[0]);
  return 0;
}



Measured memory_bytes: 3336
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cntv(v,a) count(v.begin(),v.end(),a)
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
const ll X[]= {+0,+0,+1,-1,-1,+1,-1,+1};
const ll Y[]= {-1,+1,+0,+0,+1,+1,-1,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
// head collected

ll t, n, k, _, __,ans;
string str;

start;

    cin1(t);

    ll sum = 0;
    rep(i, 1, t+1){
        if( i%3==0 || i%5==0)
            continue;
        sum += i;
    }


    coul(sum);
     /*if( a == 7 || b == 7 || c ==  7 )
        coul("Yes");
     else
        coul( "No");*/



finish


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 5e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
ll n, k;
int a[N];
vector<int>vc;
int vis[N];
int main() {
	scanf("%lld%lld", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int u = 1;
	while (!vis[u]) {
		vc.push_back(u);
		vis[u] = 1;
		u = a[u];
	}
	n = (ll)vc.size();
	if (k < n) {
		printf("%d\n", vc[k]);
		return 0;
	}
	int s = 0;
	for (int i = 0; i < n; i++)if (vc[i] == u)s = i;
	ll t = n - s;
	printf("%d", vc[s + (k - s) % t]);
	return 0;
}

Measured memory_bytes: 5928
#include<iostream>
#include<string>
using namespace std;
int main(){
    string cards, shuffle1, shuffle2;
    int m, x;
    int j = 0;
    while(j <= 10){
        cin >> cards >> m;
        if(cards == "-"){
            break;
        }
        for(int i = 0; i < m; i++){
            cin >> x;
            shuffle1 = cards.substr(0, x);
            shuffle2 = cards.substr(x, cards.size() - x);
            cards = shuffle2 + shuffle1;
        }
        cout << cards << endl;
        j += 1;
        
    }
    
    
    return 0;
}


Measured memory_bytes: 3212
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

i64 nC2(i64 n) {
    return n * (n - 1) / 2;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N, P);
    var(string, S);
    reverse(all(S));

    if (P == 2) {
        i64 ans = 0;
        rep(i, 0, N) {
            if ((S[i] - '0') % 2 == 0) ans += N - i;
        }
        print(ans);
        return 0;
    }

    if (P == 5) {
        i64 ans = 0;
        rep(i, 0, N) {
            if ((S[i] - '0') % 5 == 0) ans += N - i;
        }
        print(ans);
        return 0;
    }

    vector<i64> cum(N + 1);
    vector<i64> cnt(P);
    i64 p10 = 1;
    rep(i, 0, N) {
        cum[i + 1] = cum[i] + p10 * (S[i] - '0');
        cum[i + 1] %= P;
        p10 *= 10;
        p10 %= P;
        cnt[cum[i]] += 1;
    }
    cnt[cum[N]] += 1;

    i64 ans = 0;
    rep(i, 0, P) {
        ans += nC2(cnt[i]);
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 2196
import itertools
import numpy as np
N = int(input())
sug=[]
#print(sug)
for i in range(N):
  sug.append([])
  A = int(input())
  for j in range(A):
    sug[i].append(list(map(lambda x: int(x),input().split())))
#print(sug)
  
bi = [1,0]
x = itertools.product(bi,repeat=N)
max_honest=0
for i in x:
  #print(i)
  flag=True
  for idx in range(N):
    if i[idx]==1:
      for candidate in sug[idx]:
        if i[candidate[0]-1] != candidate[1]:
          flag=False
          break
      if not flag:
        continue
  if not flag:
    continue
  if max_honest<sum(i):
    max_honest=sum(i)
print(max_honest)

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

using namespace std;

int main(){
  int64_t n;
  int64_t a;
  int64_t b;
  int64_t ans=0;
  cin >> n >> a >> b;
  if(a>b){
    int64_t tmp=a;
    a=b;
    b=tmp;
  }
  if(abs(a-b)%2!=0){
    if(abs(1-a) < abs(n-b)){
      ans = abs(1-a);
      ans++;
      b = abs(b-ans);
      ans = ans+abs(b-1)/2;
    }
    else{
      ans = abs(n-b);
      ans++;
      a = abs(a+ans);
      ans = ans+abs(n-a)/2;
    }
  }
  else{
    ans=abs(b-a)/2;
  }
  cout << ans << endl;
}


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

def solve(N: int, K: int, A: "List[int]"):

    ans = math.ceil((N-1)/(K-1))
    print(ans)

    return


# Generated by 1.1.5 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
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
def sol(lis):
    if len(lis)<=2:
        return abs(lis[0]-lis[1])
    costs = [0,abs(lis[0]-lis[1])]
    for i in range(2,len(lis)):
        x = abs(lis[i]-lis[i-1])
        y = abs(lis[i]-lis[i-2])
        costs.append(min(x+costs[-1],y+costs[-2]))
    return costs[-1]
input()
lis = list(map(int,input().split(' ')))
print(sol(lis))

Measured memory_bytes: 20444
#include<iostream>
#include<vector>

int main(){
    int n;
    int ans = 0;

    std::cin >> n;
    std::vector<int> d(n);
    for(int i = 0; i < n; i++){
        std::cin >> d.at(i);
    }

    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            ans += d.at(i) * d.at(j);
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int bubbleSort(int A[N],int n){
	
	int swap = 0,temp;
	for(int i = 0; i < n-1; i++){
		for(int j = n-1; j > i; j--){
			if( A[j] < A[j-1]){
				temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;
				swap++;
			}
		}
	}
	
	return swap;
	
}

int main(void){
	
	int A[N];
	int n,swap;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &A[i]);
	}
	
	swap = bubbleSort(A,n);
	
	for(int i = 0; i < n; i++){
		if( i == n-1 ){
			printf("%d\n", A[i]);
			break;
		}
		printf("%d ", A[i]);
	}
	printf("%d\n", swap);
	
}


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

int main() {
	int x;
	cin >> x;
	if (x >= 2000) {
		cout << 1 << endl;
		return 0;
	}
	int hun = x / 100;
	int min = hun * 100;
	int max = min + 5 * hun;
	if (min <= x && x <= max) cout << 1 << endl;
	else cout << 0 << endl;
}

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

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

    int R=0;
    int B=0;
    for(int i=0; i<N; i++){
        if(S[i]-'R'==0){
            R++;
        }else{
            B++;
        }
    }
    if(R>B){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define revstr(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
int main(void)
{
	ld a,b,x;
	cin>>a>>b>>x;
	if((a*a*b)/2.0>=x)
	{
		ld result=atan((a*b*b)/(2.0*x))*180/M_PI;
		printf("%0.7Lf\n",result);
		return 0;
	}
	ld result=atan((2.0*((a*a*b)-x))/(a*a*a))*180/M_PI;
	printf("%0.7Lf\n",result);
	return 0;
}

Measured memory_bytes: 256
function main(arg) {
    let lines = arg.split("\n")
    let [n,m,k] = lines[0].split(" ").map(x=>parseInt(x))
    let A = lines[1].split(" ").map(x=>parseInt(x))
    let B = lines[2].split(" ").map(x=>parseInt(x))

    let a = [0]
    let b = [0]
    for(let i=0; i<n; i++) {
        a.push(a[i]+A[i])
    }
    for(let i=0; i<m; i++) {
        b.push(b[i]+B[i])
    }
    
    let ans=0, j=m
    for(let i=0; i<=n; i++) {
        if(a[i] > k)break;
        while(b[j] > k-a[i]) {
            j--
        }
        ans = Math.max(ans, i+j)
    }
    console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 83008