akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an+1) 
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


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

typedef vector<int> vi;
typedef vector<vi> vvi;

const int MAX_V = 3600;
const int INF = 9999999;

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

int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;

int h, w;

bool in(int i, int j){
	return 0 <= i && i < h && 0 <= j && j < w;
}

int toV(int i, int j, int dir){
	return 4 * (i * w + j) + dir;
}

void calc(){
	fill(d, d + V, INF);
	fill(used, used + V, false);
	d[0] = 0;

	while (true) {
		int v = -1;
		for (int u = 0; u < V; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}

		if (v == -1)break;
		used[v] = true;
		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int main(){
	while (cin >> w >> h , w != 0 || h != 0) {
		vvi s = vvi(h, vi(w, 0));
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				cin >> s[i][j];
		int c[4];
		for (int i = 0; i < 4; i++)
			cin >> c[i];

		for (int i = 0; i < MAX_V; i++)
			for (int j = 0; j < MAX_V; j++)
				cost[i][j] = INF;

		V = 4 * w * h;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int dir = 0; dir < 4; dir++) {
					cost[toV(i, j, dir)][toV(i, j, dir)] = 0;
					for (int ndir = 0; ndir < 4; ndir++) {
						int ni = i + dy[ndir], nj = j + dx[ndir];
						if (!in(ni, nj)) continue;
						if (s[i][j] != 4 && (dir + s[i][j]) % 4 == ndir)
							cost[toV(i, j, dir)][toV(ni, nj, ndir)] = 0;
						else
							cost[toV(i, j, dir)][toV(ni, nj, ndir)] = c[(ndir - dir + 4) % 4];
					}
				}
			}
		}

		calc();

		int ans = INF;
		for (int dir = 0; dir < 4; dir++) {
			ans = min(ans, d[toV(h - 1, w - 1, dir)]);
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 51860
s = input()
count = 0

margin = 0
length = len(s)
while length > 0:

    if s[length-1] == "A":
       count += margin
       s = s[:length-1]
    elif s[length-2:] == "BC":
        margin += 1
        s = s[:length-2]
    else:
        s = s[:length-1]
        margin = 0

    length = len(s)

print(count)

Measured memory_bytes: 3500
import java.util.*;
class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int a = n / 100;
		int b = n % 100 / 10;
		int c = n % 100 % 10;
		
		if(a == 7 || b == 7 || c ==7) {
		    System.out.println("Yes");
		}
		else System.out.println("No");
		
	}
}

Measured memory_bytes: 35696
n=input()
print(n+': ',end='')
n=int(n)
x = 2
ans = []
while x * x <= n:
    while n % x == 0:
        n //= x
        ans.append(x)
    x = x + 1
if n > 1:
    ans.append(n)
print(" ".join(list(map(str, ans))))



Measured memory_bytes: 5600
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   string s;
   cin >> s;
   vector<bool> seen(256,0);
   for (char c : s) seen[c] = 1;
   if (seen['N'] != seen['S'] || seen['E'] != seen['W']) {
      cout << "No";
   } else {
      cout << "Yes";
   }
}

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

int bubblesort(int A[], int N) {
        int sw = 0;
        bool flag = 1;
        for (int i=0; flag; i++) {
        flag = 0;
         for (int j=N-1; j >i; j--) {
                if (A[j-1] > A[j]) {
                swap(A[j-1],A[j]);
                flag = 1;
                sw++;
                }
                }
        }
        return sw;
}

