akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 200006
using namespace std;

int a[MAX];
pair<int, int> p[MAX];
int main(){
	int n, size = 0;
	cin >> n;
	fill(p, p+MAX, make_pair(0, 0));
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	sort(a, a+MAX);
	int ans = 0;
	for(int i = 0;i < MAX;i++){
		if(p[size].first != a[i])size++;
		p[size].first = a[i];
		p[size].second++;
	}
	for(int i = 1;i <= size;i++){
		if(p[i].first < p[i].second)ans += p[i].second-p[i].first;
		if(p[i].first > p[i].second)ans += p[i].second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
s = input()
m = []
for i in s:
        m.append(i)
count_list = []
for i in m:
        count = 0
        for j in m:
                if i == j:
                        count += 1
        count_list.append(count)
for i in count_list:
        if i != 2:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 3060
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
P<int,int> dis[305][305];
V<P<int,int> > v[305];
int n;
#define PP pair<pair<int,int>,int>
priority_queue<PP,vector<PP>,greater<PP> > q;
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int m,l;
	cin>>n>>m>>l;
	int x,y,z;
	FOR(i,1,m){
		cin>>x>>y>>z;
		if(z>l)continue;
		v[x].PB(MP(y,z));
		v[y].PB(MP(x,z));
	} 
	FOR(i,1,n){
		FOR(j,1,n)dis[i][j]=MP(-1,0);
	}
	FOR(i,1,n){
		q.push(MP(MP(0,0),i));
		while(!q.empty()){
			PP t=q.top();q.pop();
			if(dis[i][t.S].F!=-1)continue;
			dis[i][t.S]=t.F;
			for(int j=0;j<v[t.S].size();j++){
				if(dis[i][v[t.S][j].F].F!=-1)continue;
				if(v[t.S][j].S+t.F.S>l){
					q.push(MP(MP(t.F.F+1,v[t.S][j].S),v[t.S][j].F));
				}else{
					q.push(MP(MP(t.F.F,t.F.S+v[t.S][j].S),v[t.S][j].F));
				}
			}
		}
	}
	int q,s1,s2;
	cin>>q;
	FOR(i,1,q){
		cin>>s1>>s2;
		cout<<dis[s1][s2].F<<'\n';
	}
	return 0;
}




Measured memory_bytes: 3072
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head
 
 
 
const int N = 4e3+10;
int n, x, a[N], b[N];
ll dp[N];
 
int main() {
	scanf("%d%d", &n, &x);
	REP(i,1,n) scanf("%d", a+i),a[i+n]=a[i];
	memset(b,0x3f,sizeof b);
	ll ans = 1e18;
	REP(j,0,n) {
		REP(i,1,n) b[i]=min(b[i],a[i-j+n]);
		ans = min(ans, accumulate(b+1,b+1+n,0ll)+(ll)j*x);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const { //値をt乗する
    if (!t) return 1; // t == 0
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this; //*thisは元の値(t乗する対象)
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll n,k;
vector<mint> fact(5000000);

mint nCr(ll n, ll r){
  if(r==0) return mint(1);
  return fact[n] * fact[r].inv() * fact[n-r].inv(); 
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  fact[0] = mint(1);
  rep2(i,1,5000000){
    fact[i] = fact[i-1] * i;
  }
  if(k+1 >= n){
    mint ans = fact[2*n-1] * fact[n].inv() * fact[n-1].inv();
    cout << ans.x << endl;
  }else{
    mint ans = 0;
    for(ll i = 0; i <=k; i++){
       ans += nCr(n,i) * nCr(n-1,i);
    }
    cout << ans.x << endl;
  }
  
  return 0;
}


Measured memory_bytes: 39296
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Node
{
	int num, cost, tic;

	Node( int n, int c, int t ) : num( n ), cost( c ), tic( t )
	{
		return;
	}

	bool operator > ( const Node &a ) const
	{
		return a.cost < cost;
	}
};

struct Edge
{
	int to, cost;

	Edge( int t, int c ) : to( t ), cost( c )
	{
		return;
	}
};

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

	while ( true )
	{
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;

		if ( !( c | n | m | s | d ) )
		{
			break;
		}

		s--;
		d--;

		vector< vector< Edge > > G( n, vector< Edge >() );

		REP( i, 0, m )
		{
			int a, b, f;
			cin >> a >> b >> f;

			a--;
			b--;

			G[a].PB( Edge( b, f ) );
			G[b].PB( Edge( a, f ) );
		}

		VVI dist( n, VI( c + 1, INT_MAX ) );

		priority_queue< Node, vector< Node >, greater< Node > > que;
		que.push( Node( s, 0, 0 ) );

		while ( !que.empty() )
		{
			Node cur = que.top();
			que.pop();

			if ( c < cur.tic || dist[ cur.num ][ cur.tic ] <= cur.cost )
			{
				continue;
			}

			dist[ cur.num ][ cur.tic ] = cur.cost;

			REP( i, 0, G[ cur.num ].size() )
			{
				que.push( Node( G[ cur.num ][i].to, cur.cost + G[ cur.num ][i].cost, cur.tic ) );
				que.push( Node( G[ cur.num ][i].to, cur.cost + G[ cur.num ][i].cost / 2, cur.tic + 1 ) );
			}
		}

		cout << *min_element( ALL( dist[d] ) ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1368
package main

import "fmt"

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	ans := 0
	for i := 1; i <= k; i++ {
		if i >= 1 && i <= a {
			ans++
		}
		if a+b < i && i <= k {
			ans--
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 1776
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
#define LL long long
 
LL read() {
	LL x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}
 
int main() {
	LL n = read(), l = read(), r = read();
	if(l > r) return puts("0"), 0;
	if(l != r && n == 1) return puts("0"), 0;
	printf("%lld\n", ((n - 1) * r + l) - ((n - 1) * l + r) + 1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)

// for debug macro
bool global_debug_flag = false;
#define DEBUG(val) \
  if (global_debug_flag) cout << #val << " = " << val << endl

int main() {
  int n;
  read n;
  vector<int> data(n);
  REP(i, n) {
    int x;
    read x;
    data[i] = x;
  }

  sort(data.begin(), data.end());
  int pre = data[0];
  bool flag = true;
  FOR(i, 1, n) {
    if (data[i] == pre) {
      DEBUG(data[i]);
      flag = false;
      break;
    } else {
      pre = data[i];
    }
  }
  if (flag) {
    echo "YES" fin;
  } else {
    echo "NO" fin;
  }
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
using pp=pair<int,pair<int,int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  int n,q;
  cin>>n>>q;
  int k=sqrt(n);
  int s=(n+k-1)/k;
  vector<ll> a(n,0);
  vector<ll> b(s,0);

  vector<ll> ans;
  for(int i=0;i<q;i++){
    int com;
    cin>>com;
    if(com==0){
      int x;
      ll y;
      cin>>x>>y;
      x--;
      a.at(x)+=y;
      b.at(x/k)+=y;
    }else{
      int x,y;
      cin>>x>>y;
      x--;
      ll sum=0;
      while(x<y&&x%k!=0){
        sum+=a.at(x);
        x++;
      }
      while(x<y&&y%k!=0){
        y--;
        sum+=a.at(y);
      }
      while(x<y){
        sum+=b.at(x/k);
        x+=k;
      }
      ans.push_back(sum);
    }
  }

  for(int i=0;i<ans.size();i++){
    cout<<ans.at(i)<<endl;
  }
}



Measured memory_bytes: 4332
N = int(input())
a = list(map(int, input().split()))
b = [0]*(N+1)
for i in range(N, 0, -1):
    if sum(b[i::i])%2 != a[i-1]:
        b[i] = 1
print (sum(b))
ans = []
for i, j in enumerate(b):
    if j == 1:
        ans.append(i)
print (*ans)

Measured memory_bytes: 14136
#include <iostream>
#include <queue>
using namespace std;
int w,h,count;
typedef struct{
	int x;
	int y;
}POS;
POS start,goal,flag;

int map[31][31];
int wall[100][100];
queue <POS> q;

int check(){
	POS nextpos;
	q.push(start);
	q.push(flag);
	while(count<=w*h){
		POS pos=q.front();
		q.pop();
		if(pos.x==goal.x&&pos.y==goal.y)return count;
		if(pos.x==-1){
			count++;
			q.push(flag);
		}else{
			if(pos.x>0&&wall[pos.x*2-1][pos.y]==0 &&map[pos.x-1][pos.y]==0){
				nextpos.x=pos.x-1;
				nextpos.y=pos.y;
				q.push(nextpos);
				map[nextpos.x][nextpos.y]=1;
			}

			if(pos.y>0&&wall[pos.x*2][pos.y-1]==0 &&map[pos.x][pos.y-1]==0){
				nextpos.x=pos.x;
				nextpos.y=pos.y-1;
				q.push(nextpos);
				map[nextpos.x][nextpos.y]=1;
			}

			if(pos.x<h-1&&wall[pos.x*2+1][pos.y]==0 &&map[pos.x+1][pos.y]==0){
				nextpos.x=pos.x+1;
				nextpos.y=pos.y;
				q.push(nextpos);
				map[nextpos.x][nextpos.y]=1;
			}

			if(pos.y<w-1&&wall[pos.x*2][pos.y]==0 &&map[pos.x][pos.y+1]==0){
				nextpos.x=pos.x;
				nextpos.y=pos.y+1;
				q.push(nextpos);
				map[nextpos.x][nextpos.y]=1;
			}

		}
		//cout <<pos.x <<" " <<pos.y <<endl;
	}
	return 0;
}

int main(){
	start.x=start.y=0;
	flag.x=flag.y=-1;
	while(1){
		cin >>w >>h;
		if(!(w||h))break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				map[i][j]=0;
			}
		}
		for(int i=0;i<2*h-1;i++){
			for(int j=0;j<w;j++){
				if(j==w-1&&i%2==0)continue;
				cin >>wall[i][j];
			}
		}
		count=1;
		goal.x=h-1;
		goal.y=w-1;
		cout << check()<<endl;
		while(!q.empty())q.pop();
	}
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int in[110000], idx[110000], ans[110000];;
bool nz[110000];

signed main() {
    cin >> N;
    for (int i = 1; i <= N; i++)cin >> in[i];

    int m = -1;
    for (int i = 0; i <= N; i++) {
        nz[i] = in[i] > m;
        m = max(m, in[i]);
    }

    for (int i = 0; i <= N; i++)idx[i] = i;
    stable_sort(idx, idx + N + 1, [](int a, int b) {
        return in[a] > in[b];
    });

    int prev = 101000, sum = 0;
    idx[101000] = 101000;
    for (int i = 0; i <= N; i++) {
        if (nz[idx[i]]) {
            ans[idx[prev]] = sum - i * in[idx[i]];
            sum = (i + 1) * in[idx[i]];
            prev = i;
        } else {
            sum += in[idx[i]];
        }
    }
    for (int i = 1; i <= N; i++)cout << ans[i] << endl;
}


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

int main () {
    int n, t;
    cin >> n >> t;
    
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);
    
    int ans = a[0];
    for (int i = 1; i < t; i++)
        ans += a[i];

    cout << ans;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <vector>

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

using namespace std;

int dp1[1111111];
int dp2[1111111];

int main() {
  vector<int> v1, v2;

  for (int i = 1; i*(i+1)*(i+2)/6 <= 1000006; i++) {
    int a = i*(i+1)*(i+2)/6;
    v1.push_back(a); 
    if (a & 1) { v2.push_back(a); }
  }
  rep(i, 1000006) {
    dp1[i] = int(1e8);
    dp2[i] = int(1e8);
  }
  dp1[0] = 0;
  dp2[0] = 0;
  // dp[x] := xを構成するために必要な正四面体数の個数の最小値
  //
  rep(i, 1000006) {
    rep(j, v1.size()) {
      if (i+v1[j] > 1000006) { continue; }
      dp1[i+v1[j]] = min(dp1[i]+1, dp1[i+v1[j]]);
    }
    rep(j, v2.size()) {
      if (i+v2[j] > 1000006) { continue; }
      dp2[i+v2[j]] = min(dp2[i]+1, dp2[i+v2[j]]);
    }
  }
 
  int in;
  while (cin >> in) {
    if (in == 0) { break; }
    cout << dp1[in] << " " << dp2[in] << endl;
  }

  return 0;
}


Measured memory_bytes: 10952
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: u32 = sc.read();
    let mut ok = false;
    for _ in 0..n {
        let a: u32 = sc.read();
        if a % 2 == 1 {
            ok = true;
        }
    }
    if ok {
        println!("first");
    } else {
        println!("second");
    }
}

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

int main(){
    uint64_t A,B,C,D;
    cin>>A>>B>>C>>D;

    uint64_t totalnum = B-A+1;
    uint64_t numC,numD,comnum=0;
    uint64_t minC,maxC,minD,maxD,mincom,maxcom;
    minC = A/C;
    maxC = B/C;
    if(A%C !=0){
        minC++;
    }
    numC = maxC-minC+1;

    minD = A/D;
    maxD = B/D;
    if(A%D !=0){
        minD++;
    }
    numD = maxD-minD+1;

  /* ユークリッドの互除法 */
    uint64_t r,a,b;
    if(C <D){
        a=D;
        b=C;
    }
    else{
        a=C;
        b=D;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    uint64_t ComN = C*D/b;
    mincom = A/ComN;
    maxcom = B/ComN;
    if(A%ComN !=0){
        mincom++;
    }
    comnum = maxcom-mincom+1;

    totalnum = totalnum -numC -numD +comnum;
    cout<<totalnum <<endl;

}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//input
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type Node struct {
	key int
	p   *Node
	l   *Node
	r   *Node
}

var NIL *Node

var root *Node
var n int

func preorder(u *Node, l []int) []int {
	if u != NIL {

		//fmt.Printf(" %d", u.key)
		l = append(l, u.key)
		l = preorder(u.l, l)
		l = preorder(u.r, l)
	}
	return l

}

func inorder(u *Node, l []int) []int {
	if u != NIL {
		l = inorder(u.l, l)
		//fmt.Printf(" %d", u.key)
		l = append(l, u.key)
		l = inorder(u.r, l)
	}
	return l
}

func printList(list []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

//挿入
func insert(v int) {
	var x, y *Node

	//x: 走査する初期値
	//y: xの親 = NIL
	x = root

	//z: 挿入するNode
	z := &Node{v, NIL, NIL, NIL}
	//zの親を求める
	for x != NIL {
		y = x
		if z.key < x.key {
			x = x.l
		} else {
			x = x.r
		}
	}

	z.p = y
	if y == NIL {
		root = z //木が空のときは、zをrootとする
	} else if z.key < y.key {
		y.l = z //zをyの左の子にする
	} else {
		y.r = z //zをyの右のことする
	}

}

//探索
func find(v int, u *Node) *Node {
	for u != NIL && v != u.key {
		if v < u.key {
			u = u.l
		} else {
			u = u.r
		}
	}
	return u
}

//削除
func delete(u *Node) {
	// nodeに子がない場合(case1)または子が1つの場合(case2)はnodeを削除対象にする
	// 子が2つある場合(case3)はnodeの次節点を削除対象にする

	// 削除対象のnodeをyとする
	var y *Node
	if u.l == nil || u.r == nil {
		//子を持たないか、子が1つのときは、入力した節点
		y = u
	} else {
		//子を2つ持つときは、次の節点に移動
		y = getSuccessor(u)
	}

	var x *Node
	//yの子xを決める
	if y.l != NIL {
		x = y.l //左に子があれば、それをxとする
	} else {
		x = y.r //左に子がなければ、右の子をxとする
	}

	//xの親として、yの親を設定
	if x != NIL {
		x.p = y.p
	}

	if y.p == NIL {
		root = x //yがrootのとき、rootをxに書き換える
	} else if y == y.p.l {
		y.p.l = x //yが左の子のとき、xをy.pの左の子とする
	} else {
		y.p.r = x //yが右の子のとき、xをy.pの右の子とする
	}

	//zの次節点が削除された場合
	if y != u {
		u.key = y.key //yのデータをzにコピーする
	}

}

func getSuccessor(n *Node) *Node {
	if n.r != nil {
		return getMinimum(n.r)
	}

	y := n.p
	for y != nil && n == y.r {
		n = y
		y = n.p
	}
	return y
}

func getMinimum(x *Node) *Node {
	for x.l != nil {
		x = x.l
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		verb := nextStr()
		if verb == "insert" {
			v := nextInt()
			insert(v)
		} else if verb == "print" {
			printList(inorder(root, []int{}))
			printList(preorder(root, []int{}))
		} else if verb == "find" {
			v := nextInt()
			t := find(v, root)
			if t != NIL {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		} else if verb == "delete" {
			v := nextInt()
			t := find(v, root)
			if t != NIL {
				delete(t)
			}
		}
	}
	//fmt.Println(root)
}



Measured memory_bytes: 39292
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;

bool cmp(const pair<int, int> &a, const pair<int, int> &b){
	if (a.second == b.second)
		return a.first < b.first;
	return a.second < b.second;
}

int main() {
	IO
	int n, a, b;
	cin >> n;
	pair <ll, ll> p[n];
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		p[i] = {a, b};
	}
	sort (p, p + n, cmp);
	ll sum = 0;
	for (int i = 0; i < n; i++){
		sum += p[i].first;
		if (sum > p[i].second) return cout << "No", 0;
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 3328
{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  n <- getInt
  aList <- concat . transpose <$> replicateM 3 getInts
  let a = listArray (1,3*n) aList
  let part = all (\(i,j)->even (i-j) && ((i`mod`3==2) == (j`mod`3==2))) $ zip aList [1..3*n]
  let i3 = and [x==y&&y==z | i<-[1,4..3*n], let x=(a!i - 1)`div`3, let y=(a!(i+1) - 1)`div`3, let z=(a!(i+2) - 1)`div`3]
  let sigAll = sig [1..3*n] a
  let sig2x = sig [2,8..3*n] a
  let sig2y = sig [5,11..3*n] a
  let sig13x = even $ length $ filter (\ i -> (a!i)`mod`3==0) [4,10..3*n]
  let sig13y = even $ length $ filter (\ i -> (a!i)`mod`3==0) [1,7..3*n]
  putStrLn . yesNo $ part && i3 && sigAll && sig2x == sig13x && sig2y == sig13y

sig ix a = even $ length ix - length (cycles ix a)

cycles :: (Ix a) => [a] -> Array a a -> [[a]]
cycles ix a = let
  -- ix = indices a
  go x = do
    s <- get
    if S.member x s
    then return []
    else do
      put $ S.insert x s
      (x:) <$> go (a!x)
  in
  filter (not . null) $ flip evalState S.empty $ mapM go ix

type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "Yes"
yesNo False = "No"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 95612
N = int(input())
A = list(map(int, input().split()))
k = 0
while max(A) > N - 1:
    S = 0
    for i in range(N):
        S += A[i] // N

    for i in range(N):
        A[i] = A[i] - (A[i] // N) * N + S - A[i] // N

    k += S

print(k)


Measured memory_bytes: 3060
// ORZ YJZ
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n, a[105], p;
ll dp[105][2];
int main() {
	n=readint();p=readint();rep(i,1,n) a[i]=readint()&1;
	dp[0][0]=1;
	rep(i,1,n) {
		dp[i][a[i]]=1;
		rep(j,1,i-1) {
			dp[i][0]+=dp[j][a[i]];
			dp[i][1]+=dp[j][!(a[i])];
		}
//		cerr<<dp[i][0]<<' '<<dp[i][1]<<endl;
	}
	ll ans=0;
	rep(i,0,n) ans+=dp[i][p];
	printll(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int a, b;
	cin >> a >> b;
	cout << a*b << '\n';
}


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

using namespace std;

const int N = 505;

int n, m;
char g[N][N], a[N][N], b[N][N];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
  	scanf("%s", g[i] + 1);
  	for (int j = 1; j <= m + 1; ++j) {
  	  a[i][j] = b[i][j] = g[i][j];
  	}
  }
  for (int j = 1; j <= m; ++j) {
  	a[1][j] = '#';
  }
  for (int j = 1; j <= m; j += 2) {
  	for (int i = 2; i < n; ++i) a[i][j] = '#';
  }
  for (int j = 1; j <= m; ++j) {
  	b[n][j] = '#';
  }
  for (int j = 2; j <= m; j += 2) {
  	for (int i = 2; i < n; ++i) b[i][j] = '#';
  }
  for (int i = 1; i <= n; ++i) puts(a[i] + 1);
  cout << '\n';
  for (int i = 1; i <= n; ++i) puts(b[i] + 1);
  return 0;
}



Measured memory_bytes: 4428
#include <stdio.h>

int max(int a, int b) {
  return a > b ? a : b;
}

int main(void) {
  int i, j, k, n, ans = 1000000;
  scanf("%d", &n);
  int l[n], sum = 0;
  for(i = 0; i < n; ++i) {
    scanf("%d", &l[i]);
    sum += l[i];
  }
  for(i = 1; i <= 50000; ++i) {
    int dp[n];
    for(j = 0; j < n; ++j) dp[j] = 1000000;
    for(j = 0; j < n; ++j) {
      int now = 0;
      for(k = j; k < n; ++k) {
        now += l[k];
        int tt;
        if(!j) tt = 0;
        else tt = dp[j - 1];
        if(now >= i && dp[k] > max(now, tt)) dp[k] = max(now, tt); 
      }
    }
    if(dp[n - 1] != sum && ans > dp[n - 1] - i) ans = dp[n - 1] - i;
    /*if(i == 17) {
      for(j = 0; j < n; ++j) printf("%d ", dp[j]);
     printf("\n");
    }*/
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2740
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1e9+7
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_V 100
#define MAX_E 100

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

int dfs(int i, int a, int b, int c);

int N, A, B, C;
int l[8];

int main() {

  cin >> N >> A >> B >> C;
  rep(i, N) cin >> l[i];

  cout << dfs(0, 0, 0, 0) << endl;

  return 0;
}

int dfs(int i, int a, int b, int c) {

  if(i==N) {
    if(a!=0&&b!=0&&c!=0) {
      return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    }else {
      return INF;
    }
  }

  int res1 = dfs(i+1, a, b, c);
  int res2 = dfs(i+1, a+l[i], b, c) + 10;
  int res3 = dfs(i+1, a, b+l[i], c) + 10;
  int res4 = dfs(i+1, a, b, c+l[i]) + 10;

  return min({res1, res2, res3, res4});
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int count(long long n) {
    if (n == 1 || n == 0) return 0;
    if (n % 3 == 0) return count(n/3)+1;
    return count(n/3+1)+1;
}

int main() {
    long long n;
    cin >> n;
    cout << count(n) << endl;
    return 0;
}

Measured memory_bytes: 0
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
a =l()
first = 1000
for i in range(n-1):
    if a[i] > a[i+1]:
        stuck = a[cnt:i+1]
        b = first//min(stuck)
        first += (max(stuck)-min(stuck))*b
        cnt = i+1

stuck=a[cnt:]
b = first//min(stuck)
first += (max(stuck)-min(stuck))*b

print(first)


Measured memory_bytes: 10312
#include<iostream>
using namespace std;
main()
{
    string s;
    int a,b;
    cin >> s;
    a = (s[0] ^ 48 ) * 10 + (s[1] ^ 48);
    b = (s[2] ^ 48 ) * 10 + (s[3] ^ 48);
    
    if( (0 < a && a <= 12 ) && ( 0 < b && b<=12 ) )
    {
        printf("AMBIGUOUS\n");
    }
    else if (0 < b && b <= 12 )
    {
        printf( "YYMM\n");
    }
    else if ( 0 < a && a <= 12)
    {
        printf( "MMYY\n");
    }
    else
    {
        printf( "NA\n");
    }
    
    return 0;
    
}

Measured memory_bytes: 256
#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()

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

  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++)cin>>L[i];
  sort(rng(L));
  int sum=0;
  for(int i=0;i<N-1;i++){
    sum+=L[i];
  }
  if(sum>L[N-1])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
 short map[31], w, n;
 while(cin >> w) {
  cin >> n;
  w++;
  for(int i=1; i < w; i++) map[i] = i;
  for(int i=0; i < n; i++) {
   int a, b;
   scanf("%d,%d", &a, &b);
   int tmp = map[a];
   map[a] = map[b];
   map[b] = tmp;
  }
  for(int i=1; i < w; i++) cout << map[i] << endl;
 }
 return 0;
}

Measured memory_bytes: 0
//testcode.cpp
#include <iostream>
using namespace std;


int main() {
    int A , B , C , Q_b , R_b , Q_c , R_c ;
  	cin >> A ;
    cin >> B >> C ;

// B = Q_b * A + R_b
    Q_b = B/A ;
    R_b = B%A ;

// C = Q_c * A + R_c
    Q_c = C/A;
    R_c = C%A ;

    if (Q_c - Q_b > 0) {
      cout << "OK" ;
    } else {
        if (R_b == 0) {
          cout << "OK" ;
        } else {
          cout << "NG" ;
        }    
    }  
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> st(N);
    int num;
    string res;
    int ansa = 0, answ = 0;
    for(int i = 0; i < M; i++){
        cin >> num >> res;
        if(st.at(num-1).first == 0){
            if(res == "AC"){
                st.at(num-1).first = 1;
                answ += st.at(num-1).second;
                ansa++;
            }
            else if(res == "WA") st.at(num-1).second++;
            else {
                cout << 0 << endl;
                return 0;
            }
        }
        else continue;
    }
    cout << ansa << " " << answ << endl;
}

Measured memory_bytes: 1024
import sys
n = int(input())
sort_list = list(map(int,input().split()))

cnt = []
def merge(A, left,mid,right):
    n1 = mid -left
    n2 = right - mid
    L = [i for i in A[left : left + n1]]
    R = [i for i in A[mid : mid + n2]]
    L.append(sys.maxsize)
    R.append(sys.maxsize)

    i = 0
    j = 0
    c = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        c += 1

    cnt.append(c)

def mergesort(A,left,right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right)

mergesort(sort_list, 0, len(sort_list))
print(' '.join([str(i) for i in sort_list]))
print(sum(cnt))



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

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

    int N;
    ll x;
    cin >> N >> x;
    vector<ll> a(N);
    for (auto &p : a) {
        cin >> p;
    }
    sort(a.begin(), a.end());
    int pnt = 0;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (x >= a.at(i)) {
            x -= a.at(i);
            ans++;
        } else {
            x = 0;
            break;
        }
    }
    if (x > 0) {
        ans--;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
h, w, m = gets.split.map(&:to_i)

r = Array.new(h+1,0)
r_max = 0
r_max_index = []
c = Array.new(w+1,0)
c_max = 0
c_max_index = []
d = Hash.new {|hash,key| hash[key] = {}}
m.times do
    a,b = gets.split.map(&:to_i)

    if r_max < (r[a] += 1)
        r_max = r[a]
        r_max_index = [a]
    elsif r_max == r[a]
        r_max_index << a
    end

    if c_max < (c[b] += 1)
        c_max = c[b]
        c_max_index = [b]
    elsif c_max == c[b]
        c_max_index << b
    end

    d[a][b] = 1
end

r_max_index.each do |a|
    c_max_index.each do |b|
        if !d[a][b]
            p r_max + c_max
            exit
        end
    end
end

p r_max + c_max - 1

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

int main(){
    string s;
    cin >> s;
    int ans = 700;
    rep(i, 3){
        if(s.at(i) == 'o') ans+=100;
    }
    cout << ans << endl;
    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var dp = new long[N];

            dp[1] = Math.Abs(h[0] - h[1]);
            for (var i = 2; i < N; i++)
            {
                dp[i] = Math.Min(dp[i - 2] + Math.Abs(h[i] - h[i - 2]), dp[i - 1] + Math.Abs(h[i] - h[i - 1]));
            }
            Console.WriteLine(dp[N - 1]);
        }
    }
}


Measured memory_bytes: 19680
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

int f(vector<PII>& v, int dr, int dc)
{
    int i;
    int res = SIZE(v);
    FOR(i, 0, SIZE(v))
    {
        PII t(v[i].first - dr, v[i].second - dc);
        int pos = lower_bound(ALL(v), t) - v.begin();
        if(0 <= pos && pos < SIZE(v) && v[pos] == t) --res;
    }
    return res;
}

void solve(int test)
{
    int n;
    cin >> n;
    int i, j;
    vector<PII> v(n);
    FOR(i, 0, n) cin >> v[i].first >> v[i].second;

    sort(ALL(v));
    int res = n;
    FOR(i, 0, n)
    FOR(j, 0, n)
    {
        int dr = v[i].first - v[j].first;
        int dc = v[i].second - v[j].second;
        if(dr != 0 || dc != 0) res = min(res, f(v, dr, dc));
    }
    
    cout << res << endl;
}

int main()
{
    int t, T;
    T = 1;
    //scanf("%d", &T);
    FOR(t, 0, T) solve(t);
    
    return 0;
};



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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define REPD(i,n) FOR(i,n-1,0)
#define PB push_back
#define mod 1000000007


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";
    
    return 0;   
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <functional>

using namespace std;

string reverse(string a) {
	string b = "";
	for (int i = a.size()-1; i >= 0; i--) {
		b += a[i];
	}
	return b;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string a;
		cin >> a;
		priority_queue< string, vector<string>, greater<string> >pq;
		for (int i = 1; i < a.size(); i++) {
			string b = a.substr(0, i);
			string c = a.substr(i);
			pq.push(b+c);
			pq.push(reverse(b)+c);
			pq.push(b+reverse(c));
			pq.push(reverse(b)+reverse(c));
			pq.push(c+b);
			pq.push(reverse(c)+b);
			pq.push(c+reverse(b));
			pq.push(reverse(c)+reverse(b));
		}
		int counter = 0;
		while (!pq.empty()) {
			counter++;
			string k = pq.top();
			pq.pop();
			while (!pq.empty()) {
				if (k == pq.top()) {
					pq.pop();
				} else {
					break;
				}
			}
		}
		cout << counter << endl;
	}
	return 0;
}

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

int main() {
  int r,g,b;
  cin >> r >> g >> b;
  if ((r*100 + g*10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3636
def main():
    N, K, *A = map(int, open(0).read().split())
    log_k = 0
    k = K
    while k > 0:
        k >>= 1
        log_k += 1
    # print(log_k)

    # level 1
    work = [A[i] for i in range(N)]

    ans = 1
    for k in range(log_k):
        if (K >> k) & 1 == 1:
            ans = work[ans - 1]
        work = [work[work[i] - 1] for i in range(N)]
    print(ans)

if __name__ == '__main__':
  main()


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

int main() {
   int n;
   string s;
   cin >> n >> s;
   int ct = 0;
   rep(A,10)rep(B,10)rep(C,10) {
      char a = A + '0';
      char b = B + '0';
      char c = C + '0';
      vector<char> x = {a,b,c};
      int f = 0;
      rep(i,n) {
         if (s[i] == x[f]) f++;
         if (f == 3) break;
      }
      if (f == 3) ct++;
   }
   cout << ct << endl;
}

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



int main(){
	int a[14];
	int i=0,n;
	while (scanf("%d",&n)!=EOF){
		if(n==0){
			i--;
			printf("%d\n",a[i]);
		}else{
			a[i]=n;
			i++;
		}
	}

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define LL long long
using namespace std;
inline LL read(){
	LL red=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
	while (ch>='0'&&ch<='9') red=red*10+ch-'0',ch=getchar();
	return red*f;
}
LL n,min_=(LL)1<<45,max_=(LL)-min_,S;
int main(){
	n=read();
	while (n--){
		LL x=read();
		if (x<min_) min_=x;
		if (x>max_) max_=x;
		S+=x;
	}
	cout<<min_<<" "<<max_<<" "<<S<<"\n";
	return 0;
}


Measured memory_bytes: 3112
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans=0
for i in range(n):
    s=0
    a=[]
    a=list(map(int,input().split()))
    for k in range(m):
        s+=a[k]*b[k]
    if s+c>0:
        ans+=1
print(ans)


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

using namespace std;
using ll = long long;

int main() {
    int x = 0;
    cin >> x;
    if(x >=1800){
        cout << 1 << endl;
    }else if(x >=1600){
        cout << 2 << endl;
    }else if(x >=1400){
        cout << 3 << endl;
    }else if(x >=1200){
        cout << 4 << endl;
    }else if(x >=1000){
        cout << 5 << endl;
    }else if(x >=800){
        cout << 6 << endl;
    }else if(x >=600){
        cout << 7 << endl;
    }else if(x >=400){
        cout << 8 << endl; 
    }
    return 0;
}

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

int main()
{
	string S;
	cin >> S;
	int b = 0, r = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '0') b++;
		else r++;
	}
	cout << min(b, r) * 2 << endl;
}

Measured memory_bytes: 512
N, D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]

ans = 0
x = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(D):
      x += abs(X[i][k] - X[j][k])**2
    x = x**0.5
    if x == int(x):
      ans += 1
    x = 0
print(ans)

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

int main() {
  string S;
  long long K;
  cin >> S >> K;

  int cnt = 0;

  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '1') cnt++;
    else break;
  }

  if (K <= cnt) {
    cout << "1" << "\n";
    return 0;
  }

  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != '1') {
      cout << S.at(i) << "\n";
      return 0;
    }
  }
}

Measured memory_bytes: 256
#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;}
typedef long long ll;
int bsr(int x) { return 31 - __builtin_clz(x); }
using D = double;
const D pi = acos(-1);
using Pc = complex<D>;

void fft(bool type, vector<Pc> &c){	//multiply : false -> mult -> true
	static vector<Pc> buf[30];
	int N = c.size();
	int s = bsr(N);
	assert(1<<s == N);
	if(buf[s].empty()){
		buf[s]=vector<Pc>(N);
		rep(i,N) buf[s][i] = polar<D>(1,i*2*pi/N);
	}
	vector<Pc> a(N),b(N);
	copy(begin(c),end(c),begin(a));
	rep1(i,s){
		int W = 1<<(s-i);
		for(int y=0;y<N/2;y+=W){
			Pc now = buf[s][y];
			if(type) now = conj(now);
			rep(x,W){
				auto l =       a[y<<1 | x];
				auto r = now * a[y<<1 | x | W];
				b[y | x]        = l+r;
				b[y | x | N>>1] = l-r;
			}
		}
		swap(a,b);
	}
	copy(begin(a),end(a),begin(c));
}

template<class D>
vector<D> multiply_fft(const vector<D>& x,const vector<D>& y){
	int S = x.size()+y.size()-1;
	int N = 2<<bsr(S-1);
	vector<Pc> a(N),b(N);
	rep(i,x.size()) a[i] = Pc( x[i] , 0 );
	rep(i,y.size()) b[i] = Pc( y[i] , 0 );
	fft(false,a);
	fft(false,b);

	vector<D> z(S);
	vector<Pc> c(N);
	rep(i,N) c[i] = a[i]*b[i];
	fft(true,c);
	rep(i,S){
		c[i] *= 1.0/N;
		z[i] = c[i].real();
	}
	return z;
}



ll N;
ll dp[100010];
ll inf = 1e18;
int main(){
	cin>>N;
	set<ll> cand;
	ll p=1;
	rep(tt,N){
		cand.insert(p);
		p = p*10%N;
	}
//	show(cand.size());
	vector<D> f(N);
	for(int x: cand){
		f[x] = 1;
	}
	vector<D> f2(N);
	{
		vector<D> h = multiply_fft(f,f);
		rep(i,h.size()) if(h[i]>0.5) f2[i%N] = 1;
		for(int x:cand) f2[x] = 200000;
	}
	vector<D> g = f2;
//	show(f);
//	show(g);
	for(int t=1;;t++){
		if(g[0] > 200000 - 1){
			cout<<t*2-1<<endl;
			return 0;
		}
		if(g[0] > 0.5){
			cout<<t*2<<endl;
			return 0;
		}

		vector<D> h = multiply_fft(g,f2);
		rep(i,g.size()) g[i] = 0;
		rep(i,h.size()){
			if(h[i] > 0.5) g[i%N] = 1;
		}
		if(h[0] > 200000 - 1 || h[N] > 200000 - 1){
			cout<<t*2+1<<endl;
			return 0;
		}
		if(h[0] > 0.5 || h[N] > 0.5){
			cout<<t*2+2<<endl;
			return 0;
		}
	}

}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  int num = 1;
  
  for(int i = 0; i < N; i++){
    if(num + K > num * 2){
      num *=2;
    }else{
      num +=K;
    }
  }
  cout << num << endl;
  
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[]
l=[]
for i in range(n):     
      A=int(input())
      L=[list(map(int,input().split())) for _ in range(A)]
      a.append(A)
      l.append(L)
ans=0
for i in range(2**n):
      b=[0]*n
      for j in range(n):
            if (i>>j)&1:
                  b[j]=1
      for k in range(n):
            for h in range(a[k]):
                  hito=l[k][h][0]-1
                  singi=l[k][h][1]
                  if b[k]==1 and b[hito]!=singi:
                        break      
            else:
                  continue
            break
      else:
            ans=max(ans,sum(b))

print(ans)
                  


Measured memory_bytes: 9212
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N,M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    G[x].append(y)
#G[i]は頂点iから辺でつながっている頂点のlist
def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)
    
    for i in range(len(g)):
        if i not in visited:
            dfs(i)
        
    return topological_list[::-1]

T = topological_sort(G)
dist = [0]*N
for n in T:
    for v in G[n]:
        dist[v] = max(dist[v],dist[n]+1)       
        
print(max(dist))

Measured memory_bytes: 131412
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using LL = long long;

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

    LL A, B;
    vector<pair<int, int>> AB;

    for (int i = 0; i < N; i++) {
        cin >> A >> B;
        AB.emplace_back(B, A);
    }

    sort(AB.begin(), AB.end());

    string ans = "Yes";
    LL t = 0;

    for (auto ab : AB) {
        t += ab.second;
        if (t > ab.first) {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2420
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: i,n,dd
    integer(int32), allocatable:: d(:,:)

    read*, n
    allocate(d(2,n))
    do i=1,n
        read*, d(:,i)
    end do

    do i=3,n
        if (f(d(:,i-2)) .and. f(d(:,i-1)) .and. f(d(:,i))) then
            print'(a)', "Yes"
            stop
        end if
    end do
    print'(a)', "No"
contains
    function f(a) result(ret)
        integer(int32):: a(2)
        logical:: ret
        ret = a(1) == a(2)
    end function
end program main

Measured memory_bytes: 2932
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long LL;

int main()
{
    LL n , m , sum = 0;
    scanf("%lld %lld",&n , &m);
    if(2 * n <= m){
        sum += n;
        m -= (2 * n);
        sum +=(m/4);
    }
    else{
        sum = (m/2);
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 128