akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int const modulo = 998244353;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  int result = 1;
  int nul = n, r = 0, g = 0, b = 0, rg = 0, gb = 0, rb = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'R'){
      if(0 < gb){
        result = 1LL * result * gb % modulo;
        gb--;
      } else if(0 < g){
        result = 1LL * result * g % modulo;
        g--;
        rg++;
      } else if(0 < b){
        result = 1LL * result * b % modulo;
        b--;
        rb++;
      } else {
        result = 1LL * result * nul % modulo;
        nul--;
        r++;
      }
    } else if(s[i] == 'G'){
      if(0 < rb){
        result = 1LL * result * rb % modulo;
        rb--;
      } else if(0 < r){
        result = 1LL * result * r % modulo;
        r--;
        rg++;
      } else if(0 < b){
        result = 1LL * result * b % modulo;
        b--;
        gb++;
      } else {
        result = 1LL * result * nul % modulo;
        nul--;
        g++;
      }
    } else if(s[i] == 'B'){
      if(0 < rg){
        result = 1LL * result * rg % modulo;
        rg--;
      } else if(0 < r){
        result = 1LL * result * r % modulo;
        r--;
        rb++;
      } else if(0 < g){
        result = 1LL * result * g % modulo;
        g--;
        gb++;
      } else {
        result = 1LL * result * nul % modulo;
        nul--;
        b++;
      }
    }
  }
  cout << result;
  return 0;
}


Measured memory_bytes: 900
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
double pi=3.1415926535898;
//double pi=acos(-1.0);
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)   for(int i=0;i<int(n);i++)
#define rep(i,a,b) for(int i=a;i<=int(b);++i)/*
#define rng(i,a,b) for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define pii        pair<int,int>
#define pis        pair<int,string>
#define vi         vector<int>
#define F          first
#define S          second
//#define max(a,b) a<b?b:a  __builtin_popcount;
//#define min(a,b) a<b?a:b
//freopen("output.txt","w",stdout),freopen("input.txt","r",stdin);
const ll M  = 1e9+7 ;
const int N = 100100;
const int inf = INT_MAX;
const double eps = 1e-7;
//////////////////////    Hi    ^_^  hack me if you can :P
*/
ll n;
int ans = 20 ;
int main()
{
    speed;
    cin>>n;
    int sq = sqrt(n);
    rep(i,1,sq+1)
    {
        if (n%i==0)
        {
            ans = min( ans , max( int( log10(i) ), int( log10(n/i) ) ) );
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<utility>
#include<vector>
#include<stack>
using namespace std;

int main(){
	int N, M;
	scanf("%d %d", &N, &M);
	vector<int> Adjacent[N];
	pair<int, int> Edge[M];
	for (int i = 0; i < M; ++i){
		scanf("%d %d", &Edge[i].first, &Edge[i].second);
		Edge[i].first--;Edge[i].second--;
		Adjacent[Edge[i].first].push_back(Edge[i].second);
		Adjacent[Edge[i].second].push_back(Edge[i].first);
	}
	int answer = 0;
	bool has_been_discovered[N];
	for (int i = 0; i < M; ++i){
		for (int j = 0; j < N; ++j) has_been_discovered[j] = false;
		stack<int> S;
		S.push(Edge[i].first);
		has_been_discovered[Edge[i].first] = true;
		bool is_bridge = true;
		while(!S.empty()){
			int u = S.top(); S.pop();
			for (int j = 0; j < Adjacent[u].size(); ++j){
				int v = Adjacent[u][j];
				if(u == Edge[i].first && v == Edge[i].second) continue;
				if(v == Edge[i].second){
					is_bridge = false;
					break;
				}
				if(!has_been_discovered[v]){
					has_been_discovered[v] = true;
					S.push(v);
				}
			}
			if(!is_bridge) break;
		}
		if(is_bridge) answer++;
	}
	printf("%d\n", answer);
	return 0;
}

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

int main(){

	int w[10], k[10];
	
	for(int i=0; i<2; i++){
		for(int j=0; j<10; j++){
			if(i == 0) cin >> w[j];
			else cin >> k[j];
		}
	}
	
	sort(w, w+10, greater<int>());
	sort(k, k+10, greater<int>());
	
	cout << w[0] + w[1] + w[2] << " " << k[0] + k[1] + k[2] << endl;
	
	return 0;

}

Measured memory_bytes: 1180
// *** creator : cfmasterr *** //
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> edges(n - 1);
  vector<vector<int>> g(n);
  map<pair<int, int>, int> color;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    edges[i].first = x;
    edges[i].second = y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> p(n);
  function<void(int, int)> Dfs = [&](int v, int pv) {
    for (int u : g[v]) {
      if (u != pv) {
        p[u] = v;
        Dfs(u, v);
      }
    }
  };
  Dfs(0, -1);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, (int) g[i].size());
  }
  cout << mx << '\n';
  vector<int> que = {0};
  vector<int> dist(n, -1);
  dist[0] = 0;
  for (int b = 0; b < (int) que.size(); b++) {
    int c = 0;
    for (int v : g[que[b]]) {
      if (dist[v] == -1) {
        ++c;
        dist[v] = dist[que[b]] + 1;
        que.push_back(v);
        if (que[b]) {
          if (c == color[make_pair(que[b], p[que[b]])]) {
           ++c;
          }
        }
        color[make_pair(que[b], v)] = color[make_pair(v, que[b])] = c;
      }
    }
  }
  for (auto& p : edges) {
    cout << color[make_pair(p.first, p.second)] << '\n';
  }
  return 0;
}