int main() {
 int A[100], N, sw;
 cin >> N;
        for (int i=0; i<N; i++) {
        cin >> A[i];
        }
 sw = bubblesort(A,N);

 for (int i=0;i<N;i++)
        {
                if (i) cout << " ";
                cout << A[i];
        }
 cout << endl;
 cout << sw << endl;

 return 0;

}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int 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();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/******************************head*******************************/
const int maxn=100005;
int a[maxn],b[maxn],c[maxn],x,y,z,n,id[maxn];
i64 pr[maxn],sf[maxn];
priority_queue<int,vector<int>,greater<int> > heap;
i64 ans=0;
inline bool cmp(int x,int y){
	return a[x]-b[x]<a[y]-b[y];
}
int main(){
	read(x);read(y);read(z);n=x+y+z;
	rep(i,1,n){
		read(a[i]);read(b[i]);read(c[i]);
		ans+=c[i];
		a[i]-=c[i];b[i]-=c[i];
	}
	rep(i,1,n)id[i]=i;
	sort(id+1,id+1+n,cmp);
	i64 nowsum=0;
	rep(i,1,n){
		int v=id[i];
		if(heap.size()==y&&heap.top()<b[v]){
			nowsum-=heap.top();heap.pop();
			nowsum+=b[v];heap.push(b[v]);
		}
		if(heap.size()<y){
			nowsum+=b[v];heap.push(b[v]);
		}
		if(heap.size()==y)
			pr[i]=nowsum;
		else
			pr[i]=-1e18;
	}
	while(heap.size())nowsum-=heap.top(),heap.pop();assert(nowsum==0);
	per(i,n,1){
		int v=id[i];
		if(heap.size()==x&&heap.top()<a[v]){
			nowsum-=heap.top();heap.pop();
			nowsum+=a[v];heap.push(a[v]);
		}
		if(heap.size()<x){
			nowsum+=a[v];heap.push(a[v]);
		}
		if(heap.size()==x)
			sf[i]=nowsum;
		else
			sf[i]=-1e18;
		}
	i64 nowmax=-1e18;
	rep(i,1,n-1)nowmax=max(nowmax,pr[i]+sf[i+1]);
	ans+=nowmax;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3832
#include <stdio.h>

int main(){
  int n,d,x,a[100];
  int count = 0;
  int i,j;
  scanf("%d %d %d",&n,&d,&x);
  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }

  for(i = 0;i < n;i++){
    for(j = 1;j <= d;j = j+a[i]){
      count++;
    }
  }

  printf("%d\n",count + x);
  return(0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)998244353;
const double eps=1e-9;
long long seen[100005],v[100005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,x,m,sum=0;
    cin>>n>>x>>m;
    if(n<=100000){
        sum=v[1]=x;
        for(int i=2;i<=n;i++)
            v[i]=(v[i-1]*v[i-1])%m,
            sum+=v[i];
        return cout<<sum,0;
    }
    int ctr=1,cycleBegin,cycleEnd;
    sum=v[1]=x;
    for(int i=2;;i++)
    {
        v[i]=(v[i-1]*v[i-1])%m;
        cycleBegin=seen[v[i]];
        cycleEnd=i-1;
        if(seen[v[i]])
            break;
        seen[v[i]]=i;
        sum+=v[i];
        ctr++;
    }
    long long cycleSum=0;
    for(int i=cycleBegin;i<=cycleEnd;i++)
        cycleSum+=v[i];
    long long rem=n-ctr;
    sum+=rem/(cycleEnd-cycleBegin+1)*cycleSum;
    rem%=cycleEnd-cycleBegin+1;
    for(int i=cycleBegin;i<cycleBegin+rem;i++)
        sum+=v[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 4756
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll n,m;

int main(){
	cin>>n>>m;
	if(n==1&&m==1){
		cout<<1<<endl;
	}else if(n==1||m==1){
		cout<<n*m-2<<endl;
	}else{
		cout<<(n-2)*(m-2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
p = list(map(int, input().split()))
g = [[] for _ in range(0,n+1)]
visit = [None] * (n+1)
ans = 0
for _ in range(0,m):
    x,y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
for i in range(1,n+1):
    if visit[i] is not None:
        continue
    stack = [i]
    part = [i]
    visit[i] = 0
    while len(stack) > 0:
        q = stack.pop()
        for qq in g[q]:
            if visit[qq] is None:
                visit[qq] = 0
                part.append(qq)
                stack.append(qq)
    part2 = set()
    for i in part:
        part2.add(p[i-1])
    for i in part:
        if i in part2:
            ans += 1
print(ans)

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

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    int A,B;
    cin >> A >> B;
    if(A <=8 && B<= 8)cout << "Yay!" << endl;
    else cout << ":(" << endl;

}


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

int main(){
	while(1){
		int n,m;
		cin >> n >> m;
		if(n == 0) break;
		
		vector<int> cell(n),dice(m);
		for(int i=0; i<n; i++){
			cin >> cell[i];
		}
		for(int i=0; i<m; i++){
			cin >> dice[i];
		}
		int curr = 0;
		int ans = 1;
		for(int i=0; i<m; i++, ans++){
			curr += dice[i];
			if(curr >= n-1) break;
			curr += cell[curr];
			if(curr >= n-1) break;
		}
		cout << ans << endl;
	}
	return 0;
}



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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n, k;
  cin >> n >> k;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  
  int dp[n] = {0};
  for(int i=0;i<n-1;i++){
    int minValue = dp[i]+abs(h[i]-h[i+1]);
    for(int j=1;j<k;j++){
      if(j>i)break;
      int value = dp[i-j]+abs(h[i-j]-h[i+1]);
      if(value<minValue) minValue = value;
    }
    dp[i+1] = minValue;
  }

  cout << dp[n-1] << endl;
  
  return 0;
}




Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
const int MAXN = 1005;
const int MAXM = 200005;

vector<int> gph[MAXN];
int adj[MAXN][MAXN], vis[MAXN];
int n, m;
int s[MAXM], e[MAXM];

void dfs(int r, int v){
	vis[v] = 1;
	adj[r][v]++;
	for(auto &i : gph[v]){
		if(i == r) continue;
		if(!vis[i] && adj[r][i] < 2){
			dfs(r, i);
		}
	}
}

int main(){
	cin >> n >> m;
	for(int i=0; i<m; i++){
		scanf("%d %d",&s[i],&e[i]);
		gph[s[i]].push_back(e[i]);
	}
	for(int i=1; i<=n; i++){
		for(auto &j : gph[i]){
			if(adj[i][j] < 2){
				memset(vis, 0, sizeof(vis));
				dfs(i, j);
			}
		}
	}
	for(int i=0; i<m; i++){
		if(adj[e[i]][s[i]] == 0){
			puts(adj[s[i]][e[i]] > 1 ? "diff" : "same");
		}
		else{
			puts(adj[s[i]][e[i]] > 1 ? "same" : "diff");
		}
	}
}


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

int main(){

int A;
int B;
int C;

cin>>A;
cin>>B;
cin>>C;

if(A==B&&A!=C){cout<<"Yes"<<endl;}

else if(A==C&&A!=B){cout<<"Yes"<<endl;}

else if(B==C&&A!=B){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}


}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> z(n, vector<ll>(n, 1000000000));
    vector<tuple<ll, ll, ll>> ky(m);
    vector<vector<ll>> ans(n, vector<ll>(n, 1000000000));
    for (int i = 0; i < m; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        z[a][b] = c;
        z[b][a] = c;
        ky[i] = make_tuple(a, b, c);
    }
    for (int i = 0; i < n; i++) {
        vector<bool> used(n);
        for (int j = 0; j < n; j++) {
            used[j] = false;
        }
        ans[i][i] = 0;
        ll mint = 0;
        while (1) {
            mint = -1;
            for (ll j = 0; j < n; j++) {
                if (!used[j] && (mint== -1 || ans[i][mint] > ans[i][j]))mint = j;
            }
            if (mint == -1)break;
            used[mint] = true;
            for (ll j = 0; j < n; j++) {
                ans[i][j] = min(ans[i][mint] + z[j][mint], ans[i][j]);
            }
        }
    }
    ll ansans = 0;
    for (int i = 0; i < m; i++) {
        if (ans[get<0>(ky[i])][get<1>(ky[i])] != get<2>(ky[i])) { ansans++; }
    }
    cout << ansans << endl;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 6)
def input():
	return sys.stdin.readline()[:-1]

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

edge = [[] for i in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

cnt = 0
for i in range(n):
	h = H[i]
	flag = 1
	for nxt in edge[i]:
		# print(nxt)
		# print(H)
		if H[nxt] >= h:
			flag = 0
			break
		elif H[nxt] < h: continue
	if flag: cnt += 1

print(cnt)

Measured memory_bytes: 89984
n = int(input())
A = [0] + [int(a) for a in input().split()]
B = [0]*(n+1)
B[-1] = A[-1]
for i in range(n-1,0,-1):
    a = A[i]
    for j in range(i,n+1,i):
        a += B[j]
    B[i] = a%2
s = sum(B)
print(s)
if s != 0:
    print(*[idx for idx,b in enumerate(B) if b==1])

Measured memory_bytes: 13108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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; }

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

int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py[90001];
int d[90001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>H>>W>>D;
    REP(i,H) REP(j,W) cin>>A,px[A]=i,py[A]=j;
    for(int i=D+1;i<=H*W;i++) d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    cin>>Q;
    while(Q--){
        cin>>L>>R;
        cout<<d[R]-d[L]<<endl;
    }
}


Measured memory_bytes: 2176
using System;

namespace _0066
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == null)
                {
                    break;
                }
                bool flag = true;
                for (int i = 0; i < 3; i++)
                {
                    int now = i * 3;
                    if (s[now] != 's' && s[now] == s[now + 1] && s[now] == s[now + 2] && flag)
                    {
                        Console.WriteLine(s[now]);
                        flag = false;
                    }
                    else if (s[i] != 's' && s[i] == s[i + 3] && s[i] == s[i + 6] && flag)
                    {
                        Console.WriteLine(s[i]);
                        flag = false;
                    }
                }
                if (flag)
                {
                    if (s[0] != 's' && s[0] == s[4] && s[0] == s[8])
                    {
                        Console.WriteLine(s[0]);
                        flag = false;
                    }
                    else if (s[2] != 's' && s[2] == s[4] && s[2] == s[6])
                    {
                        Console.WriteLine(s[2]);
                        flag = false;
                    }
                }
                if (flag)
                {
                    Console.WriteLine("d");
                }
            }
        }
    }
}

