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

using namespace std;
typedef long long ll;
ll a[200010],fro[200010],bac[200010],dpfro[200010][2],dpbac[200010][2];
int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    if(n%2==0){
        ll ans1 = 0;
        dpfro[0][0] = 0; dpfro[0][1] = 0;
        dpfro[2][0] = a[0]; dpfro[2][1] = a[1];
        for(i=4;i<=n;i+=2){
            dpfro[i][0] = dpfro[i - 2][0] + a[i - 2];
            dpfro[i][1] = max(dpfro[i - 2][0],dpfro[i - 2][1]) + a[i - 1];
        }
        cout << max(dpfro[n][0],dpfro[n][1]) << endl;
    }else{
        dpfro[0][0] = 0; dpfro[0][1] = 0;
        dpfro[2][0] = a[0]; dpfro[2][1] = a[1];
        for(i=4;i<=n;i+=2){
            dpfro[i][0] = dpfro[i - 2][0] + a[i - 2];
            dpfro[i][1] = max(dpfro[i - 2][0],dpfro[i - 2][1]) + a[i - 1];
        }
        dpbac[n - 1][0] = 0; dpbac[n - 1][1] = 0;
        dpbac[n - 3][0] = a[n - 1]; dpbac[n - 3][1] = a[n - 2];
        for(i=n - 5;i>=0;i--){
            dpbac[i][0] = dpbac[i + 2][0] + a[i + 2];
            dpbac[i][1] = max(dpbac[i + 2][0],dpbac[i + 2][1]) + a[i + 1];
        }
        ll ans = -10000000000000000;
        for(i=0;i<n;i+=2){
            ans = max(ans,max(dpfro[i][0],dpfro[i][1]) + max(dpbac[i][0],dpbac[i][1]));
        }
        /*for(i=0;i<n;i++){
          cout << i << " " << dpfro[i][0] << " " << dpfro[i][1] << " " << dpbac[i][0] << " " << dpbac[i][1] << endl;
        }*/
        cout << ans << endl;
    }
}

Measured memory_bytes: 11432
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const int MOD = 998244353;

int X[100010];
int diff[100010];
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) cin >> X[i];
	sort(X, X + M);
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = X[M - 1] - X[0];
	for (int i = 0; i < M - 1; i++) {
		diff[i] = X[i + 1] - X[i];
	}
	sort(diff, diff + M - 1, greater<int>());
	for (int i = 0; i < N - 1; i++) {
		ans -= diff[i];
	}
	cout << ans << endl;
}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  } else if ((A + B) < (C + D)){
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
s = input()
ss = set(s)
# print(ss)
ans = float('inf')
for si in ss:
    cnt = 0
    copy_s = list(s)
    # print(copy_s)
    while len(set(copy_s)) != 1:
        # copy_s.pop()
        cnt += 1
        for i in range(len(copy_s)-1):
            if copy_s[i+1] == si:
                copy_s[i] = si
        copy_s.pop()
    ans = min(ans, cnt)

print(ans)

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a==b&&a!=c)cout<<"Yes"<<endl;
	else if(a==c&&a!=b)cout<<"Yes"<<endl;
	else if(b==c&&a!=b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  string s;
  cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3572
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let r: f64 = iter.next().unwrap().parse().unwrap();
    let pi: f64 = std::f64::consts::PI;

    println!("{} {}", r * r * pi, 2.0 * r * pi);
}


Measured memory_bytes: 5060
#include <iostream>
#include <cmath>

using namespace std;

// 入力
long long N;

