akhauriyash/Code-Regression huggingface dataset:
def cin; gets.split.map(&:to_i) end
def cout(*x); puts x.join(" ") end

exit if $0 != __FILE__

$n, *$abc = cin
$l = Array.new($n).map { gets.to_i }

def dfs(i, a, b, c)
  if i == $n then
#    puts "#{i},#{a},#{b},#{c}"
    return 10000*8 if [a,b,c].min == 0
    return ($abc[0]-a).abs + ($abc[1]-b).abs + ($abc[2]-c).abs
  end
  r0 = dfs(i+1, a, b, c)
  r1 = dfs(i+1, a+$l[i], b, c) + 10
  r2 = dfs(i+1, a, b+$l[i], c) + 10
  r3 = dfs(i+1, a, b, c+$l[i]) + 10
#  p [r0,r1,r2,r3]
  [r0,r1,r2,r3].min
end

puts dfs(0, 0, 0, 0)-30

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;

        vector<int> t(n);
        vector<int> c(n);
        vector<vector<int>> tm(n, vector<int>(510, 0));
        vector<vector<int>> dlap(n, vector<int>(n, 0));
        for (int i = 0; i < n; ++i) {
            cin >> t[i] >> c[i];
        }
        for (int i = 1; i < 510; ++i) {
            for (int j = 0; j < n; ++j) {
                if (c[j] * 2 < i) continue;
                if (i < 3) {
                    tm[j][i] = t[j] * i;
                    continue;
                }
                int ma = tm[j][i - 1] + t[j];
                for (int k = 0; k < n; ++k) {
                    if (tm[k][i - (dlap[j][k] + 1) * 2] > ma) {
                        ma = tm[k][i - (dlap[j][k] + 1) * 2];
                    }
                }
                for (int k = 0; k < n; ++k) {
                    if (tm[k][i - (dlap[j][k] + 1) * 2] == ma) {
                        ++dlap[j][k];
                    }
                }
                tm[j][i] = ma;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            ans = max(ans, tm[i][c[i] * 2]);
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3144
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())


def main():
    if abs(a-b) > k:
        return ":("
    if abs(a-c) > k:
        return ":("
    if abs(a-d) > k:
        return ":("
    if abs(a-e) > k:
        return ":("
    if abs(b-c) > k:
        return ":("
    if abs(b-d) > k:
        return ":("
    if abs(b-e) > k:
        return ":("
    if abs(c-d) > k:
        return ":("
    if abs(c-e) > k:
        return ":("
    if abs(d-e) > k:
        return ":("
    return "Yay!"


print(main())

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    S = [rl().rstrip() for _ in range(N)]
    
    ans = 0
    for b in range(N):
        flg = True
        for i in range(N):
            ii = (i + b) % N
            for j in range(N):
                jj = (j + b) % N
                if S[i][jj] != S[j][ii]:
                    flg = False
                    break
            if not flg:
                break
        ans += flg
    ans *= N
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39792
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d, ans = 0;
    cin >> d >> n;
    for(int i = 1; i <= 10000000; i++){
        int cnt = 0, tmp = i;
        while(1){
            if(tmp % 100 == 0){
                cnt++;
                tmp /= 100;
            }else break;
        }
        if(cnt == d){
            ans++;
            if(ans == n){
                cout << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}
int ans[1000005];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    string a;
    cin>>a;
    int tot=0;
    for(int i=0;i<n;i++)
    {
        tot+=a[i]-'0';
    }
    vector<pair<int,int> >lol;
    if(tot==0)
    {
        for(int i=0;i<n;i++)
            cout<<1<<'\n';
        return 0;
    }
    else if(tot==1)
    {
        if(a[n-1]=='1')
        {
            for(int i=0;i<n-1;i++)
            {
                if(a[i]=='1')
                    cout<<0<<'\n';
                else
                    cout<<2<<'\n';
            }
        }
        else
        {
            for(int i=0;i<n-1;i++)
            {
                if(a[i]=='0')
                    cout<<1<<'\n';
                else
                    cout<<0<<'\n';
            }            
        }
        
        if(a[n-1]=='1')
            cout<<0;
        else
            cout<<2;
        return 0;        
    }
    if(tot>1)
    {
        int x=tot-1;
        int tt=1;
        int rem=0;
        for(int i=n-1;i>=0;i--)
        {
            rem+=((a[i]-'0')*tt)%x;
            rem%=x;
            tt=(tt*2)%x;
        }
        int y=tot+1;
        tt=1;
        int rem2=0;
        for(int i=n-1;i>=0;i--)
        {
            rem2+=((a[i]-'0')*tt)%y;
            rem2%=y;
            tt=(tt*2)%y;
        }
        int tt1=1;
        int tt2=1;
        for(int i=n-1;i>=0;i--)
        {
            int z=0;
            if(a[i]=='1')
            {
                z=rem-tt1+x;
                z%=x;
            }
            else
            {
                z=rem2+tt2;
                z%=y;                
            }
            lol.push_back({z,1});
            tt1=(tt1*2)%x;
            tt2=(tt2*2)%y;
        }
    }
    reverse(lol.begin(),lol.end());
    // for(auto i:lol)
    //     cout<<i.first<<endl;
    for(auto i:lol)
    {
        int cnt=1;
        int xx=i.first;
        // cout<<xx<<endl;
        while (xx>0)
        {
            int z=__builtin_popcount(xx);
            // cout<<xx<<" "<<z<<" "<<cnt<<endl;
            xx%=z;
            cnt++;
        }
        // break;
        cout<<cnt<<'\n';
    }
    

} 
    


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

using namespace std;
int main(){
    stack<int> s;
    string c = "";
    int a,b;
    while(cin >> c){
        if(c == "+" || !c.compare("-") || !c.compare("*")){
            a = s.top();
            s.pop();
            b = s.top();
            s.pop();
            if(!c.compare("+")){
                s.push(a+b);
            }else if(!c.compare("-")){
                s.push(b-a);
            }else if(!c.compare("*")){
                s.push(a*b);
            }
        }else{
            s.push( stoi(c) );
        }
        
    }
    cout << s.top() << endl;
    
    return 0;
}


Measured memory_bytes: 3184
#include <float.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int f(int r, int l){
	return min2(l, r-l);
}

int d[2000];
int main(void){
	int n=nextpint();
	int x=nextpint();
	int y=nextpint();
	int r=y-x+1;
	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			int now;
			if(i<=x && y<=j){
				now=j-i+x-y+1;
			}else if(i<=x && j<=x){
				now=j-i;
			}else if(y<=i && y<=j){
				now=j-i;
			}else if(i<=x){
				now=x-i+f(r, j-x);
			}else if(y<=j){
				now=j-y+f(r, y-i);
			}else{
				now=f(r, j-i);
			}
			//printf("%d %d %d\n", i, j, now);
			d[now]++;
		}
	}
	for(int i=1; i<n; i++){
		printf("%d\n", d[i]);
	}
}