Measured memory_bytes: 8776
n = int(input())
t, a = map(int, input().split())
h_list = [int(i) for i in input().split()]

ans=(abs(t - h_list[0] * 0.006-1),1)   # diff,index
for index,height in enumerate( h_list):
    tempa = t - height * 0.006
    if ans[0] > abs(tempa - a):
        ans = (abs(tempa - a), index + 1)
print(ans[1])    

Measured memory_bytes: 3060
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int p10[10];
  int frac[10];
  p10[0] = 1;
  frac[0] = 1;
  REP(i,9) p10[i+1] = p10[i]*10;
  REP(i,9) frac[i+1] = frac[i]*(i+1);
  while(1){
    int n;
    cin>>n;
    if(!n) break;
    vector<string> f(n);
    vector<char> abts;
    REP(i,n) {
      cin>>f[i];
      for (char c:f[i])
        if ('A' <= c && c <= 'Z') abts.push_back(c);
    }
    sort(begin(abts),end(abts));
    auto itr = unique(begin(abts),end(abts));
    abts.erase(itr, end(abts));
    int l = abts.size();
    vector<int> val(l);
    vector<bool> zeroable(l,true);
    REP(i,n) {
      int m=f[i].size();
      REP(j,m) {
        int k=find(begin(abts),end(abts),f[i][j])-begin(abts);
        val[k] += p10[m-j-1] * (i==(n-1)?-1:1);
        if (j==0&&m>1) zeroable[k] = false;
      }
    }
    vector<int> v(10);
    iota(begin(v),end(v),0);
    int cnt = 0;
    do{
      int sum = 0;
      int ok = true;
      REP(i,l) {
        sum += val[i] * v[i];
        if (!zeroable[i] && v[i] == 0) ok = false;
      }
      if (sum == 0 && ok) ++cnt;
    } while(next_permutation(begin(v),end(v)));
    cout << (cnt / frac[10-l]) << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
_=int(input())
a=list(map(int,input().split()))

x,y,z=0,0,0
for i in a:
    if i%4 == 0:
        z+=1
    elif i%2 == 0:
        y+=1
    else:
        x+=1
if y:
    if x <= z:
        print('Yes')
    else:
        print('No')
else:
    if x <= z+1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 20000
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int w[110], v[110];
ll dp[105][305][105];
signed main(void)
{
	int n, W;
	cin >> n >> W;
	REP(i, n) cin >> w[i] >> v[i];

	for(int i=n-1; i>=0; --i) {
		REP(j, n*3+1) {
			FOR(k, 1, n+1) {
				//cout << i << " " << j << " " << k << " ";
				if(j < w[i] - w[0]) {
					dp[i][j][k] = dp[i+1][j][k];
				} else {
					//if(i == 0) cout << dp[i+1][j][k] << " " << dp[i+1][j-(w[i]-w[0])][k-1] + v[i] << " ";
					dp[i][j][k] = max(dp[i+1][j][k], dp[i+1][j-(w[i]-w[0])][k-1] + v[i]);
				}
				//cout << dp[i][j][k] << endl;
			}
		}
	}

	/*REP(i, n) {
		REP(j, W) {
			REP(k, n) {
				cout << dp[i][j][k] << " ";
			}
			cout << endl;
		}
		cout << "---------------" << endl;
	}*/

	ll ret = -1;
	REP(j, 3*n+1) {
		REP(k, n+1) {
			//cout << dp[0][j][k] << " ";
			if(j + k*w[0] <= W)
				ret = max(ret, dp[0][j][k]);
		}
		//cout << endl;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v)
{
    ll dp[N + 10][W + 10];

    memset(dp, 0, sizeof dp);

    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            ll weight = w[i - 1];
            ll value = v[i - 1];
            if (j - weight >= 0)
            {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight] + value);
            }
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }
    }

    cout << dp[N][W] << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long W;
    scanf("%lld", &W);
    std::vector<long long> w(N);
    std::vector<long long> v(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &w[i]);
        scanf("%lld", &v[i]);
    }
    solve(N, W, std::move(w), std::move(v));
    return 0;
}


