akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 998244353
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



int fac[310000];

int inv(int x){
  if(x==1) return 1;
  return (M-M/x)*inv(M%x)%M;
}


int comb(int n,int k){
  if(n<k) return 0;
  int x=(fac[k]*fac[n-k])%M;
  return (fac[n]*inv(x))%M;
}

int fac_init(int n){
  fac[0]=1;
  FOR(i,1,n+1){
    fac[i]=fac[i-1]*i;
    fac[i]%=M;
  }
}

main(){

  int n,k;
  cin>>k>>n;
  fac_init(100000);

  FOR(i,2,2*k+1){
    int res=0;
    int q=i;
    if(q>k+1) q=(k+1)*2-q;
    int a=q/2;
    rep(i,a+1){
      if(!(k-a+n-i-1>=0&&n-i>=0)) continue;

      int t=comb(a,i)*comb(k-a+n-i-1,n-i)%M;
      res+=t;
      res%=M;
    }

    cout<<res<<endl;
  }

}


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

using namespace std;
 
int main()
{
  string x;
 
  cin >> x;
 
   
  while ( x != "0")
    {
 
      int sum = 0;
   
      for ( int i = 0; i < (int)x.size(); i++)
        {
          sum += x[i] - '0';
        }
      cout << sum << endl;
      cin >> x;
    }
   
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    S.pop_back();
    while(true){
        if(S.size()%2 != 0){
            S.pop_back(); continue;
        }
        int h = S.size()/2;
        if(S.substr(0, h) == S.substr(h, h)){
            cout << S.size() << endl;
            return 0;
        }
        S.pop_back();
    }
    return 0;
}




Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True, end="")

sx,sy,tx,ty=LI()

for i in range(abs(ty-sy)):
	pf("U")

for i in range(abs(sx-tx)):
	pf("R")

for i in range(abs(ty-sy)):
	pf("D")
	
for i in range(abs(sx-tx)):
	pf("L")

pf("L")

for i in range(abs(ty-sy)):
	pf("U")
pf("U")
pf("R")

for i in range(abs(sx-tx)):
	pf("R")
	
pf("D")

pf("R")

for i in range(abs(ty-sy)):
	pf("D")
pf("D")
pf("L")
for i in range(abs(tx-sx)):
	pf("L")
pf("U")

Measured memory_bytes: 6464
def f(X,Y):
    return abs(X[0]-Y[0])+abs(X[1]-Y[1])

inf=float("inf")
N,M=map(int,input().split())

P=[]
for _ in range(N):
    a,b=map(int,input().split())
    P.append((a,b))

Q=[("*","*")]
for _ in range(M):
    c,d=map(int,input().split())
    Q.append((c,d))

S=[]
for X in P:
    D=inf
    J=0
    for k in range(1,M+1):
        if D>f(X,Q[k]):
            D=f(X,Q[k])
            J=k

    S.append(J)

print("\n".join(map(str,S)))


Measured memory_bytes: 70124
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define pi pair<int,int>
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VEC() vector<ll int>v
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    ll int n,mod=1e9+7,sum=0,x,res=0;
    cin>>n;
  vector<ll int>v;
  for(int i=0;i<n;i++)
  {
      cin>>x;
      sum+=x;
      v.pb(x);
  }
  for(int i=0;i<n-1;i++)
  {
      res%=mod;
      sum-=v[i];
      x=sum%mod;
      res+=x*v[i];
  }
  cout<<res%mod<<endl;

}


Measured memory_bytes: 5340
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx")
#include <bits/stdc++.h>