Measured memory_bytes: 128
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    string S;
    cin >> S;
    string R=S, L=S;
    int cnt[2]={0};
    int edge[2]={0}, cur=0;
    edge[0]=(int)(S[0]-'0');
    edge[1]=(int)(S[S.length()-1]-'0');
    if(S.length()>=2) {
        reps(i,1,S.length()-1) {
            if((int)(L[i]-'0')==(int)(L[i-1]-'0')) {
                cnt[0]++;
                L[i]='0'+!(int)(L[i-1]-'0');
            }
            int cur = S.length()-1-i;
            if((int)(R[cur]-'0')==(int)(R[cur+1]-'0')) {
                cnt[1]++;
                R[cur]='0'+!(int)(R[cur+1]-'0');
            }
        }
        cout << MIN(cnt[0],cnt[1]);
    } else {
        cout << 0 << endl;
    }
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

  vector<string> ANS;
  void DFS(int D,int N,string str,int k)
  {
    // DEBUG("call",D);
    if(D==N)
    {
      cout<<str<<endl;
      return;
    }
    for (int i = 0; i <= k; i++)
    {
      DFS(D+1,N,str+char('a'+i),max(k,i+1));
    }
    return;
  }
void solve(void)
{
  int N;
  cin>>N;
  DFS(0,N,"",0);
  sort(ALL(ANS));

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			long ans = 1;
			var a = cin.ArrayLong(n);
			bool ok = true;
			if (a.Contains(0)) ans = 0;
            for (int i = 0; i < n; i++)
            {
				if(1000000000000000000.0 / ans < a[i])
                {
					ok = false;
					goto End;
                }
				ans *= a[i];
            }
			End:
            if (ok && ans <= 1000000000000000000L) Console.WriteLine(ans);
            else Console.WriteLine(-1);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 41068
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

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

  int sum=0;
  for(int i=0;i<N;i++) sum+=L+i;

  int ans=MOD;
  for(int i=0;i<N;i++){
    int tmp=sum-(L+i);
    if(abs(tmp-sum)<abs(ans-sum)) ans=tmp; 
  }

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;
int N;

int main() {
  cin >> N;
  int a = N%10;
  N /= 10;
  int b = N%10;
  N /= 10;
  int c = N%10;
  if (a == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define re register
int fac[3000100],ifac[3000100],f[3000100];
const int mod=998244353;
int ex(re int a,re int b)
{
	re int ans=1;
	for(;b;b>>=1,a=(long long)a*a%mod)if(b&1)ans=(long long)ans*a%mod;
	return ans;
}
int c(re int a,re int b){return (long long)fac[a]*ifac[b]%mod*ifac[a-b]%mod;}
int main()
{
	re int n,m,mm,ans=0;
	scanf("%d%d",&n,&m);mm=3*m/2;
	fac[0]=1;
	for(re int i=1;i<=n+mm;i++)fac[i]=(long long)fac[i-1]*i%mod;ifac[n+mm]=ex(fac[n+mm],mod-2);
	for(re int i=n+mm;i;i--)ifac[i-1]=(long long)ifac[i]*i%mod;
	for(re int i=0;i<=mm;i++)
	{
		f[i]=c(n+i-1,n-1);
		if(m*3-i*2<=m&&m*3-i*2<=n)ans=(ans+(long long)f[i]*c(n,m*3-i*2))%mod;
	}
	ans=(ans+(long long)(mod-f[m-1])*n)%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 22784
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  ll H, W;
  cin >> H >> W;
  ll ans = ceil((H*W)/2.0);
  if(H == 1 || W == 1){
    ans = 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    w = Counter(IS())
    for wi in w.values():
        if wi%2!=0:
            print('No')
            return None
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
ll x,y,a,b,c;
ll aa[100100],bb[100100],cc[100100];
int main()
{
	ios::sync_with_stdio(0);
	cin>>x>>y>>a>>b>>c;
	rep(i,a)
		cin>>aa[i];
	rep(i,b)
		cin>>bb[i];
	rep(i,c)
		cin>>cc[i];
	sort(aa,aa+a);
	//reverse(aa,aa+a); 
	sort(bb,bb+b);
	//reverse(bb,bb+b); 
	sort(cc,cc+c);
	reverse(cc,cc+c);
	ll a1=a-x,b1=b-y,c1=0;
	ll ans=0;
	forn(i,a-x,a)
		ans+=aa[i];
	forn(i,b-y,b)
		ans+=bb[i];
	//cout<<ans<<endl;
	while(aa[a1]<cc[c1]||bb[b1]<cc[c1])
	{
		if(c1>=c)break;
		if(a1>=a&&b1>=b)break;
		if(a1>=a&&bb[b1]>=cc[c1])break;
		if(b1>=b&&aa[a1]>=cc[c1])break;
		if(bb[b1]<cc[c1]&&aa[a1]>=cc[c1]&&b1<b)
		{
			ans-=bb[b1++];
			ans+=cc[c1++];
		}
		else if(aa[a1]<cc[c1]&&bb[b1]>cc[c1]&&a1<a)
		{
			ans-=aa[a1++];
			ans+=cc[c1++];
		}
		else
		{
			if((aa[a1]>=bb[b1]&&a1<a&&b1<b)||(a1>=a&&b1<b))
			{
				ans-=bb[b1++];
				ans+=cc[c1++];
			}
			else
			{
				ans-=aa[a1++];
				ans+=cc[c1++];
			}
		}
	}
	 cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 2560
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int N = readln.split[0].to!int;
  int[] a = readln.split.to!(int[]);

  int[] ans = new int[N];
  foreach_reverse(i, c; a) {
    ulong n = i + 1;
    ans[i] = c ^ iota(i, N, n).map!(j => ans[j]).reduce!"a ^ b";
  }

  int cnt = ans.reduce!"a+b";
  writeln(cnt);
  foreach(i, c; ans) {
    if(c == 1) write(i+1, " ");
  }
}


Measured memory_bytes: 7704
#include<stdio.h>
void gcd(int x, int y);
void output(int x);

int main(void){
  int x=0;
  int y=0;

  scanf("%d",&x);
  scanf("%d",&y);

 
  gcd(x,y);

  return 0;
}


void gcd(int x, int y){
 
  int t=0;
  if(y==0)
    output(x);
  else{
    t = x%y;
    gcd(y,t);
  }
}

void output(int x){
  printf("%d",x);
  putchar('\n');
}




  



Measured memory_bytes: 2136
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^8 -> 8回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p.at(i);

    int ans = 0;
    int curMin = 1e9;
    rep(i, n) {
        curMin = min(curMin, p.at(i));
        if (curMin == p.at(i)) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4036
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a + b >= 10) {
            System.out.println("error");
            return;
        }
        System.out.println(a + b);
    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> k >> s;

    vector<int> num;
    int right;
    if (s[0] == '0')
        num.push_back(0);
    for (int left = 0; left < n;)
    {
        right = left;
        while (right < n && s[left] == s[right])
        {
            right++;
        }
        num.push_back(right - left);
        left = right;
    }
    if (s.back() == '0')
        num.push_back(0);

    vector<int> ruiseki((int)num.size() + 1, 0);
    for (int i = 0; i < num.size(); i++)
    {
        ruiseki[i + 1] = ruiseki[i] + num[i];
    }

    int ans = 0;
    for (int left = 0; left < ruiseki.size(); left += 2)
    {
        int right = left + 2 * k + 1;
        if (right >= (int)ruiseki.size())
            right = (int)ruiseki.size() - 1;
        ans = max(ans, ruiseki[right] - ruiseki[left]);
    }

    cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> par;

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

    void init(int n) { par.assign(n, -1); }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind fr(N);
    vector<int> cnt(N, 0);
    rep(_, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        fr.merge(a, b);
        cnt[a]++;
        cnt[b]++;
    }

    rep(_, K) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        if (fr.issame(c, d)) cnt[c]++, cnt[d]++;
    }

    rep(i, N) cout << max(fr.size(i) - cnt[i] - 1, 0) << " ";
    cout << endl;
}


Measured memory_bytes: 1664
import numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))[::-1]
SUM = 0
cnt = 0
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM >= H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)


