akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

const ll INF=(ll)1e18;
//const int INF=(1<<30);

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

  if(abs(N-M)>1){
    cout << 0 << endl;
    exit(0);
  }
  mint ans=1;
  FOR(i,1,N+1){
    ans*=i;
  }
  FOR(i,1,M+1){
    ans*=i;
  }
  if(N==M)ans*=2;

  cout << ans.x << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,l;
    cin>>n>>l;
    ll ans=0;
    int m=INF;
    for(int i=0;i<n;i++){
        ans+=l+i;
        if(abs(m)>abs(l+i)){
            m=l+i;
        }
    }
    cout<<ans-m<<endl;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong a, b, c;
	cin >> a >> b >> c;

	cout << (a+b >= c ? "Yes" : "No") << endl;

	return 0;
}

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

int main(){
    int n, sum=0;
    cin>>n;
    int l[n];
    for (int i = 0; i < n; i++)
    {
        cin>>l[i];
        sum += l[i];
    }
    int flag=0;
    for (int i = 0; i < n; i++)
    {
        if (l[i] >= sum-l[i])
        {
            flag=1;
        }
        
    }
    if (flag==1)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }
    
    
    
    
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	LL ret = 0;
	map<LL, int> x;
	int n;
	cin >> n;
	LL b = 0;
	x[0] = 1;
	for (int i : range(n)) {
		LL a;
		cin >> a;
		b += a;
		x[b]++;
		ret += x[b]-1;
	}
	cout << ret << endl;
	return 0;
}


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

int main(){
long long n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  
  long long ans=max({(n-1)/a, (n-1)/b, (n-1)/c, (n-1)/d, (n-1)/e})+5;
// 最も登場可能人数が少ない交通機関で割ると、
// そこを通過する時間がわかり、あとは最後に都市1に残った1人の
//残りの都市分(＋5分)で答えが出る
   
  cout<<ans;
}

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

int sub(string a,string b){
	int x = 0;
	for(int i=0;i<a.length();i++){
		if(a[i]!=b[i]){x++;}
	}
	return x;
}

int main(){
	int min = INT_MAX;
	string S,T;
	cin >> S;
	cin >> T;
	for(int i=0;i<S.length()-T.length()+1;i++){
		int sa = sub(S.substr(i,T.length()) ,T);
		if(sa<min){min = sa;}
	}
	cout << min << endl;
	return 0;
}


Measured memory_bytes: 3612
import itertools
import numpy as np


def check_eight(n):
    div_list = []
    for i in range(3, n + 1, 2):
        if n % i == 0:
            while n % i == 0:
                n = n // i
                div_list.append(i)
        if n == 1:
            break

    answer_list = []
    for i in range(1, len(div_list)+1):
        comb = itertools.combinations(div_list, i)
        for c in comb:
            c = np.array(c)
            answer_list.append(c.prod())
    answer = len(set(answer_list)) + 1
    
    return answer == 8

if __name__ == "__main__":
    N = int(input())

    count = 0
    for n in range(1, N + 1, 2):
        count += check_eight(n)

    print(count)

Measured memory_bytes: 27220
s = input()
n = len(s)
a = [0] * n
b = 0
for i in range(n):
    if s[i] == 'R':
        b += 1
    elif b:
        a[i - 1] += 0 - - b // 2
        a[i] += b // 2
        b = 0
a[-1] += b

b = 0
for i in range(n - 1, -1, -1):
    if s[i] == 'L':
        b += 1
    elif b:
        a[i] += b // 2
        a[i + 1] += 0 - - b // 2
        b = 0
a[0] += b
print(*a)


Measured memory_bytes: 10676
import java.util.ArrayDeque;
import java.util.LinkedList;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		int n = ReadIntMan.readint();
		int m = ReadIntMan.readint();

		Node[] v = new Node[n];
		for (int i=0; i < n; i++) {
			v[i] = new Node();
		}

		for (int i=0; i < m; i++) {
			int s = ReadIntMan.readint();
			int t = ReadIntMan.readint();

			v[s].friends.add(t);
			v[t].friends.add(s);
		}

		for (int id=0; id < n; id++) {
			decompose(v, id, id);
		}

		StringBuilder ans = new StringBuilder();

		int q = ReadIntMan.readint();
		for (int i=0; i < q; i++) {
			int s = ReadIntMan.readint();
			int t = ReadIntMan.readint();

			if (v[s].label == v[t].label) ans.append("yes\n");
			else ans.append("no\n");
		}

		System.out.print(ans);
	}

	public static void decompose(Node[] u,int id, int label) {
//		if (u[id].label != -1) return;
//		u[id].label = label;
//		for (int i=0; i < u[id].friends.size(); i++) {
//			int f = u[id].friends.get(i);
//			decompose(u, f, label);
//		}
		ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
		stack.push(id);
		do {
			int index = stack.pop();
			if (u[index].label != -1) continue;
			u[index].label = label;
			for (int i=0; i < u[index].friends.size(); i++) {
				int friend = u[index].friends.get(i);
				stack.push(friend);
			}
		} while ( ! stack.isEmpty() );
	}

	public static class Node {
		int label;

		LinkedList<Integer> friends;

		public Node() {
			this.label = -1;
			this.friends = new LinkedList<>();
		}
	}

	public static class ReadIntMan {
		public static int readint() throws Exception {
			int c = System.in.read();

			while (spaceorenter(c)) {
				c = System.in.read();
			}

			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = System.in.read();
			}

			int n = 0;
			while (! spaceorenter(c)) {
				n = 10*n;
				n = n + c - '0';
				c = System.in.read();
			}

			return sgn * n;
		}

		private static boolean spaceorenter(int c) {
			return c == ' ' || c == '\n' || c == '\r';
		}
	}
}

