akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
    vector<vector<int>> A(3, vector<int>(3));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);
    for (int i = 0; i < N; i++)
    {
        cin >> b[i];
    }

    //横
    int cntR, cntC, cntD1 = 0, cntD2 = 0;
    for (int i = 0; i < 3; i++)
    {
        cntR = 0;
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < N; k++)
            {
                if (A[i][j] == b[k])
                {
                    cntR++;
                    continue;
                }
            }
        }
        if (cntR == 3)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    //縦
    for (int i = 0; i < 3; i++)
    {
        cntC = 0;
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < N; k++)
            {
                if (A[j][i] == b[k])
                {
                    cntC++;
                    continue;
                }
            }
        }
        if (cntC == 3)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    //斜め1
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (A[i][i] == b[j])
            {
                cntD1++;
                continue;
            }
        }
    }
    if (cntD1 == 3)
    {
        cout << "Yes" << endl;
        return 0;
    }
    //斜め2
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (A[i][2 - i] == b[j])
            {
                cntD2++;
                continue;
            }
        }
    }
    if (cntD2 == 3)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;
constexpr ll MOD = 998244353;

ll calc(const string& s) {
  ll m = 0;
  for (char c : s) {
    m += c - 'a';
    m %= 3;
  }
  return m;
}

int main() {
  string s;
  cin>>s;
  int n = s.size();
  if (n < 4) {
    set<string> t;
    t.insert(s);
    queue<string> q;
    q.push(s);
    while (!q.empty()) {
      string tmp = q.front();
      q.pop();
      REP(i,n-1) {
        if (tmp[i] != tmp[i+1]) {
          int sum = 3;
          sum -= (tmp[i] - 'a') + (tmp[i+1] - 'a');
          string next = tmp;
          next[i] = sum + 'a';
          next[i+1] = sum + 'a';
          if (t.count(next) == 0) {
            t.insert(next);
            q.push(next);
          }
        }
      }
    }
    cout << t.size() << endl;
    return 0;
  }
  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(3, vector<ll>(3, 0)));
  dp[0][0][0] = 1;
  REP(i,n) {
    REP(j,3)REP(k,3) {
      REP(c,3) {
        if (i!=0 && c==k) continue;
        dp[i+1][(j+c)%3][c] += dp[i][j][k];
        dp[i+1][(j+c)%3][c] %= MOD;
      }
    }
  }
  ll m = calc(s);
  ll sum = 0;
  REP(i,3) sum += dp[n][m][i];
  sum %= MOD;
  ll pm = 1;
  REP(i,n-1) {
    pm *= 3;
    pm %= MOD;
  }
  ll ans = pm - sum;
  if (ans < 0) ans += MOD;
  bool diff = true;
  bool same = true;
  REP(i,n-1) {
    if (s[i] == s[i+1]) diff = false;
    else same = false;
  }
  if (diff) {
    ans += 1;
    ans %= MOD;
  }
  if (same) {
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 39556
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, M, C;
  cin >> N >> M >> C;
  vector<ll> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  ll a;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll sum = C;
    for (int j = 0; j < M; j++) {
      cin >> a;
      sum += a * B[j];
    }
    if (sum > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int n = read(), k = read();
    printf("%d\n", n - k + 1);
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
from operator import mul
from functools import reduce


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


# 重複組み合わせは nHr = (n + r - 1)Cn
def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def solve(v):
    if v < 2:
        return ans
    return ans - cmb(v, 2) + cmb(v - 1, 2)


N = int(input())
A = inpl()
cA = Counter(A)

ans = 0
for v in cA.values():
    ans += v * (v - 1) // 2
# print(ans)
for a in A:
    print(solve(cA[a]))


Measured memory_bytes: 26764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Console.ReadLine().Split(' ');
            if (data[0] == data[1] && data[1] == data[2]&&data[0]==data[2])
            {
                Console.WriteLine("No");
            }
            else if(data[0] != data[1] && data[1] != data[2] && data[0] != data[2])
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
            
            
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  
  string a,b,c;
  cin>>a>>b>>c;
     transform(a.begin(), a.end(), a.begin(), ::toupper);
     transform(b.begin(), b.end(), b.begin(), ::toupper);
     transform(c.begin(), c.end(), c.begin(), ::toupper);
  cout<<a[0]<<b[0]<<c[0]<<"\n";
}

Measured memory_bytes: 256
def main():
    import sys
    from collections import Counter
    N=int(sys.stdin.readline())
    A=list(map(int,sys.stdin.readline().split()))
    C=Counter([i+x for i,x in enumerate(A)])
    output=0
    for key,val in Counter([i-x for i,x in enumerate(A)]).items():
        if key in C.keys():
            output+=val*C[key]
    print(output)

main()

Measured memory_bytes: 61564
#include<iostream>
#include<cstdio>
#include<list>

using namespace std;

int main()
{
	list<int> v;
	int N;
	char A[20];
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%s", A);
		if (A[0] == 'i')
		{
			int key;
			scanf("%d", &key);
			v.push_front(key);
		}
		else if (A[0] == 'd')
		{
			if (A[6] == 'F')
			{
				v.pop_front();
			}
			else if (A[6] == 'L')
			{
				v.pop_back();
			}
			else
			{
				int key;
				scanf("%d", &key);
				for (list<int>::iterator it = v.begin(); it != v.end(); it++)
				{
					if (*it == key)
					{
						v.erase(it);
						break;
					}
				}
			}
		}
	}
	int sum = 0;
	for (list<int>::iterator it = v.begin(); it != v.end(); it++)
	{
		if (sum++ > 0)
		{
			cout << ' ' <<*it ;
		}
		else
		{
			cout << *it;
		}

	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 34372
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - 1 or 2
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];
  UFT() {}

  void init(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

UFT uft;

/* subroutines */

/* main */

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

  uft.init(n);
  int gn = n;

  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--, y--;

    if (! uft.same(x, y)) {
      uft.merge(x, y);
      gn--;
    }
  }

  printf("%d\n", gn);
  return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(),k = sc.nextInt();
    int l[] = new int[n];
    for(int i = 0;i < n;i++){
      l[i] = sc.nextInt();
    }
    Arrays.sort(l);
    int ans = 0;
    for(int i = 0;i < k;i++){
      ans += l[n-1-i];
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
using namespace std;
 
int main(void)
{
  long W = 0, H = 0, x = 0, y = 0;
  cin >> W >> H >> x >> y;
  
  cout << double(W) * double(H) / 2<< " ";
  
  if(2 * x == W && 2 * y == H)
  {
    cout << 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
require "bigdecimal"
require "bigdecimal/util"

def gi() gets.to_i end
def gs() gets.chomp end
def gim() gets.split.map(&:to_i) end
def gsm() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end

#####
k,n = gim
nums = gim

gaps = [(nums[0] + k-nums[-1])]
(n-1).times do |i|
  gaps.push(nums[i+1] - nums[i])
end

gaps.sort!
print gaps[0..-2].inject(:+)

Measured memory_bytes: 19364
from collections import deque

def dfs(graph, start):
    stack = deque()
    costs = [0] * (N+1)
    stack.append([start,0])
    costs[start] = -1
    while stack:
        a, cost = stack.popleft()
        for b in graph[a].keys():
            if not costs[b]:
                stack.append([b,cost+1])
                costs[b] = cost+1
    return costs

N = int(input())
graph = {}
for i in range(N-1):
    a,b = map(int, input().split())
    if a not in graph:
        graph[a] = {}
    if b not in graph:
        graph[b] = {}
    graph[a][b] = graph[b][a] = 1
f_costs = dfs(graph,1)
s_costs = dfs(graph,N)
f_cnt = 1
for i in range(2,N):
    if f_costs[i] <= s_costs[i]:
        f_cnt += 1
# print(f_costs, s_costs, f_cnt)
print('Fennec' if f_cnt > N - f_cnt else 'Snuke')


Measured memory_bytes: 53480
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    cout<<n*n<<endl;
    return 0;
}





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

int main(void)
{
	int N,M;

	cin >> N >> M;

	int x,y;
	int hn = N/2+1;
	int ans;
	for(int i = 0; i < M; i++){
		cin >> x >> y;
		if(x > hn)
			x = N - x + 1;
		if(y > hn)
			y = N - y + 1;

		if(x < y){
			ans = x % 3;
		}
		else
			ans = y % 3;
		if(ans == 0)
			ans = 3;

		cout << ans << endl;

	}


	return 0;
}

Measured memory_bytes: 1164
import math
N = int(input())
X = []
Y = []
for n in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
S = 0
for i in range(N):
    for j in range(N):
        d = (X[i]-X[j])**2 + (Y[i]-Y[j])**2
        S += math.sqrt(d)
print(S/N)


Measured memory_bytes: 3060
def manhattan(a,b,c,d):
    return abs(a-c)+abs(b-d)

n,m = list(map(int,input().split()))

X = []
Y = []
for i in range(n):
    a,b = list(map(int,input().split()))
    X.append([a,b])

for i in range(m):
    c,d = list(map(int,input().split()))
    Y.append([c,d])

for x in X:
    dist = 1e9
    choise = 1
    for n,y in enumerate(Y):
        mh = manhattan(x[0],x[1],y[0],y[1])
        if mh < dist:
            dist = mh
            choise = n+1
    print(choise)

Measured memory_bytes: 3064
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
import bisect
A,B,Q = getList()
temple = []
shrine = []
for i in range(A):
    temple.append(getN())

for i in range(B):
    shrine.append(getN())

temple.sort()
shrine.sort()

near_sh = []
for t in temple:
    a = bisect.bisect_left(shrine, t)
    if a == 0:
        l = -1000000000000
    else:
        l = shrine[a-1]
    if a == B:
        r = 1000000000000
    else:
        r = shrine[a]
    near_sh.append((l,r))

def calc(x, a, direction):
    #l=1
    try:
        near_temp = temple[a-direction]
    except:
        return 100000000000
    cost_outshrine = abs(x-near_sh[a-direction][1-direction])
    cost_inshrine = abs(x-near_temp)
    if cost_inshrine < abs(near_temp - near_sh[a-direction][0+direction]):
        #print("cost", near_sh[a - direction][0 + direction], cost_inshrine)
        cost_inshrine = (abs(near_temp - near_sh[a-direction][0+direction])) + min(cost_inshrine, abs(x- near_sh[a - direction][0 + direction]))

    #print("inoput", cost_inshrine,cost_outshrine,a,direction)
    return min(cost_inshrine, cost_outshrine)

#print(shrine)
#print(temple)
#print(near_sh)
for i in range(Q):
    x = getN()
    a = bisect.bisect_left(temple,x)
    if a != 0:
        cost_l = calc(x,a,1)
    else:
        cost_l = 1000000000000
    if a != A:
        cost_r = calc(x,a,0)
    else:
        cost_r = 1000000000000

    print(min(cost_l, cost_r))


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, k;

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

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

    cout << (n-1+(k-2)) / (k-1) << '\n';

    return 0;
}


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

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int i=0;
		while(true){
        	int x=Integer.parseInt(br.readLine());
        	if(x==0) break;
    		i++;
    		System.out.println("Case "+i+": "+x);
        }
	}
}

