akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define nguyendz the_best

#define all(n) n.begin(),n.end()
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define ff first
#define ss second
//#define ((x|y)-y) (x&(~y))
//#define gcd(fibo(x),fibo(y)) = fibo(gcd(x,y))
using namespace std;
const ll maxn=3e5+1;
const ll maxx=1e13;
const ll mod=1e9+7;
const ll mod1=998244353;

vector <pll> adj[maxn];
set<ll> adj1[maxn];
//vector<ll> ans;
//bool kt[maxn];
pll a[maxn];
pll p[maxn];
ll dd[maxn] ;
vector<ll> ans;
ll dfs(ll u)
{
    dd[u]=1;
    for (auto p:adj[u])
    {
        if (!dd[p.ff])
        {
            ll kt=dfs(p.ff);
            if (kt)
            {
                ans.pb(p.ss);
            }
           a[u].ss+=kt;
		   a[u].ss%=2;
        }
    }
    return a[u].ss;
}

int main()
{
    // freopen("test.txt","r",stdin);
    // freopen("CHEMIST.OUT","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i].ff>>a[i].ss;
	sort(a+1,a+n+1);

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

		a[i].ss+=a[i+1].ss;
		a[i].ss%=2;
    }
	for(int i=1;i<=m;i++)
	{
		cin>>p[i].ff>>p[i].ss;
		ll t1=p[i].ff;
		ll t2=p[i].ss;
		p[i].ff=(lower_bound(a+1,a+n+1,make_pair(p[i].ff,0ll))-a)-1;
		//nho hon =
		p[i].ss=(upper_bound(a+1,a+n+1,make_pair(p[i].ss,1ll))-a)-1;
		// nho hon han
	//	cout <<t1<<" "<<t2<<" "<<p[i].ff<<" "<<p[i].ss<<endl;
		adj[p[i].ff].pb(make_pair(p[i].ss,i));
		adj[p[i].ss].pb(make_pair(p[i].ff,i));
	}
	for (int i=0;i<=n;i++)
    {
        if (!dd[i])
        {

            if (dfs(i))
            {
                cout <<-1;
                return 0;
            }
        }
    }
    cout <<ans.size()<<endl;
    sort(all(ans));
    for (auto p:ans)
    {
        cout <<p<<" ";
    }

}


Measured memory_bytes: 48764
r,c = map(int,input().split())
rowsum = [0 for i in range(c)]
for i in range(r):
    colsum = 0
    nums = [int(e) for e in input().split()]
    for j in range(c):
        print(nums[j],end=" ")
        colsum = colsum + nums[j]
        rowsum[j] = rowsum[j] + nums[j]
    print(colsum)
print(*rowsum,end = " ")
print(sum(rowsum))


Measured memory_bytes: 5636
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    val (t, a) = readLine()!!.split(' ').map(String::toLong)
    val hList = readLine()!!.split(' ').map(String::toLong)
    val tList = hList.map { t - it * 0.006 }
    val dList = mutableMapOf<Int, Double>()
    tList.forEachIndexed { index, d -> dList[index] = Math.abs(d - a) }
    println(dList.minBy { it.value }!!.key + 1)
}

Measured memory_bytes: 36416
import scipy.sparse as S
import itertools as i
m=lambda:map(int,input().split())
N,M,_=m()
R=m()
G=S.dok_matrix((N,N))
G.update((lambda x:((next(x)-1,next(x)-1),next(x)))(m())for _ in range(M))
G=S.csgraph.floyd_warshall(G.tocsr(),directed=0)
print(int(min(sum(G[a-1,b-1]for a,b in zip(p[1:],p))for p in i.permutations(R))))

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

typedef long long LL;
typedef pair<LL,LL> PII;
int INF = (int) 1e6;
#define MAX_V 30100
struct edge { int to,cap,rev;};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
int V;
void add_edge(int from, int to,int cap)  {
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}
void bfs(int s) {
  //	memset(level,-1,sizeof(level)) ;
  for(int a=0; a<MAX_V; a++)level[a]=-1;
  queue<int>que;
  level[s]=0;
  que.push(s);
  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for(int i=0; i<G[v].size(); i++) {
      edge &e = G[v][i];
      if(e.cap>0 && level[e.to]<0) {
	level[e.to] = level[v]+1;
	que.push(e.to) ;
      }
    }
  }
}

