akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<stack>
#include<array>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/graph/adjacency_list.hpp>
#include<boost/graph/dijkstra_shortest_paths.hpp>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
using namespace std;
using namespace boost;
using graph_t = adjacency_list<
	vecS, vecS, directedS, no_property, property<edge_weight_t, int>>;


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

	int N;
	cin >> N;
	vector<int>L(N * 2);
	rep(i, N * 2)cin >> L[i];
	sort(ALL(L));
	int answer = 0;
	rep(i, N)answer += L[i * 2];
	cout << answer << endl;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

typedef struct _tmp_t {
  int64    a;
  int64    b; // 1==ac
} tmp_t;

tmp_t *get_NSeq (int64 n)
{
  tmp_t *buf;
  int64 i,cnt;
  char  str[3];

  buf = malloc((size_t)(n * sizeof(tmp_t)));
  for (i=0; i<n; i++) {
    get_N(&buf[i].a);
    cnt = scanf("%s", str);
    if (str[0] == 'A') {
      buf[i].b = 1;
    } else {
      buf[i].b = 0;
    }
  }

  return buf;
}



int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

typedef unsigned char uint8;

#define SIZE (10*10*10*10*10)

int64 ac[SIZE+1];
int64 wa[SIZE+1];

int main()
{
  int64 N, M, i, ans, pen, qnum;
  tmp_t *q;
  char *str;

  get_NK(&N, &M);

  q = get_NSeq (M);

  for (i=0; i<=N; i++) {
    ac[i] = 0;
    wa[i] = 0;
  }
  ans = 0;
  pen = 0;

  for (i=0; i<M; i++) {
    qnum = q[i].a;
    if (q[i].b) {//ac
      ac[qnum]++;
    } else {
      if (ac[qnum] == 0) {
        wa[qnum]++;
      }
    }
  }
  for (i=1; i<=N; i++) {
    if (ac[i] > 0) {
      ans++;
      pen += wa[i];
    }
  }

  printf ("%lld %lld", ans, pen);
  return 0;
}



Measured memory_bytes: 3328
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <fstream>
 