Measured memory_bytes: 17100
N = int(input())
for _ in range(N):
    balls = list(map(int, input().split()))
    B, C = [0], [0]
    ans = 1
    for i in range(10):
        b = balls[i]
        if b > B[-1]:
            B.append(b)
        else:
            if b > C[-1]:
                C.append(b)
            else:
                ans = 0
                break
    print("YES" if ans else "NO")

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

int main() {
	double d, e;
	while (cin >> d >> e, d) {
		double Min = (double)INT_MAX;
		for (double x = 0; x <= d; x++)
			Min = min(Min, abs(e - sqrt(x*x + (d - x)*(d - x))));
		printf("%.10f\n", Min);
	}
}

Measured memory_bytes: 3204
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
bool artpts[100000];
int dfs_num[100000], dfs_low[100000], dfsNumberCounter = 0, rootChildren = 0;
vector<int> adjlist[100000];
void artPt(int u, int p) {
    dfs_low[u] = dfs_num[u] = dfsNumberCounter++;
    for (int v: adjlist[u]) {
        if (dfs_num[v] == -1) {
            if (u == 0) ++rootChildren;
            artPt(v, u);
            if (dfs_low[v] >= dfs_num[u]) artpts[u] = true;
            dfs_low[u] = min(dfs_low[u], dfs_low[v]);
        } else if (v != p) dfs_low[u] = min(dfs_low[u], dfs_num[v]);
    }
}
int main() {
    int N, M, a, b;
    scanf("%d %d", &N, &M);
    fill_n(dfs_num, N, -1);
    fill_n(dfs_low, N, 0);
    fill_n(artpts, N, false);
    for (int i = 0; i < M; ++i) {
        scanf("%d %d", &a, &b);
        adjlist[a - 1].push_back(b - 1);
        adjlist[b - 1].push_back(a - 1);
    }
    for (int i = 0; i < N; ++i) {
        if (adjlist[i].size() % 2) {
            printf("No");
            return 0;
        }
    }
    for (int i = 0; i < N; ++i) {
        if (adjlist[i].size() > 4) {
            printf("Yes");
            return 0;
        }
    }
    artPt(0, -1);
    if (rootChildren > 1) artpts[0] = true;
    else artpts[0] = false;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (artpts[i]) ans += 2;
        else if (adjlist[i].size() == 4) ans += 1;
    }
    if (ans > 2) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 10880
