akhauriyash/Code-Regression huggingface dataset:
{
  const main = (input: string) => {
    const r = reader(input)
    const [X, Y] = r.ns()

    // X + Y == 3 * n - 1
    if ((X + Y) % 3 !== 0) {
      console.log(0)
      return
    }
    const n = (X + Y) / 3
    const rot = Math.min(X, Y) - n + 1

    // console.log({ n, rot })

    if (rot < 0) {
      console.log(0)
      return
    }
    _fset(n)

    const res = _ncr(n, rot - 1)

    console.log(res)
  }

  const _mod = 10 ** 9 + 7
  const fac: number[] = []
  const finv: number[] = []

  const _mul = (...a) =>
    a.reduce(
      (r, c) => ((((r >> 16) * c) % _mod) * 65536 + (r & 65535) * c) % _mod,
      1
    )
  const _inv = b => {
    for (var a = _mod, u = 0, v = 1, t; b; v = t)
      (t = (a / b) | 0),
        (a -= t * b),
        (u -= t * v),
        (t = a),
        (a = b),
        (b = t),
        (t = u),
        (u = v)
    u %= _mod
    return u < 0 ? u + _mod : u
  }

  const _fset = (n: number) => {
    fac.length = n + 1
    fac[0] = fac[1] = 1
    for (let i = 2; i <= n; ) {
      fac[i] = _mul(fac[i - 1], i++)
    }
    finv.length = n + 1
    finv[0] = finv[1] = 1
    finv[n] = _inv(fac[n])
    for (let i = n; 2 < i; ) {
      finv[i - 1] = _mul(finv[i], i--)
    }
    // invs.length=n+1,invs[0]=invs[1]=1;
    // for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  }

  const _ncr = (n, r) => _mul(fac[n], finv[r], finv[n - r])

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}


Measured memory_bytes: 25948
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V;
	List<int>[] es;
	void Solve()
	{
		var I = G;
		V = I[0];
		var M = I[1];
		es = new List<int>[V];
		dp = new int[V];
		for (var i = 0; i < V; i++) { es[i] = new List<int>(); dp[i] = -1; }
		for (var i = 0; i < M; i++)
		{
			I = G;
			es[I[0] - 1].Add(I[1] - 1);
		}
		var ans = 0;
		for (var i = 0; i < V; i++) ans = Max(ans, Calc(i));
		WriteLine(ans);
	}
	int[] dp;
	int Calc(int v)
	{
		if (dp[v]<0)
		{
			dp[v] = 0;
			foreach (var w in es[v]) dp[v] = Max(dp[v], 1 + Calc(w));
		}
		return dp[v];
	}
}


Measured memory_bytes: 29692
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
typedef long long ll;
int main() {
	// your code goes here
    ll n;
  	cin>>n;
    map<string,ll>mp;
    for(int i=0;i<n;i++)
    {
      string s;
      cin>>s;
      mp[s]=1;
    }
    ll sz=0;
    for(auto it:mp)
      sz++;
  	cout<<sz;
  
	return 0;
}


Measured memory_bytes: 19228
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int s(ll x) {
	if(!x) return 0;
	return x%10+s(x/10);
}
int main() {
	int K;
	scanf("%d",&K);
	ll n=1,d=1;
	printf("%d\n",1); K--;
	while(K--) {
		if(s(n+10*d)*(n+d)>(n+10*d)*s(n+d)) d*=10;
		printf("%lld\n",n+=d);
	}
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		sc.close();
		
		int count = 0;
		count = s.length() - 2;
		System.out.println(s.substring(0, 1) + count + s.substring(s.length() - 1));
	}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
    int n,m,b,i,j,k,r;
    cin>>n>>m;
    k=n;
    while(n--)
    {
        cin>>r;
        while(r--)
        {
            cin>>b;
            a[b]++;
        }
    }
    int cunt=0;
    for(i=1;i<=m;i++)
    {
        if(a[i]==k)cunt++;
    }
    cout<<cunt<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private static final List<IntegralRectangle> RECTANGLES;

    static {
        RECTANGLES = new ArrayList<>();
        Main main = new Main();
        for(int y = 1; y < 150; y++) {
            for(int x = -~y; x < 150; x++) {
                RECTANGLES.add(main.new IntegralRectangle(y, x));
            }
        }
        Collections.sort(RECTANGLES);
    }

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

    void solve() {
        int height;
        int width;
        while((height = scn.nextInt()) > 0 | (width = scn.nextInt()) > 0) {
            IntegralRectangle base = new IntegralRectangle(height, width);
            for(IntegralRectangle rectangle : RECTANGLES) {
                if(base.compareTo(rectangle) < 0) {
                    System.out.println(rectangle);
                    break;
                }
            }
        }
    }

    class IntegralRectangle implements Comparable<IntegralRectangle> {
        int height;
        int width;

        public IntegralRectangle(int height, int width) {
            this.height = height;
            this.width  = width;
        }

        private int squareDiagonal() {
            return height * height + width * width;
        }

        @Override
        public int compareTo(IntegralRectangle another) {
            if(this.squareDiagonal() > another.squareDiagonal()) {
                return 1;
            } else if(this.squareDiagonal() < another.squareDiagonal()) {
                return -1;
            } else {
                if(this.height != another.height) {
                    return this.height > another.height ? 1 : -1;
                } else {
                    return 0;
                }
            }
        }

        @Override
        public String toString() {
            return height + " " + width;
        }
    }
}

