akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

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

        for (int i = 0; i <= 100; i++) {
            for (int j = 0; j <= 100; j++) {
                int[] dist = new int[300];
                HashMap<Integer, Integer> mm = new HashMap<>();
                boolean ok = true;
                for (int k = 0; k < 300; k++) {
                    dist[k] = -1;
                }
                for (int k = 0; k < n; k++) {
                    int d = Math.abs(i - y[k]) + Math.abs(j - x[k]);
                    if (dist[d] == -1) {
                        dist[d] = h[k];
                    } else {
                        if (dist[d] != h[k]) {
                            ok = false;
                            break;
                        }
                    }

                    if (h[k] != 0 && mm.containsKey(h[k]) && mm.get(h[k]) != d) {
                        ok = false;
                        break;
                    }
                    if (h[k] != 0 && !mm.containsKey(h[k])) {
                        mm.put(h[k], d);
                    }
                }

                long d = (long) Math.abs(i - y[0]) + Math.abs(j - x[0]) + h[0];
                for (int ll = 0; ll < n; ll++) {
                    if (h[ll] == 0)
                        continue;
                    d = (long) Math.abs(i - y[ll]) + Math.abs(j - x[ll]) + h[ll];
                    if (d <= 0) {
                        ok = false;
                        continue;
                    }
                    for (int k = 0; k < n; k++) {
                        long hh = (long) Math.max(d - Math.abs(y[k] - i) - Math.abs(x[k] - j), 0);
                        if (hh != h[k]) {
                            ok = false;
                            break;
                        }
                    }

                }
                if (ok) {
                    System.out.println(j + " " + i + " " + d);
                }

            }
        }
    }

}


Measured memory_bytes: 41676
#include <iostream>

using namespace std;
int grundy(long long x, long long k){
	if(x<k){
		return 0;
	}else if(x%k==0){
		return x/k;
	}else if(x>k*k){
		return grundy(x-x/k-1,k);
	}else{
		int m = x/k;//99/35 = 2
		int n = x - m*k;// 99 - 2*35 = 29
		long long y = n%(m+1); //29%3 = 2
		if(x!=m*k+y){//99!=72
			return grundy(x/k*k+y,k);
		}else{//72=72
			return grundy(x-x/k-1,k);
		}
	}
}

int main(){
	long long a[210],k[210],i,n,ans=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i] >> k[i];
		ans ^= grundy(a[i],k[i]);
		//cout << grundy(a[i],k[i]) << endl;
	}
	
	if(ans!=0){
		cout << "Takahashi" << endl;
	}else{
		cout << "Aoki" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int mod = 2019;
int main() {
	int l, r;
	cin >> l >> r;

	long long ans = mod;
	if (r - l >= mod) {
		ans = 0;
	} else {
		for (long long i = l; i <= r; i++) {
			for (long long j = i + 1; j <= r; j++) {
				ans = min(ans, i * j % mod);
			}
		}
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int r, c, s; cin>>r>>c>>s;
	int hepsi = 1<<(r-1);
	int best = 1e9;
	char vec[r][c];
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin>>vec[i][j];
			vec[i][j] -= '0';
		}
	}
	for(int x = 0; x < hepsi; x++){
		int tmp_ans = 0;
		vector<int> tmp(r, 0);
		int u = 0;
		for(int i = 0; i < r; i++){
			if(x>>i & 1) tmp_ans++;
		}
		bool clear_check = 0;
		for(int j = 0; j < c; j++){
			u = 0;
			vector<int> tmp_tmp(r, 0);
			for(int i = 0; i < r; i++){
				if(vec[i][j] == 1){
					tmp_tmp[u]++;
				}
				if(tmp[u] + tmp_tmp[u] > s && !clear_check){
					tmp_ans++;
					clear_check = 1;
				}
				if(x>>i & 1){
					u++;
				}
			}
			if(clear_check){
				for(int i = 0; i < r; i++) tmp[i] = 0;
			}
			clear_check = 0;
			for(int i = 0; i < r; i++) tmp[i] += tmp_tmp[i];
		}
		bool check = 1;
		for(auto sayi: tmp){
			if(sayi > s){
				check = 0;
				break;
			}
		}
		if(check)best = min(best, tmp_ans);
	}
	cout<<best<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
typedef long long ll;
typedef pair<ll, ll> P;
map<long long, long long> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
bool bitcheck(int x, int y) { return (x >> y) & 1; }
signed main() {
    ll d, g;
    cin >> d >> g;
    vector<ll> p(d);
    vector<ll> c(d);
    REP(i, d) {
        cin >> p[i];
        cin >> c[i];
    }
    ll mnproblems = 1000000;
    REP(i, 1 << d) {
        ll sum = 0;
        ll problems = 0;
        REP(j, d) {
            if (bitcheck(i, j)) {
                sum += p[j] * (j + 1) * 100 + c[j];
                problems += p[j];
            }
        }
        if (sum >= g) {
            mnproblems = min(mnproblems, problems);
        }
        for (int j = d - 1; j >= 0; j--) {
            if (!bitcheck(i, j)) {
                if (sum < g) {
                    problems += (((g - sum + (j + 1) * 100) - 1) / ((j + 1) * 100));
                }
                sum += (p[j] - 1) * (j + 1) * 100;
                if (sum >= g) {
                    mnproblems = min(mnproblems, problems);
                }
            }
        }
    }
    cout << mnproblems << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int used[(int)2e5 + 100];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1;i <= n - 1;i++){
		int a;
		cin >> a;
		used[a]++;
	}
	for(int i = 1;i <= n;i++)cout << used[i] << endl;
	return 0;
}
 

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  string S;
  cin >> N >> S;
  vec< int > l(N + 1, 0);
  vec< int > r(N + 1, 0);
  REP(i, N) { l[i + 1] = l[i] + (S[i] == 'W'); }
  REP(i, N) { r[i + 1] = r[i] + (S[N - 1 - i] == 'E'); }
  int ans = INF;
  REP(i, N) {
    int curAns = l[i] + r[N - 1 - i];
    chmin(ans, curAns);
  }
  print(ans);
}

