akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  if(S[K-1] == 'A'){
    S[K-1] = 'a';
  }
   else if(S[K-1] == 'B'){
     S[K-1] = 'b';
   }
   else{
     S[K-1] = 'c';
   }
   cout << S << endl;
       return 0;
       }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int a,b,k,ans=0,c;
    cin>>a>>b>>k;
    for(int i=min(a,b);i>=1;i--){
        if(a%(i)==0&&b%(i)==0) ans++;
        if(ans==k){
            c=i;
            break;
        }
    }
    cout<<c;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		double[] p = new double[n+1];
		double[] q = new double[n+1];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 1; i <= n; i++) {
			p[i] = Double.parseDouble(st.nextToken());
		}
		st = new StringTokenizer(reader.readLine());
		for (int i = 0; i <= n; i++) {
			q[i] = Double.parseDouble(st.nextToken());
		}
		reader.close();
		System.out.println(getMinCost(n, p, q));
	}

	private double getMinCost(int n, double[] p, double[] q) {
		double[][] e = new double[n+2][n+1];
		double[][] w = new double[n+2][n+1];
		for (int i = 0; i <= n; i++) {
			e[i+1][i] = q[i];
			w[i+1][i] = q[i];
		}
		for (int l = 1; l <= n; l++) {
			for (int i = 1; i <= n - l + 1; i++) {
				int j = i + l - 1;
				e[i][j] = Double.MAX_VALUE;
				w[i][j] = w[i][j - 1] + p[j] + q[j];
				for (int r = i; r <= j; r++) {
					e[i][j] = Math.min(e[i][j], e[i][r-1] + e[r+1][j] + w[i][j]);
				}
			}
		}
		return e[1][n];
	}
}



Measured memory_bytes: 30648
import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
X = input()

def make_divisors(n):
	divisors = []
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n//i)
	return divisors

mod = 998244353
pow2 = [1]
for i in range(N):
	pow2.append((pow2[-1]*2) % mod)

yakusu_n = make_divisors(2*N)
yakusu_n.sort()



ans = 0
before = 0

#print(yakusu_n)
num_dict = defaultdict(int)
for n in yakusu_n:
	if N % (2*n) != 0 and N % n == 0:
		num = 0
		for i in range(n):
			if X[i] == "1":
				num += pow2[n - 1 - i]
		Y = list(X[:n])
		for i in range(n):
			if Y[i] == "0":
				Y.append("1")
			else:
				Y.append("0")
		Y = "".join(Y)
		Y = Y*(N//n)
		Y = Y[0:N]
		if X >= Y:
			num += 1
		#print(num, X>=Y)
		num_yakusu = make_divisors(n)
		for z in num_yakusu:
			num -= num_dict[z]
		num_dict[n] = num
		num *= 2*n
		num %= mod
		ans += num
		ans %= mod
		#print(n, ans, before, Y, X)

print(ans)

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

int main(){
  char s[10000000];

  cin>>s;
  int n = strlen(s);
  int t = n;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      t = min(t,max(i+1,n-i-1));
    }
  }

  cout<<t<<endl;

  return 0;
}


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

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

  if ((N % 1000) % 111 ==  0) {
    cout << "Yes" << endl;
  }
  
  else if ((N -(N % 10)) % 1110 == 0)  {
    cout << "Yes" << endl;
  }
  
  else { cout << "No" << endl;
  } 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    scanf("%d",&n);
    
    int x[n],y[n];
    
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&y[i]);
    }

    double p1,p2,p3,max=0;
    
    for(i=0;i<n;i++){
        p1+=abs(x[i]-y[i]);
        p2+=pow(abs(x[i]-y[i]), 2);
        p3+=pow(abs(x[i]-y[i]), 3);
        if(max<abs(x[i]-y[i])){
            max = abs(x[i]-y[i]);
        }
    }
    
    printf("%f\n",p1);
    printf("%f\n",sqrt(p2));
    printf("%f\n",pow(p3, 1.0/3.0));
    printf("%f\n",max);
    
    return 0;
}