Measured memory_bytes: 28132
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<int> A(Q),seq;
	for(int i =0; i < Q; i++) {
		cin >> A[i];
		A[i]--;
	}
	vector<bool> vis(M,0);
	for(int i =Q-1; i >= 0; i--) if(!vis[A[i]]) {
		seq.push_back(A[i]);
		vis[A[i]] =1;
	}
	for(int i =0; i < M; i++) if(!vis[i]) {
		seq.push_back(i);
		vis[i] =1;
	}
	vector<int> rev(M);
	for(int i =0; i < M; i++) rev[seq[i]] =i;

	vector<int> cnt(M+1,0);
	cnt[0] =N;
	for(int i =0; i < M; i++) vis[i] =0;
	for(int i =Q-1; i >= 0; i--) {
		int id =rev[A[i]];
		if(cnt[id] == 0 && !vis[A[i]]) {
			cout << "No\n";
			return 0;
		}
		if(cnt[id] == 0) continue;
		vis[A[i]] =1;
		cnt[id]--;
		cnt[id+1]++;
	}

	int mid =M-1;
	while(mid > 0 && seq[mid-1] < seq[mid]) mid--;
	for(int i =0; i < mid; i++) if(cnt[i]) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 1912
using System;
using System.Collections.Generic;
class Program
{
 
    static void Main()
    {
        string S = Console.ReadLine();
        string T = Console.ReadLine();
        int Sa = S.Length;
        int Ta = T.Length;
 
 
        int An = Ta - Sa;
 
        if (An == 1 && T.Substring(0,Sa)==S)
        {
            Console.WriteLine("Yes");
        }
        else
            Console.WriteLine("No");
 
 
 
    }
}

Measured memory_bytes: 25816
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s, t; cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

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

int main(){
    vector<char>S;
    string s; cin >> s;

    for(int i=0; i<s.size(); i++){
        if(s[i]!='B'){
            S.push_back(s[i]);
        } else {
            if(S.size()!=0) S.pop_back();
        }
    }

    for(int i=0; i<S.size(); i++){
        cout << S[i];
    }    
    cout << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define mod 1000000007
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int t;
        map<string,int> m;
        int n; cin>>n;
        while(n--){
          string s; cin>>s;
          m[s]++;
        }
        cout<<m.size();
        return 0;
}


Measured memory_bytes: 19200
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        int n;
        cin >> n;
        int i,j,x,y;
        int ans=inf;
        for(i=1; i*i<=n; i++){
            if(n%i==0){
                x=i;
                y=n/i;
                int k=abs(x-1)+abs(y-1);
                ans=min(ans,k);
            }
        }
        
        cout << ans << '\n';
        

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3000;
double valeur[MAXN];
int N;

double total[MAXN][MAXN];
int main()
{
	cin >> N;
	for (int i = 0 ; i < N ;  i++)
	{
		cin>>valeur[i];
	}

	for (int nbPris = 0 ; nbPris <= N ; nbPris++)
	{
		for (int pos = (int)max(0 , nbPris - 1) ; pos < N ; pos++)
		{
			if (pos > 0) total[nbPris][pos] = total[nbPris][pos - 1] * (1.0 - valeur[pos]);
			else if (nbPris == 0) total[nbPris][pos] = (1.0 - valeur[pos]);
			else total[nbPris][pos] = valeur[pos];
			if (nbPris > 0) total[nbPris][pos] += (total[nbPris - 1][pos - 1] * valeur[pos]);
		}
	}
	double sortie = 0.0;
	for (int i = (N + 1) / 2 ; i <= N ; i++)
	{
		sortie += total[i][N - 1];
	}

	cout << setprecision(15) << fixed;
	cout<<sortie<<endl;
}