Measured memory_bytes: 20472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

	sort(a.rbegin(), a.rend());
	sort(f.begin(), f.end());
	ll l=-1, r=1000000000000;//l ng  r ok
	while(l+1<r){
		ll m=(l+r)/2;
		ll c=0;
		rep(i, n) c+=max((ll)0, (ll)a[i]-m/f[i]);
		if(c<=k) r=m;
		else l=m;
	}

	cout<<r<<endl;
	return 0;
}


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

int main() {
 int x;
  cin >> x;
  for(int i=0;i<10003;i++){
    int p=x+i;
    int count=2;
    for(int j=2;j<p;j++){
      if(p%j==0){
      break;
      }
      count++;
    }
    if(count==p){
  cout << p <<endl;
    break;
    }
    }
  }



Measured memory_bytes: 256
N = int(input())

def prefix_postfix(n):
    sn = str(n)
    return int(sn[0]), int(sn[-1])

import numpy as np
cnt = np.zeros((10, 10), np.uint64)

for i in range(1, N+1):
    pair = prefix_postfix(i)
    cnt[pair] += 1

ans = 0

for i in range(10):
    for j in range(10):
        ans += cnt[i, j] * cnt[j, i]

print(int(ans))


Measured memory_bytes: 12432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;

#define pb push_back
#define mp make_pair


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

    ll t,n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2;

    return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vpl arr(n);
  rep(i, n) cin >> arr[i].first >> arr[i].second;
  sort(all(arr));
  rep(i, n){
    k -= arr[i].second;
    if(k <= 0){
      cout << arr[i].first << endl;
      return 0;
    }
  }
  cout << arr[n-1].first << endl;
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
S = input()
E_count = S.count("E")
W_count = 0
ans = N
for i in range(N):
  if S[i] == "E":
    E_count-=1
    ans = min(ans, W_count+E_count)
  else:
    ans = min(ans, W_count+E_count)
    W_count += 1
print(ans)

Measured memory_bytes: 3700
#include<iostream>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
 
int uf[100100], r[100100];
 
void init(int n){
  rep(i,n)uf[i] = i, r[i] = 0;
}
 
int find(int a){
  if(uf[a] == a)return a;
  return uf[a] = find(uf[a]);
}
 
void unite(int a,int b){
  a = find(a); b = find(b);
  if(a==b)return;
  if(r[a] < r[b])uf[a] = b;
  else{
    uf[b] = a;
    if(r[a] == r[b])r[b]++;
  }
}
 
ll pow(ll a, ll n){
  ll res = 1;
  while(n){
    if(n&1)(res *= a) %= mod;
    (a *= a) %= mod; n>>=1;
  }
  return res;
}
 
int n,m,a,b;
 
int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(false);
 
  while(cin >> n >> m, n){
    init(n);
 
    rep(i,m){
      cin >> a >> b; a--; b--;
      unite(a,b);
    }
 
    map<int,int> g;
    rep(i,n)g[find(i)]++;
     
    ll ans = pow(2,g.size());
    if(m>0)ans++;
    cout << ans%mod << endl;
  }
}

Measured memory_bytes: 6664
import fractions
N=int(input())

tlist=[]
for i in range(N):
  tlist.append(int(input()))
#print(tlist)

answer=tlist[0]
for i in range(1,N):
  answer=answer*tlist[i]//fractions.gcd(answer,tlist[i])
  
print(answer)

