akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll res1 = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    ll res2 = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans += res2 * res1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.*;
import java.io.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String t = sc.next();

    sc.close();

    String[] S = s.split("");
    String[] T = t.split("");

    Arrays.sort(S);
    Arrays.sort(T, Comparator.reverseOrder());

    String s_ = "";
    String t_ = "";

    for (int i = 0; i < S.length; i++) {
      s_ += S[i];
    }

    for (int i = 0; i < T.length; i++) {
      t_ += T[i];
    }

    int c = s_.compareTo(t_);

    if (c < 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++) 
#define S(v) sort(v.begin(),v.end());

const ll mod = 1E9+7;

int main()
{
   ll n;
   cin>>n;
   
   cout<<(1000-n%1000)%1000;
   // cout<<1900%1000;
}

Measured memory_bytes: 3592
import math
import numpy as np
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
def prime_factor(n):
    ass = {}
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            if i not in ass:
                ass[i]=1
            else:
                ass[i]+=1
            n = n//i
    if n != 1:
        if n not in ass:
            ass[n]=1
        else:
            ass[n]+=1
    return ass
N=int(input())
if N==1:
    print(0)
    exit()
if is_prime(N):
    print(1)
    exit()
primelist=prime_factor(N)
num_list=[]
ans=0
for i,j in primelist.items():
    for k in range(1,j+1):
        num_list.append(i**k)
for i in num_list:
    if N%i==0:
        ans+=1
        N/=i
print(ans)



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

using namespace std;