Measured memory_bytes: 27200
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
#define chkmin(a,b) (a) = min((a), (b))
#define chkmax(a,b) (a) = max((a), (b))
using namespace std;
int inf = 1e9, mod = 1e9;

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n; cin >> n;
    vi arr(n);
    for (int i=0;i<n;i++) cin >> arr[i], arr[i] -= i + 1;
    sort(all(arr));
    int b = arr[n/2], sum = 0;
    for(auto &v:arr) sum += abs(v - b);
    cout << sum << endl;
    return 0;
}


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

using namespace std;

constexpr long long power(long long b, long long e, long long mod){
  long long ret = 1;
  while(e){
    if(e & 1){
      ret *= b;
      ret %= mod;
    }

    b *= b;
    b %= mod;
    e >>= 1;
  }

  return ret;
}

long long rec(int d, vector<long long>& f){
  if(f[d] >= 0) return f[d];
  if(d == 0) return f[d] = 0;
  return f[d] = rec(d % (__builtin_popcount(d)), f) + 1;
}

int main(){
  vector<long long> f(200001, -1);
  for(int i = 200000; i >= 0; i--){
    rec(i, f);
  }
  
  int N;
  cin >> N;
  
  string X;
  cin >> X;
  int ones = 0;
  long long x = 0;
  for(int i = 0; i < N; i++){
    if(X[i] == '1'){
      ones++;
    }
  }
  
  if(ones == 0){
    for(int i = 0; i < N; i++){
      cout << 1 << endl;
    }
    return 0;
  }else if(ones == 1){
    long long all_one = 0;
    for(int i = 0; i < N; i++){
      if(X[i] == '1') all_one = power(2, N - i - 1, ones + 1);
    }
    
    for(int i = 0; i < N; i++){
      if(X[i] == '1'){
        cout << 0 << endl;
      }else{
        cout << f[((all_one + power(2, N - i - 1, ones + 1)) % 2 + 2) % 2] + 1 << endl;
      }
    }
    return 0;
  }
  
  long long all_one = 0, semi_one = 0;
  for(int i = 0; i < N; i++){
    if(X[i] == '1'){
      all_one += power(2, N - i - 1, ones + 1);
      semi_one += power(2, N - i - 1, ones - 1);
    }
    all_one %= ones + 1;
    semi_one %= ones - 1;
  }
  
  for(int i = 0; i < N; i++){
    if(X[i] == '1'){
      cout << f[((semi_one - power(2, N - i - 1, ones - 1)) % (ones - 1) + (ones - 1)) % (ones - 1)] + 1 << endl;
    }else{
      cout << f[((all_one + power(2, N - i - 1, ones + 1)) % (ones + 1) + (ones + 1)) % (ones + 1)] + 1 << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 5200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskD {
        static int log(long a  , long b){
            int ans = 0;
            while (a/b!=0){a/=b;ans++;}
            return ans;
        }
        static long pow(long a , long b){
            if (b==0)return 1;
            long v = pow(a , b/2);
            long ans = v*v;
            if (b%2!=0)ans*=a;
            return ans;
        }
        static  int[] count;
        static  boolean[] visited;
        static ArrayList<Integer>[] frinds;
        static int[] color ;
        public static void dfs(int v , int val){
            visited[v]=true;
            count[val]++;
            color[v]=val;
            if (frinds[v]!=null)for (int u: frinds[v]) {
                if (!visited[u]) dfs(u , val);
            }
        }
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] co = new long[n+2];
            long val= 0;
            for (int i = 1; i <=n ; i++) {
                co[i]=in.nextInt();
            }
            long [] todelete=new long[n+1];
            for (int i = 1; i <=n ; i++) {
                todelete[i]+=Math.abs(co[i]-co[i-1]);
                todelete[i]+=Math.abs(co[i]-co[i+1]);
            }
            for (int i = 1; i <=n+1; i++) {
                val+=Math.abs(co[i]-co[i-1]) ;
            }
            for (int i = 1; i <=n ; i++) {
                System.out.println(val-todelete[i]+Math.abs(co[i-1]-co[i+1]));
            }











        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 54000
a,b=map(int,input().split())
s=[1,3,5,7,8,10,12]
t=[4,6,9,11]
if a in s:
    a = 0
elif a in t:
    a = 1
else:
    a = 2
if b in s:
    b = 0
elif b in t:
    b = 1
else:
    b = 2
print("Yes" if a==b else "No")

Measured memory_bytes: 9020
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	a := getNextInt(scanner)
	b := getNextInt(scanner)

	cm := CombinationMod{}
	cm.init(h + w)

	var ans int64

	for i := 1; i < h-a; i++ {
		ans += cm.calc(b+i-2, i-1) * cm.calc(h-i+w-b-1, h-i)
		ans %= cm.mod
	}
	center := cm.calc(h-a-1+b-1, b-1) * cm.calc(a-1+w-b, a)
	ans += center % cm.mod

	fmt.Fprintln(writer, ans%cm.mod)
	writer.Flush()
}

// CombinationMod ...
type CombinationMod struct {
	n, mod   int64
	fac, inv []int64
}

func (cm *CombinationMod) init(n int) {
	cm.n = int64(n)
	cm.fac = make([]int64, n+1)
	cm.inv = make([]int64, n+1)
	cm.fac[0] = 1
	cm.inv[0] = 1
	cm.mod = int64(1e9 + 7)
	var i int64
	for i = 1; i < cm.n+1; i++ {
		cm.fac[i] = (cm.fac[i-1] * i) % cm.mod
		cm.inv[i] = cm.calcInv(cm.fac[i])
	}
}

func (cm *CombinationMod) calcInv(n int64) int64 {
	if n == 1 {
		return 1
	}
	var a, b, x, y int64
	a = cm.mod
	b = n
	x = 1
	y = -a / b

	stack := [][]int64{
		[]int64{
			x, y,
		},
	}
	for a%b > 0 {
		a, b = b, a%b
		x = 1
		y = -a / b
		stack = append(stack, []int64{
			x, y,
		})
	}

	for i := len(stack) - 2; i > 0; i-- {
		stack[i-1][0] *= stack[i][1]
		stack[i-1][1] *= stack[i][1]
		stack[i-1][1] += stack[i][0]
	}

	ans := stack[0][1] % cm.mod
	if ans < 0 {
		ans += cm.mod
	}

	return ans
}

func (cm *CombinationMod) calc(n, m int) int64 {
	ans := (cm.fac[n] * ((cm.inv[m] * cm.inv[n-m]) % cm.mod)) % cm.mod
	return ans
}


Measured memory_bytes: 7040
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  double r, p = 6.28318530717958623200/2; cin >> r;
  cout << r * 2 * p << endl;
}


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

int main(){
    int N;
    cin >> N;
    if (N == 1 || N == 3) {
        cout << "First" << endl;
        return 0;
    }
    if (N == 2) {
        cout << "Second" << endl;
        return 0;
    }
    vector<vector<int>> edge(N+1, vector<int>());
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> dist(N+1, 1000000);
    dist[1] = 0;
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (dist[nxt] > dist[now]+1) {
                dist[nxt] = dist[now]+1;
                q.push(nxt);
            }
        }
    }
    int distmax = 0;
    int pos = 0;
    for (int i = 1; i <= N; i++) {
        if (dist[i] > distmax) {
            distmax = dist[i];
            pos = i;
        }
    }
    
    for (int i = 1; i <= N; i++) dist[i] = 1000000;
    dist[pos] = 0;
    q.push(pos);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (dist[nxt] > dist[now]+1) {
                dist[nxt] = dist[now]+1;
                q.push(nxt);
            }
        }
    }
    int rad = 0;
    pos = 0;
    for (int i = 1; i <= N; i++) {
        if (dist[i] > rad) {
            rad = dist[i];
            pos = i;
        }
    }
    if (rad % 3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

Measured memory_bytes: 13556
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int m, n, field[90][90];
int dy[] = {-1,0,1,0}, dx[] = {0,-1,0,1};

int dfs(int y, int x, int c){
  //  printf("%d %d %d\n", y, x, c);
  field[y][x] = 0;
  int res = c;
  rep(i, 4){
    int ny = y + dy[i], nx = x + dx[i];
    if(ny < 0 || ny >= n || nx < 0 || nx >= m || !field[ny][nx]) continue;
    res = max(res, dfs(ny, nx, c+1));
  }
  field[y][x] = 1;
  return res;
}

int main(){
  while(scanf("%d%d", &m, &n) && m+n){
    rep(i, n) rep(j, m) scanf("%d", &field[i][j]);

    int res = 0;
    rep(i, n) rep(j, m) if(field[i][j]) res = max(res, dfs(i, j, 1));

    printf("%d\n", res);
  }
  return 0;
}

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

int main(){

  int r,c;

  while(true){
    cin >> r >> c;
    if(!r && !c) break;

    if((r * c) % 2 == 0) cout << "yes";
    else cout << "no";

    cout << endl;
  }
} 

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int ans = 0;
    ans += (H2 - H1) * 60;
    ans += M2 - M1;

    cout << ans - K << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include <unordered_map>  
#include <map>
#include <string> 
using namespace std;
int main() {
	int n;
	string st;
	unordered_map<string, int> m;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> st;
		m[st]++;
	}

	cout << m.size() << endl;
	return 0;


}