Measured memory_bytes: 5048
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    long[long] D;
    foreach (i; 1 .. N + 1)
    {
        auto f = factorize(i);
        foreach (k, v; f)
            D[k] = D.get(k, 0) + v;
    }
    long ans = 1;
    foreach (k, v; D)
        ans *= v + 1, ans %= MOD;
    writeln(ans);
}

/// 素因数分解
T[U] factorize(T = long, U = long)(T x)
{
    assert(0 < x, "x is negative");
    long[long] ps;
    while ((x & 1) == 0)
        x /= 2, ps[2] = (2 in ps) ? ps[2] + 1 : 1;
    for (long i = 3; i * i <= x; i += 2)
        while (x % i == 0)
            x /= i, ps[i] = (i in ps) ? ps[i] + 1 : 1;
    if (x != 1)
        ps[x] = (x in ps) ? ps[x] + 1 : 1;
    return ps;
}


Measured memory_bytes: 3852
# coding: utf-8
# Your code here!
S = list(input())
N = len(S)
area = []
ans = [0 for i in range(N)]

start = 0
L_start = None
R_flg = True
for i in range(1, N):
    if S[i] == 'R':
        if not R_flg:
            R_flg = True
            area.append((start, L_start, i-1))
            start = i
    elif S[i] == 'L':
        if R_flg:
            R_flg = False
            L_start = i
area.append((start,L_start,i))
for a in area:
    r,b,l = a[0],a[1],a[2]
    length = l - r + 1
    ans[b-1] = length // 2
    ans[b] = length // 2
    if length % 2 == 1:
        ans[b - (l-b)%2] += 1
print(' '.join(list(map(str, ans))))

Measured memory_bytes: 20004
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    //static long mod = 1000000007;
    
    static int[][] aa = new int[3][];
    static int[][] bb = new int[3][];

    static object process(TextReader input) {

        for(int i=0; i<3; i++) {
            aa[i] = new int[3];
            bb[i] = new int[3];
            var spl   = input.ReadLine().Split(' ');
            aa[i][0]     = int.Parse(spl[0]);
            aa[i][1]     = int.Parse(spl[1]);
            aa[i][2]     = int.Parse(spl[2]);
        }

        var n = int.Parse(input.ReadLine());
        for(int i=0; i<n; i++) {
            var x = int.Parse(input.ReadLine());
            check(x);
        }

        return check2() ? "Yes" : "No";
    }

    static void check(int x) {
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                if (aa[i][j] == x) {
                    bb[i][j] = 1;
                }
            }
        }
    }
    static bool check2() {
        if(bb[0][0] == 1 && bb[0][1] == 1 && bb[0][2] == 1) return true;
        if(bb[1][0] == 1 && bb[1][1] == 1 && bb[1][2] == 1) return true;
        if(bb[2][0] == 1 && bb[2][1] == 1 && bb[2][2] == 1) return true;
        
        if(bb[0][0] == 1 && bb[1][0] == 1 && bb[2][0] == 1) return true;
        if(bb[0][1] == 1 && bb[1][1] == 1 && bb[2][1] == 1) return true;
        if(bb[0][2] == 1 && bb[1][2] == 1 && bb[2][2] == 1) return true;
        
        if(bb[0][0] == 1 && bb[1][1] == 1 && bb[2][2] == 1) return true;        
        if(bb[0][2] == 1 && bb[1][1] == 1 && bb[2][0] == 1) return true;

        return false;
    }

}


Measured memory_bytes: 13268
import collections

s = input()
a = collections.deque(s)
ans = 0
while 1 < len(a):
	if a[0] == a[len(a) - 1]:
		a.popleft()
		a.pop()
	elif a[0] == 'x':
		a.append('x')
		ans += 1
	elif a[len(a) - 1] == 'x':
		a.appendleft('x')
		ans += 1
	else:
		ans = -1
		break
print(ans)

Measured memory_bytes: 4204
#include <algorithm>
#include <cinttypes>
#include <cstdint>
#include <cstdio>
#include <vector>