Measured memory_bytes: 86144
#include <bits/stdc++.h>
#define tam 300010

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vi> graph;

bool comp(ll a, ll b) {
	return a > b;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    vi arr;
    int in;
    arr.reserve(n + 10);
    for (int i = 0; i < n; i++) {
        cin >> in;
        arr.push_back(in);
    }
    sort(arr.begin(), arr.end());
    int cont = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int temp = arr[i] + arr[j];
            int x = lower_bound(arr.begin(), arr.end(), temp) - arr.begin();
            x--;
            cont += (x - j);
        }
    }
    cout << cont << "\n";
	return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>	a(n); for (auto&& x : a)cin >> x;

	vector< vector<long long> > dp(n+1, vector<long long>(2));
	dp[0][0] = 0; dp[0][1] = (int)-1e9;
	for (int i = 0; i < n; i++) {
		dp[i+1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
		dp[i+1][1] = max(dp[i][1] + a[i], dp[i][0] - a[i]);
	}
	cout << dp[n][0] << endl;

	return 0;
}

Measured memory_bytes: 6144
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
    vector<int> A(3);
    REP(i,3) cin >> A[i];
    sort(A.begin(),A.end());
    int ans = A[2] - A[1];
    A[0] += ans;
    if((A[2] - A[0])%2 == 1){
        ans++;
        A[2]++;
    }
    ans += (A[2]-A[0])/2;
    cout << ans << endl;
    return 0;
}


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