Measured memory_bytes: 17696
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
   
    long long int n1,m1,t;
 //   cin>>t;
   t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=1,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int c=0,n,m,l=0,r=0,k,min1=10000000000000,max2=-100;
 cin>>n;
 
 /*long long int a[n];
 for(i=0;i<n;i++)
 cin>>a[i];
 */
 p=n%1000;
 if(p==0)
 cout<<p;
 else
 cout<<(1000-p);
 }
 return 0;
}


Measured memory_bytes: 3672
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  bool can = false;
  while(a <= b){
    if(a % k == 0){
      can = true;
    }
    a++;
  }
  
  if(can) cout << "OK" << endl;
  else cout << "NG" << endl;
      
}

Measured memory_bytes: 3496
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 100005;
//////////////////////////////

int n;
Int dp[N][13];
string s;

void solve()
{
	cin >> s;
	n = s.size();
	if (s[0] == '?') {
		for (int j = 0; j < 10; j++) dp[1][j] = 1;
	}
	else {
		dp[1][s[0] - '0'] = 1;
	}

	for (int i = 1; i < n; i++) {
		if (s[i] != '?') {
			int tmp = s[i] - '0';
			for (int j = 0; j < 13; j++) {
				(dp[i + 1][(tmp + 10 * j) % 13] += dp[i][j]) %= MOD;
			}
		}
		else {
			for (int tmp = 0; tmp < 10; tmp++) {
				for (int j = 0; j < 13; j++) {
					(dp[i + 1][(tmp + 10 * j) % 13] += dp[i][j]) %= MOD;
				}
			}
		}		
	}

	cout << dp[n][5] << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 13952
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int a[] = new int[80];
		int b[] = new int[80];
		int c[] = new int[80];
		String st1, st2;

		n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 80; j++) {
				a[j] = 0;
				b[j] = 0;
				c[j] = 0;
			}
			st1 = sc.next();
			st2 = sc.next();
			if (80 < st1.length() || 80 < st2.length()) {
				System.out.println("overflow");
				continue;
			}
			for (int j = st1.length() - 1; 0 <= j; j--) {
				a[80 - st1.length() + j] = st1.charAt(j) - '0';
			}
			for (int j = st2.length() - 1; 0 <= j; j--) {
				b[80 - st2.length() + j] = st2.charAt(j) - '0';
			}

			f(a, b, c, 79);
			if (9 < c[0]) {
				System.out.println("overflow");
			} else {
				for (int j = 0; j < 80; j++) {
					if (c[j] != 0) {
						for (int k = j; k < 80; k++) {
							System.out.print(c[k]);
						}
						break;
					}
					if (j == 79 && a[j] == 0) {
						System.out.print("0");
					}
				}
				System.out.println();
			}
		}
	}

	public static void f(int a[], int b[], int c[], int k) {
		if (k < 0) {
			return ;
		}
		c[k] += (a[k] + b[k]);
		if (10 <= c[k]) {
			if (0 < k) {
				c[k] %= 10;
				c[k - 1]++;
			}
		}
		f(a, b, c, k - 1);
	}
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n; cin >> n;
    vll fib(n+1);
    fib[0] = fib[1] = 1;
    for(int i = 2; i <= n; ++i) {
        fib[i] = fib[i-1] + fib[i-2];
    }
    cout << fib[n] << '\n';
    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3180