Measured memory_bytes: 70016
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(b, a * n) << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    string s;
    cin >> n >> s;
    int al[30] = {0};
    int cnt = 0;
    rep(i,n){
        al[s[i]-'a']++;
    }
    rep(i,26){
        if(al[i] != 0)cnt++;
    }
    int ans = 1;
    cerr << cnt << endl;
    rep(i,26){
        if(al[i] == 0)continue;
        else{
            ans *= al[i]+1;
            ans %= MOD;
        }
    }
    cout << (ans+MOD-1)%MOD << endl;


    
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://agc031.contest.atcoder.jp/tasks/agc031_a
// rm -r -f test;oj dl http://abc107.contest.atcoder.jp/tasks/abc107_b

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,a[1050];
double r;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		r+=1.0/a[i];
	}
	cout<<1/r;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, a[212345];

    cin >> n;
    REP(i, n)
    cin >> a[i];

    int l = 0;
    int r = 0;
    ll sum = a[0];
    ll xsum = a[0];

    ll res = 0;

    if (n == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    while (true)
    {
        while (r < n && sum == xsum)
        {
            r++;
            sum += a[r];
            xsum ^= a[r];
        }

        if (r < n)
        {
            sum -= a[r];
            xsum ^= a[r];
        }

        r--;

        res += r - l + 1;

        sum -= a[l];
        xsum ^= a[l];

        l++;

        if (l == n - 1)
            break;
    }

    res++;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
ll dp[101][100001]; 

ll knapsack(ll *arw,ll *arv,ll w,ll n){
  if(n==0 || w==0) return dp[n][w];
  if(dp[n][w]!=0)return dp[n][w];
  ll a=knapsack(arw,arv,w,n-1);
  ll b=0;
  if(w-arw[n-1]>=0){
    b=knapsack(arw,arv,w-arw[n-1],n-1)+arv[n-1];
  }
  dp[n][w]=max(a,b);
  return dp[n][w]; 
}



int main(){
  ll n,w,a,b;
  cin>>n>>w;
  ll arv[n],arw[n];
  for(int i=0;i<n;i++)
    cin>>arw[i]>>arv[i];
    cout<<knapsack(arw,arv,w,n);
    return 0;
} 

Measured memory_bytes: 77440
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 4079, mlg = 17, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ans = 1<<30, mab[maxn], mac[maxn], mbc[maxn];
bool good(int *dp, string &a, string &b, int s) {
	if(dp[s] >= 0) return dp[s];
	dp[s] = 1;
	for(int j = 0, i = s; dp[s] && i < a.size() && j < b.size(); i++, j++) {
		dp[s] &= a[i] == b[j] || a[i] == '?' || b[j] == '?';
	}
	return dp[s];
}
void solve(string a, string b, string c) {
	memset(mab, -1, sizeof mab);
	memset(mbc, -1, sizeof mbc);
	memset(mac, -1, sizeof mac);
	for(int i = 0; i <= a.size(); i++) {//shift for b
		for(int j = 0; j <= max(b.size(), a.size()); j++) {//shift for c
			if(good(mab, a, b, i) && good(mbc, b, c, j) && good(mac, a, c, i+j)) ans = min(ans, max({(int)a.size(), (int)b.size()+i, (int)c.size()+i+j}));
		}
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	string a, b, c;
	cin >> a >> b >> c;
	solve(a, b, c);
	solve(a, c, b);
	solve(b, a, c);
	solve(b, c, a);
	solve(c, a, b);
	solve(c, b, a);
	cout << ans << '\n';
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(100000)

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

graph = [{} for _ in range(N)]
for l, r, d in LRD:
	l, r = l - 1, r - 1
	graph[l][r] = d
	graph[r][l] = -d

visited = [False] * N
depths = [-1] * N
def dfs(v, p, d):
	if visited[v]:
		return True
	visited[v] = True
	depths[v] = d

	for n in graph[v]:
		if n == p:
			continue
		n_depth = d + graph[v][n]
		if depths[n] != -1 and depths[n] != n_depth:
			return False
		result = dfs(n, v, n_depth)
		if not result:
			return False
	return True

for n in range(N):
	if not dfs(n, -1, 0):
		print("No")
		break
else:
	print("Yes")


Measured memory_bytes: 165968
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        if(k<=9){
            System.out.println(k);
            return;
        }

        Queue<Long> q = new PriorityQueue<>();
        for(long i=1;i<10;i++){
            q.add(i);
        }
        int count = 9;
        long now = 0;
        while(true){
            long tmp = q.poll();
            long r1 = rank1(tmp);

            if(tmp%10!=0){
                now = tmp*10+r1-1;
                q.add(now);
                count++;
                if(count==k)break;
            }

            now = tmp*10+r1;
            q.add(now);
            count++;
            if(count==k)break;

            if(tmp%10!=9){
                now = tmp*10+r1+1;
                q.add(now);
                count++;
                if(count==k)break;
            }
        }
        System.out.println(now);

    }

    public static int rank1(long a) {
        String[] tmp = String.valueOf(a).split("");
        return Integer.parseInt(tmp[tmp.length-1]);
    }
}


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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

bool ok (string s){
    string g = s;
    reverse(g.begin(), g.end());
    return s==g;
}

int main() {
    string str, f; cin>>str;
    if(ok(str)){
        cout<<0<<endl;
        return 0;
    }
    vector<int> xpos;
    for(int i = 0; i < sz(str); i++)
    {
        if(str[i]!='x')f+=str[i];
    }
    
    if(ok(f)){
        int i = 0, cnt = 0, res = 0;
        vector<int> xcnt;
        for(int p = 0; p < sz(str); p++)
        {
            if(str[p]!=f[i]){
                ++cnt;
                if(p==sz(str)-1)xcnt.push_back(cnt);
            }
            else{
                i++;
                xcnt.push_back(cnt);
                if(p==sz(str)-1)xcnt.push_back(0);
                cnt=0;
            }
        }
        
        for(int i=0;i<sz(xcnt)/2;i++){
            res+=abs(xcnt[i]-xcnt[sz(xcnt)-1-i]);
        }
        cout<<res<<endl;

    }else{
        cout<<-1<<endl;
    }

    return 0;
}

Measured memory_bytes: 1216
/**********************************************************
 * �T���v���ʂ��̂Ɋۈ������������(��)
***********************************************************/

#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int n;
	cin >> n;
	vector<int> t(n+1,0),v(n+1,0);

	for(int i = 1; i <= n; i++) cin >> t[i];
	for(int i = 1; i <= n; i++) cin >> v[i];
	for(int i = 1; i <= n; i++) t[i] += t[i-1];
	for(int i = 1; i <= n; i++) t[i] *= 2, v[i] *= 2;

	vector<int> g(t.back()+10,0);
	for(int i = 1; i <= n; i++) g[t[i]] = v[i];
	for(int i = 1; i <= n; i++){
		for(int j = t[i-1]+1; g[j] != v[i]; j++) g[j] = v[i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = t[i-1]; g[j] != v[i]; j++) g[j] = min(g[j],v[i]);
	}

	g[0] = g[t.back()] = 0;
	for(int x = 1; x < t.back(); x++){
		g[x] = min(g[x],g[x-1]+1);
	}
	for(int x = t.back()-1; x >= 0; x--){
		g[x] = min(g[x],g[x+1]+1);
	}
/*
	for(int i = 0; i <= t.back(); i++){
		cout << i << ":";
		for(int j = 0; j < g[i]; j++){
			printf("%3d",g[i]);
		}
		cout << endl;
	}
*/
	double ans = 0,tmp;
	for(int i = 0; i < t.back(); ){
		tmp = i;
		//cout << "======================================" << endl;
		if(g[i] == g[i+1]){
			while(g[i] == g[i+1]) i++;
			ans += (g[i]+g[tmp])*(i-tmp)/8.0;
			//cout << "a" << endl;
		}else if(g[i] > g[i+1]){
			while(g[i] > g[i+1]) i++;
			ans += (g[i]+g[tmp])*(i-tmp)/8.0;
			//cout << "b" << endl;
		}else{
			while(g[i] < g[i+1]) i++;
			ans += (g[i]+g[tmp])*(i-tmp)/8.0;
			//cout << "c" << endl;
		}
		//cout << i << " " << tmp << endl;
		//cout << ans << endl;
	}
	//cout << "============================================" << endl;
	cout << fixed << ans << endl;
	return 0;
}