N = int(input())
Yen = 0
Bit = 0

for i in range(N):
    x,u = input().split()
    x1 = float(x) 
    if u =="JPY":
        Yen += x1
    elif u == "BTC":
        Bit += x1

Yen +=Bit*380000

print(Yen)

Measured memory_bytes: 3060
n = int(input())
ta = [[int(i) for i in input().split()] for i in range(n)]

ct = ta[0][0]
ca = ta[0][1]

for i in range(1, n):
    t, a = ta[i]

    if ct / t > ca / a:
        if ct%t == 0:
            rate = ct//t
        else:
            rate = ct//t+1
    else:
        if ca%a == 0:
            rate = ca//a
        else:
            rate = ca//a+1
    ct = rate * t
    ca = rate * a
print(ct+ca)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
char mat[501][510];
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    bool found =false;
    FOR(i, n)FOR(j, n)cin >> mat[i][j], found |= (mat[i][j] == '#');

    if(!found){
        cout << -1;
        return 0;
    }
    int ans =0;
    int mn = 1000;
    FOR(row, n){
        found =false;
        FOR(col, n){
            if(mat[col][row] == '#')found =true;
        } 
        int cnt = 0;
        FOR(i, n){
            if(mat[row][i] == '.')cnt++;
        }
        mn = min(mn, cnt + (found == false));
    }
    int cnt = 0;
    int op = 0;
    FOR(col, n){
        cnt = 0;
        FOR(i, n){
           if(mat[i][col] == '#')cnt++; 
        }
        if(cnt != n)op++;
    }
    cout << mn + op << endl;

}