Measured memory_bytes: 5396
S = gets.chomp

ln = S.length

sum = 0
start = 0
result = 0
(0..(1 << (ln - 1)) - 1).each do |bit|
  (0..(ln - 1)).each do |i|
    next unless (bit >> i) & 1 == 1

    num = S[start..i].to_i
    sum += num
    start = i + 1
  end

  last_num = S[start..ln].to_i

  result += sum + last_num
  sum = 0
  start = 0
end

puts result

Measured memory_bytes: 14288
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] X = new int[N][D];
        
        int count = 0;

        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double distance = 0;
                int diff = 0;
                for(int k = 0; k<D; k++){
                    diff = X[i][k]-X[j][k];
                    distance += diff*diff;
                }
                if(Math.sqrt(distance) % 1==0){
                    count += 1;
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,i,j,p=0,k=0;
cin>>n;
long long a[n-1];
for(i=0;i<n-1;i++){
    cin>>a[i];
}sort(a,a+n-1);
for(i=1;i<=n;i++){p=0;
for(j=k;j<n-1;j++){
    if(i==a[j]){
        p++;
    }else{
        k=j;break;
    }
}cout<<p<<endl;;
    
}
    return 0;
  
}


Measured memory_bytes: 5172
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();
            Console.WriteLine(s.Distinct().Count() == 3?"Yes":"No");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

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

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

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

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

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


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

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include <unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int, int> P;
//struct edge {int to,cost;};
#define VMAX 200+10
string S;

