akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,D;
    cin>>n>>D;
    vi d(n),a(n),b(n+1),ans(n);
    for(int i=0;i<n;i++) cin>>d[i];
    for(int i=0;i<n;i++)
    {
        a[i]=D;
        D=min(D,abs(D-d[i]));
    }
    ll cur=1;
    for(int i=n-1;i>=0;i--)
    {
        ans[i]=(cur<=a[i]);
        if(cur>d[i]/2)
            cur+=d[i];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int tt;
        cin>>tt;
        cout<<(ans[tt-1]?"YES":"NO")<<'\n';
    }

}

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

using namespace std;

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

vector<int> l(n);

for (int i = 0; i < n; i++)
{
    cin >> l[i];
}

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

int min,max,lf,ri,mid,lans,hans,cnt=0;
for (int i = 0; i < n-1; ++i)
{
   for (int j = i+1; j < n; ++j)
   {  
       
       lf=j;ri=n;
       max = l[i]+l[j];
      
       while(lf+1<ri){
        mid = (lf+ri)/2;
        if (l[mid]<max) {lf=mid;}
        else ri=mid;      
       }
       hans = lf;
       cnt+=hans-j;
       
   }
}

cout << cnt;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n;
		n=sc.nextInt();
		int i,x;
		for(i=1;i<=n;i++){
			x=i;
			if(x%3==0){
				System.out.printf(" %d", i);
			}else{
			while(true){
				if(x%10==3){
					System.out.printf(" %d", i);
					break;
				}
				x/=10;
				if(x<3){
					break;
				}
			}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 40108
m={}
def bits(n):
    if n in m:
        return m[n]
    elif n==0:
        m[n]=1
        return 1
    else:
        m[n]=((1+bits(n-1))*2+1)
        return m[n]
c={}
def pat(n):
    if n in c:
        return c[n]
    elif n==0:
        c[n]=1
        return c[n]
    else:
        c[n]=1+pat(n-1)*2
        return c[n]

def func(n, x):
    if n==0:
        return 1
    if x <=1:
        return 0
    elif x-1 <= bits(n-1):
        return func(n-1, x-1)
    elif x-1-bits(n-1)<=1:
        return pat(n-1)+1
    else:
        return pat(n-1)+1+func(n-1, x-1-bits(n-1)-1)

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

#print (func(n, x))
print(func(n, x))


Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt() {return Integer.parseInt(s.next());}
	static long gLong() {return Long.parseLong(s.next());}

	public static void main(String[]$){
		long r=0,x=gLong(),y=gLong();
		for(;x<=y;x*=2)
			++r;
		System.out.println(r);
	}
}

Measured memory_bytes: 23124
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mod 1000000007
#define inf 1e18
#define setbits(x) __builtin_popcount(x)
#define zrbits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define fi(i,n) for(int i = 0;i < n;i++)
#define fd(i,n) for(int i = n;i >= 0;i--)
int dif(int a,int b){if(a > b)return a - b;else return b - a;}
int gcd(int a, int b){if(b == 0)return a;return gcd(b, a%b);}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int h[n];
    fi(i,n)cin>>h[i];
    int ans[n];
    ans[0] = 0;
    ans[1] = dif(h[0],h[1]);
    for(int i = 2;i < n;i++)
    {
    	ans[i] = min((ans[i - 1] + dif(h[i],h[i - 1])),(ans[i - 2] + dif(h[i],h[i - 2])));
    }
    cout<<ans[n - 1];
	return 0;
}


Measured memory_bytes: 5168
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll cnt1=0,cnt2=0,cnt3=0;
    rep(i,n){
        ll p;
        cin >> p;
        if(p<=a) cnt1++;
        if(a+1<=p && p<=b) cnt2++;
        if(b+1<=p) cnt3++;
    }
    cout << min({cnt1,cnt2,cnt3}) << endl;
    return 0;
}

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