int main() {
    vector<int> v(3);
    for (int i = 0; i < 3; ++i)
        cin >> v[i];

    sort(v.begin(), v.end());
    cout << v[0] + v[1] << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
	string k="abcdefghijklmnopqrstuvwxyza";
	string s;
	int n;
	cin>>s>>n;
	for(int i=0;i<s.length();i++)
	{
		if(static_cast<int>(s[i]-'a')==0)continue;
		else if(26-static_cast<int>(s[i]-'a')<=n)
		{
			n-=26-static_cast<int>(s[i]-'a');
			s.replace(i,1,"a");
		}
	}
	n%=26;
	if(n)
	{
		for(int i=s.length()-1;i>=0;i--)
		{
			int p=static_cast<int>(s[i]-'a');
			if(n>=25)
			{
				s.replace(i,1,"z");
				n-=25-p;
			}
			else
			{
				s.replace(i,1,k.substr(p+min(25-p,n),1));
				int q=min(25-p,n);
				n-=q;
			}
			if(n==0)
			{
				cout<<s<<endl;
				return 0;
			}
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 998244353;
const ld PI = acos((long double)(-1));

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define INF 1e+9
#define EPS 0.00000001

const int kame = 4;
const int turu = 2;

int main() {
    int x, y;
    cin >> x >> y;

    bool flag = false;

    for(int i = 0; i < x + 1; ++i){
        int a = i * kame;
        int b = (x - i) * turu;
        if((a + b) == y){
            flag = true;
        }
    }

    if(flag){
        println(Yes);
    }else{
        println(No);
    }
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int h,n;
    while (cin >> h >> n) {
        VI dp(10*h,inf);
        dp[0] = 0;
        FOR(i,0,n) {
            int w,v; cin >> w >> v;
            FOR(j,0,dp.size()) if (j-w >= 0)
                dp[j] = min(dp[j], dp[j-w]+v);
        }
        int ans = inf;
        FOR(i,h,dp.size())
            ans = min(ans, dp[i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

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

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
typedef long long Long;
typedef long double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

const int N = 1e6 + 5;

bool vis[N];

void mark(int x) {
  if (vis[x]) return;
  for (int i = x; i < N; i += x) {
    vis[i] = true;
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n;
  cin >> n;

  vector<int> a(n);
  cin >> a;

  sort(all(a));
  int res = 0;
  for (int i = 0; i < n; ++i) {
    if (i + 1 != n && a[i] == a[i + 1]) mark(a[i]);
    if (vis[a[i]]) continue;
    ++res;
    mark(a[i]);
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 5032
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys, math, random, operator
from string import ascii_lowercase, ascii_uppercase
from fractions import Fraction, gcd
#from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from Queue import Queue, PriorityQueue
from collections import deque, defaultdict, Counter
#getcontext().prec = 100

MOD = 10**9 + 7
INF = float("+inf")

if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
    sys.stdin = io.BytesIO(sys.stdin.read())
    raw_input = lambda: sys.stdin.readline().rstrip()
pr = lambda *args: sys.stdout.write(" ".join(str(x) for x in args) + "\n")
epr = lambda *args: sys.stderr.write(" ".join(str(x) for x in args) + "\n")
die = lambda *args: pr(*args) ^ exit(0)

read_str = raw_input
read_strs = lambda: raw_input().split()
read_int = lambda: int(raw_input())
read_ints = lambda: map(int, raw_input().split())
read_float = lambda: float(raw_input())
read_floats = lambda: map(float, raw_input().split())

"---------------------------------------------------------------"

N, C, K = read_ints()
arr = []
for i in xrange(N):
    t = read_int()
    arr.append(t)
arr.sort()
# epr(arr)
last_bus = INF
nfree = 0
ans = 0
for t in reversed(arr):
    if t >= last_bus - K and nfree > 0:
        nfree -= 1
    else:
        # print "TAKE FOR", t-K, t
        ans += 1
        nfree = C - 1
        last_bus = t

print ans




Measured memory_bytes: 7892
n, q = gets.split.map(&:to_i)
a = n.times.map{[]}

q.times do
  command, num1, num2 = gets.split.map(&:to_i)
  case command
  when 0
    a[num1].push num2
  when 1
    puts a[num1].join(" ")
  else
    a[num1].clear
  end
end


Measured memory_bytes: 15652
import java.util.Scanner;

public class Main {

	static boolean[] prime;

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

		prime = new boolean[100000001];
		int count = 0;

		for (int i=2; i<=10000; i++) {
			if (prime[i]) continue;
			for (int j=i*2; j<=100000000; j+=i) {
				prime[j] = true;
			}
		}

		int n = sc.nextInt();
		for (int i=0; i<n; i++) {
			int num = sc.nextInt();
			if (!prime[num]) {
				count++;
			}
		}

		System.out.println(count);

		sc.close();
	}

}

Measured memory_bytes: 140420
function Main(input) {
  const [d, t, s] = input.trim().split(' ').map(x => parseInt(x))
  if (s*t >= d) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30476
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int maxn=5005;
const int INF=0x3f3f3f3f;

int a[maxn],b[maxn],c[maxn],d[maxn];
int s[maxn],n;
int sa[maxn],h[maxn],rk[maxn];
int sum[maxn];
char str[maxn];
bool cmp(int r[],int a,int b,int k)
{
    return r[a]==r[b]&&r[a+k]==r[b+k];
}
void build_sa(int r[],int sa[],int n,int m)
{
    int i,j,p,*x=a,*y=b;
    for(int i=0; i<m; c[i++]=0);
    for(int i=0; i<n; c[x[i++]=r[i-1]]++);
    for(int i=0; i<m; c[++i]+=c[i-1]);
    for(int i=n-1; i>=0; sa[--c[x[i]]]=i--);
    for(j=1,p=1; p<n; j<<=1,m=p)
    {
        for(p=0,i=n-j; i<n; y[p++]=i++);
        for(i=0; i<n; i++)if(sa[i]>=j)y[p++]=sa[i]-j;
        for(i=0; i<n; d[i++]=x[y[i-1]]);
        for(i=0; i<m; c[i++]=0);
        for(i=0; i<n; c[d[i++]]++);
        for(i=0; i<m; c[++i]+=c[i-1]);
        for(i=n-1; i>=0; sa[--c[d[i--]]]=y[i+1]);
        for(swap(x,y),p=1,x[sa[0]]=0,i=1; i<n; i++)
            x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
    }
}
void calh(int r[],int sa[],int n)
{
    int i,j,k=0;
    for(i=1; i<=n; rk[sa[i++]]=i-1);
    for(i=0; i<n; h[rk[i++]]=k)
        for(k?k--:0,j=sa[rk[i]-1]; r[i+k]==r[j+k]; k++);
}
int main()
{
    int Q;
    scanf("%s",str);
    n=strlen(str);
    for(int i=0; i<n; i++)
        s[i]=(int)str[i];
    s[n]=0;
    build_sa(s,sa,n+1,256);
    calh(s,sa,n);

    int tot=0;
    for(int i=1; i<=n; i++)
    {
        sum[i] = n-sa[i]-h[i];
        tot+=sum[i];
    }
    for(int i=2; i<=n; i++)
        sum[i]+=sum[i-1];
    int kth,ans;

    cin>>kth;
    if(kth>tot)kth%=tot;
    int L=0,R=n,mid;
    while(L<=R)
    {
        mid=(L+R)>>1;
        if(sum[mid]>=kth)
        {
            ans=mid;
            R=mid-1;
        }
        else L=mid+1;
    }
    int s=sa[ans];
    int t=s+kth-sum[ans-1]+h[ans]-1;
    for(int i=s; i<=t; i++)cout<<str[i];
    cout<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x=0,big=0;
    char s[1010];
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>s[i];
        if(s[i]=='I'){  
            x++;
            if(x>big){
                big=x;;
            }
        }else{
            x--;
        }
    }
    cout<<big<<'\n';
    return(0);
}

Measured memory_bytes: 256
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	a,b = LI()
	print(math.ceil((a+b)/2))


if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main(){
    
    int n;
    cin>>n;
    set<string> s;
    for(int i=0; i<n; i++){
        string t;
        cin>>t;
        s.insert(t);
    }
    cout<<s.size()<<"\n";
}


Measured memory_bytes: 19156
N,H = map(int,input().split())
ls = []
for i in range(N):
    a,b = map(int,input().split())
    ls.append([a,b])
ls.sort()
ls.sort(key=lambda x:-x[0])
mainkatana = ls.pop(0)
ls.sort(key=lambda x:-x[1])
ls.append([0,0])
ii = 0
while ls[0][1] >= mainkatana[0] and H > mainkatana[1]:
    ii += 1
    nage = ls.pop(0)
    H -= nage[1]
cut = max(0,-(-(H-mainkatana[1])//mainkatana[0]))
ii += cut
if H > 0:
    ii += 1
print(ii)

Measured memory_bytes: 28872
#include <iostream>
#include <string>

int main()
{
	int n;
	int a[1000];
	std::cin >> n;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
	}

	bool is_denied = false;
	for (int i = 0; i < n; ++i)
	{
		if (((a[i]) & 0x1) == 0)
		{
			if (a[i] % 3 == 0 || a[i] % 5 == 0)
			{
				// ok
			}
			else
			{
				is_denied = true;
			}
		}
		if (is_denied)
		{
			break;
		}
	}
	const char *result_s = is_denied ? "DENIED" : "APPROVED";
	std::cout << result_s << std::endl;
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  int a,b;
  int count=0;
  vector <int> v(n);
  for(int i=0;i<n;i++)
    cin>>v[i];
  for(int i=1;i<n-1;i++)
  {
      a=v[i-1];
      b=v[i+1];
      if((v[i]>a && v[i]<b)||(v[i]<a&&v[i]>b))
        count+=1;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;


//#define debugger
#define rep int kase; scanf("%d", &kase); while(kase--)

int main(){
  #ifdef debugger
  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  #endif // debugger
  int n;
  scanf("%d", &n);
  if(n / 100 == n % 10) printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

int main() {
    string s;
    string p;
    cin >> s >> p;
    s += s;

    if (s.find(p) == string::npos)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


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


def f(n):
    '''
    >>> f(105)
    8
    '''
    ret = 0
    for i in range(1, n+1):
        if n % i == 0:
            ret += 1
    return ret

def solve(N: int):
    ret = 0
    for i in range(1, N+1):
        if i % 2 == 1 and f(i) == 8:
            ret += 1
    return ret

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Measured memory_bytes: 7712
// Problem : A - Circle Pond
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_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;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	double pi = 3.141592653589793238;
	int n;
	cin>>n;
	double ans = n * 1.00;
	ans = ans * 2.0;
	ans = ans * pi;
	cout<<setprecision(20)<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if (C >= A && C <= B){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import heapq as hp
n, m = map(int, input().split())
list_A = list(map(int, input().split()))
# list_A = sorted(list_A)

a_q = []
for i in list_A:
    hp.heappush(a_q, -1*i)

for i in range(m):
    tmp = hp.heappop(a_q)
    tmp = hp.heappush(a_q, int(tmp/2))

print(-sum(a_q))

Measured memory_bytes: 14180
#include<bits/stdc++.h>
#define maxn 100009
#define mk make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> P;
multiset<int>st[maxn];
map<P,int>mp;
map<P,int>::iterator it;
multiset<int>::iterator jt;
int fa[maxn],sz[maxn];
queue<P>q;
vector<int>vec[maxn];
int find(int x){if(fa[x]!=x) fa[x]=find(fa[x]);return fa[x];}
int main(){
  int n,x,y;
  scanf("%d",&n);
  for(int i=1;i<n;i++){
    scanf("%d%d",&x,&y);
    st[x].insert(y),st[y].insert(x);
    mp[mk(x,y)]+=1,mp[mk(y,x)]+=1;
  }
  for(int i=1;i<n;i++){
    scanf("%d%d",&x,&y);
    st[x].insert(y),st[y].insert(x);
    mp[mk(x,y)]+=1,mp[mk(y,x)]+=1;
  }
  for(it=mp.begin();it!=mp.end();it++)
    if(it->se==2) q.push(it->fi);
  for(int i=1;i<=n;i++) fa[i]=i,sz[i]=1,vec[i].pb(i);
  for(int T=1;T<n;T++){
  tp:
    if(q.empty()) puts("NO"),exit(0);
    P u=q.front();q.pop();
    mp.erase(u);
    int x=find(u.fi),y=find(u.se);
    if(x==y) goto tp;
    if(sz[x]>sz[y]) swap(x,y);
    for(jt=st[x].begin();jt!=st[x].end();jt++){
      int k=find(*jt);if(k==y) continue;
      st[y].insert(k),st[k].insert(y),mp[mk(y,k)]+=1,mp[mk(k,y)]+=1;
      if(mp[mk(y,k)]==2) q.push(mk(y,k));
      if(mp[mk(k,y)]==2) q.push(mk(k,y));
      st[k].erase(st[k].find(x));
    }
    st[y].erase(x);
    fa[x]=y,sz[y]+=sz[x];
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 63488
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
//-------------------関数----------------------//
ll a[114514];
int main() {
  ll n;
  cin >> n;
  ll cnt = 0;
  REP(i, n) { cin >> a[i]; }
  ll flag = 0;
  cnt += a[0] / 2;
  if (a[0] % 2 == 1) {
    flag = 1;
  }
  REP(i, n - 1) {
    if (a[i + 1] == 0) {
      flag = 0;
      continue;
    }
    if (flag == 1) {
      cnt++;
      flag = 0;
      a[i + 1] -= 1;
    }
    cnt += a[i + 1] / 2;
    if (a[i + 1] % 2)
      flag = 1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int n = sc.nextInt();
		
		for (int i=1; i<=n; i++) {
			if (i%3 == 0) System.out.print(" "+i);
			else if (String.valueOf(i).contains("3") || i%10==3) System.out.print(" "+i);
		}
		
		System.out.println();
		
	}
}


Measured memory_bytes: 29336
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define PI 3.1415926535

typedef struct{
  double x;
  double y;
}Point;

void KochCurve(Point,Point,int);

int main(void){
  int n;
  Point p1={0,0};
  Point p2={100,0};

  scanf("%d", &n);

  printf("%.8f %.8f\n", p1.x, p1.y);
  KochCurve(p1,p2,n);
  printf("%.8f %.8f\n", p2.x, p2.y);

  return 0;
}

void KochCurve(Point p1, Point p2, int n){
  Point p3,p4,p5;

  if(n==0) return;

  p3.x=(2*p1.x+p2.x)/3.0;
  p3.y=(2*p1.y+p2.y)/3.0;
  p4.x=(p1.x+2*p2.x)/3.0;
  p4.y=(p1.y+2*p2.y)/3.0;
  p5.x=(p4.x-p3.x)*cos(PI/3)-(p4.y-p3.y)*sin(PI/3)+p3.x;
  p5.y=(p4.x-p3.x)*sin(PI/3)+(p4.y-p3.y)*cos(PI/3)+p3.y;

  KochCurve(p1,p3,n-1);
  printf("%.8f %.8f\n", p3.x, p3.y);
  KochCurve(p3,p5,n-1);
  printf("%.8f %.8f\n", p5.x, p5.y);
  KochCurve(p5,p4,n-1);
  printf("%.8f %.8f\n", p4.x, p4.y);
  KochCurve(p4,p2,n-1);

  return;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	int odd=0;
	
	odd=n*(n-1)/2+m*(m-1)/2;
	cout<<odd<< endl;
	return 0;
}


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

using namespace std;
typedef long long LL;
const int maxn = 400005;
const int mod = 1e9+7;

int n,p[maxn],sum[maxn],ans;

int findp(int t) {
	return p[t]?p[t]=findp(p[t]):t;
}
void merge(int u,int v) {
	u=findp(u);v=findp(v);
	u!=v?(p[u]=v,sum[v]+=sum[u]):0;
}

struct edge {
	int u,v,next;
}edg[maxn];
int ehead[maxn],ecnt;
void add(int u,int v) {
	edg[++ecnt]=(edge){u,v,ehead[u]};
	ehead[u]=ecnt;sum[findp(u)]--;
	edg[++ecnt]=(edge){v,u,ehead[v]};
	ehead[v]=ecnt;sum[findp(v)]--;
}

LL fpm(LL p,LL k) {
	LL res=1ll;p%=mod;
	while (k) {
		if (k&1) (res*=p)%=mod;
		(p*=p)%=mod;k>>=1;
	}
	return res;
}

int stk[maxn],top,fa[maxn],cal[maxn],res,val;bool ins[maxn],tag,onr[maxn];
void FindRing(int u)
{
	ins[u]=true;
	for (int v,j=ehead[u];j&&!tag;j=edg[j].next)
	if ((v=edg[j].v)!=fa[u]) {
		if (ins[v]) {
			tag=onr[u]=true;stk[++top]=u;
			for (int i=u;i!=v;i=fa[i])
				stk[++top]=fa[i],onr[fa[i]]=true;
		}
		else fa[v]=u,FindRing(v);
	}
	ins[u]=false;
}
void calc(int u,int fa)
{
	cal[u]=1;ins[u]=true;
	for (int v,j=ehead[u];j;j=edg[j].next)
	if ((v=edg[j].v)!=fa&&!onr[v]) {
		calc(v,u);v<fa?cal[u]+=cal[v]:0;
	}
	if (fa) res=(LL)res*cal[u]%mod;
}
void calcR(int u,int fa)
{
	if (ins[u]) return ;
	cal[u]=1;ins[u]=true;
	for (int v,j=ehead[u];j;j=edg[j].next)
	if ((v=edg[j].v)!=fa&&v<fa) {
		calcR(v,u);cal[u]+=cal[v];
	}
	val=(LL)val*cal[u]%mod;
}
int main()
{
	#ifdef Amberframe
		freopen("arc083f.in","r",stdin);
		freopen("arc083f.out","w",stdout);
	#endif
	scanf("%d",&n);ans=1;
	for (int i=1;i<=n<<1;i++) ans=(LL)ans*i%mod;
	for (int i=2;i<=(n<<1|1);i++) sum[i]=2;
	for (int u,v,i=1;i<=n<<1;i++)
		scanf("%d %d",&u,&v),add(u<<1,v<<1|1),merge(u<<1,v<<1|1);
	for (int i=2;i<=(n<<1|1);i++)
		if (sum[i]&&!p[i]) {puts("0");return 0;}
	
	for (int i=2;i<=(n<<1|1);i++)
	if (!p[i]) {
		res=1;tag=false;top=0;FindRing(i);
		for (int j=1;j<=top;j++) calc(stk[j],0);
		stk[0]=stk[top];stk[top+1]=stk[1];
		int oans=0;val=1;
		for (int j=1;j<=top;j++) ins[stk[j]]=false;
		for (int j=1;j<=top;j++) calcR(stk[j],stk[j-1]);
		oans=fpm((LL)res*val,mod-2);val=1;
		for (int j=1;j<=top;j++) ins[stk[j]]=false;
		for (int j=1;j<=top;j++) calcR(stk[j],stk[j+1]);
		oans=(oans+fpm((LL)res*val,mod-2))%mod;
		ans=(LL)ans*oans%mod;
	}
	printf("%d",ans);
	return 0;
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N; cin >> N;
    ll A[N], B[N];
    pair<ll, int> C[N];
    ll sumA = 0, sumB = 0;
    rep(i, N){
        cin >> A[i] >> B[i];
        sumA += A[i];
        sumB += B[i];
        C[i].first = A[i] + B[i];
        C[i].second = i;
    }
    sort(C, C+N);
    reverse(C, C+N);
    rep(i, N){
        if(i % 2 == 0){
            sumB -= B[C[i].second];
        }
        else{
            sumA -= A[C[i].second];
        }
    }
    cout << sumA - sumB << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int w;
    int[][] wv;
    int[][] dp;

    long m = 0;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        w = sc.nextInt();
        wv = new int[n][2];
        for (int i = 0; i < n; i++) {
            wv[i][0] = sc.nextInt();
            wv[i][1] = sc.nextInt();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        dp();
        System.out.println(m);
    }

    private void dp() {
        dp = new int[n+1][n*1000+1];
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j < n * 1000 + 1; j++) {
                dp[i][j] = (int)1e9+50000;
            }
        }
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= n*1000; j++) {
                if (j < wv[i-1][1]) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = Math.min(dp[i-1][j - wv[i-1][1]] + wv[i-1][0], dp[i-1][j]);
                }
            }
        }
        for (int i = 0; i <= n*1000; i++) {
            if (dp[n][i] <= w) {
                m = Math.max(m, i);
            }
        }
    }
}

Measured memory_bytes: 83112
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int ans=0;
        int temp;
        if(C <= A){
            temp = A;
            A = C;
            C = temp;
            temp = B;
            B = D;
            D = temp;
        }
        if(B <= C) ans=0;
        else if(D <= B) ans = D - C;
        else ans = B - C;
        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  string n;
  cin >> n;
  if((n[0] == n[1] && n[1] == n[2])||(n[1] == n[2] && n[2] == n[3])) cout <<"Yes"<< endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

string S;

int main() {
	cin >> S;
	cout << S.substr(0, 5) << " " << S.substr(6, 7) << " " << S.substr(14, 5) << endl;
	return 0;
}

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

int main(){
	int n;
	double s[1000],a,m;

	while(1){
		cin >> n;
		
		if(n==0)break;

		double all=0,z=0;
		
		for(int i=0; i<n; i++){
			cin >> s[i];
			all += s[i];
		}
		
		m = all/n;

		for(int i=0; i<n; i++){
			z += pow(s[i]-m,2);
		}

		a = sqrt(z/n);

		printf("%f\n",a);
		//printf("test all=%.10f m=%.10f z=%.10f\n",all,m,z); //test
	}

	return 0;
}

Measured memory_bytes: 3196
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

for i in range(N):
    P[i]-=1

ans=-float('inf')

for start in range(N):
    loop_len=1
    pos=P[start]
    score=C[pos]
    scores=[score]

    while pos!=start:
        loop_len+=1
        pos=P[pos]
        score+=C[pos]
        scores.append(score)
    
    loops=(K-1)//loop_len

    if score>0:
        cand=score*loops + max(scores[:(K-loop_len*loops)])
    else:
        cand=max(scores[:min(K,loop_len)])
    ans=max(ans,cand)
print(ans)

Measured memory_bytes: 81904
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // ネットワークフロー時の逆辺
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
        from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

vector<int> P;

void dfs(const Graph &g, int v, int u, vector<int> &q) {
	q.push_back(v);
	if(v == g.size() -1) {
		P = q;
		q.pop_back();
		return;
	}
	EACH(i, g[v]) if(i->to != u) {
		dfs(g, i->to, v, q);
	}
	q.pop_back();
}

void dfs2(const Graph &g, int v, int c, vector<int> &color) {
	color[v] = c;
	EACH(i, g[v]) if(color[i->to] < 0) {
		dfs2(g, i->to, c, color);
	}
}

signed main(){
	int N;
	cin >> N;
	Graph g(N);
	for(int i = 1; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		addUndirectedEdge(g, a, b, 0);
	}
	vector<int> q;
	dfs(g, 0, -1, q);
	vector<int> color(N, -1);
	//for(int i = 0; i < P.size(); ++i) {
	//	cerr << P[i] << ",";
	//}
	//cerr<< endl;
	for(int i = 0; i < P.size(); ++i) {
		color[P[i]] = i > (P.size() - 1) / 2 ? 1: 0;
		// for(int i = 0; i < N; ++i) cout << color[i];
		// cout << endl;
	}
	for(int i = 0; i < P.size(); ++i) {
		dfs2(g, P[i], color[P[i]], color);

		// for(int i = 0; i < N; ++i) cout << color[i];
		// cout << endl;
	}
	int cnt = 0;
	for(int i = 0; i < N; ++i) {
		if(color[i] == 0) {
			++cnt;
		}
	}
	// cerr << cnt << endl;
	if(cnt <= N - cnt) {
		cout << "Snuke" << endl;
	} else {
		cout << "Fennec" << endl;
	}
	return 0;
}


Measured memory_bytes: 19192
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	typedef double d;
    #define    thunder   ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL)
    int main()

    {
    thunder;
    string s;
    cin>>s;
    int su=0;
    for(int i=0;i<s.length();i++)
    {
        su+=s[i]-'0';
    }
    if(su%9) cout<<"No";
    else cout<<"Yes";
    }

Measured memory_bytes: 3732
#include <stdio.h>

int main(void){
	
	int tate, yoko, taikaku;
	int hisigata = 0, chouhoukei = 0;
	
	while(scanf("%d,%d,%d", &tate, &yoko, &taikaku) != EOF){
		
		//ひし形かチェック
		if(tate == yoko){
			
			hisigata++;
			
		}
		
		//長方形かチェック
		if((tate*tate) + (yoko*yoko) == taikaku*taikaku){
			
			chouhoukei++;
			
		}
		
	}
	
	printf("%d\n", chouhoukei);
	printf("%d\n", hisigata);
	
	return 0;
	
}

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

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int l,r,d;
    cin >> l >> r >> d;
    cout << r/d-(l-1)/d;
    return 0;
}


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

int main()
{
    long long x,y,t,i,j,n,xl,yl,cnt=0,tl,prod,trel;
    bool ok=1;
    cin>>n;
    cin>>tl>>xl>>yl;
    prod=xl+yl;
    if(xl==yl&&yl==0)
            prod=2;
    if(prod<=tl&&(tl-prod)%2==0){}
    else ok=0;


    for(i=2;i<=n;i++)
    {
        cin>>t>>x>>y;

        prod=fabs(x-xl)+fabs(y-yl);
        trel=fabs(t-tl);
        if(prod==0)
            prod=2;
        if(prod<=trel&&(trel-prod)%2==0){}
        else ok=0;
        xl=x;
        yl=y;
        tl=t;
    }
    if(ok==1)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


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


typedef struct{
  int size;
  int A[102];
}stack;


int main(){
  char c[15]="";//文字列の初期化
  char d;
  int i;
  stack *S;
  S=malloc(sizeof(stack));
  S->size=0;//ここで初期化

  while(1){
    scanf("%[^ \n]%c",c,&d);
    if(c[0]=='+'){
      S->A[S->size -1]=S->A[S->size -1]+S->A[S->size];
      S->size-=1;
    }
    else if(c[0]=='-'){
      S->A[S->size -1]=S->A[S->size -1]-S->A[S->size];
      S->size-=1;
    }
    else if(c[0]=='*'){
      S->A[S->size -1]=S->A[S->size -1]*S->A[S->size];
      S->size-=1;
    }
    else{
      S->A[S->size +1]=atoi(c);
      S->size+=1;
    }
    if(d=='\n') break;
  }
  printf("%d\n",S->A[S->size]);
  return 0;
}


Measured memory_bytes: 2080
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N;
    cin >> N;
    int a[N];
    int s[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
        s[i]=a[i];
    }
    sort(s,s+N);
    for(int i=0;i<N;i++){
        if(a[i]!=s[N-1]){
            cout << s[N-1] << endl;
        }else if(a[i]==s[N-1]){
            cout << s[N-2] << endl;
        }
    }
}


Measured memory_bytes: 3200
s=raw_input()
k=len(s)/2+1
lef=(len(s)-1)/2
ch=s[lef]
rig=(len(s))/2
while 0<=lef and rig<len(s):
    if s[lef]==s[rig] and ch==s[lef]:
        k+=1
        lef-=1
        rig+=1
    else:
        k-=1
        break
print(k-(lef==-1))

Measured memory_bytes: 2820
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100007],b[100007];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&a[i]);
    }
    if(n>=m)
        printf("0");
    else{
        int y=0;
        sort(a+1,a+1+m);
        for(int i=2;i<m;i++){
            y=a[i+1]-a[i];
            b[i]=y;
        }
        long long sum=0;
        b[1]=a[2]-a[1];
        sort(b+1,b+m);
        for(int i=1;i<=m-n;i++){
            sum+=b[i];
        }
        printf("%lld",sum);
    }
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
a = [set() for _ in range(N)]

for i in range(N):
    id = int(input()) - 1
    a[id].add(i)

step = -1
#already = a[1]
now = a[1]
next = set()
for i in range(N-1):
    #already = already.union(now)
    if 0 in now:
        step = i+1
        break
    for j in now:
        next = next.union(a[j])
    now = next
    next = set()

print(step)

Measured memory_bytes: 35300
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	vector<ll> r,w;
	for(ll i=0;i<n;i++){
		if(s[i]=='R') r.push_back(i);
		else w.push_back(i);
	}
	ll ans=0;
	ll p=r.size()-1;
	for(ll i=0;i<w.size();i++){
		if(p>=0&&r[p]>w[i]){
			ans++;
			p--;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5828
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map { it.toLong() }

    fun f(h: Long, w: Long): Long {
        var ans = Long.MAX_VALUE
        for (h1 in 1 until h) {
            val h2 = h - h1

            val a = listOf(h1 * w, (h2 / 2) * w, (h2 - h2 / 2) * w)
            ans = Math.min(ans, a.max()!! - a.min()!!)

            val b = listOf(h1 * w, h2 * (w / 2), h2 * (w - w / 2))
            ans = Math.min(ans, b.max()!! - b.min()!!)
        }
        return ans
    }

    println(Math.min(f(h, w), f(w, h)))
}


Measured memory_bytes: 50392
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

void solve(std::string S){
    set<char> c;
    REP(i, 4) c.insert(S[i]);
    bool ans = true;
    if (c.size() != 2) ans = false;
    else if (S[0] == S[1] && S[1] == S[2]) ans = false;
    if (ans) cout << YES << '\n';
    else cout << NO << '\n';

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

const int maxn = 200005;
int n, k, a[maxn], p[maxn], m[maxn];
ll ans;
vector<int> v[maxn];

int main(){
    scanf("%d %d", &n, &k);
    for(int i = 1, a; i <= n; i++) scanf("%d", &a), p[i] = (p[i - 1] + a) % k;
    if(k == 1){ puts("0"); return 0; }
    vector<int> cpr;
    for(int i = 0; i <= n; i++) m[i] = ((p[i] - i) % k + k) % k, cpr.push_back(m[i]);
    sort(cpr.begin(), cpr.end());
    cpr.resize(unique(cpr.begin(), cpr.end()) - cpr.begin());
    for(int i = 0; i <= n; i++) m[i] = lower_bound(cpr.begin(), cpr.end(), m[i]) - cpr.begin() + 1, v[m[i]].push_back(i);
    for(int i = 1; i <= n; i++){
        int x = m[i - 1];
        ans += upper_bound(v[x].begin(), v[x].end(), i + k - 2) - lower_bound(v[x].begin(), v[x].end(), i);
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 13556
import sys

def main():
    N = int(input())
    h = list(map(int, input().split()))

    ans = 0
    zero_list = [0] * N

    while True:
        for i in range(N):
            if h[i] > zero_list[i]:
                L_p = i
                R_p = i

                for j in range(L_p+1, N):
                    if h[j] > zero_list[i]:
                        R_p = j
                    else:
                        break

                for k in range(L_p, R_p+1):
                    zero_list[k] += 1

                ans += 1
                break

        if h == zero_list:
            break
    print(ans)

main()

Measured memory_bytes: 3064
/******
	~site:    atcoder.jp
	~user:    Turkhuu
	~problem: AtCoder Beginner Contest 177 - C (abc177_c)
** **/

#include<bits/stdc++.h>

#define FFOR(i,s,e,k) for(int i=s;(k==1?i<=e:i>=e);i+=k)
#define FOR(i,n) FFOR(i,0,n-1,1)
#define FORR(i,s,e) FFOR(i,s,e,1)
#define ll long long
#define PQ priority_queue
#define pb push_back
#define ppb pop_back()
#define pp push
#define MIN(v) *min_element(v.begin(),v.end())
#define MAX(v) *max_element(v.begin(),v.end())
#define SORT(v) sort(v.begin(),v.end())
#define TROS(v) sort(v.rbegin(),v.rend())
#define CNT(v,x) count(v.begin(),v.end(),x)
#define MOD 1000000007
using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	ll a[200001];
	FOR(i,n){
		cin>>a[i];
		if(i>0) a[i]+=a[i-1];
	}
	ll sum=0;
	FOR(i,n){
		int k=(i==0?a[i]:a[i]-a[i-1]);
		sum+=(k*((a[n-1]-a[i])%MOD))%MOD;
		sum%=MOD;
	}
	cout<<sum;
}

Measured memory_bytes: 5184
n = int(input())

ans = 0
cmax = -1
for ii in range(1, n + 1):
    c = 0
    i = ii
    while i > 0:
        if i % 2 == 0:
            i = i // 2
            c += 1
        else:
            break
    if c > cmax:
        ans = ii
        cmax = c
print(ans)


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<array<int64_t, 2>> ta(n);
    for (auto&& x : ta) {
        cin >> x[0] >> x[1];
    }

    array<int64_t, 2> ans = ta[0];
    for (const auto& x : ta) {
        auto y = max((ans[0] - 1) / x[0] + 1, (ans[1] - 1) / x[1] + 1);
        ans[0] = x[0] * y;
        ans[1] = x[1] * y;
    }

    cout << ans[0] + ans[1] << endl;
}

Measured memory_bytes: 256
def main():
    H, W, K = list(map(int, input().split()))
    dp = [[0 for _ in range(W)] for _ in range(H + 1)]
    dp[0][0] = 1

    for i in range(H):
        for j in range(1 << (W - 1)):
            if '11' in bin(j):
                continue
            j <<= 1
            for w in range(W):
                if j & (1 << w):
                    dp[i + 1][w] += dp[i][w - 1]
                elif j & (1 << (w + 1)):
                    dp[i + 1][w] += dp[i][w + 1]
                else:
                    dp[i + 1][w] += dp[i][w]
                dp[i + 1][w] %= (10 ** 9 + 7)

    print(dp[H][K - 1])


if __name__ == '__main__':
    main()


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

using namespace std;

/* template */

using ll = long long;

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

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

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

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

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

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


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

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1e15+7;

constexpr int INF = 1e9+7;

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

/* template */

std::vector<int> Z_Algorithm(const string &s){
    int n = s.size();
    std::vector<int> z(n);
    z[0] = n;
    int i = 1,j = 0;
    while(i<n){
        while(i+j<n && s[j]==s[i+j]) j++;
        z[i] = j;
        if(j==0){ i++; continue; }
        int k = 1;
        while(i+k<n && k+z[k]<j){
            z[i+k] = z[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return z;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; string s; cin >> n >> s;
    int ans = 0;
    rep(i,0,n){
        vector<int> z = Z_Algorithm(s.substr(i,s.size()-i));
        rep(j,1,z.size()){
            chmax(ans,min(z[j],j));
        }
    }
    cout << ans << endl;
}

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

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

    int total = 0;
    while(m--){
        int a;
        cin >> a;
        n -= a;
    }
    cout << (n >= 0 ? n : -1) << endl;
}

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

int main(void){
    // Here your code !
    int n;
    int m = 1000000007;
    cin >> n;
    string s[2];
    cin >> s[0];
    cin >> s[1];
    
    unsigned int dp = 1;
    bool was_vertical = false;
    for(int i = 0; i < s[0].length(); i++){
        // cout << "dp: " << dp << "\n"; 
        bool vertical = s[0][i] == s[1][i];
        if(i == 0){
            if(vertical){
                dp = 3;
            }
            else{
                dp = 6;
                i++;
            }
            was_vertical = vertical;
            continue;
        }
        if(vertical){
            if(was_vertical)
                dp = dp * 2 % m;
        }
        else{
            if(was_vertical){
                dp = dp * 2 % m;
            }
            else{
                dp = dp * 3 % m;
            }
            i++;
        }
        was_vertical = vertical;
    }
    cout << dp;
}


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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()

s_len = len(s)
ans = 0
A_cnt = 0
BC_flag = False

i = 0
while i < s_len:
	if not BC_flag:
		if s[i] == "A":
			A_cnt += 1
			BC_flag = True
		i += 1
	else:
		if s[i] == "A":
			A_cnt += 1
			i += 1
		elif s[i:i+2] == "BC":
			ans += A_cnt
			i += 2
		else:
			A_cnt = 0
			BC_flag = False
print(ans)

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

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

    vector<pair<long long, long long>> v;

    for(int i=0; i<n; i++)
    {
        long long a, b;
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());

    long long res = 0;

    for(int i=0; i<v.size(); i++)
    {
        if(v[i].second<=m)
        {
            res += v[i].first*v[i].second;
            m= m-v[i].second;
        }
        else
        {
            res += v[i].first*m;
            m= 0;
            break;

        }
    }

    cout<<res<<endl;
}


Measured memory_bytes: 2420