int adp[4000][8000];
int bdp[4000][8000];
int F[4000], T[4000];
int f, t, X, Y;
bool A, B;
int mode = 0; int cnt = 0;
bool ADP(int a, int b) {
	if (adp[a][b] != -1)return adp[a][b];
	if (a == f ) {
		return adp[a][b] = b == X;
	}
	return adp[a][b] = ADP(a + 1, b + F[a]) || ADP(a + 1, b - F[a]);
}
bool BDP(int a, int b) {
	if (bdp[a][b] != -1)return bdp[a][b];
	if (a == t ) {
		return bdp[a][b] = b == Y;
	}
	return bdp[a][b] = BDP(a + 1, b + T[a]) || BDP(a + 1, b - T[a]);
}
int main() {
	std::ios_base::sync_with_stdio(false);
	cin >> S >> X >> Y;
	
	REP(i, S.size()) {
		if (S[i] == 'T') {
			if (mode == 0) { F[f] = cnt, f++, cnt = 0, mode = 1; }
			else { T[t] = cnt, t++, cnt = 0, mode = 0; }
		}
		else {
			cnt++;
		}
	}
	if (mode == 0) { F[f] = cnt, f++, cnt = 0, mode = 1; }
	else { T[t] = cnt, t++, cnt = 0, mode = 0; }
	REP(i, 4000)REP(j, 8000)adp[i][j] = bdp[i][j] = -1;
	
	cout << (ADP(1, F[0]) && BDP(0,0) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 250496
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
VEC<bool> build(string s, VEC<bool> isSheep) {
  int n = s.length();
  for (int i = 1; i < n + 1; i++) {
    if (s[i % n] == 'o') {
      if (isSheep[i % n]) {
        isSheep[(i + 1) % n] = isSheep[(i - 1) % n];
      } else {
        isSheep[(i + 1) % n] = !isSheep[(i - 1) % n];
      }
    } else {
      if (isSheep[i % n]) {
        isSheep[(i + 1) % n] = !isSheep[(i - 1) % n];
      } else {
        isSheep[(i + 1) % n] = isSheep[(i - 1) % n];
      }
    }
  }
  return isSheep;
}
bool isValid(string s, VEC<bool> isSheep) {
  int n = s.length();
  REPC(pos, 1, n) {
    if (s[pos%n] == 'o') {
      if (isSheep[pos % n]) {
        if (isSheep[(pos - 1) % n] != isSheep[(pos + 1) % n])
          return 0;
      } else {
        if (isSheep[(pos - 1) % n] == isSheep[(pos + 1) % n])
          return 0;
      }
    } else {
      if (isSheep[pos % n]) {
        if (isSheep[(pos - 1) % n] == isSheep[(pos + 1) % n])
          return 0;
      } else {
        if (isSheep[(pos - 1) % n] != isSheep[(pos + 1) % n])
          return 0;
      }
    }
  }
  return 1;
}
void disp(VEC<bool> s) {
  int n = s.size();
  REP(i, 0, n) { cout << (s[i] ? "S" : "W"); }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  VEC<bool> isSheep(n, 0);
  VEC<bool> ans(n);
  isSheep[0] = 1;
  isSheep[1] = 1;
  ans = build(s, isSheep);
  DUMP(ans);
  if (isValid(s, ans)){
    disp(ans);
    return 0;
  }
  isSheep[0] = 1;
  isSheep[1] = 0;
  ans = build(s, isSheep);
  DUMP(ans);
  if (isValid(s, ans)) {
    disp(ans);
    return 0;
  }
  isSheep[0] = 0;
  isSheep[1] = 1;
  ans = build(s, isSheep);
  DUMP(ans);
  if (isValid(s, ans)){
    disp(ans);
    return 0;
  }
  isSheep[0] = 0;
  isSheep[1] = 0;
  ans = build(s, isSheep);
  DUMP(ans);
  if (isValid(s, ans)){
    disp(ans);
    return 0;
  }
  cout << -1 << endl;

  return 0;
}


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

int main(void){
    int D;cin>>D;
    int c[27];
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    int s[366][27];
    for(int i=1;i<=D;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
    int t[366];
    int last[27]={};
    int v=0;
    for(int i=1;i<=D;i++){
        cin>>t[i];
        last[t[i]]=i;
        v+=s[i][t[i]];
        for(int j=1;j<=26;j++){
            v-=c[j]*(i-last[j]);
        }
    cout<<v<<endl;
    }
    return 0;
}


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

using namespace std;
#define int int64_t
#define fi first
#define se second
#define endl '\n'

int dx[2] = {0, 1};
int dy[2] = {1, 0};
int h, w;
vector<string> a;
vector<vector<int>> used;
void dfs(int x, int y) {
     used[x][y] = true;
     for (int dir = 0;dir < 2; ++dir) {
          int nx = x + dx[dir];
          int ny = y + dy[dir];
          if (nx < h && ny < w && !used[nx][ny] && a[nx][ny] == '#') {
               dfs(nx, ny);
          }
     }
}



signed main()
{
     srand(time(nullptr));
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     cin >> h >> w;
     a.resize(h);
     used.resize(h, vector<int>(w));
     int cnt = 0;
     for (int i = 0; i < h; ++i) {
          cin >> a[i];
          cnt += count(a[i].begin(), a[i].end(), '#');
     }
     dfs(0, 0);
     for (int i = 0; i < h; ++i) {
          for (int j = 0; j < w; ++j) {
               if (a[i][j] == '#' && !used[i][j]) {
                    cout << "Impossible";
                    return 0;
               }
          }
     }
     if (!used[h-1][w-1] || cnt != h + w - 1) {
          cout << "Impossible";
     } else {
          cout << "Possible";
     }
     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a;
	int b;
	int x;
	
	cin >> a >> b >> x;
	
	if (x > a + b || x < a) {
		cout << "NO\n";
	}
	else {
		cout << "YES\n";
	}
	return 0;
}

Measured memory_bytes: 256
import sys
f=sys.stdin

n,_,_=map(int,f.readline().split())
a=list(map(int,f.readline().split()))
q=list(map(int,f.readline().split()))
s=list(range(n))

pos=0
for ai in a:
    if ai%2:
        pos+=-ai
    else:
        pos+=ai
    pos%=len(s)
    s.pop(pos)
for qi in q:
    print 1 if qi in s else 0

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


int main() {
  int n;
  int data[10];
  cin >> n;
  while ( n > 0 ) {
    n--;
    int flag = 1;
    for ( int i = 0; i < 10; i++ ) cin >> data[i];
    int b = 0,c = 0;
    for ( int i = 0; i < 10; i++ ) {
      if ( b < data[i] ) b = data[i];
      else if ( c < data[i] ) c = data[i];
      else flag = 0;
    }
    if ( flag ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    vector<string> S(3);
    for (int i = 0; i < 3; ++i) {
        cin >> S[i];
    }

    int M = 2100;
    int off = M * 4;
    int N = M * 10;
    vector<vector<vector<bool>>> match(3, vector<vector<bool>>(3, vector<bool>(N, true)));

    for (int i = 0; i < 3; ++i) {
        for (int j = i + 1; j < 3; ++j) {
            auto& s = S[i];
            auto& t = S[j];
            for (int a = 0; a < s.length(); ++a) {
                for (int b = 0; b < t.length(); ++b) {
                    if (s[a] != t[b] && s[a] != '?' && t[b] != '?') {
                        match[i][j][a - b + off] = false;
                    }
                }
            }
        }
    }

    int res = M * 3;

    for (int i = -2 * M; i <=  2 * M; ++i) {
        for (int j = - 2 * M; j <= 2 * M; ++j) {
            if (match[0][1][i + off] && match[0][2][j + off] && match[1][2][j - i + off]) {
                int l = min(0, min(i, j));
                int r = max((int)S[0].length(), max((int) S[1].length() + i, (int) S[2].length() + j));
                int ans = r - l;
                res = min(res, ans);
            }
        }
    }
    cout << res << '\n';

    return 0;
}

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

using namespace std;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

long long a[100002];

vector<long long> diff;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int n;
    cin >> n;

    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = 0; i < n; ++i){
        long long j;
        cin >> j;
        diff.push_back(a[i] - j);
    }

    sort(diff.begin(), diff.end());

    long long extras = 0;
    int left = 0, right = n - 1, changed = 0;

    while(left < n && diff[left] < 0){

        while(right >= 0 && diff[right] > 0 && extras < -diff[left]){
            extras += diff[right--];
            ++changed;
        }

        if(extras < -diff[left]){
            cout << -1;
            return 0;
        }

        extras += diff[left++];
        ++changed;

    }

    cout << changed;

    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; O << '\n'; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;




void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a;
        vector<int> b(n); cin >> b;
        vector<int> vec;
        for (int i = 1; i <= n; i++) vec.emplace_back(i);

        int x, y;
        int i = 0;
        do {
                i++;
                if (vec == a) x  = i;
                if (vec == b) y = i;
        } while (next_permutation(all(vec)));

        cout << abs(x - y);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

            // DP(動的計画法)で解く
            int[] dp = new int[n + 1];

            // n <= 100,000
            for (int i = 0; i <= n; i++) {
                dp[i] = i;
                // 6の倍数
                for (int j = 6;; j *= 6) {
                    if (i - j >= 0) {
                        if (dp[i] > dp[i - j] + 1) {
                            dp[i] = dp[i - j] + 1;
                        }
                    } else {
                        break;
                    }
                }
                // 9の倍数
                for (int j = 9;; j *= 9) {
                    if (i - j >= 0) {
                        if (dp[i] > dp[i - j] + 1) {
                            dp[i] = dp[i - j] + 1;
                        }
                    } else {
                        break;
                    }
                }
            }

            System.out.println(dp[n]);
        }
    }

}


Measured memory_bytes: 23252
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt() * 2;
		long length[] = new long[num];
		for(int i = 0; i < num; i ++) {
			length[i] = sc.nextLong();
		}
		Arrays.sort(length);
		long ans = 0;
		for(int i = 0; i < num; i += 2) {
			ans += length[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{   
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        long n = long.Parse(inputs[0]);
        long m = long.Parse(inputs[1]);
        long result = Math.Min(n , m / 2);
        result += (m - result * 2) / 4;
        System.Console.WriteLine(result);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int main(void){
	int s,b,copy;
	int i,j;
	int a[200];
	scanf("%d%d",&s,&b);
	for(i=0;i<s;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=b;i++){
		for(j=0;j<s-1;j++){
			if(a[j]%i>a[j+1]%i){
				copy=a[j];
				a[j]=a[j+1];
				a[j+1]=copy;
			}
		}
	}
	for(i=0;i<s;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}


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

int n, k;
vector<int> a;
int ans = 0;
vector<int> G[100010];

int dfs(int now, int pre){
    int h = 0;
    rep(i, 0, G[now].size()){
        int next = G[now][i];
        chmax(h, dfs(next, now) + 1);
    }
    if(h == k - 1 && now != 0 && pre != 0){
        ans++; h = -1;
    }
    return h;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    a.resize(n);
    rep(i, 0, n){
        cin >> a[i]; a[i]--;
        if(i != 0) G[a[i]].push_back(i);
    }    
    if(a[0] != 0){a[0] = 0; ans++;}
    dfs(0, -1);
    cout << ans << endl;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<int> solve(int n, const std::vector<int> &c, const std::vector<std::vector<int> > &val) {
	auto score = [&] (const std::vector<int> &all) {
		int last[26];
		for (auto &i : last) i = -1;
		int res = 0;
		for (int i = 0; i < n; i++) {
			int cur = all[i];
			last[cur] = i;
			for (int j = 0; j < 26; j++) res -= c[j] * (i - last[j]);
			res += val[i][cur];
		}
		return res;
	};
	
	std::vector<int> cur(n);
	for (int i = 0; i < n; i++) cur[i] = i % 26;
	int cur_score = score(cur);
	int best_score = -1000000000;
	std::vector<int> best;
	
	std::random_device rnd_dev;
	std::mt19937 rnd(rnd_dev() ^ time(NULL));
	
	clock_t start = clock();
	while (1) {
		clock_t cur_time = clock();
		if (cur_time - start > 1.95 * CLOCKS_PER_SEC) break;
		int r0 = std::uniform_int_distribution<>(0, n - 1)(rnd);
		int r1 = std::uniform_int_distribution<>(0, n - 1)(rnd);
		std::swap(cur[r0], cur[r1]);
		double threshold = 1.95 - (double) (cur_time - start) / CLOCKS_PER_SEC;
		// std::cerr << threshold << std::endl;
		int new_score = score(cur);
		if (new_score > best_score * (1 - threshold * 0.01)) cur_score = new_score;
		else std::swap(cur[r0], cur[r1]);
		if (best_score < cur_score) best_score = cur_score, best = cur;
	}
	
	return best;
}

void input() {
	int n = ri();
	std::vector<int> c(26);
	for (auto &i : c) i = ri();
	std::vector<std::vector<int> > val(n, std::vector<int>(26));
	for (auto &i : val) for (auto &j : i) j = ri();
	for (auto i : solve(n, c, val)) printf("%d\n", i + 1);
}

void random_test() {
	std::random_device rnd_dev;
	std::mt19937 rnd(rnd_dev() ^ time(NULL));
	
	int n = 365;
	std::vector<int> c(26);
	for (auto &i : c) i = std::uniform_int_distribution<>(0, 100)(rnd);
	std::vector<std::vector<int> > val(n, std::vector<int>(26));
	for (auto &i : val) for (auto &j : i) j = std::uniform_int_distribution<>(0, 20000)(rnd);
	
	auto res = solve(n, c, val);
	
	
	int last[26];
	for (auto &i : last) i = -1;
	int score = 0;
	for (int i = 0; i < n; i++) {
		last[res[i]] = i;
		for (int j = 0; j < 26; j++) score -= c[j] * (i - last[j]);
		score += val[i][res[i]];
	}
	printf("%d\n", score);
}

int main() {
#	ifdef LOCAL
	random_test();
#	else
	input();
#	endif
	return 0;
}



Measured memory_bytes: 3908
H,W = map(int,input().split())
ans = 0
wx = W // 2
hx = H // 2
wy = W % 2
hy = H % 2

if H == 1 or W == 1:
  print(1)
  exit()

if wy == 0 and hy == 0:
  ans = (W * H) / 2
elif wy == 1 and hy == 0:
  ans = (((W-1)*H)/2) + (H / 2)
elif wy == 0 and hy == 1:
  ans = ((W*(H-1))/2) + (W / 2)
else:
  ans = (((W-1)*(H-1))/2) + ((W-1) / 2) + ((H-1) / 2) + 1
print(int(ans))

Measured memory_bytes: 3064
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
char chr;
int H,W;
int main() {
	cin>>H>>W;
	int B[101][101]={};
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>chr;
			if(chr=='c')B[i][j]=0;
			if(chr=='.')B[i][j]=-1;
		}
	}
	for(int i=0;i<H;i++){
		for(int j=1;j<W;j++){
			if(B[i][j-1]==0){
				if(B[i][j]>0){
					B[i][j]+=1;
				}else{
					if(B[i][j]<0){
						B[i][j]=1;
					}
				}
			}
			if(B[i][j-1]>0){
				if(B[i][j]!=0){
					B[i][j]=B[i][j-1]+1;
				}
			}
		}

	}

	for(int i=0;i<H;i++){
		cout<<B[i][0];
		for(int j=1;j<W;j++){
			cout<<" "<<B[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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


void solve(string S){
    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
}

int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import copy
n = int(input())
p = list(map(int,input().split()))
r = list()
for k in range(n):
    r.append(k+1)
if p == r:
    print("YES")
    exit()
for i in range(0,n-1):
    for j in range(i+1,n):
        q = copy.copy(p)
        q[j] = p[i]
        q[i] = p[j]
        if q == r:
            print("YES")
            exit()

print("NO")

Measured memory_bytes: 3444
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	int n;
	string s;
	cin >> n;
	cin >> s;
	int x=0;
	int m=x;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='I')
			x++;
		else
			x--;
		m=max(m,x);
	}
	cout << m;
}

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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
typedef vector<int> vi;
typedef vector<string> vs;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

inline bool in(int x, int y,int w,int h){
    return 0<=x&&0<=y && y<h && x<w;
}

int solve(vs & g){
    int h=g.size();int w=g[0].size();
    int sx,sy;
    rep(i,h)rep(j,w)if(g[i][j]=='@'){
        sx=j;sy=i;
    }


    while(1){
        bool fine=true;
        
        rep(y,h)rep(x,w){
            if(g[y][x]=='@'){
                rep(d,4){
                    int nx=x+dx[d];
                    int ny=y+dy[d];
                    if(!in(nx,ny,w,h)) continue;
                    if(g[ny][nx]!='.') continue;
                    g[ny][nx]='@';
                    fine=false;
                }
            }
        }
        
        if(fine)break;
    }

    // rep(i,h)cout<<g[i]<<endl;

    int c=0;
    rep(i,h)rep(j,w)c+=g[i][j]=='@';
    return c;
}


int main(){
    int w,h;
    while(cin>>w>>h && w){
        vs g(h);
        rep(i,h)cin>>g[i];
        cout<<solve(g)<<endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main(){

  int X,Y,Z;
  cin >> X >> Y >> Z;

  long long int ans = 0;
  for(int i = 1;;i++){
    if(X - (Y * i + Z * (i+1)) >= 0)ans = i;
    else break;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline())
h = list(map(int, sys.stdin.readline().split()))

dp = [10 ** 9] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, n):

    h1 = dp[i - 1] + abs(h[i] - h[i - 1])
    dp[i] = h1 if h1 < dp[i] else dp[i]

    h2 = dp[i - 2] + abs(h[i] - h[i - 2])
    dp[i] = h2 if h2 < dp[i] else dp[i]

print(dp[-1])

Measured memory_bytes: 50324
#include "bits/stdc++.h"
using namespace std;
int main() {
    int A,B,C,D,Sl,Sm;
    cin >> A >> B >> C >> D;
    Sl = A * B;
    Sm = C * D;
    if(Sl>Sm){
        cout << Sl << endl;
    }
    else if(Sm>Sl){
        cout << Sm << endl;
    }
    else{
        cout << Sl << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 1000000000
#define MIN -1000000000

int main()
{
  int n,x,y=0,min=MAX,max=MIN,i;

  scanf("%d",&n);
  
  scanf("%d",&x);
  if(min>x)min=x;
  
  for(i=1;i<n;i++)
    {
      scanf("%d",&x);

      if(max<(x-min))max=x-min;
      if(min>x)min=x;

    }

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

  return 0;
}



Measured memory_bytes: 2104
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

def cmb(n, r, mod):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n-r)
	return fact[n]*factinv[r]*factinv[n-r]%mod

mod = 10**9+7
N = 10**5+100  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N+1):
	fact.append((fact[-1]*i)%mod)
	inv.append((-inv[mod%i]*(mod//i))%mod)
	factinv.append((factinv[-1]*inv[-1])%mod)

maxans = 0
for i in range(k, n+1):
	maxans = maxans + (a[i-1] * (cmb(i, k, mod)-cmb(i-1, k, mod))) % mod

minans = 0
for i in range(k, n+1):
	minans = minans + (a[n-i] * (cmb(i, k, mod)-cmb(i-1, k, mod))) % mod
print((maxans-minans)%mod)

Measured memory_bytes: 20184
#include <stdio.h>

int main(void)
{
	int a, b, sum, cont;
	int i;
	
	while(scanf("%d %d", &a, &b) != EOF){
		
		sum = a + b;
		
		for(i = 10, cont = 1; ; i *= 10, cont++){
			if(sum % i == sum)
				break;
		}
		
		printf("%d\n", cont);
	}
	
	return 0;
}

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

int ans;

void SofI(int num, int n) {
	if (num > n * 9) { return; }
	else if (num < 0) { return; }
	else if (num != 0 && n == 0) { return; }
	else if (num == 0) {
		ans++;
		return;
	}
	else {
		for (int i = 0; i < 10; i++) {
			SofI(num - i, n - 1);
		}
	}

}

int main(void) {
		int num;
		while (cin >> num) {
			if (num == 0) break;
			ans = 0;
			SofI(num, 4);
			cout << ans << endl;
		}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int64_t lucas(int N) {
  vector<int64_t> L = {2, 1};

  for (int i = 2; i < N + 1; i++) {
    L.push_back( L.at(i-1) + L.at(i-2) );
  }
  return L.at(N);
/*
  // Recursive function results in TLE.
  if (N < 0) {
    return 0;
  }
  else if (N == 0) {
    return 2;
  }
  else if (N == 1) {
    return 1;
  }
  return lucas(N-1) + lucas(N-2);
*/
}

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

  cout << lucas(N) << "\n";
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;

int main(){
    int N,Y;
    scanf("%d %d",&N,&Y);
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            int y = 10000 * i + 5000 * j + 1000 * (N-i-j);
            if(y == Y && (i+j)<=N) {
                printf("%d %d %d\n",i,j,N-i-j);
                return 0;
            }
        }
    }
    printf("%d %d %d\n",-1,-1,-1);
    return 0;
}

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

using namespace std;

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


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll s = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    	s += a[i];
    }
    if (n == 1) {
        cout << "YES" <<  endl;
        return 0;
    }
    ll once = n * (n + 1) / 2;
    if (s % once) {
        cout << "NO" << endl;
        return 0;
    }
    ll totB = 0;
    ll k = s / once;
    for (int i = 0; i < n; i++) {
        ll A = a[(i + 1) % n] - a[i] - k;   
        A = -A;
        if (A % n || A < 0) {
            cout << "NO" << endl;
            return 0;   
        }
        totB += A / n;    
    }
    cout << (totB == k ? "YES" : "NO") << endl;
}   


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

int main() {
    ll n, d, ans = 0; cin >> n >> d;
    vector<ll> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    for (int i = 0; i < n; i++)
    {
        ll a = x[i] * x[i] + y[i] * y[i];
        if (d * d >= a) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6436
def main(H,W,A,B):
    ans = [[] for _ in range(H)]
    #print(ans)
    cntB = 0
    for i in range(H):
        cntB += 1
        cntA = 1
        for j in range(W):
            if cntB <= B:
                if cntA <= A:
                    ans[i].append(0)
                    cntA += 1
                else:
                    ans[i].append(1)
            else:
                if cntA <= A:
                    ans[i].append(1)
                    cntA += 1
                else:
                    ans[i].append(0)
    return ans

H,W,A,B = map(int,input().split())
ans = main(H,W,A,B)
for i in range(H):
    tmp = ans[i]
    tmp = map(str,tmp)
    print(''.join(tmp))


Measured memory_bytes: 17980
#include<iostream>

using namespace std;

int N, D;
const int N_MAX = 10, D_MAX = 10;
int X[N_MAX][D_MAX];

int main() {
	cin >> N >> D;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X[i][j];
		}
	}
	int ans = 0;
	for (int i0 = 0; i0 < N; i0++) {
		for (int i1 = i0+1; i1 < N; i1++) {
			int dist_2 = 0;
			for (int j = 0; j < D; j++) {
				dist_2 += (X[i0][j] - X[i1][j]) * (X[i0][j] - X[i1][j]);
			}
			for (int n = 0; n < 1000; n++) {
				if (dist_2 == n * n) {
//					cout << dist_2 << endl;
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n,k,q = gets.split.map(&:to_i)
a = []



q.times do
  a << gets.to_i
end

point = []
n.times do
 point << k
end


a.each do |var|
  point[var-1] += 1
end


point.each do |i|
  if i > q
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 4148
K, N = map(int, input().split())
A = list(map(int, input().split()))

A_aida = []
for i in range(N-1):
    A_aida.append(A[i+1]-A[i])

A_aida.append((K-A[-1]) + A[0])

print(K - max(A_aida))


Measured memory_bytes: 25840
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>

int main(){
    int H, W;
    int int_max = 10000;
    std::vector<std::string> A;
    std::vector<std::vector<std::vector<int>>> dp;

    std::cin >> H >> W;

    A = std::vector<std::string>(H, " ");
    dp = std::vector<std::vector<std::vector<int>>>(5, std::vector<std::vector<int>>(H, std::vector<int>(W, int_max)));

    
    for(int h=0;h<H;h++){
        std::cin >> A[h];
    }

    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            dp[0][h][w] = std::min(h!=0?dp[0][h-1][w]:int_max, w!=0?dp[0][h][w-1]:int_max)+1;
            dp[1][h][W-1-w] = std::min(h!=0?dp[1][h-1][W-1-w]:int_max, w!=0?dp[1][h][W-w]:int_max)+1;
            dp[2][H-1-h][w] = std::min(h!=0?dp[2][H-h][w]:int_max, w!=0?dp[2][H-1-h][w-1]:int_max)+1;
            dp[3][H-1-h][W-1-w] = std::min(h!=0?dp[3][H-h][W-1-w]:int_max, w!=0?dp[3][H-1-h][W-w]:int_max)+1;
            if(A[h][w] == '#') dp[0][h][w] = 0;
            if(A[h][W-1-w] == '#') dp[1][h][W-1-w] = 0;
            if(A[H-1-h][w] == '#') dp[2][H-1-h][w] = 0;
            if(A[H-1-h][W-1-w] == '#') dp[3][H-1-h][W-1-w] = 0;
        }
    }

    int res = 0;
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            dp[4][h][w] = std::min({
                dp[0][h][w],
                dp[1][h][w],
                dp[2][h][w],
                dp[3][h][w]
            });

            if(dp[4][h][w] < int_max && res < dp[4][h][w]) res = dp[4][h][w];
        }
    }

    std::cout << res << std::endl;

    return 0;
}

Measured memory_bytes: 23936
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import static java.lang.Character.toLowerCase;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] cnt = new int[26];
		String line;
		while ((line = br.readLine()) != null) {
			char[] chars = line.toCharArray();
			for (char c : chars) {
				if (!isLowerCase(c) && !isUpperCase(c))
					continue;

				cnt[toLowerCase(c) - 'a']++;
			}
		}

		for (int i = 0; i < cnt.length; i++) {
			System.out.print((char) ('a' + i));
			System.out.println(" : " + cnt[i]);
		}
	}
}

Measured memory_bytes: 16888
from collections import Counter
def dd(S):
    S += "#"
    s0 = S[0]
    cnt, r = 1, 0
    for s in S[1:]:
        if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
        s0 = s
    return r
S = input().rstrip()
K = int(input())
s = dd(S)
t = dd(S*2)
if len(Counter(S))==1:
    print(len(S)*K//2)
else:
    print(s*K + (t-2*s)*(K-1))
"""
aaa
3
"""

Measured memory_bytes: 65088
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <climits>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

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

	double r = sqrt(n);
	cout << (int)r * (int)r <<endl;
}



Measured memory_bytes: 256
from itertools import product
N=int(input())

F=[]
P=[]

for n in range(N):
    F.append(list(map(int,input().split())))
    
for n in range(N):
    P.append(list(map(int,input().split())))

ans=-10**10
for p in product(range(2),repeat=10):
    if len(set(p))==1 and p[0]==0:
        continue
    p_ = 0
    for idx,f in enumerate(F):
        c=0
        for i in range(10):
            c += f[i]*p[i]
        p_ += P[idx][c]
        
    if ans < p_:
        ans=p_
        
print(ans)


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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> points(n, vector<int>(3));
    for(int i = 0; i < n; ++i){
        cin >> points[i][0] >> points[i][1] >> points[i][2];
    }
    vector<vector<int>> dp(n, vector<int>(3));
    dp[0][0] = points[0][0];
    dp[0][1] = points[0][1];
    dp[0][2] = points[0][2]; 
    for(int i = 1; i < n; ++i){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + points[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + points[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + points[i][2];
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
    return 0;
}

Measured memory_bytes: 11136
import java.util.*;
import java.math.BigInteger;
// warm-up
// created more space
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), A=sc.nextInt(), B=sc.nextInt(), t=n, i=0;
		BigInteger s = BigInteger.ZERO;
		long[] T = new long[n];
		long[] b = new long[n-1];
		long[] c = new long[n-1];
		while (t-->0) T[i++] = sc.nextLong();
		b[0] = c[0] = (T[1]-T[0])*A;
		for (i=1; i<n-1; i++) {
			b[i] = (T[i+1]-T[i])*A;
			c[i] = b[i]+c[i-1];
		}
		for (i=0; i<n-1; i++) {
			s = s.add(new BigInteger(""+Math.min(B,b[i])));
			s = new BigInteger(""+Math.min(c[i],s.longValue()));
		}
		System.out.println(s);
		sc.close();			
	}

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

}

Measured memory_bytes: 63964