namespace {
    template<int n, typename T>
    void mult(const T *__restrict a, const T *__restrict b, T *__restrict res) {
        if (n <= 64) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    res[i + j] += a[i] * b[j];
                }
            }
        } else {
            const int mid = n / 2;
            alignas(64) T btmp[n], E[n] = {};
            auto atmp = btmp + mid;
            for (int i = 0; i < mid; i++) {
                atmp[i] = a[i] + a[i + mid];
                btmp[i] = b[i] + b[i + mid];
            }
            mult<mid>(atmp, btmp, E);
            mult<mid>(a + 0, b + 0, res);
            mult<mid>(a + mid, b + mid, res + n);
            for (int i = 0; i < mid; i++) {
                const auto tmp = res[i + mid];
                res[i + mid] += E[i] - res[i] - res[i + 2 * mid];
                res[i + 2 * mid] += E[i + mid] - tmp - res[i + 3 * mid];
            }
        }
    }
}

using ll = long long;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    const int NMAX = (1 << 11)*49;
    alignas(64) static ll a[NMAX], b[NMAX * 2];
    int n; ll k; std::cin >> n >> k;
    for (int i = 0, val; i < n; i++) {
        std::cin >> val;
        a[val]++;
    }
    mult<NMAX>(a,a,b);
    ll answ(0);
    for (int i = 2 * NMAX - 1; k > 0 && i >= 0; i--) {
        answ += std::min(k, b[i]) * i;
        k -= b[i];
    }
    std::cout << answ << std::endl;
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    ll n,p;
    cin>>n>>p;
    ll e=0,o=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a%2==0)e++;
        else o++;
    }
    if(p%2==1){
        if(o==0)cout<<0<<endl;
        else{
            ll q = (ll)pow(2,e);
            if(o==1)cout<<q<<endl;
            else{
                ll r = (ll)pow(2,o);
                r/=2;
                cout<<q*r<<endl;
            }
        }
    }
    else{
        ll q = 0,r=0;
        q = (ll)pow(2,e);
        if(o>1)r = (ll)pow(2,o);
        r/=2;
        if(o<=1)cout<<q<<endl;
        else cout<<q*r<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(void){
    long int N,M,i,cnt=0;
    scanf("%ld%ld",&N,&M);
    long int A[N][2];
    for(i=0;i<N;i++) scanf("%ld%ld",&A[i][0],&A[i][1]);
    qsort(A,N,sizeof(A[0]),compare_int);
    for(i=0;i<N;i++){
        if(A[i][1]<M){
            cnt+=A[i][0]*A[i][1];
            M-=A[i][1];
        }
        else{
            cnt+=A[i][0]*M;
            break;
        }
    }
    printf("%ld\n",cnt);
    return 0;
}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, K, S;
  cin >> N >> K >> S;
  for(int i = 0; i < K; i++){
    cout << S << ' ';
  }
  for(int i = 0; i < N - K; i++){
    if(S == 1000000000)cout << S - 1 << ' ';
    else cout << S + 1 << ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
const int mod = 1000000007;
//const int mod = 998244353;
 
 
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);
 
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}
 
int main(int argc, const char * argv[]) {
    
    ll N; cin >> N;
    vector<ll> A(N);
    for(ll i=0;i<N;i++){
        cin >> A[i];
    }
    
    ll sum=A[0] ^ A[1];
    for(ll i=2;i<N;i++){
        sum = sum ^ A[i];
    }
    
    vector<ll> B(N);
    for(ll i=0;i<N;i++){
        B[i] = sum ^ A[i];
        cout << B[i] << endl;
    }
    
    
    
    
    
    
    return 0;
}


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