Measured memory_bytes: 696
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<class T>inline void read(T &res)
{
    char c;
    T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';
    res*=flag;
}/*
char a[30];
int main()
{
    char ans[30000];
    int k=0;
    for(int i=1;i<=26;i++)
        a[i]='a'+i-1;
    ll x;
    read(x);
    while(x)
    {
        //printf("%c",a[x%26]);
        ans[k++]=a[x%26];
        x/=26;
    }
    while(k--)
        printf("%c",ans[k]);
    return 0;
}
*/
int main()
{
    int n,k;
    int a[1005];
    read(n);
    read(k);
    for(int i=0;i<n;i++)
        read(a[i]);
    sort(a,a+n);
    ll sum=0;
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dist(int a,int b,int c,int d)
{
    return abs(a-c)+abs(b-d);
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> >x,y;
    for(int i=0; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        x.push_back({a,b});
    }
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        y.push_back({a,b});
    }
    for(int i=0; i<n; i++)
    {
        int mn=INT_MAX,pos=0;
        for(int j=0; j<m; j++)
        {
            int cur=dist(x[i].first,x[i].second,y[j].first,y[j].second);
            if(cur<mn)
            {
                mn=cur;
                pos=j;
            }
        }
        cout<<pos+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 3660
import java.util.*;
import java.io.*;
 class Main
{
     static class InputReader {
        private InputStream stream;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0;
        private int ptrbuf = 0;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int readByte() {
            if (lenbuf == -1) throw new UnknownError();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = stream.read(inbuf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        private boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        private int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
    }
    public static void main(String args[])
    {
        InputReader sc=new InputReader(System.in);
        int n;
        n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
        }
        int count=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]!=a[i-1])
            continue;
            else
            {
              a[i]=1000;
              count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <string.h>
int main(void){
    char str1[200],str2[100],str3[100];
    scanf("%s %s",str1,str2);
    strcpy(str3,str1);
    strcat(str1,str3);
    
    if(strstr(str1,str2)==NULL) printf("No\n");
    else printf("Yes\n");
    
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int64_t N, ans = 0;
    cin >> N;
    for(int64_t k = 1; k * (k + 1) < N; k++) {
        if(N % k == 0) {
            ans += N / k - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

left=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][j]=='.':
      cnt+=1
      left[i][j]=cnt
    else:
      cnt=0
      left[i][j]=cnt
      
right=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][w-j-1]=='.':
      cnt+=1
      right[i][j]=cnt
    else:
      cnt=0
      right[i][j]=cnt

up=[[0]*w for i in range(h)]
for i in range(w):
  cnt=0
  for j in range(h):
    if grid[j][i]=='.':
        cnt+=1
        up[j][i]=cnt
    else:
        cnt=0
        up[j][i]=cnt

down=[[0]*w for i in range(h)]
for i in range(w):
  cnt=0
  for j in range(h):
    if grid[h-j-1][i]=='.':
        cnt+=1
        down[j][i]=cnt
    else:
        cnt=0
        down[j][i]=cnt

ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      tmp=left[i][j]+right[i][w-j-1]+up[i][j]+down[h-i-1][j]-3
      if tmp>ans:
        ans=tmp
    else:
      continue
print(ans)
    

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

ab = 4
af = 3
ar = 10

data = [[[0 for i in range(ar)] for j in range(af)] for k in range(ab)]

for i in range(n):
    instr = input().split()
    b = int(instr[0])
    f = int(instr[1])
    r = int(instr[2])
    v = int(instr[3])

    data[b - 1][f - 1][r - 1] += v

for i in range(ab):
    if i != 0:
        print('#' * 20)
    for j in range(af):
        print("", *data[i][j])



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

int main(){
	int n; string s,t; cin>>n>>s>>t;
	string s1,t1;
	int cnt=0;
	rep(i,n){
		s1=s.substr(i,n), t1=t.substr(0,n-i);
		if(s1==t1) {cnt=s1.size(); break;}
	}
	cout<<2*n-cnt<<endl;
}

Measured memory_bytes: 3632
s=input()
if s[0]!="A":
    print("WA")
else:
    ss=s.lower()
    l=len(s)
    dif=0
    for i in range(1,l):
        if s[i]!=ss[i]:
            dif+=1
    if dif==1:
        ok=0
        for i in range(2,l-1):
            if s[i]=="C":
                ok=1
        print("AC" if ok==1 else "WA")
    else:
        print("WA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
const LL MOD = (LL)1e9+7;
const LL INF = (LL)1e9+7;
const LL INFLL = (LL)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	cin >> n;
	vector<LL> line(n);
	foreach(i, line)cin>>i;
	sort(ALL(line));
	auto func = [&](LL e, int count){
		multiset<LL> s;
		foreach(i, line)s.insert(i);
		LL bnum = e;
		s.erase(s.find(e));
		LL res = 0;
		while(s.size()){
			if(count&1){
				res += *s.rbegin() - bnum;
				bnum = *s.rbegin();
				s.erase(s.find(bnum));
			}else{
				res += bnum - *s.begin();
				bnum = *s.begin();
				s.erase(s.find(bnum));
			}
			++count;
		}
		return res;
	};

	LL ans = 0;
	for(int i=-1;i<=1;++i){
		REP(j, 2){
			chmax(ans, func(line[min(n-1, n/2+i)], j));
		}
	}
	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;

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

  for(int i=0; i<6; i++){
    if(s[2]==s[3] && s[4]== s[5]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif


template <typename T>
struct Dijkstra {
  private:
    struct edge{
      int to;
      T cost;
      edge(int to,T cost):to(to),cost(cost){}
      bool operator<(const edge &e)const{return cost>e.cost;}
    };
    int n;
    vector<vector<edge> > G;
    vector<T> dist;
    vector<int> preV;
  public:
    Dijkstra(int n_):n(n_),G(n_){};
    void add_edge(int u, int v, T c) {
      assert(u < n);
      assert(v < n);
      G[u].emplace_back(v,c);
    }
    void build(int s) {
      dist.assign(n,numeric_limits<T>::max());
      preV.assign(n,-1);
      dist[s] = 0;
      priority_queue<edge> que;
      que.push(edge(s,0LL));
      while(!que.empty()) {
        auto p = que.top(); que.pop();
        int v = p.to;
        if (dist[v] < p.cost) continue;
        for (auto e:G[v]) {
          if (dist[e.to] > dist[v]+e.cost) {
            dist[e.to] = p.cost+e.cost;
            preV[e.to] = v;
            que.push(edge(e.to,dist[e.to]));
          }
        }
      }
    }
    int get_path(int to) { //経路復元
      // vector<int> path;
      // for(; to != -1; to = preV[to]){
      //   path.emplace_back(to);
      // }
      // reverse(path.begin(), path.end());
      // return path;
      return preV[to];
    }
    T operator[](int k){
      assert(k < n);
      return dist[k];
    }
};


int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,m;
  cin >> n >> m;
  Dijkstra<int> dijkstra(n);
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    dijkstra.add_edge(a,b,1);
    dijkstra.add_edge(b,a,1);
  }
  dijkstra.build(0);
  bool ok = true;
  vector<int> ans(n);
  for (int i = 1; i < n; ++i) {
    if (dijkstra[i] == numeric_limits<int>::max()) {
      ok = false; break;
    }
    ans[i] = dijkstra.get_path(i) +1;
  }
  cout << (ok ? "Yes" : "No") << endl;
  if (ok) {
     for (int i = 1; i < n; ++i) {
       cout << ans[i] << "\n";
     }
  }
  return 0;
}

Measured memory_bytes: 13532
fn main() {
    proconio::input! {
        n: usize,
        a: [usize;n],
    }
    let m=*a.iter().max().unwrap()as usize+1;
    let mut p=vec![false;m];
    let mut f=true;
    'outer: for a in &a {
        let mut a=*a;
        let mut k=2;
        while k*k<=a {
            if a%k==0 {
                if p[k] {
                    f=false;
                    break 'outer;
                }
                p[k]=true;
                while a%k==0 {
                    a/=k;
                }
            }
            k+=1;
        }
        if a>1 {
            if p[a] {
                f=false;
                break;
            }
            p[a]=true;
        }
    }
    if f {
        println!("pairwise coprime");
        return;
    }
    if a.into_iter().fold(0,|a,b|num::integer::gcd(a,b))==1 {
        println!("setwise coprime");
    }
    else {
        println!("not coprime");
    }
}


Measured memory_bytes: 17492
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int N, M;
vector<vector<int>> e(100000, vector<int>());
int dp[100001];

int dfs(int x){

    if(dp[x] != -1){
        return dp[x];
    }
    else{
        int temp = 0;
        for(int i = 0; i < (int)e[x].size(); i++){
            temp = max(temp, dfs(e[x][i]) + 1);
        }
        dp[x] = temp;
        return temp;
    }
}

int main(){

    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        e[x - 1].push_back(y - 1);
    }

    for(int i = 0; i < N; i++){
        dp[i] = -1;
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
        ans = max(ans, dfs(i));
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 8192
import java.util.Scanner;

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

    public static void main(String[] args) {
        int N = sc.nextInt();
        double[] p = new double[N + 1];
        double[][] f = new double[N + 1][N + 1];
        for(int i = 1; i <= N;  i++)p[i] = sc.nextDouble();

        f[0][0] = 1;
        for(int i = 1; i <= N; i ++){
            f[i][0] = f[i - 1][0] * (1 - p[i]);
            for(int j = 1; j <= i; j ++){
                f[i][j] = f[i - 1][j - 1] * p[i] + f[i - 1][j] * (1 - p[i]);
            }
        }
        int cnt;
        if((N&1) == 1) cnt = N + 1 >> 1;
        else cnt = (N >> 1) + 1;
        double res = 0.0;
        for(int i = cnt; i <= N; i++)res += f[N][i];
        System.out.println(res);
    }
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int C;
  C = A + B;
  if ( C <= (A - B) ){
    C = A -B;
  }
  if( C <= (A * B) ){
    C = A * B;
  }
  cout << C << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    if(k>(b-a)/2){
        for (int i = a; i <= b; i++)
        {
            cout << i << endl;
        }
    }else{
        rep0(i,k){
            cout << a+i << endl;
        }
        for (int i = b-k+1; i <= b; i++)
        {
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

#define NUM_MAX 100000

struct katana {
    int cut;
    int throw;
};

int desc_by_throw(const void *a1, const void *a2) {
    struct katana *k1 = (struct katana*)a1;
    struct katana *k2 = (struct katana*)a2;
    return k2->throw - k1->throw;
}

int main(void) {
    int ks, hp;
    get_int2(&ks, &hp);
    static struct katana katanas[NUM_MAX+1];

    int i;
    int cut_max = 0;
    for(i = 0; i < ks; i++) {
        get_int2(&katanas[i].cut, &katanas[i].throw);
        cut_max = max(cut_max, katanas[i].cut);
    }
    katanas[ks] = (struct katana){cut_max, cut_max};
    qsort(katanas, ks+1, sizeof(struct katana), desc_by_throw);

    int cnt = 0;
    for(i = 0; i < ks+1; i++) {
        if(hp<=0) break;
        // attack the enemy by cut until we defeat it.
        if(katanas[i].throw == cut_max) {
            cnt += (hp-1)/cut_max + 1;
            break;
        } else {
            hp -= katanas[i].throw;
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

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

import sys
import os
import math


N = int(input())

for i in range(N):
    ax, ay, ar, bx, by, br = map(float, input().split())

    between_center = math.hypot(ax - bx, ay - by)

    # ????????£????????????
    if between_center > ar + br:
        print(0)

    # ????????????????????¨
    else:
        # B in A
        if ar > between_center + br:
            print(2)

        # A in B
        elif br > between_center + ar:
            print(-2)

        else:
            print(1)

Measured memory_bytes: 7596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, l;
    cin >> n >> l;
    int minv = 100000, minv2;
    for (int i = 1; i <= n; i++) {
        if (minv > abs(l+i-1)) minv2 = l+i-1;
        minv = min(minv, abs(l+i-1));
    }
    int ans = 0 - minv2;
    for (int i = 1; i <= n; i++) {
        int taste = l+i-1;
        ans += taste;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7;
  
//const int maxn=
 
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int n;
    cin>>n;
    
    string str;
    cin>>str;
    
    for(int i=0;i<str.size();i++)
    {
    	str[i]=(str[i]-'A'+n)%26+'A';
	}
	
	cout<<str<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::*;
use proconio::{input, fastout, marker::*};

#[fastout]
fn main() {
  input!{
      n: u64,
      a: [u64;n]
  }
  let mut s:u64 = a.iter().sum();
  let mut ans:u64 = 0;
  let MOD = 1_000_000_007;
  for i in a {
      s -= i;
      ans += ((s%MOD)*(i%MOD))%MOD;
      ans %= MOD;
  }
  println!("{}",ans);
}


Measured memory_bytes: 5676
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	int R, G;

	cin >> R >> G;

	cout << 2 * G - R << endl;

	return 0;
}

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<algorithm>
using namespace std;
int v[100005][3];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	{
		char col;
		scanf("%d%d %c",&v[i][0],&v[i][1],&col);
		v[i][0]%=2*k;v[i][1]%=2*k;
		v[i][2]=('W'==col);
	}
	int ans=0;
	for(int i=0;i<k;i++) //行 
	{
		int cnt=0,p=0,q=k-1,tot[2005]={};
		for(int j=0;j<n;j++)
		{
			int g=0;
			if(p<=v[j][1] && v[j][1]<=q) g++;
			if(i<=v[j][0] && v[j][0]<=i+k-1) g++;
			if(g%2==v[j][2]) tot[v[j][1]]++,cnt++;
			else tot[v[j][1]]--;
		}
		for(;q<2*k;q++,p++)
		{
			ans=max(ans,max(cnt,n-cnt));
			cnt-=tot[q+1]+tot[p];
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1280
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  vi A(N);
  cin >> A;
  map<int, int> cnt;
  int ans = 0;
  rep(i, 0, N) {
    ans += cnt[A[i] - i];
    cnt[-(A[i] + i)]++;
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 27408
#include <bits/stdc++.h>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

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

int factorization(int n){
    int fac_ans = 1.0;
    for(int i=1;i<=n;i++) fac_ans *= i;
    return fac_ans;
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 100000000;

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

    string c;
    cin >> c;

    int f_i=0,b_i=n-1;

    int cnt=0;

    while(1){
        if(c[f_i] != 'W'){
            if(f_i == b_i) break;
            f_i++;
        }else{
            if(c[b_i] != 'R'){
                if(b_i == f_i) break;
                b_i--;
            }else{
                swap(c[f_i],c[b_i]);
                cnt++;
                //cout << c << endl;
            }
        }
    }
    int q;
    repr(i,n){
        if(c[i]=='R') q=i;
    }

    rep(i,q){
        if(c[i]=='W'){
            cnt++;
            c[i] = 'R';
        }
    }

    cout << cnt << endl;
    //cout << c << endl;

    return 0;
}

Measured memory_bytes: 3756
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
/*#include <ext/pb_ds/assoc_container.hpp> // Общий файл.
#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rep0(i, n) for(int i = (0); i < (n); i++)
#define repd(i,m,n) for(int i=(m); i > (n); i--)
#define iter(el, arr) for(auto& el : arr)
#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)

#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()

#define ld long double
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plli pair<pll,int>
#define mp make_pair
#define MP make_pair
#define sz(a) int((a).size())
#define X first
#define Y second

#define endl '\n'
#define pb push_back
#define has(i, m) (m.find(i) != m.end())

#define vi vector<int>
#define vll vector<ll>
#define vch vector<char>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vb vector<bool>
#define vvb vector<vb>
#define pdd pair<long double, long double>
#define vpll vector<pll>
#define vpdd vector<pair<long double, long double> >
#define pq priority_queue
#define mod 1000000007
using namespace std;

#define lsb(i) ((-i) & i)


int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int n;
	cin >> n;
	vi arr(n);
	vi vals(1e5 + 5);
	rep0(i, n) {
		cin >> arr[i];
		vals[arr[i]]++;
		vals[arr[i] + 1]++;
		vals[arr[i] + 2]++;
	}

	cout << *max_element(ALL(vals)) << endl;
}

Measured memory_bytes: 1024
// 2014/06/20 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

		if(cin.eof())
			break;

		int cnt = 0;
		string::size_type index = 0;
		while(true){
			index = s.find("JOI", index);

			if(index==string::npos)
				break;

			cnt++;
			index++;
		}
		cout << cnt << endl;
 
		cnt = 0;
		index = 0;
		while(true){
			index = s.find("IOI", index);

			if(index==string::npos)
				break;

			cnt++;
			index++;
		}
		cout << cnt << endl;
	}

	return 0;
}

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

int main(){

    int a,b;
    char op;

    while(1){

      scanf("%d %c %d",&a,&op,&b);

      if(op == '?') break;

        switch(op){

          case '+':
             printf("%d\n",a+b);
             break;
          case '-':
             printf("%d\n",a-b);
             break;
          case '*':
             printf("%d\n",a*b);
             break;
          case '/':
             printf("%d\n",a/b);
             break;
         }
      }

    return 0;

}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main() 
{
    cin>>a>>b>>c;
    if(a==1) 
	{
        cout<<"YES"<<endl;
        return 0;
    }
    for(int i=1;i<=100;i++)
    {
        if(a*i%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, l;
    cin >> n >> l;
    vector<string> S;
    S.resize(n);
    rep(i, n) {
        cin >> S[i];
    }
    sort(S.begin(), S.end());

    string ans;
    rep(i, n) {
        ans += S[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#n = int(input())
a,b=map(int,input().split()) #横並び
x,y=map(int,input().split())
ret = x*b+a*y-x*y
print(a*b-ret)
#x=[int(input()) for i in range(3)] #縦に並んだのを配列に
#y=list(map(int,input().split())) #横に並んだのを配列に
#print('YNEOS'[1::2])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    for(int i=0;i<k;i++) ans+=a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>
#include<array>

using namespace std;

int main()
{
  array<int, 4> a;
  array<int, 4> b;

  while ( cin >> a[0] >> a[1] >> a[2] >> a[3] )
    {
      cin >> b[0] >> b[1] >> b[2] >> b[3];

      int ht = 0;
      int bl = 0;
      
      for ( auto i = 0; i < 4; ++i )
        for ( auto j = 0; j < 4; ++j )
          if ( a[i] == b[j] )
            if ( i == j )
              ++ht;
            else
              ++bl;
      cout << ht << " " << bl << endl;
    }
  
  return 0;
}

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

int main(int argc, char **argv)
{
	ll A, B; cin >> A >> B;

	ll i{0};
	ll num{1};
	while (num < B)
	{
		num += A-1;
		++i;
	}
	std::cout << i << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2666;
int n,a[N],s;
vector<Pii>solve(Vi a){
	if(SZ(a)==4)return {mp(0,0),mp(1,0),mp(1,1),mp(0,1)};
	int offset=0;
	while(!(a[0]==1&&a[1]==1&&a[2]==-1)){
		auto tmp=a.back();per(i,SZ(a)-1,1)a[i]=a[i-1];a[0]=tmp;offset++;
	}
	
	Vi b;rep(i,0,SZ(a)-1)if(i!=1&&i!=2)b.pb(a[i]);
	vector<Pii>ans=solve(b);
	while(!(ans[0].fi<ans[1].fi&&ans[0].se==ans[1].se)){
		for(auto &a:ans)a=mp(a.se,SZ(ans)-a.fi+1);
	}
	for(auto &a:ans)a=mp(2*a.fi,2*a.se);
	auto tmp=ans[1];
	ans.insert(ans.begin()+2,mp(tmp.fi,tmp.se+1));
	ans.insert(ans.begin()+2,mp(tmp.fi+1,tmp.se+1));
	ans[1].fi++;
//	ans.insert(ans.begin()+2,mp(tmp.fi+1,tmp.se));
	b.clear();Vi c;for(auto x:ans)b.pb(x.fi),c.pb(x.se);
	sort(ALL(b));sort(ALL(c));
	for(auto &x:ans)x=mp(lower_bound(ALL(b),x.fi)-b.begin()+1,lower_bound(ALL(c),x.se)-c.begin()+1);
	
	offset=SZ(a)-offset;
	while(offset--){
		auto tmp=ans.back();per(i,SZ(ans)-1,1)ans[i]=ans[i-1];ans[0]=tmp;
	}
	return ans;
}
int main() {
	read(n);rep(i,1,n)read(a[i]),a[i]=a[i]==90?1:-1,s+=a[i];
	if(s!=4){puts("-1");return 0;}
	Vi b;rep(i,1,n)b.pb(a[i]);
	vector<Pii>ans=solve(b);
	for(auto x:ans)if(x!=ans[0])printf("%d %d\n",x.fi,x.se);
	auto x=ans[0];
	printf("%d %d\n",x.fi,x.se);
	return 0;
}


Measured memory_bytes: 2688
import           Control.Applicative
import           Control.Monad
import           Data.List

type Dice=[Int]

rotate:: Dice -> Char -> Dice
rotate [u,f,r,l,b,d] 'E' = [l,f,u,d,b,r]
rotate [u,f,r,l,b,d] 'N' = [f,d,r,l,u,b]
rotate [u,f,r,l,b,d] 'S' = [b,u,r,l,d,f]
rotate [u,f,r,l,b,d] 'W' = [r,f,d,u,b,l]
rotate xs _              = xs

search :: [Dice]->Int->Int->Dice
search dices up front
  | null found =  search [ rotate d opt | d <-dices, opt<-"ENSW" ] up front
  | otherwise = head found
  where
    found = [dice | dice@[u,f,r,l,b,d]<-dices, u==up, f==front]

main :: IO ()
main = do
  dice <- map read . words <$> getLine
  qs <- getLine
  query <- replicateM (read qs) (map read . words <$> getLine)
  putStr $ unlines $ map show [search [dice] up front !!2 | [up, front]<-query]



Measured memory_bytes: 4112
#include <iostream>

using namespace std;

int main(){
    int N;
    int b[100];
    int tmp[100];
    bool used[100];
    cin >> N;
    int ans[100];
    for(int i = 0; i < N; i++){
        cin >> b[i];
        tmp[i] = b[i];
        used[i] = false;
    }
    for(int i = N-1; i >= 0; i--){
        
        for(int j = i; j >= 0; j--){
            if(b[j] == j+1){
                ans[i] = j+1;
                //cout << j+1 << endl;
                int idx = 0;
                for(int k = 0; k <= i; k++){
                    if(k != j){
                        tmp[idx] = b[k];
                        idx++;
                    }
                }
                for(int k = 0; k < i; k++) b[k] = tmp[k];
                break;
            }
            if(j == 0){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(int i = 0; i < N; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc048c()
}

fun abc048c() {
    val (n, x) = readLine()!!.split(' ').map { it.toLong() }
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()
    val initValue = aList.copyOf()

    var answer = 0L
    for (i in 0 until aList.lastIndex) {
        val value = aList[i]
        val diff = value + aList[i + 1] - x
        if (diff > 0) {
            val remain = diff - aList[i + 1]
            aList[i + 1] = Math.max(0, aList[i + 1] - diff)
            if (remain > 0) aList[i] -= remain
            answer += diff
        }
    }

    println(answer)
}


Measured memory_bytes: 70472
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int n;
    double v, u;
    priority_queue<double, vector<double>, greater<double>> q;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> v;
        q.push(v);
    }
    for (int i = 0; i < n - 1; ++i) {
        v = q.top();
        q.pop();
        u = q.top();
        q.pop();
        q.push((u + v) / 2);
    }
    cout << fixed << setprecision(10) << q.top() << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
mod = int(1e9) + 7
line = 'TAGC'
ng = {"AGC", "ACG", "GAC", "ATGC", "AGGC", "ACGC", "AGTC", "AGCC"}
D = {line[(i//16)%4]+line[(i//4)%4]+line[i%4]: i for i in range(64)}
invD = {i: line[(i//16)%4]+line[(i//4)%4]+line[i%4] for i in range(64)}
dp = [[0 for _ in range(N+1)] for __ in range(64)]
dp[0][0] = 1
for i in range(4):
  dp[i][1] = 1
for i in range(16):
  dp[i][2] = 1
for i in range(3, N+1):
  for j in range(64):
    for k in range(4):
      last = invD[j]
      if last not in ng:
        if (last[1:] + line[k]) not in ng and last + line[k] not in ng:
          dp[D[last[1:]+line[k]]][i] += dp[D[last]][i-1]
          dp[D[last[1:]+line[k]]][i] %= mod
S = 0
for i in range(64):
  S += dp[i][N]
  S %= mod
print(S)

Measured memory_bytes: 9308
N = int(input())
X = []
for i, x in enumerate(map(int, input().split())):
    X.append((x, i))

X.sort()
Y = [0] * N
for j, (x, i) in enumerate(X):
    Y[i] = j

mid = N / 2
l = X[N // 2 - 1][0]
r = X[N // 2][0]
ans = []
for j in Y:
    if j < mid:
        ans.append(r)
    else:
        ans.append(l)

print(*ans, sep='\n')


Measured memory_bytes: 115668
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(void){
  int prime[50000];
  int prime_f[51001];
  int k;
  int n;
  int i,j;
  int n_size;

  while(cin>>n){
    k=0;
    memset(prime_f,0,sizeof(prime_f));
    prime_f[0]=prime_f[1]=1;
    for(i=2;i<51000;i++){
      if(!prime_f[i]){
	k++;
	prime[k]=i;
	for(j=2*i;j<51000;j+=i){
	  prime_f[j]=1;
	}
      }
    }

    for(i=0;i<k;i++){
      if(prime[i]>=n){
	if(prime[i]==n){
	  cout<<prime[i-1]<<" "<<prime[i+1]<<endl;
	}else{
	  cout<<prime[i-1]<<" "<<prime[i]<<endl;
	}
	break;
      }  
    }
  }
  return(0);
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
using namespace std;
int h[100005];
int minn[100005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	minn[n-2]=h[n-1];
	for(int i=n-3;i>=0;i--){
		minn[i]=min(minn[i+1],h[i+1]);
	}
/*	for(int i=0;i<n-1;i++){
		cout<<minn[i]<<" ";
	}
	cout<<endl;
*/	for(int i=0;i<n-1;i++){
		if(h[i]-minn[i]>1){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl             '\n'
#define mem(a, n)        memset(a, n, sizeof(a))
#define repeat(i, a, n)  for(int i=a; i<n; i++)

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

int main(){
    quicken();

    int n, k, l, r, maxi, zero;
    string str; cin >> n >> k >> str;

    vector<pair<int, int>> v;
    l = r = zero = 0;
    while(l<=r && r<n){
        if(r<n) while(str[r]==str[l]) r++;
        v.push_back({l, r-1}), l = r;
    }

    n = v.size(), l = r = maxi = 0;
    if(str[0]=='1')
        while(l<=r && r<n){
            if(r&1) zero++;
            if(zero>k){
                if(l%2==0) zero--, l+=2;
                else zero--, l++;
            }
            maxi = max(maxi, v[r].second-v[l].first+1);
            r++;
        }
    else
        while(l<=r && r<n){
            if(r%2==0) zero++;
            if(zero>k){
                if(l&1) zero--, l+=2;
                else zero--, l++;
            }
            maxi = max(maxi, v[r].second-v[l].first+1);
            r++;
        }
   cout << maxi;

    return 0;
}

Measured memory_bytes: 1528
A,B,M = map(int,input().split())

As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
XYC = []
min_cost = 10**10
for i in range(M):
    x,y,c = map(int,input().split())
    cost = As[x-1] + Bs[y-1]-c
    min_cost = min(min_cost,cost)
min_cost = min(min_cost,min(As)+min(Bs))
print(min_cost)

Measured memory_bytes: 18612
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int R = scanner.nextInt();
    int G = scanner.nextInt();
    int B = scanner.nextInt();
    int N = scanner.nextInt();

    long count = 0;
    for (int i = 0; i <= N / R; i++) {
      int r = N - R * i;
      for (int j = 0; j <= r / G; j++) {
        if ((r - G * j) % B == 0) count++;
      }
    }
    System.out.println(count);
  }
}


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

using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
using Tuple = tuple<int, int, int>;


struct Sieve {
    ll n;

    // fには、その数を割れる素因数が
    // primesには素数が入ってる
    vector<ll> f, primes;

    // nまでの素因数列挙
    Sieve(ll n=1): n(n), f(n+1) {
        f[0] = f[1] = -1;
        for(ll i=2; i <= n; i++) {
            if(f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for(ll j = i+i; j <= n; j += i) {
                if(!f[j]) f[j] = i;
            }
        }
    }

    bool isPrime(ll x) { return f[x] == x; }

    // xを素因数分解する関数
    vector<ll> factorList(ll x) {
        vector<ll> res;
        while(x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }

    vector<P> factor(ll x) {
        vector<ll> factors = factorList(x);
        if(factors.size() == 0) return {};
        vector<P> res(1, P(factors[0],0));
        for (ll p : factors) {
            if(res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};


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

ll modnum = 1e9+7;

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

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

    Sieve s = Sieve(1e6);

    map<ll, ll> mp;
    rep(i, n) {
        auto f = s.factor(a[i]);
        for(auto p : f) {
            mp[p.first] = max(p.second, mp[p.first]);
        }
    }

    ll lcm = 1;
    for(auto p : mp) {
        rep(i, p.second) {
            lcm *= p.first;
            lcm %= modnum;
        }
    }

    ll ans = 0;
    rep(i, n) {
        ans += lcm * modinv(a[i], modnum);
        ans %= modnum;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9336