using namespace std;
 
 
#define LL long long
#define N 1001000
#define M 3000011
#define MP make_pair
#define Pi acos(-1.0)
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define ls (root << 1)
#define rs (ls | 1)
#define md ((ll+rr)/2)
#define lson ll, md, ls
#define rson md+1, rr, rs
#define mod 1000000009
#define inf 0x3f3f3f3f
#define sqr(x) ((x)*(x))
#define eps 1e-6
#define MP make_pair
#define uLL unsigned long long
LL powmod(LL a,LL b) {LL res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
#define F(x) ((x)/3+((x)%3 == 1 ? 0 : tb))
#define G(x) ((x)<tb ? (x)*3+1 : ((x) - tb)*3+2)
#define lowbit(x) ((x)&(-x))
#define fi first
#define se second
#define pii pair<int,int>

int gcd(int a,int b){
	while(b){
		int t = a % b;
		a = b;
		b = t;
	}
	return a;
}

int fst[N],nxt[M],vv[M],e;
int dep[N],K,ans;

void init(){
	e= 0;
	memset(fst,-1,sizeof fst);
}

void add(int u,int v){
	vv[e] = v,nxt[e] = fst[u],fst[u] = e++;
	vv[e] = u,nxt[e] = fst[v],fst[v] = e++;
}

int dfs(int u,int f){
	int mx = dep[u];
	for(int i = fst[u]; ~i; i = nxt[i]){
		int  v= vv[i];
		if(v == f) continue;
		dep[v] = dep[u]+1;
		mx = max(dfs(v,u),mx);
	}
	if(u != 1 && f != 1 && mx - dep[u] == K - 1){
		ans++;
		return 0;
	}
	return mx;
}

int main(){
	int n;
	scanf("%d%d",&n,&K);
	init();
	for(int i = 1; i <= n; i++){
		int u;
		scanf("%d",&u);
		if(i == 1){
			if(u != 1) ans++;
			continue;
		}
		else{
			add(i,u);
		}
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

vector<bool> solve(int n, vector<bool> const & s){
    rep(i,2){
        rep(j,2){
            vector<bool> res(n);
            res.at(0) = i;
            res.at(1) = j;
            for(int k = 2; k < n; k++){
                res.at(k) = res.at(k-1)^res.at(k-2)^s.at(k-1);
            }
            if(s.at(n-1)==res.at(n-2)^res.at(n-1)^res.at(0)&&s.at(0)==res.at(n-1)^res.at(0)^res.at(1))return res;
        }
    }
    return vector<bool>();
}

int main(){
    int N; cin>>N;
    vector<bool> S(N);
    rep(i,N){
        char tmp; cin>>tmp;
        S.at(i) = (tmp=='o');
    }
    vector<bool> res = solve(N,S);
    if(res.empty())cout<<-1<<endl;
    else{
        for(auto b: res) cout << (b ? 'S' : 'W');
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int l = s.length();
        boolean ans = false;
        for (int i = 0; i < l; i++) {
            int count = 0;
            for (int j = 0; j < l; j++) {
                if (i + j < l) {
                    if (s.charAt(j) == t.charAt(j + i)) count++;
                } else {
                    if (s.charAt(j) == t.charAt(j + i - l)) count++;
                }
            }
            if (count == l) ans = true;
        }
        if (ans) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }    
}


Measured memory_bytes: 23636
import numpy as np

d = int(input())

c = list(map(int, input().split()))

sd = np.zeros((d, 26), dtype=np.int)
for i in range(d):
  s = list(map(int, input().split()))
  s_array = np.array(s)
  sd[i, :] = s_array
  
for i in range(d):
  print(np.argmax(sd[i, :])+1)

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = pow(10,9) + 7;

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

int main(){

    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }
    int ans = 0;
    int max = P[0];
    for(int i = 0; i < N; i++){
        if(P[i] > max) continue;
        ans++;
        max = P[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll odd = 0;
    rep(i, n){
        cin >> a[i];
        if(a[i] % 2 == 1)odd++;
    }
    if(odd % 2 == 0)cout << "YES";
    else cout << "NO";
}      

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

int main() {
  int h, w, k; cin >> h >> w >> k; int a[h][w], c=1;
  for(int i=0; i<h; i++) {
    string s; cin >> s;
    for(int j=0; j<w; j++) {
      if (s[j] == '#') a[i][j]=c, c++;
      else a[i][j] = -1;
    }
  }

  // 下へ
  for(int i=0; i<h-1; i++) {
    for(int j=0; j<w; j++) {
      if (a[i+1][j] == -1 && a[i][j] != -1) a[i+1][j] = a[i][j];
    }
  }
  // 上へ
  for(int i=h-2; i>=0; i--) {
    for(int j=0; j<w; j++) {
      if (a[i][j] == -1 && a[i+1][j] != -1) a[i][j] = a[i+1][j];
    }
  }
  // 右へ
  for(int i=0; i<h; i++) {
    for(int j=0; j<w-1; j++) {
      if (a[i][j+1] == -1 && a[i][j] != -1) a[i][j+1] = a[i][j];
    }
  }
  // left
  for(int i=0; i<h; i++) {
    for(int j=w-2; j>=0; j--) {
      if (a[i][j] == -1 && a[i][j+1] != -1) a[i][j] = a[i][j+1];
    }
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cout << a[i][j] << " ";
    } cout << endl;
  }
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main() {
    int n,a=0,b=0,x=0,y=0,z=0,w=0;
    cin>>n;
    int A[n],B[100001],C[100001];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    for(int i=0;i<n;i++){
        B[A[i]]=0;
        C[A[i]]=0;
    }

    for(int i=0;i<n;i++){
        if(i%2==0){
            B[A[i]]++;
        }else{
            C[A[i]]++;
        }
    }


    for(int i=0;i<n;i++){
        if(i%2==0){
            if(B[A[i]]>x){
                x=B[A[i]];
                a=i;

            }

        }else if(C[A[i]]>y){
            y=C[A[i]];
            b=i;
        }
    }
    if(A[a]!=A[b]){
        cout<<n-x-y;
    }else{
        for(int i=0;i<n;i++){
            if(i%2==0){
                if(B[A[i]]>z && A[i]!=A[a]){
                    z=B[A[i]];
                }
            }else{
                if(C[A[i]]>w && A[i]!=A[b]){
                    w=C[A[i]];
                }

            }
        }
        if(z==0 && w ==0){
            cout<<n/2;
        }else{
            if(x+w>=y+z){
                cout<<n-x-w;
            }else{
                cout<<n-y-z;
            }

        }

    }


    }

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

vector<int> ix{1, 0, -1, 0};
vector<int> iy{0, -1, 0, 1};
int main(){
  while(1){
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    int field[30][30][4]; // 右・上・左・下
    rep(i, h)rep(j, w)rep(k, 4) field[i][j][k] = 1;
    int wall;
    rep(i, h){
      rep(j, w-1){
        cin >> wall;
        field[i][j][0] = wall;
        field[i][j+1][2] = wall;
      }
      if (i == h-1) break;
      rep(j, w){
        cin >> wall;
        field[i][j][3] = wall;
        field[i+1][j][1] = wall;
      }
    }
    
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    dist[0][0] = 0;
    que.push(make_pair(0, 0));
    int ans = 0;
    bool flag = false;
    while(!que.empty()){
      auto pos = que.front();
      que.pop();
      int px = pos.first;
      int py = pos.second;
      rep(i, 4){
        int nx = px + ix[i];
        int ny = py + iy[i];
        if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
        if (dist[ny][nx] != -1) continue;
        if (field[py][px][i] == 1) continue;
        dist[ny][nx] = dist[py][px] + 1;
        que.push(make_pair(nx, ny));
        if (nx == w-1 && ny == h-1){
          ans = dist[ny][nx] + 1;
          flag = true;
          break;
        }
      }
      if (flag) break;
    }
    cout << ans << endl;
  }
    
  return 0;
}


Measured memory_bytes: 3128
#include<stdio.h>
int i;
#define rep(i,n) for(i=0;i<n;i++)
#define max(x,y) ((x)>(y)?(x):(y))
int cmp(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}
int main(){
  int n;
  scanf("%d",&n);
  int a[n],d[n];
  rep(i,n){scanf("%d",&a[i]);d[i]=a[i];}
  qsort(a,n,sizeof(int),cmp);
  rep(i,n){
    if(d[i]==a[n-1])
      printf("%d\n",a[n-2]);
    else 
      printf("%d\n",a[n-1]);
  }
  return 0;
}


Measured memory_bytes: 3116
def get_digit_sum(n):
    ans = 0
    while n > 0:
        ans += n % 10
        n //= 10
    return ans


N, A, B = map(int, input().split())

ans = 0
for i in range(1, N + 1):
    if A <= get_digit_sum(i) <= B:
        ans += i
print(ans)


Measured memory_bytes: 2940
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

struct UnionFind {
    parent: Option<usize>,
    size: u32,
}

impl Clone for UnionFind {
    fn clone(&self) -> Self {
        UnionFind {
            parent: self.parent.clone(),
            size: self.size,
        }
    }
}

fn root(a: usize, uf: &mut Vec<UnionFind>) -> usize {
    if let Some(v) = uf[a].parent {
        let tmp = root(v, uf);
        uf[a].parent = Some(tmp);
        tmp
    } else {
        a
    }
}

fn union(a: usize, b: usize, uf: &mut Vec<UnionFind>) {
    let ar = root(a, uf);
    let br = root(b, uf);
    if ar == br {
        return;
    }
    if uf[ar].size >= uf[br].size {
        uf[ar].size += uf[br].size;
        uf[br].parent = Some(ar);
    } else {
        uf[br].size += uf[ar].size;
        uf[ar].parent = Some(br);
    }
}

use std::collections::BTreeSet;

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let mut uf = vec![
        UnionFind {
            parent: None,
            size: 1
        };
        m
    ];
    let mut s = BTreeSet::new();
    for _ in 0..n {
        let klv: Vec<usize> = read_vec();
        let k = klv[0];
        for i in 1..k {
            let l1 = klv[i] - 1;
            let l2 = klv[i + 1] - 1;
            union(l1, l2, &mut uf);
            s.insert(l1);
        }
        s.insert(klv[k] - 1);
    }
    let mut cnt = 0;
    for i in 0..m {
        if !s.contains(&i) {
            continue;
        }
        if uf[i].parent == None {
            cnt += 1;
        }
    }

    if cnt == 1 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 8444
<?php

class Operator
{
    private $operations;
    private $operations_count;

    public function doOperations()
    {
        fscanf(STDIN, '%d', $this->operations_count);
        $this->operations = new \SplDoublyLinkedList();
        for (;$this->operations_count > 0;$this->operations_count -= 1) {
            $operation = explode(' ', trim(fgets(STDIN)));
            if ($operation[0] === 'insert') {
                $this->operations->unshift($operation[1]);
            } elseif ($operation[0] === 'deleteFirst') {
                $this->operations->shift();
            } elseif ($operation[0] === 'deleteLast') {
                $this->operations->pop();
            } elseif ($operation[0] === 'delete') {
                foreach ($this->operations as $key => $element) {
                    if ($element === $operation[1]) {
                        $this->operations->offsetUnset($key);
                        break;
                    }
                }
            }
        }
    }

    public function getAnswer()
    {
        $keys_operated = array();

        while (count($this->operations) > 0) {
            $keys_operated[] = $this->operations->shift();
        }
        echo implode(' ', $keys_operated), PHP_EOL;
    }
}

$operator = new Operator();
$operator->doOperations();
$operator->getAnswer();



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int N,K;
  cin >> N >> K;
  int ans=0;
  REP(i,N){
    int x;
    cin >> x;
    ans += min(x,K-x)*2;
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    cout<<60*(h2-h1)+(m2-m1)-k<<endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<29;
const LL OO=1e18;

const int N=1e5+100;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int d[N];
int bug[N];
int v[16];
int f[1<<16];
int main()
{
	int n=gi(),i,s,t,a,b,c,ans=0,m=0;
	for (i=1;i<n;i++) {
		a=gi(),b=gi(),c=gi();
		d[a]^=c,d[b]^=c;	
	}
	for (i=0;i<n;i++) ++bug[d[i]];
	for (i=1;i<16;i++) {
		ans+=bug[i]/2;
		if (bug[i]&1) v[m++]=i;
	}
	for (s=1;s<1<<m;s++) {
		for (i=c=0;i<m;i++) if (s>>i&1) c^=v[i];
		if (c) f[s]=oo;
		else for (i=0,f[s]=-1;i<m;i++) f[s]+=s>>i&1;
		for (t=s;(--t)&=s;)
			upmin(f[s],f[t]+f[s^t]);
	}
	cout<<ans+f[(1<<m)-1]<<endl;
	return 0;
}


Measured memory_bytes: 768
input = gets.chomp
N = input.to_i
input = gets.chomp
monster_list = input.split(" ").map{|e| e.to_i}

loop {
  monster_list.sort!
  atacker = monster_list.shift
  monster_list.delete_if { |e| e%atacker == 0 }
  if monster_list.size==0
    monster_list << atacker
  end
  monster_list.sort!
  monster_list[0] -= atacker*(monster_list[0]/atacker)
  monster_list.delete_at(0) if monster_list[0] == 0
  monster_list << atacker
  break if monster_list.size==1
}
puts monster_list.first


Measured memory_bytes: 10248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    int n,m;
    int isix[25]={};
    int isiy[25]={};
    int nowx,nowy;
    int ban[25][25];
    char dir;
    int dist;
    int judge;
    while(1==1)
    {
        judge=1;
        nowx=10;
        nowy=10;
        REP(i,25)isix[i]=10000;
        REP(i,25)isiy[i]=10000;
        REP(i,25)REP(j,25)ban[i][j]=0;
        scanf("%d\n",&n);
        if(n==0)return 0;
        REP(i,n)scanf("%d %d\n",&isix[i],&isiy[i]);
        scanf("%d\n",&m);
        REP(i,m)
        {
            scanf("%c %d\n",&dir,&dist);
            while(dir=='N'&&dist>0)
            {
                dist--;
                nowy++;
                ban[nowy][nowx]=1;
            }
            while(dir=='E'&&dist>0)
            {
                dist--;
                nowx++;
                ban[nowy][nowx]=1;
            }
            while(dir=='S'&&dist>0)
            {
                dist--;
                nowy--;
                ban[nowy][nowx]=1;
            }
            while(dir=='W'&&dist>0)
            {
                dist--;
                nowx--;
                ban[nowy][nowx]=1;
            }
        }
        REP(i,n)
        {
            if(ban[isiy[i]][isix[i]]==0)judge=0;
        }
        if(judge==0)printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define INF 1000000000000000
using namespace std;
int A,B,Q;
int main(void)
{
  scanf("%d %d %d",&A,&B,&Q);
  vector<long long int> s,t,x;
  int i=0,j=0,k=0;
  long long int input;
  for(i=1;i<=A;i++) {
    cin>>input;
    s.push_back(input);
  }
  s.push_back(INF);
  s.push_back(-INF);
  i=0;
  for(i=1;i<=B;i++) {
    cin>>input;
    t.push_back(input);
  }
  t.push_back(INF);
  t.push_back(-INF);
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  i=0;
  for(i=0;i<Q;i++) {
    cin>>input;
    x.push_back(input);
  }
  for(i=0;i<Q;i++) {
    long long int ans=INF,d[4];
    int sleft=distance(s.begin(),lower_bound(s.begin(),s.end()-1,x[i]))-1;
    int tleft=distance(t.begin(),lower_bound(t.begin(),t.end()-1,x[i]))-1;
    j=k=0;
    for(j=sleft;j<sleft+2;j++) {
      for(k=tleft;k<tleft+2;k++) {
        d[0]=abs(x[i]-s[j])+abs(t[k]-s[j]);
        d[1]=abs(x[i]-t[k])+abs(t[k]-s[j]);
        ans=min(ans,(min(d[0],d[1])));
      }
    }
    printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
int N;
vector<int> p, q;
int cntp, cntq;
int cnt;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    p.resize(N);
    q.resize(N);
    for(int i = 0; i < N; i++) cin >> p[i];
    for(int i = 0; i < N; i++) cin >> q[i];
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        cnt++;
        if(v == p) cntp = cnt;
        if(v == q) cntq = cnt;
    } while(next_permutation(v.begin(), v.end()));
    cout << abs(cntp - cntq) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ept 1e-9

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

int n, m;
int main() 
{
	n = read();
	m = read();
    if (n == 1 && m > 1) cout << m - 2;
   	else if (n > 1 && m == 1) cout << n - 2;
    else if (n == 1 && m == 1) cout << 1;
    else cout << 1ll * n * m - 2 * n - 2 * m + 4;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <sstream>
#include <cctype>
using namespace std;

#define PQ priority_queue
#define P pair<int,int>
#define CLA(array) memset(array,0,sizeof array)
#define CLINF(array) memset(array,0x3f,sizeof array)
#define CLF(array) memset(array,-1,sizeof array)
#define DB(a) cout << "DEBUG " << a << endl;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100000 + 50;
const int INF = 1 << 30;
int k;
LL a[55];

bool ok(){
	for(int i = 0; i < k; i++){
		if(a[i] >= k) return false;
	}
	return true;
}
int main(){
    //ios_base::sync_with_stdio(false);
	while(~scanf("%d", &k)){
		LL sum = 0, sum2 = 0;
		for(int i = 0; i < k; i++){
			scanf("%lld", &a[i]);
			if(a[i] >= k) sum += (a[i] / k);
			sum2 += a[i];
			// cout << a[i] - k << endl;
		}
		sort(a, a+k);
		if(a[k-1] < k){
			printf("0\n");
			continue;
		}
		// cout << sum << endl;
		// cout << sum2 << endl;
		LL ans = 0;
		while(!ok()){
			for(int i = 0; i < k; i ++){
				LL tmp = a[i]/k;
				a[i] %= k;
				ans += tmp;
				for(int j = 0; j < k; j++){
					if(i!=j) a[j] += tmp;
				}
			}
		}
		cout << ans << endl;
		// cout << sum/(LL)k << endl;
	}


    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    LL l, r;
    cin >> l >> r;

    if(r-l > 1000){
        cout << 0 << endl;
        return 0;
    }else{
        LL ans = 2019;
        for(LL i=l;i<r+1;i++){
            for(LL j=i+1;j<r+1;j++){
                ans = min(ans, i*j%2019);
            }
        }
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,s,t = LI()
    s -= 1
    t -= 1
    v = [[] for i in range(n)]
    f = [0]*n
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
        f[a] += 1
        f[b] += 1
    l = []
    for i in range(n):
        if f[i] == 1:
            l.append(i)
    depth = [-1]*n
    depth[t] = 0
    q = deque([t])
    while q:
        x = q.popleft()
        for y in v[x]:
            if depth[y] < 0:
                depth[y] = depth[x]+1
                q.append(y)
    d = [-1]*n
    d[s] = 0
    q = deque([s])
    while q:
        x = q.popleft()
        for y in v[x]:
            if d[y] < 0:
                d[y] = d[x]+1
                q.append(y)
    l.sort(key = lambda x:-depth[x])
    for i in l:
        if d[i] < depth[i]:
            break
    print(depth[i]-1)
    return

#Solve
if __name__ == "__main__":
    solve()


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

signed main() {
  int n,k; cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  
  for(int j=0;j<n-k;j++){
    if(a[j]<a[j+k])
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
}

Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define min(a, b) (a > b ? b : a)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll nck(int n, int k) { ll ret = 1; rep(i, k) {ret *= n - i; ret /= i + 1; } return ret; } // n <= 60
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n, m;
    cin >> n >> m;
    
    priority_queue<int> q;
    
    rep(i, n) {
        int a;
        cin >> a;
        q.push(a);
    }
    
    vector<pii> v(m);
    rep(i, m) cin >> v[i].S >> v[i].F;
    
    sort(all(v), greater<pii>());
    
    int cnt = 0;
    rep(i, m) {
        rep(j, v[i].S) {
            q.push(v[i].F);
        }
        cnt += v[i].S;
        if (cnt > n) break;
    }
    
    ll sum = 0;
    rep(i, n) {
        sum += q.top();
        q.pop();
        
    }
    
    out(sum);
}


Measured memory_bytes: 3316
n = int(input())
cnt = 0
for _ in range(n):
    a, b = map(int, input().split())
    if cnt:
        if a == b:
            cnt += 1
            if cnt >= 3:
                print("Yes")
                break
        else:
            cnt = 0
    else:
        if a == b:
            cnt += 1
else:
    print("No")


Measured memory_bytes: 9168
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
int n,x,y,z,lim,m;
ll f[41][200200];

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

ll qpow(ll x,int y)
{
	ll ans=1;
	while (y)
	{
		if (y&1) ans=ans*x%maxd;
		x=x*x%maxd;y>>=1;
	}
	return ans;
}

int main()
{
	n=read();x=read();y=read();z=read();
	int final=(1<<(x+y+z-1))|(1<<(y+z-1))|(1<<(z-1));
	m=x+y+z;lim=(1<<m)-1;
	//cout << lim << endl;
	//cout << final << endl;
	f[0][0]=1;
	rep(i,1,n)
	{
		rep(pre,0,lim)
		{
			if ((pre&final)==final) continue;
			rep(j,1,10)
			{
				int sta=((pre<<j)|(1<<(j-1)))&lim;
				if ((sta&final)==final) continue;
				f[i][sta]=(f[i][sta]+f[i-1][pre])%maxd;
			}
		}
	}
	ll ans=0;
	rep(i,0,lim)
	{
		//cout << i << endl;
		if ((i&final)==final) continue;
		ans=(ans+f[n][i])%maxd;
	}
	ans=(qpow(10,n)-ans+maxd)%maxd;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 62208
N = gets.to_i
A = gets.split.map(&:to_i)
L = Array.new(N + 1, 0)
R = Array.new(N + 1, 0)
N.times{|i| L[i + 1] = L[i].gcd(A[i]) }
N.times.reverse_each{|i| R[i] = R[i + 1].gcd(A[i]) }
puts N.times.map{|i| L[i].gcd(R[i + 1]) }.max



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

int n;
int a[20], x[20][20], y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}


int main() {
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >>a[i];
        for(int j=1;j<=a[i];j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int result = 0;
    for(int bit = 1; bit < (1 << n); bit++) {
        bool flg = true;
        for(int i=1;i<=n;i++) {
            if(!(bit & (1 << (i-1)))) continue;
            for(int j=1;j<=a[i];j++) {
                if(((bit >> (x[i][j]-1)) & 1) ^ y[i][j]) flg = false;
            }
        }
        if(flg) result = max(result, counter(bit));
    }
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  #define int long
  int N;cin>>N;
  vector<int>A(N);for(int i=0;i<N;i++)cin>>A[i];
  vector<int>sl(N),sr(N);sl[0]=A[0];sr[N-1]=A[N-1];
  for(int i=1;i<N;i++)sl[i]=sl[i-1]+A[i];
  for(int i=N-2;i>=0;i--)sr[i]=sr[i+1]+A[i];
  
  int m=LONG_MAX;
  for(int i=0;i<N-1;i++){//どこで切るか
    if(m>abs(sl[i]-sr[i+1]))m=abs(sl[i]-sr[i+1]);
  }
  cout<<m;
  
                             
  
  
  
}



Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int maxValuse = 0;
            int nowValuse = 0;
            for(int i = 0; i < N; i++)
            {
                if (S.Substring(i, 1) == "I")
                {
                    nowValuse += 1;
                    maxValuse = Math.Max(maxValuse, nowValuse);
                }
                else if(S.Substring(i,1) == "D")
                {
                    nowValuse -= 1;
                    maxValuse = Math.Max(maxValuse, nowValuse);
                }
            }
            Console.WriteLine(maxValuse);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 27524
N = int(input())
list_A = list(map(int,input().split()))

ans = 0
tem_max = list_A[0]

for i in range(0,N):
    if tem_max > list_A[i]:
        ans += tem_max - list_A[i]
    else:
        tem_max = list_A[i]
print(ans)

Measured memory_bytes: 32088
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int main()
{
  long long N, M, K;
  std::cin >> N >> M >> K;
  std::vector<long long> A(N), B(M);
  for(auto& val: A)
    std::cin >> val;
  for(auto& val: B)
    std::cin >> val;
  int ans = 0;
  long long tmp = 0;
  int i = 0;
  for(; i < A.size(); ++i)
  {
    if(K < tmp + A[i])
      break;
    tmp += A[i];
  }
  int j = 0;
  for(; j < B.size(); ++j)
  {
    if(K < tmp + B[j])
      break;
    tmp += B[j];
  }
  ans = i + j;
  for(; j < B.size(); ++j)
  {
    while(K < tmp + B[j] && 0 < i)
    {
      tmp -= A[i - 1];
      i--;
    }
    tmp += B[j];
    if(tmp <= K)
    {
      ans = std::max(ans, i + j + 1);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

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

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long int;

int main(){
    int X,Y,Z;
    cin>>X>>Y>>Z;
    printf("%d %d %d\n",Z,X,Y);
    
    return 0;
}




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

using namespace std;
int main(void)
{
    int n,m;
    int a[50],b[50],c[50],d[50];

    cin >> n >> m;

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

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

    int t = 0;
    int check;
    for (int i = 0; i < n; i++) {
        for (int j = m-1; j >= 0; j--) {
            if (j == m-1) {
               t = abs(a[i] - c[j]) + abs(b[i] - d[j]);
               check = j+1;
               continue;
            }
            if (t >= abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                t = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                check = j+1;
            } 
        }
        cout << check << endl;
    }
    
    return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define minit(a,b) memset(a, b, sizeof(a))

int N, M, memoM1[111][2], memoM2[111][3][3];
const int MOD = (int)1e6;

void modAdd(int& a, int add) { a = (a + add) % MOD; }

int recM1(int y, int s) {
	if (y == N + 1) {
		if (s == 0) return 1;
		return 0;
	}
	
	int& res = memoM1[y][s];
	if (res != -1) return res;
	res = 0;
	
	modAdd(res, recM1(y + 1, s));
	modAdd(res, recM1(y + 1, 1 - s));
	
	return res;
}

int recM2(int y, int x, int s) {
	if (y == N + 1) {
		if (s == 0 && x == 2) return 1;
		return 0;
	}
	
	int& res = memoM2[y][x][s];
	if (res != -1) return res;
	res = 0;
	
	modAdd(res, recM2(y + 1, x, s));
	
	if (x == 0) {
		assert(s != 1);
		
		if (s == 0) {
			modAdd(res, recM2(y + 1, 0, 2));
			modAdd(res, recM2(y + 1, 1, 0));
			modAdd(res, recM2(y + 1, 2, 0));
		} else {
			modAdd(res, recM2(y + 1, 2, 0));
		}
	}
	
	if (x == 1) {
		assert(s == 0);
		modAdd(res, recM2(y + 1, 0, 0));
		modAdd(res, recM2(y + 1, 2, 0));
	}
	
	if (x == 2) {
		assert(s != 2);
		
		if (s == 0) {
			modAdd(res, recM2(y + 1, 2, 1));
			modAdd(res, recM2(y + 1, 1, 0));
			modAdd(res, recM2(y + 1, 0, 0));
		} else {
			modAdd(res, recM2(y + 1, 0, 0));
		}
	}
	
	return res;
}

int main() {
	cin >> N >> M;
	
	if (M == 1) {
		minit(memoM1, -1);
		cout << recM1(0, 0) << endl;
	} else {
		minit(memoM2, -1);
		cout << recM2(0, 0, 0) << endl;
	}
}

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

using namespace std;

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

	vector<vector<int>> x(n, vector<int>(d, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int dist2 = 0;
			for (int k = 0; k < d; k++) {
				int tmp = x[i][k] - x[j][k];
				dist2 += tmp * tmp;
			}

			int rt = sqrt(dist2) + 0.5;
			if (rt * rt == dist2) {
				ans++;
			}
		}
	}

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


Measured memory_bytes: 256
N=io.read("n")
T=io.read("n")
A=io.read("n")
t={}
for i=1,N do 
  t[i]=T-io.read("n")*0.006-A
  if t[i]<0 then
    t[i]=-t[i]
  end
end
a=t[1]
b=1
for i=2,N do
  if a>t[i] then
    a=t[i]
    b=i
  end
end
print(b)

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD = 1e9+7;

bool comp(const P& lhs, const P& rhs)
{
	if(lhs.second-lhs.first==rhs.second-rhs.first)
		return lhs.first<rhs.first;
	else
		return lhs.second-lhs.first>rhs.second-rhs.first;
}
P gsb[3];

ll ab(ll n)
{
	ll ret=n;
	for(ll a=0;a<=n/gsb[0].first;a++)
	{
		ll now=n-a*gsb[0].first;
		if(now<0)
			break;
		for(ll b=0;b<=now/gsb[1].first;b++)
		{
			ll nownow=now-b*gsb[1].first;
			if(nownow<0)
				break;
			ll c=nownow/gsb[2].first;
			ll tmp=(nownow+gsb[2].first)%gsb[2].first;
			tmp+=c*gsb[2].second+b*gsb[1].second+a*gsb[0].second;
			ret=max(ret,tmp);
		}
	}
	return ret;
}

ll ba(ll n)
{
	ll ret=n;
	for(ll a=0;a<=n/gsb[0].second;a++)
	{
		ll now=n-a*gsb[0].second;
		if(now<0)
			break;
		for(ll b=0;b<=now/gsb[1].second;b++)
		{
			ll nownow=now-b*gsb[1].second;
			if(nownow<0)
				break;
			ll c=nownow/gsb[2].second;
			ll tmp=(nownow+gsb[2].second)%gsb[2].second;
			tmp+=c*gsb[2].first+b*gsb[1].first+a*gsb[0].first;
			ret=max(ret,tmp);
		}
	}
	return ret;
}

ll ba2(ll n)
{
	ll ret=n;
	sort(gsb,gsb+3,comp);
	reverse(gsb,gsb+3);
	bool f[3];
	for(int i=0;i<3;i++)
	{
		if(gsb[i].first-gsb[i].second>0)
			f[i]=true;
		else
			f[i]=false;
	}
	if(!f[0])
		return ret;
	if(!f[1])
	{
		ret=(n%gsb[0].second)+gsb[0].first*(n/gsb[0].second);
		return ret;
	}
	for(ll a=0;a<=n/gsb[0].second;a++)
	{
		ll now=n-a*gsb[0].second;
		if(now<0)
			break;
		ll b=now/gsb[1].second;
		ll tmp=now-gsb[1].second*b;
		tmp+=b*gsb[1].first+a*gsb[0].first;
		ret=max(tmp,ret);
	}
	return ret;
}


int main()
{
	int n;
	ll ans=0;
	cin>>n;
	ans=n;
	for(int i=0;i<3;i++)
		cin>>gsb[i].first;
	for(int i=0;i<3;i++)
		cin>>gsb[i].second;
	ll abans=ab(n);
	ll test=ba2(n);
	ll baans=ba(n);
	cerr<<test<<" "<<baans<<endl;
	ans=max(abans,baans);
	if(abans>n && baans>0)
	{
		ans=ba2(abans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.text.*;

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

      dfs(0);

      System.out.println(ans);
    }
    public static void dfs(long x) {
      if (x > n) {
        return;
      }
      String x_str = String.valueOf(x);
      if(x_str.contains("7") && x_str.contains("5") &&x_str.contains("3")) {
        ans++;
      }
      dfs(10 * x + 7);
      dfs(10 * x + 5);
      dfs(10 * x + 3);
    }
}

Measured memory_bytes: 24276
uses crt;
var n : int64;
s : string;
i,j : longint;
check : array[0..10] of boolean;
a : array[0..10] of extended;
b : array[0..10] of extended;
kq,cnt : extended;
function kc(i,j : integer) : extended;
begin
        if (i=0) or (j=0) then exit(0);
        exit(sqrt(sqr(a[i]-a[j]) + sqr(b[i]-b[j])));
end;

procedure process(m,k : integer);
var j : integer;
begin
        if (m=n+1) then begin cnt := cnt + kq;  exit; end;
        for j := 1 to n do
                if (check[j]=true) then begin
                        kq := kq + kc(j,k);
                        check[j]:=false;
                        process(m+1,j);
                        kq := kq - kc(j,k);
                        check[j]:=true;
                end;
end;

begin
        clrscr;
       { assign(input,'test.inp');reset(input);  }
        readln(n);
        for i := 1 to n do begin readln(a[i],b[i]); check[i]:=true; end;
     {   assign(output,'test.out');rewrite(output);
        clrscr;      }
        process(1,0);
        kq := 1;
        for j := 1 to n do kq := kq * j;
        write(cnt/kq : 0 : 10);
        readln;
        close(output);
end.



Measured memory_bytes: 128
var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var building = [];
for (var i = 0; i < 4; i++) {
    building.push([]);
    for (var j = 0; j < 3; j++) {
        building[i].push([]);
        for (var k = 0; k < 10; k++) {
            building[i][j].push(0);
        }
    }
}

var lines = input.split(/\n/g);
for (var i = 1; i <= +lines[0]; i++) {
    var
        line = lines[i].split(' ').map(Number),
        b = line[0] - 1,
        f = line[1] - 1,
        r = line[2] - 1,
        v = line[3];

    if (building[b][f][r] + v < 0) {
        building[b][f][r] = 0;
    }
    else if (9 < building[b][f][r] + v) {
        building[b][f][r] = 9;
    }
    else {
        building[b][f][r] += v;
    }
}

for (var i = 0; i < 4; i++) {
    for (var j = 0; j < 3; j++){ 
        console.log(' ' + building[i][j].join(' '));
    }
    if (i != 3) console.log('####################');
}

Measured memory_bytes: 15560
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]

sum = 0
change = {"I": 1, "D": -1}
length = int(fetch_one_line())
target = fetch_one_line()
records = [0 for _ in range(length)]

for i, t in enumerate(target):
   sum += change[t]
   records[i] = sum

max_val = max(records)
if max_val < 0:
    max_val = 0
print(max_val)


Measured memory_bytes: 38384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

// ----------- VECTOR ------------
template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}
// ----------- VECTOR ------------

int main() {
  int N; cin >> N;
  vector<LL> H(N); cin >> H;

  LL cnt = 0;
  map<int, int> L;
  for (int i = 0; i < N; ++i) {
    cnt += L[i-H[i]];
    L[i + H[i]]++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 21876
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function
import sys


def main():
    n, a, b, c, d = map(int, sys.stdin.readline().strip().split(" "))
    m = n - 1
    diff = b - a

    for i in range(m):
        j = m - i
        plus_min = c * i
        plus_max = d * i
        minus_min = -c * j
        minus_max = -d * j
        minimum = plus_min + minus_max
        maximum = plus_max + minus_min
        if minimum <= diff <= maximum:
            print("YES")
            break
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 18432
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
long long n,a[1000000+100],sol;
string s;
int main()
{
    scanf("%lld",&n);
    for (long long i=1;i<=n;i++)scanf("%lld",&a[i]);
    long long nzs = a[1];
    for (long long i=2;i<=n;i++)
    {
        long long nzd = __gcd(a[i],nzs);
        nzs = nzs/nzd*a[i];
    }
    cout<<nzs<<endl;
    return 0;
}


Measured memory_bytes: 256