akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(in) in.begin(), in.end()
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int, int> PII;

ll fastPow(ll x, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n&1){
            res *= x;
            res %= mod;
        }
        x *= x;
        x %= mod;
        n >>= 1;
    }
    return res;
}

int main(){
    FIO;
    string s;
    cin >> s;
    ll mod = 1e9 + 7;
    ll n = s.size(), dp[n][13];
    reverse(all(s));
    for(ll i = 0 ; i < 13 ; i++){
        dp[0][i] = 0;
    }
    if(s[0] == '?'){
        for(ll i = 0 ; i < 10 ; i++){
            dp[0][i] = 1;
        }
    }else{
        ll x = s[0] - '0';
        dp[0][x] = 1;
    }
    for(ll i = 1 ; i < n ; i++){
        for(ll j = 0 ; j < 13 ; j++){
            dp[i][j] = 0;
        }
        if(s[i] == '?'){
            ll x = fastPow((ll)10, i, (ll)13);
            x%=13;
            for(ll k = 0 ; k < 10 ; k++){
                ll x1 = x * k;
                x1 %= 13;
                for(ll j = 0 ; j < 13 ; j++){
                    ll y = j+x1;    y %= 13;
                    dp[i][y] += dp[i-1][j];
                    dp[i][y] %= mod;
                }
            }
        }else{
            ll x = s[i] - '0';
            x *= fastPow((ll)10, i, (ll)13);
            x %= 13;
            for(ll j = 0 ; j < 13 ; j++){
                ll y = j+x; y %= 13;
                dp[i][y] += dp[i-1][j];
                dp[i][y] %= mod;
            }
        }
    }
    cout << dp[n-1][5] << endl;
    return 0;
}




Measured memory_bytes: 10704
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<stack>
#include<queue>
#include<sstream>
#include<bitset>
#include<cstdio>
#include<stdio.h>
#include<cstring>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <unordered_map>
using namespace std;
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
int main()
{
	//in_out_txt();
	fast();
	string str;
	cin>>str;
	if(str.find('a')!=string::npos && str.find('b')!=string::npos && str.find('c')!=string::npos)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define inf 1000000007

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    vector<int>v(n,inf);
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<n;i++){
        int k = lower_bound(v.begin(),v.end(),a[i])-v.begin();
        v[k] = a[i];
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(v[i]!=inf)ans = i;
    }
    cout << ans+1 << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}

ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

        
//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

vb seek(51);
vvi G(51);
map< pair<int,int>,int  > mp;
void dfs(int n){
  if(seek[n]==true)return;
  seek[n]=true;
  for(int i=0;i<G[n].size();i++){
    pair<int,int > p=make_pair(n,G[n][i]);
    pair<int,int > q=make_pair(G[n][i],n);
    if(mp[p]==1||mp[q]==1)continue;
    dfs(G[n][i]);
  }   
  return;
}
int main(){
  int N,M;cin>>N>>M;
  vi a(M),b(M);
 
  rep(i,M){
    cin>>a[i]>>b[i];
    G[a[i]].pb(b[i]);
    G[b[i]].pb(a[i]);
    pair<int,int> p=make_pair(a[i],b[i]);
    pair<int,int> q=make_pair(b[i],a[i]);
    mp[p]=0;mp[q]=0;
  }
  
 
  int ans=0;
  for(auto &x:mp){
    x.second =1;
    for(int i=1;i<=N;i++){
      seek[i]=false;
    }
    dfs(1);
    bool ok=true;
  
    for(int i=1;i<=N;i++){
      if(seek[i]==false){
        ok=false;
        break;
      }
    }
    if(!ok)ans++;
    x.second=0;
    
  }
  cout<<ans/2<<endl;
  
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
signed main(){
  int N;
  cin>>N;
  vector<vector<int>> A(N,vector<int>(N));
  for(vector<int> &v:A)
    for(int &i:v)
      cin>>i;
  vector<int> B(1<<N,0);
  B[0]=1;
  for(int i=0;i<(1<<N);i++){
    int n=__builtin_popcount(i);
    for(int j=0;j<N;j++){
      if((!(i & (1<<j))) && A[n][j])
        B[i^(1<<j)]=(B[i^(1<<j)]+B[i])%mod;
    }
  }
  cout<<B[(1<<N)-1]<<endl;
}

Measured memory_bytes: 19576
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool flag=true;


int main() {
    string S,ans;
    cin>>
    S;

    ll sum=0;
    ll tmp=0;
    int X[S.size()];
    ll Y;
    int size=S.size();
    Y=atoll(S.c_str());

    FOR(i,0,S.size()-1){
        X[S.size()-1-i]= (Y%10);
        Y = Y/10;
    }

    for (int bit = 0; bit < (1<<(size-1)); ++bit)
    {
        tmp=X[0];
        for (int i = 0; i < size-1; ++i) {
            if (bit & (1<<i)) {
                sum+=tmp;

                tmp=X[i+1];
            }else{
                tmp=tmp*10+X[i+1];
            }

        }
        sum+=tmp;

    }

    cout<< sum;

  return 0;
}


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


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String str_raw1[] = br.readLine().split(" ");
        String str_raw2[] = br.readLine().split(" ");
        int[] raw1 = new int[n];
        int[] raw2 = new int[n];
        for (int i = 0; i < n; i++) {
            raw1[i] = Integer.parseInt(str_raw1[i]);
            raw2[i] = Integer.parseInt(str_raw2[i]);
        }
        
        int[] sums = new int[n];
        int max = -1;
        for (int i = 0; i < n; i++) {
            sums[i] = 0;
            for (int j = 0; j <= i; j++) {
                sums[i] += raw1[j];
            }
            for (int k = i; k < n; k++) {
                sums[i] += raw2[k];
            }
            max = Math.max(sums[i], max);
        }
        
        System.out.println(max);
    }
}


