akhauriyash/Code-Regression huggingface dataset:
from collections import deque

def main():
    N, Q = [int(i) for i in input().split()]
    Ts = deque([])

    for _ in range(N):
        name, time = [i for i in input().split()]
        Ts.append({
            "name": name,
            "time": int(time)
        })

    cur_t = 0

    while len(Ts):
        task = Ts.popleft()

        # 終わらない
        if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t)


main()



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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

int main(){
    string s;
    cin >> s;
    
    string one = "R";
    string two = "RR";
    string three = "RRR";

    if(s.find(three)!=string::npos)
        cout << 3;
    else if(s.find(two)!=string::npos)
        cout << 2;
    else if(s.find(one)!=string::npos)
        cout << 1;
    else
        cout << 0;
}


Measured memory_bytes: 3608
import math

N,D = map(int,input().split())
X = [[0 for i in range(D)] for j in range(N)]
for i in range(N):
  X[i] = list(map(int,input().split()))


count = 0
for i in range(N):
    for j in range(N - i - 1):
        k = N - j - 1
        L = 0
        for num in range(D):
            L += (X[i][num]-X[k][num])**2
        L = math.sqrt(L)
        if L.is_integer()==True:
            count += 1
print(int(count))            

Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int A,B,T;
    private void solve() {
        A = nextInt();
        B = nextInt();
        T = nextInt();

        out.println(T / A * B);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21076
# ABC_173_C_H_and_V.py

H,W,K=list(map(int, input().split()))
A=[list(input()) for _ in range(H)]
# print(A)

# bitDP2回ぶん回せば行けるのでは？
# bitが1は残す方で

ans=0
for i in range(1,2**H):
    for j in range(1,2**W):
        resx=[]
        resy=[]
        ct=0
        for k in range(H):
            if (i>>k)&1:
                resx.append(k)
        for l in range(W):
            if (j>>l)&1:
                resy.append(l)
        # print(resx,resy)
        B=[[A[k][l] for l in resy] for k in resx]
        for k in range(len(resx)):
            ct+=B[k].count('#')
        # print(ct)
        if ct==K:
            ans+=1
print(ans)

Measured memory_bytes: 74868
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;
ll mod = 1e9+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

int main(){
  ll N, H;
  cin >> N >> H;
  int blade = -1;
  priority_queue<int> q;
  rep(i, N){
    int a, b;
    cin >> a >> b;
    blade = max(blade, a);
    q.push(b);
  }

  int ans = 0;
  while(!q.empty() && q.top() >= blade && H > 0){
    H -= q.top(); q.pop();
    ans++;
  }

  H = max(0LL, H);

  ans += (int)ceil((1.0*H) / (1.0*blade));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 892
a,b,k=map(int,input().split())
li=[]
for i in range(a,a+k):
    if a<=i<=b:
        li.append(i)
for i in range(b-k+1,b+1):
    if a<=i<=b:
        li.append(i)
li=sorted(set(li))
for i in li:
    print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    string s, t;
    cin >> s >> t;
    rep (s.length() + 1) {
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
        rotate(s.begin(), s.begin() + 1, s.end());
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
ans = 0
for i in range(2):

  if A > 3 and A >= B:
    ans += A
    A -= 1
    continue

  if B > 3 and B > A:
    ans += B
    B -= 1
    continue
  
  if A == 3 and B == 3:
    ans += A

print(ans)




Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

int cnt;
int l;
int A[1000000];
int n;
std::vector<int> G;

void insertionSort(int A[], int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	for (int h=1; ; ) {
		if (h > n) {
			break;
		}
		G.push_back(h);
		h = 3*h + 1;
	}

	for (int i = G.size()-1; i >=0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main() {
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	cnt = 0;

	shellSort(A, n);

	std::cout << G.size() << std::endl;

	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) {
		printf("%d\n", A[i]);
	}

	return 0;
}




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

#define ll long long
#define pii pair<int, int>
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    string S, T;
    cin >> S;
    cin >> T;

    int ans = 0;
    REP(i, 3) {
        if (S.at(i) == T.at(i)) ans += 1;
    }

    print(ans);
}

signed main() {
    solve();
}


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

long long int N, ans[101];

int main(){
    for(int x = 0; x < 26; ++x){
        for(int y = 0; y < 15; ++y){
            if(4 * x + 7 * y <= 100) // 100を超えていなかったら
                ans[4 * x + 7 * y] = 1;
        }
    }
    cin >> N;
    puts(ans[N] ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

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

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

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

    int count = 0;
    for(i = 1; i < n-1; i++){
        if(v[i-1] < v[i] && v[i] < v[i+1]){
            count++;
        }else if(v[i-1] > v[i] && v[i] > v[i+1]){
            count++;
        }
    }

    cout << count << endl;
}

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

int main() {
  int MOD = 1000000007;
  int n; cin>>n;
  ll sum=0,ans=0;
  vector<ll> a(n);
  rep(i,n) {
    cin>>a[i];
    sum+=a[i];
    sum%=MOD;
  }

  rep(i,n-1) {
    sum-=a[i];
    if(sum<0) sum+=MOD;
    ans+=a[i]*sum%MOD;
    ans%=MOD;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------
void Main(){
  int n,k;
  cin>>n>>k;
  vl h(n);
  cin>>h;
  sort(rng(h));
  ll ans =1e10;
  rep(i,n-k+1){
    mins(ans,h[k-1+i]-h[i]);
  }
  cout<<ans;
} int main(int argc,char** argv)
{fastio; myio; Main();}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;

int main()
{
	int N, K; cin >> N >> K;
	vector<int> P(N);
	for (int i = 0; i < N; ++i) {
		cin >> P[i];
	}
	sort(P.begin(), P.end());
	int sum = 0;
	for (int i = 0; i < K; ++i) {
		sum += P[i];
	}
	cout << sum << endl;
}



Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n;  cin >> n;
    vector<int>a(n);
    rep(i, n)   cin >> a[i];
    vector<vector<ll> >dp(n+1, vector<ll>(n+1));  //dp[i][j] := [i,j)
    for(int k = 1; k <= n; k++){
        for(int l = 0; l <= n-k; l++){
            int i = l;
            int j = k + l;
            if((n-(j-i)+1) % 2 == 1){
                dp[i][j] = max(dp[i][j-1] + a[j-1], dp[i+1][j] + a[i]);
            }else{
                dp[i][j] = min(dp[i][j-1] - a[j-1], dp[i+1][j] - a[i]);
            }
        }
    }
    cout << dp[0][n] << endl;
}


Measured memory_bytes: 70784
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int dp[N], inD[N];

class GLongestPath {
public:
    int dfs(int u) {
        if (dp[u] != -1) return dp[u];
        int res = 1;
        for (int v: adj[u]) {
            res = max(res, 1 + dfs(v));
        }
        return dp[u] = res;
    }

    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        for (int i = 0; i < m; ++i) {
            int u, v;
            in >> u >> v;
            adj[u].push_back(v);
            inD[v]++;
        }
        memset(dp, -1, sizeof dp);
        int res = 1;
        for (int i = 1; i <= n; ++i) if (inD[i] == 0) res = max(res, dfs(i));
        out << res - 1;
    }
};


int32_t main() {
    GLongestPath solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 11008
require 'prime'

n = gets.chomp.to_i

# 階差数列
# 2 ** 45 > 10 ** 12(= nの最大値)だから45まで用意
# 2 ** 45の2は素数の最小値
arr = [1, 3, 6, 10, 15, 21, 28, 36, 45]

# 素因数分解
# pdは[[p1, p1の指数], [p2, p2の指数], ... ]のような形
pd = n.prime_division

# n = p1^e1 * p2^e2 * ... のようにしたとき
# p1^1), p1^2, ... でnを順番に割っていきたい
result = 0
pd.each do |(p, exp)|
#  # 階差数列を利用して exp -> p^iでnを順番に割れる個数に変換
#  # ex) exp = 7 なら p^1, p^2, p^3 の3回で割れる. p^4では割れない
#  result += arr.index{|a| a > exp}
i = 1
cnt = 0
while exp > 0 do
  exp -= i
  i += 1
  cnt += 1 if exp >= 0
end
result += cnt
end

puts result


Measured memory_bytes: 14420
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int n, x ;
  cin >> n >> x ;
  vector<int> vec(n) ;
  vector<int> sum(n+1) ;
  sum.at(0) = 0 ;
  int count = 0 ;
  
  REP(i, n){
    cin >> vec.at(i) ;
  }
  REP(i, n){
    sum.at(i+1) = sum.at(i) + vec.at(i) ;
  }
  REP(i,n+1){
    if(sum.at(i)<=x){
      count++ ;
    }
  }
  
  cout << count <<endl ;
  
  
    return 0 ;
}




Measured memory_bytes: 256
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 10003, maxM = 20003, maxT = 80003;
int a[maxN][2];
pair<int, int> ha[maxM];

int cntNode, id[maxT];
vector<int> g[maxT];
#define lSon (k << 1)
#define rSon (k << 1 | 1)
#define mid ((l + r) >> 1)
inline void build(int k, int l, int r) {
    if (l == r) {
        id[k] = ha[l].second;
        return ;
    }
    id[k] = ++cntNode;
    build(lSon, l, mid), g[id[k]].push_back(id[lSon]);
    build(rSon, mid + 1, r), g[id[k]].push_back(id[rSon]);
}
inline void modify(int k, int l, int r, int from, int x, int y) {
    if (x <= l && r <= y) {
        g[from].push_back(id[k]);
        return ;
    }
    if (x <= mid)
        modify(lSon, l, mid, from, x, y);
    if (mid < y)
        modify(rSon, mid + 1, r, from, x, y);
}
#undef lSon
#undef rSon
#undef mid

int stk[maxT], top, dfn[maxT], low[maxT], tim, belong[maxT], cntSCC;
void tarjan(int x) {
    stk[++top] = x, dfn[x] = low[x] = ++tim;
    for (int y : g[x])
        if (!dfn[y])
            tarjan(y), low[x] = min(low[x], low[y]);
        else
            if (!belong[y])
                low[x] = min(low[x], dfn[y]);
    if (dfn[x] == low[x]) {
        int y;
        ++cntSCC;
        do
            y = stk[top--], belong[y] = cntSCC;
        while (y != x);
    }
}

int main() {
    int n = read(), m = n << 1, i, j, l, r, mid, x, y, z;
    for (i = 1; i <= n; ++i) {
        a[i][0] = read(), ha[i] = make_pair(a[i][0], i + n);
        a[i][1] = read(), ha[i + n] = make_pair(a[i][1], i);
    }
    sort(ha + 1, ha + m + 1);
    
    l = 0, r = ha[m].first - ha[1].first;
    while (l < r) {
        mid = (l + r + 1) >> 1;
        
        for (i = 1; i <= cntNode; ++i)
            g[i].clear();
        top = 0;
        memset(dfn + 1, 0, sizeof(int) * cntNode), tim = 0;
        memset(belong + 1, 0, sizeof(int) * cntNode), cntSCC = 0;
        cntNode = m, build(1, 1, m);
        for (i = 1; i <= n; ++i)
            for (j = 0; j < 2; ++j) {
                x = lower_bound(ha + 1, ha + m + 1, make_pair(a[i][j] - mid + 1, 0)) - ha;
                z = lower_bound(ha + 1, ha + m + 1, make_pair(a[i][j], (j ^ 1) * n + i)) - ha;
                y = upper_bound(ha + 1, ha + m + 1, make_pair(a[i][j] + mid - 1, m)) - ha - 1;
                if (x < z)
                    modify(1, 1, m, j * n + i, x, z - 1);
                if (z < y)
                    modify(1, 1, m, j * n + i, z + 1, y);
            }
        for (i = 1; i <= cntNode; ++i)
            if (!dfn[i])
                tarjan(i);
        for (i = 1; i <= n; ++i)
            if (belong[i] == belong[i + n])
                break;
        
        i > n ? l = mid : r = mid - 1;
    }
    
    printf("%d\n", l);
    return 0;
}


Measured memory_bytes: 11264
import sys, re
from collections import deque, defaultdict, Counter
from math import log10, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()

dp = (0, 1)  # 左:ちょうど  右:1だけ多い
for i in N:
	i = int(i)
	dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i))
print(dp[0])


Measured memory_bytes: 16468
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

if A_list.count(0) > 0:
    print(0)
else:
    ans = 1
    for i in range(N):
        ans *= A_list[i]
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)

Measured memory_bytes: 21644
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.14159265358979323846264338327950L
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;
using Graph = vector<vector<int>>;


int main() {

	int X, Y;

	cin >> X >> Y;

	if ((floor((Y - 2 * X) / 2.0) == (Y - 2 * X) / 2.0 && (Y - 2 * X) / 2.0>=0)&&((4*X-Y)/2>=0 && floor((4 * X - Y) / 2.0)== (4 * X - Y) / 2.0)){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+2;
const int inf=1e9+7;
struct Dinic 
{
   int n, s, t;
   struct Edge 
   {
      int to, cap, flow, rev;
      Edge(int to = 0, int cap = 0, int flow = 0, int rev = 0) :
         to(to), cap(cap), flow(flow), rev(rev) {}
   };
   vector <int> d;
   vector <int> ptr;
   vector<vector<Edge>> g;
 
   Dinic(int n = 0, int s = 0, int t = 0) :
      n(n), s(s), t(t), d(n + 2), ptr(n + 2), g(n + 2) {}
   void addEdge(int u, int v, int cap) 
   {
      g[u].emplace_back(v, cap, 0, g[v].size());
      g[v].emplace_back(u, 0, 0, g[u].size() - 1);
   }
 
   bool bfs() 
   {
      fill(d.begin(), d.end(), -1);
      fill(ptr.begin(), ptr.end(), 0);
 
      queue <int> q;
      d[s] = 0;
      q.push(s);
      while (!q.empty()) 
      {
         int u = q.front();
         q.pop();
         for (auto e : g[u]) 
         {
            if (d[e.to] == -1 && e.cap > e.flow) 
            {
               d[e.to] = d[u] + 1;
               q.push(e.to);
            }
         }
      }
      return d[t] != -1;
   }
 
   int dfs(int u, int flow) 
   {
      if (u == t) 
      {
         return flow;
      }
      for (int &i = ptr[u]; i < (int)g[u].size(); i++) 
      {
         auto &e = g[u][i];
         if (e.cap <= e.flow || d[e.to] != d[u] + 1) 
            continue;
         int nxt = dfs(e.to, min(flow, e.cap - e.flow));
         if (nxt) 
         {
            e.flow += nxt;
            g[e.to][e.rev].flow -= nxt;
            return nxt;
         }
      }
      return 0;
   }
   int maxFlow() 
   {
      int ans = 0;
      while (bfs()) 
      {
         while(true)
         {
            int now = dfs(s, inf);
            if (now) ans += now;
            else break;
         }
      }
      return ans;
   }
};
int p[N],q[N],a[N],b[N];
bool used[N],used1[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	int sz1=0,sz2=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>p[i]; p[i]++;
	}
	for(i=1;i<=n;i++){
		cin>>q[i]; q[i]++;
	}
	for(i=1;i<=n;i++){
		if(!used[i]){
			used[i]=true; j=p[i]; sz1++; a[i]=sz1;
			while(j!=i){
				used[j]=true; a[j]=sz1; j=p[j];
			}
		}
	}
	for(i=1;i<=n;i++){
		if(!used1[i]){
			used1[i]=true; j=q[i]; sz2++; b[i]=sz2;
			while(j!=i){
				used1[j]=true; b[j]=sz2; j=q[j];
			}
		}
	}
	int s=sz1+sz2+1,t=sz1+sz2+2,ans=n;
	Dinic aanh(t,s,t);
	for(i=1;i<=n;i++){
		if(p[i]==i&&q[i]==i){
			ans--;
		}
		else{
			if(p[i]==i){
				aanh.addEdge(sz1+b[i],t,1);
			}
			else{
				if(q[i]==i){
					aanh.addEdge(s,a[i],1);
				}
				else{
					aanh.addEdge(sz1+b[i],a[i],1);
					if(p[i]==q[i]){
						aanh.addEdge(a[i],sz1+b[i],1);
					}
				}
			}
		}
	}
	cout<<ans-aanh.maxFlow();
}

Measured memory_bytes: 16796
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//template<typename A, size_t N, typename T>
//void Fill(A(&array)[N], const T &val) {
	//std::fill((T*)array, (T*)(array + N), val);
//}

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

class UnionFind
{
public:
	UnionFind(ll size) : parent(size), rank(size) {
		for (ll i = 0; i < size; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	};

	ll root(ll x) {
		if (parent[x] == x) {
			return x;
		}
		else {
			return parent[x] = root(parent[x]);
		}
	}

	bool same(ll x, ll y) {
		return root(x) == root(y);
	}

	void unite(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return;

		if (rank[x] < rank[y]) {
			parent[x] = y;
		}
		else {
			parent[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}

private:
	//parent[i]==j  : iの親がj
	vector<ll> parent;
	vector<ll> rank;

};

//解法
void solve() {

	ll N, M;
	cin >> N >> M;

	UnionFind UF(N);

	rep(i, M) {
		ll X, Y, Z;
		cin >> X >> Y >> Z;
		X--; Y--;

		UF.unite(X, Y);
	}

	vector<bool> vec(N,false);
	ll ans = 0;

	rep(i, N) {
		ll top = UF.root(i);
		if (vec[top] == false) {
			vec[top] = true;
			ans++;
		}
	}

	cout << ans;
}

int main() {

	//入力

	solve();
	cout << endl;
	return 0;
}


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

long long hcf(long long a, long long b)
{
	if(a==b)
		return a;
	else if(a>b)
		return hcf(a-b,b);
	else
		return hcf(a,b-a);
}

int main()
{
	long long int a,b,x,ans;
	cin >> a >> b;
	x = hcf(a,b);
	cout << (a*b)/x << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
typedef pair<ll,mp> mmp;

ll n;
ll a,b,c;
vector<ll> q;

vector<char> ans;
vector< set<mmp> > e;
bool flag = false;

void func(ll i,ll aa,ll bb, ll cc){
 if( flag ) return;
 if( i==n ){
  cout<<"Yes"<<endl;
  for(auto i:ans)cout<<i<<endl;
  flag = true;
  return;
 }
 /*if( e[i].find(mmp(aa,mp(bb,cc) ) ) != e[i].end() ) return;
 else {
  e[i].insert( mmp(aa,mp(bb,cc) ) );
 }*/

 if( q[i] == 1 ){//AB
  if( aa == 0 && bb == 0 ) return;
  else if( aa == 0 ){
   ans[i] = 'A';
   func(i+1,aa+1,bb-1,cc);

  }else if( bb == 0 ){
   ans[i] = 'B';
   func(i+1,aa-1,bb+1,cc);
  }else{
   ans[i] = 'A';
   func(i+1,aa+1,bb-1,cc);
   ans[i] = 'B';
   func(i+1,aa-1,bb+1,cc);
  }
 }else if( q[i] == 2 ){//BC
  if( cc == 0 && bb == 0 ) return;
  else if( cc == 0 ){
   ans[i] = 'C';
   func(i+1,aa,bb-1,cc+1);

  }else if( bb == 0 ){
   ans[i] = 'B';
   func(i+1,aa,bb+1,cc-1);
  }else{
   ans[i] = 'C';
   func(i+1,aa,bb-1,cc+1);
   ans[i] = 'B';
   func(i+1,aa,bb+1,cc-1);
  }

 }else{
  
  if( aa == 0 && cc == 0 ) return;
  else if( aa == 0 ){
   ans[i] = 'A';
   func(i+1,aa+1,bb,cc-1);

  }else if( cc == 0 ){
   ans[i] = 'C';
   func(i+1,aa-1,bb,cc+1);
  }else{
   ans[i] = 'A';
   func(i+1,aa+1,bb,cc-1);
   ans[i] = 'C';
   func(i+1,aa-1,bb,cc+1);
  }

 }

}


int main(){
 cin>>n;
 cin>>a>>b>>c;
 q = vector<ll> (n);
 ans = vector<char>(n);
 e = vector<set<mmp> >(n);
 for(ll i=0;i<n;i++){
  string s;
  cin>>s;
  if( s== "AB"){
   q[i] = 1;
  }else if( s == "BC"){
   q[i] = 2;
  }else{
   q[i] = 3;
  }
 }

 func(0,a,b,c);
  if( !flag ) cout<<"No"<<endl;



    return 0;
}


Measured memory_bytes: 18288
#ifndef UNION_FIND_HPP
#define UNION_FIND_HPP

#include <vector>

namespace tklib {

class UnionFind {
private:
    std::vector<int> par;
    int components;

public:
    UnionFind(int n) : par(n, -1), components(n) {}

    bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) {
            return false;
        } else {
            if (par[x] < par[y]) std::swap(x, y);
            par[y] += par[x];
            par[x] = y;
            --components;
            return true;
        }
    }

    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }

    int size(int x) {
        return -par[find(x)];
    }

    int count() {
        return components;
    }
};

} // namespace tklib

#endif // UNION_FIND_HPP


#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    
    tklib::UnionFind uf(n);
    while(q--) {
        int c, x, y;
        cin >> c >> x >> y;
        if(c) cout << (uf.find(x) == uf.find(y) ? 1 : 0) << '\n';
        else uf.unite(x, y);
    }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int64_t a, b, c;
  cin >> a >> b >> c;
  int64_t K=(c-a-b);
  if(K<=0){
    cout << "No" << endl;
    return 0;
  }
  if(4*a*b<K*K){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
dp1,dp2=[0]*(n+1),[0]*(n+1)
from heapq import heappop,heappush
q1,q2=[],[]
for i in range(2*n):
  heappush(q1,a[i])
  heappush(q2,-a[-i-1])
  if i<n:
    dp1[0]+=a[i]
    dp2[-1]+=a[-i-1]
  else:
    dp1[i-n+1]=dp1[i-n]+a[i]-heappop(q1)
    dp2[n-i-2]=dp2[n-i-1]+a[-i-1]+heappop(q2)
print(max([dp1[i]-dp2[i] for i in range(n+1)]))

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

int main(){
    string a, b;
    cin >> a >> b;
    if(a.size() < b.size()){
        cout << "LESS" << endl;
    } else if(a.size() > b.size()){
        cout << "GREATER" << endl;
    } else {
        int i;
        for(i = 0; i < a.size(); i++){
            if(a[i] - '0' > b[i] - '0'){
                cout << "GREATER" << endl;
                return 0;
            } else if (a[i] - '0' < b[i] - '0'){
                cout << "LESS" << endl;
                return 0;
            }
        }
        if(i == a.size()){
            cout << "EQUAL" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
S = input()


l = 0
r = len(S)-1
cnt = 0
while l < r:
    #print(l,r)
    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        if S[l] == "x":
            #末尾にxを追加し削除
            l += 1
            cnt += 1
        elif S[r] == "x":
            r -= 1
            cnt += 1
        else:
            print(-1)
            exit()


print(cnt)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N;
	cin >> N;
	if ('A' <= N && N <= 'Z') cout << 1 << endl;
	else if ('a' <= N && N <= 'z') cout << 2 << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 3120
/**
 * Created by hiramekun at 07:51 on 2020-03-31.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, w;
    cin >> h >> w;
    char a[h][w];
    stack<P> q;
    bool used[h][w];
    rep(i, h) rep(j, w) used[i][j] = false;
    rep(i, h) rep(j, w) {
            cin >> a[i][j];
            if (a[i][j] == '#') {
                q.push(P(i, j));
                used[i][j] = true;
            }
        }
    ll ans = 0;
    while (!q.empty()) {
        stack<P> q2;
        q2 = q;
        q = stack<P>();
        bool plus = false;

        while (!q2.empty()) {
            P now = q2.top();
            q2.pop();
            ll x = now.F, y = now.S;
            rep(i, 4) {
                ll nx = x + dx[i], ny = y + dy[i];
                if (nx < 0 || h - 1 < nx || ny < 0 || w - 1 < ny) continue;
                if (!used[nx][ny]) {
                    if (!plus) ans++, plus = true;
                    used[nx][ny] = true;
                    q.push(P(nx, ny));
                }
            }
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n;
    cin>>n;
    vec<ll> a(n);
    REP(i,n) cin>>a[i];

    ll sum=0;
    REP(i,n) sum^=a[i];
    for(auto &i:a) i&=~sum;//偶数のbitだけかんがえる

    vec<ll> base;
    for(auto &i:a){
        for(auto b:base){
            chmin(i,i^b);
        }
        if(i) base.push_back(i);
    }
    sort(all(base),greater<ll>());

    ll A=0;
    for(auto b:base) chmax(A, A^b);//奇数のみの集合を作る

    ll B=sum^A;
    cout<<A+B<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


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

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define trav(it, a) for(auto& it : a)
#define allin(it, a) for(auto it : a)
#define read(v, a, b) for(int i=(a); i<(b); i++) scanf("%d", &v[i]);
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define db(x) cerr << #x << " == " << x << endl

const int maxn = 1e5 + 100;
const ll inf = 0x3f3f3f3f3f3f3f3f;

void min_self(ll& a, ll b){
	a = min(a, b);
}

int main(){
	int n, W;
	scanf("%d %d", &n, &W);
	int max_value = n * 1000;
	vector<ll> dp(max_value + 1, inf);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		int weight, value;
		scanf("%d %d", &weight, &value);
		for(int value_already = max_value - value; value_already >= 0; --value_already){
			min_self(dp[value_already + value], dp[value_already] + weight);
		}
	}
	for(int i = max_value; i >= 0; i--)
		if(dp[i] <= W){
			printf("%d\n", i);
			return 0;
		}
}


Measured memory_bytes: 1024
//6:48
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
ll max(ll a, ll b){return(a>b)?a:b;}
ll min(ll a, ll b){return(a<b)?a:b;}
ll abss(ll a){return(a<0)?-a:a;}

ll gcd(ll a, ll b){
        if(b > a){
                ll tmp = b;
                b = a;
                a = tmp;
        }
        if(b == 0) return a;
        else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
        ll gcdi = gcd(a,b);
        return a/gcdi*(b);
}

int main(){
        ll N;
        scanf("%lld",&N);
        N -= 6;
        ll ans = 1;
        if(N <= 0){ puts("1"); return 0;}
        ans += (N/11)*2;
        N -= (N/11)*11;
        ans += N/5;
        N -= (N/5)*5;
        if(N != 0)ans++;
        printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <cmath>


using namespace std;

//  ||
// \

int main() {
	int a = 0, b = 0, k = 0;
	cin >> a >> b >> k;
	int min = 0;
	if(a > b) {
		min = b;
	}
	else {
		min = a;
	}
	int cpt = 0;
	int divider = 0;
	for(int i = min; i > 0; i--) {
		if(a % i == 0 && b % i == 0) {
			
			divider = i;
			cpt = cpt + 1;
		}
		if(cpt == k) {
			break;
		}

	}
	cout << divider << endl;
	

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <iostream>

using namespace std;

int main() {
    int W, a, b;
    cin >> W >> a >> b;

    int aw = a + W;
    if (a <= b && b <= aw) {
        cout << 0 << endl;
        return 0;
    }

    int bw = b + W;
    cout << min({abs(a - b), abs(a - bw), abs(aw - b)}) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    int l = sc.nextInt();
    String ans = "YES";
    int[] list = new int[l];
    
    for(int i = 0; i < l; i++){
      list[i] = sc.nextInt();
    }
    
    Arrays.sort(list);
    
    for(int i = 0; i < l-1 ; i++){
      if(list[i]==list[i+1]){
        ans = "NO";
        break;
      }
    }
    
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 67020
#include<stdio.h>
#define ll long long
#define max(p,q)((p)>(q)?(p):(q))
#define MOD 1000000007
#define add(x,k)(x=(x+(t)*(k))%MOD)
ll dp[60][60][5000];
//dp[i][j][k]=i番目までみて、j個未確定で、奇妙さkが確定
int main(){
	int n,kk;
	scanf("%d%d",&n,&kk);
	dp[0][0][0]=1;
	for(int i=0;i<n;i++)for(int j=0;j<=i;j++)for(int k=0;k<1300;k++){
		ll t=dp[i][j][k];
		//自分同士で結ぶ
		add(dp[i+1][j][k+2*j],1);
		//両方使う
		if(j)add(dp[i+1][j-1][k+2*(j-1)],j*j);
		//片方使う
		if(j)add(dp[i+1][j][k+2*j],2*j);
		//使わない
		add(dp[i+1][j+1][k+2*(j+1)],1);
	}
	printf("%lld",dp[n][0][kk]);
}

Measured memory_bytes: 116864
#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, cnt4;
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
	{
		int v;
		scanf("%d", &v);
		if(v % 4 == 0) ++cnt4;
		else if(v % 2 == 0) ++cnt2;
		else ++cnt1;
	}
	if(cnt1 > cnt4 + 1) puts("No");
	else if(cnt1 == cnt4 + 1) puts(cnt2 ? "No" : "Yes");
	else puts("Yes");
	return 0;
}
	

Measured memory_bytes: 3684
# 2019/08/06

s=input()
k=int(input())
ls=len(s)

ans=set(s)
for i in range(2,k+1):
    l=1
    res=s[0:i]
    while l<ls-i+1:
        ans.add(res)
        r=l+i-1
        res=res[1:]+s[r]
        l+=1
    ans.add(res)
ans=sorted(list(ans))
print(ans[k-1])

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

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

const double eps=1e-5;
const int INF=1e9;



int main()
{
    LL n,a,b;
    cin>>n>>a>>b;
    LL ans=0;
    if(n==1)
    {
        if(a==b)
        {
            ans++;
        }
    }
    else
    {
        n-=2;
        if(a<=b)
            ans=(b-a)*n+1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m,l,s,t,jj[16],e[16],INF=1e+9;
int G[300][300],paths[17][17],dp[1<<17][17];
int main(){
	while(true){
		for(int i=0;i<300;i++){
			for(int j=0;j<300;j++){
				G[i][j]=INF;
				if(i==j) G[i][j]=0;
			}
		}
		cin >> n >> m >> l >> s >> t;
		s--;
		if(!n) break;
		for(int i=0;i<m;i++){
			int a,b,c;
			cin >> a >> b >> c;
			a--;b--;
			G[a][b]=c;G[b][a]=c;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					G[j][k]=min(G[j][k],G[j][i]+G[i][k]);
				}
			}
		}
		for(int i=0;i<l;i++){
			cin >> jj[i] >> e[i];
			jj[i]--;
		}
		for(int i=0;i<l;i++){
			for(int j=0;j<l;j++){
				paths[i+1][j+1]=G[jj[i]][jj[j]]+e[j];
				if(i==j) paths[i+1][j+1]=0;
			}
		}
		for(int i=0;i<l;i++){
			paths[0][i+1]=G[s][jj[i]]+e[i];
			paths[i+1][0]=G[s][jj[i]];
		}
		paths[0][0]=0;
		for(int i=0;i<(1<<17);i++){
			for(int j=0;j<17;j++){
				dp[i][j]=INF;
			}
		}
		int ans=0;
		dp[1][0]=0;
		for(int i=0;i<(1<<(l+1));i++){
			for(int j=0;j<l+1;j++){
				if((i&(1<<j))==0) continue;
				for(int k=0;k<l+1;k++){
					if((i&(1<<k))==0) continue;
					dp[i][j]=min(dp[i][j],dp[i-(1<<j)][k]+paths[k][j]);
				}
//				cout <<"       "<< i << " " << j << " " << dp[i][j] << endl;
				if(dp[i][j]+paths[j][0]>t) continue;
				else{
					int tmp=i,hoge=-1;
					while(tmp>0){
						hoge+=(tmp%2);
						tmp/=2;
					}
					ans=max(ans,hoge);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 10216
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

string S;

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

  string A = S.substr(0, 2);
  string B = S.substr(2, 4);

  if ("01" <= A && A <= "12" && "01" <= B && B <= "12") {
    cout << "AMBIGUOUS" << endl;
  } else if ("01" <= A && A <= "12") {
    cout << "MMYY" << endl;
  } else if ("01" <= B && B <= "12") {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }

  return 0;
}

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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a[n],b[n];
  for(ll i=0;i<n;i++) cin >> a[i];
  for(ll i=0;i<n;i++) cin >> b[i];
  ll sum=0;
  ll s[n];
  for(ll i=0;i<n;i++){
    s[i]=a[i]-b[i];
    sum+=s[i];
  }
  if(sum<0) cout << -1 << endl;
  else{
    ll ans=0;
    ll count=0;
    for(ll i=0;i<n;i++){
      if(s[i]<0){
        ans++;
        count+=s[i];
      }
    }
    sort(s,s+n);
    reverse(s,s+n);
    for(ll i=0;i<n;i++){
      if(count>=0) break;
      count+=s[i];
      ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2560
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;

///aとbの最大公約数を求める関数。計算量はO(log min(a, b))
Int Gcd(Int a, Int b) {
	if (a % b == 0)return b;
	else return Gcd(b, a % b);
}

void calc() {

	Int N, M; std::cin >> N >> M;
	Int sum = 0;
	rep(i, M) {
		Int tmp; std::cin >> tmp;
		sum += tmp;
	}
	if (sum > N)std::cout << -1;
	else std::cout << N - sum;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc149/abc149_d.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;

  map<char, int> points;
  // 勝利したときの点
  points.emplace('r', R);
  points.emplace('s', S);
  points.emplace('p', P);
  map<char, char> win;
  // 勝てる手
  win.emplace('s', 'r');
  win.emplace('p', 's');
  win.emplace('r', 'p');

  string t;
  cin >> t;

  // Group化
  vector<vector<char>> o(K, vector<char>(0));
  rep(i, N) { o[i % K].push_back(t[i]); }

  vector<char> org{'r', 's', 'p'};
  ll ans = 0;

  rep(k, K) {
    // 貪欲法
    int sz = o[k].size();
    vector<char> i(sz);
    rep(l, sz) {
      if (l == 0) {
        i[l] = win.at(o[k][l]);
        ans += points.at(i[l]);
      } else if (i[l - 1] == win.at(o[k][l])) {
        if (l < sz - 1) {
          // 同じ手が出せない
          for (char x : org) {
            if (x != win.at(o[k][l]) && x != win.at(o[k][l + 1])) {
              i[l] = x;
              break;
            }
          }
        }
      } else {
        i[l] = win.at(o[k][l]);
        ans += points.at(i[l]);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 5200
def cmb(n, r):
    if n < 2: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N, M = map(int, input().split())

print(cmb(N, 2) + cmb(M, 2))


Measured memory_bytes: 3064