namespace Greatest_Common_Divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int m = int.Parse(input[0]);
            int n = int.Parse(input[1]);
            Console.WriteLine(My_Algorithm.GCD(m,n));
        }
    }

    public static class My_Algorithm
    {
        //?????\?????????
        public static void Insertion_Sort(ref int[] array)
        {
            for (int i = 1; i < array.Length; ++i)
            {
                int v = array[i];
                int j = i - 1;
                while (j >= 0 && array[j] > v)
                {
                    array[j + 1] = array[j];
                    --j;
                }
                array[j + 1] = v;
                //for (int k = 0; k < array.Length - 1; ++k) Console.Write("{0} ", array[k]);
                //Console.WriteLine(array[array.Length - 1]);
            }
        }

        //?????§??¬?´???°
        public static int GCD(int m, int n)
        {
            if ((m == 0) || (n == 0)) return 0;
            while ((m != 0) && (n != 0))
            {
                if (m > n) m = m % n;
                else n = n % m;
            }
            if (m == 0) return n;
            else return m;
        }
        public static long GCD(long m, long n)
        {
            if ((m == 0) || (n == 0)) return 0;
            while ((m != 0) && (n != 0))
            {
                if (m > n) m = m % n;
                else n = n % m;
            }
            if (m == 0) return n;
            else return m;
        }
        //????°???¬?????°
        public static int LCM(int m, int n)
        {
            if ((m == 0) || (n == 0)) return 0;
            return m * n / My_Algorithm.GCD(m, n);
        }
        public static long LCM(long m, long n)
        {
            if ((m == 0) || (n == 0)) return 0;
            return m * n / My_Algorithm.GCD(m, n);
        }
    }


}


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

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