template<typename T>
void update_min(T &min, T const &new_one) {
    if (new_one < min) {
        min = new_one;
    }
}

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

    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        a[i] -= i + 1;
    }

    std::sort(a.begin(), a.end());
    std::vector<int64_t> psum_a(n);
    int64_t sum_a = 0;
    
    psum_a[0] = a[0];
    sum_a = a[0];
    for (int i = 1; i < n; ++i) {
        psum_a[i] = psum_a[i-1] + a[i];
        sum_a += a[i];
    }

    int64_t min_sad;
    if (true) {
        int64_t b = a[0];
        min_sad = (sum_a - b) - (n-1) * b;
    }

    for (int i = 1; i < n; ++i) {
        // b = a[i]
        int64_t b = a[i];
        int64_t sum_lft = psum_a[i-1];
        int64_t sum_rit = sum_a - sum_lft - a[i];
        update_min(min_sad, b*i - sum_lft + sum_rit - (n-i-1) * b);
    }

    printf("%" PRIi64 "\n", min_sad);

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

int main() {
	int x;
	cin >> x;
	int ans = 0;
	ll deg = 0;
	while (1) {
		ans++;
		deg += x;
		if (deg % 360 == 0) {
			cout << ans << endl;
			return 0;
		}
	}

}






Measured memory_bytes: 3652
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, M = map(int, input().split())
    X = list(sorted(list(map(int, input().split()))))

    length = abs(X[-1] - X[0])

    space = []
    for i in range(len(X) - 1):
        space.append(X[i + 1] - X[i])

    t = sum(sorted(space, reverse=True)[:N - 1])
    print(length - t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14728
#define rep(i,n) for (int i=0;i<n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
 
 
int main(){
  
long long a,b,c,d;
  cin >> a >>b >> c >> d;
  cout << max(max(a*d,a*c),max(b*c,b*d)) << endl;
  
  
}




Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 305;
const int NIL = -1;
const ll LINF = 1LL << 50;
/* global variables */
/* funciton */
/* main */
int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    vector<vector<ll>> dp(N+1, vector<ll>(N+1));

    // もらうDP
    // dp[x][y] = a[x], ... a[y-1]までのやつが残っているときの最適解
    for (int len = 1; len <= N; len++) {
        for (int x = 0; x <= N - len; x++) {
            int y = x + len;
            if ((N-len) % 2 == 0) {  // 専攻
                dp[x][y] = max(dp[x+1][y] + a[x], dp[x][y-1] + a[y-1]);
            }
            else {  // 後攻
                dp[x][y] = min(dp[x+1][y] - a[x], dp[x][y-1] - a[y-1]);
            }
        }
    }
    cout << dp[0][N] << '\n';
}

Measured memory_bytes: 73728
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353
#define MAX 100000

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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 main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	ll A, B, C;
	cin >> A >> B >> C;

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




	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000 
const long long  MOD =1e9+7;
#define MAXR 100000 
int main(){
    long long int X;
    cin >> X;
    long long int K;
    cin >> K;
    long  long int D;
    cin >> D;
    
    long long int Ans=INF;
    if(X<0){
        long long int count = (-1*X)/D;
        if((-1*X)%D==0)count = (-1*X)/D;
        else count++;
        if(count >=K)cout << abs(X+D*K) << endl;
        else{
            if((K-count)%2==0)cout << abs(X+D*count) << endl;
            else cout << abs(X+D*count-D) << endl;
        }
    }else{
        long long int count =X/D;
        if(X%D==0)count = X/D;
        else count++;
        if(count>=K)cout << abs(X-D*K) << endl;
        else{
            if((K-count)%2==0)cout << abs(X-D*count) << endl;
            else cout << abs(X-D*count+D) << endl;
        }
    }
}

Measured memory_bytes: 3548
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    print( "Yay!" if A <= 8 and B <=8 else ":(" )


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod 300002
#define ll  long long
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int x;
	double sum = 0;
	cin >> x;
	int* y = new int[x];
	for (int i = 0; i < x; i++) {
		cin >> y[i];
	}
	sort(y, y + x);
	sum = (y[0] + y[1]) / 2.0;
	for (int i = 2; i < x; i++) {
		sum = (sum + y[i]) / 2.0;
	}
	printf("%.7lf\n", sum);
  return 0;
}

Measured memory_bytes: 256
import itertools

n = int(input())
l = list(map(int, input().split()))

ans = 0
for i in itertools.combinations(l, 3):
    x, y, z = i[0], i[1], i[2]

    if x!=y and y!=z and z!=x and x+y>z and y+z>x and x+z>y:
        ans += 1

print(ans)



Measured memory_bytes: 9120
typedef long long ll;
#include "bits/stdc++.h"
using namespace std;

int a[1100000]{};
int elm[1100000]{};