int main() {
    int n;
    ll l;
    cin >> n >> l;
    VL a(n);
    REP(i,n) scanf("%lld", &a[i]);

    int x = -1;
    REP(i,n-1){
        if (a[i]+a[i+1] >= l){
            x = i;
            break;
        }
    }

    if (x == -1){
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    REP(i,x) printf("%d\n", i+1);
    FORR(i,n-1,x+1) printf("%d\n", i);

}


Measured memory_bytes: 1536
import numpy as np

ss = [0] + np.fromiter(map(lambda c: 1 if c == 'A' else 2, input()), dtype=int).cumsum().tolist()
ts = [0] + np.fromiter(map(lambda c: 1 if c == 'A' else 2, input()), dtype=int).cumsum().tolist()
q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    print('YES' if (ss[b] - ss[a - 1]) % 3 == (ts[d] - ts[c - 1]) % 3 else 'NO')


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

ll multi(ll d, int b, int t){
    ll ans = b;
    ll base = b;
    // cout << "ans" << ans << b << t << endl;
    for(int j=1;j<t;j++){
        ans = (ans * base) % d;
    }
    return ans;
}

int main() {
    vector<int> A(1100000, 0);
    int N, number;
    cin >> N;
    int max_number = 0;
    ll D = 998244353;
    int first;
    for (int i=0;i<N;i++){
        cin >> number;
        if(i==0){
            first = number;
        }
        A.at(number)++;
        if(number > max_number){
            max_number = number;
        }
    }
    if(A.at(0)!=1 || first!=0){
        cout << 0;
        return 0;
    }
    if(A.at(1)==0){
        if(max_number==0){
            cout << 1;
        }else{
            cout << 0;
        }
        return 0;
    }
    ll count = 1;
    for(int i=2;i<max_number+2;i++){
        if(A.at(i)==0){
            if(i > max_number){
                cout << count;
            }else{
                cout << 0;
            }
            return 0;
        }
        count = (multi(D, A.at(i-1), A.at(i)) * count) % D;
    }
    
}


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

const string YES = "Yes";
const string NO = "No";

void solve(std::string w){
    map<char, ll> ans;
    ll n = w.length();
    for(ll i=0; i< n; i++){
        if(!ans.count(w.at(i)))    
            ans[w[i]]=1;
        else 
            ans.at(w[i])++;
    }
    map<char, ll>::iterator it;
    for(it = ans.begin(); it != ans.end(); it++){
        if('a'<=it->first && it->second <='z' && it->second%2) {
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
    return;
}

int main(){
    std::string w;
    std::cin >> w;
    solve(w);
    return 0;
}


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

int main(){
  int N; cin >> N;
  long long l[100];
  l[0]=2;
  l[1]=1;
  if(N>1){
    for(int i=2; i<=N; i++){
      l[i]=l[i-1]+l[i-2];
    }
  }
  cout << l[N] << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	static char[] k = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int L = 0;
		int R = 0;
		for(int i = 0; i < n; i++) {
			String s1 = stdIn.next();
			String s2 = stdIn.next();
			
			if(s1.compareTo(s2) == 0) {
				L++;
				R++;
			}
			else if(s1.compareTo(s2) < 0) {
				L += 3;
			}
			else {
				R += 3;
			}
		}
		
		System.out.println(R + " " + L);
	}
}

Measured memory_bytes: 20800
s=input()
k=int(input())
t=""
if k==1:
  print(s[0])
else:
  for i in s:
    if int(i)==1:
      t+=i
    else:
      t+=i
      break
  if k>len(t):
    print(t[-1])
  else:
    print(t[k-1])
  

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (auto&& e : h) {
    cin >> e;
  }
  vector<bool> ok(n, true);
  while (m--) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (h[a] <= h[b]) {
      ok[a] = false;
    }
    if (h[b] <= h[a]) {
      ok[b] = false;
    }
  }
  cout << count(begin(ok), end(ok), true) << '\n';
}


Measured memory_bytes: 3732
from collections import Counter

N = int(input())
A = set(list(map(int, input().split())))

# カードは1 or 2枚まで減らせる
# Nは奇数なので，1枚のカードは奇数種
# 全体で奇数種のとき，2枚のカードは偶数種
# 偶数種のとき，奇数種
# 2枚のカードはペアで1枚ずつにできる

ans = len(A) - (0 if len(A) % 2 == 1 else 1)
print(ans)


Measured memory_bytes: 14948
n, = [int(x) for x in input().split(" ")]
dx = [set() for x in range(10**5+1)]
dy = [set() for x in range(10**5+1)]

class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1
        self.x_num = 0

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                unite_root.parent_ = root
                root.rank_ = max(root.rank_, unite_root.rank_ + 1)
                root.member_num_ = root.member_num_ + unite_root.member_num_
                root.x_num = max(root.x_num, unite_root.x_num)
            else:
                root.parent_ = unite_root
                unite_root.rank_ = max(root.rank_ + 1, unite_root.rank_)
                unite_root.member_num_ = root.member_num_ + unite_root.member_num_
                unite_root.x_num = max(root.x_num, unite_root.x_num)

for i in range(n):
    x, y = [int(x) for x in input().split(" ")]
    dx[x].add(y)
    dy[y].add(x)

node_list = [UnionFindNode(i) for i in range(len(dy))]

for xi, dxx in enumerate(dx):
    b = None
    for y in dxx:
        if b == None:
            b = y
            continue
        node_list[y].unite(node_list[b])
        b = y

r = 0
for xi, dxx in enumerate(dx):
    if len(dxx) == 0:
        continue
    r += node_list[dxx.pop()].root().member_num_ 

print(r-n)


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

using namespace std;

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

uint64_t mpow(uint64_t x, uint64_t p, uint64_t m){
  uint64_t r = 1;
  while(p > 0){
    if(p&1) (r *= x) %= m;
    (x *= x) %= m;
    p >>= 1;
  }
  return r;
}

int main(){
  constexpr uint64_t mod = 998244353;
  int n, m, k;
  cin >> n >> m >> k;
  if(m == 1){
    cout << (n <= k + 1 ? 1 : 0) << endl;
    return 0;
  }
  uint64_t mi = mpow(m - 1, mod - 2, mod);
  uint64_t r = 0;
  uint64_t p = mpow(m - 1, n - 1, mod);
  REP(i, k + 1){
    r += p;
    (p *= n - 1 - i) %= mod;
    (p *= mpow(i + 1, mod - 2, mod)) %= mod;
    (p *= mi) %= mod;
  }
  ((r %= mod) *= m) %= mod;
  cout << r << endl;
  return 0;
}


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