int main(){
    int N; cin >> N;
    int h[N];
    for(int i=0;i<N;i++) cin >> h[i];
    int t[N];
    for(int i=1;i<N;i++){
        t[i]=h[i]-h[i-1];
    }
    int ans=0;
    int res=0;
    for(int i=1;i<N;i++){
        if(t[i]<=0) res++;
        else res=0;
        ans=max(res,ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
pairs = []
N = int(input(''))
for i in range(N):
    pair = input('')
    pair = pair.split(' ')
    pairs.append(pair)

cou = 0
for i, lst in enumerate(pairs):
    if cou == 3:
        break
    elif lst[0] == lst[1]:
        cou += 1
    else:
        cou = 0

if cou != 3:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 9092
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;

int main(void){
    int N,M,Q;
    cin >> N >> M >> Q;
    int check[505][505]={0};
    int ans[505][505]={0};
    int l[200005],r[200005];
    int p[100005],q[100005];
    for(int i=1; i<=M; i++){
        cin >> l[i] >> r[i];
        check[l[i]][r[i]]+=1;
    }
    //ここから工事TLE
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            ans[i][j]=ans[i][j-1];
            for(int k=0; k+i<=N; k++){
                ans[i][j]+=check[i+k][j];
            }
        }
    }
    //この先固定
    for(int i=1; i<=Q; i++){
        cin >> p[i] >> q[i];
    }
    for(int i=1; i<=Q; i++){
        cout << ans[p[i]][q[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 5248
sa = list(input())
sb = list(input())
sc = list(input())
t = 'a'
while (1):
    if t == 'a':
        if len(sa) == 0:
            print('A')
            exit()
        else:
            t = sa.pop(0)
    elif t == 'b':
        if len(sb) == 0:
            print('B')
            exit()
        else:
            t = sb.pop(0)
    elif t == 'c':
        if len(sc) == 0:
            print('C')
            exit()
        else:
            t = sc.pop(0)


Measured memory_bytes: 3064
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
ans = [0]*2
for i in range(n):
    if i%2==0:
        ans[0] -= 2*a[i//2]
    else:
        ans[0] += 2*a[n-1-i//2]
    
    if i%2==0:
        ans[1] += 2*a[n-1-i//2]
    else:
        ans[1] -= 2*a[i//2]
if n%2==0:
    ans[0] +=a[n//2-1]
    ans[0] -=a[n//2]
    ans[1] +=a[n//2-1]
    ans[1] -=a[n//2]
else:
    ans[0] +=a[n//2]
    ans[0] +=a[n//2-1]
    ans[1] -=a[n//2]
    ans[1] -=a[n//2+1]
print(max(ans))

Measured memory_bytes: 7512
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
wl = [input()]
rule = True
for i in range(1,n):
    s = input()
    if s in wl or s[0] != wl[-1][-1]:
        rule = False
    wl.append(s)

if rule:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int start=0;
  int goal=100001;
  rep(i,m){
    int s,g;
    cin >> s >> g;
    if(g<start){
      cout << 0 << endl;
      return 0;
    }
    if(s>goal){
      cout << 0 << endl;
      return 0;
    }
    if(s>start){
      start=s;
    }
    if(g<goal){
      goal=g;
    }
  }
  int ans=0;
  for(int i=start;i<goal+1;i++){
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
a = [0] * n
ans = 0
for i in range(1,n):
     if h[i-1] >=h[i]:
          ans += 1
     else:
          a[i-1] = ans
          ans = 0

print(max(max(a),ans))

Measured memory_bytes: 14224
#include<stdio.h>
int main(){
  int t,n;//チケットの種類を示すtとチケットの枚数を示すt
  int i;//カウンタ
  int ans[4];//答えを入力順に格納する変数
  for(i=0;i<4;i++){
    scanf("%d %d",&t,&n);
    switch(t){
    case 1 :
      ans[i]=0;
      ans[i]=n*6000;
      break;
    case 2:
      ans[i]=0;
      ans[i]=n*4000;
      break;
    case 3:
      ans[i]=0;
      ans[i]=n*3000;
      break;
    case 4:
      ans[i]=0;
      ans[i]=n*2000;
      break;
    }
  }
  //答えの出力
  for(i=0;i<4;i++){
    printf("%d\n",ans[i]);
  }
  return(0);
}



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

using namespace std;

vector<int>dag[100005];
int indegree[100005], dp[100005];
queue<int> myq;


int main(){

    int N, M, u,v;
    cin >> N >> M;

    for(int i = 0; i < M; i++){

        cin >> u >> v;
        dag[u].push_back(v);
        indegree[v]++;
    }

    for(int i = 1; i <= N; i++) if(indegree[i] == 0) myq.push(i);

    while(!myq.empty()){

        int current = myq.front();
        myq.pop();
        for(int i = 0; i < (int) dag[current].size(); i++){
            dp[dag[current][i]] = max(dp[dag[current][i]], dp[current] + 1);
            indegree[dag[current][i]]--;
            if(indegree[dag[current][i]] == 0) myq.push(dag[current][i]);
        }

    }

    int res = 0;
    for(int i = 1; i <= N; i++) res = max(res, dp[i]);

    cout << res;
}


Measured memory_bytes: 6528
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

k=int(input())

if k%2==0 or k%5==0:
    print(-1)
else:
    # if k%7==0:
    #     k//=7
    tmp=1
    cnt=1
    k*=9
    while 7*(tmp*10-1)%k:
        tmp*=10
        tmp%=k
        cnt+=1
    print(cnt)

Measured memory_bytes: 68264
N, M, K = map(int, input().split())
yes = False
for i in range(0, N + 1):
    for j in range(0, M + 1):
        if K == i * j + (N - i) * (M - j):
            yes = True
            break
    if yes:
        break
        
if yes:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;

void main(){
    auto a=readln;
    auto b=readln;
    if(a.length>b.length)writeln("GREATER");
    else if(a.length<b.length)writeln("LESS");
    else{
        foreach(ab;zip(a,b)){
            if(ab[0].to!int>ab[1].to!int){
writeln("GREATER");return;
            }else if(ab[0].to!int<ab[1].to!int){
writeln("LESS");return;
            }
        }
    writeln("EQUAL");
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n)cin>>a[i];
    int cntf=0,cntt=0;
    rep(i,0,n){
        if(a[i]%4==0)cntf++;
        else if(a[i]%2==0)cntt++;
    }
    int rest=n-(cntt+cntf);
    if(rest>cntf){
        if(cntt!=0||rest-cntf>1){
        cout<<"No"<<endl;
        return 0;
        }

    }
    cout<<"Yes"<<endl;
    return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
int main(){
    ll S;
    cin>>S;
    
    ll sum=0;
    ll d=digitPoor(S)-1;
    REP(i,pow(2,d)){
        ll t=S;
        int bf=0;
        for(int j=0;j<d;j++){
            if((i>>j&1)==1){
                ll aa=ll((t%int(pow(10,j+1)))/(int)pow(10,bf));
                sum+=aa;
                //cout<<aa<<" ";
                bf=j+1;
            }
        }
        sum+=ll(t/pow(10,bf));
        //s(t/pow(10,bf));
        //sl();
    }
    cout<<sum;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7


X,A,B = map(int,input().split())

if B <= A:
    print("delicious")
else:
    if B <= A+X:
        print("safe")
    else:
        print("dangerous") 


Measured memory_bytes: 5456
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let dfs vs n =
  let d = Array.make n (-1) in
  let rec doit i j =
    d.(i) <- j;
    List.iter (fun v -> if d.(v) = (-1) then doit v j) vs.(i) in
  Array.iteri (fun i e -> if e = (-1) then doit i i) d;
  d

let () =
  let read_ints () = read_line () |> split_on_char ' ' |>  List.map int_of_string in
  let (n, m) = match read_ints () with
    | [n; m] -> (n, m)
    | _ -> assert false in
  let vs = Array.make n [] in
  for _ = 0 to m - 1 do
    match read_ints () with
    | [s; t] ->
      vs.(s) <- t :: vs.(s);
      vs.(t) <- s :: vs.(t);
    | _ -> assert false
  done;
  let d = dfs vs n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    match read_ints () with
    | [s; t] -> Printf.printf (if d.(s) = d.(t) then "yes\n" else "no\n")
    | _ -> assert false
  done

Measured memory_bytes: 19128
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[1]==s[2]){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    
}

Measured memory_bytes: 256
typedef long long ll;

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

#include <queue>
#include <cstdio>
#include <set>
#include <iostream>

using namespace std;

int main(){
  vector<vector<ll> > dp(5, vector<ll>(4000 + 1));
  dp[0][0] = 1;

  REP(i,4) REP(j,4000 + 1) if(dp[i][j]){
    for(int k = 0; k <= 1000 && j + k <= 4000; k++){
      dp[i + 1][j + k] += dp[i][j];
    }
  }

  int s;
  while(cin >> s)
    cout << dp[4][s] << endl;

  return 0;
}

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

int main(){

    int days;
    int num;
    cin >> days >> num;

    vector<int> h_num(num);
    int i;
    int sum = 0;

    for (i=0; i<num; i++){
        cin >> h_num.at(i);
        sum += h_num.at(i);
    }

    if (days >= sum){
        cout << days-sum << endl;
        return 0;
    }
    else{
        cout << -1 << endl;
        return 0;
    }

}

Measured memory_bytes: 3644
import math
from collections import defaultdict


n = int(input())
arr = list(map(int, input().split()))
dp = [math.inf] * n
dp[0] = 0
dp[1] = abs(arr[1] - arr[0])
if (n == 2):
    print(dp[1])
else:
    dp[2] = min(abs(arr[2] - arr[0]), abs(arr[2] - arr[1]) + dp[1])
    for i in range(2, n):
        dp[i] = min(abs(arr[i] - arr[i-1]) + dp[i-1], abs(arr[i] - arr[i-2]) + dp[i-2])
    print(dp[-1])


Measured memory_bytes: 21240
N=int(input())
S=input().rstrip()
t=S.count('R')*S.count('G')*S.count('B')
d=0
for i in range(N):
  for j in range(i+1,N):
    if S[i]==S[j]: continue
    k=2*j-i
    if k>=N or S[i]==S[k] or S[j]==S[k]: continue
    d+=1
print(t-d)


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}


/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
//constexpr int inf = 1<<30;
constexpr int mod = 1000000007;

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

  vi a(n);
  rep(i, 0, n) cin >> a[i];

  vi cnt(n+1);
  cnt[0] = 3;

  int ans = 1;
  rep(i, 0, n){
    (ans *= cnt[a[i]]) %= mod;
    if(cnt[a[i]] == 0){
      cout << 0 << endl;
      return 0;
    }
    cnt[a[i]]--;
    cnt[a[i]+1]++;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

int main() {

    int n;
    cin >> n;

    vector<long double> ps(n+1);
    vector<vector<long double>> dp(n+1, vector<long double>(n+1, 0));

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

    dp[0][0] = 1.0;

    for (int i = 0; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i > j) continue;
            if (i == 0) {
                dp[i][j] = dp[i][j-1] * (1 - ps[j]);
            }
            else if (i == j) {
                dp[i][j] = dp[i-1][j-1] * ps[j];
            } else if (i < j) {
                dp[i][j] = dp[i][j-1] * (1-ps[j]) + dp[i-1][j-1] * ps[j];
            }
        }
    }

    int k;
    n % 2 != 0 ? k = n / 2 + 1 : k = n / 2;

    long double sum = 0;
    for (int i = k; i <= n; i++) {
        sum += dp[i][n];
    }

    cout << std::setprecision(10);
    cout << sum << "\n";

    return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int a,b,c;
  while(cin >> a >> b >> c){
    if(a == b and b != c and c != a) puts_all("Yes");
    else if(a != b and b == c and c != a) puts_all("Yes");
    else if(a != b and b != c and c == a) puts_all("Yes");
    else puts_all("No");
  }

  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ( (A + B) < (C + D)) {
    cout << "Right" << endl;
  }
  else if ( (A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = str(input())
Cs = []
for _ in range(Q):
  l, r = map(int, input().split())
  Cs.append((l, r))

det_idx = []
for i in range(N-1):
  if S[i:i+2] == 'AC':
    det_idx.append(i)

from bisect import bisect_left
for c in Cs:
  ans = bisect_left(det_idx, c[1]-1) - bisect_left(det_idx, c[0]-1)
  print(ans)

Measured memory_bytes: 19420
use v5.18;
use warnings;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

my $n = read_line;
say do {
  if ($n == 1) {
    'Hello World'
  }
  else {
    my $A = read_line;
    my $B = read_line;
    $A + $B;
  }
};


Measured memory_bytes: 640
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext())
            System.out.println(GCD(sc.nextInt(),sc.nextInt()));
    }
    static int GCD(int x,int y) {
        return x==0?y:GCD(y%x,x);
    }
}


Measured memory_bytes: 26036
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main()
{
    int n;
    cin >> n;
    int flag = 1;
    vector<string> w(n);
    cin >> w[0];
    for(int i = 1; i < n; i++){
        cin >> w[i];
        if(w[i-1].back() != w[i].front()) flag = 0;
    }
    sort(w.begin(),w.end());
    for(int i = 1; i < n; i++){
        if(w[i-1] == w[i]) flag = 0;
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll a,b,n;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a>b) swap(a,b);
	if((a-b)%2==0){
		printf("%lld\n",(b-a)/2);
	}
	else{
		ll ans=0;
		ans+=(b-a)/2+1ll;
		ll tmp=min(n-max(a,b),min(a,b)-1);
		ans+=tmp;
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    if(n<=1){
        cout<<"0"<<endl;
        return 0;
    }
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    if(n==2){
        cout<<arr[1]-arr[0]<<endl;
        return 0;
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4208
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;

int A[100001];

void solve(){
	int n,k,q;
	cin>>n>>k>>q;
	for(int i=0;i<q; i++){
		int x; cin>>x;
		A[x]++;
	}
	for(int i=1; i<=n; i++){
		if(k + A[i]<= q){
			cout<<"No\n";
		}
		else cout<<"Yes\n";
	}

}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}

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

int main() {
  // input
  int n {0};
  cin >> n;
  int tmp {0};
  cin >> tmp;
  int minv = tmp;
  int ans = -(1 << 30);

  for (int i = 1; i < n; i++) {
    cin >> tmp;
    if (ans <= tmp - minv) {
      ans = tmp - minv;
    }
    if (minv >= tmp) minv = tmp;
  }

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



Measured memory_bytes: 3100
#include <iostream>
using namespace std;
typedef long long int ll;
ll const mod = 1000000007;
ll dp[1<<22];
ll n;
ll map1[50][50];
int main()
{
    scanf("%lld",&n);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <=n ; j++)
        {
            scanf("%lld",&map1[i][j]);
        }
    }
    dp[0] = 1;
    for(int i = 1; i < (1<<n); i++)
    {
        int now = __builtin_popcount(i);
        for(int k = 1; k <= n; k++)
        {
            if((i>>(k-1)&1)&&map1[now][k])
            {
                dp[i]+= dp[i^(1<<(k-1))];
                dp[i]%=mod;
            }
        }
    }

    printf("%lld\n",dp[(1<<n)-1]);
}


Measured memory_bytes: 20180
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s, t;std::cin >> s >> t;
  ll n = s.size();

  //できない場合 tが0000000 && s!=t
  bool z = true;
  for(auto c:t) if(c=='1') z = false;
  if(z){
    std::cout << (s==t?0:-1) << '\n';
    exit(0);
  }

  vll l(n), r(n);
  //各点に対し、もしその点が変更が必要な点だった場合、
  //右側と左側それぞれ最小でどれくらいシフトが必要かのテーブルが必要
  for(int i=0;i<n;i++){
    // left
    ll cnt = 0, idx = i;
    while(true){
      if(t[idx]=='1') break;
      cnt++, idx--;
      if(idx<0) idx += n-1;
    }
    l[i] = cnt;
    cnt = 0, idx = i;
    while(true){
      if(t[idx]=='1') break;
      cnt++, idx++;
      if(idx>=n) idx%=n;
    }
    r[i] = cnt;
  }

  ll ans = 1000000000;
  //どこを基準にするか
  for(int st=0;st<n;st++){
    vvl dat;
    //変更が必要な点xを列挙
    for(int i=0;i<n;i++){
      ll to = (i-st+n)%n;
      if(s[i]!=t[to]) dat.push_back(vll{l[i], r[i]});
    }
    ll m = dat.size();
    sort(all(dat));
    vll rmax(m+1, 0);
    for(int i=m-1;i>=0;i--) rmax[i] = max(rmax[i+1], dat[i][1]);
    ll tmp = 1000000000;

    for(int i=0;i<=m;i++){
      ll L = (i==0?0:dat[i-1][0]);
      ll R = rmax[i];
      tmp = min(tmp, 2*(max((ll)0, L-st)+R)+st);
      ll fl = n-st;
      tmp = min(tmp, 2*(L+max((ll)0, R-fl))+fl);
    }
    ans = min(ans, tmp+m);
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main(){
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> A(a), B(b);
  for(int i = 0; i < a; ++i) cin >> A[i];
  for(int i = 0; i < b; ++i) cin >> B[i];
  int ans = *min_element(A.begin(), A.end()) + *min_element(B.begin(), B.end());
  for(int i = 0; i < m; ++i){
    int x, y, c;
    cin >> x >> y >> c;
    ans = min(ans,A[x-1]+B[y-1]-c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
        int slime = sc.nextInt();
		String a = sc.next();
        String b[] = a.split("");
        int ans = slime;
     
        for(int i = 0; i < slime - 1;i++){
			if(b[i].equals(b[i+1])){
              ans -= 1;
            }
        }
      	System.out.println(ans);
 
    }
}

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


int main(){
    cout<<fixed<<setprecision(10);

    ll n;cin>>n;
    rep(i,n){
        ll x = i+1;
        if(x%3==0){
            cout<<" "<<i+1;
            continue;
        }
        
        while(x){
            if(x%10 == 3) {cout<<" "<<i+1; break;}
            x /= 10;
        }
    }
    cout<<endl;

    

    return 0;
}






Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e5+10, M=(ll)1e9+1 ;
const int mod = 1e9+7  ;


void work(){
    ll n,k;
    cin >> n >> k;
    if(k > ((n-1)*(n-2))/2){
        cout << -1 ;
        return;
    }

    ll cnt=((n-2)*(n-1))/2 ,x=0;
//    cout << cnt << endl;
    vll ans;
    x=cnt;

    for(ll i=1;i<=n;i++){
        if(i==2)
            continue;
        ans.pb({2,i});
    }
//    cout << x << endl;
    for(ll i=3;i<=n;i++){
        if(x==k){
            break;
        }
        ans.pb({1,i});
        x--;

    }

    if(x!=k){
        for(ll i=3;i<=n;i++){
            for(ll j=i+1;j<=n;j++){
                if(x==k)
                    break;
                ans.pb({i,j});
                x--;

            }
            if(x==k)
                break;
        }
    }
    cout << ans.size() << "\n";
    for(ll i=0;i<ans.size();i++)
        cout << ans[i].f << " "<< ans[i].s << "\n";
//    for(ll i=1;i<=n;i++){
//        for(ll j=i+1;j<=n;j++){
//            cout << i << " " << j << "\n";
//            x++;
//            if(x==cnt)
//                return;
//        }
//    }
}
int main(){
 ios_base::sync_with_stdio(0);

    ll t,z;
    // cin >> t;
    // z=t;
    t=1;
    while(t--){
            // cout << "Case #" << z-t << ": ";
            work();
    }
   return 0;

}


Measured memory_bytes: 512
N,K=map(int,input().split())
x=list(map(int,input().split()))
al=[]
for i in range(N-K+1):
  if x[i]*x[i+K-1]<0:
    al.append(max(abs(x[i]),abs(x[i+K-1]))+2*min(abs(x[i]),abs(x[i+K-1])))
  elif x[i]>=0:
    al.append(x[i+K-1])
  else:
    al.append(abs(x[i]))
print(min(al))

Measured memory_bytes: 14228
#include <stdio.h>

int main(){
  int n,i,j,c=0,f[100],minj,x;
  scanf("%d",&n);
  for(i=0;i<=n-1;i++){
    scanf("%d",&f[i]);
  }
  for(i=0;i<=n-1;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(f[j]<f[minj]){
	minj=j;
      }
    }
     if(f[i]>f[minj]){
        c++;
      }
	x=f[minj];
	f[minj]=f[i];
	f[i]=x;
  }
  for(i=0;i<n-1;i++){
    printf("%d ",f[i]);
  }
  printf("%d\n",f[n-1]);
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
  int h,w;
  while(1) {
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    if(h == 0 || w == 0) continue;
    REP(i,h) {
      if(i == 0 || i == h-1) {
        REP(j,w) {
          cout << "#";
        }
        cout << endl;
      } else {
        REP(j,w) {
          if(j == 0 || j == w-1) {
            cout << "#";
          } else {
            cout << ".";
          }
        }
        cout << endl;
      }
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int x,a,b;
  cin>>x>>a>>b;
  x-=a;
  cout<<x%b<<endl;
  return 0;
}


Measured memory_bytes: 256
/*
      author : Nishikawa
      created: 04.08.2020 17:15:19
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int N;
    double D;
    cin >> N >> D;
    int count=0;
    for(int i=0; i<N; i++){
        double X,Y;
        cin >> X >> Y;
        double norm =sqrt(X*X+Y*Y);
        if(norm<=D) count++;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3760
import sys
sys.setrecursionlimit(10**9)
def dfs(parent,current,distance):
  global m
  m[current]=distance
  for child in graph[current]:
    if child[0]==parent:
      continue
    dfs(current,child[0],distance+child[1])
n=int(input())
graph=[]
for i in range(n+1):
  graph.append([])
m=[0]*(n+1)
for i in range(n-1):
  a,b,c=map(int,input().split())
  graph[a].append([b,c])
  graph[b].append([a,c])
q,k=map(int,input().split())
dfs(k,k,0)
for i in range(q):
  x,y=map(int,input().split())
  print(m[x]+m[y])


Measured memory_bytes: 228512