int main() {
	int s;
	cin >> s;
	a[1] = s;
	elm[a[1]]++;
	int i = 2;
	while (i < 1100000)
	{
		if (a[i-1] % 2 == 0) {
			a[i] = a[i - 1] / 2;
		}
		else {
			a[i] = 3 * a[i - 1] + 1;
		}

		elm[a[i]]++;
		if (elm[a[i]] == 2) {
			break;
		}
		i++;
	}
	cout << i << endl;
}

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

int main () 
{
    int a, b, c;
    cin >> a >> b >> c;
    
    if (a < b && b < c) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    
    return 0;
}


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

int main(){
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    sum+=A[i];
  }
  if(H>sum) cout <<"No"<<endl;
  else cout <<"Yes"<<endl;
}

Measured memory_bytes: 640
s = input()
n = len(s)
m = n + 1
a1, a2 = [0] * m, [0] * m
cnt = 0
for i in range(n-1, -1, -1):
    if s[i] == ">":
        a2[i+1] = cnt
        cnt += 1
    else:
        a2[i+1] = cnt
        cnt = 0
a2[0] = cnt

cnt = 0
for i in range(n):
    if s[i] == "<":
        a1[i] = cnt
        cnt += 1
    else:
        a1[i] = cnt
        cnt = 0
a1[-1] = cnt

print(sum([max(a1[i], a2[i]) for i in range(m)]))


Measured memory_bytes: 31900
class SWAG():
    def __init__(self,unit,f):
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        self.f=f
    def __refill_right(self):
        temp=[]
        n=len(self.data_l)
        for _ in range(n//2):
            temp.append(self.popleft())
        for _ in range(n//2,n):
            self.append(self.popleft())
        for _ in range(n//2):
            self.appendleft(temp.pop())
    def __refill_left(self):
        temp=[]
        n=len(self.data_r)
        for _ in range(n//2):
            temp.append(self.pop())
        for _ in range(n//2,n):
            self.appendleft(self.pop())
        for _ in range(n//2):
            self.append(temp.pop())
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__refill_right()
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__refill_left()
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min)
s_max=SWAG(0,max)
*_,=map(s_min.append,p[:k-1])
*_,=map(s_max.append,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

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

#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()
#define VT(T) vector<T>

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;

ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();

ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}

ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}

ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

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

	int r;
	cin>>r;
	cout<<r*r<<endl;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;


void call(int n)
{
	int i = 1;

	do{
		int x = i;

		if (x % 3 == 0){
			cout << " " << i;
			continue;
		}

		do{
			if(x % 10 == 3){
				cout << " " << i;
				break;
			}else
				x /= 10;
		}while(x);

	}while(++i <= n);

	cout << endl;
}

int main()
{
	int n;

	cin >> n;

	call(n);

	return 0;
}


Measured memory_bytes: 3108
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        final long MOD = 1000000000+7;
        long n = sc.nextInt();
        long a=1; //10^n : a
        long b=2; //9^n : b
        long c=1; //8^n : c
        //=====================================
        //全通りの組み合わせ            10^n :a
        //1~9(9種)のみの組み合わせ      9^n :b
        //0,2~9(9種)のみの組み合わせ    9^n :b
        //2~9(8種)のみの組み合わせ      8^n :c
        //10種-8種-(9種-8種)-(9種-8種) : a-c-(b-c)*2 : a-2b+c
        //=====================================
        for(long i=0;i<n;i++){
            a*=10;
            b*=9;
            c*=8;
            a%=MOD;
            b%=MOD;
            c%=MOD;
        }
        //if(a<0)a+=MOD;
        //if(b<0)b+=MOD;
        //if(c<0)c+=MOD;
        //System.out.println(a);
        //System.out.println(b);
        //System.out.println(c);
        long x = (a-b+c+MOD)%MOD;
        System.out.println(x);
    }
}

class Monmo {
    
}


Measured memory_bytes: 35684
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i
a = 0
for i in 0..A
    for j in 0..B
        for k in 0..C
            if 500 * i + 100 * j + 50 * k == X
                a += 1
            end
        end
    end
end

puts a

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace atcoder;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, q;
    std::cin >> n >> q;
    
    fenwick_tree<int64_t> fw(n);
    
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        fw.add(i, a);
    }
    
    for (int i = 0; i < q; ++i) {
        int t, a, b;
        std::cin >> t >> a >> b;
        if (t == 0) {
            fw.add(a, b);
        } else {
            std::cout << fw.sum(a, b) << "\n";
        }
    }
    
    return 0;
}

Measured memory_bytes: 8252
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define inf 1000000007
//#define for(i, a, b) for(int i=a; i<b; i++)
int dp[1000001] = {0};