Measured memory_bytes: 384
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = (a - c) * (b - d);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
	long n = long.Parse(Console.ReadLine());
  long[,] vertexes = new long[n,4];
  bool answer = true;
    for(long i = 0; i < n; i++)
    {
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    vertexes[i,0] = nums[0];
    vertexes[i,1] = nums[1];
    vertexes[i,2] = nums[2];
    vertexes[i,3] = nums[3];
    }

    for(long i = 0; i < n; i++)
    {
    long a = vertexes[i,0];
    long b = vertexes[i,1];
    long c = vertexes[i,2];
    long d = vertexes[i,3];
      if(a < b) answer = false;
      else if(d < b) answer = false;
      else if(b-1 < c+1) answer = true;
      else
      {
        answer = true;
        long gcd = Gcd(b, d);
        long memo = (c+1-a)%gcd;
        long memoSub = (b-1-a)%gcd;
        if(memo == 0) answer = false;
        else if(memoSub < memo) answer = false;
        else if(b-c-2 >= gcd-1) answer = false;
      }
      Console.WriteLine(answer ? "Yes" : "No");
    
    }
  }

  static long Gcd(long a, long b) 
    {//引数a,bの最大公約数を返す
         if (a < b)
             return Gcd(b, a);//入れ替え
         while (b != 0) 
         {
             long changeTo = a % b;
             a = b;
             b = changeTo;
         }
         return a;
     }

    
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll A,B,X;
    cin >> A >> B >> X;
    cout << B/X - A/X + (A%X==0)<< endl;
}

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

