akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	ll N, K;
	cin >> N >> K;

	int A[200001];
	rep1(i, N) cin >> A[i];

	int c[200001] = {};
	int B[200001] = {};
	for (int i = N; i >= 1; i--) {
		if (c[A[i]] == 0) {
			c[A[i]] = i;
		}
		else {
			B[i] = c[A[i]];
			c[A[i]] = i;
		}
	}

	int C[200002] = {};
	for (int i = N; i >= 1; i--) {
		if (B[i] == 0) {
			C[i] = A[i];
		}
		else {
			C[i] = C[B[i] + 1];
		}
	}

	int D[200001] = {};
	rep(i, 200001) D[i] = -1;
	rep1(i, N) {
		if (D[A[i]] == -1) {
			if (i + 1 <= N + 1) D[A[i]] = C[i + 1];
		}
	}
	D[0] = C[1];

	int vis[200001] = {};

	int num = 0;
	int k = 0;
	vector<int> ans;
	while (vis[k] == 0) {
		vis[k] = num + 1;
		k = D[k];
		ans.pb(k);
		num++;
	}

	int num2 = vis[k] - 1;


	int tmp = 0;
	if (K >= 2) {
		K -= 2;
		if (K >= num) {
			K = (K - num2) % (num - num2) + num2;
		}
		rep1(i, N) {
			if (A[i] == ans[K]) {
				tmp = i;
				break;
			}
		}
	}

	for (int i = tmp + 1; i <= N; i++) {
		if (B[i] == 0) cosp(A[i]);
		else i = B[i];
	}

	Would you please return 0;
}

Measured memory_bytes: 7156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
const int MN=100000;
int N,M,Q,a[MN];
bool done[MN];		//value done?
int its[MN];		//where iterate?
set<int> v2ps[MN];
int top;
bool okalone(int num,int I){
	if(num!=top) return 0;
	for(int it=I;it<Q&&num<M;it++){
		int v=a[it];
		if(done[v]) continue;
		if(v>num) return 0;
		if(a[it]==num){
			num++;
			while(num<M&&done[num]) num++;
		}
	}
	return 1;
}
bool solve(){
	cin>>N>>M>>Q;
	if(N==1) return 1;
	rep(i,Q) cin>>a[Q-1-i],a[Q-1-i]--;
	rep(i,Q) v2ps[a[i]].insert(i);
	while(true){
		int I=its[0];
		for(;I<Q;I++){
			if(!done[a[I]]) break;
		}
		if(I==Q){
			return 1;
		}
		int v=a[I];
//		show(I);
//		show(v);

		if(okalone(v,I)) return 1;

		set<int>& st=v2ps[v];
		rep(i,N){
			auto it=st.lower_bound(its[i]);
			if(it==st.end()) return 0;
			its[i]=*it;
			st.erase(it);
		}
		done[v]=1;
		if(top==v){
			while(top<M&&done[top]) top++;
		}
	}
	assert(false);
}

int main(){
	if(solve()) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, sum = 0;
	
	cin >> n;
	
	sum = n;
	
	while(sum>=1000)
	{
		sum -= 1000;
	}
	
	
	if(sum==0)
	{
		cout << "0" << endl;
	}
	else
	{
		cout << 1000-sum << endl;
	}
	
return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<algorithm>
using namespace std;
int a[101];
int main()
{
    int n,c=1;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a, a+n);
    for(int i=1;i<n;i++)
        if(a[i]!=a[i-1])
            c++;
    printf("%d",c);
}


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

using namespace std;

#define int long long

int a,b;

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

	cin >> a >> b;
	int g = __gcd(a,b);
	cout << a*b/g;
}

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

