akhauriyash/Code-Regression huggingface dataset:
fn solve() {
    let mut n: i64 = read();
    let mut ans = String::new();
    while n != 0 {
        if n.abs() % 2 != 0 {
            ans.push('1');
            n -= 1;
        } else {
            ans.push('0');
        }
        n /= -2;
    }
    if ans.len() == 0 {
        ans.push('0');
    }
    println!("{}", ans.chars().rev().collect::<String>());
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2208
// https://atcoder.jp/contests/abc145/tasks/abc145_c

#include "algorithm"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

ll k(ll a) {
  if (a == 0) return 1;
  return a * k(a - 1);
}

double dist(PL a, PL b) {
  return sqrt((b.first - a.first) * (b.first - a.first) +
              (b.second - a.second) * (b.second - a.second));
}

void solve() {
  ll N;
  cin >> N;
  VPL ps(N);

  rep(i, N) {
    ll x, y;
    cin >> x >> y;
    ps[i] = {x, y};
  }

  double distSum = 0;

  ll kk = k(N - 2);
  rep(j, N) rep(i, j) { distSum += dist(ps[i], ps[j]) * 2 * k(N - 1); }

  double res = distSum / k(N);

  cout << fixed;
  cout << setprecision(10);
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& e : a) cin >> e;
    sort(begin(a), end(a));
    int s = unique(begin(a), end(a)) - begin(a);
    cout << n-(n-s+1)/2*2 << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
 
int main(void){
  //変数の定義
  int N,i;
  scanf("%d",&N);
  //iにNの１の位を代入
  i = N % 10;
  
  //iの値で場合わけ
  switch(i){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      printf("hon");
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      printf("pon");
      break;
    case 3:
      printf("bon");
      break;
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

vector<int> normalize(vector<int> &v) {
  vector<vector<int>> w;
  w.push_back(v);
  vector<int> next(4);
  for (int k = 0; k < 3; k++) {
    for (int j = 0; j < 4; j++) next[j] = w.back()[(j + 1) % 4];
    w.push_back(next);
  }
  sort(w.begin(), w.end());
  return w[0];
}

ll comb(ll n, ll k) {
  if (k == 1) {
    return n;
  } else if (k == 2) {
    return n * (n - 1);
  } else if (k == 3) {
    return n * (n - 1) * (n - 2);
  } else {
    return n * (n - 1) * (n - 2) * (n - 3);
  }
}

int weight(vector<int> v) {
  if (v[0] == v[1] && v[1] == v[2] && v[2] == v[3]) return 4;
  if (v[0] == v[2] && v[1] == v[3]) return 2;
  return 1;
}

ll po(ll e, ll x) {
  if (x == 1) return e;
  if (x == 2) return e * e;
  return e * e * e * e;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> c(n);
  map<vector<int>, int> mp;
  for (int i = 0; i < n; i++) {
    vector<int> v(4);
    for (int j = 0; j < 4; j++) cin >> v[j];
    auto w = normalize(v);

    mp[w]++;
    c[i] = w;
  }
  ll ans = 0;

  for (int i = 0; i < n; i++) {
    mp[c[i]]--;
    for (int j = i + 1; j < n; j++) {
      mp[c[j]]--;
      for (int k = 0; k < 4; k++) {
        map<vector<int>, int> want;
        for (int l = 0; l < 4; l++) {
          vector<int> side(4);
          side[0] = c[i][(l + k) % 4];
          side[1] = c[i][(l + k + 1) % 4];
          side[2] = c[j][(3 - l)];
          side[3] = c[j][(4 - l) % 4];
          reverse(side.begin(), side.end());
          want[normalize(side)]++;
        }

        ll tmp = 1;
        for (auto &pr : want) {
          tmp *= comb(mp[pr.first], pr.second) * po(weight(pr.first), pr.second);
        }
        ans += tmp;
      }
      mp[c[j]]++;
    }
    mp[c[i]]++;
  }

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


Measured memory_bytes: 140032
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll h; cin>>h;
	ll ct=1, ret=0;
	while(h)
		ret+=ct, ct<<=1, h>>=1;
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n , k;
    cin >> n >> k;

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

    int b[200010]{0};
    for(int i = 0; i < n; i++)
    {
        b[a[i]]++;
    }
    sort(b,b+200010);

    int cntKind = 0;
    for(int i = 200010 - n; i < 200010; i++)
    {  
        if(b[i] != 0) cntKind++;
    }

    int fixKind = cntKind - k;
    if(fixKind < 0) fixKind = 0;

    int cntFix = 0;
    for(int i = 200010 - cntKind; i < 200010; i++)
    {  
        if(fixKind == 0) break;
        fixKind --;
        cntFix += b[i];
    }

    cout << cntFix << endl;
}
 

Measured memory_bytes: 1792
#include"bits/stdc++.h"
#include"math.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std; 
typedef long long ll;
int main(){ 
  string s; int k;
  cin >> s >> k;
  ll count=0, x=0,y=0;
  ll n=s.size();
  for(ll i=0;i<n-1;i++){
    if(s[0]==s[i+1]){
      
      x++;}
    else if(s[0]!=s[i+1]){
      break;}}
  for(ll i=n-2;i>=0;i--){
    if(s[n-1]==s[i]){
    y++;}
    else{break;}}
  ll z=0;
  if(s[0]==s[n-1]){
    z=x+y;
  }
  for(ll i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      count++;i++;}}
    count = count*k;
 if(z==2*n-2){
    cout << (n*k)/2 << endl;}
  else if(z==0){
    cout << count << endl;}
  
 else{
    cout << count-(((x+1)/2+(y+1)/2-(x+y+2)/2))*(k-1) << endl;}}


Measured memory_bytes: 256
N = int(input())
cities = []
cities_index_points = {}

for i in range(N):
    s,p = input().split()
    p = int(p)
    cities.append(s)
    try:
        x = cities_index_points[s]
        x.append((i,p))
    except:
        cities_index_points[s] = [(i,p)]

cities = sorted(set(cities))

for c in cities:
    iplist = cities_index_points[c]
    iplist.sort(key=lambda x: x[1], reverse=True)
    for ip in iplist:
        print(ip[0]+1)


Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[31][2];
int l[55][1000100];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[100333];

P u[100011];
queue<int> q;

//stack<int> s;
set<int> s;
map<long long,int> p;
vector<int> v,v1;

bool as(P a,P b)
{
  return a.y<b.y;
}

int f(int n,int m,int c)
{
  if(c>a) return 0;
  if(l[n][m]>=0) return l[n][m];
  int x=mod,e=0;
  for(int i=1,p=1;i<=a;p*=2,i++)
  if((m&p)==0&&o[i][(i-c+10000)%2]>=n)
  {
    //puts("#");
    x=min(x,e+f(o[i][(i-c+10000)%2],m+p,c+1));
    //printf("#%d %d %d %d\n",i,x,c,m);
    e++;
  }
  else if((m&p)==0) e++;
  return l[n][m]=x;
}

int main()
{
  memset(l,-1,sizeof(l));
  scanf("%d",&a);
  for(int i=0;i<2;i++)
  for(int t=1;t<=a;t++)
    scanf("%d",&o[t][i]);
  k=f(0,0,1);
  if(k<mod) printf("%d",k);
  else puts("-1");
}



Measured memory_bytes: 215168
//int ask(ll n){
//    cout << "? " << n << endl;
//    char re;
//    cin >> re;
//    return re == 'Y';
//}
//void answer(ll n){
//    cout << "! " << n << endl;
//    exit(0);
//}
//void special(){
//    ll p = 9;
//    ll ans = 1;
//    while(!ask(p)){
//        p *= 10;
//        ans *= 10;
//    }
//    answer(ans);
//}
//void __(){
//    if(ask(ll(1e10))){
//        special();
//    }
//    ll sz = 1, p10 = 10;
//    while(ask(p10)){
//        ++sz;
//        p10 *= 10;
//    }
//    ll lo = p10/10, hi = p10-1, mid;
//    while(lo < hi){
//        mid = (lo+hi)/2;
//        ll mult = ll(1e9);
//        if(ask(mult*mid))
//            hi = mid;
//        else
//            lo = mid+1;
//    }
//    answer(lo);
//}
//
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
int ask(ll n){
    cout << "? " << n << endl;
    char re;
    cin >> re;
    return re == 'Y';
}
void answer(ll n){
    cout << "! " << n << endl;
    exit(0);
}
void special(){
    ll p = 9;
    ll ans = 1;
    while(!ask(p)){
        p *= 10;
        ans *= 10;
    }
    answer(ans);
}
void __(){
    if(ask(ll(1e10))){
        special();
    }
    ll sz = 1, p10 = 10;
    while(ask(p10)){
        ++sz;
        p10 *= 10;
    }
    ll lo = p10/10, hi = p10-1, mid;
    while(lo < hi){
        mid = (lo+hi)/2;
        ll mult = ll(1e9);
        if(ask(mult*mid))
            hi = mid;
        else
            lo = mid+1;
    }
    answer(lo);
}
int main(){
    cout << fixed << setprecision(15);
        __();
}


Measured memory_bytes: 684
import itertools
import math
from sys import stdin
input = stdin.readline


def main():
  N, D = list(map(int, input().split()))
  XY = [tuple(map(int, input().split())) for _ in range(N)]

  cnt = 0
  for i in range(N):
    x, y = XY[i]
    d = math.sqrt(x**2 + y**2)
    if d <= D:
      cnt += 1

  print(cnt)


if(__name__ == '__main__'):
  main()


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

int main() {
  int N, K;
  cin >> N >> K;
  int x, result = 0;
  for (int i = 0; i < N; ++i) {
    cin >> x;
    if (K - x < x) {
      result += 2 * (K - x);
    } else {
      result += 2 * x;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var ans,s;

console.log(main());
function main(){
  var h = o.a();
  var w = o.a();
  var k = o.a();
  s = o.r(h,1);
  ans = xArray(1,h,w);
  solve(0,0,h,w,1,k);
  return ans.map(a=>a.join(" ")).join("\n");
}

function solve(y,x,h,w,id,k){
  if(k === 1){
    for(var y3 = y; y3 < h; y3++)
    for(var x3 = x; x3 < w; x3++){
      ans[y3][x3] = id;
    }
    return;
  }
  var y2 = xArray(0,h-y);
  var x2 = xArray(0,w-x);
  for(var y3 = y; y3 < h; y3++){
    for(var x3 = x; x3 < w; x3++){
      if(s[y3][x3] === "#"){
        y2[y3-y]++;
        x2[x3-x]++;
      }
    }
  }
  for(var y3 = y+1; y3 < h; y3++)y2[y3-y] += y2[y3-y-1];
  for(var x3 = x+1; x3 < w; x3++)x2[x3-x] += x2[x3-x-1];
  if(x + 1 === w)return f(y,x,h,w,id,k,y2);
  var xf = x+w>>1;
  xf-= x;
  if(x2[xf] === 0){
    while(++xf){
      if(x2[xf] !== 0)break;
    }
    if(x2[xf] === k)return f(y,x,h,w,id,k,y2);
  }
  if(x2[xf] === k){
    while(--xf){
      if(x2[xf] !== k)break;
    }
    if(x2[xf] === 0 || x2[xf] === k)return f(y,x,h,w,id,k,y2,k);
  }
  solve(y,x,h,xf+x+1,id,x2[xf]);
  solve(y,xf+x+1,h,w,id+x2[xf],k-x2[xf]);
}

function f(y,x,h,w,id,k,y2){
  var yf = y+h>>1;
  yf -= y;
  if(y2[yf] === 0){
    while(++yf){
      if(y2[yf] !== 0)break;
    }
  }else if(y2[yf] === k){
    while(--yf){
      if(y2[yf] !== k)break;
    }
  }
  solve(y,x,yf+y+1,w,id,y2[yf]);
  solve(yf+y+1,x,h,w,id+y2[yf],k-y2[yf]);
}

Measured memory_bytes: 21304
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

bool empty(vector<int> &vi){ return vi.empty(); }


int main(){
  int m;
  while(cin >> m && m){
    int I, J;
    vector<vector<int> > vvi;
    for(int i = 1; i <= m; i++){
      vector<int> vi;
      vi.push_back(i);
      vvi.push_back(vi);
    }
		   
    while(cin >> I >> J && (I || J)){
      if(I == J) continue;
      if(J == 0){
	bool ok = false;
	for(int i = 0; i < (int)vvi.size(); i++){
	  for(int j = 0; j < (int)vvi[i].size(); j++){
	    if(vvi[i][j] == I){
	      ok = true;
	      if(j != 0){
		if(j == ((int)vvi[i].size() - 1)){
		  vector<int> vi;
		  vi.push_back(I);
		  vvi[i].pop_back();
		  vvi.push_back(vi);
		  
		}else{
		  int c = vvi[i].size() - j;
		  for(int k = 0; k < c; k++){
		    vector<int> vi(1, vvi[i][vvi[i].size() - 1]);
		    vvi[i].pop_back();
		    vvi.push_back(vi);
		  }
		  
		}
		
	      }
	      break;
	    }
	  }
	  if(ok) break;
	}
      }else{
	P pi, pj;
	for(int i = 0; i < (int)vvi.size(); i++){
	  for(int j = 0; j < (int)vvi[i].size(); j++){
	    if(vvi[i][j] == I) pi = P(i, j);
	    if(vvi[i][j] == J) pj = P(i, j);
	  }
	}
	if(pi.first == pj.first) {
	  if(pi.second < pj.second){	

	    int c = vvi[pi.first].size() - pi.second - 1;
	    for(int i = 0; i < c; i++) {
	      vector<int> vi(1, vvi[pi.first][vvi[pi.first].size() - 1]);
	      vvi[pi.first].pop_back();
	      if(vi[0] == J) vi.push_back(I);
	      vvi.push_back(vi);
	    }
	    vvi[pi.first].pop_back();
	  }
	}else{
	  if(vvi[pi.first].size() - pi.second == 1){
	    vvi[pi.first].pop_back();
	    vvi[pj.first].push_back(I);
	  }else{
	    int c = vvi[pi.first].size() - pi.second;
	    for(int i = 0; i < c - 1; i++){
	      vector<int> vi(1, vvi[pi.first][vvi[pi.first].size() - 1]);
	      vvi.push_back(vi);
	      vvi[pi.first].pop_back();
	    }
	    vvi[pi.first].pop_back();
	    vvi[pj.first].push_back(I);
	  }
	  
	}
      }
    
      vvi.erase(remove_if(vvi.begin(), vvi.end(), empty), vvi.end());
    
    }
    vector<int> res;
    for(int i = 0; i < (int)vvi.size(); i++) res.push_back((int)vvi[i].size());
    sort(res.begin(),res.end());
    for(int i = 0; i < (int)res.size(); i++){
      cout << res[i]<< endl;
    }
    cout << "end" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

const int MOD = 1000000007;

long long pow(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n % 2 == 1) res = res * x % MOD;
    x = x * x % MOD;
    n = n / 2;
  }
  return res;
}

long long modInverse(long long x) {
  return pow(x, MOD - 2);
}

long long fact[100005];

int main() {
  fact[0] = 1;
  for (int i = 1; i <= 100000; ++i) {
    fact[i] = fact[i - 1] * i % MOD;
  }

  int N, M;
  cin >> N >> M;

  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }
  if ((N + M) & 1) {
    cout << fact[N] * fact[M] % MOD << endl;
  } else {
    cout << fact[N] * fact[M] % MOD * 2 % MOD << endl;
  }
}


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


int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--, t--;
  vector<vector<int>> graph(n, vector<int>());
  for (int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  vector<vector<int>> dists(n, vector<int>(2, 2147483647 / 2));
  dists[s][0] = 0;
  queue<pair<int, int>> q{};
  q.push(make_pair(s, 0));
  while (q.size() >= 1){
    auto elem = q.front();q.pop();
    auto parity = elem.second;
    auto ind = elem.first;
    auto dist = dists[ind][parity];
    for (auto&& item : graph[ind]){
      if (dists[item][parity ^ 1] <= dist + 1) continue;
      dists[item][parity ^ 1] = dist + 1;
      q.push(make_pair(item, parity ^ 1));
    }
  }
  if (dists[t][0] == 2){
    cout << 2 << endl;
    return 0;
  }
  if (dists[t][1] >= 10000000){
    cout << -1 << endl;
    return 0;
  }
  auto res = dists[t][1];
  while (true){
    if (res == 1) goto end;
    for (int i = 2; i * i <= res; i++){
      if (res % i == 0) goto end;
    }
    cout << res << endl;
    return 0;
  end:;
    res += 2;
  }
}



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


long long x, k, d, jumps, pp;
int main() {
	//freopen("input.txt", "r", stdin);
	cin >> x >> k >> d;
	x = abs(x);
	if(x > d) {
		jumps = x / d;
		pp = x;
		x = x % d;
		if(k > jumps) {
			k = k - jumps;
			if(k&1) {
				cout << abs(d - x) << '\n';
			} else {
				cout << x << '\n';
			}
			//cout << x << '\n';
		}
		else
			cout << abs(pp - k*d) << '\n';		
	}
	else if(d > x){
		if(k%2 == 0)
			cout << x << '\n';
		else
			cout << abs(d - x) << '\n';
	} else { //x == d
		if(k&1)
			cout << "0\n";
		else
			cout << x << '\n';	 
	}
	return 0;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main
{
	static int [] dp;
	static ArrayList<Integer>[] a;
	public static int solve(int i)
	{
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ret=0;
		for(int j=0;j<a[i].size();j++)
		{
			ret=Math.max(ret,solve(a[i].get(j))+1);
		}
		dp[i]=ret;
		return dp[i];
	}
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		a=new ArrayList[n];
		dp = new int [n];
		for(int i=0;i<n;i++)
		{
			dp[i]=-1;
			a[i]=new ArrayList<Integer>();
		}
		for(int i=0;i<m;i++)
		{
			int p=in.nextInt();
			int q=in.nextInt();
			a[p-1].add(q-1);
		}
		int ret=0;
		for(int i=0;i<n;i++)
		{
			ret=Math.max(ret,solve(i));
		}
		System.out.println(ret);
	}
}
	

Measured memory_bytes: 100636
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
bool used[410][410];
string ma[410];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int h,w;lint a,b;
void dfs(int x,int y){
	if(used[x][y]) return;
	used[x][y]=true;
	if(ma[x][y]=='.') a++;else b++;
	rep(i,4){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<0 || ny<0 || nx>=h || ny>=w) continue;
		if(ma[x][y]==ma[nx][ny]) continue;
		dfs(nx,ny);
	}
}
int main()
{
	cin>>h>>w;memset(used,false,sizeof(used));
	lint out=0;
	rep(i,h) cin>>ma[i];
	rep(i,h) rep(j,w){
		if(used[i][j]) continue;
		a=b=0;
		dfs(i,j);
		out+=a*b;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 18176
import java.util.Scanner;

public class Main {

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

		    int k = sc.nextInt();
		    int x = sc.nextInt();

		    for(int i=x-k+1;i<=x+k-1;i++) {
		    	System.out.print(i+" ");
		    }

		    sc.close();
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	string s;
	int A=0, B;
	cin >>s;
	rep(i, 6) {
		if (s.at(i)== '1') {
			A++;;
		}
	}
	
	cout << A<< endl;
}

Measured memory_bytes: 256
import java.util.*;
 import java.math.BigInteger;
public class Main
{
	static int ans[];
	public static  void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		// String h[]=sc.nextLine().split(" ");
		long n=Long.parseLong(sc.nextLine());
		String h[]=sc.nextLine().split(" ");
		Hashtable<Long,Integer>hash=new Hashtable<>();
		int flag=0;
		long s=0;
		hash.put(Long.parseLong(h[0]),1);
		for(long i=1;i<n;i++)
		{
			if(hash.containsKey(i-Long.parseLong(h[(int)i])))
			{
				s+=hash.get(i-Long.parseLong(h[(int)i]));
			}
			if(!hash.containsKey(i+Long.parseLong(h[(int)i])))
			{
				hash.put(Long.parseLong(h[(int)i])+i,0);
			}
			hash.put(Long.parseLong(h[(int)i])+i,hash.get(Long.parseLong(h[(int)i])+i)+1);
		}
		System.out.println(s);
		
	}
	static String get(long a, long b)
	{long y=1;
		while(true)
		{

			long z=y-a;
			long q=get2(y,z);
			// System
			if(q==b){return y+" "+z;}
			else if(q>b){return "-1";}
			y+=1;
		}
		// return "-1";
	}
	static long get2(long y, long z)
	{
		return (long)(Math.pow(y,4)+Math.pow(y,3)*z+Math.pow(y,2)*Math.pow(z,2)+y*Math.pow(z,3)+Math.pow(z,4));
	}
	static void get(ArrayList<ArrayList<Integer>>arr, int i , int p,int val[], int arr1[], int len)
	{
		for(int j=0;j<arr.get(i).size();j++)
		{
			if(ans[arr.get(i).get(j)]==0 && arr.get(i).get(j)!=p){
			if(val[arr.get(i).get(j)]>arr1[len-1])
			{
				arr1[len]=val[arr.get(i).get(j)];
				ans[arr.get(i).get(j)]=len+1;
				get(arr,arr.get(i).get(j),i,val,arr1,len+1);
				
			}
			else
			{
				int index=bin(arr1, val[arr.get(i).get(j)], len-1);
				ans[arr.get(i).get(j)]=len;
				// int g=arr1[index];
				arr1[index]=val[arr.get(i).get(j)];
				get(arr,arr.get(i).get(j),i,val,arr1,len);
				// arr1[index]=g;
			}}

		}
	}
	static int bin(int arr[], int val, int len)
	{
		if(arr[0]>=val){return 0;}
		int l=0;
		int r=len;
		while (r - l > 1) { 
            int m = l + (r - l) / 2; 
            if (arr[m] >= val) 
                r = m; 
            else
                l = m; 
        } 
  
        return r; 
		// return l;
	}
	
	

}
class Pair
{
	int a;
	int b;
	int c;
	int d;
	Pair(int e,int f, int g,int h){
		a=e;
		b=f;
		c=g;
		d=h;
	}
}



	


Measured memory_bytes: 91012
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll f[200011],n,m,w[110],c[110],ans;
int main()
{
	memset(f,0x7f,sizeof(f));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>w[i]>>c[i];
	f[0]=0;
	for(int i=1;i<=n;i++)
		for(int j=200010;j>=c[i];j--)
			f[j]=min(f[j],f[j-c[i]]+w[i]);
	for(int j=0;j<=200010;j++)
		if(f[j]<=m)
			ans=j;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2300
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//降順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int N;
    scanf("%d",&N);
    struct data whr[N];
    whr[0].a=0;whr[0].b=0;whr[0].c=0;
    for(int i=1;i<=N;i++){
        scanf("%d%d%d",&whr[i].a,&whr[i].b,&whr[i].c);
    }
    for(int i=0;i<N;i++){
        int sa=0;
        sa=(whr[i+1].a-whr[i].a);
        sa-=abs(whr[i+1].b-whr[i].b);
        if(sa<0){
            printf("No");
            return 0;
        }else{
            ;
        }
        sa-=abs(whr[i+1].c-whr[i].c);
        if(sa<0){
            printf("No");
            return 0;
        }else{
            ;
        }
        if(sa%2==1){
            printf("No");
            return 0;
        }else{
            ;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 1280
#line 1 "template.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b < 0) {
    cout << "No" << endl;
    return 0;
  }
  ll left = 4 * a * b;
  ll right = (c - a - b) * (c - a - b);
  cout << (left < right ? "Yes" : "No") << endl;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  int A,B;
  cin >> A >> B;
  
  if((A+B) >= 10) cout << "error" << endl;
  else cout << A+B << endl;
  
  return 0;
  
}


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

int main() {
    int n, m = 0, mini = 1000000005;
    bool zero = false;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        if(a[i] < 0) m++;
        else if(a[i] == 0) zero = true;
        mini = min(mini, abs(a[i]));
    }
    long long int ans = 0;
    for(int i = 0; i < n; ++i) ans += max(a[i], -a[i]);
    if(zero) cout << ans << '\n';
    else {
        if(m%2 == 0) cout << ans << '\n';
        else cout << ans - mini*2 << '\n';
    }
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

template<typename T>
void chmax(T& a,const T& b)
{
	a=max(a,b);
}

int main()
{
	for(int c,d,w,x;cin>>c>>d>>w>>x,c|d|w|x;){
		static int e[30][15],f[30][15];
		rep(i,c) rep(j,d) cin>>e[j][i];
		rep(i,c) rep(j,d) cin>>f[j][i];
		
		static int dp[31][6][1000]; // [日][2回以上ライブを行った回数][疲労]
		memset(dp,-1,sizeof dp);
		
		dp[0][0][0]=0;
		rep(i,d) rep(j,x+1) rep(k,1000){
			if(dp[i][j][k]==-1) continue;
			rep(l,c){
				chmax(dp[i+1][j][k],dp[i][j][k]);
				chmax(dp[i+1][j][k+f[i][l]],dp[i][j][k]+e[i][l]);
			}
			if(j==x) continue;
			rep(l,c){
				if(e[i][l]==0) continue;
				int esum=e[i][l],fsum=f[i][l];
				repi(r,l+1,c){
					if(e[i][r]==0) break;
					esum+=e[i][r];
					fsum+=f[i][r];
					chmax(dp[i+1][j+1][k+fsum],dp[i][j][k]+esum);
				}
			}
		}
		
		int res=0;
		rep(i,x+1) rep(j,w+1)
			chmax(res,dp[d][i][j]);
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1896
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define pb push_back
#define powerof2 ()
using ll = long long;
const ll M = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> is;
ll power(ll x,ll y){
    if(y==0)
    return 1;
    ll res=power(x,y/2);
    res=(res*res)%M;
    if(y&(ll)1)
    res=(res*x)%M;
    return res;
}


int n,q;string s;
vector<ll> t;

void build(int v,int a,int b)
{
    if(a==b){
    t[v]=1LL<<(s[a]-97);return;}
    int m=(a+b)/2;
    build(v*2,a,m);
    build(v*2+1,m+1,b);
    t[v]=t[v*2]|t[v*2+1];
}
void update(int v,int a,int b,int p,int va)
{
    if(a==b)
    {
        t[v]=1LL<<va;
        return;
    }
    int m=(a+b)/2;
    if(p<=m)
    update(v*2,a,m,p,va);
    else
    update(v*2+1,m+1,b,p,va);
    t[v]=t[v*2]|t[v*2+1];
}
ll ans(int v,int a,int b,int l,int r)
{
    if(r<l||r<a||b<l)
    return 0;
    if(a>=l&&b<=r)
    return t[v];
    int m=(a+b)/2;
    return ans(v*2,a,m,l,min(r,m))|ans(v*2+1,m+1,b,max(l,m+1),r);
}
void solve(){
    cin>>n>>s>>q;
    t.resize(4*n+20,0);
    build(1,0,n-1);
    while(q--)
    {
        int ty;
        cin>>ty;
        if(ty==1)
        {
            int in;char c;
            cin>>in>>c;in--;
            if(s[in]!=c){s[in]=c;
            update(1,0,n-1,in,c-97);}
        }
        else
        {
            int l,r;cin>>l>>r;
            l--;r--;
            ll va=ans(1,0,n-1,l,r);
            cout<<__builtin_popcount(va)<<endl;
        }
    }
}
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

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

int main() {
  string str;
  char one =' ';
  char two =' ';
  char zero =' ';
  bool chk = true;
  
  cin >> str;
  
  for(int i = 0; i < 4; i++){
    if(one == zero){
      one = str.at(i);
      continue;
    }else if(str.at(i) == one){
      continue;
    }
    
    if(two == zero){
      two = str.at(i);
      continue;
    }else if(str.at(i) == two){
      continue;
    }
    
    chk = false;
    break;
  }
  
  if(chk == false || two == zero) cout << "No";
  else cout << "Yes";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<string.h>
#include<set>
#include<map>
#define LL long long
#define pr pair<int,int>
#define fr first
#define sc second
//#define mp make_pair
using namespace std;
LL read( ){LL sum=0;char c=getchar( );bool f=0;while(c<'0' || c>'9') {if(c=='-') f=1;c=getchar( );}while(c>='0' && c<='9') {sum=sum*10+c-'0';c=getchar( );}if(f) return -sum;return sum;}
void read(int &sum){sum=0;char c=getchar( );bool f=0;while(c<'0' || c>'9') {if(c=='-') f=1;c=getchar( );}while(c>='0' && c<='9') {sum=sum*10+c-'0';c=getchar( );}if(f) sum=-sum;}
void read(LL &sum){sum=0;char c=getchar( );bool f=0;while(c<'0' || c>'9') {if(c=='-') f=1;c=getchar( );}while(c>='0' && c<='9') {sum=sum*10+c-'0';c=getchar( );}if(f) sum=-sum;}
int B[105];
int main( )
{
  int i,n=read( );
  for(i=1;i<n;i++) read(B[i]);
  int ans=0;
  for(i=2;i<n;i++) ans+=min(B[i-1],B[i]);
  ans+=B[1];ans+=B[n-1];
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

edge = [[0] * N for _ in range(N)] #1: 辺あり, 0: 辺なし
# print (edge) 

#必要な辺が多すぎるとき
if ((N - 1) * (N -2))//2 < K:
    print (-1)
    exit()

def output(lst): #リストをもらって答えをアウトプットする
    count = 0
    for i in lst:
        for j in i:
            if j == 1:
                count += 1
    print (count)
    for i in range(N):
        for j in range(N):
            if lst[i][j] == 1:
                if i <= j:
                    print (i + 1, j + 1)
                else:
                    print (j + 1, i + 1)
    return

for i in range(1, N): #1からすべての点に伸ばし、トータルで(n-1)C2の組を作る
    edge[0][i] = 1
    #あと何組減らさないといけないか
res = ((N - 1) * (N - 2)) //2 - K
#組を減らす必要があるときTrue
if res == 0:
    output(edge)
    exit()

tmp = 0
while True:
    tmp += 1
    for i in range(1, N):
        if res == 0:
            # flag = False
            output(edge)
            exit()
        if i + tmp < N:
            if i != i + tmp and edge[i][i + tmp] == 0 and edge[i + tmp][i] == 0:
                edge[i][i + tmp] = 1
                res -= 1
        else:
            if i != ((i + tmp) % N) + 1 and edge[i][((i + tmp) % N) + 1] == 0 and edge[((i + tmp) % N) + 1][i] == 0:
                edge[i][((i + tmp) % N) + 1] = 1
                res -= 1


Measured memory_bytes: 3700
n, x, m = map(int, input().split())
P = [] # value of pre & cycle
sum_p = 0 # sum of pre + cycle
X = [-1] * m # for cycle check
for i in range(n):
    if X[x] > -1:
        cyc_len = len(P) - X[x]
        nxt_len = (n - X[x]) % cyc_len
        pre = sum(P[:X[x]])
        cyc = (sum_p - pre) * ((n - X[x]) // cyc_len)
        nxt = sum(P[X[x]: X[x] + nxt_len])
        print(pre + cyc + nxt)
        exit()
    X[x] = i
    P.append(x)
    sum_p += x
    x = x*x % m
print(sum_p)


Measured memory_bytes: 13400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl
#define all(vec) vec.begin(), vec.end()
 
int gcd(int x, int y) {
    if (x%y == 0) return y;
    return gcd(y, x%y);
}
 
int main() {
    int x, y;
    cin >> x >> y;
    ct(gcd(x, y));
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    int n;
    cin >> n;
    int count = 0;
    for(int i = 0; i < n; ++i) {
    	int t;
    	cin >> t;
    	if(i % 2 == 0 && t % 2 != 0) {
    		count++;
    	}
    }
    cout << count << "\n";
	return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define ll long long
#define fore(i,a,b) for(int i=a;i<b;i++)
#define mp make_pair
#define vll vector<ll>
#define vi vector<int>
#define vvi vector<vi>
#define fst first
#define snd second
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define pb push_back
#define pii pair<int,int>
#define FIFO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define RFWF freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;

int main() {
	int n;
	cin>>n;
	int a=n%10;
	if(a==2 or a==4 or a==5 or a==7 or a==9) cout<<"hon";
	else if(a==3) cout<<"bon";
	else cout<<"pon";
	return 0;
}


Measured memory_bytes: 3636
n = int(input())
info = []
for i in range(n):
  info.append(input().split())
for i in range(n):
  info[i].append(i+1)
info_sorted = sorted(info, key=lambda x:(x[0],-int(x[1])))
for i in range(n):
  print(info_sorted[i][2])


Measured memory_bytes: 3060
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int N=scan.nextInt();
    int[] d=new int[N];
    int sum=0;

    for(int i=0;i<N;i++){
      d[i]=scan.nextInt();
    }
    for(int i=0;i<N;i++){
      for(int j=i+1;j<N;j++){
        sum+=d[i]*d[j];
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 23252
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

// use std::collections::BTreeMap;

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let _: u64 = iter.read();
	let a: u64 = iter.read();
	let b: u64 = iter.read();
	let c: u64 = iter.read();
	let d: u64 = iter.read();

	let mapstring: String = iter.read();
	let map: Vec<char> = mapstring.chars().collect();

	if search(&map, 1, b - 1, d - 1, 0, 0) {
		let t: u64 = if d < c { 3 } else { 1 };
		if search(&map, t, a - 1, c - 1, b - 1, d - 1) {
			println!("Yes");
			return;
		}
	}
	println!("No");
}

fn search(map: &Vec<char>, length: u64, start: u64, end: u64, minc: u64, maxc: u64) -> bool {
	let mut cnt = 0;
	let mut f = true;
	let mut max = false;
	// println!("# {} {}", start, end);
	for i in (start as usize)..((end as usize) + 1) {
		let x = map[i];
		// println!("{} {}", i, x);
		if '.' == x {
			let j = i as u64;
			if maxc < j && 1 == cnt {
				f = false;
			}
			cnt += 1;
			if cnt >= length && ((minc < j && f) || 1 == length) {
				max = true;
			}
		} else {
			if 0 == cnt {
				return false;
			}
			let j = i as u64;
			if maxc < j {
				f = false;
			}
			// min = false;
			cnt = 0;
		}
	}
	max
}


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

typedef long long ll;
#define int ll
#define pb push_back
const int INF = 1e18;

signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n,k; cin>>n>>k;
	int cost[n+1];
	for(int i=1;i<=n;i++)
		cin>>cost[i];

	vector<int> dp(n+1,INF);
	dp[1] = 0;
	for(int i=1;i<n;i++){
		for(int j=i+1;j <= min(i+k,n);j++) 
			dp[j] = min(dp[j],dp[i] + abs(cost[i]-cost[j]));
	}
	cout<< dp[n];


	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  int N,K;
  
  cin >> N >> K;
  vector <int> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end() );
  long long ans = 0;

  rep(i,K){
    ans += A.at(i);
  }
  cout << ans << endl;

}

  




Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
 
void print_vec(vector<int> B)
{
 
	for(int i =0;i<B.size();i++)
	{
		cout<<B[i]<<" ";
	}
	cout<<endl;
}

void print_vec_vec_bool(vector<vector<bool>> A)
{
	for(int i = 0 ; i < A.size() ; i++)
	{
		for(int j = 0 ; j < A[i].size() ; j++)
		{
			cout<<A[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}

bool compare(string A1,string A2)
{
  if( A1[1] == '=' && A2[1] == '!')
  {
    return (A1<(A2));
  }
  return (A2 < A1);
}

void print_vec_string(vector<string> A)
{
	for(int i = 0 ; i <A.size() ;i++)
	{
		cout<<A[i]<<" ";
	}
	cout<<endl;
}
 
void print_multiset(multiset<pair<int,pair<int,int>>> s)
{
	auto itr = s.begin();
	while(itr != s.end())
	{
		pair<int,pair<int,int>> p = *itr;
		cout<<"(("<<p.first<<"),("<<p.second.first<<","<<p.second.second<<") ";
		itr++;
	}
	cout<<endl;
}

bool check_1(int x,vector<int> &connection_1, vector<vector<bool>> &adj)
{
  for(int i = 0 ; i < connection_1.size() ; i++)
  {
    if(adj[x][connection_1[i]] == true)
    {
      return false;
    }
  }
  return true;
}

bool check_2(int x,vector<int> &connection_2, vector<vector<bool>> &adj)
{
  for(int i = 0 ; i < connection_2.size() ; i++)
  {
    if(adj[x][connection_2[i]] == true)
    {
      return false;
    }
  }
  return true;
}

int main()
{
	int a,b;
	cin>>a>>b;
	int count = 1;
	int ans = 0;
	while(count < b)
	{
		count += (a-1);
		ans++; 
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
S = gets
if S.chars[0] == S.chars[1]
  if S.chars[2] == S.chars[3] && S.chars[2] != S.chars[0]
    puts "Yes" 
  else
    puts "No" 
  end
elsif S.chars[0] == S.chars[2]
  if S.chars[1] == S.chars[3] && S.chars[1] != S.chars[0]
    puts "Yes" 
  else
    puts "No" 
  end
elsif S.chars[0] == S.chars[3]
  if S.chars[1] == S.chars[2] && S.chars[1] != S.chars[0]
    puts "Yes" 
  else
    puts "No" 
  end
else
  puts "No"
end

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
ll N;
  cin>>N;
  ll A[N],sum[N];
  ll summod=0;
  for(ll i=0;i<N;i++){
  cin>>A[i];
  }

  for(ll i=0;i<N;i++){
    summod=summod+A[N-1-i];
    summod=summod%(1000000007);
    sum[N-2-i]=summod;
  }
  ll ans=0;
  for(ll i=0;i<N-1;i++){
    ans=ans+A[i]*sum[i];
    ans=ans%(1000000007);
    //cout<<ans<<endl;
  }
  
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 6712
n, m = map(int, input().split())
l, r = [0]*m, [0]*m
for i in range(m):
    l[i], r[i] = map(int, input().split())

ll = max(l)
rr = min(r)
if rr-ll >= 0:
    print(rr-ll+1)
else:
    print(0)

Measured memory_bytes: 10868
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;


#define int long long
// #define double ld
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}


signed main() {
    srand(time(0));
    accell();
    int n, a;
    cin >> n >> a;
    cout << (n + a - 1) / a;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int changeCount =  T.length();
        //比較する最初の文字を決める
        for(int start=0; start<=S.length()-T.length(); start++) {
            int count = 0;
            for(int i=0; i<T.length(); i++) {
                if(S.charAt(start+i)!=(T.charAt(i)))  {
                    count ++;
                }
            }
            if(changeCount > count) {
                changeCount = count;
            }
        }
        System.out.println(changeCount);
    }
}


Measured memory_bytes: 35884
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
map <string, int> mp;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }

  ll ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ll count = it->second;
    ans += count * (count - 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[101][101],w,t,h,p,pp,x[101],y[101],tt[101],ans=0;
main(){
	cin>>w>>h>>t>>p;
	r(i,p)cin>>x[i]>>y[i]>>tt[i];
	r(i,h)r(j,w){
		cin>>pp;
		if(!pp)a[i][j]=-1;
	}
	r(i,p)if(a[y[i]][x[i]]!=-1)a[y[i]][x[i]]++;
	r(i,h)r(j,w)if(a[i][j]>=1)ans+=a[i][j];
	cout<<ans<<endl;
}

Measured memory_bytes: 3108
#include<iostream>
using namespace std;
int main(){
    int A,B,C;
    cin >>B>>A>>C;
    if(C>B){
        int D=C-B;
        if(D>A){
            cout <<"NA"<<endl;
        }else{
            cout << D <<endl;
        }
    }else{
        cout << 0<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

int main()
{
    unsigned long long int n, k, x1, x2;

    scanf("%llu%llu", &n, &k);

    x1 = n % k;

    if (x1 > k)
        x2 = x1 - k;
    else 
        x2 = k - x1;
    
    printf("%llu\n", x1 < x2 ? x1 : x2);

    return 0;
}

Measured memory_bytes: 1728
#include <iostream>

using namespace std;

int main(){
  int n,m,i,j;
  cin >> n >>m;
  int a[n][m],b[m];
  for (i=0;i<n;i++) {
    for (j=0;j<m;j++) {
      cin >> a[i][j];
    }
  }

  for (j=0;j<m;j++) {
    cin >> b[j];
  }

  int c[n];
  for (i=0;i<n;i++) {
    c[i]=0;
    for (j=0;j<m;j++) {
      c[i]+=a[i][j]*b[j];
    }
    cout << c[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define INF (1<<29)
#define all(c) (c).begin(),(c).end()
#define pb(c) push_back(c)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int main(){
  ios::sync_with_stdio(false);

  for(int i = 0; i < 7; i++){
    int a, b;
    cin >> a >> b;
    cout << a-b << endl;
  }

}

Measured memory_bytes: 1196