akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
	int n;
	int tmp;
	int tmp2;
	cin >> n;
	ll sum = 0;
	for (int i=1;i <=n;i++) {
		for (int j= 1 ; j<=n ;j++) {
			for (int k= 1 ; k<=n ;k++) {
				tmp = gcd(i,j);
				tmp2 = gcd(tmp,k);
			sum+= tmp2;
			}
		}
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3196
n = int(input())

M = 1000000007
#compute all prime number in 1000

def isPrime(x):
    for i in range(2,x):
        if x%i==0:
            return False
    return True

primes = []
cnt = dict()
for i in range(2,1000):
    if isPrime(i):
        primes.append(i)
        cnt[i] = 0
for i in range(2,n+1):
    x = i
    for p in primes:
        if p>x:
            break
        while x%p==0:
            x//=p
            cnt[p]+=1

res = 1

for p,c in cnt.items():
    res = (res*(c+1))%M
print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define llint long long

using namespace std;

llint n, l, t;
llint x[100005], w[100005];
vector<llint> vec[2];
llint ans[100005];

int main(void)
{
	cin >> n >> l >> t;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> w[i];
		w[i]--;
		vec[w[i]].push_back(x[i]);
	}
	t *= 2;
	
	for(int i = 0; i < n; i++){
		llint z = i;
		if(w[i] == 0){
			z += t/l * vec[1].size(), z %= n;
			if(x[i]+t%l < l) z += upper_bound(vec[1].begin(), vec[1].end(), x[i]+t%l) - lower_bound(vec[1].begin(), vec[1].end(), x[i]), z %= n;
			else{
				z += vec[1].end() - lower_bound(vec[1].begin(), vec[1].end(), x[i]), z %= n;
				z += upper_bound(vec[1].begin(), vec[1].end(), x[i]+t%l-l) - vec[1].begin(), z %= n;
			}
			ans[z] = (x[i]+t/2)%l;
		}
		else{
			z += n - t/l * vec[0].size() % n, z %= n;
			if(x[i]-t%l >= 0) z += n - (upper_bound(vec[0].begin(), vec[0].end(), x[i]) - lower_bound(vec[0].begin(), vec[0].end(), x[i]-t%l)) % n, z %= n;
			else{
				z += n - (upper_bound(vec[0].begin(), vec[0].end(), x[i]) - vec[0].begin()) % n, z %= n;
				z += n - (vec[0].end() - lower_bound(vec[0].begin(), vec[0].end(), x[i]-t%l+l)) % n, z %= n;
			}
			ans[z] = (x[i]-t/2%l+l)%l;
		}
	}
	
	for(int i = 0; i < n; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,n,m,d,k=2,f=0;
    vector<pair<long long,long>>x;
    cin>>n;
//    for(i=1; i<=n; i++)
//        b[i]=i;
    for(i=1; i<=n; i++)
    {
        cin>>m;
        x.push_back({m,i});
    }
    sort(x.begin(),x.end());
//    for(i=1;i<n;i++)
//        cout<<x[i].first<< " "<<x[i].second<<endl;
    if(x[0].first !=1)
        cout<<-1<<endl;
    else
    {
        d=x[0].second;
        //cout<<d<<endl;
        for(i=1; i<n; i++)
        {
            if(x[i].first == k)
            {
                if(x[i].second > d)
                {
                    d=x[i].second;
                    k++;
                    //cout<<d<<" "<<k<<endl;
                }
            }
        }

            cout<<n-k+1<<endl;
    }
}



Measured memory_bytes: 6384
def bellman_ford(N, M, edge):
    d = [10 ** 100] * N
    d[0] = 0
    infFlag = False
    for count in range(N + 23):
        for i in range(M):
            if d[edge[i][0]] + edge[i][2] < d[edge[i][1]]:
                d[edge[i][1]] = d[edge[i][0]] + edge[i][2]
                if count == N + 22 and edge[i][1] == N - 1:
                    infFlag = True
    return infFlag, -d[N - 1]


def main():
    N, M = map(int, input().split())
    edge = []
    for i in range(M):
        a, b, c = map(int, input().split())
        edge.append([a - 1, b - 1, -c])
    infFlag, ans = bellman_ford(N, M, edge)
    if infFlag:
        print('inf')
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3408
#include <cstdio>

static const size_t N_MAX = 100;

size_t N;
int A[N_MAX];

void inspect() {
  for (size_t i = 0; i < N - 1; i++)
    printf("%d ", A[i]);
  printf("%d\n", A[N-1]);
}

int main() {
  scanf("%zu", &N);
  for (size_t i = 0; i < N; i++)
    scanf("%d", &A[i]);
  inspect();
  for (size_t i = 1; i < N; i++) {
    auto v = A[i];
    auto j = i;
    while (j >= 1 && A[j-1] > v) {
      A[j] = A[j-1];
      j--;
    }
    A[j] = v;
    inspect();
  }
  return 0;
}

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

long double arr[2000000];

int main()
{
    int t;
    cin >> t;
    int ac = 0, wa = 0, tle = 0, re = 0;
    while(t--)
    {
        string s;
        cin >> s;
        if(s=="WA")wa++;
        else if (s=="TLE")tle++;
        else if(s=="RE")re++;
        else ac++;
    }
       cout << "AC" << " x " << ac << endl;
       cout << "WA" << " x " << wa << endl;
       cout << "TLE" << " x " << tle << endl;
       cout << "RE" << " x " << re << endl;


}


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

#define int long long

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

int H, W, K;
char A[800][800];
int dp[800][800] = {};

signed main() {
    cin >> H >> W >> K;
    int sy, sx;
    for (int i = 0; i < H; i++) {
        string Al;
        cin >> Al;
        for (int j = 0; j < W; j++) {
            A[i][j] = Al[j];
            if (A[i][j] == 'S') {
                sy = i, sx = j;
            }
        }
    }
    queue<pair<int, int> > bfs;
    bfs.push(make_pair(sy, sx));
    dp[sy][sx] = 1;
    while (!bfs.empty()) {
        int y = bfs.front().first, x = bfs.front().second;
        bfs.pop();
        if (dp[y][x] == K + 1) {
            continue;
        }
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W || A[ny][nx] == '#' || dp[ny][nx] != 0) {
                continue;
            }
            bfs.push(make_pair(ny, nx));
            dp[ny][nx] = dp[y][x] + 1;
        }
    }
    int ans = LLONG_MAX;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (dp[i][j] != 0) {
                if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
                    ans = 1;
                }
                ans = min(ans, 1 + (int)ceil((double)i / K));
                ans = min(ans, 1 + (int)ceil((double)j / K));
                ans = min(ans, 1 + (int)ceil((double)(H - i - 1) / K));
                ans = min(ans, 1 + (int)ceil((double)(W - j - 1) / K));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5888
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long i64;