int main(){

  int a,b,c;
  cin >> a >> b	>> c;

  if(a==b&&b==c){
    cout << 1 << endl;
  }else	if(a==b||b==c||a==c){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }


}


Measured memory_bytes: 256
#include <iostream> 

using namespace std;



int main() {

    string s;
    cin >> s;

    string res = s;

    for (int i = res.size()-1; i >= 0; i--){
        s.pop_back();

        if (s.size() % 2 == 0){
            string t1 = s.substr(0, s.size() / 2);
            string t2 = s.substr(s.size() / 2, s.size());

            // cout << " t1 : " << t1 << ", t2 : " << t2 << endl;

            if (t1 == t2){
                cout << s.size() << endl;
                return 0;
            }
        }
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;	

ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin >> n >> k;
	if (k == 0){
		cout << (n-1)*(n)/2 << endl;
		for (int z=0;z<n;z++){
			for (int x=z+1;x<n;x++){
				cout << z+1 << " " << x+1 << endl;
			}
		}
		return 0;
	}
	if (k > ((n-1)*(n-2)/2)){
		cout << -1 << endl;
		return 0;
	}
	ll c = ((n-1)*(n-2))/2;
	vector <pair<ll,ll>> graph;
	for (int z=1;z<n;z++){
		graph.push_back(make_pair(1,z+1));
	}
	ll l = 1;
	ll r = 2;
	ll add = 0;
	ll temp = 2;
	while (c != k){
		if (l == n) {
			temp = 2;
			add++;
			l = 1; r = 2;
		}
		if (r+add >= n) {
			graph.push_back(make_pair(l+1,temp));
			temp++;
		}
		else graph.push_back(make_pair(l+1,r+1+add));
		l++;r++;
		c--;
	}
	cout << graph.size() << endl;
	for (int z=0;z<graph.size();z++){
		cout << graph[z].first << " " <<graph[z].second << endl;
	}
	cin >> n;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    char n;
    cin>>n;
	int a=n-'a';
    if(a>=0&&a<=25)cout<<'a';
  	else cout<<'A';
	return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#define SENTINEL (1000000001)
#define putChar(c) ; *p = (c); ++p;

int c = 0;
int S[500000];
int L[250001];
int R[250001];
char str[5500010];
char *p = str;

static void Merge(int A[], int left, int mid, int right);
static void MergeSort(int A[], int left, int right);
static int getNum(void);
static void putNum(int n);

int main(void) {
	register int i;
	int n;
	
	fread(str, sizeof(char), 5500000, stdin);
	n = getNum();
	for (i = 0; i < n; ++i) {
		S[i] = getNum();
	}
	
	MergeSort(S, 0, n);
	
	--n;
	p = str;
	for (i = 0; i < n; ++i) {
		putNum(S[i]);
		putChar( ' ' );
	}
	putNum(S[i]);
	putChar( '\n' );
	
	putNum(c);
	putChar( '\0' );
	
	puts(str);

	return 0;
}

int getNum(void) {
	int n = 0;
	while ((*p >= '0') && (*p <= '9')) {
		n = n * 10 + (int)(*p - '0');
		++p;
	} 
	++p;
	return n;
}

void putNum(int n) {
	int d = n / 10;
	if (n < 10) {
		putChar( '0' + (char)n );
		return;
	}
	if (d) putNum(d);
	putChar( '0' + (char)(n % 10) );
}

void Merge(int A[], int left, int mid, int right) {
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	memcpy(L, A + left, n1 * sizeof(int));
	memcpy(R, A + mid, n2 * sizeof(int));
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for (k = left; k < right; ++k) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			++i;
		} else {
			A[k] = R[j];
			++j;
		}
	}
	c += k - left;
}

void MergeSort(int A[], int left, int right) {
	int mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		MergeSort(A, left, mid);
		MergeSort(A, mid, right);
		Merge(A, left, mid, right);
	}
}

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

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(new Program().Run() ? "Yes" : "No");
    }

    bool Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int pt = 0;
        int px = 0;
        int py = 0;
        for (int i = 0; i < n; i++)
        {
            int t = sc.NextInt();
            int x = sc.NextInt();
            int y = sc.NextInt();
            if (Math.Abs(x - px) + Math.Abs(y - py) > t - pt) return false;
            if (((t - pt) - (Math.Abs(x - px) + Math.Abs(y - py))) % 2 == 1) return false;
            pt = t;
            px = x;
            py = y;
        }
        return true;
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}



Measured memory_bytes: 15160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

const int INF=1e8;

int minlen(vector<P> A,vector<P> B){
    int res=1e8;
    for(P p:B){
        int a=lower_bound(A.begin(),A.end(),p)-A.begin();
        if(a==A.size())continue;
        if(A.at(a).first!=p.first)continue;
        chmin(res,A.at(a).second-p.second);
    }
    return res;
}

