akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
	int N;
	int A[200000];
	int i;
	scanf("%d",&N);
	for(i=0; i<N; i++){
		scanf("%d",&A[i]);
	}

	qsort(A, N, sizeof(int),asc );
	
	for(i=1; i<N; i+=2){
		if((A[i]==A[i-1]) || (A[i]==A[i+1])){ printf("NO\n"); return 0;}
	}
	if( A[N]==A[N-1] ){ printf("NO\n"); return 0;}
	printf("YES\n"); return 0;


}	

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

struct Problem {

    void Solve() {
        UL S, W; cin >> S >> W;
        if (S <= W) cout << "unsafe";
        else cout << "safe";
        cout << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    //cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}


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

int main()
{
    string S;
    cin >> S;
    if (S.size() % 2 != 0)
    {
        cout << "No" << endl;
    }
    else
    {
        rep(i, S.size())
        {
            if (S.at(i) != 'h')
            {
                cout << "No" << endl;
                return 0;
            }
            i++;
            if (S.at(i) != 'i')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if (X < 600)
            System.out.println("8");
        else if(X < 800)
            System.out.println("7");
      	else if(X < 1000)
            System.out.println("6");
      	else if(X < 1200)
            System.out.println("5");
      	else if(X < 1400)
            System.out.println("4");
      	else if(X < 1600)
            System.out.println("3");
      	else if(X < 1800)
            System.out.println("2");
      	else if(X < 2000)
            System.out.println("1");
    }
}

Measured memory_bytes: 35652
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int a,b,c,sum,max,ans;
	int dim[5];
	cin>>a>>b>>c;
	dim[0]=a,dim[1]=b,dim[2]=c;
	sort(dim,dim+3);
	sum=a+b+c;
	max=dim[2];
	for(int i=0;;i++){
		int temp=(max+i)*3;
		if((temp-sum)%2==0){
			ans=(temp-sum)/2;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
int main() {
string s;
cin>>s;
bool a;

for(int i = 0; i<s.size();i++){
	if((s[2]==s[3])&& (s[4]==s[5])){
		a = true;
	}

	else{
		a = false;
	}
}
if (a==true){
    cout<<"Yes";
}
else{
    cout<<"No";
}
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int q = int.Parse(Console.ReadLine());

            for (int i = 0; i < q; i++)
            {
                string order = Console.ReadLine();
                string[] orderdata = order.Split(' ');
                int a = int.Parse(orderdata[1]);
                int b = int.Parse(orderdata[2]);
               
                switch(orderdata[0])
                {
                    case "print":
                        string printout = str.Substring(a, b-a+1);
                        Console.WriteLine(printout);

                        break;
                    case "reverse":
                        string change = str.Substring(a, b-a+1);
                        char[] temp = change.ToCharArray();
                        Array.Reverse(temp);
                        string middle = new string(temp);
                        str = str.Remove(a, b - a + 1);
                        str = str.Insert(a,middle);

                        break;
                    case "replace":
                        string p = orderdata[3];
                        str = str.Remove(a,b-a+1);
                        str = str.Insert(a, p);

                        break;                    
                }
            }



        }
    }
}

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

int main()
{
  ll n,i;
  cin>>n;
  ll h[n],ans[n];
  for(i=0;i<n;i++) cin>>h[i];
 
  for(i=0;i<n;i++) 
  {
   if(i<3) ans[i]=abs(h[i]-h[0]);
   else
   {
   ans[i]=min(ans[i-1]+abs(h[i-1]-h[i]),
              ans[i-2]+abs(h[i-2]-h[i]));
    
   }
  }
  cout<<ans[n-1]<<endl;
}


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

string S;
vector<char> DP[50][51];//[i][j]:=[i,j)????????§???

bool isnumber(int l, int r){
    if(r-l>=2&&S[l]=='0') return false;
    for(int i=l;i<r;i++){
        if(!(isdigit(S[i])||S[i]=='?')) return false;
    }
    return true;
}

vector<char> number(int l, int r){
    vector<char> ret(0);
    if(isnumber(l,r)){
        for(int i=l;i<r;i++){
            ret.push_back((S[i]=='?'?'9':S[i]));
        }
    }
    return ret;
}

vector<char> segment(int l, int r){
    auto comp = [](const vector<char>& A, const vector<char>& B){
        if(A.size()<B.size()) return true;
        else if(A.size()>B.size()) return false;
        else{
            for(int i=0;i<A.size();i++){
                if(A[i]>B[i]) return false;
                else if(A[i]<B[i]) return true;
            }
            return true;
        }
    };
    vector<char> ret=number(l,r);
    if(ret.size()) return ret;
    if(r-l>=6&&(S[l]=='R'||S[l]=='L'||S[l]=='?')&&(S[l+1]=='('||S[l+1]=='?')&&(S[r-1]==')'||S[r-1]=='?')){
        for(int i=l+3;i<r-2;i++){
            if(S[i]==','||S[i]=='?'){
                if(DP[l+2][i].size()&&DP[i+1][r-1].size()){
                    if(S[l]=='R')ret=max(ret,DP[i+1][r-1],comp);
                    if(S[l]=='L')ret=max(ret,DP[l+2][i],comp);
                    if(S[l]=='?')ret=max({ret,DP[l+2][i],DP[i+1][r-1]},comp);
                }
            }
        }
    }
    return ret;
}

int main(){
    cin>>S;
    for(int len=1;len<=S.size();len++){
        for(int i=0;i+len<=S.size();i++){
            DP[i][i+len]=segment(i,i+len);
            // cout<<'['<<i<<") : "<< DP[i][i+len]<<endl;
        }
    }
    if(DP[0][S.size()].size()){
        // cout<<DP[0][S.size()]<<endl;
        for(auto c:DP[0][S.size()]) cout<<c;
        cout<<endl;
    }else{
        cout<<"invalid"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    vector<vector<ll>> g(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll ans = 0;
    rep(i, n) {
        bool f = true;
        for(auto x : g[i]) {
            if (h[i] <= h[x]) {
                f = false;
                break;
            }
        }
        if (f) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9796
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n){
    cin >> p.at(i);
  }

  sort(all(p));

  int sum =0;

  rep(i,k){
    sum = sum + p.at(i);
  }

  cout << sum << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;
bool check[1000];
int arr[1000];
int main(){
    int diff=0, max=0, maxl=0, y=1, temp=0, minl=INT_MAX;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(check[s[i]]==false){
            check[s[i]]=true;
            diff++;
        }
        arr[s[i]]++;
        if(arr[s[i]]>max){
            max=arr[s[i]];
        }
    }
    if(diff==1){
        cout << maxl << endl;
    }
    else if(diff==s.size()){
        maxl=s.size()/2;
        cout << maxl << endl;
    }
    else{
        for(int i='a'; i<='z'; i++){
                for(int j=0; j<s.size(); j++){
                    if(s[j]!=i){
                        temp++;
                    }
                    else{
                        if(maxl<temp){
                            maxl = temp;
                        }
                        temp=0;
                    }
                }
                if(maxl<temp){
                    maxl=temp;
                }
                minl=min(maxl, minl);
            temp=0;
            maxl=0;
        }
        maxl = s.size()/2;
        cout << min(maxl, minl) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define in std::cin
#define out std::cout
#define endl std::endl
typedef long long int ll;
int main() {
	int n;
	in >> n;
	if (n % 2 == 0) out <<n<< endl;
	else out<<2*n<<endl;
	
}

Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    K = int(input())
    A, B = [int(item) for item in input().split()]

    for i in range(A, B+1):
        if i % K == 0:
            print('OK')
            break
    else:
        print('NG')

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9180
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
int dp[101][1 << 16];
void init() {
	rep(i, 101) {
		rep(j, 1 << 16) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	return;
}
int main() {
	int n;
	while (cin >> n, n) {
		init();
		P man[100] = {};
		int s, e, m, l;
		rep(i, n) {
			cin >> m >> l;
			man[i].second = l;
			rep(j, m) {
				cin >> s >> e;
				Rep1(k, s - 6, e - 7) {
					man[i].first += (int)(pow(2, k)+0.001);
				}
			}
		}
		rep(i, n) {
			int nx = man[i].first;
			per(j, (1 << 16)) {
				if (dp[i][j] == -1)continue;
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				bool f = true;
				rep(k, 16) {
					if ((nx&(1<<k))&&(j&(1<<k))){
						f = false;
					}
				}
				if (!f)continue;
				dp[i + 1][nx + j] = max(dp[i + 1][nx + j], dp[i][j] + man[i].second);
			}
		}
		int ma = -1;
		rep(i, 1 << 16) {
			ma = max(ma, dp[n][i]);
		}
		cout << ma << endl;
	}
	return 0;
}


Measured memory_bytes: 28956
using namespace std;
#include<iostream>
#include<vector>
int N,M;
int ans=1;
const int maxW=100001;
const int maxN=101;


long DP[maxW];
long w[maxN];
long v[maxN];


int main(){
    int N,W;
    int a,b;
    cin >> N >> W;  
    for(int i = 1; i<= N;i++){
        cin >> a >> b; 
        w[i]=a;
        v[i]=b;
    }
    for(int wj = 0; wj <=W; wj++){
        DP[wj] = 0; 
    }

    for(int i = 1; i<= N; i++){
        for(int wj = W; wj >= w[i]; wj--){
            DP[wj] = max(DP[wj], DP[wj - w[i]] + v[i]);  
        }
    }
    cout << DP[W] << endl;

}

Measured memory_bytes: 1024
import copy
n = int(input())

bit = 0
n_sub = n
while n_sub > 0:
  bit += 1
  n_sub //= 10

index = 0
key = [(3, 1), (5, 2), (7, 3)]

for i in range(1, bit):
  last = len(key)
  for j in range(index, last):
    k1, k2 = key[j][0], key[j][1]
    if k2 == 1:
      key.append((k1*10+3, 1))
      key.append((k1*10+5, 4))
      key.append((k1*10+7, 5))
    if k2 == 2:
      key.append((k1*10+3, 4))
      key.append((k1*10+5, 2))
      key.append((k1*10+7, 6))
    if k2 == 3:
      key.append((k1*10+3, 5))
      key.append((k1*10+5, 6))
      key.append((k1*10+7, 3))
    if k2 == 4:
      key.append((k1*10+3, 4))
      key.append((k1*10+5, 4))
      key.append((k1*10+7, 7))
    if k2 == 5:
      key.append((k1*10+3, 5))
      key.append((k1*10+5, 7))
      key.append((k1*10+7, 5))
    if k2 == 6:
      key.append((k1*10+3, 7))
      key.append((k1*10+5, 6))
      key.append((k1*10+7, 6))
    if k2 == 7:
      key.append((k1*10+3, 7))
      key.append((k1*10+5, 7))
      key.append((k1*10+7, 7))
  index = last

ans = 0
for value in key:
  v1, v2 = value[0], value[1]
  if v2 == 7 and v1 <= n:
    ans += 1
print(ans)

Measured memory_bytes: 6628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(x);
    in(y);

    rep(t, 51) {
        rep(k, 26) {
            if (t * 2 + k * 4 == y && t + k == x) {
                out("Yes");
                return 0;
            }
        }
    }
    out("No");
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
n = input()
result = sum(map(int, n))
acc = 0
for i, c in enumerate(n):
    if int(c):
        result = max(result, acc + (int(c) - 1) + (len(n) - i - 1) * 9)
    acc += int(c)
print(result)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <unordered_set>

int64_t f(int64_t num)
{
  int64_t ret = 1;
  for (int i = 0; i < 5; ++i)
  {
    ret *= num;
  }
  return ret;
}

int main()
{
  int64_t x;
  std::cin >> x;
  int64_t a = 1;
  int64_t b = 0;
  while(f(a) - f(b) != x && f(a) + f(b) != x)
  {
    if (f(a) - f(b) > x)
    {
      ++b;
    }
    else if (f(a) - f(b) < x && f(a) + f(b) > x)
    {
      ++a;
    }
    else
    {
      if (2 * f(a) < x)
      {
        ++a;
      }
      else
      {
        int64_t tmp = b;
        bool isOK = false;
        while(tmp < a && f(a) + f(tmp) < x)
        {
          ++tmp;
          if (f(a) + f(tmp) == x)
          {
            b = tmp;
            isOK = true;
            break;
          }
        }
        if (isOK == false)
        {
          ++a;
        }
      }
      
    }
  }
  if (f(a) - f(b) == x)
  {
    std::cout << a << " " << b << std::endl;
  }
  else
  {
    std::cout << a << " " << -b << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 3624
// AOJ Volume 1 Problem 0108

#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	int array[13], array_next[13];
	int freq[100], freq_next[100];
	int step;
	int flag;
	int i;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		memset(freq, 0, sizeof(freq));
		for (i = 1; i <= n; i++){
			scanf("%d", &array[i]);
			freq[array[i]]++;
		}
		
		step = 0;
		while (1){
			memset(freq_next, 0, sizeof(freq_next));
			for (i = 1; i <= n; i++){
				array_next[i] = freq[array[i]];
				freq_next[array_next[i]]++;
			}
		
			if (memcmp(array, array_next, sizeof(array)) == 0){
				break;
			}
			step++;
			memcpy(array, array_next, sizeof(array));
			memcpy(freq, freq_next, sizeof(freq));
		}
		
		printf("%d\n", step);
		flag = 0;
		for (i = 1; i <= n; i++){
			if (flag == 1){
				printf(" ");
			}
			flag = 1;
			printf("%d", array[i]);
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    val (k, n) = readIntList()
    val a = readIntList()
    val kukan = Array(n) { 0 }

    for (i in 0 until n - 1) kukan[i] = a[i + 1] - a[i]
    kukan[n - 1] = k - a[n - 1] + a[0]
    println(k - kukan.max()!!)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 82908
#include <bits/stdc++.h>
using namespace std;
//素数判定の引用元https://qiita.com/asksaito/items/76b71602dd956b79dbf7
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main() {
    int x;
    cin >> x;
    while(1){
        if(IsPrime(x)){
            cout << x << endl;
            return 0;
        }
        x++;
    }
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
mo = 1000000007
A_val = 1
for i in range(A):
    A_val = ((A_val * (N - i) * pow(i+1, mo-2, mo))) % mo
B_val = 1
for i in range(B):
    B_val = ((B_val * (N - i) * pow(i+1, mo-2, mo))) % mo
    
ans = (pow(2, N, mo) - 1 - A_val - B_val) % mo
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;

    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll ans = 0;
    ll res = K;
    ll a = min(K, A);
    ans += a;
    res -= a;
    if (res == 0) {
        cout << ans << endl;
        return 0;
    }

    ll b = min(res, B);
    res -= b;
    if (res == 0) {
        cout << ans << endl;
        return 0;
    }

    ans += -1 * res;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3588
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x))

const int N(20);
char s[N];
int ans = 0;

int main()
{
	scanf("%s", s); int len = strlen(s);
	for(RG int i = 0; i < len; i++)
	{
		int cnt = 0;
		for(RG int j = i; j < len; j++)
			if(s[j] == 'A' || s[j] == 'G' || s[j] == 'C' || s[j] == 'T')
				++cnt;
			else break;
		ans = std::max(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
/* ex3_1
  terakura */

#include <stdio.h>

int main(void){

    int a, b, c = 0;

    scanf("%d %d", &a, &b);

  //aをbで割った商が0になるまで繰り返す
    while(a>0){
      a = a/b;    //aにaをbで割った商を代入
      c++;    //cに１をたす
    }

    printf("%d\n", c);    //桁数を出力

    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

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

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

vector<int> get_pf(const string& s) {
    int n = (int) s.length();
    vector<int> pi (n);
    for (int i=1; i<n; ++i) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }
    return pi;
}

vector<int> get_goodness(const string& s) {
    vector<int> result(s.size() + 1, 0);
    auto pf = get_pf(s);
    for (int i = 2; i <= s.size(); ++i) {
        result[i] = int(pf[i - 1] > 0 && (i % (i - pf[i - 1])) == 0);
    }
    return result;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    int n = s.size();
    {
        bool is_all_one_c = true;
        for (int i = 1; i < n && is_all_one_c; ++i) {
            if (s[i] != s[0]) is_all_one_c = false;
        }
        if (is_all_one_c) {
            cout << n << "\n" << 1 << "\n";
            return 0;
        }
    }
    // vector<int> pref_good(n + 1, false), suff_good(n + 1, false);
    auto pref_good = get_goodness(s);
    reverse(s.begin(), s.end());
    auto suff_good = get_goodness(s);
    // cout << pref_good << suff_good;
    /*
    for (int k = 1; k < n; ++k) {
        // if (n % k > 0) continue;
        if (!suff_good[k]) {
            for (int st_i = k; st_i + k <= n; ++st_i) {
                if (st_i == k || suff_good[st_i]) {
                    suff_good[st_i + k] = true;
                    for (int i = 0; i < k && suff_good[st_i + k]; ++i) {
                        if (s[n - 1 - i] != s[n - 1 - st_i - i]) suff_good[st_i + k] = false;
                    }
                }
            }
        }
        if (!pref_good[k]) {
            for (int st_i = k; st_i + k <= n; ++st_i) {
                if (st_i == k || pref_good[st_i]) {
                    pref_good[st_i + k] = true;
                    for (int i = 0; i < k && pref_good[st_i + k]; ++i) {
                        if (s[i] != s[st_i + i]) pref_good[st_i + k] = false;
                    }
                }
            }
        }
    }
    // cout << pref_good << suff_good;
    */
    if (!suff_good[n]) {
        cout << "1\n1";
    } else {
        cout << "2\n";
        int ans = 0;
        for (int l = 1; l < n; ++l) {
            if (!pref_good[l] && !suff_good[n - l]) ++ans;
        }
        cout << ans;
    }
}


Measured memory_bytes: 9644
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>

using namespace std;

/*3^N - すべて奇数*/

int main() {
	int N, A[10];
	int ans, odd;

	scanf("%d", &N);
	for (int i=0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	ans = 1;
	for (int i = 0; i < N; i++) {
		ans = ans * 3;
	}
	odd = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) {
			odd = odd * 2;
		}
	}
	ans = ans - odd;
	printf("%d\n", ans);
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<Set<Integer>> list = new ArrayList<Set<Integer>>();
		for (int i = 0; i < M; i++) {
			int k = sc.nextInt();
			Set<Integer> set = new HashSet<Integer>();
			for (int j = 0; j < k; j++) {
				set.add(sc.nextInt());
			}
			list.add(set);
		}
		int p[] = new int[M];
		for (int i = 0; i < M; i++) {
			p[i] = sc.nextInt();
		}
		int pattern = (int) (Math.pow(2, N));
		int result = 0;
		for (int i = 0; i < pattern; i++) {
			if (Main.check(i, list, p) == true) {
				result++;
			}
		}
		System.out.print(result);
	}

	public static boolean check(int pattern, List<Set<Integer>> list, int p[]) {
		boolean b = true;
		for (int i = 0; i < p.length; i++) {
			Set<Integer> set = list.get(i);
			int num = 1;
			int count = 0;
			int temp = pattern;
			while (temp > 0) {
				if (temp % 2 == 1) {
					if (set.contains(num) == true) {
						count++;
					}
				}
				temp /= 2;
				num++;
			}
			if (count % 2 != p[i]) {
				return false;
			}
		}
		return true;

	}
}

Measured memory_bytes: 37160
local N = io.read("n")
local A = {}
local S = {}
for i=1,N do
    local n = io.read("n")
    A[i] = n
    if not S[n] then
        S[n] = 0
    end
    S[n] = S[n] + 1
end
table.sort(A)

local function target(r)
    local r2 = r + 1
    local t = 2
    while t < r2 do
        t = t * 2
    end
    return t, t - r
end

local ans = 0
for i=N,2,-1 do
    local r = A[i]
    local t, c = target(r)
    local hit = false
    if S[r] > 0 then
        S[r] = S[r] - 1
        if S[c] and S[c] > 0 then
            ans = ans + 1
            S[c] = S[c] - 1
            hit = true
        end
    end
    --print(r, t, c, hit)
end
print(ans)

Measured memory_bytes: 17372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int A[8][8]; //  i <-> j
int N, M;

int main() {

	cin >> N >> M;

	rep(i, N)
		rep(j, N)
	{
		A[i][j] = 0;
	}

	rep(i, M){
		int a, b;
		cin >> a >> b;
		a--; b--;
		A[a][b] = 1;
		A[b][a] = 1;
	}

	int ret = 0;

	vector<int> v;
	rep(i, N){ v.push_back(i); }
	do {
		if (v[0] != 0) continue;

		bool success = true;
		rep(i, N - 1){ success &= (A[v[i]][v[i + 1]] == 1); }
		if (success) ret += 1;

	} while (next_permutation(v.begin(), v.end()));     // 次の順列を生成

	cout << ret << endl;

}

Measured memory_bytes: 256
using System;
 
public class Test
{
  public static void Main(string[] args){
    var n = int.Parse(Console.ReadLine());
    var s = Console.ReadLine();
    
    if(n % 2 != 0){
      Console.WriteLine("No");
      return;
    }
    
    var a = s.Substring(0, n/2);
    var b = s.Substring(n/2);
    
    if(a == b){
      Console.WriteLine("Yes");
    }else{
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define mst(a, b) memset(a, b, sizeof(a))
typedef long long LL;
const int N = 150 + 10;

//int sg[N][N];
//
//int getSG(int x, int y) {
//    if (x == 0 && y == 0 || x == 1 && y == 0 || x == 0 && y == 1)
//        return 0;
//    if (~sg[x][y])
//        return sg[x][y];
//    bool vis[N];
//    mst(vis, false);
//    for (int i = 1; 2 * i <= x; i++)
//        vis[getSG(x - i * 2, y + i)] = true;
//    for (int i = 1; 2 * i <= y; i++)
//        vis[getSG(x + i, y - i * 2)] = true;
//    for (int i = 0; ; i++) if (!vis[i])
//        return sg[x][y] = i;
//}

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
#endif // LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);

//    mst(sg, -1);
//
//    for (int i = 0; i <= 10; i++) {
//        for (int j = 0; j <= 10; j++) if (!getSG(i, j))
//            cout << i << " " << j << "\n";
//    }

    LL x, y;

    cin >> x >> y;

    if (abs(x - y) <= 1)
        cout << "Brown" << "\n";
    else
        cout << "Alice" << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;
ll dp;

int main(){
   ll n,k,ans=0,a,b,c,d;
   string s;
   
   map<string,int> m{};

   cin>>a>>b;

   if(a<=b)cout<<"unsafe";
   else cout<<"safe ";
   cout<<endl;;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    set<int>dc;
    int b=3;
    forn(i,0,2)
    {
        int a;
        cin>>a;
        dc.insert(a);
    }
    if(dc.size()==1)cout<<"Yes";
    else cout<<"No";




     return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
x,y=gets.split.map!(&:to_i)
s=Array.new(y)
c=Array.new(y)
dame=0
ame=0
ans=Array.new(x,0)
if x>1
  ans[0]=1
end
for i in 0..y-1
  s[i],c[i]=gets.split.map!(&:to_i)
  if s[i]==1 && c[i]==0
    ame=1
  else
    ans[s[i]-1]=c[i]
  end
end
for i in 0..y-1
  for j in 0..y-1
    if s[i]==s[j]
      if c[i]!=c[j]
        dame=1
      end
    end
  end
end
if dame==1 || ame==1
  if x==1 && dame==0
    puts 0
  else
    puts -1
  end
else
  for k in 0..x-1
  print(ans[k])
  end
end


Measured memory_bytes: 14300
N = int(input())
W = [str(input()) for i in range(0, N)]

done = 0
for idx, i in enumerate(W[1:], 1):
    if W[idx - 1][len(W[idx - 1]) - 1] != i[0]:
        break
    done += 1

if done + 1 == len(W) and len(set(W)) == len(W):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <cstdio>
#include <queue>
#include <algorithm>

struct qwq {
    int a,b;
    inline bool operator<(const qwq &x) const {
        return a<x.a;
    }
}x[100005];

std::priority_queue<int>q;

int main() {
    int n,m,i,j=1,s=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d%d",&x[i].a,&x[i].b);
    std::sort(x+1,x+n+1);
    for(i=1;i<=m;i++) {
        for(;x[j].a==i&&j<=n;j++)q.push(x[j].b);
        if(!q.empty()) {s+=q.top();q.pop();}
    }
    printf("%d",s);
    return 0;
}



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

using namespace std;

const int N = 4010;

int b[N][N];
int a[N];

int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i + n] = a[i];
  }
  for (int i = 0; i < n + n; i++) {
    b[i][i] = a[i];
    for (int j = i + 1; j < n + n; j++) {
      b[i][j] = min(b[i][j - 1], a[j]);
    }
  }
  long long ans = (long long) 1e18;
  for (int sp = 0; sp < n; sp++) {
    long long cur = sp * 1LL * x;
    for (int i = 0; i < n; i++) {
      cur += b[i][i + sp];
    }
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 45440
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for s in range(0, N):
    si = input()
    if si == 'AC':
        AC += 1
    elif si == 'WA':
        WA += 1
    elif si == 'TLE':
        TLE += 1
    elif si == 'RE':
        RE += 1
print('AC x {}'.format(AC))
print('WA x {}'.format(WA))
print('TLE x {}'.format(TLE))
print('RE x {}'.format(RE))


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int d[30][30];
int a[500][500];
int dp[3][30];
vector<P> v[3];
int main()
{
    int n, c;
    cin >> n >> c;
    rep(i, c)
    {
        rep(j, c)
        {
            cin >> d[i][j];
        }
    }
    rep(i, n)
    {
        rep(j, n)
        {
            cin >> a[i][j];
        }
    }
    rep(i, n)
    {
        rep(j, n)
        {
            dp[(i + j) % 3][a[i][j] - 1]++;
        }
    }
    rep(i, 3)
    {
        rep(j, c)
        {
            int t = 0;
            rep(k, c)
            {
                t += dp[i][k] * d[k][j];
            }
            v[i].push_back(P(t, j));
        }
        sort(v[i].begin(), v[i].end());
    }
    int mn = 1e9;
    rep(i, 3)
    {
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (v[0][i].second == v[1][j].second || v[2][k].second == v[1][j].second || v[0][i].second == v[2][k].second)
                    continue;
                mn = min(mn, v[0][i].first + v[1][j].first + v[2][k].first);
            }
        }
    }
    cout << mn << endl;
}

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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; int N, M; cin >> N >> M;
  vi H(N); FORE(i,H)cin>>i;
  mi E(N);
  int a,b;
  REP(i,M){
    cin>>a>>b;--a,--b;
    E[a].PB(b);E[b].PB(a);
  }
  int ans = 0;
  REP(i,N){
    int ok = 1;
    FORE(j,E[i])if(H[j]>=H[i]){ok=0;break;}
    ans += ok;
  }
  cout << ans << endl;
}


Measured memory_bytes: 8724
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];
ll a[N];

int main() {
    FAST;
    ll n,i,j;
    cin>>n;
    string s;
    cin>>s;

    vector<ll> r,g,b;
    Ff(i,0,n)
    {
        if(s[i]=='R')
        r.pb(i);
        if(s[i]=='G')
        g.pb(i);
        if(s[i]=='B')
        b.pb(i);
    }
    ll ans=0;
    Ff(i,0,n){
        Ff(j,i+1,n)
        {
            if(s[i]!=s[j])
            {
                if(s[i]!='B' && s[j]!='B')
                {
                    auto itr=upper_bound(all(b),j);
                    auto itr1=--b.end();
                    ans+=itr1-itr+1;
                    if(binary_search(all(b),2*j-i))
                    ans--;
                }
                else if(s[i]!='G' && s[j]!='G')
                {
                    auto itr=upper_bound(all(g),j);
                    auto itr1=--g.end();
                    ans+=itr1-itr+1;
                    if(binary_search(all(g),2*j-i))
                    ans--;
                }
                else{
                    auto itr=upper_bound(all(r),j);
                    auto itr1=--r.end();
                    ans+=itr1-itr+1;
                    if(binary_search(all(r),2*j-i))
                    ans--;
                }
            }
        }
        
    }
    cout<<ans;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main(){
  int A,B;
  cin >> A >> B;

  int ports = 1;
  int taps = 0;
  
  if(B == 1){
    cout << 0;
    return 0;
  }
  
  for(int i=1;i<=20;i++){
    taps++;
    ports = ports -1 + A;
    if(ports >= B){break;}
  }
  cout << taps;
    
  // 1  2
  // 2  2-1+2 = 3
  // 3  3 -1 +2 = 4
  // 1  A
  // 2  (A)-1+A = 2A -1
  // 3  (2A -1) - 1 + A = 3A -2  
  
}


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



int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main(){

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


long long int n,m;
cin >> n>>m;
int c=0;
if(n>1){
c=n*(n-1)/2;
}else{
c=0;
}
int d=0;
if(m>1){
d=m*(m-1)/2;
}else{
d=0;
}

cout <<c+d<< endl;

}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = [1]
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
g.reverse()
for i in range(len(g)):
    if g[i] == g[i + mod]:
        d = i
        break
if k <= n:
    for i in range(k):
        q.append(s)
        s = a[s-1]
    q.reverse()
    print(q[0])
else:
    print(g[d+(k-d)%mod])

Measured memory_bytes: 32272
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

vector<ll> evaluation(vector<ll>& C, vector<vector<ll>>& S, vector<ll>& T) {
  ll D = T.size();
  vector<ll> res(D, 0);
  vector<ll> last(26, 0);
  ll score = 0;
  for (ll i = 0; i < D; ++i) {
    ll contest = T.at(i) - 1;
    last.at(contest) = i + 1;
    score += S.at(i).at(contest);
    for (ll j = 0; j < 26; ++j) {
      score -= (i + 1 - last.at(j)) * C.at(j);
    }
    res.at(i) = score;
  }
  return res;
}

int main() {
  ll D;
  cin >> D;
  vector<ll> C(26), T(D);
  vector<vector<ll>> S(D, vector<ll>(26));
  for (ll i = 0; i < 26; ++i) {
    cin >> C.at(i);
  }
  for (ll i = 0; i < D; ++i) {
    for (ll j = 0; j < 26; ++j) {
      cin >> S.at(i).at(j);
    }
  }
  for (ll i = 0; i < D; ++i) {
    cin >> T.at(i);
  }
  vector<ll> ans = evaluation(C, S, T);
  for (ll i = 0; i < ans.size(); ++i) {
    cout << ans.at(i) << "\n";
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    vector<int> a(N),b(N);
    rep(i,N) cin>>a[i];
    rep(i,N) cin>>b[i];
    //a[i]<=b[j]はいつか到達できる、猶予の回数はb[j]-a[i];
    //a[i]>b[j]があった時、a[i]<=b[j]の猶予の回数を用いて一致させる(ただし、a[i],b[i]についてa[i]のみ+2をするので猶予の回数/2が一致操作回数)
    //この猶予の回数を使い切ってしまったとき、一致させることが出来ない
    ll ocnt=0;
    ll tcnt=0;
    rep(i,N){
        if(a[i]<=b[i]) ocnt+=(b[i]-a[i])/2;
        else tcnt+=a[i]-b[i];
    }
    if(ocnt>=tcnt) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}


Measured memory_bytes: 384
//
// Ford-Fulkerson's maximum flow 
// 
// Description:
//   Given a directed network G = (V, E) with edge capacity c: E->R.
//   The algorithm finds a maximum flow. 
//
// Algorithm:
//   Ford-Fulkerson's augmenting path algorithm
//
// Complexity:
//   O(m F), where F is the maximum flow value.
// 
// Verified:
//   AOJ GRL_6_A: Maximum Flow
//
// Reference:
//   B. H. Korte and J. Vygen (2008):
//   Combinatorial Optimization: Theory and Algorithms.
//   Springer Berlin Heidelberg. 
//

#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())

const int INF = 1 << 30;
struct graph {
  typedef long long flow_type;
  struct edge {
    int src, dst;
    flow_type capacity, flow;
    size_t rev;
  };
  int n;
  vector<vector<edge>> adj;
  graph(int n) : n(n), adj(n) { }
  void add_edge(int src, int dst, flow_type capacity) {
    adj[src].push_back({src, dst, capacity, 0, adj[dst].size()});
    adj[dst].push_back({dst, src, 0, 0, adj[src].size()-1});
  }
  int max_flow(int s, int t) {
    vector<bool> visited(n);
    function<flow_type(int,flow_type)> augment = [&](int u, flow_type cur) {
      if (u == t) return cur;
      visited[u] = true;
      for (auto &e: adj[u]) {
        if (!visited[e.dst] && e.capacity > e.flow) {
          flow_type f = augment(e.dst, min(e.capacity - e.flow, cur));
          if (f > 0) {
            e.flow += f;
            adj[e.dst][e.rev].flow -= f;
            return f;
          }
        }
      }
      return flow_type(0);
    };
    for (int u = 0; u < n; ++u)
      for (auto &e: adj[u]) e.flow = 0;

    flow_type flow = 0;
    while (1) {
      fill(all(visited), false);
      flow_type f = augment(s, INF);
      if (f == 0) break;
      flow += f;
    }
    return flow;
  }
};

int main() {
  for (int n, m; scanf("%d %d", &n, &m) == 2; ) {
    graph g(n);
    for (int i = 0; i < m; ++i) {
      int u, v, w;
      scanf("%d %d %d", &u, &v, &w);
      g.add_edge(u, v, w);
    }
    printf("%d\n", g.max_flow(0, n-1));
  }
}

Measured memory_bytes: 3324
/*input
1422

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

map<ll, int> mp;

int fun(ll n) {
  if (n == 0) return 0;
  if (n == 1) return 1;
  if (mp.count(n)) return mp[n];
  int ans = 0;
  if (n % 2 == 0)
    ans = add(ans, mul(2, fun(n / 2)) + fun(n / 2 - 1));
  else
    ans = add(ans, mul(2, fun(n / 2)) + fun(n / 2 + 1));
  return mp[n] = ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin >> n;
  int ans = fun(n + 1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int p, q, r;
    cin >> p >> q >> r;
    cout << min({p + q, p + r, q + r}) << endl;
    return 0;
    
}


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

using namespace std;

int main(void) {
    long n, p;
    cin >> n >> p;

    vector<pair<long, long>> a;

    for (long i = 2; i * i <= p; i++) {
        if (p % i != 0) continue;

        long c = 0;
        while (p % i == 0) {
            c++;
            p /= i;
        }

        a.push_back({i, c});
    }

    if (p != 1) a.push_back({p, 1});

    long ans = 1;

    for (auto& e: a) if (e.second >= n) ans *= pow(e.first, e.second / n);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
_, K = map(int, input().split())
S = input()

offset = not (int(S[0]) ^ (K & 1))
runs = []

prev = S[0]
run = 0
for c in S:
    if c != prev:
        runs.append(run)
        run = 0
    prev = c
    run += 1
runs.append(run)

L = len(runs)
candidates = []

prev = sum(runs[max(0, offset - K): min(L, offset + K + 1)])
answer = prev

for i in range(offset + 2, L, 2):
    now = prev
    old_left = i - 2 - K
    new_right = i + K
    if old_left >= 0:
        now -= runs[old_left]
    if old_left + 1 >= 0:
        now -= runs[old_left + 1]
    if new_right - 1 < L:
        now += runs[new_right - 1]
    if new_right < L:
        now += runs[new_right]
    prev = now
    if prev > answer:
        answer = prev

print(answer)


Measured memory_bytes: 4340