int CeilIndex(const vector<i64>& tail,int l,int r,i64 key)
{
    while(r - l > 1)
    {
        int m = (l + r) / 2;
        if(tail[m] >= key)
            r = m;
        else   
            l = m;
    }
    return r;
}

vector<i64> LIS(const vector<i64>& vec)
{
    vector<i64> tail;
    tail.push_back(vec[0]);

    for(int i = 1;i < vec.size();++i)
    {
        if(vec[i] < tail[0])
            tail[0] = vec[i];
        else if(vec[i] > tail.back())
        tail.push_back(vec[i]);
        else
        {
            tail[CeilIndex(tail,-1,tail.size() - 1,vec[i])] = vec[i];
        }
    }
    return tail;
}

#include <iostream>

int main()
{
    int n;
    cin >> n;
    vector<i64> a;
    for(int i = 0;i < n;i++)
    {
        int t;
        cin >> t;
        a.push_back(t);
    }

    cout << LIS(a).size() << endl;
}




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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int main() {
    ll n, m;
    cin >> n >> m;
    ll ans = 0;

    if(n*2 >= m) {
        cout << m/2 << endl;
        return 0;
    } else {
        ans += n;
        m -= 2*n;
        cout << ans + m/4 << endl;
    }

    return 0;
}
 

Measured memory_bytes: 256
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = sorted(LI())
counter_A = collections.Counter(A)
sequence = [0]*(10**6+1)
ans = 0
for k,v in counter_A.items():
    if sequence[k]==1:
        continue
    if v==1:
        ans += 1
    for i in range(k,10**6+1,k):
        sequence[i] = 1
print(ans)