void solve(){
	int n, a=0, b=0;
	cin>>n;
	int arr[n], arr2[n];
	for(int i=0;i<n;i++) cin>>arr[i], arr2[i]=arr[i];
	sort(arr2, arr2+n);
	a = arr2[n-1], b = arr2[n-2];
	if(a==b){
		for(int i=0;i<n;i++) cout<<a<<endl;
	}
	else{
			for(int i=0;i<n;i++){
		if(arr[i]==a) cout<<b<<endl;
		else cout<<a<<endl;
	}
	}


}
signed main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int n;
	cin >> n;
	float cnt = 0.0;
	for(int i = n;i > 0;i--){
		if(i % 2 == 1){
			cnt++;
		}
	}
	cout << float(cnt) / float(n) << endl;
}

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

main(){
  int a , b , n, x;
  cin >> n >> a >> b;
  if ( a * n > b )
    cout << b << endl;
  else if ( a * n < b)
 	cout << a * n << endl;
  else 
    cout << b << endl;
}

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

int main() {
    int n; cin >> n;
    int p[20];
    for (int i = 0; i < n; i++) cin >> p[i];

    int c = 0;
    for (int i = 2; i < n; i++) {
        if ((p[i - 2] < p[i - 1]) && (p[i - 1] < p[i])) c++;
        if ((p[i - 2] > p[i - 1]) && (p[i - 1] > p[i])) c++;
    }

    cout << c << endl;
    return 0;
}

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

#define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i)
#define sz(x) ((int) (x).size())
#define ll long long
#define mp make_pair
#define pii pair<int, int >
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define zero(x) memset((x), (0), sizeof (x))
#define zerox(x, y) memset((x), (y), sizeof (x))

using namespace std;

int main()
{
#ifdef PIT
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif //PIT

	ios_base::sync_with_stdio(false); cin.tie(0);
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d;
	cin >> n;
	ll pri = q, y;
	if(pri*2 > h) pri = h;
	else pri = pri*2;
	if(pri*2 > s) pri = s;
	else pri = pri*2;
	y = pri;
	if(pri*2 > d) pri = d;
	else pri = pri*2;
	if(n&1) cout << n/2 * pri + y << endl;
	else cout << n/2 * pri << endl;
	
#ifdef PIT
flush(cout);
cerr << endl << "Time: " << (clock() / double(CLOCKS_PER_SEC)) << endl;
#endif //PIT
	return 0;
}


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

int main(){
	int n ; cin >> n ;
	double ans = 0 ;
	for(int i=0;i<n;i++){
		double x ; cin >> x ;
		string s ; cin >> s ;
		if(s=="JPY") ans += x ;
		else ans += x*380000.0 ;
	}
    cout << fixed << setprecision(10) << ans << endl ;
}

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

using namespace std;

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

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

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

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	int h,w,k; cin>>h>>w>>k;
	ll dp[200][10]={};
	dp[0][0]=1;
	if(w==1){
		co(1);
		return 0;
	}
	FOR(i,1,h+1){
		FOR(j,0,1<<(w-1)){
			int flag=true;
			FOR(s,0,w-2){
				if((1&(j>>s))&(1&(j>>(s+1)))) flag=false;
			}
			if(flag){
				FOR(s,0,w-1){
					if(1&(j>>s)){
						(dp[i][s]+=dp[i-1][s+1])%=MOD;
						(dp[i][s+1]+=dp[i-1][s])%=MOD;
					}else{
						if(s==0) (dp[i][s]+=dp[i-1][s])%=MOD;
						if(s==w-2 || !(1&(j>>(s+1)))) (dp[i][s+1]+=dp[i-1][s+1])%=MOD;
					}
				}
			}
		}
	}
	co(dp[h][k-1]);
}


Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int n;
ll dp[100010][3];
ll happy[100010][3];

ll solve(int i, int last) {
    if(i == n) return 0;
    if(dp[i][last] != -1) return dp[i][last];

    for(int j = 0; j < 3; j++) {
        if(j != last) {
            dp[i][last] = max(dp[i][last], happy[i][j] + solve(i+1, j));
        }
    }
    return dp[i][last];
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) cin >> happy[i][j];
    }
    ll ans = 0;
    for(int i = 0; i < 3; i++) {
        ans = max(ans, solve(0, i));
    }
    cout << ans << "\n";
}


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

int main() {
    string s;
    cin >> s;

    vector<string> day = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

    for (int i = 0; i < 7; i++) {
        if (day[i] == s) {
            cout << i + 1 << endl;
            break;
        }
    }
}


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