Measured memory_bytes: 512
import java.util.*;

public class Main {
    static long[] base = new long[61];
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        base[0] = 1;
        for (int i = 1; i < base.length; i++) {
            base[i] = base[i - 1] * 2 % MOD;
        }
        boolean[][] arr = new boolean[n + 1][61];
        for (int i = 1; i <= n; i++) {
            arr[i] = getArray(sc.nextLong());
        }
        long ans = 0;
        int[][] sums = new int[n + 1][61];
        for (int i = 0; i < 61; i++) {
            for (int j = 1; j <= n; j++) {
                sums[j][i] = sums[j - 1][i];
                if (arr[j][i]) {
                    sums[j][i]++;
                } 
                if (arr[j][i]) {
                    ans += (j - sums[j][i]) * base[i];
                    ans %= MOD;
                } else {
                    ans += sums[j][i] * base[i];
                    ans %= MOD;
                }
                
            }
        }
        System.out.println(ans);
    }
    
    static boolean[] getArray(long x) {
        boolean[] ans = new boolean[61];
        for (int i = 0; i <= 60; i++) {
            ans[i] = x % 2 == 1;
            x /= 2;
        }
        return ans;
    }
}


Measured memory_bytes: 248184
N, K = map(int, input().split())
MOD=10**9+7

from operator import mul
from functools import reduce

def cmb(n,r):
    if n < r: return 0 # added
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(1,K+1):
    ans=cmb(N-K+1, i)%MOD*cmb(K-1, i-1)%MOD
    # cmb(N-K+i, i) -> cmb(N-K+1, i)
    print(ans)

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

struct UnionFind {
    vector<int> par;
    vector<int> rnk;
 
    UnionFind(int n) {
        par.assign(n, 0);
        rnk.assign(n, 1);
        for(int i=0; i<n; i++) {
            par[i] = i;
        }
    }
 
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        if(rnk[x] < rnk[y]) swap(x, y);
        rnk[x] += rnk[y];
        par[y] = x;
    }
 
    int find(int x) {
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }
 
    bool same(int x, int y) {
        return find(x) == find(y);
    }
 
    int size(int x) {
        return rnk[find(x)];
    }
};

signed main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N+1);
    vvi lang(M);
    rep(i, N) {
        int k;
        cin >> k;
        rep(j, k) {
            int l;
            cin >> l;
            l--;
            lang[l].pb(i);
            int t = lang[l].size();
            if(t>1) {
                uf.unite(lang[l][t-1], lang[l][t-2]);
            }
        }
    }

    /*rep(i, M) {
        if(lang[i].size()<2) continue;
        FOR(j, 1, lang[i].size()) {
            uf.unite(lang[i][0], lang[i][j]);
        }
    }*/

    if(uf.size(0)==N) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 5368
H , W = [int(i) for i in input().split()]

a = []

for i in range(H):
    line = [int(i) for i in input().split()]
    a.append(line)
ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] % 2 == 1:
            ans.append(str(i+1) + ' '+ str(j+1)+' '+str(i+1) + ' '+str(j+2))
            a[i][j+1] += 1


for i in range(H-1):
    if a[i][W-1] % 2 ==1:
        ans.append(str(i+1)+' '+str(W)+' '+str(i+2)+' '+str(W))
        a[i+1][W-1] +=1
print(len(ans))
for i in ans:
    print(i)


Measured memory_bytes: 16220
l = (list)(map(int, input().split()))

count = 0
max_num = max(l)
l2 = []
for n in l:
  c = (max_num-n)//2
  count += c
  l2.append(n+2*c)