Measured memory_bytes: 23124
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

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

  int32_t N, K;
  cin >> N >> K;
  int32_t sum = 0;
  for (int32_t i = 0; i < N; ++i) {
    int32_t x;
    cin >> x;
    sum += min(2 * x, 2 * (K - x));
  }
  cout << sum << endl;

  return 0;
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> dp(N + 1, 1e9);
    dp[0] = 0;
    rep(i, N) {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        for (int j = 6; i + j <= N; j *= 6) {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        }
        for (int j = 9; i + j <= N; j *= 9) {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        }
    }
    cout << dp[N] << "\n";
}

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

namespace AtCoder
{
    class _063C
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            List<int> Datas = Enumerable.Range(1, N).Select(x => int.Parse(Console.ReadLine())).ToList();

            int sum = Datas.Sum();

            if (sum % 10 == 0)
                if (Datas.Where(x => x % 10 != 0).Count() != 0)
                    sum -= Datas.Where(x => x % 10 != 0).Min();
                else
                    sum = 0;

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11348
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200003;

map<ll,ll> primefactor(ll n){
  map<ll,ll> res;
  for( ll i=2LL ;i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}



int main(){
  ll n,m;
  cin>>n>>m;
  ll ans=0;
  ll p=min(n,m/2);
  ans+=p;
  n-=p;
  m-=2*p;
  ans+=m/4;
  cout<<ans<<endl;
  return 0;
}


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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var N = int.Parse(s);
            var d = int.Parse(s[0].ToString());
            var e = d * 100 + d * 10 + d;
            
            if(N <= e)
            {
                Console.WriteLine(e);
            }
            else
            {
                Console.WriteLine(e + 111);
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, m, X, Y;
    int ans=1000;
    cin >> n >> m >> X >> Y;
    vector<int> x(n);
    vector<int> y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    
    int maxx = *max_element(all(x));
    int miny = *min_element(all(y));

    int start = max(maxx, X);
    int end = min(miny, Y);

    for(int i=start; i<=end; i++){
        if(X < i && i < Y && maxx < i && i <= miny){
            ans = i;
        }
    }

    if(ans == 1000) out("War");
    else out("No War");
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=55;
const db G=9.8;
const db eps=1e-10;

int n,v,x,y;
int l[N],b[N],r[N],t[N];

db calc(db vy,db t) {
    return vy*t-0.5*G*t*t;
}

int cmp(db lb,db rb,db val) {
    return val<lb+eps?-1:val>rb-eps?1:0;
}

bool ok(int qx,int qy) {
    db a=0.25*G*G,b_=G*qy-v*v,c=qx*qx+qy*qy;
    db Delta=b_*b_-4*a*c;
    if (Delta<0) return false;
    for (int i=-1;i<=1;i+=2) {
        db t2=(-b_+i*sqrt(Delta))/(2*a);
        if (t2<0) continue;
        db t1=sqrt(t2);
        db vx=qx/t1;
        db vy=qy/t1+0.5*G*t1;
        db yt=calc(vy,x/vx);
        if (yt<y-eps) continue;
        bool ok=true;
        for (int i=1;i<=n;i++) {
            if (l[i]>=x) continue;
            if (r[i]==x&&y<=t[i]&&yt>=b[i]) ok=false;
            int yL=cmp(b[i],t[i],calc(vy,l[i]/vx));
            int yR=cmp(b[i],t[i],calc(vy,r[i]/vx));
            int xT=cmp(l[i],r[i],vx*(vy/G));
            int yT=cmp(b[i],t[i],calc(vy,vy/G));
            if (xT==0&&yT>=0&&yL<0) ok=false;
            if (yL*yR<=0) ok=false;
        }
        if (ok) { return true; }
    }
    return false;
}

int main()
{
    scanf("%d%d%d%d",&n,&v,&x,&y);
    for (int i=1;i<=n;i++) {
        scanf("%d%d%d%d",l+i,b+i,r+i,t+i);
        r[i]=min(r[i],x);
    }
    bool ans=ok(x,y);
    for (int i=1;i<=n;i++) {
        if (ok(l[i],t[i])||ok(r[i],t[i])) {
            ans=true;
            break;
        }
    }
    if (ans) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 3168
#include<stdio.h>
int a[200005],b[200005],c[200005]={0},d[200005]={0};
int main()
{
	int n,m,i,k=0,j,t=0,o=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		if(a[i]==1)
			c[b[i]]++;
		if(b[i]==n)
			d[a[i]]++;
	}
	for(i=1;i<=n;i++)
	{
		if(c[i]==1&&d[i]==1)
		{
			printf("POSSIBLE\n");
			return 0;
		}
		
	}
		printf("IMPOSSIBLE\n");
		return 0;
		
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;

#define PI acos(-1)
typedef long long ll;
#define INF 0x3f3f3f3f
int mod = 1000000007;
int rec[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n, k;
	while (cin >>n >> k)
	{
		int S = 1<<n;
		ll ans = 1LL<<60;
		for (int s = 0; s < S; s++)
		{
			ll cur = 1;
			for (int i = 0; i < n; i++)
				if (s>>i&1)
					cur *= 2;
				else
					cur += k;
			ans = min(ans, cur);
		}
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
#define SZ(xx) ((int)xx.size())
#define lowbit(xx) (xx&(-xx))
#define pb push_back
typedef pair<int,int> pii;
 
const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;
int dp[maxn][maxn];
char s[maxn];
 
main() {
//	string s;
	int n;
	cin >> n >> (char*)(s + 2); 
	dp[1][1] = 1;
	for (int i = 2; i <= n; i++) {
		if (s[i] == '>') {
			dp[i][i] = 0;
			for (int j = i - 1; j >= 1; j--) {
				dp[i][j] = dp[i-1][j] + dp[i][j+1];
				dp[i][j] %= mod;
			}
		}else {
			dp[i][1] = 0;
			for (int j = 2; j <= i; j++) {
				dp[i][j] = dp[i-1][j-1] + dp[i][j-1];
				dp[i][j] %= mod;
			}
		} 
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += dp[n][i];
		ans %= mod; 
	}
	cout << ans << "\n";
 
}

Measured memory_bytes: 49780
#include <iostream>
#include <stdlib.h>
#include <math.h>

#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))

using namespace std;

int main() {
	int N;
	char a[101], b[101], c[101];
	cin >> N;
	cin >> a >> b >> c;

	int count = 0;
	int ab, bc, ca;
	for (int i = 0; i < N; i++) {
		ab = (a[i] == b[i]) ? 1 : 0;
		bc = (c[i] == b[i]) ? 1 : 0;
		ca = (a[i] == c[i]) ? 1 : 0;
		int t = ab + bc + ca;
		if (t == 0) {
			count += 2;
		}
		else if (t == 1) {
			count++;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int main(){
    int a, b;
    cin >> a >> b;
    int n1 = 1, n2 = 1, ans = 0;
    if (a != 1) {
        rep(i, 2) {
            n1 *= a;
            a--;
        }
        n1 /= 2;
        ans += n1;
    } else {
        ans += 0;
    }
    if (b != 1) {
        rep(i,2) {
            n2 *= b;
            b--;
        }
        n2 /= 2;
        ans += n2;
    } else {
        ans += 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)

using namespace std;
vi fa;
void f(int a)
{
    fa.pb(1);
    for(int i=1;i<=a;i++)
    {
        fa.pb(i*fa[i-1]);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    f(n);
//    fa[0]=0;
//    forn(i,n+1)
//    {
//        printf("%d\n",fa[i]);
//    }
    vi a(n),b(n);
    forn(i,n)
    {
        scanf("%d",&a[i]);
    }
    forn(i,n)
    {
        scanf("%d",&b[i]);
    }
    int A=1,B=1;
    vi fra(n+1),frb(n+1);
    forn(i,n)
    {
        fra[i+1]=1;
        frb[i+1]=1;
    }
    for(int i=n;i>0;i--)
    {
        int cnt=a[n-i]-1;
        forn(j,a[n-i])
        {
            if(j>0)cnt-=fra[j];
        }
        fra[a[n-i]]--;
        A+=fa[i-1]*(a[n-i]-1-cnt);
        cnt=b[n-i]-1;
        forn(j,b[n-i])
        {
            if(j>0)cnt-=frb[j];
        }
        frb[b[n-i]]--;
        B+=fa[i-1]*(b[n-i]-1-cnt);
//        printf("%d %d\n",A,B);
    }
    printf("%d\n",abs(A-B));
    return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int Inf = (int) 1e9;
		
		int[][] min = new int[H][];
		for(int i=0;i<H;i++){
			min[i] = new int[W];
			for(int j=0;j<W;j++) min[i][j] = Inf;
		}
		
		int[] dx = new int[]{1, 0, -1, 0};
		int[] dy = new int[]{0, -1, 0, 1};
		
		
		var q = new Queue<int>();
		min[0][0] = 1;
		q.Enqueue(0);
		while(q.Count > 0){
			var now = q.Dequeue();
			int y = now / W;
			int x = now % W;
			for(int t=0;t<4;t++){
				int ny = y + dy[t];
				int nx = x + dx[t];
				if(!InRange(ny, 0, H) || !InRange(nx, 0, W)) continue;
				if(min[ny][nx] != Inf) continue;
				if(S[ny][nx] == '#') continue;
				min[ny][nx] = min[y][x] + 1;
				q.Enqueue(ny * W + nx);
			}
		}
		
		if(min[H-1][W-1] == Inf){
			Console.WriteLine(-1);
			return;
		}
		int cnt = S.Select(s => s.Count(c => c == '#')).Sum();
		Console.WriteLine(H * W - min[H-1][W-1] - cnt);
		
		
		
	}
	
	bool InRange(int t, int l, int r){
		return l <= t && t < r;
	}
	
	int H,W;
	String[] S;
	public Sol(){
		var d = ria();
		H = d[0]; W = d[1];
		S = new String[H];
		for(int i=0;i<H;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main(){
  string S;
  cin >> S;
  int E = S.size();
  vector<int> M(E, 0);
  M.at(0) = 1;
  if (S.at(0) == S.at(1)) {
    M.at(1) = 1; M.at(2) = 2;
  }
  else {
    M.at(1) = 2;
    M.at(2) = (S.at(1) == S.at(2) ? 2 : 3);
  }
  for (int i=3; i < E; i++) {
    M.at(i) = (S.at(i) == S.at(i-1) ? M.at(i-3) + 2 : M.at(i-1) + 1);
  }
  cout << M.at(E-1) << endl;
}

Measured memory_bytes: 1412
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	x := 0
	var B []int
	B = append(B, 10000000)
	for i := 0; i < n-1; i++ {
		x = nextInt()
		B = append(B, x)
	}
	B = append(B, 10000000)

	// fmt.Println(B)

	var a int
	var c int
	for i := 0; i < n; i++ {
		if B[i] > B[i+1] {
			a = B[i+1]
		} else {
			a = B[i]
		}
		// fmt.Println(a)

		c += a
	}
	fmt.Println(c)
}


Measured memory_bytes: 640
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

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

    int hour = sec / 3600;
    sec %= 3600;

    int minute = sec / 60;
    sec %= 60;

    cout << hour << ":" << minute << ":" << sec << endl;

    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
	ll N, X;
	cin >> N >> X;
	ll ans = N; N -= X;
	while(true) {
		if(N < X) swap(N, X);
		if(N % X == 0) { ans += (2 * N / X - 1) * X; break; }
		ans += 2 * X * (N / X);
		N %= X;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
for _ in [0] * int(raw_input()):
  h, m = map(int, raw_input().split(':'))
  x = abs(h*60 - m*11)
  x = min([x, 720-x])
  if x<60: print 'alert'
  elif 180<=x: print 'safe'
  else: print 'warning'

Measured memory_bytes: 4208
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}


int main(){
    ll x,y;
    cin >> x >> y;
    if (x==0){
        if (y>=0){
            cout << y << endl;
        }else{
            cout << abs(y)+1 << endl;
        }
        return 0;
    }
    if (x>0){
        if (y>0){
            if (x>y){
                ll z=x-y;
                cout << z+2 << endl;
            }else{
                ll z=y-x;
                cout << z << endl;
            }
        }else{
            if (x>abs(y)){
                ll z=x-abs(y);
                cout << z+1 << endl;
            }else{
                ll z=abs(y)-x;
                cout << z+1 << endl;
            }
        }
    }else{
        if (y>0){
            if (abs(x)>y){
                ll z=abs(x)-y;
                cout << z+1 << endl;
            }else{
                ll z=y-abs(x);
                cout << z+1 << endl;
            }
        }else{
            if (x>y){
                ll z=abs(y)-abs(x);
                cout << z+2 << endl;
            }else{
                ll z=abs(x)-abs(y);
                cout << z << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3660
N, A, B = map(int, input().split())
if N == 1:
    if A == B: print(1)
    else:print(0)
    exit()
if A > B:
    print(0)
    exit()
m = A + (N-2)*A + B
M = A + (N-2)*B + B
print(max(0,M-m+1))

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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll long long int

int main()
{
    FAST;
    ll a,b,c=0,d=0,e;
    char g;
    while(cin>>g){
    c=c+g-'0';
	}
	if (c%9==0)
    {
    	cout <<"Yes";
	}
	else
	cout<<"No";
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;

  using pll = pair<ll, ll>;
  vector<vector<pll>> G(N);
  vector<bool> visited(N, false);
  for (ll i = 0; i < N - 1; i++)
  {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    G.at(a).push_back(make_pair(b, i));
    G.at(b).push_back(make_pair(a, i));
  }

  ll K = 0;
  vector<ll> ans(N - 1, 0);

  queue<ll> Q;
  Q.push(0);
  while (!Q.empty())
  {
    ll V = Q.front();
    Q.pop();
    chmax(K, (ll)G.at(V).size());
    visited.at(V) = true;

    ll cnt = 1;
    ll ng = 0;
    for (auto nv : G.at(V))
    {
      if (visited.at(nv.first))
        ng = ans.at(nv.second);
    }

    for (auto nv : G.at(V))
    {
      if (!visited.at(nv.first))
      {
        Q.push(nv.first);

        if (cnt == ng)
          cnt++;
        ans.at(nv.second) = cnt;
        cnt++;
      }
    }
    //cerr << "* " << V << endl;
  }

  cout << K << endl;
  for (ll i = 0; i < N - 1; i++)
  {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 8832
#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>
#include <bitset>

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 <<" ";}
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... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(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); }



void solve(void)
{
  int N,A,B;
  cin>>N>>A>>B;
  cout<< max(0LL,A + (N-1)*B - A*(N-1) - B + 1)<<endl;
  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: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 100000+10;

long long pow2[maxn];
long long arr[maxn];
long long ll[maxn], rr[maxn];

int main() {
    pow2[0] = 1;
    bool flag = 0;
    for(int i = 1;i <= 100000;i ++) {
        if(flag == 0)
            pow2[i] = 2 * pow2[i-1];
        else if(flag == 1)
            pow2[i] = pow2[i-1];
        if(pow2[i] > 4e18) flag = 1;
    }

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

    flag = 1;

    for(int i = n-1;i >= 0;i --) {
        ll[i] = (ll[i+1] + arr[i+1]) / 2 + (ll[i+1] + arr[i+1]) % 2;
        rr[i] = min(arr[i+1] + rr[i+1], pow2[i] - arr[i]);
//        cout << ll[i] << " " << rr[i] << endl;
        if(ll[i] < 0 || ll[i] > rr[i]) flag = 0;
    }
    
    for(int i = 0;i <= n;i ++) {
        if(arr[i] > pow2[i]) flag = 0;
    }
    

    if(!flag) {
        cout << "-1" << endl;
        return 0;
    }


    long long sum = 0;

    for(int i = 0;i <= n;i ++) {
        sum += arr[i];
        sum += rr[i];
        rr[i+1] = min(rr[i+1], rr[i]*2-arr[i+1]);
    }
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 6956
#include <stdio.h>

int main(void)

{
	int s= 0;
	int hours= 0,minutes= 0,seconds= 0;
	int result= 0;

	scanf("%d",&s);
	hours = s / 3600;
	minutes = (s-hours*60*60)/60;
	seconds = s - hours*3600 - minutes*60;
	
	printf("%d:%d:%d\n",hours,minutes,seconds);

	return(0);

}

Measured memory_bytes: 592
A, B, K =map(int, input().split())
tmp = []
try:
    for i in range(2,min(A,B)+1):
        if A%i == 0 and B%i == 0:
            tmp.append(i)
    tmp.sort(reverse=True)
    print(tmp[K-1])
except:
    print(1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
const int p=1e9+7;
int n, c[N];
int dp[N], t[N], nxt[N];
int main(){
	scanf("%d", &n); for(int i=1; i<=n; ++i){
		scanf("%d", &c[i]); if(t[c[i]])nxt[t[c[i]]]=i;
		t[c[i]]=i;
	}
	dp[1]=1;
	for(int i=1; i<=n; ++i){
		if(nxt[i]>i+1)(dp[nxt[i]]+=dp[i])%=p;
		(dp[i+1]+=dp[i])%=p;
	}
	printf("%d",dp[n]);
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define ROF(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

void solve(){
    int n;
    scanf("%d",&n);
    vector<int> arr(n);
    FOR(i,0,n-1) scanf("%d",&arr[i]);
    sort(all(arr));
    int ans = 0;
    FOR(i, 0, n-1){
        FOR(j, i+1, n-1){
            if(arr[i] == arr[j]) continue;
            FOR(k, j+1, n-1){
                if(arr[j] == arr[k]) continue;
                if(arr[i]+arr[j] > arr[k]) ++ans;
            }
        }
    }
    printf("%d",ans);
}

int main(){
    solve();
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

Measured memory_bytes: 3780
//Koch Curve

#include<stdio.h>
#include<math.h>

typedef struct
{
  double x,y;
}Locate;

void koch(int n,Locate a,Locate b)
{
  Locate s,t,u;
  double change = M_PI*60.0/180.0;

  if(n == 0) return;
  //calculate
  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x)*cos(change) - (t.y - s.y)*sin(change) + s.x;
  u.y = (t.x - s.x)*sin(change) + (t.y - s.y)*cos(change) + s.y;


  //work again
  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main()
{
  int n;
  Locate a,b;
  
  //initialize number
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  //input data
  scanf("%d",&n);

  printf("%.8f %.8f\n",a.x,a.y);
  //work
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0; 
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "YES\n"
#define N cout << "NO\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i, n) for (int i = 0; i < n; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)

long long mod = 1000000007 , ans = 1 ;
int p(long long a , long long b)
{
    while(b)
    {
        if(b%2)
        {
            ans = ( (ans%mod)*(a%mod) ) %mod ;
        }
        a = ((a%mod)*(a%mod))%mod ;
        b /= 2 ;
    }
    return ans ;
}


int prime[1000010] ;
void fun()
{
	for (int i = 1 ; i < 1000001; i++)
	{
		for (int j = i ; j < 1000001; j += i)
		{
               prime[j]++;
		}
	}
}
int x[1000010] ;

int gcd(ll a,ll b)
{
     if(b == 0)
     {
          return a ;
     }
     return gcd(b,a%b) ;
}
int main()
{
     fun() ;
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int n , ans = 0 ;
     cin >> n ;
     for(int i = 1 ; i < n ; i++)
     {
          ans += prime[i] ;
          // cout << prime[i] << endl ;
     }
     cout << ans << endl ;
}


Measured memory_bytes: 7596
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(7);

    string s;
    int ans = 0;
    while (getline(cin, s))
    {
        int n = s.size();

        int sum = 0;
        for (int i = 0; i < n; ++i)
        {
            if (s[i] >= '0' && s[i] <= '9')
            {
                sum = sum * 10 + s[i] - '0';
            }
            else
            {
                ans += sum;
                sum = 0;
            }
        }
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;


int main() {
  int H, W, N;
  cin >> H >> W;
  vector< int > dp(W);
  dp[0] = 1;
  for(int i = 0; i < H; i++) {
    string s;
    cin >> s;
    vector< int > nxt(W);
    for(int j = 0; j < W; j++) {
      if(s[j] == '#') continue;
      if(j > 0) (nxt[j] += nxt[j - 1]) %= mod;
      (nxt[j] += dp[j]) %= mod;
    }
    dp.swap(nxt);
  }
  cout << dp.back() << endl;
}



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

using namespace std;

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int j=1;
	bool b[n];
	for(int i=0;i<n;i++){
		b[i]=false;
	}
	for(int i=0;i<n;i++){
		if(a[i]==j){
			j++;
			b[i]=true;
		}
	}
	int count=0;
	for(int i=0;i<n;i++){
		if(b[i]==false){
			count++;
		}
	}
	if(count<=n-1){
		cout<<count;
	}else{
		cout<<-1;
	}
}

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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)


void solve() 
{
    int n;
  	cin>>n;
  	if(n>=400 && n<=599)
      cout<<8<<'\n';
  	else if(n>=600 && n<=799)
      cout<<7<<'\n';
  	else if(n>=800 && n<=999)
      cout<<6<<'\n'; 
  	else if(n>=1000 && n<=1199)
      cout<<5<<'\n';
  	else if(n>=1200 && n<=1399)
      cout<<4<<'\n';
  	else if(n>=1400 && n<=1599)
      cout<<3<<'\n';
  	else if(n>=1600 && n<=1799)
      cout<<2<<'\n';
  	else if(n>=1800 && n<=1999)
      cout<<1<<'\n';
  
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc = 1; 
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}

Measured memory_bytes: 3644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

int n, k;
priority_queue<int> small;
priority_queue<int, vector<int>, greater<int>> large;
signed main(){
  cin>>n;int cnt = 0;
  int m = 0;
  rep(i,n){
    int q;cin>>q;
    if(q == 1){
      int a, b;cin>>a>>b;cnt++;k += b;
      if(cnt % 2 == 0){
        int r = small.top();
        if(small.top() > a){
          large.push(small.top());
          small.pop();
          small.push(a);
        }else{
          large.push(a);
        }
        m += abs(r - a);
      }else{
        if(large.empty() || large.top() > a)small.push(a);
        else{
          small.push(large.top());
          large.pop();
          large.push(a);
        }
        if(small.top() != a)m += abs(small.top() - a);
      }
    }else{
      cout << small.top() << " " << m+k << endl;
    }
  }
}



Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
vector<int> g[100005];
// int dis[100005];
int pre[100005], c[100005];
bool used[100005];

void setDis(int from) {
	FOR(i, g[from].size()) {
		int v = g[from][i];
		if (used[v]) continue;
		pre[v] = from;
		// dis[v] = dis[from]+1;
		used[v] = true;
		setDis(v);
	}
	return;
}

vector<int> get_path(int t) {
	vector<int> path;
	for (; t != -1; t = pre[t]) path.push_back(t);
	reverse(path.begin(), path.end());
	return path;
}

void dfs(int from) {
	FOR(i, g[from].size()) {
		int v = g[from][i];
		if (used[v]) continue;
		if (c[v] == 0) c[v] = c[from];
		used[v] = true;
		dfs(v);
	}
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	FOR(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	// dis[0] = 0;
	used[0] = true;
	fill(pre, pre+n, -1);
	setDis(0);
	vector<int> path = get_path(n-1);
	// FOR(i, path.size()) {
	// 	cout << path[i] << endl;
	// }
	fill(c, c+n, 0);
	FOR(i, path.size()) {
		if (i < (path.size()+1)/2) c[path[i]] = 1;
		else c[path[i]] = -1;
	}
	// FOR(i, n) cout << c[i] << endl;
	fill(used, used+n, false);
	used[0] = true;
	dfs(0);
	int cnt = 0;
	FOR(i, n) {
		if (c[i] > 0) cnt++;
	}

	if (cnt > n/2) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
	


	return 0;
}

Measured memory_bytes: 11768
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int m,g,a[7],b[7],c,n;
void rec(int k,int s){
	rep(i,b[k]+1){
		int t=s+a[k]*i;
		if(t<n&&k<m-1)rec(k+1,t);
		if(t==n)c++;
	}
}
int main(){
	while(cin>>m,m){
		rep(i,m)cin>>a[i]>>b[i];
		cin>>g;
		rep(i,g){
			c=0; cin>>n;
			rec(0,0);
			cout<<c<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 868
#include<bits/stdc++.h>
using namespace std;
int main () {
  char S[100];
  int si = 0;
  string com;
  cin >> com;
  for (int i = 0; i < (int)com.size(); i ++) {
    char c = com[i];
    if (c == '0') {
      S[si] = '0';
      si ++;
    }
    if (c == '1') {
      S[si] = '1';
      si ++;
    }
    if (c == 'B') {
      si = max(si - 1, 0);
    }
  }
  for (int i = 0; i < si; i ++) {
    cout << S[i];
  }
  cout << endl;
}


Measured memory_bytes: 3596
import collections

N = int(input())
UKV = [list(map(int,input().split())) for _ in range(N)]

dist = [-1]*N
que = collections.deque()

G = [[]]*N
for ukv in UKV:
    G[ukv[0]-1] = sorted(ukv[2:])

dist[0] = 0
que.append(1)

while len(que) != 0:
    v = que.popleft()
    for nv in G[v-1]:
        if dist[nv-1] != -1:
            continue
        dist[nv-1] = dist[v-1] + 1
        que.append(nv)

for i,d in enumerate(dist):
    print(i+1, d)


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


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

    int i = S.length()-T.length(), j = 0;
    while(i >= 0 && j < T.length())
    {
        if(S[i+j] == '?' || S[i+j] == T[j])
        {
            j++;
        }
        else
        {
            i--;
            j = 0;
        }
        if(j == T.length())
        {
            S.replace(i, T.length(), T);
            REP(i, S.length()) if(S[i] == '?') S[i] = 'a';
            cout << S << endl;
            return;
        }
    }
    cout << "UNRESTORABLE" << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = 1 << 61;
    static int[] x4 = {-1, 0, 0, 1};
    static int[] y4 = {0, -1, 1, 0};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] W = new String[n];
        for(int i = 0; i < n; i++) W[i] = in.next();
        Set<String> words = new HashSet<>();

        words.add(W[0]);
        for(int i = 1; i < n; i++) {
            if(words.contains(W[i])) {
                System.out.println("No");
                return;
            }

            if(W[i].charAt(0) != W[i-1].charAt(W[i-1].length()-1)) {
                System.out.println("No");
                return;
            }

            words.add(W[i]);
        }

        System.out.println("Yes");
    }
}

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

using namespace std;

long long a[100005], n, ans;

int main() {

    cin >> n;

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        if(a[i - 1] && a[i]) {ans++; a[i]--;}
        ans += a[i] / 2;
        a[i] %= 2;
    }

    cout << ans;

    return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
using ll = long long;

bool ans[10][10][10];
bool checked2[10][10];
bool checked[10];
bool completed(int i,int j) {
	for (int p = 0; p < 10; p++) {
		if (!ans[i][j][p])return false;
	}
	return true;
}

int main() {

	int N;
	string S;
	cin >> N >> S;
	int count = 0;
	for (int i = 0; i < N; i++) {
		int a = S[i] - '0';
		if (checked[a])continue;
		checked[a] = true;
		for (int j = i+1; j < N; j++) {
			int b = S[j]-'0';
			if (checked2[a][b])continue;
			checked2[a][b] = true;
			for (int k = j + 1; k < N;k++) {
				int c = S[k]-'0';
				//if (!ans[a][b][c]) {
					ans[a][b][c] = true;
					//count++;
					if (completed(a, b))break;

				//}
			}
		}
	}
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				if (ans[i][j][k])count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3652
N,W=list(map(int,input().split()))

w1 = []
w2 = []
w3 = []
w4 = []


for i in range(N):
    w,v = list(map(int,input().split()))
    if i==0:
        w0 = w
    
    if w==w0:
        w1.append(v)
    elif w==w0+1:
        w2.append(v)
    elif w==w0+2:
        w3.append(v)
    else:
        w4.append(v)

w1.sort()
w1=w1[::-1]

w2.sort()
w2=w2[::-1]

w3.sort()
w3=w3[::-1]

w4.sort()
w4=w4[::-1]
max_V = 0
for i1 in range(len(w1)+1):
    for i2 in range(len(w2)+1):
        for i3 in range(len(w3)+1):
            for i4 in range(len(w4)+1):
                w = i1*w0 + i2*(w0+1) + i3*(w0+2) + i4 * (w0+3)
                if w<=W:
                    V = sum(w1[:i1])+sum(w2[:i2])+sum(w3[:i3])+sum(w4[:i4])
                    max_V = max(V,max_V)

print(max_V)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	if(s=="SUN") cout<<7;
	else if(s=="MON") cout<<6;
	else if(s=="TUE") cout<<5;
	else if(s=="WED") cout<<4;
	else if(s=="THU") cout<<3;
	else if(s=="FRI") cout<<2;
	else if(s=="SAT") cout<<1;
	return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256