akhauriyash/Code-Regression huggingface dataset:
/* ABC135-C.c
   Takatan */

#include<stdio.h>
#include<stdlib.h>
int main(void){
    int number, *town, *brave, i;
    long long int count;
    count = 0;

    scanf( "%d" , &number);

    town = malloc(sizeof(int) * (number+1)); /* メモリを確保 */
    brave = malloc(sizeof(int) * number); /* メモリを確保 */

    for(i=0; i < number+1; i++){
        scanf( "%d" , town+i);
    }
    for(i=0; i < number; i++){
        scanf( "%d" , brave+i);
            /* i番目の勇者が2つの街のモンスターを順に倒し、モンスターの残りをtownに保存する。 */
        if(town[i]<brave[i]){
            count += town[i]; /* 倒せる数を加算 */
            brave[i] = brave[i]-town[i]; /* 残り倒せるモンスターの数を保存 */
            if(town[i+1]<brave[i]){
                count += town[i+1]; /* 倒せる数を加算 */
                town[i+1] = 0; /* 残りのモンスターの数を保存 */
            }else{
                count += brave[i]; /* 倒せる数を加算 */
                town[i+1] = town[i+1] - brave[i]; /* 残りのモンスターの数を保存 */
            }
        }else{
            count += brave[i]; /* 倒せる数を加算 */
        }
    }

    printf( "%lld\n" , count);
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  while (H != 0 || W != 0) {
    if (H == 0 || W == 0) {
      cout << endl;
      cin >> H >> W;
      continue;
    }

    for (int x = 0; x < H; x++) {
      for (int y = 0; y < W; y++) {
        if (x == 0 || x == (H-1) || y == 0 || y == (W-1)) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
    cin >> H >> W;
  }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define int long long int
using namespace std;

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	while (t--) {
		int n;
		long double d, x, y;
		cin >> n;
		cin >> d;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			cin >> x >> y;
			long double k = sqrt(x * x + y * y);
			if (k <= d) cnt++;
		}
		cout << cnt << endl;

	}
	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<(int)(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;

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

  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;

  int cnta=0, cntb=0;
  rep(i, n){
    if(s[i]=='a'){
      if(cnta<a+b){
        cnta++;
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    if(s[i]=='b'){
      if(cnta<a+b&&cntb<b){
        cnta++;
        cntb++;
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    if(s[i]=='c')cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3592
object Main extends App {
    for (r <- io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))) {
        var (rem, res, i) = (r(0), 0, r(2))
        while (i > 0) {
            rem = rem % r(1) * 10
            res += rem / r(1)
            i -= 1
        }
        println(res)
    }
}

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

int main() {
  int H,W;
  cin >> H >> W;

  vector<string> data(H);
  for (int i = 0; i < H; i++) {
    cin >> data[i];
    bool flag = true;
    for (int j = 0; j < W; j++) {
      if (data[i][j] == '#') {
        flag = false;
      }
    }
    if (flag == true) {
      data[i][0] = '$';
    }
  }

  for (int i = 0; i < W; i++) {
    bool flg = true;
    for (int j = 0; j < H; j++) {
      if (data[j][i] == '#') {
        flg = false;
      }
    }
    if (flg == true) {
      for (int k = 0; k < H; k++) {
        if (data[k][i] != '$') data[k][i] = '%';
      }
    }
  }

  for (int i = 0; i < H; i++) {
    if (data[i][0] == '$') {
      continue;
    }
    for (int j = 0; j < W; j++) {
      if (data[i][j] == '%') continue;
      cout << data[i][j];
    }
    cout << endl;
  }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        if (a == 1 || b == 1) {
            mp[a*b]++;
        }
        if (a == n || b == n) {
            mp[min(a, b)]++;
        }
    }
    bool ok = false;
    for(auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->second == 2) ok = true;
    }
    if (ok) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 9600
S=input()
rl=[0]
f=0
for c in S:
    if (c=='R' and f%2==1) or (c=='L' and f%2==0):
        f+=1
        rl.append(0)
    rl[f]+=1
rla=[0]*len(rl)
rla[0]=rl[0]
for i in range(len(rl)-1):
    rla[i+1]=rla[i]+rl[i+1]
a=[0]*len(S)
for i in range(len(rl)//2):
    a[rla[i*2]-1]=(rl[i*2]+1)//2+rl[i*2+1]//2
for i in range(len(rl)//2):
    a[rla[i*2]]=rl[i*2]//2+(rl[i*2+1]+1)//2
print(*a)

Measured memory_bytes: 11072
#include<stdio.h>
char d[1000010];
int dd[1000010]={0};
int main(){
  int w,h,a,b,c,n,i,j,k,x,y,mi,mj,p[1000010]={0};
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};
  scanf("%d %d",&w,&h);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf(" %c",&d[i*1000+j]);
      if(d[i*1000+j]=='t')d[mi=i*1000+j]='.';
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(d[i*1000+j]=='#')continue;
      for(k=0;k<4;k++){
	y=i+Y[k];
	x=j+X[k];
	if(y<0||x<0||w==x||h==y||d[y*1000+x]=='#')continue;
	for(a=i*1000+j+1;p[a];a=p[a]);
	for(b=y*1000+x+1;p[b];b=p[b]);
	if(a-b){
	  if(dd[a]< dd[b]) p[a]=b;
	  if(dd[a]>=dd[b]) p[b]=a;
	  if(dd[a]==dd[b])dd[b]++;
	}
      }
    }
  }
  scanf("%d",&n);
  for(c=0;c<=n;c++){
    for(a=1;p[a];a=p[a]);
    for(mj=mi+1;p[mj];mj=p[mj]);
    if(mj==a){
      printf("%d\n",c);
      break;
    }
    if(c==n){
      printf("-1\n");
      break;
    }
    scanf("%d %d",&j,&i);
    if(d[i*1000+j]=='.')continue;
    d[i*1000+j]='.';
    /*for(a=0;a<h;a++){
      for(b=0;b<w;b++)printf("%8d",p[a*1000+b+1]);
      printf("\n");
    }printf("\n");//*/
    for(k=0;k<4;k++){
      y=i+Y[k];
      x=j+X[k];
      if(y<0||x<0||w==x||h==y||d[y*1000+x]=='#')continue;
      for(a=i*1000+j+1;p[a];a=p[a]);
      for(b=y*1000+x+1;p[b];b=p[b]);
      if(a-b){
	if(dd[a]< dd[b]) p[a]=b;
	if(dd[a]>=dd[b]) p[b]=a;
	if(dd[a]==dd[b])dd[a]++;
      }
    }
  }
  /*for(i=0;i<h;i++){
    for(j=0;j<w;j++)printf("%8d",p[i*1000+j+1]);
    printf("\n");
    }//*/
  while(c++<n)scanf("%*d %*d");
  return 0;
}
   

Measured memory_bytes: 9396
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	b := nextLine()
	m := map[string]string{
		"A": "T",
		"T": "A",
		"C": "G",
		"G": "C",
	}
	fmt.Println(m[b])
}


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

long long N, M, V, P;
vector<long long> A;

bool possible(int index) {
    while (index > 0 && A[index] == A[index - 1])
        index--;

    if (index < P)
        return true;

    long long automatic = P - 1 + N - index;

    if (automatic >= V)
        return A[index] + M >= A[P - 1];

    long long still_need_per_judge = V - automatic;
    long long still_to_add = M * still_need_per_judge;
    long long target = A[index] + M;

    for (int i = P - 1; i < index; i++) {
        long long take = min(M, target - A[i]);
        take = min(take, still_to_add);
        take = max(take, 0LL);

        if (A[i] + take > target)
            return false;

        still_to_add -= take;
    }

    return still_to_add == 0;
}

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

    cin >> N >> M >> V >> P;
    A.resize(N);

    for (auto &a : A)
        cin >> a;

    sort(A.rbegin(), A.rend());
    int low = 0, high = N;

    while (low < high) {
        int mid = (low + high) / 2;

        if (possible(mid))
            low = mid + 1;
        else
            high = mid;
    }

    cout << low << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う
#include <bits/stdc++.h> //piの利用で必要(M_PI)
#include <algorithm>
#include <climits>
#include <map>
#define rep(i, c) for (int i = 0; i < (int)c; i++) //atcoderの解説コードに利用されていたので，ある程度一般生があるかと思われる．
#define ll long long

int main()
{
    int r;
    std::cin >> r;

    std::cout << r*r << std::endl;

    return 0;
}

Measured memory_bytes: 3636
N, K = map(int,input().split())
A = list(map(int, input().split()))
tmp = [0]*(N-K)
for i in range(N-K):
    tmp[i] = A[i]/A[K+i]

for i in range(N-K):
    if tmp[i] < 1:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 31628
import math
from decimal import Decimal

N, K = map(int, input().split())

win = 0

for i in range(1, N+1):
    if K - i < 1:
        win += 1
        continue

    win += (1/2)**(math.ceil(math.log2(K/i)))
    #print((math.ceil(math.log2(K/i))))

print('{:.10g}'.format(Decimal(win/N)))


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[110],b[110],cnt;
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		cin>>b[i];
		if(a[i]>b[i])cnt+=a[i]-b[i];
	}
	cout<<cnt<<endl;
	return 0;
}

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

A = []

x = []
y = []

for i in range(N):
    temp = int(input())
    A.append(temp)
    temp3 = []
    temp4 = []
    for j in range(temp):
        temp1,temp2 = map(int,input().split())
        temp3.append(temp1)
        temp4.append(temp2)
    x.append(temp3)
    y.append(temp4)

res = 0

for i in range(2 ** N):
    isOK = True
    honest = 0
    for j in range(N):
        if ((i >> j) & 1):
            honest += 1
            for k in range(A[j]):
                if (((i >> (x[j][k]-1)) & 1) ^ y[j][k]):
                    isOK = False
    if isOK:
        res = max(res,honest)

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll cv = a[0], ans = 0;
    reps(i, 1, n) {
        ans += max(0LL, cv - a[i]);
        chmax(cv, a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4764
#pragma GCC optimize "-O3"
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
#include"bits/stdc++.h"

using namespace std;

#define MAX 2000

int n;
int m;

vector<int> v[MAX];

queue<tuple<int, int, int> > q;

set<pair<int, int> > s;

bitset<MAX> con[MAX];

bitset<MAX>  child[MAX];
bitset<MAX> par[MAX];

bitset<MAX> stk;

inline void dfs(int b, int pr = -1) {
	auto &c = child[b];
	c.set(b, 1);
	for (int go : v[b]) {
		if (go == pr)continue;
		dfs(go, b);
		c |= child[go];
	}
}

int pat[MAX][MAX];
int lca[MAX][MAX];

int dep[MAX];


inline void dfs2(int b, int pr = -1, int star = 0) {
	pat[star][b] = pr;
	lca[star][b] = b;
	if (pr != -1) {
		if (lca[star][pr] != -1) {
			if (dep[lca[star][pr]] < dep[b]) {
				lca[star][b] = lca[star][pr];
			}
		}
	}
	for (int go : v[b]) {
		if (go == pr)continue;
		dfs2(go, b, star);
	}
}
inline void dfs3(int b, int pr = -1, int d = 0) {
	stk.set(b, 1);
	par[b] = stk;
	dep[b] = d;
	for (int go : v[b]) {
		if (go == pr)continue;
		dfs3(go, b, d + 1);
	}
	stk.set(b, 0);
}
bitset<MAX> ff;
int main() {
	cin >> n >> m;
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs3(0);
	dfs(0);
	for (int i = 0; i < n; i++) {
		dfs2(i, -1, i);
	}
	int edd = 0;
	for (int i = 0; i < m; i++) {
		int c, d;
		scanf("%d%d", &c, &d);
		c--;
		d--;
		con[c].set(d, 1);
		con[d].set(c, 1);
		q.push(make_tuple(0, c, d));
		edd++;
	}
	bitset<MAX> full;
	for (int i = 0; i < n; i++) {
		full.set(i);
	}
	while (!q.empty()) {
		int centre, lef, rig;
		tie(centre, lef, rig) = q.front();
		q.pop();
		int A = lef;
		int B = rig;
		ff.reset();
		if (lca[A][B] == B) {
			swap(A, B);
		}
		if (lca[A][B] == A) {
			ff = child[B] ^ full^child[pat[B][A]] ^ par[B] ^ par[A];
		}
		else {
			ff = child[B] ^ child[A] ^ par[A] ^ par[B];
			ff.set(lca[A][B]);
		}
		ff &= con[A] ^ con[B];
		//the node unconnected to node B
		//connected to A
		//the node is available at the pair(A,B)
		for (int i = (int)ff._Find_first(); i < n; i = (int)ff._Find_next(i)) {
			if (i == A || i == B)continue;
			if (con[B].test(i)) {
				swap(A, B);
			}
			q.push(make_tuple(A, i, B));
			con[i].set(B);
			con[B].set(i);
			edd++;
		}
	}
	cout << edd << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  double A[N],c;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    c += 1/A[i];
  }
  c = 1/c;
  cout <<std::fixed << c << endl;
}  

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    DMP(a);
    
    int ans = INF;
    for(int i = 0; i < N; i++){
    	
        int tmp = 0;
        while(a[i]){
        DMP(a[i],!(ans&1));
        	if(!(a[i]&1)) tmp++;
            else break;
        	a[i] >>= 1;
        }
        ans = min(ans, tmp);
    }
    
    cout << ans << "\n";

	return 0;
}


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

int main() {
    int k,n,ans=0;
    cin>>k>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    a.push_back(a.at(0)+k);
    for (int i=1; i<n+1; i++) {
        ans=max(ans,a.at(i)-a.at(i-1));
    }
    cout<<k-ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
struct node{
	int pos,num;
	bool operator<(const node& a)const{
		return num<a.num;
	}
};
struct node1{
	int pos,num;
	bool operator<(const node1& a)const{
		return pos<a.pos;
	}
};
char s[maxn];
bool vis[maxn]={0};
node p[maxn]={0},p1[maxn]={0};
node1 p2[maxn]={0};
ll ans[maxn]={0};
ll sum[maxn]={0};
int k[100];
int main()
{
	int n;
	scanf("%d %s",&n,s+1);
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d",&k[i]);
	}
	int num=0;
	int now1=0,now2=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='M')num++;
		else if(s[i]=='D'){
			p1[++now1].pos=i;
			p1[now1].num=num;
		}
		else if(s[i]=='C'){
			p[++now2].pos=i;
			p[now2].num=num;
			p2[now2].pos=i;
			p2[now2].num=num;
		}
	}
	for(int i=1;i<=now2;i++){
		sum[i]=sum[i-1]+p[i].num;
	}
	for(int j=1;j<=q;j++)
	{
		ll sum1=0;
	for(int i=1;i<=now1;i++){
		node aa;
		node1 bb;
		aa.num=p1[i].num+1;
		bb.pos=p1[i].pos+k[j];
		int x=lower_bound(p+1,p+now2+1,aa)-p;
		int y=lower_bound(p2+1,p2+now2+1,bb)-p2;
		y--;
		if(x==now2+1)continue;
		sum1+=sum[y]-sum[x-1]-p1[i].num*1ll*(y-x+1);
	}
	ans[j]=sum1;
}
	for(int i=1;i<=q;i++){
		printf("%lld\n",ans[i]);
	}
}