int main() {
    int N;
    cin>>N;
    vector<int> X(N),Y(N),U(N);
    rep(i,N){
        char c;
        cin>>X.at(i)>>Y.at(i)>>c;
        if(c=='U')U.at(i)=0;
        if(c=='R')U.at(i)=1;
        if(c=='D')U.at(i)=2;
        if(c=='L')U.at(i)=3;
    }
    int ans=INF;
    rep(_,4){
        vector<P> UDD(0),DRD(0),UP(0),RI(0);
        rep(i,N){
            if(U.at(i)==2){
                UDD.pb({X.at(i),Y.at(i)});
                DRD.pb({X.at(i)-Y.at(i),Y.at(i)});
            }
            if(U.at(i)==0){
                UP.pb({X.at(i),Y.at(i)});
            }
            if(U.at(i)==1){
                RI.pb({X.at(i)-Y.at(i),Y.at(i)});
            }
        }
        sort(UDD.begin(),UDD.end());
        sort(DRD.begin(),DRD.end());
        chmin(ans,minlen(UDD,UP)*5);
        chmin(ans,minlen(DRD,RI)*10);

        rep(i,N){
            int x=X.at(i),y=Y.at(i);
            X.at(i)=y;
            Y.at(i)=-x;
            U.at(i)=(U.at(i)+1)%4;
        }
    }
    if(ans==INF)cout<<"SAFE"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 10300
import java.util.Scanner;

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

        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int c = Integer.parseInt(scanner.next());
        int d = Integer.parseInt(scanner.next());
        int sum = 0;
        if (a <= b) {
            sum += a;
        } else {
            sum += b;
        }

        if (c <= d) {
            sum += c;
        } else {
            sum += d;
        }
        System.out.println(sum);
    }
}


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

int main(){
int a,b,c,d,e;
cin >> a >> b >> c >> d >> e;
int M = 0;
int A = 0;
while (A < a){
  A += 10;
}
M = max(M,A-a);
int B = 0;
while (B < b){
  B += 10;
}
M = max(M,B-b);
int C = 0;
while (C < c){
  C += 10;
}
M = max(M,C-c);
int D = 0;
while (D < d){
  D += 10;
}
M = max(M,D-d);
int E = 0;
while (E < e){
  E += 10;
}
M = max(M,E-e);
cout << A+B+C+D+E-M << endl;
}

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

const int Max = 20;
int n, n2;
int A[Max];

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

int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &n2);
    for(int j=0; j<n2; j++){
        int m;
        scanf("%d", &m);
        bool ans = solve(0, m);
        if (ans) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int main()

{


    ll x,y,nr,ng,nc;
    cin>>x>>y>>nr>>ng>>nc;

    ll R[nr],G[ng],C[nc];



    for(int i=0;i<nr;i++)
    {
        cin>>R[i];
    }
       for(int i=0;i<ng;i++)
    {
         cin>>G[i];
    }
       for(int i=0;i<nc;i++)
    {
        cin>>C[i];
    }

    sort(R,R+nr);
    sort(G,G+ng);
    sort(C,C+nc);

    vector<ll> v;

    ll sum = 0;

    for(int i=nr-1,k=0;k<x;i--,k++)
    {
        v.push_back(R[i]);
        sum+=R[i];
    }

     for(int i=ng-1,k=0;k<y;i--,k++)
    {
        v.push_back(G[i]);
        sum+=G[i];
    }

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

    for(int i=0,j=nc-1,k=0;i<nc;i++,j--,k++)
    {
        if(C[j]>v[i])
        {
            sum-=v[i];
            sum+=C[j];
        }
        else
            break;
    }
    cout<<sum<<endl;









    return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  double pi = 3.141592;
  int n; cin >> n;
  printf("%.4f\n", 2.0*n*pi);

  return 0;
}

Measured memory_bytes: 3764
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

under = 0
over = []
cnt = 0

for i in range(N):
    if B[i] > A[i]:
        under += B[i] - A[i]
        cnt += 1
    elif B[i] < A[i]:
        over.append(A[i] - B[i])

over.sort(reverse=True)


# print("u", under)
# print("o", over)

for s in over:
    if under <= 0:
        break
    under -= s
    cnt += 1

if under <= 0:
    print(cnt)
else:
    print(-1)


Measured memory_bytes: 18356
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{

    ll N;
    cin >> N;
    if(N%2==1) out(0);
    else{
        ll a = 0;
        ll b = 5;
        while (b <= N) {
            a += N/b/2;
            b *= 5;
        }
        out(a);
    }


    return 0;
}


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

using P = pair<long long, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> a(n);
    for (int i = 0; i < n; i++) {
        int t, d;
        cin >> t >> d;
        a.at(t - 1).push_back(d);
    }
    for (int i = 0; i < n; i++) {
        sort(a.at(i).rbegin(), a.at(i).rend());
    }

    vector<long long> top_d, other;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < (int)a.at(i).size(); j++) {
            if (j == 0) top_d.push_back(a.at(i).at(j));
            else other.push_back(a.at(i).at(j));
        }
    }

    sort(top_d.rbegin(), top_d.rend());
    sort(other.rbegin(), other.rend());

    long long sum = 0;
    int r1 = min(k, (int)other.size()), r2 = k - r1;
    for (int i = 0; i < r1; i++) {
        sum += other.at(i);
    }
    for (int i = 0; i < r2; i++) {
        sum += top_d.at(i);
    }
    
    long long ans = sum + (long long)r2 * r2;

    for (int i = 0; i < k; i++) {
        r1--;
        if (r1 < 0 || (int)top_d.size() <= r2) break;
        
        sum -= other.at(r1);
        sum += top_d.at(r2);
        r2++;
        ans = max(ans, sum + (long long)r2 * r2);
    }
    cout << ans << endl;
}  

