akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 300010, MOD = (int)(1e9 + 7);
inline void Add(int& x,int y) {
  x = x + y >= MOD ? x + y - MOD : x + y;
}
inline void Sub(int& x,int y) {
  x = x - y < 0 ? x - y + MOD : x - y;
}
char str[N];
int n, dp[N][2][3][3], ans;
int main() {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  dp[0][0][0][0] = 1;
  rep (i, 1, n) {
    if (str[i] == '?' || str[i] == '0') {
      rep (a, 0, 1) rep (b, 0, 2) rep (c, 0, 2) if (dp[i-1][a][b][c]) {
	int na = a, nb = (b == 0 ? 1 : 3 - b), nc = c;
	if (i == n) {
	  if (nb == 0 || nb == 2) {
	    na ^= 1;
	    if (nc == 0 && na == 1 && nb == 0) ++ nc;
	    else if (nc == 1 && na == 0 && nb == 0) ++ nc;
	  }
	  nb = 0;
	}
	Add(dp[i][na][nb][nc], dp[i-1][a][b][c]);
      }
    }
    if (str[i] == '?' || str[i] == '1') {
      rep (a, 0, 1) rep (b, 0, 2) rep (c, 0, 2) if (dp[i-1][a][b][c]) {
	int na = a, nb = b, nc = c;
	if (nb == 0 || nb == 2) {
	  na ^= 1;
	  if (nc == 0 && na == 1 && nb == 0) ++ nc;
	  else if (nc == 1 && na == 0 && nb == 0) ++ nc;
	}
	nb = 0;
	if (i == n) {
	  na ^= 1;
	  if (nc == 0 && na == 1) ++ nc;
	  else if (nc == 1 && na == 0) ++ nc;	  
	}
	Add(dp[i][na][nb][nc], dp[i-1][a][b][c]);
      }
    }
  }
  rep (a, 0, 1) rep (b, 0, 2)
    Add(ans, dp[n][a][b][2]);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long LL;

#define fin "\n"


#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
int main(){
    LL x,y;
    cin>>x>>y;
    LL res=1e15;
    LL sa=abs(abs(x)-abs(y));
    if(y>x)chmin(res,y-x);
    if(x>=0&&y>=0&&x>y){
        chmin(res,x-y+2);
        chmin(res,y+x+1);
    }
    if(x<=0&&y<=0){
        chmin(res,sa+2);
    }
    
    if(x*y<=0)
        chmin(res,abs(sa+1));
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(a,b,c,d) for (register int a=b;a<=c;a+=d)
#define FD(a,b,c,d) for (register int a=b;a>=c;a-=d)
using namespace std;
const int M=1100;
long long a[M],b[M],c[M],a1[M],b1[M],c1[M],f[M],ans=-10000000000000;
int n,m;
int main(){
	
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*1;
		b1[i]=b[i]*1;
		c1[i]=c[i]*1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
			f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<" "<<f[1]<<endl;
for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*-1;
		b1[i]=b[i]*1;
		c1[i]=c[i]*1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
			f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<endl;
for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*1;
		b1[i]=b[i]*-1;
		c1[i]=c[i]*1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
			f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<endl;
for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*1;
		b1[i]=b[i]*1;
		c1[i]=c[i]*-1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
			f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<endl;
for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*-1;
		b1[i]=b[i]*-1;
		c1[i]=c[i]*1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
			f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<endl;
for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*1;
		b1[i]=b[i]*-1;
		c1[i]=c[i]*-1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
			f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<endl;
for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*-1;
		b1[i]=b[i]*1;
		c1[i]=c[i]*-1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
			f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<endl;
	for (int i=1;i<=m;i++)
	{
		f[i]=-30000000000000+100;
	}
	for (int i=1;i<=n;i++)
	{
		a1[i]=a[i]*-1;
		b1[i]=b[i]*-1;
		c1[i]=c[i]*-1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=min(i,m);j>0;j--)
		{
		 f[j]=max(a1[i]+b1[i]+c1[i]+f[j-1],f[j]);
		}
	}
	ans=max(ans,f[m]);
	//cout<<f[m]<<endl;
	cout<<ans<<endl;
	return 0;
}





Measured memory_bytes: 256
import sys
import numpy as np

readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]

s = input()