Measured memory_bytes: 122604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int res = 0;
  int k = 0;
  for (int now = 1; now <= 1000; now++) {
    res += now;
    if (res == N) {
      k = now;
      break;
    }
    if (res > N) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  vector<int> ans[(N*2) / k];
  int cnt = 1;
  for (int i = 0; i < (N*2) / k; i++) {
    for (int j = i + 1; j < (N*2) / k; j++) {
      ans[i].push_back(cnt);
      ans[j].push_back(cnt);
      cnt++;
    }
  }

  cout << (N*2) / k << endl;
  for (int i = 0; i < (N*2)/k; i++) {
    cout << ans[i].size() << " ";
    for (int j = 0; j < ans[i].size(); j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#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;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long a, long long b, long long h){
 cout << (a+b) * h/2<<endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long h;
    scanf("%lld",&h);
    solve(a, b, h);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A[111111];

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  long long dp[111111][2];

  memset(dp, -1, sizeof(dp));

  dp[0][0] = - A[0];
  dp[0][1] =   A[0];

  for (int i = 1; i < N - 1; i ++) {
    dp[i][0] = std::max(dp[i - 1][0] + A[i], dp[i - 1][1] - A[i]);
    dp[i][1] = std::max(dp[i - 1][0] - A[i], dp[i - 1][1] + A[i]);
  }

  dp[N - 1][0] = dp[N - 2][0] - A[N - 1];
  dp[N - 1][1] = dp[N - 2][1] + A[N - 1];

  std::cout << std::max(dp[N - 1][0], dp[N - 1][1]) << std::endl;

  return 0;
}


Measured memory_bytes: 2432
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = input()[0:-1]
# n = int(input())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]
n = int(input())
a = list(map(int, input().split()))
# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    if 0 in a:
        print(0)
    else:
        ans = 1
        for i in a:
            ans *= i
            if ans >10**18:
                print(-1)
                exit()
        print(ans)    
if __name__ == '__main__':
    main()

Measured memory_bytes: 21812
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;
int gcd(int a, int b){
   int c;
   if(a<b){c=b;b=a;a=c;}
   while(a%b!=0){
       c=a%b;
       a=b;
       b=c;
   }
   return b;
}
int main() {

    int i, j, n, p, q, temp;
    int t;
    int time = 0;
    int flag = 0;
    int maxa = 0;
    string s;
    cin >> n;
    int a[n];
    int right[n];
    int left[n];
    int kotae[n];

    for (i = 0; i < n; ++i) {
        cin >> a[i];
    }
    left[0] = a[0];
    right[n-1] = a[n - 1];
    for (i = 1; i < n; i++) {
        left[i] = gcd(left[i - 1], a[i]);
    }

    for (i = n-2; i >= 0; i--) {
        right[i] = gcd(right[i + 1], a[i]);
    }
    for (i = 0; i < n; i++) {
        if(i==0){kotae[i]=right[1];}
        else if(i==n-1){kotae[i]=left[n-2];}
        else {
            kotae[i] = gcd(left[i - 1], right[i+1]);
        }
        maxa=max(kotae[i],maxa);
    }
    cout << maxa;

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		int n = s.length();
		
		int []a = new int [n];
		
		for(int i = n-1 ;i >= 0 ;i--) {
			a[n-i-1] = (s.charAt(i) - '0');
		}
		
		int []p = new int [n];
		
		p[0] = 1;
		for(int i = 1; i < n;i++) {
			p[i] = (p[i-1] * 10)%2019;
		}
		
		int []sum = new int [n+1];
		int []cnt = new int [2020];
		
		cnt[sum[0]]++;

		for(int i = 0 ; i < n;i++) {
			sum[i+1] = (sum[i] + a[i]*p[i])%2019;
			cnt[sum[i+1]]++;
		}
		
		int q = 0;
		
		for(int i =0 ; i < 2020 ;i++) {
			q += ((cnt[i]-1)*cnt[i])/2;
		}
		
		System.out.println(q);
		
	}
	}




Measured memory_bytes: 42788
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string s;
int x, y, px, py;
std::vector<int>ls, lr, ud;

int main()
{
	in >> s >> x >> y;

	int lastT = -1;
	rep(i, s.length())
	{
		if (s[i] == 'T')
		{
			ls.push_back(i - lastT - 1);
			lastT = i;
		}
		else if (i == s.length() - 1)
		{
			ls.push_back(i - lastT);
		}
	}
	rep(i, ls.size())
	{
		if (i % 2 == 0) { lr.push_back(ls[i]); }
		else { ud.push_back(ls[i]); }
	}
	std::sort(lr.begin() + 1, lr.end(), std::greater<int>());
	std::sort(ud.begin(), ud.end(), std::greater<int>());
	int looking = 0;	// 0:→ 1:← 2:↑ 3:↓
	rep(i, ls.size())
	{
		if (i == 0) { px += lr[i]; }
		else
		{
			if (looking <= 1)
			{
				if (y - py >= 0)
				{
					looking = 2;
					py += ud[i / 2];
				}
				else
				{
					looking = 3;
					py -= ud[i / 2];
				}
			}
			else
			{
				if (x - px >= 0)
				{
					looking = 0;
					px += lr[i / 2];
				}
				else
				{
					looking = 1;
					px -= lr[i / 2];
				}
			}
		}
	}
	if (x == px && y == py) { out << "Yes" << std::endl; }
	else { out << "No" << std::endl; }
	return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-

# sys.setrecursionlimit(100000)
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)

def slv(N, M, Q, ABCD):

    def dfs(a, n):
        r = 0
        if n == N:
            t = 0
            for abcd in ABCD:
                A, B, C, D = abcd
                if a[B] - a[A] == C:
                    t += D
            return t
        b = a[-1]
        for c in range(b, M+1):
            a.append(c)
            r = max(r, dfs(a, n+1))
            a.pop()
        return r
    return dfs([1], 0)


def main():
    N, M, Q = read_int_n()
    ABCD = [read_int_n() for _ in range(Q)]
    print(slv(N, M, Q, ABCD))


if __name__ == '__main__':
    main()


Measured memory_bytes: 81628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define LOOP while(true)
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> X(N);
	rep(i, N)cin >> X[i];//X座標
	int ans = 0;
	int Lim0 = K / 2;//Aが動く限界
	
	for(int i = 0; i < N; i++){
		int dis;
		if(X[i] > Lim0)dis = abs(K - X[i]);//X[i]がLim0よりx軸の正の方向
		else dis = X[i];//0 < X[i] <= Lim0
		ans += dis * 2;//往復なので2倍
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long N , K;
  cin >> N >> K;
  N %= K; 
  if(N == 0){
    cout << 0 << endl;
  }
  else if(N > abs(N - K)){
    cout << abs(N-K) << endl;
  }
  else if(N < abs(N - K)){
    cout << N << endl;
  }
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>


int main(void)
{
  //dとnを入力
  int d,n;
  scanf("%d%d",&d,&n);


  //n個の座標をforで入力
  int i,j,k;
  /*
  int x[n][d];
  for(i=0;i<n;i++)
    for(k=0;k<d;k++)
      scanf("%d",&x[i][k]);
      */
  int x[d][n];
  for(i=0;i<d;i++)
    for(k=0;k<n;k++)
      scanf("%d",&x[i][k]);



  //計算開始
  double dist;
  int cnt=0;

  //i,jを決める
  for(i=0;i<d;i++)
    //for(j=i+1;j<n-(i+1);j++){
    for(j=i+1;j<d;j++){
/*
printf("(%d,%d,%d,%d) - (%d,%d,%d,%d)  ",
                x[i][0], x[i][1], x[i][2], x[i][3],
                x[j][0], x[j][1], x[j][2], x[j][3]);
                */

      //点iと点jの距離を求める
      dist = 0;
      for(k=0;k<n;k++)
        //dist += (x[i][k]-x[j][k])^2;
        dist += pow(x[i][k]-x[j][k],2);
      dist = sqrt(dist);
//   printf("%f\n", dist);

      //ceil(切り上げ関数)とfloor(切り捨て関数)を使ってdistが整数か判定
      //distが整数ならcntを1増やす
      if(ceil(dist)==floor(dist))
//      if (dist*dist==pow((int)dist,2))
        cnt++;
    }


  //cntを出力して終了
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 128
def selection_sort():
    N = int(input())
    A = [int(_) for _ in input().split()]

    ans = 0

    for i in range(N):
        minj = i 
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        if i != minj:
            ans += 1
    
    print(' '.join(map(str, A)))
    print(ans)
        

selection_sort()



Measured memory_bytes: 5604
#ifndef YK_INCLUDE
#include <bits/stdc++.h>
#endif //! YK_INCLUDE
int main() {
    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

    int N, M, C;
    std::cin >> N >> M >> C;
    std::vector<int> B(M);
    for(auto&i:B)std::cin >> i;
    int ans = 0;
    for(int i = 0;i<N;++i){
    	int sum = 0;
    	for(int j = 0;j<M;++j){
    		int A;
    		std::cin >> A;
    		sum += A*B[j];
    	}
    	if(sum+C>0)++ans;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<char> s(N);
  for(int i=0;i<N;i++) {
    cin>>s.at(i);
  }
  
  string ans="Three";
  for(int i=0;i<N;i++) {
    if(s.at(i)=='Y') {
      ans="Four";
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int N;
    cin>>N;
    vector <int>p(N);
    for(int i=0 ; i<N ; i++){
        cin>>p[i];
    	p[i]-=1;
    }
	int count=0;
	for(int i=0 ; i<N ; i++){
		if(p[i]==i){
			if(p[i+1]==i+1)i++;
			count+=1;
		}
	}
    cout<<count<<endl;
    
    
    return 0;
}


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

bool isRect(int data[5][5], int x1, int y1, int x2, int y2){
  for(int i = y1; i < y2; i++) {
    for(int j = x1; j < x2; j++) {
      if(j < 0 || j >= 5) return false;
      if(i < 0 || i >= 5) return false;
      if(data[i][j] != 1) return false;
    }
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  for(int t = 0; t < n; t++) {
    int data[5][5];
    for(int i = 0; i < 5; i++) {
      for(int j = 0; j < 5; j++) {
	cin >> data[i][j];
      }
    }
    int max = -1;
    for(int i = 0; i < 5; i++) {
      for(int j = 0; j < 5; j++) {
	for(int h = 1; h <= 5; h++) {
	  for(int w = 1; w <= 5; w++) {
	    if(isRect(data, j, i, j+w, i+h)) {
	      int newValue = w*h;
	      if(newValue > max) max = newValue;
	    }
	  }
	}
      }
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <map>
#include <utility>
#include<functional>
#include <unordered_map>
#include <set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define MOD 1000000007           //10億　= 10^9になってる
#define juu 100000               //10万 10e5
#define hyaku 1000000            //100万　10e6
#define mINF -922337200085470000 //llのmax-1桁の小さい方
#define pINF 922337203600070000  //llのmax-1桁のデカい方
#define uINF 1844674407300000000 //ullのmax-1桁してる
#define pi 3.1415926535897932384
#define all(v) v.begin(), v.end()
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}

/*intで収まる範囲であってくれ*/
ll nCr(ll n, ll r)
{
    ll val = 1;
    ll i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(ll n, ll r)
{
    ll val = 1;
    ll i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}
template <typename T>
bool chmin(T &a, const T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &a, const T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

/*ソートして被りを無くす*/
template <typename T>
void eraseSame(T &a)
{
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

/*aとbで大きい方を後ろにする。変更なしならtrue、ありならfalse */
template <typename T>
bool swapmax(T &a, T &b)
{
    T temp;
    temp = a;
    if (a > b)
    {
        a = b;
        b = temp;
        return false;
    }
    return true;
}
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

/*一行に入力が何個あるかを1,ぶち込むvectorを2*/
template <typename T>
void splitIn(ll N, vector<T> &array)
{
    T temp;
    int i = 0;
    if(N == 0){
        return ;
    }
    array.resize(N);
    while (cin >> temp)
    {
        array[i] = temp;
        i++;
        if (i >= N)
        {
            break;
        }
    }
    return;
}
int main()
{
    ll n,m;
    cin >> n >>m;
   cout << lcm(n,m);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

const int MAX_N = 400;

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

bool color[MAX_N][MAX_N];
int H, W;

char ch[MAX_N+1];
bool used[MAX_N][MAX_N];

void input(){
    cin >> H >> W;
    for(int i=0; i<H; ++i){
        cin >> ch;
        for(int j=0; j<W; ++j){
            color[i][j] = (ch[j] == '#');
        }
    }
}

bool isin_(int i, int j){
    return i>=0 && i < H && j>=0 && j <W;
}

bool check_(int i, int j, int d){
    int ni = i + di[d];
    int nj = j + dj[d];
    if(!isin_(ni, nj)) return false;
    if(color[i][j] == color[ni][nj]) return false;
    return true;
}


long long solve(){
    long long ans = 0;
    long long b = 0, w = 0;
    for(int i= 0; i<H; ++i){
        for(int j=0; j<W; ++j){
            if(used[i][j]) continue;
            b = 0;
            w = 0;
            queue<P> que;
            used[i][j] = true;
            que.push(P(i, j));
            while(!que.empty()){
                P p = que.front();
                que.pop();
                int ci = p.first, cj = p.second;
                if(color[ci][cj]) b++;
                else w++;
                for(int d=0; d<4; ++d){
                    if(!check_(ci, cj, d)) continue;
                    int ni = ci + di[d], nj = cj + dj[d];
                    if(used[ni][nj]) continue;
                    used[ni][nj] = true;
                    que.push(P(ni, nj));

                }
            }
            ans += b * w;
        }
    }
    return ans;
}


int main(){
    input();
    long long ans = solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        ArrayList<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            A.add(scanner.nextInt());
        }
        int g = A.get(0);
        for (int i = 1; i < N; i++) {
            g = gcd(g, A.get(i));
        }
        int maxa = Collections.max(A);
        if(K%g == 0 && maxa >= K){
            System.out.println("POSSIBLE");
        }else{
            System.out.println("IMPOSSIBLE");
        }
    }

    public static int gcd(int a, int b){
        if(a<b){
            int temp = a;
            a = b;
            b=temp;
        }
        if(b ==0){
            return a;
        }
        a = a % b;
        return gcd(a,b);
    }
}

Measured memory_bytes: 60616
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// AOJ DSL_3_C The Number of Windows

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q; cin >> N >> Q;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
  }
  vector<ll> X(N);
  REP(i, Q){
    cin >> X[i];
  }
  REP(i, Q){
    int right = 0;
    ll res = 0, s = 0; // sは和
    for(int left = 0; left < N; left++){
      // rightの位置決め
      while(right < N && s+A[right] <= X[i]){
        s += A[right]; // 実際にrightを1進めたときの処理
        right++;
      }
    
      // whileループをbreakした後(rightは条件を満たす最大)に行う処理
      res += (right - left); // 要素の長さを足すことで組数を求めている
    
      // leftをインクリメントする準備
      if(right == left) right++;
      else s -= A[left];
    }
    cout << res << endl;
  }
}


Measured memory_bytes: 4372
#include<iostream>
#include<vector>

struct segment_tree_max{
  int n;
  std::vector<int64_t> data;
  int64_t identity;

  int64_t max(int64_t a,int64_t b){return a<b?b:a;}

  segment_tree_max(){}
  segment_tree_max(int sz,int64_t id){
    n = 1;
    while(n<sz)n*=2;
    identity = id;
    data.resize(2*n,identity);
  }
  void set(int i,int64_t val){
    i += n;
    data[i] = val;
    i /= 2;
    while(i){
      data[i] = max(data[2*i],data[2*i+1]);
      i /= 2;
    }
  }
  int64_t get_max(int l,int r){
    l += n, r += n;
    int64_t res = identity;
    while(l<r){
      if(l&1) res = max(res,data[l++]);
      if(r&1) res = max(res,data[--r]);
      l /= 2, r /= 2;
    }
    return res;
  }
  int64_t operator[](int k)const{
    return data[k+n];
  }
};

int main(){

  int n;
  std::cin>>n;
  std::vector<int64_t> h(n),a(n);
  for(auto& hi:h)std::cin>>hi;
  for(auto& ai:a)std::cin>>ai;

  segment_tree_max dp(n+1,0);

  for(int i=0;i<n;++i){
    auto& hi = h[i];
    auto& ai = a[i];
    int64_t tmp = dp.get_max(0,hi);
    dp.set(hi,tmp+ai);
  }

  int64_t ans = dp.get_max(0,n+1);
  std::cout<<ans<<std::endl;

}

Measured memory_bytes: 10372
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define foreach(c, it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)

typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

int main(){
  
  int N;
  cin >> N;
  while(N--) {
    string s; cin >> s;
    if(s[0] != '>') {
      cout << "NA" << endl;
      continue;
    }
    int select = 0;
    if(s[1] == '\'') {
      int cnt = 0;
      if(!(s.size() % 2)) {
        for(int i = 2; i < s.size() / 2; i++) {
          if(s[i] != '=') {
            select = -1;
            break;
          }
          cnt++;
        }
        if(~select && !cnt) {
          cout << "NA" << endl;
          continue;
        }
        for(int i = s.size() / 2 + 1; i < s.size() - 1; i++) {
          if(s[i] != '=') {
            select = -1;
            break;
          }
          cnt--;
        }
      } else select = -1;
      if(!cnt && ~select && s[s.size() / 2] == '#' && s[s.size() - 1] == '~')
        cout << "A" << endl;
      else cout << "NA" << endl; 
    } else if(s[1] == '^') {
      if(!(s.size() % 2)) {
        for(int i = 2; i < s.size() - 2; i++) {
          if((!(i % 2) && s[i] != 'Q') || (i % 2 && s[i] != '=')) {
            select = -1;
            break;
          }
        }
        if(s.size() >= 6 && ~select && s[s.size() - 1] == s[s.size() - 2] && s[s.size() - 1] == '~') cout << "B" << endl;
        else cout << "NA" << endl;
      } else cout << "NA" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 1208
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	ll co[n+1] ={};
	REP(i, n) co[a[i]] ++;
	ll sum = 0;
	REP1(i, n) sum += co[i] * (co[i]-1) /2;
	REP(i,n) cout << sum - co[a[i]] + 1 << endl;
}

Measured memory_bytes: 4992
import sys

def subset(line):
    l = line.strip().split(" ")
    a = list(map(int, l))
    xy = list(map(lambda x: [x // 10, x % 10], a))
    dominos = [[2 if [x, y] in xy and x == y else \
                1 if [x, y] in xy else \
                1 if [y, x] in xy else 0 \
                for x in range(0, 7)] for y in range(0, 7)] 
    digits = []
    for i in xy:
        digits.extend(i)
    digits = list(set(digits))
    digits.sort()
    return digits, dominos

def add_matrix(a, b):
    c = [[a[j][i] + b[j][i] for i in range(0, 7)] for j in range(0, 7)]
    return c

def mul_matrix(a, b):
    c = [[0 for i in range(0, 7)] for j in range(0, 7)]
    for j in range(0, 7):
        for i in range(0, 7):
            for k in range(0, 7):
                c[j][i] += a[j][k] * b[k][i]
    return c
                
def is_connected(d, g):
    a = g[:]
    z = [[0 for i in range(0, 7)] for j in range(0, 7)]
    b = a
    for i in range(0, 7):
        z = add_matrix(z, b)
        b = mul_matrix(b, a)
    zeros = 0
    for i in d:
        if z[d[0]][i] == 0:
            zeros += 1
    return zeros == 0
        
lno = 0
for line in sys.stdin:
    lno += 1
    if lno == 1:
        n = int(line)
    else:
        digits, dominos = subset(line)
        if not is_connected(digits, dominos):
            print("No")
        else:
            order = [sum(dominos[i]) for i in range(0, 7)]
            odd = 0
            for i in digits:
                if order[i] % 2 != 0:
                    odd += 1
            if odd <= 2:
                print("Yes")
            else:
                print("No")
        lno = 0


Measured memory_bytes: 5620
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N;
int h[MAX_N + 1];

int main(void)
{
  cin >> N;
  REP(i, N) cin >> h[i];
  int cnt = 0;
  int s = 0, t = 0;
  while (s < N) {
    t = s;
    while (t < N && h[t] != 0) h[t]--, t++;
    if (t != s) cnt++;
    while (s < N && h[s] == 0) s++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int dp[100005][3];
int main()
{
  int n,i;
  cin>>n;
  int a,b,c;
  for(i=0;i<n;i++)
  {
    cin>>a>>b>>c;
    if(i==0) dp[i][0]=a;dp[i][1]=b;dp[i][2]=c;
    dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
  }
  cout<<max( max(dp[n-1][0],dp[n-1][1]),dp[n-1][2] );
 
  return 0;
}

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


int main(){
        int N,i;
        cin >> N;
        int a;
        vector <int> c(N);
        for(int i=0; i<N; i++) {
                cin >> c[i];
        }

        sort(c.begin(), c.end() );

        a=accumulate(c.begin(), c.end(), 0);

        if(a%10==0) {
                for(i=0; i<N; i++) {
                        if(c[i]%10!=0) {
                                a-=c[i];
                                break;
                        }
                }
                if(a==accumulate(c.begin(), c.end(), 0)) {
                        a=0;
                }
        }

        cout << a << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-15
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;
 
int main(){
    Init();
    long double a, b, c;
    cin >> a >> b >> c;
    (sqrt(a)+sqrt(b)+EPS < sqrt(c)) ? Yes() : No();
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC130_b solver = new ABC130_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC130_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int X = in.nextInt();
            int i = 1;
            int ttl = 0;
            for (i = 1; i <= N; i++) {
                ttl += in.nextInt();
                if (ttl > X) {
                    break;
                }

            }
            out.println(i);
        }

    }
}



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

public class Main {

    Scanner sc = new Scanner(System.in);

    int MOD = (int)998244353;

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

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer>[] lists = new ArrayList[n];

        for (int i=0; i<n; i++) lists[i] = new ArrayList<>();

        int[][] arr = new int[m][2];

        for (int i=0; i<m; i++) {
            int a = sc.nextInt() - 1;
            int num = sc.nextInt();
            lists[a].add(num);
            arr[i][0] = a;
            arr[i][1] = num;
        }

        for (int i=0; i<n; i++) {
            Collections.sort(lists[i]);
        }

//        System.out.println(lists[0]);

        StringBuilder sb = new StringBuilder();

        DecimalFormat df = new DecimalFormat("000000");
        for (int i=0; i<m; i++) {
            int a = arr[i][0];
            int num = arr[i][1];
            num = lowerbound1(lists[a], num) + 1;
            a += 1;
            StringBuilder str = new StringBuilder();
            str.append(df.format(a));
            str.append(df.format(num));
            sb.append(str + "\n");
        }

        System.out.println(sb.toString());


    }

    public static int lowerbound1(List<Integer> list, int value){
        int left = 0;
        int right = list.size();
        while (left<right){
            int mid = (left+right)/2;
            if (list.get(mid)<value){
                left = mid+1;
            }else {
                right = mid;
            }
        }
        return left;
    }
}



Measured memory_bytes: 113788
#include <bits/stdc++.h>
using namespace std;
 
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")"; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ "; for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") "; return os<<"}"; }
    #define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " |"; __f(comma + 1, args...); }
#define rng(x) x.begin(), x.end()
#define pb push_back
#define F first
#define S second
#define el '\n'
 
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
 
/*-----------------------------Code begins----------------------------------*/

vvi moves;
vector <string> mat;
int n, m;
deque <pi> DQ;

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

bool isValid(int x, int y){
    return x >= 0 and x < n and y >= 0 and y < m and mat[x][y] == '.';
}

void solve(){
    cin>>n>>m;
    int sx, sy; cin>>sx>>sy; sx--; sy--;
    int ex, ey; cin>>ex>>ey; ex--; ey--;
    moves = vvi(n, vi(m, 1e9));
    mat = vector <string> (n);
    for(string &str : mat) cin>>str;

    moves[sx][sy] = 0;
    DQ.pb({sx, sy});

    while(!DQ.empty()){
        int x = DQ.front().F, y = DQ.front().S; DQ.pop_front();
        if(x == ex and y == ey) break;

        for (int i = 0; i < 4; ++i){
            int nx = x + dx[i], ny = y + dy[i];
            if(!isValid(nx, ny)) continue;
            if(moves[nx][ny] > moves[x][y]){
                moves[nx][ny] = moves[x][y];
                DQ.push_front({nx, ny});
            }
        }

        for (int nx = x-2; nx <= x+2; ++nx){
            for (int ny = y-2; ny <= y+2; ++ny){
                if(!isValid(nx, ny)) continue;
                if(moves[nx][ny] > moves[x][y] + 1){
                    moves[nx][ny] = moves[x][y] + 1;
                    DQ.pb({nx, ny});
                }
            }
        }
    }
    cout<<(moves[ex][ey]==1e9 ? -1 : moves[ex][ey])<<el;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T=1;
    // cin>>T; 
    while(T--){
        solve();
    }
    return 0; 
}

Measured memory_bytes: 8704
def run(x, y):
    '''
    '''
    for i in range(x + 1): # turtle
        if y == 2 * i + 4 * (x - i):
            print('Yes')
            return
    print('No')



if __name__ == '__main__':
    x, y = list(map(int, input().split()))
    run(x, y)

Measured memory_bytes: 9180
s = input()
t = input()
x = len(t)
mx= 0

res= 0
for i in range(len(s) - x+1):
    # print(i)
    tmp = s[i:i+x]
    cntmp = 0
    for j in range(x):
        if t[j] == tmp[j]:
            cntmp += 1
    # print(tmp, i)
    res = max(res, cntmp)
print(x-res)

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

int main() {
	string c_1,c_2,c_3;
	for (int i = 0; i < 3; i++)cin >> c_1 >> c_2 >> c_3;
	cout << c_1[0] <<c_2[1]<<c_3[2]<< endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<pii>v;
    vector<ll>a(n);
    ll var = 0;
    rep(i, 0, n){
        ll b;
        cin >> b;
        b--;
        if(a[b] == 0)var++;
        a[b]++;
    }
    sort(a.begin(), a.end(), greater<ll>());
    if(var <= k)cout << "0" << endl;
    else{
        ll cnt = 0;
        rep(i, 0, k){
            cnt += a[i];
        }
        cout << n-cnt << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int>data(N);
  int y;
  cin >> y;
  data.at(0)=y;
  for(int i=1;i<N;i++){
    int x;
    cin >> x;
    data.at(i)=data.at(i-1)+x;
  }
  int64_t sei_ans=0;
  int64_t hu_ans=0;
  int zyoutai=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      int a=max(0,1-data.at(i)-zyoutai);
      zyoutai+=a;
      sei_ans+=a;
    }
    else{
      int a=max(0,1+data.at(i)+zyoutai);
      zyoutai-=a;
      sei_ans+=a;
    }
  }
  zyoutai=0;
  for(int i=0;i<N;i++){
    if(i%2!=0){
      int a=max(0,1-data.at(i)-zyoutai);
      zyoutai+=a;
      hu_ans+=a;
    }
    else{
      int a=max(0,1+data.at(i)+zyoutai);
      zyoutai-=a;
      hu_ans+=a;
    }
  }
  cout << min(sei_ans,hu_ans) << endl;
}


Measured memory_bytes: 640
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

const int MAXN = 10010;
int N, A[MAXN], B[MAXN];

int main() {
	int i, t;
	scanf("%d", &N);
	for(i = 1; i <= N; i++) scanf("%d", &A[i]);
	for(i = 1; i <= N; i++) scanf("%d", &B[i]);
	
	ll canDec = 0, toDec = 0;
	for(i = 1; i <= N; i++) {
		t = A[i] - B[i];
		if(t < 0) canDec += (-t) / 2;
		if(t > 0) toDec += t;
	}
	printf(toDec <= canDec ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define mod 1000000007
 
void solve() {
    int n;
    cin >> n;
    if (!(n % 1000)) cout << "0\n";
    else {
        cout << 1000 *(n / 1000 + 1) - n;
    }
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int c[3][3];
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      cin >> c[i][j];
  int da[] = {c[0][1] - c[0][0], c[0][2] - c[0][1]}, db[] = {c[1][0]-c[0][0], c[2][0]-c[1][0]};
  for(int i = 0; i < 3; ++i){
    for(int j = 0; j < 2; ++j){
      if(c[i][j+1]-c[i][j] != da[j]){
        cout << "No" << endl;
        return 0;
      }
      if(c[j+1][i]-c[j][i] != db[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace std;
 
int main()
{
   FAST/**/
   
   ll n,k;
   cin>>n>>k;
   
   ld arr[n];
   rep(n)
        cin>>arr[i];
   
   ld pref[n];
   pref[0] = arr[0];
   for(ll i=1;i<n;i++)
        pref[i] = pref[i-1] + arr[i];
   
   ld ans = 0;
   for(ll i=0;i+k-1<n;i++)
   {
       ld en = pref[i+k-1];
       ld st = 0;
       if(i-1>-1)
            st = pref[i-1];
       en-=st;
       ans = max(ans, en/2 + (ld)0.5*k);
   }
   
   cout<<fixed<<setprecision(12)<<ans;
   
   return 0;        
}  

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,a,b;
  cin >>n>>a>>b;
  int t = (b-a)%2;
  if(t==0){
    cout << "Alice" << endl;
  }
  else{
    cout << "Borys" << endl;
  }
}




Measured memory_bytes: 256