Measured memory_bytes: 6904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;
    int sum = 0;
    vec<int> v;
    bool one = false;
    for(int i=0;i<N;i++){
        int n = S[i]-'0';
        int add = n;
        bool even = (N-1==(i | (N-i-1)));
        sum += add*even;
        sum %= 2;
        if(i!=N-1){
            int m = S[i+1]-'0';
            one |= abs(n-m)==1;
            v.push_back(abs(n-m));
        }
    }
    if(one) cout << sum%2 << "\n";
    else{
        sum = 0;
        for(int i=0;i<N-1;i++){
            int n = (v[i]==2? 1:0);
            int add = n;
            bool even = (N-2==(i| (N-i-2)));
            sum += add*even;
            sum %= 2;
        }
        cout << (sum%2? 2:0) << "\n";
    }
}

Measured memory_bytes: 8344
fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    let n: i32  = n.trim().parse().unwrap();
    
    if n % 2 == 0 {
        println!("{}", n);
    } else {
        println!("{}", n * 2);
    }
}



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

const int MAX_N = 5000 + 7;

int n;
int A[MAX_N];
int B[MAX_N];
int lmax[MAX_N][MAX_N], rmin[MAX_N][MAX_N];
ll l, r;
ll dp[MAX_N][MAX_N];


int main() {
    scanf("%d%lld%lld", &n, &r, &l);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
        B[A[i]] = i;
    }
    
    for (int k = 1; k <= n; k++) {
        int cnt = 0;
        for (int t = 1; t < k; t++) {
            if (A[t] > A[k])
                cnt++;
            lmax[t][A[k]] = cnt;
        }
    }
    
    for (int k = n; k >= 0; k--)
        for (int i = n; i >= 1; i--) {
            if (k == n || i == n)
                dp[k][i] = 0;
            else if (B[i] <= k) {
                dp[k][i] = dp[k][i + 1];
            }
            else {
                dp[k][i] = min(l + dp[k][i + 1], r * (lmax[B[i] - 1][i] - lmax[k][i]) + dp[B[i] - 1][i + 1]);
            }
        }

    /*for (int i = 1; i <= n; i++)
        printf("%d ", lmin[i]);
    printf("\n");
    for (int i = 1; i <= n; i++)
        printf("%d ", rmax[i]);
    printf("\n");*/

    /*for (int i = 0; i <= n; i++)
        dp[i][n - i] = 0;
    for (int sum = n - 1; sum >= 0; sum--)
        for (int i = 0; i <= sum; i++) {
            int j = sum - i;
            dp[i][j] = l + dp[i + 1][j];
            if (lmin[i + 1] >= n - j + 1)
                dp[i][j] = min(dp[i][j], dp[i + 1][j]);
            dp[i][j] = min(dp[i][j], r + dp[i][j + 1]);
            if (rmax[n - j] <= i)
                dp[i][j] = min(dp[i][j], dp[i][j + 1]);
            //printf("!!!!!%d %d: %lld\n", i, j, dp[i][j]);
        }*/
    printf("%lld\n", dp[0][1]);
}


Measured memory_bytes: 295552
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;
int main()
{
   int T;
   cin>>T;
   string s;
  cin>>s;
   int flag=0;
   if(T%2!=0)
    printf("No\n");
   else
   {
       for(int i=0;i<T/2;i++)
       {
           if(s[i]!=s[i+T/2])
           {
               flag=1;
               break;
           }

       }
       if(flag==0)
        printf("Yes\n");
       else
        printf("No\n");
   }


}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc071/tasks/arc081_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll N, A, l, c, p, hw[2] = {0, 0};
vector<ll> s;

int main()
{
  l = c = p = 0;

  cin >> N;
  REP(i, N)
  {
    cin >> A;
    s.push_back(A);
  }

  sort(ALL(s));
  reverse(ALL(s));

  for (auto &i : s)
  {
    if (l == i)
      c++;
    else
    {
      l = i;
      c = 1;
    }

    if (c == 2)
    {
      hw[p] = i;
      if (p == 1)
        break;
      p++;
      c = 0;
    }
  }

  cout << hw[0] * hw[1] << '\n';

  return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int A = std.nextInt();
        int B = std.nextInt();
        int C = std.nextInt();

        int count = Math.min(B / A, C);
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args){
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt() - 1;

        int[] move = new int[n];
        Arrays.fill(move, -1);

        List<Long> list = new ArrayList<>();

        int cle = 1;
        int b = 0;
        int v = 0;
        while (move[v] == -1) {
            move[v] = list.size();
            list.add((long)v);
            v = arr[v];
        }

        cle = list.size() - move[v];
        b = move[v];

//        System.out.println(cle);
//        System.out.println(b);
//        System.out.println(list);

        if (k < b) {
            System.out.println(list.get((int)k) + 1);
        } else {
            long rem = (k - b) % cle;
//            System.out.println((int)(b + rem));
            System.out.println(list.get((int)(b + rem)) + 1);
        }


    }


}


Measured memory_bytes: 60652
// Harmony

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>

using namespace std;