int main() {
  int n,r = 0,b = 0;
  string s;
  cin >> n >> s;
  for (int i; i < n; i++){
    if (s.at(i) == 'R')
      r++;
    else
      b++;
  }
  if(r > b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int N,M;
int ds[222][222], dl[222][222];
int r[1111];
int dp[1111][222];

int const inf = 1<<28;

int main(){
    while(cin>>N>>M && N){
        rep(i,N)rep(j,N) ds[i][j] = dl[i][j] = inf;
        rep(i,N) ds[i][i] = dl[i][i] = 0;
        rep(i,M){
            int x,y,d; char c;
            cin >> x >> y >> d >> c;
            x--; y--;
            if(c=='L') dl[x][y] = dl[y][x] = min(d,dl[y][x]);
            if(c=='S') ds[x][y] = ds[y][x] = min(d,ds[y][x]);
        }
        int x; cin >> x;
        rep(i,x){
            cin >> r[i];
            r[i]--;
        }
        rep(k,N)rep(i,N)rep(j,N){
            dl[i][j] = min(dl[i][j],dl[i][k]+dl[k][j]);
            ds[i][j] = min(ds[i][j],ds[i][k]+ds[k][j]);
        }
        rep(i,x+1)rep(j,N) dp[i][j] = inf;
        dp[0][r[0]] = 0;
        loop(i,1,x){
            rep(j,N){
                // ティツ按ケテ」ツつ男テ」ツ?ォテァツスツョテ」ツ??」ツ?ヲテヲツュツゥテ」ツ??」ツ?ヲr[i]テ」ツ?クティツ。ツ古」ツ??
                dp[i][j] = min(dp[i][j], dp[i-1][j]+dl[r[i-1]][r[i]]);
                rep(k,N){
                    // ティツ按ケテ」ツつ津・ツ渉姪」ツつ甘」ツ?ォティツ。ツ古」ツ?催」ツ??ィツ按ケテ」ツ?ァkテ」ツ?セテ」ツ?ァテァツァツサテ・ツ仰陛」ツ?療」ツ??ヲツュツゥテ」ツ??」ツ?ヲr[i]テ」ツ?ォティツ。ツ古」ツ??
                    dp[i][k] = min(dp[i][k], dp[i-1][j]+dl[r[i-1]][j]+ds[j][k]+dl[k][r[i]]);
                }
            }
        }
        int ans = inf;
        rep(i,N) ans = min(ans, dp[x-1][i]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 2388
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    vector<LL> l(n + 1,0);
    l[0] = 2; l[1] = 1;
    loop(i, 2, n + 1) {
        l[i] = l[i - 1] + l[i - 2];
    }
    cout << l[n] << endl;
}


Measured memory_bytes: 256
S = input()
T = input()
sl = len(S)
tl = len(T)
res = list(S)

def check(s1, s2):
    for i in range(len(s1)):
        if s1[i] == '?':
            continue
        if s1[i] != s2[i]:
            return False
    return True

for i in range(sl-tl, -1, -1):
    if check(S[i: i+tl], T):
        res[i: i+tl] = T
        res = ['a' if s == '?' else s for s in res]
        break
else:
    res = list('UNRESTORABLE')

print(''.join(res))


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

using namespace std;

string s,ans;

int main(){
    cin>>s;

    for(int i=0;i<s.size();i++){
                    ans.push_back(s[i]);
            if(s[i]=='B'&&ans.size()!=0){
            ans.pop_back();
                if(ans.size()!=0)ans.pop_back();
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="valid\n";
string N="invalid\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; }
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st,s1,s2,s3; char ch;
    while(cin>>a>>b)
    {
        if(a>9||b>9)cout<<-1<<en;
        else cout<<a*b<<en;
    }
}



Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            s = Console.ReadLine().Split(' ');
            long[] v = new long[N];
            for (int i = 0; i < N; i++)
            {
                v[i] = long.Parse(s[i]);
            }

            long ans = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (v[i] + v[i + 1] <= M)
                {
                    continue;
                }


                long eat = v[i] + v[i + 1] - M;
                ans += eat;

                if (v[i + 1] < eat)
                {
                    v[i + 1] = 0;
                    v[i] = M;
                }
                else
                {
                    v[i + 1] -= (v[i] + v[i + 1] - M);
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 25436
import sys
sys.setrecursionlimit(10**5)


def pow_mod(n,k,m):#nのk乗したものをmod mしたものを高速に算出する関数
    if k==0:
        return 1
    if k&1:
        return (pow_mod(n,k-1,m)*n%m)%m
    else:
        return (pow_mod(n,k//2,m)**2)%m

N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
A.sort()

#Nが奇数の場合
#Aをソートして、先頭に0、そのあとは2,2,4,4,となる。そうなっていない場合は間違い


if N&1:
    if A[0]!=0:
        print(0)
        exit()

    for i in range(1,N,2):
        if A[i]!=A[i+1] or A[i]!=i+1:
            print(0)
            exit()
    print(pow_mod(2,((N-1)//2),MOD))

else:
    for i in range(0,N,2):
        if A[i]!=A[i+1] or A[i]!=i+1:
            print(0)
            exit()
    print(pow_mod(2,N//2,MOD))

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
int A[N], dp1[N], dp2[N], len1 = 1, len2 = 1;
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)scanf("%d", &A[i]);
	dp1[1] = dp2[1] = A[1];
	for (int i = 2; i <= n; i++) {
		if (dp1[len1] >= A[i])dp1[++len1] = A[i];
		else dp1[upper_bound(dp1 + 1, dp1 + 1 + len1, A[i], greater<int>()) - dp1] = A[i];
		if (dp2[len2] < A[i])dp2[++len2] = A[i];
		else dp2[lower_bound(dp2 + 1, dp2 + 1 + len2, A[i]) - dp2] = A[i];
	}
	printf("%d", len1);
}

Measured memory_bytes: 1024
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#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 trace4(a, b, c, d)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll x;
	cin >> x;
	ll z=x%11;
	ll ans = (x/11)*2;
	if(z>6) cout << ans+2;
	else if(z && z<=6) cout << ans+1;
	else cout << ans;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC044
{
    class Program
    {
        static void Main(string[] args)
        {
            new A();
            //new B();
        }
    }

    class A
    {
        public A()
        {
            int N, K, X, Y;
            N = int.Parse(Console.ReadLine());
            K = int.Parse(Console.ReadLine());
            X = int.Parse(Console.ReadLine());
            Y = int.Parse(Console.ReadLine());

            int ans;
            if (N - K >= 0)
                ans = X * K + Y * (N - K);
            else
                ans = X * N;
            Console.WriteLine(ans);
        }
    }

    class B
    {
        public B()
        {
            string str = Console.ReadLine();
            char[] cstr = str.ToCharArray();
            int[] ary = new int[26];

            foreach (var e in cstr)
                ary[e-'a']++;

            string ans = "Yes";
            foreach (var e in ary)
                if (e%2 != 0)
                {
                    ans = "No";
                    break;
                }

            Console.WriteLine(ans);
        }
    }
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int pool = 0; int out = 0;
    REP(i, S.size()) {
        if(S[i] == '(') {
            pool++;
        } else {
            if(pool > 0) {
                pool--;
            } else {
                out++;
            }
        } 
    }
    REP(i, out) {
        S = '(' + S;
    }
    REP(i, pool) {
        S = S + ')';
    }
    cout << S << endl;
}

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

/*vector<long long int>::iterator position;
position=lower_bound(a.begin(),a.end(),b[i]);
key=distance(a.begin(),position);*/

/**/

int main(){
    ll n,k,i,ans;
    cin>>n>>k;

    ans=n%k;
    if(abs(ans-k)<ans){ans=abs(ans-k);}

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { n: number, p: number[] } => {
  const n = +lines[0]
  const p = lines[1].split(' ').map(line => +line)
  const obj = { n, p }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { n, p } = parseLines(lines)
  let count = 0
  for (let i = 0; i < n - 2; i++) {
    let a = p.slice(i, 3 + i)
    a.sort((b, c) => b - c)
    if (a[1] === p[i+1]) {
      count += 1
    }
  }
  return `${count}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7628
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    A.sort()
    apper = collections.Counter()

    for a in A:
        apper[a] += 1

    start = 1 if len(A) % 2 == 0 else 0
    for i in range(start, len(A), 2):
        if i not in apper:
            return 0
        if i == 0 and apper[0] != 1:
            return 0
        if i != 0 and apper[i] != 2:
            return 0
    if 0 in apper:
        apper.pop(0)

    return (2 ** len(apper)) % 1000000007


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 60192
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:64000000")
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <cctype>
#include <numeric>
#include <memory>
#include <functional>
#if __cplusplus >= 201103L
#include <cwchar>
#include <cwctype>
#include <array>
#include <forward_list>
#include <unordered_map>
#include <unordered_set>
#include <ratio>
#endif
using namespace std;
#define Debug(x) cerr << #x << " = " << x << endl
#define Debug22(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl;
#define Debug2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define Debug3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<")\n";
#define Debug_arr(v,n) for(int i=0;i<n;++i) cerr<<#v<<"["<<i<<"]"<<" = "<<v[i]<<endl;
#define SET(p,v) fill((__typeof(**p)*)p,(__typeof(**p)*)p+sizeof(p),v);
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
typedef vector<int> vi;
const int INF = (int)1e7;
int n;
vector<vector<int> > G;
vector<int> d1, d2;
void bfs(int s, vi &d) {
	d[s] = 0;
	queue<int> q;
	q.push(s);
	while (q.size()) {
		int u = q.front();
		q.pop();
		for (int i = 0; i < (int)G[u].size(); ++i) {
			int v = G[u][i];
			if (d[v] > d[u] + 1) {
				d[v] = d[u] + 1;
				q.push(v);
			}
		}
	}
}
 
int main(void) {
	cin>>n;
	G.resize(n);
	for(int i=0;i<n-1;++i) {
		int a,b;
		cin>>a>>b;
		G[a-1].push_back(b-1);
		G[b-1].push_back(a-1);
	}
	d1.resize(n,INF);
	bfs(0,d1);
	d2.resize(n,INF);
	bfs(n-1,d2);
	int black=0;
	for(int i=1;i<n-1;++i) {
		if(d1[i]<=d2[i]) ++black;
	}
	int white=n-2-black;
	if(black>white) cout<<"Fennec\n";
	else cout<<"Snuke\n";
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll x;
    cin>>x;
    if(x<7){
        cout<<1<<endl;
    }else if(x<12){
        cout<<2<<endl;
    }else{
        ll ans=x/11;
        ans*=2;
        if(x%11!=0 && x%11<7){
            ans+=1;
        }
        if(x%11!=0 && 7<=x%11){
            ans+=2;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef vector<ull> vll;

const ull BASE = 1e9+7;

//Rolling Hash
vll acc_h, power;

void init_roll(string &s, int n){
  acc_h.resize(n+1,0);
  power.resize(n+1,1);
  for(int i=1;i<=n;i++){
    power[i] = power[i-1] * BASE;
    acc_h[i] = acc_h[i-1] * BASE + s[i-1];
  }
}

ull rolling_hash(string &s, int l, int r){
  return acc_h[r] - acc_h[l] * power[r-l];
}

int main(){
  string s;
  cin >> s;
  int n = s.size();
  init_roll(s,n);

  string res = "mitomerarenaiWA";
  for(int a=n/3;a>0;a--){
    if( (n-3*a)%2 )continue;
    int b = (n-3*a)/2;
    if(b<=0)continue;

    ull A1 = rolling_hash(s,0,a);
    ull B1 = rolling_hash(s,a,a+b);
    ull A2 = rolling_hash(s,a+b,2*a+b);
    ull B2 = rolling_hash(s,2*a+b,2*a+2*b);
    ull A3 = rolling_hash(s,2*a+2*b,3*a+2*b);

    if(A1 == A2 && A2 == A3 && B1 == B2){
      res = "Love " + s.substr(0,a+b) + "!";
      break;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 19992
n = int(input())
L,R = [0],[0]
for _ in range(n):
	l,r = (int(i) for i in input().split())
	L.append(l)
	R.append(r)
L,R,ans = sorted(L)[::-1],sorted(R),0
for i in range(n+1):
	if L[i]>R[i]: ans+=L[i]-R[i]
	else: break
print(ans*2)

Measured memory_bytes: 12944
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int MAXN = 100010;
long long sum[MAXN];
int a[MAXN],aa[MAXN],b[MAXN],c[MAXN];
int n;
int lowbit(int x){return x&(-x);}
void update(int x,int n){
	for (int i=x;i<=n;i+=lowbit(i)) {
		sum[i]++;
	}
}
int getSum(int x) {
	int ans = 0;
	for (int i=x;i>0;i-=lowbit(i)) {
		ans += sum[i];
	}
	return ans;
}
long long check(int x) {
	b[0] = 0;c[0] = 0;
	for (int i=1;i<=n;i++) {
		if (a[i]<=x) b[i] = 1;
		else b[i] = -1;
	}
	for (int i=1;i<=n;i++) {
		b[i] = b[i-1] + b[i];
		c[i] = b[i];
	}
	sort(c,c+1+n);
	int cnt = 1;
	map<int,int> mp;
	mp[c[0]] = 1;
	for (int i=1;i<=n;i++) {
		if (c[i]!=c[i-1]) {
			cnt++;
			mp[c[i]] = cnt;
		}
	}
	for (int i=0;i<=cnt;i++) sum[i]=0;
	long long res = 0;
	update(mp[0],cnt);
	for (int i=1;i<=n;i++) {
		res += getSum(mp[b[i]]-1);
		update(mp[b[i]],cnt);
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) aa[i] = a[i];
	sort(aa+1,aa+1+n);
	long long k = 1LL * n*(n+1)/2/2+1;
	int l = 1,r = n,mid,ans;
	while(l<=r) {
		mid = (l+r) / 2;
		if (check(aa[mid])>=k) {
			ans = aa[mid];
			r = mid - 1;
		}
		else l = mid + 1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;typedef long long ll;const int N=3e5+7,mod=998244353;
ll a,b,K,x,y,d,ans,C[N];int n,i,j;
void exgcd(ll a,ll b,ll&x,ll &y){
	if(b==0)d=a,x=1,y=0;
	else exgcd(b,a%b,y,x),y-=x*(a/b);
}
ll inv(ll a,ll b){
	exgcd(a,b,x,y);
	x=(x%b+b)%b;
	return x;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	for(cin>>n>>a>>b>>K,C[0]=i=1;i<=n;++i)C[i]=C[i-1]*(n-i+1)%mod*inv(i,mod)%mod;
	exgcd(a,b,x,y);
	if(K%d!=0)puts("0");
	else{
		for(i=0;i<=n;++i)if((K-a*i)%(b)==0&&K>=a*i){
			x=i;
			y=(K-a*i)/b;
			if(max(x,y)>n)continue;
			ans=(ans+C[x]*C[y])%mod;
		}
		cout<<ans<<endl;
	}
}

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

int a[102],b[102];

int main() {
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<m;i++)cin >> b[i];
    for(int z=x+1;z<=y;z++){
        bool can = true;
        for(int i=0;i<n;i++){
            if(a[i]>=z)can = false;
        }
        for(int i=0;i<m;i++){
            if(b[i]<z)can = false;
        }
        if(can)return cout << "No War",0;
    }
    cout << "War";
    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string joi = "JOI";
  vary(ll,ans,3,0);
  ll cnt = 0;
  ll ma = 0;
  s += "J";
  rep(i,s.size()){
    if(s[i] == joi[cnt]){
      ans[cnt]++;
    }
    else if(cnt < 2 && s[i] == joi[cnt+1] && ans[cnt] > 0){
      ++cnt;
      ans[cnt]++;
    }
    else{
      cnt = 0;
      if(ans[0] >= ans[1] && ans[1] <= ans[2]){
        ma = max(ma,ans[1]);
      }
      ans[0] = ans[1] = ans[2] = 0;
      if(s[i] == 'J') ans[0]++;
    }
  }
  cout << ma << endl;
  return 0;
}

Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
int main(){
    ll N;
    cin >> N;
    ll v[N];
    for(ll i = 0; i < N; i++) cin >> v[i];
    if(N == 2){
        if(v[0] == v[1]) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    map<ll, ll> o, e;
    for(ll i = 0; i < N; i += 2) o[v[i]]++;
    for(ll i = 1; i < N; i += 2) e[v[i]]++;
    vector<pair<ll, ll>> vo, ve;
    for(auto oo : o) vo.push_back(P(oo.second, oo.first));
    for(auto ee : e) ve.push_back(P(ee.second, ee.first));
    sort(vo.begin(), vo.end());
    reverse(vo.begin(), vo.end());
    sort(ve.begin(), ve.end());
    reverse(ve.begin(), ve.end());
    if(vo[0].second != ve[0].second) cout << N - vo[0].first - ve[0].first;
    else cout << N - max(vo[0].first + ve[1].first, vo[1].first + ve[0].first);
    cout << endl;
    return 0;
}


Measured memory_bytes: 9592
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORU(i,j,k) for(int i=(j);i<=(k);++i)
#define FORD(i,j,k) for(int i=(j);i>=(k);--i)

#define RDI(n) scanf("%d", &(n));
#define RDL(n) scanf("%lld", &(n));

using namespace std;

using lli = long long int;
using pll = pair<lli, lli>;

const long long int oo = 1000*1000*1000;

struct Coord
{
	int x, y;
	Coord(int x = 0, int y = 0) : x(x), y(y) {}
	Coord operator + (const Coord& droite) const
	{
		return Coord(x + droite.x, y + droite.y);
	}
};

struct AB
{
	int k;
	vector<lli> arbre;
	AB(int _k = 20, lli def = 0)
	{
		k = _k;
		FOR(i, 1 << k)
			arbre.push_back(i < (1 << (k-1)) ? 0LL : def);
		FORD(i, ((1 << (k-1)) - 1), 1)
			arbre[i] = arbre[i << 1] + arbre[(i << 1) ^ 1];
	}
	void set(int i, lli x)
	{
		int feuille = i + (1 << (k-1));
		arbre[feuille] = x;
		iset(feuille >> 1);
	}
	void iset(int noeud)
	{
		if(noeud)
		{
			arbre[noeud] = arbre[noeud << 1] + arbre[(noeud << 1)  ^ 1];
			iset(noeud >> 1);
		}
	}
	lli sum(int deb, int fin, int noeud = 1, int p = 0, int q = -1)
	{
		if(q < p)
			q = 1 << (k-1);
		if(deb <= p && q <= fin)
			return arbre[noeud];
		if(deb >= q || fin <= p)
			return 0LL;
		int mil = (p + q) / 2;
		return sum(deb, fin, noeud << 1, p, mil) + sum(deb, fin, (noeud << 1) ^ 1, mil, q);
	}
};

int main()
{
	lli a, b;
	scanf("%lld%lld", &a, &b);
	lli r = 1000*oo;
	if(0 <= a && a <= b)
		r = min(r, b - a);
	if(0 <= b && b <= a)
		r = min(r, 2 + a - b);
	if(a <= 0 && 0 <= b)
		r = min(r, 1 + abs(b + a));
	if(a <= b && b <= 0)
		r = min(r, b - a);
	if(b <= a && a <= 0)
		r = min(r, 2 + a - b);
	if(b <= 0 && 0 <= a)
		r = min(r, 1 + abs(b + a));
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,k,a[100],ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
	   ans+=min(a[i],abs(k-a[i]));
	}
	
	cout<<ans*2<<endl;
}

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n, a, x[50] = {}, dp[51][51][2501] = {};

int main() {
  cin >> n >> a;
  rep(i, 0, n) cin >> x[i];
  dp[0][0][0] = 1;

  rep(i, 0, n) rep(j, 0, i + 1) for(int k = 0;k <= 2500;k++){
    dp[i + 1][j][k] += dp[i][j][k];
    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
  }

  ll ans = 0;

  rep(i, 1, n + 1) {
    ans += dp[n][i][i * a];
  }

  cout << ans << endl;
}


Measured memory_bytes: 49152
#include <iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll=long long ;
int main(){
	ll n,k,cnt=0,num;
	cin >> n >> k;
	if(n>=11){	cnt = ((n/11)-1)*5;
		for(ll i=n-(n%11)-10;i<=n-2;i++){
			num = 63*i;
			for(ll j=1;j<=5;j++){
				if((num+9*j+9)%11==k){
					cnt++;
					//cout << i << ' ' << j << endl;
				}
			}
		}
	}
	else{
		for(ll i=n-(n%11)+1;i<=n-2;i++){
			num = 63*i;
			for(ll j=1;j<=5;j++){
				if((num+9*j+9)%11==k){
					cnt++;
					//cout << i << ' ' << j << endl;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  int ans[n];
  for(int i=0;i<n;i++)ans[i]=0;
  int p,q=1;
  for(int i=n-1;i>=0;i-=1){
    p=0;
    for(int j=i+1;j<n+1;j+=i+1){
      if(ans[j-1]){
        p=1-p;
      }
    }
    if(a[i]!=p){
      ans[i]=1;
    }
  }
  p=0;
  for(int i=0;i<n;i++)p+=ans[i];
  printf("%d\n",p);
  if(p>0){
    for(int i=0;i<n;i++){
      if(ans[i]){
        if(p){
          cout<<i+1;
          p=0;
        }
        else{
          cout<<" "<<i+1;
        }
      }
    }
  }
}
    

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int t;
   cin>>t;

   map<string,long int> m;

   while(t--){
   	 string s;
   	 cin>>s;
   	 m[s]++;
   }

   cout<<"AC x "<<m["AC"]<<endl;
   cout<<"WA x "<<m["WA"]<<endl;
   cout<<"TLE x "<<m["TLE"]<<endl;
   cout<<"RE x "<<m["RE"]<<endl;

   return 0;
}

Measured memory_bytes: 3664
import std.stdio;
import std.conv;

void main() {
    ulong n;
    long ans = 0;
    readf(" %s", &n);

    ulong[] arr;
    ulong[] pass;
    foreach (i; 0..n) {
        ulong a;
        readf(" %s", &a);
        arr ~= a;
        pass ~= 0;
    }

    ulong l = 1;
    while(1) {
        if (pass[l.to!int - 1]){
            ans = -1;
            break;
        }
        pass[l.to!int - 1] = 1;
        l = arr[l.to!int - 1];
        ans++;
        if (l == 2) {
            break;
        }
    }
    writeln(ans);
}

Measured memory_bytes: 4348
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

ans = 0
for i in range(N):
    while A[i] >= 2:
        ans += A[i] // 2
        A[i] %= 2
    if i + 1 < N and A[i] >= 1 and A[i + 1] >= 1:
        A[i] -= 1
        A[i+1] -= 1
        ans += 1
print(ans)



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

int main() {
  string S,T;
  cin >> S >> T;
  int A,B;
  cin >> A >> B;
  string U;
  cin >> U;
  if (S == U) {
    cout << A-1 <<" "<< B << endl;
  }
  else {
    cout << A <<" "<< B-1 << endl;
  }
}


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

int main(){
  int n, k, r, p, s;
  cin>>n>>k>>r>>s>>p;
  string t;
  cin>>t;
  string res=t;
  int sum=0;
  for(int i=0; i<k; i++){
    if(t[i]=='r'){
      res[i]='p';
      sum+=p;
    }else if(t[i]=='p'){
      res[i]='s';
      sum+=s;
    }else{
      res[i]='r';
      sum+=r;
    }
  }
  for(int i=k; i<n; i++){
    if(t[i]=='r'){
      if(res[i-k]=='p'){
        res[i]='x';
      }else{
        res[i]='p';
        sum+=p;
      }
    }else if(t[i]=='p'){
      if(res[i-k]=='s'){
        res[i]='x';
      }else{
        res[i]='s';
        sum+=s;
      }
    }else{
      if(res[i-k]=='r'){
        res[i]='x';
      }else{
        res[i]='r';
        sum+=r;
      }
    }
  }
  cout<<sum<<"\n";
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = INF;
    rep(i, n - m + 1) {
        int cnt = 0;
        rep(j, m) {
            if(s[i + j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  int S[N];
  for (int i = 0; i < N; i++) S[A[i]-1] = i+1;
  for (int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << S[i];
  }
  cout << endl;
}

Measured memory_bytes: 1536
from itertools import accumulate
 
N, K = map(int, input().split())
S = input()
S = [int(s) for s in S]
 
nums = list()
now = 1
count_tmp = 0
for i in range(N):
    if S[i] == now:
        count_tmp += 1
    else:
        nums.append(count_tmp)
        now = 1 - now
        count_tmp = 1
if count_tmp > 0:
    nums.append(count_tmp)
if len(nums) % 2 == 0:
    nums.append(0)
 
sums = list(accumulate([0] + nums))
 
max_add = 2 * K
ans = 0
for i in range(0, len(nums), 2):
    left = i
    right = min(i + max_add, len(nums) - 1)
    tmp = sums[right + 1] - sums[left]
    ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 9472
#include <iostream>
#include <vector>
#include<iomanip>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#include <iostream>
static const int MAX = 510;
int H, W;
int d[MAX][MAX];
vector<pair<int, int>> f;
vector<pair<int, int>> t;

bool isOdd(int a) {
    return a%2 != 0;
}

int main(int argc, const char * argv[]) {
    int i,j;
    cin >> H >> W;
    
    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            d[i][j] = 0;
        }
    }
    
    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            cin >> d[i][j];
        }
    }
    
    int cnt = 0;
    
    for (i = 0; i < H - 1; i++) {
        for (j = 0; j < W; j++) {
            if(isOdd(d[i][j])) {
                cnt++;
                f.push_back(make_pair(i+1, j+1));
                t.push_back(make_pair(i+2, j+1));
                --d[i][j];
                ++d[i+1][j];
            }
        }
    }
    
    for (j = 0; j < W-1; j++) {
        if(isOdd(d[H-1][j])) {
            cnt++;
            f.push_back(make_pair(H, j+1));
            t.push_back(make_pair(H, j+2));
            --d[H-1][j];
            ++d[H-1][j+1];
        }
    }
    
    cout << cnt << endl;
    for (int i = 0; i < cnt; i++) {
        cout << f[i].first << " " << f[i].second << " " << t[i].first << " " << t[i].second << endl;
    }
    
    return 0;
}



Measured memory_bytes: 5356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
vector<int> ver[200000];
int g[200000];
int pred[200000];
int j;
int stk[200000];
bool vis[200000];
bool usd[200000];
void dfs(int ths){
    for(int i=0;i<ver[ths].size();i++){
        int x=ver[ths][i];
        if(pred[x]==0||usd[pred[x]-1]==0)pred[x]=ths+1;
        if(vis[x]==1) continue;
        vis[x]=1;
        dfs(x);
    }
    usd[ths]=1;
}

int main() {
	//ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<n+m-1;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[b]++;
        ver[a].push_back(b);
    }
    int beg=0;
    for(int i=0;i<n;i++){
        if(g[i]==0) beg=i;
    }
    dfs(beg);
    for(int i=0;i<n;i++) cout<<pred[i]<<'\n';
	return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <set>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main() {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    // input data
    int N, s;
    std::set<int> st;
    std::cin >> N;
    for (int i=0; i<N; ++i) {
        std::cin >> s;
        st.insert(s);
    }
    std::cout<< st.size() << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
//AtCoderC++.cpp

using namespace std;


int main() {
	string s; cin >> s;
	auto appear = vector<bool>(26);
	for (size_t i = 0; i < s.length(); i++) {
		appear[s[i] - 'a'] = !appear[s[i] - 'a'];
	}
	for (size_t i = 0; i < 26; i++) {
		if (appear[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
X = int(input())

if 		X <  600 : print(8)
elif 	X <  800 : print(7)
elif 	X < 1000 : print(6)
elif 	X < 1200 : print(5)
elif 	X < 1400 : print(4)
elif 	X < 1600 : print(3)
elif 	X < 1800 : print(2)
else			 : print(1)

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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll a,b,c,s,t,x,y,z;
 ll A,B,C,S,T,X,Y,Z;

 ll cnt;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

signed main(){

	cin>>a>>b;

	vector<ll> f(a);
	vector<ll> g(a);

	REP(i,a){
		cin>>f[i]>>g[i];
		if(pow(b,2)>=pow(f[i],2)+pow(g[i],2)) cnt++;
    }


	cout<<cnt;
	
	return 0;

}


Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int dp[1010],p[1010];
vector<int>v[1010];
void dfs(int x){
    vector<P>a;
    int sum=0;
    for(int i:v[x]){
        dfs(i);
        a.pb({dp[i],p[i]});
        sum+=dp[i]+p[i];
    }
    bitset<5010>bit(1);
    for(P pp:a)bit=(bit<<pp.fi)|(bit<<pp.se);
    rep(i,p[x]+1)if(bit[i])chmin(dp[x],sum-i);
    if(dp[x]==INF){
        puts("IMPOSSIBLE");
        exit(0);
    }
}
void solve(){
    int n;
    cin>>n;
    rep(i,n-1){
        int a;
        cin>>a;
        a--;
        v[a].pb(i+1);
    }
    rep(i,n){
        cin>>p[i];
        dp[i]=INF;
    }
    dfs(0);
    puts("POSSIBLE");
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main(void){
    string a;
    cin>>a;
    if(a=="KIHBR"||a=="AKIHBR"||a=="KIHABR"||a=="KIHBAR"||a=="KIHBRA"||a=="AKIHABR"||a=="AKIHBAR"||
    a=="KIHBRA"||a=="KIHABAR"||a=="KIHABRA"||a=="KIHBARA"||a=="AKIHABAR"||a=="AKIHABRA"||a=="AKIHBARA"||
    a=="KIHABARA"||a=="AKIHABARA"){
        cout<<"YES";
    }
    else cout<<"NO";
    
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

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

int main(){
  int  A,B,C;
  cin>>A>>B>>C;
 int t =A;
 A=B;
 B=t;
 t=A;
 A=C;
 C=t;


  cout<<A<<" "<<B<<" "<<C<<endl;




}


Measured memory_bytes: 256