int dfs(int v,int t,int f) {
  if(v==t) return f;
  for(int &i = iter[v]; i<G[v].size(); i++) {
    edge &e = G[v][i];
    if(e.cap>0 && level[v] < level[e.to]) {
      int d = dfs(e.to,t,min(f,e.cap)) ;
      if(d>0) {
//      	cout << v << endl;
	e.cap -=d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t) {
  int flow = 0;
  
  for(;;) {
    bfs(s);
    if(level[t]<0) return flow;
    //		memset(iter,0,sizeof(iter)) ;
    for(int a=0; a<MAX_V; a++ ) iter[a]=0;
    int f;
    while((f=dfs(s,t,INF))>0) {
      flow += f;
    }
  }
}
int H, W;
int encode(int x, int y ) {
//	cout <<" " << W* x + y << endl;
	return W * x + y;
}


int main() {
//	int H,W;
	cin >> H >> W;
	V = 2 * H * W + 2;
	
	int base = H * W;
	int nodes = 2 * H * W;
	int nodet = nodes + 1;
	for(int i=0; i<H; i++) {
		for(int j=0; j<W; j++) {
//			cout << encode(i, j) << endl;
			add_edge(encode(i,j), encode(i,j) + base, 1);
			if(i < H-1) {
				add_edge(encode(i, j) + base, encode(i+1, j), 1);
				add_edge(encode(i+1, j) + base, encode(i, j), 1);
			}
//			cout << "a" << endl;
			if(j < W-1)  {
				add_edge(encode(i, j) + base, encode(i, j+1), 1);
				add_edge(encode(i, j+1) + base, encode(i, j), 1);
			}
			if(i==0 || j==0 || i==H-1 || j==W-1) {
				add_edge(encode(i, j) + base, nodet, 10010);
			}
		}
	}
	
	string s;
	bool muri = false;
	for(int i=0; i<H; i++) {
		cin >> s;
		for(int j=0; j<W; j++) {
			if(s[j] == 'X') {
				add_edge(nodes, encode(i,j)+base, 10000);
//				cout << encode(i,j) + base << endl;
				if(i==0 || j==0 ||  i == H-1 || j == W-1)
					muri = true;
			}
		}
	}
	int ans = max_flow(nodes, nodet);
	if(muri) ans = -1;
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>

int main(){
  int n;  scanf("%d", &n);
  char s[100005];  scanf("%s", s);
  long ans = 1;
  for(int i=1; s[i]!='\0'; i++){
    if(s[i-1] != s[i])
      ans++;
  }

  printf("%ld\n", ans);

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int N,Q;
    cin >> N >> Q;
    vector<int> C[N+1] = {};
    long long V[N+1] = {};
    bool F[N+1] = {};
    queue<int> que;

    C[0].push_back(1);

    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        C[a].emplace_back(b);
        C[b].emplace_back(a);
    }
    rep(i,Q){
        int p,x;
        cin >> p >> x;
        V[p] += x;
    }

    que.push(1);
    while(!que.empty()){
        int p = que.front();
        que.pop();
        F[p] = true;
        for(int c : C[p]){
            if(!F[c]){
                V[c] += V[p];
                que.push(c);
            }
        }
    }
    for(int i=1;i<=N;i++){
        cout  << V[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


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

signed main(){
    int A,B; cin>>A>>B;
    cout<<6-A-B<<endl;
}

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[100010];
ll finv[100010];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    //SieveOfEratosthenes(1000000);
    //factorial(100005);
    while(t--){
        int n;
        cin>>n;
        cout<<(!n);
    }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll y , x;
    cin >> x >> y;
    ll mul = y/x;
    ll ans = 0;
    while (mul > 0) {
        ans += 1;
        mul /= 2;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
q=[1.0]+[k=0]*n=gets.to_i
g=[]
$<.map{|s|a,b=s.split;(g[a.to_i-1]||=[])<<b.to_i-1}
g.map{|h|h.map{|t|q[t]+=q[k]/h.size};k+=1}
e=[a=0]*n
while k>0
s=m=0.0
g[k-=1].map{|t|s+=c=e[t];m=[m,c].max}
e[k]=1+s/z=g[k].size
z>1&&a=[a,q[k]*=(s-m)/~-z-s/z].min
end
p e[0]+a

Measured memory_bytes: 6268
program MakingTriangle
    implicit none

    integer(4) :: N
    real(8), allocatable :: L(:)
    integer(4) :: count
    integer(4) :: i, j, k

    read(*, *) N
    allocate(L(1:N))
    read(*, *) L

    count = 0
    do i = 1, N
        do j = i + 1, N
            do k = j + 1, N
                if (L(i) .ne. L(j) .and. L(i) .ne. L(k) .and. L(j) .ne. L(k) .and. &
                &   abs(L(i)-L(j)) < L(k) .and. L(k) < L(i) + L(j)) then
                    count  = count + 1
                end if
            end do
        end do
    end do

    write(*, *) count

end program MakingTriangle
        

Measured memory_bytes: 2988
def CountingSort(A, B, k, n):
    C = [0 for i in range(k)]   #  for i = 0 to k { C[i] = 0 }

    # /* C[i] ??? i ???????????°????¨?????????? */
    for j in range(n):
        C[A[j]] += 1
#        print("j:{} Aj:{} C[Aj]:{}".format(j,A[j], C[A[j]]))

    # /* C[i] ??? i ??\????????°???????????°????¨??????????*/
    for i in range(k):
#        print("\ti:{} Ci:{} Ci-1:{}".format(i,C[i], C[i-1]))
        C[i] = C[i] + C[i-1]

    for j in reversed(range(n)):
#        print("j:{} Aj:{} C[Aj]:{} k:{}".format(j,A[j], C[A[j]],k))
        B[C[A[j]]] = A[j]
        C[A[j]] -= 1

def main():
    """ ????????? """
    num = int(input().strip())
    A = list(map(int,input().split()))
    max = 0
    for i in range(num):
        if max < A[i]:
            max = A[i]
    if max < num:
        max = num
    max += 2
    B = [0 for i in range(num + 2)]
    CountingSort(A, B, max, num)
    print(" ".join(map(str,B[1:num+1])))

if __name__ == '__main__':
    main()

Measured memory_bytes: 252212
import sys

input = sys.stdin.readline


def main():
    S = [input().strip() for _ in range(3)]

    a, b, c = 0, 0, 0
    n = 0
    while True:
        ns = ''
        if n == 0:
            if a == len(S[n]):
                print("A")
                break
            ns = S[n][a]
            a += 1
        elif n == 1:
            if b == len(S[n]):
                print("B")
                break
            ns = S[n][b]
            b += 1
        else:
            if c == len(S[n]):
                print("C")
                break
            ns = S[n][c]
            c += 1

        n = ord(ns) - ord('a')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    string s;
    cin >> s;
    s[5] =' ';
    s[13] =' ';
    cout << s;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin>>n;
	int k ;
	cin>>k;
	vector<int> A;
	for(int i =0;i<n;i++)
	{
		int a;
        cin>>a;
        A.push_back(a);
	}
	
	vector<int> dp;
	for(int i =0;i<n;i++)
	dp.push_back(0);
	
	for(int i =1;i<n;i++)
	{
	dp[i] = dp[i-1] + abs(A[i]-A[i-1]);
	for(int j =2;j<=k;j++)
	{ if(i-j>=0)dp[i] = min(dp[i], (dp[i-j] + abs(A[i]-A[i-j])));
      else break;
	  }
}
	
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
int gg(){
    int x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}

int main()
{
     io;
    int T=1;
    //T=gg();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
       string s;
       cin>>s;
       ll sum=0;
       for(ll i=s.size()-1;i>-1;i--)
       {
           sum+=(s[i]-48);
       }
       if(sum%9)cout<<"No";
       else cout<<"Yes";
    }
    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;cin>>S;
  S[3]++;
  cout<<S<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

ll q;
vector<ll> vec;

int main() {
    fastInp;

    ll n, ans = 0;
    n = 7;
    vec.resize(n);
    for (int i = 0; i < n; i++) cin >> vec[i];

    ans += vec[1] * 2;
    vec[1] = 0;

    ll q = 0, add = ans;
    ans += max((vec[3] / 2) * 4 + (vec[4] / 2) * 4 + (vec[0] / 2) * 4, q);
    if (vec[0] > 0 && vec[4] > 0 && vec[3] > 0) {
        vec[0]--;
        vec[4]--;
        vec[3]--;
        q = (vec[3] / 2) * 4 + (vec[4] / 2) * 4 + (vec[0] / 2) * 4 + 6 + add;
    }
    ans = max(ans, q);

    cout << ans / 2;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(input()) for i in range(n)]

    btn = 1
    hist = set()
    while True:
        if btn == 2:
            print(len(hist))
            break

        if btn in hist:
            print(-1)
            break

        hist.add(btn)
        btn = a[btn - 1]


if __name__ == "__main__":
    main()


Measured memory_bytes: 55896
from collections import deque

H, W = map(int, input().split())
s = [input() for i in range(H)]

p = [[0 for j in range(W)] for i in range(H)]
p[0][0] = 1
visited = [[False for j in range(W)] for i in range(H)]
Q = deque()
Q.append((0, 0))
while len(Q) > 0:
    i, j = Q.popleft()
    neighbors = [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]
    for ni, nj in neighbors:
        if 0 <= ni < H and 0 <= nj < W and s[ni][nj] != '#' and p[ni][nj] == 0 and not visited[ni][nj]:
            p[ni][nj] = p[i][j] + 1
            Q.append((ni, nj))
    visited[i][j] = True

n_black = sum([row.count('#') for row in s])
print(H * W - n_black - p[H - 1][W - 1] if p[H - 1][W - 1] != 0 else - 1)


Measured memory_bytes: 3316
while 1:
    n,m = list(map(int,input().split()))
    if not n and not m:break

    ln=sorted([int(input()) for _ in range(n)])
    lm=sorted([int(input()) for _ in range(m)])
    cd_n=set(ln)
    cd_m=set(lm)

    g=(sum(lm)-sum(ln))
    f=False
    if g%2==1:f=True
    else:g=g/2
    bf=False
    for i in cd_m:
        if f:break
        for j in cd_n:
            if i-j==g:bf=True
            if bf:break
        if bf:break
    if bf and not f:print(j,i)
    else:print("-1")



Measured memory_bytes: 5612
n = int(input())
high = list(map(int, input().split()))

ans = 0
start = 0
def myfunc(start, high, ans):
    cnt = 0
    while high[start] >= high[start+1]:
        cnt += 1
        start += 1
        if start == n-1:
            break
    ans = max(ans, cnt)
    return start+1, ans

while start < n-1:
    start, ans = myfunc(start, high, ans)
print(ans)

Measured memory_bytes: 14224
n = int(input())
a = list(map(int,input().split()))
sum = 0
for i in range(n):
    sum+=a[i]
x = 0
ans = 10**10
for i in range(n):
    x+=a[i]
    if i+1<n:
        ans = min(ans,abs(sum-2*x))
print(ans)

Measured memory_bytes: 24824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
#define fr freopen("in.txt","r",stdin);
const ll INF=0x3f3f3f3f;
const ll N=1e6+7;
const ll mod=1e9+7;
ll maxn,minn;
ll T,n,m;

int main(){
	ll a,b,c,ans,k;
	ans=0;
	cin>>a>>b>>c>>k;
	if(k>=a){
		k-=a;
		ans=ans+a;
	}
	else{
		ans=ans+k;
		k=0;
	}
	if(k>=b){
		k-=b;
	}
	else{
		k=0;
	}
	ans-=k;
	cout<<ans<<endl;
	

	return 0;
}





Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        boolean[] pass = new boolean[n];
        int[] pens = new int[n];
        
        int pen = 0;
        int ac = 0;
        while (k-- > 0) {
            int q = sc.nextInt() - 1;
            String str = sc.next();
            if (str.equals("WA")) {
                if (pass[q] == false) {
                    pens[q]++;
                }
            } else {
                pass[q] = true;
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (pass[i]) {
                pen += pens[i];
            }
        }
        for (int i = 0; i < n; i++) {
            if (pass[i]){
                ac++;
            }
        }
        
        System.out.println(ac + " " + pen);
    }
}


Measured memory_bytes: 64468
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int a, b;
	char op;
	cin >> a >> op >> b;

	int ans = op == '+' ? a + b : a - b;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A+B>C+D)
        cout<<"Left"<<endl;
    else if(A+B==C+D)
        cout<<"Balanced"<<endl;
    else
        cout<<"Right"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  long n,a,b;
  scanf("%ld %ld %ld\n", &n, &a, &b);
  char s[n];
  for (long i = 0; i < n; i++) {
    scanf("%c", &s[i]);
  }

  long winners = 0;
  long foreign = 0;
  for (long i = 0; i < n; i++) {
    if (s[i] == 'a') {
      if (winners < a+b) {
        printf("Yes\n");
        winners++;
      } else {
        printf("No\n");
      }
    } else if (s[i] == 'b') {
      if (winners < a+b && foreign < b) {
        printf("Yes\n");
        winners++;
        foreign++;
      } else {
        printf("No\n");
      }
    } else {
      printf("No\n");
    }
  }

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
  int num1;
	int num2;
	int num3;
	bool flg1;

	scanf("%d %d %d",&num1,&num2,&num3);
  
	if(num1 < num2)
	{
		if(num2 < num3)
		{
			flg1 = true;
		}
		else
		{
			flg1 = false;
		}
	}
	else
	{
		flg1 = false;
	}
  
  if(flg1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}


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

int main() {
    bitset<64> b;
    int q; cin >> q;
    while (q--) {
        int t, i;  cin >> t;
        if (t < 4) cin >> i;
        if (t == 0) cout << b.test(i) << endl;
        if (t == 1) b.set(i);
        if (t == 2) b.reset(i);
        if (t == 3) b.flip(i);
        if (t == 4) cout << b.all() << endl;
        if (t == 5) cout << b.any() << endl;
        if (t == 6) cout << b.none() << endl;
        if (t == 7) cout << b.count() << endl;
        if (t == 8) cout << b.to_ullong() << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
using System;
using System.Linq;

public class AtCoder
{
  public static void Main()
  {
    var n = int.Parse(Console.ReadLine().Trim());

    var s = Console.ReadLine().Trim();

    var w = new int[n];
    var e = new int[n];

    var wc = 0;
    var ec = 0;

    for (var i = 0; i < n; i++)
    {
      if(s[i] == 'W') wc++;
      if(s[n-1-i] == 'E') ec++;
      w[i]+= wc;
      e[n-1-i]+= ec;
    }

    var min = int.MaxValue;

    for (var i = 0; i < n; i++)
    {
      var sum = 0;
      if(0 < i) sum += w[i-1];
      if(i < n - 1) sum += e[i+1];
      if(sum < min) min = sum;
    }

    Console.WriteLine(min);
  }
}

Measured memory_bytes: 14432
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var K = int.Parse(Console.ReadLine());
        var x = Console.ReadLine().Split();
        var answer = 0;
        for (int i = 0; i < N; i++){
            var xi = int.Parse(x[i]);
            answer += (xi < K - xi ? xi : K - xi) * 2;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27496
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
#endif

	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && b==c)
	{
		cout<<"No"<<endl;
	}
	else if((a==b && b!=c) || (a==c && c!=b) || (b==c && c!=a))
	{
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if(s[0]=='S')cout<<"Cloudy\n";
	else if(s[0]=='C')cout<<"Rainy\n";
	else cout<<"Sunny\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

char s[101000];
map<char,int> hs;

int main() {
	scanf("%*d%s",s);
	int n=strlen(s);
	rep(i,0,n) hs[s[i]]++;
	ll ans=1;
	for (auto p:hs) ans=ans*(p.se+1)%mod;
	printf("%lld\n",ans-1);
}

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

temp1 = n % 100

if temp1 >= 10:
    temp1 = temp1 % 10

hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]

if temp1 in hon:
    print("hon")
elif temp1 in pon:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9184
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int n,m;
  cin>>n>>m;
  int a[m],b[m];
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<n;i++){
    int count=0;
    for(int j=0;j<m;j++){
      if(a[j]==i+1) count++;
      if(b[j]==i+1) count++;
    }
    cout<<count<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCm(ll n, ll m){
    if(m == 0 || m == n){
        return 1;
    } else if(m == 1){
        return n;
    }
    return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

int main(void){
    string s;
    cin >> s;

    string ans = s[0] + to_string(s.size() - 2) + s[s.size() - 1];

    cout << ans << endl;

}

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

int main() {
  string s;
  cin >> s;
long long ans = 0;
  int b = 0;
  for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == 'B') {
      b++;
    } else {
      ans += b;
    }
  }
  cout << ans;
}

Measured memory_bytes: 640
import java.util.Scanner;

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

Measured memory_bytes: 28928
import math
N = int(input())

ans = [0] * N

for i in range(1, int(math.sqrt(N))+1):
    for j in range(1, int(math.sqrt(N)+1)):
        for k in range(1, int(math.sqrt(N)+1)):
            tmp = (i+j+k)**2 - (i*j + j*k + k*i)
            if tmp <= N:
                ans[tmp-1] += 1

for i in range(N):
    print(ans[i])

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

vector<int> *v;
int *color;
int n;

void dfs(int i, int c){
        if(color[i]==c) return;
        color[i]=c;
        for(int j=0;j<v[i].size();j++)
                dfs(v[i][j], c);
}

void assignColor(){
        int c = 1;
        for(int i=0;i<n;i++){
                if(color[i]!=0) continue;
                dfs(i,c);
                c++;
        }

}

int main(){
        int m,q,a,b;
        cin>>n>>m;
        v = new vector<int>[n];
        color = new int[n];
        for(int i=0;i<m;i++){
                cin>>a>>b;
                v[a].emplace_back(b);
                v[b].emplace_back(a);
        }
        for(int i=0;i<n;i++) color[i] = 0;

        assignColor();

        cin>>q;
        for(int i=0;i<q;i++){
                cin>>a>>b;
                if(color[a]==color[b]) cout<<"yes"<<endl;
                else cout<<"no"<<endl;
        }

        return 0;
}


Measured memory_bytes: 12108
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;


int main(){
    ll N,sum=0;
    cin >> N;
    map<string, ll> ans;
    vector<string> s(N);
    for(ll i=0; i<N; i++){
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    ans[s[i]]++;
    }
  for(auto e : ans) {
    ll tmp = e.second * (e.second - 1) / 2;
    sum += tmp;
  }
  cout << sum << endl;
}



Measured memory_bytes: 18176
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define MAX 100000
#define W 0
#define G 1
#define B 2

typedef struct Node{
  int id, d;
  struct Node *next;
} node;

int m;
node data[MAX];

void insert(int a, int id, int d)
{
  node *dd, *n;

  dd = malloc(sizeof(node));
  dd->id = id;
  dd->d = d;
  dd->next = NULL;

  for (n = &data[a]; n->next != NULL; n = n->next);
  n->next = dd;
}

void dijkstra()
{
  int c[MAX], d[MAX], min, i, u, ddd;
  node *n;
  
  for (i = 0; i < m; i++){
    c[i] = W;
    d[i] = INT_MAX;
  }
  d[0] = 0;
  while (1){
    min = INT_MAX;
    for (i = 0; i < m; i++)
      if (c[i] != B && d[i] < min){
	min = d[i];
	u = i;
      }
    if (min == INT_MAX)
      break;
    c[u] = B;
    for (n = &data[u]; n != NULL; n = n->next)
      if (c[n->id] != B && d[u]+n->d < d[n->id]){
	d[n->id] = d[u] + n->d;
	c[n->id] = G;
      }
  }
  for (i = 0; i < m; i++)
    printf("%d %d\n",i,d[i]);
}

int main()
{
  int i, j, a, b, c, d;
  
  scanf("%d",&m);
  for (i = 0; i < m; i++)
    data[i].next = NULL;
  for(i = 0; i < m; i++){
    scanf("%d%d",&a,&b);
    for (j = 0; j < b; j++){
      scanf("%d%d",&c,&d);
      insert(a,c,d);
    }
  }
  dijkstra();
  
  return 0;
}



Measured memory_bytes: 17424
n, m = [int(i) for i in input().split()]
a = []
broken = [False] * max(n+1, 3)
for _ in range(m):
    i = int(input())
    a.append(i)
    broken[i] = True

ways = [0] * 3
ways[1] = 0 if broken[1] else 1
ways[2] = 0 if broken[2] else ways[1] + 1
for i in range(3, n+1):
    if broken[i]:
        ways.append(0)
    else:
        ways.append((ways[-2]+ways[-1])%(10**9+7))

print(ways[n])


Measured memory_bytes: 8616
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

Lunlun = []
K = int(input())

def dfs(i,before):
    if i == 10:
        return
    Lunlun.append(before)
    x = before%10
    for d in (-1,0,1):
        y = x + d
        if y < 0 or y >= 10:
            continue
        dfs(i + 1,before*10 + y)

for i in range(1,10):
    dfs(0,i)
Lunlun.sort()
ans = Lunlun[K - 1]
print(ans)

Measured memory_bytes: 19356
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <queue>

int main() {
  int N, M;
  std::priority_queue<int> q;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    q.push(a);
  }
  while (M >= 1) {
    --M;
    int top = q.top();
    q.pop();
    q.push(top / 2);
  }
  long long sum = 0;
  while (!q.empty()) {
    sum += q.top();
    q.pop();
  }
  printf("%lld\n", sum);
  return 0;
}


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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int d,n,a;

main() {
    cin >> d >> n;
    a = pow(100,d);
    ct(a*n+a*(n/100)+a*(n/10000))
}





Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {


    public static void main(String[] args)  {

    	try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line;
            while((line=br.readLine())!=null){if(line.isEmpty())break;
	        	String[] spl = line.split(" ");
	            int n = Integer.parseInt(spl[0]);
	            if(n==0){break;}

	            for(int i=0; i<n; i++){
	            	//System.out.println(i+"n"+n);
	            	line= br.readLine();//spl=line.split(" ");
	            	line=line.replaceAll("Hoshino", "Hoshina");
	            	System.out.println(line);


	            }//end FOR


            }//End WHILE


        }catch(Exception e){e.printStackTrace();}

    }


}

Measured memory_bytes: 16960
N, K = map(int, input().split())
S = list(input())

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] == str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)

add = 2 * K + 1

sum = [0] * (len(nums)+1)

for i in range(len(nums)):
    sum[i+1] = sum[i] + nums[i]
ans = 0
for i in range(0, len(nums), 2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left]
    ans = max(tmp, ans)

print(ans)


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

long long n,mi=1e12;

int main()
{
    scanf("%lld",&n);
    for (long long i=1;i*i<=n;++i)
    {
        if (n%i==0)
        {
            long long x=i-1+(n/i)-1;
            mi=min(mi,x);
        }
    }
    cout<<mi;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-12;

class Compare {
  int monster_x;
  int monster_y;
public:
  Compare(int monster_x,int monster_y)
    : monster_x(monster_x), monster_y(monster_y) {}
  bool operator()(const P& ci,const P& cj) const{
    int dist_i = (ci.first - monster_x) * (ci.first - monster_x)
      + (ci.second - monster_y) * (ci.second - monster_y);
    int dist_j = (cj.first - monster_x) * (cj.first - monster_x)
      + (cj.second - monster_y) * (cj.second - monster_y);
    return dist_i < dist_j;
  }
};

class State{
  int x;
  int y;
  double dist;
};

bool dfs(int hero_x,
         int hero_y,
         double current_time,
         int S,
         int monster_x,
         int monster_y,
         const vector<P>& cristals){
  bool res = false;

  if(S == (1<<cristals.size()) - 1) return true;
  for(int i=0;i<cristals.size();i++){
    if(S & (1<<i)) continue;
    double add_time = sqrt((hero_x - cristals[i].first) * (hero_x - cristals[i].first)
                           + (hero_y - cristals[i].second) * (hero_y - cristals[i].second));
    
    double tmp_current_time = current_time + add_time;
    double impurity_arrive_time = sqrt((monster_x - cristals[i].first) * (monster_x - cristals[i].first)
                                       + (monster_y - cristals[i].second) * (monster_y - cristals[i].second));
    if(tmp_current_time >= impurity_arrive_time){
      return false;
    }
    
    res |= dfs(cristals[i].first,cristals[i].second,tmp_current_time,
               S | (1<<i),monster_x,monster_y,cristals);
  }
  return res;
}

int main(){
  int total_cristals;
  int hero_x;
  int hero_y;
  int monster_x;
  int monster_y;
  while(~scanf("%d %d %d %d %d",
               &total_cristals,
               &hero_x,
               &hero_y,
               &monster_x,
               &monster_y)){
    if(total_cristals == 0 && hero_x == 0 && hero_y == 0
       && monster_x == 0 && monster_y == 0) break;
    vector<P> cristals;
    for(int cristal_i = 0; cristal_i < total_cristals; cristal_i++){
      int x,y;
      scanf("%d %d",&x,&y);
      cristals.push_back(P(x,y));
    }
    Compare comp(monster_x,monster_y);
    sort(cristals.begin(),cristals.end(),comp);
    printf("%s\n", dfs(hero_x,hero_y,0,0,monster_x,monster_y,cristals)
           ? "YES" : "NO");
  }
}

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

using namespace std;

int n;
long long ans;
string s;
map < string, long long > a;

void Process()
{
    cin >> n;

    for (int i=1; i<=n; i++)
    {
        cin >> s;

        for (int i=0; i<=8; i++)
            for (int j=i+1; j<=9; j++)
                if (s[i] > s[j]) swap(s[i], s[j]);

        //cout << s << endl << endl;

        a[s]++;
    }

    map<string, long long>::iterator o;
    for (o=a.begin(); o!=a.end(); o++)
    {
        long long t = o->second;
        //cout << t << endl;
        ans += t*(t-1)/2;
    }

    cout << ans;
}

void Input()
{

}

int main()
{
    Input();
    Process();
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int s, w;
  cin >> s >> w;

  if(w >= s){
    cout << "unsafe" << endl;
  }
  else{
    cout << "safe" << endl;
  }

  return 0;
}


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

using namespace std;


int main(){
    int n,W;
    cin >> n >> W;
    vector<int> w(n),v(n);
    for(int i = 0; i < n ; i++) cin >> w[i] >> v[i];
    
    
    vector<vector<long long>> dp(W+1,vector<long long> (n+1,0LL));



    for(int i = 1; i < n+1;i++){
        for (int j = 0; j < W+1;j++){
            dp[j][i] = dp[j][i-1];
        }
        for (int j = 0; j < W+1; j++){
            int newWeight = j + w[i-1];
            if (newWeight <= W) dp[newWeight][i] = max(dp[newWeight][i-1],dp[j][i-1] + (long long) v[i-1]);
        }
    }
    long long ans = 0LL;
    for (int i = 0; i < W+1; i++){
        ans = max(ans,dp[i][n]);
    }
    cout << ans;
}

Measured memory_bytes: 82304
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

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

	ll n, k;
	cin >> n >> k;
	
	vector<ll> cou;
	for (ll s = n; s > 0;) {
		ll nxt_s = n/(n/s + 1);
		cou.push_back(s - nxt_s);
		s = nxt_s;
	}
	reverse(cou.begin(), cou.end());
	int m = cou.size();

	vector<ll> cur = cou;
	vector<ll> nxt(m);
	for (int i = 1; i < k; ++i) {
		for (int j = 0; j < m; ++j) {
			int t = m-1-j;
			nxt[t] = cur[j] % MOD;
		}
		for (int j = m-1; j >= 0; --j) {
			nxt[j] = (nxt[j] + (j+1 < m ? nxt[j+1] : 0)) % MOD;
			cur[j] = (nxt[j] * cou[j]) % MOD;
		}
	}

	ll res = 0;
	for (auto v : cur) res = (res + v) % MOD;
	cout << res << '\n';
}


Measured memory_bytes: 1912
#include<iostream>
using namespace std;
int main() {
  int n;
  long long min=1000000000, max=0;
  long long a[105];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i] >= max) max = a[i];
    if(a[i] <= min) min = a[i];
  }
  cout << max - min << endl;
  return 0;
}

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