int main(void) {
    cin >> N;

    long long tmp = N;
    int digit = 0;
    bool all_nine = true;
    bool only_last_not_nine = false;
    while (N != 0) {
        if (all_nine && N / 10 == 0) {
            only_last_not_nine = true;
        }
        if (N % 10 != 9) {
            all_nine = false;
        }
//        cout << N / 10 << endl;
        N /= 10;
        digit++;
    }
    N = tmp;


    int sum = 0;
    for (int i = 1; i < digit; ++i) {
        if (N % (long long) (pow(10, i)) == 9) {
            sum += 9;
        } else {
            sum += 9;
            N -= (long long) (pow(10, i));
        }
//        cout << i << endl;
//        cout << N << endl;
//        cout << sum << endl;
    }
    N = tmp;
    if (all_nine && N >= 100) {
        sum += N / (long long) (pow(10, digit - 1));
    } else if (all_nine) {
        sum += N / (long long) (pow(10, digit - 1));
    } else {
        sum += N / (long long) (pow(10, digit - 1)) - 1;
    }
//    cout << false << endl;
//    cout << only_last_not_nine << endl;
    if (!all_nine && only_last_not_nine) {
        sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int mune[4][3][10]={{{0}}};
    for(int i=0;i<n;i++){
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        mune[b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<4;i++){
        for(int r=0;r<3;r++){
            for(int y=0;y<10;y++){
                cout << " " << mune[i][r][y]  << flush;
            }
            cout << endl;
        }
        if(i!=3)cout << "####################" << endl;
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
string s;
void solve(){
	vector<char> v;
	int n= s.length();
	v.eb(s[0]);
	for(int i=1;i<n;i++){
		if(s[i]==')' && v.back()=='(') v.pop_back();
		else v.eb(s[i]);
	}
	int i=0;
	while(i<v.size()&& v[i]==')'){
		i++;
	}
	int count=i;
	int count1=v.size()-i;
	string t(count,'(');
	string t1(count1,')');
	cout << t+s+t1;
}
int main(){
	int k;
	cin >> k;
	cin >> s;
	solve();

	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)
N4 = A.select{ |a| a % 4 == 0 }.size
NO = A.select{ |a| a % 2 == 1 }.size
N2 = N - N4 - NO

puts N4 >= NO - (N2 == 0 ? 1 : 0) ? "Yes" : "No"

Measured memory_bytes: 9348
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



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

        vll A(N);
        vll B(N);
        rep(i, 0, N) cin >> A[i];
        rep(i, 0, N) cin >> B[i];

        if (N == 1) {
                cout << A[0] + B[0] << endl;
                return 0;
        }

        ll mx = -inf;
        rep(pos, 0, N) {
                ll s1 = accumulate(A.begin(), A.begin()+(pos+1), 0LL);
                ll s2 = accumulate(B.begin()+pos, B.end(), 0LL);
                chmax(mx, s1+s2);
        }

        cout << mx << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
#define MAX_V 30000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
//辺を表す構造体{行き先、容量、逆辺}
struct edge{ll to,cap,rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];//dfsですでに調べたかのフラグ
//fromからtoへの流量capの辺をグラフに追加
void add_edge(ll from,ll to,ll cap){
    //cout<<from<<" "<<to<<" "<<cap<<endl;
    G[from].push_back((edge){to,cap,static_cast<ll>(G[to].size())});
    G[to].push_back((edge){from,0,static_cast<ll>(G[from].size()-1)});
}
//増加パスをdfsで探す
ll dfs(ll v,ll t,ll f){
    if(v==t)return f;
    used[v]=true;
    for(ll i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        if(!used[e.to]&&e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
ll max_flow(ll s,ll t){
    ll flow=0;
    while(1){
        memset(used,0,sizeof(used));
        ll f=dfs(s,t,inf);
        if(f==0)return flow;
        flow+=f;
    }
}
///////////////////////////////////////



int main(){
    int x,y,e;cin>>x>>y>>e;
    set<i_i>s;
    while(e--){
        i_i z;cin>>z.first>>z.second;
        s.insert(z);
    }
    int N=105;
    int flag=0;
    for(auto z:s){
        add_edge(z.first,N+z.second,1);
        
    }
    int sta=2*N,end=2*N+1;
    rep(i,0,N-1){
        add_edge(sta,i,1);
        add_edge(i+N,end,1);
    }
    cout<<max_flow(sta,end)<<endl;
    
    return 0;
}



Measured memory_bytes: 4840
H,W = map(int, input().split())
S = [list(input()) for _ in range(H)] #データ形式はS[i][j]

eight = [[-1,-1],[0,-1],[1,-1], # 周囲8マスの定義
         [-1,0],[1,0],
         [-1,1],[0,1],[1,1]]

for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      for e in eight:
        if (0 <= i+e[0] < H) and (0 <= j+e[1] < W) :
          target = S[i+e[0]][j+e[1]]
          if target != '#' :
            if target == '.' :
              S[i+e[0]][j+e[1]] = 1
            else :
              S[i+e[0]][j+e[1]] += 1

for i in range(H):
  for j in range(W):
    print('0' if S[i][j] == '.' else str(S[i][j]), end='')
  if i < H: print('')

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    map<string,int> smap;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        smap[s]++;
    }
    int maxn=0;
    for(const auto& item:smap){
        maxn=max(maxn,item.second);
    }
    for(const auto& item:smap){
        if(maxn==item.second){
            cout<<item.first<<endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pr pair<int,int>
#define endl "\n"
#define MOD 1000000007 // 10^9 + 7
#define sz(x) (int)(x).size()
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define all(c) (c).begin(), (c).end()
#define FOR(i,b) for (int i = 0; i < (b); i++)
#define FORR(i,a,b) for (int i = a; i < (b); i++)
#define FORB(i,b) for (int i = (b); i >= (0); i--)
#define FORRB(i,a,b) for (int i = (a);i>= (b); i--)

using namespace std;

int n,k;
int arr[100010],dp[100010];

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

	//freopen("addin.txt","r",stdin);
	//freopen("addout.txt","w",stdout);
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> arr[i];
	memset(dp,63,sizeof(dp));
	dp[0] = 0,dp[1] = 0;
	for(int i = 1;i <= n;i++){

		for(int j = 1;j <= k;j++){
			if(i+j <= n)
				dp[i+j] = min(dp[i+j],dp[i] + abs(arr[i+j-1] - arr[i-1]));
			else break;
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(void){
  char a;
  cin>>a;
  switch(a){
    case 'A':
      cout<<"T"<<endl;
      break;
    case 'C':
      cout<<"G"<<endl;
      break;
    case 'G':
      cout<<"C"<<endl;
      break;
    case 'T':
      cout<<"A"<<endl;
      break;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int w[6] = {100,101,102,103,104,105};
int dp[maxn],x;
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> x;
	dp[0] = 1;
	for(int i = 0;i < 6;i++){
		for(int j = w[i];j<=x;j++) dp[j] += dp[j-w[i]];
	}
	if(dp[x]) puts("1");
	else puts("0");
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 640
#include "stdio.h"

int main(){
  int n,lim,h[100001],ans=0;
  scanf("%d %d",&n,&lim);
  for(int i=0;i<n;i++){
     scanf("%d",&h[i]);
    if(h[i]>=lim)ans++;
  }
 
  printf("%d",ans);
  return 0;
}

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

long long calc(int n, int c1, int c2, int s1, int s2, const vector<int>& options,
               int d, int nt, int ot) {
  int b1(d-1), a1(d+1), b2(d-1), a2(d+1);
  while (b1 >= 0 && options[b1] != nt) b1--;
  while (b2 >= 0 && options[b2] != ot) b2--;
  while (a1 < n && options[a1] != nt) a1++;
  while (a2 < n && options[a2] != ot) a2++;
  int x1(d-b1-1), y1(a1-d-1), z1(a1-b1-1), x2(d-b2-1), y2(a2-d-1), z2(a2-b2-1);
  int diff1 = z1*(z1+1)/2-x1*(x1+1)/2-y1*(y1+1)/2;
  int diff2 = z2*(z2+1)/2-x2*(x2+1)/2-y2*(y2+1)/2;
  return (long long) diff1 * c1 - (long long) diff2 * c2 + s1 - s2;
}

int main() {
  srand (time(NULL));
  int n;
  cin >> n;
  vector<int> c(26);
  vector<array<int, 26>> s(n);
  
  vector<int> last(26, -1);
  
  for (int i = 0; i < 26; ++i)
    cin >> c[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  
  long long total(0);
  vector<int> options(n);
  
  for (int i = 0; i < n; ++i) {
    int neg(0), test(-1);
    for (int j = 0; j < 26; ++j) neg -= c[j] * (i - last[j]);
    int max_score = -1e9;
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + c[j] * (i - last[j]);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    total += max_score;
    options[i] = test;
    last[test] = i;
  }
  /* reversed: 109149564 */
  /* sorted: 110465449 */
  /* stocahstic */
  
  for (int t = 1; t <= 200000; ++t) {
    vector<pair<int, int>> idxs(5);
    int dt = 0;
    for (int x = 0; x < 5; ++x) {
      int dd = idxs[x].first = rand() % n;
      int tt = rand() % 26;
      int ot = idxs[x].second = options[dd];
      while (ot == tt) tt = rand() % 26;
      long long ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot],
                          options, dd, tt, ot);
      dt += ns;
    }
    if (dt < 0) {
      for (int i = 0; i < 5; ++i)
        options[idxs[i].first] = idxs[i].second;
    } else {
      total += dt;
    }
  }
  for (const int& i: options) cout << i + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define pb push_back
#define ALL(v) v.begin(),v.end()
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }
using Graph = vector<vector<int>>;
int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(K <= A)
    {
        cout << K << endl;
    }
    else if(A+B >= K){
        cout << A << endl;
    }
    else{
        int d = K-A-B;
        cout << A-d << endl;
    }
    return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

// x = f(x,y) を k回
template<class T, class F>
T binpow(T y, ll k, F f, T x) {
    T ret = x, p = y;
    while(k > 0) {
        if(k%2 == 0) {p = f(p, p); k /= 2;}
        else {ret = f(ret, p); k--;}
    }
    return ret;
};

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i], a[i]--;

    vector<ll> d(n);
    iota(ALL(d), 0);
    auto mul = [](vector<ll> a, vector<ll> b) {
        vector<ll> ret(a.size());
        REP(i, a.size()) ret[i] = b[a[i]];
        return ret;
    };
    cout << binpow(a, k, mul, d)[0]+1 << endl;

    return 0;
}

Measured memory_bytes: 17316
//  IT'S NEVER TOO LATE...

		    #include <bits/stdc++.h>
			#include <complex>
		    #define ll long long

			#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
			#define forn(i, n) fore(i, 0, n)
			#define fori(i, l, r) fore(i, l, (r) + 1)
			#define sz(v) int((v).size())
			#define all(v) (v).begin(), (v).end()
			#define pb push_back
			#define mp make_pair
		    #define ff first
		    #define ss second
			#define inf 1e9
		    
			#define C complex<int>
			#define X real()
			#define Y imag()

		    using namespace std; 

		    const double PI = atan(1)*4;


		    bool isprime(int n)
		    {
		        for(int i=2;i*i<=n;i++)
		            if(n%i==0)
		                return false;
		        return true;
		    }
		     
		    bool comp(pair<int,int> a, pair<int,int> b)
		    {
		    	return b.ff < a.ff ;
		    }

		    int modpow(int b,int p,int m)
		    {
		    	if(p==0) return 1%m;
		    	if(p%2) return (b*modpow(b,p-1,m))%m;
		    	int u=modpow(b,p/2,m);
		    	return (u*u)%m;
		    }

		    vector<int> ar[100005];
		    int vis[100005],from[100005];
		    double dis[100005];
		    
		     
		/*    void dikstra(int s,int n)
		    {
		    	forn(i,n+3)
		    	{
		    		dis[i]=inf;
		    		vis[i]=0;
		    		from[i]=-1;
		    	}

		    	dis[s]=0;
		    	priority_queue<pair<int,int>> q;
		    	q.push({0,s});
		    	from[s]=s;

		    	while(!q.empty())
		    	{
		    		pair<int,int> a;
		    		a=q.top();
		    		q.pop();
		    		//cout<<a.ss<<" ";

		    		if(vis[a.ss]) continue;
		    		vis[a.ss]=1;

		    		for(pair<int,int> b:ar[a.ss])
		    		{
		    			if(dis[b.ff]>dis[a.ss] + b.ss)
		    			{
		    				dis[b.ff]=dis[a.ss] + b.ss;
		    				from[b.ff]=a.ss;
		    				q.push({-dis[b.ff],b.ff});
		    			}
		    		}
		    	}
		    }*/

		    set<int> fact(int n)
		    {
		    	set<int> s;
		    	for(int i=1;i*i<=n;i++)
		    	{
		    		if(n%i==0)
		    		{
		    			s.insert(i);
		    			s.insert(n/i);
		    		}
		    	}
		    	return s;
		    }

		    int main()
		    {
		    //	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		     
		    	#ifndef ONLINE_JUDGE
		        freopen("input.txt","r", stdin);
		        freopen("output.txt", "w", stdout);
		        #endif
		     
		    	int t=1;
		    	//cin>>t;
		    	
		    	while(t--)
		    	{
		    		int n;
		    		cin>>n;

		    		int a[n+1];
		    		ll ans=0;
		    		map<int,int> m;
		    		fori(i,1,n) cin>>a[i] , m[i+a[i]]++;

		    		fori(i,1,n)
		    		{
		    			ans+=(ll)m[i-a[i]];
		    		}

		    		cout<<ans;
		    	}

		    	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

		    	return 0;
		    }
		    				//              NOW IT'S TIME TO WAKE UP...

Measured memory_bytes: 23868
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cctype>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e7;
int n, m, c, s, g;
VVI q, r, d;

int calc_cost(int rail, int dist){
    int res = 0;
    int p = r[rail].size();
    REP(i,p){
        if (dist < q[rail][i]){
            if (i == 0) res += dist * r[rail][i];
            else res += (dist - q[rail][i-1]) * r[rail][i];
            break;
        }else{
            if (i == 0) res += q[rail][i] * r[rail][i];
            else res += (q[rail][i] - q[rail][i-1]) * r[rail][i];
        }
    }
    return res;
}

int main() {
    while (cin >> n >> m >> c >> s >> g && n){
        s--;
        g--;
        q.clear();
        r.clear();
        q.resize(c);
        r.resize(c);
        vector<VVI> dist(c, VVI(n, VI(n, INF)));
        REP(i,c) REP(j,n) dist[i][j][j] = 0;
        while (m--){
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--;
            y--;
            c--;
            dist[c][x][y] = min(dist[c][x][y], d);
            dist[c][y][x] = min(dist[c][y][x], d);
        }
        VI p(c);
        REP(i,c) cin >> p[i];
        REP(i,c){
            q[i].resize(p[i]-1);
            r[i].resize(p[i]);
            REP(j,p[i]-1) cin >> q[i][j];
            q[i].push_back(INF);
            REP(j,p[i]) cin >> r[i][j];
        }

        REP(r,c) REP(i,n) REP(j,n) REP(k,n) dist[r][j][k] = min(dist[r][j][k], dist[r][j][i] + dist[r][i][k]);

        VVI cost(n, VI(n, INF));
        REP(r,c) REP(i,n) REP(j,n){
            cost[i][j] = min(cost[i][j], calc_cost(r, dist[r][i][j]));
        }

        REP(i,n) REP(j,n) REP(k,n) cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);

        cout << (cost[s][g] == INF ? -1 : cost[s][g]) << endl;
    }
}

Measured memory_bytes: 3520
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  map<ll, ll> mp;
  rep(i, n) {
    ll a;
    cin >> a;
    mp[a]++;
    mp[a] = mp[a] % 2;
  }
  ll e = 0, o = 0;
  for (auto x : mp) {
    if (x.second & 1) {
      o++;
    } else {
      e++;
    }
  }

  ll ans = o + e - e % 2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9824
import math
N = int(input())
l = [0] * N
for x in range(1, int(math.sqrt(2 * N))):
    for y in range(1, int(math.sqrt(2 * N))):
        for z in range(1, int(math.sqrt(2 * N))):
            A = int(x * (x + y) +  y * (y + z) + z * (z + x))
            if A <= N:
                l[A - 1] += 1
for i in range(N):
    print(l[i])

Measured memory_bytes: 9156
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    long long ans=0,sum=0,a[100000],b[100000];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&a[i],&b[i]);
        sum+=a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            ans=max(ans,sum-b[i]);
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 512
<?php
$n = trim(fgets(STDIN));
$q = explode(' ',trim(fgets(STDIN)));

$m = trim(fgets(STDIN));
for($i=0; $i<$m; $i++){
	$ch = explode(' ',trim(fgets(STDIN)));
  
  	$t = 0;
  	for($j=0; $j<$n; $j++){
      if ($j == $ch[0]-1){
        $t += $ch[1];
      } else {
        $t += $q[$j];
      }
    };
  
  	if ($i !== 0) echo "\n";
  	echo $t;
}

?>

Measured memory_bytes: 4604
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      String s = sc.next();
      int lng = s.length();
      char[] c = new char[lng];
      for(int i=0;i<lng;i++){
        c[i] = s.charAt(i);
      }

      long k = Long.parseLong(sc.next());

      String start = s.substring(0,1);
      String end = s.substring(lng-1,lng);

      long ans = 0;

      int onaji = 1; //同じ数が何個続いたか
      long[] onajiN = new long[3]; //[0]初め、[1]終わり、[2]中全部
      int cnt = 0;
      char all = c[0];
      int ok = 0;
///////////////////////////////////////////////
for(int i=1;i<lng;i++){
  if(c[i-1]==c[i]){
    onaji ++;
  }
  else{
    onajiN[cnt] = onaji;
    cnt = 2;
    onaji = 1;
  }
}
onajiN[1] = onaji;

for(int i=1;i<lng;i++){
  if(all!=c[i]){
    all = '-';
  }
  if(c[i-1]==c[i]){
    //onaji ++;
    ans++;
    c[i] = '-';
  }
  //else{
    //onajiN[cnt] = onaji;
    //cnt = 2;
    //onaji = 1;
  //}
}


//System.out.println(onajiN[0]);
//System.out.println(onajiN[1]);

if(!(start.equals(end))){ok = 1;} //両端違うなら独立
if(c[lng-1]=='-'){ok = 1;} //最後が書き換わってれば両端同じは無視

if(ok==1){
  ans = ans*k;
}
else{ //両端が同じかつ最後が書き換わってない場合
/////////////////////////////////////////////////////////////
if(all==c[0]){ //全部同じ文字
  ans = k*ans + k/2;
}
else{ //mae[---]ushiro
  if(onajiN[0]%2==0){ //maeが偶数個
    ans = ans*k; //独立と同じ
  }
  else{ //maeが奇数個
    ans = ans*k;
    //連結ごとに1個増える
    ans = ans + k-1;

  }

}
/////////////////////////////////////////////////////////////
}



System.out.println(ans);

    }
}


Measured memory_bytes: 21844
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;


int main(){
	int n, k; cin >> n>> k;
	vector<ll> da(n+1);
	vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(k+2, vector<ll>(n+1, LLONG_MAX/2)));
	rip(i,n,0) cin >> da[i+1];
	dp[0][0][0] = 0;
	rip(i,n+1,1){
		rip(j,k+1,0){
			rip(l, i, 0){
				dp[i][j+1][l] = dp[i-1][j][l];
				chmin(dp[i][j][i], dp[i-1][j][l] + max(da[i] - da[l], 0LL));
			}
		}
	}
	ll ans = LLONG_MAX/2;
	rip(i,k+1,0){
		rip(j,n+1,0){
			chmin(ans, dp[n][i][j]);
		}
	}
	// vdeb(dp);
	cout << ans << endl;
}

Measured memory_bytes: 217600
S = input()[::-1]
N = len(S)
mod = 10**9 + 7
DP = [[0] * 13 for _ in range(N+1)]
DP[0][0] = 1

for i, s in enumerate(S):
    if s != '?':
        a = int(s) * pow(10, i, 13) % 13
        for j in range(13):
            DP[i+1][j] += DP[i][(j-a) % 13] % mod

    else:
        for k in range(10):
            a = k * pow(10, i, 13) % 13
            for j in range(13):
                DP[i + 1][j] += DP[i][(j - a) % 13] % mod

print(DP[N][5] % mod)


Measured memory_bytes: 61756
# ABC157C - Guess The Number
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for m in range(M)]
for i in range(10**N):
    if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1)

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

int H, N;

struct Spell {
	int at;
	int mp;
};

Spell spells[10000];

int dp[20000]; // dp[i]: 体力iを0にするのに最も少ない魔力

const int INF = 1000000000;

int main(){

	cin >> H >> N;

	int A, B;
	int at_max = 0;
	for (int i=0; i<N; i++) {
		cin >> spells[i].at >> spells[i].mp;
		at_max = max(at_max, spells[i].at);
	}

	for (int i=1; i < H + at_max; i++) {
		dp[i] = INF;
	}

	for (int i=1; i < H + at_max; i++) {
		for (int j=0; j<N; j++) {
			if (i - spells[j].at < 0) continue;

			dp[i] = min(dp[i], dp[i - spells[j].at] + spells[j].mp);
		}
	}

	int ans = INF;

	for (int i=H; i < H + at_max; i++) {
		ans = min(ans, dp[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*
Dont BLUNDER
*/
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


 */
#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)

#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1 = 998244353;
int const mod = 1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */



int modexp(int x, int n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
	}
	else {
		return (modexp((x * x) % mod, n / 2) % mod);
	}
}

int modinv(int n)
{
	return modexp(n, mod - 2);
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}





signed main()
{
	haha
#ifndef ONLINE_JUDGE

	freopen("inp.txt", "r", stdin);

	freopen("out.txt", "w", stdout);
#endif
	int n;
	d d1;
	cin >> n >> d1;
	int c = 0;
	for (int i = 0; i < n; i++) {
		d x, y;
		cin >> x >> y;
		d s = sqrt(x * x + y * y);
		if (s <= d1)
			c++;

	}
	cout << c;






}

Measured memory_bytes: 3704
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define INF (1<<31)-1
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, q;
vector<int> BIT[2];
void init(int n_) {
	n = n_ + 1;
	BIT[0].resize(n, 0);
	BIT[1].resize(n, 0);
}

void add_sub(int p, int i, int x) {
	while (i < n) {
		BIT[p][i] += x;
		i += i & -i;
	}
}

void add(int l, int r, int x) {
	add_sub(0, l, -x * (l - 1));
	add_sub(0, r, x*(r - 1));
	add_sub(1, l, x);
	add_sub(1, r, -x);
}

int sum_sub(int p, int i) {
	int s = 0;
	while (0 < i) {
		s += BIT[p][i];
		i -= i & -i;
	}
	return s;
}
int sum(int i) {
	int s = sum_sub(0, i) + sum_sub(1, i)*i;
	int t = sum_sub(0, i - 1) + sum_sub(1, i - 1)*(i - 1);
	return s - t;
}

signed main() {
	cin >> n >> q;
	init(n);
	for (int i = 0; i < q; i++) {
		int a;
		cin >> a;
		if (!a) {
			int b, c, d;
			cin >> b >> c >> d;
			add(b, c + 1, d);
		}
		else {
			int b;
			cin >> b;
			cout << sum(b) << endl;
		}
	}
}


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

int main()
{
  int h,w;
  char s[51][51];
  int i;
  int j;
  int a[51][51];
  scanf("%d%d",&h,&w);
  for(i=0;i<h;i++){
    scanf("%s",s[i]);
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      a[i][j]=-1;
      if(s[i][j]=='.'){
        a[i][j]=0;
        if(0<=i-1 && 0<=j-1){
          if(s[i-1][j-1]=='#') a[i][j]++;
        }
        if(0<=i-1){
          if(s[i-1][j]=='#') a[i][j]++;
        }
        if(0<=i-1 && j+1<=w-1){
          if(s[i-1][j+1]=='#') a[i][j]++;
        }
        if(0<=j-1){
          if(s[i][j-1]=='#') a[i][j]++;
        }
        if(j+1<=w-1){
          if(s[i][j+1]=='#') a[i][j]++;
        }
        if(i+1<=h-1 && 0<=j-1){
          if(s[i+1][j-1]=='#') a[i][j]++;
        }
        if(i+1<=h-1){
          if(s[i+1][j]=='#') a[i][j]++;
        }
        if(i+1<=h-1 && j+1<=w-1){
          if(s[i+1][j+1]=='#') a[i][j]++;
        }
      }
    }  
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(a[i][j]>-1){
        printf("%d",a[i][j]);
      }
      else if(a[i][j]==-1){
        printf("#");
      }
      if(j==w-1){
        printf("\n");
      }
    }
  }
  return 0;
}


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

string ToStr( char c ) {
   return string( 1, c );
}

int main() {
	// your code goes here
	ll n;
	cin >> n;
	string s;
	while(n > 0){
		int k = n%26;
		if( k == 0){
		s.insert(0,ToStr('z'));
		k = 26;
		}
		else
		s.insert(0,ToStr('a'+ (k-1)));
		n-=k;
		n = n/26;
	}
	cout << s << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

int Solve(string s = "") {
    cin >> s;
    for (int i = s.size() - 2; 0 < i; i -= 2)
        if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) return i;
    return 0;
}

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

    cout << Solve() << endl;

    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

V<int> inv(const V<int>& a) {
	V<int> res(a.size());
	rep(i, a.size()) {
		res[a[i]] = i;
	}
	return res;	
}

V<int> comp(const V<int>& a, const V<int>& b) { // a * b
	V<int> res(a.size());
	rep(i, a.size()) {
		res[i] = a[b[i]];
	}
	return res;
}

int main() {
	int N, K; cin >> N >> K;
	V<int> p(N), q(N);
	rep(i, N) {
		cin >> p[i], --p[i];
	}
	rep(i, N) {
		cin >> q[i], --q[i];
	}

	V<int> id(N); //mod 6
	iota(ALL(id), 0);

	{
		int cyc = (K - 1) / 6;
		V<int> base = comp(inv(q), p);
		base = comp(inv(p), base);
		base = comp(q, base);

		while (cyc > 0) {
			if (cyc & 1) {
				id = comp(base, id);
			}
			base = comp(base, base);
			cyc /= 2;
		}
	}

	int rem = (K - 1) % 6;
	p = comp(id, p);
	p = comp(p, inv(id));
	q = comp(id, q);
	q = comp(q, inv(id));

	rep(i, rem) {
		V<int> nx = comp(q, inv(p));
		p = q;
		q = nx;
	}

	rep(i, N) {
		printf("%d%c", p[i] + 1, i == N-1 ? '\n' : ' ');
	}

	return 0;
}

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


def solve(N: int, S: str):

    wc = 0
    ec = S.count("E") 

    min_res = float("inf")
    for s in S:
        if s == "E":
            ec -= 1
        min_res = min(min_res,wc+ec)
        if s == "W":
            wc += 1

    print(min_res)
    

    


# Generated by 1.1.4 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
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
import datetime
from datetime import timedelta
H1,M1,H2,M2,K=map(int,input().split())


delta1=timedelta(minutes=M1,hours=H1)
delta2=timedelta(minutes=M2,hours=H2)

delta=delta2-delta1
delta_minutes=delta.total_seconds()/60
if delta_minutes>=K:
  print(round(delta_minutes-K))
else:
  print(0)

Measured memory_bytes: 9400
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    ll ans;
    if(a >= k)ans = 1;
    else if(a <= b)ans = -1;
    else if((2 * k - a - b) % (a - b) == 0)ans = (2 * k - a - b) / (a - b) % 2 == 1?(2 * k - a - b) / (a - b):(2 * k - a - b) / (a - b) + 1;
    else ans = (2 * k - a - b) / (a - b) % 2 == 1?(2 * k - a - b) / (a - b) + 2:(2 * k - a - b) / (a - b) + 1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
gets
hs = gets.strip.split(" ").map(&:to_i)

dp = Array.new(hs.size, 0)
dp[1] = (hs[0] - hs[1]).abs

2.upto(hs.size - 1) do |i|
  a = dp[i - 2] + (hs[i - 2] - hs[i]).abs
  b = dp[i - 1] + (hs[i - 1] - hs[i]).abs

  dp[i] = [a, b].min
end

puts dp.last


Measured memory_bytes: 11780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  int ans=0;
  for(int i=1;i<N+1;++i){
    string s=to_string(i);
    if(s.size()%2==1)
      ++ans;
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n,a[10001],i;
  int min,max;
  long long sum=0;
  scanf("%d",&n);
  for(i=0; i<n; i++)
{
    scanf("%d",&a[i]);
  }
  min=a[0];
  max=a[0];
  for(i=0; i<n; i++)
{
    if(min>a[i])min=a[i];
    if(max<a[i])max=a[i];
    sum+=a[i];
  }
  printf("%d %d %ld\n",min,max,sum);
  return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll calc(ll a, ll b){
    if(a > b) swap(a,b);
    if(a == 0) return 0;
    if(b % a == 0) return 2 * a * (b / a) - a;
    return 2 * a * (b / a) + calc(b%a, a);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,X;
    cin >> N >> X;
    ll ans = N + calc(N-X, X);
    print(ans);

}


Measured memory_bytes: 384
#include <stdio.h>
#define MAX_N 100001

int a[MAX_N];

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == i) {
            cnt++;
            if (i < n && a[i + 1] == i + 1) i++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n, m;
    cin >> n >> m;
    int sum = 0;
    rep(i, m){
        int a;
        cin >> a;
        sum += a;
    }

    if(sum <= n){
        cout << n-sum << endl;
    }else{
        cout << -1 << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;



int main() {
    int n;
    cin >> n;
    int A[21];
    int B[21];
    int C[21];
    rep(i, n)cin >> A[i];
    rep(i, n)cin >> B[i];
    rep(i, n-1)cin >> C[i];
    int ans = 0;
    rep(i, n) {
        if (A[i+1] == A[i]+1)ans += C[A[i]-1];
        ans = ans + B[A[i]-1];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ABC612A
#include <iostream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    string s;
    cin>>s;
    if (s.find('7')!=string::npos) {
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

P f(int x){
	int a = x%10;
	int b = 0;
	while (x){
		b = x;
		x /= 10;
	}
	return P(a,b);
}



int main() {
int n;
cin >> n;
map<P,int> freq;
for(int i =1 ;i <= n; i++)
{
	P p = f(i);
	freq[p]++;
}
ll ans = 0;
for(int i = 1; i <= n; i++){
	P p = f(i);
	P q(p.second,p.first);
	ans += freq[q];
}
cout << ans << endl;
	return 0;
}

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

int main()
{
    int A, B, C, D;
    int first = 0, last = 0;
    cin >> A >> B >> C >> D;

    if(A>=C){
        first = A;
    }
    else{
        first = C;
    }

    if(B>=D){
        last = D;
    }
    else{
        last = B;
    }
    if((last-first)>0){
        cout << last - first << endl;
    }
    else{
        cout << "0" << endl;
    }
    
}

Measured memory_bytes: 256
n=int(input())
s=input()
mini=10**9
prew=[0]*n 
if s[0]=='W':
    prew[0]+=1 
pre=[0]*n 
if s[n-1]=='E':
    pre[n-1]+=1 
for i in range(1,n):
    #pre[i]=pre[i-1]+(s[i]=='E')
    prew[i]=prew[i-1]+(s[i]=='W')
for i in range(n-2,-1,-1):
    pre[i]=pre[i+1]+(s[i]=='E')
for i in range(1,n-1): 
    cost=prew[i-1]+pre[i+1]
    mini=min(mini,cost)
mini=min(mini,pre[0])
mini=min(mini,prew[n-1])
print(mini)

Measured memory_bytes: 47320
from itertools import combinations
import math


n, d = map(int, input().split())

xn = []
for i in range(n):
  x = [int(num) for num in input().split()]
  xn.append(x)
  
answer =  0
for i,j in combinations(range(n),2):
    sum = 0.0
    for k in range(d):
        sum += (xn[i][k]-xn[j][k])**2
    if math.sqrt(sum).is_integer():
        answer += 1
 
print(answer)

Measured memory_bytes: 9132