akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

//Turn Left
public class Main{

	double EPS = 1e-10;
	int INF = 1<<29, M = 1000;
	int[] x, y;
	boolean ok(int pre, int v, int next){
		int x1 = x[v]-x[pre], y1 = y[v]-y[pre], x2 = x[next]-x[pre], y2 = y[next]-y[pre];
		return x1*y2-x2*y1>=0;
	}
	
	int[][] pass;
	double[][] d;
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int m = sc.nextInt(), n = sc.nextInt();
			if((m|n)==0)break;
			Map<String, Integer> ref = new HashMap<String, Integer>();
			x = new int[m]; y = new int[m];
			String[] str = new String[m];
			for(int i=0;i<m;i++){
				String s = sc.next();
				ref.put(s, i);
				str[i] = s;
				x[i] = sc.nextInt(); y[i] = sc.nextInt();
			}
			double[][] dist = new double[m][m];
			List<Integer>[] adj = new List[m];
			for(int i=0;i<m;i++)adj[i]=new ArrayList<Integer>();
			Set<Integer> set = new HashSet<Integer>();
			while(n--!=0){
				int s = ref.get(sc.next()), t = ref.get(sc.next());
				set.add(s*M+t);
				adj[s].add(t); adj[t].add(s);
				dist[s][t] = dist[t][s] = Math.sqrt((x[s]-x[t])*(x[s]-x[t])+(y[s]-y[t])*(y[s]-y[t]));
			}
			
//			for(int v:set){
//				int a = v/M, b = v%M;
//				for(int k:adj[a]){
//					System.out.println(str[b]+"->"+str[a]+"->"+str[k]+" is:"+ok(b, a, k));
//				}
//				for(int k:adj[b]){
//					System.out.println(str[a]+"->"+str[b]+"->"+str[k]+" is:"+ok(a, b, k));
//				}
//				System.out.println();
//			}
			
			
			int s = ref.get(sc.next()), g = ref.get(sc.next());
			d = new double[m][m];
			for(double[]a:d)Arrays.fill(a, INF);
			pass = new int[m][m];
			for(int[]a:pass)Arrays.fill(a, INF);
			PriorityQueue<Integer> q = new PriorityQueue<Integer>(m, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					if(Math.abs(d[o1/M][o1%M]-d[o2/M][o2%M])<EPS)return pass[o1/M][o1%M]-pass[o2/M][o2%M];
					return (int)Math.signum(d[o1/M][o1%M]-d[o2/M][o2%M]);
				}
			});
			for(int v:adj[s]){
				d[v][s] = dist[s][v]; pass[v][s] = 2;
				q.add(v*M+s);
			}
			int res = INF;
			while(!q.isEmpty()){
				int a = q.poll();
				int v = a/M, pre = a%M;
				if(v==g){
					res = pass[v][pre];
					break;
				}
				for(int k:adj[v]){
					if(k==pre)continue;
					if(!ok(pre, v, k))continue;
					double w = d[v][pre] + dist[v][k];
					int t = pass[v][pre]+1;
					if(Math.abs(w-d[k][v])<EPS&&t<pass[k][v]){
						pass[k][v] = t; q.add(k*M+v);
					}
					else if(w<d[k][v]){
						d[k][v] = w; pass[k][v] = t; q.add(k*M+v);
					}
				}
			}
			System.out.println(res==INF?"impossible":res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(){
  int N;
  int a_min,a_max;

  cin>>N;

  for(int i=0;i<N;i++){
    int temp;
    cin >> temp;
    if(i==0){
      a_min=temp;
      a_max=temp;
    }

    if(temp < a_min) a_min = temp;
    else if(temp > a_max) a_max = temp;
  }
  
  
  cout << a_max - a_min << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 550
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int dp[N][N];
int cnt[N][N];
int main(){
    int n,m,q;
    cin>>n>>m>>q;
    REP(i,m){
        int l,r;
        cin>>l>>r;
        l--;
        r--;
        cnt[l][r]++;
    }
    REP(i,n){
        for(int j=i;j<n;j++){
            int tmp=0;
            for(int k=i;k<=j;k++){
            tmp+=cnt[k][j];
            }
            if(i==j){
                dp[i][j]=tmp;
            }else{
                dp[i][j]=tmp+dp[i][j-1];
            }

        }
    }
    vector<P>a(q);
    REP(i,q)cin>>a[i].first>>a[i].second;
    REP(i,q){
        OUT(dp[a[i].first-1][a[i].second-1]);
    }
    return 0;
}

Measured memory_bytes: 3840
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
L = [[[0]]]
for i in range(1, n):
    new_L = []
    for each_type in L:
        new_L += [each_type + [[i]]]
        for j in range(len(each_type)):
            new_type = deepcopy(each_type)
            new_type[j] += [i]
            new_L += [new_type]
    L = new_L


ans = []
for t in L:
    a = [''] * n
    cnt = 97
    for k in t:
        for l in k:
            a[l] = chr(cnt)
        cnt += 1
    ans += [''.join(a)]


for i in sorted(ans):
    print(i)



Measured memory_bytes: 120324
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int main(int argc, char* argv[]) {

	int N, cnt = 0;
	char s[100];

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}

	for (int i = 0; i < N; i++) {
		if (s[i] == 'P') {
			cnt++;
			break;
		}
	}

	for (int i = 0; i < N; i++) {
		if (s[i] == 'W') {
			cnt++;
			break;
		}
	}

	for (int i = 0; i < N; i++) {
		if (s[i] == 'G') {
			cnt++;
			break;
		}
	}

	for (int i = 0; i < N; i++) {
		if (s[i] == 'Y') {
			cnt++;
			break;
		}
	}

	if (cnt == 3) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}

	return 0;

}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

