akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
int main() {
	int n, m;
	cin >> n >> m;
	P p[8];
	int s, c;
	for (int i = 0; i < m; i++) {
		cin >> s >> c;
		p[i] = make_pair(s, c);
	}
	sort(p, p + m);
	vector<int>d;
	for (int i = 0; i < 1000; i++) {
		int keta = 1;
		d.push_back(i % 10);
		int ni = i / 10;
		while (ni) {
			keta++;
			d.push_back(ni % 10);
			ni /= 10;
		}
		if (keta != n) {
			continue;
		}
		reverse(d.begin(), d.end());
		int flag = 0;
		for (int j = 0; j < m; j++) {
			if (d[p[j].first - 1] != p[j].second){
				flag = 1;
				}
		}
		if (flag == 0) {
			cout << i << endl;
			return 0;
		}

	}
	cout << "-1" << endl;
	return 0;
}


Measured memory_bytes: 256
from typing import List, Dict

INF = 10**9+1


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> int:
    H, W = read_ints()
    S: List[str] = []
    for _ in range(H):
        S.append(input().strip())
    black_count = [[INF for _ in range(W)] for _ in range(H)]
    if S[0][0] == '.':
        black_count[0][0] = 0
    else:
        black_count[0][0] = 1

    for i in range(H):
        for j in range(W):
            if i == 0 and j == 0:
                continue
            if S[i][j] == '.':
                if i > 0:
                    black_count[i][j] = min(black_count[i][j], black_count[i-1][j])
                if j > 0:
                    black_count[i][j] = min(black_count[i][j], black_count[i][j-1])
            else:
                if i > 0:
                    if S[i-1][j] == '.':
                        black_count[i][j] = min(black_count[i][j], black_count[i-1][j]+1)
                    else:
                        black_count[i][j] = min(black_count[i][j], black_count[i-1][j])
                if j > 0:
                    if S[i][j-1] == '.':
                        black_count[i][j] = min(black_count[i][j], black_count[i][j-1]+1)
                    else:
                        black_count[i][j] = min(black_count[i][j], black_count[i][j-1])
    return black_count[H-1][W-1]


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 76248
from functools import reduce

n, x = [int(y) for y in input().split()]
xs = [int(y) for y in input().split()]

xs = {abs(y-x) for y in xs}

def gcd(a,b):
    while b!=0:
        a,b = b, a%b
    return a

print(reduce(gcd, xs))