i = 0
j = 0
ret = 0
while i < len(s):
    while j < len(s) and s[j] in "ACGT":
        j += 1
    ret = max(ret, j - i)
    j += 1
    i = j
print(ret)

Measured memory_bytes: 12448
#include <bits/stdc++.h>
int main()
{
    int N, M, q;
    std::scanf("%d %d", &N, &M);
    int arr[N*2], tmp[N*2];
    for (int i = 0; i < N*2; i++) {
        arr[i] = i+1;
    }
    for (int t = 0; t < M; t++) {
        std::scanf("%d", &q);
        if (q > 0) {
            for (int i = 0; i < q; i++) tmp[i] = arr[i];
            for (int i = q, j=0; i < N*2; i++, j++) arr[j] = arr[i];
            for (int i = N*2-q, j=0; i < N*2; i++, j++) arr[i] = tmp[j];

        } else if (q == 0) {
            for (int i = N, j=0; i < N*2; i++, j++) tmp[j] = arr[i];
            for (int i = N-1; i > 0; i--) arr[i*2] = arr[i];
            for (int i = 1, j=0; i < N*2; i+=2, j++) arr[i] = tmp[j];
        }
    }
    for (int i = 0; i < N*2; i++) std::cout << arr[i] << std::endl;
    return 0;
}