int main()
{
    long long A,B,C;
    cin >> A >> B >> C;
    long long tmp = C - (A - B);
    cout << (tmp >= 0? tmp : 0) << endl;

    return 0;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll A, V; cin >> A >> V;
    ll B, W; cin >> B >> W;
    ll T; cin >> T;
    ll dist = abs(A-B);
    string ans = "NO";
    if (dist <= T * (V - W)) ans = "YES";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
N = int(input())
s = list(input())
s = s * 2
q = [[True,True],[True,False],[False,True],[False,False]]
p = []
ans = []
for k in range(4):
    p = q[k]
    for i in range(N*2-2):
        if p[i + 1]:
            if s[i + 1] == "o":
                p.append(p[i])
            else:
                p.append(not p[i])
        else:
            if s[i + 1] == "o":
                p.append(not p[i])
            else:
                p.append(p[i])
    if p[0:N-1] == p[N:N*2-1]:
        for i in range(N):
            if p[i]:
                ans.append("S")
            else:
                ans.append("W")
        print("".join(ans))
        break
    if k == 3:
        print(-1)

Measured memory_bytes: 18256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>

using std::cerr;
using std::cin;
using std::cout;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ff first
#define ss second
#define pb emplace_back
#define sqr(x) ((x) * (x))
#ifdef LOCAL
#define dbg(as...) {\
    vector<string> _v; \
    std::stringstream _ss(#as);\
    string _cur, _loc;\
    while (getline(_ss, _cur, ',')) {\
        while (count(_cur.begin(), _cur.end(), '(') != count(_cur.begin(), _cur.end(), ')')) {\
            getline(_ss, _loc, ',');\
            _cur += "," + _loc;\
        }\
    _v.pb(_cur);\
    }\
    err(_v.begin(), as);\
}
#else
#define dbg(as...)
#endif

template<typename T>
void err(vector<string>::iterator it, T a) {
    cerr << it->substr((*it)[0] == ' ') << " = " << a << '\n';
}
template<typename T, typename...Ts>
void err(vector<string>::iterator it, T a, Ts...as) {
    cerr << it->substr((*it)[0] == ' ') << " = " << a << ", ";
    err(++it, as...);
}

struct init {
    init() {
        cin.tie(0);
        std::iostream::sync_with_stdio(0);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(10);
        #ifdef LOCAL
        srand(300); 
        #else
        srand(time(0));
        #endif
    }
    ~init() {
        #ifdef LOCAL
        cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
        #endif
    }
} init;


int main() {
    ll k, n = 50;
    cin >> k;
    vector<ll> a(n);
    iota(a.begin(), a.end(), k / n);
    for (int i = 0; i < k % n; ++i) a[n - i - 1]++;
    cout << "50\n";
    for (ll i : a) cout << i << ' ';
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
  int time;
  int flag;
} Data;

int n,v[200][200];
int q[200],head=0,b=1,tail=1;
Data data[200];

void eq(int x){
  q[tail]=x;
  tail++;
}

int dq(void){
  head++;
  return q[head-1];
}

int main(){
  int i,j,m,t,time=1;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      v[i][j]=0;
      data[i].flag=0;
      data[i].time=-1;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&t,&m);
    for(j=0;j<m;j++){
      scanf("%d",&t);
      v[i][t]=1;
    }
  }

  q[0]=1;
  data[1].time=0;
  data[1].flag=1;

  while(1){
    //printf("b\n");
    for(i=head;i<b;i++){
      t=dq();
      for(j=1;j<=n;j++){
	if(v[t][j]==1 && data[j].flag==0){
	  eq(j);
	  data[j].time=time;
	  data[j].flag=1;
	}
      }
    }
    time++;
    head=b;
    b=tail;
    if(head==b)break;
    //printf("%d %d %d\n",head,b,tail);
  }

  for(i=1;i<=n;i++){
    printf("%d %d\n",i,data[i].time);
  }

  return 0;
}



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

int main(){
    string s,t;
    cin>>s>>t;
    int N;
    N=s.size();
    int i;
    rep(i,N){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            break;
        }else{
            if(i==N-1){
                cout<<"Yes"<<endl;
            }
        }
    }
}

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

using namespace std;

typedef int in;
#define int long long