#include <stdio.h>
#include <string.h>
int main()
{
    char s[25],t[25];
    scanf("%s %s",s,t);
    int a,b;
    scanf("%d%d",&a,&b);
    char x[25];
    scanf("%s",x);

    if (strcmp(x,s)==0){
        a--;
    }
    else if (strcmp(x,t)==0){
        b--;
    }
    printf("%d %d\n",a,b);
    return 0;
}

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

int main(){
  int N,ans=0,num=1;
  bool flag=false;
  cin >> N;
  vector<int> a(N);
  rep(i,N) {
    cin >> a[i];
    if(a[i]==1)flag=true;
  }
  
  if(!flag){
    ans = -1;
  }
  else {
    rep(i,N){
      if(a[i]==num) num++;
    }
    ans = N-num+1;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	if (abs(n - m) > 1) cout << 0 << endl;
	else if (abs(n - m) == 1){
		ll fn = 1, fm = 1;
		for (int i = 1; i <= n; i++) fn = fn*i%PRIME;
		for (int i = 1; i <= m; i++) fm = fm*i%PRIME;
		cout << fn*fm%PRIME << endl;
	}
	else{
		ll fn = 1, fm = 1;
		for (int i = 1; i <= n; i++) fn = fn*i%PRIME;
		for (int i = 1; i <= m; i++) fm = fm*i%PRIME;
		cout << 2 * fn*fm%PRIME << endl;
	}
	return 0;
}


Measured memory_bytes: 384
n = gets.chomp.to_i
list = gets.chomp.split().map { |e|e.to_i  }
list.sort!.reverse!

if n % 2 == 0
  nList = list[0..(list.count)/2 - 1]
  ans = nList.sum * 2 - nList.max
else
  nList = list[0..(list.count)/2]
  ans = nList.sum * 2 - nList.max - nList.min
end
puts ans


Measured memory_bytes: 31816
#include <bits/stdc++.h>
typedef long long ll;
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define Fd(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;
const int N=102;

char tab[N][N];

 int main()
 {
        int A,B;
        scanf("%d%d",&A,&B);

        F(i,1,100)
        {
                F(j,1,50)
                {
                        tab[i][j]='.';
                }
        }

        F(i,1,100)
        {
                F(j,51,100) tab[i][j]='#';
        }

        A--;
        B--;

        for(int i=1;i<=100;i+=2)
        {
              for(int j=1;j<50;j+=2)
              {
                    if(B==0) break;
                    tab[i][j]='#';
                    B--;
              }
        }

        for(int i=1;i<=100;i+=2)
        {
              for(int j=52;j<=100;j+=2)
              {
                    if(A==0) break;
                    tab[i][j]='.';
                    A--;
              }
        }


        printf("100 100\n");
        F(i,1,100)
        {
            F(j,1,100)
            {
                printf("%c",tab[i][j]);
            }
            printf("\n");
        }
 }

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	ll N, M;
	cin >> N >> M;

	ll ans = 0;
	if (N != 1 && M != 1) {
		ans = (N - 2)*(M - 2);
	}
	else {
		if (N == 1 && M != 1) ans = M - 2;
		else if (M == 1 && N != 1) ans =  N - 2;
		else ans = 1;
	}
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
n = gets.to_i
ls = gets.split(' ').map(&:to_i)
counts = ls.group_by(&:itself).map {|k, v| [k, v.size] }.to_h
nums = counts.keys.sort
N = nums.length

cnt = 0
(0...N).each do |i|
  (0...i).each do |j|
    (j + 1...i).each do |k|
      if nums[i] < nums[j] + nums[k]
        cnt += counts[nums[i]] * counts[nums[j]] * counts[nums[k]]
      end
    end
  end
end
puts cnt


Measured memory_bytes: 14396
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int dist_sq(int d, vector<int> a, vector<int> b) {
    int ans = 0;
    for (int i = 0; i < d; i++) {
        ans += (a[i] - b[i]) * (a[i] - b[i]);
    }
    return ans;
}

bool is_square(int p) {
    if (p == 1) return true;
    
    map<int, int> mp;
    bool update = true;
    while (update) {
        update = false;
        for (int i = 2; i <= (int)sqrt(p); i++) {
            if (p % i == 0) {
                mp[i]++;
                p /= i;
                update = true;
                break;
            }
        }
        if (!update) mp[p]++;
    }
    
    for (auto &iter : mp) {
        if (iter.second % 2 != 0) {
            return false;
        }
    }
    return true;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, d; cin >> n >> d;
    vector<vector<int>> vs(n, vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> vs[i][j];
        }
    }
    
    int cnt = 0;

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (is_square(dist_sq(d, vs[i], vs[j]))) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, A;
ll D;
ll X[200000], H[200000];
typedef pair<ll, ll> P;
P p[200000];
ll INF = 1e+10;
ll sum[200001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> D >> A;
    for(int i = 0; i < N; i++) {
        cin >> X[i] >> H[i];
        p[i] = P(X[i], H[i]);
    }
    ll ans = 0;
    sort(p, p+N);
    for(int i = 0; i < N; i++){
        ll l = p[i].first;
        ll h = p[i].second;
        if(i > 0) sum[i] += sum[i-1];
        // cout << sum[i] << endl;
        h -= sum[i]*A;
        ll c = (h+A-1)/A;
        if(h > 0) {
            ans += c;
        auto pt = upper_bound(p, p+N, P(l+2*D, INF));
        int dif = pt-p;
        sum[i] += c;
        sum[dif] -= c;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<string> S(N);
    rep(i,N)cin >> S[i];

    map<string,int> m;
    char tmp = S[0][S[0].size()-1];
    bool ok = true;
    rep(i,N){
        m[S[i]]++;
        if(S[i][0] != tmp && i != 0)ok = false;
        tmp = S[i][S[i].size()-1];
    }
    for(auto t : m){
        if(t.S >= 2)ok = false;
    }

    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
Tpoint = 0
Hpoint = 0
for i in range(n):
    Taro ,Hanako = map(str,input().split())

    if Taro<Hanako:
        Tpoint+=0
        Hpoint+=3
    elif Taro==Hanako:
        Tpoint+=1
        Hpoint+=1
    else:
        Tpoint+=3
        Hpoint+=0
print(Tpoint,Hpoint)


Measured memory_bytes: 5596
N,Z,W = list(map(int, input().split()))
A = [W] + list(map(int, input().split()))

X = [0]*(N+1)
Y = [1e9]*(N+1)

for i in range(N,0,-1):
  X[i] = max([abs(A[i-1] - A[N])] + [Y[j] for j in range(i+1,N+1)])
  Y[i] = min([abs(A[i-1] - A[N])] + [X[j] for j in range(i+1,N+1)])

print(X[1])

Measured memory_bytes: 3188
//joisino's travel

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

signed main (){
    int n,m,R;cin>>n>>m>>R;
    vecrep(R,r,int);
    vector<vector<int>>c(n,vector<int>(n,inf));
    rep(i,0,n)c[i][i]=0;
    rep(i,0,m){
        int a,b,d;cin>>a>>b>>d;
        c[a-1][b-1]=d;
        c[b-1][a-1]=d;
    }
    rep(k,0,n)rep(i,0,n)rep(j,0,n)chmin(c[i][j],c[i][k]+c[k][j]);
    sort(range(r));
    int ans=inf;
    for(int i=0;next_permutation(range(r));i++){
        if(i==0)prev_permutation(range(r));
        int t=0;
        rep(i,1,R)t+=c[r[i-1]-1][r[i]-1];
        ans=min(ans,t);
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3776
from collections import Counter
n = int(input())
s = Counter([input() for _ in range(n)])
before = 0
ans = []
s = s.most_common()
for i in range(len(s)):
    if before == 0: before = s[i][1]
    elif before != s[i][1]: break
    ans.append(s[i][0])
for i in sorted(ans): print(i)

Measured memory_bytes: 47940
#include<stdio.h>
int main(void)
{
	int a[4],b[3],i,min,min2;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<2;i++){
		scanf("%d",&b[i]);
	}
	min=10000;
	for(i=0;i<3;i++){
		if(min>a[i]){
			min=a[i];
		}
	}
	min2=10000;
	for(i=0;i<2;i++){
		if(min2>b[i]){
			min2=b[i];
		}
	}
	printf("%d\n",min+min2-50);
	return 0;
}

Measured memory_bytes: 592
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int[] a=new int[100];
		int[] b=new int[100];
		int n=0;
		for(; sc.hasNext();){
			System.arraycopy(a, 0, b, 0, 100);
			String[] s=sc.nextLine().split(",");
			if(s.length>n){
				for(int i=0; i<s.length; i++){
					int m=Integer.parseInt(s[i]);
					if(i>0)
						a[i]=max(b[i-1]+m, b[i]+m);
					else
						a[i]=b[i]+m;
//					print(a[i]+", ");
				}
			}else{
				for(int i=0; i<s.length; i++){
					int m=Integer.parseInt(s[i]);
					a[i]=max(b[i+1]+m, b[i]+m);
//					print(a[i]+", ");
				}
			}
			n=s.length;
//			println("");
		}
		println(a[0]+"");
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
import copy
def p(a):
    for i in a[:-1]:
        print(i,end=' ')
    print(a[-1])


def selection_sort(a):
    cnt = 0
    for i in range(len(a)-1):
        fl = 0
        min = i
        for j in range(i+1,len(a)):
            if a[j][1]<a[min][1]:
                fl=1
                min = j
        cnt+=fl
        tmp = a[min]
        a[min] = a[i]
        a[i] = tmp


def bubble_sort(a):
    for i in range(len(a)-1):
        for j in range(i+1,len(a))[::-1]:
            if a[j-1][1]>a[j][1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp


n = int(input())
l = list(input().split())
a = copy.copy(l)
bubble_sort(l)
selection_sort(a)
p(l)
print('Stable')
p(a)
if a==l:
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 6340