class U {
public:
  int n;
  vector<int> p, s;
  U(int _) {
    n = _;
    p.resize(n);
    s.resize(n);
    for (int i = 0; i < n; i++) {
      p[i] = i;
      s[i] = 1;
    }
  }
  bool connect(int a, int b) {
    int ap, bp;
    for (ap = p[a]; ap != p[ap]; ap = p[ap])
      ;
    for (bp = p[b]; bp != p[bp]; bp = p[bp])
      ;
    if (ap == bp)
      return true;
    int mi = min(ap, bp), ma = max(ap, bp);
    p[ma] = mi;
    s[mi] += s[ma];
    s[ma] = 0;
    for (int pp = a; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    for (int pp = b; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    return false;
  }
  int q(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap])
      ;
    return s[ap];
  }
  int parent(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap])
      ;
    return p[ap];
  }
  bool query(int a, int b) { return parent(a) == parent(b); }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<pair<int, int>> ps(m);
  for (int i = 0; i < m; i++) {
    cin >> ps[i].first >> ps[i].second;
    ps[i].first--;
    ps[i].second--;
  }
  vll ans(m + 1);
  ll b = n * (n - 1) / 2;
  ans[m] = b;
  U u(n);
  for (int i = m - 1; i >= 0; i--) {
    if (u.query(ps[i].first, ps[i].second)) {
      ans[i] = b;
    } else {
      ll l = u.q(ps[i].first), r = u.q(ps[i].second);
      b -= l * r;
      u.connect(ps[i].first, ps[i].second);
      ans[i] = b;
    }
  }
  for (int i = 0; i < m; i++)
    cout << ans[i + 1] << endl;
  return 0;
}


Measured memory_bytes: 3712
def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

from collections import defaultdict
def factorization(n):
    # n >= 1を想定
    factors = defaultdict(int)
    if n == 1:
        return {}
    if int(n**0.5) == 1:
        return {n:1} 
    primes = getprime(int(n**0.5))
    for prime in primes:
        while n % prime == 0:
            factors[prime] += 1
            n //= prime
    if n != 1:
        factors[n] += 1
    return factors
n,p = map(int, input().split())
if p == 1:
    print(1)
    exit()