Measured memory_bytes: 17156
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

	void solve(Scanner sc) {
		String S = sc.next();
		String ms = "";
		int len = S.length();
		int ans = 0;

		if (len % 2 == 0) {
			ms = S.substring(0, len - 2);
		} else {
			ms = S.substring(0, len - 1);
		}

		if (ms.length() == 2) {
			System.out.println("2");
			return;
		}

		for (int i = ms.length(); i > 1; i-=2) {

			if(ms.substring(0, i/2).equals(ms.substring(i/2,i))) {
				ans = i;
				break;
			}
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 22740
mod = 10**9 +7
n, a, b = map(int, input().split())

nb = str(bin(n))[2:]
nblis = []
for k in range(len(nb)):
  if nb[-k-1] == '1':
    nblis.append(k)

two = [2]
for k in range(len(nb)-1):
  two.append(two[-1]*two[-1]%mod)


ans = 1
for item in nblis:
  ans = ans * two[item] %mod



bi = str(bin(mod-2))[2:]
blis = []
for k in range(len(bi)):
  if bi[-k-1] == '1':
    blis.append(k)


def modinv(N):
  if N == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(len(bi)):
      li.append(N%mod)
      N = N*N%mod
    for item in blis:
      res = res * li[item] %mod
    return res

ans_a = 1
for k in range(n-a+1, n+1):
  ans_a = ans_a*k%mod
for k in range(2, a+1):
  ans_a = ans_a*modinv(k)%mod


ans_b = 1
for k in range(n-b+1, n+1):
  ans_b = ans_b*k%mod
for k in range(2, b+1):
  ans_b = ans_b*modinv(k)%mod

print((ans-ans_a-ans_b-1)%mod)

Measured memory_bytes: 73708
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int D; cin >> D;
  vector<int> C(26);
  for(int i = 0; i < 26; i++){
    cin >> C[i];
  }

  vector<vector<int>> S(D, vector<int>(26));
  for(int i = 0; i < D; i++){
    for(int j = 0; j < 26; j++){
      cin >> S[i][j];
    }
  }

  for(int i = 0; i < D; i++){
    int ans = -1, Max = -1;
    for(int k = 0; k < 26; k++){
      if(Max < S[i][k]){
        Max = S[i][k];
        ans = k;
      }
    }
    cout << ans + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    ll diff = abs(a - b);

    ll speed_diff = v - w;
    if (speed_diff < 0) {
        cout << "NO" << endl;
        ret();
    }

    bool ok = speed_diff * t >= diff;

    cout << (ok ? "YES" : "NO") << endl;


}


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

using namespace std;
using ll = long long;

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

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

  for (int i = 0;; i++) {
    if (find(p.begin(), p.end(), x - i) == p.end()) {
      cout << x - i << endl;
      return 0;
    }
    if (find(p.begin(), p.end(), x + i) == p.end()) {
      cout << x + i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=a;i--)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define de(x) cout << #x << "=" << x << endl
#define dd(x) cout << #x << "=" << x << " "
#define pw(x) (1ll<<(x))
#define pq priority_queue
#define endl "\n"
const ll maxn=1e5+100;
const ll maxx=1e18;
ll a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans=1,flag=0;
    for(int i=0;i<n;i++){
    	cin >> a[i];
    	if(a[i]==0) flag=1;
	}
	if(flag==1){
		cout <<"0";
		return 0;
	}
	for(int i=0;i<n;i++){
		if(maxx/a[i]<ans){
			cout << "-1";
			return 0;
		}
		ans*=a[i];
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4392
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}




int main() {
	int N; cin >> N;
	int sum = 0;
	int count = 0;
	vector<int> an(N+1),bn(N+1),cn;
	for (int i = 1; i < N+1; i++) {
		cin >> an[i];
	}

	for (int i = N; i > 0; i--) {

		sum = 0;
		for (int j = 1; j * i <= N; j++) {
			sum += bn[i * j];
		}
		if (sum % 2 != an[i]) {
			bn[i] = 1;
			cn.push_back(i);
			count++;
		}

	}

	if (count == 0) cout << 0 << endl;
	else {
		cout << count << endl;
		printVec(cn);
	}


	return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int A,B,M,a[100000],b[100000],xx,yy,c;
	int ans=200000,mx=100000,my=100000;
	cin>>A>>B>>M;
	for(int i=0;i<A;i++){
		cin>>a[i];
		mx=min(a[i],mx);
	}
	for(int i=0;i<B;i++){
		cin>>b[i];
		my=min(b[i],my);
	}
	for(int i=0;i<M;i++){
		cin>>xx>>yy>>c;xx--;yy--;
		ans=min(a[xx]+b[yy]-c,ans);
	}
	ans=min(ans,mx+my);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
import math

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

ans_P = 0
for i in range(N):
    P_sort = sorted(P)
    a = P_sort.index(P[0])
    n = math.factorial(N-1-i)*a
    ans_P += n
    del P[0]

ans_Q = 0
for i in range(N):
    Q_sort = sorted(Q)
    a = Q_sort.index(Q[0])
    n = math.factorial(N-1-i)*a
    ans_Q += n
    del Q[0]

print(abs(ans_Q - ans_P))

Measured memory_bytes: 3064
N, M = tuple(map(int, input().split()))
if N == 1 and M == 1:
    print(1)
    exit()

if N == 1:
    print(M - 2)
    exit()
if M == 1:
    print(N - 2)
    exit()

print((M - 2) * (N - 2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=1e5+5;
struct node{
	int id,val;
	bool operator <(const node &b) const{
		if(val==b.val) return id<b.id;
		return val<b.val;
	}
}b[N],d[N];
int n,p[N],tot,tr[N];
void upt(int x){
	while(x<=n) tr[x]++,x+=(x&-x);
}
int query(int x){
	int res=0;
	while(x) res+=tr[x],x-=(x&-x);
	return res;
}
ll calc(int *a){
	memset(tr,0,sizeof(tr));
	ll ans=0;
	for(int i=1;i<=n;++i)
		b[i].id=i,b[i].val=a[i];
	sort(b+1,b+n+1);tot=1;
	p[b[1].id]=1;
	for(int i=2;i<=n;++i)
		if(b[i].val==b[i-1].val) p[b[i].id]=tot;
		else p[b[i].id]=++tot;
	for(int i=n;i>=1;--i){
		ans+=query(p[i]-1);
		upt(p[i]);
	}
	return ans;
}
int a[N],c[N],pos[N];
signed main(){
//	freopen("in06.txt","r",stdin);
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read(),b[i].id=i,b[i].val=a[i];
	for(int i=1;i<=n;++i)
		c[i]=read(),d[i].id=i,d[i].val=c[i];
	sort(b+1,b+n+1);
	sort(d+1,d+n+1);
	for(int i=1;i<=n;++i)
		if(b[i].val>d[i].val) return puts("No"),0;
//	for(int i=1;i<=n;++i,putchar(' '))
//		cout<<b[i].id;puts("");
//	for(int i=1;i<=n;++i,putchar(' '))
//		cout<<d[i].id;puts("");
	for(int i=1;i<=n;++i)
		p[b[i].id]=d[i].id;
//	for(int i=1;i<=n;++i)
//		cout<<p[i]<<" ";cout<<endl;
	int tot=0;
	for(int i=1;i<=n;++i)
		pos[p[i]]=i;
	for(int i=n;i>=1;--i){
		if(p[i]!=i){
			int tmp=pos[i];
			//cout<<p[pos[i]]<<" "<<p[i]<<endl;
			swap(p[pos[i]],p[i]);
			pos[p[pos[i]]]=tmp;
			++tot;
		}
	}
//	cout<<tot<<endl;
	if(tot<=n-2) puts("Yes");
	else{
		for(int i=1;i<n;++i)
			if(b[i+1].val<=d[i].val) return puts("Yes"),0;
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 9832
# https://atcoder.jp/contests/abc104/tasks/abc104_c

from itertools import product
from itertools import compress


D, G = map(int, input().split())
data = []
for _ in range(D):
    data.append(tuple(map(int, input().split())))

res = []
for bit in product(*((0,1),)*D):
    S = 0
    cnt = 0
    for i, a in enumerate(data):
        p, c = a
        S += (100*(i+1)*p + c)*(bit[i]==0)
        cnt += p*(bit[i]==0)
    if S >= G:
        res.append(cnt)
    else:
        for i, d in enumerate(reversed(bit)):
            if d:
                break
        for k in range(1,data[D-i-1][0]+1):
            cnt += 1
            if S + 100*(D-i)*k >= G:
                res.append(cnt)
                break


print(min(res))

Measured memory_bytes: 74096
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
 int x,y,a,b,c;
 cin>>x>>y>>a>>b>>c;
 vi p(a),q(b),ans(c);
 rep(i,a)cin>>p[i];
 rep(i,b)cin>>q[i];
 rep(i,c)cin>>ans[i];
 sort(been(p),greater<int>());
 sort(been(q),greater<int>());
 //sort(been(r),greater<int>());
 rep(i,x)ans.push_back(p[i]);
 rep(i,y)ans.push_back(q[i]);
 sort(been(ans),greater<int>());
 ll sum =0;
 rep(i,x+y)sum+=ans[i];
 cout<<sum<<endl;
}

Measured memory_bytes: 2680
#include <iostream>
#include <math.h>

using namespace std;

int main(int argc, const char *argv[]) {
  long long int a, b, c, d;
  cin >> a >> b >> c;

  d = c - a - b;
  if(d > 0 && 4 * a * b < d * d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

int n, m;
bool u[15][1<<15];
pair<int,int> prev[15][1<<15];
vector<pair<int,int> > action;
vector<int> a[15];
vector<int> b[15];

bool wfs(int p0, int l0, bool f) {
  queue<pair<int, int> > q;
  for (int i=0; i<n; i++) {
    for (int j=0; j<(1<<n); j++) {
      u[i][j] = false;
    }
  }
  if (!(l0 & (1<<p0))) return false;
  q.push(make_pair(p0, l0));
  u[p0][l0] = true;

  while (!q.empty()) {
    int l, p, ll, pp;
    p = q.front().first;
    l = q.front().second;
    q.pop();

    if (!f && p == n-1) return true;
    if (f && p == n-1 && (l == (1<<(n-1)))) return true;
    for (int i=0; i<(int)b[p].size(); i++) {
      ll = l ^ (1<<b[p][i]);
      if (!(ll & (1<<p))) continue;
      if (u[p][ll]) continue;
      prev[p][ll].first = p;
      prev[p][ll].second = l;
      u[p][ll] = true;
      q.push(make_pair(p, ll));
    }

    for (int i=0; i<a[p].size(); i++) {
      pp = a[p][i];
      if (!(l & (1<<pp))) continue;
      if (u[pp][l]) continue;
      prev[pp][l].first = p;
      prev[pp][l].second = l;
      u[pp][l] = true;
      q.push(make_pair(pp, l));
    }
  }
  return false;
}

void make_action(int s) {
  int p, l, pp, ll;
  action.clear();
  p = n-1;
  l = (1<<(n-1));
  while (p!=0 || l!=s) {
    pp = prev[p][l].first;
    ll = prev[p][l].second;
    if (p == pp) {
      for (int i=0; i<n; i++) {
        if ((l&(1<<i)) && !(ll&(1<<i))) {
          action.push_back(make_pair(1, i+1));
        } else if (!(l&(1<<i)) && (ll&(1<<i))) {
          action.push_back(make_pair(-1, i+1));
        }
      }
    } else {
      action.push_back(make_pair(0, p+1));
    }
    p = pp;
    l = ll;
  }
  reverse(action.begin(), action.end());
}

int main() {
  int s, t, l;
  while (1) {
    cin >> n >> m;
    if (!n && !m) break;
    l = 0;
    for (int i=0; i<n; i++) {
      a[i].clear();
      b[i].clear();
    }
    for (int i=0; i<m; i++) {
      cin >> s >> t;
      --s;
      --t;
      a[s].push_back(t);
      a[t].push_back(s);
    }
    for (int i=0; i<n; i++) {
      cin >> t;
      if (t) {
        l |= (1<<i);
      }
    }
    for (int i=0; i<n; i++) {
      cin >> s;
      for (int j=0; j<s; j++) {
        cin >> t;
        --t;
        b[i].push_back(t);
      }
    }
    for (int i=0; i<n; i++) {
      sort(b[i].begin(), b[i].end());
    }

    if (wfs(0, l, true)) {
      make_action(l);
      cout << "You can go home in " << action.size() << " steps." << endl;
      for (int i=0; i<(int)action.size(); i++) {
        if (action[i].first == 1) {
          cout << "Switch on room " << action[i].second << "." << endl;
        } else if (action[i].first == -1) {
          cout << "Switch off room " << action[i].second << "." << endl;
        } else {
          cout << "Move to room " << action[i].second << "." << endl;
        }
      }
    } else {
      if (wfs(0, l, false)) {
        cout << "You can not switch off all lights." << endl;
      } else {
        cout << "Help me!" << endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 5612
def prime_decomposition(n):
    ret = set()

    x = n

    divisor = 2
    while x % divisor == 0:
        x //= divisor
        ret.add(divisor)

    divisor = 3
    while divisor * divisor <= n:
        while x % divisor == 0:
            x //= divisor
            ret.add(divisor)
        divisor += 2

    if x > 1:
        ret.add(x)

    return ret


def main():
    from functools import reduce
    from operator import mul

    n, k, s = map(int, input().split())

    pd = prime_decomposition(s)
    if not pd:
        m = s + 1
    else:
        m = reduce(mul, pd) - 1  # 互いに素

    ret = [s] * k + [m] * (n - k)
    print(*ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46364
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main
{
	public static void main(String args[]) throws java.lang.Exception,FileNotFoundException
	{
		Scanner sc = new Scanner(System.in);

		// PrintStream obj = new PrintStream(new File("Output.txt"));
		// System.setOut(obj);

		int N = sc.nextInt();
		int K = sc.nextInt();

		String S = sc.next();

		StringBuffer str = new StringBuffer(S);

		int index = K - 1;

		for(int i = 0;i<N;i++)
		{
			Character c = str.charAt(i);

			if(i == index)
			{
				str.replace(i,i+1,Character.toLowerCase(c)+"");
			}
		}

		System.out.println(str);
		
		sc.close();
		System.out.flush();
	}
}

Measured memory_bytes: 21204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int h = Integer.parseInt(lines[0]);
            int w = Integer.parseInt(lines[1]);
            if (h == 0 && w == 0) {
                break;
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if(i==0||i==h-1||j==0||j==w-1){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 35144
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,k,ans;
signed main(){
	n=read();m=read();k=read();
	ans=n*min(m-1,k)/m;
	printf("%d",ans);
}

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

int main(){
    int N;
    cin >> N;
    bool res = false;
    for(int i=0; i <= 100 ; i += 4){
        for(int j=0; j <= 100; j += 7){
            int total = i + j;
            if(N == total) res = true;
        }
    }
    if(res)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce


D = a_int()
C = ints()
S = read_tuple(D)
T, = read_col(D)  # これをもとにスコアを計算する
T = mina(*T)

last = [-1] * len(C)
scores = [0]
for d in range(D):
    scores.append(scores[-1] + S[d][T[d]])
    last[T[d]] = d
    for i in range(26):
        scores[-1] -= C[i] * (d - last[i])
print(*scores[1:], sep='\n')


Measured memory_bytes: 68704
class PalindromePhilia:
    def calculate(self, list):
        counter = 0
        n = 0
        length =len(list)
        div = length // 2
        for d in range(div):
            if list[d] != list[length - n -1]:
                counter +=1
            n += 1
        return counter

if __name__ == "__main__":
    A = input()
    list_num = [a for a in A]
    pp = PalindromePhilia()
    result = pp.calculate(list_num)
    print(str(result))


Measured memory_bytes: 3060
from collections import deque
f=input
s=deque(f())
n=int(f())
t=0
for i in range(n):
  q=f()
  if q[0]=='1': t=1-t
  elif int(q[2])+t==2: s.append(q[4])
  else: s.appendleft(q[4])
print(''.join([s,list(s)[::-1]][t]))

Measured memory_bytes: 10476
//============================================================================
// Name        : ALDS1_2_D.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int cnt,m;
vector<int> G;

void insertionSort(vector<int>& a, int n, int g) {
	for(int i=g; i<n; ++i) {
		int j,v=a[i];
		for(j=i-g; j>=0 && a[j]>v;j-=g) {
			swap(a[j+g],a[j]);
			++cnt;
		}
		a[j+g]=v;
	}
}

void shellSort(vector<int>& a,int n) {
	cnt = 0;
	m=0;
	int d=n;
	while(1) {
		d=2*d/3;
		if(d<2) {
			G.push_back(1);
			++m;
			break;
		}
		G.push_back(d);
		++m;
	}
	for(int i=0; i<m; ++i) {
		insertionSort(a, n, G[i]);
	}
}

int main() {
	int n;
	vector<int> a;
	cin >> n;
	a.resize(n);
	for(int i=0; i<n; ++i) {
		cin >> a[i];
	}
	shellSort(a,n);
	cout << m << endl;
	for(int i=0; i<m-1; ++i) {
		cout << G[i] << " ";
	}
	cout << G[m-1] << endl;
	cout << cnt << endl;
	for(auto x : a) {
		cout << x << endl;
	}
	return 0;
}

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

public class Main {
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String s = fs.next();
		int a[] = new int[4];
		for(int i=0;i<4;i++) {
			a[i] = s.charAt(i) - '0';
		}

		for(int i=0;i<1<<3;i++) {
			int t = a[0];
			char cs[] = new char[3];
			Arrays.fill(cs,'-');
			for(int j=0;j<3;j++) {
				if((i>>j&1)==1) {
					cs[j] = '+';
					t += a[j+1];
				}				
				else {
					t -= a[j+1];
				}
			}
			if(t==7) {
				System.out.print(a[0]);
				System.out.print(cs[0]);
				System.out.print(a[1]);
				System.out.print(cs[1]);
				System.out.print(a[2]);
				System.out.print(cs[2]);
				System.out.print(a[3]);
				System.out.println("=7");
				return;
			}
		}
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

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

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

Measured memory_bytes: 23252
program main
  implicit none
  
  integer :: i,j,t,n,k,l(50)=0,s=0
  
  read(*,*)n,k
  read(*,*)(l(i),i=1,n)
  
  do i=1,N-1
     do j=i+1,N
        if(l(i) .gt. l(j))then
           t=l(i)
           l(i)=l(j)
           l(j)=t
        end if
     end do
  end do
  
  do i = n, n-k+1, -1
    s = s + l(i)
  end do
  
  write(*,*)s
end program main

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

using Edge = pair<int, int>; // 隣接ノード、コストのペア
using Graph = vector<vector<Edge>>;

int N;
Graph G;

vector<int> ans;

void dfs(int v, int p, int c) { // v: node, p: v's parent, c: color
    ans[v] = c;
    for (auto e: G.at(v)) {
        if (e.first == p) continue; // 親ノードの場合はなにのもしない。
        if (e.second & 1) dfs(e.first, v, 1 - c); // 1の場合は0で塗る。
        else dfs(e.first, v, c);
    }
}


int main(){
    cin >> N;
    G.assign(N, vector<Edge>());
    rep(i, N-1) {
        int a, b, w;
        cin >> a >> b >> w;
        --a; --b;
        G[a].push_back(Edge(b, w));
        G[b].push_back(Edge(a, w));
    }

    ans.assign(N, 0);
    dfs(0, -1, 1);

    rep(i, N) {
        cout << ans[i] << endl;
    }
}

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

using namespace std;

int N, K;
vector<int> h;

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

    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        h.push_back(t);
    }

    long min = 10000000000;

    sort(h.begin(), h.end(), greater<int>());

    for (int i = 0; i < N - K + 1; i++) {
        long tmp = h[i] - h[i + K - 1];
        if (tmp < min) min = tmp;
    }

    cout << min << endl;
    return 0;
}


Measured memory_bytes: 892
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    x = int(input())
    dp = [False] * (100000 + 1)
    dp[0] = True

    for p in [100,101,102,103,104,105]:
        for i in range(100000 + 1):
            if p <= i:
                dp[i] |= dp[i-p]

    print(1 if dp[x] else 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
#include <iostream>
using namespace std;
int main(){
  int n;cin >> n;int a[n],b[n];
  for(int i=0;i<n;i++){
    cin >>a[i];
  }
  for(int i=0;i<n;i++){
    b[a[i]-1]=i+1;
  }
  for(int i=0;i<n;i++){
  cout << b[i] << " ";
  }
  cout <<endl;
}



Measured memory_bytes: 1536
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

void solve (int n)
{
    const ll inf = (ll)1e18;
    vi x(n);
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++)
        cin >> x[i];

    ll ans = 0;
    for (int i = 1; i < n; i++)
    {
        ll cur = min((ll)b, (ll)(x[i] - x[i - 1]) * (ll)a);
        ans += cur;
    }
    cout << ans << '\n';
}

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

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int k = in.nextInt();
    int n = in.nextInt();
    int[] a = new int[n];
    int maxDist = Integer.MIN_VALUE;
    a[0] = in.nextInt();
    for (int i = 1; i < n; ++i) {
      a[i] = in.nextInt();
      int maxDist1 = a[i] - a[i - 1];
      if (maxDist1 > maxDist) {
        maxDist = maxDist1;
      }
    }
    if (k - a[n - 1] + a[0] > maxDist) {
      maxDist = k - a[n - 1] + a[0];
    }
    System.out.println(k - maxDist);
  }
}


Measured memory_bytes: 84604
import itertools
import math

if __name__ == '__main__':

	n = int(input())

	A = []
	for _ in range(n):
		A.append(list(map(int,input().split())))

	p = list(itertools.permutations(A))

	kei = 0
	for x in p:
		for i in range(n-1):
			kei += math.sqrt((x[i+1][0] - x[i][0]) ** 2 + (x[i+1][1] - x[i][1]) ** 2)
	print(kei / len(p))



Measured memory_bytes: 7972
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;
    }

    public static string Solve()
    {
        string S = Read();
        int ans = 0;
        int cnt = 0;
        for(int i=0;i<S.Length;i++)
        {
            for(int j=i;j<S.Length;j++)
            {
                for(int k=i;k<=j;k++)
                {
                    if (IsACGT(S[k]))
                    {
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                }
                ans = Math.Max(ans, cnt);
                cnt = 0;
            }
        }

        return ans.ToString();
    }
    public static bool IsACGT(char c)
    {
        switch (c)
        {
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                return true;
        }
        return false;
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


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

int main(){
  int s1[5],s2[5];

  while(true){
    cin >> s1[0] >> s2[0];
    if(!s1[0]&&!s2[0]) break;

    int max = s1[0] + s2[0],num = 1;
    for(int i = 1 ; i < 5 ; i++){
      cin >> s1[i] >> s2[i];
      if(max < s1[i]+s2[i]){
	max = s1[i] + s2[i];
	num = i + 1;
      }
    }
    switch(num){
    case 1:
      cout << 'A'; break;
    case 2:
      cout << 'B'; break;
    case 3:
      cout << 'C'; break;
    case 4:
      cout << 'D'; break;
    case 5: 
      cout << 'E'; break;
    }
    cout << ' ' << max << endl;

  }

  return 0;
}

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

int main(){
    ll y = 0;
    ll x;
    ll d = 100;
    cin >> x;
    while(d < x) {
        y++;
        d *= 1.01;
    }
    cout << y << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int N;
    cin >> N;
    map<int,int> cards;
    rep(i ,N){
        int A; cin >> A;
        cards[A]++;
    }

    int even = 0;
    for(auto& card : cards) {
        if(card.second > 2) card.second = 1 + ((card.second-3) % 2);
        if(card.second == 2) even++;
    }
    
    int kind = cards.size();
    if(even%2) cout << kind - 1 << endl;
    else cout << kind << endl;
}

Measured memory_bytes: 4992
#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"

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 + 1);
    rep(i, n + 1) cin >> a[i];
    ll ans = 0;
    rep(i, n) {
        ll b;
        cin >> b;
        ll v1 = min(a[i], b);
        ans += v1;
        b -= v1;
        ll v2 = min(a[i + 1], b);
        ans += v2;
        a[i + 1] -= v2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, q;
	cin >> n;
	VI s(n);
	rep(i, n)cin >> s[i];
	cin >> q;
	VI t(q);
	rep(i, q)cin >> t[i];
	SORT(s);
	int cnt = 0;
	rep(i, q) {
		if (binary_search(all(s), t[i]))cnt++;
	}
	cout << cnt << endl;
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}


Measured memory_bytes: 256
mod = 1000000007

N = int(input())

S = input()
S_sub = input()

P = []
now = 0
for i in range(N):
    if i>0 and S[i] != S[i-1]:
        P.append(now)
        now = 0
    now += 1
    
P.append(now)

ans = 3 if P[0]==1 else 6
now = P[0]
for p in P[1:]:
    if now == 1:
        ans = (ans*2)%mod
    elif now == 2:
        if p == 1: ans = (ans*1)%mod
        else: ans = (ans*3)%mod
    now = p
    
print(ans)

Measured memory_bytes: 3064
from itertools import product
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

D,G = map(int,input().split())

pc = [tuple(map(int,input().split())) for _ in range(D)]
pc = [(p,c,100*i) for i,(p,c) in enumerate(pc, start=1)]
res = sum(p for p,c,k in pc)
for choice in product((True,False),repeat=D):
    t = sum(c+p*k for (p,c,k),f in zip(pc,choice) if f)
    steps = sum(p for (p,c,k),f in zip(pc,choice) if f)

    if t >= G:
        res = min2(res,steps)
        continue

    for (p,c,k),f in zip(reversed(pc), reversed(choice)):
        if not f:
            break

    if p*k+t >= G:
        steps += (G-t-1)//k + 1
        res = min2(res,steps)

print(res)


Measured memory_bytes: 9200
import sys
n, y = map(int, input().split())

max10k = y // 10000

for i in range(max10k+1):
    max5k = (y - 10000 * i)//5000
    for j in range(max5k+1):
        if (y - 10000 * i - 5000 * j) // 1000 == n - i - j:
          print(i, j, (n - i - j))
          sys.exit()

print(-1,-1,-1)


Measured memory_bytes: 9112
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  char s[100];
  scanf("%s", s);
  if (s[5] != '1' &&
      (s[6] == '1' || s[6] == '2' || s[6] == '3' || s[6] == '4')) {
    printf("Heisei\n");
  } else {
    printf("TBD\n");
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main() {
	s := nextLine()
	if s[:1] == s[1:2] && s[:1] == s[2:3] {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;

string s;

int main(){
    cin>>s;
    long long sm=0;
    for(int i=0;i<s.size();++i)
        sm+= (int)(s[i]-'0');
    
    if(sm%9 == 0)
        cout<<"Yes";
    else cout<<"No";    
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
int a[510][510];

void dfs(int l, int r, int now){
    if(l+1==r) return;
    int mid = (l+r)/2;
    srep(i,l,mid){
        srep(j,mid,r){
            a[i][j] = now;
        }
    }
    dfs(l,mid,now+1);
    dfs(mid,r,now+1);
}

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

    dfs(0,n,1);
    rep(i,n){
        srep(j,i+1,n) cout << a[i][j] << ' ';
        cout << endl;
    }

    return 0;
}




Measured memory_bytes: 4496
#include<stdio.h>
long long pa[200005],pb[200005],a[200005],b[200005];
int main(){
	int n,m;
	long long k;
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=1;i<=n;i++){scanf("%lld",&a[i]);pa[i]=pa[i-1]+a[i];}
	for(int i=1;i<=m;i++){scanf("%lld",&b[i]);pb[i]=pb[i-1]+b[i];}
	int ans=0;
	for(int i=0;i<=n;i++){
		if(k-pa[i]<0ll) break;
	    k-=pa[i];
		int l=0,r=m;
		while(l<r){
			int mid=(l+r)/2;
			if(pb[mid]<=k) l=mid+1;
			else r=mid;
		}
		if(pb[l]>k) l--;
		if(i+l>ans) ans=i+l;
		k+=pa[i];
	}
	printf("%d",ans);
	return 0;
}

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

typedef long long   ll;
const int N = int(2e5);
ll s[N], t[N];

class querie{
    public:
    ll d;
    int idx;
    ll left_s, left_t;
    ll right_s, right_t;
    
    bool operator <(querie &other){
        return this->d < other.d;
    }
};

querie qu[N];
ll resp[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b, q;
    
    cin >> a >> b >> q;
    
    for(int i = 0 ; i < a ; i++){
        cin >> s[i];
    }
    
    sort(s, s + a);
    
    for(int i = 0 ; i < b ; i++){
        cin >> t[i];
    }
    
    sort(t, t + b);
    
    for(int i = 0 ; i < q ; i++){
        cin >> qu[i].d;
        
        qu[i].idx = i;
    }
    
    sort(qu, qu + q);
    
    int left_s = 0, left_t = 0;
    
    for(int i = 0 ; i < q ; i++){
        while(left_s < a - 1 && s[left_s + 1] <= qu[i].d){
            left_s++;
        }
        
        qu[i].left_s = s[left_s];
        
        while(left_t < b - 1 && t[left_t + 1] <= qu[i].d){
            left_t++;
        }
        
        qu[i].left_t = t[left_t];
        
    }
    
    int right_s = a - 1, right_t = b - 1;
    
    for(int i = q - 1 ; i >= 0 ; i--){
        while(right_s  >= 1 && s[right_s - 1] >= qu[i].d){
            right_s--;
        }
        
        qu[i].right_s = s[right_s];
        
        while(right_t >= 1 && t[right_t - 1] >= qu[i].d){
            right_t--;
        }
        
        qu[i].right_t = t[right_t];
        
    }
    
    for(int i = 0 ; i < q ; i++){
        ll best = 1e18;
        
        best = min(best,
        abs(qu[i].d - qu[i].left_s) + abs(qu[i].left_s - qu[i].left_t));
        best = min(best, 
        abs(qu[i].d - qu[i].left_t) + abs(qu[i].left_t - qu[i].left_s));
        best = min(best,
        abs(qu[i].d - qu[i].left_s) + abs(qu[i].left_s - qu[i].right_t)
        );
        best = min(best,
        abs(qu[i].d - qu[i].right_t) + abs(qu[i].left_s - qu[i].right_t)
        );
        
        best = min(best,
        abs(qu[i].d - qu[i].right_s) + abs(qu[i].right_s - qu[i].left_t));
        best = min(best, 
        abs(qu[i].d - qu[i].left_t) + abs(qu[i].left_t - qu[i].right_s));
        best = min(best,
        abs(qu[i].d - qu[i].right_s) + abs(qu[i].right_s - qu[i].right_t)
        );
        best = min(best,
        abs(qu[i].d - qu[i].right_t) + abs(qu[i].right_t - qu[i].right_s)
        );
        
        resp[qu[i].idx] = best;
        
    }
    
    for(int i = 0 ; i < q ; i++){
        cout << resp[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 11648
//
// Created by tac on 2016/10/27.
//

#include <cstdlib>
#include <iostream>
#include <cmath>

namespace {
int digit(long n) {
    return static_cast<int>(std::floor(std::log10(n)) + 1);
}
}

int main() {
    long a, b;
    while (std::cin >> a >> b) {
        std::cout << digit(a + b) << std::endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3328
var numbers = ''
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function(line) {
  if (numbers === '') {
    numbers = line
  }
  else {
    showAnswer(line)
  }
});

function showAnswer(number) {
  var inputs = numbers.split(' ')
  var a = parseInt(inputs[0])
  var b = parseInt(inputs[1])
  var c = parseInt(inputs[2])
  var number = parseInt(number)
  var rest;

  var max = Math.max(a,b,c)
  switch(max) {
    case a: 
    rest = b + c
    break
    case b: 
    rest = a + c
    break
    case c: 
    rest = a + b
    break
  }

  for(number; number > 0; number--) {
    max *=  2
  }

  console.log(max + rest)
}

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
 
//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 

//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 1000000000000000000;
 
using namespace std;

ll ans;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void find(int n, int x, int left, int y, vector<pair<ll, pair<ll, ll>>> &v, vll &xx, vll &yy)
{
    if(x==-1 && left)
    {
        return;
    }
    if(left==0)
    {
        ll m=0, m1=inf;
        repu(i,0,n-1)
        {
            m1=inf;
            rep(j,xx.size())
            {
                m1=min(m1,abs(v[i].se.fi-xx[j]));
            }
            rep(j,yy.size())
            {
                m1=min(m1,abs(v[i].se.se-yy[j]));
            }
            // cout<<m1<<" "<<v[i].se.fi<<" "<<v[i].se.se<<endl;
            m+=v[i].fi*m1;
        }
        ans=min(ans,m);
        return;
    }
    rep(i,2)
    {
        if(i==1)
        {
            xx.pb(v[x].se.fi);
            find(n,x-1,left-1,y,v,xx,yy);
            xx.pop_back();
            yy.pb(v[x].se.se);
            find(n,x-1,left-1,y,v,xx,yy);
            yy.pop_back();
        }
        else
        {
            find(n,x-1,left,y,v,xx,yy);
        }
    }
    return;
}

void solve()
{
    int n;
    cin>>n;
    vector<pair<ll, pair<ll, ll>>> v;
    ll x, y, p;
    rep(i,n)
    {
        cin>>x>>y>>p;
        v.pb(mp(p,mp(x,y)));
    }
    sort(all(v));
    repu(i,0,n)
    {
        ans=inf;
        vll xx, yy;
        xx.pb(0);
        yy.pb(0);
        find(n,n-1,i,i,v,xx,yy);
        cout<<ans<<endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}   

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

struct edge {
  int to;
  int64_t cost;
  edge(int to, int64_t cost) : to(to), cost(cost) {}
};

vector<vector<edge>> G;

void add_edge(int a, int b, int c, int64_t d) {
  G[a].push_back(edge(b, d));
  G[a].push_back(edge(c, d));
  G[b].push_back(edge(a, d));
  G[b].push_back(edge(c, d));
  G[c].push_back(edge(a, d));
  G[c].push_back(edge(b, d));
}

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;

  s--, t--;

  G.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    add_edge(a - 1, b - 1, c - 1, d);
  }

  vector<int64_t> d(n, 1001001001001001001ll);

  using P = pair<int64_t, int>;
  priority_queue<P, vector<P>, greater<P>> pq;

  d[s] = 0;
  pq.push(P(0, s));

  while (!pq.empty()) {
    P p = pq.top();
    pq.pop();

    int v = p.second;
    if (p.first < d[v]) continue;
    for (auto &e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        pq.push(P(d[e.to], e.to));
      }
    }
  }

  cout << d[t] << endl;
}



Measured memory_bytes: 23704
#include<stdio.h>
int main(){
	int n,a,i,k,max=1;
	scanf("%d",&n);
	
	for(i=1;i<33;i++){
		a=i;
		for(k=1;k<10;k++){
			a=a*i;
			if(a>n)break;
			else if(a>max)max=a;
			}
		}
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 128