akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n-1)]

edges = {}
for i in range(1,n+1):
    edges[i] = set()

for tmp in ab:
    a,b = tmp
    edges[a].add(b)
    edges[b].add(a)

group = [[],[]]
g_flag = 0
next = {1}
while(len(next) > 0):
    tmp = list(next)
    next = set()
    for i in tmp:
        group[g_flag].append(i)
        for j in edges[i]:
            next.add(j)
            edges[j].remove(i)
    g_flag = 1- g_flag

even_n = len(group[0])
odd_n = len(group[1])

ans = [0] * (n+1)
if(even_n > n//3)&(odd_n > n//3):
    g1 = group[0][ : (n+2)//3]
    g2 = group[1][ : (n+1)//3]
    g0 = group[0][(n+2)//3 :] + group[1][(n+1)//3 :]
elif(even_n <= n//3):
    g0 = group[0]+ group[1][: n//3 - even_n]
    g1 = group[1][n//3 - even_n : (n//3 - even_n) + (n+2)//3]
    g2 = group[1][(n//3 - even_n) + (n+2)//3 :]
else:
    g0 = group[1] + group[0][: n//3 - odd_n]
    g1 = group[0][n//3 - odd_n : (n//3 - odd_n) + (n+2)//3]
    g2 = group[0][(n//3 - odd_n) + (n+2)//3 :]

# print(group)
# print(g0)
# print(g1)
# print(g2)

for i in range((n+2)//3):
    ans[g1[i]] = i*3 + 1
for i in range((n+1)//3):
    ans[g2[i]] = i*3 + 2
for i,val in enumerate(g0):
    ans[val] = (i+1) * 3

print(' '.join(map(str, ans[1:])))

Measured memory_bytes: 159052
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,M;
	cin>>N>>M;
	vector<int> a(N);
	int sum = 0;
	rep(i,N){cin>>a[i]; sum += a[i];}
	sort(all(a));
	bool ok = true;
	for(int i = 0; i<M; ++i){
		if(a[N-1-i]*4*M < sum){ok = false; break;}
	}
	cout<<((ok)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, k;
    cin >> n >> k;
    if (n == 0) {
        cout << 1 << endl;
        return 0;
    }
    ll res = 0;
    while (n) {
        n /= k;
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N, D=map(int, input().split())
X=[list(map(int, input().split())) for _ in range(N)]
cnt=0
for i in range(N):
  for j in range(i+1, N):
    dis=0
    for k in range(D):
      dis+=(X[i][k]-X[j][k])**2
    dis=math.sqrt(dis)
    if dis==int(dis):
      cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
int main()
{
    map<int,int>m;
    int t,i,ans=0;
    cin>>t;
    for(i=1;i<=t;i++)
    {
        int a;
        cin>>a;
        m[a]++;
    }
    for(auto u:m)
    {
        if(u.second>=u.first)ans+=u.second-u.first;
        else ans+=u.second;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n;
vector<int> v[200010],col[200010];
int a[200010],cnt[200010];
ll ans[200010];
int lca[200010][30];
int dep[200010];
bool isit[200010];
int dfsnum(int x,int par)
{
	dep[x]=(!x ? 0 : dep[par]+1);
	cnt[x]=1;
	lca[x][0]=par;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (xi==par) continue;
		cnt[x]+=dfsnum(xi,x);
	}
	return cnt[x];
}
int go(int x,int y)
{
	//cout <<x<<" "<<y<<" ##\n";
	if (x<0) return -1;
	for (int i=0;i<20;i++) if (x & (1<<i)) y=lca[y][i];
	//cout <<y<<" #############\n";
	return y;
}
void dfs(int x,int par)
{
	//cout <<x<<" ###############\n";
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (xi==par) continue;
		dfs(xi,x);
		ll t=cnt[xi];
		vector<int> vt;
		for (int j=0;j<col[a[x]].size();j++)
			if (go(dep[col[a[x]][j]]-dep[xi],col[a[x]][j])==xi)
				t-=cnt[col[a[x]][j]],vt.push_back(j);
		for (int j=vt.size()-1;j>=0;j--) col[a[x]].erase(col[a[x]].begin()+vt[j],col[a[x]].begin()+vt[j]+1);
		//cout <<x<<" "<<xi<<" "<<t<<" ##\n";
		ans[a[x]]+=t*(t+1)/2;
	}
	col[a[x]].push_back(x);
}
int main()
{
	scanf("%lld",&n);
	for (int i=0;i<n;i++) scanf("%d",&a[i]),a[i]--,isit[a[i]]=1;
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfsnum(0,-1);
	for (int i=1;i<20;i++)
		for (int j=0;j<n;j++)
			lca[j][i]=(lca[j][i-1]==-1 ? -1 : lca[lca[j][i-1]][i-1]);
	dfs(0,-1);
	for (int i=0;i<n;i++)
	{
		ll t=n;
		for (int j=0;j<col[i].size();j++) t-=cnt[col[i][j]];
		//cout <<i+1<<" "<<t<<" ##\n";
		ans[i]+=t*(t+1)/2;
	}
	for (int i=0;i<n;i++) printf("%lld\n",isit[i] ? n*(n+1)/2-ans[i] : 0);
	return 0;
} 

Measured memory_bytes: 78984
package main

import "fmt"

func main() {
	var n, a int
	fmt.Scan(&n)

	var one, two, four int
	for range make([]struct{}, n) {
		fmt.Scan(&a)

		if a%4 == 0 {
			four++
		} else if a%2 == 0 {
			two++
		} else {
			one++
		}
	}

	if one <= four || (two == 0 && one == four+1) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV 998244353
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-10;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding space */
map<int,bool> ans;
vt<ll> primes;
bool is_prime(ll a){
  if(a < 2) return 0;
  for(ll i = 2; i*i <= a; ++i)
    if(a % i == 0)  return 0;
  return 1;
}
vt<ll> in;
int n;


bool check(ll p){
  ll t[10005] ={};
  rep(i,n+1){
    t[i%(p-1)] += in[n-i];
  }
  //rep(i,p)  cerr<< p << " " << t[i] << endl;
  if(in[n] % p)  return 0;
  rep(i,p)if(t[i]%p)  return 0;
  return 1;
}
int main(){
  rep(i,10001)  if(is_prime(i))  primes.pb(i);
  cin >> n;
  in.resize(n+1);
  rep(i,n+1) cin >> in[i];
  
  ll gcd_ = abs(in[0]);
  rep(i,n+1)  gcd_ = __gcd(gcd_, abs(in[i]));
  if( is_prime(gcd_) )  ans[gcd_] = 1;
  for(auto p : primes)if(gcd_ % p == 0)  ans[p] = 1;
  for(auto p: primes){
    if(check(p)){ans[p]  = 1;}
  }
  for(auto i: ans)  cout << i.FST << endl;
}


Measured memory_bytes: 384
n = readline.to_i
l = readline.chomp.chars
a = b = 0
as = Array.new(n){0}
bs = Array.new(n){0}
(0..l.size).map{|i|
  if l[i] == '.'
    a += 1
  else
    b += 1
  end
  as[i+1] = a
  bs[i+1] = b
}
puts (0..l.size).map{|i|
  (bs[i] - bs[0]) + (as[n] - as[i])
}.min

Measured memory_bytes: 23164
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int x,a;
    cin >> x >> a;
    if (x < a) cout << 0;
    else if (x >= a) cout << 10;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    nums = getlist()
    if len(list(set(nums))) == 2:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main() {

  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  REP(i,h) cin >> s[i];
  int ans = 0;

  REP(is, 1 << h){
    REP(js, 1 << w){
      int cnt = 0;

      REP(i,h)REP(j,w){
        //消される行，列は飛ばす．
        if(is >> i&1) continue;
        if(js >> j&1) continue;

        //消されていない行の＃のマスをカウント
        if(s[i][j] == '#') ++cnt;
      }

      if(cnt == k) ++ans;

    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
n = int(input())
x = list(map(int, input().split()))
dist = [x[i+1]-x[i] for i in range(n-1)]
mod = 10 ** 9 + 7

fact = [1]*(n+1)
r = 1
for i in range(1, n+1):
  fact[i] = r = r * i % mod
now = fact[n-1]
ans = 0
for k,d in enumerate(dist):
  ans = (ans + now * d) % mod 
  now += (fact[n-1] * pow(k+2,mod-2,mod)) % mod
print(ans)

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N, K;
  cin >> N >> K;
  if(0<=K&&K<=((N-1)*(N-2))/2){
    vector<vector<LL>> graph(N);
    LL num = 0;
    FOR(i,1,N){
      graph[0].push_back(i);
      num++;
    }
    LL cnt = ((N-1)*(N-2))/2;
    LL idx = 1;
    LL node = 2;
    while (cnt > K)
    {
      graph[idx].push_back(node);
      node++;
      if(node>=N){
        idx++;
        node = idx + 1;
      }
      cnt--;
      num++;
    }
    cout << num << endl;
    REP(i,graph.size()){
      REP(j,graph[i].size()){
        cout << i+1 SP graph[i][j]+1 << endl;
      }
    }
  }
  else
  {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 384
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val n = input.split(LINE_SEPARATOR).head.toInt
    val s = input.split(LINE_SEPARATOR).tail.head
    s.split("").sliding(3).map(_.toVector).count(_ == Vector("A", "B", "C")).toString
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """10
      |ZABCDBABCQ""".stripMargin -> """2
                                          |
                              |
                                   |""".stripMargin,
    """19
      |THREEONEFOURONEFIVE""".stripMargin -> """0
                                                   |
                              |""".stripMargin,
    """33
      |ABCCABCBABCCABACBCBBABCBCBCBCABCB""".stripMargin -> "5"
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 27324
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  for(int i=0;i<BITLE(3);i++){
    ll sum = s[0]-'0';
    for(int j=0;j<3;j++){
      if(BITLE(j)&i){
	sum += s[j+1]-'0';
      }else{
	sum -= s[j+1]-'0';
      }
    }
    if(sum == 7){
      cout<<s[0];
      for(int j=0;j<3;j++){
	if(BITLE(j)&i)cout<<'+';
	else cout<<'-';
	cout<<s[j+1];
      }
      cout<<"=7"<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

template<typename T>
struct BIT{
    int n;
    vector<T> d;
    BIT(int n=0):n(n),d(n+1){}
    void add(int i, T x=1){
        for(i++; i <= n; i += i&-i){
            d[i] += x;
        }
    }
    T sum(int i){
        T x = 0;
        for(i++; i; i -= i&-i){
            x += d[i];
        }
        return x;
    }
    T sum(int l, int r){
        return sum(r-1) - sum(l-1);
    }
};

int main(){
    int n,q;
    cin >> n >> q;
    ve<int> a(n);
    rep(i,n) cin >> a[i];
    ve<int> pi(n+1,-1);
    ve<ve<int>> ps(n);
    rep(i,n){
        int l = pi[a[i]];
        if(l != -1) ps[l].push_back((int)i);
        pi[a[i]] = (int)i;
    }
    
    ve<ve<P>> qs(n);
    rep(qi,q){
        int l,r;
        cin >> l >> r;
        l--; r--;
        qs[l].push_back(P(r,qi));
    }
    
    ve<int> ans(q);
    BIT<int> d(n);
    for(int x = n-1; x>=0; x--){
        for(int y: ps[x])d.add(y,1);
        for(P  query: qs[x]){
            int r = query.first, i = query.second;
            ans[i] = (r-x+1) - d.sum(r);
        }
    }
    rep(i,q)cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 62956
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
 
using namespace std;
 
int main()
{
    int n;
    long long d;
    int count = 0;
    long long a, b;
 
    cin >> n >> d;
 
    d *= d;
 
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        if (a * a + b * b <= d)
        {
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    long long int a,b,k;
	cin>>a>>b>>k;
	if(k>0 && k>=a)
	{
		k-=a;
		a=0;
	}
	else
    {
      a-=k;
      k=0;
    }
	if(k>0 && k>=b)
	{
		k-=b;
		b=0;
	}
	else
	b-=k;
	printf("%lld %lld",a,b);
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll ans=0;

    for(int i=0; i<n; i++){
        while(true){
            if(a[i]%2==0){
                a[i]/=2;
                ans++;
            }
            else break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3684
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 getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt64(scanner)
	m := getNextInt64(scanner)

	var ans int64
	if n*2 >= m {
		ans = m >> 1
	} else {
		ans = n + (m-n<<1)>>2
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define MAX_H 20
#define MAX_W 20
typedef pair<int, int> P;
char maze[MAX_H][MAX_W+1];
char maze_origin[MAX_H][MAX_W+1];
int d[MAX_H][MAX_W];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int bfs(int H, int W, int sx, int sy){
    queue<P> que;                
    //初期化
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            maze[h][w] = maze_origin[h][w];
            d[h][w] = INF;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;
    while(que.size()){
        P p = que.front();
        que.pop();
        for(int i = 0; i < 4; i++){
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];

            if(0<=nx && nx < H && 0<=ny && ny < W && maze[nx][ny] != '#' && d[nx][ny] == INF){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] +1;
            }
            
        }
    }

    int maxd=0;
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            if(d[h][w]==INF) continue;
            maxd = max(maxd, d[h][w]);
            //cout << "d(" << h << "," << w <<  ")" << d[h][w] << endl;
        }
    }
    return maxd;
}


int main(){
    ll H,W;
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> maze_origin[i][j];
        }
    }

    //start
    int ans=0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){

            if( maze_origin[i][j] == '#') continue;
            int ret = bfs(H,W,i,j);
            //cout << ret << endl;
            ans = max( ans, ret );
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		System.out.println(n % k == 0 ? 0 : 1);
	}
}


Measured memory_bytes: 35528
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;


int main()
{
    int n;
    int m;
    int l[100005];
    int r[100005];
    
    cin >> n >> m;
    
    int left = 1;
    int right = n;
    for (int i = 0;i < m;i++){
        cin >> l[i] >> r[i];
        if (left < l[i]){
            left = l[i];
        }
        if (right > r[i]){
            right = r[i];
        }
    }
    if (right >= left){
        cout << right - left + 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}


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

using namespace std;

typedef long long ll;

int main(){
	int n, k;
	cin >> k >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int maxi = 0, tot = 0;
	for(int i = 0; i < n - 1; i++){
		maxi = max(maxi, a[i + 1] - a[i]);
	}
	maxi = max(maxi, k + a[0] - a[n - 1]);
	cout << k - maxi << '\n';
}


Measured memory_bytes: 4404
#include<iostream>
using namespace std;
int main(){
	int n,m,p;
	while(cin>>n>>m>>p,n){
		int ans=0,d[n];
		double sum=0.0;
		for(int i=0;i<n;i++){
			cin>>d[i];
			sum+=d[i];
		}
		sum*=100;
		sum-=sum*(p*1.0/100);
		if(d[m-1]){
			ans=sum/d[m-1];
			cout<<ans<<endl;
		}
		else
		cout<<0<<endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	string s;
	cin >> s;
	int a = 0, b = 1;
	while(a<s.size()){
		if(s.at(a) == 'R' || s.at(a) == 'U' || s.at(a) == 'D'){
			a += 2;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	while(b<s.size()){
		if(s.at(b) == 'L' || s.at(b) == 'U' || s.at(b) == 'D'){
			b += 2;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

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

    
    double p_sum = 0;

    for(int i=1;i<=N;i++){
        double p = 1.0/N;
        int j = i;
        while(j<K){
            j *= 2;
            p /= 2;

        }
        p_sum += p;
    }

    cout << setprecision(13) << p_sum << endl;

    return 0;
}

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

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
#define inf 200007
#define P pair<ll,ll>

using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int ans=0,flag=0;
    vi a(n+1,10),visited(n+1,false);
    pan(i,m){
        int s,c;
        cin>>s>>c;
        if(a[s]==c || visited[s]==false){
            a[s]=c;
            visited[s]=true;
        }
        else{
            flag=true;
            break;
        }
    }
    if(flag) cout<<-1;
    else{
        if(n==1){
            if(a[1]==10) ans=0;
            else ans=a[1];
        }
        else{
            pans(i,4,1){
                if((a[1]==0)){
                    ans=-1;
                    break;
                }
                if(a[i]==10 && i==1) a[i]=1;
                else if(a[i]==10) a[i]=0;
                ans+=a[i]*pow(10,n-i);
            }
        }
        cout<<ans;
    }
}   

Measured memory_bytes: 256
gets

a = gets.chomp.split(" ").map(&:to_i)

gets.to_i.times{
    b, m, e = gets.split.map(&:to_i)
    rot = a[b...e]
    #puts "berfore rot = #{rot}"
    rot.rotate!(m-e)
    #puts "after rot = #{rot}"
    a[b...e] = rot
    #puts "current: #{a.join(' ')}"
}
puts a.join(' ')


Measured memory_bytes: 8716
list = [0]*26
while 1:
    try:
        a = input()
        for i in a: 
            for j in range(26):
                if ord(i) == j+65 or ord(i) == j+97:list[j] += 1
    except:break
for k in range(26):
    print(chr(k+97)+ " : "+str(list[k]))
    



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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
    bool ret = true;
    if (x < 2) {
        ret = false;
    }
    for (LL i = 2; i <= sqrt(x); i++) {
        if (x%i == 0) {
            ret = false;
        }
    }
    return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code
int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    int count_odd = 0;
    int count_2 = 0;
    int count_4 = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 1) {
            count_odd++;
        }
        else if (a % 4 == 0) {
            count_4++;
        }
        else {
            count_2++;
        }
    }

    if (count_2) {
        if (count_odd  <= count_4 ) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        if (count_odd <= count_4 + 1) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        
        char[] buf = S.toCharArray();
        
        int[] acCnt = new int[S.length()];
        acCnt[0] = 0;
        int sumCnt = 0;

        for (int i = 1; i < S.length(); ++i) {
        
            if ( (buf[i - 1] == 'A')  && (buf[i] == 'C') ) {
                ++sumCnt;
            }
            acCnt[i] = sumCnt;
        }
        
        for (int i = 0; i < Q; ++i) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int cnt = acCnt[r] - acCnt[l];
            System.out.println(cnt);
        }
        
    }
}


Measured memory_bytes: 67340
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
u = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    u.union(a, b)

h = {}
for i in range(N):
    h[u.find(i)] = True

print(len(h)-1)


Measured memory_bytes: 79112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D,T,S;
    cin >> D >> T >> S;
    cout << (S*T>=D? "Yes\n":"No\n");
}

Measured memory_bytes: 3648
// 27DTG
// 04072020
#include<bits/stdc++.h>
using namespace std;
#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef long double ld;
const ld pi=3.1415926535897932384626433;
const int mod = 1e9+7;
int main()
{
   bolt;
   ll n;
   cin>>n;
   ll k=ceil(1.0*n/1000);
   cout<<k*1000-n;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<functional>
#include<map>
using namespace std;
typedef long long ll;
int main()
{
	int a;
	cin>>a;
	cout<<24-a+24<<endl;
	return 0;
}


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

#define int long long

struct Dinic {
  const int INF = 1<<28;
  
  struct FlowEdge {    
    int to, cap, rev;
    FlowEdge() {}
    FlowEdge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
  };

  int n;
  vector<vector<FlowEdge> > G;
  vector<int> level, iter;

  Dinic() {}
  Dinic(int sz) : n(sz), G(n), level(n), iter(n) {}
  
  void add_edge(int from, int to, int cap) {
    G[from].push_back(FlowEdge(to, cap, G[to].size()));    
    // undirected
    //G[to].push_back(FlowEdge(from, cap, G[from].size()-1));
    // directed
    G[to].push_back(FlowEdge(from, 0, G[from].size()-1));    
  }
  
  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> Q;
    level[s] = 0;
    Q.push(s);
    while ( !Q.empty() ) {
      int v = Q.front(); Q.pop();
      for ( int i = 0; i < (int)G[v].size(); i++ ) {
	FlowEdge &e = G[v][i];
	if ( e.cap > 0 && level[e.to] < 0 ) {
	  level[e.to] = level[v]+1;
	  Q.push(e.to);
	}
      }
    }
  }
  
  int dfs(int v, int t, int f) {
    if ( v == t ) return f;
    for ( int &i = iter[v]; i < (int)G[v].size(); i++ ) {
      FlowEdge &e = G[v][i];
      if ( e.cap > 0 && level[v] < level[e.to] ) {
	int d = dfs(e.to,t,min(f,e.cap));
	if ( d > 0 ) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s, int t, int lim) {
    int flow = 0;
    while ( 1 ) {
      bfs(s);
      if ( level[t] < 0 || lim == 0 ) return flow;
      fill(iter.begin(), iter.end(), 0);
      int f;
      while ( (f=dfs(s, t, lim)) > 0 ) {	
	flow += f;
	lim -= f;
      }
    }
  }

  int max_flow(int s, int t){
    return max_flow(s, t, INF);
  }

  /*
    get_cut() is used ONLY after using max_flow()
    (because get_cut needs the infomation of level)
    
    @ret 
    infomation about the graph after using max_flow()    
    if res[i] == false, vertex i belongs to same set as s
    else vertex i belongs to same set as t
  */  
  vector<bool> get_cut(int s, int t) {
    vector<bool> res(n);
    for ( int i = 0; i < n; i++ ) {
      res[i] = (level[i] == -1);      
    }
    return res;  
  }
};

signed main(){
  int V,E;
  cin >> V >> E;
  
  Dinic dinic(V);
  for ( int i = 0; i < E; i++ ) {
    int u, v, c;
    cin >> u >> v >> c;
    dinic.add_edge(u, v, c);
  }
  
  cout << dinic.max_flow(0,V-1) << endl;
  
  return 0;
}





Measured memory_bytes: 3188
s = list(input())
q = int(input())
a = []
f = False #さかさま
for i in range(q):
    x = list(input().split())
    if x[0]=='1':
        f = not f
    else:
        if f:
            if x[1]=='1': s.append(x[2])
            else: a.append(x[2])
        else:
            if x[1]=='1': a.append(x[2])
            else: s.append(x[2])
a.reverse()
s = a+s
if f:s.reverse()
print(''.join(s))

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1000005

int n , x;
int a[MAXX];
bool used[MAXX];
int p[MAXX];

int main()
{
    _FastIO;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        used[a[i]] = true;
        p[a[i]]++;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
            p[a[i]]--;
            if(!p[a[i]])
                used[a[i]] = false;
            bool flag = true;
        for(int j = 1; j * j <= a[i]; j++){
            if(a[i] % j == 0){
                if(used[j]){
                    flag = false;
                    break;
                }
                int k = a[i] / j;
                if(used[k]){
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
            ans++;
        p[a[i]]++;
        used[a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}


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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int N = 5001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
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 << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int n, a[N * 3], b[N];
char s1[N], s2[N];

int solve() {
	int l1 = 0, l2 = 0;
	for(int i = 1; i <= n; i++) a[++l1] = 0;
	for(int i = 1; i < n; i++) if(s1[i] == '0' && s1[i + 1] == '1') a[++l1] = i;
	for(int i = 1; i < n; i++) if(s2[i] == '0' && s2[i + 1] == '1') b[++l2] = i;
	for(int i = 1; i <= n; i++) a[++l1] = n;
	int hh = 999999999;
	for(int i = 1; i <= l1 - l2 + 1; i++) {
		int ans = 0;
		for(int j = 1; j < i; j++) ans += a[j];
		for(int j = 0; j < l2; j++) ans += abs(b[j + 1] - a[j + i]);
		for(int j = l2; j < l1 - i; j++) ans += n - a[j + i];
		hh = _min(hh, ans);
	} return hh;
}

int main() {
	n = read();
	scanf("%s%s", s1 + 1, s2 + 1);
	if(n == 1 && s1[1] != s2[1]) puts("1");
	else if(n == 2 && s1[1] != s2[1] && s1[2] != s2[2]) puts("2");
	else {
		int ans = solve();
		for(int i = 1; i <= n; i++) s1[i] ^= 1, s2[i] ^= 1;
		ans += solve();
		put(ans), puts("");
	} return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define double long double
#define f(i,x,y,z) for(int i=x;i<y;i+=z)
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
ll gcd(ll,ll);
ll lcm(ll,ll);
bool prime(ll x);
ll fp(ll b,ll p,ll m);
ll inv(ll a,ll m);
int main(){
    fast;
    int a,b;
    cin>>a>>b;
    cout<<a*b<<'\n';
}
ll gcd(ll x,ll y) { return (y==0)? x: gcd(y,x%y);}
ll lcm(ll x, ll y) { return (x*y)/gcd(x,y);}
ll inv(ll a,ll m){return fp(a,m-2,m);}
bool prime(ll x){
    if(x<2) return false;
    if(x<4) return true;
    if(x%2==0 or x%3==0) return false;
    f(i,5,sqrt(x)+1,6)
        if(x%i==0 or x%(i+2)==0) return false;
    return true;
}
ll fp(ll b,ll p,ll m){
    b%=m;
    ll res=1;
    while(p>0){
        if(p%2==1)
            res=(res*b)%m;
        b=(b*b)%m;
        p=p/2;
    }
    return res%m;
}

Measured memory_bytes: 3692
#include<stdio.h>
int main(){
  int n, i, j, k, v;
  int A[1000];

  scanf("%d\n",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  for(k = 0 ; k < n ; k++){
    if(k == n - 1)printf("%d",A[k]);
    else printf("%d ",A[k]);
  }
  printf("\n");

  for(i = 1 ; i < n ; i++){
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
      A[j + 1] = v;
    }
    for(k = 0 ; k < n ; k++){
      if(k == n - 1)printf("%d",A[k]);
      else printf("%d ",A[k]);
      }
      printf("\n");
    
  }
  return 0;
}



Measured memory_bytes: 2128
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		String s = sc.next();
		char[] s_chars = s.toCharArray();
		
		int cnt = 0;
		for(int i = 0;i < n-2;i++){
		    if(s_chars[i] == 'A'){
		        if(s_chars[i+1]=='B' && s_chars[i+2]== 'C'){
		            cnt++;
		        }
		    }
		}
		
		System.out.println(cnt);
		
      
	}
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

vector<vector<pii>> r;
const ll INF = 1LL<<60;
VL dijkstra(int s ){
	priority_queue< pii, vector<pii>, greater<pii> > que;
	VL d(sz(r), INF);
	d[s] = 0;
	que.push(pii(0, s));  //cost, from
	while(!que.empty()){
		ll cost, v; tie(cost, v) = que.top();
		que.pop();
		if(d[v] < cost) continue;
		for(const auto& rp : r[v]){ 
			ll rct, rto; tie(rto, rct) = rp;
			if(d[rto] > d[v] + rct){
				d[rto] = d[v] + rct;
				que.push(pii(d[rto], rto));
			}
		}
	}
	return d;
}
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<VI> dt(n-1, VI(3));
	r.resize(n);
	rep(i, n-1){
		int u, v, w;
		cin >>u >>v >>w;
		r[u-1].emplace_back(v-1, w);
		r[v-1].emplace_back(u-1, w);
	}
	auto rv = dijkstra(0);
	rep(i, n){
		cout << (rv[i]%2? 1:0) <<"\n";
	}
	
	return 0;
}


Measured memory_bytes: 12672
#include <iostream>
#include <cmath>
 
using namespace std;
int main(){
	int n, tt, tx, ty; 
	int t = 0, x = 0, y = 0, flag = 0;
	cin >> n;
	for (int i = 0; i<n; i++){
		cin >> tt >> tx >> ty;
		if (abs(tx - x) + abs(ty - y)>(tt - t) || (abs(tx - x) + abs(ty - y)) % 2 != (tt - t) % 2)
			flag = 1;
		t = tt;
		x = tx;
		y = ty;
	}
	if (!flag)	cout << "Yes" << endl;
	else	cout << "No" << endl;
 
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a[200000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i+1;
	}
	sort(a, a+n);
	ll center;
	if(n % 2 == 0) center = (a[n/2-1]+a[n/2])/2;
	else center = a[n/2];
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs((ll)a[i] - center);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
S=input()
T=input()

for i in range(len(S)):
    if S[i]!=T[i]:
        print("No")
        exit()

print("Yes")


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

using namespace std;

#define INF 1000000007

const int MOD = 1000000000 + 7;

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<ll,ll> pll;

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

  if(k > (n - 1) * (n - 2) / 2) {
    printf("-1\n");
    return 0;
  }

  vector<vector<int>> edges; edges.clear();
  for(int i = 2; i <= n; ++i) {
    edges.push_back({1, i});
  }

  int remain = (n - 1) * (n - 2) / 2 - k;
  for(int i = 2; i <= n; ++i) {
    for(int j = 2; j < i; ++j) {
      if(remain > 0) {
        edges.push_back({i, j});
        --remain;
      }
    }
  }

  printf("%lu\n", edges.size());
  for(auto x: edges) printf("%d %d\n", x[0], x[1]);

  return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

class Circle
{
    static void Main()
    {
            string str;
            {
                str = Console.ReadLine();
                double a = double.Parse(str);
                Console.WriteLine("{0:f6} {1:f6}", a * a * Math.PI, 2*a * Math.PI);
            }
    }
}

Measured memory_bytes: 5776
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <ctime>
#include <map>
#include <set>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

#define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n')

#define I_int ll
inline I_int read() {
    I_int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
char F[200];
inline void write(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int

}
using namespace io;

using namespace std;

#define N 1000100
int n = read(), m = read(), c = read();
int b[N], a[N],ans;
int main(){
	for(int i = 1; i <= m; ++i) in(b[i]);
	for(int i = 1; i <= n; ++i) {
		ll sum = c;
		for(int j = 1; j <= m; ++j) {
			int x = read();
			sum += b[j]*x;
		}
		if(sum > 0)++ans;
	}
	outn(ans);
}

Measured memory_bytes: 2304
N = gets.to_i
A = gets.split(" ").map(&:to_i)

b = [A[0]]
1.upto(N - 1) do |i|
  b[i] = b[i-1].gcd A[i]
end

c = Array.new(N, 1)
i = N - 2
c[N - 1] = A[N-1]
while i >= 0
  c[i] = A[i].gcd(c[i+1])
  i-= 1
end

max = [b[N-2], c[1]].max

1.upto(N-2) do |i|
  v = b[i-1].gcd(c[i+1])
  max = [max, v].max
end
# p b
# p c
puts max


Measured memory_bytes: 12756
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};


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

    int H,W;
    cin>>H>>W;
    char C[22][22];
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++) cin>>C[i][j];
    }
    int ans=0;
    for(int si=1;si<=H;si++){
        for(int sj=1;sj<=W;sj++){
            if(C[si][sj]=='#') continue;
            int z[21][21];
            for(int ii=0;ii<21;ii++){
                for(int jj=0;jj<21;jj++) z[ii][jj]=MAX;
            }
            queue<P> que;
            que.push(P(si,sj));
            z[si][sj]=0;
            while(!que.empty()){
                P x=que.front(); que.pop();
                int i=x.first,j=x.second;
                for(int k=0;k<4;k++){
                    int ni=i+dx[k],nj=j+dy[k];
                    if(ni<=H && ni>=1 && nj<=W && nj>=1 && C[ni][nj]=='.' && z[ni][nj]==MAX){
                        z[ni][nj]=z[i][j]+1;
                        que.push(P(ni,nj));
                        chmax(ans,z[ni][nj]);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = 10000000
l = 0
for i in range(100):
  s = 0
  for j in range(n):
    s += pow((a[j]-(i+1)), 2)
  ans = min(s, ans)
  if(ans == s):
    l = i+1
print(ans)

      


Measured memory_bytes: 9188
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 10005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,a[MAXN],poly[MAXN];
set<int> ans;
int prime[10*MAXN];
bool is_prime[10*MAXN];
int sieve(int n)
{
    memset(is_prime,true,sizeof(is_prime));
    is_prime[0]=is_prime[1]=false;
    int p=0;
    for(int i=2;i<=n;i++)
    {
        if(is_prime[i]) prime[p++]=i;
        for(int j=0;j<p;j++)
        {
            if(prime[j]*i>n) break;
            is_prime[prime[j]*i]=false;
            if(i%prime[j]==0) break;
        }
    }
    return p;
}
mt19937 wcy(time(NULL));
int main()
{
    int p=sieve(100000);
    scanf("%d",&n);
    for(int i=0;i<=n;i++) scanf("%d",&a[i]);
    reverse(a,a+n+1);
    int g=0;
    for(int i=0;i<=n;i++) g=__gcd(g,a[i]);
    g=abs(g);
    for(int i=0;i<p;i++) 
    {
        int cnt=0;
        while(g%prime[i]==0) g/=prime[i],cnt++;
        if(cnt) ans.insert(prime[i]);
    }
    if(g!=1) ans.insert(g);
    for(int i=0;i<p;i++)
    {
        if(prime[i]>n) break;
        if(ans.count(prime[i])) continue;
        bool f=true;
        memset(poly,0,sizeof(poly));
        if(a[0]%prime[i]!=0) continue;
        for(int j=0;j<=n;j++) poly[j%(prime[i]-1)]=(poly[j%(prime[i]-1)]+a[j])%prime[i];
        for(int j=0;j<10;j++)
        {
            int x=0;
            while(x==0) x=wcy()%prime[i];
            int res=1,sum=0;
            for(int k=0;k<=prime[i]-2;k++)
            {
                sum=(sum+1LL*poly[k]*res)%prime[i];
                res=1LL*res*x%prime[i];
            }
            if(sum!=0) {f=false; break;}
        }
        if(f)
        {
            for(int x=1;x<=prime[i]-1;x++)
            {
                int res=1,sum=0;
                for(int k=0;k<=prime[i]-2;k++)
                {
                    sum=(sum+1LL*poly[k]*res)%prime[i];
                    res=1LL*res*x%prime[i];
                }
                if(sum!=0) {f=false; break;}
            }
        }
        if(f) ans.insert(prime[i]);
    }
    for(auto x:ans) printf("%d\n",x);
    return 0;
}



Measured memory_bytes: 512