ans = 1
d = factorization(p)
for k in d.keys():
    if d[k] >= n:
        ans *= (k**(d[k]//n))
print(ans)

Measured memory_bytes: 218424
N, D = map(int, input().split())
X = [[int(i) for i in input().split()] for j in range(N)]

import math
count = 0
for a in range(N-1):
    for b in range(a+1, N):
        dist = 0
        for i, j in zip(X[a], X[b]):
            dist += (i - j) ** 2       
        if dist != 0 and math.sqrt(dist).is_integer() == True:
            count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repi(i,a,b) for(i=int(a);i<int(b);++i)
    
using ll = long long;
using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    for (int i = 0; i < q; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    int ans = 0;
    vector<int> A(10);
    repi(A[0],1,m+1)
    repi(A[1],A[0],m+1)
    repi(A[2],A[1],m+1)
    repi(A[3],A[2],m+1)
    repi(A[4],A[3],m+1)
    repi(A[5],A[4],m+1)
    repi(A[6],A[5],m+1)
    repi(A[7],A[6],m+1)
    repi(A[8],A[7],m+1)
    repi(A[9],A[8],m+1) {
        int cur = 0, i;
        repi(i, 0, q) {            
            if (A[b[i]-1+10-n] - A[a[i]-1+10-n] == c[i])
                cur += d[i];
        }
        ans = max(ans, cur);        
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

  double ans = 0.0;
  FOR(i, 1, n+1){
    int x = i, cnt = 0;
    while(x < k){
      x *= 2;
      cnt += 1;
    }

    ans += 1.0 / (1 << cnt);
  }

  cout << fixed << setprecision(10) << ans / n << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    vl a(3), b(3);
    for (int i = 0; i < 3; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < 3; ++i) {
        cin >> b[i];
    }
    vl c1, v1, c2, v2;
    for (int i = 0; i < 3; ++i) {
        if (b[i] > a[i]) {
            c1.push_back(a[i]);
            v1.push_back(b[i] - a[i]);
        } else {
            c2.push_back(b[i]);
            v2.push_back(a[i] - b[i]);
        }
    }
    if (c1.size() != 0) {
        vl dp(n + 1, 0);
        for (int j = 0; j < c1.size(); ++j) {
            for (int i = 1; i <= n; ++i) {
                if (i - c1[j] >= 0)
                    chmax(dp[i], dp[i - c1[j]] + v1[j]);
            }
        }
        n += dp[n];
    }
    if (c2.size() != 0) {
        vl dp(n + 1, 0);
        for (int j = 0; j < c2.size(); ++j) {
            for (int i = 1; i <= n; ++i) {
                if (i - c2[j] >= 0)
                    chmax(dp[i], dp[i - c2[j]] + v2[j]);
            }
        }
        n += dp[n];
    }
    cout << n << "\n";
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    char s[10010];
    cin>>s;
    int len=strlen(s);
    for(int i=0;i<len;i++){
        int x=s[i]-'A';
        x=(x+n)%26;
        putchar('A'+x);
    }
    putchar('\n');
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int x = 0;
  for (int i = 0; i < S.length(); i++) {
    x += S[i] - '0';
  }
  x %= 9;

  if (x == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3748
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

long long int pas[53][53];
void init(){
  for(int i=1; i<53; i++){
    for(int j=1; j<53; j++){
      if(j==1 || i == j) pas[i][j] = 1;
      else pas[i][j] = pas[i-1][j-1] + pas[i-1][j];
    }
  }
}
int main() {
  int n, a, b; cin >> n >> a >> b;
  vector<long long int> v(n);
  map<long long int, int> mp;
  for(int i=0; i<n; i++){
    cin >> v[i];
    mp[v[i]]++;
  }
  sort(v.begin(), v.end(), greater<long long int>());

  long long int summax = 0;
  for(int i=0; i<a; i++){
    summax += v[i];
  }
  double avemax = summax*1.0 / a;
  printf("%.10lf\n", avemax);

  init();

  long long int cnt = 0;
  for(int i=a; i<=b; i++){
    long long int p = v[i-1];
    int cc = 0;
    long long int q = 0;
    for(int j=0; j<i; j++){
      if(p == v[j]) cc++;
      q += v[j];
    }
    if(q*a != summax*i) continue;
    cnt += pas[mp[p]+1][cc+1];
  }
  cout << cnt << endl;


  return 0;
}



///


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N,K;
    cin >> N >> K;

    vector<i64> h(N);
    rep(i,0,N) cin >> h[i];

    vector<i64> dp(N,inf64);
    dp[0]=0;
    rep(i,1,N){
        rep(j,1,K+1){
            if(i-j<0) break;
            chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    cout << dp[N-1] << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private class DisjointSet {
		
		int[] p, rank;
		
		public DisjointSet(int size) {
			p = new int[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			int parent = p[x];
			int v = x;
			while (parent != v) {
				parent = p[v];
				v = p[parent];
				//p[x] = v;
			}
			return parent;
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x= Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 61060
#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;

int N, M, X, res1, res2;

int main()
{
	in >> N >> M >> X;
	std::vector<int>A(M);
	rep(i, M)
	{
		in >> A[i];
		if (A[i] < X) ++res1;
		else ++res2;
	}
	out << std::min(res1, res2) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"
#define int ll

using namespace std;
typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
    static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x^(x << 11));
    x = y; y = z; z = w;
    return (w = (w^(w >> 19))^(t^(t >> 8)));
}

void init() {
    iostream::sync_with_stdio(false);
    cin.tie(0);
}

void solve() {
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
}


#undef int
int main() {
    init();
    solve();
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int suma = 0;
    if(a >= b){
        suma = a;
        a = a-1;
    } else {
        suma = b;
        b = b-1;
    }
    cout << suma + max(a,b) << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val as = List.fill(n)(sc.nextInt())
  var x2 = as.count(a => a % 4 != 0 && a % 2 == 0)
  var x4 = as.count(a => a % 4 == 0)
  println(if (2 * x4 + x2.max(1) >= n) "Yes" else "No")
}


Measured memory_bytes: 61772
#include <stdio.h>

int main(void) {

	int N,i,K,P;
	int a[100];

	scanf("%d", &N);

	for (i = 0; i < N; i++) {

		scanf("%d%d", &K, &P);

		if (K < P) a[i] = K;
		else if (K%P != 0) a[i] = K%P;
		else if (K%P == 0) a[i] = P;
	}
	for (i = 0; i < N; i++) {
		printf("%d\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 596
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    try:
        bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())
    except IndexError:
        print("-1")

H,W = map(int,input().split())
startY=0
startX=0
goalX=W-1
goalY=H-1
F = list(list(input()) for _ in range(H))
reached = [[False for i in range(W)] for i in range(H)]
count=0
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
bfs(startY,startX,count)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int lcm(int x, int y){
    return x/__gcd(x,y)*y;
}

int euler_phi(int n){
    if(n==0) return 0;
    int ret = n;
    for(int i=2; i*i<=n; ++i){
        if(n%i==0){
            ret -= ret/i;
            while(n%i==0) n/=i;
        }
    }
    if(n!=1) ret -= ret/n;
    return ret;
}

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

ll mod_pow(ll x, ll n, ll mod){
    ll ret = 1;
    while(n){
        if(n&1) (ret*=x)%=mod;
        (x*=x)%=mod;
        n>>=1;
    }
    return ret;
}

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

    map<int,int> f = factorize(n);
    int L = 1;
    for(const auto &p:f){
        if(p.se>1){
            cout << -1 << endl;
            return 0;
        }
        L = lcm(L, p.fi-1);
    }

    if(__gcd(n,L)!=1){
        cout << -1 << endl;
        return 0;
    }

    int ans = L;
    int P = euler_phi(L);
    for(int i=1; i*i<=P; ++i){
        if(P%i==0){
            for(int d:{i,P/i}){
                if(mod_pow(n,d,L) == 1) ans = min(ans,d);
            }
        }
    }

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



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int power(int a,int x){
    if(x==0) return(1);
    int p=power(a,x/2);
    p=(p*p)%M;
    if(x%2==0) return(p);
    return((p*a)%M);
}

int32_t main(){
    IOS;
    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int i=k;i<=n+1;i++){
        int mn=((i*(i-1))%M*power(2,M-2)%M)%M;
        int mx=((n*(n+1))%M*power(2,M-2)%M)%M;
        int mx2=((n-i)*(n-i+1))%M*power(2,M-2)%M;
        mx=(mx-mx2+M)%M;
        ans=(ans+mx-mn+M+1)%M;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

const int INF = 2e9;

int main(){
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    rep(i,n) cin >> x[i];
  	y = x;
    sort(x.begin(),x.end());
    int a = x[n/2 - 1];
    int b = x[n/2];
    rep(i,n){
        if(y[i] <= a) cout << b << endl;
        else cout << a << endl;
    }
}

Measured memory_bytes: 6324
N=int(input())
P=map(int,input().split())
S=[]
for x,y in zip(P, range(1,N+1)):
    if x==y: S.append(y)

S.append('$')
L=len(S)

lake=[]
lake.append(S[0])
i=1
a=0
while i<L:
    if S[i]=='$':
     a+=1
    elif lake[0]+1!=S[i]:
     a+=1
     lake=[]
     lake.append(S[i])
    else:
     lake.append(S[i])
    i+=1
print(a)

Measured memory_bytes: 20576
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define Min(a, b) ((a < b) ? a : b)

int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  x--;
  y--;
  int ans[n-1];
  for (int i=0; i<n; i++)
    ans[i] = 0;
  for (int i=0; i<n-1; i++) {
    for (int j=i+1; j<n; j++) {
      if (i<x) {
        if (j<x)
          ans[j-i]++;
        else if (j>=y)
          ans[x-i+j-y+1]++;
        else
          ans[x-i+Min(j-x, y-j+1)]++;
      } else if (i>=y) {
        ans[j-i]++;
      } else {
        if (j>=y) {
          ans[j-y+Min(i-x+1, y-i)]++;
        } else {
          ans[Min(j-i, y-j+i-x+1)]++;
        }
      }
    }
  }
  for (int i=1; i<n; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	char a[30];
	scanf("%s", a);
	a[4] = '\0';//   スラッシュのところを\0にする
	a[7] = '\0';//   上に同じ
	
	int y, m, d;
	int i,year[15],month[15],day[15];
	for (i = 0; a[i] != '\0'; i++) {
		a[i] = a[i] - 0x30;//   a[]が文字列なので整数にする
		year[i] = a[i];//   year[]に整数の西暦を入れる
	}
	for (i = 5; a[i] != '\0'; i++) {
		a[i] = a[i] - 0x30;//   整数にする
		month[i - 5] = a[i];//   月を入れる
	}
	for (i = 8; a[i] != '\0'; i++) {
		a[i] = a[i] - 0x30;//   整数にする
		day[i - 8] = a[i];//  日を入れる
	}
	y = year[0] * 1000 + year[1] * 100 + year[2] * 10 + year[3];//   yを2019みたいな感じにしたい
	m = month[0] * 10 + month[1];//   mを04みたいな感じにしたい
	d = day[0] * 10 + day[1];//   dを30みたいな感じにしたい

	if (y <= 2019 && m <= 4 && d <= 30) {
		printf("Heisei\n");
	}
	else {
		printf("TBD\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
int maxdepth;
map<VI,int> mp;

void Rev(int l,int r,vector<int> &v){
  for(int i=0;i<=10;i++){
    if(l+i>=r-i)break;
    swap(v[l+i],v[r-i]);
  }
  return;
}

void bfs(vector<int> v,int depth){
  if(depth>maxdepth)return;
  for(int i=0;i<v.size();i++){
    for(int j=i+1;j<v.size();j++){
      vector<int>v1;
      v1 = v;
      Rev(i,j,v1);
      if(mp[v1]!=0){
        if(mp[v1]>depth){
          mp[v1] = depth;
          bfs(v1,depth+1);
        }
      }else if(mp[v1]==0){
        mp[v1] = depth;
        bfs(v1,depth+1);
      }
    }
  }
  return;
}

void bfs2(vector<int> v,int depth,int &ans){
  if(depth>maxdepth)return;
  for(int i=0;i<v.size();i++){
    for(int j=i+1;j<v.size();j++){
      vector<int>v1;
      v1 = v;
      Rev(i,j,v1);
      if(mp[v1]!=0){
        ans = min(ans,mp[v1]+depth);
        bfs2(v1,depth+1,ans);
      }else if(mp[v1]==0){
        bfs2(v1,depth+1,ans);
      }
    }
  }
  return;
}



int main(){
  int n;
  cin >>n;
  maxdepth = (n -1) / 2;
  VI a(n);
  rep(i,n)cin>>a[i];
  mp[a]=0;
  bfs(a,1);
  VI b(n);
  rep(i,n)b[i]=i+1;
  if(a==b){
    cout << 0 << endl;
    return 0;
  }
  int ans = 10000;
  if(mp[b]!=0){
    cout << mp[b] << endl;
    return 0;
  }
  bfs2(b,1,ans);
  if(ans==10000){
    cout << n-1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 66788
n,kingaku = map(int,input().split())
all1000 = n*1000
if all1000>kingaku:
    print(-1,-1,-1)
    exit()
x = 0
y = 0
z = n
for i in range(n+1):
    x=i
    for j in range(n+1):
        z=n-(i+j)
        y=j
        if z<0:
            break
        money = x*10000 + y*5000 + z*1000
        if money == kingaku:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int l=0,r=s.size()-1;
	int cnt=0;
	while(l<=r){
		while(s[l]=='R'){
			l++;
		}
		
		while(s[r]=='W'){
			r--;
		}
		if(l<r)
		cnt++;
		l++,r--;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
int n,a[N],vis[16],dp[1<<15],sum[1<<15];
vector<int>v;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int u,v,w;scanf("%d%d%d",&u,&v,&w);
        a[u]^=w;a[v]^=w;
    }
    for(int i=1;i<=n;i++)
        vis[a[i]]++;
    int ans=0;
    for(int i=1;i<=15;i++)
    {
        ans+=vis[i]/2;
        if(vis[i]&1)
            v.push_back(i);
    }
    memset(dp,inf,sizeof(dp));
    dp[0]=0;
    int m=v.size();
    int up=1<<m;
    for(int i=0;i<up;i++)
    {
        for(int j=0;j<m;j++)
            if(!(i>>j&1))
        {
            int st=i^(1<<j);
            sum[st]=sum[i]^v[j];
            if(sum[st]==0) dp[st]=min(dp[st],dp[i]);
            else dp[st]=min(dp[st],dp[i]+1);
        }
    }
    printf("%d\n",ans+dp[up-1]);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
inline int sqr(int x) {
    return x * x;
}
int main() {
    int n, a[101];
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ans += sqr(a[i]);
    }
    for (int x = -100; x <= 100; x++) {
        int tmp = 0;
        for (int i = 1; i <= n; i++) {
            tmp += sqr(a[i] - x);
        }
        ans = min(ans, tmp);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))

dx=[0,0,1,-1]
dy=[1,-1,0,0]

for i in range(h):
    for j in range(w):
        if s[i][j]!="#":
            continue

        count=0
        for k in range(4):
            di=i+dy[k]
            dj=j+dx[k]

            if (di<0)|(di>h-1):
                continue
            if (dj<0)|(dj>w-1):
                continue

            if s[di][dj]=="#":
                count+=1
        if count==0:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 68196
x = int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(n**0.5+1)):
        if n % k == 0:
            return False

    return True
while True:
    if is_prime(x):
        print(x)
        exit()
    else:
        x += 1


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        int res = 0;
        for (int i = 1; i <= n; i+=2) {
            if (divisors(i) == 8) {
                res++;
            }
        }
        System.out.println(res);
    }

    private static int divisors(int n) {
        int res = 0;
        for (int p = 1; p * p <= n; p++) {
            if (n % p == 0) {
                if (p * p == n) {
                    res++;
                } else {
                    res += 2;
                }
            }
        }
        return res;
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;

using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int ma = max(h, w), mi = min(h, w);
    int times = 0;

    times = (n + ma - 1) / ma;
    cout << times << endl;
    return 0;
}

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

int main() {
  int64_t n, d;
  cin >> n >> d;
  
  int64_t count = 0;
  
  for (int64_t i = 0; i < n; i++) {
    int64_t x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d)
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3632
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> M >> K;
		while (M%K) {
			if ((M%K) % (M / K + 1) == 0) {
				M -= M%K;
			}
			else {
				M -= ((M%K) / (M / K + 1) + 1)*(M / K + 1);
			}
		}
		ans ^= M / K;
	}
	if (ans) {
		cout << "Takahashi\n";
	}
	else {
		cout << "Aoki\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, p[31] = {}, i, res;
  p[0] = 1;
  p[1] = 1;
  p[2] = 2;


  while(scanf("%d", &n) && n){
    for(i = 3; i <= n; i++) p[i] = p[i - 1] + p[i - 2] + p[i - 3];
    res = (p[n] + 3649) / 3650;
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 600
n=int(input())
h=[int(x) for x in input().split()]
a=1
for i in range(n-1):
  if h[i]>h[i+1]:
    h[i+1]+=1
    if h[i]>h[i+1]:
      print("No")
      a=0
      break
if a==1:
  print("Yes")

Measured memory_bytes: 20424
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int l, i = 0, a[n];
    while (cin >> l) {
        a[i] = l;
        i++;
    }
    int ans = 0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            ans += a[i]*a[j];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    set<int>st;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        if(st.count(a))
        {
            st.erase(a);
        }
        else st.insert(a);
    }
    cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// input
int N;

// action配列
long long a[100010][3]; // a[i],b[i],c[i]をそれぞれまとめてa[i][0], a[i][1],a[i][2]にしてしまう

// DP table
long long dp[100010][3];

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }

    //loop
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) // 2日間同じ行動はしない
                    continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // answer
    long long res = 0;
    for (int j = 0; j < 3; ++j)
        chmax(res, dp[N][j]); // 3つの中で最大のものをresに残す
    cout << res << endl;
}

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


def main():
    """Function."""
    n = int(input())
    s = str(input())

    max_val = 0
    for i in range(n-1):
        left, right = s[:i+1], s[i+1:]

        l_check, r_check = set(list(left)), set(list(right))
        temp = len(l_check & r_check)
        if temp > max_val:
            max_val = temp

    print(max_val)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define repr(i, r, l) for (ll i = (ll)(r); i > (ll)(l); i--)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define all(p) p.begin(), p.end()
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll mod=1e9+7;
const ll maxn = 2*1e5+5;
ll ceel(ll a, ll b){if (a % b == 0)return a / b;return a / b + 1;}
ll modneg(ll a,ll m){a = a % m;if(a<0)a=a+m;return a;}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };


int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ll n,x,m,sum=0;
cin>>n>>x>>m;
sum=x;
ll arr[m+5];
memset(arr,0,sizeof(arr));
vector <ll> v;
v.pb(0);
v.pb(x);
arr[x]=1;
ll idx=2;
ll fidx=0;
while(idx<=n)
{
    ll temp=(v.back()*v.back())%m;
    if(arr[temp])
    {
        fidx=arr[temp];
        break;
    }
    arr[temp]=idx;
    v.pb(temp);
    sum+=temp;
    idx++;
}
if(idx>n)
{
    cout<<sum<<endl;
    return 0;
}
ll tsum=0;
rep(i,fidx,idx)
    tsum+=v[i];
sum+=tsum*max((ll)0,(n-idx+1)/(idx-fidx));
tsum=0;
ll ldt=max((ll)0,(n-idx+1)%(idx-fidx));
rep(i,0,ldt)
{
    ll temp=(v.back()*v.back())%m;   
    v.pb(temp);
    sum+=temp;
}
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 5036
#include<stdio.h>
 
int cmpNum(int sum, int m, int mRank){
  double cmpVote;
  cmpVote = (double)sum / (double)(4*m);
  if(mRank < cmpVote) return 1;
  return 0;
}
 
int main(){
  int n,m,i,tmp,sum=0,isCorrect=0;
  scanf("%d %d", &n, &m);
  int num[n];
  int mRank[m];
  
  for(i =0; i<n; i++){
    scanf("%d",&num[i]);
    sum += num[i];
  }
  
  for(i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      if(num[i] <= num[j]){
        tmp = num[i];
        num[i] = num[j];
        num[j] = tmp;
      }
    }
  }
  
   for(i=0; i<m; i++){
     mRank[i] = num[i];
     isCorrect = cmpNum(sum,m,mRank[i]);
     if(isCorrect != 0){
       printf("No");
       return 0;
     }
   }
     
  printf("Yes");
}

Measured memory_bytes: 256
def dig(x):
    cnt = 0
    while x > 0:
        cnt += 1
        x //= 10
    return cnt

N = int(input())
ans = 999
for i in range(1, 100001):
    if i > N:
        break
    di = dig(i)
    if N % i == 0:
        j = N // i
        ans = min(ans, max(di, dig(j)))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  ll ans=MAXL;
  rep(i,max(x,y)*2+10) {
    ll sum=i*c;
    ll xx=max(0LL,x-i/2),yy=max(0LL,y-i/2);
    sum+=xx*a+yy*b;
    ans=min(ans,sum);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main() {
    ll N,M,t,r;
    cin >> N >> M;
    
    t = M-N*2;
    if(t >= 0)
        r = t/4 + N;
    else
        r = M/2;

    cout << r << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define LL long long
#define DB double
#define MOD 1000000007
#define MAXN 1000000
#define INF 1000000
#define mem(x,v) memset(x,v,sizeof(x))

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

int m,nxt,res;
char s[MAXN+5],t[MAXN+5];
int f1[MAXN+5],f2[MAXN+5];

void getfail(int *fail){
    for(int i=2,j=0;i<=m;i++){
        while(j&&t[i]!=t[j+1])j=fail[j];
        j+=(t[i]==t[j+1]);
        fail[i]=j;
    }
}

int checkpre(int x){return !(f1[x]&&x%(x-f1[x])==0);}
int checksuf(int x){return !(f2[x]&&x%(x-f2[x])==0);}

int main(){
    scanf("%s",t+1);m=strlen(t+1);
    getfail(f1),reverse(t+1,t+m+1),getfail(f2);
    if(!checkpre(m)){
        if(f1[m]==m-1)printf("%d\n%d",m,1);
        else{
            for(int i=1;i<m;i++)
            res+=(checkpre(i)&&checksuf(m-i));
            printf("%d\n%d",2,res);
        }
    }else printf("1\n1\n");
}


Measured memory_bytes: 8448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {

            //ABC051B
            var KS = ReadSplitInt();
            var K = KS[0];
            var S = KS[1];
            int cnt = 0;
            for (int i = 0; i <= K; i++)
            {
                for (int j = 0; j <= K; j++)
                {
                    var k = S - i - j;
                    if (k  >= 0 && K >= k)
                    {
                        cnt++;
                    }
                }
            }
            Console.WriteLine(cnt);

            Console.ReadKey();
        }



        #region MyRegion

        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        /// <summary>
        /// 空白区切の数値を取得する
        /// </summary>
        /// <returns>The read split int.</returns>
        public static int[] ReadSplitInt()
        {
            return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        /// <summary>
        /// 空白区切の数値を取得
        /// </summary>
        /// <returns>The read split long.</returns>
        public static long[] ReadSplitLong()
        {
            return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        }


        public static int[][] ReadSplitIntLines(int n)
        {
            return Enumerable.Range(0, n).Select(x => ReadSplitInt()).ToArray();
        }

        public static long[][] ReadSplitLongLines(int n)
        {
            return Enumerable.Range(0, n).Select(x => ReadSplitLong()).ToArray();
        }

        public static long[][] ReadSplitLongLines(long n)
        {
            var ret = new List<long[]>();
            for (long i = 0; i < n; i++)
            {
                ret.Add(ReadSplitLong().ToArray());
            }

            return ret.ToArray();
        }

        #endregion

    }
}


Measured memory_bytes: 13268
#include <stdio.h>

int main(void) {
  int a,b,j;
  while(1){
  scanf("%d %d",&a,&b);
  if(a==0&&b==0){
    break;
  }
 int i, j;
     for ( j = 0; j < a; j++ ){
 for ( i = 0; i < b; i++ ){
         if((i+j)%2==0){
             printf("#");
         } else {
             printf(".");
         }
     }
     printf("\n");
 }
  printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2048
s=list(input())
t=[]
for i in range(len(s)):
    if(s[i]=="0"):
        t = t +["0"]
    if(s[i]=="1"):
        t = t +["1"]
    if(s[i]=="B"):
        if(len(t)>0):
            t = t[:-1]
    
a="".join(t)
print(a)

Measured memory_bytes: 3060