int main() { 	
 	int R,G,B,N;
  cin >> R>>G>>B>>N;
	int r=R;
  int g=G;
  int b=B;
  int count =0;
  if(R==G==B){
  if(N%G==0){
      	int xxx=N/R; 
      int yyy=xxx+2;
      int yyyy=xxx+1;
        int yyyyy =yyy*yyyy;
    count=yyyyy/2;
}else{
    count =0;
    }
  }else{
  for(int i=0;i<=N;i+=r){
  	for(int x=0;x+i<=N;x+=g){
    	for(int y=0;y+x+i<=N;y+=b){
          if(y+x+i==N){
          count+=1;
          }
        }
    }
 	}
}
  cout << count << endl;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a <= b) {
    for (int i = 0; i < b; i++) {
      string to_string(int a);
      cout << a;
    }
  }
  
  else {
    for (int i = 0; i < a; i++) {
      string to_string(int b);
      cout << b;
    }
  }
    
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int  n = sc.nextInt();
     int[] x = new int[n];
     int[] y = new int[n];
     double ans=0;
     for(int i=0;i<n;i++){
       x[i]=sc.nextInt();
       y[i]=sc.nextInt();
     }
     
     for(int i=0;i<n;i++){
       for(int j=i;j<n;j++){
         ans += Math.sqrt(Math.pow(x[i]-x[j],2)+Math.pow(y[i]-y[j],2));
       }
     }
     ans *=2;
     ans = ans/n;
     System.out.println(ans);
   }
}


Measured memory_bytes: 23892
N,K=map(int,input().split())
A=sorted(map(int,input().split()))
d=[0]*(K+1)
for i in range(K):
    x=d[i]^1
    if x:
        for a in A:
            if i+a<K+1:
                d[i+a]=x