m = max(l2)
count += l2.count(m) % 3


print(count)


Measured memory_bytes: 3060
N, K = map(int, input().split())
S = input()
K -= 1
ans = S[:K]
if S[K] == 'A':
    ans += 'a'
elif S[K] == 'B':
    ans += 'b'
else:
    ans += 'c'
ans += S[K+1:]
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var pattern = new int[10, 10];

        for (int i = 1; i <= N; i++)
        {
            var s = i.ToString();
            var start = int.Parse(s.First().ToString());
            var end = int.Parse(s.Last().ToString());
            pattern[start, end]++;
        }

        var count = 0L;
        for (int i = 0; i <= 9; i++)
        {
            for (int j = 0; j <= 9; j++)
            {
                count += pattern[i, j] * pattern[j, i];
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 15416
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from statistics import mean
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
a = f()
m = mean(a)
min_ = 5000000000
ans = 0
for i, v in enumerate(a):
    if abs(v-m) < min_:
        min_ = abs(v-m)
        ans = i
print(ans)


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

using namespace std;

typedef long long ll;
int main()
{
	ll n,W; cin >> n >> W;
	vector<ll> s(n+1), v(n+1);
	for(int i = 1; i <= n; i++) cin >> s[i] >> v[i];

	vector<vector<ll>> dp(n+1, vector<ll>(W+1));

	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= W; j++){
			ll x = 0, y = 0;
			x = dp[i-1][j];
			if(j >= s[i]) y = dp[i-1][j-s[i]]+v[i];
			dp[i][j] = max(x,y);
		}
	}
	cout << dp[n][W];
}


Measured memory_bytes: 83200
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
vector<long long int> g[200010],w(200010);
void dfs(int v,int pre = -1)
{
  for (auto u : g[v])
  {
    if (u == pre)
    {
      continue;
    }
    w[u] += w[v];
    dfs(u,v);
  }
}
int main()
{
 long long int n,m;
  cin >> n >> m;
  for (int i = 0; i < n-1; ++i)
  {
    long long int a,b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < m; ++i)
  {
    long long int p,q;
    cin >> p >> q;
    p--;
    w[p] += q;
  }
  dfs(0);
  for (int i = 0; i < n; ++i)
  {
    cout << w[i] << " ";
  }
  return 0;
} 


Measured memory_bytes: 24320
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    int n, m, p;
    while (cin>>n>>m>>p, n||m||p) {
        int x[100];
        int total = 0;
        for (int i = 0; i < n; ++i) {
            cin>>x[i];
            total += x[i];
        }
        long long result = 0;
        result += 100 * total;
        result = result * (100-p) / 100;
        if (x[m-1] == 0) cout<<0<<endl;
        else cout << result / x[m-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>
#include<array>

using namespace std;

int main()
{
  int n;
  char c;
  string s;
  array<int, 4> cnt{};

  while ( cin >> n >> c >> s )
    {
      if ( s == "A" )
        ++cnt[0];
      else if ( s == "B" )
        ++cnt[1];
      else if ( s == "AB" )
        ++cnt[2];
      else
        ++cnt[3];
    }

  for ( auto i = 0; i < 4; ++i )
    cout << cnt[i] << endl;
  
  return 0;
}

Measured memory_bytes: 1204
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;


int main() {
	int map[50][50] = { 0 };
	int a, b, c;
	char ch;
	while (cin >> a >> ch >> b >> ch >> c) {
		map[b][a]++;
		if (c == 1) {
			map[b + 1][a]++;
			map[b - 1][a]++;
			map[b][a + 1]++;
			map[b][a - 1]++;
		}
		else if (c == 2) {
			map[b - 1][a - 1]++;
			map[b - 1][a]++;
			map[b - 1][a + 1]++;
			map[b][a + 1]++;
			map[b + 1][a + 1]++;
			map[b + 1][a]++;
			map[b + 1][a - 1]++;
			map[b][a - 1]++;
		}
		else {
			map[b - 1][a - 1]++;
			map[b - 1][a]++;
			map[b - 1][a + 1]++;
			map[b][a + 1]++;
			map[b + 1][a + 1]++;
			map[b + 1][a]++;
			map[b + 1][a - 1]++;
			map[b][a - 1]++;
			map[b + 2][a]++;
			map[b - 2][a]++;
			map[b][a + 2]++;
			map[b][a - 2]++;
		}
	}
	int ans = 0, maxl = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (!map[i][j])ans++;
			maxl = max(maxl, map[i][j]);
		}
	}
	cout << ans << endl << maxl << endl;
}

