akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#include<iomanip>
#include<math.h>
long long int C(int n, int k);
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);

using namespace std;
int main() {

	//D

	long long int x, y;
	cin >> x >> y;
	if ((x + y) % 3 == 0) {
		if ((x >= (x + y) / 3) && (y >= (x + y) / 3)) {
			cout << C((x + y) / 3, x - (x + y) / 3) << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	else {
		cout << 0 << endl;
	}

	return 0;

	//C
	/*int n;
	cin >> n;
	long double x[8], y[8];
	int i;
	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	long double dis[8][8];
	long double discounter = 0;
	int j;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			dis[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
			dis[i][j] = sqrt(dis[i][j]);
			discounter = discounter + dis[i][j];
		}
	}
	discounter = discounter / n;
	cout << fixed;
	cout << setprecision(10);
	cout << discounter << endl;
	return 0;
	*/


	/*
	vector<int> nums(n);
	iota(nums.begin(), nums.end(), 0);

	long double avepath = 0;
	do {
		for (i = 0; i < n - 1; i++) {
			avepath = avepath +		sqrt(dis[nums[i]][nums[i+1]])
		}
	} while (next_permutation(nums.begin(), nums.end()));
	/*
	
	//B
	/*int n;
	string s;
	cin >> n;
	cin >> s;
	int i;
	if (n % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	for (i = 0; i < n / 2; i++) {
		if (s[i] != s[i + (n / 2)]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;*/
}
long long int C(int n, int k) {
	//n kara k toridasu
	long long int i;
	long long int mod = 1000000007;
	long long int res = 1;
	if ((k == 0)||(k == n)) {
		return 1;
	}
	else {
		for (i = 0; i < k; i++) {
			res = (((res * (n - i)) % mod ) * modinv(i + 1, mod)) % mod;
		}
	}
	return res;
}
// a^n mod を計算する
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;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}

Measured memory_bytes: 256
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;
using static Func;
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();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var es = MakeArray(N, _ => new List<Pair>());
		for (var i = 0; i < N - 1; i++)
		{
			var I = G;
			es[I[0] - 1].Add(new Pair(I[1] - 1, I[2] % 2));
			es[I[1] - 1].Add(new Pair(I[0] - 1, I[2] % 2));
		}
		var d = new int[N];
		var st = new Stack<Pair>();
		st.Push(new Pair(0, -1));
		while (st.Count > 0)
		{
			var t = st.Pop();
			foreach (var u in es[t.T]) if (u.T != t.C) { d[u.T] = d[t.T] + u.C; st.Push(new Pair(u.T, t.T)); }
		}
		for (var i = 0; i < N; i++) WriteLine(d[i] % 2);
	}
}
static class Func { }
class Pair
{
	public readonly int T, C;
	public Pair(int t, int c) { T = t; C = c; }
}


Measured memory_bytes: 35592
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long x = Math.abs(sc.nextLong());
        long k = sc.nextLong();
        long d = sc.nextLong();

        if(x / d >= k){
            System.out.println(x - k * d);
            return;
        }

        k -= x / d;
        x -= x / d * d;

        if(k % 2 == 0){
            System.out.println(Math.abs(x));
        }else{
            System.out.println(Math.abs(x - d));
        }

    }
}


Measured memory_bytes: 35744
#include <bits/stdc++.h>
#include <iomanip>
#define M (1<<20)-1
#define MAX 100000000
#define MIN -100000000
#define mod 998244353 
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main(){
	long double l;
	cin>>l;
	long double x = l/3.0;
	long double volume = x*x*x;
	cout<<setprecision(18)<<volume<<endl;
	
	return 0;
}

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