print(['Second','First'][d[-1]])

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int A=in(),B=in(),C=in();

	cout << max(C-(A-B),0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
struct node{
	LL v,w;
}a[55];
struct edge{
	LL y,next;
}e[110];LL len=0,last[55];
LL n,c[55],M,D,ans=0;
LL f[125010],pos[55];
void cmin(LL &x,LL y) {x=(x==-1)?y:min(x,y);}
void ins(LL x,LL y)
{
	e[++len].y=y;
	e[len].next=last[x];last[x]=len;
}
void dfs(LL x)
{
	a[x].v=1;a[x].w=c[x];
	for(LL i=last[x];i;i=e[i].next)
	{
		LL y=e[i].y;dfs(y);
		a[x].v+=a[y].v;a[x].w+=a[y].w;
	}
}
bool cmp(LL x,LL y) {return a[x].v*a[y].w>a[y].v*a[x].w;}
LL solve(LL M)
{
	LL tot=0;
	for(LL i=1;i<=n;i++)
	{
		LL x=pos[i],cnt=M/a[x].w;
		if(x!=1) cnt=min(cnt,max(0LL,D-n));
		tot+=cnt*a[x].v;M-=cnt*a[x].w;
	}
	return tot;
}
int main()
{
	scanf("%lld %lld %lld",&n,&M,&D);
	scanf("%lld",&c[1]);
	for(LL i=2;i<=n;i++)
	{
		LL fa;scanf("%lld %lld",&c[i],&fa);
		ins(fa,i);
	}
	dfs(1);
	memset(f,-1,sizeof(f));f[0]=0;
	for(LL i=1;i<=n;i++)
	for(LL j=n*n*n;j>=0;j--)
		if(f[j]!=-1) for(LL k=1;k<=min(n,D);k++) cmin(f[j+a[i].v*k],f[j]+k*a[i].w);
	for(LL i=1;i<=n;i++) pos[i]=i;
	sort(pos+1,pos+n+1,cmp);
	//for(LL i=1;i<=n;i++) printf("%lld:%lld %lld\n",pos[i],a[pos[i]].v,a[pos[i]].w);
	//for(LL i=0;i<=1000;i++) printf("%lld:%lld\n",i,f[i]);
	for(LL i=0;i<=n*n*n;i++)
	{
		//printf("%lld:%lld\n",i,f[i]);
		if(f[i]==-1||f[i]>M) continue;
		ans=max(ans,i+solve(M-f[i]));
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1280
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int N;
vector<int> prime;
void prime_set() {
	prime.push_back(2);
	for (int i = 3;i <= N;i += 2) {
		bool is_prime = true;
		for (int j = 3;j * j <= i;j += 2) {
			if (i % j == 0) {
				is_prime = false;
				break;
			}
		}
		if (is_prime) prime.push_back(i);
	}
}

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

	cin >> N;
	prime_set();
	int n = prime.size();
	vector<ll> prime_cnt(n, 1);
	for (int i = 2;i <= N;i++) {
		int k = i;
		REP(j, n) {
			if (prime[j] > k) break;
			int cnt = 0;
			while (k%prime[j] == 0) {
				cnt++;
				k /= prime[j];
			}
			prime_cnt[j] += cnt;
		}
	}
	ll res = 1;
	const int mod = 1000000007;
	REP(i, n) res = res*prime_cnt[i] % mod;
	cout << res << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define ld long double 
#define float long double 
#define ll long long
#define int long long
#define vl vector<ll> 
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define endl '\n'
#define cnl cout<<endl;
#define pi  3.141592653589793238
#define ms(x,v) ((x), v, sizeof((x)))
#define MAXN 100009
#define CASET int ___T; scanf("%lld", &___T); for(int cs=1; cs <= ___T; cs++)
template<class T> bool umin(T& a, T b) { if(a > b){ a = b;return 1;}return 0;}
template<class T> bool umax(T& a, T b) { if(a < b){ a = b;return 1;}return 0;}
const int N = 200 * 1000 + 9;
const int  inf = 1e18;
const int mod=1e9+7;
int i,j,k;
void solve(){

     string s; cin >> s;
     if(s == "AAA" or s == "BBB"){
      cout << "No" << endl;

     }
     else cout << "Yes" << endl;


 return ;
}
    signed main(){
   
    //CASET
    solve();
    
   
    return 0;
  }

Measured memory_bytes: 256
n, m = map(int, input().split())
*a, = map(int, input().split())

b = 0
c = {0: 1}
cnt = 0
for a in a:
    b = (b + a) % m
    cnt += c.get(b, 0)
    c[b] = c.get(b, 0) + 1
print(cnt)

Measured memory_bytes: 14224
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , m , Q , a[N] , v[N] , _;
int vis[N] , cnt[N] , pos[N];

int main(){
  scanf("%d%d%d",&n,&m,&Q);
  rep(i,0,Q) scanf("%d",a + i);
  reverse(a,a+Q);
  rep(i,0,Q) {
    if(!vis[a[i]])
      vis[a[i]]=1,v[++_]=a[i];
  }
  rep(i,1,m+1) if(!vis[i])
    v[++_]=i;
  rep(i,1,m+1) pos[v[i]]=i;
  cnt[0]=n;
  int Max=0;
  rep(i,0,Q) {
    int t=pos[a[i]];
    if(cnt[t-1]) {
      cnt[t-1]--;
      cnt[t]++;
      Max = max(Max , t);
    } else if(Max < t) {
      puts("No");
      return 0;
    }
  }
  int Min=0;
  rep(i,0,m+1) if(cnt[i]) {
    Min=i;
    break;
  }
  int inc=true;
  rep(i,Min+2,m+1) inc&=v[i]>v[i-1];
  puts(inc ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  ll n;
  cin>>n;
  vector<ll> div(n+1,0);
  ll ans=0;
  for(ll i=1;i<=n;i++)
  {
    for(ll j=1;j*i<=n;j++)
    {
      div[i*j]++;
    }
  }
  for(ll i=1;i<=n;i++)
    ans+=i*div[i];
  cout<<ans;
}

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

#define int long long int
const int N=1e3;

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int s,w;
	cin>>s>>w;
	if(w >= s)
		cout<<"unsafe";
	else
		cout<<"safe";

	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

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

    int res = 0;
    int result = 0;
    REP(i, N + 1) {
        if(N == 1) {
            result = 1;
            break;
        }

        if(i == 0) continue;

        int cnt = 0;
        if(i % 2 == 0) {
            int num = i;
            while(true) {
                cnt++;
                num = num / 2;
                if(num % 2 == 1) break;
            }
        }

        if(res < cnt) {
            res = cnt;
            result = i;
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100005];
int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
	}
	LL ans = 1e18;
	for(int i=1;i<=n;i++){
		int l = i;
		int r = i+k-1;
		if(r > n) break;
		LL res = 0;
		if(a[l] <= 0 && 0 <= a[r]){
			res = min(abs(a[r]) + abs(a[r]-a[l]), abs(a[l]) + abs(a[r]-a[l]));
		}
		else if(a[l] <= 0 && a[r] <= 0){
			res = abs(a[l]);
		}
		else if(0 <= a[l] && 0 <= a[r]){
			res = abs(a[r]);
		}
		ans = min(ans, res);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> par;
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N) {
        for (int i = 0; i < N; ++i) {
            par[i] = i;
            siz[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        siz[ry] = siz[ry] + siz[rx];
    }

    int size(int x) {
        return siz[root(x)];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

ll cmb(ll n) {
    return n * (n - 1) / 2;
}

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

    int A[M], B[M];
    for (int i = 0; i < M; ++i) cin >> A[i] >> B[i];

    // 逆からデータ構造を構築する方が効率的
    reverse(A, A + M);
    reverse(B, B + M);

    int t = 0;
    ll ans[M];
    UnionFind uf(N);
    map<int, int> mp;
    for (int i = 0; i < M ; ++i) {

        int aa = A[i] - 1;
        int bb = B[i] - 1;

        if (i == 0) {
            ans[i] = cmb(N);
        }
        else {
            ans[i] = cmb(N);
            for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
                ans[i] -= cmb(itr->first) * itr->second;
            }
        }

        int siza = uf.size(aa);
        int sizb = uf.size(bb);
        int flg = uf.same(aa, bb);

        uf.unite(aa, bb);
        int sizab = uf.size(aa);

        if (!flg) {
            if (mp.count(siza) != 0) {
                mp[siza] -= 1;
                if (mp[siza] == 0) mp.erase(siza);
            }
            if (mp.count(sizb) != 0) {
                mp[sizb] -= 1;
                if (mp[sizb] == 0) mp.erase(sizb);
            }
            if (mp.count(sizab) != 0) {
                mp[sizab] += 1;
            }
            else {
                mp[sizab] = 1;
            }
        }
    }

    reverse(ans, ans + M);

    for (int i = 0; i < M; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ -  =**/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k,q;
    sf(n);sf(k);sf(q);
    vi a(n+1);
    fill(a.begin(),a.end(),k);
    int x;
    in(i,q)
    {
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]-q>0)
            cout<<"Yes\n";
        else cout<<"No\n";
    }
}


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

ll n, x;
map<ll, ll> mp;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n>> x;
        ll an = 1;
        for (ll i = 2; i*i <= x; i++)
                while (x % i == 0) {
                        x /= i;
                       mp[i]++;
                }
        if (x > 1) {
                mp[x]++;
        }
        for (auto s: mp) {
                if (s.second >= n)
                        an *= (ll)pow(s.first, s.second / n);
        }
        cout << an  ;
return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

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

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}

int dp[2][5005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  int *dp0 = dp[0], *dp1 = dp[1];
  for (int i = n - 2; i >= 0; --i) {
    fill(dp1, dp1 + 5005, 0);
    for (int j = i + 1; j < n; ++j) {
      if (s[i] == s[j]) {
        dp1[j] = dp0[j + 1] + 1;
        chmax(ans, min(dp1[j], j - i));
      }
    }
    swap(dp0, dp1);
  }
  cout << ans << endl;
}


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

ans = 0
r = 0
tmp = 0
for l in range(N):
    while r < N and (tmp&A[r]) == 0:
        tmp += A[r]
        r += 1
    tmp -= A[l]
    ans += r - l
print(ans)

Measured memory_bytes: 24840
#include<bits/stdc++.h>
#define ll     long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll ll,ll ll>
#define all(v) (v).begin(), (v).end()
using namespace std;

void solve()
{
    ll h, w, m, x, y;
    cin >> h >> w >> m;
    std::vector<pair<ll, ll>> col(w + 1), row(h + 1);
    for(int i = 0; i <= w; i++)
        col[i].second = i;
    for(int i = 0; i <= h; i++)
        row[i].second = i;

    map<pair<ll, ll>, bool> lol;
    for(int i = 0; i < m; i++)
    {
        cin >> x >> y;
        lol[ {x, y}] = 1;
        row[x].first++;
        col[y].first++;
    }
    sort(all(col));
    reverse(all(col));
    sort(all(row));
    reverse(all(row));
    ll ans = 0;
    for(int i = 0; i < row.size() and row[i].first == row[0].first; i++)
        for(int j = 0; j < col.size() and col[j].first == col[0].first; j++)
        {

            ans = max(ans, row[i].first + col[j].first - lol[ {row[i].second, col[j].second}]);
            if(!lol[ {row[i].second, col[j].second}])
                {cout << ans;
            return;}
        }
    cout << ans;
}
int main()
{



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

    ll TESTS = 1;
    // cin >> TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 31444
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct Dice{
  int s[6];
  void roll(char c){
    //the view from above
    // N
    //W E
    // S
    //s[0]:top
    //s[1]:south
    //s[2]:east
    //s[3]:west
    //s[4]:north
    //s[5]:bottom
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    
    // migi neji 
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }
    
    if(c=='L'){
      b=s[1];
      s[1]=s[3];
      s[3]=s[4];
      s[4]=s[2];
      s[2]=b;
    }
    
  }
  int top() {
    return s[0];
  }
  int hash(){
    int res=0;
    for(int i=0;i<6;i++) res=res*256+s[i];
    return res;
  }
};
vector<Dice> makeDices(Dice d){
  vector<Dice> res;
  for(int i=0;i<6;i++){
    Dice t(d);
    if(i==1) t.roll('N'); 
    if(i==2) t.roll('S'); 
    if(i==3) t.roll('S'),t.roll('S');
    if(i==4) t.roll('L'); 
    if(i==5) t.roll('R'); 
    for(int k=0;k<4;k++){
      res.push_back(t);
      t.roll('E');
    }
  }
  return res;
}
//END CUT HERE

signed ITP1_11_A(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  string s;cin >> s;
  for(int i=0;i<(int)s.size();i++) d.roll(s[i]);
  cout << d.top() << endl;
  return 0;
}

/*
  verified on 2018/02/09
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_A
*/

signed AOJ_0502(){
  Int n;
  while(cin>>n,n){
    Dice d;
    for(Int i=0;i<6;i++) d.s[i]=i+1;

    Int ans=d.top();
    for(Int i=0;i<n;i++){
      string s;
      cin>>s;
      d.roll(s[0]);
      ans+=d.top();
    }
    cout<<ans<<endl;
  }
  
  return 0;
}


/*
  verified on 2018/02/09
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0502
*/

signed main(){
  ITP1_11_A();
  //AOJ_0502();
  return 0;
}



Measured memory_bytes: 3184
k = int(input())

ones = set()
x = 1
while(not x in ones):
    ones.add(x)
    x = (x*10)%k

num = 1
mask = (1<<k) -1
for i in range(1,46):
    next = 0
    for j in ones:
        next |= (num<<j)
    num = (next&mask) | (next>>k)

    if(num%2==1):
        print(i)
        exit()

Measured memory_bytes: 84172
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#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()
typedef long long ll;

const int MOD = 1e9+7;

map<int64_t,int> prime_factor(int64_t n){
    map<int64_t,int>ret;
    for(int64_t i=2;i*i<=n;i++){
        while(n%i==0){
            ret[i]++;
            n/=i;
        }
    }
    if(n!=1)ret[n]=1;
    return ret;
}

int main(){
    int N;cin >> N;
    vector<int> factors(N+1);
    map<int64_t,int> pf;
    for(int i=1;i<=N;i++){
        for(auto p:prime_factor(i)){
            pf[p.first]+=p.second;
        }
    }
    ll res=1;
    for(auto p:pf){
        //cout << p.first << ' ' << p.second << endl;
        res*=p.second+1;
        res%=MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256