akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public static partial class Program
{
    public static void Main()
    {
        var n = CRL().ToInt();
        var ais = CRL().ArrayInts();

        var min = int.MaxValue;
        for (int i = -100; i <= 100; i++)
        {
            min = Math.Min(min, ais.Sum(x => Math.Pow(x - i, 2)).ToInt());
        }
        
        CWL(min);
    }
}

public static partial class Program
{
    //テンプレここから
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    public static int LCM(int a, int b) => a * b / GCD(a, b);
    public static int ToInt(this double d) => (int) d;
    public static long ToLong(this double d) => (long) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static string RL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static void WL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static int[] dx = new [] {0, -1, 0, 1};
    public static int[] dy = new [] {-1, 0, 1, 0};
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);
    //テンプレここまで
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        scanner.close();

        String ans = "No";

        for (int i = 1; i <= 9; i++) {
            if (N % i == 0) {
                int a = N / i;
                if (a >= 1 && a <= 9) {
                    ans = "Yes";
                    break;
                }
            }
        }

        System.out.println(ans);

    }

}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N+1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        a[i] += a[i-1];
    }
    set<ll> s;
    for (int l = 1; l <= N; l++) {
        for (int r = l; r <= N; r++) {
            s.insert(a[r]-a[l-1]);
        }
    }
    ll ans = 0;
    for (int k = 60; k >= 0; k--) {
        int c = 0;
        set<ll> ss = s;
        for (auto i = ss.begin(); i != ss.end();) {
            if ((1LL << k) & (*i)) {
                i++;
            }
            else {
                ss.erase(i++);
            }
        }
        if (ss.size() >= K) {
            s = ss;
            ans += (1LL << k);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 49280
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    K, S = LI()

    counter = 0
    for X in range(min(S+1, K+1)):
        for Y in range(min(S-X+1, K+1)):
            if 0<= S-X-Y <= K:
                counter += 1

    print(counter)

main()

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

int ab(int A,int B){
	A-=B;
	if(A<0)A*=(-1);
	return A;
}

int main(){
	int d,n;//2<=d<=200//1<=n<=200
	int hot[200];
	int clo[200][3];//最低/最高/派手さ
	cin>>d>>n;
	for(int i=0;i<d;i++)cin>>hot[i];
	for(int i=0;i<n;i++)for(int j=0;j<3;j++)cin>>clo[i][j];
	int dp[201][201]={0};//day//clo
	for(int i=0;i<n;i++)if(!(clo[i][0]<=hot[0]&&hot[0]<=clo[i][1]))dp[0][i]=-1;
	for(int i=1;i<d;i++){
		for(int j=0;j<n;j++){
			if(clo[j][0]<=hot[i]&&hot[i]<=clo[j][1]){
				for(int k=0;k<n;k++){
					if(dp[i-1][k]>=0){
						dp[i][j]=max(dp[i][j],dp[i-1][k]+ab(clo[j][2],clo[k][2]));
					}
				}
			}
			else dp[i][j]=-1;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++)ans=max(ans,dp[d-1][i]);
	cout<<ans<<endl;
	
}


Measured memory_bytes: 1328
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int s, w; cin >> s >> w;
    if (w>=s) nout("unsafe");
    else nout("safe");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,a[100005]={0},b[100005],c[100005],pv,ans=0;
  	bool ok=false;
    cin >> n;
    rep(i,0,n){
        cin >> a[i];
    }
    rep(i,0,n){
        if(i==0){
            if(a[i]>1){
                cout << -1 << endl;
                return 0;
            }
            b[0]=1;
        } else {
        	if(ok) b[i]=2*1e17;
            else b[i]=(b[i-1]-a[i-1])*2;
          	if(b[i]>=1e17) ok=true;
            if(a[i]>b[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    b[n+1]=1;
    repr(i,n,0){
        if(i==n){
            c[i]=a[i];
        } else {
            c[i]=c[i+1]+a[i];
        }
    }
    c[n+1]=0;
    rep(i,0,n+1){
        if(b[i]>c[i]){
            pv=i;
            break;
        }
    }
    rep(i,0,n){
        if(i<pv){
            ans+=b[i];
        } else {
            ans+=c[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5952
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=201;
const int MXN=1000001;
const int inf=1e9;
const ll INF=1e18;

int a[N];

int main(){
  boost;
  int n;
  cin>>n;
  for(int i=1;i<=n+n;i++){
    cin>>a[i];
  }
  sort(a+1,a+n+n+1);
  int ans=0;
  for(int i=n+n-1;i>=1;i-=2){
    ans+=a[i];
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// データの取得
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		int res = (H-h) * (W-w);
		
		System.out.println(res);
	}
	
}


Measured memory_bytes: 23764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
	int A = sc.nextInt();
    int B = sc.nextInt();
      int count =1;
      int i=0;
for(i=0;count<B;){
  i++;
  count=count+(A-1);
}
      System.out.println(i);

    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define OKawaiiKoto ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    OKawaiiKoto
    ll n,cnt=0;
    cin>>n;
    rep1(i,n)
    {
        ll a;
        cin>>a;
        if(a%2&&i%2) cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 3608
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s1,s2;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>s1>>s2;
	s2=s2.substr(0,s1.size());
	if(s2==s1)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


Measured memory_bytes: 3612
import numpy as np
S = input()
# S = 'BWBWBW'
S_mask = np.array([True if s=='W' else False for s in S])
# print(S_mask.sum())
W_indices = np.where(S_mask)[0]
# print(idx.sum())
W_num = S_mask.sum()
# print(idx)
print(W_indices.sum() - (W_num-1)*W_num//2)

Measured memory_bytes: 14560
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, vector<long long> d) {
    sort(d.begin(), d.end());
    ll center = d.size() / 2;

    ll ans = 0;
    if (N%2 == 0) {
        ans = d[center] - d[center-1];
    }

    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  cin >> N;
  vector<long long> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  solve(N, move(d));
  return 0;
}


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

using namespace std;

int main()
{
	int X;
	cin >> X;
	int fiveHundredYen = X / 500;
	int ans = fiveHundredYen * 1000;
	int fiveYen = (X - 500 * fiveHundredYen) / 5;
	ans += fiveYen * 5;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
const int N = 2e5 + 5;
vector <int> adj[N];
ll val[N];
bool vis[N];
//int par[N];
vector <int> tr[N];
void bfs(int u)
{
    //par[u] = u;
    queue <int> q;
    vis[u] = 1;
    q.push(u);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(auto it:adj[v])
        {
            if(!vis[it])
            {
                vis[it] = 1;
                //par[it] = v;
                q.push(it);
                tr[v].pb(it);
            }
        }
        
    }
}

void add(int u)
{
    for(auto it:tr[u])
    {
        val[it] += val[u];
        add(it);
    }
    
}

 
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
    int n,q; cin>>n>>q;
    for(int i=0;i<n-1;i++)
    {
        int p,q; cin>>p>>q;
        adj[p].pb(q); adj[q].pb(p);
    }
    bfs(1);
    for(int i=0;i<q;i++)
    {
        int p; ll x; cin>>p>>x;
        val[p] += x;
    }
    add(1);
    for(int i=1;i<=n;i++) cout<<val[i]<<' ';
	
	return 0;
}


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

int main()
{
    int a,b;

    cin>>a>>b;

    if(a<b)
        for(int i=0;i<b;i++)
        cout<<a;
    else
        for(int i=0;i<a;i++)
        cout<<b;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main(){
  int n, a[200];
  cin >> n;
  int count = 0;
  bool flag = true;
  while (flag == true){
	for (int i = 0; i < n; i ++){
    	cin >> a[i];
    	if (a[i] % 2 == 0){
      	a[i] = a[i] / 2;
    	} else {
        flag = false;
        break;
        }  
  	}
    if (flag == true){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
l = []
m = 0
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

for _ in range(a):
    l.append(input())

for x in range(a):
    for y in range(b):
        if l[x][y] == '#':
            continue

        q = []
        cq = [0]
        l2 = [[0] * b for _ in range(a)]
        s, t = x, y
        l2[s][t] = 1

        while True:
            chk = 0

            for z in range(4):
                if s + dx[z] >= 0 and s + dx[z] < a and t + dy[z] >= 0 and t + dy[z] < b and l[s + dx[z]][t + dy[z]] == '.' and l2[s + dx[z]][t + dy[z]] == 0:
                    q.append([s + dx[z], t + dy[z]])
                    l2[s + dx[z]][t + dy[z]] = cq[0] + 1
                    cq.append(cq[0] + 1)
                    chk = 1

            if len(q) == 0:
                break
            
            if chk == 1 and cq[0] + 1 > m:
                m = cq[0] + 1

            s, t = q[0][0], q[0][1]
            q.pop(0)
            cq.pop(0)
            
print(m)

Measured memory_bytes: 3188
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
def adj(n): return [[] for _ in range(n)]

n = iinput()
a = iarr()
tmp = a[0]

for i in range(1,n): tmp = tmp^a[i]
anss = []
for i in range(n): anss.append(tmp^a[i])
print(*anss)


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

int main(){
	int K,X;
	cin >> K >> X;
	
	REP(i,2*K-1){
		cout << X-K+i << " ";
	}
    return 0;
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());

  ll ans = 0;
  ll idx = 0;
  while (m--) {
    ans += v[idx].first;
    if (!(--(v[idx].second))) idx++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
	vector <string> v;
	stringstream ss(s); string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
	cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
	err(++it, args...);
}

int ini() {int x; scanf("%d", &x); return x;}
long long inl() { long long x; scanf("%lld", &x); return x;}
double ind() {double x; scanf("%lf", &x); return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n, int pos) {return n = (n | (1 << pos));}
int reset_0(int n, int pos) {return n = n & ~(1 << pos);}
bool check_bit(int n, int pos) {return n = n & (1 << pos);}

int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;

int cur[15],tem[15];
string s[12];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1, te = 0;
//    cin>>t;
	while (t--) {
		int n, m, k;
		cin >> n >> m >> k;
		for (int i = 0; i < n; ++i)cin >> s[i];
		
		int ans = INT_MAX;
		

		for(int i=0;i< (1<<(n-1)) ;++i){
			int cuts = __builtin_popcount(i);
			bool check=true;
			memset(cur,0,sizeof(cur));

			for(int j=0;j<m and check;++j){
				memset(tem,0,sizeof(tem));
				int box=0;
				for(int l=0;l<n and check;++l){
					tem[box]+=s[l][j]-'0';
					if(check_bit(i,l)){
						++box;
					}
				}

				for(int l=0;l<n;++l){
					if(tem[l]>k){
						check=false;
						break;
					}
				}

				int cut_col=0;
				for(int l=0;l<n;++l){
					if(cur[l]+tem[l] >k){
						cut_col=1;
					}
				}
				cuts+=cut_col;

				if(cut_col){
					for(int l=0;l<n;++l){
						cur[l]=tem[l];
					}
				}
				else{
					for(int l=0;l<n;++l){
						cur[l]+=tem[l];
					}
				}
			}
			if(check)ans=min(ans,cuts);
		}


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

		//printf("Case %d: ",++te);
	}
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=18,mod=1e9+7;
int n,m,a[N],c[1<<N],bit[N];
ll f[1<<N],invf[1<<N];
ll dp[N][1<<N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int main()
{
    bit[0]=f[0]=invf[0]=f[1]=invf[1]=1;
    for(int i=1;i<N;i++) bit[i]=bit[i-1]<<1;
    for(int i=2;i<1<<N;i++)
        f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<1<<N;i++)
        invf[i]=invf[i-1]*invf[i]%mod;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+m,greater<int>());
    int up=1<<n;
    dp[0][0]=1;
    for(int i=0;i<m;i++)
        for(int j=0;j<up;j++)
        {
            (dp[i+1][j]+=dp[i][j])%=mod;
            int tot=up-a[i+1]+1-j;
            for(int k=0;k<n;k++)
                if(tot>=bit[k])
            {
                if(j&bit[k]) continue;
                (dp[i+1][j^bit[k]]+=dp[i][j]*C(tot-1,bit[k]-1)%mod*f[bit[k]]%mod)%=mod;
            }
        }
    ll ans=f[up-1];c[0]=1;
    for(int i=1;i<up;i++)
    {
        c[i]=-c[i-(i&-i)];
        ans=(ans+c[i]*dp[m][i]%mod*f[up-1-i]%mod)%mod;
    }
    ans=ans*up%mod;
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 37376
s=input()
x,y=map(int, input().split())
sl=[len(i) for i in s.split('T')]
a,b={0:1},{0:1}
for i in sl[2::2]:
    if i==0:continue
    a2={}
    for j in a.keys():
        a2[j+i]=1
        a2[j-i]=1
    a=a2
for i in sl[1::2]:
    if i==0:continue
    b2={}
    for j in b.keys():
        b2[j+i]=1
        b2[j-i]=1
    b=b2
if x-sl[0] in a and y in b:print('Yes')
else:print('No')

Measured memory_bytes: 4200
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> hs(n); cin >> hs;
    hs.push_back(0);
    hs.push_back(0);
    vector<int> dp(n + 2, M);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(hs[i] - hs[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(hs[i] - hs[i + 2]));
    }
    cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main{
	static int mod = 1000000007;
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int k = Integer.parseInt(st.nextToken());
      st = new StringTokenizer(br.readLine());
      String s = st.nextToken();
      long[] fact = new long[2000001];
      fact[0] = 1;
      for(int i = 1; i < 2000001; i++)
    	  fact[i] = (fact[i-1]*i)%mod;
      long[] pow25 = new long[1000001];
      long[] pow26 = new long[1000001];
      pow25[0] = 1;
      pow26[0] = 1;
      for(int i = 1; i < 1000001; i++) {
    	  pow25[i] = (pow25[i-1]*25)%mod;
    	  pow26[i] = (pow26[i-1]*26)%mod;
      }
      long ans = pow26[k];
      long prev = 1;
      for(int i = 1; i <= k; i++) {
    	  prev = multiply(prev,multiply(s.length()+i-1,pow(i,mod-2)));
    	  ans = (ans + prev*multiply(pow25[i],pow26[k-i]))%mod;
      }
      out.println(ans);
      out.close();
   }
   static long multiply(long a, long b) {
	   return (a*b)%mod;
   }
   static long pow(long l, int p) {
	   if(p == 0)
		   return 1;
	   if(p == 1 || l == 1)
		   return l;
	   long temp = pow(l, p/2);
	   long temp1 = (temp*temp)%mod;
	   if(p%2 == 1)
		   temp1 = (temp1*l)%mod;
	   return temp1;
   }
}

Measured memory_bytes: 69584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;

int main(){
  int r; cin >> r;
  if(r < 1200){
    printf("%s", "ABC");
    return 0;
  }else if(r < 2800){
    printf("%s", "ARC");
    return 0;
  }else{
    printf("%s", "AGC");
    return 0;
  }
}

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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par;

li root(li a)
{
    while(a!=par[a])
    {
        par[a]=par[par[a]];
        a=par[a];
    }

    return a;
}

void unio(li a,li b)
{
    par[root(a)]=root(b);
}



    
int main()
{    
    

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

    li a,b;

    cin>>a>>b;

    if(500*a>=b)
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n;
  cin>>n;
  cout<<n*n*n<<endl;
  return 0;
}


Measured memory_bytes: 256
import Data.List
f [] = 0
f (i:j:is) | j-i==1 = 1 + f is
f (i:is) = 1 + f is
main = do
  getLine
  as <- map read . words <$> getLine
  print $ f [i | (i,a) <- zip [1..] as, i == a]

Measured memory_bytes: 27516
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());
    ll ans = 0;
    rep(i, N - 1)
    {
        ans += A[(i + 1) / 2];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4836
h, w = map(int ,input().split())
s = [list(input()) for _ in range(h)]
check = [[0] * w for _ in range(h)]
move = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0

for i in range(h):
    for j in range(w):
        if check[i][j] == 1:
            continue
        black, white = 0, 0 

        stack = [[i, j]]
        check[i][j] = 1
        if s[i][j] == '#':
            black += 1
        else:
            white += 1

        while len(stack) > 0:
            x, y = stack.pop()
            tmp = s[x][y]
            for dx, dy in move:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w and tmp != s[nx][ny] and check[nx][ny] == 0:
                    stack.append([nx, ny])
                    check[nx][ny] = 1
                    if s[nx][ny] == '#':
                        black += 1
                    else:
                        white += 1

        ans += black * white

print(ans)

# %%


Measured memory_bytes: 15672
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
static const int MAX=500;
int N,t[MAX+1],s[MAX+1],c[MAX+1],f[MAX+1];
int main(){
    cin>>N;
    for(int i=1;i<N;i++){
        cin>>c[i]>>s[i]>>f[i];
    }

    for(int i=1;i<N;i++){
        t[i]=s[i];
        for(int j=i;j<N-1;j++){   
            t[i]+=c[j];
            while(t[i]%f[j+1]||t[i]<s[j+1])
                t[i]++;
        }
        t[i]+=c[N-1];
    }
    t[N]=0;

    for(int i=1;i<=N;i++){
        cout<<t[i]<<"\n";
    }

    return 0;
}

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

typedef long long ll;
const ll INF = 1LL << 60;

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


int main(void){
    int N;
    cin >> N;
    ll h[N];
    ll dp[N];
    
    for(int i = 0 ; i < N ; i++){
        cin >> h[i];
    }
    for(int i = 0 ; i < N ; i++){
        dp[i] = INF;
    }
    
    dp[0] = 0;
    for(int i = 1 ; i < N ; i++){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 1){
            chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
    }
    
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5168
import java.io.*;
import java.util.Scanner;


public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int H = 0;
        int W = 0;
        String w = "";
        String h = "";
        int judge = 0;
        while(judge == 0){
            H = scan.nextInt();
            W = scan.nextInt();
            //w,hは繰り返し使うので、その都度初期化する
            if(judge == 0){
                w = "";
                h = "";
            }
            if(H == 0 && W == 0){
                judge = 1;
            }else{
                for(int i = 0;i <= W - 1;i++){    
                   w = w + "#";
                   if(i == 0 || i == W - 1){
                       h = h + "#";
                   }else{
                       h = h + ".";
                   }
                }
                //最初の行(I=0)と最後の行(I=H-1)は#連続のwを使う
                for(int I = 0;I <= H - 1;I++){
                   if(I == 0){
                       System.out.println(w);
                   }else if(I > 0 && I < H - 1){
                       System.out.println(h);
                   }else if(I == H - 1){
                       System.out.println(w + "\r\n");
                   }
                }
            }
        }
    }
}


Measured memory_bytes: 27856
#include <bits/stdc++.h>
#define long long long
using namespace std;
const long LINF = 1e18 + 1;

int n, m, dp[3001][3001];
char s[3010], t[3010];
pair<int,int> trace[3001][3001];
int main() {
  cin >> s+1 >> t+1;
  n = strlen(s+1);
  m = strlen(t+1);
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= m; j++) {
      if(s[i] == t[j] && dp[i-1][j-1] + 1 >= dp[i][j]) {
        dp[i][j] = dp[i-1][j-1] + 1;
        trace[i][j] = {i-1, j-1};
      }
      if(dp[i-1][j] >= dp[i][j]) {
        dp[i][j] = dp[i-1][j];
        trace[i][j] = {i-1, j};
      }
      if(dp[i][j-1] >= dp[i][j]) {
        dp[i][j] = max(dp[i][j-1], dp[i][j]);
        trace[i][j] = {i, j-1};
      }
      // cout << i << ' ' << j << ' ' << dp[i][j] << ' ' << trace[i][j].first << ' ' << trace[i][j].second << endl;
    }
  }
  string res;
  int i = n, j = m;
  while(i != 0 && j != 0) {
    auto p = trace[i][j];
    if(p.first == i-1 && p.second == j-1) res += s[i];
    i = p.first;
    j = p.second;
  }
  reverse(res.begin(), res.end());
  cout << res;
}


Measured memory_bytes: 105728
from sys import stdin
input = stdin.buffer.readline

def main():
    n, m = map(int, input().split())
    
    ab = [0] * m
    for ind in range(m):
        i, j = map(int, input().split())
        ab[ind] = (i-1, j-1)
    
    ab.sort()

    ans = 1
    right = ab[0][1]
    for ind in range(1, m):
        # ab[ind] ∩ a[ind-1] = Φ
        if right <= ab[ind][0]:
            ans += 1
            right = ab[ind][1]

        # ab[ind] ⊆ ab[ind-1]
        elif ab[ind][1] < right:
                right = ab[ind][1]
        
        # else:
            # pass
    
    print(ans)

main()

Measured memory_bytes: 22884
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

vector<vector<int>> next_v;
vector<string> word;
void dfs(int u, int d) {
    if(u != 0) {
        string s = string(d-1, '.') + word[u-1];
        cout << s << endl;
    }
    for(int v : next_v[u]) {
        dfs(v, d+1);
    }

}
int main(){
    iostream_init();
    int N;
    while(cin >> N) {
        next_v.resize(N+1);
        REP(i, N) {
            int K;
            cin >> K;
            string s;
            cin >> s;
            word.push_back(s);
            next_v[K].push_back(i+1);
        }
        dfs(0, 0);
    }
    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 1456
s = [i for i in input()]

for j in range(len(s)):
    if (j % 2 == 0) and (s[j] == "L"):
        print("No")
        break
    elif (j % 2 == 1) and (s[j] == "R"):
        print("No")
        break
    elif j == len(s) - 1:
        print("Yes")

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	for(int i=1;i<=y2-y1;i++)
	cout<<"U";
	for(int i=1;i<=x2-x1;i++)
	cout<<"R";
	for(int i=1;i<=y2-y1;i++)
	cout<<"D";
	for(int i=1;i<=x2-x1+1;i++)
	cout<<"L";
	for(int i=1;i<=y2-y1+1;i++)
	cout<<"U";
	for(int i=1;i<=x2-x1+1;i++)
	cout<<"R";
	cout<<"D";
	cout<<"R";
	for(int i=1;i<=y2-y1+1;i++)
	cout<<"D";
	for(int i=1;i<=x2-x1+1;i++)
	cout<<"L";
	cout<<"U"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

cnt = 0
flag = 1
while flag > 0:
    flag = 0
    for j in range(n-1,0,-1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            flag = 1
            cnt += 1
print(' '.join(map(str,a)))
print(cnt)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i =(b)-1;i>=(a);--i)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if(sz(s) & 1){
		cout << "No";
		return 0;
	}
	else{
		rep(i,0,sz(s)){
			if(s[i] != (i&1 ? 'i' : 'h')){
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    long long int i,j,a,b,n,x,y,z,t,k,sum,sum1;
    vector<long long int> v,v1;
    string s,s1;
    unordered_map<long long int,long long int> m,m1;
    unordered_map<long long int,vector<long long int>> m3;
    t=1;
   // cin>>n>>t;
    while(t--)
    {
        cin>>n>>k;
        v.push_back(0);
        for(i=0;i<n;i++)
        {
           cin>>j;
           v.push_back(j);
        }
        while(k--)
        {
            cin>>a>>b;
            m3[a].push_back(b);
            m3[b].push_back(a);
        }
        sum=0;
        for(j=1;j<=n;j++)
        {
            x=0;
          for(i=0;i<m3[j].size();i++)
          {
              k=m3[j][i];
              if(v[k]>=v[j])
              {
                  x=-1;
              }
          }
          if(x==0)
          {
              sum++;
          }
        }
    }
    cout<<sum<<endl;
}











Measured memory_bytes: 13248
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-25 12:55:29
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int n; cin >> n;
  vector<int> a(n); cin >> a;

  int ans = 0;

  // t1 : increase, t2 : decrease
  bool t1 = false, t2 = false;

  int last = a[0];

  for (int e : a) {
    if (e == last) {
      last = e;
    } else if (e > last) {
      last = e;
      if (!t1 && !t2) {
        t1 = true, t2 = false;
      } else if (t1) {
        t1 = true, t2 = false;
      } else {
        ++ans; t1 = false, t2 = false;
      }
    } else {
      last = e;
      if (!t1 && !t2) {
        t1 = false, t2 = true;
      } else if (t1) {
        ++ans; t1 = false, t2 = false;
      } else {
        t1 = false, t2 = true;
      }
    }
  }

  cout << ans + 1 << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  if(s.size() % 2 == 0){
    for(int i=0; i<s.size()/2; i++){
      if(s.at(i) != s.at(s.size()-1-i)) ans++;
    }
    cout << ans << endl;
    //cout << "even" << endl;
    return 0;
  }

  else{
    for(int i=0; i<s.size()/2; i++){
      //cout << i << ": odd" << endl;
      if(s.at(i) != s.at(s.size()-1-i)) ans++;
    }
    cout << ans << endl;
    return 0;
    
  }
    cout << "none" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        Strategy strategy = new MyStrategy();
        strategy.solve(out, sc);
        out.flush();
    }
}

class MyStrategy implements Strategy {
    @Override
    public void solve(PrintWriter out, FastScanner sc) {
        int N = sc.nextInt();
        int K = sc.nextInt();
        PriorityQueue<Integer> p = new PriorityQueue<>();
        for (int i = 0; i < N; i++) {
            p.add(sc.nextInt());
        }
        int sum = 0;
        for (int i = 0; i < K; i++) {
            sum += p.poll();
        }
        out.println(sum);
    }
}

interface Strategy {
    void solve(PrintWriter out, FastScanner sc);
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>X(N);
	for (int n = 0;n<N;++n) {
		cin >> X[n];
	}
	int ans = 1000005;
	for (int n = 1;n<=100; ++n) {
		int tmp = 0;
		for (int m = 0;m<N;++m) {
			tmp += (X[m] - n)*(X[m] - n);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const long long INF = (1LL << 60);
using namespace std;

#define int long long
const int MAX_V = 1000;
class Edge{
	public:
		int to, cost;
		Edge(int to, int cost) : to(to) ,cost(cost) {}
};
vector<bool> used;
vector<int> dis;
typedef vector<vector<Edge>> AdjList;

class SCC{
	public:
		vector<pair<int, int>> g[MAX_V]; //グラフ
		vector<pair<int, int>> rg[MAX_V]; //辺が逆になったグラフ
		vector<int> vs; //帰りがけ順の並び
		bool used[MAX_V];
		int cmp[MAX_V]; //属する強連結成分のトポロジカル順序

		void addEdge(int from, int to, int cost){
			g[from].emplace_back(make_pair(to,cost));
			rg[to].emplace_back(make_pair(from,cost));
		}

		void dfs(int v){
			used[v] = true;
			rep(i,g[v].size()){
				if(not used[g[v][i].first]) dfs(g[v][i].first);
			}
			vs.emplace_back(v);
		}

		void rdfs(int v, int k){
			used[v] = true;
			cmp[v] = k;
			rep(i,rg[v].size()){
				if(not used[rg[v][i].first]) rdfs(rg[v][i].first, k);
			}
		}

		int scc(int v){
			memset(used, 0, sizeof(used));
			vs.clear();
			rep(i,v){
				if(not used[i]) dfs(i);
			}
			memset(used, 0, sizeof(used));
			int k = 0;
			for(int i = vs.size() - 1; i >= 0; i--){
				if(not used[vs[i]]) rdfs(vs[i], k++);
			}
			return k;
		}
};


void dfs(int cur, const vector<pair<int, int>> g[1000]){
	used[cur] = true;
	for(auto to : g[cur]){
		if(used[to.first]) continue;
		dfs(to.first, g);
	}
}

bool bellmanFord(AdjList g, int n, int s) { // nは頂点数、sは開始頂点
	dis = vector<int>(n, INF);
	dis[s] = 0; // 開始点の距離は0
	rep(i,n){
		rep(v,n){
			rep(k,g[v].size()){
				Edge e = g[v][k];
				if (dis[v] != INF && dis[e.to] > dis[v] + e.cost) {
					dis[e.to] = dis[v] + e.cost;
					if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
				}
			}
		}
	}
	return false;
}

bool check(const AdjList g, const vector<int> &order, const int cmp[MAX_V]){
	int j;
	rep(i,g.size()){
		AdjList subg(g.size());
		int cnt = 0;
		for(j = i; j < g.size(); j++){
			if(used[order[j]] && cmp[order[i]] == cmp[order[j]]){
				subg[order[j]] = g[order[j]];
				cnt++;
			}
		}
		if(cnt == 1) continue;
		if(bellmanFord(subg, g.size(), order[i])){
			return true;
		}
		i = j + 1;
	}
	return false;
}

signed main(){
	int n, m;
	scanf("%lld%lld",&n,&m);

	SCC scc;
	AdjList g(n);
	rep(i,m){
		int a, b, c;
		scanf("%lld%lld%lld",&a,&b,&c);
		a--; b--;
		scc.addEdge(b,a,-c);
		g[a].emplace_back(Edge{b,-c});
	}

	used = vector<bool>(n, 0);
	dfs(n - 1, scc.g);
	scc.scc(n);
	if(check(g, scc.vs, scc.cmp)){
		puts("inf");
	}else{
		dis.clear();
		bellmanFord(g,n,0);
		printf("%lld\n", -dis[n - 1]);
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 0;

  vector<vi> S(3,vi(n+1,0));
  char c[] = {'R','G','B'};
  rep(i,3)rep(j,n){
    S[i][j+1] = S[i][j]+(s[j] == c[i]);
  }
  rep(i,n){
      srep(j,i+1,n){
        if(s[i] != s[j]){
          int k;
          if(s[i] != 'R' && s[j] != 'R') k = 0;
          if(s[i] != 'G' && s[j] != 'G') k = 1;
          if(s[i] != 'B' && s[j] != 'B') k = 2;
          int d = j-i;
          ans+= S[k][n]- S[k][j];
          if(j+d<n)ans-=(s[j+d] == c[k]);

        }
      }
  }

  print(ans);
  return 0;
}

Measured memory_bytes: 3704