int main()
{
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    int p[A], q[B], r[C];

    for (int i = 0; i < A; ++i) cin >> p[i];
    for (int i = 0; i < B; ++i) cin >> q[i];
    for (int i = 0; i < C; ++i) cin >> r[i];

    sort(p, p + A, greater<int>());
    sort(q, q + B, greater<int>());
    sort(r, r + C, greater<int>());

    priority_queue<
         int
        ,vector<int>
        ,greater<int>
    > que;

    for (int i = 0; i < X; ++i) que.push(p[i]);
    for (int i = 0; i < Y; ++i) que.push(q[i]);
    for (int i = 0; i < C; ++i) {
        if (que.top() < r[i]) {
            que.pop();
            que.push(r[i]);
        }
    }

    long long ans = 0;
    for (int i = 0; i < X + Y; ++i) {
        ans += que.top();
        que.pop();
    }

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

Measured memory_bytes: 2552
#include <iostream>
#include <vector>
#include <set>
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define forsn(i,s,n) for(int i = int(s); i < int(n); i++)
#define rforn(i,n) for(int i = int(n)-1; i > 0; i--)
using namespace std;
const int CANT_LETRAS = 26;

int main()
{
    string word;
    cin >> word;
    if(int(word.size()) < CANT_LETRAS)
    {
        int letras[CANT_LETRAS];
        forn(i,CANT_LETRAS) letras[i] = 0;
        forn(i,word.size()) letras[word[i]-'a'] = 1;
        int s = 0;
        for(;letras[s] != 0; s++);
        cout << word << char('a'+s) << endl;
        return 0;
    }

    int menores[CANT_LETRAS];
    forn(i,CANT_LETRAS) menores[i] = 0;

    //int menor = word[int(word.size()-1)];
    for(int i = int(word.size()-1); i > 0; i--)
    {
        //Tengo que fijarme que si   
        menores[word[i]-'a'] = 1;
        forsn(z,word[i-1]-'a',26)
        {
            if(menores[z] == 1)
            {
                cout << word.substr(0,i-1) << char('a'+z) << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import bisect


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n = int(input())
    s = input()
    R, G, B = [], [], []
    for i in range(n):
        index = i+1
        if s[i] == "R":
            R.append(index)
        elif s[i] == "G":
            G.append(index)
        elif s[i] == "B":
            B.append(index)
    all_count = len(R)*len(G)*len(B)
    count = 0
    # j - i != k - j
    # k = 2j - i
    for i in range(n):
        for j in range(i+1, n):
            if s[i] == s[j]:
                continue
            k = 2*j - i
            if k >= n:
                continue
            if s[k] == s[i] or s[k] == s[j]:
                continue
            count += 1
    print(all_count - count)

def bi(num, a, b, x):
    print((a * num) + (b * len(str(b))))
    if (a * num) + (b * len(str(b))) <= x:
        return False
    return True

def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 73988
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long



signed main(void) {
  int N, L;
  cin >> N >> L;
  int sum = 0;
  rep (i, N) {
  	sum += L+i;
  }
  if (L >= 0) {
  	sum -= L;
  } else {
  	if (N >= 1-L) {

  	} else {
  		sum -= L + N -1;
  	}
  }

  cout << sum << endl;

  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    string S; cin >> S;

    int p = 0;
    REP(i,N){
        if(S[i]=='1') p++;
    }

    reverse(ALL(S));

    vector<int> amari0(N);
    vector<int> amari1(N);


    int num0 = 1;
    int num1 = 1;

    ll sum0 = 0, sum1 = 0;

    REP(i,N){
        num0 %= p+1;
        amari0[i] = num0;
        
        if(S[i] == '1'){
            sum0 += num0;
            sum0 %= p+1;
        }
        num0 *= 2;
    }

    if(p!=1){
        REP(i,N){
            num1 %= p-1;
            amari1[i] = num1;
            
            if(S[i] == '1'){
                sum1 += num1;
                sum1 %= p-1;
            }
            num1 *= 2;
        }
    }
    


    // REPR(i,N-1){
    //     if(S[i] == '0'){
    //         cout << (sum0 + amari0[i])%(p+1) << endl;
    //     }else{
    //         cout << (sum1 - amari1[i] + p-1)%(p-1) << endl;
    //     }
    // }

    vector<int> table(200100, 0);
    FOR(i,1,200010){
        int pc = __builtin_popcount(i);
        if(i%pc==0) table[i] = 1;
        else table[i] = table[i%pc]+1;
    }

    vector<int> ans(N,0);
    REP(i,N){
        if(S[i] == '0'){
            ans[i] = table[(sum0 + amari0[i])%(p+1)];
        }else if(S[i] == '1' && p==1){
            ans[i] = -1;
        }else{
            ans[i] = table[(sum1 - amari1[i] + p-1)%(p-1)];
        }
    }


    reverse(ALL(ans));
    REP(i,N){
        cout << ans[i]+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 6828
using System;
using System.Collections.Generic;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            var colors = new List<bool>();
            foreach (var c in str)
            {
                if (c == '1')
                {
                    colors.Add(true);
                }
                else
                {
                    colors.Add(false);
                }
            }


            var sum = 0;
            var i = 0;
            while (i < colors.Count - 1)
            {
                if (colors[i] != colors[i + 1])
                {
                    colors.RemoveAt(i);
                    colors.RemoveAt(i);
                    sum += 2;

                    if (i != 0)
                    {
                        i--;
                    }
                }
                else
                {
                    i++;
                }
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<algorithm>
int read(){int x=0,c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))x=x*10+c-48,c=getchar();return x;}
void over(){puts("-1"),std::exit(0);}
const int N=500007;
std::vector<int>e[N];
int n,m,ans,eu,ev,a[N],fa[N],dep[N],f[N];
void dfs(int u)
{
    dep[u]=dep[fa[u]]+1,f[u]=dep[u]&1? 1:-1;
    for(int v:e[u]) if(v^fa[u]) dep[v]? (eu=u,ev=v):(fa[v]=u,dfs(v),f[u]+=f[v]);
}
void work1()
{
    if(f[1]) over();
    for(int i=1;i<=n;++i) ans+=abs(f[i]);
    printf("%d",ans);
}
void work2()
{
    if(f[1]&1) over();
    int x=-f[1]/2;
    for(;eu;eu=fa[eu]) f[eu]+=x;
    for(;ev;ev=fa[ev]) f[ev]+=x;
    for(int i=1;i<=n;++i) ans+=abs(f[i]);
    printf("%d",ans+abs(x));
}
void work3()
{
    if(f[1]) over();
    int c=0,x;
    for(;ev^eu;ev=fa[ev]) a[++c]=f[ev],dep[ev]=0;
    std::sort(a+1,a+c+1),x=a[(c+1)/2];
    for(int i=1;i<=n;++i) if(dep[i]) ans+=abs(f[i]);
    for(int i=1;i<=c;++i) ans+=abs(a[i]-x);
    printf("%d",ans+abs(x));
}
int main()
{
    n=read(),m=read();
    for(int i=1,u,v;i<=m;++i) u=read(),v=read(),e[u].push_back(v),e[v].push_back(u);
    dfs(1);
    m==n-1? work1():(abs(dep[eu]-dep[ev])&1? work3():work2());
}


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

int main() {
	int K, S;
	cin >> K >> S;
	int N = 0;
	for (int X = 0; X <= K; X++) {
		int Ymin = S - X - K;
		int Ymax = S - X;
		Ymin = Ymin > 0 ? Ymin : 0;
		Ymin = Ymin <= K ? Ymin : K+1;
		Ymax = Ymax < K ? Ymax : K;
		Ymax = Ymax >= 0 ? Ymax : -1;
		N += Ymax - Ymin + 1;
	}
	cout << N;
}

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

using namespace std;

const int MOD = 1000000007;

int main(){
	vector<long long> inv(1001);
	vector<long long> fact(1001);
	vector<long long> factInv(1001);
	inv[0] = inv[1] = 1;
	fact[0] = fact[1] = 1;
	factInv[0] = factInv[1] = 1;
	for(int i=2;i<inv.size();i++){
		inv[i] = inv[MOD%i] * (MOD - MOD/i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	long long dp[2][1001];
	static long long comb[1001][1001];
	comb[1][0] = comb[1][1] = 1;
	for(int i=2;i<=1000;i++){
		comb[i][0] = 1;
		for(int j=1;j<i;j++) comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%MOD;
		comb[i][i] = 1;
	}
	int N, A, B, C, D;
	while(cin >> N >> A >> B >> C >> D){
		memset(dp, 0, sizeof(dp));
		dp[0][N] = 1;
		for(int i=0;i<=N;i++){
			int cur = i%2, next = 1-i%2;
			for(int j=0;j<=N;j++) dp[next][j] = dp[cur][j];
			if(i < A || B < i) continue;
			for(int j=0;j<=N;j++){
				long long div = 1;
				for(int k=1;k*i<=j;k++){
					div = (div * factInv[i])%MOD;
					div = (div * inv[k])%MOD;
					if(k > D) break;
					if(k < C) continue;
					long long add = dp[cur][j] * comb[j][k*i] % MOD * fact[k*i] % MOD * div % MOD;
					dp[next][j-k*i] += add;
					dp[next][j-k*i] %= MOD;
				}
			}
		}
		cout << dp[1-N%2][0] << endl;
	}
}


Measured memory_bytes: 7168
#include <atcoder/all>
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/

int n, m;
char field[110][110];

const int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0};
bool in(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }

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

    cin >> n >> m;
    rep(i, n) cin >> field[i];

    atcoder::mf_graph<int> mf(n * m + 2);
    const int S = n * m, T = n * m + 1;

    rep(i, n) rep(j, m) {
        if(field[i][j] == '#') continue;
        if((i + j) % 2 == 0) {
            mf.add_edge(S, i * m + j, 1);
            rep(d, 4) {
                int xx = i + dx[d];
                int yy = j + dy[d];
                if(in(xx, yy) && field[xx][yy] == '.')
                    mf.add_edge(i * m + j, xx * m + yy, 1);
            }
        } else
            mf.add_edge(i * m + j, T, 1);
    }

    cout << mf.flow(S, T) << endl;
    for(auto &&e : mf.edges()) {
        if(e.flow != 1 || e.from == S || e.to == T) continue;
        int sx = e.from / m;
        int sy = e.from % m;
        int tx = e.to / m;
        int ty = e.to % m;
        if(sx == tx) {
            if(sy > ty) swap(sy, ty);
            field[sx][sy] = '>';
            field[tx][ty] = '<';
        } else {
            if(sx > tx) swap(sx, tx);
            field[sx][sy] = 'v';
            field[tx][ty] = '^';
        }
    }

    rep(i, n) cout << field[i] << endl;

    return 0;
}

Measured memory_bytes: 5684
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
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;
}
double PI = 3.141592653589793238;
vector<vector<int>>G(100030);
int main() {
	int n, m;
	cin >> n >> m;
	vector<int>v;
	for (int i = 0; i < n; i++) {
		int h;
		cin >> h;
		v.push_back(h);
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int sum = G[i].size();
		int s = 0;
		for (auto iter : G[i]) {
			if (v[i - 1] > v[iter - 1]) {
				s++;
			}
		}
		if (s == sum) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 8652
m[100][100];
D(x,y,n){
	if(n<4){
		m[x][y]=1;
		if(n>1)m[x][y-1]=1;
		if(n==2)m[x+1][y-1]=1;
		if(n>2)m[x][y-2]=1,m[x+1][y-2]=1,m[x+2][y-2]=1,m[x+2][y-1]=1,m[x+2][y]=1;
		return;
	}
	int i=0,j=0;
	for(;j<n;j++)m[x+i][y-j]=1;j--;
	for(;i<n;i++)m[x+i][y-j]=1;i--;
	for(;j>=0;j--)m[x+i][y-j]=1;j++;
	for(;i>=2;i--)m[x+i][y-j]=1;j++;
	if(n-4){
		m[x+2][y-1]=1;
		D(x+2,y-2,n-4);
	}
}
main(d,n,i,j){
	for(scanf("%d",&d);d;d--){
		memset(m,0,sizeof(m));scanf("%d",&n);D(0,n-1,n);
		for(i=0;i<n;putchar('\n'),i++)
			for(j=0;j<n;j++)putchar(m[j][i]?'#':' ');
		if(d>1)putchar('\n');
	}
exit(0);}

Measured memory_bytes: 612
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))

mi = 1000000
ans = 0
for i in range(n):
    deg = abs(1000*t - 6*h[i] - 1000*a)
    if mi > deg:
        mi = deg
        ans = i+1
print(ans)


Measured memory_bytes: 3060
X, K, D = map(int, input().split(" "))

X = abs(X)
now = X
over_zero_step = 0
over_zero = 0
not_over_zero = now
flg = 0

if X < abs(K * D):
    q = X // D
    now = X - q * D
    now = abs(now)
#    print(now, q)    
    for i in range(q+1, K+1):
        nxt = now - D
        if nxt < 0:
            over_zero = nxt
            not_over_zero = now
            over_zero_step = i
            break
        now = nxt
else:
    remaining_step = 0
    nearest_point = X - K * D
    flg = 1

if flg == 0:
        
    if abs(over_zero) <= not_over_zero:
        nearest_point = over_zero
        nearest_point_step = over_zero_step
        next_nearest_point = not_over_zero
        remaining_step = K - nearest_point_step
    else:
        nearest_point = not_over_zero
        nearest_point_step = over_zero_step - 1
        next_nearest_point = over_zero
        remaining_step = K - nearest_point_step

#print("rem", remaining_step)
if remaining_step % 2 == 0:
    print(abs(nearest_point))
else:
    print(abs(next_nearest_point))

Measured memory_bytes: 9248
#include <stdio.h>
#include <string.h>

#define S_MAX 1000000

int main(void) {
    char S[S_MAX];
    scanf("%s", S);

    int snum=strlen(S);

    char RS[snum];
    for (int i = snum; i >= 0; i--) {
        // printf("%d, %d, %c\n", i, snum-i, S[i-1]);
        RS[snum-i] = S[i-1];
    }

    for (int i = 0; i < snum;) {
        if (strncmp(&RS[i], "maerd", 5) == 0) {
            i = i + 5;
        } else if (strncmp(&RS[i], "remaerd", 7) == 0) {
            i = i + 7;
        } else if (strncmp(&RS[i], "esare", 5) == 0) {
            i = i + 5;
        } else if (strncmp(&RS[i], "resare", 6) == 0) {
            i = i + 6;
        } else {
            printf("NO\n");
            return 0;
        }
    }

    printf("%s\n", "YES");
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[100];
	cin>>n;
	int s=0,g=0;
	while(n--)
	{
		int d;
		cin>>d;
		g=max(d,g);
		if(d>=g) s++;
	}
	printf("%d",s);
}

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

const int time_max = 86410;

int imos[time_max];

int time_split(char Tens_Place,char One_Place){
    int return_num;
    string s = {Tens_Place, One_Place};
    stringstream ss;
    ss << s;
    ss >> return_num;
    return return_num;
}

int main() {

    while(1) {

        int n;

        cin >> n;

        if(n==0){
            break;
        }

        for(int i=0; i<time_max; i++){
            imos[i] = 0;
        }

        for (int i = 0; i < n; i++) {
            string start, goal;
            cin >> start >> goal;
            int h, m, s;
            h = time_split(start[0], start[1]);
            m = time_split(start[3], start[4]);
            s = time_split(start[6], start[7]);
            imos[h * 60 * 60 + m * 60 + s]++;
            h = time_split(goal[0], goal[1]);
            m = time_split(goal[3], goal[4]);
            s = time_split(goal[6], goal[7]);
            imos[h * 60 * 60 + m * 60 + s]--;
        }

        for (int i = 1; i < time_max; i++) {
            imos[i] += imos[i - 1];
        }

        int ans = 0;

        for (int i = 0; i < time_max; i++) {
            ans = max(ans, imos[i]);
        }

        cout << ans << endl;

    }

    return 0;
}


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b;
	A = b - a;
	ans = b + A;
	cout << ans;
}

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

int cnt[3];
const int mod = 998244353;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	long long int ans = 1;
	for(int i=1;i<=n;i++)
		ans=ans*i%mod;
	for(int i=0;i<s.size();i++){
		int op;
		if(s[i]=='R')	op = 0;
		else if(s[i]=='G')	op = 1;
		else	op = 2;
		vector<int> v(cnt,cnt+3);
		int x = cnt[op]++;
		sort(v.begin(),v.end(),greater<int>());
		if(v[0]==x);
		else if(v[1]==x)	ans = ans*(v[0]-v[1])%mod;
		else	ans = ans*(v[1]-v[2])%mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 720
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;
int N_MAX = 50;
typedef pair<long long,long long> P;
int main()
{
  int n,k,i,j,l;
  long long x,y,res=LLONG_MAX;
  P p[N_MAX];
  vector<long long> q;
  cin >> n >> k;
  for(i=0;i<n;i++)
    cin >> p[i].first >> p[i].second;
  sort(p,p+n);
  for(i=0;i<n-k+1;i++){
    q.clear();
    x=p[i+k-1].first-p[i].first;
    for(j=i;j<i+k;j++)
      q.push_back(p[j].second);
    sort(q.begin(),q.end());
    y=q[k-1]-q[0];
    res=min(res,x*y);
    for(j=i+k;j<n;j++){
      q.push_back(p[j].second);
      sort(q.begin(),q.end());
      x=p[j].first-p[i].first;
      y=LLONG_MAX;
      for(l=0;l<=j-i-k+1;l++)
        y=min(y,q[l+k-1]-q[l]);
      res=min(res,x*y);
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0];
    const T = arg[1];
    
    for(let i=S.length - T.length; i>=0; i--) {
        let flag = true;
        let sub  = S.substr(i, T.length);

        for(let j=0; j<T.length; j++) {
            if(sub.charAt(j) !== T.charAt(j) && sub.charAt(j) !== "?") {
                flag = false;
                break;
            }
        }
        
        if(flag === true) {
            let answer = S.substring(0, i) + T + S.substring(parseInt(i) + T.length);
            answer = answer.replace(/\?/g, "a");
            console.log(answer);
            return;
        }
    }
    
    console.log("UNRESTORABLE");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

# inputa = [int(n) for n in inputa]
# inputa.sort()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

odd =  int(math.floor((a+1) / 2))
even = int(math.floor(a / 2))

ans = odd * even
print(ans)



Measured memory_bytes: 38256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int main(){
  int N, M; cin >> N >> M;
  int cnt[N] = {};
  for (int i = 0; i < M; i++){
    int A, B; scanf("%d%d", &A, &B);
    A--; B--;
    cnt[A]++; cnt[B]++;
  }

  for (int i = 0; i < N; i++){
    if (cnt[i] % 2 != 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define end puts("No"),exit(0)
const int maxn=1e5+10;
int hea[maxn],nxt[maxn<<1],to[maxn<<1],p[maxn],l[maxn],r[maxn],tot;
void add(int a,int b) {
	nxt[++tot]=hea[a];
	hea[a]=tot;
	to[tot]=b;
}
void dfs(int x,int f,int d) {
	if(~p[x])l[x]=r[x]=p[x];
	else if(d)l[x]=-1e9+1,r[x]=1e9-1;
	else l[x]=-1e9,r[x]=1e9;
	for(int i=hea[x];i;i=nxt[i])
		if(to[i]!=f) {
			dfs(to[i],x,d^1);
			if(l[x]>-1e8&&!((l[x]+l[to[i]])%2))end;
			l[x]=max(l[x],l[to[i]]-1);
			r[x]=min(r[x],r[to[i]]+1);
		}
	if(l[x]>r[x])end;
}
void dfs1(int x,int f,int v) {
	p[x]=v;
	for(int i=hea[x];i;i=nxt[i])
		if(to[i]!=f) {
			int vv=v-1;
			if(l[to[i]]<=vv&&vv<=r[to[i]])dfs1(to[i],x,vv);
			else dfs1(to[i],x,vv+2);
		}
}
signed main() {
	memset(p,-1,sizeof(p));
	int n,a,b,k;
	scanf("%d",&n);
	for(int i=1;i<n;i++) {
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	scanf("%d",&k);
	for(int i=1;i<=k;i++) {
		scanf("%d%d",&a,&b);
		p[a]=b;
	}
	dfs(a,0,b%2);
	puts("Yes");
	dfs1(a,0,b);
	for(int i=1;i<=n;i++)
		printf("%d\n",p[i]);
	return 0;
}

Measured memory_bytes: 14712
x, k, d = map(int, input().split())
if abs(x) // d >= k:
    if x > 0:
        print(x - k * d)
    else:
        print(abs(k * d + x))
    exit()
div = abs(x) // d
k -= div
if x > 0:
    x -= div * d
else:
    x += div * d
if k % 2 == 0:
    print(abs(x))
else:
    print(abs(abs(x) - d))


Measured memory_bytes: 9060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 7;
const int mod = 1e9 + 7;
inline int add(int x, int y) {int res = x + y; if (res >= mod) res -= mod; return res;}
inline int mul(int x, int y) {ll res = (ll)x * y; res -= res / mod * mod; return res;}
vector<int>G[MAXN];
int dp[MAXN][2];
void dfs(int u, int f) // 0-white 1-black
{
    dp[u][0] = dp[u][1] = 1;
    for (int v : G[u]) if (v != f)
    {
        dfs(v, u);
        dp[u][0] = mul(dp[u][0], add(dp[v][0], dp[v][1]));
        dp[u][1] = mul(dp[u][1], dp[v][0]);
    }
}
int main()
{
    int n; scanf("%d", &n);
    for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), G[u].push_back(v), G[v].push_back(u);
    dfs(1, 0);
    printf("%d\n", add(dp[1][0], dp[1][1]));
    return 0;
}

Measured memory_bytes: 13440
#include <iostream>
#include <string>
#include <cstdlib>
 
using namespace std;
 
int top,S[101];
string str;
 
 
void initialize() {
  top = 0;
}
 
int isEmpty() {
  return top == 0;
}
 
int isFull() {
  return top >= 100;
}
 
void push(int x) {
  if ( isFull() )cout << "overflow" << endl;
  else {
    top++;
    S[top] = x;
  }
}
 
int pop() {
  if ( isEmpty() ) cout << "underflow" << endl;
  else {
    top--;
    return S[top+1];
  }
}
 
int main() {
   
  initialize();
   
  int num1,num2;
   
  while ( cin >> str ) {
     
    if ( str[0] == '+') {
      num1 = pop();
      num2 = pop();
      push( num1 + num2 );
       
    }else if ( str[0] == '-' ) {
       
      num1 = pop();
      num2 = pop();
      push( num2 - num1 );
       
    }else if ( str[0] == '*' ) {
       
      num1 = pop();
      num2 = pop();
      push( num1 * num2 );
       
    } else {
       
      push(atoi(str.c_str()));
       
    }
     
  }
   
  cout << pop() << endl;
 
  return 0;
}

Measured memory_bytes: 3132
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

L=input()
a=0
x=10**9+7
def bp(a,n):
        r=1
        while(n):
           if n%2:
              r=r*a%x
           a=a*a%x
           n>>=1
        return r
c=len(L)
y=0
for i in range(c):
 if L[i]=="1":
  a+=(bp(3,c-1-i)*bp(2,y))%x
  a%=x
  y+=1
print((a+2**y)%x)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  string s;
  cin >> s;
  int ans1 = 0, ans2 = 0;
  rep(i, s.size()) {
    if (i%2 == 0) {
      if (s.at(i) == '0') {
        ans1++;
      } else {
        ans2++;
      }
    } else {
      if (s.at(i) == '1') {
        ans1++;
      } else {
        ans2++;
      }
    }
  }
  cout << min(s.size()-ans1, s.size()-ans2) << endl;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

N = int(input())
x = list(map(int, input().split()))

d = 0
for p in range(min(x), max(x) + 1):
    c = 0
    for xi in x:
        c += (xi - p) ** 2

    d = c if not d else min(d, c)

print(d)


Measured memory_bytes: 3060
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;*/
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
typedef long long ll;
typedef pair<ll, ll> Pa;

/*
template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

typedef modint<MOD> m;
m func[400001];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
m comb(m n, m r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}*/

int h[100000];
int dp[100001];
int main() {
	cin >> N;
	rep(i, N) {
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	rep(i, N - 2) {
		dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1]));
	}
	cout << dp[N - 1];
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#define PI 3.1415926535897932384626433
using namespace std;
int main(){
    double nowx=0,nowy=0,nowkaku=PI/2;
    while(1){
        double ho,kaku;
        scanf("%lf,%lf",&ho,&kaku);
        if(ho==0&&kaku==0)break;
        nowy+=sin(nowkaku)*ho;
        nowx+=cos(nowkaku)*ho;
        nowkaku+=PI/180*kaku;
    }
    printf("%d\n%d\n",(int)nowx*-1,(int)nowy);
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

string a,b,c;

int main(){
	
  	cin >> a >> b >> c;
	char diff = 'A'-'a';
  	printf("%c%c%c\n",a[0]+diff,b[0]+diff,c[0]+diff);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] mens = new int[n];
		for(int i = 0; i < n; i++) {
			mens[i] = sc.nextInt();
		}
		int[] ans = new int[n];

		for(int i = 0; i < n; i++) {
			int a = mens[i] - 1;
			ans[a] = i;
		}
		for(int i = 0; i < n; i++) {
			System.out.println(ans[i] + 1);
		}

	}

}

Measured memory_bytes: 62120
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;

	if (a > b){
		if (c > a){
			cout << b << " " << a << " " << c << endl;
		}
		else if (b > c){
			cout << c << " " << b << " " << a << endl;
		}
		else{
			cout << b << " " << c << " " << a << endl;
		}
	} else {
		if (c > b){
			cout << a << " " << b << " " << c << endl;
		}
		else if (a > c){
			cout << c << " " << a << " " << b << endl;
		}
		else{
			cout << a << " " << c << " " << b << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3072
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int  n = Integer.parseInt(sc.next());
        if (n%2==0) {
            System.out.println(0.5d);
        } else { 
             System.out.println((double)((n+1)/2)/(double)n);
        }
        
    }
    
    private static void sort(int[] d, int left, int right){
        if(left>=right){return;}
        int p = d[(left+right)/2];
        int l=left, r=right;
        int tmp;
        while(l<=r){
            while(d[l]>p){l++;}
            while(d[r]<p){r--;}
            if(l<=r){
                tmp=d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++; r--;
            }
        }
        sort(d, left, r);
        sort(d, l, right);
    }
}

Measured memory_bytes: 23124
#B問題
N = int(input())
R_list = []
for i in range(N):
    S, P=map(str, input().split())
    R_list.append([S , int(P)*-1 , i+1])
R_list.sort()
for i in range(N):
    R_list[i].append(i+1)
R_list.sort(key=lambda x:x[3])
for i in range(N):
    print(R_list[i][2])

    

Measured memory_bytes: 3060
using Yorukatsu056.Questions;
using Yorukatsu056.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu056.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/abc077/tasks/abc077_a
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s1 = inputStream.ReadLine();
            var s2 = inputStream.ReadLine();

            for (int i = 0; i < 3; i++)
            {
                if (s1[i] != s2[2 - i])
                {
                    yield return "NO";
                    yield break;
                }
            }

            yield return "YES";
        }
    }
}


namespace Yorukatsu056
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu056.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu056.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13140
#include<iostream>

using namespace std;

typedef long long ll;

ll a[10000], b[10000];
int N;

int main() {
	cin >> N;
	ll cta = 0;
	ll ctb = 0;
	ll A = 0, B = 0;

	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)cin >> b[i];

	for (int i = 0; i < N; i++) {
		if (a[i] > b[i])ctb += (a[i] - b[i]), B += (a[i] - b[i]);//必須回数
		else if (a[i] < b[i])cta += (b[i] - a[i]), A += (b[i] - a[i]) / 2;//猶予回数
	}
	if (cta >= ctb * 2 && A >= B)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long    // %d=>%lld
#define pb push_back
#define INF (1e9+7)
#define llINF 1e17
#define EPS 1e-9
#define pi acos(-1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;

const int MAX_n = 100000;
int n,a[MAX_n];

bool dp[MAX_n];
int cnt;

void check(int x){
    if(x == 1){
        dp[x]=false;
        return;
    }
    if(dp[x] == false){
        return;
    }else {
        dp[x]=false;
        check(a[x]-1);
        cnt++;
    }
    return;
}


signed main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    fill(dp,dp+n,true);

    check(0);

    if(dp[1]){
        cout<< -1<< endl;
    }else{
        cout<< cnt<< endl;
    }


    return 0;
}

Measured memory_bytes: 2304
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        FastScanner sc = new FastScanner(Console.OpenStandardInput());
        int N = sc.nextInt();
        int[] A = sc.intArray(N);
        bool flg = true;
        foreach (int Ai in A)
            if (Ai % 2 == 0 && Ai % 3 != 0 && Ai % 5 != 0)
            {
                flg = false;
                break;
            }
        Console.WriteLine(flg ? "APPROVED" : "DENIED");
    }
}

// FastScanner start
public class FastScanner
{
    public readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public FastScanner(Stream stream)
    {
        str = stream;
    }
    private T[] enumerate<T>(int n, Func<T> f)
    {
        var a = new T[n];
        for (int i = 0; i < n; ++i) a[i] = f();
        return a;
    }
    public char nextChar()
    {
        byte b = 0;
        do
        {
            b = read();
        }
        while ((b < 33 || 126 < b) && !isEof);
        return (char)b;
    }
    public int nextInt()
    {
        return (isEof) ? int.MinValue : (int)nextLong();
    }
    public long nextLong()
    {
        if (isEof)
        {
            return long.MinValue;
        }
        long ret = 0;
        byte b = 0;
        var ng = false;
        do
        {
            b = read();
        }
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-')
        {
            ng = true;
            b = read();
        }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
            {
                return ng ? -ret : ret;
            }
            else ret = ret * 10 + b - '0';
        }
    }
    public int[] intArray(int n)
    {
        return enumerate(n, nextInt);
    }
    public long[] longArray(int n)
    {
        return enumerate(n, nextLong);
    }
    public char[] charArray(int n)
    {
        return enumerate(n, nextChar);
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = nextChar(); b >= 33 && b <= 126; b = (char)read())
        {
            sb.Append(b);
        }
        return sb.ToString();
    }
    private byte read()
    {
        if (isEof)
        {
            return 0;
        }
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
}
// FastScanner end

Measured memory_bytes: 13140
N = int(input())
A=list(map(int, input().split()))
B=[A[N-1]]
#print(B[0])
for i in range(len(A)-2):
    #print(i)
    b=B[i]+A[N-2-i]
    B.append(b)
#print(B)
total=0
for i in range(len(B)):
    total += A[i]*B[len(B)-1-i]

print(total%(10**9+7))

Measured memory_bytes: 31440
#include "bits/stdc++.h"

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
#define EPS 1e-9

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 250, M = 1e6 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

void go(int tc = 0){
    ll x, k, d; cin >> x >> k >> d;

    ll moves = abs(ceil(1.0 * x / d));

    moves = min(moves, k);

    ll n = (x + (x > 0 ? -1 : 1) * moves * d);

    ll remMoves = k - moves;

    if(remMoves & 1){
        cout << min(abs(n + d), abs(n - d));
    }
    else{
        if(remMoves > 1)
            cout << min({abs(n), abs(n - 2 * d), abs(n + 2 * d)});
        else
            cout << abs(n);
    }

}

int main(){
    init();

//    freopen("in.in", "r", stdin);
//    freopen("out.out", "w", stdout);

   int t = 1, tc = 1;
//   cin >> t;
    while(t--)
        go(tc++);
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
 
int n, f[10][10];
ll ans;
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; ++i){
		int x=i;
		while(x>=10) x/=10;
		++f[x][i%10];
	}
	for(int i=1; i<=n; ++i){
		int x=i;
		while(x>=10) x/=10;
		ans+=f[i%10][x];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256