Measured memory_bytes: 3156
#include <cstdio>
#define N 2005][2005
int n, m, Q, s, b[N], c[N], d[N];
char a[N];
int main() {
	int i, j, p, q, x, y;
	scanf("%d%d%d", &n, &m ,&Q);
	for(i=1; i<=n; i++) scanf("%s", &a[i][1]);
	for(i=1; i<=n; i++) for(j=1; j<=m; j++) b[i][j] = b[i-1][j] + b[i][j-1] - b[i-1][j-1] + (a[i][j]=='1');
	for(i=1; i<=n; i++) for(j=1; j<m; j++)  c[i][j] = c[i-1][j] + c[i][j-1] - c[i-1][j-1] + (a[i][j]=='1' && a[i][j+1]=='1');
	for(i=1; i<n; i++)  for(j=1; j<=m; j++) d[i][j] = d[i-1][j] + d[i][j-1] - d[i-1][j-1] + (a[i][j]=='1' && a[i+1][j]=='1');
	while(Q--) {
		scanf("%d%d%d%d", &p, &q ,&x, &y);
		p--, q--, s = b[x][y] - b[x][q] - b[p][y] + b[p][q];
			 y--, s-= c[x][y] - c[x][q] - c[p][y] + c[p][q];
		x--, y++, s-= d[x][y] - d[x][q] - d[p][y] + d[p][q];
		printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 52736
//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef pair<int,int> pi;
typedef long long ll;
const int N=2e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
priority_queue<pi,vector<pi>,greater<pi> >Q[N];
int fa[N],dx[N],a[N],b[N],q[N],s[N];
ll sum;int n,m,l,r,mid,ans,mx;
inline int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void merge(int u,int v){
	if(Q[u].size()<Q[v].size())Q[u].swap(Q[v]);
	while(!Q[v].empty()){
		R int w=Q[v].top().se;Q[v].pop();
		if(find(w)!=find(u))Q[u].push(pi(dx[w],w));
	}
}
bool ck(){
	int h=1,t=0,u;
	fp(u,1,n){
		fa[u]=u,s[u]=b[u],dx[u]=a[u]-b[u]-mid;
		if(dx[u]<=0)q[++t]=u;
	}
	if(h>t)return false;
	fp(u,1,n){
		while(!Q[u].empty())Q[u].pop();
		go(u)Q[u].push(pi(dx[v],v));
	}
	R int cnt=0;
	while(h<=t){
		u=q[h++];
		while(!Q[u].empty()){
			R int v=Q[u].top().se;
			if(dx[v]>s[u])break;
			Q[u].pop();if(find(v)==find(u))continue;
			v=find(v);
			if(s[u]+s[v]>=mx)return true;
			s[u]+=s[v],fa[v]=find(u),++cnt,merge(u,v);
		}
	}
	return cnt==n-1;
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d",&n,&m);
	fp(i,1,n)scanf("%d%d",&a[i],&b[i]),sum+=b[i];
	for(R int i=1,u,v;i<=m;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	fp(i,1,n)cmax(mx,a[i]-b[i]);
	mid=0;if(ck())return printf("%lld\n",sum),0;
	l=1,r=mx;
	while(l<=r){
		mid=(l+r)>>1;
		ck()?(ans=mid,r=mid-1):l=mid+1;
	}
	printf("%lld\n",sum+ans);
	return 0;
}

Measured memory_bytes: 20092
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	string S;
	cin >> S;

	int v = 0;

	for (int i = 0; i < S.length(); i++) {
		v += stoi(S.substr(i, 1));
	}

	if (v % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3720
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N, X = map(int, input().split())
    print(3 * (N - gcd(N, X)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5484
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

	using i8 = std::int_least8_t;
	using i32 = std::int_least32_t;
	using i64 = std::int_least64_t;
	using u8 = std::uint_least8_t;
	using u32 = std::uint_least32_t;
	using u64 = std::uint_least64_t;
	using isize = std::ptrdiff_t;
	using usize = std::size_t;

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
		constexpr itr begin() const noexcept { return itr(l); }
		constexpr itr end() const noexcept { return itr(f); }
	};
	template <class T> using vec_alias = std::vector<T>;
	template <class T> auto md_vec(const usize n, const T &value) {
		return std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> constexpr T difference(const T &a, const T &b) {
		return a < b ? b - a : a - b;
	}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cassert>

namespace n91 {

	void stop(){}

	void main_() {
		usize n;
		u64 a, b;
		std::cin >> n >> a >> b;
		std::vector<usize> p(n);
		for (auto &e : p) {
			std::cin >> e;
			--e;
		}
		p.emplace_back(n);
		static constexpr u64 INF = std::numeric_limits<u64>::max();
		std::vector<u64> dp(n + 1, INF);
		for (const auto i : rep(0, n + 1)) {

			u64 acc = 0;
			usize prev = 0;
			for (const auto k : revrep(0, i)) {
				if (p[k] > p[i]) {
					acc += a;
				}
				else if (p[k] < prev) {
					acc += b;
				}
				else {
					prev = p[k];
					if (dp[k] + acc < dp[i]) {
						dp[i] = dp[k] + acc;
					}
					acc += b;
				}
			}
			if (acc < dp[i]) {
				dp[i] = acc;
			}
		}
		std::cout << dp.back() << std::endl;
		stop();
	}

} // namespace n91

int main() {
	n91::main_();
	return 0;
}


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

int n;
char alpha[10] = {'a','b','c','d','e','f','g','h','i','j' };

void f(int cur, string v, int prev) 
{
	if (cur == n) {
		cout << v << endl;
		return;
	}

	for (int i = 0; i <= prev; ++i) {
		v[cur] = alpha[i];
		f(cur + 1, v, prev);
	}

	v[cur] = alpha[prev + 1];
	f(cur + 1, v, prev + 1);
}

int main()
{
	cin >> n;

	string v;
	v.resize(n, 'a');
	int cur = 1;
	int prev = 0;
	f(cur, v, prev);

	return 0;
}

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

int findSet(int x, vector<int>& Forest){
    if (Forest[x] == x) return x;
    return Forest[x] = findSet(Forest[x], Forest);
}

void unite(int x, int y, vector<int>& Forest, vector<int>& rank){
    int x_ = findSet(x, Forest);
    int y_ = findSet(y, Forest);
    if (rank[x_] == rank[y_]) {
        Forest[y_] = x_;
        rank[x_]++;
        return;
    }
    if (rank[x_] > rank[y_]) {
        Forest[y_] = x_;
    } else {
        Forest[x_] = y_;
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> Forest(n);
    for (int i = 0; i < n; i++) {
        Forest[i] = i;
    }
    vector<int> rank(n, 0);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            unite(x, y, Forest, rank);
        } else {
            cout << (findSet(x, Forest) == findSet(y, Forest)) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3172
/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
  To be updated after "Accept".

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

int main () {
	int a = read, x = read;
	int b = read, y = read;
	if (a == b) return puts("YES"), 0;
	if (x <= y) return puts("NO"), 0;
	ll d = read;
	d *= x - y;
	if (std::abs(a - b) <= d) puts("YES");
	else puts("NO");
}


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

typedef long long ll;

int main() {
    int r, D, x2000;
    cin >> r >> D >> x2000;
    int xi = x2000;
    for (int i=0;i<10;i++){
        xi = r*xi - D;
        cout << xi << endl;
    }

}



Measured memory_bytes: 256
X, K, D = list(map(int, input().split()))
X = abs(X)
if(X >= K * D):
  print(X - K * D)
else:
  q = X // D
  r = X % D
  if((K - q) % 2 == 0):
    print(r)
  else:
    print(abs(r - D))


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int x, a; cin >> x >> a;
        if (x < a) cout << 0;
        else cout << 10;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

struct edge_t {
  int other;
  int count;
  edge_t *rev;
};

vector<int> path;
void dfs(int v, vector<vector<edge_t*>> &adj) {
  while (!adj[v].empty()) {
    edge_t *last = adj[v].back();
    adj[v].pop_back();
    if (last->count == 0) {
      delete last;
      continue;
    }
    last->count = 0;
    last->rev->count = 0;

    dfs(last->other, adj);
    delete last;
  }
  path.push_back(v);
}

void answer_no() {
  printf("No\n");
  exit(0);
}

void answer_yes() {
  printf("Yes\n");
  exit(0);
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<edge_t*>> adj(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b), --a, --b;
    adj[a].emplace_back(new edge_t);
    adj[b].emplace_back(new edge_t);
    edge_t *ab = adj[a].back();
    edge_t *ba = adj[b].back();
    ab->other = b;
    ab->rev = ba;
    ab->count = 1;
    ba->other = a;
    ba->rev = ab;
    ba->count = 1;
  }

  for (int i = 0; i < n; ++i) {
    if (adj[i].size() % 2 != 0)
      answer_no();
    if (adj[i].empty())
      answer_no();
  }

  vector<int> fours;
  for (int i = 0; i < n; ++i) {
    if (adj[i].size() >= 6)
      answer_yes();
    if (adj[i].size() == 4)
      fours.push_back(i);
  }
  if ((int)fours.size() <= 1)
    answer_no();
  if ((int)fours.size() >= 3)
    answer_yes();

  path.clear();
  dfs(0, adj);
  path.pop_back();

  vector<int> order;
  for (int i = 0; i < (int)path.size(); ++i) {
    if (path[i] == fours[0]) order.push_back(0);
    else if (path[i] == fours[1]) order.push_back(1);
  }
  assert((int)order.size() == 4);
  for (int i = 0; i + 1 < (int)order.size(); ++i)
    if (order[i] == order[i + 1])
      answer_yes();
  answer_no();

  return 0;
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve() {
    string s;
    cin >> s;
    char x = s[(int)s.sz - 1];
    if(x == 's') cout << s << "es";
    else cout << s << "s";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


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

using namespace std;

constexpr int INF = (1 << 29);
constexpr int MOD = ((1e8) + 7);

int main()
{
    int r, c, x1, y1, x2, y2;
    cin >> r >> c >> y1 >> x1 >> y2 >> x2;

    vector<vector<int>> d(r, vector<int>(c, INF));
    vector<vector<int>> e(r, vector<int>(c, 0));
    d[y1][x1] = 0;
    e[y1][x1] = 1;

    constexpr int dx[] = {-1, +0, +1, +0};
    constexpr int dy[] = {+0, -1, +0, +1};
    
    queue<pair<int, int>> que;
    que.push(make_pair(y1, x1));    
    
    while (!que.empty()) {
        int x, y;
        tie(y, x) = que.front(); que.pop();

        for (int i = 0; i < 4; i++) {
            int ny = (y + dy[i] + r) % r;
            int nx = (x + dx[i] + c) % c;

            if (d[y][x] + 1 <= d[ny][nx]) {
                e[ny][nx] += e[y][x];
                e[ny][nx] %= MOD;
            }
            
            if (d[y][x] + 1 < d[ny][nx]) {
                d[ny][nx] = d[y][x] + 1;
                que.push(make_pair(ny, nx));
            }
        }        
    }
    cout << e[y2][x2] << endl;
    return 0;
}

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

#define INF 1e9
#define PI 3.141592653589793238
typedef long long ll;

int main() {
    double r;cin>>r;
    printf("%.2lf", 2*PI*r);



    return 0;
}

Measured memory_bytes: 3776
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
  for j in range(i+1, N):
    dij = A[i][j]
    res = True
    for k in range(N):
      if k in [i, j]:
        continue
      dikj = A[i][k] + A[k][j]
      if dij > dikj:
        print(-1)
        quit()
      elif dij == dikj:
        res = False
    if res:
      ans += dij

print(ans)

Measured memory_bytes: 43996
n, k = gets.chomp.split(" ").map(&:to_i)
r, s, p = gets.chomp.split(" ").map(&:to_i)
t = gets.chomp.split("")

for i in 0..(k - 1)
  j = i
  while j < t.size do
    if (j - k) >= 0 and t[j - k] == t[j] then
      t[j] = "x"
    end

    j += k
  end
end

sum = t.reduce(0) do |sum, a|
  case a
  when "r"
    sum + p
  when "s"
    sum + r
  when "p"
    sum + s
  else
    sum
  end
end

p sum

Measured memory_bytes: 9852
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void) {
  string s;
  cin >> s;
  int cnt = 1;
  string prev = s.substr(0, 1);
  int i = 1;
  while (i < s.size()) {
    for (int j = 1; j <= s.size() - i; j++) {
      string sub = s.substr(i, j);
      if (sub != prev) {
        prev = sub;
        cnt++;
        i += sub.size();
        break;
      }
      else if (i == s.size() - 1) {
        i++;
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b; cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
int solve(vector<vector<int>> &compatibility,int n){
	int max_size = 1LL << n;
	vector<int> dp(max_size,0);
	dp[max_size-1] = 1;
	for(int mask=max_size-2;mask>=0;mask--){
		int setBits = __builtin_popcount(mask);
		for(int i=0;i<n;i++){
			if(compatibility[setBits][i] == 1 && ((mask >> i) & 1) == 0){
				dp[mask] += dp[(mask | (1<<i))];
				dp[mask] %= mod;
			}
		}
	}
	return dp[0];
}
int32_t main(int32_t argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int test = 1;
	//cin>>test;
	while(test--){
		int n;
		cin >> n;
		vector<vector<int>> compatibility(n,vector<int>(n));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin >> compatibility[i][j];
			}
		}
		if(n == 1){
			if(compatibility[0][0] == 0){
				cout << 0 <<"\n";
			}else{
				cout << 1 << "\n";
			}
			continue;
		}	
		int ans = solve(compatibility,n);
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 11372
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
                string input = Console.ReadLine();
                char[] change = input.ToCharArray();

                for (int i = 0; i < change.Length; i++)
                {
                    if (char.IsLower(change[i]))
                    {
                        change[i] = char.ToUpper(change[i]);
                    }else if(char.IsUpper(change[i])){
                        change[i] = char.ToLower(change[i]);
                    }
                }

                for (int i = 0; i < change.Length; i++)
                {
                    Console.Write(string.Format("{0}", change[i]));
                }
                Console.WriteLine();   
        }
    }
}

Measured memory_bytes: 9336
N=int(input())
a_list = list(map(int,input().split()))

#累積和を作成
s_list=[0]
sum=0
for i in a_list:
    sum+=i
    s_list.append(sum)

#print(s_list)

target=s_list[-1]//2

tmp1=10**10
for i in range(1,N):
    tmp2=abs(target-s_list[i])
    tmp1=min(tmp1,tmp2)#より小さいほうをtmp1に格納
    if tmp1 == tmp2:
        ans_index=i

#print(ans_index)
print(abs(s_list[-1]-2*s_list[ans_index]))

Measured memory_bytes: 101464
x, k, d = map(int, input().split())

result = 0

abs_x = abs(x)
firstNearestIterNum = abs_x // d

if firstNearestIterNum >= k:
	result = abs_x - (d * k)
else:
	if (k - firstNearestIterNum) % 2 == 1:
		result = abs_x - (d * (firstNearestIterNum + 1))
	else:
		result = abs_x - d * firstNearestIterNum

print(abs(result))

Measured memory_bytes: 9052
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

struct Node{

  int key;
  Node *right,*left,*parent;

    };

Node *root,*NIL;

Node * find(Node *u,int k){
  while(u!=NIL && k!=u->key){

    if(k < u->key){
      u=u->left;
}
    else u=u->right;
  }
  return u;
}

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
   z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;

  if(y==NIL){
    root=z;
  }

  else{
      if(z->key < y->key){
      y->left=z;
    }

    else{
      y->right=z;
    }
  }
}

void inorder(Node *u){

  if(u==NIL) return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u){

  if(u==NIL) return;

  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,a;

  string com;

  scanf("%d",&n);

  for(i=0;i<n;i++){
       cin >> com;

    if(com[0]=='f'){
      scanf("%d",&a);
      Node *t =find(root,a);
      if(t!=NIL){
        printf("yes\n");
      }

      else printf("no\n");
    }

    else if(com=="insert"){
      scanf("%d",&a);
      insert(a);
    }

    else if(com=="print"){
        
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}




Measured memory_bytes: 21940
mask = {
    'N': (1, 5, 2, 3, 0, 4),
    'R': (0, 2, 4, 1, 3, 5)
    }


def isIdentifyDice(dice, dice2):
    find = False

    for i in range(4):

        for j in range(4):
            if dice == dice2:
                find = True
                break
            dice = [dice[x] for x in mask['R']]

        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['N']]

    dice = [dice[x] for x in mask['R']]
    dice = [dice[x] for x in mask['N']]
    for j in range(4):
        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['R']]

    dice = [dice[x] for x in mask['N']]
    dice = [dice[x] for x in mask['N']]
    for j in range(4):
        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['R']]

    return find


n = int(input())
dt = list(map(int, input().split()))

chk = True
for i in range(n - 1):
    dc = list(map(int, input().split()))
    chk = not isIdentifyDice(dc, dt)
    if not chk:
        break

print("Yes" if chk else "No")



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
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...);
}



void solve(){
    ll a,b,c;
    cin >> a >> b >> c;
    cout << c << " " <<a << " " << b << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
input_from_file
#endif
 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
   // cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

Measured memory_bytes: 3628
n=int(input())
a=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(a[0]-a[1])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
print(dp[n-1])

Measured memory_bytes: 20440
#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() {
  int r;
  cin >> r;
  int ans;
  ans = 3 * r * r;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ll n;
    cin >> n;
    if (n % 11 == 0) cout << n/11*2;
    else {
        ll res = n/11*2;
        if (n/11*11+6 >= n) cout << res+1;
        else cout << res+2;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll modinv(ll a, ll mod) {
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

ll modpow(ll a, ll b, ll mod) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a%mod;
		a = a * a%mod;
		b >>= 1;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	a.push_back(a[0]);
	b.push_back(b[0]);
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) x[i] = a[i] ^ a[i + 1];
	for (int i = 0; i < n; i++) y[i] = b[i] ^ b[i + 1];
	ll mod1 = 998244353; ll base1 = 10007; ll p = 0;
	ll mod2 = 1000000007; ll base2 = 10009; ll q = 0;
	for (int i = 0; i < n; i++) {
		p += x[i]; p *= base1; p %= mod1;
		q += x[i]; q *= base2; q %= mod2;
	}
	ll ok1 = 0; ll ok2 = 0;
	for (int i = 0; i < n; i++) {
		ok1 += y[i]; ok1 *= base1; ok1 %= mod1;
		ok2 += y[i]; ok2 *= base2; ok2 %= mod2;
	}
	for (int i = 0; i < n; i++) {
		if (ok1 == p && ok2 == q) {
			ll val = a[0] ^ b[(n - i) % n];
			if (val == a[1] ^ b[(n + 1 - i) % n] && val == a[2] ^ b[(n + 2 - i) % n]) {
				cout << i << ' ' << val << endl;
			}
		}
		ok1 *= modinv(base1, mod1); ok1 %= mod1;
		ok1 -= y[n - 1 - i]; ok1 += mod1; ok1 %= mod1;
		ok1 += y[n - 1 - i] * modpow(base1, n, mod1) % mod1;
		ok1 %= mod1;
		ok2 *= modinv(base2, mod2); ok2 %= mod2;
		ok2 -= y[n - 1 - i]; ok2 += mod2; ok2 %= mod2;
		ok2 += y[n - 1 - i] * modpow(base2, n, mod2) % mod2;
		ok2 %= mod2;
	}
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

struct Modcomb{
  int mod; //$BAG?t(B
  std::vector<long long int>fac;  //$B3,>h(B
  std::vector<long long int>finv; //$B3,>h$N5U85(B
  std::vector<long long int>inv;  //$B5U85(B

  //nCr=n!/r!(n-r)!
  Modcomb(int max,int mod){
    this->mod=mod;
    fac.resize(max+1,0);
    finv.resize(max+1,0);
    inv.resize(max+1,0);
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<=max;i++){
      fac[i]=(fac[i-1]*i%mod)%mod;
      inv[i]=mod-inv[mod%i]*(mod/i)%mod;
      finv[i]=finv[i-1]*inv[i]%mod;
    }
  }

  long long int slove(int n,int r){
    if(n<r)return 0;
    if(n<0||r<0)return 0;
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod;
  }
};

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

  int N,K;
  cin>>N>>K;
  Modcomb comb(N+1,MOD);
  for(int i=0;i<K;i++){
    cout<<(comb.slove(K-1,i)*comb.slove(N-K+1,i+1))%MOD<<endl;
  }
  return 0; }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

constexpr ll LNF = 1ll<<60;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */
ll n,a,b,c,d;
map<ll,ll> m;

ll dfs(ll here){
    if(m[here]!=0) return m[here];
    if(here<=0) return 0;
    if(here==1) return d;
    ll t = LNF;
    if(here<LNF/d) t = here*d;
    chmin(t,a+d*(here%2ll)+dfs(here/2ll));
    if(here%2==1){
        chmin(t,a+d+dfs((here+1ll)/2ll));
    }
    chmin(t,b+d*(here%3ll)+dfs(here/3ll));
    if(here%3!=0){
        chmin(t,b+d*(3ll-here%3ll)+dfs((here+2ll)/3ll));
    }
    chmin(t,c+d*(here%5ll)+dfs(here/5ll));
    if(here%5!=0){
        chmin(t,c+d*(5ll-here%5ll)+dfs((here+4ll)/5ll));
    }
    m[here] = t;
    return t;
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    rep(_,0,t){
        cin >> n >> a >> b >> c >> d;
        m.clear();
        ll ans = dfs(n);
        cout << ans << endl;
    }
}

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

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))

typedef long long ll;

int main(){
    
    set< pair<int,int> > M;
    int N;
    cin>>N;
    int cnt=0;
    REP(i,N){
        int t; cin>>t;
        if(M.find(make_pair(i+1,t))!=M.end()){
            cnt++;
        }else if(M.find(make_pair(t,i+1))!=M.end()){
            cnt++;
        }else{
            M.insert(make_pair(t,i+1));
        }
    }
    
    cout<<cnt<<endl;
    
    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;

    vector<long long> dp(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        dp.at(i) = dp.at(i - 1) + i;
    }

    long long ans = 0;
    for (int i = K; i <= N; i++) {
        ans += (abs(dp.at(i - 1) - (dp.at(N) - dp.at(N - i))) + 1) % 1000000007;
        ans %= 1000000007;
    }
    ans++;
    ans %= 1000000007;

    cout << ans << endl;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}
const int mod = 1e9 + 7 ; 
signed main (){
  int n;
  cin >> n;
  ll power = 1;
  for(int i = 1; i <= n;i++){
power *= i;
power %= mod;
  }

  cout << power << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  string S;
  cin >> S;
  int r = 0, b = 0;
  rep(i, S.size())
  {
    (S.at(i) == '0') ? ++r : ++b;
  }
  int ans = min(r, b);
  cout << ans * 2 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
const int N=25005;
using namespace std;
typedef long long ll;
ll c[100][N],ar[N],n,a;
int main()
{
    cin>>n>>a;
    c[0][0]=1;
    ll ans=0;
    for(int i=1;i<=n;i++){
        cin>>ar[i];
        for(int j=N-ar[i];j>=0;j--){
            for(int cn=0;cn<=i;cn++){
                if(j+ar[i]>=N)continue;
                 c[cn+1][j+ar[i]]+=c[cn][j];
            }

        }
    }
    for(int i=1;i<=n;i++){
        ans+=c[i][i*a];
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 13588
import java.util.*;

public class Main{
    static Scanner sc = new Scanner(System.in);
        
    public static void main(String[] args) {
        int n = Integer.parseInt(sc.nextLine());
        int count = 0;
        for(int i = 0;i<n;i++){
            String temp = sc.nextLine();
            if(temp.charAt(0) == temp.charAt(2)){
                count++;
            }else{
                count = 0;
            }
            if(count == 3){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 35876
import java.util.*;
import java.lang.*;

public class Main{
    
    static int i = 1;
    static int n;
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int[] a = new int[n];
        
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        
        for (int i = 0; i < n - 1; i++) {
            System.out.print(a[n - 1 - i] + " ");
        }
        System.out.println(a[0]);
        
    }
}



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

solve :: [Int] -> String
solve ns =
    unwords . map show $ sort ns

main =      
    mapM_ putStrLn =<< map solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = takeWhile (not . all (== 0)) . map (map read . words)

Measured memory_bytes: 4480
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T> >;

const ll MOD=1e9+7;

int N;

inline int q(int k){
  cout<<k<<endl;
  string s;cin>>s;
  if(s[0]=='F') return 0;
  if(s[0]=='M') return 1;
  return 2;
}

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

  cin>>N;

  int a;a=q(0);
  if(a==2) return 0;

  int l=1,r=N;
  while(l<r){
    int m=(l+r)/2;
    int b=q(m);
    if(b==2) return 0;
    if((b-a+2)%2 == m%2){
      l=m+1;
    }else{
      r=m;
    }
  }

  return 0;
}


Measured memory_bytes: 852
#include <stdio.h>

int main(){
    int i, n, m, miss, a[1000], min, min_idx, res;

    scanf("%d%d", &n, &m);

    min_idx = 0;
    for(i=0;i<m;i++){
        scanf("%d%d", &a[i], &miss);
        if(i == 0) {
            min = a[0];
        }
        if(min > a[i]){
            min = a[i];
            min_idx = i;
        }
    }

    res = 0;
    for(i=0;i<m;i++){
        if(i != min_idx && a[i] < n){
            res += n - a[i];
        }
    }

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

    return 0;
}

Measured memory_bytes: 600
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]: ass.append(i)
    return ass
d, ans = [0]*(10**5+1), [0]*(10**5+1)
for i in primes(10**5): d[i] += 1
for i in range(2, 10**5+1):
    ans[i] += ans[i-1]
    if i%2==1 and d[i] and d[(i+1)//2]: ans[i] += 1
for _ in range(int(input())):
    l, r = map(int, input().split())
    print(ans[r]-ans[l-1])

Measured memory_bytes: 7364
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math
N,D,A=map(int,input().split())
XH=[list(map(int,input().split())) for i in range(N)]
XH=sorted(XH,key=lambda x:x[0])

lst=[]
bomb=[]
count=0
nowbomb=0
idx=0
#print(XH)
for x,h in XH:
    #print(lst,bomb)
    if lst:
        while idx<len(lst) and lst[idx]<x-D:
            nowbomb-=bomb[idx]
            idx+=1
    #print(nowbomb)
    a=h-nowbomb
    if a>0:

        b=a//A+(a%A>0)*1
        #print(a,b)
        nowbomb+=b*A
        count+=b
        lst.append(x+D)
        bomb.append(b*A)

print(count)


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int ans=(h2-h1)*60+(m2-m1);
    if(ans<0)
    {
        ans+=24*60;
    }
    ans-=k;
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string s;cin>>s;
    string ans="";
    rep(i,s.size()){
        if(s.at(i)==',')ans+=" ";
        else ans+=s.at(i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;

long long n;
long long a[1000];
long long ans;
long long gcd(long long x,long long y)
{
	if(y==0)return x;
	else return gcd(y,x%y);
}
int main()
{
	cin>>n;
	ans=1;
	rep(i,n)cin>>a[i];
	rep(i,n)
	{
		ans=ans/gcd(ans,a[i])*a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
tasks = []
for i in range(n):
    a, b = map(int, input().split())
    tasks.append([b,a])
tasks = sorted(tasks)

time = 0
res = True
for i in range(n):
    time = time + tasks[i][1]
    if time > tasks[i][0]:
        res = False
print("Yes" if res else "No")

Measured memory_bytes: 37156
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        l:i64,
    }
    let mut ans = (std::i64::MAX);
    let mut index = 0;
    let v:Vec<_> = (0..n).map(|x| x as i64 + l ).collect();
    let sum = v.iter().sum::<i64>();
    for j in 0..n {
        let dist = (sum-(sum-v[j])).abs();
        if ans > dist {
            index = j;
        }
        ans = min(ans,dist);
    }
    // let min_v = ans.iter().map(|&x| x.abs()).min().unwrap();

    // println!("{:?}",ans);
    println!("{}",sum-v[index]);
}

Measured memory_bytes: 4352