Measured memory_bytes: 3024
def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return right-left


def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left+right)//2
        ans1 = merge_sort(A, left, mid)
        ans2 = merge_sort(A, mid, right)
        return merge(A, left, mid, right)+ans1+ans2
    return 0


N = int(input())
S = list(map(int, input().split()))
ans = merge_sort(S, 0, N)
print(*S)
print(ans)



Measured memory_bytes: 61648
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long a,b,s;
int main()
{
	long long u,v;
	cin>>a>>b;
	u=b;
	v=0;
	while(u!=0)
	{
		v++;
		u/=10;
	}
	a=(a*pow(10,v))+b;
	s=sqrt(a);
	if(s*s==a)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return(0);
}

Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, qq = list(map(int, input().rstrip('\n').split()))

    ls = collections.defaultdict(list)
    ls[1]
    for i in range(n-1):
        a, b = map(int, input().rstrip('\n').split())
        ls[a] += [b]
        ls[b] += [a]

    ans = [0 for _ in range(n)]
    for i in range(qq):
        p, x = map(int, input().rstrip('\n').split())
        ans[p-1] += x

    q = collections.deque()
    q.append(1)
    fq = collections.defaultdict(list)
    while True:
        if len(q) != 0:
            p = q.popleft()
            fq[p]
            for i in ls[p]:
                if i not in fq:
                    q.append(i)
                    ans[i-1] += ans[p-1]
        else:
            break
    print(*ans)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 98276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    REP(i, n){
        cin >> a.at(i);
        cin >> b.at(i);
    }
    sort(ALL(a));
    sort(ALL(b));

    ll ans = 0;
    if(n % 2 == 1){
        ll minv = a.at(n / 2);
        ll maxv = b.at(n / 2);
        ans = maxv - minv + 1;
    }else{
        ll minv2 = a.at(n / 2 - 1) + a.at(n / 2);
        ll maxv2 = b.at(n / 2 - 1) + b.at(n / 2);
        ans = maxv2 - minv2 + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6360
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define INF 9223372036854777ll
#define pb push_back
using namespace std;

void solve(){
    int n;
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
    cin>>a[i][j];
    int dp[(1<<n)]={};
    dp[0]=1;
    for(int i=0;i<(1<<n)-1;++i){
        int x=__builtin_popcount(i);
        for(int j=0;j<n;++j){
            if(a[x][j] && !(i & (1<<j))){
                int m=i ^ (1<<j);
                dp[m]+=dp[i];
                dp[m]%=mod;
            }
        }
    }
    
    cout<<dp[(1<<n)-1];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 11744
-- Switching Railroad Cars
import Control.Monad.State

type Stack a = StateT [Int] IO a

main = getContents >>= solve

solve :: String -> IO ()
solve = (\xs -> evalStateT (switchRailroad xs) []) . map read . lines

-- reference:
-- Simple StateT use
-- https://wiki.haskell.org/Simple_StateT_use
pop :: Stack Int
pop = do
  (x:xs) <- get
  put xs
  return x

push :: Int -> Stack Int
push x = do
  xs <- get
  put (x:xs)
  return x

switchRailroad :: [Int] -> Stack ()
switchRailroad [] = return ()
switchRailroad (x:xs)
  | x == 0 = do n <- pop
                liftIO $ print n
                switchRailroad xs
  | otherwise = do push x
                   switchRailroad xs

Measured memory_bytes: 3992
def readinput():
    n,k=map(int,input().split())
    lr=[]
    for _ in range(k):
        l,r=map(int,input().split())
        lr.append((l,r))
    return n,k,lr

def main(n,k,lr):
    lrs=sorted(lr,key=lambda x:x[0])
    MOD=998244353
    dp=[0]*(n+1)
    dp[1]=1
    for i in range(1,n):
        #print(i)
        if dp[i]==0:
            continue
        skip=False
        for l,r in lrs:
            for j in range(l,r+1):
                #print('i+j: {}'.format(i+j))
                if i+j>n:
                    skip=True
                    break
                dp[i+j]=(dp[i+j]+dp[i])%MOD
                #print(dp)
            if skip:
                break
    return dp[n]

def main2(n,k,lr):
    lrs=sorted(lr,key=lambda x:x[0])
    MOD=998244353
    dp=[0]*(n+1)
    ruiseki=[0]*(n+1)
    dp[1]=1
    ruiseki[1]=1
    for i in range(2,n+1):
        for l,r in lrs:
            if i-l<1:
                break
            dp[i]+=ruiseki[i-l]-ruiseki[max(1,i-r)-1]
        dp[i]=dp[i]%MOD
        ruiseki[i]=(ruiseki[i-1]+dp[i])%MOD
    return dp[n]

if __name__=='__main__':
    n,k,lr=readinput()
    ans=main2(n,k,lr)
    print(ans)


Measured memory_bytes: 24660
n,m,x=map(int,input().split())
c=[]
a=[]

for i in range(n):
    ca=list(map(int,input().split()))
    c.append(ca[0])
    a.append(ca[1:])
ok=False
money=[]

for cnt in range(2**n):
    aa=[0 for j in range(m)]
    mon=0
    for i in range(n):
        if 2**i & cnt !=0:
            mon+=c[i]
            for mm in range(m):
                aa[mm]+=a[i][mm]
    if min(aa) >= x:
        ok = True
        money.append(mon)

if ok:
    print(min(money))
else:
    print(-1)

Measured memory_bytes: 9304
#define M 99999
T[M],t[M];main(I,i,j,m,a,b,p,q){
for(i=2;i<M;i++)if(!T[i])for(j=i*2;j<M;j+=i)T[j]=1;
for(i=2,j=1;i<M;i++)if(!T[i])t[j++]=i;
for(;scanf("%d%d%d",&m,&a,&b),m;printf("%d %d\n",p,q))for(i=1;I=t[i];i++)if(I*I>m)i=0,m--;else if((p=I)*(q=m/I)==m&&!T[q]&&a*q<=b*p)break;
exit(0);}

Measured memory_bytes: 1028
#include <iostream>
#include <iomanip>  
#include <cmath>
#include <algorithm> 
#include <vector> 

using namespace std; 

typedef long long ll;

long long a, b, n, x;

long long f(long long a, long long b, long long n) {
    return ll(floor(a * n / b)) - (a * 1ll * ll(floor(n / b)));
}

int main(){
    cin >> a >> b >> x;
    if (a == b) {
        cout << min(x, a - 1);
        return 0;
    }
    if (a <= b) {
        int dv = b / a;
        cout << f(a, b, min(b - dv, x));
        return 0;
    }
    cout << f(a, b, min(x, b - 1));
}
/* 3.57 */

Measured memory_bytes: 3532
n = int(input())
p = [int(i) for i in input().split()]
m = 1000
c = 0
v = 0
for i in range(n-1):
	if c == 0:
		if p[i+1] > p[i]:
			c = m // p[i]
			v = p[i]
			m -= c * v
	else:
		if p[i+1] < p[i]:
			m += p[i] * c
			c = 0
if c > 0:
     m += p[n-1] * c
print(m)
     


Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(type,var,n) vector<type> var((uint)n);rep(i,n)cin>>var[i];
#define linit(type,var,n) list<type> var;rep(i,n){type _v;cin>>_v;var.push_back(_v);}
#define range(container) container.begin(),container.end()
#define rep(i,first,end) for(ull i=first;i<(end);i++)
#define outl(out) cout<<(out)<<endl;

const ull INF = (ull)(-1LL);

typedef ull ntype;

typedef vector<ntype> vntype;
typedef list<ntype> lntype;

template <typename TYPE = ntype>
struct UnionFind{
	vector<TYPE> parent;
	vector<unsigned int> _size;
	UnionFind(unsigned int n)
		:
		parent(n), _size(n, 1)
	{
		rep(i, 0, n)parent[i] = i;
	}
	TYPE root(TYPE x){ return (x == parent[x]) ? x : (parent[x] = root(parent[x])); }
	void merge(TYPE x, TYPE y)
	{
		if (root(x) != root(y)){
			_size[root(x)] += _size[root(y)];
			parent[root(y)] = root(x);
		}
	}
	bool same(TYPE x, TYPE y){ return root(x) == root(y); }
	unsigned int size(TYPE x){ return _size[root(x)]; }
};

int main(void){
	init(ntype, n);
	init(ntype, m);
	init(ntype, k);

	UnionFind<> uf(n);
	vntype ans(n, 0);

	rep(i, 0, m){
		ntype a, b;
		cin >> a >> b;
		a--;
		b--;
		uf.merge(a, b);
		ans[a]--;
		ans[b]--;
	}

	rep(i, 0, n){
		ans[i] += uf.size(i) - 1;
	}

	rep(i, 0, k){
		ntype c, d;
		cin >> c >> d;
		c--;
		d--;
		if (uf.same(c, d)){
			ans[c]--;
			ans[d]--;
		}
	}

	rep(i, 0, n){
		cout << ans[i] << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3200