int main(void) {
	int H,W;
	array<array<int,100>,100> a;
	for (int i=0; i<100; i++) {
		for (int j=0; j<100; j++) {
			a[i][j]='.';
		}
	}
	cin >> H >> W;
	vector<int> hr,wr;

	for (int i=0; i<H; i++) {
		bool flg = true;
		for (int j=0; j<W; j++) {
			char tmp;
			cin >> tmp;
			if (tmp=='#') flg = false;
			a[i][j] = tmp;
		}
		if (flg) hr.push_back(i);
	}
	for (int j=0; j<W; j++) {
		bool flg = true;
		for (int i=0; i<H; i++) {
			if (a[i][j]=='#') flg = false;
		}
		if (flg) wr.push_back(j);
	}
	for (int i=0; i<H; i++) {
		if (find(hr.begin(), hr.end(), i)==hr.end()) {
			for (int j=0; j<W; j++) {
				if (find(wr.begin(), wr.end(), j)==wr.end()) {
					cout << (char)a[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0]);
  var ans="1";
  var x =0;
  var a =0;
  if(n>0){
    for(i=0;x<n;i=i+2){
      x+=Math.pow(2,i);
      a=i
    }
    for(i=0;i<a;i++){
      if(n>x-Math.pow(2,a-i)/2){
        if(i%2==0){
        ans+="0";
        x=x;
        }else{
          ans+="1";
          x=x;

        }
      }else{
        if(i%2==0){
        ans+="1";
        x=x-Math.pow(2,a-i)/2;
        }else{
          ans+="0";
          x=x-Math.pow(2,a-i)/2;

        }
      }
    }

  }else if(n<0){
    for(i=1;x>n;i=i+2){
      x+=Math.pow(-2,i);
      a=i
    }
    for(i=1;i<=a;i++){
      if(n>=x+Math.pow(2,a-(i-1))/2){
        if(i%2==0){
        ans+="0";
        x=x+Math.pow(2,a-(i-1))/2;
        }else{
          ans+="1";
          x=x+Math.pow(2,a-(i-1))/2;

        }
      }else{
        if(i%2==0){
        ans+="1";
        x=x;
        }else{
          ans+="0";
          x=x;

        }
      }
    }

  }else{
    ans=0;
  }
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
i=list(map(int, input().split()))
a=list(map(int, input().split()))
k=i[0]
n=i[1]
f=0
for j in range (0,n-1):
    if a[j+1]-a[j]>f:
        f=a[j+1]-a[j]
if a[0]+k-a[n-1]>f:
    f=a[0]+k-a[n-1]
print(k-f)

Measured memory_bytes: 26444
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

int pre[maxn], p[maxn], pos[maxn];

int find(int x){
	int r = x;
	while(pre[r] != r)
		r = pre[r];
	int i = x, t;
	while(i != r){
		t = pre[i];
		pre[i] = r;
		i = t;
	}
	return r;
}

void join(int x, int y){
	int fx = find(x), fy = find(y);
	if(fx != fy) pre[fx] = fy;
}

int main()
{
	int n, m; scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++)	scanf("%d", p + i), pre[i] = i, pos[p[i]] = i;
	for(int i = 1; i <= m; i++){
		int x, y; scanf("%d %d", &x, &y);
		if(x > y) swap(x, y);
		join(x, y);
	}
	for(int i = 1; i <= n; i++) find(i);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(pre[i] == pre[pos[i]]) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1408
#include<string>
#include<iomanip>
#include<iostream>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string a, b,c;
	int x, y;
	cin >> a >> b;
	cin >> x >> y;
	cin >> c;
	if (c == a)
	{
		cout << x - 1 << " " << y;
	}
	else
	{
		cout << x << " " << y - 1;
	}
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;
long long n,i,ans,nans;
long long fact[1000005];
long long inv[1000005];
long long put(long long baza, long long exp)
{
    if(exp==0)
        return 1;

    long long ans=put(baza, exp/2);
    ans*=ans;
    ans%=mod;

    if(exp%2)
    {
        ans*=baza;
        ans%=mod;
    }

    return ans;
}
void genfact()
{
    fact[0]=1;
    for(long long i=1;i<=n;i++)
        fact[i]=(fact[i-1]*i)%mod;

    inv[n]=put(fact[n], mod-2);
    for(long long i=n-1;i>=0;i--)
        inv[i]=(inv[i+1]*(i+1))%mod;
}
long long comb(long long k, long long n)
{
    long long ans=fact[n]*inv[n-k];
    ans%=mod;
    ans*=inv[k];
    ans%=mod;

    return ans;
}
int main()
{
    cin>>n;
    genfact();

    for(i=2;i<=n;i++)
    {
        nans=put(2, i)-2;
        if(nans<0)
            nans+=mod;

        nans*=comb(i, n);
        nans%=mod;

        nans*=put(8, n-i);
        nans%=mod;

        ans+=nans;
        ans%=mod;
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 19108
import numpy as np
r,D,x=map(int,input().split())
def func(r, D, x):
    return r*x - D

X = np.zeros(10)
X[0] = func(r,D,x)
for i in range(10-1):
    X[i+1] = func(r, D, X[i])
for j in X:
    print(int(j))

Measured memory_bytes: 12488
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

#define SQ(x) (x * x)

int main(void)
{
  int N, i;
  double x1, x2, x3;
  double y1, y2, y3;
  double a, b, c, d, e, f;
  double l, m, n;
  double xp,yp, r;

  cin >> N;
  for (i = 0; i < N; i++){
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    
    a = x1 - x2;
    b = y1 - y2;
    c = -1 * (SQ(x1) - SQ(x2) + SQ(y1) - SQ(y2));
    d = x1 - x3;
    e = y1 - y3;
    f = -1 * (SQ(x1) - SQ(x3) + SQ(y1) - SQ(y3));
    
    l = (c * e - b * f) / (e * a - b * d);
    m = (d * c - a * f) / (d * b - e * a);
    
    n = -1 * (SQ(x1) + SQ(y1) + l * x1 + m * y1);
    
    xp = l / -2.0;
    yp = m / -2.0;
    r = sqrt(SQ(l) + SQ(m) - 4 * n) / 2.0;
    
    printf("%.3f %.3f %.3f\n", xp, yp, r);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdlib>  // abs() for integer
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int k, n;
    cin >> k >> n;
    //int a[210000];
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = a[1] - a[0];
    rep(i, n - 1) {
        ans = max(a[i + 1] - a[i], ans);
    }
    if (a[0] != 0) ans = max(k - a[n - 1] + a[0], ans);
    else ans = max(k - a[n - 1], ans);
    cout << k - ans << endl;
    

}

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

int main() {
    int N;
    cin >> N;
    double ans;
    if(N % 2 == 0) ans = 0.5;
    else ans = (double)(N + 1) / (2 * N);

    cout << fixed << setprecision(10) << ans << endl;
}

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

int main(){
    int n;
    cin>>n;
    
    int res = 0;
    int ct = 0;
    for(int i = 1;i <= n;i++){
        int tmp = i;
        while(tmp > 0){
            tmp = tmp/10;
            ct++;
        }
        if(ct%2 != 0)res++;
        ct = 0;
    }
    
    cout<<res;
    return 0;
}

Measured memory_bytes: 256
class UnionFind: 
    def __init__(self, numV):
        self.pars = list(range(numV))
        self.ranks = [0] * numV
        self.sizes = [1] * numV
    def getRoot(self, x):
        par = self.pars[x]
        if par != x:
            self.pars[x] = par = self.getRoot(par)
        return par
    def merge(self, x, y):
        x, y = self.getRoot(x), self.getRoot(y)
        sx, sy = self.sizes[x], self.sizes[y]
        if x == y: return (0, 0)
        if self.ranks[x] < self.ranks[y]:
            self.pars[x] = y
            self.sizes[y] += sx
        else:
            self.pars[y] = x
            self.sizes[x] += sy
            if self.ranks[x] == self.ranks[y]:
                self.ranks[x] += 1
        return (sx, sy)
    def isSame(self, x, y):
        return self.getRoot(x) == self.getRoot(y)
    def updatePars(self):
        for v in range(len(self.pars)):
            self.getRoot(v)
    def getSize(self, x):
        return self.sizes[self.getRoot(x)]

import sys
input = sys.stdin.buffer.readline
n, m = map(int,input().split())

uf = UnionFind(n)
e = [[] for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    if not b in e[a]:
        uf.merge(a,b)

print(max(uf.sizes))

Measured memory_bytes: 89024
N=gets.chomp.to_i
arr=[]
N.times { |i|
    l={}
    input= gets.chomp.split
    l[:city] = input[0]
    l[:score] = input[1].to_i
    l[:order] = i+1
    arr.push l
}

arr.sort! { |a,b|
    if a[:city] === b[:city]
        b[:score].to_i <=> a[:score].to_i
    elsif a[:city] > b[:city] 
        1
    else
        -1
    end
}
puts arr.map { |e| e[:order]}


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long n, m, sum, a[100005], d[100005];
int main() {
	int i;
	cin>>n>>m;
	for(i=0; i<m; i++) scanf("%lld", &a[i]);
	sort(a, a+m);
	for(i=0; i<m-1; i++) d[i] = a[i+1] - a[i];
	sort(d, d+m-1);
	for(i=0; i<m-n; i++) sum += d[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define n 500000
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
void solve();
int main()
{
//	ios_base::sync_with_stdio(0);
//	cin.tie(0); cout.tie(0);
	int times = 1;
//	cin >> times;
	for(int i=0; i<times; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

int a, b, c, d, e, f, g, h;
//int arr[n + 50], arr1[n + 50], arr2[n + 50];

//type here

void solve()
{
	cin >> a >> b;
	double table[1050] = {0}, arr[a + 50];
	for(int i=1; i<=1000; i++)
		table[i] = table[i - 1] + i;
	for(int i=0; i<a; i++)
	{
		double tmp; cin >> tmp;
		arr[i] = (double)table[(int)tmp] / tmp;
	}
	double tmp = 0, mx = 0;
	int left = 0;
	for(int i=0; i < a; i++)
	{
		if(i - left + 1 > b) tmp -= arr[left++];
		tmp += arr[i];
		if(i < b - 1) continue;
		mx = max(mx, tmp);
	}
	printf("%.10lf", mx);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define INF 0x3f3f3f3f
#define pii pair<int, int>
#define mem(x, a) memset(x, a, sizeof(x))
#define AC ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;

const int maxn = 2e5 + 50;
int n;
int bit[maxn], a[maxn], h[maxn];

int lowbit(int x){
	return x & -x;
}

void modify(int x, int val){
	for(int i = x; i <= n; i += lowbit(i)){
		bit[i] = max(val, bit[i]);
	}
}

int query(int x){
	int ans = -INF;
	for(int i = x; i >= 1; i -= lowbit(i)){
		ans = max(ans, bit[i]);
	}
	return ans;
}

main(){
	AC;
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> h[i];
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++){
		int val = query(h[i]) + a[i];
		modify(h[i], val);
	}
	cout << query(n) << "\n";
}

Measured memory_bytes: 8332
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();String op =sc.next();int b=sc.nextInt();
		while (!op.equals("?")){
				if(op.equals("+")){
			System.out.println(a + b);
		}else if(op.equals("-")){
			System.out.println(a - b);
		}else if(op.equals("*")){
			System.out.println(a * b);
		}else if(op.equals("/")){
			System.out.println(a / b);
		}else {System.out.println("tas");}
				a=sc.nextInt();op =sc.next();b=sc.nextInt();}
				}
		}

Measured memory_bytes: 18004
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String tmp = sc.nextLine();
		long ans   = 0;

		for(int i = 0; i < tmp.length(); i++) {
			int y = Integer.parseInt(tmp.substring(i, i + 1));
			ans += y;

		}

		String a;
		if(ans % 9 == 0) {
			a = "Yes";
		}else {
			a = "No";
		}


		System.out.println(a);

	}

}


Measured memory_bytes: 50328
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        if (scanner.hasNextLine()) {
            String[] array = scanner.nextLine().split(" ");
            int N = Integer.parseInt(array[0]);

            String[] Xs = scanner.nextLine().split(" ");
            int[] intArray = new int[N];
            int n = 0;
            for (int i = 0; i < N; ++i) {
                int w = Integer.parseInt(Xs[i]);
                intArray[i] = w;
                if (w > n) {
                    n = w;
                }
            }
            int r = 0;
            int minMax = 0;
            for (int i = 0; i < N; ++i) {
                int w = intArray[i];
                int wMin;
                if (n - w > w) {
                    wMin = w;
                } else {
                    wMin = n - w;
                }
                if (wMin > minMax) {
                    minMax = wMin;
                    r = w;
                }
            }
            System.out.println(n + " " + r);
        }
    }
}

Measured memory_bytes: 49068
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
result = 0
for k in range(N):
    if B[k] <= A[k]:
        result += B[k]
    else:
        remain = max([A[k+1] - (B[k] - A[k]) , 0])
        result += A[k] + A[k+1] - remain
        A[k+1] = remain
print(result)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,T;
    cin >> N >> T;
    vector<int> t(N+1);
    rep(i,N){
        cin >> t[i];
    }
    ll ans = 0;
    rep(i,N){
        if(i==N-1){
            ans+=T;
        }else{
            ans += min(T,t[i+1]-t[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<unordered_map>
#include<cstdio>
#include<set>
#include<map>
#include<algorithm>
#define int long long
using namespace std;

struct star {
	int cost, x, y;
};
bool operator <(const star &a,const  star &b) {
	return a.cost < b.cost;
}

star A[300000];
map<int, int>X;
map<int, int>Y;
signed main(){
	int a, b; scanf("%lld%lld", &a, &b);
	for (int c = 0; c < a; c++) {
		int d, e, f; scanf("%lld%lld%lld", &d, &e, &f);
		A[c] = { f,d,e };
	}
	sort(A, A + a);
	int MAX = 0;
	for (int s = 0, g = 0; g < a; g++) {
		X[A[g].x]++;
		Y[A[g].y]++;
		while (s < g&&A[s].cost + b < A[g].cost) {
			X[A[s].x]--;
			Y[A[s].y]--;
			if (X[A[s].x] == 0) {
				X.erase(A[s].x);
			}
			if (Y[A[s].y] == 0) {
				Y.erase(A[s].y);
			}
			s++;
		}
		int n = X.rbegin()->first - X.begin()->first;
		int m = Y.rbegin()->first - Y.begin()->first;
		MAX = max(MAX, n*m);
	}
	printf("%lld\n", MAX);
}

Measured memory_bytes: 23668
#include<bits/stdc++.h>
using namespace std;
#define mod 1e9+7
#define ll long long int

char arr[1000][1000];
ll dp[1000][1000];




int main(){
    int R,C;
    cin>>R>>C;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            cin>>arr[i][j];
            if(arr[i][j]=='#'){
                dp[i][j]=0;
            }
        }
    }
    bool detect1=false;
    bool detect2=false;
    for(int i=0;i<R;i++){
        if(arr[i][0]=='#'){
            detect1=true;
        }
        if(detect1){
            dp[i][0]=0;
        }
        else{
            dp[i][0]=1;
        }
        
    }
    for(int j=0;j<C;j++){
        if(arr[0][j]=='#'){
            detect2=true;
        }
        if(detect2){
            dp[0][j]=0;
        }
        else{
            dp[0][j]=1;
        }
    }
    for(int i=1;i<R;i++){
        for(int j=1;j<C;j++){
            if(dp[i][j]==0){
                continue;
            }
            if(dp[i-1][j]!=0){
                dp[i][j]=dp[i-1][j]% ((ll)mod);
            }
            if(dp[i][j-1]!=0){
                if(dp[i-1][j]!=0){
                    dp[i][j]+=dp[i][j-1]% ((ll)mod);
                }
                else{
                    dp[i][j]=dp[i][j-1]%((ll) mod);
                }
                dp[i][j]=dp[i][j]%((ll) mod);
            }
            if(dp[i-1][j]==0 and dp[i][j-1]==0){
                dp[i][j]=0;
            }
        }
    }
    
    cout<<dp[R-1][C-1];
}

Measured memory_bytes: 9088
# D - String Formation

from collections import deque

S = deque([s for s in input()])
Q = int(input())
rev = False

for _ in range(Q):
    T = [t for t in input().split()]
    t = int(T[0])
    if t == 1:
        rev = not rev
    if t == 2:
        f, c = int(T[1]), T[2]
        if f == 1:
            if rev:
                S.append(c)
            else:
                S.appendleft(c)
        if f == 2:
            if rev:
                S.appendleft(c)
            else:
                S.append(c)

S = ''.join(list(S))
print(S if not rev else S[::-1])


Measured memory_bytes: 8420
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int main(){
  ll X, Y;
  cin >> X >> Y;

  ll g = gcd(X, Y);

  if(g == Y){
    cout << -1 << endl;
  }else{
    cout << X << endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
 int n, in, sum, max;
 max = sum=0;
 cin >> n;
 while (n--)
 {
  cin >> in;
  sum += in;
  if (in > max) max = in;
 }
 sum -= max;
 if (max < sum) cout << "Yes" << endl;
 else cout << "No" << endl;
 return 0;
}


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

using namespace std;

typedef long long int ll;

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

  for (int i = 1; i <= 5; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      cout << i << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

void code()
{
    ll n;
    cin>>n;
    ll A[n];
    ll count[n+1]={0};
    for(ll i=1;i<n;i++)
    {
        cin>>A[i];
        count[A[i]]++;
    }
    for(ll i=1;i<=n;i++)
    {
        cout<<count[i]<<endl;
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        code();
    }
}

Measured memory_bytes: 6740
#include<iostream>
int GCM(int a,int b){
	if(b==0)return a;
	return GCM(b,a%b);
}

int main(){
	int a,b,c,d,e,f;
	std::cout.precision(3);
	std::cout.setf(std::ios::fixed);
	while(std::cin>>a>>b>>c>>d>>e>>f){
		double x=0.0,y=0.0;
		double a_=a,b_=b,c_=c,d_=d,e_=e,f_=f;
		b_*=d,c_*=d;
		e_*=a,f_*=a;
		y=(c_-f_)/(b_-e_);
		x=(c-y*b)/a;
		std::cout<<x<<" "<<y<<std::endl;
	}
	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  int l = 1000, r = 0;
  for (auto &i : a) {
    cin >> i;
    l = min(l, i);
    r = max(r, i);
  }
  cout << r - l << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3604
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std ;

int main(void){
    int ans=0;
    string S,T;

    cin >> S >> T;
    for(int i=0; i<3; i++)
        if(S[i]==T[i]) ans++;
    
    cout << ans << endl;

    return 0;
}


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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool ok=false;
    for(int i=a;i<a*b;i+=a){
        if(i%b==c){
            ok=true;
            break;
        }
    }
    if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        int m = S % 3600 / 60;
        int s = S % 3600 % 60;

        System.out.println(h + ":" + m + ":" + s);
    }
}



Measured memory_bytes: 26248
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

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

char s[104];
int main(void){
	uint32_t k=nextpint();
	uint32_t n=nextstr(s);
	if(n<=k){
		s[n]=10;
	}else{
		s[k]=s[k+1]=s[k+2]='.';
		s[k+3]=10;
		n=k+3;
	}
	write(STDOUT_FILENO, s, n+1);
}


Measured memory_bytes: 1528
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    vector<int> ans(N, 0);
    REP(i, N){
        vector<int> d(N, 1e5);
        d[i] = 0;
        queue<P> q;
        if (i > 0) q.push(P(i, i-1));
        if (i < N-1) q.push(P(i, i+1));
        if (i == X) q.push(P(i, Y));
        if (i == Y) q.push(P(i, X));
        while(q.size() > 0){
            P tmp = q.front();
            int t = tmp.second;
            d[tmp.second] = min(d[tmp.second], d[tmp.first] + 1);
            if (t > 0 && d[t-1] == 1e5) q.push(P(t, t-1));
            if (t < N-1 && d[t+1] == 1e5) q.push(P(t, t+1));
            if (t == X && d[Y] == 1e5) q.push(P(t, Y));
            if (t == Y && d[X] == 1e5) q.push(P(t, X));
            q.pop();
        }
        REP(i, N) ans[d[i]]++;
    }
    REP(i, N-1) cout << (ans[i+1] / 2) << endl;
    return 0;
}


Measured memory_bytes: 256