using namespace std;

int main()
{
    long n,i,sum=0,pos=0;
    cin>>n;
    
    string s[n],X;
    long t[n];
    
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        cin>>t[i];
    }
    
    cin>>X;
    
    for(i=0;i<n;i++)
    {
        if(X==s[i])
        {
            pos = i;
            break;
        }
    }
    
    for(i=pos+1;i<n;i++)
        sum = sum + t[i];

    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]
A, P = [int(x) for x in stdin.readline().rstrip().split()]

print((3*A+P)//2)


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

int main()
{
  string a, b;
  cin >> a >> b;
  float n = stoi(a + b);
  if(sqrt(n) - (int)sqrt(n) == 0.0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
# cook your dish here
import sys
def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w') 
#file()	
def main(N, arr):

	#initialising with positive infinity value
	maxi=float("inf")

	#initialising the answer variable
	ans=0

	#iterating linesrly
	for i in range(N):

		#finding minimum at each step
	    maxi=min(maxi,arr[i])
	    #increasing the final ans
	    ans+=maxi
	    print("dhh")

    #returning the answer
	return ans
        

if __name__ == '__main__':

	#length of the array
	'''N = 4

	#Maximum size of each individual bucket
	Arr = [4,3,2,1]

	#passing the values to the main function
	answer = main(N,Arr)

	#printing the result
	print(answer)'''
	n=int(input())

	l=list(map(int, input().split()))
	ans=0
	for i in range(n):
		for j in range(i+1,n):
			ans+=(l[i]*l[j])
	print(ans)		

Measured memory_bytes: 9128
n=int(input())
s=[i for i in range(1,2*n+1)]
for _ in range(int(input())):
    a=int(input())
    if a:
        s=s[a:]+s[:a]
    else: 
        s=[s[i+n*j]for i in range(n) for j in[0,1]]
print(*s,sep='\n')

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

int main()
{
    int n, k;
    string s;
    cin >> n >> s >> k;
    char target = s[k - 1];
    for(int i = 0; i < n; ++i)
    {
        if(s[i] != target)
        {
            s[i] = '*';
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int N,i,sum=0;
    scanf("%d\n", &N);
    int A[N],B[N],C[N];
    for(i=0;i<N;i++){
        scanf("%d", &A[i]);
    }
    for(i=0;i<N;i++){
        scanf("%d", &B[i]);
    }
    for(i=0;i<N-1;i++){
        scanf("%d", &C[i]);

    }
    for(i=0,sum=0;i<N;i++){
        if((A[i]-A[i-1])==1&&A[i]!=1){
            sum=sum+B[A[i]-1]+C[A[i]-2];
        }
        else{
            sum=sum+B[A[i]-1];
        }
    }
    printf("%d", sum);

    return 0;
}


Measured memory_bytes: 128
/*
  coded by: mi_ni_
  "LIVE LONG AND PROSPER"
*/
 
#include <bits/stdc++.h>
using namespace std;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(fun) int tc; cin>>tc; while(tc--){ fun(); }
#define TEST_CASE_2 int tc; cin>>tc; for(int i=1;i<=tc;i++)
#define TEST_CASE_3(fun) int tc; cin>>tc; for(int i=1;i<=tc;i++){ cout<<"Case #"<<i<<": "; fun(); }
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define forab(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define forabr(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define all(x) x.begin(),x.end()
#define trav(i,x) for(auto& i:x)

using ll=long long int;
using ull=unsigned long long int;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vii=vector<pii>;
using vll=vector<pll>;

const ld pi=acosl(-1);
const int inf=(int)1e9+7;
const ll INF=(ll)1e18+7;

//other
template<typename T> inline bool powerof2(T a){ return (a&&(!(a&(a-1)))); }
template<typename T> inline T log_2(T a){ T res=-1; while(a){ a/=2; res++; } return res; }

//make sure to choose TEST_CASE in main for multiple test cases
void solve(){
    int n;
    cin>>n;
    vi arr(n+1);
    forab(i,1,n) cin>>arr[i];
    arr[0]=arr[1];
    vi dp(n+1,0);
    forab(i,2,n) dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    cout<<dp[n]<<'\n';
}

int main(){
    FAST_IO
    cout<<fixed<<setprecision(10);
    //init_fact();
    //TEST_CASE(solve)
    //TEST_CASE_2{}
    //TEST_CASE_3(solve)
    solve();
    return 0;
}

Measured memory_bytes: 3992
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] points = new int[n][d];
        for (int i = 0; i < n; ++i) {
            points[i] = new int[d];
            for (int j = 0; j < d; ++j) {
                points[i][j] = scanner.nextInt();
            }
        }
        int[] ok = new int[40005];
        for (int i = 0; i < 200; ++i) {
            ok[i * i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                int dis = 0;
                for (int k = 0; k < d; ++k) {
                    dis += (points[i][k] - points[j][k]) * (points[i][k] - points[j][k]);
                }
                if (ok[dis] == 1) {
                    ++ans;
                }
            }
        }
        System.out.println(ans);

    }

}


Measured memory_bytes: 22356
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll x, y, z, k;
  cin >> x >> y >> z >> k;

  vll as(x), bs(y), cs(z);

  rep(i, x) cin >> as[i];
  rep(i, y) cin >> bs[i];
  rep(i, z) cin >> cs[i];
  rSort(as), rSort(bs), rSort(cs);

  using Q = pair<ll, T>;
  set<Q> st;
  rep(i, x) {
    ll jmax = k / (i + 1) + 1;
    rep(j, min(y, jmax)) {
      ll kmax = k / ((i + 1) * (j + 1)) + 1;
      rep(k, min(z, kmax)) {
        st.emplace(Q(as[i] + bs[j] + cs[k],
                     T(i, j, k)));
      }
    }
  }
  auto itr = st.rbegin();
  rep(i, k) cout << (*(itr++)).first << endl;

  return 0;
}


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

int main(){
	int n,a,b;
	while( cin >> n >> a >> b , n || a || b ){
		int dp[1000001] = {0};
		dp[0] = 1;
		for(int i=0 ; i <= n ; i++ ){
			if( dp[i] == 1 ){
				if( i+a <= n ){
					dp[i+a] = 1;
				}
				if( i+b <= n ){
					dp[i+b] = 1;
				}
			}
		}
		int ans = 0;
		for(int i=1 ; i <= n ; i++ ){
			if( dp[i] == 0 ){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <cstdio>

#define ll long long

template<class T>void fr(T &a) {
    T s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=w*s;
}
template<class T>T fr() {T a;fr(a);return a;}
#define R() fr<ll>()

int main() {
	ll a=R(),ans=0;
	if(a%2)return !printf("0");
	a/=10;
	for(;a;a/=5) ans+=a;
	return !printf("%lld\n",ans);
}

Measured memory_bytes: 128
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main (String [] args){
		//		String [][] boad = new String[4][4];
		List <Integer> list = new ArrayList<Integer>();
		List <String> list2 = new ArrayList<String>();
		String s = sc.next();
		int answer = 0;
//		int in = Integer.parseInt(sc.next());
//		int c = 0;
		String d = "";
		for(int i = 0;i <s.length();i++){
			list2.add(String.valueOf(s.charAt(i)));
		}

		for(int i = 0;i <list2.size();i++){
			if(list2.get(i).equals("9")){
				list2.set(i, "1");
			}else if(list2.get(i).equals("1")){
				list2.set(i, "9");
			}
			d += list2.get(i);
		}
		
//		for(int i = 0;i<n;i++){
//			list.add(Integer.parseInt(sc.next()));
//		}
		
		System.out.println(d);
		System.out.flush();
		sc.close();
	}
}

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

using namespace std;


int main(void) {
    string S;
    int count_A=0,count_B=0;

    cin>>S;

    for(int i=0;i<S.size();i++){
        if(S[i] == 'A'){
            count_A++;
        }else{
            count_B++;
        }
    }

    if(count_B == 0 || count_A == 0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }




	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	vector<int> N(4);
	cin >> N[0] >> N[1] >> N[2] >> N[3];
	sort(N.begin(), N.end());
	if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9)cout << "YES" << endl;
	else cout << "NO" << endl;
}

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);
        ABC120_2 solver = new ABC120_2();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC120_2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int K = in.nextInt();
            int a = Math.max(A, B);
            int b = Math.min(A, B);
            int counter = b;
            while (true) {
                if ((a % counter == 0) && (b % counter == 0)) {
                    K--;
                    if (K == 0) {
                        out.println(counter);
                        return;
                    }
                }
                counter--;
            }
        }

    }
}



Measured memory_bytes: 23124
from itertools import combinations
from math import sqrt
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
print(len(list(filter(lambda x: x==float(int(x)), map(lambda t: sqrt(sum(map(lambda y,z: (y-z)**2, t[0], t[1]))), combinations(X, 2))))))

Measured memory_bytes: 3188