using namespace std;

int main() {

  int N, T;
  cin >> N >> T;
  vector<int> cs(N);
  vector<int> ts(N);
  for (int i = 0; i < N; ++i) {
    cin >> cs[i] >> ts[i];
  }

  int min = 1e9;
  for (int i = 0; i < N; ++i) {
    if (ts[i] <= T) {
      if (cs[i] <= min) {
        min = cs[i];
      }
    }
  }

  if (min != 1e9) {
    cout << min << endl;
  } else {
    cout << "TLE" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(n+1, 0);
  REP(i, m){
    int t;
    cin >> t;
    a[t]++;
  }
  int ans = 0, t = 0;
  REP(i, x) ans += a[i];
  FORe(i, x+1, n) t += a[i];
  chmin(ans, t);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, shortest_path

def main():
    n = int(input())
    s = np.array([list(input()) for _ in range(n)], dtype=np.int64)
    wf = csgraph_from_dense(s)
    wf = shortest_path(wf, method="FW")
    idx = -1
    tmp = 0
    for i in range(n):
        for j in range(n):
            if wf[i][j] > tmp:
                idx = i
                tmp = wf[i][j]
    st = [set() for _ in range(int(tmp)+1)]
    f = True
    for j in range(n):
        x = int(wf[idx][j])
        for v in st[x]:
            if s[j][v] != 0:
                f = False
        st[x].add(j)
    if f:
        print(int(tmp)+1)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 16836
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int n,m;
    cin >> n >> m;
    // int ans = (n+m)*(n+m-1)/2-n-m;
    int ans = ((n)*(n-1) + (m)*(m-1)) / 2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

ll n,k;
void solve(){
 cin >> n >> k;
 cout << min(n%k,k-n%k) << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 256
n = gets.to_i
d = gets.split.map(&:to_i)

if d[0] != 0
  puts 0
  exit
end

mod = 998244353

node_cnt = Array.new(n, 0)
n.times do |i|
  node_cnt[d[i]] += 1
end

if node_cnt[0] > 1
  puts 0
  exit
end

ans = 1
sum = 0
1.upto(n - 1) do |i|
  ans *= node_cnt[i - 1] ** node_cnt[i]
  ans %= mod
  sum += node_cnt[i]
  break if sum == n
end

puts ans

Measured memory_bytes: 9612