in main(){
    int n,m,a[100005];
    cin >> n >> m;
    for(int i = 0 ; i < n ; i ++){
        cin >> a[i];
    }
    vector<pair<int,int> > v;
    for(int i = 0 ; i < m ; i ++){
        int x,y;
        cin >> x >> y;
        v.push_back({y,x});
    }
    sort(a,a + n);
    sort(v.rbegin(),v.rend());
    int idx = 0;
    for(int i = 0 ; i < m ; i ++){
        int b = v[i].second,c = v[i].first;
        while(idx < n && b > 0 && a[idx] < c){
            a[idx] = c;
            idx ++;
            b --;
        }
    }
    int ans = 0;
    for(int i = 0 ; i < n ; i ++){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3188
# https://atcoder.jp/contests/apc001/tasks/apc001_c
# oは空席,mは男,fは女
# 奇数ならば必ずoは一つなければおかしい
# N=7のとき→mfmfomf oが奇数個だとoの両隣は必ず違う性別になる

# どの空席を見つけるか？奇数個のある方の空席を見つける
# mfm f omf だったら真ん中がfだったら右側にある
# mof m fmf だったら真ん中がmだったら左側にある
# mom f omo もできるからだめだ...

# 少なくとも1つは空席がある区間を二分探索する
# mfm f mof のように真ん中がfのとき左側はoが無いor 複数ある →右側には必ず一つ以上ある
# mfo m fof

# 二分探索したときに真ん中がfだと右側にoがある十分条件、 mだと左側にoがある十分条件
# ↑mから始まる場合。fから始まる場合は逆

N = int(input())

V = 'Vacant'
F = 'Female'
M = 'Male'
print(0, flush=True)
first = input()
if first == V:
    exit()
# print(N - 1, flush=True)
# right = input()
# if right == input():
#     exit()
left = 0
right = N - 1

# 二分探索
while True:
    mid = (left + right) // 2
    print(mid, flush=True)
    com = input()
    should_same = (mid - left) % 2 == 0  # oがなかったときにfirstと同じであるべきか？
    if should_same:
        cond = first == com
    else:
        cond = first != com

    if com == V:
        exit()
    if not cond:  # cond==Trueは左側は整っている
        # 左側を探索する十分条件
        right = mid - 1
    else:
        # 右側
        first = F if com != F else M
        left = mid + 1


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

lint f(vector<lint> &score, string &t) {
  lint n = t.size();

  // cerr << "t = " << t << endl;
  vector<vector<lint>> dp(n + 1, vector<lint> (4, 0));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= 3; j++) {
      char win;
      if(t[i] == 'r') win = 3;
      else if(t[i] == 's') win = 1;
      else win = 2;

      for(int l = 1; l <= 3; l++) {
        if(l == j) continue;
        lint add = 0;
        if(l == win) add = score[l - 1];
        dp[i + 1][l] = max(dp[i + 1][l], dp[i][j] + add);
      }
    }
  }

  lint ret = 0;
  for(int l = 1; l <= 3; l++) ret = max(ret, dp[n][l]);
  return ret;
}

int main() {
  
  lint n, k; cin >> n >> k;
  vector<lint> score(3);
  for(int i = 0; i < 3; i++) cin >> score[i];
  string t; cin >> t;
  
  lint ans = 0LL;
  for(int i = 0; i < k; i++) {
    string str = "";
    for(int j = i; j < n; j += k) {
      str += t[j];
    }

    ans += f(score, str);
  }

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


Measured memory_bytes: 7424
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
     string S;
     cin >> S;
     set<string> s;
     int n = S.length();
     if (n == 1) cout << 1 << endl;
     if (n == 2) {
       if (S.at(0) == S.at(1)) cout << 1 << endl;
       else cout << 2 << endl;
     }

     else {
       vector<int> dp(n);
       dp.at(0) = 1;
       if (S.at(0) == S.at(1)) dp.at(1) = 1;
       else dp.at(1) = 2;
       if (S.at(0) != S.at(1) && S.at(1) != S.at(2)) dp.at(2) = 3; // aba -> a, b, a
       else dp.at(2) = 2;

       for (int i = 3; i < n; i++) {
         if (S.at(i - 1) == S.at(i)) dp.at(i) = dp.at(i - 3) + 2; // ??aa -> ?, ?a, a or ?, ?, aa
         else dp.at(i) = dp.at(i - 1) + 1; // ?ab -> ?, a, b or ?a, b
       }
       cout << dp.at(n - 1) << endl;
     }
 }


Measured memory_bytes: 1412
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;

typedef long long ll;

int N;
int ans = 0;
int pre_meal;