Measured memory_bytes: 57396
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout << "debug... " << n1 << "\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
public:
    ll x, y;
};
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll fac[600000 + 2];

ll nCr(ll n, ll r, ll p)
{
    if (r == 0)
        return 1;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) %
           p;
}
int main()
{
    ::fac[0] = 1;
    for (ll i = 1; i <= 600001; i++)
        ::fac[i] = (::fac[i - 1]) * i % rem;
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
        ll n,
        k;
    cin >> n >> k;
    ve<ll> arr(n);
    rep(i, 0, n)
    {
        cin >> arr[i];
    }
    ve <ll> add(n,0),sub(n,0);
    sort (all(arr));
    rep (i,0,n)
    {
        if (k-1<=n-i-1)
        {
            sub[i]=nCr(n-i-1,k-1,rem);
        }
        if (i>=k-1)
        {
            add[i]=nCr(i,k-1,rem);
        }
    }
    ll ans=0;
    rep (i,0,n)
    {
        ans+=(arr[i]*add[i]);
        ans%=rem;
        ans-=(arr[i]*sub[i]);
        if (ans<0)
        {
            ans+=rem;
        }
        ans%=rem;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};
template <class T>
struct fenwick_tree {
	vector<T> x;
	fenwick_tree(int n) : x(n, 0) { }
	T sum(int i, int j) {
		if (i == 0) {
			T S = 0;
			for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
			return S;
		}
		else return sum(0, j) - sum(0, i - 1);
	}
	void add(int k, T a) {
		for (; k < x.size(); k |= k + 1) x[k] += a;
	}
};
signed main() {
	int n;
	scanf("%d", &n);
	vector<int> to(n), inc(n);
	REP(i, n-1) {
		int a;
		scnaf("%d", &a);
		a--;
		to[i+1] = a;
		inc[a]++;
	}

	priority_queue<int, vector<int>, greater<int>> que;
	vector<pair<int, vector<int>>> ver(n);
	vector<int> hig(n);
	REP(i, n) {
		if(!inc[i])
			que.push(i);
		hig[i] = inc[i];
	}
	while (que.size()) {
		int cur = que.top();
		que.pop();
		sort(ALL(ver[cur].second));
		REP(i, ver[cur].second.size()) {
			hig[cur] = max(hig[cur], inc[cur]-i+ ver[cur].second[i]);
		}

		ver[to[cur]].second.push_back(hig[cur]);
		if (inc[to[cur]] == ver[to[cur]].second.size()) {
			if (to[cur] != cur)
				que.push(to[cur]);
		}
	}
	int ans = 0;
	REP(i, n) {
		ans = max(ans, hig[i]);
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 7680
#include <iostream>
#include <vector>

using std::vector;

template <typename ARR>
int find(ARR& uf, int x)
{
	return uf[x] == x ? x : (uf[x] = find(uf, uf[x]));
}

template <typename ARR>
void add_uf(ARR& uf, int x, int y)
{
	uf[find(uf, x)] = find(uf, y);
}

int main()
{
	using std::cin;
	cin.sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	std::vector<int> uf(n + 1);
	for (int i = 0; i < n + 1; i++)
	{
		uf[i] = i;
	}
	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		add_uf(uf, x, y);
	}
	std::vector<int> count_v(n + 1, 0);
	int max_count = 0;
	for (int i = 1; i <= n; i++)
	{
		const int pos = find(uf, i);
		count_v[pos]++;
		if (count_v[pos] > max_count)
		{
			max_count = count_v[pos];
		}
	}
	std::cout << max_count;
	return 0;
}

Measured memory_bytes: 10992
nCombinations :: Int -> Int
nCombinations n =
  length $ [(a, b, c, d) | a <- [0..9], b <- [0..9], c <- [0..9], d <- [0..9],
                           a + b + c + d == n]

main = interact $ unlines . map (\line -> show $ nCombinations $ read line) . lines

Measured memory_bytes: 4080
N,M = map(int,input().split())
H = list(map(int,input().split()))


A  = [0] * M
B  = [0] * M

for i in range(M):
    A[i],B[i] = map(int,input().split())


#道がつながったうち、低い方の展望台がよくない展望台になる。
#辞書で高くない展望台を集合でカウントする。
    

yokunai = {}
yokunai = set(yokunai)

for i in range(M): 
    if H[A[i]-1] > H[B[i]-1]:
        yokunai.add(B[i])
    elif H[A[i]-1] < H[B[i]-1]:
        yokunai.add(A[i])
    else:
        yokunai.add(B[i])
        yokunai.add(A[i])



print(N-len(yokunai))























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

int indegree[MAX]={0};
bool completed[MAX]={0};
vector<int> edges[MAX];
int dist[MAX]={0};

void dfs(int n, int m, int i)
{
completed[i]=true;
for(int b : edges[i])
{
	dist[b]=max(dist[b],dist[i]+1);
	indegree[b]--;
	if(indegree[b]==0)
		dfs(n,m,b);
}

}

int32_t main()
{
	int n,m,x,y;
	cin>>n>>m;
	for(int i=0; i<m; i++)
	{
		cin>>x>>y;
		edges[x-1].push_back(y-1);
		indegree[y-1]++;
	}
	for(int i=0; i<n; i++)
	{
	if(indegree[i]==0&&!completed[i])
		dfs(n,m,i);
	}
	int ans=0;
	for(int i=0; i<n; i++)
	{
		ans=max(ans,dist[i]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FORr(i, j, 0)
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    rep(i, s.size()) {
        if(i + 1 == K) s[i] = tolower(s[i]);
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
def calc(a)
  return 0 if a.length == 0
  min = a.min
  a.map!{|i| i - min}
  next_list = []
  tmp_list = []
  a.each_with_index do |num,i|
    if i == a.length - 1
      tmp_list << num if num != 0
      next_list << tmp_list
    elsif num == 0
      next_list << tmp_list
      tmp_list = []
    else
      tmp_list << num
    end
  end
  return min + next_list.inject(0){|res,nl| res += calc(nl)}
end
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
puts calc(a)

Measured memory_bytes: 3964
# from sys import exit
N = int(input())
NP = [0 for i in range(N)]
for i in range(N):
    NP[i] = [str(n) for n in input().split()]
    NP[i].append(i+1)
NP = sorted(NP, key=lambda x: -int(x[1]))
NP = sorted(NP, key=lambda x: x[0])
for i in NP:
    print(i[2])


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
import collections
 
def main():
    N, M = list(map(int, input().split()))
 
    L = [0] * M
    R = [0] * M
    for i in range(M):
        L[i], R[i] = list(map(int, input().split()))
 
    ans = (int(min(R)) - int(max(L)) + 1)
    if ans < 0:
        print('0')
    else:
        print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 11244
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	new aoj0130().doIt();
    }
    class aoj0130{
    	void doIt(){
    		int n = sc.nextInt();
    		for(int i = 0;i < n;i++){
    			int alf[] = new int[128];
    			int alf2[] = new int[128];
    			String str = sc.next();
    			char ctr[] = str.toCharArray();
    			char start = ctr[0];
    			for(int j = 0;j < ctr.length - 1;j += 3){
    				if(ctr[j+1] == '-'){
    					alf[ctr[j]] = ctr[j+3];
    					alf2[ctr[j+3]] = ctr[j];
    					start = ctr[j+3];
    				}
    				else{
    					alf[ctr[j+3]] = ctr[j];
    					alf2[ctr[j]] = ctr[j+3];
    					start = ctr[j];
    				}
    			}
    			while(true){
    				if(alf2[start] != 0)start = (char)alf2[start];
    				else break;
    			}
    			System.out.print(start);
    			while(true){
    				if(alf[start] == 0)break;
    				System.out.print((char)alf[start]);
    				start = (char)alf[start];
    			}
    			System.out.println();
    		}
    	}
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> b(n);
  vector<int> v;
  rep(i,n){
    cin >> b[i];
    if(b[i]){
      v.push_back(i);
    }
  }
  vector<int> p(m);
  rep(i,m) cin >> p[i];

  vector<int> a;
  int now=0;
  rep(i,m){
    rep(j,p[i]) a.push_back(now);
    now=1-now;
  }
  vector<int> va,vb;
  rep(i,n){
    if(a[i]){
      va.push_back(i);
    }else{
      vb.push_back(i);
    }
  }
  int ans=IINF,tmp;
  if(va.size()==v.size()){
    tmp=0;
    rep(i,v.size()) tmp+=abs(va[i]-v[i]);
    ans=min(ans,tmp);
  }
  if(vb.size()==v.size()){
    tmp=0;
    rep(i,v.size()) tmp+=abs(vb[i]-v[i]);
    ans=min(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  ll k;
  int q;
  cin >> n >> k >> q;
  vector<int> a(q);
  rep(i, q) cin >> a[i];

  vector<ll> h(n, k-q);
  rep(i, q) {
    ++h[a[i]-1];
  }
  rep(i, n) {
    if(h[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 4576
using Microsoft.VisualBasic;
using System;
using static System.Console;

namespace ProblemA
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = ReadLine();

            switch(s)
            {
                case "ABC":
                    WriteLine("ARC");
                    break;
                case "ARC":
                    WriteLine("ABC");
                    break;
            }    
        }
    }
}


Measured memory_bytes: 25792
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	int n, k;
	cin >> n >> k;
	if (pow(2, n) - 1 < k || (n == 1 && k == 1)) {
		cout << -1 << endl;
		return 0;
	}
	if (!k) {
		rep(i, pow(2, n))cout << i << " ";
		for (int i = pow(2, n) - 1; i >= 0; i--)cout << i << " ";
		return 0;
	}
	cout << k << " ";
	for (int i = pow(2, n) - 1; i >= 0; i--) {
		if (i != k)cout << i << " ";
	}
	cout << k << " ";
	rep(i, pow(2, n)) {
		if (i != k)cout << i << " ";
	}
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#define INT long long int
#define MOD 1000000007
using namespace std;

INT h, w, n, all, sum, ans[10];
int dx[9] = {-2,-2,-2,-1,-1,-1,0,0,0}, dy[9] = {-2,-1,0,-2,-1,0,-2,-1,0};
map<INT, map<INT, INT> > d;

int main()
{
    cin>>h>>w>>n;
    all = (h-2)*(w-2);
    while( n-- )
    {
        int x, y;
        scanf("%d%d", &x, &y);
        for(int i = 0 ; i < 9 ; i++ )
            if( x+dx[i] > 0 && y+dy[i] > 0 && x+dx[i]+2 <= h && y+dy[i]+2 <= w )
                d[x+dx[i]][y+dy[i]]++;
    }
    for(map<INT, map<INT, INT> >::iterator it = d.begin() ; it != d.end() ; it++ )
    {
       for(map<INT, INT>::iterator jt = d[it->first].begin() ; jt != d[it->first].end(); jt++ )
            ans[jt->second]++, sum++;

    }
    cout<<(all-sum)<<endl;
    for(int i = 1 ; i < 10 ; i++ )
        cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 84608
n = gets.chomp.to_i
$result = []

def rec  (str,val, n)
  if str.size == n
    $result << str
    return
  end
  (val).times do |i|
    rec(str + ("a".ord + i).chr, val, n)
  end
  rec(str + ("a".ord + val).chr, val+1 , n)
end

rec("a", 1, n)

$result.sort.uniq.each do |str|
  puts str
end

Measured memory_bytes: 23984
a, b, c = gets.split.map(&:to_i)

max = [a, b, c].max

a, b, c = max - a, max - b, max - c

diva, a = a.divmod(2)
divb, b = b.divmod(2)
divc, c = c.divmod(2)

ans = diva + divb + divc

case a + b + c
when 2
  ans += 1
when 1
  ans += 2
end

puts ans


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int N;; 	//length
  cin >> N;
  float x[N];
  float y[N];
  rep(i, N){
    cin >> x[i] >> y[i];
  }
  
  float L;	//total length
  float l;
  int p = 1; 	//pattern
  rep(i, N){
    rep(j, N){
      //cout <<"i j:"<< i+1 << " " << i+j+2 << endl;
      l = sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
      //cout << std::setprecision(10) << l << " "<< L <<endl;
      L = L + l;
    }
    p = p*(i+1); //cout << p <<endl;
  }
  
  float ans;
  ans = (L)/N;
  cout << std::setprecision(10) << ans;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	const int n = s.size();
	int answer = 0, depth = 0;
	for(int i = 0; i < n; ++i){
		if(s[i] == 'S'){
			++depth;
		}else if(depth == 0){
			++answer;
		}else{
			--depth;
		}
	}
	answer += depth;
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 720
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  ll n;cin>>n;
  vl a;
  a.push_back(0);
  rep(i,n){
    ll x;cin>>x;
    a.push_back(x);
  }
  a.push_back(0);
  ll sum=0;
  rep(i,n+1)sum+=abs(a[i+1]-a[i]);
  rep(i,n)cout<<sum-(abs(a[i+1]-a[i])+abs(a[i+2]-a[i+1])-abs(a[i+2]-a[i]))<<endl;
}
  

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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string imp = Console.ReadLine();
            int L = imp.Length;
            int[] def = new int[L];
            for(int j = 0; j < L; j++)
            {
                def[j] = int.Parse(imp[j].ToString());
            }
            int[] sub1 = new int[L];
            int[] sub2 = new int[L];
            int count1 = 0;
            int count2 = 0;
            for(int i = 0; i < L; i++)
            {


                if (i % 2 == 0)
                {
                    sub1[i] = 0;
                    sub2[i] = 1;
                }
                else
                {
                    sub1[i] = 1;
                    sub2[i] = 0;
                }
                if (def[i] != sub1[i]) count1 += 1;
                else if (def[i] != sub2[i]) count2 += 1;
            }
            Console.Write(Math.Min(count1, count2));
            //System.Threading.Thread.Sleep(3000);
        }
    }
    
}


Measured memory_bytes: 14560
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
#include<algorithm>
using namespace std;

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

	vector<int> a(N);
	for(int i=0; i<N; i++)
		cin >> a[i];

	int sum = 0;
	for(int i=0; i<N; i++)
		sum += a[i];

	vector<pair<int, int>> v(N);
	for(int i=0; i<N; i++)
		v[i] = make_pair(abs(a[i]*N - sum), i);

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

	cout << v[0].second << endl;

	return 0;
}


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

int main() {
  long int A, B, temp, r, GCD, x;
  cin >> A >> B;
  
  if(B > A){
    temp = A;
    A = B;
    B = temp;
  }
  
  x = A * B;
  
  r = A % B;
  while(r != 0){
    temp = B;
    B = A % B;
    A = temp;
    r = A % B;
    
  }
  
  GCD = x / B;
 
  cout << GCD << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import sys
import argparse
import logging

logging.basicConfig(filename='logger.log', level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


def f(c_list: list) -> int:
    '''
    >>> f(['W'])
    0
    >>> f(['R'])
    0
    >>> f(['W','W'])
    0
    >>> f(['R','W'])
    0
    >>> f(['R','R'])
    0
    >>> f(['W','R'])
    1
    >>> f(['W','W','R','R'])
    2
    >>> f(['W','W','R','R'])
    2
    >>> f(['W', 'R', 'W', 'W', 'R', 'W', 'R', 'R',])
    3
    '''
    logger.error(c_list)
    last_red_index = -1
    n_white = 0
    n_red = 0
    for index in range(0, len(c_list)):
        if c_list[index] == 'R':
            last_red_index = index
            n_red += 1
        if c_list[index] == 'W':
            n_white += 1
    logger.error('last_red_index: %d' % (last_red_index))

    # 最後に出てくるRより左をすべてRにする
    plan1 = 0
    for index in range(0, last_red_index):
        if c_list[index] == 'W':
            plan1 += 1
    logger.error('plan1: %d' % (plan1))

    # すべてのRをWにする
    plan2 = n_white
    logger.error('plan2: %d' % (plan2))

    # すべてのRを左に寄せる
    plan3 = n_red
    for index in range(0, n_red):
        if c_list[index] == 'R':
            plan3 -= 1
    logger.error('plan3: %d' % (plan3))

    return min(plan1, plan2, plan3)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
            '--doctest', action='store_true', default=False)
    args = parser.parse_args()
    if args.doctest:
        import doctest
        doctest.testmod(verbose=True)
        sys.exit()

    n = int(sys.stdin.readline().rstrip())
    c_list = list(sys.stdin.readline().rstrip())
    print(f(c_list))

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

bool isABC[6100];
bool solve(string str) {
  if (str == "ABC") return true;
  else if (str.size() <= 2) return false;
  
  memset(isABC, 0, sizeof(isABC));
  for (int i = 0; i+2 < str.size(); ++i) {
    if (str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C') {
      isABC[i] = true;
      isABC[i+1] = true;
      isABC[i+2] = true;
    }
  }
  set<char> se;
  for (int i = 0; i < str.size(); ++i) {
    if (!isABC[i]) se.insert(str[i]);
  }
  if (se.size() != 2) return false;

  char rep = 'A';
  if (se.count(rep)) rep = 'B';
  if (se.count(rep)) rep = 'C';

  string nstr = "";
  for (int i = 0; i < str.size(); ++i) {
    if (!isABC[i]) nstr += str[i];
    else {
      nstr += rep;
      i += 2;
    }
  }
  //cout << str << " -> " << nstr << endl;

  return solve(nstr);
}

int main() {
  string str;
  while (cin >> str) {
    if (solve(str)) puts("Yes");
    else puts("No");
  }
}


Measured memory_bytes: 21984
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    map<char, int> cnt;
    rep(i,h)rep(j,w){
        char c;
        cin >> c;
        cnt[c]++;
    }
    int two = 0, fou = 0;
    for(auto p : cnt){
        int num = p.second;
        while(num > 1){
            if(num == 2 || num == 3){
                two++;
                break;
            }
            fou++;
            num -= 4;
        }
    }
    bool yes = true;
    int fou_need = (h/2) * (w/2);
    int two_need = ((h+1)/2) * ((w+1)/2) - fou_need;
    if(h%2 == 1 && w%2 == 1) two_need--;
    if(fou_need > fou) yes = false;
    else two += (fou - fou_need) * 2;
    if(two_need > two) yes = false;
    if(yes) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}

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

int main() {
	int n,k;
	cin >> n >> k;
	string s[110];
            string ans;
	for(int i=0;i<n;i++) cin >> s[i];
	sort(s,s+n);
	for(int i=0;i<n;i++) ans += s[i];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, x, y, G[100005];
vector <int> v[100005];
int dfs(int x, int pa){
	for (int i=0; i<v[x].size(); i++)
		if(v[x][i]!=pa)
			G[x]^=(dfs(v[x][i], x)+1);
	if(!v[x].size())return 1;
	else return G[x];
}
int main(){ 
	cin>>n;n--;
	while(n--)cin>>x>>y, v[x].push_back(y), v[y].push_back(x);
	if(dfs(1, 1))cout<<"Alice";
	else cout<<"Bob";
}

Measured memory_bytes: 12416
n = int(input())
dat_a = map(int, input().split())
dat_a = list(dat_a)
d1 = d2 = d4 = 0
for i in range(n):
    if dat_a[i] % 4 == 0:
        d4 += 1
    elif dat_a[i] % 2 == 0:
        d2 += 1
    else:
        d1 += 1
if d2 == 0:
    if d4 >= d1 - 1:
        print("Yes")
    else:
        print("No")
else:
    if d4 >= d1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 62704
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();
		int count = 0;
		for( int i=0; i<=N-3; i++ ){
			char ch1 = S.charAt(i);
			char ch2 = S.charAt(i+1);
			char ch3 = S.charAt(i+2);
			if( ch1=='A' && ch2=='B' && ch3=='C' ){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
s = gets.chomp

res = 0

s.length.times do |n1|
  (s.length - n1).times do |n2|
    str = s[n1..(s.length - n2)]
    if str.tr("ATCG", "").empty?
      res = str.length if res < str.length
    end
    #i)f str.include?("A") && str.include?("T") && str.include?("C") && str.include?("G"
      #p "y"
    #end
  end
end
puts res

Measured memory_bytes: 1788
/**
 *    author: Behradm
 *    Created: 13-05-2020 20:26:51
 *    In the Name of God
**/
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5+1;
int a[maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	map<int, int> m;
	int n, k, q;
	cin >> n >> k >> q;
	for (int i = 0; i < q; i++) {
		cin >> a[i];
		if (m.find(a[i]) == m.end())
			m[a[i]] = 1;
		else
			m[a[i]]++;
	}

	for (int i = 0; i < n; i++) {
		if (k - q + m[i + 1] <= 0)
			cout << "No\n";
	  else
			cout << "Yes\n";
	}
	return 0;
}




Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
int n,m,p1,p2,p3,vis[100001],ans;
vector<int> arr[100001];
void dfs(int cur,int pre) {
    vis[cur]=1;
    for (int i=0; i<arr[cur].size(); i++) {
        if (arr[cur][i]==pre or vis[arr[cur][i]]) continue;
        dfs(arr[cur][i],cur);
    }
}
int main() {
    cin>>n>>m;
    for (int i=0; i<m; i++) {
        cin>>p1>>p2>>p3; p1--; p2--;
        arr[p1].push_back(p2);
        arr[p2].push_back(p1);
    }
    for (int i=0; i<n; i++) {
        if (!vis[i]) {dfs(i,-1); ans++;}
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 13924
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
ll N;
int main() {

	cin>>N;

	ll T=1,nn=N,S=0;
	while(nn/10){
		nn/=10;
		T*=10;
		S+=9;
	}
	if((nn+1)*T-1<=N){
		S+=nn;
	}else{
		S+=(nn-1);
	}

	cout<<S<<endl;
 	return 0;
}


Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,k;
    cin>>n>>k;
    queue<ll> q;
    rep(i,k){
        ll x;
        cin>>x;
        q.push(x);
    }
    rep3(i,k,n){
        ll x;
        cin>>x;
        ll y=q.front();
        q.pop();
        q.push(x);
        if(x>y){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 4776
// https://atcoder.jp/contests/agc027/tasks/agc027_c
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}


fn has_cycle(graph: Vec<Vec<usize>>) -> bool {
    let n = graph.len();
    let mut indeg = vec![0; n];
    for i in 0..n {
        for &j in graph[i].iter() {
            indeg[j] += 1;
        }
    }

    let mut deq = VecDeque::new();
    let mut cnt = 0;
    for i in 0..n {
        if indeg[i] == 0 {
            deq.push_back(i);
            cnt += 1;
        }
    }

    while deq.len() >= 1 {
        let u = deq.pop_front().unwrap();
        for &j in graph[u].iter() {
            indeg[j] -= 1;
            if indeg[j] == 0 {
                deq.push_back(j);
                cnt += 1;
            }
        }
    }
    return cnt != n;
}

fn main() {
    input! {
        n: usize, m: usize,
        s: chars,
        edges: [(usize1, usize1); m]
    };


    let mut snum = vec![0; n];
    for i in 0..n {
        if s[i] == 'B' {
            snum[i] = 1;
        }
    }

    let mut graph = vec![vec![]; n];
    for &(u, v) in edges.iter() {
        if u == v {
            graph[u].push(v);
        } else {
            graph[u].push(v);
            graph[v].push(u);
        }
    }

    let mut dgraph = vec![vec![]; 2*n];
    for i in 0..n {
        for &t in graph[i].iter() {
            // i*2(R,R) -> t*2(R,B)
            // i*2+1(B,R) -> t*2(R,B)
            let tt = t*2 + (snum[i] ^ snum[t] ^ 1);
            if snum[t] == snum[i] {
                dgraph[i*2].push(tt);
            }
            if snum[t] != snum[i] {
                dgraph[i*2+1].push(tt);
            }
        }
    }

    if has_cycle(dgraph) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 49336
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N;
	char c[101];
	while(scanf("%d",&N),N) {
		int num[10]={0},f=0;
		scanf("%s",c);
		for(int i=0;c[i]!='\0';i++) {
			if(c[i]=='M') {
				num[i%N]++;
			}else if(c[i]=='S') {
				f+=(num[i%N]+1);
				num[i%N]=0;
			}else {
				num[i%N]+=(f+1);
				f=0;
			}
		}
		sort(num,num+N);
		printf("%d",num[0]);
		for(int i=1;i<N;i++) {
			printf(" %d",num[i]);
		}
		printf(" %d\n",f);
	}
}

Measured memory_bytes: 1052
#include <stdio.h>
#include <limits.h>

long c = 0;

void merge(long *a, long left, long mid, long right){
  long n1, n2, i, j, k;
  n1 = mid - left;
  n2 = right - mid;
  long l[n1 + 1], r[n2 + 1];
  for(i = 0; i < n1; ++i) l[i] = a[left + i];
  for(i = 0; i < n2; ++i) r[i] = a[mid + i];
  l[n1] = LONG_MAX;
  r[n2] = LONG_MAX;
  i = 0;
  j = 0;
  for(k = left; k < right; ++k){
    if(l[i] <= r[j]) a[k] = l[i++];
    else a[k] = r[j++];
    c++;
  }
}

void merge_sort(long *a, long left, long right){
  if(left + 1 < right){
    long mid = (left + right) / 2;
    merge_sort(a, left, mid);
    merge_sort(a, mid, right);
    merge(a, left, mid, right);
  }
}

int main(){
  long n, s[500000], i, j;
  scanf("%ld", &n);
  for(i = 0; i < n; ++i) scanf("%ld", s + i);

  merge_sort(s, 0, n);

  for(i = 0; i < n; ++i) printf(i != 0 ? " %ld" : "%ld", s[i]);
  printf("\n%ld\n", c);
  return 0;
}

Measured memory_bytes: 8412
#include<stdio.h>

int main(){
int m,f,r,sum;
while(1){
scanf("%d %d %d",&m,&f,&r);
if(m==-1 && f==-1 && r==-1)break;
sum=m+f;

if(m==-1 || f==-1){
printf("F");
}else if(sum>=80){
printf("A");
}else if(sum>=65){
printf("B");
}else if(sum>=50){
printf("C");
}else if(sum>=30){
    if(r>=50){printf("C");
    }else printf("D");
}else printf("F");

printf("\n");

}
return 0;
}

Measured memory_bytes: 1000
n = int(input())
a_input = sorted(list(map(int,input().split())))
x = 10**9+7

if n%2==0:#1,1,3,3,5,5...
    tmp = 1
    for i in range(0,n,2):
        if a_input[i]==a_input[i+1] and tmp==a_input[i]:
            tmp+=2
        else:
            print(0);exit()

else:#0,2,2,4,4,6,6
    tmp=2
    for i in range(1,n-1,2):
        if a_input[i]==a_input[i+1] and tmp==a_input[i]:
            tmp+=2
        else:
            print(0);exit()

print(pow(2,n//2,x))

Measured memory_bytes: 14008
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

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

int main()
{
	string s;
	cin>>s;
	ll n=s.size();
	vector<vector<ll> > dp(4,vector<ll>(n+1,0LL));
	dp[3][n]=1LL;
	for(int i = n-1; i >= 0; i--){
		dp[3][i] = (s[i]=='?'?3LL:1LL)*dp[3][i+1];
		dp[3][i]%=mod;
		ll x,y;
		y = (s[i]=='?'?3LL:1LL);
		for(int j = 0; j < 3; j++){
			x = ((s[i]=='?'||s[i]-'A'==j)?1LL:0LL);
			dp[j][i] = x*dp[j+1][i+1] + y*dp[j][i+1];
			dp[j][i]%=mod;
		}
	}

	// for(int i = 0; i < 4; i++){
	// 	for(int j = 0; j <= n; j++){
	// 		cout << dp[i][j] << "   ";
	// 	}printf("\n");
	// }

	cout << dp[0][0] << endl;


	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], n, m, v[N];
long long cnt[N][2];
vector<int> G[N];
int p1, p2, len;
long long dfs(int x, int p = 0, int d = 0) {
	++ cnt[x][d & 1];
	long long res = 0;
	for (int u : G[x]) {
		if (u == p) continue;
		if (x == p1 && u == p2) continue;
		if (x == p2 && u == p1) continue;
		res += dfs(u, x, d + 1);
		cnt[x][0] += cnt[u][0];
		cnt[x][1] += cnt[u][1];
		res += abs(cnt[u][0] - cnt[u][1]);
	}
	return res;
}
void dfs2(int x, int p = 0) {
	v[x] = v[p] + 1;
	for (int u : G[x]) {
		if (u == p) continue;
		if (v[u]) {
			p1 = x;
			p2 = u;
			len = v[x] - v[u] + 1;
		}
		else dfs2(u, x);
	}
}
long long calc(long long x) {
	memset(cnt, 0, sizeof(cnt));
	cnt[p1][0] += x;
	cnt[p2][1] += x;
	return dfs(1) + abs(x);
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		scanf("%d%d", &u, &v);
		a[i] = u, b[i] = v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if (m == n - 1) {
		long long ans = dfs(1);
		if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
		printf("%lld\n", ans);
	}
	else {
		dfs2(1);
		dfs(1);
		if (len & 1) {
			if (abs(cnt[1][0] - cnt[1][1]) & 1) return 0 * puts("-1");
			long long del = (cnt[1][0] - cnt[1][1]) / 2;
			memset(cnt, 0, sizeof(cnt));
			cnt[p1][0] -= del;
			cnt[p2][0] -= del;
			long long ans = dfs(1) + abs(del);
			printf("%lld\n", ans);
		}
		else {
			if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
			long long l = - 1e9, r = 1e9, ans = 1e18;
			while (l + 10 <= r) {
				long long midl = (l + r) / 2;
				long long midr = (midl + r) / 2;
				long long res1 = calc(midl);
				long long res2 = calc(midr);
				ans = min(ans, res1);
				ans = min(ans, res2);
				if (res1 < res2) {
					r = midr - 1;
				}
				else {
					l = midl + 1;
				}
			}
			for (int i = l; i <= r; ++ i) ans = min(ans, calc(i));
			printf("%lld\n", ans);
		}
	}
}



Measured memory_bytes: 16256
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))
INF = float("inf")
V, E, r = inpl()

edges = [inpl() for _ in range(E)]

def belman_ford(V, edges, r):
    D = [INF]*(V)
    D[r] = 0
    if V == 1:
        return [0], [False]
    
    for _ in range(V):
        update = False
        for s, t, d in edges:
            if D[t] > D[s] + d:
                D[t] = D[s] + d
                update = True
        if not update:
            break
    else:
        NEGATIVE = [False]*(V)
        for s, t, d in edges:
            if D[t] > D[s] + d:
                D[t] = D[s] + d
                NEGATIVE[t] = True
                NEGATIVE[s] = True
        return D, NEGATIVE
                
    return D, [False]*(V)
    
D, NEGATIVE = belman_ford(V, edges, r)

if any(NEGATIVE):
    print("NEGATIVE CYCLE")
else:
    for d in D:
        print("INF") if d == INF else print(d)


Measured memory_bytes: 6020
package main

import (
	"fmt"
)

// main is ...
func main() {
	const (
		aCode  = 65
		zCode  = 90
		aZDiff = 26
	)
	var n rune // int32
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)

	for _, r := range s {
		if r+n > 'Z' {
			fmt.Printf("%c", r+n-aZDiff)
			continue

		}

		// rune
		fmt.Printf("%c", r+n)
	}
}



Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,f[50] = {2};
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)
		f[i] = f[i - 1] * 2 + 2;
	cout << f[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    int n;
    cin>>n;
    int d[n];
    rep(i,n) cin>>d[i];
    sort(d, d+n);
    int ans=d[n/2]-d[n/2-1];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))
D=[]
for i in range(N):
    D.append(0)
for i in range(N):
    for j in range(M):
        D[i]+=A[i][j]*B[j]
    D[i]+=C
e=0
for i in range(len(D)):
    if D[i]>0:
        e+=1
print(e)

Measured memory_bytes: 9176