Measured memory_bytes: 28928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();

		int kakaku = 700;
		for (int i = 0; i < 3; i++) {
			if (S.charAt(i) == 'o') {
				kakaku+=100;
			}
		}
		System.out.println(kakaku);
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll n;
  cin >> n;
  cout << n / 2 * ((n + 1) / 2) << endl;
 
  return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
cards = gets.split.map(&:to_i).sort
insts = m.times.map { gets.split.map(&:to_i) }

insts = insts.sort_by(&:last).reverse

lambda do
  i = 0
  insts.each do |b, c|
    ulimit = [i + b - 1, cards.size-1].min
    i.upto(ulimit) do |j|
      if cards[j] >= c
        return
      else
        cards[j] = c
      end
    end
    i += b
  end
end.()

puts cards.inject(:+)


Measured memory_bytes: 21024
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int main()
{
	cin >> s;
	int snum = 0, tnum = 0;
	int ans = s.size();
	int i = 0;
	int tag = 0;
	while (i < s.size())
	{
		if (s[i] == 'S') {
			while (s[i] == 'S' && i < s.size()) {
				snum++; i++;
			}
			while (s[i] == 'T' && i < s.size()) {
				tnum++; i++;
			}
			if (tnum >= snum) {//s用完
				ans -= snum * 2;
				snum = tnum = 0;
			}
			else {//s没用完，留给下一次
				ans -= tnum * 2;
				snum -= tnum;
				tnum = 0;
			}
		}
		else i++;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 640
/**
*    author:  yuya1234
*    created: 10.07.2020 16:47:23
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int n;
  cin>>n;

  int x[n],xx[n];
  REP(i,n){
    cin>>x[i];
    xx[i]=x[i];
  }

  sort(xx,xx+n);
  int c1,c2;
  c1=xx[(n/2)-1];
  c2=xx[n/2];

  REP(i,n)
  {
    if(c1>=x[i])cout<<c2<<endl;
    else cout<<c1<<endl;
  }

  return 0;
}

Measured memory_bytes: 5064
use std::io::*;
use std::str::FromStr;
use std::cmp::min;
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let a:i32 = read();
    let b:i32 = read();
    let c:i32 = read();
    let d:i32 = read();
    println!("{}",min(a,b)+min(c,d));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
unordered_map<char , int> mp ;
const int N = 40010 ;
int a[4][N] ;
int main()
{
  int n ;
  string s ;
  cin >> n >> s ;
  mp['R'] = 1 , mp['G'] = 2 , mp['B'] = 3 ;
  s = " " + s ;
  for(int i = 1 ; i <= n ;i ++)
    {
      for(int j = 1; j <= 3 ;j ++)
       a[j][i] = a[j][i - 1] ;
      a[mp[s[i]]][i] ++ ;
    }
  long long cnt = 0;
  for(int i = 1; i <= n ;i ++)
   {
     for(int j = i + 1; j <= n ;j ++)
      {
        if(s[i] == s[j]) continue ;
        int x = 6 - mp[s[i]] - mp[s[j]] ;

        cnt += a[x][n] - a[x][j] ;
        if(2 * j - i <= n)
         cnt -= (mp[s[2 * j - i]] == x) ;
      }
   }
   cout << cnt << endl ;
  return 0 ;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int m;cin>>m;
    cout<<24-m+24<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<climits>
#include<queue>

using namespace std;

int main(void){
    int N;
    cin >> N;
    cout << N * (N - 1) / 2 - N / 2 << endl;
    for(int i = 1; i <= N; i++){
        for(int j = i + 1; j <= N; j++){
            if(i + j != N + (N % 2 == 0)) cout << i << " " << j << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
typedef pair<int, int> par;

struct {
	inline operator int() {
		int x;
		return scanf("%lld", &x), x;
	}
	inline operator ll() {
		ll x;
		return scanf("%lld", &x), x;
	}
	template<class T> inline void operator ()(T &x) {
		x = *this;
	}
	template<class T, class ...A >inline void operator () (T &x, A &...a) {
		x = *this;
		this->operator ()(a...);
	}
} read;

const int MAXN = 2e5 + 5, P = 1e9 + 7;
int l[MAXN], r[MAXN];
int p[MAXN];
int tmp[MAXN];
par pr[MAXN];
ll f[MAXN], s[MAXN];

int main() {
	int n = read;
	for(int i = 1; i <= n; ++i) {
		read(pr[i].second, pr[i].first);
	}
	std::sort(pr + 1, pr + n + 1);
	for(int i = 1; i <= n; ++i) {
		tmp[i] = pr[i].second;
	}
	std::sort(tmp + 1, tmp + n + 1);
	for(int i = 1; i <= n; ++i) {
		pr[i].second = int(std::lower_bound(tmp + 1, tmp + n + 1, pr[i].second) - tmp);
		p[pr[i].second] = i;
	}
	for(int i = 1; i <= n; ++i) {
		r[i] = std::max(r[i - 1], p[i]);
	}
	l[n] = p[n];
	for(int i = n - 1; i; --i) {
		l[i] = std::min(l[i + 1], p[i]);
	}
	int L = 0;
	f[0] = s[0] = 1;
	for(int i = 1; i <= n; ++i) {
		while(r[L] < l[i] - 1) {
			++L;
		}
		f[i] = (s[i - 1] - s[L - 1] + P) % P;
		s[i] = (s[i - 1] + f[i]) % P;
	}
	while(r[L] < n) {
		++L;
	}
	printf("%lld\n", (s[n] - s[L - 1] + P) % P);
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(int key,int value){
  return value >= key;
}

int binary_search(vector<int> a,int key){
  int ok = a.size();
  int ng = -1;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<ll> a(n);rep(i,n)cin>>a[i];
  vector<ll> sums(n);
  ll sum = SUM(a);

  sums[0] = a[0];
  for(int i = 1;i < a.size();++i){
    sums[i] = sums[i-1] + a[i];
  }
  ll ans = 0;
  ll sumh = sum/2+sum%2;
  ll mini = 1000000000000000000;
  rep(i,sums.size()){
    mini = min(abs(abs(sums[sums.size()-1] - sums[i]) - abs(sums[i])),mini);
  }
  ans = mini;
  print(abs(ans));
  return 0;
} 


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main()
{
    int n, r;
    cin >> n >> r;
    if (n >= 10)
        cout << r;
    else
        cout << r + (100 * (10 - n));
    return 0;
}


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


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

  int n, k, x, y;
  std::cin >> n >> k >> x >> y;
  std::cout << (n > k ? (x * k + (n - k) * y) : (x * n)) << std::endl;

  return EXIT_SUCCESS;
}


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

void prime();
bool num[10001];

int main(){
	int m, count;
	prime();
	while(cin >> m){
		count = 0;
		for(int i = 1; i <= m; i++){
			if(num[i] && num[m - i + 1]){
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

void prime(){
	vector<int> p;
	for(int i = 0; i < 10001; i++){
		num[i] = true;
    	}
    	num[0] = false;
    	num[1] = false;
	for(int i = 2; i <= 100; i++){
        	for(int j = i*2; j <= 10001; j += i){
            		if(!num[j]){
                		continue;
            		}
            		num[j] = false;
        	}
    	}
}

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

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

 int count = 0;
 int x = 1;

 while((x+k) > x*2){
  x *= 2;
  count++;
  if(count == n){
    cout << x;
    return 0;
  }
}

  while(count < n){
    x += k;
    count++;
  }
  cout << x <<endl;
  

 }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int a,b;
string s,m,n;
int main(){
	cin>>s;
	m='C';
	n='F';
	a=s.find(m);
	if(a!=string::npos)b=s.find(n,a+1);
	else {cout<<"No"<<endl;return 0;}
	if(a!=string::npos&&b!=string::npos)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
    return 0;
}

Measured memory_bytes: 256
solver::Int -> Int -> Int
solver n m = if not((n==m)||(n==m+1)||(n+1==m)) then 0 else
                      if n==m then red_prd [(red_fuc n),(red_fuc n),2]
                              else red_prd [(red_fuc m),(red_fuc n)]

red_fuc::Int -> Int
red_fuc 1 = 1
red_fuc n = let n_ = mod n 1000000007  in mod (red_fuc (n-1) * n_)  1000000007

red_prd::[Int] -> Int
red_prd []=1
red_prd (x:xs)= let x_ = mod x 1000000007 in mod ((red_prd xs) * x_) 1000000007

main::IO()
main=do
  d<-getLine
  let n:m:[]=map read (words d)
  print (solver n m)


Measured memory_bytes: 3068
/*input
8 3
ACACTACG
3 7
2 3
1 8
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
vector<int> v;
int main()
{
	IOS;
	int n,q;
	string s;
	cin>>n>>q>>s;
	REP(i,n-1) if(s[i]=='A'&&s[i+1]=='C'){
		v.pb(i);
	}
	while(q--){
		int l,r;
		cin>>l>>r;
		l--;r--;
		cout<<lower_bound(ALL(v),r)-lower_bound(ALL(v),l)<<'\n';
	}
	return 0;
}


Measured memory_bytes: 1228
fun main(args: Array<String>) {
    val (w,h,x,y) = readLine()!!.split(" ").map { it.toDouble() }
    val isHalf = w / x == 2.0 && h / y == 2.0
    val area = w * h / 2

    println(area.toString() + " " + if (isHalf) 1 else 0)
}


Measured memory_bytes: 37924
#include<stdio.h>

int main(void)
{
 	int S, h, m, s;
 
	scanf("%d", &S);
	
	h=S/3600;
	m=(S%3600)/60;
	s=(S%3600)%60;

	printf("%d:%d:%d\n", h,m,s);
	
	
   return 0;
   
}

Measured memory_bytes: 2756
#include<stdio.h>
int n,k,q,a,i,p[100000]={};
int main(){
    scanf("%d%d%d",&n,&k,&q);
    for(i=0;i<q;i++){
        scanf("%d",&a);
        p[a-1]++;
    }
    for(i=0;i<n;i++){
        if(k-q+p[i]>0)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template

int n,a[30],b[30],c[30],sum;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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

    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<n;i++)cin>>c[i];

    for(int i=1;i<=n;i++){
        sum += b[a[i]];
        if(a[i-1] == a[i] - 1) sum+= c[a[i-1]];
    }
    cout<<sum<<newl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
 
parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

res = 1000000000 + 7

main = do
  n <- readInt
  p <- readIntList
  q <- readIntList
  let p_rank = calc n p
      q_rank = calc n q
  print $ abs (p_rank - q_rank)

calc n (x:xs) = let rank = foldl' (\acc val -> if val < x then acc + 1 else acc) 0 xs in rank * fact (n - 1) + calc (n - 1) xs
calc n [] = 0

fact 0 = 1
fact !n = n * fact (n - 1)


Measured memory_bytes: 380
n=int(input())
a=list(map(int,input().split()))
aa=sum(a)-a[0]
tmp=a[0]
t=abs(tmp-aa)
ans=float("inf")
if ans>t:
    ans=t
for i in range(1,n-1):
    tmp+=a[i]
    aa-=a[i]
    t=abs(tmp-aa)
    if ans>t:
        ans=t
print(ans)

Measured memory_bytes: 30612
#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
	
	ios_base :: sync_with_stdio(0); cin.tie(NULL);
 
	string s; 
	cin >> s;

	int Q; 
	cin >> Q;

	int start = 0;

	deque <char> begin, last;

	while(Q--) {
		int T; 
		cin >> T;

		if(T == 1) { // reverse
			if (start == 1) {
				start = 0;
			}
			else start = 1;
		}
		else {
			int F; char C;
			cin >> F >> C;

			if (F == 1) { //add begin
				if (start == 0) {
					begin.push_front(C);
				}
				else {
					last.push_back(C);
				}
			}
			else { // add end
				if (start == 0) {
					last.push_back(C);
				}
				else {
					begin.push_front(C);
				}
			}
		}
	}

	if(start == 1) {

		for(int i = last.size() - 1; i >= 0; --i) {
			cout << last[i];
		}

		reverse(s.begin(), s.end());

		cout << s;

		for(int i = begin.size() - 1; i >= 0; --i) {
			cout << begin[i];
		}

	}
	else {
		
		for(int i = 0; i < begin.size(); ++i)
			cout << begin[i];

		cout << s;

		for(int i = 0; i < last.size(); ++i)
			cout << last[i];

	}

	
	cout << '\n';
 
	return 0;	
}

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

int main(void)
{
	int n;
	int a[103];
	while(cin >> n && n != 0)
	{
		int i;
		int max = -1, min = 1003;
		for(i = 0; i < n; ++i)
		{
			cin >> a[i];
			if(a[i] > max)
				max = a[i];
			if(a[i] < min)
				min = a[i];
		}
		cout << max-min << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
D = list(map(int,input().split()))
BIGNUM = 998244353

ans = 1
# 距離:頂点に対応する辞書
if D[0] != 0:
    ans = 0
distance_dict = {0:1}
for i in D[1:]:
    if not i in distance_dict:
        distance_dict[i] = 1
    else:
        distance_dict[i] += 1

#dist_list = list((distance_dict.keys())) # 0~N-1 一つでもとんでったらアウト。距離がない
#print(distance_dict)

if distance_dict[0] != 1:
    print(0)
    exit()

for i in range(1,max(distance_dict.keys())+1):
    if not i in distance_dict: # 一つでもとんでったらアウト。距離がない。連結できない
        ans = 0
        print(0)
        exit()

    elif i != 0:
        ans *= (distance_dict[i-1]**distance_dict[i]) # どこにつながるかの候補とつながる点の数
print(ans%BIGNUM)

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

int main() {
    int n;
    cin >> n;
    vector<int> p1(n);
    rep(i, n) cin >> p1[i];
    vector<int> p2(n);
    copy(p1.begin(), p1.end(), p2.begin());
    sort(p1.begin(), p1.end());

    int diff = 0;
    rep(i, n) {
        if (p1[i] != p2[i]) diff++;
    }

    if (diff <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
ac=Counter(a)
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  ans=ans+(c-b)*ac[b]
  ac[c]+=(ac[b])
  ac[b]=0
  print(ans)
  
  



Measured memory_bytes: 87736
#coding:utf-8
n = int(input())
T,A = list(map(int,input().split()))
ls_H = list(map(int,input().split()))
diff_min = 1e+8
for i,H in enumerate(ls_H):
    diff = abs((T - H  * 0.006) - A)
    if diff < diff_min:
        diff_min = diff
        ans = i
print (int(ans+1))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	ll minR = INF;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) minR = i;
	}
	cout << (int)log10(max(minR,n / minR)) + 1 << endl;
}


Measured memory_bytes: 256
N,M,K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())

sa = [0]
for i, val in enumerate(A):
  sa.append(sa[i] + val)

sb = [0]
for i, val in enumerate(B):
  sb.append(sb[i] + val)

max_num = 0
ind_max = M
for i in range(N+1):
  if(sa[i]>K):
    break
  c = 0
  for k in range(ind_max+1):
    if(sb[ind_max-k]<=K-sa[i]):
      break
    c += 1
  ind_max -= c
  max_num = max(max_num,i+ind_max)

      
      
print(max_num)

Measured memory_bytes: 110816
# 久々の幅優先探索……

import queue

def main():

    n = int(input())
    edges = [list(map(int, input().split())) for _ in range(n-1)]
    num_0_mod_3 = n // 3
    num_2_mod_3 = (n+1) // 3
    num_1_mod_3 = (n+2) // 3


    def add_edge(u, v ):
        G[u].append(v)
        G[v].append(u)

    G = [[] for _ in range(n)] #グラフの隣接リスト表現
    for edge in edges:
        add_edge(edge[0]-1, edge[1]-1)

    num_distance_even = 0
    num_distance_odd = 0

    q = queue.Queue()
    q.put(0)

    distance = [-1] * n
    distance[0] = 0
    num_distance_even += 1

    for v in G[0]:
        q.put(v)

    while(q.qsize() > 0):
        now = q.get()
        for v in G[now]:
            if distance[v] >= 0:
                pass
            else:
                q.put(v)
                distance[v] = distance[now] + 1
                if (distance[v] & 1):
                    num_distance_odd += 1
                else:
                    num_distance_even += 1

    # print(distance)
    # print(num_distance_even, num_distance_odd)

    ans = [-1] * n

    index_one = 1
    index_two = 2
    index_zero = 3

    if num_distance_even >= num_1_mod_3 + num_2_mod_3:
        # evenに120 oddに0

        for i in range(n):
            if (distance[i] & 1) == 1:
                ans[i] = index_zero
                index_zero += 3
            else:
                if (index_one <= n):
                    ans[i] = index_one
                    index_one += 3
                elif (index_two <= n):
                    ans[i] = index_two
                    index_two += 3
                else:
                    ans[i] = index_zero
                    index_zero += 3


    elif num_distance_odd >= num_1_mod_3 + num_2_mod_3:
        # evenに0 oddに012
        for i in range(n):
            if (distance[i] & 1) == 0:
                ans[i] = index_zero
                index_zero += 3
            else:
                if (index_one <= n):
                    ans[i] = index_one
                    index_one += 3
                elif (index_two <= n):
                    ans[i] = index_two
                    index_two += 3
                else:
                    ans[i] = index_zero
                    index_zero += 3

    else:
    #     num_distance_even <= num_distance_odd * 2 and num_distance_odd <= num_distance_even * 2:
        # evenを2、oddを1、適宜0
        for i in range(n):
            if (distance[i] & 1) == 1:
                if (index_one <= n):
                    ans[i] = index_one
                    index_one += 3
                else:
                    ans[i] = index_zero
                    index_zero += 3
            else:
                if (index_two <= n):
                    ans[i] = index_two
                    index_two += 3
                else:
                    ans[i] = index_zero
                    index_zero += 3

    print(' '.join(list(map(str, ans))))


if __name__ == '__main__':
    main()

Measured memory_bytes: 127512
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  long long k; cin >> k;
  long long si = s.size();
  for(int i=0;i<min(si, k);i++){
    if(s[i]!='1'){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}

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

int main()
{
    ll k;
    cin>>k;
    ll seven=0;
    for(int i=1; i<=1000000; i++)
    {

        seven*=10;
        seven+=7;
        seven%=k;
        if(seven==0)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>

// helpful functions
#define fl(i,n) for(long long i = 0; i < n; i++)
#define fls(i,a,b) for(long long i = a; i <= b; i ++)
#define afl(i,a,n) int a[n]; for(int i = 0; i < n; i++) scanf("%d", &ar[i])

// printers
#define iprint(x) printf("%d\n", x)
#define lprint(x) printf("%lld\n", x)
#define fprint(x,n) printf("%.nf\n", x)
#define dprint(x,n) printf("%.nlf\n", x)
#define sprint(x) printf("%s\n", x)

// scanners
#define iscan(x) scanf("%d", &x)
#define lcan(x) scanf("%lld", &x)
#define fscan(x) scanf("%f", &x)
#define dscan(x) scanf("%lf", &x)
#define scan(x) scanf("%s", x)
#define qs(x) long long x; scanf("%lld", &x)

int main()
{
	qs(odd); qs(even);
	iprint(odd*(odd-1)/2 + even*(even-1)/2);
	return 0;
}

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

namespace abc_048_C
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long ans1 = 0;
            /* long ans2 = 0;
             long ans3 = 0;
             long ans4 = 0;
             */
            long[] a1 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            /* long[] a2 = new long[a1.Length];
             long[] a3 = new long[a1.Length];
             long[] a4 = new long[a1.Length];
             
            for (int i = 0; i < a1.Length; i++)
            {
                a2[i] = a3[i] = a4[i] = a1[i];
            }*/
            for (long i = 1; i < n[0]; i++)
            {
                if (a1[i] + a1[i - 1] > n[1])
                {
                    ans1 += a1[i] + a1[i - 1] - n[1];
                    a1[i] = n[1] - a1[i - 1];
                    a1[i] = Math.Max(0, a1[i]);
                }
                /* 
                   if (a3[i] + a3[i - 1] > n[1])
                   {
                       ans3 += a3[i] + a3[i - 1] - n[1];
                       a3[i - 1] = n[1] - a3[i];
                   }
               */
            }
            /*
            for (long i = n[0] - 2; i >= 0; i--)
            {
                if (a2[i] + a2[i + 1] > n[1])
                {
                    ans2 += a2[i] + a2[i + 1] - n[1];
                    a2[i + 1] = n[1] - a2[i];
                }
                if (a4[i] + a4[i + 1] > n[1])
                {
                    ans4 += a4[i] + a4[i + 1] - n[1];
                    a4[i] = n[1] - a4[i + 1];
                }
            }*/
            Console.WriteLine(ans1);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 31452
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline void rd(int &x)
{
	x=0;char k=getchar();int s=1;
	while(k>'9'||k<'0'){if(k=='-')s=-1;k=getchar();}
	while(k<='9'&&k>='0')x=x*10+k-48,k=getchar();x*=s;
}
const int N=1e5;
int fir[N],nxt[N],to[N];
int cnt,x,y,du[N],n,c[N],ans[N],tot,vis[N];
struct d{int x,y;friend bool operator < (d a,d b){if(a.y!=b.y)return a.y<b.y;else return a.x<b.x;}};
void add(int u,int v)
{
	to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;
}
multiset<d>s;
int dfs(int x,int fo)
{
	int ret=0;
	for(int i=fir[x];i;i=nxt[i])
	{
		if(to[i]==fo)continue;
		ret+=dfs(to[i],x);
		ret+=min(ans[to[i]],ans[x]);
	}return ret;
}
int main()
{
	rd(n);
	for(int i=1;i<n;i++)
	{
		rd(x),rd(y),du[x]++,du[y]++,add(x,y),add(y,x);
	}
	for(int i=1;i<=n;i++)s.insert((d){i,du[i]});
	for(int i=1;i<=n;i++)rd(c[i]);sort(c+1,c+n+1);//cout<<s.size()<<endl;
	while(s.size())
	{//cout<<s.size()<<endl;
		d x=*s.begin();int k=x.x;//cout<<k<<" "<<x.y<<endl;
		ans[k]=c[++tot];vis[k]=1;s.erase(*s.lower_bound(x));//cout<<s.size()<<endl;
		for(int i=fir[k];i;i=nxt[i])
		if(!vis[to[i]])
		{
			s.erase(*s.lower_bound((d){to[i],du[to[i]]}));
			s.insert((d){to[i],du[to[i]]-1});du[to[i]]--;//cout<<s.size()<<endl;
		}
	}
	printf("%d\n",dfs(1,-1));
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 1792