int main() {
	cin >> N;
	vector <int> A(N + 1);
	vector <int> B(N + 1);
	vector <int> C(N);
	for (int i = 1; i < N + 1; i++) {
		cin >> A[i];
	}
	for (int i = 1; i < N + 1; i++) {
		cin >> B[i];
	}
	for (int i = 1; i < N; i++) {
		cin >> C[i];
	}

	ans += B[A[1]];
	pre_meal = A[1];
	for (int i = 2; i < N + 1; i++) {
		ans += B[A[i]];
		if (A[i] - pre_meal == 1) {
			ans += C[pre_meal];
		}
		pre_meal = A[i];
	}

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

Measured memory_bytes: 256
n , m = map(int, input().split())

sl = [[]] * m

for i in range(m):
  s = [num for num in map(int, input().split())]
  sl[i] = s

  
p = [num for num in map(int, input().split())]
# print(p, sl)

ans = 0
# すべてのスイッチの状態を bit全探索 (各bit 1: on, 0: off)
for i in range(1 << n):
  # print('i: ', i)
  # そのスイッチの状態で各電球が光るか
  for j in range(m):
    s = sl[j]
    ons = 0
    # 光ってる数を数える
    for k in range(1, s[0]+1):
      # bit桁 = スイッチ番号 - 1 なので、現在のスイッチの状態はこの電球の対象か
      if i & (1 << (s[k]-1)):
        ons += 1
    # 1つでも光っていないと break
    if ons % 2 != p[j]:
      break
  else:
    # すべての処理でbreakしない == すべての電球が光っている
    ans += 1


print(ans)

Measured memory_bytes: 40176
import sys
input = sys.stdin.readline
N = int(input())
table = []
dp = [[0]*3 for i in range(N)]

for i in range(N):
    a,b,c = map(int, input().split())
    table.append((a,b,c))

dp[0] = table[0]
for i in range(1,N):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            dp[i][j] = max(dp[i][j],dp[i-1][k]+table[i][j])
print(max(dp[-1]))

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

int N,K,T;
const int B = 512;
int from[200010/B+1], to[200010/B+1];
int val[200010/B*B+B];

void sync(int b){
  if(from[b] == -1) return;
  for(int i = b*B; i < (b+1)*B; ++i){
    if(val[i] == from[b]){
      val[i] = to[b];
    } else {
      val[i] = -2;
    }
  }
  from[b] = -1;
  to[b] = -1;
}

void naive(int l, int r, int x){
  for(int i = l; i < r; ++i){
    val[i] = (val[i] == x-1) ? x : -2;
  }
}

void block(int l, int r, int x){
  //assert(l%B == 0 && r%B == 0);
  l /= B; 
  r /= B;
  while(l < r){
    if(to[l] != -1){
      to[l] = (to[l] == x-1) ? x : -2;
    } else {
      from[l] = x-1;
      to[l] = x;
    }
    ++l;
  }  
}

void exec(int l, int r, int x){
  if(l/B == r/B){
    sync(l/B);
    naive(l,r,x);
  } else {
    if(l%B){
      sync(l/B);
      naive(l, l-l%B+B, x);
      l = l-l%B+B;
    }
    if(r%B){
      sync(r/B);
      naive(r-r%B, r, x);
      r = r-r%B;
    }
    block(l,r,x);
  }
}

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

  cin >> N >> K;
  cin >> T;

  memset(from, -1, sizeof from);
  memset(to, -1, sizeof to);

  while(N%B) ++N;

  for(int it = 0; it < T; ++it){
    int l,r,x;
    cin >> l >> r >> x;
    --l;
    exec(l,r,x);
  }

  for(int i = 0; i < N/B; ++i){
    sync(i);
  }

  cout << count(val, val+N, K) << endl;
}

Measured memory_bytes: 3992
#include <stdio.h>

#define MIN(A, B) ((A) < (B))? (A) : (B)

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

typedef struct {
  int length;
  int dest[501];
} Edge;

int b[501], r[501];
Edge e[501];
int t[501];
int m, n;

int augment(int u, int used[]) {
  int i;
  if (u < 0) {
    return 1;
  }
  for (i = 0; i < e[u].length; i++) {
    int d = e[u].dest[i];
    if (!used[d]) {
      used[d] = 1;
      if (augment(t[d], used)) {
        t[d] = u;
        return 1;
      }
    }
  }
  return 0;
}

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

int main() {
  int i, j;
  int ans;
  while (1) {
    m = NextInt(); n = NextInt();
    if (m + n == 0) {
      break;
    }
    for (i = 0; i < m; i++) {
      e[i].length = 0;
      b[i] = NextInt();
    }
    for (i = 0; i < n; i++) {
      r[i] = NextInt();
      t[i] = -1;
    }
  
    for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        if (gcd(b[i], r[j]) != 1) {
            e[i].dest[e[i].length++] = j;
        }
      }
    }
    ans = 0;
    for (i = 0; i < m; i++) {
      int used[1001] = { 0 };
      if (augment(i, used)) {
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int a;
    string s;

    cin>>a>>s;

    if(a>=3200){
        cout<<s<<endl;
    }
    else{
        cout<<"red"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;cin>>N;
    int C[N-1],S[N],F[N-1];
    for(int i=0;i<N-1;i++){
        cin>>C[i]>>S[i]>>F[i];
    }S[N-1]=0;
    int T[N];int arrive;
    for(int i=0;i<N;i++){
        T[i]=S[i];
        for(int j=i;j<N-1;j++){
            T[i]+=C[j];
            arrive=S[j+1];
            while(j!=N-2){
               if(T[i]<=arrive){
                   T[i]=arrive;
                   break;
               }else{
                   arrive+=F[j+1];
               }
            }
        }cout<<T[i]<<endl;
    }
}

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define eof !cin.eof()
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define ld long double
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s, n) s, s + n
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ii pair <int, int>
#define iii pair <int, ii>
#define vi vector <int>
#define vit vector <int> :: iterator
#define vlt vector <ll> :: iterator
#define vl vector <ll> 
#define vii vector <ii>
#define viii vector <iii>
#define vd vector <double>
#define vull vector <ull>
#define vc vector <char>
#define vs vector <string>
#define vvi vector <vector <int>>
#define vvl vector <vector <ll>>
#define EPS 1e-10
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
#define minof min_element
#define maxof max_element
using namespace std;

const int nax = 1e5 + 5;
vi G[nax];
int n, m, degree[nax], dist[nax];
bool vis[nax];
void dfs(int a) {
	vis[a] = true;
	for (int b : G[a]) {
		dist[b] = max(dist[b], dist[a] + 1);
		degree[b]--;
		if (!degree[b]) {
			dfs(b);
		}
	}
}
int main () {
	IOS;
	
	scanf("%d%d", &n, &m);
	while (m--) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v);
		degree[v]++;
	}
	for (int i = 1; i <= n; i++) {
		if (!(vis[i] || degree[i])) {
			dfs(i);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dist[i]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 9728